DSPRelated.com
Forums

compression knee interpolation

Started by zebra July 25, 2008
howdy,

i have a perhaps kind of silly question. i'm trying to program a
compressor with a variable knee, expressed as dB above and below the
compression threshold.

given the threshold, knee and ratio, i'd like to compute an
interpolation function (preferably a polynomial for speed) that
matches the values and first derivatives at the start and endpoints of
the knee region.

to be a little more specific:

the basic (hard knee) compressor has the value function:

given t = threshold, k = knee as ratio of threshold,  s = decibel
slope above threshold, x = input amplitude

output: f(x) = { x, if x < t ;
                      x * ( (x/t) ^ (s-1) ) , if x > t

interpolation start point: p0 =  (t/k)
interpolation end point: p1 = (t*k)

interpolating function g(p0) = f(p0), g(p1) = f(p1)

g'(p0) = f'(p0) = 1
g'(p1) = f'(p1) = s * ( k ^ (s-1) )

additionally, i'd like the condition that g''(x) < 0 over the
interpolated interval.

i got pretty far solving for a 4th order polynomial but the last
condition proves tricky to write in linear programming terms.

any suggestions for solving the polynomial, or for other types of
interpolating functions to try, would be much appreciated. perhaps,
for example, my condition of matching the derivatives is unnecessary,
though it intuitively seems like a good idea.

thought i'd give this forum a try since i suspect i'm trying to
reinvent the wheel a bit here. there must be a standard way of doing
this, even if it just means using a table; but i haven't found
anything specific on the net, just yet...

apologies in advance if this isn't a relevant topic or if my
formulation of the problem is obnoxiously naive, and thanks very much
for your time.

- ezra b
On Jul 25, 4:11&#4294967295;pm, zebra <e...@eastwestsounds.com> wrote:
> howdy, > > i have a perhaps kind of silly question. i'm trying to program a > compressor with a variable knee, expressed as dB above and below the > compression threshold. > > given the threshold, knee and ratio, i'd like to compute an > interpolation function (preferably a polynomial for speed) that > matches the values and first derivatives at the start and endpoints of > the knee region. > > to be a little more specific: > > the basic (hard knee) compressor has the value function: > > given t = threshold, k = knee as ratio of threshold, &#4294967295;s = decibel > slope above threshold, x = input amplitude > > output: f(x) = { x, if x < t ; > &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; &#4294967295; x * ( (x/t) ^ (s-1) ) , if x > t > > interpolation start point: p0 = &#4294967295;(t/k) > interpolation end point: p1 = (t*k) > > interpolating function g(p0) = f(p0), g(p1) = f(p1) > > g'(p0) = f'(p0) = 1 > g'(p1) = f'(p1) = s * ( k ^ (s-1) ) > > additionally, i'd like the condition that g''(x) < 0 over the > interpolated interval. > > i got pretty far solving for a 4th order polynomial but the last > condition proves tricky to write in linear programming terms. > > any suggestions for solving the polynomial, or for other types of > interpolating functions to try, would be much appreciated. perhaps, > for example, my condition of matching the derivatives is unnecessary, > though it intuitively seems like a good idea. > > thought i'd give this forum a try since i suspect i'm trying to > reinvent the wheel a bit here. there must be a standard way of doing > this, even if it just means using a table; but i haven't found > anything specific on the net, just yet... > > apologies in advance if this isn't a relevant topic or if my > formulation of the problem is obnoxiously naive, and thanks very much > for your time. > > - ezra b
How about converting the whole thing into the log domain (input in db, output in db), interpolating in this domain (so the gain is now piecewise-linear), and then converting back to the linear gain using an approximation of exp()? Then you can interpolate in the log domain just by convolving with a sliding rectangular window. When the window is centered on your "knee" you will automatically be creating a smoothed range that extends from (t/k) to (t*k) (referenced to the linear domain). Bob Adams

Robert Adams wrote:

> On Jul 25, 4:11 pm, zebra <e...@eastwestsounds.com> wrote: > >>howdy, >> >>i have a perhaps kind of silly question. i'm trying to program a >>compressor with a variable knee, expressed as dB above and below the >>compression threshold. >> >>given the threshold, knee and ratio, i'd like to compute an >>interpolation function (preferably a polynomial for speed) that >>matches the values and first derivatives at the start and endpoints of >>the knee region. > > How about converting the whole thing into the log domain (input in db, > output in db), interpolating in this domain (so the gain is now > piecewise-linear), and then converting back to the linear gain using > an approximation of exp()? Then you can interpolate in the log domain > just by convolving with a sliding rectangular window. When the window > is centered on your "knee" you will automatically be creating a > smoothed range that extends from (t/k) to (t*k) (referenced to the > linear domain).
I think the whole idea of the smoothed variable knee is the unnecessary overcomplication. The perception of compressor depends mainly on the difference between the linear law and the compression curve. The shape of the curve doesn't really matter. For the practical purpose, it is enough to have as little as 3..4 compression ratio set points even without any interpolation in between. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
On Jul 27, 11:56&#4294967295;am, Vladimir Vassilevsky <antispam_bo...@hotmail.com>
wrote:
> Robert Adams wrote: > > On Jul 25, 4:11 pm, zebra <e...@eastwestsounds.com> wrote: > > >>howdy, > > >>i have a perhaps kind of silly question. i'm trying to program a > >>compressor with a variable knee, expressed as dB above and below the > >>compression threshold. > > >>given the threshold, knee and ratio, i'd like to compute an > >>interpolation function (preferably a polynomial for speed) that > >>matches the values and first derivatives at the start and endpoints of > >>the knee region. > > > How about converting the whole thing into the log domain (input in db, > > output in db), interpolating in this domain (so the gain is now > > piecewise-linear), and then converting back to the linear gain using > > an approximation of exp()? Then you can interpolate in the log domain > > just by convolving with a sliding rectangular window. When the window > > is centered on your "knee" you will automatically be creating a > > smoothed range that extends from (t/k) to (t*k) (referenced to the > > linear domain). > > I think the whole idea of the smoothed variable knee is the unnecessary > overcomplication. The perception of compressor depends mainly on the > difference between the linear law and the compression curve. The shape > of the curve doesn't really matter. For the practical purpose, it is > enough to have as little as 3..4 compression ratio set points even > without any interpolation in between. > > Vladimir Vassilevsky > DSP and Mixed Signal Design Consultanthttp://www.abvolt.com- Hide quoted text - > > - Show quoted text -
I agree; interpolation probably only makes a difference if you have just a single inflection point in your input/output graph, and the slope change is dramatic (like going from 1:1 to inf:1). Otherwise just use a few points with a gradual change of slope each time. On the other hand, there may be "marketing" reasons why you want a smooth curve; many users of pro-audio gear believe that a smooth curve sounds better than a piecewise-linear curve (it does have a certain intuitive appeal...) Bob Adams
hi, thanks!

well, i've proven to my satisfaction that there exists no family of
2nd or 4th order functions that does what i proposed. then i moved on
to other tasks, and now i'm returning to this one, trying to think
along other lines...

and well, i don't happen to agree that the interpolation doesn't
matter. it's a quite noticeable difference between various knee'd
compressors if you know what you're listening for...

> > > How about converting the whole thing into the log domain (input in db, > > > output in db), interpolating in this domain (so the gain is now > > > piecewise-linear), and then converting back to the linear gain using > > > an approximation of exp()?
of course, that was the first thing i programmed as a proof-of- concept. i'm going back to using this approach more directly; the problem is now finding an acceptable fast approximation of log10(x) and 10^x, polynomial or otherwise... i'd rather not use a table, btw... any suggestions there are much appreciated!
> > > I think the whole idea of the smoothed variable knee is the unnecessary > > overcomplication. The perception of compressor depends mainly on the > > difference between the linear law and the compression curve. The shape > > of the curve doesn't really matter. For the practical purpose, it is > > enough to have as little as 3..4 compression ratio set points even > > without any interpolation in between.
i respect your opinion but i happen to have a different one. using a sharp knee adds spectral energy to the attack to a perceptually significant degree, using a couple of linear segments would do the same to a slightly lesser degree. different compressors sound demonstrably different even with the same nominal settings, especially on signals where it really matters, like, i dunno, bassy electronic kick drums... nicely recorded low piano notes... percussive things with characteristic attacks and lots of low frequencies. i'm guessing you wouldn't argue that the shape of the attack/release smoothing doesn't matter... or that a 60hz triangle wave sounds the same as a 60hz sine wave. incidentally, my application is unusual: this compressor will be used polyphonically as part of a synthesis chain, so speed and fidelity are very important. i really would like to introduce as little harmonic distortion as possible, and smoothing the knee will definitely help (sorry!)
> I agree; interpolation probably only makes a difference if you have > just a single inflection point in your input/output graph, and the > slope change is dramatic (like going from 1:1 to inf:1).
but that's exactly the critical test case! limiter on the kick drum, anyone?
> On the other hand, there may be "marketing" reasons why you want a > smooth curve; many users of pro-audio gear believe that a smooth curve > sounds better than a piecewise-linear curve (it does have a certain > intuitive appeal...)
well, i'm not a marketing person, so that's not really my motivation... i guess i'm one of those people you mention, because i really have spent a LOT of time using compressors (analog, digital, cheap, expensive, clean, dirty... this input, that sound...) and, inevitably, thinking about how they work and how they might work better. i don't think my problem is a conceptual one. my problem is really about math. anyways, thanks so much to everyone for your time! \eb
On Jul 31, 2:44&#4294967295;pm, zebra <e...@eastwestsounds.com> wrote:
> hi, thanks! > > well, i've proven to my satisfaction that there exists no family of > 2nd or 4th order functions that does what i proposed. then i moved on > to other tasks, and now i'm returning to this one, trying to think > along other lines... > > and well, i don't happen to agree that the interpolation doesn't > matter. it's a quite noticeable difference between various knee'd > compressors if you know what you're listening for... > > > > > How about converting the whole thing into the log domain (input in db, > > > > output in db), interpolating in this domain (so the gain is now > > > > piecewise-linear), and then converting back to the linear gain using > > > > an approximation of exp()? > > of course, that was the first thing i programmed as a proof-of- > concept. i'm going back to using this approach more directly; the > problem is now finding an acceptable fast approximation of log10(x) > and 10^x, polynomial or otherwise... i'd rather not use a table, > btw... any suggestions there are much appreciated! > > > > > I think the whole idea of the smoothed variable knee is the unnecessary > > > overcomplication. The perception of compressor depends mainly on the > > > difference between the linear law and the compression curve. The shape > > > of the curve doesn't really matter. For the practical purpose, it is > > > enough to have as little as 3..4 compression ratio set points even > > > without any interpolation in between. > > i respect your opinion but i happen to have a different one. using a > sharp knee adds spectral energy to the attack to a perceptually > significant degree, using a couple of linear segments would do the > same to a slightly lesser degree. different compressors sound > demonstrably different even with the same nominal settings, especially > on signals where it really matters, like, i dunno, bassy electronic > kick drums... nicely recorded low piano notes... percussive things > with characteristic attacks and lots of low frequencies. > > i'm guessing you wouldn't argue that the shape of the attack/release > smoothing doesn't matter... or that a 60hz triangle wave sounds the > same as a 60hz sine wave. > > incidentally, my application is unusual: this compressor will be used > polyphonically as part of a synthesis chain, so speed and fidelity are > very important. i really would like to introduce as little harmonic > distortion as possible, and smoothing the knee will definitely help > (sorry!) > > > I agree; interpolation probably only makes a difference if you have > > just a single inflection point in your input/output graph, and the > > slope change is dramatic (like going from 1:1 to inf:1). > > but that's exactly the critical test case! limiter on the kick drum, > anyone? > > > On the other hand, there may be "marketing" reasons why you want a > > smooth curve; many users of pro-audio gear believe that a smooth curve > > sounds better than a piecewise-linear curve (it does have a certain > > intuitive appeal...) > > well, i'm not a marketing person, so that's not really my > motivation... i guess i'm one of those people you mention, because i > really have spent a LOT of time using compressors (analog, digital, > cheap, expensive, clean, dirty... this input, that sound...) and, > inevitably, thinking about how they work and how they might work > better. i don't think my problem is a conceptual one. my problem is > really about math. > > anyways, thanks so much to everyone for your time! > > \eb
I agree that having a limiting function with 1 sharp knee is a bad idea. I guess I was trying to say that if you took an ideally- interpolated curve and broke it into 3 or 4 small "chords" that approximate the interpolated portion of the curve, it's probably going to sound the same. You just want to avoid a large change in slope between one region and the next. Back when I worked at dbx we used the log characteristics of a diode to make these smooth functions. It takes a lot of MIPs to make a decent diode these days .... Bob Adams

zebra wrote:

>>>>I think the whole idea of the smoothed variable knee is the unnecessary >>>overcomplication. The perception of compressor depends mainly on the >>>difference between the linear law and the compression curve. The shape >>>of the curve doesn't really matter. For the practical purpose, it is >>>enough to have as little as 3..4 compression ratio set points even >>>without any interpolation in between. > > > i respect your opinion but i happen to have a different one. using a > sharp knee adds spectral energy to the attack to a perceptually > significant degree, using a couple of linear segments would do the > same to a slightly lesser degree. different compressors sound > demonstrably different even with the same nominal settings, especially > on signals where it really matters, like, i dunno, bassy electronic > kick drums... nicely recorded low piano notes... percussive things > with characteristic attacks and lots of low frequencies. > > i'm guessing you wouldn't argue that the shape of the attack/release > smoothing doesn't matter... or that a 60hz triangle wave sounds the > same as a 60hz sine wave.
The compressor operates on the envelope of the signal rather then on the waveform. Its operation is quite slow: typically tens to hundreds of milliseconds. You won't be able to distinguish the 500Hz tone with triangular or sinusoidal amplitude modulation with the tens of Hz.
> incidentally, my application is unusual: this compressor will be used > polyphonically as part of a synthesis chain, so speed and fidelity are > very important. i really would like to introduce as little harmonic > distortion as possible, and smoothing the knee will definitely help > (sorry!)
We used the compressors in the consumer audio products, and I played with the different settins for a while. My impression is what matters is the compression ratio, i.e. the deviation from the linear law. The shape of the curve is largely unimportant. Very few people can actually make use of the compressor for the sound effects.
> >>I agree; interpolation probably only makes a difference if you have >>just a single inflection point in your input/output graph, and the >>slope change is dramatic (like going from 1:1 to inf:1). > > but that's exactly the critical test case! limiter on the kick drum, > anyone?
This is the case of the peak limiter, which is quite different. I tried the lookahead as well as the nonlinear clipping of the peaks vs the speedy gain adaptation. For the best results, both the instant nonlinearity and the adaptive gain should be used. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
> The compressor operates on the envelope of the signal rather then on the > waveform. Its operation is quite slow: typically tens to hundreds of > milliseconds.
hm... i really do know what a compressor does. attack times of < 2ms, or even <1ms, are not that unusual nowadays, and are desired for my application; hence the desire to avoid discontinuities in both the gain function and its first derivative if possible, the idea being to minimize harmonic distortion since this will be applied to VERY clean sounds, potentially. You won't be able to distinguish the 500Hz tone with
> triangular or sinusoidal amplitude modulation with the tens of Hz.
i don't think i really understand the phrasing here; i can indeed distinguish between waveforms of a 10hz modulator, or a 500hz modulator, or whatever, but that's not really too important; the hypothetical 60hz waveform was only an attempted analogy to the perceptual range you might experience with differently shaped knees in a compressor with about 15ms attack time. perhaps its not even a very good analogy; i am happy to abandon it.
> We used the compressors in the consumer audio products, and I played > with the different settins for a while. My impression is what matters is > the compression ratio, i.e. the deviation from the linear law. The shape > of the curve is largely unimportant. Very few people can actually make > use of the compressor for the sound effects.
??? well, i don't know if it matters, but this is a product for pro audio work. these people are VERY picky and probably have an avalon ad2044 or something in the rack to pit my gain function against. i've got a whole other set of logic to manipulate the shape and length of the release curve based on the compression history. serious business here.
> >>I agree; interpolation probably only makes a difference if you have > >>just a single inflection point in your input/output graph, and the > >>slope change is dramatic (like going from 1:1 to inf:1). > > > but that's exactly the critical test case! limiter on the kick drum, > > anyone? > > This is the case of the peak limiter, which is quite different. I tried > the lookahead as well as the nonlinear clipping of the peaks vs the > speedy gain adaptation. For the best results, both the instant > nonlinearity and the adaptive gain should be used.
????? as far as i'm concerned, peak limiting and compression are the same thing with different speeds and ratios. most smart engineers indeed know that you want to chain a fast/hard/high threshold and a slow/soft/low threshold one, for maximum transparency. look-ahead is not an option here because we might only get one sample at a time. but, please, never mind. forget that i am making a compressor. i understand compressors much better than i understand differential equations, unfortunately, so i am struggling with interpolating functions. that is my struggle. i'd rather not talk about what kinds of compression sound good; that's a flameworthy topic on other forums that kind of bores me in the first place, my own ideas being unlikely to change unless informed by the actual experiences of my ears. peace dudes! \eb
> I agree that having a limiting function with 1 sharp knee is a bad > idea. I guess I was trying to say that if you took an ideally- > interpolated curve and broke it into 3 or 4 small "chords" that > approximate the interpolated portion of the curve, it's probably going > to sound the same. You just want to avoid a large change in slope > between one region and the next.
ah! that makes sense. the work that i've done seems to show that it's impossible to match the derivatives exactly with a polynomial no matter how many segments you use. but i could be wrong. i'm by no means expert (or even very adept) with interpolation theory, so i thought perhaps there was a well-known set of bases that gets close, or a clever non-polynomial approach... or i don't really know what.
> Back when I worked at dbx we used the log characteristics of a diode > to make these smooth functions. It takes a lot of MIPs to make a > decent diode these days ....
ha! i guess that kind of sums things up, doesn't it. thanks so much for your time guys \eb \eb