FFmpeg
vaf_spectrumsynth.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * SpectrumSynth filter
24  * @todo support float pixel format
25  */
26 
27 #include "libavutil/mem.h"
28 #include "libavutil/tx.h"
29 #include "libavutil/avassert.h"
30 #include "libavutil/cpu.h"
31 #include "libavutil/ffmath.h"
32 #include "libavutil/opt.h"
33 #include "avfilter.h"
34 #include "formats.h"
35 #include "audio.h"
36 #include "filters.h"
37 #include "window_func.h"
38 
42 
43 typedef struct SpectrumSynthContext {
44  const AVClass *class;
46  int channels;
47  int scale;
48  int sliding;
49  int win_func;
50  float overlap;
52 
54  AVTXContext *fft; ///< Fast Fourier Transform context
56  AVComplexFloat **fft_in; ///< bins holder for each (displayed) channels
57  AVComplexFloat **fft_out; ///< bins holder for each (displayed) channels
58  int win_size;
59  int size;
60  int nb_freq;
61  int hop_size;
62  int start, end;
63  int xpos;
64  int xend;
66  float factor;
68  float *window_func_lut; ///< Window function LUT
70 
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
74 
75 static const AVOption spectrumsynth_options[] = {
76  { "sample_rate", "set sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64 = 44100}, 15, INT_MAX, A },
77  { "channels", "set channels", OFFSET(channels), AV_OPT_TYPE_INT, {.i64 = 1}, 1, 8, A },
78  { "scale", "set input amplitude scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64 = LOG}, 0, NB_SCALES-1, V, .unit = "scale" },
79  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0, 0, V, .unit = "scale" },
80  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=LOG}, 0, 0, V, .unit = "scale" },
81  { "slide", "set input sliding mode", OFFSET(sliding), AV_OPT_TYPE_INT, {.i64 = FULLFRAME}, 0, NB_SLIDES-1, V, .unit = "slide" },
82  { "replace", "consume old columns with new", 0, AV_OPT_TYPE_CONST, {.i64=REPLACE}, 0, 0, V, .unit = "slide" },
83  { "scroll", "consume only most right column", 0, AV_OPT_TYPE_CONST, {.i64=SCROLL}, 0, 0, V, .unit = "slide" },
84  { "fullframe", "consume full frames", 0, AV_OPT_TYPE_CONST, {.i64=FULLFRAME}, 0, 0, V, .unit = "slide" },
85  { "rscroll", "consume only most left column", 0, AV_OPT_TYPE_CONST, {.i64=RSCROLL}, 0, 0, V, .unit = "slide" },
86  WIN_FUNC_OPTION("win_func", OFFSET(win_func), A, 0),
87  { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, A },
88  { "orientation", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, V, .unit = "orientation" },
89  { "vertical", NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL}, 0, 0, V, .unit = "orientation" },
90  { "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, V, .unit = "orientation" },
91  { NULL }
92 };
93 
94 AVFILTER_DEFINE_CLASS(spectrumsynth);
95 
97 {
98  SpectrumSynthContext *s = ctx->priv;
101  AVFilterLink *magnitude = ctx->inputs[0];
102  AVFilterLink *phase = ctx->inputs[1];
103  AVFilterLink *outlink = ctx->outputs[0];
105  static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16,
108  int ret, sample_rates[] = { 48000, -1 };
109 
111  if ((ret = ff_formats_ref (formats, &outlink->incfg.formats )) < 0 ||
112  (ret = ff_add_channel_layout (&layout, &FF_COUNT2LAYOUT(s->channels))) < 0 ||
113  (ret = ff_channel_layouts_ref (layout , &outlink->incfg.channel_layouts)) < 0)
114  return ret;
115 
116  sample_rates[0] = s->sample_rate;
118  if (!formats)
119  return AVERROR(ENOMEM);
120  if ((ret = ff_formats_ref(formats, &outlink->incfg.samplerates)) < 0)
121  return ret;
122 
124  if (!formats)
125  return AVERROR(ENOMEM);
126  if ((ret = ff_formats_ref(formats, &magnitude->outcfg.formats)) < 0)
127  return ret;
128 
130  if (!formats)
131  return AVERROR(ENOMEM);
132  if ((ret = ff_formats_ref(formats, &phase->outcfg.formats)) < 0)
133  return ret;
134 
135  return 0;
136 }
137 
138 static int config_output(AVFilterLink *outlink)
139 {
140  AVFilterContext *ctx = outlink->src;
141  SpectrumSynthContext *s = ctx->priv;
142  FilterLink *inl0 = ff_filter_link(ctx->inputs[0]);
143  FilterLink *inl1 = ff_filter_link(ctx->inputs[1]);
144  int width = ctx->inputs[0]->w;
145  int height = ctx->inputs[0]->h;
146  AVRational time_base = ctx->inputs[0]->time_base;
147  AVRational frame_rate = inl0->frame_rate;
148  float factor, overlap, scale;
149  int i, ch, ret;
150 
151  outlink->sample_rate = s->sample_rate;
152  outlink->time_base = (AVRational){1, s->sample_rate};
153 
154  if (width != ctx->inputs[1]->w ||
155  height != ctx->inputs[1]->h) {
157  "Magnitude and Phase sizes differ (%dx%d vs %dx%d).\n",
158  width, height,
159  ctx->inputs[1]->w, ctx->inputs[1]->h);
160  return AVERROR_INVALIDDATA;
161  } else if (av_cmp_q(time_base, ctx->inputs[1]->time_base) != 0) {
163  "Magnitude and Phase time bases differ (%d/%d vs %d/%d).\n",
164  time_base.num, time_base.den,
165  ctx->inputs[1]->time_base.num,
166  ctx->inputs[1]->time_base.den);
167  return AVERROR_INVALIDDATA;
168  } else if (av_cmp_q(frame_rate, inl1->frame_rate) != 0) {
170  "Magnitude and Phase framerates differ (%d/%d vs %d/%d).\n",
171  frame_rate.num, frame_rate.den,
172  inl1->frame_rate.num,
173  inl1->frame_rate.den);
174  return AVERROR_INVALIDDATA;
175  }
176 
177  s->size = s->orientation == VERTICAL ? height / s->channels : width / s->channels;
178  s->xend = s->orientation == VERTICAL ? width : height;
179 
180  s->win_size = s->size * 2;
181  s->nb_freq = s->size;
182 
183  ret = av_tx_init(&s->fft, &s->tx_fn, AV_TX_FLOAT_FFT, 1, s->win_size, &scale, 0);
184  if (ret < 0) {
185  av_log(ctx, AV_LOG_ERROR, "Unable to create FFT context. "
186  "The window size might be too high.\n");
187  return ret;
188  }
189 
190  s->fft_in = av_calloc(s->channels, sizeof(*s->fft_in));
191  if (!s->fft_in)
192  return AVERROR(ENOMEM);
193  s->fft_out = av_calloc(s->channels, sizeof(*s->fft_out));
194  if (!s->fft_out)
195  return AVERROR(ENOMEM);
196 
197  for (ch = 0; ch < s->channels; ch++) {
198  s->fft_in[ch] = av_calloc(FFALIGN(s->win_size, av_cpu_max_align()), sizeof(**s->fft_in));
199  if (!s->fft_in[ch])
200  return AVERROR(ENOMEM);
201 
202  s->fft_out[ch] = av_calloc(FFALIGN(s->win_size, av_cpu_max_align()), sizeof(**s->fft_out));
203  if (!s->fft_out[ch])
204  return AVERROR(ENOMEM);
205  }
206 
207  s->buffer = ff_get_audio_buffer(outlink, s->win_size * 2);
208  if (!s->buffer)
209  return AVERROR(ENOMEM);
210 
211  /* pre-calc windowing function */
212  s->window_func_lut = av_realloc_f(s->window_func_lut, s->win_size,
213  sizeof(*s->window_func_lut));
214  if (!s->window_func_lut)
215  return AVERROR(ENOMEM);
216  generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap);
217  if (s->overlap == 1)
218  s->overlap = overlap;
219  s->hop_size = (1 - s->overlap) * s->win_size;
220  for (factor = 0, i = 0; i < s->win_size; i++) {
221  factor += s->window_func_lut[i] * s->window_func_lut[i];
222  }
223  s->factor = (factor / s->win_size) / FFMAX(1 / (1 - s->overlap) - 1, 1);
224 
225  return 0;
226 }
227 
229  int x, int y, int f, int ch)
230 {
231  const int m_linesize = s->magnitude->linesize[0];
232  const int p_linesize = s->phase->linesize[0];
233  const uint16_t *m = (uint16_t *)(s->magnitude->data[0] + y * m_linesize);
234  const uint16_t *p = (uint16_t *)(s->phase->data[0] + y * p_linesize);
235  float magnitude, phase;
236 
237  switch (s->scale) {
238  case LINEAR:
239  magnitude = m[x] / (double)UINT16_MAX;
240  break;
241  case LOG:
242  magnitude = ff_exp10(((m[x] / (double)UINT16_MAX) - 1.) * 6.);
243  break;
244  default:
245  av_assert0(0);
246  }
247  phase = ((p[x] / (double)UINT16_MAX) * 2. - 1.) * M_PI;
248 
249  s->fft_in[ch][f].re = magnitude * cos(phase);
250  s->fft_in[ch][f].im = magnitude * sin(phase);
251 }
252 
254  int x, int y, int f, int ch)
255 {
256  const int m_linesize = s->magnitude->linesize[0];
257  const int p_linesize = s->phase->linesize[0];
258  const uint8_t *m = (uint8_t *)(s->magnitude->data[0] + y * m_linesize);
259  const uint8_t *p = (uint8_t *)(s->phase->data[0] + y * p_linesize);
260  float magnitude, phase;
261 
262  switch (s->scale) {
263  case LINEAR:
264  magnitude = m[x] / (double)UINT8_MAX;
265  break;
266  case LOG:
267  magnitude = ff_exp10(((m[x] / (double)UINT8_MAX) - 1.) * 6.);
268  break;
269  default:
270  av_assert0(0);
271  }
272  phase = ((p[x] / (double)UINT8_MAX) * 2. - 1.) * M_PI;
273 
274  s->fft_in[ch][f].re = magnitude * cos(phase);
275  s->fft_in[ch][f].im = magnitude * sin(phase);
276 }
277 
278 static void read_fft_data(AVFilterContext *ctx, int x, int h, int ch)
279 {
280  SpectrumSynthContext *s = ctx->priv;
281  AVFilterLink *inlink = ctx->inputs[0];
282  int start = h * (s->channels - ch) - 1;
283  int end = h * (s->channels - ch - 1);
284  int y, f;
285 
286  switch (s->orientation) {
287  case VERTICAL:
288  switch (inlink->format) {
290  case AV_PIX_FMT_GRAY16:
291  for (y = start, f = 0; y >= end; y--, f++) {
292  read16_fft_bin(s, x, y, f, ch);
293  }
294  break;
295  case AV_PIX_FMT_YUVJ444P:
296  case AV_PIX_FMT_YUV444P:
297  case AV_PIX_FMT_GRAY8:
298  for (y = start, f = 0; y >= end; y--, f++) {
299  read8_fft_bin(s, x, y, f, ch);
300  }
301  break;
302  }
303  break;
304  case HORIZONTAL:
305  switch (inlink->format) {
307  case AV_PIX_FMT_GRAY16:
308  for (y = end, f = 0; y <= start; y++, f++) {
309  read16_fft_bin(s, y, x, f, ch);
310  }
311  break;
312  case AV_PIX_FMT_YUVJ444P:
313  case AV_PIX_FMT_YUV444P:
314  case AV_PIX_FMT_GRAY8:
315  for (y = end, f = 0; y <= start; y++, f++) {
316  read8_fft_bin(s, y, x, f, ch);
317  }
318  break;
319  }
320  break;
321  }
322 }
323 
324 static void synth_window(AVFilterContext *ctx, int x)
325 {
326  SpectrumSynthContext *s = ctx->priv;
327  const int h = s->size;
328  int nb = s->win_size;
329  int y, f, ch;
330 
331  for (ch = 0; ch < s->channels; ch++) {
332  read_fft_data(ctx, x, h, ch);
333 
334  for (y = h; y <= s->nb_freq; y++) {
335  s->fft_in[ch][y].re = 0;
336  s->fft_in[ch][y].im = 0;
337  }
338 
339  for (y = s->nb_freq + 1, f = s->nb_freq - 1; y < nb; y++, f--) {
340  s->fft_in[ch][y].re = s->fft_in[ch][f].re;
341  s->fft_in[ch][y].im = -s->fft_in[ch][f].im;
342  }
343 
344  s->tx_fn(s->fft, s->fft_out[ch], s->fft_in[ch], sizeof(AVComplexFloat));
345  }
346 }
347 
348 static int try_push_frame(AVFilterContext *ctx, int x)
349 {
350  SpectrumSynthContext *s = ctx->priv;
351  AVFilterLink *outlink = ctx->outputs[0];
352  const float factor = s->factor;
353  int ch, n, i, ret;
354  int start, end;
355  AVFrame *out;
356 
357  synth_window(ctx, x);
358 
359  for (ch = 0; ch < s->channels; ch++) {
360  float *buf = (float *)s->buffer->extended_data[ch];
361  int j, k;
362 
363  start = s->start;
364  end = s->end;
365  k = end;
366  for (i = 0, j = start; j < k && i < s->win_size; i++, j++) {
367  buf[j] += s->fft_out[ch][i].re;
368  }
369 
370  for (; i < s->win_size; i++, j++) {
371  buf[j] = s->fft_out[ch][i].re;
372  }
373 
374  start += s->hop_size;
375  end = j;
376 
377  if (start >= s->win_size) {
378  start -= s->win_size;
379  end -= s->win_size;
380 
381  if (ch == s->channels - 1) {
382  float *dst;
383  int c;
384 
385  out = ff_get_audio_buffer(outlink, s->win_size);
386  if (!out) {
387  av_frame_free(&s->magnitude);
388  av_frame_free(&s->phase);
389  return AVERROR(ENOMEM);
390  }
391 
392  out->pts = s->pts;
393  s->pts += s->win_size;
394  for (c = 0; c < s->channels; c++) {
395  dst = (float *)out->extended_data[c];
396  buf = (float *)s->buffer->extended_data[c];
397 
398  for (n = 0; n < s->win_size; n++) {
399  dst[n] = buf[n] * factor;
400  }
401  memmove(buf, buf + s->win_size, s->win_size * 4);
402  }
403 
404  ret = ff_filter_frame(outlink, out);
405  if (ret < 0)
406  return ret;
407  }
408  }
409  }
410 
411  s->start = start;
412  s->end = end;
413 
414  return 0;
415 }
416 
418 {
419  SpectrumSynthContext *s = ctx->priv;
420  int ret, x;
421 
422  if (!(s->magnitude && s->phase))
423  return 0;
424 
425  switch (s->sliding) {
426  case REPLACE:
427  ret = try_push_frame(ctx, s->xpos);
428  s->xpos++;
429  if (s->xpos >= s->xend)
430  s->xpos = 0;
431  break;
432  case SCROLL:
433  s->xpos = s->xend - 1;
434  ret = try_push_frame(ctx, s->xpos);
435  break;
436  case RSCROLL:
437  s->xpos = 0;
438  ret = try_push_frame(ctx, s->xpos);
439  break;
440  case FULLFRAME:
441  for (x = 0; x < s->xend; x++) {
442  ret = try_push_frame(ctx, x);
443  if (ret < 0)
444  break;
445  }
446  break;
447  default:
448  av_assert0(0);
449  }
450 
451  av_frame_free(&s->magnitude);
452  av_frame_free(&s->phase);
453  return ret;
454 }
455 
457 {
458  SpectrumSynthContext *s = ctx->priv;
459  AVFrame **staging[2] = { &s->magnitude, &s->phase };
460  int64_t pts;
461  int i, ret;
462 
464 
465  for (i = 0; i < 2; i++) {
466  if (*staging[i])
467  continue;
468  ret = ff_inlink_consume_frame(ctx->inputs[i], staging[i]);
469  if (ret < 0)
470  return ret;
471  if (ret) {
473  return try_push_frames(ctx);
474  }
475  }
476 
477  for (i = 0; i < 2; i++) {
478  if (ff_inlink_acknowledge_status(ctx->inputs[i], &ret, &pts)) {
479  ff_outlink_set_status(ctx->outputs[0], ret, pts);
480  ff_inlink_set_status(ctx->inputs[1 - i], ret);
481  return 0;
482  }
483  }
484 
485  if (ff_outlink_frame_wanted(ctx->outputs[0])) {
486  for (i = 0; i < 2; i++) {
487  if (!*staging[i])
488  ff_inlink_request_frame(ctx->inputs[i]);
489  }
490  }
491 
492  return FFERROR_NOT_READY;
493 }
494 
496 {
497  SpectrumSynthContext *s = ctx->priv;
498  int i;
499 
500  av_frame_free(&s->magnitude);
501  av_frame_free(&s->phase);
502  av_frame_free(&s->buffer);
503 
504  av_tx_uninit(&s->fft);
505 
506  if (s->fft_in) {
507  for (i = 0; i < s->channels; i++)
508  av_freep(&s->fft_in[i]);
509  }
510  if (s->fft_out) {
511  for (i = 0; i < s->channels; i++)
512  av_freep(&s->fft_out[i]);
513  }
514  av_freep(&s->fft_in);
515  av_freep(&s->fft_out);
516  av_freep(&s->window_func_lut);
517 }
518 
520  {
521  .name = "magnitude",
522  .type = AVMEDIA_TYPE_VIDEO,
523  },
524  {
525  .name = "phase",
526  .type = AVMEDIA_TYPE_VIDEO,
527  },
528 };
529 
531  {
532  .name = "default",
533  .type = AVMEDIA_TYPE_AUDIO,
534  .config_props = config_output,
535  },
536 };
537 
539  .name = "spectrumsynth",
540  .description = NULL_IF_CONFIG_SMALL("Convert input spectrum videos to audio output."),
541  .uninit = uninit,
542  .activate = activate,
543  .priv_size = sizeof(SpectrumSynthContext),
547  .priv_class = &spectrumsynth_class,
548 };
formats
formats
Definition: signature.h:47
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:98
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
try_push_frames
static int try_push_frames(AVFilterContext *ctx)
Definition: vaf_spectrumsynth.c:417
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AVFilterFormatsConfig::samplerates
AVFilterFormats * samplerates
Lists of supported sample rates, only for audio.
Definition: avfilter.h:121
ff_exp10
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: ffmath.h:42
AVERROR
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
opt.h
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:435
AVFilterFormatsConfig::channel_layouts
AVFilterChannelLayouts * channel_layouts
Lists of supported channel layouts, only for audio.
Definition: avfilter.h:126
out
FILE * out
Definition: movenc.c:55
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1023
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:673
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
SpectrumSynthContext::size
int size
Definition: vaf_spectrumsynth.c:59
SpectrumSynthContext::scale
int scale
Definition: vaf_spectrumsynth.c:47
AVTXContext
Definition: tx_priv.h:235
int64_t
long long int64_t
Definition: coverity.c:34
inlink
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
Definition: filter_design.txt:212
SCROLL
@ SCROLL
Definition: vaf_spectrumsynth.c:40
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:162
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
sample_rates
static const int sample_rates[]
Definition: dcaenc.h:34
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
MagnitudeScale
MagnitudeScale
Definition: vaf_spectrumsynth.c:39
AVOption
AVOption.
Definition: opt.h:429
AVComplexFloat
Definition: tx.h:27
WIN_FUNC_OPTION
#define WIN_FUNC_OPTION(win_func_opt_name, win_func_offset, flag, default_window_func)
Definition: window_func.h:37
SpectrumSynthContext
Definition: vaf_spectrumsynth.c:43
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
SpectrumSynthContext::buffer
AVFrame * buffer
Definition: vaf_spectrumsynth.c:67
av_tx_init
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...
Definition: tx.c:903
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
config_output
static int config_output(AVFilterLink *outlink)
Definition: vaf_spectrumsynth.c:138
ff_inlink_consume_frame
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1451
FF_FILTER_FORWARD_STATUS_BACK_ALL
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
Definition: filters.h:447
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(spectrumsynth)
SpectrumSynthContext::end
int end
Definition: vaf_spectrumsynth.c:62
SpectrumSynthContext::fft
AVTXContext * fft
Fast Fourier Transform context.
Definition: vaf_spectrumsynth.c:54
pts
static int64_t pts
Definition: transcode_aac.c:644
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:462
SpectrumSynthContext::start
int start
Definition: vaf_spectrumsynth.c:62
SpectrumSynthContext::sliding
int sliding
Definition: vaf_spectrumsynth.c:48
AVRational::num
int num
Numerator.
Definition: rational.h:59
SpectrumSynthContext::window_func_lut
float * window_func_lut
Window function LUT.
Definition: vaf_spectrumsynth.c:68
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
SpectrumSynthContext::magnitude
AVFrame * magnitude
Definition: vaf_spectrumsynth.c:53
SpectrumSynthContext::sample_rate
int sample_rate
Definition: vaf_spectrumsynth.c:45
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:151
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:424
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1578
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:491
Orientation
Orientation
Definition: avf_showspectrum.c:56
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:678
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
NB_SLIDES
@ NB_SLIDES
Definition: vaf_spectrumsynth.c:40
filters.h
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:304
AV_TX_FLOAT_FFT
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type of AVComplexFloat, AVComplexDouble or AVComplex...
Definition: tx.h:47
ctx
AVFormatContext * ctx
Definition: movenc.c:49
channels
channels
Definition: aptx.h:31
synth_window
static void synth_window(AVFilterContext *ctx, int x)
Definition: vaf_spectrumsynth.c:324
A
#define A
Definition: vaf_spectrumsynth.c:72
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:87
OFFSET
#define OFFSET(x)
Definition: vaf_spectrumsynth.c:71
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:32
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
ff_vaf_spectrumsynth
const AVFilter ff_vaf_spectrumsynth
Definition: vaf_spectrumsynth.c:538
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
double
double
Definition: af_crystalizer.c:132
av_cpu_max_align
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
Definition: cpu.c:274
generate_window_func
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
Definition: window_func.h:63
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, const AVChannelLayout *channel_layout)
Definition: formats.c:521
try_push_frame
static int try_push_frame(AVFilterContext *ctx, int x)
Definition: vaf_spectrumsynth.c:348
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1398
spectrumsynth_outputs
static const AVFilterPad spectrumsynth_outputs[]
Definition: vaf_spectrumsynth.c:530
SpectrumSynthContext::xend
int xend
Definition: vaf_spectrumsynth.c:64
VERTICAL
@ VERTICAL
Definition: vaf_spectrumsynth.c:41
c
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
Definition: undefined.txt:32
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
SpectrumSynthContext::phase
AVFrame * phase
Definition: vaf_spectrumsynth.c:53
SpectrumSynthContext::xpos
int xpos
Definition: vaf_spectrumsynth.c:63
f
f
Definition: af_crystalizer.c:122
ff_inlink_set_status
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
Definition: avfilter.c:1587
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
height
#define height
Definition: dsp.h:85
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
cpu.h
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
spectrumsynth_inputs
static const AVFilterPad spectrumsynth_inputs[]
Definition: vaf_spectrumsynth.c:519
read_fft_data
static void read_fft_data(AVFilterContext *ctx, int x, int h, int ch)
Definition: vaf_spectrumsynth.c:278
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
SpectrumSynthContext::factor
float factor
Definition: vaf_spectrumsynth.c:66
SpectrumSynthContext::hop_size
int hop_size
Definition: vaf_spectrumsynth.c:61
SpectrumSynthContext::orientation
int orientation
Definition: vaf_spectrumsynth.c:51
NB_ORIENTATIONS
@ NB_ORIENTATIONS
Definition: vaf_spectrumsynth.c:41
read16_fft_bin
static void read16_fft_bin(SpectrumSynthContext *s, int x, int y, int f, int ch)
Definition: vaf_spectrumsynth.c:228
SpectrumSynthContext::win_func
int win_func
Definition: vaf_spectrumsynth.c:49
M_PI
#define M_PI
Definition: mathematics.h:67
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:295
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
layout
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
Definition: filter_design.txt:18
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
HORIZONTAL
@ HORIZONTAL
Definition: vaf_spectrumsynth.c:41
SpectrumSynthContext::channels
int channels
Definition: vaf_spectrumsynth.c:46
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
SpectrumSynthContext::nb_freq
int nb_freq
Definition: vaf_spectrumsynth.c:60
SpectrumSynthContext::overlap
float overlap
Definition: vaf_spectrumsynth.c:50
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
SpectrumSynthContext::tx_fn
av_tx_fn tx_fn
Definition: vaf_spectrumsynth.c:55
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
AVFilter
Filter definition.
Definition: avfilter.h:201
ret
ret
Definition: filter_design.txt:187
SpectrumSynthContext::fft_in
AVComplexFloat ** fft_in
bins holder for each (displayed) channels
Definition: vaf_spectrumsynth.c:56
FF_COUNT2LAYOUT
#define FF_COUNT2LAYOUT(c)
Encode a channel count as a channel layout.
Definition: formats.h:102
window_func.h
FULLFRAME
@ FULLFRAME
Definition: vaf_spectrumsynth.c:40
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vaf_spectrumsynth.c:96
spectrumsynth_options
static const AVOption spectrumsynth_options[]
Definition: vaf_spectrumsynth.c:75
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
read8_fft_bin
static void read8_fft_bin(SpectrumSynthContext *s, int x, int y, int f, int ch)
Definition: vaf_spectrumsynth.c:253
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
ffmath.h
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
factor
static const int factor[16]
Definition: vf_pp7.c:80
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
audio.h
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:116
V
#define V
Definition: vaf_spectrumsynth.c:73
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
activate
static int activate(AVFilterContext *ctx)
Definition: vaf_spectrumsynth.c:456
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
LOG
@ LOG
Definition: vaf_spectrumsynth.c:39
SpectrumSynthContext::win_size
int win_size
Definition: vaf_spectrumsynth.c:58
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
h
h
Definition: vp9dsp_template.c:2070
ff_outlink_frame_wanted
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
SpectrumSynthContext::fft_out
AVComplexFloat ** fft_out
bins holder for each (displayed) channels
Definition: vaf_spectrumsynth.c:57
width
#define width
Definition: dsp.h:85
LINEAR
@ LINEAR
Definition: vaf_spectrumsynth.c:39
REPLACE
@ REPLACE
Definition: vaf_spectrumsynth.c:40
RSCROLL
@ RSCROLL
Definition: vaf_spectrumsynth.c:40
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: filters.h:236
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vaf_spectrumsynth.c:495
NB_SCALES
@ NB_SCALES
Definition: vaf_spectrumsynth.c:39
SpectrumSynthContext::pts
int64_t pts
Definition: vaf_spectrumsynth.c:65
SlideMode
SlideMode
Definition: avf_ahistogram.c:31
ff_filter_set_ready
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:237
tx.h