Gentoo Wiki ArchivesGentoo Wiki


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc



This HOWTO will attempt to explain in basic terms how to get the Dolby Digital or DTS stream from your DVD (or ripped files on your computer) to your receiver for audio processing.

NOTE: If you are just looking for AC3 support in mplayer, include the a52 USE flag.


Getting your system setup for AC3 or DTS out is actually fairly simple. There are only two things you really need: ALSA (optional OSS emulation support) and the hardware.

The computer hardware is cheap, and most motherboards these days will have some kind of onboard digital audio outputs, called S/PDIF. There are either coaxial connections (via RCA jacks) and / or optical connections (via TOSLINK or EIAJ Optical) available.

The final piece of hardware you need is a receiver that can process the 5.1 Dolby Digital and/or DTS audio streams. Obviously, that should have some S/PDIF in ports.

Let's assume you already have those setup, and we'll jump ahead to getting ALSA prepared to output the stream.

ALSA Settings

Before anything, make sure that your soundcard actually supports S/PDIF.

If you haven't already, install alsa-utils so that you have aplay and alsamixer installed on your system. We'll use that to make sure that AC3 out is enabled.

You can do this by running aplay -L, which lists your available output devices and options.

Code: aplay -L
cards 'cards.pcm'
front 'cards.pcm.front'
rear 'cards.pcm.rear'
center_lfe 'cards.pcm.center_lfe'
side 'cards.pcm.side'
surround40 'cards.pcm.surround40'
surround41 'cards.pcm.surround41'
surround50 'cards.pcm.surround50'
surround51 'cards.pcm.surround51'
surround71 'cards.pcm.surround71'
iec958 'cards.pcm.iec958'
spdif 'cards.pcm.iec958'
modem 'cards.pcm.modem'
phoneline 'cards.pcm.phoneline'
default 'cards.pcm.default'
dmix 'cards.pcm.dmix'
dsnoop 'cards.pcm.dsnoop'

Startup alsamixer in a terminal, and scroll over to the right until you see the IEC958 mixer.

Image:Alsamixer iec598.png

It is probably muted by default. All you need to do is unmute it by pressing m, and you should be set. Don't worry about the volume control next to it.

You may also need to mute the Analog to IEC958 Output

Note: Init scripts that save mixer settings (such as alsasound and aumix) may or may not be able to unmute your S/PDIF out on boot.

When finished, just hit Escape to exit out. S/PDIF out should be enabled now, so let's try it with MPlayer and a DVD.


We're using MPlayer for our test run because it's easy to use, and can give valuable feedback if something isn't working right.

Go ahead and put a DVD into your disc drive (one that has a Dolby Digital stream), make sure your receiver is set to the right input device, and try it out:

mplayer dvd:// -ao alsa:device=spdif -ac hwac3

In some cases you'll need to specify the audio track. You can do this with the -aid <track> option. 128 is usually the default value for the first track.

mplayer dvd:// -ao alsa:device=spdif -ac hwac3 -aid 128

Ideally, that should work. Look at your receiver's console display to make sure that it is sending a Dolby Digital stream, and that the 5.1 channels are being used.

If that's not working, just increment the number by 1 until you find the one you are looking for. Some DVDs have two Dolby Digital streams - a 2 channel and 5.1 channel one.

DTS is a little bit different. Instead of using hwac3 as the audio codec, we're going to force hwdts. You need to make sure you emerged MPlayer with the dts USE flag, though.

You can also make sure DTS is available (and working) with this command:

mplayer -ac help | grep -i dts

Then, try it with the same command as above:

mplayer dvd:// -ao alsa:device=spdif -ac hwdts

You might need to pass -aid 137 to get the right audio track:

mplayer dvd:// -ao alsa:device=spdif -ac hwdts -aid 137

MPlayer isn't the only media player that has AC3/DTS support. In fact, most of the major ones do, if not all of them.

Good luck, and enjoy your surround sound. :)


You might try this utility to quickly change, whether S/PDIF will be used for output or not - if your soundcard supports both.


S/PDIF by Default

If you want to have ALL your ALSA applications send the sound to your S/PDIF out, then you just need to create an .asoundrc file in your home directory containing one of below ways:

1st way:

pcm.!default spdif

