HOWTO_Surround_Sound
| Terminals / Shells • Network • X Window System • Portage • System • Filesystems • Kernel • Other |
Contents |
Setting up ALSA
First, set up ALSA using the Gentoo Linux ALSA Guide.
Surround Sound
Multi-channel PCM
Playback of multi-channel PCM is simple, if the Alsa driver supports 4 or 6 channel output then they are defined in ALSA-lib's configuration file (/etc/asound.conf) as surround51 (6 channel aka 5.1) and surround40 (4 channel aka 4.0). We simply pass surround51 or surround40 as the PCM name, and specify the number of channels to test: Use Ctrl+C to stop test.
speaker-test -D surround51 -c 6 -t wav
Remembering that surround51 and surround40 are analog, they cannot do any digital decoding or whatever.
Duplicating FL/FR on RL/RR
For lazy/pseudo 4 channel surround we can duplicate the sound from our front speakers on our rear speakers. If you didn't install alsa-utils from the guide, do it now. Fire up alsamixer...
alsamixer
and navigate right (using arrow keys) to the item "Duplicate Front", turn it on by pressing 'm'. Now navigate left to the item "Surround", make sure it turned on and the volume is adjusted to a practical level: 'Q' and 'Z' adjust the rear left speaker's volume up and down respectively, 'E' and 'C' for the right speaker and 'W' and 'X' adjust both.
Now all two-channel, stereo sound should play through four speakers.
Note that is highly dependent on what sound hardware you're using, as different drivers have different mixer controls. The control may be called something else, or it may not exist at all. If the latter is the case, you'll have to use a .asoundrc file similar to below.
Duplicating across all channels
To have the sound from mp3s and other stereo sources duplicated across all channels, not just front and rear,and using dmix, use a ~/.asoundrc file like this:
pcm.!dmix {
type dmix
ipc_key 1024
slave {
pcm "hw:0,0"
channels 6
period_size 512
buffer_size 1024
}
}
pcm.!default {
type plug
slave.pcm "dmix"
slave.channels 6
route_policy duplicate
}
This will make the sound come from your subwoofer as well as the smaller speakers in a 5.1 set. 5.1 streams are unaffected, IE work through default as well as surround51. If the sound messes up or doesn't work at all, try
replace : pcm "hw:0,0"
with : pcm {
type hw
card 0
device 0
}
or change these settings :
period_size 1024
buffer_size 8192 //use the biggest multiple of period_size you can here - I'm currently on 5120. I think this depends on your particular chip's abilities.
Remember to use alsamixer to unmute and turn up the volume on at least 'Master', 'PCM', 'Surround', 'Center' and 'LFE'; and also to change 'Channel' to 6ch from 2ch. Mute 'Duplicate'.
---
As far the config there didn't work for me, i tried to make another one for me, works great on the CA0106:
pcm.!dmix {
type plug
slave {
pcm surround51
channels 6
}
}
pcm.!default {
type plug
slave.pcm "dmix"
slave.channels 6
route_policy duplicate
}
its truely worth a try, if the other one doesnt work. the bad thing is, that dmix doesnt work after it, anyone a better solution?
This did not work on my ca0106, it complained about 0ms underrun, and when adding the period and buffer sizes, I get stereo audio with some warnings and no duplication. NOTE: This issue has been resolved by a newer version of the alsa-driver package, and this configuration works.
---
Using Surround Sound in OpenAL Applications
OpenAL is a cross-platform sound API that supports surround sound. To get OpenAL to use 4-channel sound by default, create a file in your home directory called .openalrc or use the global /etc/openalrc, and edit it as follows:
; Use ALSA (also valid: sdl, native) (define devices '(alsa)) ; Four speaker surround with ALSA (define speaker-num 4) (define alsa-out-device "surround40:0,0") ; For ALSA-in support (ie. voice chat) (define alsa-in-device "hw:0,0")
If you have a 5.1 speaker setup, change "speaker-num" to 6, and the "alsa-out-device" to "surround51:0,0". As always, you may have to replace "0,0" with the correct device and subdevice identifiers on your system. Most of the time "0,0" is correct.
Please note that surround51 and 6 channels is not always the correct choice. Unreal Tournament 2003 for example, reverts back to stereo when OpenAl is configured to use 6 channels on surround51 - it only works with 4 channels, because it uses old libraries. UT2004 can use 6 channels with the native libs.
It's possible that the game you're trying to get to work is shipped with an old or wrong version of the OpenAL lib, which causes surround sound not to work. This is the case for Unreal Tournament 2003 for example. To fix it, rename the original OpenAl lib in UT2003DIR/System and replace it with a symlink to the one in /usr/lib.
When Alsa doesn't detect channel as surround or with multiple cards
pcm.multi {
type multi;
slaves.b.pcm "hw:0,0";
slaves.b.channels 2;
slaves.c.pcm "hw:0,1";
slaves.c.channels 2;
slaves.d.pcm "hw:0,2";
slaves.d.channels 2;
bindings.0.slave b;
bindings.0.channel 0;
bindings.1.slave b;
bindings.1.channel 1;
bindings.2.slave c;
bindings.2.channel 0;
bindings.3.slave c;
bindings.3.channel 1;
bindings.4.slave d;
bindings.4.channel 0;
bindings.5.slave d;
bindings.5.channel 1;
}
pcm.!dmix {
type plug
slave {
pcm multi
channels 6
}
}
pcm.!default {
type plug
slave.pcm "dmix"
slave.channels 6
route_policy duplicate
}
I use this in my Sound Blaster because it don't identify as surrounded channels... Anyway if you have multiples cards you can make as one multiple channel card defining slaves.(b).pcm "hw:0,0"; remembering that hw:(card number),(hw channel number)
SPDIF w volume and surround
I used this asound.conf on my mythtv to get
- default everything goespdif out
- volume control of spdif within myth
- surround.
Granted it's not direct/passthrough DTS or Dolby surround, but if I want that I click 'passthrough' in myth setup and control volume from my receiver's remote. /etc/asound.conf
pcm.softvol {
type softvol
slave {
pcm
{
type route
slave.pcm "iec958"
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
}
}
control {
name "spdif" #set myth to use spdif volume control, default everything else
card 0
device 1
}
}
pcm.!default {
type plug
slave.pcm "softvol"
slave.rate 48000
}
External Links
- surround sound in Linux - Shows how to configure surround sound for watching movies and playing games.
Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.
