Long audio delays using SD Card

mborgerson

Well-known member
The attached zip file contains a sketch that is a proof-of-concept demonstration of the use of the SD card on the T4.1 as a large circular buffer to enable long audio delays. The demo implements a 20-second delay for a single channel of audio output at 44.1KHz. The demo initializes an SD card file as the circular buffer which is 9.83MB in length--sufficient for a delay of up to 111 seconds of delay for a single channel at 44.1KHz.

The demo uses 128KB of RAM1 for the buffers between the audio blocks and the SD file. I have put these buffers in RAM1 (DTCM) for best speed, but I think they might also work in RAM2 (DMAMEM) or external PSRAM (EXTMEM). The demo sends audio output to an attached audio adapter because it's really, really hard to figure out what is happening with println() to the serial monitor!

The number of seconds of delay available is limited only by the size of the file on the SD card. As you know, gigabytes of SD are getting cheaper every month, and a fast 128GB micro-SD is about $15 to $20 USD. Most new cards over 32GB have 64 to 128GB of onboard cache to carry you through block erases and block remapping for wear leveling. That cache makes determining read and write timing difficult. They are often optimized for linear sequential access--which is the case with this application.

Warning: I'm about five days from my first dive into the depths of Teensy audio processing. My T4.1 audio adapter arrived at that time (Online postal delivery from PJRC to my location 80 miles South of Portland took 1.5 to 2 days. A similar delivery from Sparkfun got caught in a blizzard in Colorado and took 5 days.) I haven't done any audio experiments over the last few years, so I expect I'm creeping up on the steep part of the learning curve.

I copied some stuff from audio library example code to allow my demo to play hums and beeps to show the delays. If you know your way around the Audio library, feel free to chuckle under your breath as you improve the code in the example.

I think this algorithm for the use of the SD card as a delay buffer may have utility outside the audio domain. Applications such as transient logging come to mind.

This proto-library needs a lot of polishing. The items on the top of my list are:

1. Why do I get error indications that are not evident in the audio output?
2. How do I change the delay on-the-fly as processing continues?
3. What changes are needed for multi-channel audio?


Of course, all the capabilities of this proto-library depend on the wonderful capabilities of the SDFat library that is part of the current TeensyDuino release. My congratulations to PJRC, Bill Greiman, and all the others that have made the T4.1 SD card such a useful peripheral.

View attachment AudioDelaySD.zip
 
Back
Top