mirror of https://git.ffmpeg.org/ffmpeg.git
avfilter/af_superequalizer: switch rdft to lavu/tx
This commit is contained in:
parent
a63879049d
commit
18ad9fb0c5
|
@ -3714,8 +3714,6 @@ stereo3d_filter_deps="gpl"
|
||||||
subtitles_filter_deps="avformat avcodec libass"
|
subtitles_filter_deps="avformat avcodec libass"
|
||||||
super2xsai_filter_deps="gpl"
|
super2xsai_filter_deps="gpl"
|
||||||
pixfmts_super2xsai_test_deps="super2xsai_filter"
|
pixfmts_super2xsai_test_deps="super2xsai_filter"
|
||||||
superequalizer_filter_deps="avcodec"
|
|
||||||
superequalizer_filter_select="rdft"
|
|
||||||
tinterlace_filter_deps="gpl"
|
tinterlace_filter_deps="gpl"
|
||||||
tinterlace_merge_test_deps="tinterlace_filter"
|
tinterlace_merge_test_deps="tinterlace_filter"
|
||||||
tinterlace_pad_test_deps="tinterlace_filter"
|
tinterlace_pad_test_deps="tinterlace_filter"
|
||||||
|
|
|
@ -20,8 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "libavutil/opt.h"
|
#include "libavutil/opt.h"
|
||||||
|
#include "libavutil/tx.h"
|
||||||
#include "libavcodec/avfft.h"
|
|
||||||
|
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "avfilter.h"
|
#include "avfilter.h"
|
||||||
|
@ -46,11 +45,12 @@ typedef struct SuperEqualizerContext {
|
||||||
float aa;
|
float aa;
|
||||||
float iza;
|
float iza;
|
||||||
float *ires, *irest;
|
float *ires, *irest;
|
||||||
float *fsamples;
|
float *fsamples, *fsamples_out;
|
||||||
int winlen, tabsize;
|
int winlen, tabsize;
|
||||||
|
|
||||||
AVFrame *in, *out;
|
AVFrame *in, *out;
|
||||||
RDFTContext *rdft, *irdft;
|
AVTXContext *rdft, *irdft;
|
||||||
|
av_tx_fn tx_fn, itx_fn;
|
||||||
} SuperEqualizerContext;
|
} SuperEqualizerContext;
|
||||||
|
|
||||||
static const float bands[] = {
|
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)
|
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);
|
ret = av_tx_init(&s->rdft, &s->tx_fn, AV_TX_FLOAT_RDFT, 0, 1 << wb, &scale, 0);
|
||||||
s->irdft = av_rdft_init(wb, IDFT_C2R);
|
if (ret < 0)
|
||||||
if (!s->rdft || !s->irdft)
|
return ret;
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
|
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->aa = 96;
|
||||||
s->winlen = (1 << (wb-1))-1;
|
s->winlen = (1 << (wb-1))-1;
|
||||||
s->tabsize = 1 << wb;
|
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->irest = av_calloc(s->tabsize, sizeof(float));
|
||||||
s->fsamples = 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);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
for (i = 0; i <= M; i++) {
|
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 winlen = s->winlen;
|
||||||
const int tabsize = s->tabsize;
|
const int tabsize = s->tabsize;
|
||||||
float *nires;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (fs <= 0)
|
if (fs <= 0)
|
||||||
|
@ -178,10 +182,7 @@ static void make_fir(SuperEqualizerContext *s, float *lbc, float *rbc, EqParamet
|
||||||
for (; i < tabsize; i++)
|
for (; i < tabsize; i++)
|
||||||
s->irest[i] = 0;
|
s->irest[i] = 0;
|
||||||
|
|
||||||
av_rdft_calc(s->rdft, s->irest);
|
s->tx_fn(s->rdft, s->ires, s->irest, sizeof(float));
|
||||||
nires = s->ires;
|
|
||||||
for (i = 0; i < tabsize; i++)
|
|
||||||
nires[i] = s->irest[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||||
|
@ -190,6 +191,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||||
SuperEqualizerContext *s = ctx->priv;
|
SuperEqualizerContext *s = ctx->priv;
|
||||||
AVFilterLink *outlink = ctx->outputs[0];
|
AVFilterLink *outlink = ctx->outputs[0];
|
||||||
const float *ires = s->ires;
|
const float *ires = s->ires;
|
||||||
|
float *fsamples_out = s->fsamples_out;
|
||||||
float *fsamples = s->fsamples;
|
float *fsamples = s->fsamples;
|
||||||
int ch, i;
|
int ch, i;
|
||||||
|
|
||||||
|
@ -211,26 +213,24 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||||
for (; i < s->tabsize; i++)
|
for (; i < s->tabsize; i++)
|
||||||
fsamples[i] = 0;
|
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];
|
for (i = 0; i <= s->tabsize / 2; i++) {
|
||||||
fsamples[1] = ires[1] * fsamples[1];
|
|
||||||
for (i = 1; i < s->tabsize / 2; i++) {
|
|
||||||
float re, im;
|
float re, im;
|
||||||
|
|
||||||
re = ires[i*2 ] * fsamples[i*2] - ires[i*2+1] * 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[i*2] + ires[i*2 ] * fsamples[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_out[i*2 ] = re;
|
||||||
fsamples[i*2+1] = im;
|
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++)
|
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++)
|
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++)
|
for (i = 0; i < s->winlen; i++)
|
||||||
ptr[i] = dst[i];
|
ptr[i] = dst[i];
|
||||||
for (i = 0; i < s->winlen; 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->irest);
|
||||||
av_freep(&s->ires);
|
av_freep(&s->ires);
|
||||||
av_freep(&s->fsamples);
|
av_freep(&s->fsamples);
|
||||||
av_rdft_end(s->rdft);
|
av_freep(&s->fsamples_out);
|
||||||
av_rdft_end(s->irdft);
|
av_tx_uninit(&s->rdft);
|
||||||
|
av_tx_uninit(&s->irdft);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const AVFilterPad superequalizer_inputs[] = {
|
static const AVFilterPad superequalizer_inputs[] = {
|
||||||
|
|
Loading…
Reference in New Issue