Difference between revisions of "Configuring Digital Sound"

From MythTV Official Wiki
Jump to: navigation, search
(ALSA Utilities)
m (Setting up ALSA's .asoundrc, Properly)
Line 32: Line 32:
 
Using the "default" ALSA configuration (or the .asoundrc specified for your particular sound card at the http://alsa-project.org/ site) gives only a very basic configuration and relies on the user to specify all the sound stream handling required for a system's sound card.  Instead of specifying this configuration information every time the sound card is used (or configuring it in every application), it makes more sense to create an ALSA configuration file.
 
Using the "default" ALSA configuration (or the .asoundrc specified for your particular sound card at the http://alsa-project.org/ site) gives only a very basic configuration and relies on the user to specify all the sound stream handling required for a system's sound card.  Instead of specifying this configuration information every time the sound card is used (or configuring it in every application), it makes more sense to create an ALSA configuration file.
  
'''[Note:''' This is not required on Fedora Core 5 and 6 systems.  The default ALSA configuration contains all of the capabilities delivered by the configuration file shown below and using this configuration file will break the ALSA configuration on FC5 systems.  FC5 users can use '''ALSA:default''' as the '''Audio output device''' and set '''mixer''' to '''default''' in the '''General''' settings section of the frontend settings. ''']'''
+
[[Image:Important.png|left]] '''[Note:''' This is not required on Fedora Core 5 and 6 systems.  The default ALSA configuration contains all of the capabilities delivered by the configuration file shown below and using this configuration file will break the ALSA configuration on FC5 systems.  FC5 users can use '''ALSA:default''' as the '''Audio output device''' and set '''mixer''' to '''default''' in the '''General''' settings section of the frontend settings. ''']'''<br style="clear:left;"/>
  
'''[Note2:'''  If you are using a version of ALSA newer than 1.0.12 -- http://alsa.opensrc.org/.asoundrc states that for most uses an .asoundrc is not necessary.  Use "aplay -l" to see a list of available device names and use "ALSA:<device name>" for the Audio output device and "default" for the mixer in the General settings section of the frontend settings. ]
+
[[Image:Important.png|left]] '''[Note2:'''  If you are using a version of ALSA newer than 1.0.12 -- http://alsa.opensrc.org/.asoundrc states that for most uses an .asoundrc is not necessary.  Use "aplay -l" to see a list of available device names and use "ALSA:<device name>" for the Audio output device and "default" for the mixer in the General settings section of the frontend settings. ''']'''<br style="clear:left;"/>
  
 
To use the ALSA configuration file below, save the text (including comments) as /etc/asound.conf (for system-wide usage) or as ~/.asoundrc (for user-specific configuration).  Edit and use the file as described in the comments at the top.  (Note that the only edit you should need to do is specifying card number and device number for the "analog-hw" and/or "digital-hw" virtual devices.)
 
To use the ALSA configuration file below, save the text (including comments) as /etc/asound.conf (for system-wide usage) or as ~/.asoundrc (for user-specific configuration).  Edit and use the file as described in the comments at the top.  (Note that the only edit you should need to do is specifying card number and device number for the "analog-hw" and/or "digital-hw" virtual devices.)
Line 51: Line 51:
  
 
replacing devicename with one of '''default''', '''analog''', '''mixed-analog''', '''digital''', or '''mixed-digital'''.  aplay doesn't support many formats, so an au file is probably the easiest one to test with.  If you need one, download ftp://ftp.kernel.org/pub/linux/kernel/SillySounds/english.au and you can hear Linus pronounce Linux (from 1994).
 
replacing devicename with one of '''default''', '''analog''', '''mixed-analog''', '''digital''', or '''mixed-digital'''.  aplay doesn't support many formats, so an au file is probably the easiest one to test with.  If you need one, download ftp://ftp.kernel.org/pub/linux/kernel/SillySounds/english.au and you can hear Linus pronounce Linux (from 1994).
 
+
{{Box File|~/.asoundrc|
 
<pre><nowiki>
 
<pre><nowiki>
 
# ~/.asoundrc or /etc/asound.conf
 
# ~/.asoundrc or /etc/asound.conf
Line 269: Line 269:
 
}
 
}
 
</nowiki></pre>
 
</nowiki></pre>
 
+
}}
 
For a detailed description of how this ALSA configuration file works, see [http://www.gossamer-threads.com/lists/mythtv/users/61265#61265 this post] from the mailing list.
 
For a detailed description of how this ALSA configuration file works, see [http://www.gossamer-threads.com/lists/mythtv/users/61265#61265 this post] from the mailing list.
  

Revision as of 03:33, 23 March 2007

Basics

Audio.pngMythTV relies on the operating system sound system to provide audio. You should make sure first and foremost that you have a working sound system outside of MythTV before thinking there is something wrong with the software.

On Linux there are generally three major sound systems that are supported by MythTV:

  • ALSA: Advanced Linux Sound Architecture
  • aRts: Analog Realtime Synthesizer
  • OSS: Open Sound System

Check the appropriate support site or Linux documentation in addition to any hints here in getting your sound card working under Linux. The MythTV wiki Sound card page also contains useful information on this topic. If you have additional information, please add it to the External Links page.

ALSA Utilities

Package.png Don't forget that there are some utilities that are included in the alsa-utils package. Use your favorite package manager to install the package. This is especially true for alsaconf recommended in the installation guide.

  • alsa_init
  • alsa_snddevice
  • alsamixer
    • text based mixer. Fills screen with all available audio inputs.
    • push the slider up to increase volume.
    • The MM at the top of column. Means MUTE Hit M key to unmute
    • The word CAPTUR above a column means it's being used as an input. Use space to select. Note that selecting some inputs automatically deselects others.
  • aplay
    • ALSA command-line sound player. Also has options for listing ALSA devices which can be helpful
  • arecord
    • ALSA command-line sound player. Also has options for listing ALSA devices which can be helpful
  • test_ioctl
    • Run as root. Can unmute sound and increase volume. Use -h for full usage information

Setting up ALSA's .asoundrc, Properly

Using the "default" ALSA configuration (or the .asoundrc specified for your particular sound card at the http://alsa-project.org/ site) gives only a very basic configuration and relies on the user to specify all the sound stream handling required for a system's sound card. Instead of specifying this configuration information every time the sound card is used (or configuring it in every application), it makes more sense to create an ALSA configuration file.

Important.png
[Note: This is not required on Fedora Core 5 and 6 systems. The default ALSA configuration contains all of the capabilities delivered by the configuration file shown below and using this configuration file will break the ALSA configuration on FC5 systems. FC5 users can use ALSA:default as the Audio output device and set mixer to default in the General settings section of the frontend settings. ]
Important.png
[Note2: If you are using a version of ALSA newer than 1.0.12 -- http://alsa.opensrc.org/.asoundrc states that for most uses an .asoundrc is not necessary. Use "aplay -l" to see a list of available device names and use "ALSA:<device name>" for the Audio output device and "default" for the mixer in the General settings section of the frontend settings. ]

To use the ALSA configuration file below, save the text (including comments) as /etc/asound.conf (for system-wide usage) or as ~/.asoundrc (for user-specific configuration). Edit and use the file as described in the comments at the top. (Note that the only edit you should need to do is specifying card number and device number for the "analog-hw" and/or "digital-hw" virtual devices.)

To use one of the named devices in Myth, specify the appropriate device for the Audio output device setting (in the General settings section of the frontend settings) using the format ALSA:devicename (case sensitive). You will need to type in the value, it's not in the list. Next, set the mixer field using the device name, but without the "ALSA:" prefix. Generally, you can use default for mixer regardless of which output device you've chosen.

At least one user reported being able to use either ASLA:digital-hw or ALSA:dmix-digital for watching TV/recordings; however, MythMusic would not work logging the error Rate doesn't match (requested 44100Hz, got 48000Hz). Changing the output device to ALSA:default fixed the problem.

The filtering performed by these definitions will prevent AC-3/DTS passthrough from working. If using passthrough, you may specify "ALSA:digital-hw" to Myth, but some things (i.e. CD playback) will no longer work.

To test the output devices, execute the command:

aplay -D devicename /path/to/audio/file.au

replacing devicename with one of default, analog, mixed-analog, digital, or mixed-digital. aplay doesn't support many formats, so an au file is probably the easiest one to test with. If you need one, download ftp://ftp.kernel.org/pub/linux/kernel/SillySounds/english.au and you can hear Linus pronounce Linux (from 1994). Template:Box File For a detailed description of how this ALSA configuration file works, see this post from the mailing list.

If you would like simultaneous digital and analog output, add the following at the end of the above /etc/asound.conf or .asoundrc file:

pcm.!default {
type plug
slave {
pcm multi
rate 48000
}
ttable.0.0 1.0
ttable.1.1 1.0
ttable.0.2 1.0
ttable.1.3 1.0
}

pcm.stereo {
type plug
slave {
pcm multi
rate 48000
}
ttable.0.0 1.0
ttable.1.1 1.0
ttable.0.2 1.0
ttable.1.3 1.0
}

ctl.stereo {
type hw
card 0
}

pcm.multi {
type multi
slaves.a.pcm "analog-hw"
slaves.a.channels 2
slaves.b.pcm "digital-hw"
slaves.b.channels 2
bindings.0.slave a
bindings.0.channel 0
bindings.1.slave a
bindings.1.channel 1
bindings.2.slave b
bindings.2.channel 0
bindings.3.slave b
bindings.3.channel 1
}

ctl.multi {
type hw
card 0
}

Then set the Audio output device setting (in the General settings section of the frontend settings) to ALSA:multi (case sensitive). If you want to use AC3 passthrough, you should also set the passthrough device to ALSA:digital or ALSA:mixed-digital. If you leave it set to Default, you will hear horrible noise on your analog output. Note that this means that when you are watching a source that uses AC3 passthrough, you will hear nothing on your analog output.

If you connect the digital output (SPDIF) of your computer to your stereo, and the analog output to your television, this set-up allows you to listen to the audio of a program through both your stereo system and your television's speakers simultaneously, or to choose between the two simply by muting one.

More information about this is available from the knoppmyth wiki: http://knoppmythwiki.org/index.php?page=DigitalAudioHowTo

Questions and Answers

I get no sound from MythTV when watching TV but MythMusic and command-line test all work fine. What is the problem?

- Check to see if you have the "AC3 Passthrough to S/PDIF" option checked in Setup. This option is should only be enabled if your tuner hardware provides AC3 audio streams. If are not receiving AC3 audio streams from your tuner hardware and check this box, you will not get any sound. (see thread)

- Check your definition of the mixer device. If you're using ALSA:default for audio output, you should change the mixer device from "/dev/mixer" to "default". (from the Gentoo Linux Wiki)

But I want to have all my sound go to the S/PDIF connector, how do I do that?

It varies by hardware, but you should be able to set up your .asoundrc to route all PCM data (2-channel) to your S/PDIF connector. See above or here's a simple example:

pcm.!default { 
type hw 
card 0 
device 1 
} 

The card and device numbers are directly related to your hardware. My system has the following devices shown using aplay -l

card 0: YMF744 [Yamaha DS-XG PCI (YMF744)], device 1: YMFPCI - IEC958 
[YMFPCI - IEC958] 
Subdevices: 1/1 
Subdevice #0: subdevice #0 

In this scenario, you would set your MythTV audio device to /dev/adsp. You can also try typing in the audio device box `ALSA:default` or `ALSA:spdif` as appropriate for your hardware to try to utilize MythTV's internal ALSA support. In order to use this though, you need to have compiled MythTV with ALSA support.

How do I set up Myth plugins to use digital sound with mplayer?

Add the following to your mplayer lines in the setting dialog, substituting the device alias you wish to use.

-ao alsa:device=digital -afm hwac3

This will tell mplayer to send output audio to the digital device. It will pass ac3 or dts directly to hardware digital out. This allows you to watch dvds and videos with digital sound correctly, while still being able to watch those with mp3 audio without having to edit the command line.

How do I set up Myth plugins to use digital sound with xine?

As the mythtv user run xine. Open the Setup screen (alt+s or accessible with a mouse). Select the audio tab. Under speaker arrangement select Pass Through.

If this does not work open xine's Setup, on the gui tab change Configuration experience level to Master of the known universe and select Apply. Then select the audio tab and examine the device.alsa_passthrough_device setting.

How do I do this with a PVR-350?

The PVR-350 encodes the TV signal it receives from its built-in tuner or from its various audio and video inputs into MPEG-2 format and streams that output to MythTV which writes that stream into files. When MythTV plays back those MPEG-2 files, or any other MPG format file for that matter, it simply streams them them back to the PVR-350 and the PVR-350 decodes the audio and video and sends them out of its cables.

To get the audio produced by the PVR-350 many people take its audio outputs and use a cable to pipe them back into their sound card's Line In jack. If you're using the Line Out jack on your sound card to send analog audio to your amplifier, then all you need to do is unmute the Line In control in your audio mixer and set the volume. However, redirecting this output to the S/PDIF output in digital format requires a few more steps.

Important.png [Note: The names of the sound card controls used in the following command examples will vary depending on the audio device installed in your computer and the driver module it uses. The command “amixer” entered without any options will output all of the controls exposed for your audio device and “alsamixer” or your favorite graphical mixer program can also be used to manipulate these controls to make these settings.]

Set Line In as a capture source and mute it so that it doesn't go out the Line Out jack:

$ amixer set 'Line',0 0%,0% mute cap

Set Capture as a capture source:

$ amixer set 'Capture',0 0%,0% mute cap

Tell the sound card to turn on S/PDIF output:

$ amixer set 'IEC958',0 unmute

Tell the sound card to route analog input to the S/PDIF port:

$ amixer set 'IEC958 Playback Source',0 'Analog In'

This last setting needs to be toggled back and forth when you switch from watching TV, TV recordings and other MPG sources via the PVR-350 card to watching DVDs, videos and listening to music. All of the non-PVR audio is PCM audio, not analog. Switching back to PCM audio can be done with:

$ amixer set 'IEC958 Playback Source',0 'PCM'

If you like, you can set up a button on your remote to toggle this setting.

If your sound card does not allow you to set the "IEC958 Playback Source", or you want to avoid having to toggle this setting back and forth, then you need to find some other way to route the analog audio from the Line In jack to PCM audio. One technique would be to use the “arecord” and “aplay” commands to route the capture sources on the sound card back in as PCM audio:

$ arecord -D hw:0,0 -f dat | aplay -D mixed-digital

Important.png [Note: Fedora Core 5 users should leave off the “-D mixed-digital” portion of this command]

If you use this approach then you will probably want to execute this command at startup so that it is always running and available while the MythTV frontend is up. One way to do that would be to add it to a script in ~/.kde/Autostart (assuming that you're using the KDE desktop.) Ad a script containing this line or add it to a script that's already there:

$ arecord -D hw:0,0 -f dat | aplay -D mixed-digital &

The “&” at the end of the line causes this command to run in background so that the script can continue executing the rest of the commands that it contains.

Important.png [Note: Again, Fedora Core 5 users should leave out the “-D mixed-digital” portion of this command]

Note that this approach may not produce the best possible sound quality. Ths sound is going out of the PVR-350, back into the soundcard, being sampled by “arecord” and “aplay” and then sent out the S/PDIF to be converted back to analog by your apmlifier. If you have an optical interconnect between your MythTV frontend and your amplifier it may help reduce ground-loop hum though. On the other hand, this technique may introduce a time lag that causes your audio to be out of sync with the video when you watch TV.

Backing up your mixer settings

Once you have your audio configured to your liking you may way to capture a snapshot of the mixer configuration as a backup, just in case. The “alsactl” command can be used for this purpose. Running the following command as root will update the default profile. Some Linux distributions use this profile to save the current ALSA mixer settings during shutdown so that they can be restored during the next boot. This is often accomplished using settings in the modules configuration file (/etc/modprobe.conf in recent Redhat/Fedora distributions.)

$ /sbin/alsactl store 0

This command will save a copy of the current mixer settings in your home directory. (Substitute your MythTV user if you used something other than “mythtv”.)

$ /sbin/alsactl -f /home/mythtv/asound.backup store 0

This command will restore the settings you saved in your home directory. (Substitute your MythTV user if you used something other than “mythtv”.)

$ /sbin/alsactl -f /home/mythtv/asound.backup restore 0

How do I do this in KnoppMyth

KnoppMyth forum post

How do I do this in Fedora Core

http://www.mythtv.org/wiki/index.php/Configuring_Digital_Sound_with_AC3_and_SPDIF,