From cb84f7469e9e703c2ed0995eca9dcd37a5dd4f53 Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Mon, 26 Sep 2022 19:13:49 -0400 Subject: [PATCH] Mute Audio Option (-o null) --- src/dsd_audio.c | 22 +++++++++++----------- src/dsd_main.c | 10 ++++++++-- src/dsd_ncurses.c | 34 +++++++++++++++++++++++++--------- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/dsd_audio.c b/src/dsd_audio.c index 0c298f3..25ada7a 100644 --- a/src/dsd_audio.c +++ b/src/dsd_audio.c @@ -526,18 +526,18 @@ openAudioOutDevice (dsd_opts * opts, int speed) else { struct stat stat_buf; - if(stat(opts->audio_out_dev, &stat_buf) != 0 && strncmp(opts->audio_out_dev, "pulse", 5 != 0)) //HERE - { - fprintf (stderr,"Error, couldn't open %s\n", opts->audio_out_dev); - exit(1); - } + // if(stat(opts->audio_out_dev, &stat_buf) != 0 && strncmp(opts->audio_out_dev, "pulse", 5 != 0)) //HERE + // { + // fprintf (stderr,"Error, couldn't open %s\n", opts->audio_out_dev); + // exit(1); + // } - if( (!(S_ISCHR(stat_buf.st_mode) || S_ISBLK(stat_buf.st_mode))) && strncmp(opts->audio_out_dev, "pulse", 5 != 0)) - { - // this is not a device - fprintf (stderr,"Error, %s is not a device. use -w filename for wav output.\n", opts->audio_out_dev); - exit(1); - } + // if( (!(S_ISCHR(stat_buf.st_mode) || S_ISBLK(stat_buf.st_mode))) && strncmp(opts->audio_out_dev, "pulse", 5 != 0)) + // { + // // this is not a device + // fprintf (stderr,"Error, %s is not a device. use -w filename for wav output.\n", opts->audio_out_dev); + // exit(1); + // } } fprintf (stderr,"Audio Out Device: %s\n", opts->audio_out_dev); } diff --git a/src/dsd_main.c b/src/dsd_main.c index ac1bfe7..6a60fd3 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -1596,12 +1596,18 @@ main (int argc, char **argv) if((strncmp(opts.audio_in_dev, "pulse", 5) == 0)) { - opts.audio_in_type == 0; + opts.audio_in_type = 0; } if((strncmp(opts.audio_out_dev, "pulse", 5) == 0)) { - opts.audio_out_type == 0; + opts.audio_out_type = 0; + } + + if((strncmp(opts.audio_out_dev, "null", 4) == 0)) + { + opts.audio_out_type = 9; //9 for NULL, or mute output + opts.audio_out = 0; //turn off so we won't playSynthesized } if (opts.playfiles == 1) diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c index 325ff45..9e53f01 100644 --- a/src/dsd_ncurses.c +++ b/src/dsd_ncurses.c @@ -189,15 +189,15 @@ void beeper (dsd_opts * opts, dsd_state * state, int type) if (loop == 1) { //only beep on R if dmr_stereo is active and slot 2, else beep on L - if (type == 0 && state->dmr_stereo == 1) + if (type == 0 && state->dmr_stereo == 1 && opts->audio_out == 1) { pa_simple_write(opts->pulse_digi_dev_out, buf, sizeof(buf), NULL); } - if (type == 1 && state->dmr_stereo == 1) + if (type == 1 && state->dmr_stereo == 1 && opts->audio_out == 1) { pa_simple_write(opts->pulse_digi_dev_outR, buf, sizeof(buf), NULL); } - if (state->dmr_stereo == 0) + if (state->dmr_stereo == 0 && opts->audio_out == 1) { pa_simple_write(opts->pulse_digi_dev_out, buf, sizeof(buf), NULL); } @@ -256,7 +256,7 @@ char *choicesc[] = { "Setup and Start RTL Input ", "Retune RTL Dongle ", " ", - " ", //removing options no longer necesary or not recommended + "Toggle Audio Mute ", //removing options no longer necesary or not recommended "Toggle NCurses Compact Mode", "Toggle NCurses Call History", "Stop All Decoded WAV Saving", @@ -380,8 +380,11 @@ void ncursesOpen (dsd_opts * opts, dsd_state * state) //ncursesMenu void ncursesMenu (dsd_opts * opts, dsd_state * state) { - // state->menuopen = 1; //flag the menu is open, stop processing getFrameSync - closePulseOutput (opts); + //close pulse output if not null output + if (opts->audio_out == 1 && opts->audio_out_type == 0) + { + closePulseOutput (opts); + } if (opts->audio_in_type == 0) //close pulse input if it is the specified input method { @@ -707,7 +710,16 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state) if (choicec == 9) { - //vacant box + if (opts->audio_out == 0) + { + opts->audio_out = 1; + opts->audio_out_type = 0; + } + else + { + opts->audio_out = 0; + opts->audio_out_type = 9; + } } if (choicec == 10) @@ -1451,8 +1463,12 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state) refresh(); state->menuopen = 0; //flag the menu is closed, resume processing getFrameSync - //reopen pulse output with new parameters - openPulseOutput (opts); + //reopen pulse output with new parameters, if not null output type + if (opts->audio_out == 1 && opts->audio_out_type == 0) + { + openPulseOutput (opts); + } + if (opts->audio_in_type == 0) //reopen pulse input if it is the specified input method {