Howto set up AC3 sound

This document describes how to set up a Dolby Digital AC3 compatible sound card to produce digital AC3 sound via VDR. Please note that this solution does not include the actual sound processing and amplifying. You still need an external AC3 decoder, an amplifier and 6 loudspeakers :-)

This guide was written by Carsten Koch. If you have any questions or comments, please contact Carsten directly.

Step 1: Get a sound card that has an SPDIF output.

I bought a Leadtek Winfast 4Xsound ( from german dealer Atelco ( It has both electrical and optical (via a second slot cover) SPDIF outputs and inputs. The package also contains a 2m TOSLink optical cable and an adapter from TOSLink to Miniplug. With all this stuff, I consider the price (DM 65) to be quite a bargain. Atelco informed me that they will not carry this model much longer, so you better call them before you take a long trip to one of their shops or before you wait in vain for a mail order.

The card is based on the CMI 8738 chip, see for details.

Step 2: Install the latest beta ALSA drivers, library and utilities.

Older drivers may generally support the CMI 8738, but they may not support the SPDIF (IEC958) inputs and outputs. If your CMI 8738 sound already works, but your mixer tool does not show the SPDIF inputs and outputs, I suggest you install the latest ALSA drivers.

At the time I wrote this, these were

Note: the ALSA library 0.9beta10 doesn't work well. That's why I recommend using driver 0.9beta10 together with lib/utils 0.9beta9.

You may want to check for even newer versions. If you are feeling adventuresome, you may also try to check out their latest CVS versions from

As the CVS repository does not contain the (autoconf-generated) configure script, at least on my SuSE 7.2 system, this turned out to be complicated, as autoconf appears not to be set up correctly for this purpose in SuSE 7.2. It turned out that the autoconf M4 macro file aclocal.m4 was not found, so M4 did not substitute a required macro. I could fix that by copying /usr/share/libtool/libltdl/aclocal.m4 to /usr/share/autoconf on my system. Your mileage may vary, please do not ask me if you have trouble with autoconf on your system, I am not an autoconf expert.

Step 3: Activate the driver module.

Do not try to activate the driver module via Yast2. At least the Yast2 in my SuSE 7.2 system could not handle the new 0.9beta driver. Simply put the following into your modules.conf manually:

# ALSA native device support
alias char-major-116 snd
options snd snd_major=116 snd_cards_limit=1
alias snd-card-0 snd-card-cmipci
# OSS/Free setup
alias char-major-14 soundcore
alias sound-slot-0 snd-card-0
alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-1 snd-seq-oss
alias sound-service-0-3 snd-pcm-oss
alias sound-service-0-8 snd-seq-oss
alias sound-service-0-12 snd-pcm-oss

Now you should be able to play sound both through the optical and electrical outputs of your sound card.

Do not proceed to the next step before you have verified that you can play PCM sound. For example, play an mp3 file with mpg123.

Step 4: Connect the SPDIF output of the DVB card to the SPDIF input of the sound card.

Obviously, it would be a hazzle to switch your receiver from an analog to a digital input back and forth all the time. So it would be best to play back not only sound from AC3 recordings via the digital connection, but live sound and sound from non-AC3 recordings as well. At least the old DVB cards have an electrical SPDIF output that can be directly connected to the 4xSound card's electrical SPDIF input. That input is located on the optical module (additional slot cover) that comes with the card. It is labelled "J1-SPDIF IN". See Page 5 of the sound card manual.

Connect the signal pin of J1 with the SPDIF out pin of the DVB card (see If your version of the DVB card does not have an SPDIF output, you can of course also connect the DVB card's line output to the sound card's line input. The following text assumes that you have made the internal connection.

Step 5: Set up the ALSA mixing parameters.

You can use the interactive (ncurses) tool alsamixer or the command line tool amixer to set up the ALSA mixing parameters. See the "alsamixer" and "amixer" man pages. I have muted '3D Control - Switch', 'Synth', 'Line', 'Line-In As Rear', 'CD', 'Mic', 'Mic Boost', 'IEC958 Copyright', 'IEC958 In Valid', 'IEC958 Loop', 'IEC958 Out To DAC', 'Aux', 'Analog Four Channel', 'Exchange DAC' and I have unmuted everything else.

Step 6: Install the specially patched ac3dec tool.

As you may have heard, the Dolby Laboratories are threatening to sue everyone who offers an AC3 decoder without paying licenses to them. In spite of it's name, we are not using the ac3dec tool as an AC3 decoder. We use this tool to transmit the AC3 stream to the IEC958 output of the sound card. The actual decoding takes place in your receiver, which of course must have an SPDIF input and must be able to decode AC3.

You can find ac3dec in the ac3-tools directory in the ALSA CVS repository on sourceforge.

There is one problem in the interaction between vdr, ac3dec and the ALSA system: vdr starts up the "external AC3 sound tool" supplied via the -a vdr command line parameter, even if the recording to be
played back does not contain any AC3 sound. ac3dec, as it currently exists in the sourceforge CVS repository, mutes everything else (in particular, our normal DVB sound), as soon as it starts up. Consequently, when you run vdr with the -a "ac3dec -C" parameter, you will not hear any sound when playing back non-AC3 recordings.

There are three solution alternatives:

  1. Change vdr to only bring up ac3dec when there is data for it. This may not be trivial, as parts of one recording may contain AC3 sound, while other parts of the same recording may not. But I am sure that this problem can be solved and that this solution may turn out to be the best one in the long run.
  2. Wrap a shell script around the ac3dec call that reads one byte from stdin (dd of=/dev/null bs=1 count=1) before actually starting ac3dec. I have tried that. It works.
  3. patch ac3dec so it does not mute anything before it has actually received the first data block. Robert Schneider has developed such a patch. I have made a few changes to it. Here is my current version. This the solution that I am using at the moment.

Step 7: Run vdr with the "-a 'ac3dec -C'" parameter.

As an example, you can use

./runvdr -c . -v /video -a "'ac3dec -C'"

to run vdr.

Note that vdr currently does not feed the AC3 data into ac3dec during live viewing. vdr only records AC3 data onto its recording files and feeds them into ac3dec during playback. In order to record AC3 data successfully, you have to meet the following conditions:

  1. The station you are recording must currently broadcast AC3 sound. Pro7 now broadcasts AC3 sound often. I also heard that Cinedome Deluxe broadcasts AC3 sound, but I do not have the PW package, so I have no experience with that.
  2. You must specify the AC3 PID in the audio PID field of your channels.conf file preceded by a semicolon.
    As an example, your Pro7 entry should look like this:


    256 is the normal audio PID, 257 is the AC3 PID.
  3. According to Stefan Hagedorn, recording AC3 sound works better when you reload the driver immediately before you start the recording. I have achieved this automatically, by reducing the watchdog timer from 60 seconds to 3 seconds. At least on my system, vdr panics a few times a day and reloads the driver in the runvdr script, so I always have a more-or-less freshly reloaded driver all the time. The best watchdog timer value for your system may depend on the overall performance of your system and on other parameters. 3 seconds works great for me, the best value for you may be different.

Disclaimer: The above steps worked for me. Your mileage may vary. In particular, I would assume that the above works with few or maybe even no other sound cards than the one I tried. Do it all at your own risk. I wrote this howto in the hope that it will be useful, but no guarantees of any kind are implied. Please do not swamp me with e-mail. I know little more about the matter than I wrote above. Other knowledgable people on the linux-dvb mailing list may be able to help you better than I could, so please ask the list for help if you get stuck.

© 2001 Carsten Koch