gain [-e|-B|-b|-r] [-n] [-l|-h] [gain-dB]
Without other options, gain-dB is used to adjust the signal
power level by the given number of dB: positive amplifies
(beware of clipping), negative attenuates. With other options,
the gain-dB amplification or attenuation is (logically) applied
after the processing due to those options.
Given the -e option, the levels of the audio channels of a
multi-channel sample are "equalised", i.e. gain is applied to all
channels other than that with the highest peak level, such that
all channels attain the same peak level (but, without also giving
-n, the audio is not "normalised").
The -B (balance) option is similar to -e, but with -B, the RMS
level is used instead of the peak level. -B might be used to
correct stereo imbalance caused by an imperfect record turntable
cartridge. Note that unlike -e, -B might cause some clipping.
-b is similar to -B but has clipping protection, i.e. if necessary
to prevent clipping whilst balancing, attenuation is
applied to all channels. Note, however, that in conjunction
with -n, -B and -b are synonymous.
The -r option is used in conjunction with a prior invocation of
gain with the -h option - see below for details.
The -n option normalises the audio to 0dB FSD; it is often used
in conjunction with a negative gain-dB to the effect that the
audio is normalised to a given level below 0dB. For example:
gain -n |
normalises to 0dB, and
gain -n -3 |
normalises to -3dB.
The -l option invokes a simple limiter, e.g.
gain -l 6 |
will apply 6dB of gain but never clip. Note that limiting more than a few dBs more than occasionally (in a piece of audio) is not recommended as it can cause audible distortion. See the compand effect for a more capable limiter.
The -h option is used to apply gain to provide head-room for
subsequent processing. For example, with
gain -h bass +6 |
6dB of attenuation will be applied prior to the bass boosting
effect thus ensuring that it will not clip. Of course, with
bass, it is obvious how much headroom will be needed, but with
other effects (e.g. rate, dither) it is not always as clear.
Another advantage of using gain -h rather than an explicit
attenuation, is that if the headroom is not used by subsequent
effects, it can be reclaimed with gain -r, for example:
gain -h bass +6 rate 44100 gain -r |
The above effects chain guarantees never to clip nor amplify; it attenuates if necessary to prevent clipping, but by only as much as is needed to do so.
Output formatting (dithering and bit-depth reduction) also requires headroom (which cannot be "reclaimed"), e.g.
gain -h bass +6 rate 44100 gain -rh dither |
Here, the second gain invocation, reclaims as much of the headroom as it can from the preceding effects, but retains as much headroom as is needed for subsequent processing.
See also the norm and vol effects.