Login / Register 0 items | $0.00 New @ KVR
JCJR
KVRAF
 
2292 posts since 17 Apr, 2005, from S.E. TN

Postby JCJR; Sat Jul 28, 2018 12:15 pm Most harmonically pure attack shape?

Maybe this could apply to some synth envelope applications but this question is in context of a peak limiter. My most recent homebrew lookahead peak limiter has worked quite good enough for a couple of years but I keep thinking about making it "optimally refined" before publishing the source code (as reaper jsfx plugin).

It identifies each over-thresh peak and draws a "flat top" envelope segment over the span of the peak. Peak value is calculated so that theshold level is always 1.0 regardless of the threshold setting. So the envelope always stays at 1.0 so long as [ input <= threshold ]. If a peak happens to go +6 dB above threshold, then the peak value would be 2.0. Etc.

For example if we encounter a peak which is over-theshold for 8 consecutive samples, and the loudest peak in those 8 samples happens to be 2.0, then it draws a flat-top 8 sample envelope segment with the max value of 2.0 covering the duration of that over.

There are various other features in the algorithm, but "flat-topping gain on the peaks" is intended to avoid some kinds of peak distortion.

So to minimize intermod distortion while lookahead changing gain, what is the "harmonically purest" attack shape? Because it is a one-shot and not a repeating waveform, then maybe the answer would not be immediately obvious. Or maybe it is cut-and-dried simple obvious, dunno.

Just making the lookahead attack segment "smooth" with a sigmoid shape seems clean-sounding in practice. I'm just curious if there is a "theoretical ideal" most-harmonically-pure one-shot shape.

In other words, starting from a "raw" peak envelope that looks like this:

____________----------------____________


Would the rising half of a cosine wave make the "most harmonically pure" lookahead attack segment? Or maybe the first half of a windowed sinc? Or something else?

The lookahead attack duration is typically PeakDuration + 1 ms. So an 8 sample over at 44.1 k samplerate would have a 52 sample attack segment leading into the flat-top region.
matt42
KVRian
 
1017 posts since 9 Jan, 2006

Postby matt42; Sat Jul 28, 2018 1:18 pm Re: Most harmonically pure attack shape?

Dunno, how about some kind of blep or blamp? They are inherently band limited (or pseudo band limited?), so should be relatively clean to use those to transition between the flat top regions
matt42
KVRian
 
1017 posts since 9 Jan, 2006

Postby matt42; Sat Jul 28, 2018 2:06 pm Re: Most harmonically pure attack shape?

Also too much ripple in the transition might not sound so good and possibly let some overs pass during transition.

Perhaps start with a nice, ripple free, window function, that is continuous to at least the first derivative, such as Nuttall window or similar. Then integrate the function twice to have a ramp that is continuous up to the third derivative and ripple free.

Just for the record I haven't tested any of this out. Just thinking off the top of my head
JCJR
KVRAF
 
2292 posts since 17 Apr, 2005, from S.E. TN

Postby JCJR; Sat Jul 28, 2018 4:29 pm Re: Most harmonically pure attack shape?

Thanks. Agreed that any ripple in the attack (or sustain or release) segments seem intuitively the wrong thing to do. OTOH "perfect" sinc lowpass filters have the ripple, so intuition might be somehow wrong.
matt42
KVRian
 
1017 posts since 9 Jan, 2006

Postby matt42; Sat Jul 28, 2018 11:23 pm Re: Most harmonically pure attack shape?

Yeah, some ripple might be fine. I haven't thought it through 100%. If you want to test that, rather than use half a windowed sinc as you mentioned, I would try a BLAMP (Band Limited rAMP). You start with a full windowed sinc kernel then integrate twice to arrive at a ramp . At 50 odd samples you should be able to design a nicely band limited kernel as the starting point
User avatar
Aleksey Vaneev
KVRAF
 
3486 posts since 7 Sep, 2002

Postby Aleksey Vaneev; Sat Jul 28, 2018 11:34 pm Re: Most harmonically pure attack shape?

