Mike Swierenga

Playing the Blues by the Skin of your Teeth

The Problem

While working on projects around our house, my wife Emily and I listen to music using our esteemed Bluetooth speaker. Often times, though, our quest takes us into different rooms of the house, as I emphasize to Emily the importance of parallelization for optimizing workloads. Two eye-rolls later, and at least one of us is unable to hear the music well from our new position. We need to connect another speaker.

I’ve been reluctant to buy a lavish set of speakers that wirelessly network with each other to sync up. And I definitely don’t need more wires in my house. I figured it could be more fun to attempt to build something to achieve this through some Linux utilities on a Raspberry Pi. Basically, what I wanted was to connect my phone or computer to a Pi and let the Pi manage connections between multiple speakers, routing audio from the source (phone) to 1 or more Bluetooth sinks (speakers).

A Possible Solution

Luckily for me, as I began my research searching for an existing solution or project, I came across a repository on GitHub called bluecast that was a work-in-progress attempt at exactly what I wanted. That never happens! (it actually happens all the time, which is quite handy).

The bluecast project README goes through the steps to get everything setup, but the main components are:

  • you need 3 total Bluetooth adapters (for me: 1 internal, 2 USB)
  • ensure BlueZ is installed and enabled for the Pi (or whatever Linux machine you want to try this on)
  • PulseAudio is the main utility that serves as the workhorse for routing audio between each of the devices

The steps after that seemed pretty straight-forward (checkout the bluecast README for the actual commands and config files):

  • Add users to the `pulse-access` group
  • Allow PulseAudio to interface with BlueZ through D-BUS
  • Adjust PulseAudio’s resample method
  • Configure the PulseAudio service, including loading module-bluetooth-discover
  • Scan for and connect to each of the bluetooth devices with bluetoothctl
  • Verify the phone is available as a source for PulseAudio
  • Verify the speakers are available as sinks for PulseAudio
  • Link the phone source to each of the speaker sinks

After getting everything in order and following the configuration steps from the README,  I was ready for the first test. I pressed play on my phone’s music app and immediately heard a loud screeching sound emanating from a nearby Bluetooth speaker. Something seemed off. I doubled-checked I wasn’t streaming one of my favourite Pink Floyd numbers, Several Species of Small Furry Animals Gathered Together in a Cave and Grooving with a Pict. Nope.

Deaf and defeated, I removed power from all offending devices and gathered my thoughts. I’ll have to revisit this another lab day.