History

avfilter/af_afftdn: change noise profile to floating point precision

Paul B Mahol committed 4 years ago

Commit 386e5e41 parent 32e99151 file · +21 −20Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_afftdn.c+21−20
@@ -50,7 +50,7 @@ enum NoiseType { · 49 unmodified lines
5050 };
5151
5252 typedef struct DeNoiseChannel {
53− int band_noise[NB_PROFILE_BANDS];
53+ double band_noise[NB_PROFILE_BANDS];
5454 double noise_band_auto_var[NB_PROFILE_BANDS];
5555 double noise_band_sample[NB_PROFILE_BANDS];
5656 double *amt;
@@ -181,9 +181,9 @@ static const AVOption afftdn_options[] = { · 124 unmodified lines
181181
182182 AVFILTER_DEFINE_CLASS(afftdn);
183183
184−static int get_band_noise(AudioFFTDeNoiseContext *s,
185− int band, double a,
186− double b, double c)
184+static double get_band_noise(AudioFFTDeNoiseContext *s,
185+ int band, double a,
186+ double b, double c)
187187 {
188188 double d1, d2, d3;
189189
@@ -194,7 +194,7 @@ static int get_band_noise(AudioFFTDeNoiseContext *s, · 4 unmodified lines
194194 d3 = s->band_centre[band] / c;
195195 d3 = 10.0 * log(1.0 + d3 * d3) / M_LN10;
196196
197− return lrint(-d1 + d2 - d3);
197+ return -d1 + d2 - d3;
198198 }
199199
200200 static void factor(double *array, int size)
@@ -230,9 +230,9 @@ static void solve(double *matrix, double *vector, int size) · 29 unmodified lines
230230 }
231231 }
232232
233−static int process_get_band_noise(AudioFFTDeNoiseContext *s,
234− DeNoiseChannel *dnch,
235− int band)
233+static double process_get_band_noise(AudioFFTDeNoiseContext *s,
234+ DeNoiseChannel *dnch,
235+ int band)
236236 {
237237 double product, sum, f;
238238 int i = 0;
@@ -257,7 +257,7 @@ static int process_get_band_noise(AudioFFTDeNoiseContext *s, · 18 unmodified lines
257257 product *= f;
258258 }
259259
260− return lrint(sum);
260+ return sum;
261261 }
262262
263263 static void calculate_sfm(AudioFFTDeNoiseContext *s,
@@ -537,7 +537,8 @@ static void read_custom_noise(AudioFFTDeNoiseContext *s, int ch) · 273 unmodified lines
537537 {
538538 DeNoiseChannel *dnch = &s->dnch[ch];
539539 char *p, *arg, *saveptr = NULL;
540− int i, ret, band_noise[NB_PROFILE_BANDS] = { 0 };
540+ double band_noise[NB_PROFILE_BANDS] = { 0.f };
541+ int ret;
541542
542543 if (!s->band_noise_str)
543544 return;
@@ -546,19 +547,19 @@ static void read_custom_noise(AudioFFTDeNoiseContext *s, int ch) · 2 unmodified lines
546547 if (!p)
547548 return;
548549
549− for (i = 0; i < NB_PROFILE_BANDS; i++) {
550+ for (int i = 0; i < NB_PROFILE_BANDS; i++) {
550551 if (!(arg = av_strtok(p, "| ", &saveptr)))
551552 break;
552553
553554 p = NULL;
554555
555− ret = av_sscanf(arg, "%d", &band_noise[i]);
556+ ret = av_sscanf(arg, "%f", &band_noise[i]);
556557 if (ret != 1) {
557− av_log(s, AV_LOG_ERROR, "Custom band noise must be integer.\n");
558+ av_log(s, AV_LOG_ERROR, "Custom band noise must be float.\n");
558559 break;
559560 }
560561
561− band_noise[i] = av_clip(band_noise[i], -24, 24);
562+ band_noise[i] = av_clipd(band_noise[i], -24., 24.);
562563 }
563564
564565 av_free(p);
@@ -594,7 +595,7 @@ static void set_parameters(AudioFFTDeNoiseContext *s) · 29 unmodified lines
594595 }
595596 }
596597
597−static void reduce_mean(int *band_noise)
598+static void reduce_mean(double *band_noise)
598599 {
599600 double mean = 0.f;
600601
@@ -683,7 +684,7 @@ static int config_input(AVFilterLink *inlink) · 82 unmodified lines
683684 switch (s->noise_type) {
684685 case WHITE_NOISE:
685686 for (i = 0; i < NB_PROFILE_BANDS; i++)
686− dnch->band_noise[i] = 0;
687+ dnch->band_noise[i] = 0.;
687688 break;
688689 case VINYL_NOISE:
689690 for (i = 0; i < NB_PROFILE_BANDS; i++)
@@ -956,7 +957,7 @@ static void set_noise_profile(AudioFFTDeNoiseContext *s, · 266 unmodified lines
956957 double *sample_noise,
957958 int new_profile)
958959 {
959− int new_band_noise[NB_PROFILE_BANDS];
960+ double new_band_noise[NB_PROFILE_BANDS];
960961 double temp[NB_PROFILE_BANDS];
961962 double sum = 0.0, d1;
962963 float new_noise_floor;
@@ -995,9 +996,9 @@ static void set_noise_profile(AudioFFTDeNoiseContext *s, · 32 unmodified lines
995996 if (new_profile) {
996997 av_log(s, AV_LOG_INFO, "bn=");
997998 for (int m = 0; m < NB_PROFILE_BANDS; m++) {
998− new_band_noise[m] = lrint(temp[m]);
999− new_band_noise[m] = av_clip(new_band_noise[m], -24, 24);
1000− av_log(s, AV_LOG_INFO, "%d ", new_band_noise[m]);
999+ new_band_noise[m] = temp[m];
1000+ new_band_noise[m] = av_clipd(new_band_noise[m], -24.0, 24.0);
1001+ av_log(s, AV_LOG_INFO, "%f ", new_band_noise[m]);
10011002 }
10021003 av_log(s, AV_LOG_INFO, "\n");
10031004 memcpy(dnch->band_noise, new_band_noise, sizeof(new_band_noise));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t