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:

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

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

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.

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

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.

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:

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

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.

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

How do I get my mac mini SPDIF out working?

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:

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