[music-dsp] Look-ahead & buffering

James Chandler Jr jchandjr at bellsouth.net
Mon Jan 26 11:50:10 EST 2004


> after more thought on the other techniques (sorting, etc), i'm believe
> that they were working on a different type of processor. maybe an
> auto-attack/release limiter/maximizer, or something like that. here's a
> URL:
> http://aulos.calarts.edu/pipermail/music-dsp/1998-August/020551.html

That approach was apparently trying to gain-adjust at buffer block boundaries.
IMO, a dynamics tool probably isn't gonna "sound right" unless envelopes and
gain are adjusted per-sample.

Lookahead is probably most useful in a peaklimiter. In peaklimiters, the gain
has a fairly sudden onset of infinity:1 ratio (when the level approaches a
theshold close to the clipping amplitude).

The rationale for look-ahead-- take a simple test signal-- perhaps a few seconds
of a -12 dB sine wave, followed by a 'step up' to a few seconds of a +12 dB sine
wave.

Without lookahead, the first cycle which exceeds threshold, will instantly 'clip
off' at the theshold level. Because the limiter envelope has release, cycles
following the first over-theshold half-wave, have minimal distortion if the
envelope ripple isn't too bad.

The sudden nonlinearity on the first half-wave after the 'step up', can
sometimes be perceived by the ear as a click or thump, which most folks wouldn't
want in their music.

          *       *

  *      * *     * *
 * *
*   *   *   *   *   *   *   Input With Step
     * *
      *      * *     * *

              *       *


  *      ***      *
 * *             * *
*   *   *   *   *   *   *   Output With Step
     * *     * *     * *
      *       *       *

If the limiter looks ahead, the gain can be lowered before the wave exceeds
threshold, smoothing the non-linearity so we don't hear obvious artifacts.

How much lookahead? How to smoothly anticipate gain change?

If you lookahead by time-offseting the envelope, not doing a smooth level
reduction, the envelope of percussive sounds would "pre-pump" any sustained
tones ahead of the transient, which might be as aggravating as a click.

AFAIK the great-grandaddy of software limiters was the Waves L1 lookahead
limiter. The late lamented Michael Gerzon told me that the L1 uses a
finely-tuned FIR filter to do the "smooth ramp" in lookahead gain reduction, but
I can't guarantee that is true.

I do the lookahead ramp by backwards-filtering into the lookahead area with a
first-order IIR envelope detector, instant-attack, 14 mS release.

For musical signals, forward-backward IIR envelope smoothing might have less
envelope ripple (less IM distortion) for short-release, instant-attack
envelopes. Forward-backward envelope filtering "fills in the troughs" of the
ripple from both directions. Perhaps less CPU expense than an equivalent FIR.

My plugin works on buffer blocks (as most plugins must). I store the lookahead
envelope history (for the length of the lookahead) and "add on" each new buffer
block each time the plugin 'process' function gets called.

I first run the backwards IIR envelope from the end of the "new block", all the
way back to the beginning of the cached "lookahead block".

Then run a forwards IIR envelope on-top of the backwards envelope value array,
from the beginning of the "lookahead area" thru the end of the new buffer.

If an over-threshold transient happens, the backwards IIR envelope has made sure
that the envelope will smoothly rise (and the gain smoothly fall) before hitting
a transient. The gain reduction at the transient's peak is the exact value it
should be, to avoid clipping.

After the backward-forward 14 mS release envelope smoothing, I use a third IIR
forward envelope for program-adaptive-release final smoothing.

Anyway, those are two of many possible ways to "skin the cat".

James Chandler Jr.





More information about the music-dsp mailing list