Skip to content

Commit 060238b

Browse files
committed
Code quality and maintenance
Renamed Enabled/Disabled values to Activated/Deactivated. Trivially Britified the English in some places and fixed some typos. Improved dB/amplitude conversion precision and speed in some places. Removed slow and unprecise "fastReciprocal" function, replaced it with fast and precise "slow 1/x" instead. Various other minor code, performance and/or precision improvements. Advanced version number to 1.8.3.
1 parent 6f720e5 commit 060238b

37 files changed

+153
-185
lines changed

Clipper/hard_clipper.jsfx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
desc: Hard Clipper
2-
version: 1.8.2
2+
version: 1.8.3
33
author: chokehold
44
tags: processing gain amplitude clipper distortion saturation
55
link: https://github.com/chkhld/jsfx/
@@ -16,7 +16,7 @@ about:
1616
smoother, but it comes at the cost of losing true 0 dBfs
1717
peak safety from all the filtering. If you need reliable
1818
0 dBfs peak safety, then load another clipper after this,
19-
or just simply disable oversampling.
19+
or just simply deactivate oversampling.
2020

2121
Since hard clipping causes lots of aliasing, I've added
2222
a DC Blocker, can't hurt to have it ready, just in case.
@@ -25,7 +25,7 @@ about:
2525
slider1:dBCeil=0<-48, 0,0.01> Ceiling dBfs
2626
slider2:dBGain=0< 0,48,0.01> Boost dB
2727
slider3:ovs=0<0,1,{Off,On}> Oversampling
28-
slider4:blocker=0<0,1,{Enabled,Disabled}> DC Blocker
28+
slider4:blocker=0<0,1,{Activated,Deactivated}> DC Blocker
2929

3030
in_pin:left input
3131
in_pin:right input
@@ -38,7 +38,7 @@ out_pin:right output
3838
ups = 100000;
3939

4040
// Decibel to gain factor conversion
41-
function dBToGain (decibels) (10.0 ^ (decibels / 20.0));
41+
function dBToGain (decibels) (pow(10, decibels * 0.05));
4242

4343
// Hard clipping function with ceiling
4444
function hardclip ()
@@ -147,7 +147,7 @@ out_pin:right output
147147
);
148148
);
149149

150-
// If DC blocking enabled
150+
// If DC blocking activated
151151
blocker == 0 ?
152152
(
153153
// Run the DC blocker on each sample

Clipper/knee_clipper.jsfx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
desc: Knee Clipper
2-
version: 1.8.2b
2+
version: 1.8.3
33
author: chokehold
44
tags: processing gain amplitude clipper distortion saturation
55
link: https://github.com/chkhld/jsfx/
@@ -11,7 +11,7 @@ about:
1111

1212
Hard clippers are usually lamented about as producing digital, cold and nasty
1313
sound. But they are perfect for very short overs, as they will not affect the
14-
signal in any way before overs actually happen, and only those occuring overs
14+
signal in any way before overs actually happen, and only those apparent overs
1515
will be clipped, nothing else. You can get away with lots of hard clipping on
1616
percussive and transient-rich material like drums. For more consistent things
1717
like a bass track or a full mix, hard clipping is not ideal as it tends to be
@@ -48,14 +48,14 @@ about:
4848
Any signal within the lower and upper knee threshold range is gently rescaled
4949
to fit below the ceiling, even if the signal originally shot past the ceiling,
5050
within the confines of the [ceiling,upper knee threshold] range. This imparts
51-
a little bit of soft clipping saturation, and preverves the life in very loud
51+
a little bit of soft clipping saturation, and preserves the life in very loud
5252
transients significantly better than other, more trivial clipping methods.
5353

5454
The "super soft" option decides how the part of the signal within the knee is
55-
rescaled. With the "super soft" option disabled, the rescaling is more linear
55+
rescaled. With the "super soft" option deactivated rescaling gets more linear
5656
which means the transition into hard clipping occurs later but faster, so the
5757
signal can become slightly louder before the hard distortion kicks in, but at
58-
the cost of being harsher and much more immediate. With "super soft" enabled,
58+
the cost of being harsher and much more immediate. With "super soft" selected,
5959
rescaling inside the knee uses cosine interpolation to transition between the
6060
unclipped and clipped states more gradually. This sounds less harsh but comes
6161
at the cost of some output volume.
@@ -82,12 +82,12 @@ about:
8282
In the metering section, the ceiling is displayed as a red line while no knee
8383
is set. Anything above the red line will be hard-clipped. As soon as there is
8484
a knee present, the ceiling turns orange, because it now no longer represents
85-
the point of hard clipping. With knee enabled, the yellow marker line left of
85+
the point of hard clipping. With knee selected the yellow marker line left of
8686
the ceiling line visualizes the onset of the knee. Signal exceeding that line
8787
is gently compacted until it hits the upper limit of the knee range, which is
8888
displayed as the red marker line to the right of the ceiling. Anything beyond
8989
the red line will be hard-clipped, even with the knee, even with "super soft"
90-
mode enabled.
90+
mode activated.
9191

9292
The green bar in the metering section reflects the incoming audio signal of a
9393
plugin input channel. The blue bar underneath it reflects the outgoing signal

Clipper/sine_clipper.jsfx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
desc: Sine Clipper
2-
version: 1.8.2
2+
version: 1.8.3
33
author: chokehold
44
tags: processing gain amplitude clipper distortion saturation
55
link: https://github.com/chkhld/jsfx/
@@ -54,7 +54,7 @@ about:
5454
those aforementioned sigmoids tend to cause. The transition into distortion
5555
also happens noticeably smoother.
5656

57-
TL;DR: More headroom, louder signal, fewer artifacts, softer clipping onset,
57+
TL;DR: More headroom, louder signal, fewer artefacts, softer clipping onset,
5858
less "buzz". There's no reason to keep using regular sigmoid-based clippers
5959
anymore like a basic boomer. ;)
6060

