Go to the documentation of this file.
59 static const char *
const var_names[] = {
"sr",
"b",
"nb",
"ch",
"chs",
"pts",
"re",
"im",
NULL };
62 #define OFFSET(x) offsetof(AFFTFiltContext, x)
63 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
76 static inline double getreal(
void *priv,
double x,
double ch)
81 ich =
av_clip(ch, 0,
s->nb_exprs - 1);
82 ix =
av_clip(x, 0,
s->window_size / 2);
84 return s->fft_out[ich][ix].re;
87 static inline double getimag(
void *priv,
double x,
double ch)
92 ich =
av_clip(ch, 0,
s->nb_exprs - 1);
93 ix =
av_clip(x, 0,
s->window_size / 2);
95 return s->fft_out[ich][ix].im;
98 static double realf(
void *priv,
double x,
double ch) {
return getreal(priv, x, ch); }
99 static double imagf(
void *priv,
double x,
double ch) {
return getimag(priv, x, ch); }
108 char *saveptr =
NULL;
110 float overlap,
scale;
112 const char *last_expr =
"1";
115 s->channels =
inlink->channels;
125 s->window_size =
s->fft_size;
140 for (ch = 0; ch <
inlink->channels; ch++) {
141 s->fft_in[ch] =
av_calloc(buf_size,
sizeof(**
s->fft_in));
145 s->fft_out[ch] =
av_calloc(buf_size,
sizeof(**
s->fft_out));
149 s->fft_temp[ch] =
av_calloc(buf_size,
sizeof(**
s->fft_temp));
150 if (!
s->fft_temp[ch])
166 for (ch = 0; ch <
inlink->channels; ch++) {
180 args =
av_strdup(
s->img_str ?
s->img_str :
s->real_str);
186 for (ch = 0; ch <
inlink->channels; ch++) {
204 sizeof(*
s->window_func_lut));
205 if (!
s->window_func_lut)
209 s->overlap = overlap;
211 s->hop_size =
s->window_size * (1 -
s->overlap);
212 if (
s->hop_size <= 0)
230 const int window_size =
s->window_size;
231 const float f = 1. / (
s->window_size / 2);
246 for (ch = 0; ch <
inlink->channels; ch++) {
251 fft_in[n].re =
src[n] *
s->window_func_lut[n];
255 for (; n < window_size; n++) {
266 for (ch = 0; ch <
inlink->channels; ch++) {
270 s->tx_fn(
s->fft, fft_out, fft_in,
sizeof(
float));
273 for (ch = 0; ch <
inlink->channels; ch++) {
276 float *buf = (
float *)
s->buffer->extended_data[ch];
280 if (
ctx->is_disabled) {
281 for (n = 0; n <= window_size / 2; n++) {
282 fft_temp[n].
re = fft_out[n].
re;
283 fft_temp[n].
im = fft_out[n].
im;
286 for (n = 0; n <= window_size / 2; n++) {
301 for (n = window_size / 2 + 1, x = window_size / 2 - 1; n < window_size; n++, x--) {
302 fft_temp[n].
re = fft_temp[x].
re;
303 fft_temp[n].
im = -fft_temp[x].
im;
306 s->itx_fn(
s->ifft, fft_out, fft_temp,
sizeof(
float));
308 for (
i = 0;
i < window_size;
i++) {
309 buf[
i] +=
s->fft_out[ch][
i].re *
f;
322 for (ch = 0; ch <
inlink->channels; ch++) {
323 float *dst = (
float *)
out->extended_data[ch];
324 float *buf = (
float *)
s->buffer->extended_data[ch];
326 for (n = 0; n <
s->hop_size; n++)
327 dst[n] = buf[n] * (1.
f -
s->overlap);
328 memmove(buf, buf +
s->hop_size, window_size * 4);
407 for (
i = 0;
i <
s->channels;
i++) {
419 for (
i = 0;
i <
s->nb_exprs;
i++) {
449 .description =
NULL_IF_CONFIG_SMALL(
"Apply arbitrary expressions to samples in frequency domain."),
451 .priv_class = &afftfilt_class,
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
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
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
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.
#define AVERROR_EOF
End of file.
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.
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 outputs[]
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Context for an Audio FIFO Buffer.
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
static const AVFilterPad inputs[]
static av_always_inline float scale(float x, float s)
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.
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
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 AVComplexFloat.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define FILTER_INPUTS(array)
#define av_realloc_f(p, o, n)
Describe the class of an AVClass context structure.
static const char *const var_names[]
static int config_input(AVFilterLink *inlink)
Rational number (pair of numerator and denominator).
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
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)
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
static int filter_frame(AVFilterLink *inlink)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_NOPTS_VALUE
Undefined timestamp value.
static double getimag(void *priv, double x, double ch)
static int activate(AVFilterContext *ctx)
AVComplexFloat ** fft_temp
FF_FILTER_FORWARD_WANTED(outlink, inlink)
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
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.
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
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static av_cold void uninit(AVFilterContext *ctx)
char * av_strdup(const char *s)
Duplicate a string.
static double realf(void *priv, double x, double ch)
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...
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.