Multiple open SD files and the Audio library interrupts (reentrancy)

Status
Not open for further replies.

unicornpower

Well-known member
I'm writing a looper effect which requires recording to one audio buffer (a file on the SD card), whilst reading from another (a different file on the SD card). The 'play file' is read during an AudioStream::update(), e.g. within an interrupt. The 'record file' is written to during the standard main loop update. I'm struggling to find documentation about the SD library and reentrancy, and whether it should be possible to have 2 open SD files where calls into SD functions may 'overlap', e.g an SD function is called on one file, and during this function call, an interrupt triggers which calls an SD function on another file.

This is making it hard for me to determine if I simply have a bug in my code, or I'm doing something unsupported.

For anyone interested, the full code is here https://github.com/cutlasses/Looper. This is running on a Teensy 3.5, using the built in ADC and DAC.

The issue I have is that the main loop hangs when the audio stream closes its file. I've traced the flow of control to this:

Code:
--Main Loop--                                --Interrupt--

call to SD::write()
on record file

                                             call to SD::close()
                                             on play file

HANG

SD::write() never terminates

                                             interrupt continues interrupting
 
I'm still not sure on the answer here. But, I'm assuming (from my experiements) that the current Teensy SD library is not re-entrant. Therefore I should not be accessing files within an interrupt AND the main loop? From studying the Recorder.ino example, I notice that this never reads and writes at the same time (it's either recording or playing).

I think my best solution is to use a record queue and a play queue. So that the audio effect ::update() function never access the SD card. I'd be interested to hear a definite answer about whether the SD library is re-entrant though.
 
Status
Not open for further replies.
Back
Top