Friday, July 19, 2013

Play audio output to multiple devices via pulse audio, or more pulse audio woes.

I've since moved past Ubuntu 12.04 to 13.04 and have run into more troubles with pulseaudio. This is unrelated to my previous issues.

Admittedly this is a fairly fringe case that most people would not run into but that seems to be my experience with Linux in general. Usually a quick google search fixes me up, but this one was a bit trickier.

I have a media center setup with xbmc on a full desktop install of Ubuntu 13.04. It works great, I use the desktop for various things that xbmc has yet to integrate with  or doesn't yet have a great experience with. (e.g. Google Play Music, songza, youtube), and use xbmc to play my movie and TV content.

From my media center to my PC since I'm often playing high quality content I tend to prefer using HDMI to connect the two. It is easy and provides a very high level of quality. Unfortunately for me (and apparently for most modern receivers) my receiver will only output analog audio to my speakers on my patio (Zone 2) and HDMI is a digital signal. And thanks to the copyright issues with converting a digital HDMI signal (hard to copy) to an analog signal (easy to copy) the capability to convert to analog is stripped out of the HDMI connections.

So what this means practically is I have to connect an analog cable from my media center to my receiver as well as the digital HDMI connection. This gives me the best of both worlds, the reciever basically selects the highest quality signal that it can deliver. The trick is that I have to broadcast the signal to more than one device, which is not something pulse audio is setup to do out of the box in Ubuntu 13.04.

What is the fix? I did some googling and found a suggestion to use the paprefs package to control the Pulse Audio Preferences. Unfortunately for me this didn't work, despite an indication that it should from the information in paprefs. Essentially you enable simultaneous output and pulse audio is supposed to broadcast the signal to all your output devices. It never output to my analog out.

Back to google and I found this info: https://wiki.archlinux.org/index.php/PulseAudio/Examples#Simultaneous_HDMI_and_Analog_Output

Relevant sections copy/pasted below.
<snip>

Simultaneous HDMI and Analog Output

PulseAudio allows for simultaneous output to multiple sources. In this example, some applications are configured to use HDMI while others are configured to use analog. Multiple applications are able to receive audio at the same time.
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: ALC889A Analog [ALC889A Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 1: ALC889A Digital [ALC889A Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 3: HDMI 0 [HDMI 0]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
The key to a configuration like this is to understand that whatever is selected in pavucontrol under Configuration>Internal AUdio is the default device. Load pavucontrol>Configuration and select HDMI as the profile.
Add the following to /etc/pulse/default.pa to setup the analog as a secondary source:
### Load analog device
load-module module-alsa-sink device=hw:0,0
load-module module-combine-sink sink_name=combined
set-default-sink combined
Restart PulseAudio, run pavucontrol and select the "Output Devices" tab. Three settings should be displayed:
  1. Internal Audio Digital Stereo (HDMI)
  2. Internal Audio
  3. Simultaneous output to Internal Audio Digital Stereo (HDMI), Internal Audio
Now start a program that will use pulseaudio such as mplayer, vlc, mpd, etc. and switch to the "Playback" tab. A pulldown should be available for the running program to select one of the three sources.
</snip>
This did work! YAY, now I'm able to listen to audio on my patio without much trouble. Rad!

No comments:

Post a Comment