From ec9c220ad7fb58921f40409fa4fcdf670e89ba6c Mon Sep 17 00:00:00 2001 From: lwvmobile <59371473+lwvmobile@users.noreply.github.com> Date: Wed, 4 May 2022 10:28:35 -0400 Subject: [PATCH] Fix Upsampling Bug Fix Upsampling Bug --Change logic to only upsample audio when out sample rate is greater than 8k. --Revert RTL and MBE output sample rate to 8k/1 due to random crackling --RTL will still shift to 24k/2 for DMR TDMA stereo, may produce noticeable crackling, unknown as of now, unable to test. --- src/dsd_audio.c | 26 +++++++++++++++++--------- src/dsd_main.c | 20 ++++++++++++-------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/dsd_audio.c b/src/dsd_audio.c index ea1644f..a5e277d 100644 --- a/src/dsd_audio.c +++ b/src/dsd_audio.c @@ -156,8 +156,9 @@ processAudio (dsd_opts * opts, dsd_state * state) // copy audio data to output buffer and upsample if necessary state->audio_out_temp_buf_p = state->audio_out_temp_buf; - //the only time we don't want to upsample is when playing back MBE files, upsampling them seems to cause random crackling - if (opts->playfiles == 0) //opts->split == 0 + //we only want to upsample when using sample rates greater than 8k for output, + //hard set to 8k for RTL mono and MBE playback, otherwise crackling may occur. + if (opts->pulse_digi_rate_out > 8000) { for (n = 0; n < 160; n++) { @@ -296,8 +297,9 @@ processAudioR (dsd_opts * opts, dsd_state * state) // copy audio data to output buffer and upsample if necessary state->audio_out_temp_buf_pR = state->audio_out_temp_bufR; - //the only time we don't want to upsample is when playing back MBE files, upsampling them seems to cause random crackling - if (opts->playfiles == 0) //opts->split == 0 + //we only want to upsample when using sample rates greater than 8k for output, + //hard set to 8k for RTL mono and MBE playback, otherwise crackling may occur. + if (opts->pulse_digi_rate_out > 8000) { for (n = 0; n < 160; n++) { @@ -388,6 +390,11 @@ playSynthesizedVoice (dsd_opts * opts, dsd_state * state) //go F yourself PA } else + { + //Test just sending it straight on since I think I've figured out the STDIN and RTL for Stereo + pa_simple_write(opts->pulse_digi_dev_out, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2), NULL); //Yay! It works. + state->audio_out_idx = 0; + } //most likely don't need this seperation anymore with L and R, just push it out without any condional checks /* @@ -404,9 +411,7 @@ playSynthesizedVoice (dsd_opts * opts, dsd_state * state) state->audio_out_idx = 0; } */ - //Test just sending it straight on since I think I've figured out the STDIN and RTL for Stereo - pa_simple_write(opts->pulse_digi_dev_out, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2), NULL); //Yay! It works. - state->audio_out_idx = 0; + } @@ -434,6 +439,10 @@ playSynthesizedVoiceR (dsd_opts * opts, dsd_state * state) //go F yourself PA } else + { + pa_simple_write(opts->pulse_digi_dev_outR, (state->audio_out_buf_pR - state->audio_out_idxR), (state->audio_out_idxR * 2), NULL); //Yay! It works. + state->audio_out_idxR = 0; + } /* //most likely don't need this seperation anymore with L and R, just push it out without any condional checks if(opts->dmr_stereo == 1) //state->currentslot == 1 && opts->audio_in_type != 3 && opts->dmr_stereo == 1 @@ -442,8 +451,7 @@ playSynthesizedVoiceR (dsd_opts * opts, dsd_state * state) state->audio_out_idxR = 0; } */ - pa_simple_write(opts->pulse_digi_dev_outR, (state->audio_out_buf_pR - state->audio_out_idxR), (state->audio_out_idxR * 2), NULL); //Yay! It works. - state->audio_out_idxR = 0; + } if (state->audio_out_idx2R >= 800000) diff --git a/src/dsd_main.c b/src/dsd_main.c index 6517858..e183c86 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -218,6 +218,7 @@ initOpts (dsd_opts * opts) opts->inverted_dpmr = 0; opts->dmr_stereo = 0; opts->aggressive_framesync = 1; //more aggressive to combat wonk wonk voice decoding + //opts->audio_in_type = 0; } void @@ -489,7 +490,7 @@ usage () fprintf (stderr," May Cause Skipping or sync issues if bad signal/errors\n"); fprintf (stderr," -F Enable DMR TDMA Stereo Passive Frame Sync\n"); fprintf (stderr," This feature will attempt to resync less often due to excessive voice errors\n"); - fprintf (stderr," Use if skipping occurs, but may cuase wonky audio due to loss of good sync\n"); + fprintf (stderr," Use if skipping occurs, but may cause wonky audio due to loss of good sync\n"); fprintf (stderr," -Z Log MBE Payload to console\n"); fprintf (stderr,"\n"); fprintf (stderr,"Report bugs to: https://github.com/lwvmobile/dsd-fme/issues \n"); @@ -500,10 +501,11 @@ void liveScanner (dsd_opts * opts, dsd_state * state) { -//not sure this section is needed now that I've worked out the issue, wasn't upsampling due to split == 1 +//still need this section mostly due the the crackling on the rtl dongle when upsampled +//probably need to dig a little deeper, maybe inlvl releated? if (opts->audio_in_type == 1) { - opts->pulse_digi_rate_out = 48000; + opts->pulse_digi_rate_out = 48000; //change to 48K/1 for STDIN input opts->pulse_digi_out_channels = 1; if (opts->dmr_stereo == 1) { @@ -533,13 +535,14 @@ if (opts->audio_in_type == 1) #ifdef USE_RTLSDR if(opts->audio_in_type == 3) { - //not sure this section is needed now that I've worked out the issue, wasn't upsampling due to split == 1 - opts->pulse_digi_rate_out = 48000; //rtl needs 8000 and 1 channel is mono system + //still need this section mostly due the the crackling on the rtl dongle when upsampled + //probably need to dig a little deeper, maybe inlvl releated? + opts->pulse_digi_rate_out = 8000; //revert to 8K/1 for RTL input, random crackling otherwise opts->pulse_digi_out_channels = 1; if (opts->dmr_stereo == 1) { - opts->pulse_digi_rate_out = 24000; //rtl needs 4000 by 2 channel for DMR TDMA Stereo output - opts->pulse_digi_out_channels = 2; + opts->pulse_digi_rate_out = 24000; //rtl needs 24000 by 2 channel for DMR TDMA Stereo output + opts->pulse_digi_out_channels = 2; //minimal crackling 'may' be observed, not sure, can't test to see on DMR with RTL fprintf (stderr, "RTL Audio Rate Out set to 24000 Khz/2 Channel \n"); } else fprintf (stderr, "RTL Audio Rate Out set to 48000 Khz/1 Channel \n"); @@ -1323,7 +1326,8 @@ main (int argc, char **argv) if (opts.playfiles == 1) { - opts.pulse_digi_rate_out = 8000; //need set to 8000 for amb/imb playback, upsamling seems to cause random crackles + //need set to 8000/1 for amb/imb playback, upsampling seems to cause random crackling + opts.pulse_digi_rate_out = 8000; opts.pulse_digi_out_channels = 1; openPulseOutput(&opts); //need to open it up for output playMbeFiles (&opts, &state, argc, argv);