I'm trying to re-familiarize myself with JSFX programming and in doing so I'm programming a gate plugin. I'm using ReaGate as a basic template since I'm familiar with how it works and so are many on this forum. I started off with the most basic controls and added a new control with each new version.
v1 started with Threshold[dB], Attack[ms], and Release[ms] controls
v2 added a Hold[ms] control
v3 added a Pre-open[ms] control (i learned a bit about PDC and arrays on that one...)
Now I'm at version 4 and I'm trying to add a Hysteresis[dB] control.
I've got a control that indeed affects the threshold at which the gate closes, but when I a/b it with ReaGate (I put ReaGate in one headphone and my gate in the other) it doesn't quite behave in the same way... everything sounds mono at the same settings until i start using the Hysteresis controls.
So because I'm not just trying to learn how to program in JSFX, I'm also trying to learn the mathematics of how things work, I'm wondering if anybody knows where/how the value of the Hysteresis control in ReaGate is used...
This is the latest version of my plugin:
Code:
desc:Gate v4 - Threshold, Hysteresis, Pre-open, Attack, Hold, Release (by zappazapper)
slider1: -120 <-120, 60, 0.1>Threshold [dB]
slider2: 0 <-120, 12, 0.1>Hysteresis [dB]
slider3: 0 <0, 250, 1>Pre-open [ms]
slider4: 1 <0, 500, 1>Attack [ms]
slider5: 100 <0, 1000, 1>Hold [ms]
slider6: 20 <0, 5000, 1>Release [ms]
@init
gainOpen = 1;
gainClosed = 0;
gain = gainOpen;
pdc_bot_ch = 0;
pdc_top_ch = 2;
pdc_delay = 250 / 1000 * srate;
bufferWrite = 0;
bufferRead = bufferWrite + 1;
holdCurrent = 0;
@slider
threshold = 10 ^ (slider1 / 20);
hysteresis = 10 ^ ((slider1 + slider2) / 20);
preopen = (slider3 / 1000 * srate);
gainAttack = 1 / (slider4 / 1000 * srate);
slider4 == 0 ? gainAttack = 1;
hold = slider5 / 1000 * srate;
gainRelease = 1 / (slider6 / 1000 * srate);
slider6 == 0 ? gainRelease = 1;
@sample
detector = max(abs(spl0), abs(spl1));
detector < threshold ?
(
detector < hysteresis ?
(
holdCurrent < 1 ?
(
gain = gain - gainRelease;
)
:
(
gain = gain + gainAttack;
holdCurrent = holdCurrent - 1;
)
;
)
:
(
gain = gain + gainAttack;
holdCurrent = hold;
)
;
)
:
(
gain = gain + gainAttack;
holdCurrent = hold;
)
;
gain < gainClosed ? gain = gainClosed;
gain > gainOpen ? gain = gainOpen;
buffer0[bufferWrite] = spl0;
buffer1[bufferWrite] = spl1;
bufferGain = bufferWrite - preopen;
bufferGain < 0 ? bufferGain = bufferGain + (250 / 1000 * srate);
buffer0[bufferGain] = buffer0[bufferGain] * gain;
buffer1[bufferGain] = buffer1[bufferGain] * gain;
spl0 = buffer0[bufferRead];
spl1 = buffer1[bufferRead];
bufferWrite = bufferWrite + 1;
bufferWrite > 250 / 1000 * srate ? bufferWrite = bufferWrite - (250 / 1000 * srate);
bufferRead = bufferWrite + 1;
bufferRead > 250 / 1000 * srate ? bufferRead = bufferRead - (250 / 1000 * srate);
As you can see, in my plugin, there is a "threshold" variable, which is converted from the Threshold[dB] slider, and a "hysteresis" variable, which is converted from the sum of the Threshold[dB] and Hysteresis[dB] sliders... to me, that's how it made sense... if your threshold is at -40dB, and your hysteresis is at -5dB, the gate should start closing when the level reaches -45dB...
Is anybody familiar with this concept and can give me some insight?
Thanks in advance...