3.10. Channel manipulation

3.10.1. General information

Unfortunately, there is no standard for how channels are ordered. The orders listed below are those of AC-3 and are fairly typical; try them and see if your source matches. Channels are numbered starting with 0.

mono

  1. center

stereo

  1. left

  2. right

quadraphonic

  1. left front

  2. right front

  3. left rear

  4. right rear

surround 4.0

  1. left front

  2. right front

  3. center rear

  4. center front

surround 5.0

  1. left front

  2. right front

  3. left rear

  4. right rear

  5. center front

surround 5.1

  1. left front

  2. right front

  3. left rear

  4. right rear

  5. center front

  6. subwoofer

The -channels option is used to request the number of channels from the audio decoder. Some audio codecs use the number of specified channels to decide if downmixing the source is necessary. Note that this does not always affect the number of output channels. For example, using -channels 4 to play a stereo MP3 file will still result in 2-channel output since the MP3 codec will not produce the extra channels.

The channels audio filter can be used to create or remove channels and is useful for controlling the number of channels sent to the sound card. See the following sections for more information on channel manipulation.

3.10.2. Playing mono with two speakers

Mono sounds a lot better when played through two speakers - especially when using headphones. Audio files that truly have one channel are automatically played through two speakers; unfortunately, most files with mono sound are actually encoded as stereo with one channel silent. The easiest and most foolproof way to make both speakers output the same audio is the extrastereo filter:

mplayer filename -af extrastereo=0

This averages both channels, resulting in both channels being half as loud as the original. The next sections have examples of other ways to do this without a volume decrease, but they are more complex and require different options depending on which channel to keep. If you really need to maintain the volume, it may be easier to experiment with the volume filter and find the right value. For example:

mplayer filename -af extrastereo=0,volume=5

3.10.3. Channel copying/moving

The channels filter can move any or all channels. Setting up all the suboptions for the channels filter can be complicated and takes a little care.

  1. Decide how many output channels you need. This is the first suboption.

  2. Count how many channel moves you will do. This is the second suboption. Each channel can be moved to several different channels at the same time, but keep in mind that when a channel is moved (even if to only one destination) the source channel will be empty unless another channel is moved into it. To copy a channel, keeping the source the same, simply move the channel into both the destination and the source. For example:

    channel 2 --> channel 3
    channel 2 --> channel 2

  3. Write out the channel copies as pairs of suboptions. Note that the first channel is 0, the second is 1, etc. The order of these suboptions does not matter as long as they are properly grouped into source:destination pairs.

Example: one channel in two speakers

Here is an example of another way to play one channel in both speakers. Suppose for this example that the left channel should be played and the right channel discarded. Following the steps above:

  1. In order to provide an output channel for each of the two speakers, the first suboption must be "2".

  2. The left channel needs to be moved to the right channel, and also must be moved to itself so it won't be empty. This is a total of two moves, making the second suboption "2" as well.

  3. To move the left channel (channel 0) into the right channel (channel 1), the suboption pair is "0:1", "0:0" moves the left channel onto itself.

Putting that all together gives:

mplayer filename -af channels=2:2:0:1:0:0

The advantage this example has over extrastereo is that the volume of each output channel is the same as the input channel. The disadvantage is that the suboptions must be changed to "2:2:1:0:1:1" when the desired audio is in the right channel. Also, it is more difficult to remember and type.

Example: left channel in two speakers shortcut

There is actually a much easier way to use the channels filter for playing the left channel in both speakers:

mplayer filename -af channels=1

The second channel is discarded and, with no further suboptions, the single remaining channel is left alone. Sound card drivers automatically play single-channel audio in both speakers. This only works when the desired channel is on the left.

Example: duplicate front channels to the rear

Another common operation is to duplicate the front channels and play them back on the rear speakers of a quadraphonic setup.

  1. There should be four output channels. The first suboption is "4".

  2. Each of the two front channels needs to be moved to the corresponding rear channel and also to itself. This is four moves, so the second suboption is "4".

  3. The left front (channel 0) needs to moved to the left rear (channel 2): "0:2". The left front also needs to be moved to itself: "0:0". The right front (channel 1) is moved to the right rear (channel 3): "1:3", and also to itself: "1:1".

Combine all the suboptions to get:

mplayer filename -af channels=4:4:0:2:0:0:1:3:1:1

