Go to the documentation of this file.
56 static 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
73 static 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;
84 static 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;
95 static double realf(
void *priv,
double x,
double ch) {
return getreal(priv, x, ch); }
96 static 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";
112 s->channels =
inlink->ch_layout.nb_channels;
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;
145 for (ch = 0; ch <
inlink->ch_layout.nb_channels; ch++) {
146 s->fft_in[ch] =
av_calloc(buf_size,
sizeof(**
s->fft_in));
150 s->fft_out[ch] =
av_calloc(buf_size,
sizeof(**
s->fft_out));
154 s->fft_temp[ch] =
av_calloc(buf_size,
sizeof(**
s->fft_temp));
155 if (!
s->fft_temp[ch])
171 for (ch = 0; ch <
inlink->ch_layout.nb_channels; ch++) {
185 args =
av_strdup(
s->img_str ?
s->img_str :
s->real_str);
191 for (ch = 0; ch <
inlink->ch_layout.nb_channels; ch++) {
205 sizeof(*
s->window_func_lut));
206 if (!
s->window_func_lut)
209 for (
int i = 0;
i <
s->window_size;
i++)
210 s->window_func_lut[
i] =
sqrtf(
s->window_func_lut[
i] /
s->window_size);
212 s->overlap = overlap;
214 s->hop_size =
s->window_size * (1 -
s->overlap);
215 if (
s->hop_size <= 0)
236 const int start = (
channels * jobnr) / nb_jobs;
237 const int end = (
channels * (jobnr+1)) / nb_jobs;
239 for (
int ch = start; ch < end; ch++) {
243 s->tx_fn(
s->fft[ch], fft_out, fft_in,
sizeof(*fft_in));
252 const int window_size =
s->window_size;
253 const float *window_lut =
s->window_func_lut;
254 const float f =
sqrtf(1.
f -
s->overlap);
256 const int start = (
channels * jobnr) / nb_jobs;
257 const int end = (
channels * (jobnr+1)) / nb_jobs;
262 for (
int ch = start; ch < end; ch++) {
265 float *buf = (
float *)
s->buffer->extended_data[ch];
269 if (
ctx->is_disabled) {
270 for (
int n = 0; n < window_size; n++) {
271 fft_temp[n].
re = fft_out[n].
re;
272 fft_temp[n].
im = fft_out[n].
im;
275 for (
int n = 0; n <= window_size / 2; n++) {
289 for (
int n = window_size / 2 + 1, x = window_size / 2 - 1; n < window_size; n++, x--) {
290 fft_temp[n].
re = fft_temp[x].
re;
291 fft_temp[n].
im = -fft_temp[x].
im;
295 s->itx_fn(
s->ifft[ch], fft_out, fft_temp,
sizeof(*fft_temp));
297 memmove(buf, buf +
s->hop_size, window_size *
sizeof(
float));
298 for (
int i = 0;
i < window_size;
i++)
299 buf[
i] += fft_out[
i].re * window_lut[
i] *
f;
310 const int window_size =
s->window_size;
311 const float *window_lut =
s->window_func_lut;
316 for (ch = 0; ch <
inlink->ch_layout.nb_channels; ch++) {
317 const int offset =
s->window_size -
s->hop_size;
318 float *
src = (
float *)
s->window->extended_data[ch];
325 for (n = 0; n < window_size; n++) {
326 fft_in[n].re =
src[n] * window_lut[n];
351 for (ch = 0; ch <
inlink->ch_layout.nb_channels; ch++) {
352 float *
dst = (
float *)
out->extended_data[ch];
353 float *buf = (
float *)
s->buffer->extended_data[ch];
355 memcpy(
dst, buf,
s->hop_size *
sizeof(
float));
403 for (
i = 0;
i <
s->channels;
i++) {
422 for (
i = 0;
i <
s->nb_exprs;
i++) {
444 .description =
NULL_IF_CONFIG_SMALL(
"Apply arbitrary expressions to samples in frequency domain."),
446 .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[]
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.
#define FILTER_INPUTS(array)
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_OUTPUTS(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 FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
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.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
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
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
@ AV_OPT_TYPE_INT
Underlying C type is int.
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 AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
@ 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...