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/tx.h"
28 #include "libavutil/avassert.h"
30 #include "libavutil/cpu.h"
31 #include "libavutil/ffmath.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/parseutils.h"
34 #include "avfilter.h"
35 #include "formats.h"
36 #include "audio.h"
37 #include "video.h"
38 #include "filters.h"
39 #include "internal.h"
40 #include "window_func.h"
41 
45 
46 typedef struct SpectrumSynthContext {
47  const AVClass *class;
49  int channels;
50  int scale;
51  int sliding;
52  int win_func;
53  float overlap;
55 
57  AVTXContext *fft; ///< Fast Fourier Transform context
59  AVComplexFloat **fft_in; ///< bins holder for each (displayed) channels
60  AVComplexFloat **fft_out; ///< bins holder for each (displayed) channels
61  int win_size;
62  int size;
63  int nb_freq;
64  int hop_size;
65  int start, end;
66  int xpos;
67  int xend;
68  int64_t pts;
69  float factor;
71  float *window_func_lut; ///< Window function LUT
73 
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
77 
78 static const AVOption spectrumsynth_options[] = {
79  { "sample_rate", "set sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64 = 44100}, 15, INT_MAX, A },
80  { "channels", "set channels", OFFSET(channels), AV_OPT_TYPE_INT, {.i64 = 1}, 1, 8, A },
81  { "scale", "set input amplitude scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64 = LOG}, 0, NB_SCALES-1, V, "scale" },
82  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0, 0, V, "scale" },
83  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=LOG}, 0, 0, V, "scale" },
84  { "slide", "set input sliding mode", OFFSET(sliding), AV_OPT_TYPE_INT, {.i64 = FULLFRAME}, 0, NB_SLIDES-1, V, "slide" },
85  { "replace", "consume old columns with new", 0, AV_OPT_TYPE_CONST, {.i64=REPLACE}, 0, 0, V, "slide" },
86  { "scroll", "consume only most right column", 0, AV_OPT_TYPE_CONST, {.i64=SCROLL}, 0, 0, V, "slide" },
87  { "fullframe", "consume full frames", 0, AV_OPT_TYPE_CONST, {.i64=FULLFRAME}, 0, 0, V, "slide" },
88  { "rscroll", "consume only most left column", 0, AV_OPT_TYPE_CONST, {.i64=RSCROLL}, 0, 0, V, "slide" },
89  { "win_func", "set window function", OFFSET(win_func), AV_OPT_TYPE_INT, {.i64 = 0}, 0, NB_WFUNC-1, A, "win_func" },
90  { "rect", "Rectangular", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_RECT}, 0, 0, A, "win_func" },
91  { "bartlett", "Bartlett", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BARTLETT}, 0, 0, A, "win_func" },
92  { "hann", "Hann", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING}, 0, 0, A, "win_func" },
93  { "hanning", "Hanning", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING}, 0, 0, A, "win_func" },
94  { "hamming", "Hamming", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HAMMING}, 0, 0, A, "win_func" },
95  { "sine", "Sine", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_SINE}, 0, 0, A, "win_func" },
96  { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, A },
97  { "orientation", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, V, "orientation" },
98  { "vertical", NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL}, 0, 0, V, "orientation" },
99  { "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, V, "orientation" },
100  { NULL }
101 };
102 
103 AVFILTER_DEFINE_CLASS(spectrumsynth);
104 
106 {
107  SpectrumSynthContext *s = ctx->priv;
110  AVFilterLink *magnitude = ctx->inputs[0];
111  AVFilterLink *phase = ctx->inputs[1];
112  AVFilterLink *outlink = ctx->outputs[0];
114  static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16,
117  int ret, sample_rates[] = { 48000, -1 };
118 
120  if ((ret = ff_formats_ref (formats, &outlink->incfg.formats )) < 0 ||
121  (ret = ff_add_channel_layout (&layout, FF_COUNT2LAYOUT(s->channels))) < 0 ||
122  (ret = ff_channel_layouts_ref (layout , &outlink->incfg.channel_layouts)) < 0)
123  return ret;
124 
125  sample_rates[0] = s->sample_rate;
127  if (!formats)
128  return AVERROR(ENOMEM);
129  if ((ret = ff_formats_ref(formats, &outlink->incfg.samplerates)) < 0)
130  return ret;
131 
133  if (!formats)
134  return AVERROR(ENOMEM);
135  if ((ret = ff_formats_ref(formats, &magnitude->outcfg.formats)) < 0)
136  return ret;
137 
139  if (!formats)
140  return AVERROR(ENOMEM);
141  if ((ret = ff_formats_ref(formats, &phase->outcfg.formats)) < 0)
142  return ret;
143 
144  return 0;
145 }
146 
147 static int config_output(AVFilterLink *outlink)
148 {
149  AVFilterContext *ctx = outlink->src;
150  SpectrumSynthContext *s = ctx->priv;
151  int width = ctx->inputs[0]->w;
152  int height = ctx->inputs[0]->h;
153  AVRational time_base = ctx->inputs[0]->time_base;
154  AVRational frame_rate = ctx->inputs[0]->frame_rate;
155  float factor, overlap, scale;
156  int i, ch, ret;
157 
158  outlink->sample_rate = s->sample_rate;
159  outlink->time_base = (AVRational){1, s->sample_rate};
160 
161  if (width != ctx->inputs[1]->w ||
162  height != ctx->inputs[1]->h) {
164  "Magnitude and Phase sizes differ (%dx%d vs %dx%d).\n",
165  width, height,
166  ctx->inputs[1]->w, ctx->inputs[1]->h);
167  return AVERROR_INVALIDDATA;
168  } else if (av_cmp_q(time_base, ctx->inputs[1]->time_base) != 0) {
170  "Magnitude and Phase time bases differ (%d/%d vs %d/%d).\n",
171  time_base.num, time_base.den,
172  ctx->inputs[1]->time_base.num,
173  ctx->inputs[1]->time_base.den);
174  return AVERROR_INVALIDDATA;
175  } else if (av_cmp_q(frame_rate, ctx->inputs[1]->frame_rate) != 0) {
177  "Magnitude and Phase framerates differ (%d/%d vs %d/%d).\n",
178  frame_rate.num, frame_rate.den,
179  ctx->inputs[1]->frame_rate.num,
180  ctx->inputs[1]->frame_rate.den);
181  return AVERROR_INVALIDDATA;
182  }
183 
184  s->size = s->orientation == VERTICAL ? height / s->channels : width / s->channels;
185  s->xend = s->orientation == VERTICAL ? width : height;
186 
187  s->win_size = s->size * 2;
188  s->nb_freq = s->size;
189 
190  ret = av_tx_init(&s->fft, &s->tx_fn, AV_TX_FLOAT_FFT, 1, s->win_size, &scale, 0);
191  if (ret < 0) {
192  av_log(ctx, AV_LOG_ERROR, "Unable to create FFT context. "
193  "The window size might be too high.\n");
194  return ret;
195  }
196 
197  s->fft_in = av_calloc(s->channels, sizeof(*s->fft_in));
198  if (!s->fft_in)
199  return AVERROR(ENOMEM);
200  s->fft_out = av_calloc(s->channels, sizeof(*s->fft_out));
201  if (!s->fft_out)
202  return AVERROR(ENOMEM);
203 
204  for (ch = 0; ch < s->channels; ch++) {
205  s->fft_in[ch] = av_calloc(FFALIGN(s->win_size, av_cpu_max_align()), sizeof(**s->fft_in));
206  if (!s->fft_in[ch])
207  return AVERROR(ENOMEM);
208 
209  s->fft_out[ch] = av_calloc(FFALIGN(s->win_size, av_cpu_max_align()), sizeof(**s->fft_out));
210  if (!s->fft_out[ch])
211  return AVERROR(ENOMEM);
212  }
213 
214  s->buffer = ff_get_audio_buffer(outlink, s->win_size * 2);
215  if (!s->buffer)
216  return AVERROR(ENOMEM);
217 
218  /* pre-calc windowing function */
219  s->window_func_lut = av_realloc_f(s->window_func_lut, s->win_size,
220  sizeof(*s->window_func_lut));
221  if (!s->window_func_lut)
222  return AVERROR(ENOMEM);
223  generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap);
224  if (s->overlap == 1)
225  s->overlap = overlap;
226  s->hop_size = (1 - s->overlap) * s->win_size;
227  for (factor = 0, i = 0; i < s->win_size; i++) {
228  factor += s->window_func_lut[i] * s->window_func_lut[i];
229  }
230  s->factor = (factor / s->win_size) / FFMAX(1 / (1 - s->overlap) - 1, 1);
231 
232  return 0;
233 }
234 
236  int x, int y, int f, int ch)
237 {
238  const int m_linesize = s->magnitude->linesize[0];
239  const int p_linesize = s->phase->linesize[0];
240  const uint16_t *m = (uint16_t *)(s->magnitude->data[0] + y * m_linesize);
241  const uint16_t *p = (uint16_t *)(s->phase->data[0] + y * p_linesize);
242  float magnitude, phase;
243 
244  switch (s->scale) {
245  case LINEAR:
246  magnitude = m[x] / (double)UINT16_MAX;
247  break;
248  case LOG:
249  magnitude = ff_exp10(((m[x] / (double)UINT16_MAX) - 1.) * 6.);
250  break;
251  default:
252  av_assert0(0);
253  }
254  phase = ((p[x] / (double)UINT16_MAX) * 2. - 1.) * M_PI;
255 
256  s->fft_in[ch][f].re = magnitude * cos(phase);
257  s->fft_in[ch][f].im = magnitude * sin(phase);
258 }
259 
261  int x, int y, int f, int ch)
262 {
263  const int m_linesize = s->magnitude->linesize[0];
264  const int p_linesize = s->phase->linesize[0];
265  const uint8_t *m = (uint8_t *)(s->magnitude->data[0] + y * m_linesize);
266  const uint8_t *p = (uint8_t *)(s->phase->data[0] + y * p_linesize);
267  float magnitude, phase;
268 
269  switch (s->scale) {
270  case LINEAR:
271  magnitude = m[x] / (double)UINT8_MAX;
272  break;
273  case LOG:
274  magnitude = ff_exp10(((m[x] / (double)UINT8_MAX) - 1.) * 6.);
275  break;
276  default:
277  av_assert0(0);
278  }
279  phase = ((p[x] / (double)UINT8_MAX) * 2. - 1.) * M_PI;
280 
281  s->fft_in[ch][f].re = magnitude * cos(phase);
282  s->fft_in[ch][f].im = magnitude * sin(phase);
283 }
284 
285 static void read_fft_data(AVFilterContext *ctx, int x, int h, int ch)
286 {
287  SpectrumSynthContext *s = ctx->priv;
288  AVFilterLink *inlink = ctx->inputs[0];
289  int start = h * (s->channels - ch) - 1;
290  int end = h * (s->channels - ch - 1);
291  int y, f;
292 
293  switch (s->orientation) {
294  case VERTICAL:
295  switch (inlink->format) {
297  case AV_PIX_FMT_GRAY16:
298  for (y = start, f = 0; y >= end; y--, f++) {
299  read16_fft_bin(s, x, y, f, ch);
300  }
301  break;
302  case AV_PIX_FMT_YUVJ444P:
303  case AV_PIX_FMT_YUV444P:
304  case AV_PIX_FMT_GRAY8:
305  for (y = start, f = 0; y >= end; y--, f++) {
306  read8_fft_bin(s, x, y, f, ch);
307  }
308  break;
309  }
310  break;
311  case HORIZONTAL:
312  switch (inlink->format) {
314  case AV_PIX_FMT_GRAY16:
315  for (y = end, f = 0; y <= start; y++, f++) {
316  read16_fft_bin(s, y, x, f, ch);
317  }
318  break;
319  case AV_PIX_FMT_YUVJ444P:
320  case AV_PIX_FMT_YUV444P:
321  case AV_PIX_FMT_GRAY8:
322  for (y = end, f = 0; y <= start; y++, f++) {
323  read8_fft_bin(s, y, x, f, ch);
324  }
325  break;
326  }
327  break;
328  }
329 }
330 
331 static void synth_window(AVFilterContext *ctx, int x)
332 {
333  SpectrumSynthContext *s = ctx->priv;
334  const int h = s->size;
335  int nb = s->win_size;
336  int y, f, ch;
337 
338  for (ch = 0; ch < s->channels; ch++) {
339  read_fft_data(ctx, x, h, ch);
340 
341  for (y = h; y <= s->nb_freq; y++) {
342  s->fft_in[ch][y].re = 0;
343  s->fft_in[ch][y].im = 0;
344  }
345 
346  for (y = s->nb_freq + 1, f = s->nb_freq - 1; y < nb; y++, f--) {
347  s->fft_in[ch][y].re = s->fft_in[ch][f].re;
348  s->fft_in[ch][y].im = -s->fft_in[ch][f].im;
349  }
350 
351  s->tx_fn(s->fft, s->fft_out[ch], s->fft_in[ch], sizeof(float));
352  }
353 }
354 
355 static int try_push_frame(AVFilterContext *ctx, int x)
356 {
357  SpectrumSynthContext *s = ctx->priv;
358  AVFilterLink *outlink = ctx->outputs[0];
359  const float factor = s->factor;
360  int ch, n, i, ret;
361  int start, end;
362  AVFrame *out;
363 
364  synth_window(ctx, x);
365 
366  for (ch = 0; ch < s->channels; ch++) {
367  float *buf = (float *)s->buffer->extended_data[ch];
368  int j, k;
369 
370  start = s->start;
371  end = s->end;
372  k = end;
373  for (i = 0, j = start; j < k && i < s->win_size; i++, j++) {
374  buf[j] += s->fft_out[ch][i].re;
375  }
376 
377  for (; i < s->win_size; i++, j++) {
378  buf[j] = s->fft_out[ch][i].re;
379  }
380 
381  start += s->hop_size;
382  end = j;
383 
384  if (start >= s->win_size) {
385  start -= s->win_size;
386  end -= s->win_size;
387 
388  if (ch == s->channels - 1) {
389  float *dst;
390  int c;
391 
392  out = ff_get_audio_buffer(outlink, s->win_size);
393  if (!out) {
394  av_frame_free(&s->magnitude);
395  av_frame_free(&s->phase);
396  return AVERROR(ENOMEM);
397  }
398 
399  out->pts = s->pts;
400  s->pts += s->win_size;
401  for (c = 0; c < s->channels; c++) {
402  dst = (float *)out->extended_data[c];
403  buf = (float *)s->buffer->extended_data[c];
404 
405  for (n = 0; n < s->win_size; n++) {
406  dst[n] = buf[n] * factor;
407  }
408  memmove(buf, buf + s->win_size, s->win_size * 4);
409  }
410 
411  ret = ff_filter_frame(outlink, out);
412  if (ret < 0)
413  return ret;
414  }
415  }
416  }
417 
418  s->start = start;
419  s->end = end;
420 
421  return 0;
422 }
423 
425 {
426  SpectrumSynthContext *s = ctx->priv;
427  int ret, x;
428 
429  if (!(s->magnitude && s->phase))
430  return 0;
431 
432  switch (s->sliding) {
433  case REPLACE:
434  ret = try_push_frame(ctx, s->xpos);
435  s->xpos++;
436  if (s->xpos >= s->xend)
437  s->xpos = 0;
438  break;
439  case SCROLL:
440  s->xpos = s->xend - 1;
441  ret = try_push_frame(ctx, s->xpos);
442  break;
443  case RSCROLL:
444  s->xpos = 0;
445  ret = try_push_frame(ctx, s->xpos);
446  break;
447  case FULLFRAME:
448  for (x = 0; x < s->xend; x++) {
449  ret = try_push_frame(ctx, x);
450  if (ret < 0)
451  break;
452  }
453  break;
454  default:
455  av_assert0(0);
456  }
457 
458  av_frame_free(&s->magnitude);
459  av_frame_free(&s->phase);
460  return ret;
461 }
462 
464 {
465  SpectrumSynthContext *s = ctx->priv;
466  AVFrame **staging[2] = { &s->magnitude, &s->phase };
467  int64_t pts;
468  int i, ret;
469 
471 
472  for (i = 0; i < 2; i++) {
473  if (*staging[i])
474  continue;
475  ret = ff_inlink_consume_frame(ctx->inputs[i], staging[i]);
476  if (ret < 0)
477  return ret;
478  if (ret) {
480  return try_push_frames(ctx);
481  }
482  }
483 
484  for (i = 0; i < 2; i++) {
485  if (ff_inlink_acknowledge_status(ctx->inputs[i], &ret, &pts)) {
486  ff_outlink_set_status(ctx->outputs[0], ret, pts);
487  ff_inlink_set_status(ctx->inputs[1 - i], ret);
488  return 0;
489  }
490  }
491 
492  if (ff_outlink_frame_wanted(ctx->outputs[0])) {
493  for (i = 0; i < 2; i++) {
494  if (!*staging[i])
495  ff_inlink_request_frame(ctx->inputs[i]);
496  }
497  }
498 
499  return FFERROR_NOT_READY;
500 }
501 
503 {
504  SpectrumSynthContext *s = ctx->priv;
505  int i;
506 
507  av_frame_free(&s->magnitude);
508  av_frame_free(&s->phase);
509  av_frame_free(&s->buffer);
510 
511  av_tx_uninit(&s->fft);
512 
513  if (s->fft_in) {
514  for (i = 0; i < s->channels; i++)
515  av_freep(&s->fft_in[i]);
516  }
517  if (s->fft_out) {
518  for (i = 0; i < s->channels; i++)
519  av_freep(&s->fft_out[i]);
520  }
521  av_freep(&s->fft_in);
522  av_freep(&s->fft_out);
523  av_freep(&s->window_func_lut);
524 }
525 
527  {
528  .name = "magnitude",
529  .type = AVMEDIA_TYPE_VIDEO,
530  },
531  {
532  .name = "phase",
533  .type = AVMEDIA_TYPE_VIDEO,
534  },
535 };
536 
538  {
539  .name = "default",
540  .type = AVMEDIA_TYPE_AUDIO,
541  .config_props = config_output,
542  },
543 };
544 
546  .name = "spectrumsynth",
547  .description = NULL_IF_CONFIG_SMALL("Convert input spectrum videos to audio output."),
548  .uninit = uninit,
549  .query_formats = query_formats,
550  .activate = activate,
551  .priv_size = sizeof(SpectrumSynthContext),
554  .priv_class = &spectrumsynth_class,
555 };
formats
formats
Definition: signature.h:48
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:88
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:69
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:424
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AVFilterFormatsConfig::samplerates
AVFilterFormats * samplerates
Lists of supported sample rates, only for audio.
Definition: avfilter.h:455
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:380
AVFilterFormatsConfig::channel_layouts
AVFilterChannelLayouts * channel_layouts
Lists of supported channel layouts, only for audio.
Definition: avfilter.h:460
out
FILE * out
Definition: movenc.c:54
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1019
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:548
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
SpectrumSynthContext::size
int size
Definition: vaf_spectrumsynth.c:62
SpectrumSynthContext::scale
int scale
Definition: vaf_spectrumsynth.c:50
AVTXContext
Definition: tx_priv.h:110
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:43
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:112
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
MagnitudeScale
MagnitudeScale
Definition: vaf_spectrumsynth.c:42
AVOption
AVOption.
Definition: opt.h:247
AVComplexFloat
Definition: tx.h:27
SpectrumSynthContext
Definition: vaf_spectrumsynth.c:46
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:153
video.h
SpectrumSynthContext::buffer
AVFrame * buffer
Definition: vaf_spectrumsynth.c:70
sample_rate
sample_rate
Definition: ffmpeg_filter.c:156
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:228
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:147
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:1418
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:212
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(spectrumsynth)
SpectrumSynthContext::end
int end
Definition: vaf_spectrumsynth.c:65
SpectrumSynthContext::fft
AVTXContext * fft
Fast Fourier Transform context.
Definition: vaf_spectrumsynth.c:57
pts
static int64_t pts
Definition: transcode_aac.c:653
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:373
SpectrumSynthContext::start
int start
Definition: vaf_spectrumsynth.c:65
SpectrumSynthContext::sliding
int sliding
Definition: vaf_spectrumsynth.c:51
AVRational::num
int num
Numerator.
Definition: rational.h:59
SpectrumSynthContext::window_func_lut
float * window_func_lut
Window function LUT.
Definition: vaf_spectrumsynth.c:71
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
SpectrumSynthContext::magnitude
AVFrame * magnitude
Definition: vaf_spectrumsynth.c:56
SpectrumSynthContext::sample_rate
int sample_rate
Definition: vaf_spectrumsynth.c:48
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:102
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:189
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:425
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1535
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:402
Orientation
Orientation
Definition: avf_showspectrum.c:54
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:553
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
NB_SLIDES
@ NB_SLIDES
Definition: vaf_spectrumsynth.c:43
filters.h
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:290
AV_TX_FLOAT_FFT
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type AVComplexFloat.
Definition: tx.h:45
WFUNC_RECT
@ WFUNC_RECT
Definition: window_func.h:28
ctx
AVFormatContext * ctx
Definition: movenc.c:48
channels
channels
Definition: aptx.h:33
synth_window
static void synth_window(AVFilterContext *ctx, int x)
Definition: vaf_spectrumsynth.c:331
A
#define A
Definition: vaf_spectrumsynth.c:75
f
#define f(width, name)
Definition: cbs_vp9.c:255
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:152
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:80
OFFSET
#define OFFSET(x)
Definition: vaf_spectrumsynth.c:74
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:33
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:545
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
WFUNC_HAMMING
@ WFUNC_HAMMING
Definition: af_firequalizer.c:36
parseutils.h
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:244
generate_window_func
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
Definition: window_func.h:36
WFUNC_HANNING
@ WFUNC_HANNING
Definition: window_func.h:28
WFUNC_BARTLETT
@ WFUNC_BARTLETT
Definition: window_func.h:29
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
try_push_frame
static int try_push_frame(AVFilterContext *ctx, int x)
Definition: vaf_spectrumsynth.c:355
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:1372
spectrumsynth_outputs
static const AVFilterPad spectrumsynth_outputs[]
Definition: vaf_spectrumsynth.c:537
SpectrumSynthContext::xend
int xend
Definition: vaf_spectrumsynth.c:67
VERTICAL
@ VERTICAL
Definition: vaf_spectrumsynth.c:44
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
SpectrumSynthContext::phase
AVFrame * phase
Definition: vaf_spectrumsynth.c:56
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
SpectrumSynthContext::xpos
int xpos
Definition: vaf_spectrumsynth.c:66
ff_inlink_set_status
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
Definition: avfilter.c:1543
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:117
cpu.h
spectrumsynth_inputs
static const AVFilterPad spectrumsynth_inputs[]
Definition: vaf_spectrumsynth.c:526
read_fft_data
static void read_fft_data(AVFilterContext *ctx, int x, int h, int ch)
Definition: vaf_spectrumsynth.c:285
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
SpectrumSynthContext::factor
float factor
Definition: vaf_spectrumsynth.c:69
SpectrumSynthContext::hop_size
int hop_size
Definition: vaf_spectrumsynth.c:64
height
#define height
SpectrumSynthContext::orientation
int orientation
Definition: vaf_spectrumsynth.c:54
NB_ORIENTATIONS
@ NB_ORIENTATIONS
Definition: vaf_spectrumsynth.c:44
read16_fft_bin
static void read16_fft_bin(SpectrumSynthContext *s, int x, int y, int f, int ch)
Definition: vaf_spectrumsynth.c:235
SpectrumSynthContext::win_func
int win_func
Definition: vaf_spectrumsynth.c:52
M_PI
#define M_PI
Definition: mathematics.h:52
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:213
sample_rates
sample_rates
Definition: ffmpeg_filter.c:156
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:227
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
int i
Definition: input.c:406
HORIZONTAL
@ HORIZONTAL
Definition: vaf_spectrumsynth.c:44
SpectrumSynthContext::channels
int channels
Definition: vaf_spectrumsynth.c:49
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
SpectrumSynthContext::nb_freq
int nb_freq
Definition: vaf_spectrumsynth.c:63
SpectrumSynthContext::overlap
float overlap
Definition: vaf_spectrumsynth.c:53
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
SpectrumSynthContext::tx_fn
av_tx_fn tx_fn
Definition: vaf_spectrumsynth.c:58
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:149
ret
ret
Definition: filter_design.txt:187
SpectrumSynthContext::fft_in
AVComplexFloat ** fft_in
bins holder for each (displayed) channels
Definition: vaf_spectrumsynth.c:59
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:43
NB_WFUNC
@ NB_WFUNC
Definition: af_firequalizer.c:44
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vaf_spectrumsynth.c:105
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Equivalent of av_mallocz_array().
Definition: mem.c:269
channel_layout.h
WFUNC_SINE
@ WFUNC_SINE
Definition: window_func.h:30
spectrumsynth_options
static const AVOption spectrumsynth_options[]
Definition: vaf_spectrumsynth.c:78
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
read8_fft_bin
static void read8_fft_bin(SpectrumSynthContext *s, int x, int y, int f, int ch)
Definition: vaf_spectrumsynth.c:260
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
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:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:346
factor
static const int factor[16]
Definition: vf_pp7.c:76
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
audio.h
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:450
V
#define V
Definition: vaf_spectrumsynth.c:76
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
activate
static int activate(AVFilterContext *ctx)
Definition: vaf_spectrumsynth.c:463
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:153
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
LOG
@ LOG
Definition: vaf_spectrumsynth.c:42
SpectrumSynthContext::win_size
int win_size
Definition: vaf_spectrumsynth.c:61
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
h
h
Definition: vp9dsp_template.c:2038
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:60
LINEAR
@ LINEAR
Definition: vaf_spectrumsynth.c:42
REPLACE
@ REPLACE
Definition: vaf_spectrumsynth.c:43
RSCROLL
@ RSCROLL
Definition: vaf_spectrumsynth.c:43
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vaf_spectrumsynth.c:502
NB_SCALES
@ NB_SCALES
Definition: vaf_spectrumsynth.c:42
SpectrumSynthContext::pts
int64_t pts
Definition: vaf_spectrumsynth.c:68
SlideMode
SlideMode
Definition: avf_ahistogram.c:33
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:212
tx.h