HOW TO
make a

DIGITAL LIMITER


preface

The following is based on Peter Falkner's thesis "Entwicklung eines digitalen Stereo-Limiters mit Hilfe des Signalprozessors DSP56001" .

As the thesis' title indicates, Falkner developed a digital stereo-limiter based on a digital signal-processor by Motorola.
Since now personal computers are much more powerful than they were when Falkner wrote his thesis, it is nowadays more or less quite useless to use a highly specialised DSP for signal processing, in fact a normal PC will surely do.

Therefore this howto is written to give anyone interested some insight in programming his own limiter/compressor module; for those who are not willing or able to do it themselves I have added example sources for use with a real-time music system called puredata.


what for ?

If analogue audio-signals are processed and these signals are driving the processing units into saturation because of being too high-levelled, these units won't work properly, but will generate a more or less distorted signal. Because of the properties of analogue units, this distortion will normally be harmonic and therefore, although annoying, often acceptable (for example, if you think of distortion- and fuzz-boxes which are often applied, for example, on guitars in popular music (e.g. rock-music), then you will even find it great).

If digital signals are processed, these overdrive-effects do not drive any processing units into saturation (because of the completely different idea of handling signals this is simply not possibly), instead, if the maximum elongation of a signal exceeds the maximum possible value of the processing unit, this unit will output a highly inharmonically distorted signal that depends mainly on the way, the processing unit is treating such over-drives. It may be, that the output signal is set to zero, to the maximum value or that overflow (wrap) effects appear. Because of the inharmonic components, this signal is, by all means (maybe by almost all means), not desirable.

To prevent signals from being overdriven, units are developed, that are controlling the amplitude of a signal in a way that no saturation- and overflow-effects may appear. This is done by dynamically changing the amount of amplification of the signal, meaning, that "loud" signals are amplified less or are even softened, while "soft" signals are amplified more, thus meaning that the signal's dynamics are being limited, that the signal is being compressed.

The difference between compressor and limiter units is that compressors will amplify "soft" signals with a factor greater than 1, while a limiter will leave "soft" signals (e.g. signals that are softer than the specified limit) unchanged.

musical signals

The human ear itself has similarities to an analogue limiter/compressor. Of the possible 140dB hearing range only 60dB can be used in a considerable time, thus the limiting process is nothing completely artificial.
The dynamic quality of the human ear gives us some ideas of how to make a limiter.

If the regulation process is done very fast and hard, no dynamics of the signal will be left at all. This does not correspond to our normal hearing habits, in fact, it destroys the musicality of any (traditional) musical piece.
To avoid this, the regulation time has to be long enough to keep a relative dynamic. Of course, if the regulation process is done far too fast, inharmonic components will be added, and so the limiting process has definitively not the desired effect.

It is indispensable to prevent the listener from being able to hear the regulation process.

A psycho-acoustic effect called "forward masking" is helpful : soft sounds that are followed immediately by very loud ones cannot be heard by the human ear at all! The regulation process will be masked and therefore unhearable, if it takes place in this very short time immediately before loud signals.
If the input signal softens again, the amplification must not be increased as fast. If this process will start only after a certain "hold time" and then increase the amplification in an exponential way, thus following the WEBER-FECHNER-rule, this regulation process will not be heard (at least not in a disturbing way) and the musicality of the piece will not be destroyed by preserving a relative dynamic.

Regulating very fast and hard is not disturbing for "unmusical" sounds, such as cracks etc.

simple limiter

The limiter amplifies the signal by a factor amp that is normally less than 1 (a compressor will allow factors greater than 1 to).
If the limiter's output
OUT := IN * amp (1)
would exceed the limit, than a change of the amplification-factor amp becomes inevitable. The new factor is calculated by the relation
amp_new := limit / IN (2)

thus the new output value exactly reaches the limit; since the amplification must not increase again for a certain hold-time, we will have to set

time := holdtime (3)

After this time has elapsed (with no fresh reduction in between, which of course would reset the time variable) we can start to augment the amp factor again, following WEBER & FECHNER we use an exponential increase, thus resulting in a linear hearing sensation.

amp_new = amp_old * coa (4)

coa stands for "change of amplification" which is no creative variable-name at all.

To increase the amplification, coa has to be greater than 1.
This regaining process will be continued up to the point, where amp would be greater than 1.

Some "problems" occur at all time-dependent variables, e.g. time, hold_time & coa, because the calculations are done at sample-rate.

Therefore it is wise and necessary to make these variables dependent on the sample-rate to increase efficiency.
If we substitute time by samples via

holdsamples := holdtime * samplerate (5)
it is very easy to count down the hold-time every turn with
samples := samples - 1 (6)

