Difference between revisions of "Configuring Digital Sound"

From MythTV Official Wiki
Jump to: navigation, search
m (Setting up mplayer for PulseAudio)
m (Updated PulseAudio Perfect Setup link)
 
(34 intermediate revisions by 14 users not shown)
Line 1: Line 1:
 +
{{Note box|Please note that the following information is mostly outdated and no longer relevant in mythtv 0.23 and later.}}
 +
 
== Basics ==
 
== Basics ==
 
[[Image:Audio.png]]MythTV 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.   
 
[[Image:Audio.png]]MythTV 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.   
Line 22: Line 24:
 
You need to be aware that ALSA by default will upsample all of your audio to 48 kHz. This keeps it compatible with TV broadcasts as well as Dolby Digital and DTS surround on DVDs. ALSA typically takes the sound from your content, routes it through a module called "plug" where this resampling takes place, and then routes it to a module called "dmix", a software mixer, before it outputs it to your SPDIF/iec958 connector.  
 
You need to be aware that ALSA by default will upsample all of your audio to 48 kHz. This keeps it compatible with TV broadcasts as well as Dolby Digital and DTS surround on DVDs. ALSA typically takes the sound from your content, routes it through a module called "plug" where this resampling takes place, and then routes it to a module called "dmix", a software mixer, before it outputs it to your SPDIF/iec958 connector.  
  
For Die hard Audiophiles, this resampling is a real source of irritation as CD audio is made using PCM at 44.1Khz. The upsampling in ALSA is unfortunately very low quality, and if you have a half decent amplifier and speakers, you will notice that CD playback has a congested compressed sound to it. This is very easy to overcome, by sending all your audio directly to your soundcards SPDIF or IEC958 Connector. The device name for this connector is typically "cards.pcm.iec958". So just configure this device as the audio device in MythTV.
+
For Die hard Audiophiles, this resampling is a real source of irritation as CD audio is made using PCM at 44.1 kHz. The upsampling in ALSA is unfortunately very low quality, and if you have a half decent amplifier and speakers, you will notice that CD playback has a congested compressed sound to it. This is very easy to overcome, by sending all your audio directly to your soundcards SPDIF or IEC958 Connector. The device name for this connector is typically "cards.pcm.iec958". So just configure this device as the audio device in MythTV.
  
 
On Mythfrontend Utilities/Setup->Setup-General  go to the Audio page and set your audio device as
 
On Mythfrontend Utilities/Setup->Setup-General  go to the Audio page and set your audio device as
Line 30: Line 32:
 
   Enable AC3 to SPDIF passthrough  check
 
   Enable AC3 to SPDIF passthrough  check
 
   Enable DTS to SPDIF passthrough  check
 
   Enable DTS to SPDIF passthrough  check
 +
  Use internal volume controls      uncheck
  
 
With most modern Linux distros there is not a need to mess around with the ALSA configuration files
 
With most modern Linux distros there is not a need to mess around with the ALSA configuration files
Line 35: Line 38:
 
Check your device names with
 
Check your device names with
  
   >aplay -L
+
   aplay -L
  
 
   iec958 'cards.pcm.iec958'
 
   iec958 'cards.pcm.iec958'
Line 53: Line 56:
 
== PulseAudio ==
 
== PulseAudio ==
  
