Cleanup code related to symbol out (logic did not change)

This commit is contained in:
Volo Zyko
2023-06-29 18:51:58 +03:00
parent 32a3ba535b
commit 0bc75f6f78
6 changed files with 18 additions and 59 deletions

View File

@@ -229,7 +229,6 @@ typedef struct
char symbol_out_file[1024]; char symbol_out_file[1024];
char lrrp_out_file[1024]; char lrrp_out_file[1024];
char szNumbers[1024]; //**tera 10/32/64 char str 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_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 short int mbe_outR; //flag for mbe out, don't attempt fclose more than once
SNDFILE *wav_out_f; 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 openWavOutFileRaw (dsd_opts * opts, dsd_state * state);
void openSymbolOutFile (dsd_opts * opts, dsd_state * state); void openSymbolOutFile (dsd_opts * opts, dsd_state * state);
void closeSymbolOutFile (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 writeRawSample (dsd_opts * opts, dsd_state * state, short sample);
void closeWavOutFile (dsd_opts * opts, dsd_state * state); void closeWavOutFile (dsd_opts * opts, dsd_state * state);
void closeWavOutFileL (dsd_opts * opts, dsd_state * state); void closeWavOutFileL (dsd_opts * opts, dsd_state * state);

View File

@@ -445,7 +445,7 @@ get_dibit_and_analog_signal (dsd_opts* opts, dsd_state* state, int* out_analog_s
} }
//symbol/dibit file capture/writing //symbol/dibit file capture/writing
if (opts->symbol_out == 1) if (opts->symbol_out_f)
{ {
//fprintf (stderr, "%d", dibit); //fprintf (stderr, "%d", dibit);
fputc (dibit, opts->symbol_out_f); fputc (dibit, opts->symbol_out_f);

View File

@@ -560,29 +560,15 @@ void closeWavOutFileRaw (dsd_opts * opts, dsd_state * state)
void openSymbolOutFile (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"); 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) void closeSymbolOutFile (dsd_opts * opts, dsd_state * state)
{ {
//Do something if (opts->symbol_out_f)
if (opts->symbol_out == 1)
{ {
if (opts->symbol_out_f != NULL) fclose(opts->symbol_out_f);
{ opts->symbol_out_f = NULL;
fclose(opts->symbol_out_f);
opts->symbol_out_f = NULL;
}
opts->symbol_out = 0; //set flag to 1
} }
} }

View File

@@ -352,7 +352,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
dibit = 51; // '3' dibit = 51; // '3'
} }
if (opts->symbol_out == 1 && dibit != 0) if (opts->symbol_out_f && dibit != 0)
{ {
int csymbol = 0; int csymbol = 0;
if (dibit == 49) if (dibit == 49)

View File

@@ -501,7 +501,6 @@ initOpts (dsd_opts * opts)
//end import filenames //end import filenames
opts->szNumbers[0] = 0; opts->szNumbers[0] = 0;
opts->symbol_out_f = NULL; opts->symbol_out_f = NULL;
opts->symbol_out = 0;
opts->mbe_out = 0; opts->mbe_out = 0;
opts->mbe_outR = 0; //second slot on a TDMA system opts->mbe_outR = 0; //second slot on a TDMA system
opts->wav_out_f = NULL; opts->wav_out_f = NULL;
@@ -1312,11 +1311,8 @@ cleanupAndExit (dsd_opts * opts, dsd_state * state)
closeWavOutFileL (opts, state); closeWavOutFileL (opts, state);
closeWavOutFileR (opts, state); closeWavOutFileR (opts, state);
} }
if (opts->symbol_out == 1) closeSymbolOutFile (opts, state);
{
closeSymbolOutFile (opts, state);
}
//close MBE out files //close MBE out files
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state); if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (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); strncpy(opts.symbol_out_file, optarg, 1023);
opts.symbol_out_file[1023] = '\0'; opts.symbol_out_file[1023] = '\0';
fprintf (stderr,"Writing + Appending symbol capture to file %s\n", opts.symbol_out_file); fprintf (stderr,"Writing + Appending symbol capture to file %s\n", opts.symbol_out_file);
opts.symbol_out = 1;
openSymbolOutFile (&opts, &state); openSymbolOutFile (&opts, &state);
break; break;

View File

@@ -607,12 +607,7 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state)
wscanw(entry_win, "%s", opts->symbol_out_file); //&opts->symbol_out_file wscanw(entry_win, "%s", opts->symbol_out_file); //&opts->symbol_out_file
noecho(); noecho();
if (opts->symbol_out_file[0] != 0) //NULL openSymbolOutFile (opts, state);
{
opts->symbol_out = 1; //set flag to 1
openSymbolOutFile (opts, state);
}
} }
if (choicec == 4) if (choicec == 4)
{ {
@@ -1030,16 +1025,10 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state)
if (choicec == 16) //stop/close last file RECORDING 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 closeSymbolOutFile (opts, state);
{ sprintf (opts->audio_in_dev, "%s", opts->symbol_out_file); //swap output bin filename to input for quick replay
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
} }
choicec = 18; //exit 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); 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); 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); 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 if (c == 82) //'R', save symbol capture bin with date/time string as name
{ {
sprintf (opts->symbol_out_file, "%s %s.bin", getDateN(), getTimeN()); sprintf (opts->symbol_out_file, "%s %s.bin", getDateN(), getTimeN());
if (opts->symbol_out_file[0] != 0) openSymbolOutFile (opts, state);
{
opts->symbol_out = 1; //set flag to 1
openSymbolOutFile (opts, state);
}
} }
if (c == 114) //'r' key, stop capturing symbol capture bin file 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) closeSymbolOutFile (opts, state);
{ sprintf (opts->audio_in_dev, "%s", opts->symbol_out_file);
fclose(opts->symbol_out_f);
sprintf (opts->audio_in_dev, "%s", opts->symbol_out_file);
}
opts->symbol_out = 0;
} }
} }