[GUIDE] Patchbox OS with Jack Audio Output to Bluetooth

The following steps, coupled with a Raspberry Pi 4 and Patchbox OS, will produce a configuration where Jack audio plays back through bluetooth (e.g. speaker or headphones) instead of the headphone output or other audio device.

1. Install Patchbox OS version 112320 image (on Raspberry Pi 4)
2. SSH to Patchbox and complete Patchbox setup.
a. If ethernet/internet is available, accept prompt to update.
b. For audio device, use onboard sound (headphones) with settings: 44100, 512, 3.
c. Choose a module: “none: default patchbox OS envioronment”
d. Complete Patchbox setup.
3. Update repositories and raspberry pi files.
a. sudo apt update
b. sudo apt upgrade
4. Remove onboard audio conflict by editing /boot/config.txt.
sudo nano /boot/config.txt
a. Comment out onboard audio:
#dtparam=audio=on
5. Delay Jack until Bluetooth connected by editing Jack Service
a. Make copy of jack.service to /etc
sudo cp /lib/systemd/system/jack.service /etc/systemd/system/jack.service
b. Edit jack.service
sudo nano /etc/systemd/system/jack.service
c. Add line above ExecStart
ExecStartPre=/bin/sleep 15
15 worked for me - the number of seconds may depend on the reliable pairing time for your BT speaker/headphone.
d. Refresh services and restart jack
sudo systemctl daemon-reload
sudo systemctl restart jack
6. Update jack startup parameters to use bluetooth
a. Edit jackdrc
sudo nano /etc/jackdrc
b. Comment out (#) existing execution line for reference
c. Add new jack startup line, with destination bluealsa (bluetooth)
exec /usr/bin/jackd -r -d alsa -P bluealsa -n 3 -S -o 2 -X seq
7. Create /etc/asound.conf
a. Create file
sudo nano /etc/asound.conf
b. Add contents:
If you don’t know your Bluetooth Device address (bluealsa.device…XX:XX etc) yet, it’s ok to do step 8 first!

defaults.bluealsa.interface "hci0"
defaults.bluealsa.service "org.bluealsa"
defaults.bluealsa.device "XX:XX:XX:XX:XX:XX"
defaults.bluealsa.profile "a2dp"
defaults.bluealsa.delay 10000

pcm.!default {
	type asym
	playback.pcm {
		type plug
		slave.pcm "output"
	}
	capture.pcm {
		type plug
		slave.pcm "input"
	}
}

pcm.output {
	type bluealsa
	device "XX:XX:XX:XX:XX:XX"
	profile "a2dp"
}

ctl.!default {
	type bluealsa
}

8. Connect to your bluetooth audio playback device.
a. Turn on BT device and activate pairing before entering these commands.
bluetoothctl
power on
agent on
default-agent
scan on (Identify your bluetooth device address)
(Replace any XX in this guide with your bluetooth device address)
pair XX:XX:XX:XX:XX:XX
trust XX:XX:XX:XX:XX:XX
connect XX:XX:XX:XX:XX:XX
9. Ensure BT device connects at boot time:
a. Edit rc.local
sudo nano /etc/rc.local
i. Add, right before Exit 0 line:
echo “connect XX:XX:XX:XX:XX:XX \nquit” | bluetoothctl
10. Address SAP and Privacy errors.
a. Edit bluetooth service.
sudo nano /lib/systemd/system/bluetooth.service
Add --noplugin=sap to ExecStart:
ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=sap
b. Edit bthelper service.
sudo nano /lib/systemd/system/bthelper@.service
Replace contents with:

[Unit]
Description=Raspberry Pi bluetooth helper
Requires=bluetooth.service
After=bluetooth.service
[Service]
Type=simple
ExecStartPre=/bin/sleep 2
ExecStart=/usr/bin/bthelper %I

The ‘sleep 2’ is a delay to help with connection timing.
11. Reboot and Verify Jack Startup.
a. Check Jack Service
sudo systemctl status jack
b. A successful result includes Jack with a green active status, like:
JACK Success

Now Jack should be operational, with audio playing over bluetooth! For my setup, the next steps include installing the KXStudio repository, Carla, Helm, and ZynAddSubFx. I use Carla to connect incoming midi with LV2 instrument plugs and direct them to the outputs. If you try Carla with Jack as the engine, I recommend using the ‘Patchbay’ configuration to wire the correct MIDI, audio playback, and plug-ins, together. It works!

5 Likes

Thank you for the awesome guide! Just one question: does this only work with RP4 or also with older models?

I think it should work with any Pi model that has built-in Bluetooth (and even it could work with Bluetooth dongles in case built in one is absent), at least I can’t come up with reasons why it wouldn’t. :slight_smile:

Hello, thank you very much for your guide, it has been very useful!
This shouldn’t work with Modep right?
I am trying to set the output of modep to some headphones

Edit :

I managed to hear the modep audio in the headphones, I put a drum sequencer, it is heard without delay, the only problem is that there is no line input or it does not recognize it? I suspect that there must be some more procedure, I am occupying an interface uphoria umc 22

@ nwblnc The provided setup is for Jack audio output only, like working with non-live audio ‘in the box’ or triggered via MIDI. I have not used Modep. I would suggest seeing if your input device is detected and can be wired to the output in Patchable. For my configuration, instead of Patchable I use KXStudio Carla, with a Jack & Patchbay configuration for my MIDI-driven setup.

1 Like

What output do you get when running arecord -l and aplay -l when everything is hooked up to the Pi?

If this is via Bluetooth, there’s going to be a delay, it’s just not apparent when just using the drum sequencer, without any live processing of any other instrument.

Yes, imagine it, useful anyway, not for now, I will try the command you shared