Difference between revisions of "Configuring Digital Sound"

From MythTV Official Wiki
Jump to: navigation, search
(Edit performed by mwstuffer.pl)
 
m (DigitalSoundHowTo moved to Configuring Digital Sound)
(No difference)

Revision as of 02:57, 2 December 2005

    1. language:en

Digital Sound Help Pages

[[Table Of Contents]]

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

Michael T. Dean wrote:

I'm trying to clear up all confusion on ALSA's .asoundrc and which ALSA device to use for S/PDIF output from Myth. The small posts I've made didn't seem to provide enough information, so I'm going all out on this one. That entails a lot of "how it works" and a very long--but very flexible--.asoundrc. (Oh, and by the way, thanks to those who asked these questions, I've finally cleared up _all_ my confusion about how to create a proper .asoundrc.  :)

A little bit ago Derek Watson wrote:

I struggled to work out what to put here also, but in the end discovered
that using -ac alsa9:nforce works nicely in mplayer, and ALSA:nforce
works in Myth. This is using the same mapping as you use below, and the
.asoundrc file that was posted to the list a while back.
 

Derek meant the .asoundrc posted by chua_kanteck and included here so we can pick it apart:

 pcm.nforce-hw {
 type hw
 card 0
 }

 pcm.!default {
 type plug
 slave.pcm "nforce"
 }

 pcm.nforce {
 type dmix
 ipc_key 1234
 slave {
 pcm "hw:0,2"
 period_time 0
 period_size 1024
 buffer_size 4096
 rate 44100
 }
 }

 ctl.nforce-hw {
 type hw
 card 0
 }

Derek continued:

However, now I have a problem in that the sample rate that my tv card is
using to capture audio (SAA7134) is 32kHz which the digital output
interface can't support (get a message saying requested 3200Hz, got
0Hz). I get no sound at all when using 48kHz - maybe the SAA7134 doesn't
support this audio sample rate?

Now, it may seem like I'm going on and on about this, but that's only because it seems my warnings are going unheeded--

*the dmix plugin is evil!!!* 

(Or, more precisely, dmix is evil when used incorrectly. Apologies to any ALSA developers for the drama. ;)

You'll notice that the .asoundrc above defines a virtual device (or "alias") called "nforce-hw" and another called "nforce". The "nforce-hw" device is connected directly to "hw:0,0" and the "nforce" device uses the dmix plugin to perform direct software mixing of audio streams (i.e. takes two inputs and provides one output), but it _only_ supports audio at a fixed frequency (by default 48000Hz) format (S16), channels (2), and period_time (125000) (see http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html#pcm_plugins_dmix ). However, by defining a slave device, one can modify these defaults. In the .asoundrc given, the modified frequency is 44100Hz--good for CD's. Unfortunately, bad for DVD's, bad for MythTV 32KHz channels, bad for MythTV 48KHz channels, bad for some Quick Time and some AVI files, etc. That's why your sound doesn't work with "ALSA:nforce"--the audio format is wrong.

Note that the .asoundrc also defines a virtual device called "default" (using pcm.!default to override the "default" definition of "default"). This device uses the "plug" (automatic conversion) plugin to automatically convert the sample rate, channels, and format as appropriate. chua_kanteck has, therefore, told ALSA that if no device is specified (or if a device named "default" is specified), it should use the plug plugin to convert the audio in for output on the S/PDIF device.

Assuming S/PDIF is on device 2 as above, you should be able to send a signal directly to the hardware by specifying "ALSA:hw:0,2" to Myth and "alsa9:hw:0,2" to MPlayer. Unfortunately, though, the signals are not necessarily the right format, so we'll need to do a conversion. Note, however, that on some nForce2 boards S/PDIF is device 1 (and possibly some other device). If this is the case with your board (run "aplay -l" to find out), replace all occurrences of "device 2" with "device 1" and (for completeness sake) all occurrences of "hw:0,2" in the comments with "hw:0,1".

Therefore, I recommend the following .asoundrc. Feel free to change the alias names (note that spdif--among other names--is reserved, though). I used analog, mixed-analog, digital, and mixed-digital because they aren't reserved, they don't have special characters, and they're descriptive. If using multiple sound cards, you might want to add something to specify that this is nForce analog, etc.

