mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 11:33:54 +01:00
configure the bs412 max
This commit is contained in:
@@ -11,7 +11,7 @@ inline float deviation_to_dbr(float deviation) {
|
|||||||
return 10.0f * (log2f(deviation) - LOG2_19000) * 0.30103f;
|
return 10.0f * (log2f(deviation) - LOG2_19000) * 0.30103f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_bs412(BS412Compressor* mpx, float mpx_deviation, float target_power, float attack, float release, int sample_rate) {
|
void init_bs412(BS412Compressor* mpx, float mpx_deviation, float target_power, float attack, float release, float max, int sample_rate) {
|
||||||
mpx->mpx_deviation = mpx_deviation;
|
mpx->mpx_deviation = mpx_deviation;
|
||||||
mpx->average_counter = 0;
|
mpx->average_counter = 0;
|
||||||
mpx->average = 0;
|
mpx->average = 0;
|
||||||
@@ -20,6 +20,7 @@ void init_bs412(BS412Compressor* mpx, float mpx_deviation, float target_power, f
|
|||||||
mpx->release = expf(-1.0f / (release * sample_rate));
|
mpx->release = expf(-1.0f / (release * sample_rate));
|
||||||
mpx->target = target_power;
|
mpx->target = target_power;
|
||||||
mpx->gain = 1.0f;
|
mpx->gain = 1.0f;
|
||||||
|
mpx->max = max;
|
||||||
#ifdef BS412_DEBUG
|
#ifdef BS412_DEBUG
|
||||||
debug_printf("Initialized MPX power measurement with sample rate: %d\n", sample_rate);
|
debug_printf("Initialized MPX power measurement with sample rate: %d\n", sample_rate);
|
||||||
#endif
|
#endif
|
||||||
@@ -51,7 +52,7 @@ float bs412_compress(BS412Compressor* mpx, float sample) {
|
|||||||
mpx->gain = mpx->gain * mpx->attack + (1.0f - mpx->attack) * gain_target;
|
mpx->gain = mpx->gain * mpx->attack + (1.0f - mpx->attack) * gain_target;
|
||||||
else
|
else
|
||||||
mpx->gain = mpx->gain * mpx->release + (1.0f - mpx->release) * gain_target;
|
mpx->gain = mpx->gain * mpx->release + (1.0f - mpx->release) * gain_target;
|
||||||
mpx->gain = fminf(1.0f, mpx->gain);
|
mpx->gain = fminf(mpx->max, mpx->gain);
|
||||||
|
|
||||||
return fminf(sample*mpx->gain, dbr_to_deviation(mpx->target*1.1f));
|
return fminf(sample*mpx->gain, dbr_to_deviation(mpx->target*1.1f));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ typedef struct
|
|||||||
float target;
|
float target;
|
||||||
float attack;
|
float attack;
|
||||||
float release;
|
float release;
|
||||||
|
float max;
|
||||||
float gain;
|
float gain;
|
||||||
double average;
|
double average;
|
||||||
} BS412Compressor;
|
} BS412Compressor;
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ typedef struct
|
|||||||
float agc_min;
|
float agc_min;
|
||||||
float bs412_attack;
|
float bs412_attack;
|
||||||
float bs412_release;
|
float bs412_release;
|
||||||
|
float bs412_max;
|
||||||
} FM95_Config;
|
} FM95_Config;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -167,7 +168,7 @@ int run_fm95(const FM95_Config config, FM95_Runtime* runtime) {
|
|||||||
init_preemphasis(&preemp_r, config.preemphasis, config.sample_rate, config.preemp_unity_freq);
|
init_preemphasis(&preemp_r, config.preemphasis, config.sample_rate, config.preemp_unity_freq);
|
||||||
|
|
||||||
BS412Compressor bs412;
|
BS412Compressor bs412;
|
||||||
init_bs412(&bs412, config.mpx_deviation, config.mpx_power, config.bs412_attack, config.bs412_release, config.sample_rate);
|
init_bs412(&bs412, config.mpx_deviation, config.mpx_power, config.bs412_attack, config.bs412_release, config.bs412_max, config.sample_rate);
|
||||||
|
|
||||||
TiltCorrectionFilter tilter;
|
TiltCorrectionFilter tilter;
|
||||||
tilt_init(&tilter, config.tilt);
|
tilt_init(&tilter, config.tilt);
|
||||||
@@ -353,6 +354,8 @@ static int config_handler(void* user, const char* section, const char* name, con
|
|||||||
pconfig->volumes.rds_step = strtof(value, NULL);
|
pconfig->volumes.rds_step = strtof(value, NULL);
|
||||||
} else if(MATCH("fm95", "tilt")) {
|
} else if(MATCH("fm95", "tilt")) {
|
||||||
pconfig->tilt = strtof(value, NULL);
|
pconfig->tilt = strtof(value, NULL);
|
||||||
|
} else if(MATCH("advanced", "bs412_max")) {
|
||||||
|
pconfig->bs412_max = strtof(value, NULL);
|
||||||
} else {
|
} else {
|
||||||
return 0; // Unknown section/name
|
return 0; // Unknown section/name
|
||||||
}
|
}
|
||||||
@@ -461,6 +464,7 @@ int main(int argc, char **argv) {
|
|||||||
.agc_max = 1.75f,
|
.agc_max = 1.75f,
|
||||||
.bs412_attack = 0.03f,
|
.bs412_attack = 0.03f,
|
||||||
.bs412_release = 0.02,
|
.bs412_release = 0.02,
|
||||||
|
.bs412_max = 1.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
FM95_DeviceNames dv_names = {
|
FM95_DeviceNames dv_names = {
|
||||||
|
|||||||
Reference in New Issue
Block a user