Playing compressed audio contains can be quiete complicated and needs some process power. So I’m going to start to play .WAV, .AIFF and raw PCM data.
The first step will be to read a container format and decode the contained audio stream. There are multiple libraries which can do the job for us. For now we’ll use libsndfile because it’s simple and supports common FOS audio containers.
For cross-platform playback I’m using libao, which supports alsa and has direct access to the pulseaudio server on linux.
Start by reading a audio container. In this example a .WAV file.A
Then we can decode our complete audio container to a raw pcm format by allocating the needed memory and start the decoding.
The size of the buffer has to be channels * samples * sizeof(short) as we’re reading shorts.