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

Unified · Split

libavfilter/af_afftdn.c+21−20
@@ -50,7 +50,7 @@ enum NoiseType { · 49 unmodified lines
50};50};
51 51
52typedef struct DeNoiseChannel {52typedef struct DeNoiseChannel {
53 int band_noise[NB_PROFILE_BANDS];53 double band_noise[NB_PROFILE_BANDS];
54 double noise_band_auto_var[NB_PROFILE_BANDS];54 double noise_band_auto_var[NB_PROFILE_BANDS];
55 double noise_band_sample[NB_PROFILE_BANDS];55 double noise_band_sample[NB_PROFILE_BANDS];
56 double *amt;56 double *amt;
@@ -181,9 +181,9 @@ static const AVOption afftdn_options[] = { · 124 unmodified lines
181 181
182AVFILTER_DEFINE_CLASS(afftdn);182AVFILTER_DEFINE_CLASS(afftdn);
183 183
184static int get_band_noise(AudioFFTDeNoiseContext *s,184static double get_band_noise(AudioFFTDeNoiseContext *s,
185 int band, double a,185 int band, double a,
186 double b, double c)186 double b, double c)
187{187{
188 double d1, d2, d3;188 double d1, d2, d3;
189 189
@@ -194,7 +194,7 @@ static int get_band_noise(AudioFFTDeNoiseContext *s, · 4 unmodified lines
194 d3 = s->band_centre[band] / c;194 d3 = s->band_centre[band] / c;
195 d3 = 10.0 * log(1.0 + d3 * d3) / M_LN10;195 d3 = 10.0 * log(1.0 + d3 * d3) / M_LN10;
196 196
197 return lrint(-d1 + d2 - d3);197 return -d1 + d2 - d3;
198}198}
199 199
200static void factor(double *array, int size)200static void factor(double *array, int size)
@@ -230,9 +230,9 @@ static void solve(double *matrix, double *vector, int size) · 29 unmodified lines
230 }230 }
231}231}
232 232
233static int process_get_band_noise(AudioFFTDeNoiseContext *s,233static double process_get_band_noise(AudioFFTDeNoiseContext *s,
234 DeNoiseChannel *dnch,234 DeNoiseChannel *dnch,
235 int band)235 int band)
236{236{
237 double product, sum, f;237 double product, sum, f;
238 int i = 0;238 int i = 0;
@@ -257,7 +257,7 @@ static int process_get_band_noise(AudioFFTDeNoiseContext *s, · 18 unmodified lines
257 product *= f;257 product *= f;
258 }258 }
259 259
260 return lrint(sum);260 return sum;
261}261}
262 262
263static void calculate_sfm(AudioFFTDeNoiseContext *s,263static void calculate_sfm(AudioFFTDeNoiseContext *s,
@@ -537,7 +537,8 @@ static void read_custom_noise(AudioFFTDeNoiseContext *s, int ch) · 273 unmodified lines
537{537{
538 DeNoiseChannel *dnch = &s->dnch[ch];538 DeNoiseChannel *dnch = &s->dnch[ch];
539 char *p, *arg, *saveptr = NULL;539 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;
541 542
542 if (!s->band_noise_str)543 if (!s->band_noise_str)
543 return;544 return;
@@ -546,19 +547,19 @@ static void read_custom_noise(AudioFFTDeNoiseContext *s, int ch) · 2 unmodified lines
546 if (!p)547 if (!p)
547 return;548 return;
548 549
549 for (i = 0; i < NB_PROFILE_BANDS; i++) {550 for (int i = 0; i < NB_PROFILE_BANDS; i++) {
550 if (!(arg = av_strtok(p, "| ", &saveptr)))551 if (!(arg = av_strtok(p, "| ", &saveptr)))
551 break;552 break;
552 553
553 p = NULL;554 p = NULL;
554 555
555 ret = av_sscanf(arg, "%d", &band_noise[i]);556 ret = av_sscanf(arg, "%f", &band_noise[i]);
556 if (ret != 1) {557 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");
558 break;559 break;
559 }560 }
560 561
561 band_noise[i] = av_clip(band_noise[i], -24, 24);562 band_noise[i] = av_clipd(band_noise[i], -24., 24.);
562 }563 }
563 564
564 av_free(p);565 av_free(p);
@@ -594,7 +595,7 @@ static void set_parameters(AudioFFTDeNoiseContext *s) · 29 unmodified lines
594 }595 }
595}596}
596 597
597static void reduce_mean(int *band_noise)598static void reduce_mean(double *band_noise)
598{599{
599 double mean = 0.f;600 double mean = 0.f;
600 601
@@ -683,7 +684,7 @@ static int config_input(AVFilterLink *inlink) · 82 unmodified lines
683 switch (s->noise_type) {684 switch (s->noise_type) {
684 case WHITE_NOISE:685 case WHITE_NOISE:
685 for (i = 0; i < NB_PROFILE_BANDS; i++)686 for (i = 0; i < NB_PROFILE_BANDS; i++)
686 dnch->band_noise[i] = 0;687 dnch->band_noise[i] = 0.;
687 break;688 break;
688 case VINYL_NOISE:689 case VINYL_NOISE:
689 for (i = 0; i < NB_PROFILE_BANDS; i++)690 for (i = 0; i < NB_PROFILE_BANDS; i++)
@@ -956,7 +957,7 @@ static void set_noise_profile(AudioFFTDeNoiseContext *s, · 266 unmodified lines
956 double *sample_noise,957 double *sample_noise,
957 int new_profile)958 int new_profile)
958{959{
959 int new_band_noise[NB_PROFILE_BANDS];960 double new_band_noise[NB_PROFILE_BANDS];
960 double temp[NB_PROFILE_BANDS];961 double temp[NB_PROFILE_BANDS];
961 double sum = 0.0, d1;962 double sum = 0.0, d1;
962 float new_noise_floor;963 float new_noise_floor;
@@ -995,9 +996,9 @@ static void set_noise_profile(AudioFFTDeNoiseContext *s, · 32 unmodified lines
995 if (new_profile) {996 if (new_profile) {
996 av_log(s, AV_LOG_INFO, "bn=");997 av_log(s, AV_LOG_INFO, "bn=");
997 for (int m = 0; m < NB_PROFILE_BANDS; m++) {998 for (int m = 0; m < NB_PROFILE_BANDS; m++) {
998 new_band_noise[m] = lrint(temp[m]);999 new_band_noise[m] = temp[m];
999 new_band_noise[m] = av_clip(new_band_noise[m], -24, 24);1000 new_band_noise[m] = av_clipd(new_band_noise[m], -24.0, 24.0);
1000 av_log(s, AV_LOG_INFO, "%d ", new_band_noise[m]);1001 av_log(s, AV_LOG_INFO, "%f ", new_band_noise[m]);
1001 }1002 }
1002 av_log(s, AV_LOG_INFO, "\n");1003 av_log(s, AV_LOG_INFO, "\n");
1003 memcpy(dnch->band_noise, new_band_noise, sizeof(new_band_noise));1004 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