Alright, so you ponied-up and purchased a nice 5.1 soundsystem– you’re the man now dog. You hook that bad-boy up to your new HDMI-capable receiver and you’re ready to take your beast new soundsystem for it’s maiden voyage through the frequencies of your favorite song from the Mary Poppins soundtrack ohh what’s the name of that track– Ohhh yea “Spoonful of Sugar” in crisp 6-channel sound. You finally sit down and hit “play” only to find that the sound is all messed up! Sounds that should be coming out of the center channel are instead coming out of your left rear speaker and your right rear speaker is for some strange reason acting as your subwoofer. This is clearly one of those god damn you Linux moments.I mean don’t get me wrong, I love Linux but it’s the kind of love that’s filled with moments of utter hatred– so really like pretty-much all forms of love I guess.
So, how do we fix this. The answer is simple use PulseAudio.
Background on PulseAudio:
PulseAudio as I understand it (and this is an understanding based on tinkering and usage… not research) basically rides on top of the lower-level sound program called Alsa. Alsa used to handle all your audio needs by itself before PulseAudio came out… the reason PulseAudio was developed however is because Alsa has very few options and can’t handle much configuration for advanced behavior such as turning down the volume for individual applications or having several computers all using the speakers of one computer over a network connection in a client/server model of audio playback. Because of the evolving needs of the userbase and the limited ability of Alsa to accomodate those needs, PulseAudio was born.
People LOVE to hate on PulseAudio because back in the day it used to be filled with tons of bugs and knowledge/familiarity with it was low as it was the new kid on the linux-audio block; however since those days PulseAudio has matured ten fold and is pretty-much the galactic standard for audio in modern linux distributions… including of course Ubuntu. Ubuntu comes by default using PulseAudio so we don’t need to install any fancy schmancy new programs here– just modify the configuration we already have.
In order to fix this problem we’re going to need to make use of PulseAudio’s “module-remap-sink” functionality.
Module-remap-sink (or “remap-sink” for the rest of this post) will basically allow us to remap individual channels to send them to their proper speaker. The first step here is to build a channel-map to guide you in the process and help you keep your head on straight.
A great command to help you setup your channel-map is:
$speaker-test -c6 -l1 -twav
Speaker-test will generate a voice which tells you what each speaker presently maps to, a very helpful command that is included in all of the Ubuntu derivatives.
Left Front ————-> Left Front
From the channel-map we created above, we can see that two of the 6 channels are just fine– so we need to re-map the other four. In order to do this we’re going to need to modify two files, the “/etc/pulse/default.pa” file and the “/etc/pulse/system.pa” file. Let’s open both of those files up with your favorite text editor.
In both files we’re going to comment-out the following code as indicated:
### Automatically load driver modules depending on the hardware available .ifexists module-udev-detect.so load-module module-udev-detect .else ### Alternatively use the static hardware detection module (for systems that ### lack udev support) load-module module-detect .endif
### Automatically load driver modules depending on the hardware available .ifexists module-udev-detect.so #load-module module-udev-detect .else ### Alternatively use the static hardware detection module (for systems that ### lack udev support) #load-module module-detect .endif
At this point we’re going to save the changes in the “system.pa” file and close it. Now the rest of the changes are to occur in the “default.pa” file which has already been slightly modified as mentioned above.
Adding the following lines to the “/etc/pulse/default.pa” will make these re-mappings global for the entire system. If you only wanted to make these channel-remappings for your user you could add them to the “/home/*your_username*/.pulse/default.pa” file instead.
Now let’s use the remap-sink to modify the four channels that are not mapped properly. Modify the following three lines to fit your situation and add them to the “default.pa” file.
# Definition of standard sink
load-module module-alsa-sink sink_name=standard device=hw:0 channels=6 channel_map=front-left,front-center,front-right,rear-left,rear-right,subwoofer
# Remapping Function
load-module module-remap-sink sink_name=remapped_sound master=standard channels=6 master_channel_map=front-left,front-center,front-right,rear-left,rear-right,subwoofer channel_map=front-left,rear-left,front-right,front-center,rear-right,subwoofer
# Setting Default to your new re-mapped sink
# (should match the "sink_name" in line 2)
The first line is a definition of the standard/existing sink. The second line references that definition in both the “master” and “master_channel_map” variables. The second line above is the one that actually handles the remapping. Read the blurb from PulseAudio.org below which defines the “master_channel_map” variable in the second line for a better understanding.
The channels in the master sink, where the channels listed in channel_map will be relayed to. channel_map and master_channel_map must have equal number of channels listed, because the channels will be mapped based on their position in the list, i.e. the first channel in channel_map will be relayed to the first channel in master_channel_map and so on.”
Left Front ————–> Left Front
So the channels (in the order they are listed) in “master_channel_map” will map onto the channels (in the order they are listed) of “channel_map”. Sort of like the channel-map we drew out above except with different titles on the columns… make sense? I hope so.
Once you’ve added those two lines to the “/etc/pulse/default.pa” file you can save the changes and restart PulseAudio with the commands below:
$sudo /etc/init.d/pulseaudio restart
Perhaps the method above is a bit overkill but I like to be positive.
From here you should be able to load “gnome-volume-control” on the terminal and see that under the “Hardware” tab you have a new device that you are able to select that relates to the new remapped sink you just created. Select that device (if it isn’t selected already) and let’s take those new speakers for another test drive. I recommend re-running the speaker-test command to double-check everything.
$speaker-test -c6 -l1 -twav
Hope this tutorial worked out for you, if it didn’t or if something could be improved feel free to throw it in the comments!