2.3.2 Audio output devices

2.3.2.1 Audio/Video synchronisation

MPlayer's audio interface is called libao2. It currently contains these drivers:

oss
OSS (ioctl) driver (supports hardware AC3 passthrough)
sdl
SDL driver (supports ESD, ARTS etc)
nas
NAS (Network Audio System) driver
alsa5
native ALSA 0.5 driver
alsa9
native ALSA 0.9 driver (supports hardware AC3 passthrough)
sun
SUN audio driver (/dev/audio) for BSD and Solaris8 users
arts
native ARTS driver (mostly for KDE users)
esd
native ESD driver (mostly for GNOME users)

Fact is, Linux sound card drivers have compatibility problems. The cause is that MPlayer uses a feature that well coded audio drivers implement to maintain audio/video sync. Regrettably, some driver authors do not care about this function, it is not needed for playing MP3s or for sound effects.

Other media players like aviplay or xine possibly work out-of-the-box with these drivers because they use "simple" methods with internal timing. A note: time showed their methods aren't AS efficient as MPlayer's.

With a correctly written audio driver MPlayer will never create audio related A/V desynchronisation, unless your file is badly broken. Some options to work around these problems are described in the man page).

If you happen to have a bad audio driver, try the -autosync option, it should sort out your problems. See the man page for detailed information.

Some notes:

On Solaris, use the SUN audio driver with the -ao sun option, otherwise neither video nor audio will work.

2.3.2.2 Sound Card experiences, recommendations

VIA onboard chipset (via82cxxx) 48kHz only
Driver: from the gkernel project
Aureal Vortex 2
    OSS:no driver
OSS/Pro:OK
ALSA:no driver
Max kHz:48
Driver:aureal.sourceforge.net
Driver2: from Pontscho's page (buffer size increased to 32k)
GUS PnP
OSS:no driver
OSS/Pro:OK
ALSA:OK
Max kHz:48
SB Live!
OSS:Analog OK, SP/DIF not working
ALSA:Both OK
Max kHz:192
SB AWE 64
OSS:max 44kHz
ALSA:48kHz sounds bad
Max kHz:48
Gravis UltraSound ACE
OSS:not OK
ALSA:OK
Max kHz:44
Gravis UltraSound MAX
OSS:OK
ALSA:OK (?)
Max kHz:48
ESS 688
OSS:OK
ALSA:OK (?)
Max kHz:48
C-Media cards (which ones?)
OSS:not OK (hissing) (?)
ALSA:OK (?)
Max kHz:?
Yamaha cards (*ymf*)
OSS:not OK (?) (maybe -ao sdl)
ALSA:OK only with ALSA 0.5 with OSS emulation AND -ao sdl (!) (?)
Max kHz:?
Cards with envy24 chips (like Terratec EWS88MT)
OSS:?
OSS/Pro:OK
ALSA:?
Max kHz:?
PC Speaker or DAC
OSS:OK (Use the SDL driver: -ao sdl)
ALSA:no driver
Max kHz:The driver emulates 44.1, maybe more.
Driver:ftp://ftp.infradead.org/pub/pcsp

On Linux, a 2.4.x kernel is highly recommended. Kernel 2.2 is not tested.

If the sound clicks when playing from CD-ROM, turn on IRQ unmasking, e.g. hdparm -u1 /dev/cdrom (man hdparm). This is generally beneficial and described in more detail in the CD-ROM section.

Feedback to this document is welcome. Please tell us how MPlayer and your sound card(s) worked together.

2.3.2.3 Audio filters

The old audio plugins have been superseded by a new audio filter layer. Audio filters are used for changing the properties of the audio data before the sound reaches the sound card. The activation and deactivation of the filters is normally automated but can be overridden. The filters are activated when the properties of the audio data differ from those required by the sound card and deactivated if unnecessary. The -af filter1,filter2,... switch is used to override the automatic activation of filters or to insert filters that are not automatically inserted. The filters will be executed as they appear in the comma separated list.

Example:
  mplayer -af resample,pan movie.avi

would run the sound through the resampling filter followed by the pan filter. Observe that the list must not contain any spaces, else it will fail.

