Lunar Mushrooms Lunar Mushrooms - 2 months ago 6x
Linux Question

ALSA Api: How to play two wave files simultaneously?

What is the required API configuration/call for playing two independent wavefiles overlapped ?
I tried to do so , I am getting resource busy error. Some pointers to solve the problem will be very helpful.

Following is the error message from

of the second wavefile

"Device or resource busy"


ALSA does not provide a mixer. If you need to play multiple audio streams at the same time, you need to mix them together on your own.

The easiest way this can be accomplished is by decoding the WAV files to float samples, add them, and clip them when converting them back to integer samples.

Alternatively, you can try to open the default audio device (and not a hardware device like "hw:0") multiple times, once for each stream you wish to play, and hope that the dmix ALSA plugin is loaded and will provide the mixing functionality.