ALSA upmixing
WORK IN PROGRESS! Not linked from anywhere, nobody panic.
This page will attempt to explain in relatively simple and straightforward terms how to use ALSA to upmix the stereo output from common audio sources to actually use all the speakers in a non-digital (4.1, 5.1, 7.1, etc.) configuration. The assumptions being made are that you will have ALSA sound modules installed have configured MythTV's Audio output device to "ALSA:default".
Most of the audio files people play with MythMusic and most broadcast SD television only carry a simple 2-channel stereo signal. ALSA, being somewhat literally-minded about sound playback, will quite merrily only send sound to your front left and right speakers, leaving the others completely unutilized. The process of making ALSA split up this stereo signal to be fed to the subwoofer (a.k.a. LFE) as well as the rear channels is called "upmixing".
The snippets of code mentioned here may be added to the ~/.asoundrc for the account the frontend is running as, or (if you're feeling frisky) to the global /etc/asound.conf file. You won't need to restart the frontend for changes to this file to take effect, but you will at least need to exit back to the main frontend menus to allow Myth to let go of the sound card and reinitialize it.
First we're going to cover some basic troubleshooting techniques for ALSA so that you can actually test the changes you make to know for sure that what you want is actually happening. I'm sure you're familiar with the alsamixer command, but the first thing you may wish to check on is that the Surround, Center, and LFE sliders (and any variations on that theme) are unmuted/up. If these are set to zero or muted, you won't get any sound out of those channels at all.
Testing to see if your speakers are plugged into the right ports and at least minimally functional on your sound card is actually very easy. ALSA ships with a `speaker-test` command which will send some output to each speaker briefly. This is an exceptionally useful tool because with some of the newest cards and many notebooks, the ALSA developers may not have yet had a chance to update/fix the driver to actually handle enabling routing to the output ports properly. With your speakers connected to the computer, turned on, and the volume set to a "reasonable" level, type the following command (hit ^C when you're done) and you'll hear a voice say the name of the front left and front right speakers, from each speaker.
speaker-test -c2 -twav -l1
The -l1 argument makes speaker-test run through the list of speakers once (don't specify -l at all and it will run over and over). The -twav argument makes it use a wav file of a female voice naming the outputs. If while you're doing a looping test her voice begins to annoy you (it does me after about a dozen repetitions) you can leave out -twav and speaker-test will use pink noise (somewhat like mild static) instead. The number after -c specifies the total number of speakers you have and we start with two because by default, that's all ALSA itself will be configured to test. Later you'll use -c6 if you have a 5.1 (two front, two rear, one center, and one subwoofer) speaker system, but you will need to know which PCM profile to use for output, which brings us to the next command...
If you invoke aplay with the -L argument, you will see a short list of the PCM outputs (ones useful to us have been highlighted below) which ALSA already knows about. Creating a new one for what we're about to do is not only unnecessary, but also beyond the scope of this document. Run `aplay -L` and examine your output carefully.
root@mythbox:~# aplay -L front:CARD=Live,DEV=0 SB Live 5.1 [SB0220], ADC Capture/Standard PCM Playback Front speakers rear:CARD=Live,DEV=0 SB Live 5.1 [SB0220], ADC Capture/Standard PCM Playback Rear speakers center_lfe:CARD=Live,DEV=0 SB Live 5.1 [SB0220], ADC Capture/Standard PCM Playback Center and Subwoofer speakers surround40:CARD=Live,DEV=0 SB Live 5.1 [SB0220], ADC Capture/Standard PCM Playback 4.0 Surround output to Front and Rear speakers surround41:CARD=Live,DEV=0 SB Live 5.1 [SB0220], ADC Capture/Standard PCM Playback 4.1 Surround output to Front, Rear and Subwoofer speakers surround50:CARD=Live,DEV=0 SB Live 5.1 [SB0220], ADC Capture/Standard PCM Playback 5.0 Surround output to Front, Center and Rear speakers surround51:CARD=Live,DEV=0 SB Live 5.1 [SB0220], ADC Capture/Standard PCM Playback 5.1 Surround output to Front, Center, Rear and Subwoofer speakers iec958:CARD=Live,DEV=0 SB Live 5.1 [SB0220], Multichannel Capture/PT Playback IEC958 (S/PDIF) Digital Audio Output null Discard all samples (playback) or generate zero samples (capture)
What each of these are for should be relatively self-explanatory.
OKay, so this section is basically teh suck at the moment and I will definitely come back and just explain how the ttable argument works so that people can construct their own.
# 2.0 to 4.0 simply mirrors the front speakers to the rear speakers. pcm.20to40 { type route slave.pcm surround51 slave.channels 6 ttable.0.0 1 ttable.1.1 1 ttable.0.2 1 ttable.1.3 1 } # 2.0 to 4.1 mirrors the front speakers to the rear speakers, and combines the two pcm.20to51 { type route slave.pcm surround51 slave.channels 6 ttable.0.0 1 ttable.1.1 1 ttable.0.2 1 ttable.1.3 1 ttable.0.4 0.5 ttable.1.4 0.5 }
pcm.20to50 { type route slave.pcm surround51 slave.channels 6 ttable.0.0 1 ttable.1.1 1 ttable.0.2 1 ttable.1.3 1 ttable.0.4 0.5 ttable.1.4 0.5 }
pcm.20to51 { type route slave.pcm surround51 slave.channels 6 ttable.0.0 1 ttable.1.1 1 ttable.0.2 1 ttable.1.3 1 ttable.0.4 0.5 ttable.1.4 0.5 ttable.1.5 0.5 ttable.0.5 0.5 }
pcm.20to71 { type route slave.pcm surround51 slave.channels 6 ttable.0.0 1 ttable.1.1 1 ttable.0.2 1 ttable.1.3 1 ttable.0.4 0.5 ttable.1.4 0.5 ttable.1.5 0.5 ttable.0.5 0.5 }
As a temporary measure to solve a problem this creates, below is a code fragment which you can put in /etc/asound.conf which creates a new master mixer element called 'SoftMaster'. The problem upmixing has is that an existing Master control typically only changes the volume of the front right and left outputs... so you have to make a new element that controls them all.
# Expand stereo to all channels including LFE pcm.20to51 { type route slave.pcm surround51 slave.channels 6 ttable.0.0 1 ttable.1.1 1 ttable.0.2 1 ttable.1.3 1 ttable.0.4 0.33 ttable.1.4 0.33 ttable.1.5 0.33 ttable.0.5 0.33 } # Create the SoftMaster mixer device that controls *all* channels pcm.!default { type softvol slave.pcm "20to51" control { name "SoftMaster" card 0 } }