Go Down

Topic: Play multiple audio files? Polyphony? (Read 5810 times) previous topic - next topic

TobiasRipper

Sep 22, 2016, 05:28 am Last Edit: Sep 22, 2016, 06:02 am by TobiasRipper
There's a project that needs to have more than one audio file to play at the same time > music and sound effects triggered by an arduino. I've been looking at this:

Mini MP3 Player Module

It only plays a single audio file at a time though (monophonic) and to get poly, I'd need to make an analog mixer circuit and have several of these run at once.

Are the any polyphonic (multiple simultanious voices) solutions out there?
Habeeb!!! Clean up on aisle four!!!

Grumpy_Mike

Quote
Are the any polyphonic (multiple simultanious voices) solutions out there?
Never seen one.
There is a library that will do more than one audio file but the quality is low.

TobiasRipper

Never seen one.
There is a library that will do more than one audio file but the quality is low.
Ah I see. That's unfortunate. There is indeed also the limit of only having one file open at once if a barebone arduino is used to produce the sound.
Habeeb!!! Clean up on aisle four!!!

Grumpy_Mike

Quote
here is indeed also the limit of only having one file open at once
That is true. This is the link I was talking about:-
https://github.com/TMRh20/TMRpcm
This gets over that by reading sections of a file into buffers and playing from the buffers.

TobiasRipper

I guess I might have to go with multiple audio modules then. I wonder if there is a way to wire 2 or 3 of the player modules to read from the same card as long as they are not reading the same file?
Habeeb!!! Clean up on aisle four!!!

Grumpy_Mike

Sorry but no. The one file only is a restriction of the SD card technology, nothing else.

TobiasRipper

Do you by any chance know if an Attiny has enough memory to play audio from a buffer?
Habeeb!!! Clean up on aisle four!!!

CrossRoads

Ha ha,
Attiny2313: 128 Bytes Internal SRAM
Attiny 24/44/84: 128/256/512 Bytes of Internal SRAM
Attiny 25/45/85: 128/256/512 Bytes Internal SRAM

Atmega328P: 2Kbytes SRAM
Atmega2560: 8K bytes SRAM
Atmega1284P: 16 Kbytes SRAM

8-bit audio, 5K max frequency playback for 1 second: needs 10 Kbyte SRAM
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.

CrossRoads

#8
Sep 26, 2016, 04:57 am Last Edit: Sep 26, 2016, 04:57 am by CrossRoads
You can have one Arduino command several MP3 modules via serial commands and have each module playback a different file from its SD card:

http://www.mdfly.com/search.php?search_query=mp3
Mix the outputs into an analog mixer, can be as simple as having outputs combined thru 10K resistors into a Computer speaker, see this schematic:

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.

pjrc

#9
Sep 26, 2016, 12:14 pm Last Edit: Sep 26, 2016, 12:39 pm by Paul Stoffregen
Sorry but no. The one file only is a restriction of the SD card technology, nothing else.
Oh Mike, you should know better than this.

With a more powerful board and more sophisticated library design, of course 2 or more files can be played simultaneously from a SD card.  My audio library for Teensy does it easily, with two stereo files at 44.1 kHz sample rate.  Here's video evidence, if you or anyone else is skeptical (start viewing at 9:06, if this link doesn't automatically begin 9 minutes into the video).

https://youtu.be/wqt55OAabVs?t=9m6s

The restriction isn't SD card technology at all.  It's the limited performance of 8 bit AVR and its lack of sophisticated peripherals & DMA, with well designed libraries to efficiently stream with those peripherals.

When your processor is just barely fast enough to read one audio file and it consumes nearly 100% of its CPU time (and most of its RAM) doing so, without any way to efficiently process and output that data other than tightly synchronized to output the samples as they're read, then of course you can't play more files simultaneously.  But that's not the SD card technology holding you back.  It might seem that way if you only ever work with such very limited microcontrollers and fixed-function modules which support 1 file at a time (or the simplistic example code Arduino publishes for Due & Zero), but in fact that very capable SD card is just sitting there responding to the very slow read speed and limited software of regular AVR-based Arduino.

So much more is actually possible with SD cards, and audio in general, when using more capable hardware.


TobiasRipper

#10
Oct 27, 2016, 12:06 am Last Edit: Oct 27, 2016, 12:11 am by TobiasRipper
You can have one Arduino command several MP3 modules via serial commands and have each module playback a different file from its SD card:

http://www.mdfly.com/search.php?search_query=mp3
Mix the outputs into an analog mixer, can be as simple as having outputs combined thru 10K resistors into a Computer speaker, see this schematic:


Heck I didn't get the notifications and the moment I thought the discussion was over, I get the two most useful answers.

Yeah using two modules was my only way out but the analog mixer with resistors would effectively half the volume so now I'd need to implement an amplifier to boost the signals back up.

The second answer certainly looks much more advanced but it seems to yield the result I'm after. I'm only in need of 2, max 3 voices if possible.

Also I am working with the atmega chip directly with an arduino boot-loader which may or may not be something I have to seriously take into account with the second answer. The workshop one. It looks like some custom teensy board with a built in audio solution and card reader. I'd have to figure out how to implement a stereo system myself which is why that mp3 module looked so good, everything is already on it, just send the commands of which track to play.
Habeeb!!! Clean up on aisle four!!!

pjrc

#11
Oct 27, 2016, 03:14 am Last Edit: Oct 27, 2016, 03:15 am by Paul Stoffregen
That workshop hardware is just a Teensy 3.2 with this audio shield on top.  If you're ok with 12 bit DAC quality (which is certainly much better than PWM, but not as good as 16 bit quality from that shield), you can just use the DAC pin instead of the shield.  In the design tool, you just remove the I2S object and put the DAC one in its place.

TobiasRipper

#12
Oct 27, 2016, 04:33 pm Last Edit: Oct 27, 2016, 04:53 pm by TobiasRipper
It appears that the teensy audio shield runs on a SGTL5000 code chip. http://cdn.sparkfun.com/datasheets/Dev/Teensy/SGTL5000.pdf

The polyphonic stereo audio is pretty much key but audio is only a part of what is going on in this project. The library demonstrates polyphonic playback so perhaps I can attempt to use an atmega328 standalone processor with this chip.

The teensy with the shield may take up a bit too much space considering that this is meant to e a handheld device and I still have to fit a dot matrix display and a mini qwerty keyboard onto one single device. 3D printing the enclosure n all.

What I find intriguing is that the teensy shield only has only one chip on board - the SGTL5000 chip. Which begs the question of hos exactly the teensy is reading the sd card. So either the teensy has and onboard solution for sd card reding or the SGTL5000 does.

Habeeb!!! Clean up on aisle four!!!

Grumpy_Mike

Quote
Which begs the question of hos exactly the teensy is reading the sd card. So either the teensy has and onboard solution for sd card reding or the SGTL5000 does.
Look at the schematic. Any processor has the capability of reading an SD card, it is simply an SPI protocol. The SGTL5000 has no connection to the SD card.

TobiasRipper

Look at the schematic. Any processor has the capability of reading an SD card, it is simply an SPI protocol. The SGTL5000 has no connection to the SD card.
It's one of those things that I wouldn't be able to distinguish even if it was right in front of me, simply since my level of understanding these things is not at the level yet.
Habeeb!!! Clean up on aisle four!!!

Go Up