diff options
author | Paul B Mahol <onemda@gmail.com> | 2022-03-18 10:38:15 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2022-03-18 11:24:44 +0100 |
commit | 28447a4290e2a0c653f985e5d66181bffc372b06 (patch) | |
tree | 762416c5596dc990e52c5135808d4dd8e37aaef4 | |
parent | ef8283fe1c95f80e65f7a87b7fe0641bb5aa7e76 (diff) | |
download | ffmpeg-28447a4290e2a0c653f985e5d66181bffc372b06.tar.gz |
avfilter/af_afftdn: refactor set_noise_profile()
-rw-r--r-- | libavfilter/af_afftdn.c | 65 |
1 files changed, 23 insertions, 42 deletions
diff --git a/libavfilter/af_afftdn.c b/libavfilter/af_afftdn.c index d6154f3fbd..75895fa3d9 100644 --- a/libavfilter/af_afftdn.c +++ b/libavfilter/af_afftdn.c @@ -912,58 +912,39 @@ static void finish_sample_noise(AudioFFTDeNoiseContext *s, static void set_noise_profile(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, - double *sample_noise, - int new_profile) + double *sample_noise) { double new_band_noise[NB_PROFILE_BANDS]; double temp[NB_PROFILE_BANDS]; - double sum = 0.0, d1; - float new_noise_floor; - int i = 0, n; + double sum = 0.0; for (int m = 0; m < NB_PROFILE_BANDS; m++) temp[m] = sample_noise[m]; - if (new_profile) { - for (int m = 0; m < SOLVE_SIZE; m++) { - sum = 0.0; - for (n = 0; n < NB_PROFILE_BANDS; n++) - sum += s->matrix_b[i++] * temp[n]; - s->vector_b[m] = sum; - } - solve(s->matrix_a, s->vector_b, SOLVE_SIZE); - i = 0; - for (int m = 0; m < NB_PROFILE_BANDS; m++) { - sum = 0.0; - for (n = 0; n < SOLVE_SIZE; n++) - sum += s->matrix_c[i++] * s->vector_b[n]; - temp[m] = sum; - } + for (int m = 0, i = 0; m < SOLVE_SIZE; m++) { + sum = 0.0; + for (int n = 0; n < NB_PROFILE_BANDS; n++) + sum += s->matrix_b[i++] * temp[n]; + s->vector_b[m] = sum; + } + solve(s->matrix_a, s->vector_b, SOLVE_SIZE); + for (int m = 0, i = 0; m < NB_PROFILE_BANDS; m++) { + sum = 0.0; + for (int n = 0; n < SOLVE_SIZE; n++) + sum += s->matrix_c[i++] * s->vector_b[n]; + temp[m] = sum; } - sum = 0.0; - for (int m = 0; m < NB_PROFILE_BANDS; m++) - sum += temp[m]; - - d1 = sum / NB_PROFILE_BANDS; - for (int m = 0; m < NB_PROFILE_BANDS; m++) - temp[m] -= d1; - - new_noise_floor = d1; + reduce_mean(temp); - if (new_profile) { - av_log(s, AV_LOG_INFO, "bn="); - for (int m = 0; m < NB_PROFILE_BANDS; m++) { - new_band_noise[m] = temp[m]; - new_band_noise[m] = av_clipd(new_band_noise[m], -24.0, 24.0); - av_log(s, AV_LOG_INFO, "%f ", new_band_noise[m]); - } - av_log(s, AV_LOG_INFO, "\n"); - memcpy(dnch->band_noise, new_band_noise, sizeof(new_band_noise)); + av_log(s, AV_LOG_INFO, "bn="); + for (int m = 0; m < NB_PROFILE_BANDS; m++) { + new_band_noise[m] = temp[m]; + new_band_noise[m] = av_clipd(new_band_noise[m], -24.0, 24.0); + av_log(s, AV_LOG_INFO, "%f ", new_band_noise[m]); } - - if (s->track_noise) - dnch->noise_floor = new_noise_floor; + av_log(s, AV_LOG_INFO, "\n"); + memcpy(dnch->band_noise, new_band_noise, sizeof(new_band_noise)); } static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) @@ -1074,7 +1055,7 @@ static int output_frame(AVFilterLink *inlink, AVFrame *in) double sample_noise[NB_PROFILE_BANDS]; finish_sample_noise(s, dnch, sample_noise); - set_noise_profile(s, dnch, sample_noise, 1); + set_noise_profile(s, dnch, sample_noise); set_parameters(s, dnch, 1, 1); } s->sample_noise = 0; |