From ea569a28742a91c9198b2bc89bcbb94c52012a1a Mon Sep 17 00:00:00 2001 From: Kuba <132459354+KubaPro010@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:55:55 +0100 Subject: [PATCH] add limiter threshold setting --- README.md | 4 +++- src/pifmrds/control_pipe.c | 10 +++++++++- src/pifmrds/control_pipe.h | 1 + src/pifmrds/fm_mpx.c | 6 +++--- src/pifmrds/fm_mpx.h | 2 +- src/pifmrds/pi_fm_rds.cpp | 28 +++++++++++++++++++++++----- 6 files changed, 40 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ac4ea90..2929bf4 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,8 @@ if you have a arg with no argume... wait what args with args? anyways like the i `-preemphasis` - you can enter 0 or off for disabled, or us (75μs), default is 50μs, you can also enter any num and have that μs of pre-emp
`-af` - same as pifmadv
`-rdsvolume` - rds volume, so how many times is the rds "louder"
-`-pilotvolume` - pilot volume

+`-pilotvolume` - pilot volume
+`-limiterthreshold` - limiter threshold, limits to 10

now you know what you can pass as the args to the program, but theres a pipe still, it wont include the ones in pifmadv or pifmrds:
`PI` - you can change pi code while runtime, useful when you forgot to set a pi code, but you probably won't care about it
@@ -181,6 +182,7 @@ now you know what you can pass as the args to the program, but theres a pipe sti `PIV` - gain but not audio or rds but stereo pilot gain (default = 0.9)
`COM` - toggle, like rds but it doesnt toggle the rds, it does toggle the COMPRESSOR
`CMG` - change compressor max gain recip
+`LIM` - same as that arg

