Difference between revisions of "Configuring Digital Sound"

From MythTV Official Wiki
Jump to: navigation, search
m (Setting up ALSA's .asoundrc, Properly)
m (Setting up ALSA's .asoundrc, Properly)
Line 57: Line 57:
  
 
##### DEVICE NAMES #####
 
##### DEVICE NAMES #####
 
 
# This configuration file defines four devices for use by the user.  Those
 
# This configuration file defines four devices for use by the user.  Those
 
# devices are "analog", "mixed-analog", "digital", and "mixed-digital".  The
 
# devices are "analog", "mixed-analog", "digital", and "mixed-digital".  The

Revision as of 18:17, 30 May 2006

Basics

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.

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. If you have additional information, please add it to the /External Links page.

ALSA Utilities

Don't forget that there are some utilities that are included in the alsa-utils package. Use your favorite RPM 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.

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.

If using AC-3/DTS passthrough, do not use the mixed-digital device. Use digital, instead.

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).

# ~/.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 "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
}

For a detailed description of how this ALSA configuration file works, see this post from the mailing list.

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 -ac hwac3,

This will tell mplayer to send output audio to the digital device. It will pass ac3 directly to hardware digital out, but the , on the end tells it to fail gracefully back to default pcm if there is no ac3 stream present. 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 do this with a PVR-350?

The PVR350 takes the tv signal from the air and picks out the sound and video. It then passes this to myth where it's written to an MPEG file. When it's played back myth passes the MPEG to the PVR350 and it decodes sound and video and send it out of it's cables.

Many people take the PVR sound and pipe it back into line-in where it passes through the card to it's outputs and onto the amp. OK, so we need to redirect this to the S/PDIF output, not the master output.

Although the FAQ, section 7.2 suggests

 amixer set Line,0 75%,75% mute captur

which sets lin-in to 75%, mute's it and marks it for capture then

 amixer set Capture,0 100%,100% mute captur

which I interpret as mute the capture channel (so it's not heard directly), listen to the capture input (line-in) at 100% and act as a capture device (so Myth can read it), further reading suggests that Myth doesn't do this for the PVRs - it just lets the line-in flow out of the master output.

I guess most people with a PVR350 have the line-in unmuted under alsamixer - and Myth controls the master volume thus allowing you to adjust the (analog) volume under mythtv.

It really doesn't matter what playback device you tell Myth to use... ALSA:default, /dev/dsp, /dev/null it won't pay the slightest bit of attention when using the PVR-350 hardware decoding.

However, once the hardware decoder outputs the audio signal, we must capture it with the sound card and output it to the cards digital output. To do this, run alsamixer, look for a control labeled, "Analog to IEC958 Output [Off]," and turn it on (by pushing the "m" key).

If your sound card does not support automatically passing analog input to digital output (via the "Analog to IEC958 Output" control), you need to find some other way of doing the same. What we need is something that can run in parallel that captures line-in and feeds it to the pcm output?

For now you can manually run this command whilst playing back nuvs with Myth:

arecord -D hw:0,0 -fdat | aplay -D mixed-digital 

which works for me --David Greaves

Note that this may not produce the best quality. Ths sound is going out of the PVR350, back into the soundcard, being sampled and then sent up the S/PDIF to be converted back to analog. If you have an optical interconnect it may help reduce ground-loop hum though. It also helps if all your other signals travel the s/pdif pathways and you don't have to keep switching inputs.

How do I do this in KnoppMyth

KnoppMyth forum post