From 0bc75f6f78e7f989bfd4aa26e7aded4635ce126e Mon Sep 17 00:00:00 2001 From: Volo Zyko Date: Thu, 29 Jun 2023 18:51:58 +0300 Subject: [PATCH] Cleanup code related to symbol out (logic did not change) --- include/dsd.h | 2 -- src/dsd_dibit.c | 2 +- src/dsd_file.c | 22 ++++------------------ src/dsd_frame_sync.c | 2 +- src/dsd_main.c | 9 ++------- src/dsd_ncurses.c | 40 ++++++++++------------------------------ 6 files changed, 18 insertions(+), 59 deletions(-) diff --git a/include/dsd.h b/include/dsd.h index 4aded7e..16f9ee6 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -229,7 +229,6 @@ typedef struct char symbol_out_file[1024]; char lrrp_out_file[1024]; char szNumbers[1024]; //**tera 10/32/64 char str - short int symbol_out; short int mbe_out; //flag for mbe out, don't attempt fclose more than once short int mbe_outR; //flag for mbe out, don't attempt fclose more than once SNDFILE *wav_out_f; @@ -838,7 +837,6 @@ void openWavOutFileR (dsd_opts * opts, dsd_state * state); void openWavOutFileRaw (dsd_opts * opts, dsd_state * state); void openSymbolOutFile (dsd_opts * opts, dsd_state * state); void closeSymbolOutFile (dsd_opts * opts, dsd_state * state); -void writeSymbolOutFile (dsd_opts * opts, dsd_state * state); void writeRawSample (dsd_opts * opts, dsd_state * state, short sample); void closeWavOutFile (dsd_opts * opts, dsd_state * state); void closeWavOutFileL (dsd_opts * opts, dsd_state * state); diff --git a/src/dsd_dibit.c b/src/dsd_dibit.c index 3fbff10..ecf4515 100644 --- a/src/dsd_dibit.c +++ b/src/dsd_dibit.c @@ -445,7 +445,7 @@ get_dibit_and_analog_signal (dsd_opts* opts, dsd_state* state, int* out_analog_s } //symbol/dibit file capture/writing - if (opts->symbol_out == 1) + if (opts->symbol_out_f) { //fprintf (stderr, "%d", dibit); fputc (dibit, opts->symbol_out_f); diff --git a/src/dsd_file.c b/src/dsd_file.c index 9ff0246..95687ba 100644 --- a/src/dsd_file.c +++ b/src/dsd_file.c @@ -560,29 +560,15 @@ void closeWavOutFileRaw (dsd_opts * opts, dsd_state * state) void openSymbolOutFile (dsd_opts * opts, dsd_state * state) { - //Do something + closeSymbolOutFile(opts, state); opts->symbol_out_f = fopen (opts->symbol_out_file, "w"); } -void writeSymbolOutFile (dsd_opts * opts, dsd_state * state) -{ - //Do something - -} - void closeSymbolOutFile (dsd_opts * opts, dsd_state * state) { - //Do something - if (opts->symbol_out == 1) + if (opts->symbol_out_f) { - if (opts->symbol_out_f != NULL) - { - fclose(opts->symbol_out_f); - opts->symbol_out_f = NULL; - } - - opts->symbol_out = 0; //set flag to 1 - + fclose(opts->symbol_out_f); + opts->symbol_out_f = NULL; } - } diff --git a/src/dsd_frame_sync.c b/src/dsd_frame_sync.c index d99c507..4df4186 100644 --- a/src/dsd_frame_sync.c +++ b/src/dsd_frame_sync.c @@ -352,7 +352,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) dibit = 51; // '3' } - if (opts->symbol_out == 1 && dibit != 0) + if (opts->symbol_out_f && dibit != 0) { int csymbol = 0; if (dibit == 49) diff --git a/src/dsd_main.c b/src/dsd_main.c index 20fe634..f10dccf 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -501,7 +501,6 @@ initOpts (dsd_opts * opts) //end import filenames opts->szNumbers[0] = 0; opts->symbol_out_f = NULL; - opts->symbol_out = 0; opts->mbe_out = 0; opts->mbe_outR = 0; //second slot on a TDMA system opts->wav_out_f = NULL; @@ -1312,11 +1311,8 @@ cleanupAndExit (dsd_opts * opts, dsd_state * state) closeWavOutFileL (opts, state); closeWavOutFileR (opts, state); } - if (opts->symbol_out == 1) - { - closeSymbolOutFile (opts, state); - } - + closeSymbolOutFile (opts, state); + //close MBE out files if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state); if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state); @@ -1698,7 +1694,6 @@ main (int argc, char **argv) strncpy(opts.symbol_out_file, optarg, 1023); opts.symbol_out_file[1023] = '\0'; fprintf (stderr,"Writing + Appending symbol capture to file %s\n", opts.symbol_out_file); - opts.symbol_out = 1; openSymbolOutFile (&opts, &state); break; diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c index bd3d287..9652081 100644 --- a/src/dsd_ncurses.c +++ b/src/dsd_ncurses.c @@ -607,12 +607,7 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state) wscanw(entry_win, "%s", opts->symbol_out_file); //&opts->symbol_out_file noecho(); - if (opts->symbol_out_file[0] != 0) //NULL - { - opts->symbol_out = 1; //set flag to 1 - openSymbolOutFile (opts, state); - } - + openSymbolOutFile (opts, state); } if (choicec == 4) { @@ -1030,16 +1025,10 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state) if (choicec == 16) //stop/close last file RECORDING { - if (opts->symbol_out == 1) + if (opts->symbol_out_f) { - if (opts->symbol_out_file[0] != 0) //NULL - { - fclose(opts->symbol_out_f); //free(): double free detected in tcache 2 (this is a new one) happens when closing more than once - sprintf (opts->audio_in_dev, "%s", opts->symbol_out_file); //swap output bin filename to input for quick replay - } - - opts->symbol_out = 0; //set flag to 1 - + closeSymbolOutFile (opts, state); + sprintf (opts->audio_in_dev, "%s", opts->symbol_out_file); //swap output bin filename to input for quick replay } choicec = 18; //exit } @@ -2278,11 +2267,11 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) { printw ("| Appending Raw Sig Audio WAV to file %s\n", opts->wav_out_file_raw); } - if (opts->symbol_out_file[0] != 0 && opts->symbol_out == 1) + if (opts->symbol_out_file[0] != 0) { printw ("| SymbolC Bin: %s\n", opts->symbol_out_file); } - if (opts->wav_out_file[0] != 0 && opts->dmr_stereo_wav == 0) + if (opts->wav_out_file[0] != 0) { printw ("| Decoded WAV: %s\n", opts->wav_out_file); } @@ -3420,24 +3409,15 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) if (c == 82) //'R', save symbol capture bin with date/time string as name { sprintf (opts->symbol_out_file, "%s %s.bin", getDateN(), getTimeN()); - if (opts->symbol_out_file[0] != 0) - { - opts->symbol_out = 1; //set flag to 1 - openSymbolOutFile (opts, state); - } + openSymbolOutFile (opts, state); } if (c == 114) //'r' key, stop capturing symbol capture bin file { - if (opts->symbol_out == 1) + if (opts->symbol_out_f) { - if (opts->symbol_out_file[0] != 0) - { - fclose(opts->symbol_out_f); - sprintf (opts->audio_in_dev, "%s", opts->symbol_out_file); - } - - opts->symbol_out = 0; + closeSymbolOutFile (opts, state); + sprintf (opts->audio_in_dev, "%s", opts->symbol_out_file); } }