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_OPTION("win_func", OFFSET(win_func), A, 0),
90  { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, A },
91  { "orientation", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, V, "orientation" },
92  { "vertical", NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL}, 0, 0, V, "orientation" },
93  { "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, V, "orientation" },
94  { NULL }
95 };
96 
97 AVFILTER_DEFINE_CLASS(spectrumsynth);
98 
100 {
101  SpectrumSynthContext *s = ctx->priv;
104  AVFilterLink *magnitude = ctx->inputs[0];
105  AVFilterLink *phase = ctx->inputs[1];
106  AVFilterLink *outlink = ctx->outputs[0];
108  static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16,
111  int ret, sample_rates[] = { 48000, -1 };
112 
114  if ((ret = ff_formats_ref (formats, &outlink->incfg.formats )) < 0 ||
115  (ret = ff_add_channel_layout (&layout, FF_COUNT2LAYOUT(s->channels))) < 0 ||
116  (ret = ff_channel_layouts_ref (layout , &outlink->incfg.channel_layouts)) < 0)
117  return ret;
118 
119  sample_rates[0] = s->sample_rate;
121  if (!formats)
122  return AVERROR(ENOMEM);
123  if ((ret = ff_formats_ref(formats, &outlink->incfg.samplerates)) < 0)
124  return ret;
125 
127  if (!formats)
128  return AVERROR(ENOMEM);
129  if ((ret = ff_formats_ref(formats, &magnitude->outcfg.formats)) < 0)
130  return ret;
131 
133  if (!formats)
134  return AVERROR(ENOMEM);
135  if ((ret = ff_formats_ref(formats, &phase->outcfg.formats)) < 0)
136  return ret;
137 
138  return 0;
139 }
140 
141 static int config_output(AVFilterLink *outlink)
142 {
143  AVFilterContext *ctx = outlink->src;
144  SpectrumSynthContext *s = ctx->priv;
145  int width = ctx->inputs[0]->w;
146  int height = ctx->inputs[0]->h;
147  AVRational time_base = ctx->inputs[0]->time_base;
148  AVRational frame_rate = ctx->inputs[0]->frame_rate;
149  float factor, overlap, scale;
150  int i, ch, ret;
151 
152  outlink->sample_rate = s->sample_rate;
153  outlink->time_base = (AVRational){1, s->sample_rate};
154 
155  if (width != ctx->inputs[1]->w ||
156  height != ctx->inputs[1]->h) {
158  "Magnitude and Phase sizes differ (%dx%d vs %dx%d).\n",
159  width, height,
160  ctx->inputs[1]->w, ctx->inputs[1]->h);
161  return AVERROR_INVALIDDATA;
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);
168  return AVERROR_INVALIDDATA;
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);
175  return AVERROR_INVALIDDATA;
176  }
177 
178  s->size = s->orientation == VERTICAL ? height / s->channels : width / s->channels;
179  s->xend = s->orientation == VERTICAL ? width : height;
180 
181  s->win_size = s->size * 2;
182  s->nb_freq = s->size;
183 
184  ret = av_tx_init(&s->fft, &s->tx_fn, AV_TX_FLOAT_FFT, 1, s->win_size, &scale, 0);
185  if (ret < 0) {
186  av_log(ctx, AV_LOG_ERROR, "Unable to create FFT context. "
187  "The window size might be too high.\n");
188  return ret;
189  }
190 
191  s->fft_in = av_calloc(s->channels, sizeof(*s->fft_in));
192  if (!s->fft_in)
193  return AVERROR(ENOMEM);
194  s->fft_out = av_calloc(s->channels, sizeof(*s->fft_out));
195  if (!s->fft_out)
196  return AVERROR(ENOMEM);
197 
198  for (ch = 0; ch < s->channels; ch++) {
199  s->fft_in[ch] = av_calloc(FFALIGN(s->win_size, av_cpu_max_align()), sizeof(**s->fft_in));
200  if (!s->fft_in[ch])
201  return AVERROR(ENOMEM);
202 
203  s->fft_out[ch] = av_calloc(FFALIGN(s->win_size, av_cpu_max_align()), sizeof(**s->fft_out));
204  if (!s->fft_out[ch])
205  return AVERROR(ENOMEM);
206  }
207 
208  s->buffer = ff_get_audio_buffer(outlink, s->win_size * 2);
209  if (!s->buffer)
210  return AVERROR(ENOMEM);
211 
212  /* pre-calc windowing function */
213  s->window_func_lut = av_realloc_f(s->window_func_lut, s->win_size,
214  sizeof(*s->window_func_lut));
215  if (!s->window_func_lut)
216  return AVERROR(ENOMEM);
217  generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap);
218  if (s->overlap == 1)
219  s->overlap = overlap;
220  s->hop_size = (1 - s->overlap) * s->win_size;
221  for (factor = 0, i = 0; i < s->win_size; i++) {
222  factor += s->window_func_lut[i] * s->window_func_lut[i];
223  }
224  s->factor = (factor / s->win_size) / FFMAX(1 / (1 - s->overlap) - 1, 1);
225 
226  return 0;
227 }
228 
230  int x, int y, int f, int ch)
231 {
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;
237 
238  switch (s->scale) {
239  case LINEAR:
240  magnitude = m[x] / (double)UINT16_MAX;
241  break;
242  case LOG:
243  magnitude = ff_exp10(((m[x] / (double)UINT16_MAX) - 1.) * 6.);
244  break;
245  default:
246  av_assert0(0);
247  }
248  phase = ((p[x] / (double)UINT16_MAX) * 2. - 1.) * M_PI;
249 
250  s->fft_in[ch][f].re = magnitude * cos(phase);
251  s->fft_in[ch][f].im = magnitude * sin(phase);
252 }
253 
255  int x, int y, int f, int ch)
256 {
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;
262 
263  switch (s->scale) {
264  case LINEAR:
265  magnitude = m[x] / (double)UINT8_MAX;
266  break;
267  case LOG:
268  magnitude = ff_exp10(((m[x] / (double)UINT8_MAX) - 1.) * 6.);
269  break;
270  default:
271  av_assert0(0);
272  }
273  phase = ((p[x] / (double)UINT8_MAX) * 2. - 1.) * M_PI;
274 
275  s->fft_in[ch][f].re = magnitude * cos(phase);
276  s->fft_in[ch][f].im = magnitude * sin(phase);
277 }
278 
279 static void read_fft_data(AVFilterContext *ctx, int x, int h, int ch)
280 {
281  SpectrumSynthContext *s = ctx->priv;
282  AVFilterLink *inlink = ctx->inputs[0];
283  int start = h * (s->channels - ch) - 1;
284  int end = h * (s->channels - ch - 1);
285  int y, f;
286 
287  switch (s->orientation) {
288  case VERTICAL:
289  switch (inlink->format) {
291  case AV_PIX_FMT_GRAY16:
292  for (y = start, f = 0; y >= end; y--, f++) {
293  read16_fft_bin(s, x, y, f, ch);
294  }
295  break;
296  case AV_PIX_FMT_YUVJ444P:
297  case AV_PIX_FMT_YUV444P:
298  case AV_PIX_FMT_GRAY8:
299  for (y = start, f = 0; y >= end; y--, f++) {
300  read8_fft_bin(s, x, y, f, ch);
301  }
302  break;
303  }
304  break;
305  case HORIZONTAL:
306  switch (inlink->format) {
308  case AV_PIX_FMT_GRAY16:
309  for (y = end, f = 0; y <= start; y++, f++) {
310  read16_fft_bin(s, y, x, f, ch);
311  }
312  break;
313  case AV_PIX_FMT_YUVJ444P:
314  case AV_PIX_FMT_YUV444P:
315  case AV_PIX_FMT_GRAY8:
316  for (y = end, f = 0; y <= start; y++, f++) {
317  read8_fft_bin(s, y, x, f, ch);
318  }
319  break;
320  }
321  break;
322  }
323 }
324 
325 static void synth_window(AVFilterContext *ctx, int x)
326 {
327  SpectrumSynthContext *s = ctx->priv;
328  const int h = s->size;
329  int nb = s->win_size;
330  int y, f, ch;
331 
332  for (ch = 0; ch < s->channels; ch++) {
333  read_fft_data(ctx, x, h, ch);
334 
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;
338  }
339 
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;
343  }
344 
345  s->tx_fn(s->fft, s->fft_out[ch], s->fft_in[ch], sizeof(float));
346  }
347 }
348 
349 static int try_push_frame(AVFilterContext *ctx, int x)
350 {
351  SpectrumSynthContext *s = ctx->priv;
352  AVFilterLink *outlink = ctx->outputs[0];
353  const float factor = s->factor;
354  int ch, n, i, ret;
355  int start, end;
356  AVFrame *out;
357 
358  synth_window(ctx, x);
359 
360  for (ch = 0; ch < s->channels; ch++) {
361  float *buf = (float *)s->buffer->extended_data[ch];
362  int j, k;
363 
364  start = s->start;
365  end = s->end;
366  k = end;
367  for (i = 0, j = start; j < k && i < s->win_size; i++, j++) {
368  buf[j] += s->fft_out[ch][i].re;
369  }
370 
371  for (; i < s->win_size; i++, j++) {
372  buf[j] = s->fft_out[ch][i].re;
373  }
374 
375  start += s->hop_size;
376  end = j;
377 
378  if (start >= s->win_size) {
379  start -= s->win_size;
380  end -= s->win_size;
381 
382  if (ch == s->channels - 1) {
383  float *dst;
384  int c;
385 
386  out = ff_get_audio_buffer(outlink, s->win_size);
387  if (!out) {
388  av_frame_free(&s->magnitude);
389  av_frame_free(&s->phase);
390  return AVERROR(ENOMEM);
391  }
392 
393  out->pts = s->pts;
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];
398 
399  for (n = 0; n < s->win_size; n++) {
400  dst[n] = buf[n] * factor;
401  }
402  memmove(buf, buf + s->win_size, s->win_size * 4);
403  }
404 
405  ret = ff_filter_frame(outlink, out);
406  if (ret < 0)
407  return ret;
408  }
409  }
410  }
411 
412  s->start = start;
413  s->end = end;
414 
415  return 0;
416 }
417 
419 {
420  SpectrumSynthContext *s = ctx->priv;
421  int ret, x;
422 
423  if (!(s->magnitude && s->phase))
424  return 0;
425 
426  switch (s->sliding) {
427  case REPLACE:
428  ret = try_push_frame(ctx, s->xpos);
429  s->xpos++;
430  if (s->xpos >= s->xend)
431  s->xpos = 0;
432  break;
433  case SCROLL:
434  s->xpos = s->xend - 1;
435  ret = try_push_frame(ctx, s->xpos);
436  break;
437  case RSCROLL:
438  s->xpos = 0;
439  ret = try_push_frame(ctx, s->xpos);
440  break;
441  case FULLFRAME:
442  for (x = 0; x < s->xend; x++) {
443  ret = try_push_frame(ctx, x);
444  if (ret < 0)
445  break;
446  }
447  break;
448  default:
449  av_assert0(0);
450  }
451 
452  av_frame_free(&s->magnitude);
453  av_frame_free(&s->phase);
454  return ret;
455 }
456 
458 {
459  SpectrumSynthContext *s = ctx->priv;
460  AVFrame **staging[2] = { &s->magnitude, &s->phase };
461  int64_t pts;
462  int i, ret;
463 
465 
466  for (i = 0; i < 2; i++) {
467  if (*staging[i])
468  continue;
469  ret = ff_inlink_consume_frame(ctx->inputs[i], staging[i]);
470  if (ret < 0)
471  return ret;
472  if (ret) {
474  return try_push_frames(ctx);
475  }
476  }
477 
478  for (i = 0; i < 2; i++) {
479  if (ff_inlink_acknowledge_status(ctx->inputs[i], &ret, &pts)) {
480  ff_outlink_set_status(ctx->outputs[0], ret, pts);
481  ff_inlink_set_status(ctx->inputs[1 - i], ret);
482  return 0;
483  }
484  }
485 
486  if (ff_outlink_frame_wanted(ctx->outputs[0])) {
487  for (i = 0; i < 2; i++) {
488  if (!*staging[i])
489  ff_inlink_request_frame(ctx->inputs[i]);
490  }
491  }
492 
493  return FFERROR_NOT_READY;
494 }
495 
497 {
498  SpectrumSynthContext *s = ctx->priv;
499  int i;
500 
501  av_frame_free(&s->magnitude);
502  av_frame_free(&s->phase);
503  av_frame_free(&s->buffer);
504 
505  av_tx_uninit(&s->fft);
506 
507  if (s->fft_in) {
508  for (i = 0; i < s->channels; i++)
509  av_freep(&s->fft_in[i]);
510  }
511  if (s->fft_out) {
512  for (i = 0; i < s->channels; i++)
513  av_freep(&s->fft_out[i]);
514  }
515  av_freep(&s->fft_in);
516  av_freep(&s->fft_out);
517  av_freep(&s->window_func_lut);
518 }
519 
521  {
522  .name = "magnitude",
523  .type = AVMEDIA_TYPE_VIDEO,
524  },
525  {
526  .name = "phase",
527  .type = AVMEDIA_TYPE_VIDEO,
528  },
529 };
530 
532  {
533  .name = "default",
534  .type = AVMEDIA_TYPE_AUDIO,
535  .config_props = config_output,
536  },
537 };
538 
540  .name = "spectrumsynth",
541  .description = NULL_IF_CONFIG_SMALL("Convert input spectrum videos to audio output."),
542  .uninit = uninit,
543  .activate = activate,
544  .priv_size = sizeof(SpectrumSynthContext),
548  .priv_class = &spectrumsynth_class,
549 };
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:418
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AVFilterFormatsConfig::samplerates
AVFilterFormats * samplerates
Lists of supported sample rates, only for audio.
Definition: avfilter.h:495
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:381
AVFilterFormatsConfig::channel_layouts
AVFilterChannelLayouts * channel_layouts
Lists of supported channel layouts, only for audio.
Definition: avfilter.h:500
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:1018
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:550
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
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:168
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:36
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:141
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:1417
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
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1377
pts
static int64_t pts
Definition: transcode_aac.c:653
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:375
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:426
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1534
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:404
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:555
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
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:325
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:191
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:539
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
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:60
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:349
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:1371
spectrumsynth_outputs
static const AVFilterPad spectrumsynth_outputs[]
Definition: vaf_spectrumsynth.c:531
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:1542
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:520
read_fft_data
static void read_fft_data(AVFilterContext *ctx, int x, int h, int ch)
Definition: vaf_spectrumsynth.c:279
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:229
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
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
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_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
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
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vaf_spectrumsynth.c:99
channel_layout.h
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:254
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:386
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:490
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:457
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
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:496
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:211
tx.h