I've been experimenting with playing two or more WAV files at once.
I got this to work by tweaking Kye's sd code to return an sd file's beginning data sector address when the file is opened. My code reads data via FAT routines to get the WAV parameters, but then reads data by raw sd sector to read the audio data. That way, several audio files can be opened, their parameters read and saved, then data reads can be done in interleaved file order.
It works, but after playing with it for awhile, I think it would be a cleaner approach if there were FAT library code that had the ability to open more than one file at a time, then use FAT routines to read data.
My code makes an array of file reader objects, where each object uses a cog to read and deliver data to the PWM player section. Again, it works, but since even in the P2 there are only 8 cogs, I think this is too limiting of an approach. Better to have one reader cog for all files, even though it would be more complicated than my simple array of buffers and reader cogs.
My code does have some nice features. It can play WAV files of any combination of mono or stereo, 8, 16, 24 or 32 bits, any data rate (as long as the overall data retrieval rate is less than about 280K bytes per second.)
For example, it can play a 1 channel 24 bit 48000 rate WAV together with a 1 channel 8 bit 8000 WAV with a combined rate of 152,000 bytes per second, but it can't cleanly play two 2 channel, 16 bit 44100 files because the sd retrieval can't keep up with the 352800 byte rate. They will play, but because of buffer underruns, it'll sound choppy as buffers wait to be updated.
As I was looking for sound effect WAV files to test, I kept seeing 24 bit WAV files, and out of curiosity for how they were implemented, I developed code to play them. In the process of doing that, it turned out to only need a few more lines to add the ability to play 32 bit WAVes, so I added them for completeness, although I don't know where 32 bit WAV files would ever be used.
The code generally works well, but for some reason, out of a dozen sample files, there are two WAV files that play great by themselves but when loaded to play together, one corrupts the other and I haven't figured out why.
I made an optional debug display to run as the files play to monitor the first sector buffer, showing remaining sectors to play and to show if there are buffer underruns. But it only currently monitors the first file being played. It could be enhanced to show the status of all files when multiple files are played, but I didn't get that far in development.
I know the FSRW sd code is faster than Kye's, but I used Kye's for two reasons. First, my version of FSRW fails to read more than about 80 files in a FAT folder, where Kye's code had no problem reading up to almost 1000. Second, when playing files on a 4-sd RAISD propeller board, it seemed that Kye's code was more reliable in switching between sd card sockets at runtime, where FSRW would often fail to remount sd cards.
I don't think I'll be doing any more on this particular project for awhile because my daughter gave me a propeller 2 for Christmas, and I've been busy getting started with that. But eventually, I think a second version of this would be a great P2 project.
In regard to the P2, I'd like to give a thanks to JonnyMac for his P2 tutorials and example code. I've watched the P2 development over the years but have never really followed it, and wouldn't have known where to start except for JonnyMac's getting started tutorial and for his clean, easily readable programming style.