Help with envelope detector

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

camsr wrote:plusfer, google the AudioTK library, member miles here on this forum made it. It has a module, I think it's called atk-rel filter or envelope or something, works nicely.
Thanks. Indeed, there is an AttackReleaseFilter that does just the A-R part, and also a PowerFilter to play between pure Peak (squared) and RMS (with a 1 pole filter).

Post

Zaphod (giancarlo) wrote:That library is full of "if". There is no smooth apparently. It seems the native simplified approach reported on dspguru
Yes, it is basically just ifs. I haven't played with max to check which one was faster or not. In my compressors, the worse computation time is not from the this stage.
The smoothing part is done before by another filter if you want to have smoothing.
There is also a filter with hysteresis.

Post

Zaphod (giancarlo) wrote:That library is full of "if". There is no smooth apparently. It seems the native simplified approach reported on dspguru
The function in question is quite good IMO. One stage filters the other so it's always smooth (or rather filtered) between transitions.

Post

Zaphod (giancarlo) wrote: About smooth approach, the effect is indeed not very strong. As soon add you raise the constant all release values will be leading to the same "release action" and the compressor is "gone".
This is why auto-release is important. And it depends on how sophisticated the detection is, maybe it goes beyond just voltage (or amplitude).

Post

camsr wrote:
Zaphod (giancarlo) wrote: About smooth approach, the effect is indeed not very strong. As soon add you raise the constant all release values will be leading to the same "release action" and the compressor is "gone".
This is why auto-release is important. And it depends on how sophisticated the detection is, maybe it goes beyond just voltage (or amplitude).
Agreed

Post

camsr wrote:
Zaphod (giancarlo) wrote: About smooth approach, the effect is indeed not very strong. As soon add you raise the constant all release values will be leading to the same "release action" and the compressor is "gone".
This is why auto-release is important. And it depends on how sophisticated the detection is, maybe it goes beyond just voltage (or amplitude).
Actually, as I was thinking about the equivalent given before, a proper compiler would generate a code that could actually be more complicated with the max() version. The ?: is equivalent to the ifs(), but more obscure and you need to obfuscate the parameters to make it similar with one additional multiplication. So ifs are actually better for clarity and performance.

Post

JCJR wrote:Hi plusfer
How is it sounding bad to you? Distortion? Aliasing? Un-musical dynamics control?

Do you want peak compression with fairly fast attack? RMS compression with fairly fast attack? Smoother, slower compression?
The attack sounds like a click some times, when the attack is no too fast and not to slow.
If i reduce the attack time even more (0.1 ms) I get a lot of (THD)distortion in general, but the click sound disappear.
I've only one real compressor, so It is the only real reference that I can have, and this does not happen, even at very short times the THD is low. (it is a 1176 clone)

Miles1981 wrote:
camsr wrote:plusfer, google the AudioTK library, member miles here on this forum made it. It has a module, I think it's called atk-rel filter or envelope or something, works nicely.
Thanks. Indeed, there is an AttackReleaseFilter that does just the A-R part, and also a PowerFilter to play between pure Peak (squared) and RMS (with a 1 pole filter).
Great!! thank you for share your library :)


now I have a lot of info to test :D
I'll tell you how it has gone.
camsr, giancarlo, ichad, JCJR, Miles thanks for your help!

Post

plusfer wrote:
JCJR wrote:Hi plusfer
How is it sounding bad to you? Distortion? Aliasing? Un-musical dynamics control?

Do you want peak compression with fairly fast attack? RMS compression with fairly fast attack? Smoother, slower compression?
The attack sounds like a click some times, when the attack is no too fast and not to slow.
If i reduce the attack time even more (0.1 ms) I get a lot of (THD)distortion in general, but the click sound disappear.
I've only one real compressor, so It is the only real reference that I can have, and this does not happen, even at very short times the THD is low. (it is a 1176 clone)
Thanks plusfer. Am not an expert, but have been long interested in the topic. Take comments with a grain of salt.

The 1176 may be a slightly different case, though more generally perhaps any compressor design would be its own individual case.

Has been decades since I had hands-on experience with 1176. At the time I wasn't so impressed but perhaps only because of my own ignorance.

Nowadays the 1176 seems considered "legendary" because it supposedly sounds great with very fast attack times. I do not doubt such claims. Merely saying "supposedly" because I do not know from recent personal experience, and do not recall from long-ago experience. So far as I recall the 1176 was originally designed to be a limiter as much as compressor.

Some seem to like 1176 fast behavior on drums among other things. Have read that some like to track vocals thru a chain of slow LA2A and fast 1176. Presumably the 1176 catching fast transients which get magnified by a high-gain setting thru the slow LA2A. Or some entirely different explanation, dunno.

There are numerous ways to make a compressor. Some "bass-ackwards" designs sometimes working great in some uses, and some "theoretically better" designs maybe not sounding so good. And what sounds good to one fella may sound bad to another.

