PDA

View Full Version : Audio Library Latency from SD Card



cbnathanael
09-12-2015, 03:06 PM
Hi, folks!

My goal is to use the Teensy 3.1 and SD adapter to loop a single raw file, and inject random raws on top of that under certain circumstances. From what I can see, the Audio Library does that just fine. My concern is with the latency in loading the secondary audio files. What's the typical delay between issuing the play command and actually hearing the audio?

Some things I've considered:

Audio adapter with the W25Q128FV memory addition, but the board is slightly too large (!!) for my application.
wav2sketch conversion, but I'm aiming to use 10-20 files, so it doesn't fit within the Teensy's memory.


The secondary question is attaching an amp to the Teensy. I'm assuming I can connect the DAC pin to something like Adafruit's 2.5W amp (https://www.adafruit.com/products/2130)...but I haven't done my homework on this part, yet.

Thanks!
Nate

mxxx
09-12-2015, 07:45 PM
What's the typical delay between issuing the play command and actually hearing the audio?


it somewhat depends. a few ms from SD/FAT and a few ms from the audio engine. this thread (https://forum.pjrc.com/threads/28974-Audio-Library-Play-Latency?p=76344&viewfull=1#post76344) has some pointers. generally speaking, latency is quite a bit better with spi flash.

cbnathanael
09-12-2015, 07:51 PM
Excellent link, thanks! An initial skimmed it look promising.

I'm considering flash, but it might be "too difficult" for the end result of the project (non-teensy user loading audio files). A hybrid might work, though. I assume it's possible to have the teensy copy files from the SD to flash during setup?

mxxx
09-12-2015, 09:21 PM
yep, take a look at the CopyFromSD (https://github.com/PaulStoffregen/SerialFlash/blob/master/examples/CopyFromSD/CopyFromSD.ino) example, it's basically doing that. the end user doesn't have to know really, except it'll take a while.

cbnathanael
09-12-2015, 10:37 PM
That's great! Thanks!

PaulStoffregen
09-13-2015, 01:48 AM
The SPI flash chips have lower latency. But unless there's some very special need for precise timing (like special waveform cancellation techniques), either way should have lower latency that humans can perceive. If it's just a matter of whether humans can perceive the delays, I'd recommend going with whatever approach is simplest.

If using a SD card, don't forget to run the benchmark, in File > Examples > Audio > HardwareTesting > SdCardTest. Do this first, so you can know if your card is fast enough when used with the (limited) Arduino SD library.

If you don't need to ever write to the card, and you're ok with trying experimental code, you can edit SD_t3.h to turn on the experimental optimizations.

cbnathanael
09-13-2015, 04:56 AM
Thanks, Paul!

This stuff is amazing...I'm surprised at how easy it is to get up and running. The SD Card was unexpectedly fast (I bought a cheapo off-brand from Target, and even opening 4 files, I was seeing less than 10ms latency).

Now, for playing WAVs through the DAC, I assume an amp is needed... Will a simple class D work? (like the adafruit one I linked above)

PaulStoffregen
09-13-2015, 06:57 AM
Yeah, almost any amp that takes a standard line-level signal should work fine.

That Adafruit one has 24 dB gain, which is a bit high. By default, Teensy's DAC output is 1.2V peak-to-peak with a full scale signal. You might have to turn the volume adjustment down quite a bit, but it should work.

cbnathanael
09-19-2015, 04:38 AM
The adafruit amp arrived today, and it's working like a champ. Thanks, Paul!

MacroMachines
01-17-2016, 01:12 PM
If you don't need to ever write to the card, and you're ok with trying experimental code, you can edit SD_t3.h to turn on the experimental optimizations.

I wanted to check out the optimized version and downloaded from your github but I need to record audio files as well. Does this mean you do not have writing ability if optimized is enabled?

PaulStoffregen
01-17-2016, 01:17 PM
Does this mean you do not have writing ability if optimized is enabled?

Correct, there's absolutely no writing to the SD card with the optimizations compiled.

You don't get to have your cake and eat it too. Well, at least not until I do a *LOT* more work on the SD library. Someday.....