From 32d4c0ed72b91adcb7f61d27b72cf871a53e258f Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Tue, 25 Jul 2023 13:10:19 -0400 Subject: [PATCH] AGF by Left/Right Channel/Slot; --- src/dsd_audio2.c | 63 ++++++++++++++++++++++++++++------------------- src/dsd_main.c | 1 + src/dsd_ncurses.c | 16 ++++++------ 3 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/dsd_audio2.c b/src/dsd_audio2.c index 07f7d52..6a664a9 100644 --- a/src/dsd_audio2.c +++ b/src/dsd_audio2.c @@ -1,19 +1,21 @@ #include "dsd.h" -void agf (dsd_opts * opts, dsd_state * state, float samp[160]) +void agf (dsd_opts * opts, dsd_state * state, float samp[160], int slot) { int i, run; run = 1; float empty[160]; memset (empty, 0.1f, sizeof(empty)); - if(opts->pulse_digi_out_channels == 2){}; //compiler warning garbo - float max = 0.0f; float mmax = 0.75f; float mmin = -0.75f; float df; //decimation value - df = (384.0f / (float)opts->pulse_digi_out_channels) * (50.0f - state->aout_gain); + + if (slot == 0) + df = (384.0f / (float)opts->pulse_digi_out_channels) * (50.0f - state->aout_gain); + if (slot == 1) + df = (384.0f / (float)opts->pulse_digi_out_channels) * (50.0f - state->aout_gainR); //this comparison is to determine whether or not to run gain on 'empty' samples (2v last 2, silent frames, etc) if (memcmp(empty, samp, sizeof(empty)) == 0) run = 0; @@ -27,17 +29,28 @@ void agf (dsd_opts * opts, dsd_state * state, float samp[160]) if (samp[i] > mmax) samp[i] = mmax; if (samp[i] < mmin) - samp[i] = mmin; //this could have been an issue before "-mmin"? + samp[i] = mmin; - //max value + //determine max value for adjustments if (fabs(samp[i]) > max) max = samp[i]; + } //crude auto gain for float values - if (max < 0.351f && max > 0.1f && state->aout_gain < 42) state->aout_gain += 0.33f; //state->aout_gain++; - if (max > 0.35f && state->aout_gain > 1) state->aout_gain -= 0.33f; //state->aout_gain--; + if (slot == 0) + { + if (max < 0.351f && max > 0.1f && state->aout_gain < 42) state->aout_gain += 0.33f; //state->aout_gain++; + if (max > 0.35f && state->aout_gain > 1) state->aout_gain -= 0.33f; //state->aout_gain--; + } + + if (slot == 1) + { + if (max < 0.351f && max > 0.1f && state->aout_gainR < 42) state->aout_gainR += 0.33f; //state->aout_gain++; + if (max > 0.35f && state->aout_gainR > 1) state->aout_gainR -= 0.33f; //state->aout_gain--; + } + AGF_END: ; //do nothing @@ -107,12 +120,12 @@ void playSynthesizedVoiceFS3 (dsd_opts * opts, dsd_state * state) //TODO: add option to bypass enc with a toggle as well //run autogain on the f_ buffers - agf (opts, state, state->f_l4[0]); - agf (opts, state, state->f_r4[0]); - agf (opts, state, state->f_l4[1]); - agf (opts, state, state->f_r4[1]); - agf (opts, state, state->f_l4[2]); - agf (opts, state, state->f_r4[2]); + agf (opts, state, state->f_l4[0],0); + agf (opts, state, state->f_r4[0],1); + agf (opts, state, state->f_l4[1],0); + agf (opts, state, state->f_r4[1],1); + agf (opts, state, state->f_l4[2],0); + agf (opts, state, state->f_r4[2],1); //interleave left and right channels from the temp (float) buffer with makeshift 'volume' decimation for (i = 0; i < 160; i++) @@ -428,15 +441,15 @@ void playSynthesizedVoiceFS4 (dsd_opts * opts, dsd_state * state) memset (empty, 0.1f, sizeof(empty)); //run autogain on the f_ buffers - agf (opts, state, state->f_l4[0]); - agf (opts, state, state->f_r4[0]); - agf (opts, state, state->f_l4[1]); - agf (opts, state, state->f_r4[1]); - agf (opts, state, state->f_l4[2]); //doing 2 and 3 here will break the memcmp below, so we also do it on empty - agf (opts, state, state->f_r4[2]); - agf (opts, state, state->f_l4[3]); - agf (opts, state, state->f_r4[3]); - agf (opts, state, empty); //running empty may cause auto gain control issues, and also any auto gain applied here will invalidate the memcmp + agf (opts, state, state->f_l4[0],0); + agf (opts, state, state->f_r4[0],1); + agf (opts, state, state->f_l4[1],0); + agf (opts, state, state->f_r4[1],1); + agf (opts, state, state->f_l4[2],0); //doing 2 and 3 here will break the memcmp below, so we also do it on empty + agf (opts, state, state->f_r4[2],1); + agf (opts, state, state->f_l4[3],0); + agf (opts, state, state->f_r4[3],1); + agf (opts, state, empty,2); //running empty may cause auto gain control issues, and also any auto gain applied here will invalidate the memcmp //interleave left and right channels from the temp (float) buffer with makeshift 'volume' decimation for (i = 0; i < 160; i++) @@ -735,7 +748,7 @@ void playSynthesizedVoiceFS (dsd_opts * opts, dsd_state * state) //TODO: add option to bypass enc with a toggle as well //run autogain on the f_ buffers - agf (opts, state, state->f_l); + agf (opts, state, state->f_l,0); //at this point, if both channels are still flagged as enc, then we can skip all playback/writing functions if (encL) @@ -800,7 +813,7 @@ void playSynthesizedVoiceFS (dsd_opts * opts, dsd_state * state) void playSynthesizedVoiceFM (dsd_opts * opts, dsd_state * state) { - agf(opts, state, state->f_l); + agf(opts, state, state->f_l,0); if (opts->audio_out_type == 0) pa_simple_write(opts->pulse_digi_dev_out, state->f_l, 160*4, NULL); diff --git a/src/dsd_main.c b/src/dsd_main.c index 53ee89b..cb04f3b 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -1586,6 +1586,7 @@ main (int argc, char **argv) opts.floating_point = 1; //enable floating point audio output opts.audio_gain = 0; state.aout_gain = 25.0f; //seems like a nonimal value for float during testing anyways + state.aout_gainR = 25.0f; //seems like a nonimal value for float during testing anyways fprintf (stderr,"Enabling Experimental Floating Point Audio Output\n"); break; diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c index 5c00115..4ba4f26 100644 --- a/src/dsd_ncurses.c +++ b/src/dsd_ncurses.c @@ -2303,17 +2303,18 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) printw (" Gain: AGC;"); else printw (" Gain: %idB;", opts->rtl_gain_value); - printw (" PPM: %i;", opts->rtlsdr_ppm_error); - printw (" SQ: %i;", opts->rtl_squelch_level); - printw (" RMS: %04i;", opts->rtl_rms); - printw (" BW: %i kHz;", opts->rtl_bandwidth); - printw (" FRQ: %i;", opts->rtlsdr_center_freq); + printw (" PPM: %i;", opts->rtlsdr_ppm_error); + printw (" SQ: %i;", opts->rtl_squelch_level); + printw (" RMS: %04i;", opts->rtl_rms); + printw (" BW: %i kHz;", opts->rtl_bandwidth); + printw (" FRQ: %i;", opts->rtlsdr_center_freq); if (opts->rtl_udp_port != 0) printw ("\n| External Tuning on UDP Port: %i", opts->rtl_udp_port); printw ("\n"); } if (opts->audio_out_type == 0) { - printw ("| Pulse Audio Output: %i kHz; %i Channel; Auto Gain: %.1f;", opts->pulse_digi_rate_out/1000, opts->pulse_digi_out_channels, state->aout_gain*2); + printw ("| Pulse Audio Output: %i kHz; %i Channel; G: %.1f%%;", opts->pulse_digi_rate_out/1000, opts->pulse_digi_out_channels, state->aout_gain*2); + if (opts->pulse_digi_out_channels == 2) printw (" G: %.1f%%;", state->aout_gainR*2); if (state->audio_smoothing == 1 && opts->floating_point == 0) printw (" Smoothing On;"); //only on short if (opts->floating_point == 1) printw (" Floating Point;"); @@ -2321,7 +2322,8 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) } if (opts->audio_out_type == 5) { - printw ("| OSS Audio Output: %i kHz; %d Channel; Auto Gain %.1f;", SAMPLE_RATE_OUT/1000, opts->pulse_digi_out_channels, state->aout_gain*2); + printw ("| Pulse Audio Output: %i kHz; %i Channel; G: %.1f%%;", opts->pulse_digi_rate_out/1000, opts->pulse_digi_out_channels, state->aout_gain*2); + if (opts->pulse_digi_out_channels == 2) printw (" G: %.1f%%;", state->aout_gainR*2); if (state->audio_smoothing == 1 && opts->floating_point == 0) printw (" Smoothing On;"); //nly on short if (opts->floating_point == 1) printw (" Floating Point;"); printw (" \n");