The filters often have switches that change their behavior. These switches are explained in detail in the sections below. A filter will execute using default settings if its switches are omitted. Here is an example of how to use filters in combination with filter specific switches:

  mplayer -af resample=11025,pan=1:0.5:0.5 -channels 1 -srate 11025 media.avi

would set the output frequency of the resample filter to 11025Hz and downmix the audio to 1 channel using the pan filter.

Most filters respond to the -v switch, which makes the filters print out status messages.

The overall execution of the filter layer is controlled using the -af-adv switch. This switch has two suboptions:

force
is an integer between 0 and 3 that controls how the filters are inserted and what speed/accuracy optimizations they use:
0
Use automatic insertion of filters and optimize according to CPU speed.
1
Use automatic insertion of filters and optimize for the highest speed. If this option is set the processing of the audio data will be done using fix point arithmetics. Warning: Some features in the audio filters will silently fail, and the sound quality may drop.
2
Use automatic insertion of filters and optimize for quality. If this option is set the processing of the audio data will be done using floating point instructions and is therefore quite CPU intensive, but gives a lot higher sound quality than fix point processing.
3
Use no automatic insertion of filters and no optimization. Warning: It may be possible to crash MPlayer using this setting.
list
is an alias for the -af switch.
2.3.2.3.1 Up/Down-sampling

MPlayer fully supports sound up/down-sampling. This filter can be used if you have a fixed frequency sound card or if you are stuck with an old sound card that is only capable of max 44.1kHz. This filter is automatically enabled if it is necessary, but it can also be explicitly enabled on the command line. It has three switches:

srate
is an integer used for setting the output sample frequency in Hz. The valid range for this parameter is 8kHz to 192kHz. If the input and output sample frequency are the same or if this parameter is omitted the filter is automatically unloaded. A high sample frequency normally improves the audio quality, especially when used in combination with other filters.
sloppy
is an optional binary parameter that allows the output frequency to differ slightly from the frequency given by srate. This switch can be used if the startup of the playback is extremely slow.
fast
is an optional binary parameter that enables linear interpolation as resampling method. Linear interpolation is extremely fast, but suffers from poor sound quality especially when used for up-sampling.

Example:
  mplayer -af resample=44100:0:1

would set the output frequency of the resample filter to 44100Hz using exact output frequency scaling and linear interpolation.

2.3.2.3.2 Changing the number of channels

The channels filter can be used for adding and removing channels, it can also be used for routing or copying channels. It is automatically enabled when the output from the audio filter layer differs from the input layer or when it is requested by another filter. This filter unloads itself if not needed. The number of switches is dynamic:

nch
is an integer between 1 and 6 that is used for setting the number of output channels. This switch is required, leaving it empty results in a runtime error.
nr
is an integer between 1 and 6 that is used for specifying the number of routes. This parameter is optional. If it is omitted the default routing is used.
from1:to1:from2:to2:from3:to3...
are pairs of numbers between 0 and 5 that define where each channel should be routed.

If only nch is given the default routing is used, it works as follows: If the number of output channels is bigger than the number of input channels empty channels are inserted (except mixing from mono to stereo, then the mono channel is repeated in both of the output channels). If the number of output channels is smaller than the number of input channels the exceeding channels are truncated.

Example 1:
  mplayer -af channels=4:4:0:1:1:0:2:2:3:3 media.avi

would change the number of channels to 4 and set up 4 routes that swap channel 0 and channel 1 and leave channel 2 and 3 intact. Observe that if media containing two channels was played back, channels 2 and 3 would contain silence but 0 and 1 would still be swapped.

Example 2:
  mplayer -af channels=6:4:0:0:0:1:0:2:0:3 media.avi

would change the number of channels to 6 and set up 4 routes that copy channel 0 to channels 0 to 3. Channel 4 and 5 will contain silence.

2.3.2.3.3 Sample format converter

This filter is a sample format converter. It is automatically enabled when needed by the sound card or another filter.

bps
can be 1, 2 or 4 and denotes the number of bytes per sample. This switch is required, leaving it empty results in a runtime error.
f
is a text string describing the sample format. The string is a concatenated mix of: alaw, mulaw or imaadpcm, float or int, unsigned or signed, le or be (little or big endian). This switch is required, leaving it empty results in a runtime error.

Example:
  mplayer media.avi -af format=4:float

