Calculating a waveform while the audio file is playing

rmri

New member
I'm implementing a sequencer on the Teensy 4.1.
While the sequencer is playing back up to 8 voices I'd like to generate the waveform of the selected sample.
I'm using `SD.open` to open the file and process the samples in batches of 128 samples to calculate 200 sample long waveform array for the audio file.

However, if I do this repeatedly - changing the selected sample - I get audio dropouts.
I minimized my code to the point where I only open the selected file and still get the dropouts, so my understanding is that I should come up with a better way to read the same file from multiple file handlers.

What are some of the best practices related to reading the same file with different offsets simultaneously?
I've seen some people playing back the same sample polyphonically, so I think it should be possible. Any help would be greatly appreciated.
 
“Best practice” is to post a short sketch that someone else can compile and try out, using only the Arduino IDE and minimal hardware.

There are a couple of libraries capable of streaming multiple audio files from SD card while also doing other file activities, but it’s not clear from your description if that’s what you want to do. If it is, this thread may be of interest.
 
Just the latest TeensyVariablePlayback library should do it, but you must wrap all SD filesystem accesses with calls to AudioEventResponder::disableResponse() and AudioEventResponder::enableResponse() - see the FileAccess example.
 
Thank you, it worked.
I used AudioPlaySdResmp as a drop-in replacement for AudioPlaySdWav and wrapped SD.open(...) and file.read(...) with the mentioned calls.
I'm noticing some distortion on my samples that I have to look into, but otherwise the hang / crash issues I've been having have been fixed.
 
Great news. Don’t forget to wrap file.close() as well…

AudioPlaySdWav is usable in simple applications, but not really for 8 voices, and certainly not if you want to do other file access while streaming. That’s because it only reads tiny chunks, and does so inside the audio interrupt, resulting in mayhem when it interrupts itself.
 
What also worked for my DJ-player was precalculating the waveform and saving it in a separate file. You might not need all the data, making loading after calculation faster and you could also do some FFT for frequency detection. Takes about 6 seconds for a 5min track with FFT.

waveform.jpg
 
Back
Top