This page will help you to output 5.1 AC-3 through Alsa, enabling Pulseaudio to use it. The default is to export audio over SPDIF using PCM, which is stereo-only.
Automated installer script
The following script does the steps outlined in the rest of the document. It has only been tested on Ubuntu 14.04 in 2014-12-27. Warning though, do not run it twice since you'll end up inserting same stuff to asound.conf twice.
For Ubuntu 16.04 you need to do next steps:
1. Enable "Source code" repository, do apt-get update.
2. Install libavresample-dev package
sudo apt-get install libavresample-dev
3. Download and run script
chmod +x ./DigitalAC-3PulseaudioInstaller sudo ./DigitalAC-3PulseaudioInstaller
DigitalAC-3PulseaudioInstaller
Configuring asound.conf
If you are using Oneiric Ocelot or later, add the following text to a new file, /usr/share/alsa/alsa.conf.d/a52.conf .For versions prior to Oneiric Ocelot (11.10) , add the following to /etc/asound.conf:
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 } }
Configuring /etc/pulse/daemon.conf
Find line
; default-sample-rate = 44100
Add a line underneath it
default-sample-rate = 48000
By default it is 44100 and this inconsistency with asound.conf causes compatibility issues between programs such as Skype and Steam and possibly others. Thanks to Ben who spent time to find this out and went to the trouble to report it!
Building/Installing Required a52 Plugin
Install dependencies
Install the dependencies for building the asound2 a52 plugin with the following commands:
sudo apt-get build-dep libasound2-plugins sudo apt-get install libavcodec-dev libavformat-dev
N.b! If this fails, make sure that you have the source code lines enabled in Software Center/apt.
Get source for plugin
Create a tmp directory to work in, and install the asound2 source:
mkdir ~/tmp cd ~/tmp apt-get source libasound2-plugins
Build plugin
Build the plugins:
cd alsa-plugins-* ./configure libtoolize --force --copy && aclocal && autoconf && automake --add-missing && make
Install plugin
For Oneiric Ocelot (11.10) or Later
The alsa-libs have been moved to /usr/lib/(i386 or x64)-linux-gnu/alsa-lib
We need to copy the a52 plugin to /usr/lib/alsa-lib and /usr/lib/xxx-linux-gnu/alsa-lib (these commands work for all architectures)
cd a52/.libs sudo cp libasound_module_pcm_a52.la libasound_module_pcm_a52.so /usr/lib/alsa-lib/ sudo cp libasound_module_pcm_a52.so /usr/lib/`uname -i`-linux-gnu/alsa-lib/
For Versions prior to Oneiric Ocelot (11.10)
Copy the a52 plugin to /usr/lib/alsa-lib:
cd a52/.libs sudo cp libasound_module_pcm_a52.la libasound_module_pcm_a52.so /usr/lib/alsa-lib/
Restart ALSA
Either restart your computer or reload ALSA with the following:
sudo alsa reload killall pulseaudio
(At this point, Pulseaudio should restart unless you've disabled 'autospawning')
PulseAudio Setup
Set Sound Hardware Device
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!
2ch Output For Music
If 2 channel output (fl, fr, sub) for music is desired then both audacious and mplayer can bypass pulse.
Audacious
Preferences -> Audio -> Output: alsa, Plugin preference: iec958
MPlayer
- Edit ~/.mplayer/config:
ao=alsa:device=spdif
- Also this can be added to ignore regular music files:
afm=hwac3
Troubleshooting
If the 'Digital Surround 5.1' profile does not show up, it probably means that alsa didn't create it correctly. To test if alsa sees the a52 device, type:
aplay -D a52:0