would set the output output format to 4 bytes per sample floating point data.

2.3.2.3.4 Delay

This filter delays the sound to the loudspeakers in order to make the sound in the different channels arrive at the same time to the listening position. It is only useful if you have more than 2 loudspeakers. This filter has a variable number of parameters:

d1:d2:d3...
are floating point numbers representing the delays in ms that should be imposed on the different channels. The minimum delay is 0ms and the maximum is 1000ms.

To calculate the required delay for the different channels do as follows:

  1. Measure the distance to the loudspeakers in meters in relation to your listening position, giving you the distances s1 to s5 (for a 5.1 system). There is no point in compensating for the sub-woofer (you will not hear the difference anyway).
  2. Subtract the distances s1 to s5 from the maximum distance i.e.
    s[i] = max(s) - s[i]; i = 1...5
  3. Calculated the required delays in ms as
    d[i] = 1000*s[i]/342; i = 1...5

Example:
  mplayer -af delay=10.5:10.5:0:0:7:0 media.avi

would delay front left and right by 10.5ms, the two rear channels and the sub by 0ms and the center channel by 7ms.

2.3.2.3.5 Software volume control

This filter is a software volume control. Use this filter with caution since it can reduce the signal to noise ratio of the sound. In most cases it is best to set the level for the PCM sound to max, leave this filter out and control the output level to your speakers with the master volume control of the mixer. If there is an external amplifier connected to the computer (this is almost always the case), the noise level can be minimized by adjusting the master level and the volume knob on the amplifier until the hissing noise in the background is gone. This filter has two switches:

v
is a floating point number between -200 and +60 which represents the volume level in dB. The default level is -10dB.
c
is a binary control that turns soft clipping on and off. Soft-clipping can make the sound more smooth if very high volume levels are used. Enable this switch if the dynamic range of the loudspeakers is very low. Be aware that this feature creates distortion and should be considered a last resort.

Example:
  mplayer -af volume=10.1:0 media.avi

would amplify the sound by 10.1dB and hard-clip if the sound level is too high.

This filter has a second feature: It measures the overall maximum sound level and prints out that level when MPlayer exits. This volume estimate can be used for setting the sound level in MEncoder such that the maximum dynamic range is utilized.

2.3.2.3.6 Equalizer

This filter is a 10 octave band graphic equalizer, implemented using 10 IIR band pass filters. This means that it works regardless of what type of audio is being played back. The center frequencies for the 10 bands are:

Band No.Center frequency
031.25 Hz
162.50 Hz
2125.0 Hz
3250.0 Hz
4500.0 Hz
51.000 kHz
62.000 kHz
74.000 kHz
88.000 kHz
916.00 kHz

If the sample rate of the sound being played back is lower than the center frequency for a frequency band, then that band will be disabled. A known bug with this filter is that the characteristics for the uppermost band are not completely symmetric if the sample rate is close to the center frequency of that band. This problem can be worked around by up-sampling the sound using the resample filter before it reaches this filter.

This filter has 10 parameters:

g1:g2:g3...g10
are floating point numbers between -12 to +12dB representing the gain in dB for each frequency band.

Example:
  mplayer -af equalizer=11:11:10:5:0:-12:0:5:12:12 media.avi

would amplify the sound in the upper and lower frequency region while canceling it almost completely around 1kHz.

2.3.2.3.7 Panning filter

This filter can be used for mixing the channels arbitrarily. It is basically a combination of the volume control and the channels filter. There are two major uses for this filter:

  1. Down-mixing many channels to only a few, stereo to mono for example.
  2. Varying the "width" of the center speaker in a surround sound system.

This filter is hard to use, and will require some tinkering before the desired result is obtained. The number of switches for this filter depends on the number of output channels:

nch
is an integer between 1 and 6 and is used for setting the number of output channels. This switch is required, leaving it empty results in a runtime error.
l00:l01:l02:..l10:l11:l12:...ln0:ln1:ln2:...
are floating point values between 0 and 1. l[i][j] determines how much of input channel j is mixed into output channel i.

Example:
  mplayer -af pan=1:0.5:0.5 -channels 1 media.avi

would down-mix from stereo to mono.

Note: Audio plugins have been deprecated by audio filters and will be removed soon.

2.3.2.4 Audio plugins (deprecated)