@@ -68,11 +68,10 @@ slider2:dBGain=0<-48,48,0.01>Boost [dB]
6868
@init
6969

7070
// Convenience variables for CPU economy during processing
71-
halfPi = $pi * 0.5;
72-
oneOverSix = 1/6;
71+
halfPi = $pi * 0.5;
7372

7473
// Converts dB values to float gain factors
75-
function dBToGain (decibels) (pow(2, decibels * oneOverSix));
74+
function dBToGain (decibels) (pow(10, decibels * 0.05));
7675

7776
// SINE CLIPPING -------------------------------------------------------------
7877
//

Clipper/soft_clipper.jsfx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
desc: Soft Clipper
2-
version: 1.8.2
2+
version: 1.8.3
33
author: chokehold
44
tags: processing gain amplitude clipper distortion saturation
55
link: https://github.com/chkhld/jsfx/
@@ -25,7 +25,7 @@ about:
2525
Saturation and soft-clipping can also introduce evil aliasing,
2626
that's when newly generated harmonics are so high in frequency
2727
that they shoot past 22 kHz and could not possibly be handled
28-
anymore by the samplerate, so they "fold back" into the lower
28+
anymore by the sample rate so they "fold back" into the lower
2929
part of the frequency spectrum where they can cause havoc and
3030
destruction by becoming audible, sitting in unharmonic spaces
3131
and even cancelling out signal that you actually want to hear.
@@ -74,8 +74,8 @@ slider1:dBCeil=0<-48, 0,0.01> Ceiling dBfs
7474
slider2:dBGain=0< 0,48,0.01> Boost dBfs
7575
slider3:ovs=1<0,4,{Off,2x,4x,8x,16x}> Oversampling
7676
slider4:filter=1<0,3,{Relaxed,Normal,Heavy,Insane}> Filtering
77-
slider5:blocker=1<0,0,{Disabled,Enabled}> DC blocker
78-
slider6:hard=0<0,1,{Disabled,Enabled}> Hard clipping
77+
slider5:blocker=1<0,0,{Deactivated,Activated}> DC blocker
78+
slider6:hard=0<0,1,{Deactivated,Activated}> Hard clipping
7979

8080
in_pin:left input
8181
in_pin:right input
@@ -95,7 +95,7 @@ out_pin:right output
9595
orderDn = 1;
9696

9797
// Decibel to gain factor conversion
98-
function dBToGain (decibels) (10.0 ^ (decibels / 20.0));
98+
function dBToGain (decibels) (pow(10, decibels * 0.05));
9999

100100
// Hyperbolic tangent approximation, used for soft clipping.
101101
//
@@ -308,15 +308,15 @@ out_pin:right output
308308
);
309309
);
310310

311-
// If DC blocking enabled
311+
// If DC blocking activated
312312
blocker == 1 ?
313313
(
314314
// Run the DC blocker on each sample
315315
spl0.dcBlocker();
316316
spl1.dcBlocker();
317317
);
318318

