Difference between revisions of "Configuring Digital Sound with AC3 and SPDIF"

From MythTV Official Wiki
Jump to: navigation, search
(Fixed typo)
 
(17 intermediate revisions by 12 users not shown)
Line 1: Line 1:
Many motherboards come with an on-board [http://www.mythtv.org/wiki/index.php/SPDIF 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.
+
{{Note box|Please note that the following information is mostly outdated and no longer necessary when using a modern linux distribution. The only item still relevant with mythtv 0.24 and newer is to make sure the IEC958 output is not muted.}}
  
Most modern Linux distributions ship with the [http://www.alsa-project.org/ ALSA] libraries and corresponding utilities pre-installed and configured out of the box. This simplifies the setup. If your distribution doesn't install ALSA by default, consult the [Configuring Digital Sound] entry on this wiki.
+
 
 +
Many motherboards come with an on-board [[SPDIF|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.
 +
 
 +
Most modern Linux distributions ship with the [http://www.alsa-project.org/ ALSA] libraries and corresponding utilities pre-installed and configured out of the box. This simplifies the setup. If your distribution doesn't install ALSA by default, consult the [[Configuring Digital Sound]] entry on this wiki.
  
 
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.
 
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.
Line 11: Line 14:
 
== Requirements ==
 
== Requirements ==
  
<ul>
+
*You need to have S/PDIF available on your motherboard or sound card.
<li>You need to have S/PDIF available on your motherboard.</li>
+
*You need to have an S/PDIF adapter (also known as an "SPDIF Bracket") that brings some form of digital port to the exterior of the machine (optical audio, coaxial audio). These are extremely difficult to find. You may want to construct your own, see [[How_to_build_a_optical_SPDIF_bracket]].  Check the [[Sound card]] WIKI entry for more information.
<li>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 [http://www.vidabox.com/shop/index.php?main_page=product_info&cPath=4&products_id=9 Vidabox].  Check the [http://www.mythtv.org/wiki/index.php/Sound_card Sound Card] entry in this WIKI.</li>
+
*A digital-audio capable receiver.
<li>A digital-audio capable receiver.</li>
+
*The proper cabling.
<li>The proper cabling.</li>
+
*Fedora Core 5 (or above) installed (much of this page applies to other distributions, too).
<li>Fedora Core 5 (and above) installed</li>
+
*Some time on your hands, uninterrupted.
<li>Some time on your hands, uninterrupted. </li>
+
</ul>
+
  
 
== Find and Un-Mute Your S/PDIF ==
 
== Find and Un-Mute Your S/PDIF ==
Line 49: Line 50:
  
  
== [http://www.mythtv.org/wiki/index.php/Configuring_Digital_Sound Digital Sound] ==
+
== [[Configuring Digital Sound|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.
+
The [[Configuring 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.
+
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 is '''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:
 
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:
 
<pre>aplay -D ALSA:spdif test.ac3</pre>
 
<pre>aplay -D ALSA:spdif test.ac3</pre>
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.
+
This is, actually, a good sign.  Testing with mplayer "mplayer" should output digital AC3 sound which will tell you that the device is working:
 +
<pre>
 +
mplayer -ao alsa:device=spdif -ac hwac3 test.ac3
 +
</pre>
 +
You can also test against an inserted DVD or a DVD iso.  See the "Testing" section near the end of this document. 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 ==
 
== Configuration files ==
Line 97: Line 102:
 
This part is the easy part.  Fire up mythfrontend and navigate to:
 
This part is the easy part.  Fire up mythfrontend and navigate to:
 
Utilities/Setup->Setup->General
 
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".
+
On Page 3, change the default audio device to "ALSA:default" and change the passthrough device to "ALSA:default".  Check the box next to "AC3 to SPDIF passthrough". Uncheck the box next to "Use internal volume control."
  
== Configure MythMusic for Digital Sound ==
+
The experimental setting "Use video as timebase" under the Playback
 +
section of TV Settings is incompatible with AC3 to SPDIF passthrough. If "Use
 +
video as timebase" is checked, you will get stuttering audio output or
 +
not audio at all. "Use video as timebase" '''must''' be unchecked if you want
 +
AC3 audio to work.
 +
 
 +
== 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'''.
 
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'''.
Line 111: Line 122:
 
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.
 
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.
+
Note that you can not get the ALSA utility "speaker-test -c6" to work over the digital audio output. speaker-test only uses left and right channels, the other channels are not sent. To test a digital connection in multi-channel mode you need to use a surround sound AC3 or DTS sample file and mplayer.
 +
 
 +
You can download free a 5.1 ac3 sample from http://www.lynnemusic.com/surround.html
 +
The following commands should test this
 +
<pre>
 +
wget http://www.lynnepublishing.com/surround/www_lynnemusic_com_surround_test.ac3
 +
mplayer -ao alsa:device=spdif -ac hwac3 www_lynnemusic_com_surround_test.ac3 -loop 0
 +
</pre>
  
 
== References ==
 
== References ==
<ul>
+
*[[Configuring Digital Sound]]
<li>[http://www.mythtv.org/wiki/index.php/Configuring_Digital_Sound http://www.mythtv.org/wiki/index.php/Configuring_Digital_Sound]</li>
+
*[[DigitalSoundHowTo]]
<li>[http://gentoo-wiki.com/HOWTO_Dolby_Digital_Out_(AC3,_SPDIF) http://gentoo-wiki.com/HOWTO_Dolby_Digital_Out_(AC3,_SPDIF)]</li>
+
*[http://gentoo-wiki.com/HOWTO_Dolby_Digital_Out_(AC3,_SPDIF) http://gentoo-wiki.com/HOWTO_Dolby_Digital_Out_(AC3,_SPDIF)]
<li>[http://www.mythtv.org/wiki/index.php/DigitalSoundHowTo http://www.mythtv.org/wiki/index.php/DigitalSoundHowTo]</li>
+
*[http://www.gossamer-threads.com/lists/mythtv/users/250580?search_string=M-audio;#250580 http://www.gossamer-threads.com/lists/mythtv/users/250580?search_string=M-audio;#250580]
<li>[http://www.gossamer-threads.com/lists/mythtv/users/250580?search_string=M-audio;#250580 http://www.gossamer-threads.com/lists/mythtv/users/250580?search_string=M-audio;#250580]</li>
+
  
 
[[Category:HOWTO]] [[Category:Sound_cards]]
 
[[Category:HOWTO]] [[Category:Sound_cards]]

Latest revision as of 21:02, 11 October 2011

Important.png Note: Please note that the following information is mostly outdated and no longer necessary when using a modern linux distribution. The only item still relevant with mythtv 0.24 and newer is to make sure the IEC958 output is not muted.


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.

Most modern Linux distributions ship with the ALSA libraries and corresponding utilities pre-installed and configured out of the box. This simplifies the setup. If your distribution doesn't install ALSA by default, consult the Configuring Digital Sound entry on this wiki.

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 Configuring Digital Sound page provides a good starting point for configuring ALSA. 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.

Requirements

  • You need to have S/PDIF available on your motherboard or sound card.
  • You need to have an S/PDIF adapter (also known as an "SPDIF Bracket") that brings some form of digital port to the exterior of the machine (optical audio, coaxial audio). These are extremely difficult to find. You may want to construct your own, see How_to_build_a_optical_SPDIF_bracket. Check the Sound card WIKI entry for more information.
  • A digital-audio capable receiver.
  • The proper cabling.
  • Fedora Core 5 (or above) installed (much of this page applies to other distributions, too).
  • 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 Configuring 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 is 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 "mplayer" should output digital AC3 sound which will tell you that the device is working:

mplayer -ao alsa:device=spdif -ac hwac3 test.ac3

You can also test against an inserted DVD or a DVD iso. See the "Testing" section near the end of this document. 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". Check the box next to "AC3 to SPDIF passthrough". Uncheck the box next to "Use internal volume control."

The experimental setting "Use video as timebase" under the Playback section of TV Settings is incompatible with AC3 to SPDIF passthrough. If "Use video as timebase" is checked, you will get stuttering audio output or not audio at all. "Use video as timebase" must be unchecked if you want AC3 audio to work.

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.

Testing

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://
or
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.

Note that you can not get the ALSA utility "speaker-test -c6" to work over the digital audio output. speaker-test only uses left and right channels, the other channels are not sent. To test a digital connection in multi-channel mode you need to use a surround sound AC3 or DTS sample file and mplayer.

You can download free a 5.1 ac3 sample from http://www.lynnemusic.com/surround.html The following commands should test this

wget http://www.lynnepublishing.com/surround/www_lynnemusic_com_surround_test.ac3
mplayer -ao alsa:device=spdif -ac hwac3 www_lynnemusic_com_surround_test.ac3 -loop 0

References