FFmpeg
avf_showfreqs.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 #include <float.h>
22 #include <math.h>
23 
24 #include "libavutil/tx.h"
25 #include "libavutil/audio_fifo.h"
26 #include "libavutil/avassert.h"
27 #include "libavutil/avstring.h"
29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/parseutils.h"
32 #include "audio.h"
33 #include "filters.h"
34 #include "video.h"
35 #include "avfilter.h"
36 #include "internal.h"
37 #include "window_func.h"
38 
44 
45 typedef struct ShowFreqsContext {
46  const AVClass *class;
47  int w, h;
48  int mode;
49  int data_mode;
50  int cmode;
51  int fft_size;
52  int ascale, fscale;
53  int avg;
54  int win_func;
59  float **avg_data;
61  float overlap;
62  float minamp;
63  int hop_size;
65  int nb_freq;
66  int win_size;
67  float scale;
68  char *colors;
70  int64_t pts;
72 
73 #define OFFSET(x) offsetof(ShowFreqsContext, x)
74 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
75 
76 static const AVOption showfreqs_options[] = {
77  { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "1024x512"}, 0, 0, FLAGS },
78  { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "1024x512"}, 0, 0, FLAGS },
79  { "mode", "set display mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=BAR}, 0, NB_MODES-1, FLAGS, "mode" },
80  { "line", "show lines", 0, AV_OPT_TYPE_CONST, {.i64=LINE}, 0, 0, FLAGS, "mode" },
81  { "bar", "show bars", 0, AV_OPT_TYPE_CONST, {.i64=BAR}, 0, 0, FLAGS, "mode" },
82  { "dot", "show dots", 0, AV_OPT_TYPE_CONST, {.i64=DOT}, 0, 0, FLAGS, "mode" },
83  { "ascale", "set amplitude scale", OFFSET(ascale), AV_OPT_TYPE_INT, {.i64=AS_LOG}, 0, NB_ASCALES-1, FLAGS, "ascale" },
84  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=AS_LINEAR}, 0, 0, FLAGS, "ascale" },
85  { "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=AS_SQRT}, 0, 0, FLAGS, "ascale" },
86  { "cbrt", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64=AS_CBRT}, 0, 0, FLAGS, "ascale" },
87  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=AS_LOG}, 0, 0, FLAGS, "ascale" },
88  { "fscale", "set frequency scale", OFFSET(fscale), AV_OPT_TYPE_INT, {.i64=FS_LINEAR}, 0, NB_FSCALES-1, FLAGS, "fscale" },
89  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=FS_LINEAR}, 0, 0, FLAGS, "fscale" },
90  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=FS_LOG}, 0, 0, FLAGS, "fscale" },
91  { "rlog", "reverse logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=FS_RLOG}, 0, 0, FLAGS, "fscale" },
92  { "win_size", "set window size", OFFSET(fft_size), AV_OPT_TYPE_INT, {.i64=2048}, 16, 65536, FLAGS },
93  WIN_FUNC_OPTION("win_func", OFFSET(win_func), FLAGS, WFUNC_HANNING),
94  { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=1.}, 0., 1., FLAGS },
95  { "averaging", "set time averaging", OFFSET(avg), AV_OPT_TYPE_INT, {.i64=1}, 0, INT32_MAX, FLAGS },
96  { "colors", "set channels colors", OFFSET(colors), AV_OPT_TYPE_STRING, {.str = "red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0, FLAGS },
97  { "cmode", "set channel mode", OFFSET(cmode), AV_OPT_TYPE_INT, {.i64=COMBINED}, 0, NB_CMODES-1, FLAGS, "cmode" },
98  { "combined", "show all channels in same window", 0, AV_OPT_TYPE_CONST, {.i64=COMBINED}, 0, 0, FLAGS, "cmode" },
99  { "separate", "show each channel in own window", 0, AV_OPT_TYPE_CONST, {.i64=SEPARATE}, 0, 0, FLAGS, "cmode" },
100  { "minamp", "set minimum amplitude", OFFSET(minamp), AV_OPT_TYPE_FLOAT, {.dbl=1e-6}, FLT_MIN, 1e-6, FLAGS },
101  { "data", "set data mode", OFFSET(data_mode), AV_OPT_TYPE_INT, {.i64=MAGNITUDE}, 0, NB_DATA-1, FLAGS, "data" },
102  { "magnitude", "show magnitude", 0, AV_OPT_TYPE_CONST, {.i64=MAGNITUDE}, 0, 0, FLAGS, "data" },
103  { "phase", "show phase", 0, AV_OPT_TYPE_CONST, {.i64=PHASE}, 0, 0, FLAGS, "data" },
104  { "delay", "show group delay",0, AV_OPT_TYPE_CONST, {.i64=DELAY}, 0, 0, FLAGS, "data" },
105  { NULL }
106 };
107 
108 AVFILTER_DEFINE_CLASS(showfreqs);
109 
111 {
114  AVFilterLink *inlink = ctx->inputs[0];
115  AVFilterLink *outlink = ctx->outputs[0];
117  static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
118  int ret;
119 
120  /* set input audio formats */
122  if ((ret = ff_formats_ref(formats, &inlink->outcfg.formats)) < 0)
123  return ret;
124 
126  if ((ret = ff_channel_layouts_ref(layouts, &inlink->outcfg.channel_layouts)) < 0)
127  return ret;
128 
130  if ((ret = ff_formats_ref(formats, &inlink->outcfg.samplerates)) < 0)
131  return ret;
132 
133  /* set output video format */
135  if ((ret = ff_formats_ref(formats, &outlink->incfg.formats)) < 0)
136  return ret;
137 
138  return 0;
139 }
140 
142 {
143  ShowFreqsContext *s = ctx->priv;
144 
145  s->pts = AV_NOPTS_VALUE;
146 
147  return 0;
148 }
149 
150 static int config_output(AVFilterLink *outlink)
151 {
152  AVFilterContext *ctx = outlink->src;
153  AVFilterLink *inlink = ctx->inputs[0];
154  ShowFreqsContext *s = ctx->priv;
155  float overlap, scale;
156  int i, ret;
157 
158  s->nb_freq = s->fft_size / 2;
159  s->win_size = s->fft_size;
160  av_audio_fifo_free(s->fifo);
161  av_tx_uninit(&s->fft);
162  ret = av_tx_init(&s->fft, &s->tx_fn, AV_TX_FLOAT_FFT, 0, s->fft_size, &scale, 0);
163  if (ret < 0) {
164  av_log(ctx, AV_LOG_ERROR, "Unable to create FFT context. "
165  "The window size might be too high.\n");
166  return ret;
167  }
168 
169  /* FFT buffers: x2 for each (display) channel buffer.
170  * Note: we use free and malloc instead of a realloc-like function to
171  * make sure the buffer is aligned in memory for the FFT functions. */
172  for (i = 0; i < s->nb_channels; i++) {
173  av_freep(&s->fft_input[i]);
174  av_freep(&s->fft_data[i]);
175  av_freep(&s->avg_data[i]);
176  }
177  av_freep(&s->fft_input);
178  av_freep(&s->fft_data);
179  av_freep(&s->avg_data);
180  s->nb_channels = inlink->channels;
181 
182  s->fft_input = av_calloc(s->nb_channels, sizeof(*s->fft_input));
183  if (!s->fft_input)
184  return AVERROR(ENOMEM);
185  s->fft_data = av_calloc(s->nb_channels, sizeof(*s->fft_data));
186  if (!s->fft_data)
187  return AVERROR(ENOMEM);
188  s->avg_data = av_calloc(s->nb_channels, sizeof(*s->avg_data));
189  if (!s->avg_data)
190  return AVERROR(ENOMEM);
191  for (i = 0; i < s->nb_channels; i++) {
192  s->fft_input[i] = av_calloc(FFALIGN(s->win_size, 512), sizeof(**s->fft_input));
193  s->fft_data[i] = av_calloc(FFALIGN(s->win_size, 512), sizeof(**s->fft_data));
194  s->avg_data[i] = av_calloc(s->nb_freq, sizeof(**s->avg_data));
195  if (!s->fft_data[i] || !s->avg_data[i] || !s->fft_input[i])
196  return AVERROR(ENOMEM);
197  }
198 
199  /* pre-calc windowing function */
200  s->window_func_lut = av_realloc_f(s->window_func_lut, s->win_size,
201  sizeof(*s->window_func_lut));
202  if (!s->window_func_lut)
203  return AVERROR(ENOMEM);
204  generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap);
205  if (s->overlap == 1.)
206  s->overlap = overlap;
207  s->hop_size = (1. - s->overlap) * s->win_size;
208  if (s->hop_size < 1) {
209  av_log(ctx, AV_LOG_ERROR, "overlap %f too big\n", s->overlap);
210  return AVERROR(EINVAL);
211  }
212 
213  for (s->scale = 0, i = 0; i < s->win_size; i++) {
214  s->scale += s->window_func_lut[i] * s->window_func_lut[i];
215  }
216 
217  outlink->frame_rate = av_make_q(inlink->sample_rate, s->win_size * (1.-s->overlap));
218  outlink->sample_aspect_ratio = (AVRational){1,1};
219  outlink->w = s->w;
220  outlink->h = s->h;
221 
222  s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->win_size);
223  if (!s->fifo)
224  return AVERROR(ENOMEM);
225  return 0;
226 }
227 
228 static inline void draw_dot(AVFrame *out, int x, int y, uint8_t fg[4])
229 {
230 
231  uint32_t color = AV_RL32(out->data[0] + y * out->linesize[0] + x * 4);
232 
233  if ((color & 0xffffff) != 0)
234  AV_WL32(out->data[0] + y * out->linesize[0] + x * 4, AV_RL32(fg) | color);
235  else
236  AV_WL32(out->data[0] + y * out->linesize[0] + x * 4, AV_RL32(fg));
237 }
238 
239 static int get_sx(ShowFreqsContext *s, int f)
240 {
241  switch (s->fscale) {
242  case FS_LINEAR:
243  return (s->w/(float)s->nb_freq)*f;
244  case FS_LOG:
245  return s->w-pow(s->w, (s->nb_freq-f-1)/(s->nb_freq-1.));
246  case FS_RLOG:
247  return pow(s->w, f/(s->nb_freq-1.));
248  }
249 
250  return 0;
251 }
252 
253 static float get_bsize(ShowFreqsContext *s, int f)
254 {
255  switch (s->fscale) {
256  case FS_LINEAR:
257  return s->w/(float)s->nb_freq;
258  case FS_LOG:
259  return pow(s->w, (s->nb_freq-f-1)/(s->nb_freq-1.))-
260  pow(s->w, (s->nb_freq-f-2)/(s->nb_freq-1.));
261  case FS_RLOG:
262  return pow(s->w, (f+1)/(s->nb_freq-1.))-
263  pow(s->w, f /(s->nb_freq-1.));
264  }
265 
266  return 1.;
267 }
268 
269 static inline void plot_freq(ShowFreqsContext *s, int ch,
270  double a, int f, uint8_t fg[4], int *prev_y,
271  AVFrame *out, AVFilterLink *outlink)
272 {
273  const int w = s->w;
274  const float min = s->minamp;
275  const float avg = s->avg_data[ch][f];
276  const float bsize = get_bsize(s, f);
277  const int sx = get_sx(s, f);
278  int end = outlink->h;
279  int x, y, i;
280 
281  switch(s->ascale) {
282  case AS_SQRT:
283  a = 1.0 - sqrt(a);
284  break;
285  case AS_CBRT:
286  a = 1.0 - cbrt(a);
287  break;
288  case AS_LOG:
289  a = log(av_clipd(a, min, 1)) / log(min);
290  break;
291  case AS_LINEAR:
292  a = 1.0 - a;
293  break;
294  }
295 
296  switch (s->cmode) {
297  case COMBINED:
298  y = a * outlink->h - 1;
299  break;
300  case SEPARATE:
301  end = (outlink->h / s->nb_channels) * (ch + 1);
302  y = (outlink->h / s->nb_channels) * ch + a * (outlink->h / s->nb_channels) - 1;
303  break;
304  default:
305  av_assert0(0);
306  }
307  if (y < 0)
308  return;
309 
310  switch (s->avg) {
311  case 0:
312  y = s->avg_data[ch][f] = !outlink->frame_count_in ? y : FFMIN(avg, y);
313  break;
314  case 1:
315  break;
316  default:
317  s->avg_data[ch][f] = avg + y * (y - avg) / (FFMIN(outlink->frame_count_in + 1, s->avg) * y);
318  y = s->avg_data[ch][f];
319  break;
320  }
321 
322  switch(s->mode) {
323  case LINE:
324  if (*prev_y == -1) {
325  *prev_y = y;
326  }
327  if (y <= *prev_y) {
328  for (x = sx + 1; x < sx + bsize && x < w; x++)
329  draw_dot(out, x, y, fg);
330  for (i = y; i <= *prev_y; i++)
331  draw_dot(out, sx, i, fg);
332  } else {
333  for (i = *prev_y; i <= y; i++)
334  draw_dot(out, sx, i, fg);
335  for (x = sx + 1; x < sx + bsize && x < w; x++)
336  draw_dot(out, x, i - 1, fg);
337  }
338  *prev_y = y;
339  break;
340  case BAR:
341  for (x = sx; x < sx + bsize && x < w; x++)
342  for (i = y; i < end; i++)
343  draw_dot(out, x, i, fg);
344  break;
345  case DOT:
346  for (x = sx; x < sx + bsize && x < w; x++)
347  draw_dot(out, x, y, fg);
348  break;
349  }
350 }
351 
353 {
354  AVFilterContext *ctx = inlink->dst;
355  AVFilterLink *outlink = ctx->outputs[0];
356  ShowFreqsContext *s = ctx->priv;
357  const int win_size = s->win_size;
358  char *colors, *color, *saveptr = NULL;
359  AVFrame *out;
360  int ch, n;
361 
362  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
363  if (!out)
364  return AVERROR(ENOMEM);
365 
366  for (n = 0; n < outlink->h; n++)
367  memset(out->data[0] + out->linesize[0] * n, 0, outlink->w * 4);
368 
369  /* fill FFT input with the number of samples available */
370  for (ch = 0; ch < s->nb_channels; ch++) {
371  const float *p = (float *)in->extended_data[ch];
372 
373  for (n = 0; n < in->nb_samples; n++) {
374  s->fft_input[ch][n].re = p[n] * s->window_func_lut[n];
375  s->fft_input[ch][n].im = 0;
376  }
377  for (; n < win_size; n++) {
378  s->fft_input[ch][n].re = 0;
379  s->fft_input[ch][n].im = 0;
380  }
381  }
382 
383  /* run FFT on each samples set */
384  for (ch = 0; ch < s->nb_channels; ch++) {
385  s->tx_fn(s->fft, s->fft_data[ch], s->fft_input[ch], sizeof(float));
386  }
387 
388 #define RE(x, ch) s->fft_data[ch][x].re
389 #define IM(x, ch) s->fft_data[ch][x].im
390 #define M(a, b) (sqrt((a) * (a) + (b) * (b)))
391 #define P(a, b) (atan2((b), (a)))
392 
393  colors = av_strdup(s->colors);
394  if (!colors) {
395  av_frame_free(&out);
396  return AVERROR(ENOMEM);
397  }
398 
399  for (ch = 0; ch < s->nb_channels; ch++) {
400  uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
401  int prev_y = -1, f;
402  double a;
403 
404  color = av_strtok(ch == 0 ? colors : NULL, " |", &saveptr);
405  if (color)
406  av_parse_color(fg, color, -1, ctx);
407 
408  switch (s->data_mode) {
409  case MAGNITUDE:
410  a = av_clipd(M(RE(0, ch), 0) / s->scale, 0, 1);
411  plot_freq(s, ch, a, 0, fg, &prev_y, out, outlink);
412 
413  for (f = 1; f < s->nb_freq; f++) {
414  a = av_clipd(M(RE(f, ch), IM(f, ch)) / s->scale, 0, 1);
415 
416  plot_freq(s, ch, a, f, fg, &prev_y, out, outlink);
417  }
418  break;
419  case PHASE:
420  a = av_clipd((M_PI + P(RE(0, ch), 0)) / (2. * M_PI), 0, 1);
421  plot_freq(s, ch, a, 0, fg, &prev_y, out, outlink);
422 
423  for (f = 1; f < s->nb_freq; f++) {
424  a = av_clipd((M_PI + P(RE(f, ch), IM(f, ch))) / (2. * M_PI), 0, 1);
425 
426  plot_freq(s, ch, a, f, fg, &prev_y, out, outlink);
427  }
428  break;
429  case DELAY:
430  plot_freq(s, ch, 0, 0, fg, &prev_y, out, outlink);
431 
432  for (f = 1; f < s->nb_freq; f++) {
433  a = av_clipd((M_PI - P(IM(f, ch) * RE(f-1, ch) - IM(f-1, ch) * RE(f, ch),
434  RE(f, ch) * RE(f-1, ch) + IM(f, ch) * IM(f-1, ch))) / (2. * M_PI), 0, 1);
435 
436  plot_freq(s, ch, a, f, fg, &prev_y, out, outlink);
437  }
438  break;
439  }
440  }
441 
442  av_free(colors);
443  out->pts = in->pts;
444  out->sample_aspect_ratio = (AVRational){1,1};
445  return ff_filter_frame(outlink, out);
446 }
447 
449 {
450  AVFilterContext *ctx = inlink->dst;
451  ShowFreqsContext *s = ctx->priv;
452  AVFrame *fin = NULL;
453  int ret = 0;
454 
455  fin = ff_get_audio_buffer(inlink, s->win_size);
456  if (!fin) {
457  ret = AVERROR(ENOMEM);
458  goto fail;
459  }
460 
461  fin->pts = s->pts;
462  s->pts += s->hop_size;
463  ret = av_audio_fifo_peek(s->fifo, (void **)fin->extended_data, s->win_size);
464  if (ret < 0)
465  goto fail;
466 
467  ret = plot_freqs(inlink, fin);
468  av_frame_free(&fin);
469  av_audio_fifo_drain(s->fifo, s->hop_size);
470 
471 fail:
472  av_frame_free(&fin);
473  return ret;
474 }
475 
477 {
478  AVFilterLink *inlink = ctx->inputs[0];
479  AVFilterLink *outlink = ctx->outputs[0];
480  ShowFreqsContext *s = ctx->priv;
481  AVFrame *in = NULL;
482  int ret = 0;
483 
485 
486  if (av_audio_fifo_size(s->fifo) < s->win_size)
487  ret = ff_inlink_consume_samples(inlink, s->win_size, s->win_size, &in);
488  if (ret < 0)
489  return ret;
490  if (ret > 0) {
491  av_audio_fifo_write(s->fifo, (void **)in->extended_data, in->nb_samples);
492  if (s->pts == AV_NOPTS_VALUE)
493  s->pts = in->pts;
494  av_frame_free(&in);
495  }
496 
497  if (av_audio_fifo_size(s->fifo) >= s->win_size) {
499  if (ret <= 0)
500  return ret;
501  }
502 
505 
506  return FFERROR_NOT_READY;
507 }
508 
510 {
511  ShowFreqsContext *s = ctx->priv;
512  int i;
513 
514  av_tx_uninit(&s->fft);
515  for (i = 0; i < s->nb_channels; i++) {
516  if (s->fft_input)
517  av_freep(&s->fft_input[i]);
518  if (s->fft_data)
519  av_freep(&s->fft_data[i]);
520  if (s->avg_data)
521  av_freep(&s->avg_data[i]);
522  }
523  av_freep(&s->fft_input);
524  av_freep(&s->fft_data);
525  av_freep(&s->avg_data);
526  av_freep(&s->window_func_lut);
527  av_audio_fifo_free(s->fifo);
528 }
529 
530 static const AVFilterPad showfreqs_inputs[] = {
531  {
532  .name = "default",
533  .type = AVMEDIA_TYPE_AUDIO,
534  },
535 };
536 
537 static const AVFilterPad showfreqs_outputs[] = {
538  {
539  .name = "default",
540  .type = AVMEDIA_TYPE_VIDEO,
541  .config_props = config_output,
542  },
543 };
544 
546  .name = "showfreqs",
547  .description = NULL_IF_CONFIG_SMALL("Convert input audio to a frequencies video output."),
548  .init = init,
549  .uninit = uninit,
550  .priv_size = sizeof(ShowFreqsContext),
551  .activate = activate,
555  .priv_class = &showfreqs_class,
556 };
av_audio_fifo_free
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
formats
formats
Definition: signature.h:48
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:98
ShowFreqsContext::tx_fn
av_tx_fn tx_fn
Definition: avf_showfreqs.c:56
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
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
ShowFreqsContext::fscale
int fscale
Definition: avf_showfreqs.c:52
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
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
out
FILE * out
Definition: movenc.c:54
M
#define M(a, b)
ShowFreqsContext::win_func
int win_func
Definition: avf_showfreqs.c:54
color
Definition: vf_paletteuse.c:599
FrequencyScale
FrequencyScale
Definition: avf_showfreqs.c:42
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
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
ShowFreqsContext::scale
float scale
Definition: avf_showfreqs.c:67
av_parse_color
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
Definition: parseutils.c:354
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
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
NB_CMODES
@ NB_CMODES
Definition: avf_showfreqs.c:41
LINE
@ LINE
Definition: avf_showfreqs.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:112
RE
#define RE(x, ch)
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:396
w
uint8_t w
Definition: llviddspenc.c:38
draw_dot
static void draw_dot(AVFrame *out, int x, int y, uint8_t fg[4])
Definition: avf_showfreqs.c:228
ShowFreqsContext::fft
AVTXContext * fft
Definition: avf_showfreqs.c:55
showfreqs_inputs
static const AVFilterPad showfreqs_inputs[]
Definition: avf_showfreqs.c:530
DELAY
@ DELAY
Definition: avf_showfreqs.c:39
AVOption
AVOption.
Definition: opt.h:247
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:168
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: avf_showfreqs.c:110
NB_ASCALES
@ NB_ASCALES
Definition: avf_showfreqs.c:43
float.h
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
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:153
ff_avf_showfreqs
const AVFilter ff_avf_showfreqs
Definition: avf_showfreqs.c:545
P
#define P(a, b)
video.h
ShowFreqsContext::w
int w
Definition: avf_showfreqs.c:47
FF_FILTER_FORWARD_STATUS_BACK
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition: filters.h:199
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
OFFSET
#define OFFSET(x)
Definition: avf_showfreqs.c:73
ShowFreqsContext::fft_data
AVComplexFloat ** fft_data
Definition: avf_showfreqs.c:58
AVAudioFifo
Context for an Audio FIFO Buffer.
Definition: audio_fifo.c:34
ShowFreqsContext::h
int h
Definition: avf_showfreqs.c:47
av_audio_fifo_drain
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
Definition: audio_fifo.c:201
fail
#define fail()
Definition: checkasm.h:127
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1377
FS_LOG
@ FS_LOG
Definition: avf_showfreqs.c:42
ChannelMode
ChannelMode
Definition: avf_showfreqs.c:41
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
cbrt
#define cbrt
Definition: tablegen.h:35
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
AmplitudeScale
AmplitudeScale
Definition: avf_ahistogram.c:32
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
BAR
@ BAR
Definition: avf_showfreqs.c:40
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
ShowFreqsContext::nb_channels
int nb_channels
Definition: avf_showfreqs.c:64
config_output
static int config_output(AVFilterLink *outlink)
Definition: avf_showfreqs.c:150
av_audio_fifo_write
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
Definition: audio_fifo.c:112
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_strtok
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
Definition: avstring.c:186
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
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
ShowFreqsContext::colors
char * colors
Definition: avf_showfreqs.c:68
ctx
AVFormatContext * ctx
Definition: movenc.c:48
filter_frame
static int filter_frame(AVFilterLink *inlink)
Definition: avf_showfreqs.c:448
FS_LINEAR
@ FS_LINEAR
Definition: avf_showfreqs.c:42
f
#define f(width, name)
Definition: cbs_vp9.c:255
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
ShowFreqsContext::fft_size
int fft_size
Definition: avf_showfreqs.c:51
if
if(ret)
Definition: filter_design.txt:179
SEPARATE
@ SEPARATE
Definition: avf_showfreqs.c:41
ShowFreqsContext::nb_freq
int nb_freq
Definition: avf_showfreqs.c:65
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:33
FLAGS
#define FLAGS
Definition: avf_showfreqs.c:74
ShowFreqsContext::fft_input
AVComplexFloat ** fft_input
Definition: avf_showfreqs.c:57
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
ff_inlink_consume_samples
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
Definition: avfilter.c:1436
NULL
#define NULL
Definition: coverity.c:32
ShowFreqsContext::cmode
int cmode
Definition: avf_showfreqs.c:50
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
av_audio_fifo_alloc
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
Definition: audio_fifo.c:59
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:234
init
static av_cold int init(AVFilterContext *ctx)
Definition: avf_showfreqs.c:141
parseutils.h
ShowFreqsContext::minamp
float minamp
Definition: avf_showfreqs.c:62
generate_window_func
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
Definition: window_func.h:60
WFUNC_HANNING
@ WFUNC_HANNING
Definition: window_func.h:28
ShowFreqsContext::ascale
int ascale
Definition: avf_showfreqs.c:52
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
ShowFreqsContext::avg_data
float ** avg_data
Definition: avf_showfreqs.c:59
ShowFreqsContext::hop_size
int hop_size
Definition: avf_showfreqs.c:63
DataMode
DataMode
Definition: avf_showfreqs.c:39
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
av_clipd
#define av_clipd
Definition: common.h:147
activate
static int activate(AVFilterContext *ctx)
Definition: avf_showfreqs.c:476
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:92
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
ShowFreqsContext::mode
int mode
Definition: avf_showfreqs.c:48
avg
#define avg(a, b, c, d)
Definition: colorspacedsp_template.c:28
plot_freqs
static int plot_freqs(AVFilterLink *inlink, AVFrame *in)
Definition: avf_showfreqs.c:352
IM
#define IM(x, ch)
ShowFreqsContext
Definition: avf_showfreqs.c:45
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
MAGNITUDE
@ MAGNITUDE
Definition: avf_showfreqs.c:39
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
ff_all_channel_layouts
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:516
av_audio_fifo_size
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Definition: audio_fifo.c:228
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
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:227
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:369
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
AS_LINEAR
@ AS_LINEAR
Definition: avf_showfreqs.c:43
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:350
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
FS_RLOG
@ FS_RLOG
Definition: avf_showfreqs.c:42
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
get_sx
static int get_sx(ShowFreqsContext *s, int f)
Definition: avf_showfreqs.c:239
audio_fifo.h
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
AVFilter
Filter definition.
Definition: avfilter.h:149
NB_MODES
@ NB_MODES
Definition: avf_showfreqs.c:40
ret
ret
Definition: filter_design.txt:187
plot_freq
static void plot_freq(ShowFreqsContext *s, int ch, double a, int f, uint8_t fg[4], int *prev_y, AVFrame *out, AVFilterLink *outlink)
Definition: avf_showfreqs.c:269
showfreqs_outputs
static const AVFilterPad showfreqs_outputs[]
Definition: avf_showfreqs.c:537
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
ShowFreqsContext::window_func_lut
float * window_func_lut
Definition: avf_showfreqs.c:60
window_func.h
NB_FSCALES
@ NB_FSCALES
Definition: avf_showfreqs.c:42
ShowFreqsContext::pts
int64_t pts
Definition: avf_showfreqs.c:70
showfreqs_options
static const AVOption showfreqs_options[]
Definition: avf_showfreqs.c:76
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:510
channel_layout.h
mode
mode
Definition: ebur128.h:83
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: avf_showfreqs.c:509
ShowFreqsContext::data_mode
int data_mode
Definition: avf_showfreqs.c:49
AVFilterContext
An instance of a filter.
Definition: avfilter.h:386
ShowFreqsContext::win_size
int win_size
Definition: avf_showfreqs.c:66
DisplayMode
DisplayMode
Definition: avf_ahistogram.c:34
ShowFreqsContext::avg
int avg
Definition: avf_showfreqs.c:53
get_bsize
static float get_bsize(ShowFreqsContext *s, int f)
Definition: avf_showfreqs.c:253
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:279
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
audio.h
NB_DATA
@ NB_DATA
Definition: avf_showfreqs.c:39
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:490
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
FF_FILTER_FORWARD_STATUS
FF_FILTER_FORWARD_STATUS(inlink, outlink)
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
AS_CBRT
@ AS_CBRT
Definition: avf_showfreqs.c:43
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
COMBINED
@ COMBINED
Definition: avf_showfreqs.c:41
PHASE
@ PHASE
Definition: avf_showfreqs.c:39
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ShowFreqsContext::fifo
AVAudioFifo * fifo
Definition: avf_showfreqs.c:69
DOT
@ DOT
Definition: avf_showfreqs.c:40
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:228
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(showfreqs)
av_audio_fifo_peek
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
Definition: audio_fifo.c:138
AS_LOG
@ AS_LOG
Definition: avf_showfreqs.c:43
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
ShowFreqsContext::overlap
float overlap
Definition: avf_showfreqs.c:61
AS_SQRT
@ AS_SQRT
Definition: avf_showfreqs.c:43
tx.h
min
float min
Definition: vorbis_enc_data.h:429