Configuring Digital Sound with AC3 and SPDIF

From MythTV Official Wiki
Revision as of 04:16, 4 February 2007 by Wesmoc (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Many motherboards come with an on-board S/PDIF connector. This interface provides a mechanism for the output (and, on some motherboards, the input) of raw digital audio. With a MythTV setup, the S/PDIF connection is truly the key toward passing digital audio out of the system and in to your home theater receiver.

On Fedora Core 5, the ALSA libraries and corresponding utilities come pre-installed and configured out of the box. Other distributions may or may not have this feature, but this simplifies the setup.

There are many How-To's and WIKI entries available for configuring digital sound, and there are others that focus on sending the output via SPDIF, but none seem to combine the two.

The MythTV WIKI has a good How-To for configuring Digital Sound and provides a good starting point for configuring it on Fedora Core 5. However, due to the pre-installation nature of Fedora Core 5 and the ALSA suite, a fair chunk of the WIKI document does not apply and a lot of the information gets lost in the mix.

It is just way too easy to get confused between S/PDIF, /dev/adsp, /dev/dsp, /dev/mixer, and all of the others.


  • You need to have S/PDIF available on your motherboard.
  • You need to have an S/PDIF adapter that brings some form of digital port to the exterior of the machine (optical audio, coaxial audio). One such adapter is from Vidabox. Check the Sound Card entry in this WIKI.
  • A digital-audio capable receiver.
  • The proper cabling.
  • Fedora Core 5 (and above) installed
  • Some time on your hands, uninterrupted.

Find and Un-Mute Your S/PDIF

In this scenario, the goal is to have all audio sent out via the S/PDIF adaptor. Fedora Core 5, by default, has the S/PDIF output muted. First and foremost, you need to make sure that your system recognizes the on-board S/PDIF:

#> 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'

Specifically, we are concerned with "iec958", which shows up above. "spdif" also shows up, and, as you can see, it is simply an alias to the "iec958" device.

Now, bring up alsamixer and, using the arrow keys, move over to the "iec958" device and un-mute it by hitting the "m" key. Hit "esc" to exit and save the settings. (this image was taken directly from the Gentoo Wiki).

Alsamixer iec598.png

With the S/PDIF interface unmuted, we are free to start sending audio down the line.

Digital Sound

The Digital Sound entry in this Wiki is very complete. However, from my experience, it was a lot more than I needed. As such, some of the important information got lost.

By default, with Fedora Core 5, all of the correct entries are automatically put together for you. Hence, there is no need for a local .asoundrc or /etc/asound.conf in order to send digital audio out via the SPDIF adapter. All you need to reference ALSA:spdif when performing your tests. But this is not the end solution, so please, read onwards.

Testing the output with a snippet of an ac3 file that I had on hand (you can pull one off of a DVD if need be) produced audible static:

aplay -D ALSA:spdif test.ac3

This is, actually, a good sign. Testing with "mplayer" (see the "Testing" section near the end of this document) should output digital AC3 sound which will tell you that the device is working. You can also test with a MP3 file and get audio (maybe..), but it will be slightly faster due to the difference between the MP3's 44.1khz and the expected digital audio at 48khz. Don't worry.. this will get resolved.

Configuration files

Create the following /etc/asound.conf:

pcm.!default {
type plug
slave {
pcm "spdif"
rate 48000
format S16_LE

This entry will be in addition to the default ALSA settings that come with Fedora Core 5.

I also added the following to my /etc/modprobe.conf file as suggested in the Gentoo document, but it seemed to make no difference if it was there or not. I added it for the sake of consistency, but I will probably remove it.

options snd-pcm-oss dsp_map=1

The "dsp_map=#" obtained by running "aplay" and observing the output:

]# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: V8237 [VIA 8237], device 0: VIA 8237 [VIA 8237]
  Subdevices: 3/4
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
card 0: V8237 [VIA 8237], device 1: VIA 8237 [VIA 8237]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

In this case, I know that on my motherboard I have a bunch of on-board output options (L/R, Subwoofer, L/R rear, etc) in addition to the on-board S/PDIF. So, I know that my spdif is "card 0, device 1". Hence, the "dsp_map" setting is set to the device, which is "1". This may or may not be the same for your system.

Configure MythTV for Digital Sound

This part is the easy part. Fire up mythfrontend and navigate to: Utilities/Setup->Setup->General On Page 3, change the default audio device to "ALSA:default" and change the passthrough device to "ALSA:default". Finally, check the box next to "AC3 to SPDIF passthrough".

Configure MythMusic for Digital Sound

There is conflicting documentation out there that says you need to make changes to the Music Settings page. However, if you do the steps above, you will not need to make any changes here.


Although it has been left out (I hope to add this shortly), it is best to test things at every step to make sure you are doing things correctly. I cannot stress this enough since it directly helps to debug where things might be going wrong.

You can test with mplayer via:

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

Since I happened to have a number of my DVD's imported in to MythVideo, I had the ISO images easily accessible to test with.

I was unable to get the ALSA utility "speaker-test -c6" to work over the digital audio output.