Wednesday, November 3, 2010

HOWTO: A52 Encoded 5.1 Surround Sound Awesomeness with PulseAudio and ALSA

There are two steps here: add the a52 plugin, and tell pulseaudio to use it.

Step 1:
Go to a terminal and do the following:

Code:
sudo bash
echo "pcm.a52 {
@args [CARD]
@args.CARD {
type string
}
type rate
slave {
pcm {
type a52
bitrate 448
channels 6
card $CARD
}
rate 48000 #required somehow, otherwise nothing happens in PulseAudio
}
}
" > /etc/asound.conf
cd /tmp
apt-get source libasound2-plugins
apt-get build-dep libasound2-plugins
apt-get install libavcodec-dev
cd alsa-plugins-*
./configure
make
cd a52/.libs
cp libasound_module_pcm_a52.la libasound_module_pcm_a52.so /usr/lib/alsa-lib/
cd /tmp
rm alsa-plugins-* -rf

Step 2:
Either reboot or type the following (while still root):

Code:
alsa reload
killall pulseaudio

Pulse should come back on its own unless you disabled autospawn.

Now pulse should be aware of your digital surround output. Go to System -> Preferences -> Sound. Click on the "Hardware" tab and change the profile to one of the 'Digital Surround 5.1' profiles. Play some sound (I like to test with www.pandora.com) and enjoy!

If it doesn't show up, it probably means that alsa didn't create it correctly. To test if alsa sees the a52 device, type:

Code:
aplay -D a52:0

If it errors out (audio open error: No such file or directory) then that means it did not like your asound.conf settings. You might learn something by looking at the output of 'sudo alsa reload' or just 'aplay'.

To see if it works, you can test with this command:

Code:
speaker-test -Da52:0 -c6

One other useful debug tool is to disable autospawn in /etc/pulseaudio/client.conf (uncomment the autospawn line) and kill pulseaudio. Then if you run 'pulseaudio -vv' you can see what pulse is doing. Change the number of 'v's for more information.

Always double check alsamixer if things seem weird.