No such thing as "harmonically pure attack shape". Attack shape basically affects the frequency roll-off above a threshold frequency (e.g. 1ms attack shape sets 1000 Hz as an approximate threshold frequency). Attack shape then works as a filter to the peak level hold signal. In the end attack shape mixes with the spectrum of the signal being limited, and there one attack shape may suit one sound better than the other.

One of the least coloring attack shape I've found can be examined in Elephant 4 plugin: select TransShape = -0.50 and Trans=Sharp. It can be extracted by processing a DC-shifted signal (in the left channel) with a single spike (in the right channel).
Image
matt42
KVRian
 
1017 posts since 9 Jan, 2006

Postby matt42; Sun Jul 29, 2018 1:05 am Re: Most harmonically pure attack shape?

Aleksey Vaneev wrote:Attack shape then works as a filter to the peak level hold signal.
Right, so we can essentially filter the gain reduction signal. Which then modulates the input signal. Presumably the more harmonically sparse the gain reduction signal the less artifacts such as intermodulation distortion, aliasing, etc will result. But the attack is also a time domain phenomenon, so I guess we also need an attack shape that subjectively sounds good in the time domain?
User avatar
Aleksey Vaneev
KVRAF
 
3486 posts since 7 Sep, 2002

Postby Aleksey Vaneev; Sun Jul 29, 2018 7:12 am Re: Most harmonically pure attack shape?

matt42 wrote:
Aleksey Vaneev wrote:Attack shape then works as a filter to the peak level hold signal.
Right, so we can essentially filter the gain reduction signal. Which then modulates the input signal. Presumably the more harmonically sparse the gain reduction signal the less artifacts such as intermodulation distortion, aliasing, etc will result. But the attack is also a time domain phenomenon, so I guess we also need an attack shape that subjectively sounds good in the time domain?

Well, attack shape, or filter can't "sound" by itself without the context of the signal being limited. But you can make a spectral plot of it, not going to give much info on how it sounds, though.
Image
matt42
KVRian
 
1017 posts since 9 Jan, 2006

Postby matt42; Sun Jul 29, 2018 8:17 am Re: Most harmonically pure attack shape?

Thanks, I probably wasn't being very clear. On the one hand yes, I'm talking about harmonic analysis of the gain reduction signal itself. But with regards the "subjective sound" I meant the actual final limited output relating to the attack regions, not the sound of the the gain reduction signal, or it's attack segment.
signalsmith
KVRer
 
6 posts since 5 Jul, 2018

Postby signalsmith; Sun Jul 29, 2018 9:28 am Re: Most harmonically pure attack shape?

JCJR wrote:So to minimize intermod distortion while lookahead changing gain, what is the "harmonically purest" attack shape? [...] I'm just curious if there is a "theoretical ideal" most-harmonically-pure one-shot shape.


