Playing Multiple Sound Files (.wav) Individually and Simultaneously


I am using Arduino UNO and SD card module with TMRpcm library. I have selected Arduino digital pin 9 as "tmrpcm.speakerPin" because I am using Arduino UNO. Now I want to play multiple audio files (at least) from SD card simultaneously and individually. I have found that I could use Arduino pins 5, 6, 11 or 46 as "tmrpcm.speakerPin" if I use Arduino Mega. My questions are:

  1. Is it possible to use Arduino pins 5, 6, 11 and 46 as "tmrpcm.speakerPin" if I use Arduino Mega to play audio files simultaneously and individually?

  2. Or What kind of hardware or library I need to play multiple audio files simultaneously and individually using Arduino?

I am looking for your help.

Saddam Hossain

Is it possible to use Arduino pins 5, 6, 11 and 46 as "tmrpcm.speakerPin" if I use Arduino Mega to play audio files simultaneously and individually?

No. That technique requires two timers, one as a high speed source of adjustable duty cycle square waves and the other to generate the sample timing. So you can only have two audio outputs as there are two PWM generators per timer. Then you have the problem of reading two files from an SD card.

I did see a library that did this, I will see if I can find it.

This is it reading more than one file from an SD card and playback through PWM Although I am not too impressed with the quality.

However I would recommend using a DF Module module for each sound channel you want, and using an instance of software serial to control each.

I've never used the TMRpcm library, but I know about digital audio.

If you want to play two (or more) files at once, mixing is done by summation. (Analog mixers are built-around summing amplifiers.) To mix digitally, you "simply" sum the data sample-by-sample.

However, you have to reduce the levels so you don't go over 0dBFS (100%) to prevent [u]clipping[/u]. Of course you don't have to mix the files equally at 50/50, but the sum cannot exceed 100%. So technically you end-up averaging (maybe a weighted average) rather than simply summing.

And actually, something worse than clipping can happen... You can overflow the number of bits and data will "roll-over" (loosing the most significant bit or overwriting the sign-bit) and you can get horrible distortion. It takes a couple more processing steps to force clean-clipping in case of an overflow.*

And of course if the files have different sample rates, one file has to be re-sampled before you can sum sample-by-sample.

  • Usually (in a "real computer" or DSP chip) digital signal processing is cone in floating-point so you can go over 0dB without clipping/rolling over. However, ADCs & DACs are integer so the data has to be converted back to integer before playing, and the "forced clipping" (if needed) is normally done during the conversion to integer.

May I suggest to have a look at Teensy and the Audio Adaptor Board for Teensy. It would do that job nicely.

If you wanted to just buy something that does the job already, see:

A friend of mine uses a couple of 'em in a digital instrument.

Quite a clever little board:

robertsonics: Unlike most other embedded audio players, the WAV Trigger is polyphonic; it can play and blend up to 14 tracks at a time.

Yours, TonyWilk

Quite a clever little board:

It is indeed, could be the answer to a lot of people’s problems here. Good find +1