ALSA Multi-channel Audio mini-HOWTO


Last modified: Wed Apr 01 11:25:06 2009
Author: Uday Reddy <udayreddy () {gmail.com}>
French translation (Translated into French by Sylvio Desjardins)
Беларускі пераклад (Belarusian)


Creative Commons License

This work is licensed under a Creative Commons NonCommercial Sampling Plus 1.0 License.


NEW: Go here if you are looking for surround sound with PulseAudio (the new default audio layer with the latest Linux distributions)


DISCLAIMER: I am not responsible for any harm you cause to anything as a result of following this HOWTO.


This HOWTO is meant for those who want to setup 4.1 or 5.1 channel audio playback on their Linux machines, and make full use of all speakers for playback with different applications. Most of the information has been compiled from ALSA docs, ALSA Wiki FAQ, and man pages.sld Comments and questions are welcome.


You should have a 4.1 or 5.1 channel sound card or integrated on-board 4.1/5.1 channel support (like Intel ICH5 or higher), and 4.1/5.1/6.1 speakers (for eg., in case of 5.1 -- two front, two rear, one center, and a subwoofer). I assume that you have one of the later versions of ALSA installed (1.0.11 is the latest as of this writing), and that your sound card driver is installed. This should not be a problem if you are using a popular Linux distribution.

  1. Physical connections
  2. Editing ~/.asoundrc
  3. Setting default volumes
  4. Testing your setup
  5. Configuring applications
  6. References

1. Physical connections

You would have mostly done the physical connections correctly (with ports color-coded) as explained in your speaker manual. If you have a separate 5.1 channel sound card, you may have separate ports for front, rear, center/LFE, mike, etc. For most of the chips that come with on-board Intel ICH5 audio, the rear channels are shared with line-in, and mike with Center/LFE. The best way to set up your speakers would be to connect those shared ports to speakers, and use the front-panel ports for your mike and headphone.

2. Editing ~/.asoundrc

By default, you'll find that only your front speakers (2 out of 5.1) are being used whenever you play audio from xmms, MPlayer, or any other application (unless the audio is 5.1 encoded). You want output on all your speakers even for stereo audio; hence, this additional manual configuration. I hate to say this, but M$ Windows is far ahead in this aspect (you don't have to do anything other than specifying your speaker configuration, and 2-channel audio is automatically played on 5 speakers and 5-channel audio is played as it should be by WMP). If you have an Intel ICH5 audio card, you can put my .asoundrc in your home directory. Otherwise, the portion you need to append to your ~/.asoundrc is the following:

# for 5.1 speakers
pcm.ch51dup {
         slave.pcm surround51
         slave.channels 6
         type route
         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.0.5 0.5
         ttable.1.5 0.5
}

# for 4.1 speakers
pcm.ch41dup {
         type route
         slave.pcm surround41
         slave.channels 5
         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
}
            

The ALSA standard channel number assignments are: #0 - front left, #1 - front right, #2 - rear left, #3 - rear right, #4 - center, and #5 - LFE (subwoofer). In the above custom-created devices, we used ALSA's route plugin to copy front left and right channels to the corresponding rear channels, and create center and LFE each from 50% of left and right channels (TODO: the ideal way would be to use a low-pass filter to isolate low frequencies to send to the subwoofer, but this hadn't been possible till recently. Anyway, most subwoofers have a low-pass filter to ensure that high frequencies don't pass through and you may not notice a difference).

The channel mappings are sometimes messed up for some hardware; see end of Section 4 on how to fix that.

3. Setting default volumes

Append the following to your /etc/rc.local so that the right controls are unmuted and the volumes correctly set at boot time.

# vi /etc/rc.local 
... echo Setting 5.1 Channel volumes... amixer -q set Master 100% unmute amixer -q set PCM 40% unmute amixer -q set Surround 100% unmute amixer -q set "Surround Jack Mode" "Independent" amixer -q set Center 81% unmute amixer -q set LFE 100% unmute amixer -q set "Mic select" "Mic1" amixer -q set "Mic" 65% unmute amixer -q set "Channel mode" "6ch" amixer -q set "Center/LFE Down mix" mute amixer -q set "Duplicate Front" mute

For jack-sharing sound cards, use:

