mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
minor changes and optimizations
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "bs412.h"
|
||||
|
||||
#define BS412_TIME 60
|
||||
#define CLAMP(x, lo, hi) (((x) < (lo)) ? (lo) : ((x) > (hi) ? (hi) : (x)))
|
||||
|
||||
#define SQRT19000 180499999.99999997f // (19000 / sqrt(2)) * 19000 / sqrt(2)
|
||||
|
||||
@@ -71,14 +72,14 @@ float bs412_compress(BS412Compressor* comp, float audio, float sample_mpx) {
|
||||
return combined;
|
||||
}
|
||||
|
||||
float target_gain = powf(10.0f, (comp->target - modulation_power) / 10.0f);
|
||||
float target_gain = expf((comp->target - modulation_power) * 0.2302585093f); // 1/10 * ln(10)
|
||||
if (modulation_power > comp->target) comp->gain = comp->attack * comp->gain + (1.0f - comp->attack) * target_gain;
|
||||
else comp->gain = comp->release * comp->gain + (1.0f - comp->release) * target_gain;
|
||||
|
||||
comp->gain = fmaxf(0.0f, fminf(2.0f, comp->gain));
|
||||
comp->gain = CLAMP(comp->gain, 0.0f, comp->max_gain);
|
||||
|
||||
float output_sample = (audio * comp->gain) + sample_mpx;
|
||||
if(deviation_to_dbr(avg_deviation * comp->gain) > comp->target && deviation_to_dbr(avg_deviation) < comp->target) {
|
||||
if(deviation_to_dbr(avg_deviation * comp->gain) > comp->target && modulation_power < comp->target) {
|
||||
// Gain is too much, reduce
|
||||
float overshoot_dbr = deviation_to_dbr(avg_deviation * comp->gain) - comp->target;
|
||||
float reduction_factor = powf(10.0f, -overshoot_dbr / 10.0f);
|
||||
|
||||
@@ -424,7 +424,7 @@ int setup_audio(FM95_Runtime* runtime, const FM95_DeviceNames dv_names, const FM
|
||||
if(config.options.mpx_on) free_PulseDevice(&runtime->mpx_device);
|
||||
return 1;
|
||||
}
|
||||
runtime->rds_in = malloc(sizeof(float) * BUFFER_SIZE * config.rds_streams);
|
||||
runtime->rds_in = calloc(sizeof(float) * BUFFER_SIZE * config.rds_streams);
|
||||
}
|
||||
|
||||
printf("Connecting to output device... (%s)\n", dv_names.output);
|
||||
@@ -491,8 +491,6 @@ void init_runtime(FM95_Runtime* runtime, const FM95_Config config) {
|
||||
initAGC(&runtime->agc, config.sample_rate, config.agc_target, config.agc_min, config.agc_max, config.agc_attack, config.agc_release);
|
||||
runtime->agc.currentGain = last_gain;
|
||||
}
|
||||
|
||||
if(config.options.rds_on) memset(runtime->rds_in, 0, sizeof(float) * BUFFER_SIZE * config.rds_streams);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
@@ -35,13 +35,13 @@ typedef struct {
|
||||
} AudioBuffer;
|
||||
|
||||
AudioBuffer* create_audio_buffer(int capacity) {
|
||||
AudioBuffer* buffer = (AudioBuffer*)malloc(sizeof(AudioBuffer));
|
||||
AudioBuffer* buffer = (AudioBuffer*)calloc(sizeof(AudioBuffer));
|
||||
if (!buffer) {
|
||||
perror("Failed to allocate audio buffer");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer->packets = (AudioPacket*)malloc(capacity * sizeof(AudioPacket));
|
||||
buffer->packets = (AudioPacket*)calloc(capacity * sizeof(AudioPacket));
|
||||
if (!buffer->packets) {
|
||||
perror("Failed to allocate packet buffer");
|
||||
free(buffer);
|
||||
|
||||
Reference in New Issue
Block a user