0
1
mirror of https://github.com/radio95-rnt/fm95.git synced 2026-02-26 19:23:51 +01:00

diffrent makeup gain implementation

This commit is contained in:
2025-03-02 09:52:23 +01:00
parent a27e2bb7a5
commit 4970977a27
2 changed files with 17 additions and 14 deletions

View File

@@ -135,6 +135,7 @@ void init_compressor(Compressor *compressor, float threshold, float ratio, float
} }
float rms_compress(Compressor *compressor, float sample) { float rms_compress(Compressor *compressor, float sample) {
sample *= voltage_db_to_voltage(compressor->makeup_gain);
float env; float env;
float rmsAlpha = 1.0f - exp(-1.0f / (compressor->rmsTime * compressor->sample_rate)); float rmsAlpha = 1.0f - exp(-1.0f / (compressor->rmsTime * compressor->sample_rate));
compressor->rmsEnv = (1.0f - rmsAlpha) * compressor->rmsEnv + rmsAlpha * (sample * sample); 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; compressor->gainReduction = coeff * compressor->gainReduction + (1.0f - coeff) * targetGR;
float gain = voltage_db_to_voltage(compressor->makeup_gain - compressor->gainReduction); float gain = voltage_db_to_voltage(compressor->gainReduction);
return sample * gain; return (sample * gain) / voltage_db_to_voltage(compressor->makeup_gain);
} }
float peak_compress(Compressor *compressor, float sample) { 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 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; compressor->gainReduction = coeff * compressor->gainReduction + (1.0f - coeff) * targetGR;
float gain = voltage_db_to_voltage(compressor->makeup_gain - compressor->gainReduction); float gain = voltage_db_to_voltage(compressor->gainReduction);
return sample * gain; 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) { 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) { 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_l;
float env_r; float env_r;
float rmsAlpha = 1.0f - exp(-1.0f / (compressor->rmsTime * compressor->sample_rate)); 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; compressor->gainReduction = coeff * compressor->gainReduction + (1.0f - coeff) * shared_target_gr;
float gain = voltage_db_to_voltage(compressor->makeup_gain - compressor->gainReduction); float gain = voltage_db_to_voltage(compressor->gainReduction);
*output_r = r * gain; *output_r = (r * gain) / voltage_db_to_voltage(compressor->makeup_gain);
return l * 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 peak_compress_stereo(StereoCompressor *compressor, float l, float r, float *output_r) {
float env_l = fabsf(l); float env_l = fabsf(l*voltage_db_to_voltage(compressor->makeup_gain));
float env_r = fabsf(r); float env_r = fabsf(r*voltage_db_to_voltage(compressor->makeup_gain));
float input_db = voltage_to_voltage_db(env_l); float input_db = voltage_to_voltage_db(env_l);
float input_db_r = voltage_to_voltage_db(env_r); 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; compressor->gainReduction = coeff * compressor->gainReduction + (1.0f - coeff) * shared_target_gr;
float gain = voltage_db_to_voltage(compressor->makeup_gain - compressor->gainReduction); float gain = voltage_db_to_voltage(compressor->gainReduction);
*output_r = r * gain; *output_r = (r * gain) / voltage_db_to_voltage(compressor->makeup_gain);
return l * gain; return (l*gain) / voltage_db_to_voltage(compressor->makeup_gain);
} }

View File

@@ -377,7 +377,7 @@ int main(int argc, char **argv) {
StereoCompressor comp; StereoCompressor comp;
// THRESH RATIO KNE MAKE ATT REL RMS // 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 // #endregion
signal(SIGINT, stop); signal(SIGINT, stop);