Streaming multiple WAV files from an sd card

  audio, c++, raspberry-pi, sdl

I have a raspberry pi-like SBC with very little memory. I am writing an application that plays up to 8 long (10+ min) wav files on loop and mixes the volume / panning of each based on gpio input.

I started out using python and quickly realised that all the prebuilt libraries I could find load the entire audio sample into memory (i.e. pygame using SDL), which is not going to be possible with the clip lengths I want to support and the fairly limited ram available.

I had thought it might be possible in c++ to set up a ring buffer of a sensible size for each clip, continuously reading each file into the buffers and having the mixer consume them but I’m not sure if this is the best option. It seems like SD card i/o should be able to handle this easily with 8x stereo 16bit wavs at 44k coming to about 1.5MB/s and I should be able to store a decent amount in memory, though I can’t find any examples of it being done this way.

Is this a decent idea? What other considerations could I be missing? Is there a more sensible option considering that latency is not a major concern?

Source: Windows Questions C++

LEAVE A COMMENT