Play multiple audio files? Polyphony?

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?

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.

Grumpy_Mike:
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.

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:-

This gets over that by reading sections of a file into buffers and playing from the buffers.

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?

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

Do you by any chance know if an Attiny has enough memory to play audio from a buffer?

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

You can have one Arduino command several MP3 modules via serial commands and have each module playback a different file from its SD card:

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:

Grumpy_Mike:
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).

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.

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:

MDFLY - Search Results for "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.

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.

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.

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.

Grumpy_Mike:
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.

Do you really need stereo? With the other PWM approaches, you get only mono, and rather low quality mono.

The STGL5000 has stereo DAC, stereo ADC, and a headphone amp. If you only need a mono DAC, it's kinda overkill.

Well actually the STGL5000 sounds perfect for the job for the following reasons.

The project at hand is a handheld game (but not a console or emulator for existing games - this one is for a my specific game). I'm a composer by primary trade, writing the score (soundtrack) for this game, which is in stereo. From the sound and music standpoint, stereo signal allows you to make up a more immersive experience depending on the sound mixing techniques.

Also, as a composer, the work I put into writing the detail and working on the mix of the music such as defining instruments in the stereo space would be lost if I would just play the sound in mono and with a lower resolution to that point.

So the stereo signal is the primary reason why I was excited to see that mp3 module I posted in the original post. It's plays stereo audio and at the common bitrate.

► the Wav trigger board 50€ is an high-fidelity polyphonic board
it can play and mix up to 14 stereo tracks simultaneously and independently, with very low latency.

or mp3 trigger

or Teensy 20$ + audio Adaptor Board 14$ PJRC Store

► I'm rather investigating using multiple DFPlayers with their own TF card via several Serial ports
https://fr.aliexpress.com/item/TF-Card-U-Disk-Mini-MP3-Player-Audio-Voice-Module-For-Arduino-DFPlay-Min-Board/32659645208.html 1€15

in addition with a audio mixer circuit like CrossRoads said in message #8
or more sophisticated circuits. Principle described here circuitlib.com how-to-build-an-audio-mixer LM833 op-amp

allaboutcircuits.com build-an-audio-mixer/ with LF347 op-amp + -12/+12V PSU

oscium.com how-build-audio-mixer with 1 Quad Operational Amplifier chip (LM324) + Microprocessor M68HC11E9BCFN2
5V PSU

electroschematics.com 3-channels-audio-mixer/ with LM3900 op-amp

But some circuits require +15V and -15V supply which is not easy to get... or the workaround of virtual ground.

Any circuit suggestion? :slight_smile: