Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

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

  1. #1

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

    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 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:

    --Main Loop--                                --Interrupt--
    call to SD::write()
    on record file
                                                 call to SD::close()
                                                 on play file
    SD::write() never terminates
                                                 interrupt continues interrupting

  2. #2
    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.

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Germany NRW
    No, it is not re-entrant.

  4. #4
    Ah, thanks very much! At least I know I'm headed in the right direction now!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts