This is post is basically a love letter to the Pulseaudio and Gnome Bluetooth developers.
I upgraded my laptop to Ubuntu Karmic recently, which brought with it the ability to use my Bluetooth A2DP headphones natively. Getting them running is now as simple as using the Bluetooth icon in the panel to pair the laptop with the headphones, and then selecting them in the Sound Preferences applet, on the Output tab.
As soon as the headphones are connected, they show up as a new audio device. Selecting it instantly (and seamlessly) migrates my sounds and music from the laptop sound device onto the headphones. The Play/Pause, Next Track and Previous Track buttons all generate media key keypresses – so Rhythmbox and Totem behave like they’re supposed to. It’s lovely.
If that we’re all, it would already be pretty sweet in my opinion, but wait – there’s more!
A few days after starting to use my bluetooth headphones, my wife and I took a trip to Barcelona (from Dublin, where we live for the next few weeks… more on that later). When we got to the airport, the first thing we learned was that our flight had been delayed by 3 hours. Since I occasionally hack on multimedia related things, I typically have a few DVDs
with me for testing. In this case, I had Vicky Christina Barcelona on hand, and we hadn’t watched it yet – a perfect choice for 2 people on their way to Barcelona.
Problem! There are four sets of ears wanting to listen to the DVD, and only 2 audio channels produced. I could choose to send the sound to either the in built sound device, and listen on the earbuds my wife had, or I could send it to my bluetooth headphones, but not both.
Pulseaudio to the rescue! With a bit of command-line fu (no GUI for this, but that’s totally do-able), I created a virtual audio device, using Pulseaudio’s “combine” module. Like the name suggests, it combines multiple other audio devices into a single one. It can do more complex combinations (such as sending some channels hither and others thither), but I just needed a straight mirroring of the devices. In a terminal, I ran:
pactl load-module module-combine sink_name=shared_play adjust_time=3 slaves=”alsa_output.pci-0000_00_1b.0.analog-stereo,bluez_sink.00_15_0F_72_70_E1″
Hey presto! Now there’s a third audio device available in the Sound Preferences to send the sound to, and it comes out both the wired ear buds and my bluetooth headphones (with a very slight sync offset, but close enough for my purposes).
Also, for those interested – the names of the 2 audio devices in my pactl command line came from the output of ‘pactl list’.
This kind of seamless migration of running audio streams really isn’t possible to do without something like Pulseaudio that can manage stream routing on the fly. I’m well aware that Pulseaudio integration into the distributions has been a bumpy ride for lots of people, but I think the end goal justifies the painful process of fixing all the sound drivers. I hope you do too!
edit
Lennart points out that the extra paprefs application has a “Add virtual output device for simultaneous output on all local sound cards” check-box that does the same thing as loading the combine module manual, but also handles hot-plugging of devices as they appear and disappear.
Happy you like it.
However, it’s even nicer than what you describe: simply install paprefs and check the checkbox that is called “Add virtual output device for simultaneous output on all local sound cards” and you are done. Not fiddling on the command line. Just a check box. This will combine all local hw sound cards (which includes BT and ALSA), even with hotplug and unplug.
(In their infinite wisdowm I think the Ubuntuans decided to stick with PA utilities versions that are some 7 releases back or so, for some reason I don’t understand. Not sure if that archaic version of paprefs they ship already has the checkbox, but I’d assume it has.)
There *is* a GUI for combining all your devices into one. Just install paprefs. Then run it and, in the Simultaneous Output tab, make sure to check
[X] “Add virtual output device for simultaneous output on all local devices”.
To disable the regular speakers (and only output to the two headphones) I assume you can just mute them normally.
Nice trick… although I imagine designing a good UI for this kind of thing could be quite the challenge.
You just happened to run “pactl load-module module-combine sink_name=shared_play adjust_time=3 slaves=â€alsa_output.pci-0000_00_1b.0.analog-stereo,bluez_sink.00_15_0F_72_70_E1″ in a terminal?
Where would anyone even begin to find the command options, let alone the sepcific numeric values?
I have recently decided that being able to fling audio from my laptop through pulse on my HTPC and use its considerably larger speakers to annoy the neighbours is my new favourite thing ever.
Cool! I have to ask, though – what about the other two sets of ears? Were they left without anything to listen to?
@Nick Johnson: The other 2 sets of ears are spares. We carry them around in our pockets in case the primary sets need replacing 🙂
Well, you did say they wanted to listen. 😉
PA is great until it suddenly forgets that you want to use your USB headset and randomly makes apps use the onboard sound card.
Or sound in a game will randomly stutter, stutter, and die completely.
But hey I hear that’s all Ubuntu’s fault – so much, that PA doesn’t even have a usable bugtracker of their own.
”
But hey I hear that’s all Ubuntu’s fault – so much, that PA doesn’t even have a usable bugtracker of their own.”
What a huge lie. Ubuntu patches PA very horribly. They have to deal with that on their own.
PulseAudio works fine and the bug tracker for that is at pulse audio website.
With benefits with this, perhaps I will someday be able to forgive PA (or Ubuntu) for how horribly difficult it is to get S/PDIF output to work (by purging PA from the system).
“I’m well aware that Pulseaudio integration into the distributions has been a bumpy ride for lots of people, but I think the end goal justifies the painful process of fixing all the sound drivers. ”
The end goal never justifies unneeded pain for casual users. Pulseaudio could and should be integrated at slower peace. (ie. testing it in real live only in distros beta releases, shipping in official release after few iterations.)
@Philip: Yeah, SP/DIF passthrough of encoded streams seems to be still a large blind spot in PA’s world view. Any comment, Lennart?
@Anonymous from Poland: I disagree. That might be true for a commercial product, but in my opinion if “casual users” expect software for no money, they take the good with the bad. Join the collaborative effort to improve things and consider the QA pain the price of admission.
It would certainly be nice if pulse audio knew about actual latencies and made the sound stream match the video stream and other sound streams.
@Russ: Using either audio device individually works fine. The not-quite-perfect synch problem comes from the combine module.