Audio play single in memory WAV - fails

Status
Not open for further replies.

isdale

Active member
I'm trying to play a single wav file from memory on Teensy 3.2 when triggered. As a test I do it in a loop.
The first play works ok, but subsequent play seem to either play other parts of wav or nothing.

Below is the basic code used. I'm not including the AudioSample files as most are from the Audio libary examples SamplePlayer. It is pretty simple, only one AudioConnection tween audio and teensy DAC
Once it starts play, it uses isPlaying() to delay until the sound stops. (is there a better alternative?)
When playing Buzzer, it plays first time, says it counted to 7, then waits and tries again
Sometimes the sound comes again, other times it is clipped off, other times nothing comes out even though it says it played.

If not this, what would be the simplest PlaySound() using Audio library?

Code:
// revision of PJRC Audio SamplePlayer that just cycles thru all
// does not use Buttons, only uses DAC

#include <TeensyAudio.h>  // simple rename to avoid conflict with Arduino Audio lib built into IDE
#include <SerialFlash.h>

// WAV files converted to code by wav2sketch
//#include "AudioSampleOne.h"
//#include "AudioSampleSnare.h"
//#include "AudioSampleBell.h"
#include "AudioSampleBuzzer.h"

//#define SOUND AudioSampleOne
#define SOUND AudioSampleBuzzer
//#define SOUND AudioSampleBell

// Create the Audio components.  These should be created in the
// order data flows, inputs/sources -> processing -> outputs
// one memory sound, one analog output, and one audio connection
AudioPlayMemory    playMemSound;
AudioOutputAnalog  dac;  
AudioConnection c10(playMemSound, 0, dac, 0);

void setup() {
  Serial.begin(115200);
  delay(500);
  Serial.println("Teensy One Sound Player");

  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(10);

}

void loop() 
{
  playOneSound();
  delay (2000);
}

void playOneSound()
{
  Serial.println("PlayOneSound");
  int count=0;
//  delay(100);
  playMemSound.play(SOUND);
//  delay(50);
  while (playMemSound.isPlaying())
  {
    count++;
    delay(200);
  }
  Serial.printf("Played sound %d counts\n", count);
}
 
Looks like it oughta work.

Can you share AudioSampleBuzzer.h and AudioSampleBuzzer.cpp, so I can try running it here?
 
Looks like it oughta work.

Can you share AudioSampleBuzzer.h and AudioSampleBuzzer.cpp, so I can try running it here?

I get similar odd results using the Bell and Snare from the Audio>examples>SamplePlay but here are the Sample One and SampleBuzzer
 

Attachments

  • AudioSampleOne.cpp
    80.9 KB · Views: 76
  • AudioSampleOne.h
    101 bytes · Views: 74
  • AudioSampleBuzzer.cpp
    162.9 KB · Views: 75
  • AudioSampleBuzzer.h
    105 bytes · Views: 66
I'm running it here on a Teensy 3.2. It makes a 90s-era business phone ringing sound every 2 seconds. It rings every time. Hasn't stopped even one over the last several minutes.

I edited "TeensyAudio.h" back to "Audio.h", but otherwise it's exactly the code you posted, with these 4 files added to its folder.

Maybe your installation is somehow corrupted. Or maybe files from other libs are causing trouble? Simplest thing might be to try on another computer, especially one that hasn't used Arduino before. Or maybe try uninstalling whatever other libs are conflicting? If you're using Windows or Linux, Arduino has a portable mode where it runs self-contained. You could try extracting a copy from a zip file, run the Teensyduino installer on that copy, then create the "portable" folder. Hopefully that will be enough to prevent that copy of the Arduino IDE from using the files elsewhere on your PC.

Best I can do is tell you it definitely does work when I run it here.
 
did you let it run a bit?
I dont have a naked machine, but I did a clean and reinstall from my mac, and also from a windows 10 laptop. And another PC.All build and load into teensy and it starts to play.

It plays about 4 times then starts clipping it off. Successive rings/plays clip more and more until it doesnt play at all. Then it comes back strong for a bit, then clips again.

This happens on both Buzzer and AudioSampleOne. Since they are large, I thought I'd try AudioSampleBell - which is from the Audio>examples>SamplePlayer. It does similar clipping and not playing - it sounds like it is playing from different parts of the memory (eg starting late)

Maybe it is something with this teensy and/or the speaker? (iHome speaker wired to DAC pin)

We are wiring up my AudioTutorial with a lineOut to speaker on the Audio board to try it. Maybe some other 3.2 with the DAC too.

(TeensyAudio hack was to work around an earlier issue with library conflict in the IDE)
 
the iHome is designed to go from any line output, like a phone (w/o bluetooth). It worked fine taking output from a DFPlayerMini but maybe it does need more boost?
 
did you let it run a bit?
...
It plays about 4 times then starts clipping it off. Successive rings/plays clip more and more until it doesnt play at all. Then it comes back strong for a bit, then clips again.

Yes, I let it play for several minutes. After a couple hundred plays, I really had to turn the speaker off.

I tested by connecting the DAC pin directly to the cord which runs to Aux input on the front of this monitor speaker (M-Audio AV40, now discontinued)


DSC_0260_web.jpg
 
Last edited:
Plugged into a 12v sparkfun amplifier it clips.

In theory you should be able to just turn the volume almost all the way down with the pots connected to the inputs. But that amp has so much voltage gain that only the first few degrees of the pot's rotation might be usable.

Maybe try replacing R1 and R3 on that Sparkfun amplifier with 10K resistors. Or just solder 10K resistors in parallel with the 100K ones already on the board, for approx 9.1K. That should reduce the total voltage gain into a range that's much more useful for this project.
 
That 12vdc amp wont be used for final project, but adding resistors may make it more usable for other ones. (I dont want to add another power supply to this system.)
For this project I ordered one of the LC Prop Shields, and also some of the mono amps from Sparkfun+Adafruit. Given it costs me more for shipping than the boards, I usually buy several at a time. We'll see which ones arrive first and what works best going into the PA system similar to your M-Audio speaker that is part of the whole 'Game Show' rig.
I'll post some pics of this project when complete. Its been a loooong time building. ;-)
 
and what works best going into the PA system similar to your M-Audio speaker that is part of the whole 'Game Show' rig.

You should *not* connect those class-D amplifier outputs to anything other than a regular speaker. They output waveforms similar to PWM. The idea is the speaker is basically a big inductor, since it's a coil of wire that doesn't conduct the very high frequency switching. It should *only* ever be connected to a speaker!

Do not connect a class-D amplifier output to the input of a PA system, home stereo, the input of an amplified computer speaker, or any other gear you care about.
 
You should *not* connect those class-D amplifier outputs to anything other than a regular speaker. They output waveforms similar to PWM. ...
Do not connect a class-D amplifier output to the input of a PA system, home stereo, the input of an amplified computer speaker, or any other gear you care about.

The LM48310 used on the PropShield is a Class D, so it is NOT a viable preamp for the teensy->PA. Do you have any recommendations for a device to go tween them?
 
Status
Not open for further replies.
Back
Top