History

avfilter/af_afftdn: switch to TX FFT from avutil

Paul B Mahol committed 5 years ago

Commit 925d41e1 parent 51c22f62 files · +47 −45Browse files

Unified · Split

2 files
  1. configure +0 −3
  2. libavfilter/af_afftdn.c +47 −42
configure+0−3
@@ -3542,8 +3542,6 @@ libzmq_protocol_deps="libzmq" · 3541 unmodified lines
35423542 libzmq_protocol_select="network"
35433543
35443544 # filters
3545−afftdn_filter_deps="avcodec"
3546−afftdn_filter_select="fft"
35473545 afftfilt_filter_deps="avcodec"
35483546 afftfilt_filter_select="fft"
35493547 afir_filter_deps="avcodec"
@@ -7261,7 +7259,6 @@ done · 3711 unmodified lines
72617259 enabled zlib && add_cppflags -DZLIB_CONST
72627260
72637261 # conditional library dependencies, in any order
7264−enabled afftdn_filter && prepend avfilter_deps "avcodec"
72657262 enabled afftfilt_filter && prepend avfilter_deps "avcodec"
72667263 enabled afir_filter && prepend avfilter_deps "avcodec"
72677264 enabled amovie_filter && prepend avfilter_deps "avformat avcodec"
libavfilter/af_afftdn.c+47−42
@@ -24,7 +24,7 @@ · 23 unmodified lines
2424 #include "libavutil/avstring.h"
2525 #include "libavutil/channel_layout.h"
2626 #include "libavutil/opt.h"
27−#include "libavcodec/avfft.h"
27+#include "libavutil/tx.h"
2828 #include "avfilter.h"
2929 #include "audio.h"
3030 #include "formats.h"
@@ -66,8 +66,10 @@ typedef struct DeNoiseChannel { · 35 unmodified lines
6666 double *abs_var;
6767 double *rel_var;
6868 double *min_abs_var;
69− FFTComplex *fft_data;
70− FFTContext *fft, *ifft;
69+ AVComplexFloat *fft_in;
70+ AVComplexFloat *fft_out;
71+ AVTXContext *fft, *ifft;
72+ av_tx_fn tx_fn, itx_fn;
7173
7274 double noise_band_norm[15];
7375 double noise_band_avr[15];
@@ -290,7 +292,7 @@ static double limit_gain(double a, double b) · 216 unmodified lines
290292 }
291293
292294 static void process_frame(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch,
293− FFTComplex *fft_data,
295+ AVComplexFloat *fft_data,
294296 double *prior, double *prior_band_excit, int track_noise)
295297 {
296298 double d1, d2, d3, gain;
@@ -612,7 +614,7 @@ static int config_input(AVFilterLink *inlink) · 315 unmodified lines
612614 AVFilterContext *ctx = inlink->dst;
613615 AudioFFTDeNoiseContext *s = ctx->priv;
614616 double wscale, sar, sum, sdiv;
615− int i, j, k, m, n;
617+ int i, j, k, m, n, ret;
616618
617619 s->dnch = av_calloc(inlink->channels, sizeof(*s->dnch));
618620 if (!s->dnch)
@@ -680,6 +682,7 @@ static int config_input(AVFilterLink *inlink) · 61 unmodified lines
680682
681683 for (int ch = 0; ch < inlink->channels; ch++) {
682684 DeNoiseChannel *dnch = &s->dnch[ch];
685+ float scale;
683686
684687 switch (s->noise_type) {
685688 case WHITE_NOISE:
@@ -727,9 +730,14 @@ static int config_input(AVFilterLink *inlink) · 41 unmodified lines
727730 dnch->abs_var = av_calloc(s->bin_count, sizeof(*dnch->abs_var));
728731 dnch->rel_var = av_calloc(s->bin_count, sizeof(*dnch->rel_var));
729732 dnch->min_abs_var = av_calloc(s->bin_count, sizeof(*dnch->min_abs_var));
730− dnch->fft_data = av_calloc(s->fft_length2 + 1, sizeof(*dnch->fft_data));
731− dnch->fft = av_fft_init(av_log2(s->fft_length2), 0);
732− dnch->ifft = av_fft_init(av_log2(s->fft_length2), 1);
733+ dnch->fft_in = av_calloc(s->fft_length2 + 1, sizeof(*dnch->fft_in));
734+ dnch->fft_out = av_calloc(s->fft_length2 + 1, sizeof(*dnch->fft_out));
735+ ret = av_tx_init(&dnch->fft, &dnch->tx_fn, AV_TX_FLOAT_FFT, 0, s->fft_length2, &scale, 0);
736+ if (ret < 0)
737+ return ret;
738+ ret = av_tx_init(&dnch->ifft, &dnch->itx_fn, AV_TX_FLOAT_FFT, 1, s->fft_length2, &scale, 0);
739+ if (ret < 0)
740+ return ret;
733741 dnch->spread_function = av_calloc(s->number_of_bands * s->number_of_bands,
734742 sizeof(*dnch->spread_function));
735743
@@ -742,7 +750,8 @@ static int config_input(AVFilterLink *inlink) · 6 unmodified lines
742750 !dnch->clean_data ||
743751 !dnch->noisy_data ||
744752 !dnch->out_samples ||
745− !dnch->fft_data ||
753+ !dnch->fft_in ||
754+ !dnch->fft_out ||
746755 !dnch->abs_var ||
747756 !dnch->rel_var ||
748757 !dnch->min_abs_var ||
@@ -855,7 +864,7 @@ static int config_input(AVFilterLink *inlink) · 106 unmodified lines
855864 return 0;
856865 }
857866
858−static void preprocess(FFTComplex *in, int len)
867+static void preprocess(AVComplexFloat *in, int len)
859868 {
860869 double d1, d2, d3, d4, d5, d6, d7, d8, d9, d10;
861870 int n, i, k;
@@ -888,7 +897,7 @@ static void preprocess(FFTComplex *in, int len) · 26 unmodified lines
888897 in[0].im = d2 - in[0].im;
889898 }
890899
891−static void postprocess(FFTComplex *in, int len)
900+static void postprocess(AVComplexFloat *in, int len)
892901 {
893902 double d1, d2, d3, d4, d5, d6, d7, d8, d9, d10;
894903 int n, i, k;
@@ -938,28 +947,27 @@ static void sample_noise_block(AudioFFTDeNoiseContext *s, · 43 unmodified lines
938947 int edge, j, k, n, edgemax;
939948
940949 for (int i = 0; i < s->window_length; i++) {
941− dnch->fft_data[i].re = s->window[i] * src[i] * (1LL << 24);
942− dnch->fft_data[i].im = 0.0;
950+ dnch->fft_in[i].re = s->window[i] * src[i] * (1LL << 24);
951+ dnch->fft_in[i].im = 0.0;
943952 }
944953
945954 for (int i = s->window_length; i < s->fft_length2; i++) {
946− dnch->fft_data[i].re = 0.0;
947− dnch->fft_data[i].im = 0.0;
955+ dnch->fft_in[i].re = 0.0;
956+ dnch->fft_in[i].im = 0.0;
948957 }
949958
950− av_fft_permute(dnch->fft, dnch->fft_data);
951− av_fft_calc(dnch->fft, dnch->fft_data);
959+ dnch->tx_fn(dnch->fft, dnch->fft_out, dnch->fft_in, sizeof(float));
952960
953− preprocess(dnch->fft_data, s->fft_length);
961+ preprocess(dnch->fft_out, s->fft_length);
954962
955963 edge = s->noise_band_edge[0];
956964 j = edge;
957965 k = 0;
958966 n = j;
959967 edgemax = fmin(s->fft_length2, s->noise_band_edge[15]);
960− dnch->fft_data[s->fft_length2].re = dnch->fft_data[0].im;
961− dnch->fft_data[0].im = 0.0;
962− dnch->fft_data[s->fft_length2].im = 0.0;
968+ dnch->fft_out[s->fft_length2].re = dnch->fft_out[0].im;
969+ dnch->fft_out[0].im = 0.0;
970+ dnch->fft_out[s->fft_length2].im = 0.0;
963971
964972 for (int i = j; i <= edgemax; i++) {
965973 if ((i == j) && (i < edgemax)) {
@@ -979,10 +987,10 @@ static void sample_noise_block(AudioFFTDeNoiseContext *s, · 13 unmodified lines
979987 avr = 0.0;
980988 avi = 0.0;
981989 }
982− avr += dnch->fft_data[n].re;
983− avi += dnch->fft_data[n].im;
984− mag2 = dnch->fft_data[n].re * dnch->fft_data[n].re +
985− dnch->fft_data[n].im * dnch->fft_data[n].im;
990+ avr += dnch->fft_out[n].re;
991+ avi += dnch->fft_out[n].im;
992+ mag2 = dnch->fft_out[n].re * dnch->fft_out[n].re +
993+ dnch->fft_out[n].im * dnch->fft_out[n].im;
986994
987995 mag2 = fmax(mag2, s->sample_floor);
988996
@@ -1107,30 +1115,28 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_job · 118 unmodified lines
11071115 }
11081116
11091117 for (int m = 0; m < s->window_length; m++) {
1110− dnch->fft_data[m].re = s->window[m] * src[m] * (1LL << 24);
1111− dnch->fft_data[m].im = 0;
1118+ dnch->fft_in[m].re = s->window[m] * src[m] * (1LL << 24);
1119+ dnch->fft_in[m].im = 0;
11121120 }
11131121
11141122 for (int m = s->window_length; m < s->fft_length2; m++) {
1115− dnch->fft_data[m].re = 0;
1116− dnch->fft_data[m].im = 0;
1123+ dnch->fft_in[m].re = 0;
1124+ dnch->fft_in[m].im = 0;
11171125 }
11181126
1119− av_fft_permute(dnch->fft, dnch->fft_data);
1120− av_fft_calc(dnch->fft, dnch->fft_data);
1127+ dnch->tx_fn(dnch->fft, dnch->fft_out, dnch->fft_in, sizeof(float));
11211128
1122− preprocess(dnch->fft_data, s->fft_length);
1123− process_frame(s, dnch, dnch->fft_data,
1129+ preprocess(dnch->fft_out, s->fft_length);
1130+ process_frame(s, dnch, dnch->fft_out,
11241131 dnch->prior,
11251132 dnch->prior_band_excit,
11261133 s->track_noise);
1127− postprocess(dnch->fft_data, s->fft_length);
1134+ postprocess(dnch->fft_out, s->fft_length);
11281135
1129− av_fft_permute(dnch->ifft, dnch->fft_data);
1130− av_fft_calc(dnch->ifft, dnch->fft_data);
1136+ dnch->itx_fn(dnch->ifft, dnch->fft_in, dnch->fft_out, sizeof(float));
11311137
11321138 for (int m = 0; m < s->window_length; m++)
1133− dst[m] += s->window[m] * dnch->fft_data[m].re / (1LL << 24);
1139+ dst[m] += s->window[m] * dnch->fft_in[m].re / (1LL << 24);
11341140 }
11351141
11361142 return 0;
@@ -1330,11 +1336,10 @@ static av_cold void uninit(AVFilterContext *ctx) · 193 unmodified lines
13301336 av_freep(&dnch->abs_var);
13311337 av_freep(&dnch->rel_var);
13321338 av_freep(&dnch->min_abs_var);
1333− av_freep(&dnch->fft_data);
1334− av_fft_end(dnch->fft);
1335− dnch->fft = NULL;
1336− av_fft_end(dnch->ifft);
1337− dnch->ifft = NULL;
1339+ av_freep(&dnch->fft_in);
1340+ av_freep(&dnch->fft_out);
1341+ av_tx_uninit(&dnch->fft);
1342+ av_tx_uninit(&dnch->ifft);
13381343 }
13391344 av_freep(&s->dnch);
13401345 }

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