DD4WH
Well-known member
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-Glitches-When-Sampling-Quad-Audio
https://forum.pjrc.com/threads/43834-Real-low-latency-logging-for-Teensy-3-5-3-6-SDIO-SD
https://forum.pjrc.com/threads/47075-Audio-Board-and-stereo-recording?highlight=audio+recording
https://forum.pjrc.com/threads/46150-Recording-Stereo-Audio-to-SD-Card?highlight=audio+recording
https://forum.pjrc.com/threads/4256...-audio-library?p=160848&viewfull=1#post160848
https://forum.pjrc.com/threads/52127-Bits-of-audio-missing-from-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:
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:
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:
Other configurations (untested) include:
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
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-Glitches-When-Sampling-Quad-Audio
https://forum.pjrc.com/threads/43834-Real-low-latency-logging-for-Teensy-3-5-3-6-SDIO-SD
https://forum.pjrc.com/threads/47075-Audio-Board-and-stereo-recording?highlight=audio+recording
https://forum.pjrc.com/threads/46150-Recording-Stereo-Audio-to-SD-Card?highlight=audio+recording
https://forum.pjrc.com/threads/4256...-audio-library?p=160848&viewfull=1#post160848
https://forum.pjrc.com/threads/52127-Bits-of-audio-missing-from-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