From 529148ee181995ccf0d9ba20d14d2263504a164e Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Sun, 19 Nov 2023 13:57:01 -0500 Subject: [PATCH] Patch - Fix DMR TII Per Call for G; #172 --- patch/g_dmr_per_call_wav_file_fixes.patch | 489 ++++++++++++++++++++++ 1 file changed, 489 insertions(+) create mode 100644 patch/g_dmr_per_call_wav_file_fixes.patch diff --git a/patch/g_dmr_per_call_wav_file_fixes.patch b/patch/g_dmr_per_call_wav_file_fixes.patch new file mode 100644 index 0000000..9eb4aa1 --- /dev/null +++ b/patch/g_dmr_per_call_wav_file_fixes.patch @@ -0,0 +1,489 @@ +diff --git a/src/dmr_csbk.c b/src/dmr_csbk.c +index 0780788..7e8a3bc 100644 +--- a/src/dmr_csbk.c ++++ b/src/dmr_csbk.c +@@ -518,6 +518,25 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 + //rigctl + if (opts->use_rigctl == 1) + { ++ if (state->currentslot == 0) ++ { ++ //close any perCall wav files that are open ++ if (opts->dmr_stereo_wav == 1 && opts->wav_out_f != NULL) ++ { ++ closeWavOutFileL (opts, state); ++ opts->wav_out_f = NULL; ++ } ++ } ++ else if (state->currentslot == 1) ++ { ++ //close any perCall wav files that are open ++ if (opts->dmr_stereo_wav == 1 && opts->wav_out_fR != NULL) ++ { ++ closeWavOutFileR (opts, state); ++ opts->wav_out_fR = NULL; ++ } ++ } ++ + dmr_reset_blocks (opts, state); //reset all block gathering since we are tuning away + //reset some strings + sprintf (state->call_string[state->currentslot], "%s", " "); //21 spaces +@@ -534,6 +553,26 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 + else if (opts->audio_in_type == 3) + { + #ifdef USE_RTLSDR ++ ++ if (state->currentslot == 0) ++ { ++ //close any perCall wav files that are open ++ if (opts->dmr_stereo_wav == 1 && opts->wav_out_f != NULL) ++ { ++ closeWavOutFileL (opts, state); ++ opts->wav_out_f = NULL; ++ } ++ } ++ else if (state->currentslot == 1) ++ { ++ //close any perCall wav files that are open ++ if (opts->dmr_stereo_wav == 1 && opts->wav_out_fR != NULL) ++ { ++ closeWavOutFileR (opts, state); ++ opts->wav_out_fR = NULL; ++ } ++ } ++ + dmr_reset_blocks (opts, state); //reset all block gathering since we are tuning away + //reset some strings + sprintf (state->call_string[state->currentslot], "%s", " "); //21 spaces +diff --git a/src/dmr_flco.c b/src/dmr_flco.c +index 2c54880..44977f6 100644 +--- a/src/dmr_flco.c ++++ b/src/dmr_flco.c +@@ -10,6 +10,38 @@ + *-----------------------------------------------------------------------------*/ + + #include "dsd.h" ++//I really just need to make ONE consolidated date and time function that works correctly ++char * getDateFLC(void) { ++ #ifdef AERO_BUILD ++ char datename[80]; ++ #else ++ char datename[99]; ++ #endif ++ char * curr2; ++ struct tm * to; ++ time_t t; ++ t = time(NULL); ++ to = localtime( & t); ++ strftime(datename, sizeof(datename), "%Y%m%d", to); ++ curr2 = strtok(datename, " "); ++ return curr2; ++} ++ ++//fix from YorgosTheodorakis fork -- https://github.com/YorgosTheodorakis/dsd-fme/commit/7884ee555521a887d388152b3b1f11f20433a94b ++char * getTimeFLC(void) //get pretty hhmmss timestamp ++{ ++ char * curr = (char *) malloc(9); ++ time_t t = time(NULL); ++ struct tm * ptm = localtime(& t); ++ sprintf( ++ curr, ++ "%02d%02d%02d", ++ ptm->tm_hour, ++ ptm->tm_min, ++ ptm->tm_sec ++ ); ++ return curr; ++} + + //combined flco handler (vlc, tlc, emb), minus the superfluous structs and strings + void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t CRCCorrect, uint32_t IrrecoverableErrors, uint8_t type) +@@ -304,6 +336,14 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C + state->dmr_so = so; + state->lasttg = target; + state->lastsrc = source; ++ char * timestr; ++ timestr = getTimeFLC(); ++ //open wav file here if not already opened ++ if (opts->dmr_stereo_wav == 1 && opts->wav_out_f == NULL) ++ { ++ sprintf (opts->wav_out_file, "./%s/%s %s CC %d - TG %d - RD %d", opts->wav_out_dir, getDateFLC(), timestr, state->dmr_color_code, target, source); ++ openWavOutFileL (opts, state); ++ } + } + if (state->currentslot == 1) + { +@@ -311,6 +351,14 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C + state->dmr_soR = so; + state->lasttgR = target; + state->lastsrcR = source; ++ char * timestr; ++ timestr = getTimeFLC(); ++ //open wav file here if not already opened ++ if (opts->dmr_stereo_wav == 1 && opts->wav_out_fR == NULL) ++ { ++ sprintf (opts->wav_out_fileR, "./%s/%s %s CC %d - TG %d - RD %d", opts->wav_out_dir, getDateFLC(), timestr, state->dmr_color_code, target, source); ++ openWavOutFileR (opts, state); ++ } + } + + //update cc amd vc sync time for trunking purposes (particularly Con+) +@@ -337,6 +385,12 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C + //reset gain + if (opts->floating_point == 1) + state->aout_gain = opts->audio_gain; ++ //close any perCall wav files that are open ++ if (opts->dmr_stereo_wav == 1 && opts->wav_out_f != NULL) ++ { ++ closeWavOutFileL (opts, state); ++ opts->wav_out_f = NULL; ++ } + } + if (state->currentslot == 1) + { +@@ -350,6 +404,12 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C + //reset gain + if (opts->floating_point == 1) + state->aout_gainR = opts->audio_gain; ++ //close any perCall wav files that are open ++ if (opts->dmr_stereo_wav == 1 && opts->wav_out_fR != NULL) ++ { ++ closeWavOutFileR (opts, state); ++ opts->wav_out_fR = NULL; ++ } + } + + } +diff --git a/src/dsd_file.c b/src/dsd_file.c +index 8e9094c..4ccec6a 100644 +--- a/src/dsd_file.c ++++ b/src/dsd_file.c +@@ -366,7 +366,7 @@ void closeMbeOutFile (dsd_opts * opts, dsd_state * state) + fclose (opts->mbe_out_f); + opts->mbe_out_f = NULL; + opts->mbe_out = 0; +- fprintf (stderr, "\nClosing MBE out file 1.\n"); ++ // fprintf (stderr, "\nClosing MBE out file 1.\n"); + } + + } +@@ -385,7 +385,7 @@ void closeMbeOutFileR (dsd_opts * opts, dsd_state * state) + fclose (opts->mbe_out_fR); + opts->mbe_out_fR = NULL; + opts->mbe_outR = 0; +- fprintf (stderr, "\nClosing MBE out file 2.\n"); ++ // fprintf (stderr, "\nClosing MBE out file 2.\n"); + } + + } +@@ -420,7 +420,7 @@ void openMbeOutFile (dsd_opts * opts, dsd_state * state) + } + + state->tgcount = 0; +- ++ //TODO: Change the date/time functions here to operate without using colons + sprintf (opts->mbe_out_file, "%s %s S1%s", getDateF(), getTimeF(), ext); + + sprintf (opts->mbe_out_path, "%s%s", opts->mbe_out_dir, opts->mbe_out_file); +@@ -467,7 +467,7 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state) + } + + state->tgcount = 0; +- ++ //TODO: Change the date/time functions here to operate without using colons + sprintf (opts->mbe_out_fileR, "%s %s S2%s", getDateF(), getTimeF(), ext); + + sprintf (opts->mbe_out_path, "%s%s", opts->mbe_out_dir, opts->mbe_out_fileR); +@@ -557,6 +557,43 @@ void closeWavOutFile (dsd_opts * opts, dsd_state * state) + UNUSED(state); + + sf_close(opts->wav_out_f); ++ ++ //TODO: Remove .wav extension in the wav file itself when opening them, and then concantenate .wav and run the system command to 'mv' it and rename it that way ++ char shell[2065], newfilename[1032], tempa[1024], tempb[1032]; //make these larger if needed ++ int result; ++ sprintf (newfilename, "%s.wav", opts->wav_out_file); ++ //of course, the cygwin build doesn't seem to support the system() command properly, wasted way too much time on this, should have just went with ++ //the rename() function immediately instead, damned piece of sH*t ++ //If I pursue this fix later on, just using rename will be a better option, unsure if we would need to ++ //change the / to a \ for windows or not though ++#ifdef AERO_BUILD ++ // opts->wav_out_file[1] = '\b'; ++ // newfilename[1] = '\b'; ++ ++ opts->wav_out_file[5] = '\\'; ++ newfilename[5] = '\\'; ++ memcpy (tempa, opts->wav_out_file+2, 1022); ++ memcpy (tempb, newfilename+2, 1030); ++ UNUSED(shell); ++ ++ // sprintf (shell, "move \"%s\" \"%s\" ", opts->wav_out_file, newfilename); ++ // fprintf (stderr, " move \"%s\" \"%s\" ", opts->wav_out_file, newfilename); //debug ++ // sprintf (shell, "move \"%s\" \"%s\" ", tempa, tempb); ++ // fprintf (stderr, " move \"%s\" \"%s\" ", tempa, tempb); //debug ++ // fprintf (stderr, "%s", shell); //debug ++ ++ result = rename (tempa, tempb); ++#else ++ sprintf (shell, "mv '%s' '%s'", opts->wav_out_file, newfilename); ++ result = system (shell); ++ UNUSED2(tempa, tempb); ++#endif ++ // result = system (shell); ++ ++ //TODO: Check output of result for failure ++ // fprintf (stderr, "\n Close WAV FileF %s; Result: %d \n", newfilename, result); ++ UNUSED(result); ++ + } + + void closeWavOutFileL (dsd_opts * opts, dsd_state * state) +@@ -564,6 +601,40 @@ void closeWavOutFileL (dsd_opts * opts, dsd_state * state) + UNUSED(state); + + sf_close(opts->wav_out_f); ++ ++ //TODO: Remove .wav extension in the wav file itself when opening them, and then concantenate .wav and run the system command to 'mv' it and rename it that way ++ char shell[2065], newfilename[1032], tempa[1024], tempb[1032]; //make these larger if needed ++ int result; ++ sprintf (newfilename, "%s.wav", opts->wav_out_file); ++#ifdef AERO_BUILD ++ // opts->wav_out_file[1] = '\b'; ++ // newfilename[1] = '\b'; ++ ++ opts->wav_out_file[5] = '\\'; ++ newfilename[5] = '\\'; ++ memcpy (tempa, opts->wav_out_file+2, 1022); ++ memcpy (tempb, newfilename+2, 1030); ++ UNUSED(shell); ++ ++ // sprintf (shell, "move \"%s\" \"%s\" ", opts->wav_out_file, newfilename); ++ // fprintf (stderr, " move \"%s\" \"%s\" ", opts->wav_out_file, newfilename); //debug ++ // sprintf (shell, "move \"%s\" \"%s\" ", tempa, tempb); ++ // fprintf (stderr, " move \"%s\" \"%s\" ", tempa, tempb); //debug ++ // fprintf (stderr, "%s", shell); //debug ++ ++ result = rename (tempa, tempb); ++ ++#else ++ sprintf (shell, "mv '%s' '%s'", opts->wav_out_file, newfilename); ++ result = system (shell); ++ UNUSED2(tempa, tempb); ++#endif ++ // result = system (shell); ++ ++ //TODO: Check output of result for failure ++ // fprintf (stderr, "\n Close WAV FileL %s; Result: %d \n", newfilename, result); ++ UNUSED(result); ++ + } + + void closeWavOutFileR (dsd_opts * opts, dsd_state * state) +@@ -571,6 +642,40 @@ void closeWavOutFileR (dsd_opts * opts, dsd_state * state) + UNUSED(state); + + sf_close(opts->wav_out_fR); ++ ++ //TODO: Remove .wav extension in the wav file itself when opening them, and then concantenate .wav and run the system command to 'mv' it and rename it that way ++ char shell[2065], newfilename[1032], tempa[1024], tempb[1032]; //make these larger if needed ++ int result; ++ sprintf (newfilename, "%s.wav", opts->wav_out_fileR); ++#ifdef AERO_BUILD ++ ++ // opts->wav_out_fileR[1] = '\b'; ++ // newfilename[1] = '\b'; ++ ++ UNUSED(shell); ++ opts->wav_out_fileR[5] = '\\'; ++ newfilename[5] = '\\'; ++ memcpy (tempa, opts->wav_out_fileR+2, 1022); ++ memcpy (tempb, newfilename+2, 1030); ++ ++ // sprintf (shell, "move \"%s\" \"%s\" ", opts->wav_out_fileR, newfilename); ++ // fprintf (stderr, " move \"%s\" \"%s\" ", opts->wav_out_fileR, newfilename); //debug ++ // sprintf (shell, "move \"%s\" \"%s\" ", tempa, tempb); ++ // fprintf (stderr, " move \"%s\" \"%s\" ", tempa, tempb); //debug ++ // fprintf (stderr, "%s", shell); //debug ++ ++ result = rename (tempa, tempb); ++ ++#else ++ sprintf (shell, "mv '%s' '%s'", opts->wav_out_fileR, newfilename); ++ result = system (shell); ++ UNUSED2(tempa, tempb); ++#endif ++ // result = system (shell); ++ ++ //TODO: Check output of result for failure ++ // fprintf (stderr, "\n Close WAV FileR %s; Result: %d \n", newfilename, result); ++ UNUSED(result); + } + + void closeWavOutFileRaw (dsd_opts * opts, dsd_state * state) +diff --git a/src/dsd_main.c b/src/dsd_main.c +index 58174be..64ec180 100644 +--- a/src/dsd_main.c ++++ b/src/dsd_main.c +@@ -107,6 +107,19 @@ void + noCarrier (dsd_opts * opts, dsd_state * state) + { + ++ //close any perCall wav files that are open ++ if (opts->dmr_stereo_wav == 1 && opts->wav_out_f != NULL) ++ { ++ closeWavOutFileL (opts, state); ++ opts->wav_out_f = NULL; ++ } ++ if (opts->dmr_stereo_wav == 1 && opts->wav_out_fR != NULL) ++ { ++ closeWavOutFileR (opts, state); ++ opts->wav_out_fR = NULL; ++ } ++ //end perCall wav file close ++ + #ifdef AERO_BUILD + //TODO: Investigate why getSymbol needs to be run first in this context...truly confused here + if(opts->frame_m17 == 1) //&& opts->audio_in_type == 5 +diff --git a/src/dsd_mbe.c b/src/dsd_mbe.c +index 9f609ca..f23209c 100644 +--- a/src/dsd_mbe.c ++++ b/src/dsd_mbe.c +@@ -1191,7 +1191,8 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a + if (state->dmr_encL == 0 || opts->dmr_mute_encL == 0) + { + //write wav to per call on left channel Slot 1 +- writeSynthesizedVoice (opts, state); ++ if (opts->wav_out_f != NULL) ++ writeSynthesizedVoice (opts, state); + } + } + +@@ -1201,7 +1202,8 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a + if (state->dmr_encR == 0 || opts->dmr_mute_encR == 0) + { + //write wav to per call on right channel Slot 2 +- writeSynthesizedVoiceR (opts, state); ++ if (opts->wav_out_fR != NULL) ++ writeSynthesizedVoiceR (opts, state); + } + } + +diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c +index 4646e77..4e29344 100644 +--- a/src/dsd_ncurses.c ++++ b/src/dsd_ncurses.c +@@ -999,7 +999,7 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state) + if (choicec == 12) + { + //flesh out all closewavs and sprint "" wav filenames +- closeWavOutFile (opts, state); ++ // closeWavOutFile (opts, state); + closeWavOutFileL (opts, state); + closeWavOutFileR (opts, state); + //closeWavOutFileRaw (opts, state); +@@ -2063,6 +2063,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) + if (opts->dmr_stereo_wav == 1 && src != 0 ) //&& tgn != 0, some TG can be 0 on NXDN + { + //close old first, assign name based on time and radio, open wav file ++ if (opts->wav_out_f != NULL) + closeWavOutFileL (opts, state); + sprintf (opts->wav_out_file, "./%s/%s %s NXDN - RAN %d - TGT %d - SRC %d.wav", opts->wav_out_dir, getDateN(), timestr, rn, tgn, src); + openWavOutFileL (opts, state); //testing for now, will want to move to per call later +@@ -2105,13 +2106,14 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) + call_matrix[9][5] = time(NULL); + + //open wav file if enabled and both rd and tg are not 0 +- if (opts->dmr_stereo_wav == 1 && rd != 0 && tg != 0) +- { +- //close old first, assign name based on time and radio, open wav file +- closeWavOutFileL (opts, state); +- sprintf (opts->wav_out_file, "./%s/%s %s MS - CC %d - TG %d - RD %d.wav", opts->wav_out_dir, getDateN(), timestr, dcc, tg, rd); +- openWavOutFileL (opts, state); //testing for now, will want to move to per call later +- } ++ // if (opts->dmr_stereo_wav == 1 && rd != 0 && tg != 0) ++ // { ++ // //close old first, assign name based on time and radio, open wav file ++ // if (opts->wav_out_f != NULL) ++ // closeWavOutFileL (opts, state); ++ // sprintf (opts->wav_out_file, "./%s/%s %s MS - CC %d - TG %d - RD %d.wav", opts->wav_out_dir, getDateN(), timestr, dcc, tg, rd); ++ // openWavOutFileL (opts, state); //testing for now, will want to move to per call later ++ // } + + if (opts->call_alert == 1 && rd != 0 && tg != 0) + { +@@ -2126,7 +2128,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) + } + + //DMR BS Slot 1 - matrix 0-4 +- if ( call_matrix[4][2] != rd && (lls == 11 || lls == 12 || lls == 10 || lls == 13 || lls == 35 || lls == 36) ) ++ if ( call_matrix[4][2] != rd && (lls == 11 || lls == 12 || lls == 10 || lls == 13 ) ) //|| lls == 35 || lls == 36 + { + + for (short int k = 0; k < 4; k++) +@@ -2147,14 +2149,14 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) + call_matrix[4][5] = time(NULL); + + //open wav file if enabled and both rd and tg are not 0 +- if (opts->dmr_stereo_wav == 1 && rd != 0 && tg != 0) +- { +- //close old first, assign name based on time and radio, open wav file +- closeWavOutFileL (opts, state); +- +- sprintf (opts->wav_out_file, "./%s/%s %s CC %d - TG %d - RD %d.wav", opts->wav_out_dir, getDateN(), timestr, dcc, tg, rd); +- openWavOutFileL (opts, state); //testing for now, will want to move to per call later +- } ++ // if (opts->dmr_stereo_wav == 1 && rd != 0 && tg != 0) ++ // { ++ // //close old first, assign name based on time and radio, open wav file ++ // if (opts->wav_out_f != NULL) ++ // closeWavOutFileL (opts, state); ++ // sprintf (opts->wav_out_file, "./%s/%s %s CC %d - TG %d - RD %d", opts->wav_out_dir, getDateN(), timestr, dcc, tg, rd); ++ // openWavOutFileL (opts, state); //testing for now, will want to move to per call later ++ // } + + if (opts->call_alert == 1 && rd != 0 && tg != 0) + { +@@ -2190,20 +2192,21 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) + call_matrix[9][5] = time(NULL); + + //open wav file if enabled and both rdR and tgR are not 0 +- if (opts->dmr_stereo_wav == 1 && rdR != 0 && tgR != 0) +- { +- //close old first, assign name based on time and radio, open wav file +- closeWavOutFileR (opts, state); +- sprintf (opts->wav_out_fileR, "./%s/%s %s CC %d - TG %d - RD %d.wav", opts->wav_out_dir, getDateN(), timestr, dcc, tgR, rdR); +- openWavOutFileR (opts, state); //testing for now, will want to move to per call later +- } ++ // if (opts->dmr_stereo_wav == 1 && rdR != 0 && tgR != 0) ++ // { ++ // //close old first, assign name based on time and radio, open wav file ++ // if (opts->wav_out_fR != NULL) ++ // closeWavOutFileR (opts, state); ++ // sprintf (opts->wav_out_fileR, "./%s/%s %s CC %d - TG %d - RD %d", opts->wav_out_dir, getDateN(), timestr, dcc, tgR, rdR); ++ // openWavOutFileR (opts, state); //testing for now, will want to move to per call later ++ // } + +- if (opts->call_alert == 1 && rdR != 0 && tgR != 0) +- { +- //fprintf (stderr, "BEEP 1 BS RIGHT\n"); +- beeper (opts, state, 1); +- state->dmr_end_alert[1] = 0; //new voice frame, okay to beep at the end of it +- } ++ // if (opts->call_alert == 1 && rdR != 0 && tgR != 0) ++ // { ++ // //fprintf (stderr, "BEEP 1 BS RIGHT\n"); ++ // beeper (opts, state, 1); ++ // state->dmr_end_alert[1] = 0; //new voice frame, okay to beep at the end of it ++ // } + + memset(state->dmr_alias_block_segment[1], 0, sizeof(state->dmr_alias_block_segment[1])); + sprintf (state->dmr_embedded_gps[1], "%s", ""); +@@ -3913,7 +3916,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) + if (c == 112) //'p' key - stop all per call wav files + { + //hope this one doesn't cause random crashing or garbage writing +- closeWavOutFile (opts, state); ++ // closeWavOutFile (opts, state); + closeWavOutFileL (opts, state); + closeWavOutFileR (opts, state); + sprintf (opts->wav_out_file, "%s", "");