3.10.4. Channel mixing

The pan filter can mix channels in user-specified proportions. This allows for everything the channels filter can do and more. Unfortunately, the suboptions are much more complicated.

  1. Decide how many channels to work with. You may need to specify this with -channels and/or -af channels. Later examples will show when to use which.

  2. Decide how many channels to feed into pan (further decoded channels are discarded). This is the first suboption, and it also controls how many channels to employ for output.

  3. The remaining suboptions specify how much of each channel gets mixed into each other channel. This is the complicated part. To break the task down, split the suboptions into several sets, one set for each input channel. Each suboption within a set corresponds to an output channel. The number you specify will be the percentage of the input channel that gets mixed into the output channel.

    pan accepts values from 0 to 512, yielding 0% to 51200% of the original volume. Be careful when using values greater than 1. Not only can this give you very high volume, but if you exceed the sample range of your sound card you may hear painful pops and clicks. If you want you can follow pan with ,volume to enable clipping, but it is best to keep the values of pan low enough that clipping is not necessary.

Example: one channel in two speakers

Here is yet another example for playing the left channel in two speakers. Follow the steps above:

  1. pan should output two channels, so the first suboption is "2".

  2. Since we have two input channels, there will be two sets of suboptions. Since there are also two output channels, there will be two suboptions per set. The left channel from the file should go with full volume to the new left and the right channels. Thus the first set of suboptions is "1:1". The right channel should be discarded, so the second would be "0:0". Any 0 values at the end can be left out, but for ease of understanding we will keep them.

Putting those options together gives:

mplayer filename -af pan=2:1:1:0:0

If the right channel is desired instead of the left, the suboptions to pan will be "2:0:0:1:1".

Example: left channel in two speakers shortcut

As with channels, there is a shortcut that only works with the left channel:

mplayer filename -af pan=1:1

Since pan has only one channel of input (the other channel is discarded), there is only one set with one suboption, which specifies that the only channel gets 100% of itself.

Example: downmixing 6-channel PCM

MPlayer's decoder for 6-channel PCM is not capable of downmixing. Here is a way to downmix PCM using pan:

  1. The number of output channels is 2, so the first suboption is "2".

  2. With six input channels there will be six sets of options. Fortunately, since we only care about the output of the first two channels, we only need to make two sets; the remaining four sets can be omitted. Beware that not all multichannel audio files have the same channel order! This example demonstrates downmixing a file with the same channels as AC-3 5.1:

    0 - front left
    1 - front right
    2 - rear left
    3 - rear right
    4 - center front
    5 - subwoofer

    The first set of suboptions lists the percentages of the original volume, in order, which each output channel should receive from the front left channel: "1:0". The front right channel should go into the right output: "0:1". The same for the rear channels: "1:0" and "0:1". The center channel goes into both output channels with half volume: "0.5:0.5", and the subwoofer goes into both with full volume: "1:1".

Put all that together, for:

mplayer 6-channel.wav -af pan=2:1:0:0:1:1:0:0:1:0.5:0.5:1:1

The percentages listed above are only a rough example. Feel free to tweak them.

Example: Playing 5.1 audio on big speakers without a subwoofer

If you have a huge pair of front speakers you may not want to waste any money on buying a subwoofer for a complete 5.1 sound system. If you use -channels 5 to request that liba52 decode 5.1 audio in 5.0, the subwoofer channel is simply discarded. If you want to distribute the subwoofer channel yourself you need to downmix manually with pan:

  1. Since pan needs to examine all six channels, specify -channels 6 so liba52 decodes them all.

  2. pan outputs to only five channels, the first suboption is 5.

  3. Six input channels and five output channels means six sets of five suboptions.

    • The left front channel only replicates onto itself: "1:0:0:0:0"

    • Same for the right front channel: "0:1:0:0:0"

    • Same for the left rear channel: "0:0:1:0:0"

    • And also the same for the right rear channel: "0:0:0:1:0"

    • Center front, too: "0:0:0:0:1"

    • And now we have to decide what to do with the subwoofer, e.g. half into front right and front left: "0.5:0.5:0:0:0"

Combine all those options to get:

mplayer dvd://1 -channels 6 -af pan=5:1:0:0:0:0:0:1:0:0:0:0:0:1:0:0:0:0:0:1:0:0:0:0:0:1:0.5:0.5:0:0:0