mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 03:23:54 +01:00
add bs412 max
This commit is contained in:
@@ -13,7 +13,7 @@ inline float deviation_to_dbr(float deviation) {
|
|||||||
return 10*log10f((deviation*deviation)/SQRT19000);
|
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->mpx_deviation = mpx_deviation;
|
||||||
comp->avg_power = 0.0f;
|
comp->avg_power = 0.0f;
|
||||||
comp->alpha = 1.0f / (BS412_TIME * sample_rate);
|
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->can_compress = 0;
|
||||||
comp->second_counter = 0;
|
comp->second_counter = 0;
|
||||||
comp->last_output = 0.0f;
|
comp->last_output = 0.0f;
|
||||||
|
comp->max_gain = max_gain;
|
||||||
#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
|
||||||
@@ -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 overshoot_dbr = deviation_to_dbr(avg_deviation * comp->gain) - comp->target;
|
||||||
float reduction_factor = powf(10.0f, -overshoot_dbr / 10.0f);
|
float reduction_factor = powf(10.0f, -overshoot_dbr / 10.0f);
|
||||||
comp->gain *= reduction_factor;
|
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++;
|
comp->sample_counter++;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ typedef struct
|
|||||||
float target;
|
float target;
|
||||||
float attack;
|
float attack;
|
||||||
float release;
|
float release;
|
||||||
|
float max_gain;
|
||||||
float gain;
|
float gain;
|
||||||
double avg_power;
|
double avg_power;
|
||||||
double alpha;
|
double alpha;
|
||||||
@@ -30,5 +31,5 @@ typedef struct
|
|||||||
// float dbr_to_deviation(float dbr);
|
// float dbr_to_deviation(float dbr);
|
||||||
float deviation_to_dbr(float deviation);
|
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);
|
float bs412_compress(BS412Compressor *comp, float audio, float sample_mpx);
|
||||||
14
src/fm95.c
14
src/fm95.c
@@ -70,6 +70,7 @@ typedef struct {
|
|||||||
float agc_min;
|
float agc_min;
|
||||||
float bs412_attack;
|
float bs412_attack;
|
||||||
float bs412_release;
|
float bs412_release;
|
||||||
|
float bs412_max;
|
||||||
float lpf_cutoff;
|
float lpf_cutoff;
|
||||||
} FM95_Config;
|
} 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);
|
pconfig->bs412_attack = strtof(value, NULL);
|
||||||
} else if(MATCH("fm95", "bs412_release")) {
|
} else if(MATCH("fm95", "bs412_release")) {
|
||||||
pconfig->bs412_release = strtof(value, NULL);
|
pconfig->bs412_release = strtof(value, NULL);
|
||||||
|
} else if(MATCH("fm95", "bs412_max")) {
|
||||||
|
pconfig->bs412_max = strtof(value, NULL);
|
||||||
} else if(MATCH("advanced", "lpf_order")) {
|
} else if(MATCH("advanced", "lpf_order")) {
|
||||||
pconfig->lpf_order = atoi(value);
|
pconfig->lpf_order = atoi(value);
|
||||||
} else if(MATCH("advanced", "stereo_ssb")) {
|
} 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 = {
|
pa_buffer_attr output_buffer_atr = {
|
||||||
.maxlength = buffer_maxlength,
|
.maxlength = buffer_maxlength,
|
||||||
.tlength = buffer_tlength_fragsize,
|
.tlength = buffer_tlength_fragsize,
|
||||||
.prebuf = 64
|
.prebuf = 512
|
||||||
};
|
};
|
||||||
|
|
||||||
int opentime_pulse_error;
|
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_sample_counter = runtime->bs412.sample_counter;
|
||||||
last_second_counter = runtime->bs412.second_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.gain = last_gain;
|
||||||
runtime->bs412.avg_power = last_power;
|
runtime->bs412.avg_power = last_power;
|
||||||
runtime->bs412.can_compress = last_compress;
|
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) {
|
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 = {
|
FM95_Config config = {
|
||||||
.volumes = {
|
.volumes = {
|
||||||
@@ -529,8 +532,9 @@ int main(int argc, char **argv) {
|
|||||||
.agc_min = 0.1f,
|
.agc_min = 0.1f,
|
||||||
.agc_max = 1.5f,
|
.agc_max = 1.5f,
|
||||||
.bs412_attack = 0.05f,
|
.bs412_attack = 0.05f,
|
||||||
.bs412_release = 0.025,
|
.bs412_release = 0.025f,
|
||||||
.lpf_cutoff = 15000,
|
.bs412_max = 2.82f,
|
||||||
|
.lpf_cutoff = 15000.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
FM95_DeviceNames dv_names = {
|
FM95_DeviceNames dv_names = {
|
||||||
|
|||||||
Reference in New Issue
Block a user