2nd way (if above doesn't work):

pcm.!default {
       type hw
       card 0
       device 2

3rd way (if you have more than one sound card / need resampling / other funkiness ):

Obviously you will need to change the pcm string line to match your setup. The output of aplay -L will probably help.

pcm.!default {
       type plug
       slave.pcm "iec958:CARD=V8235,DEV=0" # taken from aplay -L 
       slave.rate 48000 # optional resampling to 48kHz

That config file tells ALSA to override using the default device, and instead makes 'spdif' or 'hardware device 2' your default. That's probably going to be your S/PDIF out.

Just be sure to create that file for whoever is playing the sounds. Or you can put it in /etc/asound.conf to make it the global default.

On-the-fly Dolby Digital Encoding

Note: Author's note: This setup does not support mixing. It's nice for listening to music, but you may want to avoid setting this to default and just set your media player's output to this manually.
Note: Upmixing can be processor intensive and can severely affect video playback. If you find your video doesn't play back properly after adding these configs it's very likely the upmixing is too demanding for your system

Alternatively, ALSA can encode to a Dolby Digital data stream. The media-plugins/alsa-plugins package has a plugin called a52 that handles the encoding. Enabling on-the-fly dolby encoding is as easy as adding this to your /etc/alsa/alsa.conf or your ~/.asoundrc:

pcm.a52encode {
	type a52

This is the bare minimum setup. By default, it uses audio card 0, 6 channels, and a 48 KHz samplerate. Additional options can be found in /usr/share/doc/alsa-plugins-version/a52.txt.bz2.

Note: If you do not have the a52 plugin in /usr/lib/alsa-lib/ even after emerging the latest media-plugins/alsa-plugins then your media-video/ffmpeg version most likely is too old. At the time of writing the stable ffmpeg-0.4.9_p20070616 causes media-plugins/alsa-plugins to report checking for avcodec_open in -lavcodec... no at the configure step and not to build the a52 plugin. Instead unmask and install media-video/ffmpeg-0.4.9_p20080206 and recompile alsa-plugins afterwards.

Unfortunately, stereo sound doesn't get upmixed without additional work. Add this to ~/.asoundrc as well.

pcm.stereoupmix {
	type upmix
	slave.pcm "a52encode"
	channels 6 

This will upmix stereo sound into surround sound and send it to the encoder plugin. I report this setup doesn't work with Amarok. Use this one instead for the same result

pcm.stereoupmix {
       type route
       slave.pcm "a52encode"
       slave.channels 6
       ttable.0.0 1
       ttable.1.1 1
       ttable.0.2 1
       ttable.1.3 1
       ttable.0.4 0.5
       ttable.1.4 0.5
       ttable.0.5 0.5
       ttable.1.5 0.5

And in Amarok, configure output with alsa, and plug:stereoupmix in the correct fields.

Note: This is a simple upmixer. It copies the audio to the rear speakers and averages the left/right channels before sending them to the center and subwoofer channels. If your receiver has Dolby ProLogic 2, or some other upmixing feature, try it out as well, you may prefer that sound instead.

Like above, setting alsa to use this by default is done by adding this to ~/.asoundrc:

pcm.!default "plug:a52encode"

or if you want your audio upmixed,

pcm.!default "plug:stereoupmix"


There are some applications that want to send the Dolby Digital Stream over OSS (MythTV is an example), and if you want to pipe everything going through /dev/dsp to your S/PDIF out, that's possible too.

First of all, you must have ALSA installed as modules with OSS support. Whether you use the in-kernel ALSA modules or emerge alsa-drivers is up to you.

Secondly, edit /etc/modprobe.d/alsa and add this line to the end.

File: /etc/modprobe.d/alsa
 options snd-pcm-oss dsp_map=2

Afterwards run update-modules.

The 2 in the example is similar to ALSA's hw:0,2 setting above in .asoundrc. They are both the number for the hardware device you are outputting to by default.

One more handy note. If you are using MythTV and want to do S/PDIF out with OSS, then leave the audio output device as /dev/dsp and the mixer as /dev/mixer.

Alternatively, some versions automatically make the digital output available in /dev/adsp. This method, if available, is less likely to get ALSA confused.

If you facing a problem that Adobe Flash Player plays no sound you can add following lines to your ~/.asoundrc

pcm.!default {
type plug
slave.pcm "dmixer"

#Pretty sure this part does nothing
pcm.dsp {
type plug
slave.pcm "dmixer"

pcm.dmixer {
type dmix
ipc_key 1024
slave {
pcm "hw:0,2"
period_time 0
period_size 1024
buffer_size 4096
rate 44100
bindings {
0 0
1 1

ctl.dmixer {
type hw
card 0

A word about chipsets

Not all audio chipsets that support S/PDIF have the S/PDIF output mapped to a device in the manner that can be accessed via hw:0,2 or dsp_map=2. The use of hw:0,2 comes from the fact that the nForce chipsets common on many of today's motherboards use hw:0,2 as an alias for S/PDIF output.

If your chipset doesn't map S/PDIF to hw:0,2 or similar device number then it may still be be possible for you to use S/PDIF using ALSA using the 'spdif' ALSA device. However, you will not be able use OSS pass-through via dsp_map=2.

Test Your Setup

Execute speaker-test from media-sound/alsa-utils to generate some sound to make sure that your setup is working.

speaker-test -c6

External Links

This article is still a Stub. You can help Gentoo-Wiki by expanding it.

Retrieved from ""

Last modified: Sun, 21 Sep 2008 14:07:00 +1000 Hits: 58,898

Created by, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.