# vi /etc/rc.local
...
echo Setting 5.1 Channel volumes... 
amixer -q set Master 100% unmute  
amixer -q set PCM 40% unmute  
amixer -q set Surround 100% unmute  
amixer -q set Center 81% unmute  
amixer -q set LFE 100% unmute  
amixer -q set "Surround Jack Mode" "Shared"  
amixer -q set "Mic select" "Mic2"   
amixer -q set "Mic" 65% unmute  
amixer -q set "Channel mode" "6ch"   
amixer -q set "Center/LFE Down mix" mute   
amixer -q set "Duplicate Front" mute   
            

The convenient way of adjusting volume is to use the external nice control that came with your surround speakers. That would increase volume on all speakers proportionally. This is better than adjusting mixer controls separately. So, master is set to "100%", and you can adjust the proportion to what you feel is comfortable. For now, you can immediately run it as: . /etc/rc.local

4. Testing your setup

Make sure that you have run /etc/rc.local. The 'speaker-test' utility that comes with alsa-utils can be used to test your setup.

$ speaker-test -c 6 -D surround51 -t wav

speaker-test 1.0.11rc2

Playback device is surround51
Stream parameters are 48000Hz, S16_LE, 6 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 3 to 5461
Period size range from 3 to 5461
Periods = 4
Buffer time size 2525
To choose buffer_size = 5460
To choose period_size = 1365
was set period_size = 1365
was set buffer_size = 5460
0 - Front Left
4 - Center
1 - Front Right
3 - Rear Right
2 - Rear Left
5 - LFE
Time per period = 17.800086
            

You should hear noise one by one on all your speakers. A common issue with some ICH5 chips is that the Center and LFE channels are swapped with rear channels. To fix this, you'll have to edit a section of /etc/alsa/cards/ICH4.conf to make it like /etc/alsa/cards/ICH.conf. You can use my ICH4.conf. Also, some older versions of ALSA have a problem with the rear right channel; so upgrade in that case. Note the configuration file that you need to edit in your /etc/alsa/cards depends on your sound card; look under /proc/asound/ to figure this out.

To test your microphone, use Skype.

5. Configuring applications

We'll now configure commonly-used apps (XMMS, MPlayer, Xine, Gaim, beep-media-player) to make use of the ch51dup device to duplicate two channel output onto all your speakers and subwoofer.

For XMMS, go to Preferences -> Audio I/O plugins. Under "Output plugin", select "ALSA 1.2 output plugin", click 'Configure', and in the 'Audio device' field, enter "ch51dup" (or "ch41dup" in case of 4.1 speakers). Devices you created in .asoundrc are not enumerated here, so you have to manually enter it. Similar configuration can be done for beep-media-player. All two-channel encoded songs (MP3, WMA, etc. songs) will now play on all five speakers (Thanks to Eric Browne for pointing out a problem (possibly due to particular version combinations of xmms and ALSA libs?) while using ch51dup with xmms. In case xmms playback is choppy/stuttered, append this to your .asoundrc and use duplicate as your device instead of ch51dup).


For MPlayer, open ~/.mplayer/config, and put the following lines in it:

$ vi ~/.mplayer/config

ao=alsa:device=ch51dup
channels=6 

By default, MPlayer will now use the ch51dup device. However, if you want to play 5.1 channel encoded video with it (like DVDs), you'll have to use the default surround51 device, which you can by just invoking MPlayer as 'mplayer -ao alsa <filename-5.1-audio>. I don't know of a way to tell MPlayer to automatically choose a particular device based on the content being played. Xine would by default use the surround51 device for playing DVDs that are Dolby 5.1 encoded. So, you don't have to do anything there unless you play stereo files with it.

You may also want to change the mplayer plug-in configuration used for playing videos within browsers. As most of them have stereo audio, you may want to edit the audio output option line in /etc/mplayerplug-in.conf to make it use ch51dup.

# vi /etc/mplayerplug-in.conf

...
ao=alsa:device=ch51dup,oss,arts,esd
...
            

For gaim, go to Preferences->Sounds. Under 'Sound Method', choose 'Command' from the 'Method' drop-down list, and enter 'aplay -c 6 -r 44100 -D ch51dup' for 'Sound command'.


Comments, questions, and feedback by email are welcome.

References

  1. ALSA Wiki FAQ
  2. ALSA Surround Sound Wiki
  3. ALSA FAQ028
  4. MPlayer doc

Creative Commons License

This work is licensed under a Creative Commons NonCommercial Sampling Plus 1.0 License.


Average number of hits / day: 63
Total to-date: 400,972


Up to my home page