How to implement a compressor in Pd as a patch?
@porres Explanation and patch from @katjav is now updated for Vanilla....... http://www.katjaas.nl/compander/compander.html
The main problem in the digital domain is knowing the power of the signal in advance so as to reduce it according to that power. It can be done but introduces a delay to the signal that will be disturbing in a live environment, or it is not done and a fast attack will get through the compressor.
That looks (no delay) to be the case with the cyclone abstraction.
It can be acceptable..... analogue compressors have an "attack" control that controls the delay before compression, but in the digital domain you normally have no choice.
She has solved that problem.
David.
How to implement a compressor in Pd as a patch?
Howdy, I'm giving a try at how to implement a compressor as a Pd patch. This is what I came up with, it needs cyclone 0.3! ==> compression~.zip
I'm using rms average to detect the gain level and rampsmooth~ to perform attack/release. I wouldn't know how to do it in Vanilla...
Seems rough and rudimentary. It's more of an intuitive approach, as I don't know much about compressor design.
I'm hoping to get feedback from you people on how to implement a compressor in Pd as a patch and how and why this approach is "ok" and can be improved, or if it's all terribly wrong.
Are there any other attempts to implement compession in Pd out there?
Thanks
Cheers
Compressor attack / release time
For the broken language your issue isn't really clear to me.
Maybe this will help:
[>]
[<=]
[>=~]
[<~]
[threshold~]
[select]
[expr if(condition, ifTrue-expr, ifFalse-expr)]
[expr~ if (condition, ifTrue-expr, ifFalse-expr)]
[expr~ if($v1>0.5, 10, 20)]
also look inside the expr-helpfile
A compressor patch is explained here:
http://designingsound.org/2013/06/28/tutorial-a-compressor-in-pure-data/
Does setting the various gains on stacked effects make any difference? Or...
The numerical considerations of digital arithmetic are something to think about as whale-av mentions
Also, every effect is different. Obviously some function in a way that will alter the volume, or behave non-linearly with inputs of different volume.
An example might be a filter combined with an expander or compressor. At different frequencies the signal will have bigger or smaller amplitude, and will therefore interact with the compressor differently.
Another example would be a wave shaper
There are things called "linear operations" Most filters are linear. This basically means that if you switch the order of them the outcome will be the same, or if you change the volume of the input signal the volume of the output will be proportional to the change
What's your favorite noisegate?
Been having issue with the noisegates I use (all based on the fft library). (They all sound like I am talking from underwater.
Any suggestions? :---))) besides just renting studio time. Maybe I just need to change the settings when it gets the mask??? To?
Had thought the compressor I have been working on would solve the problem.
But, alas, alack, (DOH!!! mark it up as just another example on the learning curve) all the noise is still there when the compressor kicks in.
So that concept is a wash. i.e.: sure it works when there is just noise. But that is not what I want/need.
Eagerly and much excitedly awaiting your response,
-svanya
Little help please: building my own compressor (updated below...)
@whale-av
'Some compressors (AKG were the first I remember) introduce a tiny delay to the main signal so as to introduce the required compression before the signal arrives (catch all transients). That is called "feed forward compression"':
I incorporated this as a "lookahead" passing a variable to the initial delay line;
'You will also see (on manufactured units) "attack" (time for compression to ramp up....... approx.? 0-10ms.... to allow short transients to pass more naturally... un-"chopped") and "release" (the time to slowly release the compression after the signal has dropped below the threshold again....... 50ms-2sec.... usually about 300ms is good for vocals)';
I included these and the numbers you suggest as the ramp values for attack: from below threshold to the "ratio" value and decay for below-threshold to a percent between that value and 0 (think this is a good option, because it sounds really screwy when it drops to nothing) and for those values above-the-limit dropping to the limit.
'bad microphone technique.': For example?
'knee': how to add this? via ADSR envelope? not sure how I would go about make the curve (soft knee)...suggestions?
'your patch looks like a spaghetti omelette to me at the moment!': I was sorry to hear this for two reason: the pain you must have/are undergoing and that perhaps my patch was a "mess". (not time to be sensitive tho. so pushed on.) Hope all is doing better for you.
Regarding this update:
ALL:
the controls:
limit, ratio, threshold, and makeup gain are all calibrated on the fly using the updateControls subpatch which scales the "left" and "right" values of each control (using range messages) accordingly
all signals are grouped into 4 categories using the moses's: below-threshold, above-threshold-below-ratio, above-ratio-below-limit, and above-limit
limit:
"above limit" signals are brought down to this limit
ratio:
"above ratio-below limit" signals are left untouched
threshold:
"above threshold-below ratio" are brought up to the ratio value
above_env:
Is to be used as a noisegate meter if the value is a positive number then the threshold is above the env~, i.e. background noise
attack/decay and ?:
? because I am not certain, if in the context of compressors I have applied these concepts correctly:
attack: the length of time it takes to make the upward ramps, 0-10 ms
decay: the length of time it takes to make the downward ramps, 50-2000 ms
% drop:
what percent between 0 and the threshold the signal is to be decreased, in other words, filter the noise completely or just a little bit, 100% drops it to 0, 1% drops it 1% below the threshold (fyi: I found dropping it completey to 0 sounded "wrong")
makeup gain:
the amount to increase the final output, between the limit and 1
lookahead:
how much time the delay line should be between 0-100 ms (have NO idea what range this "should" be, so input is requested)
ramps:
graphical representation (from left to right) of the the threshold, ratio, and limit on a 0 to 1 scale
meterLimit:
the env~ (really just a vu) and a line representing where the threshold is on that same scale (0 to 1) in order to better judge where to set the values
which_range:
A meter showing from left-to-right where the current sound is (to be used as simple guide to setting the parameters): silence, above silence-below threshold, above threshold-below ratio, above ratio-below limit, and above limit
I DO hope this is useful to someone/anyone. And ,if nothing else, might act as a guide to others addressing this pretty-darn challenging concept.
I have included some features which I have not seen other compressors include, while there are others I might or probably will/should include later, ex. a soft knee on the curves.
All opinions/insight/daily feelings/usage of/ etc. etc. etc. are very welcome.
Peace and may your days, hearts, minds, and loved ones be over-flow-ering with Music.
-svanya
p.s. will probably move this lateron to the abstractions section, once I am certain everything is working as planned.


