History

avfilter/af_surround: switch to rdft from avutil/tx

Paul B Mahol committed 4 years ago

Commit b015c101 parent f05c5292 files · +36 −30Browse files

Unified · Split

2 files
  1. configure +0 −2
  2. libavfilter/af_surround.c +36 −28
configure+0−2
@@ -3729,8 +3729,6 @@ super2xsai_filter_deps="gpl" · 3728 unmodified lines
37293729 pixfmts_super2xsai_test_deps="super2xsai_filter"
37303730 superequalizer_filter_deps="avcodec"
37313731 superequalizer_filter_select="rdft"
3732−surround_filter_deps="avcodec"
3733−surround_filter_select="rdft"
37343732 tinterlace_filter_deps="gpl"
37353733 tinterlace_merge_test_deps="tinterlace_filter"
37363734 tinterlace_pad_test_deps="tinterlace_filter"
libavfilter/af_surround.c+36−28
@@ -22,7 +22,7 @@ · 21 unmodified lines
2222 #include "libavutil/audio_fifo.h"
2323 #include "libavutil/channel_layout.h"
2424 #include "libavutil/opt.h"
25−#include "libavcodec/avfft.h"
25+#include "libavutil/tx.h"
2626 #include "avfilter.h"
2727 #include "audio.h"
2828 #include "filters.h"
@@ -97,14 +97,17 @@ typedef struct AudioSurroundContext { · 68 unmodified lines
9797 int nb_in_channels;
9898 int nb_out_channels;
9999
100+ AVFrame *input_in;
100101 AVFrame *input;
101102 AVFrame *output;
103+ AVFrame *output_out;
102104 AVFrame *overlap_buffer;
103105
104106 int buf_size;
105107 int hop_size;
106108 AVAudioFifo *fifo;
107− RDFTContext **rdft, **irdft;
109+ AVTXContext **rdft, **irdft;
110+ av_tx_fn tx_fn, itx_fn;
108111 float *window_func_lut;
109112
110113 int64_t pts;
@@ -203,7 +206,9 @@ static int config_input(AVFilterLink *inlink) · 92 unmodified lines
203206 s->nb_in_channels = inlink->channels;
204207
205208 for (ch = 0; ch < inlink->channels; ch++) {
206− s->rdft[ch] = av_rdft_init(ff_log2(s->buf_size), DFT_R2C);
209+ float scale = 1.f;
210+
211+ av_tx_init(&s->rdft[ch], &s->tx_fn, AV_TX_FLOAT_RDFT, 0, s->buf_size, &scale, 0);
207212 if (!s->rdft[ch])
208213 return AVERROR(ENOMEM);
209214 }
@@ -240,7 +245,11 @@ static int config_input(AVFilterLink *inlink) · 30 unmodified lines
240245 if (ch >= 0)
241246 s->input_levels[ch] *= s->lfe_in;
242247
243− s->input = ff_get_audio_buffer(inlink, s->buf_size * 2);
248+ s->input_in = ff_get_audio_buffer(inlink, s->buf_size + 2);
249+ if (!s->input_in)
250+ return AVERROR(ENOMEM);
251+
252+ s->input = ff_get_audio_buffer(inlink, s->buf_size + 2);
244253 if (!s->input)
245254 return AVERROR(ENOMEM);
246255
@@ -266,7 +275,9 @@ static int config_output(AVFilterLink *outlink) · 19 unmodified lines
266275 s->nb_out_channels = outlink->channels;
267276
268277 for (ch = 0; ch < outlink->channels; ch++) {
269− s->irdft[ch] = av_rdft_init(ff_log2(s->buf_size), IDFT_C2R);
278+ float iscale = 1.f;
279+
280+ av_tx_init(&s->irdft[ch], &s->itx_fn, AV_TX_FLOAT_RDFT, 0, s->buf_size, &iscale, 0);
270281 if (!s->irdft[ch])
271282 return AVERROR(ENOMEM);
272283 }
@@ -303,9 +314,10 @@ static int config_output(AVFilterLink *outlink) · 30 unmodified lines
303314 if (ch >= 0)
304315 s->output_levels[ch] *= s->lfe_out;
305316
306− s->output = ff_get_audio_buffer(outlink, s->buf_size * 2);
317+ s->output_out = ff_get_audio_buffer(outlink, s->buf_size + 2);
318+ s->output = ff_get_audio_buffer(outlink, s->buf_size + 2);
307319 s->overlap_buffer = ff_get_audio_buffer(outlink, s->buf_size * 2);
308− if (!s->overlap_buffer || !s->output)
320+ if (!s->overlap_buffer || !s->output || !s->output_out)
309321 return AVERROR(ENOMEM);
310322
311323 return 0;
@@ -1099,7 +1111,7 @@ static void filter_stereo(AVFilterContext *ctx) · 787 unmodified lines
10991111 srcl = (float *)s->input->extended_data[0];
11001112 srcr = (float *)s->input->extended_data[1];
11011113
1102− for (n = 0; n < s->buf_size; n++) {
1114+ for (n = 0; n < s->buf_size / 2 + 1; n++) {
11031115 float l_re = srcl[2 * n], r_re = srcr[2 * n];
11041116 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
11051117 float c_phase = atan2f(l_im + r_im, l_re + r_re);
@@ -1133,7 +1145,7 @@ static void filter_surround(AVFilterContext *ctx) · 27 unmodified lines
11331145 srcr = (float *)s->input->extended_data[1];
11341146 srcc = (float *)s->input->extended_data[2];
11351147
1136− for (n = 0; n < s->buf_size; n++) {
1148+ for (n = 0; n < s->buf_size / 2 + 1; n++) {
11371149 float l_re = srcl[2 * n], r_re = srcr[2 * n];
11381150 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
11391151 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
@@ -1169,7 +1181,7 @@ static void filter_2_1(AVFilterContext *ctx) · 29 unmodified lines
11691181 srcr = (float *)s->input->extended_data[1];
11701182 srclfe = (float *)s->input->extended_data[2];
11711183
1172− for (n = 0; n < s->buf_size; n++) {
1184+ for (n = 0; n < s->buf_size / 2 + 1; n++) {
11731185 float l_re = srcl[2 * n], r_re = srcr[2 * n];
11741186 float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
11751187 float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
@@ -1206,7 +1218,7 @@ static void filter_5_0_side(AVFilterContext *ctx) · 30 unmodified lines
12061218 srcsl = (float *)s->input->extended_data[3];
12071219 srcsr = (float *)s->input->extended_data[4];
12081220
1209− for (n = 0; n < s->buf_size; n++) {
1221+ for (n = 0; n < s->buf_size / 2 + 1; n++) {
12101222 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
12111223 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
12121224 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
@@ -1264,7 +1276,7 @@ static void filter_5_1_side(AVFilterContext *ctx) · 51 unmodified lines
12641276 srcsl = (float *)s->input->extended_data[4];
12651277 srcsr = (float *)s->input->extended_data[5];
12661278
1267− for (n = 0; n < s->buf_size; n++) {
1279+ for (n = 0; n < s->buf_size / 2 + 1; n++) {
12681280 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
12691281 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
12701282 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
@@ -1323,7 +1335,7 @@ static void filter_5_1_back(AVFilterContext *ctx) · 52 unmodified lines
13231335 srcbl = (float *)s->input->extended_data[4];
13241336 srcbr = (float *)s->input->extended_data[5];
13251337
1326− for (n = 0; n < s->buf_size; n++) {
1338+ for (n = 0; n < s->buf_size / 2 + 1; n++) {
13271339 float fl_re = srcl[2 * n], fr_re = srcr[2 * n];
13281340 float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1];
13291341 float c_re = srcc[2 * n], c_im = srcc[2 * n + 1];
@@ -1532,14 +1544,12 @@ static int fft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) · 202 unmodified lines
15321544 float *dst;
15331545 int n;
15341546
1535− memset(s->input->extended_data[ch] + s->buf_size * sizeof(float), 0, s->buf_size * sizeof(float));
1536−
1537− dst = (float *)s->input->extended_data[ch];
1547+ dst = (float *)s->input_in->extended_data[ch];
15381548 for (n = 0; n < s->buf_size; n++) {
15391549 dst[n] *= s->window_func_lut[n] * level_in;
15401550 }
15411551
1542− av_rdft_calc(s->rdft[ch], (float *)s->input->extended_data[ch]);
1552+ s->tx_fn(s->rdft[ch], (float *)s->input->extended_data[ch], dst, sizeof(float));
15431553
15441554 return 0;
15451555 }
@@ -1552,10 +1562,9 @@ static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) · 6 unmodified lines
15521562 float *dst, *ptr;
15531563 int n;
15541564
1555− av_rdft_calc(s->irdft[ch], (float *)s->output->extended_data[ch]);
1556−
1557− dst = (float *)s->output->extended_data[ch];
1565+ dst = (float *)s->output_out->extended_data[ch];
15581566 ptr = (float *)s->overlap_buffer->extended_data[ch];
1567+ s->itx_fn(s->irdft[ch], dst, (float *)s->output->extended_data[ch], sizeof(float));
15591568
15601569 memmove(s->overlap_buffer->extended_data[ch],
15611570 s->overlap_buffer->extended_data[ch] + s->hop_size * sizeof(float),
@@ -1582,7 +1591,7 @@ static int filter_frame(AVFilterLink *inlink) · 20 unmodified lines
15821591 AVFrame *out;
15831592 int ret;
15841593
1585− ret = av_audio_fifo_peek(s->fifo, (void **)s->input->extended_data, s->buf_size);
1594+ ret = av_audio_fifo_peek(s->fifo, (void **)s->input_in->extended_data, s->buf_size);
15861595 if (ret < 0)
15871596 return ret;
15881597
@@ -1664,18 +1673,17 @@ static int activate(AVFilterContext *ctx) · 75 unmodified lines
16641673 static av_cold void uninit(AVFilterContext *ctx)
16651674 {
16661675 AudioSurroundContext *s = ctx->priv;
1667− int ch;
16681676
1677+ av_frame_free(&s->input_in);
16691678 av_frame_free(&s->input);
16701679 av_frame_free(&s->output);
1680+ av_frame_free(&s->output_out);
16711681 av_frame_free(&s->overlap_buffer);
16721682
1673− for (ch = 0; ch < s->nb_in_channels; ch++) {
1674− av_rdft_end(s->rdft[ch]);
1675− }
1676− for (ch = 0; ch < s->nb_out_channels; ch++) {
1677− av_rdft_end(s->irdft[ch]);
1678− }
1683+ for (int ch = 0; ch < s->nb_in_channels; ch++)
1684+ av_tx_uninit(&s->rdft[ch]);
1685+ for (int ch = 0; ch < s->nb_out_channels; ch++)
1686+ av_tx_uninit(&s->irdft[ch]);
16791687 av_freep(&s->input_levels);
16801688 av_freep(&s->output_levels);
16811689 av_freep(&s->rdft);

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