it is more complicated with coa, not because of the sample-rate but because of its dependency on time itself.

Let n be the number of samples (e.g.: calculation turns) in which amp should double with relation(4) again.

coa^n = 2 (7)
coa = e^( ln(2) / n) (8)
With
holdtime := n / f_samplerate (9)
we finally get
coa = e^(ln(2) / (f_samplerate * holdtime)) (10)

click limiter

As I mentioned above, cracks and singular peaks of the audio-signal could be limited in a harder way than normal music.
To distinct between cracks and music, we notice, that these peaks are normally much "louder" (although much shorter) than music. Therefore we can define a second threshold, beyond which clicks and Wagner's anvils are located. If this second limit is exceeded, a faster and harder regulation can take place till we fall back below it.

It is more efficient, to define this limit indirectly, e.g. as an amplification limit.

alimit := limit1 / limit2 (11)

If amp is less than alimit, the signal has gone beyond this second limit. A fast regulation with coa2 < coa1 and hold_time2 < hold_time1 may take place.
If amp regains a value greater than alimit, the normal regulation will do what is left to be done.

compressor

As it is very important to prevent signals from outranging the maximum values, it is often of more musical interest to compress the dynamics of a signal by various ratios. Although the limiter was not designed for this purpose originally (as the name indicates), it can easily be modified to match these specifications.
The most important thing to notice is (again) the non-linear behaviour of the human ear. With respect to this effect, the compressor has to work with a logarythmic scale too. Furthermore the ratio is usually given in dB:

ratio = change_of_INputlevel [dB] / change_of_OUTputlevel [dB] (12)
Therefore the level of the OUTput-signal calculates as
OUT [dB] = treshold + ratio * (IN - treshold) [dB] (13)

We'll design our compressor to pass through signals with low levels unchanged, high leveled signals should be limited whereas all other signals (e.g. those that are between an upper limit and a lower treshold) should be compressed with any ratio (in dB).

I suggest that the limit-value should be the actual OUTput-limit. This means for ratios other than 1, that the maximum INput-level for a signal that will only be compressed but not limited is different from the OUTput-level (see (13)).

The logarythmical ratio curve cannot simply be expressed by multiplication of values. In fact we have to calculate

amp = (treshold / IN)^ratio (14)

to get our new compressed amplification. For signals leveled higher than limit the signal is limited normally.

oversampling

Digital signals are represented by a series of equidistant samples of an analogue signal. Peaks of the analogue signal may fall between two samples and are therefore not directly represented in the digital domain.

Nonetheless, these peaks are reconstructed by a digital-audio-converter and must not be neglected.
The dac will reconstruct the "original" signal by multiplying the "digital spectrum" with a rectangular window (thus getting rid of alias-frequencies), which is equivalent to convolute the signal with a sinc-pulse in the time-domain.

sinc(x) = sin(x) / x (15)

This process can be simulated roughly to get the real maxima of a signal.

Convolution is an operation that needs both past and future values of a signal (in fact, it needs all the values of the signal at any time, but since we are only estimating, our number of values will be tickable off on our fingers).
Since we have great problems with the future values, we need a buffer, where the values can be stored. Delaying the signal, we get values that are in the relative future of the actual sample, although the future and the actual values are both past.

This obvious disadvantage is none, because so we can realise a transient-limiter.
This kind of limiter regulate amp before the triggering moment and therefore will be able to use the already discussed phenomenon of "forward masking".
Since the signal is delayed only for some milliseconds, normally no "real-time-problems" will arise.

It is efficient to use a ring-buffer.

multichannel limiter

If we have a multi-channelled signal, we must not apply limiters on each channel separately, because this would completely change the balance of the channels and therefore destroy the room situation.
To avoid this, all channels have to be regulated by the same amount.

There are several possibilities to realise this


The master-slave-method is more efficient but needs different programs for master and slaves. The pares-inter-pares method is more complicated, but needs only one single program that is applied on each channel.

As indicated above, nowadays PCs are used rather than monolithic DSP-boards to do digital signal processing. Since all the tasks are performed on one single (or double...) CPU, the problem of programming a number of parallel processors is obsolete now, although the algorithm should be cheap in terms of CPU-usage.

Therefore the master-slave-mode seems preferable for use on normal PCs. To reduce the amount of calculation, of course, the minimum number of calculation should have to be done for all channels in a "parallel" way. Inevitable it seems to calculate the maximum of amplitudes of all channels "parallel". If the maximum of all channels is evaluated, it is rather easy (for further details see above) to calculate the overall-amplification-factor including back-regulation.


1607:forum::für::umläute:1999