I'm using a Teensy 4.1 with an Audio Board (Teensyduino 1.57) to play instruments from sample files on a SD Card with a very low latency (<10ms) for live playing and polyphony. There will be a knob that allows you to select an instrument and then the program will load that instrument's samples from the SD Card for playing.
I've tested the latency for playing a sine wave with the Audio library and then listening with an electret mic for the note-to-sound latency and it is around 7 ms. I'd like to play the WAV file samples on the SD card just as fast, but running into problems. For reference, I'm using this SD card which I think should be fast enough: https://www.amazon.com/gp/product/B09X7CRKRZ/
I first tried to use the AudioPlaySdWav from the Audio library which clocks in around 40 ms, slower than I need. I could use wav2sketch to turn the WAV files into .h and .cpp sketch files which I guess then get stored on Flash memory and then use AudioPlayMemory to play them but I have many gigabytes of audio files on the SD Card and they cannot all be stored in Flash.
My Teensy has two chips soldered to the underside for extra 16MB of PSRAM so I could try to load just the currently selected instrument's worth of WAV files from the SD Card into an array and then use AudioPlayMemory to play the arrays as needed, I figure this is the fastest possible way too since they would be playing straight from RAM. Does anyone know if there are libraries that allow you to quickly load a WAV from an SD Card into an array in PSRAM memory?
Also does anyone know any better or faster ways to do this?
Side note: I've also been trying to use a Raspberry PI 4 for this since that has tons of RAM to load the WAV files into memory, but I found the latency to be around 60 ms using the code from the Samplerbox project: https://github.com/josephernest/SamplerBox
Has anyone been able to get a Raspberry Pi or other set up around 10 ms latency?
Thanks for any advice!
I've tested the latency for playing a sine wave with the Audio library and then listening with an electret mic for the note-to-sound latency and it is around 7 ms. I'd like to play the WAV file samples on the SD card just as fast, but running into problems. For reference, I'm using this SD card which I think should be fast enough: https://www.amazon.com/gp/product/B09X7CRKRZ/
I first tried to use the AudioPlaySdWav from the Audio library which clocks in around 40 ms, slower than I need. I could use wav2sketch to turn the WAV files into .h and .cpp sketch files which I guess then get stored on Flash memory and then use AudioPlayMemory to play them but I have many gigabytes of audio files on the SD Card and they cannot all be stored in Flash.
My Teensy has two chips soldered to the underside for extra 16MB of PSRAM so I could try to load just the currently selected instrument's worth of WAV files from the SD Card into an array and then use AudioPlayMemory to play the arrays as needed, I figure this is the fastest possible way too since they would be playing straight from RAM. Does anyone know if there are libraries that allow you to quickly load a WAV from an SD Card into an array in PSRAM memory?
Also does anyone know any better or faster ways to do this?
Side note: I've also been trying to use a Raspberry PI 4 for this since that has tons of RAM to load the WAV files into memory, but I found the latency to be around 60 ms using the code from the Samplerbox project: https://github.com/josephernest/SamplerBox
Has anyone been able to get a Raspberry Pi or other set up around 10 ms latency?
Thanks for any advice!