New library for PWM playback from SD cards: SimpleSDAudio

Hi,
I also thought about extending the library to multi-playback, even on AVR based plattforms. On AVR, the interrupt itself creates big overhead due the many PUSH and POP stuff (I think ARM has a somewhat nicer architecture there), so doing things in interrupt is not the best way. On Arduino, if sample buffer is not changed, I works a little like a ping-pong buffer, because a whole sector of samples is read before the buffer is released for playback. If multi-playback of different sounds starts sector aligned, two different sectors can be read and added together in playback buffer and the buffer can be released as one block. This become more complex when not sector aligned.

For your approach I like your idea of buffering the sounds in different memory locations and maybe adding them in interrupt (maybe also scale the values for volume control). SD cards tend to be damn slow if sectors are not read in order, to overcome this your approach could lead to read n sectors from file 1 and then n sectors from file 2. With n being a number bigger than 1, you can trade more possible simultaneos channels at the cost of a bigger starting delay.

BTW: But decide and try yourself, getting the best compromise involved a huge efford of research even for that simple "SimpleSDLibrary" on AVRs. It was a long way to find out that simply using a high PWM rate even at low sampling rates is the most important factor on the way to get nicer audio output. On that way I also tried things like storing 1 bit delta-sigma-coded audio on a SD card and playing that back at high rates through SPI output. It worked good, but involved heavy conversion on PC side and adding sounds or even modifying the volume is not possible anymore. In the end I considered it not simple enough for Arduino world...