MPlayer has support for audio plugins. Audio plugins can be used for changing the properties of the audio data before the sound reaches the sound card. They are enabled using the -aop switch which takes a list=plugin1,plugin2,... argument. The list argument is required and determines which plugins should be used and in which order they should be executed. Example:

  mplayer media.avi -aop list=resample,format

would run the sound through the resampling plugin followed by the format plugin.

The plugins can also have switches that change their behavior. These switches are explained in detail in the sections below. A plugin will execute using default settings if its switches are omitted. Here is an example of how to use plugins in combination with plugin specific switches:

  mplayer media.avi -aop list=resample,format:fout=44100:format=0x8

would set the output frequency of the resample plugin to 44100Hz and the output format of the format plugin to AFMT_U8.

Currently audio plugins can not be used in MEncoder.

2.3.2.4.1 Up/Downsampling

MPlayer fully supports up/downsampling of the sound. This plugin can be used if you have a fixed frequency sound card or if you are stuck with an old sound card that is only capable of max 44.1kHz. Whether is usage of this plugin is necessary or not, is autodetected. This plugin has one switch: fout which is used for setting the desired output sample frequency. It defaults to 48kHz, and is given in <Hz>.

Usage:
  mplayer media.avi -aop list=resample:fout=<required frequency in Hz, like 44100>

Note that the output frequency should not be scaled up from the default value. Scaling up will cause the audio and video streams to be played in slow motion in addition to audio distortion.

2.3.2.4.2 Surround Sound decoding

MPlayer has an audio plugin that can decode matrix encoded surround sound. Dolby Surround is an example of a matrix encoded format. Many files with 2 channel audio actually contain matrixed surround sound. To use this feature you need a sound card supporting at least 4 channels.

Usage:
  mplayer media.avi -aop list=surround

2.3.2.3.3 Sample format converter

If your sound card driver does not support signed 16bit int data type, this plugin can be used to change the format to one which your sound card can understand. It has one switch, format, which can be set to one of the numbers found in libao2/afmt.h. This plugin is hardly ever needed and is intended for advanced users. Keep in mind that this plugin only changes the sample format and not the sample frequency or the number of channels.

Usage:
  mplayer media.avi -aop list=format:format=<required output format>

2.3.2.4.4 Delay

This plugin delays the sound and is intended as an example of how to develop new plugins. It can not be used for anything useful from a users perspective and is mentioned here for the sake of completeness only. Do not use this plugin unless you are a developer.

2.3.2.4.5 Software volume control

This plugin is a software replacement for the volume control, and can be used on machines with a broken mixer device. It can also be used if one wants to change the output volume of MPlayer without changing the PCM volume setting in the mixer. It has one switch volume that is used for setting the initial sound level. The initial sound level can be set to values between 0 and 255 and defaults to 101 which equals 0dB amplification. Use this plugin with caution since it can reduce the signal to noise ratio of the sound. In most cases it is best to set the level for the PCM sound to max, leave this plugin out and control the output level to your speakers with the master volume control of the mixer. If there is an external amplifier connected to the computer (this is almost always the case), the noise level can be minimized by adjusting the master level and the volume knob on the amplifier until the hissing noise in the background is gone.

Usage:
  mplayer media.avi -aop list=volume:volume=<0-255>

This plugin also has compressor or "soft-clipping" capabilities. Compression can be used if the dynamic range of the sound is very high or if the dynamic range of the loudspeakers is very low. Be aware that this feature creates distortion and should be considered a last resort.

Usage:
  mplayer media.avi -aop list=volume:softclip

2.3.2.4.6 Extrastereo

This plugin (linearly) increases the difference between left and right channels (like the XMMS extrastereo plugin) which gives some sort of "live" effect to playback.

Usage:
  mplayer media.avi -aop list=extrastereo
  mplayer media.avi -aop list=extrastereo:mul=3.45

The default coefficient (mul) is a float number that defaults to 2.5. If you set it to 0.0, you will have mono sound (average of both channels). If you set it to 1.0, sound will be unchanged, if you set it to -1.0, left and right channels will be swapped.

2.3.2.4.7 Volume normalizer

This plugin maximizes the volume without distorting the sound.

Usage:
  mplayer media.avi -aop list=volnorm