diff --git a/lib/filters.c b/lib/filters.c index d6a6767..f6b93c6 100644 --- a/lib/filters.c +++ b/lib/filters.c @@ -135,6 +135,7 @@ void init_compressor(Compressor *compressor, float threshold, float ratio, float } float rms_compress(Compressor *compressor, float sample) { + sample *= voltage_db_to_voltage(compressor->makeup_gain); float env; float rmsAlpha = 1.0f - exp(-1.0f / (compressor->rmsTime * compressor->sample_rate)); compressor->rmsEnv = (1.0f - rmsAlpha) * compressor->rmsEnv + rmsAlpha * (sample * sample); @@ -166,12 +167,12 @@ float rms_compress(Compressor *compressor, float sample) { } compressor->gainReduction = coeff * compressor->gainReduction + (1.0f - coeff) * targetGR; - float gain = voltage_db_to_voltage(compressor->makeup_gain - compressor->gainReduction); - return sample * gain; + float gain = voltage_db_to_voltage(compressor->gainReduction); + return (sample * gain) / voltage_db_to_voltage(compressor->makeup_gain); } float peak_compress(Compressor *compressor, float sample) { - float env = fabsf(sample); + float env = fabsf(sample*voltage_db_to_voltage(compressor->makeup_gain)); float input_db = voltage_to_voltage_db(env); @@ -199,8 +200,8 @@ float peak_compress(Compressor *compressor, float sample) { } compressor->gainReduction = coeff * compressor->gainReduction + (1.0f - coeff) * targetGR; - float gain = voltage_db_to_voltage(compressor->makeup_gain - compressor->gainReduction); - return sample * gain; + float gain = voltage_db_to_voltage(compressor->gainReduction); + return (sample * gain) / voltage_db_to_voltage(compressor->makeup_gain); } void init_compressor_stereo(StereoCompressor *compressor, float threshold, float ratio, float knee, float makeup_gain, float attack, float release, float rmsTime, float sample_rate) { @@ -218,6 +219,8 @@ void init_compressor_stereo(StereoCompressor *compressor, float threshold, float } float rms_compress_stereo(StereoCompressor *compressor, float l, float r, float *output_r) { + l *= voltage_db_to_voltage(compressor->makeup_gain); + r *= voltage_db_to_voltage(compressor->makeup_gain); float env_l; float env_r; float rmsAlpha = 1.0f - exp(-1.0f / (compressor->rmsTime * compressor->sample_rate)); @@ -275,14 +278,14 @@ float rms_compress_stereo(StereoCompressor *compressor, float l, float r, float } compressor->gainReduction = coeff * compressor->gainReduction + (1.0f - coeff) * shared_target_gr; - float gain = voltage_db_to_voltage(compressor->makeup_gain - compressor->gainReduction); - *output_r = r * gain; - return l * gain; + float gain = voltage_db_to_voltage(compressor->gainReduction); + *output_r = (r * gain) / voltage_db_to_voltage(compressor->makeup_gain); + return (l * gain) / voltage_db_to_voltage(compressor->makeup_gain); } float peak_compress_stereo(StereoCompressor *compressor, float l, float r, float *output_r) { - float env_l = fabsf(l); - float env_r = fabsf(r); + float env_l = fabsf(l*voltage_db_to_voltage(compressor->makeup_gain)); + float env_r = fabsf(r*voltage_db_to_voltage(compressor->makeup_gain)); float input_db = voltage_to_voltage_db(env_l); float input_db_r = voltage_to_voltage_db(env_r); @@ -333,7 +336,7 @@ float peak_compress_stereo(StereoCompressor *compressor, float l, float r, float } compressor->gainReduction = coeff * compressor->gainReduction + (1.0f - coeff) * shared_target_gr; - float gain = voltage_db_to_voltage(compressor->makeup_gain - compressor->gainReduction); - *output_r = r * gain; - return l * gain; + float gain = voltage_db_to_voltage(compressor->gainReduction); + *output_r = (r * gain) / voltage_db_to_voltage(compressor->makeup_gain); + return (l*gain) / voltage_db_to_voltage(compressor->makeup_gain); } \ No newline at end of file diff --git a/src/fm95.c b/src/fm95.c index 5a2bac2..bb27a5a 100644 --- a/src/fm95.c +++ b/src/fm95.c @@ -377,7 +377,7 @@ int main(int argc, char **argv) { StereoCompressor comp; // THRESH RATIO KNE MAKE ATT REL RMS - init_compressor_stereo(&comp, -2.0f, 8.0f, 2.0f, 12.0f, 0.025f, 0.4f, 0.04f, SAMPLE_RATE); + init_compressor_stereo(&comp, -2.0f, 8.0f, 2.0f, 6.0f, 0.025f, 0.4f, 0.04f, SAMPLE_RATE); // #endregion signal(SIGINT, stop);