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

Thread: Audio Recording / Logging to SD card --> microSoundRecorder

  1. #1
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    225

    Audio Recording / Logging to SD card --> microSoundRecorder

    You can find many threads dealing with this topic in the PJRC forum. I have gone through many of them and tried a lot of the given code, but unfortunately I could not find easy-to-use code which reliably records audio onto an SD card without glitches and/or missing samples. Not only me, but obviously many forum users are looking for a reliable way to record audio to an SD card.

    THEREFORE IN THIS THREAD I WOULD LIKE TO SUMMARIZE MY EXPERIENCES WITH AUDIO RECORDING TO SD CARD, GIVE LINKS TO DIFFERENT CODE EXAMPLES BY OTHER FORUM USERS AND FINALLY GIVE A LINK TO A VERY NICE SOLUTION PROGRAMMED BY WALTER, WMXZ, WHICH WORKS VERY WELL AND HAS BEEN EXTENSIVELY TESTED IN THE FIELD FOR UNATTENDED AUDIO RECORDINGS OF BIRDS AND OTHER ANIMALS.

    At first sight, recording audio to the SD card is very easy to achieve (Teensy plus audio board) with the example given in the Audio lib using the mic input of the Teensy audio board or the line input.

    https://github.com/PaulStoffregen/Audio/blob/master/examples/Recorder/Recorder.ino


    Other Teensy friends have programmed their own recording sketches using other inputs or other goals. These sketches differ largely in their reliability and the ease of use by unexperienced users.

    However, it is often pointed out that the recordings have glitches or missing samples:

    https://forum.pjrc.com/threads/47259-Save-file-to-SD-in-a-different-thread-(or-use-interrupts-for-sampling-)?highlight=audio+recording

    https://forum.pjrc.com/threads/46873...ing-Quad-Audio
    https://forum.pjrc.com/threads/43834...-5-3-6-SDIO-SD
    https://forum.pjrc.com/threads/47075...udio+recording
    https://forum.pjrc.com/threads/46150...udio+recording
    https://forum.pjrc.com/threads/42562...l=1#post160848
    https://forum.pjrc.com/threads/52127...rom-recordings

    Also for me, when I tested several of these sketches, I realized that it is very hard to achieve reliable recordings without glitches and lost samples for several reasons:


    • SD cards sometimes need a considerable amount of time to react to the Teensy write command. This can take up to half a second or even more. This means that the audio library has to buffer all the samples coming into the audio queue and subsequently write them to the SD card while simultaneously buffering all the recent audio samples coming in
    • The audio lib has a restriction of a maximum number of audio blocks it can buffer. This maximum number is often too low to cover the latency of an SD card, which leads to buffer overrun and lost samples


    The consequence is that I looked for a more reliable way and discovered that Walter, WMXZ had already programmed such a sketch (for the Teensy 3.6 only, because a very large RAM is needed for the audio buffer). When I contacted Walter with a further wish list of features, he was so kind to add a lot of other useful features and I carried out a lot of testing on the bench and in the field.

    https://forum.pjrc.com/threads/46136-Yet-another-SimpleAudioLogger


    The sketch can be found here:

    https://github.com/WMXZ-EU/microSoundRecorder

    It has many useful features built-in:


    • Time scheduled recordings
    • Audio-triggered recordings
    • Application to program recording settings without having to reprogram the Teensy
    • Automatic time & date stamps
    • WAV-file header
    • Hibernation function to save power
    • Function to regularly wake up in order to wake up a USB power bank that could be used to power the Teensy


    In several field test sessions we tested the reliability and the usability for an unexperienced user like me. It works very well and has the potential of expansion for different input sources. At the moment it has been tested in the following configurations:


    • Teensy 3.6. & two ICS43434 digital microphones (STEREO)
    • Teensy 3.6. & one ICS43434 digital microphone (MONO)


    Other configurations (untested) include:

    • Built-in ADC MONO
    • Built-in ADC STEREO
    • Audio board I2S Stereo input
    • Audio board I2S Quad input


    See the WIKI on github for further information and documentation.

    https://github.com/WMXZ-EU/microSoundRecorder/wiki

    Thanks a lot to Walter WMXZ for the excellent solution and thanks to Paul for all the work with the Teensy audio library!

    Have fun with the Teensy!

    Frank DD4WH

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,438
    One could try to add a SPI-RAM as buffer for the SD-Card to the audio-shield. It has the same pinout as FLASH, so the existing pads will work.

  3. #3
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,646
    Quote Originally Posted by Frank B View Post
    One could try to add a SPI-RAM as buffer for the SD-Card to the audio-shield. It has the same pinout as FLASH, so the existing pads will work.
    I have thought about it and have done it on another project (using T3.2), but this limits the overall bit rate to half the SPI-RAM clock rate (write to RAM and read from RAM).
    The T3.6 allows already for about 200 kB buffer, so for the 23LC1024 to be useful one needs data rates > 2 MB/s while covering 0.1 s uSD delays. As the 23LC1024 access is limited to 20 MHz, this supports up to 10 MBit/s or 1.25 MB/s data rate (write and read)
    In the absence of quad SPI (SQI) on Teensy, this results to an interesting design. I may think about it, as I have an application where 200 kB buffer is not large enough (high speed multichannel acquisition totalling a datarate of 30 MBit/s), but I still have some 23LC1024 available, so I even may try it.

  4. #4
    Senior Member Blackaddr's Avatar
    Join Date
    Mar 2017
    Location
    Canada
    Posts
    170
    Quote Originally Posted by Frank B View Post
    One could try to add a SPI-RAM as buffer for the SD-Card to the audio-shield. It has the same pinout as FLASH, so the existing pads will work.
    This is the approach I had been planning for an upcoming project on my TGA Pro board. I've already modified crteensy's DmaSpi library to support DMA transfers to/from the SPI RAM. As you guys already suggested, use the SPI RAM as a big FIFO buffer for writing to the SD card.

    As a very rough calculation, Each channel of audio is 44100 * 16 bits = 705.6 KHz. I figured the 20 MHz SPI rate should provide enough total throughput for several channels of read and write.

    Of course I haven't tried any of this yet!

Posting Permissions

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