and thats all, and remember kids dont pirate diff --git a/src/pifmrds/control_pipe.c b/src/pifmrds/control_pipe.c index d5a9a67..d9dcc2b 100644 --- a/src/pifmrds/control_pipe.c +++ b/src/pifmrds/control_pipe.c @@ -247,7 +247,15 @@ ResultAndArg poll_control_pipe(int log) { } resarg.res = CONTROL_PIPE_COMPRESSORMAXGAINRECIP_SET; resarg.arg = arg; - } + } else if(fifo[0] == 'L' && fifo[1] == 'I' && fifo[2] == 'M') { + if(log==1) { + printf("Set Limiter Threshold to "); + printf(arg); + printf("\n"); + } + resarg.res = CONTROL_PIPE_LIMITERTHRESHOLD_SET; + resarg.arg = arg; + } } return resarg; } diff --git a/src/pifmrds/control_pipe.h b/src/pifmrds/control_pipe.h index 29f990d..53c24b2 100644 --- a/src/pifmrds/control_pipe.h +++ b/src/pifmrds/control_pipe.h @@ -27,6 +27,7 @@ #define CONTROL_PIPE_MPXGEN_SET 20 #define CONTROL_PIPE_COMPRESSOR_SET 21 #define CONTROL_PIPE_COMPRESSORMAXGAINRECIP_SET 23 +#define CONTROL_PIPE_LIMITERTHRESHOLD_SET 24 typedef struct { int res; diff --git a/src/pifmrds/fm_mpx.c b/src/pifmrds/fm_mpx.c index 6b1eca3..8faed16 100644 --- a/src/pifmrds/fm_mpx.c +++ b/src/pifmrds/fm_mpx.c @@ -209,7 +209,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 enablecompressor, int rds_ct_enabled, float rds_volume, int paused, float pilot_volume, int generate_multiplex) { +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, int rds_ct_enabled, float rds_volume, int paused, float pilot_volume, int generate_multiplex, float limiter_threshold) { *audio_buffer = 0.0; int stereo_capable = (channels > 1) && (!disablestereo); //chatgpt if(!drds && generate_multiplex) get_rds_samples(mpx_buffer, length, stereo_capable, rds_ct_enabled, rds_volume); @@ -333,8 +333,8 @@ int fm_mpx_get_samples(float *mpx_buffer, int drds, float compressor_decay, floa if(channels > 1) out_right = 0; } - out_left = limiter(out_left, 0.8, 1); //chatgpt says that its -1.9382 db, amplified a mp3 2000 times, without this it was fucking huge it took like a mhz but with this, about 20khz - if( channels > 1 ) out_right = limiter(out_right, 0.8, 1); + out_left = limiter(out_left, limiter_threshold, 1); //chatgpt says that 0.8 is -1.9382 db, amplified a mp3 2000 times, without this it was fucking huge it took like a mhz but with this, about 20khz + if( channels > 1 ) out_right = limiter(out_right, limiter_threshold, 1); // Generate the stereo mpx if( channels > 1 ) { diff --git a/src/pifmrds/fm_mpx.h b/src/pifmrds/fm_mpx.h index db547fc..16327d6 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, int enablecompressor, int rds_ct_enabled, float rds_volume, int paused, float pilot_volume, int generate_multiplex); +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, int rds_ct_enabled, float rds_volume, int paused, float pilot_volume, int generate_multiplex, float limiter_threshold); extern int fm_mpx_close(); diff --git a/src/pifmrds/pi_fm_rds.cpp b/src/pifmrds/pi_fm_rds.cpp index 57c963a..10338bd 100644 --- a/src/pifmrds/pi_fm_rds.cpp +++ b/src/pifmrds/pi_fm_rds.cpp @@ -39,7 +39,7 @@ static void fatal(char *fmt, ...) terminate(0); } -int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, 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, int rds_ct_enabled, float rds_volume, float pilot_volume, int disablestereo, int log) { +int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, 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, int rds_ct_enabled, float rds_volume, float pilot_volume, int disablestereo, int log, int limiter_threshold) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = terminate; @@ -149,9 +149,11 @@ int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, enablecompressor = pollResult.arg_int; } else if(pollResult.res == CONTROL_PIPE_COMPRESSORMAXGAINRECIP_SET) { compressor_max_gain_recip = std::stof(pollResult.arg); + } else if(pollResult.res == CONTROL_PIPE_LIMITERTHRESHOLD_SET) { + limiter_threshold = std::stof(pollResult.arg); } } - if(fm_mpx_get_samples(data, drds, compressor_decay, compressor_attack, compressor_max_gain_recip, dstereo, gaim, enablecompressor, rds_ct_enabled, rds_volume, paused, pilot_volume, generate_multiplex) < 0 ) terminate(0); + if(fm_mpx_get_samples(data, drds, compressor_decay, compressor_attack, compressor_max_gain_recip, dstereo, gaim, enablecompressor, rds_ct_enabled, rds_volume, paused, pilot_volume, generate_multiplex, limiter_threshold) < 0 ) terminate(0); data_len = DATA_SIZE; for(int i=0;i< data_len;i++) { devfreq[i] = data[i]*deviation_scale_factor; @@ -176,6 +178,7 @@ int main(int argc, char **argv) { int enable_compressor = 1; float rds_volume = 1.0; float pilot_volume = 0.9; + float limiter_threshold = 0.8; int log = 1; int ta = 0; int tp = 0; @@ -189,6 +192,7 @@ int main(int argc, char **argv) { int rawSampleRate = 44100; int rawChannels = 2; int compressorchanges = 0; + int limiterchanges = 0; double preemp = 50e-6; //eu int deviation = 75000; int alternative_freq[100] = {}; @@ -228,6 +232,13 @@ int main(int argc, char **argv) { i++; compressor_max_gain_recip = atof(param); compressorchanges = 1; + } else if(strcmp("-limiterthreshold", arg)==0 && param != NULL) { + i++; + limiter_threshold = atof(param); + limiterchanges = 1; + if(1 && limiter_threshold > 10) { //if you dont want this for some reason than change the 1 to a 0 + fatal("Nuh uh (limiter threshold cant be bigger than 10)"); + } } else if(strcmp("-rdsvolume", arg)==0 && param != NULL) { i++; rds_volume = atof(param); @@ -287,7 +298,7 @@ int main(int argc, char **argv) { i++; int tpower = atoi(param); if(tpower > 7 || tpower < 0) fatal("Power can be between 0 and 7"); - else power = tpower; //OMG SUCH ONE LINER + else power = tpower; } else if(strcmp("-raw", arg)==0) { i++; raw = 1; @@ -308,7 +319,7 @@ int main(int argc, char **argv) { if(strcmp("us", param)==0) { preemp = 75e-6; //usa } else if(strcmp("eu", param)==0) { - printf("eu default but ok\n"); + printf("premp eu default but ok\n"); preemp = 50e-6; } else if(strcmp("off", param)==0 || strcmp("0", param)==0) { preemp = 0; //disabled @@ -331,6 +342,13 @@ int main(int argc, char **argv) { if(compressorchanges) { printf("You've changed the compressor settings, just don't set it too low, so the deviation won't go crazy\n"); } + if(limiterchanges) { + if(limiter_threshold > 0.8) { + printf("You changed the limiter settings, audio might be quiet now"); + } else { //we've incremented it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (69 lol) + printf("You changed the limiter settings, be careful."); + } + } if(!enable_compressor) { printf("DUDE YOU ARE CRAZY?\n"); } @@ -338,6 +356,6 @@ int main(int argc, char **argv) { int FifoSize=DATA_SIZE*2; //fmmod=new ngfmdmasync(carrier_freq,228000,14,FifoSize, false, gpiopin); //you can mod fmmod=new ngfmdmasync(carrier_freq,228000,14,FifoSize, false); - int errcode = tx(carrier_freq, audio_file, pi, ps, rt, 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, ct, rds_volume, pilot_volume, dstereo, log); + int errcode = tx(carrier_freq, audio_file, pi, ps, rt, 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, ct, rds_volume, pilot_volume, dstereo, log, limiter_threshold); terminate(errcode); }