Go to the documentation of this file.
57 static const char *
const var_names[] = {
"sr",
"b",
"nb",
"ch",
"chs",
"pts",
"re",
"im",
NULL };
60 #define OFFSET(x) offsetof(AFFTFiltContext, x)
61 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
74 static inline double getreal(
void *priv,
double x,
double ch)
79 ich =
av_clip(ch, 0,
s->nb_exprs - 1);
80 ix =
av_clip(x, 0,
s->window_size / 2);
82 return s->fft_out[ich][ix].re;
85 static inline double getimag(
void *priv,
double x,
double ch)
90 ich =
av_clip(ch, 0,
s->nb_exprs - 1);
91 ix =
av_clip(x, 0,
s->window_size / 2);
93 return s->fft_out[ich][ix].im;
96 static double realf(
void *priv,
double x,
double ch) {
return getreal(priv, x, ch); }
97 static double imagf(
void *priv,
double x,
double ch) {
return getimag(priv, x, ch); }
106 char *saveptr =
NULL;
108 float overlap,
scale = 1.f;
110 const char *last_expr =
"1";
113 s->channels =
inlink->ch_layout.nb_channels;
116 if (!
s->fft || !
s->ifft)
119 for (
int ch = 0; ch <
s->channels; ch++) {
125 for (
int ch = 0; ch <
s->channels; ch++) {
131 s->window_size =
s->fft_size;
146 for (ch = 0; ch <
inlink->ch_layout.nb_channels; ch++) {
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])
172 for (ch = 0; ch <
inlink->ch_layout.nb_channels; ch++) {
186 args =
av_strdup(
s->img_str ?
s->img_str :
s->real_str);
192 for (ch = 0; ch <
inlink->ch_layout.nb_channels; ch++) {
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)
237 const int start = (
channels * jobnr) / nb_jobs;
238 const int end = (
channels * (jobnr+1)) / nb_jobs;
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);
257 const int start = (
channels * jobnr) / nb_jobs;
258 const int end = (
channels * (jobnr+1)) / nb_jobs;
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;
317 for (ch = 0; ch <
inlink->ch_layout.nb_channels; ch++) {
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];
352 for (ch = 0; ch <
inlink->ch_layout.nb_channels; ch++) {
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));
404 for (
i = 0;
i <
s->channels;
i++) {
423 for (
i = 0;
i <
s->nb_exprs;
i++) {
445 .description =
NULL_IF_CONFIG_SMALL(
"Apply arbitrary expressions to samples in frequency domain."),
447 .priv_class = &afftfilt_class,
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
@ AV_SAMPLE_FMT_FLTP
float, planar
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVComplexFloat ** fft_out
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static const AVOption afftfilt_options[]
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define WIN_FUNC_OPTION(win_func_opt_name, win_func_offset, flag, default_window_func)
const char * name
Filter name.
static int tx_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
A link between two filters.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
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...
static const char *const func2_names[]
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.
static const AVFilterPad inputs[]
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
A filter pad used for either input or output.
static double(*const func2[])(void *, double, double)
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
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().
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type of AVComplexFloat, AVComplexDouble or AVComplex...
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
#define FILTER_INPUTS(array)
static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define av_realloc_f(p, o, n)
Describe the class of an AVClass context structure.
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 av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static const char *const var_names[]
static int config_input(AVFilterLink *inlink)
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
static __device__ float sqrtf(float a)
AVFILTER_DEFINE_CLASS(afftfilt)
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static double getimag(void *priv, double x, double ch)
static int activate(AVFilterContext *ctx)
AVComplexFloat ** fft_temp
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
FF_FILTER_FORWARD_WANTED(outlink, inlink)
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
uint8_t ** extended_data
pointers to the data planes/channels.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
static double imagf(void *priv, double x, double ch)
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
const AVFilter ff_af_afftfilt
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
static av_cold void uninit(AVFilterContext *ctx)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
char * av_strdup(const char *s)
Duplicate a string.
static double realf(void *priv, double x, double ch)
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static double getreal(void *priv, double x, double ch)
#define FILTER_OUTPUTS(array)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)