History

avfilter/af_afftfilt: switch to TX FFT from avutil

Paul B Mahol committed 5 years ago

Commit a428d2a1 parent 6e66e2c2 files · +51 −43Browse files

Unified · Split

2 files
  1. configure +0 −3
  2. libavfilter/af_afftfilt.c +51 −40
configure+0−3
@@ -3542,8 +3542,6 @@ libzmq_protocol_deps="libzmq" · 3541 unmodified lines
35423542 libzmq_protocol_select="network"
35433543
35443544 # filters
3545−afftfilt_filter_deps="avcodec"
3546−afftfilt_filter_select="fft"
35473545 afir_filter_deps="avcodec"
35483546 afir_filter_select="rdft"
35493547 ametadata_filter_deps="avformat"
@@ -7256,7 +7254,6 @@ done · 3706 unmodified lines
72567254 enabled zlib && add_cppflags -DZLIB_CONST
72577255
72587256 # conditional library dependencies, in any order
7259−enabled afftfilt_filter && prepend avfilter_deps "avcodec"
72607257 enabled afir_filter && prepend avfilter_deps "avcodec"
72617258 enabled amovie_filter && prepend avfilter_deps "avformat avcodec"
72627259 enabled aresample_filter && prepend avfilter_deps "swresample"
libavfilter/af_afftfilt.c+51−40
@@ -23,8 +23,8 @@ · 22 unmodified lines
2323 #include "libavfilter/internal.h"
2424 #include "libavutil/common.h"
2525 #include "libavutil/opt.h"
26−#include "libavcodec/avfft.h"
2726 #include "libavutil/eval.h"
27+#include "libavutil/tx.h"
2828 #include "audio.h"
2929 #include "filters.h"
3030 #include "window_func.h"
@@ -34,11 +34,12 @@ typedef struct AFFTFiltContext { · 3 unmodified lines
3434 char *real_str;
3535 char *img_str;
3636 int fft_size;
37− int fft_bits;
3837
39− FFTContext *fft, *ifft;
40− FFTComplex **fft_data;
41− FFTComplex **fft_temp;
38+ AVTXContext *fft, *ifft;
39+ av_tx_fn tx_fn, itx_fn;
40+ AVComplexFloat **fft_in;
41+ AVComplexFloat **fft_out;
42+ AVComplexFloat **fft_temp;
4243 int nb_exprs;
4344 int channels;
4445 int window_size;
@@ -100,7 +101,7 @@ static inline double getreal(void *priv, double x, double ch) · 55 unmodified lines
100101 ich = av_clip(ch, 0, s->nb_exprs - 1);
101102 ix = av_clip(x, 0, s->window_size / 2);
102103
103− return s->fft_data[ich][ix].re;
104+ return s->fft_out[ich][ix].re;
104105 }
105106
106107 static inline double getimag(void *priv, double x, double ch)
@@ -111,7 +112,7 @@ static inline double getimag(void *priv, double x, double ch) · 4 unmodified lines
111112 ich = av_clip(ch, 0, s->nb_exprs - 1);
112113 ix = av_clip(x, 0, s->window_size / 2);
113114
114− return s->fft_data[ich][ix].im;
115+ return s->fft_out[ich][ix].im;
115116 }
116117
117118 static double realf(void *priv, double x, double ch) { return getreal(priv, x, ch); }
@@ -126,22 +127,28 @@ static int config_input(AVFilterLink *inlink) · 8 unmodified lines
126127 AFFTFiltContext *s = ctx->priv;
127128 char *saveptr = NULL;
128129 int ret = 0, ch;
129− float overlap;
130+ float overlap, scale;
130131 char *args;
131132 const char *last_expr = "1";
132133
133134 s->channels = inlink->channels;
134135 s->pts = AV_NOPTS_VALUE;
135− s->fft_bits = av_log2(s->fft_size);
136− s->fft = av_fft_init(s->fft_bits, 0);
137− s->ifft = av_fft_init(s->fft_bits, 1);
138− if (!s->fft || !s->ifft)
139− return AVERROR(ENOMEM);
136+ ret = av_tx_init(&s->fft, &s->tx_fn, AV_TX_FLOAT_FFT, 0, s->fft_size, &scale, 0);
137+ if (ret < 0)
138+ return ret;
139+
140+ ret = av_tx_init(&s->ifft, &s->itx_fn, AV_TX_FLOAT_FFT, 1, s->fft_size, &scale, 0);
141+ if (ret < 0)
142+ return ret;
140143
141− s->window_size = 1 << s->fft_bits;
144+ s->window_size = s->fft_size;
142145
143− s->fft_data = av_calloc(inlink->channels, sizeof(*s->fft_data));
144− if (!s->fft_data)
146+ s->fft_in = av_calloc(inlink->channels, sizeof(*s->fft_in));
147+ if (!s->fft_in)
148+ return AVERROR(ENOMEM);
149+
150+ s->fft_out = av_calloc(inlink->channels, sizeof(*s->fft_out));
151+ if (!s->fft_out)
145152 return AVERROR(ENOMEM);
146153
147154 s->fft_temp = av_calloc(inlink->channels, sizeof(*s->fft_temp));
@@ -149,12 +156,14 @@ static int config_input(AVFilterLink *inlink) · 1 unmodified line
149156 return AVERROR(ENOMEM);
150157
151158 for (ch = 0; ch < inlink->channels; ch++) {
152− s->fft_data[ch] = av_calloc(s->window_size, sizeof(**s->fft_data));
153− if (!s->fft_data[ch])
159+ s->fft_in[ch] = av_calloc(s->window_size, sizeof(**s->fft_in));
160+ if (!s->fft_in[ch])
161+ return AVERROR(ENOMEM);
162+
163+ s->fft_out[ch] = av_calloc(s->window_size, sizeof(**s->fft_out));
164+ if (!s->fft_out[ch])
154165 return AVERROR(ENOMEM);
155− }
156166
157− for (ch = 0; ch < inlink->channels; ch++) {
158167 s->fft_temp[ch] = av_calloc(s->window_size, sizeof(**s->fft_temp));
159168 if (!s->fft_temp[ch])
160169 return AVERROR(ENOMEM);
@@ -254,16 +263,16 @@ static int filter_frame(AVFilterLink *inlink) · 93 unmodified lines
254263
255264 for (ch = 0; ch < inlink->channels; ch++) {
256265 const float *src = (float *)in->extended_data[ch];
257− FFTComplex *fft_data = s->fft_data[ch];
266+ AVComplexFloat *fft_in = s->fft_in[ch];
258267
259268 for (n = 0; n < in->nb_samples; n++) {
260− fft_data[n].re = src[n] * s->window_func_lut[n];
261− fft_data[n].im = 0;
269+ fft_in[n].re = src[n] * s->window_func_lut[n];
270+ fft_in[n].im = 0;
262271 }
263272
264273 for (; n < window_size; n++) {
265− fft_data[n].re = 0;
266− fft_data[n].im = 0;
274+ fft_in[n].re = 0;
275+ fft_in[n].im = 0;
267276 }
268277 }
269278
@@ -273,15 +282,15 @@ static int filter_frame(AVFilterLink *inlink) · 3 unmodified lines
273282 values[VAR_CHANNELS] = inlink->channels;
274283
275284 for (ch = 0; ch < inlink->channels; ch++) {
276− FFTComplex *fft_data = s->fft_data[ch];
285+ AVComplexFloat *fft_in = s->fft_in[ch];
286+ AVComplexFloat *fft_out = s->fft_out[ch];
277287
278− av_fft_permute(s->fft, fft_data);
279− av_fft_calc(s->fft, fft_data);
288+ s->tx_fn(s->fft, fft_out, fft_in, sizeof(float));
280289 }
281290
282291 for (ch = 0; ch < inlink->channels; ch++) {
283− FFTComplex *fft_data = s->fft_data[ch];
284− FFTComplex *fft_temp = s->fft_temp[ch];
292+ AVComplexFloat *fft_out = s->fft_out[ch];
293+ AVComplexFloat *fft_temp = s->fft_temp[ch];
285294 float *buf = (float *)s->buffer->extended_data[ch];
286295 int x;
287296 values[VAR_CHANNEL] = ch;
@@ -290,8 +299,8 @@ static int filter_frame(AVFilterLink *inlink) · 2 unmodified lines
290299 float fr, fi;
291300
292301 values[VAR_BIN] = n;
293− values[VAR_REAL] = fft_data[n].re;
294− values[VAR_IMAG] = fft_data[n].im;
302+ values[VAR_REAL] = fft_out[n].re;
303+ values[VAR_IMAG] = fft_out[n].im;
295304
296305 fr = av_expr_eval(s->real[ch], values, s);
297306 fi = av_expr_eval(s->imag[ch], values, s);
@@ -305,11 +314,10 @@ static int filter_frame(AVFilterLink *inlink) · 7 unmodified lines
305314 fft_temp[n].im = -fft_temp[x].im;
306315 }
307316
308− av_fft_permute(s->ifft, fft_temp);
309− av_fft_calc(s->ifft, fft_temp);
317+ s->itx_fn(s->ifft, fft_out, fft_temp, sizeof(float));
310318
311319 for (i = 0; i < window_size; i++) {
312− buf[i] += s->fft_temp[ch][i].re * f;
320+ buf[i] += s->fft_out[ch][i].re * f;
313321 }
314322 }
315323
@@ -434,16 +442,19 @@ static av_cold void uninit(AVFilterContext *ctx) · 118 unmodified lines
434442 AFFTFiltContext *s = ctx->priv;
435443 int i;
436444
437− av_fft_end(s->fft);
438− av_fft_end(s->ifft);
445+ av_tx_uninit(&s->fft);
446+ av_tx_uninit(&s->ifft);
439447
440448 for (i = 0; i < s->channels; i++) {
441− if (s->fft_data)
442− av_freep(&s->fft_data[i]);
449+ if (s->fft_in)
450+ av_freep(&s->fft_in[i]);
451+ if (s->fft_out)
452+ av_freep(&s->fft_out[i]);
443453 if (s->fft_temp)
444454 av_freep(&s->fft_temp[i]);
445455 }
446− av_freep(&s->fft_data);
456+ av_freep(&s->fft_in);
457+ av_freep(&s->fft_out);
447458 av_freep(&s->fft_temp);
448459
449460 for (i = 0; i < s->nb_exprs; i++) {

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