mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-07-30 00:09:16 +02:00
bs412 things
This commit is contained in:
+6
-4
@@ -9,10 +9,10 @@ inline float power_to_dbr(float power, float ref) {
|
||||
return 10*log10f(power / ref);
|
||||
}
|
||||
|
||||
void init_bs412(BS412Compressor* comp, uint32_t mpx_deviation, float target_power, float attack, float release, float max_gain, float gate, float knee_db, uint32_t sample_rate) {
|
||||
void init_bs412(BS412Compressor* comp, uint32_t mpx_deviation, float target_power, float attack, float release, float max_gain, float gate, float knee_db, float strenght, uint32_t sample_rate) {
|
||||
comp->reference = (19000.0f / mpx_deviation) * (19000.0f / mpx_deviation);
|
||||
comp->avg_power = 0.0f;
|
||||
comp->alpha = 1.0f / (BS412_TIME * sample_rate);
|
||||
comp->alpha = 1.0f - expf(-1.0f / (BS412_TIME * sample_rate));
|
||||
comp->sample_rate = sample_rate;
|
||||
comp->attack = expf(-1.0f / (attack * sample_rate));
|
||||
comp->release = expf(-1.0f / (release * sample_rate));
|
||||
@@ -25,12 +25,13 @@ void init_bs412(BS412Compressor* comp, uint32_t mpx_deviation, float target_powe
|
||||
comp->gate_threshold = comp->reference * powf(10.0f, gate / 10.0f);
|
||||
comp->knee_db = knee_db; // e.g. 6.0f — width in dB around target on each side
|
||||
comp->init = true;
|
||||
comp->strenght = strenght;
|
||||
#ifdef BS412_DEBUG
|
||||
debug_printf("Initialized MPX power measurement with sample rate: %d\n", sample_rate);
|
||||
#endif
|
||||
}
|
||||
|
||||
void reinit_bs412(BS412Compressor* comp, uint32_t mpx_deviation, float target_power, float attack, float release, float max_gain, float gate, float knee_db) {
|
||||
void reinit_bs412(BS412Compressor* comp, uint32_t mpx_deviation, float target_power, float attack, float release, float max_gain, float gate, float knee_db, float strenght) {
|
||||
comp->reference = (19000.0f / mpx_deviation) * (19000.0f / mpx_deviation);
|
||||
comp->target = comp->reference * powf(10.0f, target_power / 10.0f);
|
||||
comp->target_dbr = power_to_dbr(comp->target, comp->reference);
|
||||
@@ -39,6 +40,7 @@ void reinit_bs412(BS412Compressor* comp, uint32_t mpx_deviation, float target_po
|
||||
comp->release = expf(-1.0f / (release * comp->sample_rate));
|
||||
comp->max_gain = max_gain;
|
||||
comp->knee_db = knee_db;
|
||||
comp->strenght = strenght;
|
||||
}
|
||||
|
||||
float bs412_compress(BS412Compressor* comp, float audio, float sample_mpx, float* mpx_power) {
|
||||
@@ -66,7 +68,7 @@ float bs412_compress(BS412Compressor* comp, float audio, float sample_mpx, float
|
||||
}
|
||||
|
||||
float safe_power = fmaxf(comp->avg_power, 1e-12f);
|
||||
float target_gain = sqrtf(comp->target / safe_power);
|
||||
float target_gain = powf(sqrtf(comp->target / safe_power), comp->strenght);
|
||||
|
||||
float level_dbr = power_to_dbr(comp->avg_power, comp->reference);
|
||||
float half_knee = comp->knee_db * 0.5f;
|
||||
|
||||
+3
-2
@@ -30,8 +30,9 @@ typedef struct {
|
||||
float gate_threshold;
|
||||
bool init;
|
||||
float knee_db;
|
||||
float strenght;
|
||||
} BS412Compressor;
|
||||
|
||||
void init_bs412(BS412Compressor *comp, uint32_t mpx_deviation, float target_power, float attack, float release, float max_gain, float gate, float knee_db, uint32_t sample_rate);
|
||||
void reinit_bs412(BS412Compressor *comp, uint32_t mpx_deviation, float target_power, float attack, float release, float max_gain, float gate, float knee_db);
|
||||
void init_bs412(BS412Compressor *comp, uint32_t mpx_deviation, float target_power, float attack, float release, float max_gain, float gate, float knee_db, float strenght, uint32_t sample_rate);
|
||||
void reinit_bs412(BS412Compressor *comp, uint32_t mpx_deviation, float target_power, float attack, float release, float max_gain, float gate, float knee_db, float strenght);
|
||||
float bs412_compress(BS412Compressor *comp, float audio, float sample_mpx, float* mpx_power);
|
||||
+12
-3
@@ -68,6 +68,7 @@ typedef struct {
|
||||
float bs412_max;
|
||||
float bs412_gate;
|
||||
float bs412_knee;
|
||||
float bs412_strenght;
|
||||
float lpf_cutoff;
|
||||
} FM95_Config;
|
||||
|
||||
@@ -336,6 +337,7 @@ static int config_handler(void* user, const char* section, const char* name, con
|
||||
else if(MATCH("fm95", "bs412_max")) pconfig->bs412_max = strtof(value, NULL);
|
||||
else if(MATCH("fm95", "bs412_gate")) pconfig->bs412_gate = strtof(value, NULL);
|
||||
else if(MATCH("fm95", "bs412_knee")) pconfig->bs412_knee = strtof(value, NULL);
|
||||
else if(MATCH("fm95", "bs412_strenght")) pconfig->bs412_strenght = strtof(value, NULL);
|
||||
else if(MATCH("advanced", "lpf_order")) pconfig->lpf_order = atoi(value);
|
||||
else if(MATCH("advanced", "stereo_ssb")) pconfig->stereo_ssb = atoi(value);
|
||||
else if(MATCH("advanced", "preemp_unity")) pconfig->preemp_unity_freq = strtof(value, NULL);
|
||||
@@ -446,8 +448,8 @@ void init_runtime(FM95_Runtime* runtime, const FM95_Config config) {
|
||||
}
|
||||
|
||||
if(runtime->bs412.init == true && (runtime->bs412.sample_rate == config.sample_rate)) {
|
||||
reinit_bs412(&runtime->bs412, config.mpx_deviation, config.mpx_power, config.bs412_attack, config.bs412_release, config.bs412_max, config.bs412_gate, config.bs412_knee);
|
||||
} else init_bs412(&runtime->bs412, config.mpx_deviation, config.mpx_power, config.bs412_attack, config.bs412_release, config.bs412_max, config.bs412_gate, config.bs412_knee, config.sample_rate);
|
||||
reinit_bs412(&runtime->bs412, config.mpx_deviation, config.mpx_power, config.bs412_attack, config.bs412_release, config.bs412_max, config.bs412_gate, config.bs412_knee, config.bs412_strenght);
|
||||
} else init_bs412(&runtime->bs412, config.mpx_deviation, config.mpx_power, config.bs412_attack, config.bs412_release, config.bs412_max, config.bs412_gate, config.bs412_knee, config.bs412_strenght, config.sample_rate);
|
||||
init_stereo_encoder(&runtime->stencode, config.stereo_ssb, 4.0f, &runtime->osc, config.volumes.audio, config.volumes.pilot);
|
||||
|
||||
float last_gain = 0.0f;
|
||||
@@ -563,11 +565,17 @@ static void *handle_client(ipc_client_arg_t *arg) {
|
||||
to_reload = 1;
|
||||
break;
|
||||
case 110:
|
||||
// Set BS412 gate
|
||||
// Set BS412 knee
|
||||
memcpy(&val, buf + 1, sizeof(float));
|
||||
data->runtime->bs412.knee_db = val;
|
||||
reply = 0;
|
||||
break;
|
||||
case 111:
|
||||
// Set BS412 strenght
|
||||
memcpy(&val, buf + 1, sizeof(float));
|
||||
data->runtime->bs412.strenght = val;
|
||||
reply = 0;
|
||||
break;
|
||||
case 0xfe:
|
||||
// Fetch config
|
||||
send(fd, data->config, sizeof(FM95_Config), 0);
|
||||
@@ -630,6 +638,7 @@ int main(int argc, char **argv) {
|
||||
.bs412_max = 2.82f,
|
||||
.bs412_gate = -20.0f,
|
||||
.bs412_knee = 4.0f,
|
||||
.bs412_strenght = 1.0f,
|
||||
.lpf_cutoff = 15000.0f,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user