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

Thread: Storage and Format Questions for Audio Sound Files

  1. #1

    Storage and Format Questions for Audio Sound Files

    My project is to make a stand-alone drum machine with 30 sensors, each triggering a separate sound. I have a Teensy 3.5 and a Teensy audio shield.

    I have successfully executed a number of tutorials and examples. I can get music to play from the SD card on the audio shield (from the audio library tutorial) and can get SimplePlayer to work with momentary switches playing sound files stored in the folder with the Arduino code. I have also made my own sound files for my project and formatted them with Wav2Sketch to make them *.cpp and *.h files. This all works fine.

    The issue I have is that the Teensy does not have enough memory to store all of my audio files (*.cpp and *.h files).

    From reading through the forum, it looks like you only play *.wav or *.raw files from the SD card. Iím unclear on this and wondering if I can store my *.cpp and *.h files on the SD card. Or do I need to have all of my sound files in wav or raw format on the SD card for my triggers to access?

    Or should I purchase some additional flash memory so I can store all of my *.cpp and *.h files there. Iím not sure, but some information and/or advice would be appreciated.

    And if someone can point me to some existing code with any kind of musical instrument where the sound files are on the SD card, that would be great. I wonder if that would cause latency.
    Please note I am NOT wanting any MIDI in this project. This is a small, stand-alone project with nothing connected to the sensors other than the Teensy, itís audio shield a battery and powered speaker.

  2. #2
    Senior Member
    Join Date
    Feb 2015
    You have several options.

    - Store all wav and raw files on a microSD card. This will be probably the easiest to implement and maintain, but comes with at least 2 drawbacks: the audio library does not allow use of DMA (which would help make your code more responsive by allowing the CPU to go do other things while SD card access is happening) and the audio library only supports old-school DOS filenames (8.3 filenames). Both of these issues can be solved by modifying the audio library to use Greiman's SdFat library or SdFs library. The modifications are pretty simple though. A really good quality SD card is super important to get playback of lots of samples simultaneously. I've used Lexar 1000x 32GB cards so far and they have been good (at least 4 concurrent samples I think).

    - Store only raw files on a serial flash chip. The audio library supports raw file playback from serial flash, but not wave file. You would then need to devise a way to get the files onto the serial flash chip. Probably the easiest way to do that, would be to have the teensy copy all raw files from SD to serial flash during startup. Why bother with this? Well, serial flash has very low latency and you would be able to play a large amount of sounds simultaneously.

    - Wait for Teensy 4 to be released, and store all sound files as compiled cpp files, exactly as you are now. It might have enough flash to hold all the compiled cpp sounds.

    So, just to make it clear, none of the options includes the ability to play compiled cpp files out of external flash memory. It's internal flash memory only for compiled cpp sounds.

  3. #3
    Wcalvert, thanks for the reply. I think I understand your answer. I'll definitely get the Teensy 4 when it is released, since playing compiled cpp files out of internal flash memory is the easiest way for me to run my existing program and I've spent a lot of time figuring out how to get the code to work (with help from the forum). In the meantime and until the Teensy 4 is available, are you aware of any code in the forum, at GitHub or a Teensy tutorial or example for me to copy into my program to have my Teensy copy raw files from SD to serial flash during startup?

  4. #4

  5. #5
    Thanks wcalvert. I'll try to make this work.

  6. #6
    Wcalvert, Just to be clear. I put all my cpp files on the SD card and then when this code runs it copies all the cpp files to my internal flash to run, or I need to use raw or wav files?

  7. #7
    Senior Member
    Join Date
    Feb 2015
    Raw or wav files only Anything compiled has to fit on the internal flash memory.

Posting Permissions

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