SynthMeder ·
low cpu usage 🙂
From the original SynthMaker forum (2004–2014), with its members’ names and dates.
SynthMeder ·
low cpu usage 🙂
trogluddite ·
Many thanks SynthMeder 🙂 , I love the way you've split the code down and named everything so we can see how it works - should make it nice and easy to convert to assembly too! Just found the preference to control the curve radius too - much prefer your nice neat right angles to the default bendy loops!
The Luddite
nabulas1234 ·
Is it your work? I saw something similar but more complicated to this not long ago. Is this a simpler version of "GCompressor" (posted here already)? :>
RunBeerRun2 ·
Thanks, I'll eventually poke seriously through it, I'm starting to make mastering stuff, haven't started in SM yet.
oddson ·
The Threshold seems wrong to me...
cf. http://en.wikipedia.org/wiki/Dynamic_ra ... #Threshold
Here the Threshold is the reverse; it's how much of the signal is passed -- so the higher the value the more is passed without attenuation.
Also, doesn't it make more sense to convert the threshold and ratio values from decibels to linear multipliers while they're in the green world rather than have to convert the Envelop Follower's output in the stream world (especially as the invert function needs that fancy Taylor series math?
Or am I missing something? 😕
aliasant ·
oddson wrote: The Threshold seems wrong to me...
cf. http://en.wikipedia.org/wiki/Dynamic_ra ... #Threshold
Here the Threshold is the reverse; it's how much of the signal is passed -- so the higher the value the more is passed without attenuation.
Also, doesn't it make more sense to convert the threshold and ratio values from decibels to linear multipliers while they're in the green world rather than have to convert the Envelop Follower's output in the stream world (especially as the invert function needs that fancy Taylor series math?
Or am I missing something? 😕
Threshold. Yes. If Thresh is set to, say -24dB, everything lower then that should be clipped away so signal is 0. Anything above the clip is what you use.
You can convert all dB to linear in green but it will sound different 😉
oddson ·
aliasant wrote: ...You can convert all dB to linear in green but it will sound different 😉
Why would that be? Multiplication is communitive, and it's all multiplication, so why would it matter?
(Of course I've been wrong with stuff like this before... in fact I usually am, but I'd still like to understand.)
aliasant ·
oddson wrote: aliasant wrote: ...You can convert all dB to linear in green but it will sound different 😉
Why would that be? Multiplication is communitive, and it's all multiplication, so why would it matter?
(Of course I've been wrong with stuff like this before... in fact I usually am, but I'd still like to understand.)
Ssssshh
Secrets 🙂
exonerate ·
oddson wrote: aliasant wrote: ...You can convert all dB to linear in green but it will sound different 😉
Why would that be? Multiplication is communitive, and it's all multiplication, so why would it matter?
(Of course I've been wrong with stuff like this before... in fact I usually am, but I'd still like to understand.)
**Edit** read my next post I now don't believe doing it in linear or decibel should sound different **edit**
Well my understanding of compression is quite basic, but I do understand why they sound different. Forget the multiply the difference comes from the subtraction (in the transfer function). Subtracting two linear values will not give the same answer as subtracting two decibel equivalents and then converting back to linear.
Using the formula from the compressor lets say the input to the transfer function is -10db and the thresh is set to -20db
So -10 - -20 = 10
then this is subtracted from 0 so we have -10 now converting that to linear gives 0.31622776
Doing the same with linear values gives different results..
So in linear the input would be 0.31622776 and the thresh 0.1
Subtracting these gives 0.21622777.
Of course with the linear version there no need to subtract from 0, that is needed only in the decibel version for the db to linear conversion.
These end linear values are what the stream is being multiplied with, so obviously both ways will sound different, I'm guessing using decibels gives a more natural sound or something. 🙂
Cheers 😉
Exo
exonerate ·
Actually thinking about this further doing it in linear should sound the same. If you was doing it in linear then you would have to change the transfer function as it wouldn't work correctly as it is because it's designed to work on decibels.
Doing it in linear the transfer function could be changed to.... thresh / in
Using the same thresh and input from my last post gives 0.31622776
Which is exactly the same values as the decibel version.
So I would of though sounds exactly the same.
So converting the stream to decibels is pointless? unless someone can prove me wrong. 😉
Cheers 😉
Exo
oddson ·
Thanks Exo
My mistake was thinking the 'transfer function' was an all-or-nothing thing... I thought the code passed the signal if above the threshold and output the threshold otherwise (I know that doesn't make any sense but I just didn't think it through).
Once I read your explanation I realized it did matter (although I didn't really follow the specifics of your argument the mere fact that it's subtraction meant the communitive property doesn't hold).
Then I thought there should be a way to use the fact that adding (subtracting) dB values is like multiplying (dividing) linear.... and before I could think it through there was your second post.
I'm going to think on it a bit more to make sure I'm understanding the how the threshold should work and then give it a try. 🙂
exonerate ·
I knocked up a quick example osm....
exonerate ·
oddson wrote: Thanks Exo
My mistake was thinking the 'transfer function' was an all-or-nothing thing... I thought the code passed the signal if above the threshold and output the threshold otherwise (I know that doesn't make any sense but I just didn't think it through).
Once I read your explanation I realized it did matter (although the specifics of your argument still don't seem correct to me but the mere fact that it's subtraction meant the communitive property doesn't hold).
Then I thought there should be a way to use the fact that adding (subtracting) dB values is like multiplying (dividing) linear.... and before I could think it through there was your second post.
I'm going to think on it a bit more to make sure I'm understanding the how the threshold should work and then give it a try. 🙂
Ok I'm very interested in all this myself, I'm currently working on a multiband compressor. 😀
Cheers 😉
Exo
oddson ·
exonerate wrote: I knocked up a quick example osm....
Nice! - I think that proves the point. It shows there's no real need for converting the Envelope Follower's output to get the math to work and that's got to save a massive amount of processing.
So below the threshold the function should output unity and above threshold/input - is that right?
Next thought... any obvious way to soften that knee?
exonerate ·
oddson wrote: exonerate wrote: I knocked up a quick example osm....
Nice! - I think that proves the point. It shows there's no real need for converting the Envelope Follower's output to get the math to work and that's got to save a massive amount of processing.
So below the threshold the function should output unity and above threshold/input - is that right?
Next thought... any obvious way to soften that knee?
Yep that's right. 😀
Regarding soft knee not sure how to implement such a thing just yet, I don't think it's as simple as putting a lowpass before the output?
The multi band compressor I'm working on naturally has a variable soft knee because I'm using a modified version of the multistage env for the transfer function.
I think a soft knee might work by gradually smoothing in the ratio, instead of just multiplying. Not sure though would need to know exactly what was one was before trying to implement it ha ha. 😀
Cheers 😉
Exo
MegaHurtz ·
I think a controlled satturation will sound better, and is way more forward thinking than the loopy filter designs. Although a fixed frequency liniar irr would be cheaper than an eg, and a transfer curve cheaper than the both.
infuzion ·
MegaHurtz wrote: I think a controlled satturation will sound better, and is way more forward thinking than the loopy filter designs. Although a fixed frequency liniar irr would be cheaper than an eg, and a transfer curve cheaper than the both.
Someday, when I grow up to be a man, I will understand what you just said.
bootsy ·
About the logarithmic audio encoding in a compressor: This is just done to obtain the exponential attack and release curve behaviour but just by using a simple (linear) envelope follower. Plain linear curves doesn't sound that good but there are other techniques to compensate for that as well, e.g. making a simple envelope follower program dependent especially in feedback structures can really smooth the curves.
About the soft-knee thing: I don't see why any additional LP Filtering in the sidechain should provide soft knee characteristics (if so, the envelope follower should already provide soft-knee then, since it performs LP filtering as well).
About constructing a basic soft-knee transfer curve just design a three-way splitted function which is something like: f(x) = x for all x<A | g(x) for A<=x<=B | x*R for x>B where R is the ratio and g(x) is a "rounding" curve which connects both linear sections and is a function which is C2 continous at the crossover points A and B. g(x) could be a rather simple polynomial, you just have to find/construct a proper one 😈
Be aware that in feedback topologies (opposed to feedforward compression design) things like the resulting transfer curve typically look different from what your math program plots. I even had a soft-knee curve under my fingers which just worked in a FB design but not at all in a FF structure.
TomC ·
bootsy wrote: About constructing a basic soft-knee transfer curve just design a three-way splitted function which is something like: f(x) = x for all x<A | g(x) for A<=x<=B | x*R for x>B where R is the ratio and g(x) is a "rounding" curve which connects both linear sections and is a function which is C2 continous at the crossover points A and B. g(x) could be a rather simple polynomial, you just have to find/construct a proper one 😈
Some additional hints:
- make A and B freely adjustable
- C1 continuity is almost always good enough. I've even build a compressor with C0 continuity and it sounded as expected. So don't overcomplicate your live!
Tom
exonerate ·
bootsy wrote: About the logarithmic audio encoding in a compressor: This is just done to obtain the exponential attack and release curve behaviour but just by using a simple (linear) envelope follower. Plain linear curves doesn't sound that good but there are other techniques to compensate for that as well, e.g. making a simple envelope follower program dependent especially in feedback structures can really smooth the curves.
About the soft-knee thing: I don't see why any additional LP Filtering in the sidechain should provide soft knee characteristics (if so, the envelope follower should already provide soft-knee then, since it performs LP filtering as well).
About constructing a basic soft-knee transfer curve just design a three-way splitted function which is something like: f(x) = x for all x<A | g(x) for A<=x<=B | x*R for x>B where R is the ratio and g(x) is a "rounding" curve which connects both linear sections and is a function which is C2 continous at the crossover points A and B. g(x) could be a rather simple polynomial, you just have to find/construct a proper one 😈
Be aware that in feedback topologies (opposed to feedforward compression design) things like the resulting transfer curve typically look different from what your math program plots. I even had a soft-knee curve under my fingers which just worked in a FB design but not at all in a FF structure.
Thanks for the insight bootsy! 🙂
I overlooked the effect log encoding would have on an envelope follower. I was analysing the example in this thread, in that example the envelope follower is before the log encoding. So concerning this particular example the log encoding is indeed pointless!
I'm thinking then that creating a non linear envelope follower could be done a lot more efficiently than log encoding the entire stream. In fact I'm going to make that my next little project as I'm currently using a linear envelope follower in my multi band compressor.
Cheers 😉
Exo
exonerate ·
Hmmm why is the envelope follower linear? linear to me implys straight lines which the envelope follower doesn't have (obviously because it's a lowpass filter). So is it just a case of increasing these curves for a better sound?
Bootsy what do you mean by e.g. making a simple envelope follower program dependent especially in feedback structures can really smooth the curves.
I don't understand the "program dependent" bit. 🙂
Cheers 😉
Exo
oddson ·
The Envleope Follower is linear because its an averaging of rectified values.
It's linear in that there's no exponential math involved.
I think... at this point I've been wrong so many times. 😕
oddson ·
Ok... dB gain reduction is intrinsically non-linear and a factor of -1/x doesn't do the job.
I still don't see why the need to go all-the-way into logs and then all the way out... why not just calculate the non-linear functional values? (It seems to me it's more stream math than should be required.)
If (ignoring log basses and altering constants as needed):
log(y) = log(t) + m * (log(x-t)) // where t is a threshold and m is the slope above the knee (1/ratio?).
Then shouldn't we get something like:
y = t * (x-t)^m
So we still need to do a power function on a stream of data but don't need to go in to, and out of log values for everything.
I await being shown to be wrong yet again. 🙂
bootsy ·
exonerate wrote: I overlooked the effect log encoding would have on an envelope follower. I was analysing the example in this thread, in that example the envelope follower is before the log encoding. So concerning this particular example the log encoding is indeed pointless!
Yes, then it would be a waste of cpu. We don't need it for the compression transfer curve.
exonerate wrote: I'm thinking then that creating a non linear envelope follower could be done a lot more efficiently than log encoding the entire stream.
There is definately potential but I think at least you have to compute one exp(), probably.
bootsy ·
exonerate wrote: Bootsy what do you mean by e.g. making a simple envelope follower program dependent especially in feedback structures can really smooth the curves.
I don't understand the "program dependent" bit. 🙂
For example let us consider just the release time calculation in the envelope follower. A common technique is to add a RMS detector and to slow down the release time with it right when the RMS level goes down. Now, the release curve isn't linear anymore but similiar in the curve as an exp decay curve. In fact, it is not only level dependent as the exp curve, but truly program dependent since the RMS computation depents on the actual audio material and it's (short time) history.
MegaHurtz ·
I think the best is the RMS, maybe there are cheaper analogues? Since the powers have a very limitted domain, you might yust get away with (log A*A).
bootsy ·
oddson wrote: Ok... dB gain reduction is intrinsically non-linear and a factor of -1/x doesn't do the job.
I still don't see why the need to go all-the-way into logs and then all the way out... why not just calculate the non-linear functional values? (It seems to me it's more stream math than should be required.)
If (ignoring log basses and altering constants as needed):
log(y) = log(t) + m * (log(x-t)) // where t is a threshold and m is the slope above the knee (1/ratio?).
Then shouldn't we get something like:
y = t * (x-t)^m
So we still need to do a power function on a stream of data but don't need to go in to, and out of log values for everything.
I await being shown to be wrong yet again. 🙂
I would not mix the log/exp thing and the transfer curve computation because as discussed earlier here it does not relate to another - it just matters for the envelopes. But your suggestion to find a simpler non-lin function could be the challenge here, so we would have a scaling function one could simply add right into the standard envelope follower to obtain curves somehow similar to the exponential ones.
MegaHurtz ·
It think a soft knee should never be more than a rolloff between T and 1. The curve behind this has little sceintific meaning, except increasing your gain range. All be it a natural phenomena, thus a measurement of energy in the peak detection will help. I think more important for a good compressor is 64bit floats, at a high samplerate. Always staying true to the fact that if you cant get it out that way you didnt need more than a filter in the first place.. so you`d always have to dither.
oddson ·
This thread is getting a bit messy and is now completely off the topic of the basic compressor example (which is completely my fault).
There are three basic ideas being discussed.
1) Is there a cheaper way to calculate gain value to track the standard compression ratio system which shows a linear segment above the knee in the log-log plot?
2) Could a non-linear envelope follower could allow you to use a linear gain to avoid the issue in 1) altogether?
3) Is there a way to use a filter to soften the knee and thereby avoiding the need for a segmented function?
I don't understand the arguement in 3) at all.
I don't understand how 2) could work except as a 'sounds OK to me' method. I can't see how it would allow you to get something like a linear dB reduction above a threshold value but I can see how different methods of following an envelope would produce greatly differing results (and this seems to mirror what happens in the analogue world with photo-electronics and other exotic devices).
And obviously I haven't figured out if my point for 1) is valid at all.
I'm prepared to let my point drop for now as I've come to realize there's a lot more math and science to this that I first thought and I'll need to study the subject in much greater detail.
Does anyone feel further discussion on any of these points would be more productive in separate threads in the Sound section rather than discussing this self-described 'basic compressor'?
There was one other thing... somewhere above I asked if the Threshold knob is backwards in the example we're supposedly discussing. It seems to me this is simply because the control has 0 as min and -50 as max where it should be the reverse.
MegaHurtz ·
You are right.. Although I dont really get point 1. I did a clipper a while back that shows you the liniar plot.. But I assume you`d want the loge1 plot"?
MegaHurtz ·
the logarithm of exp in the 0-1 domain 😉
Wrote something here? To have a post removed or your name hidden, write to [email protected].