From 417a48cc71c6f1021466819c8673c02087b0e89f Mon Sep 17 00:00:00 2001 From: lwvmobile <59371473+lwvmobile@users.noreply.github.com> Date: Sat, 19 Feb 2022 10:42:55 -0500 Subject: [PATCH] resetState and Minor Ncurses Printer tweak resetState and Minor Ncurses Printer tweak don't run with -n yet, resets state, using to test to fix when input type changes, but won't decode properly --- include/dsd.h | 2 + src/dsd_frame_sync.c | 13 +++++- src/dsd_main.c | 5 +- src/dsd_ncurses.c | 10 ++-- src/dsd_reset.c | 107 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 src/dsd_reset.c diff --git a/include/dsd.h b/include/dsd.h index 8d2175d..a24cfd0 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -238,6 +238,7 @@ typedef struct pa_simple *pulse_digi_dev_in; pa_simple *pulse_digi_dev_out; int use_ncurses_terminal; + int reset_state; } dsd_opts; @@ -535,6 +536,7 @@ void NxdnEncryptionStreamGeneration (dsd_opts* opts, dsd_state* state, uint8_t K void processMbeFrameEncrypted (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char ambe_fr[4][24], char imbe7100_fr[7][24], char ambe_keystream[49], char imbe_keystream[88]); //end borrow from LEH +void resetState (dsd_state * state); #ifdef __cplusplus extern "C" { diff --git a/src/dsd_frame_sync.c b/src/dsd_frame_sync.c index cf0420b..3b37932 100644 --- a/src/dsd_frame_sync.c +++ b/src/dsd_frame_sync.c @@ -193,7 +193,12 @@ getFrameSync (dsd_opts * opts, dsd_state * state) { playRawAudio(opts, state); //this is on line 21 in dsd_audio.c } - + /* + if (opts->reset_state == 1 && state->carrier == 0) + { + resetState (state); + } + */ t++; symbol = getSymbol (opts, state, 0); @@ -1020,6 +1025,12 @@ getFrameSync (dsd_opts * opts, dsd_state * state) fprintf (stderr,"Press CTRL + C to close.\n"); //Kindly remind user to double tap CTRL + C } noCarrier (opts, state); + /* + if (opts->reset_state == 1) + { + resetState (state); + } + */ return (-1); } } diff --git a/src/dsd_main.c b/src/dsd_main.c index 3e20d69..1c70081 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -764,8 +764,9 @@ main (int argc, char **argv) } break; case 'n': - opts.audio_out = 0; - fprintf (stderr,"Disabling audio output to soundcard.\n"); + //opts.audio_out = 0; + //fprintf (stderr,"Disabling audio output to soundcard.\n"); + opts.reset_state = 1; break; case 'w': strncpy(opts.wav_out_file, optarg, 1023); diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c index 673dfc8..461609c 100644 --- a/src/dsd_ncurses.c +++ b/src/dsd_ncurses.c @@ -274,14 +274,16 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) attron(COLOR_PAIR(3)); level = (int) state->max / 164; //only update on carrier present } - //if (state->carrier == 0){ //figure out method that will tell me when is active and when not active, maybe carrier but this doesn't print anyways unless activity - //attron(COLOR_PAIR(1)); - //0 - sync type; 1 - tg/ran; 2 - rid; 3 - slot; 4 - dcc; 5 - time(NULL) ; - //} + if (state->carrier == 0 && opts->reset_state == 1) + { + resetState (state); + } + printw ("--Audio Decode----------------------------------------------------------------\n"); printw ("| In Level: [%3i%%] \n", level); printw ("| Voice Error: [%i][%i] \n| Error Bars: [%s] \n", state->errs, state->errs2, state->err_str); // + printw ("| Carrier = %i\n", state->carrier); printw ("------------------------------------------------------------------------------\n"); diff --git a/src/dsd_reset.c b/src/dsd_reset.c new file mode 100644 index 0000000..3dc1663 --- /dev/null +++ b/src/dsd_reset.c @@ -0,0 +1,107 @@ + +#include "dsd.h" +#include "p25p1_heuristics.h" + +void +resetState (dsd_state * state) +{ + + int i, j; + + state->dibit_buf = malloc (sizeof (int) * 1000000); + state->dibit_buf_p = state->dibit_buf + 200; + memset (state->dibit_buf, 0, sizeof (int) * 200); + state->repeat = 0; //not sure yet + //state->audio_out_buf = malloc (sizeof (short) * 1000000); + //memset (state->audio_out_buf, 0, 100 * sizeof (short)); + //state->audio_out_buf_p = state->audio_out_buf + 100; + //state->audio_out_float_buf = malloc (sizeof (float) * 1000000); + //memset (state->audio_out_float_buf, 0, 100 * sizeof (float)); + //state->audio_out_float_buf_p = state->audio_out_float_buf + 100; + //state->audio_out_idx = 0; + //state->audio_out_idx2 = 0; + //state->audio_out_temp_buf_p = state->audio_out_temp_buf; + //state->wav_out_bytes = 0; + state->center = 0; + state->jitter = -1; + state->synctype = -1; + state->min = -15000; + state->max = 15000; + state->lmid = 0; + state->umid = 0; + state->minref = -12000; + state->maxref = 12000; + state->lastsample = 0; + for (i = 0; i < 128; i++) + { + state->sbuf[i] = 0; + } + state->sidx = 0; + for (i = 0; i < 1024; i++) + { + state->maxbuf[i] = 15000; + } + for (i = 0; i < 1024; i++) + { + state->minbuf[i] = -15000; + } + state->midx = 0; + state->err_str[0] = 0; + sprintf (state->fsubtype, " "); + sprintf (state->ftype, " "); + state->symbolcnt = 0; + state->rf_mod = 0; + state->numflips = 0; + state->lastsynctype = -1; + state->lastp25type = 0; + state->offset = 0; + state->carrier = 0; + for (i = 0; i < 25; i++) + { + for (j = 0; j < 16; j++) + { + state->tg[i][j] = 48; + } + } + state->tgcount = 0; + state->lasttg = 0; + state->lastsrc = 0; + state->nac = 0; + state->errs = 0; + state->errs2 = 0; + state->mbe_file_type = -1; + state->optind = 0; + state->numtdulc = 0; + state->firstframe = 0; + sprintf (state->slot0light, " slot0 "); + sprintf (state->slot1light, " slot1 "); + state->aout_gain = 25; + memset (state->aout_max_buf, 0, sizeof (float) * 200); + state->aout_max_buf_p = state->aout_max_buf; + state->aout_max_buf_idx = 0; + state->samplesPerSymbol = 10; + state->symbolCenter = 4; + sprintf (state->algid, "________"); + sprintf (state->keyid, "________________"); + state->currentslot = 0; + state->cur_mp = malloc (sizeof (mbe_parms)); + state->prev_mp = malloc (sizeof (mbe_parms)); + state->prev_mp_enhanced = malloc (sizeof (mbe_parms)); + mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced); + state->p25kid = 0; + + state->debug_audio_errors = 0; + state->debug_header_errors = 0; + state->debug_header_critical_errors = 0; + + state->nxdn_last_ran = 0; + +//#ifdef TRACE_DSD +// state->debug_sample_index = 0; +// state->debug_label_file = NULL; +// state->debug_label_dibit_file = NULL; +// state->debug_label_imbe_file = NULL; +//#endif + + initialize_p25_heuristics(&state->p25_heuristics); //see if we want to re-init this or not +}