[Guide] Enable Bluetooth Audio Playback (a2dp)

I’m playing audio over Bluetooth from my phone into Patchbox OS / Modep, and listening with regular headphones or some small 2.1 speakers.
This is great for playing instruments (bass in my case) on top of a track, as the resulting output is combined Modep + song track.

I’m using a RPi 3b with an external Bluetooth dongle, as the internal one is not good enough.

Warning: Consider this experimental as my RPi sometimes freezes. I will have to try with a better quality microsd card (it’s a sandisk Ultra 32gb for now, I may try with an Extreme soon).

I probalbly had to install some software packages such as bluealsa-aplay but can’t remember them all. I hope to update with complete list after trying a new microsd card.

First thing to do is routing the audio in the .asoundrc file. Without any changes, the bluetooth audio is routed to the 3.5mm jack output, while the instrument output is coming out of the 1/4 inch jack output. I want both signals on the later.

ssh into your patchbox and then run:

nano ~/.asoundrc

pcm.jackplug {
        type plug
        slave { pcm "jack" }

pcm.jack {
        type jack
        playback_ports {
                0 system:playback_1
                1 system:playback_2

pcm.!default {
        type hw
        card 0

ctl.!default {
        type hw
        card 0

This creates a virtual port named jackplug that can be utilized by other programs.

At this point you could try if works by using the command:
/usr/bin/bluealsa-aplay -d jackplug 00:00:00:00:00:00 --pcm-buffer-time=960000

Stop this command by pressing Ctrl+C.

Try with different values for buffer time, which is expressed in microseconds. For my dongle that was the shortest useable time (0.96 seconds of buffer or signal delay).

Now if the previous command worked as desired, we want a way to make it run always on start.
I created a systemd service for this. I run the service as root, but I tell the service to authenticate as my user patch. Maybe there is a cleaner way to do this.

sudo nano /lib/systemd/a2dp-playback.service

Description=A2DP Playback

ExecStartPre=/bin/sleep 3
ExecStart=/usr/bin/bluealsa-aplay -d jackplug 00:00:00:00:00:00 --pcm-buffer-time=960000


You can see the User=patch and the good command that does the magic at ExecStart.

now run these two commands to reindex the systemd services and enable this new one:

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

If service hasn’t started yet, you can run
sudo systemctl enable a2dp-playback.service

And that should be all.


Hi there,

thanks for the guide - this is exactly what i also wanted to setup.
Sadly linux audio (especially jack) is to me like black magic.

I tried setting up the virtual port to no avail. I created ~/.asoundrc as user ‘patch’, /root/.asoundrc and /etc/asound.conf (always pasted your config), but aplay -l never listed the port “jackplug”.
I tried testing the port (even if it isn’t listed) with speaker-test -D jackplug but only got an error: Playback open error: -6,No such device or address

Any chance you could help me get this running?

Thanks in advance :slight_smile:

Seems like i’m missing some libs (i think it’s “alsa-plugins”)… :thinking:

root@pisound > /root# speaker-test -c 2 -D jackplug

speaker-test 1.1.8

Playback device is jackplug
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
ALSA lib dlmisc.c:287:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/arm-linux-gnueabihf/alsa-lib/libasound_module_pcm_jack.so ((null): /usr/lib/arm-linux-gnueabihf/alsa-> lib/libasound_module_pcm_jack.so: cannot open shared object file: No such file or directory)
Playback open error: -6,No such device or address

Sadly there’s no “alsa-plugins” package in raspbians repository. Will try to compile it myself.

Hi @velvettear,

I took a quick look into my rpi and it doesn’t look like I installed additional software.
Most likely it needs a system restart after creating the .asoundrc file.

I’ve done this long time ago, so there’s a chance that I missed a step. I’ll try to start from scratch in about a week or two.

That speaker-test tool worked good for me.
I had the asound set as root initially, but later figured out that it also works at user level. Both should work.

Good luck with it, I’ll update later.