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

add bs412 max

This commit is contained in:
2026-02-15 18:47:39 +01:00
parent 1e2a82db92
commit d820603da8
3 changed files with 14 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ inline float deviation_to_dbr(float deviation) {
return 10*log10f((deviation*deviation)/SQRT19000);
}
void init_bs412(BS412Compressor* comp, uint32_t mpx_deviation, float target_power, float attack, float release, uint32_t sample_rate) {
void init_bs412(BS412Compressor* comp, uint32_t mpx_deviation, float target_power, float attack, float release, float max_gain, uint32_t sample_rate) {
comp->mpx_deviation = mpx_deviation;
comp->avg_power = 0.0f;
comp->alpha = 1.0f / (BS412_TIME * sample_rate);
@@ -25,6 +25,7 @@ void init_bs412(BS412Compressor* comp, uint32_t mpx_deviation, float target_powe
comp->can_compress = 0;
comp->second_counter = 0;
comp->last_output = 0.0f;
comp->max_gain = max_gain;
#ifdef BS412_DEBUG
debug_printf("Initialized MPX power measurement with sample rate: %d\n", sample_rate);
#endif
@@ -82,7 +83,7 @@ float bs412_compress(BS412Compressor* comp, float audio, float sample_mpx) {
float overshoot_dbr = deviation_to_dbr(avg_deviation * comp->gain) - comp->target;
float reduction_factor = powf(10.0f, -overshoot_dbr / 10.0f);
comp->gain *= reduction_factor;
comp->gain = fmaxf(0.01f, fminf(2.82f, comp->gain));
comp->gain = fmaxf(0.01f, fminf(comp->max_gain, comp->gain));
}
comp->sample_counter++;

View File

@@ -19,6 +19,7 @@ typedef struct
float target;
float attack;
float release;
float max_gain;
float gain;
double avg_power;
double alpha;
@@ -30,5 +31,5 @@ typedef struct
// float dbr_to_deviation(float dbr);
float deviation_to_dbr(float deviation);
void init_bs412(BS412Compressor *comp, uint32_t mpx_deviation, float target_power, float attack, float release, uint32_t sample_rate);
void init_bs412(BS412Compressor *comp, uint32_t mpx_deviation, float target_power, float attack, float release, float max_gain, uint32_t sample_rate);
float bs412_compress(BS412Compressor *comp, float audio, float sample_mpx);

View File

@@ -70,6 +70,7 @@ typedef struct {
float agc_min;
float bs412_attack;
float bs412_release;
float bs412_max;
float lpf_cutoff;
} FM95_Config;
@@ -344,6 +345,8 @@ static int config_handler(void* user, const char* section, const char* name, con
pconfig->bs412_attack = strtof(value, NULL);
} else if(MATCH("fm95", "bs412_release")) {
pconfig->bs412_release = strtof(value, NULL);
} else if(MATCH("fm95", "bs412_max")) {
pconfig->bs412_max = strtof(value, NULL);
} else if(MATCH("advanced", "lpf_order")) {
pconfig->lpf_order = atoi(value);
} else if(MATCH("advanced", "stereo_ssb")) {
@@ -389,7 +392,7 @@ int setup_audio(FM95_Runtime* runtime, const FM95_DeviceNames dv_names, const FM
pa_buffer_attr output_buffer_atr = {
.maxlength = buffer_maxlength,
.tlength = buffer_tlength_fragsize,
.prebuf = 64
.prebuf = 512
};
int opentime_pulse_error;
@@ -473,7 +476,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.sample_rate);
init_bs412(&runtime->bs412, config.mpx_deviation, config.mpx_power, config.bs412_attack, config.bs412_release, config.bs412_max, config.sample_rate);
runtime->bs412.gain = last_gain;
runtime->bs412.avg_power = last_power;
runtime->bs412.can_compress = last_compress;
@@ -493,7 +496,7 @@ void init_runtime(FM95_Runtime* runtime, const FM95_Config config) {
}
int main(int argc, char **argv) {
printf("fm95 (an FM Processor by radio95) version 2.3\n");
printf("fm95 (an FM Processor by radio95) version 2.4\n");
FM95_Config config = {
.volumes = {
@@ -529,8 +532,9 @@ int main(int argc, char **argv) {
.agc_min = 0.1f,
.agc_max = 1.5f,
.bs412_attack = 0.05f,
.bs412_release = 0.025,
.lpf_cutoff = 15000,
.bs412_release = 0.025f,
.bs412_max = 2.82f,
.lpf_cutoff = 15000.0f,
};
FM95_DeviceNames dv_names = {