When I was messing with analog compressors, and times in the past when I made digital compressors, the "good sound" to my ear was a minimum attack time constant of about 1 ms, and a minimum release time constant of 10 ms. But a more typical practical "good sound" with a release of 50 or 100 ms or much more. But I do not like distortion. Some people LIKE distortion, and a short release time can deliver plenty of it. :)

Depending on the nature of the smoothing circuits. There were many analog compressors which only only used a single first-order stage of smoothing. And many digital compressors built the same, with only a single first-order stage of smoothing. Anything with only one stage of first-order smoothing needs to fit within certain time constants to "sound good" to my ear.

When the smoothing design gets fancier, then the "good sounding" time response range might be more specific to each individual smoothing design.

It is said that it is difficult to make a good-sounding digital compressor with very fast attack time, but IMO it is no walk in the park to make a good-sounding fast-attack analog compressor either.

Some issues that make very-fast-attack more difficult in digital--

1. If you run audio at 192 kHz samplerate perhaps easier. But at 44.1 k or 48 k, very fast attacks could go from low to high compression within one or two samples. Such a quick gain change makes a sharp-edged kink in the audio waveform, and the ear hears sharp-edged kinks in the audio as clicks. IMO this is also a problem with analog and it makes me wonder how 1176 can supposedly attack so fast without clicking.

2. At lower sample rates, fast gain changes amplitude modulated atop the signal, cause temporary bandwidth extensions at much higher frequencies than the 22.05 kHz Nyquist of 44.1 k audio. This brief splatter of above-nyquist frequencies get mirrored back down into the audio band. Aliasing. Even if the envelope might be slow-release with minimal high frequency content "most of the time"-- The brief transient aliasing splatter on fast gain changes could sound even uglier than the psycho-acoustic click from a fast-attack analog compressor.

So especially if trying to make a fast digital compressor, the experts tend to get fancy, with oversampled signals and other tricks to minimize aliasing. I haven't experimented with that so far.

But unless you specifically need 1176 type fast attack, the easiest way IMO is to use >= 1 ms attack time constant and > 10 ms release time constant. For most things, I personally consider release shorter than 25 ms not-very-useful. At least with simple envelope smoothers, and tracks containing low-mids or bass. A hihat track or tamborine might sound OK with a very short release, because the sound doesn't have much bass in it.

Post

1176 is heavily program dependant.
It is also a feedback compressor. It is not exactly something "simple" you can crack with a simple approach like the one you are following (no pun intended, but it is perfectly normal you cannot get easily 0.04 ms attack and 30 ms release without distorting like the hell using such simple approach )


You'll never get a fast limiter like that without
- A good smoothed technique for the peak detector
- a good program dependant technique for transients
- A decently smoothed transfer function for the computer program (call it vca, whatever)
- A decently fast peak detenction (think to catch all peaks)
- maybe same properly saturation/clipping/waveshaping stage
- Lookahead, but it is dangerous, it messes things easily




Or
- You take the schema of a 1176 and you solve the math. There are plenty of papers speaking about it, it is pretty legendary.

Post

Yes program dependent compressors can be a real pain sometimes. I think something like the 1176 or similar fast-attack variable-release, needs to have the timings set in relation to the gain reduction and peak crest factor.

Post

I would add to my list also

- Maybe a proper oversampling technique on the computer program section. It seems like it helps the detector quite a bit, especially at low frequency rates.

Post

I appreciate all your good info and advice, Giancarlo.

Am not teaching experts anything they did not know a long time ago, but maybe someone will find this useful--

Had not paid attention to "peak-type" compressor envelopes for a long time. Peak limiter strategies are a little different, as are RMS compressors.

Today did some testing to see "what is of importance" in good peak envelopes. The idea was to use crude methods, then devise branchless envelopes and such, to see how much improvement is made by the various elements. Have only tested crude methods so far.

Was using a 44.1 kHz sweep file, 1 second sweeps spanning an octave each, with 1 second silence between. 20-40 Hz, 40-80 Hz, etc up to 5120 to 10240 Hz. Sine wave at -6 dB peak. The left starts at phase 0 and the right starts at phase 90, un-smoothed. The right sweep that abruptly starts and ends on a peak, perhaps useful for some tests.

Anyway, here is a comparison with ABS rectification and a naive branched AR. The left channel is 1 ms Attack and 10 ms Release. The right channel 10 ms Attack and 100 ms Release.
Image

Next, about the same thing, replacing ABS with square / sqrt. The signal is squared, then a branched AR applied, then sqrt applied to the smoothed squared signal. Same 1 and 10 ms TC on left, 10 and 100 ms TC on right.
Image

Ripple seems slightly diminished with square vs ABS, but perhaps because the SQRT merely stretches the Release of the square/sqrt test. Higher frequency aliasing may be slightly smaller but not much. I have my doubts whether a branchless AR would much impact the aliasing, but will later test and find out.