319-
// If hard clipping is enabled
319+
// If hard clipping is activated
320320
hard == 1 ?
321321
(
322322
// Hard-clip the output to avoid any distortion outside of this

Clipper/staging_clipper.jsfx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ slider6:dBtrim=0<-24,24,0.01>Output trim [dB]
124124

125125
// The actual clipping function.
126126
//
127-
// This could be optimized into a single line, but I'll leave it
127+
// This could be optimised into a single line, but I'll leave it
128128
// spread over several lines in order to explain what's going on.
129129
function clip (sample) local (polarity)
130130
(
@@ -136,19 +136,11 @@ slider6:dBtrim=0<-24,24,0.01>Output trim [dB]
136136

137137
// Clip the boosted sample to stay below the ceiling.
138138
//
139-
// Instead of slow and expensive conditional if/elseif/etc. branching,
140-
// this uses a highly performant set of additions and multiplications
141-
// which amounts to the same as conditional branching. If the type==x
142-
// conditions are false i.e. 0, the function they're multiplied by is
143-
// not even called, let alone processed or evaluated. 0 * anything is
144-
// always 0, so the entire ((type==x) * something) is optimized to 0.
145-
// Only where the type==x condition is true i.e. 1, the function will
146-
// actually be processed and evaluated - and multiplied by 1 which of
147-
// course will also be optimized out, because 1 * something is always
148-
// just that something. Ess emm arr tee.
149-
sample = (type==0) * sineClip(sample) +
150-
(type==1) * softClip(sample) +
151-
(type==2) * hardClip(sample);
139+
(type == 0) ? (sample = sineClip(sample))
140+
:
141+
(type == 1) ? (sample = softClip(sample))
142+
:
143+
(type == 2) ? (sample = hardClip(sample));
152144

153145
// Apply the make-up gain that will shift the output level up or down
154146
// based on where the ceiling is, so that the output ceiling always

Distortion/foldback_distortion.jsfx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
desc: Foldback Distortion
2-
version: 1.8.2
2+
version: 1.8.3
33
author: chokehold
44
tags: processing distortion foldback
55
link: https://github.com/chkhld/jsfx/
@@ -27,7 +27,7 @@ about:
2727
// ----------------------------------------------------------------------------
2828
slider1:dBCeiling=0<-48, 0,0.01> Ceiling dBfs
2929
slider2:dBBoost=0< 0,48,0.01> Boost dB
30-
slider5:blocker=0<0,1,{Enabled,Disabled}> DC Blocker
30+
slider5:blocker=0<0,1,{Activated,Deactivated}> DC Blocker
3131

3232
in_pin:left input
3333
in_pin:right input
@@ -37,7 +37,7 @@ out_pin:right output
3737
@init
3838

3939
// Decibel to gain factor conversion
40-
function dBToGain (decibels) (10.0 ^ (decibels / 20.0));
40+
function dBToGain (decibels) (pow(10, decibels * 0.05));
4141

4242
function foldback () instance (signum)
4343
(
@@ -78,7 +78,7 @@ out_pin:right output
7878
spl0.foldback();
7979
spl1.foldback();
8080

81-
// If DC blocking enabled
81+
// If DC blocking activated
8282
blocker == 0 ?
8383
(
8484
// Run the DC blocker on each sample

Dynamics/bus_comp.jsfx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
desc: Bus Compressor
2-
version: 1.8.2
2+
version: 1.8.3
33
author: chokehold
44
tags: processing compressor dynamics gain
55
link: https://github.com/chkhld/jsfx/
@@ -36,7 +36,7 @@ about:
3636
M+S mode, the stereo field can appear "widened", depending on how
3737
much each channel is compressed.
3838

39-
With stereo linking disabled, both L+R channels will be processed
39+
With stereo linking turned off the L+R channels will be processed
4040
individually. Fading in stereo linking will make the detector act
4141
on a mix of the L+R channels increasingly. If you have incoherent
4242
signals (e.g. two separate guitars) on both channels, you'll most
@@ -59,7 +59,7 @@ about:
5959
the compressor squashes the signal, the more soft saturation will
6060
be introduced into the material.
6161

62-
Hard 0 dBfs output clipping may be enabled if so desired, but may
62+
Hard 0 dBfs output clipping may be selected if so desired but may
6363
be a bit harsh and buzzy sounding. Use the Makeup gain to "boost"
6464
the material into this, or don't.
6565

@@ -79,7 +79,7 @@ slider9: linkAmount=100<0, 100, 1>Stereo link [%]
7979
slider10:instability=100<0,100,0.01>Instability [%]
8080
slider11:saturation=100<0,100,0.01>Saturation [%]
8181
slider12:dBTrim=0<-24, 24, 0.01>Makeup gain [dB]
82-
slider13:clip=0<0,1,{Disabled,Hard clip 0 dBfs}>Clip output
82+
slider13:clip=0<0,1,{Deactivated,Hard clip 0 dBfs}>Clip output
8383
slider14:pctMix=100<0,100,0.01>Dry/wet mix [%]
8484

8585
in_pin:Input L

Dynamics/consolidator.jsfx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
desc: Consolidator
2-
version: 1.8.2
2+
version: 1.8.3
33
author: chokehold
44
tags: processing compressor dynamics gain limiter maximizer
55
link: https://github.com/chkhld/jsfx/
@@ -22,7 +22,7 @@ about:
2222
Stereo linking is calculated at each compressor stage independently. Linking
2323
L+R channels in the detector makes the stereo image more stable, but it robs
2424
the compressors of possible gain reduction. Rule of thumb: to squash signals
25-
as much as possible ("maximize"), use low or no stereo linking. To help keep
25+
as much as possible ("maximise"), use low or no stereo linking. To help keep
2626
a signal's stereo field intact, use high or full stereo linking.
2727

2828
Makeup gain is just a simple volume adjustment. Don't get scared when things
@@ -48,7 +48,7 @@ out_pin:Output R
4848

4949
@init
5050

51-
// Stop Reaper from re-initializing the plugin every time playback is reset
51+
// Stop Reaper from re-initialising the plugin every time playback is reset
5252
ext_noinit = 1;
5353

5454
// Various convenience constants
@@ -58,7 +58,7 @@ out_pin:Output R
5858
rcpSqrt2 = 0.7071067812; // Reciprocal constant 1.0 / sqrt(2.0)
5959

6060
// Converts dB values to float gain factors
61-
function dBToGain (decibels) (10.0 ^ (decibels / 20.0));
61+
function dBToGain (decibels) (pow(10, decibels * 0.05));
6262

6363
// Converts float gain factors to dB values
6464
function gainTodB (float) local (below)
@@ -76,9 +76,6 @@ out_pin:Output R
7676
function msToL (sampleMid, sampleSide) ((sampleMid + sampleSide) * rcpSqrt2);
7777
function msToR (sampleMid, sampleSide) ((sampleMid - sampleSide) * rcpSqrt2);
7878

79-
// Accelerated 1/value calculation
80-
function fastReciprocal (value) (sqr(invsqrt(value)));
81-
8279
// SIDECHAIN FILTER
8380
//
8481
// Simple Biquad HP filters used in the sidechain circuit.
@@ -87,8 +84,8 @@ out_pin:Output R
8784
//
8885
function eqHP (Hz, Q) instance (a1, a2, a3, m0, m1, m2) local (g, k)
8986
(
90-
g = tan(halfPi * (Hz / srate)); k = fastReciprocal(Q);
91-
a1 = fastReciprocal(1.0 + g * (g + k)); a2 = a1 * g; a3 = a2 * g;
87+
g = tan(halfPi * (Hz / srate)); k = 1.0 / Q;
88+
a1 = 1.0 / (1.0 + g * (g + k)); a2 = a1 * g; a3 = a2 * g;
9289
m0 = 1.0; m1 = -k; m2 = -1.0;
9390
);
9491
//
@@ -109,8 +106,8 @@ out_pin:Output R
109106
function attRelSetup (msAttack, msRelease) instance (coeffAtt, coeffRel) local ()
110107
(
111108
// Set attack and release time coefficients
112-
coeffAtt = exp(-1000 * fastReciprocal(msAttack * srate));
113-
coeffRel = exp(-1000 * fastReciprocal(msRelease * srate));
109+
coeffAtt = exp(-1000 / (msAttack * srate));
110+
coeffRel = exp(-1000 / (msRelease * srate));
114111
);
115112
//
116113
// This calculates the new envelope state for the current sample.
@@ -137,7 +134,7 @@ out_pin:Output R
137134
function gainCalcSetup (dBThreshold, fullRatio, dBKnee) instance (threshold, ratio, knee, kneeWidth, kneeUpper, kneeLower) local ()
138135
(
139136
threshold = dBThreshold; // signed dBfs
140-
ratio = fastReciprocal(fullRatio); // 1/x --> compression < 1, expansion > 1
137+
ratio = 1.0 / fullRatio; // 1/x --> compression < 1, expansion > 1
141138
knee = dBKnee;
142139
kneeWidth = knee * 0.5;
143140
kneeUpper = threshold + kneeWidth;

0 commit comments

Comments
 (0)