mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-12 08:47:24 -05:00
Make Analog Auto Gain Control Mostly Tolerable;
This commit is contained in:
@@ -544,6 +544,7 @@ typedef struct
|
||||
char slot0light[8];
|
||||
float aout_gain;
|
||||
float aout_gainR;
|
||||
float aout_gainA;
|
||||
float aout_max_buf[200];
|
||||
float aout_max_bufR[200];
|
||||
float *aout_max_buf_p;
|
||||
|
||||
@@ -1352,58 +1352,47 @@ void agf (dsd_opts * opts, dsd_state * state, float samp[160], int slot)
|
||||
//automatic gain short mono for analog audio and some digital mono (WIP)
|
||||
void agsm (dsd_opts * opts, dsd_state * state, short * input, int len)
|
||||
{
|
||||
int i, j;
|
||||
int i;
|
||||
|
||||
UNUSED(state);
|
||||
UNUSED(opts);
|
||||
|
||||
//NOTE: This seems to be doing better now that I got it worked out properly
|
||||
//This may produce a mild buzz sound though on the low end
|
||||
|
||||
float avg = 0.0f; //average of 20 samples
|
||||
float coeff = 0.0f; //gain coeffiecient
|
||||
float max = 0.0f; //the highest sample value
|
||||
float nom = 1500.0f; //nominator value
|
||||
float gain = (25.0f / opts->audio_gain); UNUSED(gain);
|
||||
float nom = 4800.0f; //nominator value for 48k
|
||||
float samp[960]; memset (samp, 0.0f, 960*sizeof(float));
|
||||
|
||||
//assign internal float from short input
|
||||
for (i = 0; i < len; i++)
|
||||
samp[i] = (float)input[i];
|
||||
|
||||
// gain = 2.5f;
|
||||
// for (i = 0; i < len; i++)
|
||||
// samp[i] *= gain;
|
||||
|
||||
for (j = 0; j < len/20; j++)
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
|
||||
for (i = 0; i < 20; i++)
|
||||
if ( fabsf (samp[i]) > max)
|
||||
{
|
||||
if ( fabsf (samp[(j*20)+i]) > max)
|
||||
{
|
||||
max = fabsf (samp[(j*20)+i]);
|
||||
}
|
||||
max = fabsf (samp[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 20; i++)
|
||||
avg += (float)samp[(j*20)+i];
|
||||
for (i = 0; i < len; i++)
|
||||
avg += (float)samp[i];
|
||||
|
||||
avg /= 20;
|
||||
avg /= (float)len;
|
||||
|
||||
coeff = fabsf (nom / max);
|
||||
|
||||
//keep coefficient with tolerable range when silence to prevent crackle/buzz
|
||||
if (coeff > 3.0f) coeff = 3.0f;
|
||||
|
||||
//apply the coefficient to bring the max value to our desired maximum value
|
||||
for (i = 0; i < 20; i++)
|
||||
samp[i] *= coeff;
|
||||
|
||||
coeff = fabsf (nom / max);
|
||||
|
||||
|
||||
//apply the coefficient to bring the max value to our desired maximum value
|
||||
for (i = 0; i < 20; i++)
|
||||
{
|
||||
if ( fabsf (samp[(j*20)+i]) > 110.0f) //try not to apply to near zero values
|
||||
samp[(j*20)+i] *= coeff;
|
||||
}
|
||||
|
||||
//debug
|
||||
// fprintf (stderr, "\n M: %f; C: %f; A: %f; ", max, coeff, avg);
|
||||
|
||||
max = 0; //reset
|
||||
avg = 0; //reset
|
||||
|
||||
} //end j loop
|
||||
//debug
|
||||
// fprintf (stderr, "\n M: %f; C: %f; A: %f; ", max, coeff, avg);
|
||||
|
||||
// debug
|
||||
// for (i = 0; i < len; i++)
|
||||
@@ -1416,6 +1405,8 @@ void agsm (dsd_opts * opts, dsd_state * state, short * input, int len)
|
||||
for (i = 0; i < len; i++)
|
||||
input[i] = (short)samp[i];
|
||||
|
||||
state->aout_gainA = coeff; //store for internal use
|
||||
|
||||
}
|
||||
|
||||
//until analog agc is fixed, going to use a manual gain control on this
|
||||
|
||||
@@ -907,6 +907,7 @@ initState (dsd_state * state)
|
||||
sprintf (state->slot2light, "%s", "");
|
||||
state->aout_gain = 25.0f;
|
||||
state->aout_gainR = 25.0f;
|
||||
state->aout_gainA = 0.0f; //use purely as a display or internal value, no user setting
|
||||
memset (state->aout_max_buf, 0, sizeof (float) * 200);
|
||||
state->aout_max_buf_p = state->aout_max_buf;
|
||||
state->aout_max_buf_idx = 0;
|
||||
|
||||
@@ -2403,7 +2403,9 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
|
||||
|
||||
if ( opts->audio_out_type == 0 && (opts->frame_provoice == 1 || opts->monitor_input_audio == 1) )
|
||||
{
|
||||
printw ("| Pulse Analog Output: %i kHz; %i Ch; G: %02.0f%% (/|*) Manual ", opts->pulse_raw_rate_out/1000, opts->pulse_raw_out_channels, opts->audio_gainA);
|
||||
printw ("| Pulse Analog Output: %i kHz; %i Ch; G: %02.0f%% (/|*) ", opts->pulse_raw_rate_out/1000, opts->pulse_raw_out_channels, opts->audio_gainA);
|
||||
if (opts->audio_gainA == 0.0f) printw ("Auto ");
|
||||
else printw ("Manual ");
|
||||
if (opts->audio_in_type != 3) printw ("RMS: %04ld; ", opts->rtl_rms);
|
||||
if (opts->use_lpf == 1) printw ("F: |LP|"); else printw ("F: | |");
|
||||
if (opts->use_hpf == 1) printw ("HP|"); else printw (" |");
|
||||
|
||||
Reference in New Issue
Block a user