[music-dsp] Adaptive (auto) release
James Chandler Jr
jchandjr at bellsouth.net
Fri Jan 23 11:43:01 EST 2004
----- Original Message -----
From: "Citizen Chunk" <citizenchunk at nyc.rr.com>
> instead of using the crest factor, let's just say that whenever the
> Peak is greater than the RMS, we will use the fast release (relFast),
> and if the RMS is greater than the Peak, we will use the slow release
> a short peak will trigger the compressor, but it won't affect the RMS
> very much. therefore, for the time that the envelope is above the
> threshold, the peak will be greater than the RMS, and it will use the
> fast release. (when the peak falls below the RMS, the envelope should
> be under the threshold, so it won't matter.)
> a longer peak will trigger the compressor and will make the RMS level
> rise a little and sustain after the peak falls. therefore, the envelope
> will fall sharply at first, as the peak is still greater, and then fall
> slowly, after the peak falls below the RMS.
> a very long sustained peak (that triggers the compressor) cause the RMS
> to approach the peak level. therefore, when the peak falls, the RMS
> will sustain, causing the envelope detector to use the slow release
> almost exclusively.
> in pseudo-code:
> peak = fabs (input)
> RMS = (input * input * a) + RMS * (1-a) // where a = 1 / average time
> att = 1 / attack time
> relFast = 1 / fast release
> relSlow = 1/ slow release
> // envelope detector ...
> if ( peak > envelope )
> envelope += att * (peak - envelope)
> else if ( peak > RMS )
> envelope += relFast * (peak - envelope)
> envelope += relSlow * (peak - envelope)
If the RMS is using a fairly long time constant, you could just use whichever is
greater, the RMS envelope or the Peak IIR envelope. That would be similar to
what I described about cascaded IIR envelope detectors.
If doing something fancier with variable release envelopes, I 'intuit' that a
smoothly variable release might sound better than a switch between two release
values, but am no expert.
If algorithmically comparing a full-wave-rectifier (abs(x)) peak measurement
with an RMS measurement, you might make sure you are comparing apples to
The following reasoning may be flawed, but--
With a continuous sine-wave input, RMS is about 0.707 of the measured highest
instantaneous Peak value (at the top of each half-wave).
An IIR envelope detector with very fast attack and longish release, would give
you something close to the actual Peak level.
An IIR envelope detector with longish attack-release envelopes, would be similar
to an average reading. An IIR envelope detector with longish attack-release (on
a sustained sine-wave input) would probably measure 'close to' 0.637 of the
I might be misunderstanding something, but on first glance, your above RMS
detector, appears to be calculating the Mean Squared level, rather than Root
Mean Squared level. Unless there is something special about the IIR processing
on the Squared Input value which is "kinda like" a square root operation, I
think you would have to take the square root of your 'RMS' var before you could
directly compare it to peak and average values.
In DSP RMS functions, you can sometimes arrange the process to directly use the
Mean Squared, and avoid the expensive Square Root operation. But if you want to
compare RMS to Peak and Average, I suspect you either need to Square Root your
above 'RMS' var, or alternately perhaps square the Peak and Average levels (and
apply proper scaling) to compare the three measurements.
The above discussion is only about steady sine waves, which is the only case
where RMS = 0.707 * Peak, and Average = 0.637 of Peak. However, whatever
algorithm you devise, should at least "give the right answer" with a steady sine
The ratio between RMS, Average, and Peak, changes with different shaped
waveforms, as it also changes with different kinds of musical signals. I suspect
you would get the best results to scale all your measurements according to the
ideal sine-wave relationships, before comparison.
Digital music is head-room limited by max peak value, rather than the 'Power'
(RMS) of the signal. A small-duty-cycle pulse wave would have much higher
Peak-to-RMS, or Peak-to-Average ratio, than a sine wave. With a narrow pulse
waveform, to avoid digital clipping, you would prefer to use the Peak value
rather than Average or RMS.
The same concept applies to compressing tamborine vs distorted guitar.
The Tamborine track will almost certainly clip unless you compress based on Peak
levels. This is equivalent to an envelope detector with fast attack and
The distorted guitar is more amenable to compression via Average or RMS levels
(but you still need to make sure that transient Peaks never get clipped).
> i think that this is the approach used in Daniel Weiss's DS1-MKII.
> (check out the manual here:
> http://www.weiss.ch/ds1/images/DS1-MK2_Manual%20V2_0%20E.PDF. it has
> diagrams that display it well.) i believe it is just switching between
> time constants, rather than cross-fading as i had previously
> considered. this could also be close to what Waves uses in their Ren
> Compressor with its "opto" and "electro" modes, although they claim
> that the detector is monitoring the gain reduction rather than the
> input. anyway, it's an interesting concept.
Opto compressors typically put the detector on the output of the signal. This
feedback compression rather than feedforward compression. Feedback compression
gives an 'over easy' compression curve, where the ratio increases as the input
level increases. In addition, Opto elements are odd nonlinear devices that have
different time response depending on the driving signal. They are very quirky
imperfect compressors that accidentally sound good in some musical applications.
It can be tricky to do feedback operations in the digital domain, but in a
compressor it ought to work pretty well, since the envelope detectors "slow
down" the feedback.
> i have one question, as a side topic: if i am using stereo linking, do
> i choose the greater of the sides before or after the envelope
I run different detectors on left and right, and use whichever envelope is
loudest, to modulate both channels, but there could be better ways to do it.
James Chandler jr.
More information about the music-dsp