2016-01-16 16:09:25 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Paul B Mahol
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published
|
|
|
|
* by the Free Software Foundation; either version 2.1 of the License,
|
|
|
|
* or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libavutil/avstring.h"
|
|
|
|
#include "libavfilter/internal.h"
|
|
|
|
#include "libavutil/common.h"
|
2021-08-04 14:29:54 +02:00
|
|
|
#include "libavutil/cpu.h"
|
2016-01-16 16:09:25 +02:00
|
|
|
#include "libavutil/opt.h"
|
|
|
|
#include "libavutil/eval.h"
|
2021-08-04 09:35:06 +02:00
|
|
|
#include "libavutil/tx.h"
|
2016-01-16 16:09:25 +02:00
|
|
|
#include "audio.h"
|
2019-05-08 15:03:22 +02:00
|
|
|
#include "filters.h"
|
2016-01-16 16:09:25 +02:00
|
|
|
#include "window_func.h"
|
|
|
|
|
|
|
|
typedef struct AFFTFiltContext {
|
|
|
|
const AVClass *class;
|
|
|
|
char *real_str;
|
|
|
|
char *img_str;
|
2019-07-10 15:57:38 +02:00
|
|
|
int fft_size;
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2021-08-04 09:35:06 +02:00
|
|
|
AVTXContext *fft, *ifft;
|
|
|
|
av_tx_fn tx_fn, itx_fn;
|
|
|
|
AVComplexFloat **fft_in;
|
|
|
|
AVComplexFloat **fft_out;
|
|
|
|
AVComplexFloat **fft_temp;
|
2016-01-16 16:09:25 +02:00
|
|
|
int nb_exprs;
|
2020-02-09 16:49:09 +02:00
|
|
|
int channels;
|
2016-01-16 16:09:25 +02:00
|
|
|
int window_size;
|
|
|
|
AVExpr **real;
|
|
|
|
AVExpr **imag;
|
|
|
|
int hop_size;
|
|
|
|
float overlap;
|
2022-02-22 23:26:12 +02:00
|
|
|
AVFrame *window;
|
2016-01-16 16:09:25 +02:00
|
|
|
AVFrame *buffer;
|
|
|
|
int win_func;
|
|
|
|
float *window_func_lut;
|
|
|
|
} AFFTFiltContext;
|
|
|
|
|
2018-11-11 22:11:30 +02:00
|
|
|
static const char *const var_names[] = { "sr", "b", "nb", "ch", "chs", "pts", "re", "im", NULL };
|
|
|
|
enum { VAR_SAMPLE_RATE, VAR_BIN, VAR_NBBINS, VAR_CHANNEL, VAR_CHANNELS, VAR_PTS, VAR_REAL, VAR_IMAG, VAR_VARS_NB };
|
2016-01-16 16:09:25 +02:00
|
|
|
|
|
|
|
#define OFFSET(x) offsetof(AFFTFiltContext, x)
|
|
|
|
#define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
|
|
|
|
|
|
|
|
static const AVOption afftfilt_options[] = {
|
2018-11-11 22:11:30 +02:00
|
|
|
{ "real", "set channels real expressions", OFFSET(real_str), AV_OPT_TYPE_STRING, {.str = "re" }, 0, 0, A },
|
|
|
|
{ "imag", "set channels imaginary expressions", OFFSET(img_str), AV_OPT_TYPE_STRING, {.str = "im" }, 0, 0, A },
|
2019-07-10 15:57:38 +02:00
|
|
|
{ "win_size", "set window size", OFFSET(fft_size), AV_OPT_TYPE_INT, {.i64=4096}, 16, 131072, A },
|
2021-10-15 10:41:01 +02:00
|
|
|
WIN_FUNC_OPTION("win_func", OFFSET(win_func), A, WFUNC_HANNING),
|
2016-01-16 16:09:25 +02:00
|
|
|
{ "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=0.75}, 0, 1, A },
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
AVFILTER_DEFINE_CLASS(afftfilt);
|
|
|
|
|
2018-11-11 22:11:30 +02:00
|
|
|
static inline double getreal(void *priv, double x, double ch)
|
|
|
|
{
|
|
|
|
AFFTFiltContext *s = priv;
|
|
|
|
int ich, ix;
|
|
|
|
|
|
|
|
ich = av_clip(ch, 0, s->nb_exprs - 1);
|
|
|
|
ix = av_clip(x, 0, s->window_size / 2);
|
|
|
|
|
2021-08-04 09:35:06 +02:00
|
|
|
return s->fft_out[ich][ix].re;
|
2018-11-11 22:11:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline double getimag(void *priv, double x, double ch)
|
|
|
|
{
|
|
|
|
AFFTFiltContext *s = priv;
|
|
|
|
int ich, ix;
|
|
|
|
|
|
|
|
ich = av_clip(ch, 0, s->nb_exprs - 1);
|
|
|
|
ix = av_clip(x, 0, s->window_size / 2);
|
|
|
|
|
2021-08-04 09:35:06 +02:00
|
|
|
return s->fft_out[ich][ix].im;
|
2018-11-11 22:11:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static double realf(void *priv, double x, double ch) { return getreal(priv, x, ch); }
|
|
|
|
static double imagf(void *priv, double x, double ch) { return getimag(priv, x, ch); }
|
|
|
|
|
|
|
|
static const char *const func2_names[] = { "real", "imag", NULL };
|
2020-12-27 18:36:59 +02:00
|
|
|
static double (*const func2[])(void *, double, double) = { realf, imagf, NULL };
|
2018-11-11 22:11:30 +02:00
|
|
|
|
2016-01-16 16:09:25 +02:00
|
|
|
static int config_input(AVFilterLink *inlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
AFFTFiltContext *s = ctx->priv;
|
|
|
|
char *saveptr = NULL;
|
2019-07-06 12:01:38 +02:00
|
|
|
int ret = 0, ch;
|
2021-08-04 09:35:06 +02:00
|
|
|
float overlap, scale;
|
2016-02-04 15:04:43 +02:00
|
|
|
char *args;
|
|
|
|
const char *last_expr = "1";
|
2021-08-04 10:13:46 +02:00
|
|
|
int buf_size;
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
s->channels = inlink->ch_layout.nb_channels;
|
2021-08-04 09:35:06 +02:00
|
|
|
ret = av_tx_init(&s->fft, &s->tx_fn, AV_TX_FLOAT_FFT, 0, s->fft_size, &scale, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = av_tx_init(&s->ifft, &s->itx_fn, AV_TX_FLOAT_FFT, 1, s->fft_size, &scale, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2021-08-04 09:35:06 +02:00
|
|
|
s->window_size = s->fft_size;
|
2021-08-04 10:13:46 +02:00
|
|
|
buf_size = FFALIGN(s->window_size, av_cpu_max_align());
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
s->fft_in = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->fft_in));
|
2021-08-04 09:35:06 +02:00
|
|
|
if (!s->fft_in)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
s->fft_out = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->fft_out));
|
2021-08-04 09:35:06 +02:00
|
|
|
if (!s->fft_out)
|
2016-01-16 16:09:25 +02:00
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
s->fft_temp = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->fft_temp));
|
2018-11-11 22:11:30 +02:00
|
|
|
if (!s->fft_temp)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
|
2021-08-04 10:13:46 +02:00
|
|
|
s->fft_in[ch] = av_calloc(buf_size, sizeof(**s->fft_in));
|
2021-08-04 09:35:06 +02:00
|
|
|
if (!s->fft_in[ch])
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2021-08-04 10:13:46 +02:00
|
|
|
s->fft_out[ch] = av_calloc(buf_size, sizeof(**s->fft_out));
|
2021-08-04 09:35:06 +02:00
|
|
|
if (!s->fft_out[ch])
|
2016-01-16 16:09:25 +02:00
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2021-08-04 10:13:46 +02:00
|
|
|
s->fft_temp[ch] = av_calloc(buf_size, sizeof(**s->fft_temp));
|
2018-11-11 22:11:30 +02:00
|
|
|
if (!s->fft_temp[ch])
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
s->real = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->real));
|
2016-01-16 16:09:25 +02:00
|
|
|
if (!s->real)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
s->imag = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->imag));
|
2016-01-16 16:09:25 +02:00
|
|
|
if (!s->imag)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
args = av_strdup(s->real_str);
|
|
|
|
if (!args)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
|
2016-01-16 16:09:25 +02:00
|
|
|
char *arg = av_strtok(ch == 0 ? args : NULL, "|", &saveptr);
|
|
|
|
|
|
|
|
ret = av_expr_parse(&s->real[ch], arg ? arg : last_expr, var_names,
|
2018-11-11 22:11:30 +02:00
|
|
|
NULL, NULL, func2_names, func2, 0, ctx);
|
2016-01-16 16:09:25 +02:00
|
|
|
if (ret < 0)
|
2020-02-09 16:42:48 +02:00
|
|
|
goto fail;
|
2016-01-16 16:09:25 +02:00
|
|
|
if (arg)
|
|
|
|
last_expr = arg;
|
|
|
|
s->nb_exprs++;
|
|
|
|
}
|
|
|
|
|
2020-02-09 16:42:48 +02:00
|
|
|
av_freep(&args);
|
2016-01-16 16:09:25 +02:00
|
|
|
|
|
|
|
args = av_strdup(s->img_str ? s->img_str : s->real_str);
|
|
|
|
if (!args)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2019-10-07 11:37:05 +02:00
|
|
|
saveptr = NULL;
|
|
|
|
last_expr = "1";
|
2021-08-31 16:03:14 +02:00
|
|
|
for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
|
2016-01-16 16:09:25 +02:00
|
|
|
char *arg = av_strtok(ch == 0 ? args : NULL, "|", &saveptr);
|
|
|
|
|
|
|
|
ret = av_expr_parse(&s->imag[ch], arg ? arg : last_expr, var_names,
|
2018-11-11 22:11:30 +02:00
|
|
|
NULL, NULL, func2_names, func2, 0, ctx);
|
2016-01-16 16:09:25 +02:00
|
|
|
if (ret < 0)
|
2020-02-09 16:42:48 +02:00
|
|
|
goto fail;
|
2016-01-16 16:09:25 +02:00
|
|
|
if (arg)
|
|
|
|
last_expr = arg;
|
|
|
|
}
|
|
|
|
|
2020-02-09 16:42:48 +02:00
|
|
|
av_freep(&args);
|
2016-01-16 16:09:25 +02:00
|
|
|
|
|
|
|
s->window_func_lut = av_realloc_f(s->window_func_lut, s->window_size,
|
|
|
|
sizeof(*s->window_func_lut));
|
|
|
|
if (!s->window_func_lut)
|
|
|
|
return AVERROR(ENOMEM);
|
2017-09-23 15:21:22 +02:00
|
|
|
generate_window_func(s->window_func_lut, s->window_size, s->win_func, &overlap);
|
2022-02-22 23:26:12 +02:00
|
|
|
for (int i = 0; i < s->window_size; i++)
|
|
|
|
s->window_func_lut[i] = sqrtf(s->window_func_lut[i] / s->window_size);
|
2016-01-16 16:09:25 +02:00
|
|
|
if (s->overlap == 1)
|
|
|
|
s->overlap = overlap;
|
|
|
|
|
|
|
|
s->hop_size = s->window_size * (1 - s->overlap);
|
|
|
|
if (s->hop_size <= 0)
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
s->window = ff_get_audio_buffer(inlink, s->window_size * 2);
|
|
|
|
if (!s->window)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2016-01-16 16:09:25 +02:00
|
|
|
s->buffer = ff_get_audio_buffer(inlink, s->window_size * 2);
|
|
|
|
if (!s->buffer)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2020-02-09 16:42:48 +02:00
|
|
|
fail:
|
|
|
|
av_freep(&args);
|
|
|
|
|
2016-01-16 16:09:25 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
2016-01-16 16:09:25 +02:00
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
|
|
|
AFFTFiltContext *s = ctx->priv;
|
|
|
|
const int window_size = s->window_size;
|
2022-02-22 23:26:12 +02:00
|
|
|
const float *window_lut = s->window_func_lut;
|
|
|
|
const float f = sqrtf(1.f - s->overlap);
|
2016-01-16 16:09:25 +02:00
|
|
|
double values[VAR_VARS_NB];
|
2019-05-08 15:03:22 +02:00
|
|
|
int ch, n, ret, i;
|
2022-02-22 23:26:12 +02:00
|
|
|
AVFrame *out;
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
|
2022-02-22 23:26:12 +02:00
|
|
|
const int offset = s->window_size - s->hop_size;
|
|
|
|
float *src = (float *)s->window->extended_data[ch];
|
2021-08-04 09:35:06 +02:00
|
|
|
AVComplexFloat *fft_in = s->fft_in[ch];
|
2019-05-08 15:03:22 +02:00
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
memmove(src, &src[s->hop_size], offset * sizeof(float));
|
|
|
|
memcpy(&src[offset], in->extended_data[ch], in->nb_samples * sizeof(float));
|
|
|
|
memset(&src[offset + in->nb_samples], 0, (s->hop_size - in->nb_samples) * sizeof(float));
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
for (n = 0; n < window_size; n++) {
|
|
|
|
fft_in[n].re = src[n] * window_lut[n];
|
2021-08-04 09:35:06 +02:00
|
|
|
fft_in[n].im = 0;
|
2019-05-08 15:03:22 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
values[VAR_PTS] = in->pts;
|
2019-05-08 15:03:22 +02:00
|
|
|
values[VAR_SAMPLE_RATE] = inlink->sample_rate;
|
|
|
|
values[VAR_NBBINS] = window_size / 2;
|
2021-08-31 16:03:14 +02:00
|
|
|
values[VAR_CHANNELS] = inlink->ch_layout.nb_channels;
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
|
2021-08-04 09:35:06 +02:00
|
|
|
AVComplexFloat *fft_in = s->fft_in[ch];
|
|
|
|
AVComplexFloat *fft_out = s->fft_out[ch];
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2021-08-04 09:35:06 +02:00
|
|
|
s->tx_fn(s->fft, fft_out, fft_in, sizeof(float));
|
2019-05-08 15:03:22 +02:00
|
|
|
}
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
|
2021-08-04 09:35:06 +02:00
|
|
|
AVComplexFloat *fft_out = s->fft_out[ch];
|
|
|
|
AVComplexFloat *fft_temp = s->fft_temp[ch];
|
2019-05-08 15:03:22 +02:00
|
|
|
float *buf = (float *)s->buffer->extended_data[ch];
|
|
|
|
int x;
|
|
|
|
values[VAR_CHANNEL] = ch;
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2021-09-12 13:24:49 +02:00
|
|
|
if (ctx->is_disabled) {
|
2022-02-22 23:26:12 +02:00
|
|
|
for (n = 0; n < window_size; n++) {
|
2021-09-12 13:24:49 +02:00
|
|
|
fft_temp[n].re = fft_out[n].re;
|
|
|
|
fft_temp[n].im = fft_out[n].im;
|
|
|
|
}
|
|
|
|
} else {
|
2021-09-12 13:25:22 +02:00
|
|
|
for (n = 0; n <= window_size / 2; n++) {
|
|
|
|
float fr, fi;
|
2018-11-12 10:27:08 +02:00
|
|
|
|
2021-09-12 13:25:22 +02:00
|
|
|
values[VAR_BIN] = n;
|
|
|
|
values[VAR_REAL] = fft_out[n].re;
|
|
|
|
values[VAR_IMAG] = fft_out[n].im;
|
2018-11-12 10:27:08 +02:00
|
|
|
|
2021-09-12 13:25:22 +02:00
|
|
|
fr = av_expr_eval(s->real[ch], values, s);
|
|
|
|
fi = av_expr_eval(s->imag[ch], values, s);
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2021-09-12 13:25:22 +02:00
|
|
|
fft_temp[n].re = fr;
|
|
|
|
fft_temp[n].im = fi;
|
|
|
|
}
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
for (n = window_size / 2 + 1, x = window_size / 2 - 1; n < window_size; n++, x--) {
|
|
|
|
fft_temp[n].re = fft_temp[x].re;
|
|
|
|
fft_temp[n].im = -fft_temp[x].im;
|
|
|
|
}
|
2019-05-08 15:03:22 +02:00
|
|
|
}
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2021-08-04 09:35:06 +02:00
|
|
|
s->itx_fn(s->ifft, fft_out, fft_temp, sizeof(float));
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
memmove(buf, buf + s->hop_size, window_size * sizeof(float));
|
2019-05-08 15:03:22 +02:00
|
|
|
for (i = 0; i < window_size; i++) {
|
2022-02-22 23:26:12 +02:00
|
|
|
buf[i] += fft_out[i].re * window_lut[i] * f;
|
2019-05-08 15:03:22 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2019-05-08 15:03:22 +02:00
|
|
|
out = ff_get_audio_buffer(outlink, s->hop_size);
|
|
|
|
if (!out) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto fail;
|
|
|
|
}
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
out->pts = in->pts;
|
|
|
|
out->nb_samples = in->nb_samples;
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) {
|
2019-05-08 15:03:22 +02:00
|
|
|
float *dst = (float *)out->extended_data[ch];
|
|
|
|
float *buf = (float *)s->buffer->extended_data[ch];
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
memcpy(dst, buf, s->hop_size * sizeof(float));
|
2019-05-08 15:03:22 +02:00
|
|
|
}
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2019-05-08 15:03:22 +02:00
|
|
|
ret = ff_filter_frame(outlink, out);
|
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2019-05-08 15:03:22 +02:00
|
|
|
fail:
|
|
|
|
av_frame_free(&in);
|
|
|
|
return ret < 0 ? ret : 0;
|
|
|
|
}
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2019-05-08 15:03:22 +02:00
|
|
|
static int activate(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
|
|
|
AFFTFiltContext *s = ctx->priv;
|
|
|
|
AVFrame *in = NULL;
|
|
|
|
int ret = 0, status;
|
|
|
|
int64_t pts;
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2019-05-08 15:03:22 +02:00
|
|
|
FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
ret = ff_inlink_consume_samples(inlink, s->hop_size, s->hop_size, &in);
|
|
|
|
if (ret < 0)
|
2019-05-08 15:03:22 +02:00
|
|
|
return ret;
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
if (ret > 0)
|
|
|
|
ret = filter_frame(inlink, in);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
|
|
|
|
ff_outlink_set_status(outlink, status, pts);
|
2019-05-08 15:03:22 +02:00
|
|
|
return 0;
|
2016-01-16 16:09:25 +02:00
|
|
|
}
|
|
|
|
|
2022-02-22 23:26:12 +02:00
|
|
|
FF_FILTER_FORWARD_WANTED(outlink, inlink);
|
2019-05-08 15:03:22 +02:00
|
|
|
|
|
|
|
return FFERROR_NOT_READY;
|
2016-01-16 16:09:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
AFFTFiltContext *s = ctx->priv;
|
|
|
|
int i;
|
|
|
|
|
2021-08-04 09:35:06 +02:00
|
|
|
av_tx_uninit(&s->fft);
|
|
|
|
av_tx_uninit(&s->ifft);
|
2016-01-16 16:09:25 +02:00
|
|
|
|
2020-02-09 16:49:09 +02:00
|
|
|
for (i = 0; i < s->channels; i++) {
|
2021-08-04 09:35:06 +02:00
|
|
|
if (s->fft_in)
|
|
|
|
av_freep(&s->fft_in[i]);
|
|
|
|
if (s->fft_out)
|
|
|
|
av_freep(&s->fft_out[i]);
|
2018-11-11 22:11:30 +02:00
|
|
|
if (s->fft_temp)
|
|
|
|
av_freep(&s->fft_temp[i]);
|
2016-01-16 16:09:25 +02:00
|
|
|
}
|
2021-08-04 09:35:06 +02:00
|
|
|
av_freep(&s->fft_in);
|
|
|
|
av_freep(&s->fft_out);
|
2018-11-11 22:11:30 +02:00
|
|
|
av_freep(&s->fft_temp);
|
2016-01-16 16:09:25 +02:00
|
|
|
|
|
|
|
for (i = 0; i < s->nb_exprs; i++) {
|
|
|
|
av_expr_free(s->real[i]);
|
|
|
|
av_expr_free(s->imag[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
av_freep(&s->real);
|
|
|
|
av_freep(&s->imag);
|
|
|
|
av_frame_free(&s->buffer);
|
2022-02-22 23:26:12 +02:00
|
|
|
av_frame_free(&s->window);
|
2017-06-04 22:51:57 +02:00
|
|
|
av_freep(&s->window_func_lut);
|
2016-01-16 16:09:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const AVFilterPad inputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.config_props = config_input,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-19 18:33:56 +02:00
|
|
|
const AVFilter ff_af_afftfilt = {
|
2016-01-16 16:09:25 +02:00
|
|
|
.name = "afftfilt",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Apply arbitrary expressions to samples in frequency domain."),
|
|
|
|
.priv_size = sizeof(AFFTFiltContext),
|
|
|
|
.priv_class = &afftfilt_class,
|
2021-08-12 13:05:31 +02:00
|
|
|
FILTER_INPUTS(inputs),
|
|
|
|
FILTER_OUTPUTS(outputs),
|
2021-09-27 14:23:35 +02:00
|
|
|
FILTER_SINGLE_SAMPLEFMT(AV_SAMPLE_FMT_FLTP),
|
2019-05-08 15:03:22 +02:00
|
|
|
.activate = activate,
|
2016-01-16 16:09:25 +02:00
|
|
|
.uninit = uninit,
|
2021-09-12 13:24:49 +02:00
|
|
|
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,
|
2016-01-16 16:09:25 +02:00
|
|
|
};
|