Go to the documentation of this file.
71 #define OFFSET(x) offsetof(SpectrumSynthContext, x)
72 #define A AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
73 #define V AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
76 {
"sample_rate",
"set sample rate",
OFFSET(sample_rate),
AV_OPT_TYPE_INT, {.i64 = 44100}, 15, INT_MAX,
A },
161 "Magnitude and Phase sizes differ (%dx%d vs %dx%d).\n",
163 ctx->inputs[1]->w,
ctx->inputs[1]->h);
165 }
else if (
av_cmp_q(time_base,
ctx->inputs[1]->time_base) != 0) {
167 "Magnitude and Phase time bases differ (%d/%d vs %d/%d).\n",
168 time_base.
num, time_base.
den,
169 ctx->inputs[1]->time_base.num,
170 ctx->inputs[1]->time_base.den);
174 "Magnitude and Phase framerates differ (%d/%d vs %d/%d).\n",
175 frame_rate.
num, frame_rate.
den,
184 s->win_size =
s->size * 2;
185 s->nb_freq =
s->size;
190 "The window size might be too high.\n");
197 s->fft_out =
av_calloc(
s->channels,
sizeof(*
s->fft_out));
201 for (ch = 0; ch <
s->channels; ch++) {
217 sizeof(*
s->window_func_lut));
218 if (!
s->window_func_lut)
222 s->overlap = overlap;
223 s->hop_size = (1 -
s->overlap) *
s->win_size;
225 factor +=
s->window_func_lut[
i] *
s->window_func_lut[
i];
227 s->factor = (
factor /
s->win_size) /
FFMAX(1 / (1 -
s->overlap) - 1, 1);
233 int x,
int y,
int f,
int ch)
235 const int m_linesize =
s->magnitude->linesize[0];
236 const int p_linesize =
s->phase->linesize[0];
237 const uint16_t *m = (uint16_t *)(
s->magnitude->data[0] + y * m_linesize);
238 const uint16_t *p = (uint16_t *)(
s->phase->data[0] + y * p_linesize);
239 float magnitude, phase;
243 magnitude = m[x] / (
double)UINT16_MAX;
246 magnitude =
ff_exp10(((m[x] / (
double)UINT16_MAX) - 1.) * 6.);
251 phase = ((p[x] / (
double)UINT16_MAX) * 2. - 1.) *
M_PI;
253 s->fft_in[ch][
f].re = magnitude * cos(phase);
254 s->fft_in[ch][
f].im = magnitude * sin(phase);
258 int x,
int y,
int f,
int ch)
260 const int m_linesize =
s->magnitude->linesize[0];
261 const int p_linesize =
s->phase->linesize[0];
262 const uint8_t *m = (uint8_t *)(
s->magnitude->data[0] + y * m_linesize);
263 const uint8_t *p = (uint8_t *)(
s->phase->data[0] + y * p_linesize);
264 float magnitude, phase;
268 magnitude = m[x] / (
double)UINT8_MAX;
271 magnitude =
ff_exp10(((m[x] / (
double)UINT8_MAX) - 1.) * 6.);
276 phase = ((p[x] / (
double)UINT8_MAX) * 2. - 1.) *
M_PI;
278 s->fft_in[ch][
f].re = magnitude * cos(phase);
279 s->fft_in[ch][
f].im = magnitude * sin(phase);
286 int start =
h * (
s->channels - ch) - 1;
287 int end =
h * (
s->channels - ch - 1);
290 switch (
s->orientation) {
295 for (y = start,
f = 0; y >= end; y--,
f++) {
302 for (y = start,
f = 0; y >= end; y--,
f++) {
312 for (y = end,
f = 0; y <= start; y++,
f++) {
319 for (y = end,
f = 0; y <= start; y++,
f++) {
331 const int h =
s->size;
332 int nb =
s->win_size;
335 for (ch = 0; ch <
s->channels; ch++) {
338 for (y =
h; y <=
s->nb_freq; y++) {
339 s->fft_in[ch][y].re = 0;
340 s->fft_in[ch][y].im = 0;
343 for (y =
s->nb_freq + 1,
f =
s->nb_freq - 1; y < nb; y++,
f--) {
344 s->fft_in[ch][y].re =
s->fft_in[ch][
f].re;
345 s->fft_in[ch][y].im = -
s->fft_in[ch][
f].im;
356 const float factor =
s->factor;
363 for (ch = 0; ch <
s->channels; ch++) {
364 float *buf = (
float *)
s->buffer->extended_data[ch];
370 for (
i = 0, j = start; j < k &&
i <
s->win_size;
i++, j++) {
371 buf[j] +=
s->fft_out[ch][
i].re;
374 for (;
i <
s->win_size;
i++, j++) {
375 buf[j] =
s->fft_out[ch][
i].re;
378 start +=
s->hop_size;
381 if (start >=
s->win_size) {
382 start -=
s->win_size;
385 if (ch ==
s->channels - 1) {
397 s->pts +=
s->win_size;
398 for (
c = 0;
c <
s->channels;
c++) {
399 dst = (
float *)
out->extended_data[
c];
400 buf = (
float *)
s->buffer->extended_data[
c];
402 for (n = 0; n <
s->win_size; n++) {
405 memmove(buf, buf +
s->win_size,
s->win_size * 4);
426 if (!(
s->magnitude &&
s->phase))
429 switch (
s->sliding) {
433 if (
s->xpos >=
s->xend)
437 s->xpos =
s->xend - 1;
445 for (x = 0; x <
s->xend; x++) {
463 AVFrame **staging[2] = { &
s->magnitude, &
s->phase };
469 for (
i = 0;
i < 2;
i++) {
481 for (
i = 0;
i < 2;
i++) {
490 for (
i = 0;
i < 2;
i++) {
511 for (
i = 0;
i <
s->channels;
i++)
515 for (
i = 0;
i <
s->channels;
i++)
543 .
name =
"spectrumsynth",
551 .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.
#define FILTER_INPUTS(array)
static const int sample_rates[]
This structure describes decoded (raw) audio or video data.
#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.
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...
Link properties exposed to filter code, but not external callers.
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.
#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_OUTPUTS(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...
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
#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
static FilterLink * ff_filter_link(AVFilterLink *link)
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.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static const AVFilterPad spectrumsynth_inputs[]
static void read_fft_data(AVFilterContext *ctx, int x, int h, int ch)
AVFilterContext * src
source filter
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.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
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.
#define FILTER_QUERY_FUNC2(func)
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 const AVOption spectrumsynth_options[]
static void read8_fft_bin(SpectrumSynthContext *s, int x, int y, int f, int ch)
@ AV_OPT_TYPE_INT
Underlying C type is int.
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 void scale(int *out, const int *in, const int w, const int h, const int shift)
static int activate(AVFilterContext *ctx)
static const uint16_t channel_layouts[7]
#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
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
AVComplexFloat ** fft_out
bins holder for each (displayed) channels
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
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.