Limiter question...

Ross Bencina rbencina at hotmail.com
Thu Aug 27 04:13:51 EDT 1998


Tin,

Forget overlap-add for a start...

what you need is...

1. A level detector
2. An Envelope generator
3. [optionally] a delay line to re-align the envelope with the signal

I've put my (amature) suggestions on implementing these stages below, 
but'd be interested in what the more knowledgable members of our 
comunity have to say about implementation :)


1. 
The level detector gives you the average or peak level of the incoming  
signal. One way of doing this would be to scan for the absoloute maximum 
value in your incoming buffer such as:

A.
int max = 0;
for( int i=0; i <bufferLength; i++ ){
  if( buffer[i] > max )
    max = buffer[i];
  else if (-buffer[i] > max )
    max = -buffer[i];
}

This could be performed over smaller or larger buffer lengths, depending 
on you preference (I'll mention trade-offs later )

B.
another way is to maintain an instantaneous peak value, which slowly 
decays, and is reset at every new peak:

peakval = peakval *.99;
if( abs(insamp) > max )
  max = abs(insamp);



2. 
The envelope generator generates a _smooth_[ish] sample by sample value 
which you use to scale the output (sample by sample). This could be a 
straight line, and exponential curve etc. There are different ways of 
designing the envelope, but usually it will have seperate times for 
attack, sustain and release.
For a limiter, when the level detector exceeds a threshold, you ask the 
envelope to ramp down to [threshold / level], otherwise you ask the 
envelope to ramp to unity. If the newly requested envelope value is 
lower than the current one, the envelope immediately starts its attack 
portion (ramps to the target over the attack time), if the requested 
value is larger (closer to unity) the envelope completes its sutain 
portion (if it has one) and then starts its release portions (ramps to 
the target over the release time).

3.
Even if you are updating the envelope target based on a sample by sample 
peak detector - the attack time of the envelope (which needs to  be a 
certain length to stop clicks etc.) will cause transiant peaks to be let 
through (ie the envelope won't close down quick enough and the won't get 
limited properly). Depending on the application you could: 

A. Clip the output to ensure it dosn't exceed a threshold (which should 
probably be higher than the threshold used to drive the envelope.

B. Do peak detection on the input signal, but delay the version of the 
signal you are sending out (and multiplying by the envelope) by the 
attack time of the envelope + the latency of the peak detector - this 
way the envelope will have ramped down by the time the transient gets to 
it.

Having just written this, I suspect that there is a way of simplifying 
peak detector B. by using the envelope time characteristics to smooth 
the time characteristics of the peak detector...

Jumbled, but food for thought none-the-less.

Ross B.

//------------------------------------------------------
Ross Bencina.                             rossb at kagi.com
Interactive Digital Sound Design.
AudioMulch://www.webpage.com.au/audiomulch

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com






More information about the music-dsp mailing list