From c78711ae18597b08f204d3535a4402bd532047bb Mon Sep 17 00:00:00 2001 From: Kuba <132459354+KubaPro010@users.noreply.github.com> Date: Wed, 1 Nov 2023 08:14:07 +0000 Subject: [PATCH] oh that's why (controlpipe.h) --- src/pifmrds/control_pipe.h | 4 ++-- src/pifmrds/fm_mpx.c | 6 +++--- src/pifmrds/fm_mpx.h | 2 +- src/pifmrds/pi_fm_rds.cpp | 10 +++++++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/pifmrds/control_pipe.h b/src/pifmrds/control_pipe.h index d9e22ff..b9862b2 100644 --- a/src/pifmrds/control_pipe.h +++ b/src/pifmrds/control_pipe.h @@ -18,8 +18,8 @@ #define CONTROL_PIPE_DEVIATION_SET 11 #define CONTROL_PIPE_STEREO_SET 12 #define CONTROL_PIPE_GAIN_SET 13 -#define CONTROL_PIPE_COMPRESSORDECAY_SET 13 -#define CONTROL_PIPE_COMPRESSORATTACK_SET 13 +#define CONTROL_PIPE_COMPRESSORDECAY_SET 14 +#define CONTROL_PIPE_COMPRESSORATTACK_SET 15 typedef struct { int res; diff --git a/src/pifmrds/fm_mpx.c b/src/pifmrds/fm_mpx.c index 11d6846..d476879 100644 --- a/src/pifmrds/fm_mpx.c +++ b/src/pifmrds/fm_mpx.c @@ -193,7 +193,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, float compressor_decay, float compressor_attack, float compressor_max_gain_recip, int disablestereo, float gain) { +int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, float compressor_attack, float compressor_max_gain_recip, int disablestereo, float gain, int enablecompressor) { if(!drds) get_rds_samples(mpx_buffer, length); if(inf == NULL) return 0; // if there is no audio, stop here @@ -306,9 +306,9 @@ int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, floa else if( left_max < right_max ) left_max=right_max; } - out_right=out_right/(right_max+compressor_max_gain_recip); + if(enablecompressor) out_right=out_right/(right_max+compressor_max_gain_recip); } - out_left= out_left/(left_max+compressor_max_gain_recip); // Adjust volume with limited maximum gain + if(enablecompressor) out_left= out_left/(left_max+compressor_max_gain_recip); // Adjust volume with limited maximum gain if(drds) mpx_buffer[i] = 0; //do not remove this, the bandwidht will go nuts diff --git a/src/pifmrds/fm_mpx.h b/src/pifmrds/fm_mpx.h index 96bad8c..3e81887 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); -extern int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, float compressor_attack, float compressor_max_gain_recip, int disablestereo, float gain); +extern int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, float compressor_attack, float compressor_max_gain_recip, int disablestereo, float gain, int enablecompressor); extern int fm_mpx_close(); diff --git a/src/pifmrds/pi_fm_rds.cpp b/src/pifmrds/pi_fm_rds.cpp index 3b6999c..2c7b6cf 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, float compressor_decay, float compressor_attack, float compressor_max_gain_recip) { +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, int enablecompressor) { // Catch all signals possible - it is vital we kill the DMA engine // on process exit! for (int i = 0; i < 64; i++) { @@ -208,7 +208,7 @@ int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, } } - if( fm_mpx_get_samples(data, drds, compressor_decay, compressor_attack, compressor_max_gain_recip, disablestereo, gaim) < 0 ) { + if( fm_mpx_get_samples(data, drds, compressor_decay, compressor_attack, compressor_max_gain_recip, disablestereo, gaim, enablecompressor) < 0 ) { terminate(0); } data_len = DATA_SIZE; @@ -237,6 +237,7 @@ int main(int argc, char **argv) { float compressor_decay = 0.999995; float compressor_attack = 1.0; float compressor_max_gain_recip = 0.01; + int enable_compressor = 1; int ta = 0; int tp = 0; int af_size = 0; @@ -350,6 +351,9 @@ int main(int argc, char **argv) { } else if(strcmp("-disablerds", arg)==0) { i++; drds = 1; + } else if(strcmp("-disablecompressor", arg)==0) { + i++; + enable_compressor = 0; } else if(strcmp("-preemphasis", arg)==0 && param != NULL) { i++; if(strcmp("us", param)==0) { @@ -376,6 +380,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, compressor_decay, compressor_attack, compressor_max_gain_recip); + 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, enable_compressor); terminate(errcode); }