Go Down

Topic: Can I play multiple-sounds(wav file) with one speaker? (Read 637 times) previous topic - next topic

mukisasl

Hi.
We are completely newbie in arduino.

We are making mini launchpad which has 25 pad.

So we need to play at least 3or4 wav-files simultaneously at the same time through one speaker.

Speaker needs to big for our project so we decided use studio speaker.

We are finding shield which have that function.

But, we can't find it at last.

We find some links ,but, we don't know whether them are what we find for.

here's links :
https://www.sparkfun.com/products/8894
http://174.136.57.11/~ruggedci/html/flexible_midi_shield.html
https://www.sparkfun.com/products/12000

If you could give me better alternative, please help.

gorgon

Hi,

in order to play soundfiles with half decent quality you need an mp3 or wav module of at least 10€, but that will only play one sound file at the time. For every level of polyphony you need, then an additional module is needed, with it's accompanying sd card and or sd card reader module.

If playing several samples at once is necessary I'd reccommend you to use a raspberry pi instead, which would also give you lots of DSP possibilities through pure data, supercollider etc if you want.

If you do want to use arduino to trigger mp3/wav files in the end, the only module I can reccomend is the WT5001M02-28P.

cheers

DVDdoug

I've never used an audio shield with the Arduino, but if you can figure out how to send data directly to the shield without "automatically" playing from a file, it should be easy...

Digital audio mixing is done by addition (summation).  And in fact, analog mixers are built around summing amplifiers.     Digitally, you just add the sample-by-sample data (i.e. 44,100 samples-per-second for CD quality audio).

There is one "catch".   Digital-to-analog converters are integer devices.   i,e. If you have a 16-bit DAC and you simply add two (or more) full-volume 16-bit files together you'll exceed 16-bits and clip (or roll-over, etc.).   So, you need to scale-down or average the data streams (before or after mixing).

Normally, DSP (digital signal processing) is done in floating-point.   That way you can avoid "overflow",  and scale-down the data later before converting to integer for the DAC (or WAV file, etc.). 

Also, it should be obvious that both data streams must have the same sample-rate and the same bit-depth.  If they are not the same, one must be upsampled or downsampled.

WAV files are simply a header followed by raw PCM data, so they are easy to deal with.   If you want to mix MP3 (or other compressed files) you have to decompress to PCm before mixing.

Grumpy_Mike

The problem with doing this on the Arduino are:-
1) you can not open more than one file on an SD card at any one time and there is not enough SRAM to buffer them.

2) as mentioned lack of a D/A, you have to use an external one and you have to bit bang the SPI interface because the SD card is using the hardware SPI Pins.



TMRh20

The problem with doing this on the Arduino are:-
1) you can not open more than one file on an SD card at any one time and there is not enough SRAM to buffer them.

2) as mentioned lack of a D/A, you have to use an external one and you have to bit bang the SPI interface because the SD card is using the hardware SPI Pins.



This is completely incorrect.

Take a look at https://github.com/TMRh20/TMRpcm  It demonstrates quite clearly that you can open, access, and read from multiple files on a single SD card and play them back simultaneously using only a 328 based board and no shield. Audio can also be replicated using PWM and timers without a real D/A .

Using similar methods on a Teensy or a Due would extend the capabilities quite a bit as well.





Grumpy_Mike

#5
Nov 03, 2014, 10:39 am Last Edit: Nov 03, 2014, 10:40 am by Grumpy_Mike
Quote
Take a look at https://github.com/TMRh20/TMRpcm  It demonstrates quite clearly that you can open, access, and read from multiple files on a single SD card and play them back simultaneously using only a 328 based board and no shield.
Interesting. Have you got any example videos of two files playing at once?

The Yoda speaking video was not too impressive and that was only one sample at a time.

Using the PWM timers as a D/A output connected directly to a speaker with no filtering but the "natural" frequency response of the speaker is a bit of a hack.

