From ef94b311fa28da5c8b169855a667ae46e2091503 Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Mon, 6 May 2024 21:46:29 -0400 Subject: [PATCH] Add Error Handling and Error String on Pulse Input and Output Opening #259 ; Change Input 'Name' on M17 Voice Input so it doesn't default to same source as RF Signal Input; --- CMakeLists.txt | 2 +- include/dsd.h | 1 + src/dsd_audio.c | 32 +++++++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b8c7d6..4b48ec3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,7 +59,7 @@ find_package(PulseAudio REQUIRED) find_package(CODEC2) include_directories(SYSTEM ${LIBSNDFILE_INCLUDE_DIR} ${MBE_INCLUDE_DIR} ${ITPP_INCLUDE_DIR} ${PULSEAUDIO_INCLUDE_DIRS} ${CURSES_INCLUDE_DIR}) -set(LIBS ${MBE_LIBRARY} ${LIBSNDFILE_LIBRARY} ${ITPP_LIBRARY} ${PULSEAUDIO_SIMPLE_LIBRARY} ${CURSES_LIBRARY}) +set(LIBS ${MBE_LIBRARY} ${LIBSNDFILE_LIBRARY} ${ITPP_LIBRARY} ${PULSEAUDIO_SIMPLE_LIBRARY} ${PULSEAUDIO_LIBRARY} ${CURSES_LIBRARY}) if(RTLSDR_FOUND) find_package(Threads) diff --git a/include/dsd.h b/include/dsd.h index aeb2d4a..1cff836 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -63,6 +63,7 @@ #include //PULSE AUDIO #include //PULSE AUDIO +#include //PULSE AUDIO #define SAMPLE_RATE_IN 48000 //48000 #define SAMPLE_RATE_OUT 8000 //8000 diff --git a/src/dsd_audio.c b/src/dsd_audio.c index 0ab5878..8542c65 100644 --- a/src/dsd_audio.c +++ b/src/dsd_audio.c @@ -41,6 +41,8 @@ void closePulseInput (dsd_opts * opts) void openPulseOutput(dsd_opts * opts) { + int err; + ss.format = PA_SAMPLE_S16NE; ss.channels = opts->pulse_raw_out_channels; ss.rate = opts->pulse_raw_rate_out; @@ -57,20 +59,41 @@ void openPulseOutput(dsd_opts * opts) if (opts->frame_provoice == 1 || opts->monitor_input_audio == 1) opts->pulse_raw_dev_out = pa_simple_new(NULL, "DSD-FME3", PA_STREAM_PLAYBACK, NULL, "Analog", &ss, 0, NULL, NULL); + if (err < 0) + { + fprintf (stderr, "%s", pa_strerror(err)); + exit(0); + } + pa_channel_map* fl = 0; //NULL and 0 are same in this context pa_channel_map* ss = 0; //NULL and 0 are same in this context if (opts->floating_point == 0) opts->pulse_digi_dev_out = pa_simple_new(NULL, "DSD-FME", PA_STREAM_PLAYBACK, NULL, opts->output_name, &tt, ss, NULL, NULL); + if (err < 0) + { + fprintf (stderr, "%s", pa_strerror(err)); + exit(0); + } + if (opts->floating_point == 1) + { opts->pulse_digi_dev_out = pa_simple_new(NULL, "DSD-FME", PA_STREAM_PLAYBACK, NULL, opts->output_name, &ff, fl, NULL, NULL); + if (err < 0) + { + fprintf (stderr, "%s", pa_strerror(err)); + exit(0); + } + } } void openPulseInput(dsd_opts * opts) { + int err; + cc.format = PA_SAMPLE_S16NE; cc.channels = opts->pulse_digi_in_channels; cc.rate = opts->pulse_digi_rate_in; //48000 @@ -94,8 +117,15 @@ void openPulseInput(dsd_opts * opts) lt.maxlength = -1; lt.prebuf = -1; lt.tlength = -1; + if (opts->m17encoder == 1) + opts->pulse_digi_dev_in = pa_simple_new(NULL, "DSD-FME4", PA_STREAM_RECORD, NULL, "M17 Voice Input", &cc, NULL, <, &err); + else opts->pulse_digi_dev_in = pa_simple_new(NULL, "DSD-FME", PA_STREAM_RECORD, NULL, opts->output_name, &cc, NULL, <, &err); - opts->pulse_digi_dev_in = pa_simple_new(NULL, "DSD-FME", PA_STREAM_RECORD, NULL, opts->output_name, &cc, NULL, <, NULL); + if (err < 0) + { + fprintf (stderr, "%s", pa_strerror(err)); + exit(0); + } //debug // if (opts->m17encoder == 1)