| @@ -22,7 +22,7 @@ · 21 unmodified lines |
| 22 | 22 | #include "libavutil/audio_fifo.h" |
| 23 | 23 | #include "libavutil/channel_layout.h" |
| 24 | 24 | #include "libavutil/opt.h" |
| 25 | | −#include "libavcodec/avfft.h" |
| 25 | +#include "libavutil/tx.h" |
| 26 | 26 | #include "avfilter.h" |
| 27 | 27 | #include "audio.h" |
| 28 | 28 | #include "filters.h" |
| @@ -97,14 +97,17 @@ typedef struct AudioSurroundContext { · 68 unmodified lines |
| 97 | 97 | int nb_in_channels; |
| 98 | 98 | int nb_out_channels; |
| 99 | 99 | |
| 100 | + AVFrame *input_in; |
| 100 | 101 | AVFrame *input; |
| 101 | 102 | AVFrame *output; |
| 103 | + AVFrame *output_out; |
| 102 | 104 | AVFrame *overlap_buffer; |
| 103 | 105 | |
| 104 | 106 | int buf_size; |
| 105 | 107 | int hop_size; |
| 106 | 108 | AVAudioFifo *fifo; |
| 107 | | − RDFTContext **rdft, **irdft; |
| 109 | + AVTXContext **rdft, **irdft; |
| 110 | + av_tx_fn tx_fn, itx_fn; |
| 108 | 111 | float *window_func_lut; |
| 109 | 112 | |
| 110 | 113 | int64_t pts; |
| @@ -203,7 +206,9 @@ static int config_input(AVFilterLink *inlink) · 92 unmodified lines |
| 203 | 206 | s->nb_in_channels = inlink->channels; |
| 204 | 207 | |
| 205 | 208 | 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); |
| 207 | 212 | if (!s->rdft[ch]) |
| 208 | 213 | return AVERROR(ENOMEM); |
| 209 | 214 | } |
| @@ -240,7 +245,11 @@ static int config_input(AVFilterLink *inlink) · 30 unmodified lines |
| 240 | 245 | if (ch >= 0) |
| 241 | 246 | s->input_levels[ch] *= s->lfe_in; |
| 242 | 247 | |
| 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); |
| 244 | 253 | if (!s->input) |
| 245 | 254 | return AVERROR(ENOMEM); |
| 246 | 255 | |
| @@ -266,7 +275,9 @@ static int config_output(AVFilterLink *outlink) · 19 unmodified lines |
| 266 | 275 | s->nb_out_channels = outlink->channels; |
| 267 | 276 | |
| 268 | 277 | 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); |
| 270 | 281 | if (!s->irdft[ch]) |
| 271 | 282 | return AVERROR(ENOMEM); |
| 272 | 283 | } |
| @@ -303,9 +314,10 @@ static int config_output(AVFilterLink *outlink) · 30 unmodified lines |
| 303 | 314 | if (ch >= 0) |
| 304 | 315 | s->output_levels[ch] *= s->lfe_out; |
| 305 | 316 | |
| 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); |
| 307 | 319 | 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) |
| 309 | 321 | return AVERROR(ENOMEM); |
| 310 | 322 | |
| 311 | 323 | return 0; |
| @@ -1099,7 +1111,7 @@ static void filter_stereo(AVFilterContext *ctx) · 787 unmodified lines |
| 1099 | 1111 | srcl = (float *)s->input->extended_data[0]; |
| 1100 | 1112 | srcr = (float *)s->input->extended_data[1]; |
| 1101 | 1113 | |
| 1102 | | − for (n = 0; n < s->buf_size; n++) { |
| 1114 | + for (n = 0; n < s->buf_size / 2 + 1; n++) { |
| 1103 | 1115 | float l_re = srcl[2 * n], r_re = srcr[2 * n]; |
| 1104 | 1116 | float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1]; |
| 1105 | 1117 | 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 |
| 1133 | 1145 | srcr = (float *)s->input->extended_data[1]; |
| 1134 | 1146 | srcc = (float *)s->input->extended_data[2]; |
| 1135 | 1147 | |
| 1136 | | − for (n = 0; n < s->buf_size; n++) { |
| 1148 | + for (n = 0; n < s->buf_size / 2 + 1; n++) { |
| 1137 | 1149 | float l_re = srcl[2 * n], r_re = srcr[2 * n]; |
| 1138 | 1150 | float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1]; |
| 1139 | 1151 | 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 |
| 1169 | 1181 | srcr = (float *)s->input->extended_data[1]; |
| 1170 | 1182 | srclfe = (float *)s->input->extended_data[2]; |
| 1171 | 1183 | |
| 1172 | | − for (n = 0; n < s->buf_size; n++) { |
| 1184 | + for (n = 0; n < s->buf_size / 2 + 1; n++) { |
| 1173 | 1185 | float l_re = srcl[2 * n], r_re = srcr[2 * n]; |
| 1174 | 1186 | float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1]; |
| 1175 | 1187 | 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 |
| 1206 | 1218 | srcsl = (float *)s->input->extended_data[3]; |
| 1207 | 1219 | srcsr = (float *)s->input->extended_data[4]; |
| 1208 | 1220 | |
| 1209 | | − for (n = 0; n < s->buf_size; n++) { |
| 1221 | + for (n = 0; n < s->buf_size / 2 + 1; n++) { |
| 1210 | 1222 | float fl_re = srcl[2 * n], fr_re = srcr[2 * n]; |
| 1211 | 1223 | float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1]; |
| 1212 | 1224 | 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 |
| 1264 | 1276 | srcsl = (float *)s->input->extended_data[4]; |
| 1265 | 1277 | srcsr = (float *)s->input->extended_data[5]; |
| 1266 | 1278 | |
| 1267 | | − for (n = 0; n < s->buf_size; n++) { |
| 1279 | + for (n = 0; n < s->buf_size / 2 + 1; n++) { |
| 1268 | 1280 | float fl_re = srcl[2 * n], fr_re = srcr[2 * n]; |
| 1269 | 1281 | float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1]; |
| 1270 | 1282 | 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 |
| 1323 | 1335 | srcbl = (float *)s->input->extended_data[4]; |
| 1324 | 1336 | srcbr = (float *)s->input->extended_data[5]; |
| 1325 | 1337 | |
| 1326 | | − for (n = 0; n < s->buf_size; n++) { |
| 1338 | + for (n = 0; n < s->buf_size / 2 + 1; n++) { |
| 1327 | 1339 | float fl_re = srcl[2 * n], fr_re = srcr[2 * n]; |
| 1328 | 1340 | float fl_im = srcl[2 * n + 1], fr_im = srcr[2 * n + 1]; |
| 1329 | 1341 | 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 |
| 1532 | 1544 | float *dst; |
| 1533 | 1545 | int n; |
| 1534 | 1546 | |
| 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]; |
| 1538 | 1548 | for (n = 0; n < s->buf_size; n++) { |
| 1539 | 1549 | dst[n] *= s->window_func_lut[n] * level_in; |
| 1540 | 1550 | } |
| 1541 | 1551 | |
| 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)); |
| 1543 | 1553 | |
| 1544 | 1554 | return 0; |
| 1545 | 1555 | } |
| @@ -1552,10 +1562,9 @@ static int ifft_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) · 6 unmodified lines |
| 1552 | 1562 | float *dst, *ptr; |
| 1553 | 1563 | int n; |
| 1554 | 1564 | |
| 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]; |
| 1558 | 1566 | ptr = (float *)s->overlap_buffer->extended_data[ch]; |
| 1567 | + s->itx_fn(s->irdft[ch], dst, (float *)s->output->extended_data[ch], sizeof(float)); |
| 1559 | 1568 | |
| 1560 | 1569 | memmove(s->overlap_buffer->extended_data[ch], |
| 1561 | 1570 | s->overlap_buffer->extended_data[ch] + s->hop_size * sizeof(float), |
| @@ -1582,7 +1591,7 @@ static int filter_frame(AVFilterLink *inlink) · 20 unmodified lines |
| 1582 | 1591 | AVFrame *out; |
| 1583 | 1592 | int ret; |
| 1584 | 1593 | |
| 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); |
| 1586 | 1595 | if (ret < 0) |
| 1587 | 1596 | return ret; |
| 1588 | 1597 | |
| @@ -1664,18 +1673,17 @@ static int activate(AVFilterContext *ctx) · 75 unmodified lines |
| 1664 | 1673 | static av_cold void uninit(AVFilterContext *ctx) |
| 1665 | 1674 | { |
| 1666 | 1675 | AudioSurroundContext *s = ctx->priv; |
| 1667 | | − int ch; |
| 1668 | 1676 | |
| 1677 | + av_frame_free(&s->input_in); |
| 1669 | 1678 | av_frame_free(&s->input); |
| 1670 | 1679 | av_frame_free(&s->output); |
| 1680 | + av_frame_free(&s->output_out); |
| 1671 | 1681 | av_frame_free(&s->overlap_buffer); |
| 1672 | 1682 | |
| 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]); |
| 1679 | 1687 | av_freep(&s->input_levels); |
| 1680 | 1688 | av_freep(&s->output_levels); |
| 1681 | 1689 | av_freep(&s->rdft); |