From 2005117a2c00c788b7564994de365b8cc825a4da Mon Sep 17 00:00:00 2001 From: Kuba <132459354+KubaPro010@users.noreply.github.com> Date: Sun, 29 Oct 2023 08:35:33 +0000 Subject: [PATCH] compressor adjustable --- src/pifmrds/fm_mpx.c | 5 +---- src/pifmrds/fm_mpx.h | 2 +- src/pifmrds/pi_fm_rds.cpp | 18 +++++++++++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/pifmrds/fm_mpx.c b/src/pifmrds/fm_mpx.c index 598b628..0f370a7 100644 --- a/src/pifmrds/fm_mpx.c +++ b/src/pifmrds/fm_mpx.c @@ -194,7 +194,7 @@ int fm_mpx_open(char *filename, size_t len, int raw, double preemphasis, int raw // samples provided by this function are in 0..10: they need to be divided by // 10 after. -int fm_mpx_get_samples(float *mpx_buffer, int drds) { +int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, float compressor_attack, float compressor_max_gain_recip) { if(!drds) get_rds_samples(mpx_buffer, length); if(inf == NULL) return 0; // if there is no audio, stop here @@ -274,10 +274,7 @@ int fm_mpx_get_samples(float *mpx_buffer, int drds) { // Don't expect this simple code to match the // performance of commercial broadcast equipment. float left_abs, right_abs; - float compressor_decay=0.999995; - float compressor_attack=1.0; // Setting attack to anything other than 1.0 could cause overshoot. - float compressor_max_gain_recip=0.01; left_abs=fabsf(out_left); if( left_abs>left_max ) { diff --git a/src/pifmrds/fm_mpx.h b/src/pifmrds/fm_mpx.h index 211b069..d7f2a15 100644 --- a/src/pifmrds/fm_mpx.h +++ b/src/pifmrds/fm_mpx.h @@ -22,5 +22,5 @@ */ extern int fm_mpx_open(char *filename, size_t len, int raw, double preemphasis, int rawSampleRate, int rawChannels, float cutoff_freq, float gain); -extern int fm_mpx_get_samples(float *mpx_buffer, int drds); +extern int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, float compressor_attack, float compressor_max_gain_recip); extern int fm_mpx_close(); diff --git a/src/pifmrds/pi_fm_rds.cpp b/src/pifmrds/pi_fm_rds.cpp index 8258c0f..efc558a 100644 --- a/src/pifmrds/pi_fm_rds.cpp +++ b/src/pifmrds/pi_fm_rds.cpp @@ -81,7 +81,7 @@ static volatile void *map_peripheral(uint32_t base, uint32_t len) return vaddr; } -int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, float ppm, char *control_pipe, int pty, int *af_array, int raw, int drds, double preemp, int power, int rawSampleRate, int rawChannels, int deviation, int ta, int tp, float cutoff_freq, float gaim) { +int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, float ppm, char *control_pipe, int pty, int *af_array, int raw, int drds, double preemp, int power, int rawSampleRate, int rawChannels, int deviation, int ta, int tp, float cutoff_freq, float gaim, float compressor_decay, float compressor_attack, float compressor_max_gain_recip) { // Catch all signals possible - it is vital we kill the DMA engine // on process exit! for (int i = 0; i < 64; i++) { @@ -187,7 +187,7 @@ int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, varying_ps = 0; } - if( fm_mpx_get_samples(data, drds) < 0 ) { + if( fm_mpx_get_samples(data, drds, compressor_decay, compressor_attack, compressor_max_gain_recip) < 0 ) { terminate(0); } data_len = DATA_SIZE; @@ -213,6 +213,9 @@ int main(int argc, char **argv) { char *rt = "Broadcasting on a Raspberry Pi: Simply Advanced"; uint16_t pi = 0x1234; int pty = 0; + float compressor_decay = 0.999995; + float compressor_attack = 1.0; + float compressor_max_gain_recip = 0.01; int ta = 0; int tp = 0; int af_size = 0; @@ -254,6 +257,15 @@ int main(int argc, char **argv) { } else if(strcmp("-ppm", arg)==0 && param != NULL) { i++; ppm = atof(param); + } else if(strcmp("-compressordecay", arg)==0 && param != NULL) { + i++; + compressor_decay = atof(param); + } else if(strcmp("-compressorattack", arg)==0 && param != NULL) { + i++; + compressor_attack = atof(param); + } else if(strcmp("-compressormaxgainrecip", arg)==0 && param != NULL) { + i++; + compressor_max_gain_recip = atof(param); } else if(strcmp("-pty", arg)==0 && param != NULL) { i++; pty = atoi(param); @@ -336,6 +348,6 @@ int main(int argc, char **argv) { alternative_freq[0] = af_size; int FifoSize=DATA_SIZE*2; fmmod=new ngfmdmasync(carrier_freq,228000,14,FifoSize, false, gpiopin); - int errcode = tx(carrier_freq, audio_file, pi, ps, rt, ppm, control_pipe, pty, alternative_freq, raw, drds, preemp, power, rawSampleRate, rawChannels, deviation, ta, tp, cutofffreq, gain); + int errcode = tx(carrier_freq, audio_file, pi, ps, rt, ppm, control_pipe, pty, alternative_freq, raw, drds, preemp, power, rawSampleRate, rawChannels, deviation, ta, tp, cutofffreq, gain, compressor_decay, compressor_attack, compressor_max_gain_recip); terminate(errcode); }