OK, so the details differ, but I had a similar goal, and personally I ended up settling on cosine-segments (JSFX implementation: https://geraintluff.github.io/jsfx/#Smooth%20Limiter).

The way I thought about it was comparing to window functions. Say you have a single peak - your gain envelope starts at 1, dips down and up again (using some attack/release curves), and then settles back to 1 again. This is equivalent to keeping a "dry" signal at gain 1, then also taking a segment around the peak, windowing it, and adding it back with inverted phase.

The question of harmonic distortion introduced by the gain envelope can (in this reduced case) be reasoned about using the characteristics of the "window function" of that anti-phase component. The frequencies get smudged in the same way as when you apply windowing for frequency-based processing (ignoring the original frequency at the centre, which I think should end up with a Dirac spike because of the "dry" signal).

With this perspective, using equal-length cosine-segments for both attack and release would correspond to a Hann window, which is pretty good (wide central lobe but not much sidelobe). I think sidelobe is the bigger problem here - on the other hand something like a sinc window has frequency-domain cutoffs that are too sharp, leading to pre-echo in the time domain.

It takes a bit of handwaving to generalise from one peak to many, and from symmetrical attack/release to asymmetrical (which I found I preferred), but I think it works out, because you're kinda doing some weird filtering on the gain envelope, as matt42 said. (And since multiplying by the gain-envelope means convolving in the frequency domain, filtering it means the convolution smudges your frequencies less far.)

Anyway, +1 for cosine segments, but I don't think there's a definitive best answer, as there isn't a definitive best window function.
User avatar
JoaCHIP
KVRist
 
86 posts since 1 May, 2006, from Somewhere cold and dark

Postby JoaCHIP; Sun Jul 29, 2018 11:08 pm Re: Most harmonically pure attack shape?

The question in topic is a brain twister. The faster and bigger changes you make to the amplitude, the more harmonic distortion you get. That's inevitable. But certain kinds are audible, and some are not. To make things worse, the input signal has a lot to say.

If you vibrate the volume up and down hundreds of times per second, a hihat might still sound fairly normal, whereas if you do this to a deep bass guitar note, you'll actually hear those fast volume movements as a sound. So I think it's signal dependant.

Also, it might not be a good idea to be entirely mathematical about all this. The human ear has certain expectations after all, because some signal shapes are probably more common than others. E.g. the sound of someone beating a drum or a piece of wood is a very percussive sound that decays exponentially, so maybe that shape makes sense in that case? Flutes and brass instruments and the human voice are way different obviously.
JCJR
KVRAF
 
2292 posts since 17 Apr, 2005, from S.E. TN

Postby JCJR; Mon Jul 30, 2018 9:20 am Re: Most harmonically pure attack shape?

Thanks all for the good ideas.

I think limiters only tend to sound good applied very conservatively, a max rare few dB of gain change. Ideally a limiter used conservatively wouldn't have any "changed sound" at all, but of course in the real world maybe not so lucky. Am just saying "good sound" at extreme pegged limiting was not a goal though a tool should always work as good possible.

The simple way I've been making sigmoid-shaped lookahead attacks, which seems to sound OK, but it will be easy enough to try cosine or other shapes without messing up the code too much:

The initial drawing into the "head" of the lookahead buffer is not bandlimited though the envelope shapes are sufficiently simplified so as not have LOTS of high harmonics. And then when picking off envelope values from the tail of the lookahead buffer to apply to the delayed samples, further filtering is applied to the envelope.

For example at 44.1 k samplerate, perhaps an overthresh peak has a max value of 2.0 (relative to threshold which is always 1.0). And the peak has 8 sample duration.

It would draw a flat-top value of 2.0 from PeakStart - 44 (1 ms before the beginning of the peak) thru PeakEnd, about a 52 sample flat-top. And then it would draw a linear ramp from 1.0 at [ PeakStart - (44 + 52) ] up to 2.0 at [ PeakStart - 44 ]. So the actual total lookahead before PeakStart is [ 2 ms + PeakDuration ].

Tha plugin uses a rather large lookahead buffer because it "writes into the past" after determining each peak duration, and it is set up to include the peak duration so that the lookahead would be lots bigger if a pure low bass half-wave needs heavy limiting. Maybe a heavy-limited 40 Hz half-wave could have duration of 10 ms (or lots more). With a 10 ms Bass Peak the total lookahead before the bass PeakStart would be 12 ms. OTOH a single-sample over would only have total lookahead of [ 2 ms + 1 sample ].

The first filtering when picking off the tail of the lookahead buffer is a cascade of 4 first-order lowpass filters. 5 Time Constants gets "real close" to a target value, so for one ms, setting the time constant of the first-order lowpass filters at 0.2 ms yields a tuning of about 796 Hz. After passing "1 ms of ramp followed by 1 ms of flat-top" thru the four-filter cascade, it turns into a smooth sigmoid shape with the envelope value "just kissing the flat-top max peak value" right at the beginning of the Peak.

The control signal doesn't have lots of harmonics before filtering, and after filtering is attenuated -12 dB at 800 Hz, -24 dB at 1600 Hz, -48 dB at 3200 Hz, yadda yadda. Because of frequency warping the ultimate attenuation approaching nyquist may exceed that expected from an analog model.

Because most practical music mixes do not have LOTS of energy above 5 kHz, and because of the attenuation in the control signal, I doubt that there would be sufficient high harmonics in "most music" to sum with the control harmonics, making sum frequencies above nyquist loud enough for audible aliasing, even without oversampling. But it is only an ignorant hunch.

But bass thru high-mid transient IM sum and difference frequencies would be in the output. Possibly audible or possibly not. As others said, perhaps dependent on the audio source.

It also has release features and program-dependent release, etc. But not relevant to the thread.

If I keep my algorithm and draw in cosine attack segment where I now draw in a linear ramp, maybe it would sound better. Will try find time to see. I would keep the post-filtering and the "lookahead flat top shelf", just substitute the part which draws a linear ramp. Whatever higher harmonics might be added by the cosine ramp, would just get filtered even more, and the cosine shape smoothly phase shifted into the "lookahead flat-top shelf" region.

Might be problematic trying to figure out how to evaluate which sounds better. Maybe torture-testing at ridiculous limiting amounts, so that it sounds bad, and we can perhaps pick which version doesn't sound as bad as the other? :)

I tried first-order exponential ramp segments in the above-described algorithm, a convex curve. And also "linear ramp according to dB" or "linear in log space" which is a concave curve. But I THINK maybe the simple linear ramp sounds a little better. Also, with even a 6 dB peak limiting "rather extreme" for musical results, the ramps are relatively wide and shallow. Plotting exponential attack vs linear vs "linear in log space" over 50 samples, amplitude from 1.0 to 2.0, all three plots are surprisingly close together. They diverge more drastically over a bigger Y span, but in the shallow span are rather similar to each other.
mystran
KVRAF
 
4955 posts since 11 Feb, 2006, from Helsinki, Finland

Postby mystran; Mon Jul 30, 2018 9:32 am Re: Most harmonically pure attack shape?

My current favourite for "peak clipping" is to do a sliding max-window, followed by few rounds of (cascaded, equal length) box-filtering, which is equivalent to using a B-spline kernel, but way easier to compute on the fly. As long as the max-window is at least as wide as the sum of the box-filter widths (ie. the total support of the spline), you'll hit the desired exact peak limiting exactly (after latency compensation).

You can also make the max-window wider to get a flat top if you think it's useful and the whole thing will trivially handle gain-riding perfectly as well. I suggest 3rd order (or maybe 4th order, but beyond that you sort of get diminishing returns for having to make the support wider) as a starting point for experimentation.
Image <- plugins | forum
signalsmith
KVRer
 
6 posts since 5 Jul, 2018

Postby signalsmith; Mon Jul 30, 2018 10:39 am Re: Most harmonically pure attack shape?

mystran wrote:My current favourite for "peak clipping" is to do a sliding max-window, followed by few rounds of (cascaded, equal length) box-filtering, which is equivalent to using a B-spline kernel


Slightly off-topic, but my favourite arrangement of these is to use one box-filter of length 2N, and two box-filters of length N. It produces three quadratic segments that look vaguely cosine-ish from a distance. :shrug:
JCJR
KVRAF
 
2292 posts since 17 Apr, 2005, from S.E. TN

Postby JCJR; Mon Jul 30, 2018 4:32 pm Re: Most harmonically pure attack shape?

Same off-topic, on RMS box filters:

http://errnum.com/html/jcjr_rms_compressor.html

The RMS box filter acts similar to a comb filter where a sequence of frequencies are smoothed "perfectly" while frequencies in-between are smoothed, but less perfectly. So the above described jsfx compressor cascades 5 box filters of different lengths, so that the "perfect smoothing" frequencies of the second boxcar filter center on some of the "less perfectly smoothed" frequencies from the first boxcar filter, and the third boxcar filter's "perfect smoothing" frequencies hit regions "less than perfectly smoothed" by either boxcar filter 1 or 2. And so forth for the 5 cascaded boxcar filters.

So the result is "pretty dang good and consistent" smoothing at all frequencies high enough to fit inside the total length of the boxcar filter cascade.

I don't recall playing with boxcar peak filters. Or hearing/thinking about it. Interesting idea, will try to think about it.
Next

Moderator: Moderators (Main)

Return to DSP and Plug-in Development