PDA

View Full Version : Playing Small WAV file from onboard memory - without the audio shield



eboston
01-05-2016, 03:21 AM
I have a small project that I am working on and would like to have a "background" sound playing. The WAV file is only a couple K and I'm trying to keep costs down and the circuit simple. Everything I have seen in the forums seem to be centered around the audio shield but I was hoping to find something that could play a WAV file from the onboard memory. I have a couple Teensy LC I am starting the play around with. Is this possible with the LC or do I need a 3.1?

PaulStoffregen
01-05-2016, 06:06 AM
Today the audio library only works on Teensy 3.x. Some initial work has started on LC, so eventually it'll work, but for now it doesn't run on Teensy LC.

So Teensy 3.2 is the very easy path. In fact, just open File > Examples > Audio > SamplePlayer for code that plays up to 6 simultaneous sounds from the internal program memory. All the examples send to a I2S object (the audio shield), but you can easily replace it with a DAC object, and delete the SGTL5000 object which controls the audio shield. They it'll play to the DAC pin.

If you don't need to do much else while playing, you could probably write your own code that reads data from memory and write it to the DAC pin. That's pretty simple. But doing it the way the audio lib does, so the sound keeps playing smoothly while other arbitrary code runs is, well, much harder. If you need to do stuff while the sound plays, Teensy 3.2 is definitely the right path for now.

MichaelMeissner
01-05-2016, 06:46 AM
Today the audio library only works on Teensy 3.x. Some initial work has started on LC, so eventually it'll work, but for now it doesn't run on Teensy LC.

So Teensy 3.2 is the very easy path. In fact, just open File > Examples > Audio > SamplePlayer for code that plays up to 6 simultaneous sounds from the internal program memory. All the examples send to a I2S object (the audio shield), but you can easily replace it with a DAC object, and delete the SGTL5000 object which controls the audio shield. They it'll play to the DAC pin.

If you don't need to do much else while playing, you could probably write your own code that reads data from memory and write it to the DAC pin. That's pretty simple. But doing it the way the audio lib does, so the sound keeps playing smoothly while other arbitrary code runs is, well, much harder. If you need to do stuff while the sound plays, Teensy 3.2 is definitely the right path for now.
I've asked this before, and you said to remind you after the prop shield comes out, but exactly what do you need between between the DAC and a speaker? The only hint I've seen is http://www.pjrc.com/teensy/gui/?info=AudioOutputAnalog where it says you need at least a 10F DC-blocking capacitor, but with the voltage of the DAC being 0..1.2v, I assume for most speakers you need some sort of amplifier like https://www.adafruit.com/products/2130.