diff --git a/lib/filters.c b/lib/filters.c index caa8918..97cca3c 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,13 @@ float rms_compress(Compressor *compressor, float sample) { } compressor->gainReduction = coeff * compressor->gainReduction + (1.0f - coeff) * targetBoost; - 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); float targetBoost = 0.0f; @@ -198,8 +200,8 @@ float peak_compress(Compressor *compressor, float sample) { } compressor->gainReduction = coeff * compressor->gainReduction + (1.0f - coeff) * targetBoost; - 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); } @@ -218,7 +220,10 @@ void init_compressor_stereo(StereoCompressor *compressor, float threshold, float } float rms_compress_stereo(StereoCompressor *compressor, float l, float r, float *output_r) { - float env_l, env_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)); compressor->rmsEnv = (1.0f - rmsAlpha) * compressor->rmsEnv + rmsAlpha * (l * l); compressor->rmsEnv2 = (1.0f - rmsAlpha) * compressor->rmsEnv2 + rmsAlpha * (r * r); @@ -270,14 +275,14 @@ float rms_compress_stereo(StereoCompressor *compressor, float l, float r, float } compressor->gainReduction = coeff * compressor->gainReduction + (1.0f - coeff) * shared_target_boost; - 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_l = voltage_to_voltage_db(env_l); float input_db_r = voltage_to_voltage_db(env_r); @@ -324,7 +329,7 @@ float peak_compress_stereo(StereoCompressor *compressor, float l, float r, float } compressor->gainReduction = coeff * compressor->gainReduction + (1.0f - coeff) * shared_target_boost; - 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); } diff --git a/src/fm95.c b/src/fm95.c index 13e5050..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, 3.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);