Can the SD Card play WAV sounds into a mixer block for layered/overlapping sounds?

Status
Not open for further replies.

kyranzor

Member
I have a project where the SD card plays gun-shot sound effects, which may have trailing after-effects like bullet casings or a bolt/mechanism sound.

If the device fires 3-4 consecutive shots, in rapid succession, I'd like a way to layer the same sound effect starting at the beginning of each shot, and 'layered' or 'mixed' in such a way that the final output to the speaker overlaps the sounds and will retain at least the last X amount of samples. 3-4 is probably enough for me. So 3-4 shots, would cause 3-4 bullet casing sounds AFTER also playing the gunshot sounds. Currently, If I just trigger the sound it will start from the beginning and the longer sound effects/ambience is lost except of course for the very last sound playing.

I have done a little searching, and found "AudioMixer4" library, which I think will help do what i'm thinking.
"AudioMixer4 is used in File > Examples > Audio > PlayFromSketch to combine 6 memory players, so all 6 sounds can play simultaneously."

I don't want clipping as each new sound is added to the mix, how can I avoid that? As in, i'd like each sample playing to be just as loud as the other, but overlapping. I don't know if there's a way to do automatic gain or some 'unity gain mixer' for doing what I have just mentioned. Maybe some kind of normalization involved?

Is it possible to have multiple SD card files loaded or buffered so this can work only from SD sound samples? all samples for this purpose will be only 1-2 seconds max.. with the gunshot occuring in the first 200ms, and the shell casing heard at the end.

Thanks for any guidance or links to libraries/tutorials which can help me achieve my goals! :)

edit: I see on the audio SDWav library entry in https://www.pjrc.com/teensy/td_libs_AudioPlaySdWav.html
"TODO: how many AudioPlaySdWav and Mixer4 objects can realistically run simultaneously (eg, how many "voices" can really be played). This should be tested with good cards (eg, Sandisk Ultra) and some cheap no-name cards that lack good buffer management, even though they claim "class 10" speed."

SO it sounds like I might be able to try this out straight away, and report back here to hopefully update that "TODO" with some more info for other users? :)
 
Last edited:
You need a Teensy 3.x - 3.5 and 3.6 have inbuilt SD-Slots, if you use the audioshield (great soundqualty), you can use Teensy 3.2 (SD-Slot on the shield). You'll need an amplifier. I'd use a 3.5 (5V tolerant) or 3.6 (faster).
Please wtach the really good vido from Paul, and use the design tool on this page: https://www.pjrc.com/teensy/td_libs_Audio.html
There are some useful examples in the Arduino menu after you have installed Teensyduino.
 
Usually only 3 sounds can be played simultaneously from the SD card. It's the Arduino SD library limitation.

About a dozen sounds can be played simultaneously from a serial flash chip. Those chips have very low, fixed latency, which is the big difference compared to SD cards.

If your sound can fit into the internal flash memory in Teensy 3.6, you can play *many* copies very efficiently. But there's just under 1 megabyte of that flash, so it goes quickly. Still, the sample player might be worthwhile. There's a command line tool to convert WAV files into C arrays to import into Arduino, so your sound clips go right into your program. See the File > Examples > Audio > SamplePlayer example, or the sample playing part of the tutorial for details.
 
Hey Paul and Frank thanks for the replies!

The teensy 3.2 I test with on my own custom audio board (has SD card mount and a texas instruments 25W mono channel class D amplifier IC) has enough internal memory to store ~5 samples of the lengths I work with. I have them assigned indexes for randomly playing each one, but I haven't tried playing them with a mixer/simultaneously yet.

I think 3 sounds from the SD card will actually work for me well enough, a running maximum of 3 samples at any time, with newer ones cancelling/stopping the oldest sample still playing.. should be good! In my earlier custom audio board design I had a 2Mbyte serial flash chip on the board but ended up getting rid of it. I want to focus on SD card usage for maximum flexibility for the end-users.

Thanks guys I will test all these theories out and post here to follow up in case anyone else asks.
 
Hey Paul and Frank thanks for the replies!

The teensy 3.2 I test with on my own custom audio board (has SD card mount and a texas instruments 25W mono channel class D amplifier IC) has enough internal memory to store ~5 samples of the lengths I work with. I have them assigned indexes for randomly playing each one, but I haven't tried playing them with a mixer/simultaneously yet.

I think 3 sounds from the SD card will actually work for me well enough, a running maximum of 3 samples at any time, with newer ones cancelling/stopping the oldest sample still playing.. should be good! In my earlier custom audio board design I had a 2Mbyte serial flash chip on the board but ended up getting rid of it. I want to focus on SD card usage for maximum flexibility for the end-users.

Thanks guys I will test all these theories out and post here to follow up in case anyone else asks.

Serial flash can be read *much* faster. Maybe copy the files from SD to flash (automatically)? You could use way more than 4 samples this way.
 
Frank,

I had not considered copying the files into an external flash chip, that sounds like a reasonable plan to check out. My concern is that the users are not necessarily bound to a certain length/size of file and things might fail to copy over and otherwise be a hassle if that happens. My hardware design is 99.9% locked in now too, so I can't add a serial flash chip at this point anymore anyway. I'll have to make do with library magic, but thanks!
 
Status
Not open for further replies.
Back
Top