56static const char *
const var_names[] = {
"sr",
"b",
"nb",
"ch",
"chs",
"pts",
"re",
"im",
NULL };
59#define OFFSET(x) offsetof(AFFTFiltContext, x)
60#define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
73static inline double getreal(
void *priv,
double x,
double ch)
78 ich =
av_clip(ch, 0,
s->nb_exprs - 1);
79 ix =
av_clip(x, 0,
s->window_size / 2);
81 return s->fft_out[ich][ix].re;
84static inline double getimag(
void *priv,
double x,
double ch)
89 ich =
av_clip(ch, 0,
s->nb_exprs - 1);
90 ix =
av_clip(x, 0,
s->window_size / 2);
92 return s->fft_out[ich][ix].im;
95static double realf(
void *priv,
double x,
double ch) {
return getreal(priv, x, ch); }
96static double imagf(
void *priv,
double x,
double ch) {
return getimag(priv, x, ch); }
105 char *saveptr =
NULL;
107 float overlap,
scale = 1.f;
109 const char *last_expr =
"1";
115 if (!
s->fft || !
s->ifft)
118 for (
int ch = 0; ch <
s->channels; ch++) {
124 for (
int ch = 0; ch <
s->channels; ch++) {
130 s->window_size =
s->fft_size;
132 buf_size =
FFALIGN(
s->window_size, max_align);
147 s->fft_in[ch] =
av_calloc(buf_size,
sizeof(**
s->fft_in));
151 s->fft_out[ch] =
av_calloc(buf_size,
sizeof(**
s->fft_out));
155 s->fft_temp[ch] =
av_calloc(buf_size,
sizeof(**
s->fft_temp));
156 if (!
s->fft_temp[ch])
186 args =
av_strdup(
s->img_str ?
s->img_str :
s->real_str);
206 sizeof(*
s->window_func_lut));
207 if (!
s->window_func_lut)
210 for (
int i = 0;
i <
s->window_size;
i++)
211 s->window_func_lut[
i] =
sqrtf(
s->window_func_lut[
i] /
s->window_size);
213 s->overlap = overlap;
215 s->hop_size =
s->window_size * (1 -
s->overlap);
216 if (
s->hop_size <= 0)
240 for (
int ch = start; ch < end; ch++) {
244 s->tx_fn(
s->fft[ch], fft_out, fft_in,
sizeof(*fft_in));
253 const int window_size =
s->window_size;
254 const float *window_lut =
s->window_func_lut;
255 const float f =
sqrtf(1.f -
s->overlap);
261 memcpy(values,
arg,
sizeof(values));
263 for (
int ch = start; ch < end; ch++) {
266 float *buf = (
float *)
s->buffer->extended_data[ch];
270 if (
ctx->is_disabled) {
271 for (
int n = 0; n < window_size; n++) {
272 fft_temp[n].
re = fft_out[n].
re;
273 fft_temp[n].
im = fft_out[n].
im;
276 for (
int n = 0; n <= window_size / 2; n++) {
290 for (
int n = window_size / 2 + 1, x = window_size / 2 - 1; n < window_size; n++, x--) {
291 fft_temp[n].
re = fft_temp[x].
re;
292 fft_temp[n].
im = -fft_temp[x].
im;
296 s->itx_fn(
s->ifft[ch], fft_out, fft_temp,
sizeof(*fft_temp));
298 memmove(buf, buf +
s->hop_size, window_size *
sizeof(
float));
299 for (
int i = 0;
i < window_size;
i++)
300 buf[
i] += fft_out[
i].re * window_lut[
i] *
f;
311 const int window_size =
s->window_size;
312 const float *window_lut =
s->window_func_lut;
318 const int offset =
s->window_size -
s->hop_size;
319 float *
src = (
float *)
s->window->extended_data[ch];
326 for (n = 0; n < window_size; n++) {
327 fft_in[n].
re =
src[n] * window_lut[n];
353 float *
dst = (
float *)
out->extended_data[ch];
354 float *buf = (
float *)
s->buffer->extended_data[ch];
356 memcpy(
dst, buf,
s->hop_size *
sizeof(
float));
365 return ret < 0 ? ret : 0;
404 for (
i = 0;
i <
s->channels;
i++) {
423 for (
i = 0;
i <
s->nb_exprs;
i++) {
444 .p.name =
"afftfilt",
445 .p.description =
NULL_IF_CONFIG_SMALL(
"Apply arbitrary expressions to samples in frequency domain."),
446 .p.priv_class = &afftfilt_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static const AVFilterPad inputs[]
static int config_input(AVFilterLink *inlink)
static double imagf(void *priv, double x, double ch)
static double(*const func2[])(void *, double, double)
static int tx_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
const FFFilter ff_af_afftfilt
static const AVOption afftfilt_options[]
static int config_input(AVFilterLink *inlink)
static double getreal(void *priv, double x, double ch)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static const char *const func2_names[]
static double getimag(void *priv, double x, double ch)
static int activate(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static double realf(void *priv, double x, double ch)
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
#define i(width, name, range_min, range_max)
common internal and external API header
static __device__ float sqrtf(float a)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
simple arithmetic expression evaluator
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ AV_SAMPLE_FMT_FLTP
float, planar
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static void filter_channel(MLPDecodeContext *m, unsigned int substr, unsigned int channel)
Generate PCM samples using the prediction filters and residual values read from the data stream,...
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
#define AVFILTER_DEFINE_CLASS(fname)
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
static const char *const var_names[]
AVComplexFloat ** fft_out
AVComplexFloat ** fft_temp
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
A link between two filters.
int sample_rate
samples per second
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t ** extended_data
pointers to the data planes/channels.
#define av_realloc_f(p, o, n)
static AVFormatContext * ctx
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type of AVComplexFloat, AVComplexDouble or AVComplex...
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
#define WIN_FUNC_OPTION(win_func_opt_name, win_func_offset, flag, default_window_func)
static void generate_window_func(float *lut, int N, int win_func, float *overlap)