Go to the documentation of this file.
74 #define OFFSET(x) offsetof(SpectrumSynthContext, x)
75 #define A AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
76 #define V AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
158 "Magnitude and Phase sizes differ (%dx%d vs %dx%d).\n",
160 ctx->inputs[1]->w,
ctx->inputs[1]->h);
162 }
else if (
av_cmp_q(time_base,
ctx->inputs[1]->time_base) != 0) {
164 "Magnitude and Phase time bases differ (%d/%d vs %d/%d).\n",
165 time_base.
num, time_base.
den,
166 ctx->inputs[1]->time_base.num,
167 ctx->inputs[1]->time_base.den);
169 }
else if (
av_cmp_q(frame_rate,
ctx->inputs[1]->frame_rate) != 0) {
171 "Magnitude and Phase framerates differ (%d/%d vs %d/%d).\n",
172 frame_rate.
num, frame_rate.
den,
173 ctx->inputs[1]->frame_rate.num,
174 ctx->inputs[1]->frame_rate.den);
181 s->win_size =
s->size * 2;
182 s->nb_freq =
s->size;
187 "The window size might be too high.\n");
194 s->fft_out =
av_calloc(
s->channels,
sizeof(*
s->fft_out));
198 for (ch = 0; ch <
s->channels; ch++) {
214 sizeof(*
s->window_func_lut));
215 if (!
s->window_func_lut)
219 s->overlap = overlap;
220 s->hop_size = (1 -
s->overlap) *
s->win_size;
222 factor +=
s->window_func_lut[
i] *
s->window_func_lut[
i];
224 s->factor = (
factor /
s->win_size) /
FFMAX(1 / (1 -
s->overlap) - 1, 1);
230 int x,
int y,
int f,
int ch)
232 const int m_linesize =
s->magnitude->linesize[0];
233 const int p_linesize =
s->phase->linesize[0];
234 const uint16_t *m = (uint16_t *)(
s->magnitude->data[0] + y * m_linesize);
235 const uint16_t *p = (uint16_t *)(
s->phase->data[0] + y * p_linesize);
236 float magnitude, phase;
240 magnitude = m[x] / (
double)UINT16_MAX;
243 magnitude =
ff_exp10(((m[x] / (
double)UINT16_MAX) - 1.) * 6.);
248 phase = ((p[x] / (
double)UINT16_MAX) * 2. - 1.) *
M_PI;
250 s->fft_in[ch][
f].re = magnitude * cos(phase);
251 s->fft_in[ch][
f].im = magnitude * sin(phase);
255 int x,
int y,
int f,
int ch)
257 const int m_linesize =
s->magnitude->linesize[0];
258 const int p_linesize =
s->phase->linesize[0];
259 const uint8_t *m = (uint8_t *)(
s->magnitude->data[0] + y * m_linesize);
260 const uint8_t *p = (uint8_t *)(
s->phase->data[0] + y * p_linesize);
261 float magnitude, phase;
265 magnitude = m[x] / (
double)UINT8_MAX;
268 magnitude =
ff_exp10(((m[x] / (
double)UINT8_MAX) - 1.) * 6.);
273 phase = ((p[x] / (
double)UINT8_MAX) * 2. - 1.) *
M_PI;
275 s->fft_in[ch][
f].re = magnitude * cos(phase);
276 s->fft_in[ch][
f].im = magnitude * sin(phase);
283 int start =
h * (
s->channels - ch) - 1;
284 int end =
h * (
s->channels - ch - 1);
287 switch (
s->orientation) {
292 for (y = start,
f = 0; y >= end; y--,
f++) {
299 for (y = start,
f = 0; y >= end; y--,
f++) {
309 for (y = end,
f = 0; y <= start; y++,
f++) {
316 for (y = end,
f = 0; y <= start; y++,
f++) {
328 const int h =
s->size;
329 int nb =
s->win_size;
332 for (ch = 0; ch <
s->channels; ch++) {
335 for (y =
h; y <=
s->nb_freq; y++) {
336 s->fft_in[ch][y].re = 0;
337 s->fft_in[ch][y].im = 0;
340 for (y =
s->nb_freq + 1,
f =
s->nb_freq - 1; y < nb; y++,
f--) {
341 s->fft_in[ch][y].re =
s->fft_in[ch][
f].re;
342 s->fft_in[ch][y].im = -
s->fft_in[ch][
f].im;
345 s->tx_fn(
s->fft,
s->fft_out[ch],
s->fft_in[ch],
sizeof(
float));
353 const float factor =
s->factor;
360 for (ch = 0; ch <
s->channels; ch++) {
361 float *buf = (
float *)
s->buffer->extended_data[ch];
367 for (
i = 0, j = start; j < k &&
i <
s->win_size;
i++, j++) {
368 buf[j] +=
s->fft_out[ch][
i].re;
371 for (;
i <
s->win_size;
i++, j++) {
372 buf[j] =
s->fft_out[ch][
i].re;
375 start +=
s->hop_size;
378 if (start >=
s->win_size) {
379 start -=
s->win_size;
382 if (ch ==
s->channels - 1) {
394 s->pts +=
s->win_size;
395 for (
c = 0;
c <
s->channels;
c++) {
396 dst = (
float *)
out->extended_data[
c];
397 buf = (
float *)
s->buffer->extended_data[
c];
399 for (n = 0; n <
s->win_size; n++) {
402 memmove(buf, buf +
s->win_size,
s->win_size * 4);
423 if (!(
s->magnitude &&
s->phase))
426 switch (
s->sliding) {
430 if (
s->xpos >=
s->xend)
434 s->xpos =
s->xend - 1;
442 for (x = 0; x <
s->xend; x++) {
460 AVFrame **staging[2] = { &
s->magnitude, &
s->phase };
466 for (
i = 0;
i < 2;
i++) {
478 for (
i = 0;
i < 2;
i++) {
487 for (
i = 0;
i < 2;
i++) {
508 for (
i = 0;
i <
s->channels;
i++)
512 for (
i = 0;
i <
s->channels;
i++)
540 .
name =
"spectrumsynth",
548 .priv_class = &spectrumsynth_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
A list of supported channel layouts.
static int try_push_frames(AVFilterContext *ctx)
AVPixelFormat
Pixel format.
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
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[]
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.
#define FILTER_QUERY_FUNC(func)
#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.
AVFilterFormatsConfig outcfg
Lists of supported formats / etc.
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 int config_output(AVFilterLink *outlink)
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
AVFILTER_DEFINE_CLASS(spectrumsynth)
AVTXContext * fft
Fast Fourier Transform context.
static av_always_inline float scale(float x, float s)
#define AV_PIX_FMT_GRAY16
float * window_func_lut
Window function LUT.
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
#define AV_PIX_FMT_YUV444P16
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static enum AVPixelFormat pix_fmts[]
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type of AVComplexFloat, AVComplexDouble or AVComplex...
static void synth_window(AVFilterContext *ctx, int x)
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
#define av_realloc_f(p, o, n)
Describe the class of an AVClass context structure.
const AVFilter ff_vaf_spectrumsynth
Rational number (pair of numerator and denominator).
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)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static int try_push_frame(AVFilterContext *ctx, int x)
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
static const AVFilterPad spectrumsynth_outputs[]
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const AVFilterPad spectrumsynth_inputs[]
static void read_fft_data(AVFilterContext *ctx, int x, int h, int ch)
AVFilterContext * src
source filter
AVFilterFormatsConfig incfg
Lists of supported formats / etc.
static void read16_fft_bin(SpectrumSynthContext *s, int x, int y, int f, int ch)
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
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 layout
int sample_rate
samples per second
#define i(width, name, range_min, range_max)
AVSampleFormat
Audio sample formats.
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
AVComplexFloat ** fft_in
bins holder for each (displayed) channels
static int query_formats(AVFilterContext *ctx)
static const AVOption spectrumsynth_options[]
static void read8_fft_bin(SpectrumSynthContext *s, int x, int y, int f, int ch)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static const int factor[16]
static int activate(AVFilterContext *ctx)
#define FILTER_OUTPUTS(array)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AVComplexFloat ** fft_out
bins holder for each (displayed) channels
static av_cold void uninit(AVFilterContext *ctx)
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.