To use the .asoundrc below with Myth, specify "ALSA:analog" for analog output, "ALSA:digital" for S/PDIF output, "ALSA:mixed-analog" for software-mixed analog output, or "ALSA:mixed-digital" for software-mixed S/PDIF output. (this is in the Myth -> Settings -> General and usually says /dev/dsp. You need to highlight this and then type in the value, it's not in the list of dropdowns.) You will also need to set the mixer field. You type this in without the ALSA:. Example, you can use mixed-analog. The mixed output will allow you to hear sounds generated by other programs using the mixed output device on your Myth box while watching TV, DVD's, etc. The non-mixed output will block other sounds so you won't be interrupted by beeps, clicks, etc. while watching a recording--but, unfortunately, after the recording finishes (and the ALSA device is released), the other sounds--having been queued up--will play back one after the other (it's not a pleasant sound, and is often much louder than the recording). Note, also, that the rate conversion to 48000Hz used by the mixed output may affect the audio quality (especially for low-bitrate audio).

Note that I've included a control device (ctl.name) for each virtual device. The standard way to find a control device is to prepend "ctl." to the audio device name, so we define one just in case an application tries to find the control device. Most of the time, this is unnecessary since your program won't access the control device--especially on the devices you won't use directly--but when using certain programs (like JACK, for example) a control device is required, so it makes sense to define one and doesn't hurt to define one even for the devices you won't use directly.

Finally, I included a commented out section that allows you to change the default output device used by ALSA. Uncomment the definition of "pcm.!default" at the top of the file, but be sure to only uncomment one "slave.pcm" line (i.e. uncomment four lines).

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/Silly Sounds/english.au and you can hear Linus pronounce Linux (from 1994).

HTH.

Mike

The (I hope it's the definitive) .asoundrc for nForce2 and nForce4

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

# Alias for analog output on the nForce2/4 (hw:0,0)
# - 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 nForce2/4
pcm.analog {
 type plug
 slave.pcm "analog-hw"
}

# Control device (mixer, etc.) for the nForce2 card
ctl.analog {
 type hw
 card 0
}

# Alias for (rate-converted) mixed analog output on the
# nForce2 (hw:0,0)
#  - This will accept audio input--regardless of rate--and
# convert to the rate required for the dmix plugin
# (in this case 48000Hz)
pcm.mixed-analog {
 type plug
 slave.pcm "dmix-analog"
}

# Control device (mixer, etc.) for the nForce2 card
ctl.mixed-analog {
 type hw
 card 0
}

# Alias for (rate-converted) digital (S/PDIF) output on the
# nForce2 (hw:0,2)
#  - 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 nForce2 card
ctl.digital {
 type hw
 card 0
}

# Alias for mixed (rate-converted) digital (S/PDIF) output on the
# nForce2/4 (hw:0,2)
#  - 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 nForce2 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 nForce2 (hw:0,0)
# 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
}

# Control device (mixer, etc.) for the nForce2/4 card
ctl.analog-hw {
 type hw
 card 0
}

# Alias for digital (S/PDIF) output on the nForce2/4 (hw:0,2)
# Do not use this directly--it requires specific rate,
# channels, and format
pcm.digital-hw {
 type hw
 card 0
 device 2
}

# Control device (mixer, etc.) for the nForce2/4 card
ctl.digital-hw {
 type hw
 card 0
}

# Direct software mixing plugin for analog output on
# the nForce2/4 (hw:0,0)
# 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 nForce2/4 card
ctl.dmix-analog {
 type hw
 card 0
}

# Direct software mixing plugin for digital (S/PDIF) output
# on the nForce2/4 (hw:0,2)
# 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 nForce2/4 card
ctl.dmix-digital {
 type hw
 card 0
}

Questions and Answers

I get no sound from MythTv when watching TV but Myth Music 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)

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 PVR350?

If you have an nForce soundcard then thank Michael again:

Run alsamixer, look for a control labeled, "Analog to IEC958 Output [Off]," and turn it on (by pushing the "m" key). 

With an onboard Via soundchip it seems harder...

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 a nuv file. When it's played back myth passes the nuv 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 seem to matter what playback device you tell Myth to use... ALSA:default, /dev/dsp, /dev/null it won't pay the slightest bit of attention.

What we need is something that can run in parallel that captures line-in and feeds it to the pcm output? (which, depending on .asoundrc will be spdif or analog?) Maybe this can be put into Myth one day?

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.

Category How To