Little help please: building my own compressor (updated below...)
@svanya As you say...... it's a lot easier to understand when you have made it yourself!
The term "below threshold" is when the incoming signal is not high enough to reach the threshold...... and "above" when it is higher...... it is sort of logical.....
Choosing the threshold level is crucial to the best use of the compressor.
Some compressors (AKG were the first I remember) introduce a tiny delay to the main signal so as to introduce the required compression before the signal arrives (catch all transients). That is called "feed forward compression" if I remember well. It is ok for the studio, but less of a good idea live work. Very good for a "limiter" though as it catches everything...
You will also see (on manufactured units) "attack" (time for compression to ramp up....... approx.? 0-10ms.... to allow short transients to pass more naturally... un-"chopped") and "release" (the time to slowly release the compression after the signal has dropped below the threshold again....... 50ms-2sec.... usually about 300ms is good for vocals)
Compression is good for 2 things and maybe more....... clamping the dynamic range, and so smoothing out the effects of bad microphone technique.......
...... and increasing the "power under the curve" and so increasing loudness without an increase in level....... which guitarists value highly, as the transformer/valve combination of a valve amplifier introduces distortion of the signal as the transformer reaches saturation, that we now call "compression".... (and other distortions, but keep that to yourself!)........ So compression is always used for mastering now, as there is no analogue tape (which compressed everything anyway in the "good ole days")......
Don't get me going!
All of the extra touches (knee, attack, release, etc.) have been added in an attempt to hide any unpleasant effects of the compression for the human listener......
David.
Little help please: building my own compressor (updated below...)
@svanya Hello Svanya.....
Yes, what you are calling the "floor" is (probably) the level at which the compression starts to operate, and is called the "threshold". Some compressors also have expanders, which apply a gain before the compression threshold and aid with the "levelling" of the signal..............

Expansion raises the gain before the threshold, but raises the noise floor of course at the same time, so often they have a gate as well to mute the input below a certain level.
The "ratio" is the ratio between the output level without compression, and the level with compression applied. What you are calling the "ceiling" is probably the level at which "hard" limiting is applied.............

A soft "knee" at the threshold level helps to reduce the "obviousness" of the change for the listener. Of course the hard limit is much better applied after the compressor to "cap" the final output and prevent distortion if the compression is insufficient.
Some studio compressors then automatically apply an output gain (compensation) to increase the overall level after compression, but for "live" use that is highly dangerous, as if you reduce the threshold or increase the ratio the "automatic gain" will induce acoustic feedback immediately.
David.
Little help please: building my own compressor (updated below...)
Have been trying to wrap my mind around this (compressors/sion) for some time, then today stumbled on the ADSR abstraction it (almost
) suddenly became a lottt clearer.
And from last night, when I was working with brinkman's st-limiter and finally (!-ugh!) understood it was NOT trying to limit the sounds that came in (I have been searching for the Best Possible noisegate I can find, since i use a mic and acoustic guitar) but instead is intended to prevent clipping (like a normalize~ function/patch i have previously written) and so bring down sounds that are too loud.
Sought out other limiters and found one I completely comprehended so added/modified it to take a floor value as well as ramp time as parameters, not just its limit value. And decided I might as well go "all the way" and just make my own compressor, since I understand things waaayyy better when I just make them myself.
Also modified a ADSR (attack/decay/sustain/release) abstraction to be triggered with a metro+metro duration, to run continuously. CPU overhead is not too bad so am thinking a compressor is within reach.
So my question is:
Why can't I, or perhaps even "How could I?", conjoin these two patches (below+images of their _help files) to create a compressor, which has a, d, s, r + floor/threshold + ceiling/limit.
Also, i have translated "threshold" to be my "floor" so: am I right that "ratio" is the ratio of what I am calling "floor" and "ceiling"?
Feels like there is sooo much I am NOT getting. But as my ever-loyal son put it "Yes. But you DO know so much."
Ever is the humble pure-d artist,
s
p.s. thanks, in advance for any and all help you might give. It is ALL much appreciated. And once, I get this put together I will share it, and properly credit those who made the original patches.





