Saturday, June 20, 2009

Getting AC3 Pass Through Working in Linux

This guide is about sending AC3 stream (Dolby Digital or DTS) to a receiver when playing a video file in Linux, and have the receiver doing the decoding rather than Linux.

Issues

Linux movie players require a sound backend to play. There are two main flavors of sound backend, gstreamer and xine. Unfortunately the AC3 pass through capability is broken in gstreamer. So we need to use xine. Thus the choice of the correct movie player becomes critical if you want AC3 pass through. Adding in the complexity of ALSA, setting up AC3 pass through in Linux is non trivial.

Approach

I am going to use totem-xine for movie playback, and set totem-xine to use ALSA with AC3 pass through.

My Setup

My PC has two sound cards, the on board sound card and a M-Audio Revolution 5.1. The connection to the receiver is on the M-Audio.

Linux distro I am using is Ubuntu 9.04. Aside from getting totem-xine, the instructions should apply to all distros.

Step 0: Preparation

You should have the following files for testing purpose:
  • a video file that has a Dolby Digital or DTS track
  • a .wav file
Your receiver should already be connected to your sound card using coax or toslink cable.

You should know how to open a text terminal and edit text files using application such as gedit.

Step 1: Obtaining totem-xine

I am going to use totem-xine in this guide. Totem-xine is identical to the default movie player except totem-xine uses xine as the sound backend.

To obtain totem-xine, open a text terminal, type:
sudo apt-get install totem-xine
After you install totem-xine, if you right click on a video file, and choose Open With, you should see Movie Player (xine) as a valid choice. Movie Player (xine) is totem-xine.

If you use totem-xine to play a movie, chances are you can hear the sound from the default sound card, but not in Dolby Digital or DTS.

Step 2: Locating the Correct Sound Device

In this step, we will locate the sound device where sound is being sent from your PC to your receiver.

Note that we are using ALSA here. ALSA is the default API for sound drivers in Linux.

In a text terminal, type:
aplay -L
This command will list all the audio devices that are controlled by ALSA. In my computer, the command produces:
front:CARD=NVidia,DEV=0
HDA NVidia, ALC662 Analog
Front speakers
surround40:CARD=NVidia,DEV=0
HDA NVidia, ALC662 Analog
4.0 Surround output to Front and Rear speakers
....
The output of the command is the name of each device, followed by a few lines of its description. You should look for an S/PDIF output device that belongs to the sound card of your choice, i.e. the connection from your sound card to the receiver.

One of the device listed in my setup is:
iec958:CARD=Revolution51,DEV=0
M Audio Revolution-5.1, ICE1724
IEC958 (S/PDIF) Digital Audio Output
This is the audio device I am looking for: iec958:CARD=Revolution51,DEV=0.

Use the .wav file to test the device. In the terminal, type:
aplay --device=your_device sound.wav
Using my setup as example, it is:
aplay --device=iec958:CARD=Revolution51,DEV=0 sound.wav
You should hear some sound from your receiver. If not, you have selected the wrong device and should look for another device.

Step 3: Configuring totem-xine

In this step, we are gonna configure totem-xine to do AC3 pass through on the correct sound output device. Unfortunately, totem-xine's user interface is not flexible enough to do what we want. We will need to edit its config file.

Here is where totem-xine's config file is located:
your home directory/.config/totem/xine-config
You should make a backup copy of xine-config in case you made a mistake.

Use your favorite text editor to edit xine-config, look for the line:
#audio.driver:auto
Change it to:
audio.drive:alsa
Look for the line:
audio.output.speaker_arrangement:Pass Through
Make sure the speaker arrangement is set to Pass Through.

Save the config file. Open a video file using totem-xine and exit right away. This step is crucial because it produces extra lines in the config file for further editing.

Open the totem-xine config file again, look for the line:
audio.device.alsa_front_device:default
Change it to:
audio.device.alsa_front_device:iec958:CARD=Revolution51,DEV=0
Note: iec958:CARD=Revolution51,DEV=0 is the sound device in my setup. You should change it to your sound device found in the previous step.

Look for the line:
#audio.device.alsa_passthrough_device:iec958:AES0=0x6,AES1=0x82,AES2=0x0,AES3=0x2
Change it to:
audio.device.alsa_passthrough_device:iec958:CARD=Revolution51,DEV=0
Save the config file. You are now all set. When you play a video file in totem-xine, AC3 pass through should work.

No comments:

Post a Comment