0
1
mirror of https://github.com/radio95-rnt/fm95.git synced 2026-02-27 11:33:54 +01:00

remove bs412 max

This commit is contained in:
2025-12-31 12:12:37 +01:00
parent f10f67c606
commit 0968373064
3 changed files with 6 additions and 12 deletions

View File

@@ -9,7 +9,7 @@ inline float deviation_to_dbr(float deviation) {
return 10*log10f((deviation*deviation)/((19000.0f / sqrtf(2.0f)) * (19000.0f / sqrtf(2.0f))));
}
void init_bs412(BS412Compressor* mpx, uint32_t mpx_deviation, float target_power, float attack, float release, float max, uint32_t sample_rate) {
void init_bs412(BS412Compressor* mpx, uint32_t mpx_deviation, float target_power, float attack, float release, uint32_t sample_rate) {
mpx->mpx_deviation = mpx_deviation;
mpx->avg_power = 0.0f;
mpx->alpha = 1.0f / (60.0f * sample_rate);
@@ -18,7 +18,6 @@ void init_bs412(BS412Compressor* mpx, uint32_t mpx_deviation, float target_power
mpx->release = expf(-1.0f / (release * sample_rate));
mpx->target = deviation_to_dbr(19000.0f * pow(10.0, target_power / 10.0)); // target is expected to not be our rms format
mpx->gain = 0.0f;
mpx->max = max;
mpx->can_compress = 0;
mpx->second_counter = 0;
#ifdef BS412_DEBUG
@@ -71,15 +70,15 @@ float bs412_compress(BS412Compressor* mpx, float sample) {
mpx->gain = mpx->release * mpx->gain + (1.0f - mpx->release) * target_gain;
}
mpx->gain = fmaxf(0.0f, fminf(mpx->max, mpx->gain));
mpx->gain = fmaxf(0.0f, fminf(sqrtf(2), mpx->gain));
float output_sample = sample * mpx->gain * sqrtf(2);
float output_sample = sample * mpx->gain;
if(deviation_to_dbr(avg_deviation * mpx->gain) > mpx->target && deviation_to_dbr(avg_deviation) < mpx->target) {
// Gain is too much, reduce
float overshoot_dbr = deviation_to_dbr(avg_deviation * mpx->gain) - mpx->target;
float reduction_factor = powf(10.0f, -overshoot_dbr / 10.0f);
mpx->gain *= reduction_factor;
mpx->gain = fmaxf(0.0f, fminf(mpx->max, mpx->gain));
mpx->gain = fmaxf(0.0f, fminf(sqrtf(2), mpx->gain));
}
mpx->sample_counter++;

View File

@@ -19,7 +19,6 @@ typedef struct
float target;
float attack;
float release;
float max;
float gain;
double avg_power;
double alpha;
@@ -30,5 +29,5 @@ typedef struct
float dbr_to_deviation(float dbr);
float deviation_to_dbr(float deviation);
void init_bs412(BS412Compressor *mpx, uint32_t mpx_deviation, float target_power, float attack, float release, float max, uint32_t sample_rate);
void init_bs412(BS412Compressor *mpx, uint32_t mpx_deviation, float target_power, float attack, float release, uint32_t sample_rate);
float bs412_compress(BS412Compressor *mpx, float average);

View File

@@ -73,7 +73,6 @@ typedef struct
float agc_min;
float bs412_attack;
float bs412_release;
float bs412_max;
float lpf_cutoff;
} FM95_Config;
@@ -345,8 +344,6 @@ static int config_handler(void* user, const char* section, const char* name, con
pconfig->audio_preamp = strtof(value, NULL);
} else if (MATCH("fm95", "deviation")) {
pconfig->audio_deviation = strtof(value, NULL);
} else if(MATCH("fm95", "bs412_max")) {
pconfig->bs412_max = strtof(value, NULL);
} else if(MATCH("fm95", "agc_target")) {
pconfig->agc_target = strtof(value, NULL);
} else if(MATCH("fm95", "agc_attack")) {
@@ -501,7 +498,7 @@ void init_runtime(FM95_Runtime* runtime, const FM95_Config config) {
last_sample_counter = runtime->bs412.sample_counter;
last_second_counter = runtime->bs412.second_counter;
}
init_bs412(&runtime->bs412, config.mpx_deviation, config.mpx_power, config.bs412_attack, config.bs412_release, config.bs412_max, config.sample_rate);
init_bs412(&runtime->bs412, config.mpx_deviation, config.mpx_power, config.bs412_attack, config.bs412_release, config.sample_rate);
runtime->bs412.gain = last_gain;
runtime->bs412.avg_power = last_power;
runtime->bs412.can_compress = last_compress;
@@ -557,7 +554,6 @@ int main(int argc, char **argv) {
.agc_max = 1.5f,
.bs412_attack = 0.05f,
.bs412_release = 0.025,
.bs412_max = 1.0f,
.lpf_cutoff = 15000,
};