From a365cd4e67954df3ed6e389d484329eea21ac57a Mon Sep 17 00:00:00 2001 From: ra1nb0w Date: Tue, 22 Dec 2020 22:38:51 +0100 Subject: [PATCH 01/13] cmake: fix portaudio linking issue (#103) --- cmake/FindLibPortAudio.cmake | 112 +++++++++++++++-------------------- 1 file changed, 47 insertions(+), 65 deletions(-) diff --git a/cmake/FindLibPortAudio.cmake b/cmake/FindLibPortAudio.cmake index 11e4055e..67c43e9f 100644 --- a/cmake/FindLibPortAudio.cmake +++ b/cmake/FindLibPortAudio.cmake @@ -19,88 +19,70 @@ if (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS) set(PORTAUDIO_FOUND TRUE) else (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS) if (NOT WIN32) - include(FindPkgConfig) - pkg_check_modules(PORTAUDIO2 portaudio-2.0) + include(FindPkgConfig) + pkg_check_modules(PORTAUDIO2 portaudio-2.0) endif (NOT WIN32) - if (PORTAUDIO2_FOUND) - set(PORTAUDIO_INCLUDE_DIRS - ${PORTAUDIO2_INCLUDE_DIRS} - ) - if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(PORTAUDIO_LIBRARIES "${PORTAUDIO2_LIBRARY_DIRS}/lib${PORTAUDIO2_LIBRARIES}.dylib") - else (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(PORTAUDIO_LIBRARIES - ${PORTAUDIO2_LIBRARIES} - ) - endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(PORTAUDIO_VERSION - 19 - ) - set(PORTAUDIO_FOUND TRUE) - else (PORTAUDIO2_FOUND) - find_path(PORTAUDIO_INCLUDE_DIR - NAMES - portaudio.h + find_path (PORTAUDIO_INCLUDE_DIRS + NAMES + portaudio.h PATHS + ${PORTAUDIO2_INCLUDEDIR} /usr/include /usr/local/include /opt/local/include /sw/include ) - - find_library(PORTAUDIO_LIBRARY - NAMES - portaudio - PATHS - /usr/lib - /usr/local/lib - /opt/local/lib - /sw/lib - ) - - find_path(PORTAUDIO_LIBRARY_DIR - NAMES - portaudio - PATHS - /usr/lib - /usr/local/lib - /opt/local/lib - /sw/lib + if (NOT PORTAUDIO_INCLUDE_DIRS) + set (PORTAUDIO_INCLUDE_DIRS + ${PORTAUDIO2_INCLUDE_DIRS} ) + list (APPEND PORTAUDIO_INCLUDE_DIRS ${PORTAUDIO2_INCLUDEDIR}) + endif (NOT PORTAUDIO_INCLUDE_DIRS) - set(PORTAUDIO_INCLUDE_DIRS - ${PORTAUDIO_INCLUDE_DIR} - ) - set(PORTAUDIO_LIBRARIES - ${PORTAUDIO_LIBRARY} + find_library (PORTAUDIO_LIBRARIES + NAMES + portaudio + PATHS + ${PORTAUDIO2_LIBDIR} + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + if (NOT PORTAUDIO_LIBRARIES) + if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(PORTAUDIO_LIBRARIES "${PORTAUDIO2_LIBDIR}/lib${PORTAUDIO2_LIBRARIES}.dylib") + else (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(PORTAUDIO_LIBRARIES + ${PORTAUDIO2_LIBRARIES} ) + endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + endif (NOT PORTAUDIO_LIBRARIES) - set(PORTAUDIO_LIBRARY_DIRS - ${PORTAUDIO_LIBRARY_DIR} + if (PORTAUDIO2_VERSION) + set(PORTAUDIO_VERSION + ${PORTAUDIO2_VERSION} ) - + else (PORTAUDIO2_VERSION) set(PORTAUDIO_VERSION 18 ) + endif (PORTAUDIO2_VERSION) - if (PORTAUDIO_INCLUDE_DIRS AND PORTAUDIO_LIBRARIES) - set(PORTAUDIO_FOUND TRUE) - endif (PORTAUDIO_INCLUDE_DIRS AND PORTAUDIO_LIBRARIES) - - if (PORTAUDIO_FOUND) - if (NOT Portaudio_FIND_QUIETLY) - message(STATUS "Found Portaudio: ${PORTAUDIO_LIBRARIES}") - endif (NOT Portaudio_FIND_QUIETLY) - else (PORTAUDIO_FOUND) - if (Portaudio_FIND_REQUIRED) - message(FATAL_ERROR "Could not find Portaudio") - else (Portaudio_FIND_REQUIRED) - message(STATUS "Could NOT find Portaudio") - endif (Portaudio_FIND_REQUIRED) - endif (PORTAUDIO_FOUND) - endif (PORTAUDIO2_FOUND) - + if (PORTAUDIO_INCLUDE_DIRS AND PORTAUDIO_LIBRARIES) + set(PORTAUDIO_FOUND TRUE) + endif (PORTAUDIO_INCLUDE_DIRS AND PORTAUDIO_LIBRARIES) + + if (PORTAUDIO_FOUND) + if (NOT Portaudio_FIND_QUIETLY) + message(STATUS "Found Portaudio: ${PORTAUDIO_LIBRARIES}") + endif (NOT Portaudio_FIND_QUIETLY) + else (PORTAUDIO_FOUND) + if (Portaudio_FIND_REQUIRED) + message(FATAL_ERROR "Could not find Portaudio") + endif (Portaudio_FIND_REQUIRED) + endif (PORTAUDIO_FOUND) # show the PORTAUDIO_INCLUDE_DIRS and PORTAUDIO_LIBRARIES variables only in the advanced view mark_as_advanced(PORTAUDIO_INCLUDE_DIRS PORTAUDIO_LIBRARIES) From 2705cbaa85954379afb53a3ab606b15c0c98b78f Mon Sep 17 00:00:00 2001 From: Yinette Hodge Date: Fri, 22 Oct 2021 04:47:46 +1100 Subject: [PATCH 02/13] Fixing multiple definitions of exitflag (szechyjs#104) (#105) Thanks to N0YKG for the fix! I am just making the PR :) --- include/dsd.h | 2 +- src/dsd_main.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/dsd.h b/include/dsd.h index 22ef3e9b..353b8ded 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -61,7 +61,7 @@ /* * global variables */ -int exitflag; +extern int exitflag; typedef struct diff --git a/src/dsd_main.c b/src/dsd_main.c index 4069ce02..02dececf 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -28,6 +28,7 @@ #include "p25p1_heuristics.h" #include "pa_devs.h" +int exitflag = 0; int comp (const void *a, const void *b) From 12b37b5138bc8834b8ed17b9594f61f18e7bf5db Mon Sep 17 00:00:00 2001 From: Jared Szechy Date: Mon, 13 Dec 2021 16:31:03 -0500 Subject: [PATCH 03/13] Create codeql-analysis.yml --- .github/workflows/codeql-analysis.yml | 70 +++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..055ae920 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,70 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '36 11 * * 5' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'cpp' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://git.io/codeql-language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 From d4a338e0a2a35dd47dea238cc41d1d08b92bd288 Mon Sep 17 00:00:00 2001 From: Jared Szechy Date: Mon, 13 Dec 2021 16:38:44 -0500 Subject: [PATCH 04/13] Install deps --- .github/workflows/codeql-analysis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 055ae920..24592274 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -39,6 +39,11 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v2 + + - name: Install dependencies + run: | + sudo apt-add-repository ppa:szechyjs/dsd + sudo apt-get install -y libmbe-dev libsndfile1-dev libitpp-dev portaudio19-dev # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL From 4020e8703a896ca7f6606c8bb679184d841c9546 Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Sun, 13 Mar 2022 22:37:57 -0400 Subject: [PATCH 05/13] Initialize last_dibit variable (#119) --- src/dsd_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dsd_main.c b/src/dsd_main.c index 02dececf..8ff463fe 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -236,6 +236,8 @@ initState (dsd_state * state) state->debug_header_errors = 0; state->debug_header_critical_errors = 0; + state->last_dibit = 0; + #ifdef TRACE_DSD state->debug_sample_index = 0; state->debug_label_file = NULL; From 663caa74fec1eb23dd93b227b0735f4061a4983d Mon Sep 17 00:00:00 2001 From: Patrick Eads Date: Tue, 7 Feb 2023 08:15:51 -0500 Subject: [PATCH 06/13] Refactored dsd_mbe::playMbeFile to properly handle eof and closing the currently read file, which was causing segfaults for large numbers of mbe files being read in. Extracted reader function calls to typedefed pointer, s.t. since the file type only needs to be read per file, it could be set to a generic function pointer thus cleaning up the read loop. Fixed end conditions for both the while and for loops, s.t. they break on exit flag, and their respective conditions. Removed redundant cleanup function call since the caller calls it on return of the play function anyway. --- .gitignore | 5 ++ CMakeLists.txt | 2 +- cmake/FindLibSndFile.cmake | 9 ++- src/dsd_mbe.c | 116 +++++++++++++++++++++++-------------- test/gmock/CMakeLists.txt | 2 +- test/gtest/CMakeLists.txt | 2 +- 6 files changed, 87 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index b2954aab..d675840a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,8 @@ dsd *.dylib build .DS_Store +.idea +cmake-build* +*.swp + +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c1663c5..dcd12ce8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ project(dsd) -cmake_minimum_required(VERSION 2.8.11) +cmake_minimum_required(VERSION 3.22) SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/") diff --git a/cmake/FindLibSndFile.cmake b/cmake/FindLibSndFile.cmake index b12b358d..474ea413 100644 --- a/cmake/FindLibSndFile.cmake +++ b/cmake/FindLibSndFile.cmake @@ -12,5 +12,10 @@ SET(LIBSNDFILE_NAMES ${LIBSNDFILE_NAMES} sndfile libsndfile) FIND_LIBRARY(LIBSNDFILE_LIBRARY NAMES ${LIBSNDFILE_NAMES}) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LIBSNDFILE DEFAULT_MSG LIBSNDFILE_LIBRARY - LIBSNDFILE_INCLUDE_DIR) \ No newline at end of file +if (APPLE) + find_package_handle_standard_args(LibSndFile DEFAULT_MSG LIBSNDFILE_LIBRARY + LIBSNDFILE_INCLUDE_DIR) +elseif (UNIX) + find_package_handle_standard_args(LIBSNDFILE DEFAULT_MSG LIBSNDFILE_LIBRARY + LIBSNDFILE_INCLUDE_DIR) +endif() #TODO elseif windows lol \ No newline at end of file diff --git a/src/dsd_mbe.c b/src/dsd_mbe.c index 3e93a826..1d037c1e 100644 --- a/src/dsd_mbe.c +++ b/src/dsd_mbe.c @@ -17,56 +17,84 @@ #include "dsd.h" -void -playMbeFiles (dsd_opts * opts, dsd_state * state, int argc, char **argv) -{ +typedef void (*dataReaderDef)(dsd_opts *opts, dsd_state *state); - int i; - char imbe_d[88]; - char ambe_d[49]; +void readImbe(dsd_opts *opts, dsd_state *state) { - for (i = state->optind; i < argc; i++) - { - sprintf (opts->mbe_in_file, "%s", argv[i]); - openMbeInFile (opts, state); - mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced); - printf ("playing %s\n", opts->mbe_in_file); - while (feof (opts->mbe_in_f) == 0) - { - if (state->mbe_file_type == 0) - { - readImbe4400Data (opts, state, imbe_d); - mbe_processImbe4400Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); - processAudio (opts, state); - if (opts->wav_out_f != NULL) - { - writeSynthesizedVoice (opts, state); - } - - if (opts->audio_out == 1) - { - playSynthesizedVoice (opts, state); - } + char imbe_d[88]; + readImbe4400Data(opts, state, imbe_d); + mbe_processImbe4400Dataf(state->audio_out_temp_buf, + &state->errs, + &state->errs2, + state->err_str, + imbe_d, + state->cur_mp, + state->prev_mp, + state->prev_mp_enhanced, + opts->uvquality); +} + +void readAmbe(dsd_opts *opts, dsd_state *state) { + + char ambe_d[49]; + readAmbe2450Data(opts, state, ambe_d); + mbe_processAmbe2450Dataf(state->audio_out_temp_buf, + &state->errs, + &state->errs2, + state->err_str, + ambe_d, + state->cur_mp, + state->prev_mp, + state->prev_mp_enhanced, + opts->uvquality); +} + +void playMbeFiles(dsd_opts *opts, dsd_state *state, int argc, char **argv) { + + int i; + dataReaderDef readData = NULL; + + for (i = state->optind; !exitflag && i < argc; i++) { + + strcpy(opts->mbe_in_file, argv[i]); + openMbeInFile(opts, state); + mbe_initMbeParms(state->cur_mp, + state->prev_mp, + state->prev_mp_enhanced); + printf("playing %s\n", opts->mbe_in_file); + + switch (state->mbe_file_type) { + case 0: + readData = readImbe; + break; + case 1: + readData = readAmbe; + break; + } + + while (!exitflag) { + + readData(opts, state); + processAudio(opts, state); + + if (opts->wav_out_f != NULL) { + writeSynthesizedVoice(opts, state); } - else if (state->mbe_file_type == 1) - { - readAmbe2450Data (opts, state, ambe_d); - mbe_processAmbe2450Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); - processAudio (opts, state); - if (opts->wav_out_f != NULL) - { - writeSynthesizedVoice (opts, state); - } - if (opts->audio_out == 1) - { - playSynthesizedVoice (opts, state); - } + + if (1 == opts->audio_out) { + playSynthesizedVoice(opts, state); } - if (exitflag == 1) - { - cleanupAndExit (opts, state); + + if (ferror(opts->mbe_in_f)) { + perror("I/O error when reading"); + exitflag = 1; + break; + } else if (feof(opts->mbe_in_f)) { + break; } } + + closeMbeOutFile(opts, state); } } diff --git a/test/gmock/CMakeLists.txt b/test/gmock/CMakeLists.txt index ae4dfc6f..cae30979 100644 --- a/test/gmock/CMakeLists.txt +++ b/test/gmock/CMakeLists.txt @@ -20,7 +20,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) # ${gmock_BINARY_DIR}. # Language "C" is required for find_package(Threads). project(gmock CXX C) -cmake_minimum_required(VERSION 2.6.2) +cmake_minimum_required(VERSION 3.22) # Adds Google Mock's and Google Test's header directories to the search path. include_directories("${gmock_SOURCE_DIR}/include" diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index b9498cdb..55aac098 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -36,7 +36,7 @@ endif() # ${gtest_BINARY_DIR}. # Language "C" is required for find_package(Threads). project(gtest CXX C) -cmake_minimum_required(VERSION 2.6.2) +cmake_minimum_required(VERSION 3.22) if (COMMAND set_up_hermetic_build) set_up_hermetic_build() From ed1da8a3deb1cb09e109f877eb3c2d89da80aa33 Mon Sep 17 00:00:00 2001 From: Patrick Eads Date: Tue, 7 Feb 2023 08:17:30 -0500 Subject: [PATCH 07/13] Added default case, and fixed while loop condition. --- src/dsd_mbe.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dsd_mbe.c b/src/dsd_mbe.c index 1d037c1e..07ce6531 100644 --- a/src/dsd_mbe.c +++ b/src/dsd_mbe.c @@ -70,9 +70,12 @@ void playMbeFiles(dsd_opts *opts, dsd_state *state, int argc, char **argv) { case 1: readData = readAmbe; break; + default: + exitflag = 1; + break; } - while (!exitflag) { + while (!exitflag && readData != NULL) { readData(opts, state); processAudio(opts, state); From 29da7b4655824a2926662d335a52d68f31a34613 Mon Sep 17 00:00:00 2001 From: Patrick Eads Date: Tue, 7 Feb 2023 10:40:15 -0500 Subject: [PATCH 08/13] Added a bunch of file helper functions to handle error checking. --- include/dsd.h | 3 +- src/dsd_file.c | 82 ++++++++++++++++++++++++++++++++++---------------- src/dsd_mbe.c | 54 ++++++++++++++++----------------- 3 files changed, 84 insertions(+), 55 deletions(-) diff --git a/include/dsd.h b/include/dsd.h index 353b8ded..80dc58eb 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -316,5 +316,6 @@ void processX2TDMAvoice (dsd_opts * opts, dsd_state * state); void processDSTAR_HD (dsd_opts * opts, dsd_state * state); short dmr_filter(short sample); short nxdn_filter(short sample); - +int checkFileError(FILE *file); +int handleFatalFileError(char *fileName, int fileStatus); #endif // DSD_H diff --git a/src/dsd_file.c b/src/dsd_file.c index c805885d..7a5616ad 100644 --- a/src/dsd_file.c +++ b/src/dsd_file.c @@ -17,6 +17,35 @@ #include "dsd.h" +int checkFileError(FILE *file) { + if (ferror(file)) { + return -1; + } else if (feof(file)) { + return 1; + } + + return 0; +} + +int handleFatalFileError(char *fileName, int fileStatus) { + + char errorMsg[255]; + + switch (fileStatus) { + case 0: + case 1: + break; + case -1: + default: + sprintf(errorMsg, "I/O error when reading file %s ", fileName); + perror(errorMsg); + exitflag = 1; + break; + } + + return fileStatus; +} + void saveImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d) { @@ -130,38 +159,39 @@ readAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d) return (0); } -void -openMbeInFile (dsd_opts * opts, dsd_state * state) -{ +void openMbeInFile(dsd_opts *opts, dsd_state *state) { - char cookie[5]; + char cookie[5]; + uint32_t c, i; + char errorMsg[255]; - opts->mbe_in_f = fopen (opts->mbe_in_file, "ro"); - if (opts->mbe_in_f == NULL) - { - printf ("Error: could not open %s\n", opts->mbe_in_file); + opts->mbe_in_f = fopen(opts->mbe_in_file, "ro"); + if (NULL == opts->mbe_in_f) { + sprintf(errorMsg, "Error: could not open %s ", opts->mbe_in_file); + perror(errorMsg); } - // read cookie - cookie[0] = fgetc (opts->mbe_in_f); - cookie[1] = fgetc (opts->mbe_in_f); - cookie[2] = fgetc (opts->mbe_in_f); - cookie[3] = fgetc (opts->mbe_in_f); - cookie[4] = 0; - if (strstr (cookie, ".amb") != NULL) - { - state->mbe_file_type = 1; - } - else if (strstr (cookie, ".imb") != NULL) - { - state->mbe_file_type = 0; + for (i = 0; !exitflag && i < 4; ++i) { + + c = fgetc(opts->mbe_in_f); + + if (handleFatalFileError(opts->mbe_in_file, checkFileError(opts->mbe_in_f))) { + break; + } + + // read cookie + cookie[i] = (char) c; } - else - { - state->mbe_file_type = -1; - printf ("Error - unrecognized file type\n"); + cookie[4] = 0; + + if (strstr(cookie, ".amb") != NULL) { + state->mbe_file_type = 1; + } else if (strstr(cookie, ".imb") != NULL) { + state->mbe_file_type = 0; + } else { + state->mbe_file_type = -1; + fprintf(stderr, "%s\n", "Error - unrecognized file type"); } - } void diff --git a/src/dsd_mbe.c b/src/dsd_mbe.c index 07ce6531..a7a3a23b 100644 --- a/src/dsd_mbe.c +++ b/src/dsd_mbe.c @@ -19,7 +19,7 @@ typedef void (*dataReaderDef)(dsd_opts *opts, dsd_state *state); -void readImbe(dsd_opts *opts, dsd_state *state) { +static void readImbe(dsd_opts *opts, dsd_state *state) { char imbe_d[88]; readImbe4400Data(opts, state, imbe_d); @@ -34,7 +34,7 @@ void readImbe(dsd_opts *opts, dsd_state *state) { opts->uvquality); } -void readAmbe(dsd_opts *opts, dsd_state *state) { +static void readAmbe(dsd_opts *opts, dsd_state *state) { char ambe_d[49]; readAmbe2450Data(opts, state, ambe_d); @@ -49,11 +49,30 @@ void readAmbe(dsd_opts *opts, dsd_state *state) { opts->uvquality); } +static void playMbeFile(dataReaderDef readData, dsd_opts *opts, dsd_state *state) { + + while (!exitflag && readData != NULL) { + + readData(opts, state); + processAudio(opts, state); + + if (opts->wav_out_f != NULL) { + writeSynthesizedVoice(opts, state); + } + + if (1 == opts->audio_out) { + playSynthesizedVoice(opts, state); + } + + if (handleFatalFileError(opts->mbe_in_file, checkFileError(opts->mbe_in_f))) { + break; + } + } +} + void playMbeFiles(dsd_opts *opts, dsd_state *state, int argc, char **argv) { int i; - dataReaderDef readData = NULL; - for (i = state->optind; !exitflag && i < argc; i++) { strcpy(opts->mbe_in_file, argv[i]); @@ -65,38 +84,17 @@ void playMbeFiles(dsd_opts *opts, dsd_state *state, int argc, char **argv) { switch (state->mbe_file_type) { case 0: - readData = readImbe; + playMbeFile(readImbe, opts, state); break; case 1: - readData = readAmbe; + playMbeFile(readAmbe, opts, state); break; default: + fprintf(stderr, "Error - unrecognized file type %d\n", state->mbe_file_type); exitflag = 1; break; } - while (!exitflag && readData != NULL) { - - readData(opts, state); - processAudio(opts, state); - - if (opts->wav_out_f != NULL) { - writeSynthesizedVoice(opts, state); - } - - if (1 == opts->audio_out) { - playSynthesizedVoice(opts, state); - } - - if (ferror(opts->mbe_in_f)) { - perror("I/O error when reading"); - exitflag = 1; - break; - } else if (feof(opts->mbe_in_f)) { - break; - } - } - closeMbeOutFile(opts, state); } } From 563b4d8351a46c03d426ecba404096cd77325f87 Mon Sep 17 00:00:00 2001 From: Patrick Eads Date: Tue, 7 Feb 2023 10:48:57 -0500 Subject: [PATCH 09/13] Added file open helper function. Refactored file error handler to be extensible beyond EOF being defined as -1 in glibc. Changed expected EOF in playMbeFile to be handled specially (i.e. not sent to error handler) because it's more likely than not to be expected, and in any case, we can just trying playing the next file. --- include/dsd.h | 2 +- src/dsd_file.c | 36 +++++++++++++++++++++++------------- src/dsd_mbe.c | 10 ++++++++-- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/include/dsd.h b/include/dsd.h index 80dc58eb..04f2fbc6 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -317,5 +317,5 @@ void processDSTAR_HD (dsd_opts * opts, dsd_state * state); short dmr_filter(short sample); short nxdn_filter(short sample); int checkFileError(FILE *file); -int handleFatalFileError(char *fileName, int fileStatus); +int handleFileError(char *fileName, int fileStatus); #endif // DSD_H diff --git a/src/dsd_file.c b/src/dsd_file.c index 7a5616ad..fcdadcae 100644 --- a/src/dsd_file.c +++ b/src/dsd_file.c @@ -17,25 +17,39 @@ #include "dsd.h" +static void openFile(FILE **file, char *fileName) { + char errorMsg[255]; + + *file = fopen(fileName, "ro"); + if (NULL == *file) { + sprintf(errorMsg, "Error: could not open %s ", fileName); + perror(errorMsg); + exitflag = 1; + } +} + int checkFileError(FILE *file) { if (ferror(file)) { - return -1; - } else if (feof(file)) { return 1; + } else if (feof(file)) { + return EOF; } return 0; } -int handleFatalFileError(char *fileName, int fileStatus) { +int handleFileError(char *fileName, int fileStatus) { char errorMsg[255]; switch (fileStatus) { case 0: - case 1: break; - case -1: + case EOF: + sprintf(errorMsg, "Unexpected EOF when reading file %s ", fileName); + perror(errorMsg); + break; + case 1: default: sprintf(errorMsg, "I/O error when reading file %s ", fileName); perror(errorMsg); @@ -162,20 +176,15 @@ readAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d) void openMbeInFile(dsd_opts *opts, dsd_state *state) { char cookie[5]; - uint32_t c, i; - char errorMsg[255]; + int c, i; - opts->mbe_in_f = fopen(opts->mbe_in_file, "ro"); - if (NULL == opts->mbe_in_f) { - sprintf(errorMsg, "Error: could not open %s ", opts->mbe_in_file); - perror(errorMsg); - } + openFile(&opts->mbe_in_f, opts->mbe_in_file); for (i = 0; !exitflag && i < 4; ++i) { c = fgetc(opts->mbe_in_f); - if (handleFatalFileError(opts->mbe_in_file, checkFileError(opts->mbe_in_f))) { + if (handleFileError(opts->mbe_in_file, checkFileError(opts->mbe_in_f))) { break; } @@ -191,6 +200,7 @@ void openMbeInFile(dsd_opts *opts, dsd_state *state) { } else { state->mbe_file_type = -1; fprintf(stderr, "%s\n", "Error - unrecognized file type"); + exitflag = 1; } } diff --git a/src/dsd_mbe.c b/src/dsd_mbe.c index a7a3a23b..7cef85e5 100644 --- a/src/dsd_mbe.c +++ b/src/dsd_mbe.c @@ -51,6 +51,8 @@ static void readAmbe(dsd_opts *opts, dsd_state *state) { static void playMbeFile(dataReaderDef readData, dsd_opts *opts, dsd_state *state) { + int ret; + while (!exitflag && readData != NULL) { readData(opts, state); @@ -64,7 +66,11 @@ static void playMbeFile(dataReaderDef readData, dsd_opts *opts, dsd_state *state playSynthesizedVoice(opts, state); } - if (handleFatalFileError(opts->mbe_in_file, checkFileError(opts->mbe_in_f))) { + if ((ret = checkFileError(opts->mbe_in_f))) { + + if (ret != EOF) { + handleFileError(opts->mbe_in_file, ret); + } break; } } @@ -95,7 +101,7 @@ void playMbeFiles(dsd_opts *opts, dsd_state *state, int argc, char **argv) { break; } - closeMbeOutFile(opts, state); + handleFileError(opts->mbe_in_file, fclose(opts->mbe_in_f)); } } From 067a1d5d1c2095ca07854e7219ed77a12f5255cf Mon Sep 17 00:00:00 2001 From: Patrick Eads Date: Tue, 7 Feb 2023 11:07:35 -0500 Subject: [PATCH 10/13] Made print in play function respect the quiet flag --- src/dsd_mbe.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/dsd_mbe.c b/src/dsd_mbe.c index 7cef85e5..4d38cedc 100644 --- a/src/dsd_mbe.c +++ b/src/dsd_mbe.c @@ -67,7 +67,7 @@ static void playMbeFile(dataReaderDef readData, dsd_opts *opts, dsd_state *state } if ((ret = checkFileError(opts->mbe_in_f))) { - + if (ret != EOF) { handleFileError(opts->mbe_in_file, ret); } @@ -86,7 +86,10 @@ void playMbeFiles(dsd_opts *opts, dsd_state *state, int argc, char **argv) { mbe_initMbeParms(state->cur_mp, state->prev_mp, state->prev_mp_enhanced); - printf("playing %s\n", opts->mbe_in_file); + + if (opts->verbose > 0) { + printf("playing %s\n", opts->mbe_in_file); + } switch (state->mbe_file_type) { case 0: From c2c02694927875070a3e7cbea51ea617bea48de5 Mon Sep 17 00:00:00 2001 From: Patrick Eads Date: Tue, 3 Oct 2023 16:58:07 +0000 Subject: [PATCH 11/13] reverted CMakeLists change --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dcd12ce8..4c1663c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ project(dsd) -cmake_minimum_required(VERSION 3.22) +cmake_minimum_required(VERSION 2.8.11) SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/") From f1190c3cd845f10b0f2ab8ebc5b5469bcdd8de21 Mon Sep 17 00:00:00 2001 From: Patrick Eads Date: Tue, 3 Oct 2023 16:59:46 +0000 Subject: [PATCH 12/13] reverted CMakeLists change --- test/gmock/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/gmock/CMakeLists.txt b/test/gmock/CMakeLists.txt index cae30979..ae4dfc6f 100644 --- a/test/gmock/CMakeLists.txt +++ b/test/gmock/CMakeLists.txt @@ -20,7 +20,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF) # ${gmock_BINARY_DIR}. # Language "C" is required for find_package(Threads). project(gmock CXX C) -cmake_minimum_required(VERSION 3.22) +cmake_minimum_required(VERSION 2.6.2) # Adds Google Mock's and Google Test's header directories to the search path. include_directories("${gmock_SOURCE_DIR}/include" From f7952f7bf42f47aa54d0beebee686a39bcec1254 Mon Sep 17 00:00:00 2001 From: Patrick Eads Date: Tue, 3 Oct 2023 17:00:36 +0000 Subject: [PATCH 13/13] reverted CMakeLists change, I should've just used sed --- test/gtest/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index 55aac098..b9498cdb 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -36,7 +36,7 @@ endif() # ${gtest_BINARY_DIR}. # Language "C" is required for find_package(Threads). project(gtest CXX C) -cmake_minimum_required(VERSION 3.22) +cmake_minimum_required(VERSION 2.6.2) if (COMMAND set_up_hermetic_build) set_up_hermetic_build()