Several Linux distros (Ubuntu, Fedora) now use [http://www.pulseaudio.org PulseAudio] per default.
+
Several Linux distros (Ubuntu, Fedora) now use [http://www.pulseaudio.org PulseAudio] per default. Support for PulseAudio was added in MythTV 0.23.
  
 
[http://www.pulseaudio.org/wiki/AboutPulseAudio PulseAudio] is a sound server, whose advantages are
 
[http://www.pulseaudio.org/wiki/AboutPulseAudio PulseAudio] is a sound server, whose advantages are
* [http://www.bucksch.org/xfer/songbird-pulse.png volume settings] (mixer) specific and stored per application
+
* [http://www.bucksch.org/1/misc/songbird-pulse.png volume settings] (mixer) specific and stored per application
 
* [http://0pointer.de/public/pavucontrol-move.png management] of all sound applications in one place using GUI tools
 
* [http://0pointer.de/public/pavucontrol-move.png management] of all sound applications in one place using GUI tools
 
* abstraction of hardware, including autodetection of soundcards via HAL, moving from one output to another without restarting the application and using multiple sound cards together to output more channels
 
* abstraction of hardware, including autodetection of soundcards via HAL, moving from one output to another without restarting the application and using multiple sound cards together to output more channels
* low latency
 
 
* and last but not least network transparency, i.e. sound output on different computer is possible.
 
* and last but not least network transparency, i.e. sound output on different computer is possible.
 +
Disadvantages are:
 +
* High latency, sound samples can take anywhere from half a second to 2 seconds longer to reach the sound card. Whilst this is faster than other sound servers it is unacceptably slow compared to direct interaction with alsa and can cause significant problems with video playback.
  
 
+
See also PulseAudio's website on [http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/PerfectSetup/ how to setup your computer and applications for PulseAudio].
See also PulseAudio's website on [http://www.pulseaudio.org/wiki/PerfectSetup how to setup your computer and applications for PulseAudio].
 
 
 
=== Setting up MythTV 0.21 for PulseAudio ===
 
 
 
# First off, of course test that your audio is working at all, e.g. using <code>speaker-test -c6 -t wav</code>. See also [[#Quick Check of Sound System]] below. If you can't hear anything, but get no errors, either, check with <code>alsamixer</code> that the volume is not 0 and PCM and Master and Front/Rear etc. are not muted.
 
# Install <i>libao-pulse</i> using your distro's package manager, if it is not already installed.
 
# Create the <code>~/.asoundrc</code> file listed below, in your home directory of the user that runs MythTV, e.g. <code>/home/mythtv/.asoundrc</code>. The first two sections create a virtual ALSA soundcard called "pulse", which sends all sound output to Pulse. Furthermore, the ALSA default soundcard is also defined to be the Pulse.
 
# Test the sound system again, via the same ALSA tools. Start <code>pavucontrol</code>, the Pulse Volume Control - it should now show the test application while it's running.
 
# In MythTV frontend, go to <i>Configuration</i> / <i>Basic settings</i> / <i>Audio</i> (3. page) and set the following options (and then press <i>Continue</i> until you're back in the menu):
 
## <i>Audio output device:</i> <b>ALSA:default</b> or <b>ALSA:pulse</b> (assuming you used the <code>.asoundrc</code> below) (required)
 
## <i>Use internal volume mixer:</i> <b>on</b> (= checked)
 
## <i>Mixer device:</i> <b>ALSA:default</b> (same as output device above) (required)
 
## <i>Mixer slider:</i> <b>Master</b> (required)
 
## '''TODO''' Using Master means that MythTV will change the <i>Sink</i>, the global volume for the sound card, affecting all applications. Not good. Using PCM would be better, but libao-pulse doesn't seem to emulate that.
 
# FYI, in my case, I have the following other settings:
 
## <i>Sound output to:</i> <b>Standard</b>
 
## <i>Aggressive sound buffering:</i> <b>off</b>
 
# Go into a save recording and test whether you hear sound. You should also be able to adjust the volume using your remote or keyboard, and see the MythTV volume slider, while a recording is playing.
 
# If you can start the Pulse Volume Control at the same time while playing a recording, you should see MythTV there as well (listed as <i>ALSA plug-in [mythtvfrontend]: ALSA playback</i>), with the same volume. The hardware volume setting (to be seen in <i>Sinks</i>), which is global for all apps, should remain the same.
 
 
 
 
 
<code>.asoundrc</code>:
 
<pre>
 
pcm.pulse {
 
    type pulse
 
}
 
ctl.pulse {
 
    type pulse
 
}
 
pcm.!default {
 
    type pulse
 
}
 
ctl.!default {
 
    type pulse
 
}
 
</pre>
 
 
 
'''TODO''': Dolby Digital / DTS pass-through untested, because I have no SPDIF setup.
 
 
 
=== Setting up MythTV SVN trunk with PulseAudio patch ===
 
 
 
There is a [http://svn.mythtv.org/trac/ticket/5473 patch under development] to add native PulseAudio support to MythTV. The advantages, among others, are that you don't need to set up the ALSA emulation like above, and that the Pulse Volume Control can show the title of currently running recording (TODO currently implemented?). Dolby Digital / DTS passthrough is maybe easier as well. The disadvantages are, apart from the obviously required compilation of MythTV and (re)application of the patch, that the patch still has problems: there are buffer overflows and underruns, loss of audio and high CPU usage.
 
 
 
=== Setting up mplayer for PulseAudio ===
 
 
 
In case you use mplayer for MythVideo:
 
 
 
mplayer in its current versions has native PulseAudio support. You configure it via either the
 
* commandline
 
*# Go to <i>Configuration</i> / <i>Media</i> / <i>Video</i> / <i>Playback</i>
 
*# In <i>Standard video player</i> (and <i>VCD playback command</i>), add <code>-ao pulse</code> to the end of the mplayer the commandline
 
* or mplayer configuration file
 
*# Create/edit file <code>~/.mplayer/config</code> in your home directory of the user running MythTV, e.g. <code>/home/mythtv/.mplayer/config</code>
 
*# Add the line: <code>ao=pulse</code>
 
 
 
Of course, to get remote control support in mplayer, you have to set that up as well.
 
  
 
== Quick Check of Sound System ==
 
== Quick Check of Sound System ==
  
You can use the following commands to test output is correct.
+
You can use [[Using ALSA's speaker-test utility|ALSA's speaker-test utility]] to perform output tests to determine if your speaker and sound configurations are correct and functioning properly.  A somewhat crude invocation to see if the system's default output configuration to a set of 5.1 surround sound speakers is working would be:
  
  speaker-test -c6 -t wav
+
speaker-test -twav -c6 -Dplug:surround51
  
 
Some receivers/sound devices may not properly play LPCM audio until this test is executed. Essentially it sets some state somewhere that allows LPCM to be passed to the receiver. At least this was the case on my receiver, an STR-DA3300ES Sony. Bitstreams worked fine, but LPCM would not work until I ran these speaker tests. There is probably more going on here but it won't hurt to run this test to initialize some state to make sure everything works.
 
Some receivers/sound devices may not properly play LPCM audio until this test is executed. Essentially it sets some state somewhere that allows LPCM to be passed to the receiver. At least this was the case on my receiver, an STR-DA3300ES Sony. Bitstreams worked fine, but LPCM would not work until I ran these speaker tests. There is probably more going on here but it won't hurt to run this test to initialize some state to make sure everything works.
Line 149: Line 97:
 
*test_ioctl
 
*test_ioctl
 
** Run as root.  Can unmute sound and increase volume.  Use -h for full usage information
 
** 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.
 
 
{{Note box|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 Device''' to '''default''' in the '''General''' settings section of the frontend settings.}}
 
 
{{Note box|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 Device''' 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 Device''' field using the device name, but without the "ALSA:" prefix.  Generally, you can use '''default''' for mixer device 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:
 
<pre>
 
aplay -D devicename /path/to/audio/file.au
 
</pre>
 
 
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).
 
{{Code box|~/.asoundrc|
 
<pre>
 
# ~/.asoundrc or /etc/asound.conf
 
# ALSA configuration file
 
 
##### USAGE #####
 
# Save this file as "~/.asoundrc" (for user-specific sound configuration) or
 
# "/etc/asound.conf" (for system-wide sound configuration) and specify ALSA
 
# device names ad described in the next section.
 
 
 
##### DEVICE NAMES #####
 
# This configuration file defines four devices for use by the user.  Those
 
# devices are "analog", "mixed-analog", "digital", and "mixed-digital".  The
 
# user may also re-define "default" to be identical to one of the above-named
 
# devices (i.e. to send all sound output to the digital output unless otherwise
 
# specified).  Use the device names as described below:
 
#  - "analog" outputs to the analog output directly and (at least on software
 
#  sound cards) blocks other audio output.  After playback completes, "queued"
 
#  sounds are output in sequence.
 
#  - "mixed-analog" mixes audio output from multiple programs into the analog
 
#  output (so you can hear beeps, alerts, and other noises while playing back
 
#  an audio stream).
 
#  - "digital" outputs to the digital output directly.  Since most (all?)
 
#  digital outputs expect 48kHz PCM audio, this may not work for some playback
 
#  (i.e. CD's--which are 44.1kHz PCM audio--or 32kHz audio streams from TV
 
#  recordings, etc.).
 
#  - "mixed-digital"
 
 
# All other devices created within this file are used only by the configuration
 
# file itself and should /not/ be used directly.  In other words, do not use
 
# the devices "analog-hw", "dmix-analog", "digital-hw", or "dmix-digital".
 
 
 
##### IMPORTANT #####
 
# To make this ALSA configuration file work with your sound card, you will need
 
# to define the appropriate card and device information for the "analog-hw" and
 
# "digital-hw" devices below.  You can find the card and device information
 
# using "aplay -l".
 
 
 
##### Configuration File #####
 
 
# Override the default output used by ALSA.  If you do not override the
 
# default, your default device is identical to the (unmixed) "analog" device
 
# shown below.  If you prefer mixed and/or digital output, uncomment the
 
# appropriate four lines below (only one slave.pcm line).
 
#
 
# Note, also, that as of ALSA 1.0.9, "software" sound cards have been modified
 
# such that their default "default" device is identical to the "mixed-analog"
 
# device.  Whether using an ALSA version before or after 1.0.9, it does no harm
 
# and has no affect on performance to redefine the device (even if the
 
# redefinition does not change anything).  Also, by using this ALSA
 
# configuration file, you once again have access to unmixed analog output using
 
# the "analog" device.
 
pcm.!default {
 
  type plug
 
## Uncomment the following to use (unmixed) "analog" by default
 
#  slave.pcm "analog-hw"
 
## Uncomment the following to use "mixed-analog" by default
 
  slave.pcm "dmix-analog"
 
## Uncomment the following to use (unmixed) "digital" by default
 
#  slave.pcm "digital-hw"
 
## Uncomment the following to use "mixed-digital" by default
 
#  slave.pcm "dmix-digital"
 
}
 
 
# Control device (mixer, etc.) for the card
 
ctl.!default {
 
  type hw
 
  card 0
 
}
 
 
# Alias for (converted) analog output on the card
 
# - This is identical to the device named "default"--which always exists and
 
# refers to hw:0,0 (unless overridden)
 
# - Therefore, we can specify "hw:0,0", "default", or "analog" to access analog
 
# output on the card
 
# - Note that as of ALSA 1.0.9, "software" sound card definitions redefine
 
# "default" to do mixing, meaning this device is different from "default" and
 
# allows playback while blocking other sound sources (until playback
 
# completes).
 
pcm.analog {
 
  type plug
 
  slave.pcm "analog-hw"
 
}
 
 
# Control device (mixer, etc.) for the card
 
ctl.analog {
 
  type hw
 
  card 0
 
}
 
 
# Alias for (converted) mixed analog output on the card
 
# - This will accept audio input--regardless of rate--and convert to the rate
 
# required for the dmix plugin (in this case 48000Hz)
 
# - Note that as of ALSA 1.0.9, "software" sound card definitions redefine
 
# "default" to do mixing, meaning this device is identical to "default" for
 
# "software" sound cards.
 
pcm.mixed-analog {
 
  type plug
 
  slave.pcm "dmix-analog"
 
}
 
 
# Control device (mixer, etc.) for the card
 
ctl.mixed-analog {
 
  type hw
 
  card 0
 
}
 
 
# Alias for (converted) digital (S/PDIF) output on the card
 
# - This will accept audio input--regardless of rate--and convert to the rate
 
# required for the S/PDIF hardware (in this case 48000Hz)
 
pcm.digital {
 
  type plug
 
  slave.pcm "digital-hw"
 
}
 
 
# Control device (mixer, etc.) for the card
 
ctl.digital {
 
  type hw
 
  card 0
 
}
 
 
# Alias for mixed (converted) digital (S/PDIF) output on the card
 
#  - This will accept audio input--regardless of rate--and convert to the rate
 
#  required for the S/PDIF hardware (in this case 48000Hz)
 
pcm.mixed-digital {
 
  type plug
 
  slave.pcm "dmix-digital"
 
}
 
 
# Control device (mixer, etc.) for the card
 
ctl.mixed-digital {
 
  type hw
 
  card 0
 
}
 
 
# The following devices are not useful by themselves.  They require specific
 
# rates, channels, and formats.  Therefore, you probably do not want to use
 
# them directly.  Instead use of of the devices defined above.
 
 
# Alias for analog output on the card
 
# Do not use this directly--it requires specific rate, channels, and format
 
pcm.analog-hw {
 
  type hw
 
  card 0
 
  # The default value for device is 0, so no need to specify
 
#  - Uncomment one of the below or create a new "device N" line as appropriate
 
#    for your sound card or
 
#  device 1
 
#  device 4
 
}
 
 
# Control device (mixer, etc.) for the card
 
ctl.analog-hw {
 
  type hw
 
  card 0
 
}
 
 
# Alias for digital (S/PDIF) output on the card
 
# Do not use this directly--it requires specific rate, channels, and format
 
pcm.digital-hw {
 
  type hw
 
  card 0
 
  device 1
 
#  - Comment out "device 1" above and uncomment one of the below or create a
 
#    new "device N" line as appropriate for your sound card or
 
#  device 2
 
#  device 4
 
}
 
 
# Control device (mixer, etc.) for the card
 
ctl.digital-hw {
 
  type hw
 
  card 0
 
}
 
 
# Direct software mixing plugin for analog output on the card
 
# Do not use this directly--it requires specific rate, channels, and format
 
pcm.dmix-analog {
 
  type dmix
 
  ipc_key 1234
 
  slave {
 
    pcm "analog-hw"
 
    period_time 0
 
    period_size 1024
 
    buffer_size 4096
 
    rate 48000
 
  }
 
}
 
 
# Control device (mixer, etc.) for the card
 
ctl.dmix-analog {
 
  type hw
 
  card 0
 
}
 
 
# Direct software mixing plugin for digital (S/PDIF) output on the card
 
# Do not use this directly--it requires specific rate, channels, and format
 
pcm.dmix-digital {
 
  type dmix
 
  ipc_key 1235
 
  slave {
 
    pcm "digital-hw"
 
    period_time 0
 
    period_size 1024
 
    buffer_size 4096
 
    rate 48000
 
  }
 
}
 
 
# Control device (mixer, etc.) for the card
 
ctl.dmix-digital {
 
  type hw
 
  card 0
 
}
 
</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.
 
 
If you would like simultaneous digital and analog output, add the following at the end of the above /etc/asound.conf or .asoundrc file:
 
 
<pre>
 
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
 
}
 
</pre>
 
 
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.
 
 
NOTES:  Works great from me set like this.  (FC 6, Myth 0.20 installed from RPMS). Everything goes to the right place.  In my case the analog sound to the TV is connected to my HTPC's "Front" output jacks, so I must set the '''Mixer Device''' (in the '''General''' settings section of the frontend settings) to '''default''', as above, and type "Front" into '''Mixer Controls''' so that Myth's volume control adjusts the proper channels.  Even though I am on FC 6, I ''am'' using both parts of the above  /etc/asound.conf.
 
 
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 ==
 
== Questions and Answers ==
Line 463: Line 105:
  
 
- 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 "ALSA:default". ([http://gentoo-wiki.com/HOWTO_Setup_MythTV#Audio from the Gentoo Linux Wiki])
 
- 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 "ALSA:default". ([http://gentoo-wiki.com/HOWTO_Setup_MythTV#Audio 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:
 
<pre>
 
pcm.!default {
 
type hw
 
card 0
 
device 1
 
}
 
</pre>
 
 
The card and device numbers are directly related to your hardware.  My system has the following devices shown using aplay -l
 
 
<pre>
 
card 0: YMF744 [Yamaha DS-XG PCI (YMF744)], device 1: YMFPCI - IEC958
 
[YMFPCI - IEC958]
 
Subdevices: 1/1
 
Subdevice #0: subdevice #0
 
</pre>
 
 
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? ===
 
=== How do I set up Myth plugins to use digital sound with mplayer? ===
Line 501: Line 122:
  
 
'''mplayer -ac hwac3,hwdts, -quiet %s'''
 
'''mplayer -ac hwac3,hwdts, -quiet %s'''
 
=== 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? ===
 
=== How do I do this with a PVR-350? ===
Line 551: Line 166:
 
<pre>$ /sbin/alsactl -f /home/mythtv/asound.backup restore 0</pre>
 
<pre>$ /sbin/alsactl -f /home/mythtv/asound.backup restore 0</pre>
  
=== How do I do this in KnoppMyth ===
+
=== How do I do this in KnoppMyth? ===
 
[http://mysettopbox.tv/phpBB2/viewtopic.php?t=1829 KnoppMyth forum post]
 
[http://mysettopbox.tv/phpBB2/viewtopic.php?t=1829 KnoppMyth forum post]
  
=== How do I do this in Fedora Core ===
+
=== How do I do this in Fedora Core? ===
 
[[Configuring Digital Sound with AC3 and SPDIF]]
 
[[Configuring Digital Sound with AC3 and SPDIF]]
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]
 
[[Category:Sound_cards]]
 
[[Category:Sound_cards]]
 +
 +
=== How do I get my mac mini SPDIF out working? ===
 +
 +
In Ubuntu 8.04, append this to /etc/modprobe.d/alsa-base:
 +
 +
  options snd-hda-intel model=macmini
 +
 +
Also read in mac mini ubuntu guide. [http://www.mythtv.org/wiki/Installing_MythTV_on_an_Intel_Mac_Mini_using_Ubuntu]
 +
 +
I also found that sometimes the SPDIF goes into a funky state and a reboot is the only thing that gets it out of this state. So if you think everything is right, but the sound just isn't working, try rebooting again.
 +
 +
=== How do I get 5.1 AC3 audio to work again? ===
 +
If your Dolby receiver once properly received 5.1 audio, but now just puts out loud static, an iec setting might have been changed. This fix should apply for pass-through AC3 and AC3 upconverting (stereo to 5.1 surround). The command line tool iecset will tell you the current settings:
 +
<pre>Mode: consumer
 +
Data: audio
 +
Rate: 48000 Hz
 +
Copyright: protected
 +
Emphasis: none
 +
Category: PCM coder
 +
Original: original
 +
Clock: 1000 ppm</pre>
 +
If you are feeding the receiver raw audio (PCM), then '<code>Data: audio</code>' is correct. However, if you are feeding it an encoded stream (Dolby AC3 or DTS), '<code>Data: non-audio</code>' is correct. To change it, type '<code>iecset audio on</code>' or '<code>iecset audio off</code>.'
 +
 +
However, usually you will want to go back and forth between sources. To enforce 'audio off' for AC3 stream, you can open your device with an AES parameter. To get this parameters, do 'iecset -x' after setting it up how you'd like. In this case, we're getting AC3 working again, so after turning audio off, <code>iecset -x</code> gives:
 +
<pre>AES0=0x02,AES1=0x82,AES2=0x00,AES3=0x02</pre>
 +
Add this to your device string under Setup->General->Audio System->Digital Output Device. For example, I have multiple digital cards and I want to use my INTEL card, so combining the output of '<code>aplay -L</code>' and '<code>iecset -x</code>' I use this as my Digital Output Device:
 +
<pre>ALSA:iec958:CARD=Intel,DEV=0,AES0=0x02,AES1=0x82,AES2=0x00,AES3=0x02</pre>
 +
My Audio Output Device is the same, up to the first AES setting (<code>ALSA:iec958:CARD=Intel,DEV=0</code>). I assume that if I had problems with direct PCM audio not working, I would want to use this as my Digital Audio Device string (AES0 is the only thing that changes):
 +
<pre>ALSA:iec958:CARD=Intel,DEV=0,AES0=0x00,AES1=0x82,AES2=0x00,AES3=0x02</pre>

Latest revision as of 23:56, 10 January 2016

Important.png Note: Please note that the following information is mostly outdated and no longer relevant in mythtv 0.23 and later.

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.

The default in modern Linux systems that use the 2.6 kernel is now ALSA. For MythTV installations it is advisable to turn off any sound servers that sit on top of ALSA such as Pulse Audio or the KDE or Gnome sound servers.

Bit Perfect Audio

Digital sound is the preferred method to get audio from a MythTV installation for two reasons

1. We want to have the audio decoding done outside of the computer for greater sound quality.

2. We want to play DVD with full surround sound using DTS or Dolby Digital.

You need to be aware that ALSA by default will upsample all of your audio to 48 kHz. This keeps it compatible with TV broadcasts as well as Dolby Digital and DTS surround on DVDs. ALSA typically takes the sound from your content, routes it through a module called "plug" where this resampling takes place, and then routes it to a module called "dmix", a software mixer, before it outputs it to your SPDIF/iec958 connector.

For Die hard Audiophiles, this resampling is a real source of irritation as CD audio is made using PCM at 44.1 kHz. The upsampling in ALSA is unfortunately very low quality, and if you have a half decent amplifier and speakers, you will notice that CD playback has a congested compressed sound to it. This is very easy to overcome, by sending all your audio directly to your soundcards SPDIF or IEC958 Connector. The device name for this connector is typically "cards.pcm.iec958". So just configure this device as the audio device in MythTV.

On Mythfrontend Utilities/Setup->Setup-General go to the Audio page and set your audio device as

 Audio output device        = ALSA:cards.pcm.iec958
 Passthrough outputdevice   = Alsa:iec958:{AES0 0x02}
 Enable AC3 to SPDIF passthrough   check
 Enable DTS to SPDIF passthrough   check
 Use internal volume controls      uncheck

With most modern Linux distros there is not a need to mess around with the ALSA configuration files

Check your device names with

  aplay -L
  iec958 'cards.pcm.iec958'
  spdif 'cards.pcm.iec958'

Don't forget to unmute your iec958 output using alsamixer. Now when you play a CD your amp should show PCM output at 44.1 kHz, and TV broadcasts as PCM at 48 kHz, and your DVDs will also have full blown surround.

Don't forget to rip your CDs using Lossless FLAC as the encoder (this is the default for the "Perfect" setting in the MythTV) will preserve the 44.1 kHz audio files from your CDs.

An option was added in version 0.22 (thread): if you're confident that ALSA isn't going to resample (twice) and have appropriate hardware, you can add a setting 'DisableResampler' with value 1 to the database. Otherwise the modern ALSA does software mixing by default and resamples to 48k before sending data to the card.

For the vast majority it's far better that we resample - SRC anywhere else in the chain (ALSA, card) would be done with a SNR much less than a *worst case* 97 dB..

echo "insert into settings values ('DisableResampler', 0, '<hostname of frontend>')" | mysql -u mythtv -p mythconverg

PulseAudio

Several Linux distros (Ubuntu, Fedora) now use PulseAudio per default. Support for PulseAudio was added in MythTV 0.23.

PulseAudio is a sound server, whose advantages are

  • volume settings (mixer) specific and stored per application
  • management of all sound applications in one place using GUI tools
  • abstraction of hardware, including autodetection of soundcards via HAL, moving from one output to another without restarting the application and using multiple sound cards together to output more channels
  • and last but not least network transparency, i.e. sound output on different computer is possible.

Disadvantages are:

  • High latency, sound samples can take anywhere from half a second to 2 seconds longer to reach the sound card. Whilst this is faster than other sound servers it is unacceptably slow compared to direct interaction with alsa and can cause significant problems with video playback.

See also PulseAudio's website on how to setup your computer and applications for PulseAudio.

Quick Check of Sound System

You can use ALSA's speaker-test utility to perform output tests to determine if your speaker and sound configurations are correct and functioning properly. A somewhat crude invocation to see if the system's default output configuration to a set of 5.1 surround sound speakers is working would be:

speaker-test -twav -c6 -Dplug:surround51 

Some receivers/sound devices may not properly play LPCM audio until this test is executed. Essentially it sets some state somewhere that allows LPCM to be passed to the receiver. At least this was the case on my receiver, an STR-DA3300ES Sony. Bitstreams worked fine, but LPCM would not work until I ran these speaker tests. There is probably more going on here but it won't hurt to run this test to initialize some state to make sure everything works.

 speaker-test -c2 --device cards.pcm.iec958 --rate 44100
 speaker-test -c2 --device cards.pcm.iec958 --rate 48000

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
  • alsaconf configures your sound device (run as root)
  • 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 (-L and -l) for listing ALSA devices which can be helpful
  • arecord
    • ALSA command-line sound player. Also has options (-L and -l) 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

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 "ALSA:default". (from the Gentoo Linux Wiki)

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.

An alternate Mplayer parameter list that can be used is:

-ac hwac3,hwdts,

Note the leading comma, this allow mplayer to fall back on audio codecs, from AC3, to DTS (if the file is DTS the mplayer lines at the beginning of this section will not work) if it is neither then the leading comma means it will fall back to default and play regularly (as in an mp3 avi file).

In mythtv, the final mplayer line would look something like this:

mplayer -ac hwac3,hwdts, -quiet %s

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 those generated by other PVR-x50 and similar cards, 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?

Configuring Digital Sound with AC3 and SPDIF

How do I get my mac mini SPDIF out working?

In Ubuntu 8.04, append this to /etc/modprobe.d/alsa-base:

 options snd-hda-intel model=macmini

Also read in mac mini ubuntu guide. [1]

I also found that sometimes the SPDIF goes into a funky state and a reboot is the only thing that gets it out of this state. So if you think everything is right, but the sound just isn't working, try rebooting again.

How do I get 5.1 AC3 audio to work again?

If your Dolby receiver once properly received 5.1 audio, but now just puts out loud static, an iec setting might have been changed. This fix should apply for pass-through AC3 and AC3 upconverting (stereo to 5.1 surround). The command line tool iecset will tell you the current settings:

Mode: consumer
Data: audio
Rate: 48000 Hz
Copyright: protected
Emphasis: none
Category: PCM coder
Original: original
Clock: 1000 ppm

If you are feeding the receiver raw audio (PCM), then 'Data: audio' is correct. However, if you are feeding it an encoded stream (Dolby AC3 or DTS), 'Data: non-audio' is correct. To change it, type 'iecset audio on' or 'iecset audio off.'

However, usually you will want to go back and forth between sources. To enforce 'audio off' for AC3 stream, you can open your device with an AES parameter. To get this parameters, do 'iecset -x' after setting it up how you'd like. In this case, we're getting AC3 working again, so after turning audio off, iecset -x gives:

AES0=0x02,AES1=0x82,AES2=0x00,AES3=0x02

Add this to your device string under Setup->General->Audio System->Digital Output Device. For example, I have multiple digital cards and I want to use my INTEL card, so combining the output of 'aplay -L' and 'iecset -x' I use this as my Digital Output Device:

ALSA:iec958:CARD=Intel,DEV=0,AES0=0x02,AES1=0x82,AES2=0x00,AES3=0x02

My Audio Output Device is the same, up to the first AES setting (ALSA:iec958:CARD=Intel,DEV=0). I assume that if I had problems with direct PCM audio not working, I would want to use this as my Digital Audio Device string (AES0 is the only thing that changes):

ALSA:iec958:CARD=Intel,DEV=0,AES0=0x00,AES1=0x82,AES2=0x00,AES3=0x02