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
[Unit]
Description=A2DP Playback
After=modep-mod-host.service
Requires=modep-mod-host.service
[Service]
Environment=JACK_PROMISCUOUS_SERVER=jack
ExecStartPre=/bin/sleep 3
ExecStart=/usr/bin/bluealsa-aplay -d jackplug 00:00:00:00:00:00 --pcm-buffer-time=960000
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=A2DP-Playback
User=patch
[Install]
WantedBy=multi-user.target
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.