@@ -6,6 +6,7 @@ float fxProcessGate(float input, sGate* gate) {
66 // calculate the gate-logic and online-parameters
77 switch (gate -> state ) {
88 case GATE_CLOSED :
9+ gate -> gainSet = gate -> value_gainmin ;
910 // check if we have to open the gate
1011 if (!gate -> closed ) {
1112 gate -> state = GATE_ATTACK ;
@@ -39,6 +40,9 @@ float fxProcessGate(float input, sGate* gate) {
3940 gate -> coeff = gate -> value_coeff_release ;
4041 gate -> state = GATE_CLOSED ;
4142 break ;
43+ default :
44+ gate -> state = GATE_CLOSED ;
45+ break ;
4246 }
4347
4448 // gainCurrent = (gainCurrent * coeff) + (gainSet - gainSet * coeff);
@@ -61,28 +65,39 @@ float fxProcessEq(float input, sPEQ* peq) {
6165}
6266
6367float fxProcessCompressor (float input , sCompressor * compressor ) {
64- compressor -> active = (abs (input ) > compressor -> value_threshold );
68+ float input_abs = abs (input );
69+
70+ compressor -> active = (input_abs > compressor -> value_threshold );
6571
6672 // calculate the gate-logic and online-parameters
6773 switch (compressor -> state ) {
6874 case COMPRESSOR_IDLE :
75+ compressor -> gainSet = 1.0f ;
6976 // check if we have to open the gate
7077 if (compressor -> active ) {
7178 compressor -> state = COMPRESSOR_ATTACK ;
7279 }
7380 break ;
7481 case COMPRESSOR_ATTACK :
75- compressor -> gainSet = (((abs (input ) - compressor -> value_threshold ) / compressor -> value_ratio ) + compressor -> value_threshold ) / input ;
82+ // overshoot = abs(sample) - threshold
83+ // output = (overshoot / ratio) + threshold
84+ // gainSet = output / abs(input)
85+ if ((input_abs > 0 ) && (compressor -> value_ratio != 0 )) {
86+ compressor -> gainSet = (((input_abs - compressor -> value_threshold ) / compressor -> value_ratio ) + compressor -> value_threshold ) / input_abs ;
87+ }
7688 compressor -> coeff = compressor -> value_coeff_attack ;
7789 compressor -> state = COMPRESSOR_ACTIVE ;
7890 break ;
7991 case COMPRESSOR_ACTIVE :
8092 if (compressor -> active ) {
8193 // check if we have to compress even more
82- float newValue = (((abs (input ) - compressor -> value_threshold ) / compressor -> value_ratio ) + compressor -> value_threshold ) / input ;
83- if (newValue < compressor -> gainSet ) {
84- // compress even more
85- compressor -> gainSet = newValue ;
94+ float newValue ;
95+ if ((input_abs > 0 ) && (compressor -> value_ratio != 0 )) {
96+ newValue = (((input_abs - compressor -> value_threshold ) / compressor -> value_ratio ) + compressor -> value_threshold ) / input_abs ;
97+ if (newValue < compressor -> gainSet ) {
98+ // compress even more
99+ compressor -> gainSet = newValue ;
100+ }
86101 }
87102 }else {
88103 compressor -> holdCounter = compressor -> value_hold_ticks ;
@@ -107,10 +122,13 @@ float fxProcessCompressor(float input, sCompressor* compressor) {
107122 compressor -> coeff = compressor -> value_coeff_release ;
108123 compressor -> state = COMPRESSOR_IDLE ;
109124 break ;
125+ default :
126+ compressor -> state = COMPRESSOR_IDLE ;
127+ break ;
110128 }
111129
112130 // gainCurrent = (gainCurrent * coeff) + gainSet - (gainSet * coeff);
113131 compressor -> gainCurrent = (compressor -> gainCurrent * compressor -> coeff ) + compressor -> gainSet - (compressor -> gainSet * compressor -> coeff );
114132
115- return ( input * compressor -> gainCurrent ) * compressor -> value_makeup ;
133+ return input * compressor -> gainCurrent * compressor -> value_makeup ;
116134}
0 commit comments