Hack14.Surround Yourself with Sound


Hack 14. Surround Yourself with Sound

Get theater-quality sound out of your multi-speaker setup.

When you've invested a lot of money in your audio and speaker setup, you want to make sure you get the most out of it. Don't settle for basic stereo soundmake your bass go boom boom, your center channel speak, and your rear speakers provide ambience. Under Windows, configuring this is often quite easy, as the soundcard manufacturer usually provides a program to enable surround sound, but no such software exists for Linux, so you need to go a more manual route. This hack will show you how to enable surround sound, test it, and use it with MPlayer [Hack #48].

For this hack to work, you need a soundcard that supports more than just stereo output and, of course, multiple speakers. The ideal setup, and the one I am targeting in this hack, is what is known as "5.1 surround sound." This means you have a pair of front speakers, a pair of rear speakers, a center channel speaker, and a subwoofer. As you can see, this is 5 speakers plus a .1 for the subwoofer. (Just to confuse things, some settings will call this a 6 channel configuration.) Here is what you can expect out of each speaker:


Front right and left

These two speakers provide basic stereo output. Most music CDs are designed to output stereo sound, which means these two speakers are all that is required to have an enjoyable music listening experience. Though adequate for listening to a DVD, you'll miss out on many positional effects (the placement of sounds so that it seems as if they are coming from specific places, both on and off screen). When your system is configured for 5.1 surround sound, these speakers will provide the bulk of your nonspeaking sound.


Subwoofer

The job of the subwoofer is to output low frequency soundjust how low depends upon the quality of your subwoofer. With a subwoofer added to your setup, your other speakers are relieved of the duty of producing low bass sounds. This is good, because those speakers aren't really designed for that type of output, and they'll sound better because they will only be playing the audio they can handle well. Bass output is nondirectional, so it doesn't matter where you place the subwoofer: you should still be able to hear and feel its effects. When the subwoofer is combined with just the front right and left speakers, it is known as 2.1 surround sound.


Center

This speaker mostly outputs the dialogue track from a DVD. Having speech come from a speaker underneath or on top of the monitor "centers" the voices to the images and prevents the odd effect in which dialogue doesn't seem to be coming from the actors' mouths, but rather someplace offstage. During loud action sequences with no speech, the center is sometimes used to enhance the overall fullness of the sound to further immerse you in the action.


Rear right and left

These speakers are used for off-stage and ambient sound. For example, if the movie scene has an actor being chased by a car, these speakers output the sounds of the car when it is behind the actor. Or if it is raining outside, these speakers output the rain audio to make you feel as if it is raining all around you instead of just in front of you. Scene music is often sent to these speakers as well, to more fully immerse you in the action. It may seem as if these speakers only have a supporting role in your audio setup, but think about it this way: is a movie itself any good without a supporting cast?

I tested this using nForce4 integrated sound and Logitech X-530 5.1 speaker set. The nForce4 sound is provided by the Intel8x0 Alsa driver, which is commonly used in many integrated solutions, so the instructions I give here should work without modification on many setups. I'm going to assume you already have basic audio working. (This is typically not a problem with most modern Linux distributions.) You'll also need to follow your speaker installation instructions and make sure you have each of the cables plugged into the correct outputs.

2.3.1. Configuring Your Mixer

[Hack #13] provided a basic introduction to the concept of audio mixers that control the volume levels of your audio outputs. For this hack you are going to use the alsamixer command-line mixer, because it is very straightforward to use. You should find each of the options I'll describe here in the KDE (kmix) and GNOME (gnome-alsamixer) equivalents, but the settings may be in non-obvious places in the program. To get started, run this command inside a terminal:

 $ alsamixer 

This opens an ncurses-based mixer program that you can control with your keyboard. The left and right arrows will move you to the different options, the up and down arrows control the volume or settings of that option, pressing M toggles the muting of that channel, and Esc quits and saves your changes. If you already have basic sound working, then your Master and PCM channels are already unmuted and their volume set.

In this program you need to set volume levels for the other speaker channels as well as tell the mixer how you want audio sent to the various speakers.

Using the alsamixer options for my nForce4 Intel8x0 based soundcard as a basis, here are the settings you want to configure:


Center and LFE

Unmute and set volumes levels for these two channels. Center obviously controls your center channel speakers, whereas LFE controls your low frequencies, so it determines output levels to your subwoofer.


Surround

There are two options for this. The first sets the volume levels for the rear speakers. The second controls how independently the center and rear speakers work. By default this set to Shared, but for movie watching, you should set it to Independent.


Channels

This option, which you have to scroll to the right to see, tells Alsa how many speakers you have. Set to 6 for 5.1. Most programs I use still need to be explicitly told how many speakers I have, so I've not found this option to be particularly meaningful. Perhaps in the future.


Duplicate front

When this option is unmuted, it duplicates the output sent to the front pair of speakers to the rear. This is useful when listening to stereo music if you want output from all of your speakers, but it is not desirable when movie watching. Keep this muted to ensure the rear speakers receive independent audio signals.

These settings provide the basic foundation for 5.1 audio. These settings should exist for any soundcard that supports surround sound, but I can't guarantee the option labels will remain the same.

2.3.2. Testing Surround Sound

When first playing with surround sound, it's useful to test speaker output using an audio file that sends audio to each speaker in turn. You can obtain such a file from ftp://ling.lll.hawaii.edu/pub/greg/Surround-SDL-testfiles.tgz. Download and unpack this file:

 $ wget ftp://ling.lll.hawaii.edu/pub/greg/Surround-SDL-testfiles.tgz    $ tar -xvzf Surround-SDL-testfiles.tgz 

In the expanded directory you'll find a few WAV files that have multichannel output. My personal favorite is chan-id.wav, which when played speaks the name of each channel in the appropriate speakerprovided, of course, that everything is configured correctly. To test, use this command:

 $ aplay -Dsurround51 chan-id.wav 

This command uses the Alsa aplay player to send output to each channel in turn. If you don't specify -Dsurround51, you will only get stereo output. You know everything is working correctly if you hear a woman's voice announcing each speaker channel in the appropriate speaker. If this doesn't happen for you, then go back to alsamixer and see if you missed anything.

I've noticed a few oddities with this test. For example, when I run it on my Mandriva machine with the previous command, everything works correctlyexcept my subwoofer delivers a muffled and jumbled "rear rear left right," and the rear channel speakers then give their identification correctly. The command's text output suggests that I run the command this way:

 $ aplay -Dplug:surround51 chan-id.wav 

When I do this, the front and center speakers work as they should, but I get no other output from my other speakers except for the rear right, which states the jumbled "rear rear left right." None of this turns out to matter. As long as you do get the front and center speakers to announce themselves correctly, and you hear something out of the rear speakers, surround sound should work with MPlayer.

2.3.3. Movie Watching

The real reason for surround sound is to create a near theater experience when movie watching. This section covers configuring MPlayer for surround sound. As you may recall from "Use MPlayer" [Hack #48], the mplayer command for viewing a DVD is simply:

 $ mplayer dvd:// 

Go to a scene with dialogue. Pay careful attention to which speaker the dialogue is coming out of. It will most likely be the left and right front speakers. Is any background sound coming from the rear speakers? Probably not. When you launch mplayer this way, the center and rear speakers remain silent. You have to tell mplayer that you have a multi-speaker setup like this:

 $ mplayer -channels 6 dvd:// 

Again, listen to a scene with dialogue and listen for background sound from the rear speakers. In my setup, my center channel is still muted, but I hear sound and dialogue from my rear speakers. The problem here is that we haven't told mplayer what sound system to use. This is done with a simple addition to the command:

 $ mplayer -ao alsa -channels 6 dvd:// 

Now, go to the same scenes as before. If everything is configured correctly in alsamixer, you should hear most of your sound coming from the front left and right speakers, dialogue coming from the center speaker, ambient sounds from the rear speakers, and, if you're watching explosions, then a nice boom boom from your subwoofer.

While performing your tests, you may find it useful to add the -ss nn option to your mplayer command. This skips forward the specified number of seconds so you can always start playing at a scene that lets you test both the rear- and center-channel speakers.


Specifying these settings each time you run MPlayer can be annoying. To get around this, add the options to your ~/.mplayer/config file like so:

 # Write your default config options here! ao=alsa channels=6 

As you can see, each option is identical to what you type at the command line, minus the preceding dash and converting the space to an equal sign.

If you use a GUI frontend to mplayer, it will probably provide its own preference option to enable surround sound, so check those settings if the ones in your configuration file don't work.

David Brickner




Linux Multimedia Hacks
Linux Multimedia Hacks
ISBN: 596100760
EAN: N/A
Year: 2005
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net