Mix bluetooth audio with local audio

Hi community,
I am trying to mix audio coming from a bluetooth device with local audio as shown below.

To play the audio coming from the bluetooth device on the speakers I am using alsaloop configured like this

alsaloop -C bluealsa:DEV=<BT-addr_device>,PROFILE=a2dp -P plughw:0,0 -r 48000 -c 2 -f s32_le --sync=simple -t 200000 -T 1

This works correctly as long as no audio is being played locally. That is, if you are playing audio that was launched with aplay when you try to play bluetooth audio the system gives an error:

playback plughw:0,0 open error: Device or resource busy

I have been looking for solutions on the internet and there is everything. Apparently a solution could be to create a virtual card that has two sources and a destination to act as a mixer and the output is redirected to the physical audio card (plughw:0,0). Some say that with PulseAudio this is very easy to do and with ALSA it is very complicated.

Here are my questions in case you can help me:

Is the best approach to this problem to create a virtual audio card?
With which tool should it be created?
Can PulseAudio and Bluealsa coexist in the same system?

I am using the minimum reference image BSP 6.3.0 on the Verdin iMX8MM.

Regards,
Julián

Hi @jbruno ,

Unfortunately we have limited knowledge on this topic, given that the questions are specific to ALSA and Audio Mixing in Linux as a whole.

From what I can tell your suggestions seem like good starting points. If you plan on using PulseAudio you will probably need to build a custom version of our BSP reference images that includes it, so I’d first check the virtual card alternative.

Best regards,
Lucas Akira

Hi @lucas_a.tx ,
Looking through the ALSA documentation I found that there is a mixer that allows to solve my case in the following way:

alsaloop -C bluealsa:DEV=<BT-addr_device>,PROFILE=a2dp -P plug:dmix -r 48000 -c 2 -f s32_le --sync=simple -t 200000 -T 1

aplay -D plug:dmix Gong.wav

It works for me at least!
Regards,
Julián

Glad you were able to solve it!

Thank you for sharing your solution.

Best regards,
Lucas Akira