Go Down

Topic: Playing multiple .wav files (Read 2103 times) previous topic - next topic

bdeane

New to arduino, I'm wondering if there's anyway I can play multiple .wav files simultaneously?

CrossRoads

Sure, have multiple sound playback shields that your Arduino sends commands to. Might have to not have them stacked so you can break out appropriate control wiring, or have some hardware multiplexing/switching so you can select the board you want  to send commands to.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

bdeane

Hi, I'm trying to do some research on playback shields but I can't seem to find much, would you mind explaining what they are and how they work?

DVDdoug

An audio shield contains all of the circuitry to play a sound.

It has memory for the sound files, it has a digital-to-analog converter, a clock to read & play the file at the correct sample rate, the firmware to read and decode a WAV or MP3 file header, etc.   And of course, an MP3 shield also has an MP3 decoder.

Some audio shields can drive headphones, but for speakers you either need "powered" computer speakers, or you need an external amplifier.

The Arduino simply sends a few codes telling it to play a file.    And, that's part of the problem with playing more than one file at once...    Your software isn't directly reading & playing the audio files.   That's all handled by firmware built-into the chip on the audio shield.

You might consider a Raspberry Pi.   I've never used one, but it's a small single-board computer.  It has a built-in soundchip and it can run an operating system so you should be able to do things like open two WAV files and mix the audio.

Hoek

Playing multiple WAV files is actually quite easy... the real problem is the lack of memory in the low end Arduinos is too limiting for storing WAV files in their entirety for easy access. The SD card allows a WAV file to be streamed and played but unless the bitrate is low it's usually limited to a single WAV file streaming at a time.

If however you wanted to mix together, for arguments sake 4 PCM values that can be calculated easily and fast for sample(x) = fn(t) then it's just a matter of adding the individual samples and dividing by the number of samples.

The sample below is very simple. If you have stereo output you can do all sorts of stuff in real-time with the panning as well.

Code: [Select]

int mixed = (sample1 + sample2 + sample3 + sample4) / 4; // each sample is 0 - 255
sendDAC(mixed);


Personally I would recommend an Arduino Due or a Teensy 3 if considering anything with sound manipulation.

Grumpy_Mike

#5
Mar 27, 2016, 11:29 pm Last Edit: Mar 27, 2016, 11:30 pm by Grumpy_Mike
reading more than one file from an SD card and playback through PWM
https://github.com/TMRh20/TMRpcm


Quote
You might consider a Raspberry Pi.   .......  It has a built-in soundchip
No it doesn't.

Go Up