avfilter/af_afftdn: change noise profile to floating point precision

release/5.1
Paul B Mahol 3 years ago
parent 32e99157c2
commit 386e5e4cfc
  1. 33
      libavfilter/af_afftdn.c

@ -50,7 +50,7 @@ enum NoiseType {
}; };
typedef struct DeNoiseChannel { typedef struct DeNoiseChannel {
int band_noise[NB_PROFILE_BANDS]; double band_noise[NB_PROFILE_BANDS];
double noise_band_auto_var[NB_PROFILE_BANDS]; double noise_band_auto_var[NB_PROFILE_BANDS];
double noise_band_sample[NB_PROFILE_BANDS]; double noise_band_sample[NB_PROFILE_BANDS];
double *amt; double *amt;
@ -181,7 +181,7 @@ static const AVOption afftdn_options[] = {
AVFILTER_DEFINE_CLASS(afftdn); AVFILTER_DEFINE_CLASS(afftdn);
static int get_band_noise(AudioFFTDeNoiseContext *s, static double get_band_noise(AudioFFTDeNoiseContext *s,
int band, double a, int band, double a,
double b, double c) double b, double c)
{ {
@ -194,7 +194,7 @@ static int get_band_noise(AudioFFTDeNoiseContext *s,
d3 = s->band_centre[band] / c; d3 = s->band_centre[band] / c;
d3 = 10.0 * log(1.0 + d3 * d3) / M_LN10; d3 = 10.0 * log(1.0 + d3 * d3) / M_LN10;
return lrint(-d1 + d2 - d3); return -d1 + d2 - d3;
} }
static void factor(double *array, int size) static void factor(double *array, int size)
@ -230,7 +230,7 @@ static void solve(double *matrix, double *vector, int size)
} }
} }
static int process_get_band_noise(AudioFFTDeNoiseContext *s, static double process_get_band_noise(AudioFFTDeNoiseContext *s,
DeNoiseChannel *dnch, DeNoiseChannel *dnch,
int band) int band)
{ {
@ -257,7 +257,7 @@ static int process_get_band_noise(AudioFFTDeNoiseContext *s,
product *= f; product *= f;
} }
return lrint(sum); return sum;
} }
static void calculate_sfm(AudioFFTDeNoiseContext *s, static void calculate_sfm(AudioFFTDeNoiseContext *s,
@ -537,7 +537,8 @@ static void read_custom_noise(AudioFFTDeNoiseContext *s, int ch)
{ {
DeNoiseChannel *dnch = &s->dnch[ch]; DeNoiseChannel *dnch = &s->dnch[ch];
char *p, *arg, *saveptr = NULL; char *p, *arg, *saveptr = NULL;
int i, ret, band_noise[NB_PROFILE_BANDS] = { 0 }; double band_noise[NB_PROFILE_BANDS] = { 0.f };
int ret;
if (!s->band_noise_str) if (!s->band_noise_str)
return; return;
@ -546,19 +547,19 @@ static void read_custom_noise(AudioFFTDeNoiseContext *s, int ch)
if (!p) if (!p)
return; return;
for (i = 0; i < NB_PROFILE_BANDS; i++) { for (int i = 0; i < NB_PROFILE_BANDS; i++) {
if (!(arg = av_strtok(p, "| ", &saveptr))) if (!(arg = av_strtok(p, "| ", &saveptr)))
break; break;
p = NULL; p = NULL;
ret = av_sscanf(arg, "%d", &band_noise[i]); ret = av_sscanf(arg, "%f", &band_noise[i]);
if (ret != 1) { if (ret != 1) {
av_log(s, AV_LOG_ERROR, "Custom band noise must be integer.\n"); av_log(s, AV_LOG_ERROR, "Custom band noise must be float.\n");
break; break;
} }
band_noise[i] = av_clip(band_noise[i], -24, 24); band_noise[i] = av_clipd(band_noise[i], -24., 24.);
} }
av_free(p); av_free(p);
@ -594,7 +595,7 @@ static void set_parameters(AudioFFTDeNoiseContext *s)
} }
} }
static void reduce_mean(int *band_noise) static void reduce_mean(double *band_noise)
{ {
double mean = 0.f; double mean = 0.f;
@ -683,7 +684,7 @@ static int config_input(AVFilterLink *inlink)
switch (s->noise_type) { switch (s->noise_type) {
case WHITE_NOISE: case WHITE_NOISE:
for (i = 0; i < NB_PROFILE_BANDS; i++) for (i = 0; i < NB_PROFILE_BANDS; i++)
dnch->band_noise[i] = 0; dnch->band_noise[i] = 0.;
break; break;
case VINYL_NOISE: case VINYL_NOISE:
for (i = 0; i < NB_PROFILE_BANDS; i++) for (i = 0; i < NB_PROFILE_BANDS; i++)
@ -956,7 +957,7 @@ static void set_noise_profile(AudioFFTDeNoiseContext *s,
double *sample_noise, double *sample_noise,
int new_profile) int new_profile)
{ {
int new_band_noise[NB_PROFILE_BANDS]; double new_band_noise[NB_PROFILE_BANDS];
double temp[NB_PROFILE_BANDS]; double temp[NB_PROFILE_BANDS];
double sum = 0.0, d1; double sum = 0.0, d1;
float new_noise_floor; float new_noise_floor;
@ -995,9 +996,9 @@ static void set_noise_profile(AudioFFTDeNoiseContext *s,
if (new_profile) { if (new_profile) {
av_log(s, AV_LOG_INFO, "bn="); av_log(s, AV_LOG_INFO, "bn=");
for (int m = 0; m < NB_PROFILE_BANDS; m++) { for (int m = 0; m < NB_PROFILE_BANDS; m++) {
new_band_noise[m] = lrint(temp[m]); new_band_noise[m] = temp[m];
new_band_noise[m] = av_clip(new_band_noise[m], -24, 24); new_band_noise[m] = av_clipd(new_band_noise[m], -24.0, 24.0);
av_log(s, AV_LOG_INFO, "%d ", new_band_noise[m]); av_log(s, AV_LOG_INFO, "%f ", new_band_noise[m]);
} }
av_log(s, AV_LOG_INFO, "\n"); av_log(s, AV_LOG_INFO, "\n");
memcpy(dnch->band_noise, new_band_noise, sizeof(new_band_noise)); memcpy(dnch->band_noise, new_band_noise, sizeof(new_band_noise));

Loading…
Cancel
Save