Zynthian as a bluetooth speaker

Hi fellow Zynthians!

Just wanted to share my little addition with everyone. I use my zynthian box as a pedal board in a band. I sometime need to play some songs from my phone and share it with others. Phone speakers are not so great and I thought I would try to use the bluetooth capability. I now have a working solution that streams from the phone to the zynthian box, capture with alsa_in, and then route through jack to the audio out interface. It is completely not integrated with the Zynthian interface. If there is interest, I can share the instructions (nothing challenging except for compiling a more recent version of BlueALSA), and help work on an integration.

Cheers!

4 Likes

Here are the instructions, from a fresh Zynhtian install.

apt-get install libbluetooth-dev
apt-get install libsbc-dev

git clone https://github.com/Arkq/bluez-alsa.git
cd blue-alsa
autoreconf --configure
mkdir build
cd build
../configure --enable-systemd
make
make install

sudo systemctl daemon-reload
sudo systemctl enable bluealsa.service

Then check that the bluetooth and bluealsa services are running.

systemctl status bluetooth
systemctl status bluelsa

Pair your phone/computer to the zynthian with bluetoothctl

bluetoothctl
power on
agent on
default-agent
scan on

Note the device address when you see your device name [NEW] Device xx:xx

pair xx:xx
trust xx:xx
connect xx:xx
exit

You should now be able to connect/disconnect to the zynthian.
When you are connected, start playing some music from your phone/computer.

Inject the bluetooth stream into jack with:

alsa_in -d bluealsa -p 8192 > /dev/null &

or with

zita-a2j -d bluealsa -p 8192 > /dev/null &

Then use patchage to route the signals where you want.
Or you can do that on the command line with

jack_connect alsa_in:capture_1 system:playback_1
jack_connect alsa_in:capture_2 system:playback_1

or with

jack_connect zita-a2j:capture_1 system:playback_1
jack_connect zita-a2j:capture_2 system:playback_1

The problem I have now, is that alsa_in or zita-a2j break when the bluetooth link disconnects. I need to find a way to start/stop on connection/disconnection events. Seems like bluealsa supports DBus. Also, volume control from the source does not work.

@jofemodo I finally have a working setup that would be completely based on systemd services. I would add a Bluetooth option in the Admin menu to turn on/off the feature, which would start and stop the relevant services. I would like to provide a branch to zynthian-ui and zynthian-sys. I would however need some pointers on how to complete the integration. Would you rather see me ask questions on github or continue here?

I would be interested in testing this out for you, or for the team if they are considering pulling it in. I have been planning to put a few of my spare Pis out as “radios”, and if I’m also filling the house with synthesizers that I could plug a controller into and jam along, so much the better. :>

Hi @jtode . I’ve just started pushing my work to GitHub - jwoillez/zynthian-sys: System configuration scripts & files for Zynthian. and GitHub - jwoillez/zynthian-sys: System configuration scripts & files for Zynthian.. Look for the bluetooth-sink branch there. Testing in progress. I will send a message here after going through an on-going round of tests starting with a fresh zynthian image.

Ready to test! Here are the instructions.

  1. Install the new software.
ssh root@zynthian.local
cd /zynthian
mv zynthian-sys zynthian-sys.upstream
mv zynthian-ui zynthian-ui.upstream
git clone  -b bluetooth-sink https://github.com/jwoillez/zynthian-sys.git
git clone -b bluetooth-sink https://github.com/jwoillez/zynthian-ui.git
cd zynthian-sys/scripts/recipes
install_bluealsa.sh
cd ..
update_zynthian.sh
  1. Reboot
  2. Turn Bluetooth on from the Admin menu
  3. Pair your device to the zynthian, using bluetoothctl (scan, pair XX:XX , trust XX:XX, exit)
  4. Connect your device.
  5. Play some music.

Warning: lower the volume of your output speakers, just in case. I’ve had cases where the volume was way too high.

2 Likes

This looks very good and funny.
I will give it a try next week.

Hi @jwoillez !

Nice hack! Congratulations! I will test it when i have some minutes.

For getting this into the mainstream zynthian, it should be added to the “audio input devices”, so you can choose it from the chain options menu. This implies zynautoconnect is aware of it too.

Anyway, let me test it first …

Also … do you think we could also send audio from zynthian to a bluetooth speaker? It could be interesting too.

Regards,

3 Likes

Thanks!! At the moment, the integration is in the admin menu, near the wifi entries. My use case was just to send sound through the amp connected to the output of the Zynthian. And the admin menu was fitting the bill. But I can see how being able to mix this input with effects could be interesting as well.

You will however notice that there is a significant latency in the connection. For example, I cannot use it for watching a video, as the sounds and image are significantly out of sync. Would be the same if e.g. following along to some online scores (sound delayed wrt current marker). Lowering the buffer length of the zita-a2j bridge seemed to cause dropouts.

Output to bluetooth speaker should be easy to implement as well. I am just a bit more worried about the latency issue for that use case. If the box is used as a synth, the latency seems like a show stopper. But it is worth experimenting; and I have all I need at home for that.

On a personnel note, I’d be curious to see how the current implementation works with android phones. I had trouble with my iPhone until I added the AAC codec.

1 Like

@jofemodo May I propose a pull request with what I have implemented so far?

Of course, please, but it could take some time to review and merge the PR. Currently we are focused in refactoring some deep layers of zynthian core & UI, allowing to remove some of the constrains we currently have. It takes almost all our time.

Having the possibility of sending audio to Zynthian by bluetooth, from a computer, smartphone or any player device is a good thing. From the zynthian POV it’s a new audio input source that must be available in the audio capture menu. It must be fully integrated in the autoconnect scheme too. Completing the integration would take some time, so the PR could take some time to be merged.

Best Regards

1 Like

Ok, understood. I think I understand how to integrate bluetooth as a new audio input source (currently bt:capure). With respect to autoconnect, do you expect the same behaviour as the exiting system:capture? For example, one would need to to create an Audio chain to connect bt:capture to the ZynMixer. Would that be enough, or should the bluetooth audio path be treated differently?

@jofemodo I just submitted the pull requests. bt:capture is now available in audio input sources (when the bluetooth admin option is activated), and auto connection works.

Bluetooth pairing is not managed, but I’ve started looking into how to handle bluetooth pairing from python to later integrate in the UI and/or Webconf.

3 Likes

Hello @jwoillez, this sounds really interesting, i’d like to pair my Ipad playing some music to Zynthian,
I’m new to Zynthian so my questions are really basic…
Do you know if your request it integrated in the stable branch ? and if so, i don’t find where to activate bluetooth in Zynthian ?

Cheers

1 Like