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
95 static inline double getreal(
void *priv,
double x,
double ch)
100 ich =
av_clip(ch, 0,
s->nb_exprs - 1);
101 ix =
av_clip(x, 0,
s->window_size / 2);
103 return s->fft_data[ich][ix].re;
106 static inline double getimag(
void *priv,
double x,
double ch)
111 ich =
av_clip(ch, 0,
s->nb_exprs - 1);
112 ix =
av_clip(x, 0,
s->window_size / 2);
114 return s->fft_data[ich][ix].im;
117 static double realf(
void *priv,
double x,
double ch) {
return getreal(priv, x, ch); }
118 static double imagf(
void *priv,
double x,
double ch) {
return getimag(priv, x, ch); }
127 char *saveptr =
NULL;
131 const char *last_expr =
"1";
133 s->channels =
inlink->channels;
138 if (!
s->fft || !
s->ifft)
141 s->window_size = 1 <<
s->fft_bits;
151 for (ch = 0; ch <
inlink->channels; ch++) {
152 s->fft_data[ch] =
av_calloc(
s->window_size,
sizeof(**
s->fft_data));
153 if (!
s->fft_data[ch])
157 for (ch = 0; ch <
inlink->channels; ch++) {
158 s->fft_temp[ch] =
av_calloc(
s->window_size,
sizeof(**
s->fft_temp));
159 if (!
s->fft_temp[ch])
175 for (ch = 0; ch <
inlink->channels; ch++) {
189 args =
av_strdup(
s->img_str ?
s->img_str :
s->real_str);
195 for (ch = 0; ch <
inlink->channels; ch++) {
213 sizeof(*
s->window_func_lut));
214 if (!
s->window_func_lut)
218 s->overlap = overlap;
220 s->hop_size =
s->window_size * (1 -
s->overlap);
221 if (
s->hop_size <= 0)
239 const int window_size =
s->window_size;
240 const float f = 1. / (
s->window_size / 2);
255 for (ch = 0; ch <
inlink->channels; ch++) {
256 const float *
src = (
float *)
in->extended_data[ch];
259 for (n = 0; n <
in->nb_samples; n++) {
260 fft_data[n].re =
src[n] *
s->window_func_lut[n];
264 for (; n < window_size; n++) {
275 for (ch = 0; ch <
inlink->channels; ch++) {
282 for (ch = 0; ch <
inlink->channels; ch++) {
285 float *buf = (
float *)
s->buffer->extended_data[ch];
289 for (n = 0; n <= window_size / 2; n++) {
303 for (n = window_size / 2 + 1, x = window_size / 2 - 1; n < window_size; n++, x--) {
304 fft_temp[n].
re = fft_temp[x].
re;
305 fft_temp[n].
im = -fft_temp[x].
im;
311 for (
i = 0;
i < window_size;
i++) {
312 buf[
i] +=
s->fft_temp[ch][
i].re *
f;
325 for (ch = 0; ch <
inlink->channels; ch++) {
326 float *dst = (
float *)
out->extended_data[ch];
327 float *buf = (
float *)
s->buffer->extended_data[ch];
329 for (n = 0; n <
s->hop_size; n++)
330 dst[n] = buf[n] * (1.
f -
s->overlap);
331 memmove(buf, buf +
s->hop_size, window_size * 4);
440 for (
i = 0;
i <
s->channels;
i++) {
449 for (
i = 0;
i <
s->nb_exprs;
i++) {
481 .description =
NULL_IF_CONFIG_SMALL(
"Apply arbitrary expressions to samples in frequency domain."),
483 .priv_class = &afftfilt_class,
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
av_cold void av_fft_end(FFTContext *s)
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
A list of supported channel layouts.
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static enum AVSampleFormat sample_fmts[]
enum MovChannelLayoutTag * layouts
#define AVERROR_EOF
End of file.
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.
This structure describes decoded (raw) audio or video data.
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
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.
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[]
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)
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().
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 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)
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)
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.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
AVSampleFormat
Audio sample formats.
static double imagf(void *priv, double x, double ch)
const char * name
Pad name.
static int query_formats(AVFilterContext *ctx)
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
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)
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.