HOWTO Dolby Digital and DTS
From Gentoo Linux Wiki
| Installation • Kernel & Hardware • Networks • Portage • Software • System • X Server • Gaming • Non-x86 • Emulators • Misc |
Contents |
[edit] Introduction
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 emerge flag.
[edit] Setup
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. Either SPDIF via coaxial connections and/or TOSLINK or EIAJ via optical connections. This guide talks about configuring your system for SPDIF but may be applicable to optical connections.
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 SPDIF in ports.
Let's assume you already have those setup, and we'll jump ahead to getting ALSA prepared to output the stream.
[edit] ALSA Settings
Before anything, make sure that your soundcard actually supports SPDIF.
If you haven't already, emerge media-sound/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.
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
When finished, just hit Escape to exit out. SPDIF out should be enabled now, so let's try it with MPlayer and a DVD.
[edit] MPlayer
- MPlayer Documentation: Audio Codecs
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. :)
[edit] GNOME-AlsaMixer
You might try this utility to quickly change, whether spdif will be used for output or not - if your soundcard supports both.
[edit] SPDIF by Default
If you want to have ALL your ALSA applications send the sound to your SPDIF 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 SPDIF 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.
- You may find that the "global" file in /etc/asound.conf does not work. It it's like this, try setting a chmod 755 on it first, then try a ~/.asoundrc file. (This issue should, though, never happen.)
[edit] On-the-fly Dolby Digital Encoding
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.
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.
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"
[edit] OSS and SPDIF
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 SPDIF 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/modules.d/alsa and add this line to the end.
options snd-pcm-oss dsp_map=2
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 SPDIF 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
}
[edit] A word about chipsets
Not all audio chipsets that support SPDIF have the SPDIF 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 SPDIF output.
If your chipset doesn't map SPDIF to hw:0,2 or similar device number then it may still be be possible for you to use SPDIF using ALSA using the 'spdif' ALSA device. However, you will not be able use OSS pass-through via dsp_map=2.
[edit] 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
[edit] External Links
This article is still a Stub. You can help Gentoo-Wiki by expanding it.


