[GUIDE] Enable Bluetooth Audio Playback (a2dp) on Patchbox OS 2022-05-17

I upgraded recently to latest Patchbox OS 2022-05-17. And I was able to set up Bluetooth audio playback according to my needs.

  • I have a RPi 3B. The onboard Bluetooth is known to have issues with audio, so I use a generic Bluetooth USB dongle.
  • I want to play an instrument (guitar, electric bass, etc) through the phone IN and OUT ports.
  • I want to play music on my cellphone over Bluetooth and to the same phone OUT port.
  • This would allow me to practice at home and use headphones or a small 2.1 speaker set as output.

Things are much easier since previous versions.
Pulseaudio handles most of the job. But as it runs at user level, thus it depends on user patch to be logged in for it to work properly.

Step 1: Connect to Bluetooth

  • ssh into patchbox to get the patch user logged in. ssh patch@ or 192.168.x.x
  • run the command bluetoothctl
  • list command will list your Bluetooth controllers. One for the internal Bluetooth and another for the USB dongle. Unplug and plug the dongle to identify which MAC address belongs to it.
  • select xx:xx:xx:xx:xx:xx to choose the USB dongle as the default controller.
  • discoverable on to broadcast the device. at this point you should be able to pair your phone. If you have issues at this point, try running pairable on and you may be prompted for a passcode.
  • help to show more commands, exit to quit bluetoothctl interface

After phone has paired, it’s safe to unpair and pair freely from your phone without any other interactions, as long as the user patch has an active session running (it would stop working after ending the SSH session).
Now you would also be able to play music from your phone. It will come out of the 3.5mm audio jack port.

Step 2: Keep a patch session running

run the command sudo raspi-config and select these options:
1. System Options
S5. Boot / Auto Login
B2. Console Autologin

After a system reboot we would always have a terminal session opened as patch user.
This makes pulseaudio always ready for us to connect our bluetooth phone.
Playback still goes out of the 3.5mm stereo jack. This should be desirable if you want separate outputs for phone playback and pedalboard loop.

Step 3: Send the bluetooth audio output to Jack out

To have all audio outputs (bluetooth, pedalboard and any other!) out of the phone OUT jack, the following 2 commands are needed:

  • pactl load-module module-jack-sink
  • pactl set-default-sink jack-out

This creates a new pulseaudio sink for Jack OUT and sets it as default. pactl list short sinks will list all the available sinks in case you want to switch back.

This module-jack-sink is being loaded just for the ongoing user session. To automate this on every system boot, create this file:

nano ~/.config/systemd/user/a2dp-playback.service

And add this text into it:

Description=A2DP Playback
After=sound.target pulseaudio.service

ExecStart=/usr/bin/pactl load-module module-jack-sink
ExecStart=/usr/bin/pactl set-default-sink jack_out


Save the changes ( Ctrl+X, Y, Enter).
Now run these 2 commands to get it set up

sudo systemctl daemon-reload
sudo systemctl enable a2dp-playback.service

That’s all folks. Now we can just turn our RPi on, plug our instrument and speakers/headphones in, pair our phones and enjoy without any other interruptions.

@velvettear this may be of your interest.