Here is a zoomed-in view of the aliasing in the top octave sweep (extending to 10240 Hz). Will later add a 10 kHz to 20 kHz sweep to the test. It seems honest-to-god aliasing. Did a subsequent test (not pictured) of adding a 1 kHz, fourth order low pass filter after the AR stage, which kills off the tiny squiggles but doesn't affect the gross peaks and dips up high.
Image

And then further zoomed-in, on the biggest central feature of the aliasing.
Image

So I tested a quick'n'dirty 4X oversample. A proper oversampled test, I suspect would perform better. This test, I oversampled with 3 12-tap sincs, then squared the signal, then ran the AR on the oversampled signal, then merely picked off every fourth sample to plot. No decimation filter on down-sampling except what was filtered by the AR filter running at 4X rate.

This is a crueler test because it uses 0 ms Attack rather than 1 ms (or 10 ms) attack. The earlier tests with Release 10 X longer than attack, are "kinda sorta" like peak envelopes, but they lose about a dB compared to the peak of the test input. And the output envelopes vary somewhat in level according to frequency.

To get a genuine peak sensing, would seem to want a 0 ms Attack. This test uses the same 0 ms Attack and 10 ms Release on both left and right sides. The results stay rather close to -6 dB of the input signal's level over most of the frequency band.

However the left channel is just running at 44.1 kHz, and the right channel uses the same time constants with quick'n'dirty 4 X oversampling, then inadequate downsample filtering to get back to 44.1 kHz for plotting.
Image

The oversampling seems to have minimal improvement on bass and mids. But appears to help reduce HF aliasing. A proper method might further reduce aliasing, or perhaps even with proper methods it would work better with higher oversampling. Will further experiment.

Image

Post

Thanks guys, great info!!

I started the post to understand how real compressors works, It is not my intention to make an 1176 plugin, but it's the only real compressor that I have.

About program dependent, I've read that several envelopes are used and then switch between them, but I can only see one envelope follower in the 1176 schematics:

(in red the rectifier<?>, to the right the rc filter with attack attached <?>)
Image

http://trentonblizzard.blogspot.com.ar/ ... e.html?m=1

Post

There is an article in uad website about it. There are even pictures of processed testtones, so you have an idea about it and about how differently it reacts to transients
Before starting analyzing the schema try to verify these things. You'll have a better picture about the way things work from the user point of view, before digging in development details

Post

Thanks plusfer

I never studied the 1176 schematic and am rusty on studying schematics. With apologies to that blog poster, he explains most of the rectifier well, but what he says about the envelope smoothing seems wrong or incomplete. What follows is quick supposition. For brevity is presented as "fact" but could be mistaken on various points and is posted without long deliberation.

The 6.8 uF and 100 uF caps make no difference except DC blocking and preservation of proper bias voltage for the diodes to work right. Which is mentioned in the article I think.

That 0.022 uF cap in parallel with the 470 ohm resistor has minimal effect on the envelope smoothing. Some 1176 schematics I googled do not even show that cap. It may be there to help suppress radio interference or to smooth out or speed up fast impulses. Maybe it actually influences the envelope in some way, but tis unclear to me at the moment.

There are so many 1176 schematics online, but this one for example-- http://www.gyraf.dk/gy_pd/1176/1176sch.gif

If you follow the envelope attack and release pots up to where they connect to the gain-control FET Q1. If the gate voltage to the FET is low (the normal condition) the FET acts like a high value resistor and the gain is not significantly reduced. Larger voltages to the FET gate makes it act like a smaller resistor, making a resistor divider and "turning down" the gain.

Now some of the features around the FET may be there for linearizing. Small signal FETs get non-linear with bigger signal levels, when used as attenuators like this. There are feedback tricks which improve the linear voltage range, reducing distortion with larger signals. Also, best I recall looking in an 1176 long ago, the FET may have been rather large, but maybe am remembering wrong.

Anyway, C27, 0.22 uF, may be the main attack-release smoother. C3, 200 pF, along with R7 2.2 Megohm, may act as a "fast attack" path to the FET control, a program-dependent sub-envelope mechanism.

FET input gate is many megohms, like an open circuit. So any charging or discharging that goes on related to the FET gate, is thru resistors and caps around the FET. The FET gate itself can be ignored when guestimating time constants and such of the FET control circuitry.

Anyway, that C3, if a fast spike hits it, will probably "instantly" pass on the fast spike and quickly drive down the FET gain. But its effect would be short-lived due to a brief spike, and after voltages equalize the longer envelope of C27 would become dominant.

R9 and C4 etc are possibly there for FET linearizing rather than adaptive envelopes, but maybe they perform both functions at the same time. It is a rather cunning circuit.

EDIT: On further thought C3 probably doesn't affect the envelope, and is not present in some schematics.

Post Reply

Return to “DSP and Plugin Development”