I have an application which makes two uses of playing two files at the same time. The first is where it plays a white-noise file very quietly and continuously so that the sound-card does not go to sleep and therefore not 'pop' as the card switches on and off between songs. Secondly the application allows a user to start a new song and this causes the old song to fade out and hence for a short time, both songs play.

I have been using HiFiBerry DAC+ cards successfully for these two cases without issue on old Pi 2 and 3 boards but I would now like to make use of Bluetooth connected speakers and a Pi4. I have bluetooth working on buster and i can play a single instance of mplayer but a second instance is blocked because the device is in use. I presume I need something like 'dmix' and pulseaudio but I do not know where to start as some sites state that bluetooth and pulseaudio do not work well together and other sites that say its fine but I have not found anything that shows how to share the bluetooth connection (mixing the songs together).


Answered my own question with help from this link from Mark Hills

Once you have bluealsa working and can connect devices and play, then these additional steps open up dmix capability and allow audio mixing.

Install loop module once only.

modprobe snd-aloop

Edit /etc/asound.conf for each bluetooth connection - i.e. if you change device, update this file.

defaults.bluealsa {
    interface "hci0"            # host Bluetooth adapter
    device "${REQUESTED_BT}"   # ${REQUESTED_BT_NAME}
    profile "a2dp"

pcm.hubcap {
    type plug
    slave {
        pcm "hw:Loopback,1,0"
        rate 48000
        format S32_LE

pcm.!default {
    type plug
    slave.pcm {
        type dmix
        ipc_key 2867
        slave {
            pcm "hw:Loopback,0,0"
            rate 48000
            format S32_LE
            channels 2
            period_size 1024
            buffer_size 8192

To link this to the bluetooth speaker connect using bluetoothctl as normal and then start alsaloop as a background daemon

alsaloop -C hubcap -P bluealsa -t 1000000 -S 5 -f S32_LE  -d

This adds one second latency delay but my project was music only and one second does not seem unworkable.
Note that alsaloop will exit if the bluetooth connection is broken so when switching devices you need to re-start the loopback.

Now multiple music players such as mplayer can play through ALSA at the same time and get mixed together.

mplayer -ao alsa filename

The volume control is then

amixer -D bluealsa -M set 'NAME' 90%

where NAME is the name you see in

amixer -D bluealsa

For example, for me, the first line of the response looks like this:

Simple mixer control 'Logitech BT Adapter - A2DP',0

therefore the volume can be adjusted to 90% as an example using:

amixer -D bluealsa -M set 'Logitech BT Adapter - A2DP' 90%
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year.
    – Ingo
    Aug 2 '20 at 9:33
  • The answer was added days ago now but I still cannot see the ticks so I cannot accept it. Aug 4 '20 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.