I suppose if you reduce your expectations of what constitutes "work" you can work wonders.

Paul Stoffregen

Using similar methods on a Teensy or a Due would extend the capabilities quite a bit as well.
If you do step up to a 32 bit ARM board, things get quite a lot easier.

Still, SD card random read latency and the Arduino SD library can be limiting factors.  Not all SD cards are created equal.  Many of the supposedly fast "class 10" cards, which are very quick when reading or writing one large, sequentially accessed file (eg, cameras & camcorders) turn out to be extremely slow when used with a random access pattern, or a simple pattern where 2 or 3 or more files are accessed 1 block at a time.  The Sandisk Ultra cards are much better than ordinary cards.

Because of these differences, I wrote this simple benchmark example, which attempts to read multiple 16 bit, 44.1 kHz stereo wav files and measure the worst case latency per 512 byte block.  It expresses the results in terms of the Teensy Audio Library timing.  Other than the 2 special lines to configure SPI pins (which you can simply delete), this code ought to run on any Arduino board.  Maybe the benchmarks will be interesting?

TMRh20

Interesting. Have you got any example videos of two files playing at once?

The Yoda speaking video was not too impressive and that was only one sample at a time.

Using the PWM timers as a D/A output connected directly to a speaker with no filtering but the "natural" frequency response of the speaker is a bit of a hack.

I suppose if you reduce your expectations of what constitutes "work" you can work wonders.
I haven't made any example videos, but the library includes easy examples to demonstrate the feature. The Yoda video was made by a friendly contributor, so please try to be nice.

You can resort to insults if you want, I'm not even sure what to say to the last bit...

Grumpy_Mike

In this thread,
http://forum.arduino.cc/index.php?topic=276594.0
reply #3

Quote
Arduino Uno sound playback using PWM technique -  I quickly abandoned that idea because the sound quality was really bad.
and he only wanted speech.

So it is not just me that thinks this.

TMRh20

In this thread,
http://forum.arduino.cc/index.php?topic=276594.0
reply #3
and he only wanted speech.

So it is not just me that thinks this.
Ok, nice troll tactic, change the subject after being proven wrong and insults fail.
Now the problem is the sound quality.

All I can say to that is that anybody can write bad code, and that is a matter of perception.

Wireless streaming of audio over RF24 modules using only 16mhz Arduino/AVR boards:
http://www.youtube.com/watch?v=2ZK6dcBTeT0

As you have indicated on multiple occasions that some of the things I do with these libraries are impossible, I would think that you would be quite astonished at the sound quality, and happy to have learned something new.



jon_s

We find some links ,but, we don't know whether them are what we find for.

here's links :
https://www.sparkfun.com/products/8894
http://174.136.57.11/~ruggedci/html/flexible_midi_shield.html
https://www.sparkfun.com/products/12000

If you could give me better alternative, please help.
The Sparkfun WAV trigger should be able to do what you need -- it can play up to 14 polyphonic tracks.

Pensive

Either use the WAV trigger is you just wish to mix the tracks, or if you need more power, you need to use the Teensy 3.1 with the Audio board. This supports effects, synth's, has a compressor on board etc. and is a totally customisable audio engine.

https://www.pjrc.com/store/teensy3_audio.html


16bit full DAC with headphone and line out options, plus MicroSD slot on board, and accompanying audio library for mixing multiple samples together.

You can play 2 WAVs at 44Khz 16bit Stereo concurrently from the microSD card (So if you can stand using mono, at 22Khz, I'm sure you'll manage 4 - but I haven't tested this), and you can load small short samples into sketches with WAV2Sketch, and you have 160kb of sketch memory to muck around with. Typically you'll probably want to use 8bit u-law for sketch samples to make the best of the sketch ram.


Theoretical limit of 8bit u-law mono files is up to 90 mixed in realtime, without effects, assuming they are played from sketch ram.





Go Up