From d982a2b91e90540102d0c1efb74aefdfe1b051cb Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Wed, 26 Jul 2023 15:53:55 -0400 Subject: [PATCH] Temp Commit WIP; --- src/dsd_audio2.c | 56 ++++++++++++++++++++++++++++-------------------- src/dsd_main.c | 11 ++-------- src/dsd_symbol.c | 21 ++++++++++++++++++ 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/src/dsd_audio2.c b/src/dsd_audio2.c index 7898e4c..2cc0f50 100644 --- a/src/dsd_audio2.c +++ b/src/dsd_audio2.c @@ -1,5 +1,26 @@ +/*------------------------------------------------------------------------------- + * + * + * + * TODO: Fill me in' + * + * + * LWVMOBILE + * 2023-07 DSD-FME Florida Man Edition + *-----------------------------------------------------------------------------*/ + #include "dsd.h" +//TODO: Add audio handling for left over types (X2-TDMA, dPMR, Provoice...MBEPlayback?) +//TODO: Test All voice decoders with all combos 'short mono, short stereo, float mono, float stereo) +//TODO: Look at upscaling on M17 codec 2 audio for OSS support and backport to 2.1b +//TODO: Clean comments and unused code in here +//TODO: Change + and - keys to allow switching to '0' on shorts for auto or manual with values + +//CHECKLIST(PULSE): DMR BS(OK) DMR MS (OK) P25p1 (OK) P25p2 (OK) YSF (OK) NXDN (OK) M17 (short only!) pV (OK) dPMR (OK) MBEplayback (OK) X2-TDMA (who cares lol) + +//TODO: WAV File saving (works fine on shorts, but on float, writing short to wav is not auto-gained, so super quiet, either convert to float wav files, or run processAudio AFTER memcpy of the temp_buf) + void agf (dsd_opts * opts, dsd_state * state, float samp[160], int slot) { int i, run; @@ -7,9 +28,9 @@ void agf (dsd_opts * opts, dsd_state * state, float samp[160], int slot) float empty[160]; memset (empty, 0.1f, sizeof(empty)); - float max = 0.0f; float mmax = 0.75f; float mmin = -0.75f; + float aavg = 0.0f; //average of the absolute value float df; //decimation value if (slot == 0) @@ -23,47 +44,36 @@ void agf (dsd_opts * opts, dsd_state * state, float samp[160], int slot) for (i = 0; i < 160; i++) { + samp[i] = samp[i] / df; + aavg += fabsf(samp[i]); + //simple clipping if (samp[i] > mmax) samp[i] = mmax; if (samp[i] < mmin) samp[i] = mmin; - //determine max value for adjustments - if (fabs(samp[i]) > max) - max = samp[i]; - - } - //crude auto gain for float values + aavg /= 160.0f; + if (slot == 0) { - if (max < 0.351f && max > 0.1f && state->aout_gain < 42.0f) state->aout_gain++; - if (max > 0.35f && state->aout_gain > 1.0f) state->aout_gain--; + if (aavg < 0.075f && state->aout_gain < 42.0f) state->aout_gain += 1.0f; + if (aavg >= 0.075f && state->aout_gain > 1.0f) state->aout_gain -= 1.0f; } if (slot == 1) { - if (max < 0.351f && max > 0.1f && state->aout_gainR < 42) state->aout_gainR++; - if (max > 0.35f && state->aout_gainR > 1) state->aout_gainR--; + if (aavg < 0.075f && state->aout_gainR < 42.0f) state->aout_gainR += 1.0f; + if (aavg >= 0.075f && state->aout_gainR > 1.0f) state->aout_gainR -= 1.0f; } - // if (slot == 0) - // { - // if (max < 0.351f && max > 0.1f && state->aout_gain < 42.0f) state->aout_gain += 0.33f; - // if (max > 0.35f && state->aout_gain > 1.0f) state->aout_gain -= 0.33f; - // } - - // if (slot == 1) - // { - // if (max < 0.351f && max > 0.1f && state->aout_gainR < 42) state->aout_gainR += 0.33f; - // if (max > 0.35f && state->aout_gainR > 1) state->aout_gainR -= 0.33f; - // } + //debug + // fprintf (stderr, "\nS%d - DF = %f AAVG = %f", slot, df, aavg); - AGF_END: ; //do nothing } diff --git a/src/dsd_main.c b/src/dsd_main.c index 930b837..4b10be5 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -720,9 +720,6 @@ initOpts (dsd_opts * opts) //Use P25p1 heuristics opts->use_heuristics = 0; - // if (opts->floating_point == 1) - // state->aout_gain = 25.0f; - } //initopts void @@ -1323,13 +1320,9 @@ liveScanner (dsd_opts * opts, dsd_state * state) if (opts->floating_point == 1) { - //use this for now, but see if we can really start on zero later on - //when we have a more normalized gain attack - if (opts->audio_gain == 0) - opts->audio_gain = 25.0f; - + //continue testing for as high as we can go without it suddenly clipping opts->audio_gain /= 2.0f; - if (opts->audio_gain > 45.0f) opts->audio_gain = 45.0f; + if (opts->audio_gain > 42.0f) opts->audio_gain = 42.0f; } // if (opts->audio_in_type == 1) diff --git a/src/dsd_symbol.c b/src/dsd_symbol.c index 4f3065e..176bea0 100644 --- a/src/dsd_symbol.c +++ b/src/dsd_symbol.c @@ -17,6 +17,27 @@ #include "dsd.h" +//testing sending samples into this to get an RMS value +int disctap_rms(int16_t *samples, int len, int step) //use samplespersymbol as len +/* largely lifted from rtl_power */ +{ + int i; + long p, t, s; + double dc, err; + + p = t = 0L; + for (i=0; i