[FFmpeg-cvslog] avfilter/af_superequalizer: switch rdft to lavu/tx
Paul B Mahol
git at videolan.org
Wed Feb 16 18:27:58 EET 2022
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Wed Feb 16 17:04:04 2022 +0100| [18ad9fb0c55674fda3a33203532a8d12877ff0fc] | committer: Paul B Mahol
avfilter/af_superequalizer: switch rdft to lavu/tx
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=18ad9fb0c55674fda3a33203532a8d12877ff0fc
---
configure | 2 --
libavfilter/af_superequalizer.c | 59 +++++++++++++++++++++--------------------
2 files changed, 30 insertions(+), 31 deletions(-)
diff --git a/configure b/configure
index bab1cd372b..1535dc3c5b 100755
--- a/configure
+++ b/configure
@@ -3714,8 +3714,6 @@ stereo3d_filter_deps="gpl"
subtitles_filter_deps="avformat avcodec libass"
super2xsai_filter_deps="gpl"
pixfmts_super2xsai_test_deps="super2xsai_filter"
-superequalizer_filter_deps="avcodec"
-superequalizer_filter_select="rdft"
tinterlace_filter_deps="gpl"
tinterlace_merge_test_deps="tinterlace_filter"
tinterlace_pad_test_deps="tinterlace_filter"
diff --git a/libavfilter/af_superequalizer.c b/libavfilter/af_superequalizer.c
index 2b032b0846..58ad85653d 100644
--- a/libavfilter/af_superequalizer.c
+++ b/libavfilter/af_superequalizer.c
@@ -20,8 +20,7 @@
*/
#include "libavutil/opt.h"
-
-#include "libavcodec/avfft.h"
+#include "libavutil/tx.h"
#include "audio.h"
#include "avfilter.h"
@@ -46,11 +45,12 @@ typedef struct SuperEqualizerContext {
float aa;
float iza;
float *ires, *irest;
- float *fsamples;
+ float *fsamples, *fsamples_out;
int winlen, tabsize;
AVFrame *in, *out;
- RDFTContext *rdft, *irdft;
+ AVTXContext *rdft, *irdft;
+ av_tx_fn tx_fn, itx_fn;
} SuperEqualizerContext;
static const float bands[] = {
@@ -134,21 +134,26 @@ static void process_param(float *bc, EqParameter *param, float fs)
static int equ_init(SuperEqualizerContext *s, int wb)
{
- int i,j;
+ float scale = 1.f, iscale = 1.f;
+ int i, j, ret;
- s->rdft = av_rdft_init(wb, DFT_R2C);
- s->irdft = av_rdft_init(wb, IDFT_C2R);
- if (!s->rdft || !s->irdft)
- return AVERROR(ENOMEM);
+ ret = av_tx_init(&s->rdft, &s->tx_fn, AV_TX_FLOAT_RDFT, 0, 1 << wb, &scale, 0);
+ if (ret < 0)
+ return ret;
+
+ ret = av_tx_init(&s->irdft, &s->itx_fn, AV_TX_FLOAT_RDFT, 1, 1 << wb, &iscale, 0);
+ if (ret < 0)
+ return ret;
s->aa = 96;
s->winlen = (1 << (wb-1))-1;
s->tabsize = 1 << wb;
- s->ires = av_calloc(s->tabsize, sizeof(float));
+ s->ires = av_calloc(s->tabsize + 2, sizeof(float));
s->irest = av_calloc(s->tabsize, sizeof(float));
s->fsamples = av_calloc(s->tabsize, sizeof(float));
- if (!s->ires || !s->irest || !s->fsamples)
+ s->fsamples_out = av_calloc(s->tabsize + 2, sizeof(float));
+ if (!s->ires || !s->irest || !s->fsamples || !s->fsamples_out)
return AVERROR(ENOMEM);
for (i = 0; i <= M; i++) {
@@ -166,7 +171,6 @@ static void make_fir(SuperEqualizerContext *s, float *lbc, float *rbc, EqParamet
{
const int winlen = s->winlen;
const int tabsize = s->tabsize;
- float *nires;
int i;
if (fs <= 0)
@@ -178,10 +182,7 @@ static void make_fir(SuperEqualizerContext *s, float *lbc, float *rbc, EqParamet
for (; i < tabsize; i++)
s->irest[i] = 0;
- av_rdft_calc(s->rdft, s->irest);
- nires = s->ires;
- for (i = 0; i < tabsize; i++)
- nires[i] = s->irest[i];
+ s->tx_fn(s->rdft, s->ires, s->irest, sizeof(float));
}
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
@@ -190,6 +191,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
SuperEqualizerContext *s = ctx->priv;
AVFilterLink *outlink = ctx->outputs[0];
const float *ires = s->ires;
+ float *fsamples_out = s->fsamples_out;
float *fsamples = s->fsamples;
int ch, i;
@@ -211,26 +213,24 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
for (; i < s->tabsize; i++)
fsamples[i] = 0;
- av_rdft_calc(s->rdft, fsamples);
+ s->tx_fn(s->rdft, fsamples_out, fsamples, sizeof(float));
- fsamples[0] = ires[0] * fsamples[0];
- fsamples[1] = ires[1] * fsamples[1];
- for (i = 1; i < s->tabsize / 2; i++) {
+ for (i = 0; i <= s->tabsize / 2; i++) {
float re, im;
- re = ires[i*2 ] * fsamples[i*2] - ires[i*2+1] * fsamples[i*2+1];
- im = ires[i*2+1] * fsamples[i*2] + ires[i*2 ] * fsamples[i*2+1];
+ re = ires[i*2 ] * fsamples_out[i*2] - ires[i*2+1] * fsamples_out[i*2+1];
+ im = ires[i*2+1] * fsamples_out[i*2] + ires[i*2 ] * fsamples_out[i*2+1];
- fsamples[i*2 ] = re;
- fsamples[i*2+1] = im;
+ fsamples_out[i*2 ] = re;
+ fsamples_out[i*2+1] = im;
}
- av_rdft_calc(s->irdft, fsamples);
+ s->itx_fn(s->irdft, fsamples, fsamples_out, sizeof(float));
for (i = 0; i < s->winlen; i++)
- dst[i] += fsamples[i] / s->tabsize * 2;
+ dst[i] += fsamples[i] / s->tabsize;
for (i = s->winlen; i < s->tabsize; i++)
- dst[i] = fsamples[i] / s->tabsize * 2;
+ dst[i] = fsamples[i] / s->tabsize;
for (i = 0; i < s->winlen; i++)
ptr[i] = dst[i];
for (i = 0; i < s->winlen; i++)
@@ -302,8 +302,9 @@ static av_cold void uninit(AVFilterContext *ctx)
av_freep(&s->irest);
av_freep(&s->ires);
av_freep(&s->fsamples);
- av_rdft_end(s->rdft);
- av_rdft_end(s->irdft);
+ av_freep(&s->fsamples_out);
+ av_tx_uninit(&s->rdft);
+ av_tx_uninit(&s->irdft);
}
static const AVFilterPad superequalizer_inputs[] = {
More information about the ffmpeg-cvslog
mailing list