FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 <math.h>
22 
23 #include "libavcodec/avfft.h"
24 #include "libavutil/audio_fifo.h"
25 #include "libavutil/avassert.h"
26 #include "libavutil/avstring.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/parseutils.h"
31 #include "audio.h"
32 #include "video.h"
33 #include "avfilter.h"
34 #include "internal.h"
35 #include "window_func.h"
36 
41 
42 typedef struct ShowFreqsContext {
43  const AVClass *class;
44  int w, h;
45  int mode;
46  int cmode;
47  int fft_bits;
48  int ascale, fscale;
49  int avg;
50  int win_func;
53  float **avg_data;
55  float overlap;
56  int hop_size;
58  int nb_freq;
59  int win_size;
60  float scale;
61  char *colors;
63  int64_t pts;
65 
66 #define OFFSET(x) offsetof(ShowFreqsContext, x)
67 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
68 
69 static const AVOption showfreqs_options[] = {
70  { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "1024x512"}, 0, 0, FLAGS },
71  { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "1024x512"}, 0, 0, FLAGS },
72  { "mode", "set display mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=BAR}, 0, NB_MODES-1, FLAGS, "mode" },
73  { "line", "show lines", 0, AV_OPT_TYPE_CONST, {.i64=LINE}, 0, 0, FLAGS, "mode" },
74  { "bar", "show bars", 0, AV_OPT_TYPE_CONST, {.i64=BAR}, 0, 0, FLAGS, "mode" },
75  { "dot", "show dots", 0, AV_OPT_TYPE_CONST, {.i64=DOT}, 0, 0, FLAGS, "mode" },
76  { "ascale", "set amplitude scale", OFFSET(ascale), AV_OPT_TYPE_INT, {.i64=AS_LOG}, 0, NB_ASCALES-1, FLAGS, "ascale" },
77  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=AS_LINEAR}, 0, 0, FLAGS, "ascale" },
78  { "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=AS_SQRT}, 0, 0, FLAGS, "ascale" },
79  { "cbrt", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64=AS_CBRT}, 0, 0, FLAGS, "ascale" },
80  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=AS_LOG}, 0, 0, FLAGS, "ascale" },
81  { "fscale", "set frequency scale", OFFSET(fscale), AV_OPT_TYPE_INT, {.i64=FS_LINEAR}, 0, NB_FSCALES-1, FLAGS, "fscale" },
82  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=FS_LINEAR}, 0, 0, FLAGS, "fscale" },
83  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=FS_LOG}, 0, 0, FLAGS, "fscale" },
84  { "rlog", "reverse logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=FS_RLOG}, 0, 0, FLAGS, "fscale" },
85  { "win_size", "set window size", OFFSET(fft_bits), AV_OPT_TYPE_INT, {.i64=11}, 4, 16, FLAGS, "fft" },
86  { "w16", 0, 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, FLAGS, "fft" },
87  { "w32", 0, 0, AV_OPT_TYPE_CONST, {.i64=5}, 0, 0, FLAGS, "fft" },
88  { "w64", 0, 0, AV_OPT_TYPE_CONST, {.i64=6}, 0, 0, FLAGS, "fft" },
89  { "w128", 0, 0, AV_OPT_TYPE_CONST, {.i64=7}, 0, 0, FLAGS, "fft" },
90  { "w256", 0, 0, AV_OPT_TYPE_CONST, {.i64=8}, 0, 0, FLAGS, "fft" },
91  { "w512", 0, 0, AV_OPT_TYPE_CONST, {.i64=9}, 0, 0, FLAGS, "fft" },
92  { "w1024", 0, 0, AV_OPT_TYPE_CONST, {.i64=10}, 0, 0, FLAGS, "fft" },
93  { "w2048", 0, 0, AV_OPT_TYPE_CONST, {.i64=11}, 0, 0, FLAGS, "fft" },
94  { "w4096", 0, 0, AV_OPT_TYPE_CONST, {.i64=12}, 0, 0, FLAGS, "fft" },
95  { "w8192", 0, 0, AV_OPT_TYPE_CONST, {.i64=13}, 0, 0, FLAGS, "fft" },
96  { "w16384", 0, 0, AV_OPT_TYPE_CONST, {.i64=14}, 0, 0, FLAGS, "fft" },
97  { "w32768", 0, 0, AV_OPT_TYPE_CONST, {.i64=15}, 0, 0, FLAGS, "fft" },
98  { "w65536", 0, 0, AV_OPT_TYPE_CONST, {.i64=16}, 0, 0, FLAGS, "fft" },
99  { "win_func", "set window function", OFFSET(win_func), AV_OPT_TYPE_INT, {.i64=WFUNC_HANNING}, 0, NB_WFUNC-1, FLAGS, "win_func" },
100  { "rect", "Rectangular", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_RECT}, 0, 0, FLAGS, "win_func" },
101  { "bartlett", "Bartlett", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BARTLETT}, 0, 0, FLAGS, "win_func" },
102  { "hanning", "Hanning", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HANNING}, 0, 0, FLAGS, "win_func" },
103  { "hamming", "Hamming", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_HAMMING}, 0, 0, FLAGS, "win_func" },
104  { "blackman", "Blackman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BLACKMAN}, 0, 0, FLAGS, "win_func" },
105  { "welch", "Welch", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_WELCH}, 0, 0, FLAGS, "win_func" },
106  { "flattop", "Flat-top", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_FLATTOP}, 0, 0, FLAGS, "win_func" },
107  { "bharris", "Blackman-Harris", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHARRIS}, 0, 0, FLAGS, "win_func" },
108  { "bnuttall", "Blackman-Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BNUTTALL}, 0, 0, FLAGS, "win_func" },
109  { "bhann", "Bartlett-Hann", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BHANN}, 0, 0, FLAGS, "win_func" },
110  { "sine", "Sine", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_SINE}, 0, 0, FLAGS, "win_func" },
111  { "nuttall", "Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL}, 0, 0, FLAGS, "win_func" },
112  { "lanczos", "Lanczos", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS}, 0, 0, FLAGS, "win_func" },
113  { "gauss", "Gauss", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS}, 0, 0, FLAGS, "win_func" },
114  { "tukey", "Tukey", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_TUKEY}, 0, 0, FLAGS, "win_func" },
115  { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=1.}, 0., 1., FLAGS },
116  { "averaging", "set time averaging", OFFSET(avg), AV_OPT_TYPE_INT, {.i64=1}, 0, INT32_MAX, FLAGS },
117  { "colors", "set channels colors", OFFSET(colors), AV_OPT_TYPE_STRING, {.str = "red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0, FLAGS },
118  { "cmode", "set channel mode", OFFSET(cmode), AV_OPT_TYPE_INT, {.i64=COMBINED}, 0, NB_CMODES-1, FLAGS, "cmode" },
119  { "combined", "show all channels in same window", 0, AV_OPT_TYPE_CONST, {.i64=COMBINED}, 0, 0, FLAGS, "cmode" },
120  { "separate", "show each channel in own window", 0, AV_OPT_TYPE_CONST, {.i64=SEPARATE}, 0, 0, FLAGS, "cmode" },
121  { NULL }
122 };
123 
124 AVFILTER_DEFINE_CLASS(showfreqs);
125 
127 {
130  AVFilterLink *inlink = ctx->inputs[0];
131  AVFilterLink *outlink = ctx->outputs[0];
133  static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
134  int ret;
135 
136  /* set input audio formats */
137  formats = ff_make_format_list(sample_fmts);
138  if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
139  return ret;
140 
141  layouts = ff_all_channel_layouts();
142  if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
143  return ret;
144 
145  formats = ff_all_samplerates();
146  if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
147  return ret;
148 
149  /* set output video format */
150  formats = ff_make_format_list(pix_fmts);
151  if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
152  return ret;
153 
154  return 0;
155 }
156 
158 {
159  ShowFreqsContext *s = ctx->priv;
160 
161  s->pts = AV_NOPTS_VALUE;
162 
163  return 0;
164 }
165 
166 static int config_output(AVFilterLink *outlink)
167 {
168  AVFilterContext *ctx = outlink->src;
169  AVFilterLink *inlink = ctx->inputs[0];
170  ShowFreqsContext *s = ctx->priv;
171  float overlap;
172  int i;
173 
174  s->nb_freq = 1 << (s->fft_bits - 1);
175  s->win_size = s->nb_freq << 1;
177  av_fft_end(s->fft);
178  s->fft = av_fft_init(s->fft_bits, 0);
179  if (!s->fft) {
180  av_log(ctx, AV_LOG_ERROR, "Unable to create FFT context. "
181  "The window size might be too high.\n");
182  return AVERROR(ENOMEM);
183  }
184 
185  /* FFT buffers: x2 for each (display) channel buffer.
186  * Note: we use free and malloc instead of a realloc-like function to
187  * make sure the buffer is aligned in memory for the FFT functions. */
188  for (i = 0; i < s->nb_channels; i++) {
189  av_freep(&s->fft_data[i]);
190  av_freep(&s->avg_data[i]);
191  }
192  av_freep(&s->fft_data);
193  av_freep(&s->avg_data);
194  s->nb_channels = inlink->channels;
195 
196  s->fft_data = av_calloc(s->nb_channels, sizeof(*s->fft_data));
197  if (!s->fft_data)
198  return AVERROR(ENOMEM);
199  s->avg_data = av_calloc(s->nb_channels, sizeof(*s->avg_data));
200  if (!s->fft_data)
201  return AVERROR(ENOMEM);
202  for (i = 0; i < s->nb_channels; i++) {
203  s->fft_data[i] = av_calloc(s->win_size, sizeof(**s->fft_data));
204  s->avg_data[i] = av_calloc(s->nb_freq, sizeof(**s->avg_data));
205  if (!s->fft_data[i] || !s->avg_data[i])
206  return AVERROR(ENOMEM);
207  }
208 
209  /* pre-calc windowing function */
211  sizeof(*s->window_func_lut));
212  if (!s->window_func_lut)
213  return AVERROR(ENOMEM);
215  if (s->overlap == 1.)
216  s->overlap = overlap;
217  s->hop_size = (1. - s->overlap) * s->win_size;
218  if (s->hop_size < 1) {
219  av_log(ctx, AV_LOG_ERROR, "overlap %f too big\n", s->overlap);
220  return AVERROR(EINVAL);
221  }
222 
223  for (s->scale = 0, i = 0; i < s->win_size; i++) {
224  s->scale += s->window_func_lut[i] * s->window_func_lut[i];
225  }
226 
227  outlink->frame_rate = av_make_q(inlink->sample_rate, s->win_size * (1.-s->overlap));
228  outlink->sample_aspect_ratio = (AVRational){1,1};
229  outlink->w = s->w;
230  outlink->h = s->h;
231 
232  s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->win_size);
233  if (!s->fifo)
234  return AVERROR(ENOMEM);
235  return 0;
236 }
237 
238 static inline void draw_dot(AVFrame *out, int x, int y, uint8_t fg[4])
239 {
240 
241  uint32_t color = AV_RL32(out->data[0] + y * out->linesize[0] + x * 4);
242 
243  if ((color & 0xffffff) != 0)
244  AV_WL32(out->data[0] + y * out->linesize[0] + x * 4, AV_RL32(fg) | color);
245  else
246  AV_WL32(out->data[0] + y * out->linesize[0] + x * 4, AV_RL32(fg));
247 }
248 
249 static int get_sx(ShowFreqsContext *s, int f)
250 {
251  switch (s->fscale) {
252  case FS_LINEAR:
253  return (s->w/(float)s->nb_freq)*f;
254  case FS_LOG:
255  return s->w-pow(s->w, (s->nb_freq-f-1)/(s->nb_freq-1.));
256  case FS_RLOG:
257  return pow(s->w, f/(s->nb_freq-1.));
258  }
259 
260  return 0;
261 }
262 
263 static float get_bsize(ShowFreqsContext *s, int f)
264 {
265  switch (s->fscale) {
266  case FS_LINEAR:
267  return s->w/(float)s->nb_freq;
268  case FS_LOG:
269  return pow(s->w, (s->nb_freq-f-1)/(s->nb_freq-1.))-
270  pow(s->w, (s->nb_freq-f-2)/(s->nb_freq-1.));
271  case FS_RLOG:
272  return pow(s->w, (f+1)/(s->nb_freq-1.))-
273  pow(s->w, f /(s->nb_freq-1.));
274  }
275 
276  return 1.;
277 }
278 
279 static inline void plot_freq(ShowFreqsContext *s, int ch,
280  double a, int f, uint8_t fg[4], int *prev_y,
281  AVFrame *out, AVFilterLink *outlink)
282 {
283  const int w = s->w;
284  const float avg = s->avg_data[ch][f];
285  const float bsize = get_bsize(s, f);
286  const int sx = get_sx(s, f);
287  int end = outlink->h;
288  int x, y, i;
289 
290  switch(s->ascale) {
291  case AS_SQRT:
292  a = 1.0 - sqrt(a);
293  break;
294  case AS_CBRT:
295  a = 1.0 - cbrt(a);
296  break;
297  case AS_LOG:
298  a = log(av_clipd(a, 1e-6, 1)) / log(1e-6);
299  break;
300  case AS_LINEAR:
301  a = 1.0 - a;
302  break;
303  }
304 
305  switch (s->cmode) {
306  case COMBINED:
307  y = a * outlink->h - 1;
308  break;
309  case SEPARATE:
310  end = (outlink->h / s->nb_channels) * (ch + 1);
311  y = (outlink->h / s->nb_channels) * ch + a * (outlink->h / s->nb_channels) - 1;
312  break;
313  default:
314  av_assert0(0);
315  }
316  if (y < 0)
317  return;
318 
319  switch (s->avg) {
320  case 0:
321  y = s->avg_data[ch][f] = !outlink->frame_count ? y : FFMIN(avg, y);
322  break;
323  case 1:
324  break;
325  default:
326  s->avg_data[ch][f] = avg + y * (y - avg) / (FFMIN(outlink->frame_count + 1, s->avg) * y);
327  y = s->avg_data[ch][f];
328  break;
329  }
330 
331  switch(s->mode) {
332  case LINE:
333  if (*prev_y == -1) {
334  *prev_y = y;
335  }
336  if (y <= *prev_y) {
337  for (x = sx + 1; x < sx + bsize && x < w; x++)
338  draw_dot(out, x, y, fg);
339  for (i = y; i <= *prev_y; i++)
340  draw_dot(out, sx, i, fg);
341  } else {
342  for (i = *prev_y; i <= y; i++)
343  draw_dot(out, sx, i, fg);
344  for (x = sx + 1; x < sx + bsize && x < w; x++)
345  draw_dot(out, x, i - 1, fg);
346  }
347  *prev_y = y;
348  break;
349  case BAR:
350  for (x = sx; x < sx + bsize && x < w; x++)
351  for (i = y; i < end; i++)
352  draw_dot(out, x, i, fg);
353  break;
354  case DOT:
355  for (x = sx; x < sx + bsize && x < w; x++)
356  draw_dot(out, x, y, fg);
357  break;
358  }
359 }
360 
361 static int plot_freqs(AVFilterLink *inlink, AVFrame *in)
362 {
363  AVFilterContext *ctx = inlink->dst;
364  AVFilterLink *outlink = ctx->outputs[0];
365  ShowFreqsContext *s = ctx->priv;
366  const int win_size = s->win_size;
367  char *colors, *color, *saveptr = NULL;
368  AVFrame *out;
369  int ch, n;
370 
371  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
372  if (!out)
373  return AVERROR(ENOMEM);
374 
375  for (n = 0; n < outlink->h; n++)
376  memset(out->data[0] + out->linesize[0] * n, 0, outlink->w * 4);
377 
378  /* fill FFT input with the number of samples available */
379  for (ch = 0; ch < s->nb_channels; ch++) {
380  const float *p = (float *)in->extended_data[ch];
381 
382  for (n = 0; n < in->nb_samples; n++) {
383  s->fft_data[ch][n].re = p[n] * s->window_func_lut[n];
384  s->fft_data[ch][n].im = 0;
385  }
386  for (; n < win_size; n++) {
387  s->fft_data[ch][n].re = 0;
388  s->fft_data[ch][n].im = 0;
389  }
390  }
391 
392  /* run FFT on each samples set */
393  for (ch = 0; ch < s->nb_channels; ch++) {
394  av_fft_permute(s->fft, s->fft_data[ch]);
395  av_fft_calc(s->fft, s->fft_data[ch]);
396  }
397 
398 #define RE(x, ch) s->fft_data[ch][x].re
399 #define IM(x, ch) s->fft_data[ch][x].im
400 #define M(a, b) (sqrt((a) * (a) + (b) * (b)))
401 
402  colors = av_strdup(s->colors);
403  if (!colors) {
404  av_frame_free(&out);
405  return AVERROR(ENOMEM);
406  }
407 
408  for (ch = 0; ch < s->nb_channels; ch++) {
409  uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
410  int prev_y = -1, f;
411  double a;
412 
413  color = av_strtok(ch == 0 ? colors : NULL, " |", &saveptr);
414  if (color)
415  av_parse_color(fg, color, -1, ctx);
416 
417  a = av_clipd(M(RE(0, ch), 0) / s->scale, 0, 1);
418  plot_freq(s, ch, a, 0, fg, &prev_y, out, outlink);
419 
420  for (f = 1; f < s->nb_freq; f++) {
421  a = av_clipd(M(RE(f, ch), IM(f, ch)) / s->scale, 0, 1);
422 
423  plot_freq(s, ch, a, f, fg, &prev_y, out, outlink);
424  }
425  }
426 
427  av_free(colors);
428  out->pts = in->pts;
429  return ff_filter_frame(outlink, out);
430 }
431 
432 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
433 {
434  AVFilterContext *ctx = inlink->dst;
435  ShowFreqsContext *s = ctx->priv;
436  AVFrame *fin = NULL;
437  int consumed = 0;
438  int ret = 0;
439 
440  if (s->pts == AV_NOPTS_VALUE)
441  s->pts = in->pts - av_audio_fifo_size(s->fifo);
442 
443  av_audio_fifo_write(s->fifo, (void **)in->extended_data, in->nb_samples);
444  while (av_audio_fifo_size(s->fifo) >= s->win_size) {
445  fin = ff_get_audio_buffer(inlink, s->win_size);
446  if (!fin) {
447  ret = AVERROR(ENOMEM);
448  goto fail;
449  }
450 
451  fin->pts = s->pts + consumed;
452  consumed += s->hop_size;
453  ret = av_audio_fifo_peek(s->fifo, (void **)fin->extended_data, s->win_size);
454  if (ret < 0)
455  goto fail;
456 
457  ret = plot_freqs(inlink, fin);
458  av_frame_free(&fin);
460  if (ret < 0)
461  goto fail;
462  }
463 
464 fail:
465  s->pts = AV_NOPTS_VALUE;
466  av_frame_free(&fin);
467  av_frame_free(&in);
468  return ret;
469 }
470 
472 {
473  ShowFreqsContext *s = ctx->priv;
474  int i;
475 
476  av_fft_end(s->fft);
477  for (i = 0; i < s->nb_channels; i++) {
478  if (s->fft_data)
479  av_freep(&s->fft_data[i]);
480  if (s->avg_data)
481  av_freep(&s->avg_data[i]);
482  }
483  av_freep(&s->fft_data);
484  av_freep(&s->avg_data);
487 }
488 
489 static const AVFilterPad showfreqs_inputs[] = {
490  {
491  .name = "default",
492  .type = AVMEDIA_TYPE_AUDIO,
493  .filter_frame = filter_frame,
494  },
495  { NULL }
496 };
497 
498 static const AVFilterPad showfreqs_outputs[] = {
499  {
500  .name = "default",
501  .type = AVMEDIA_TYPE_VIDEO,
502  .config_props = config_output,
503  },
504  { NULL }
505 };
506 
508  .name = "showfreqs",
509  .description = NULL_IF_CONFIG_SMALL("Convert input audio to a frequencies video output."),
510  .init = init,
511  .uninit = uninit,
512  .query_formats = query_formats,
513  .priv_size = sizeof(ShowFreqsContext),
514  .inputs = showfreqs_inputs,
515  .outputs = showfreqs_outputs,
516  .priv_class = &showfreqs_class,
517 };
float, planar
Definition: samplefmt.h:70
#define NULL
Definition: coverity.c:32
FFTContext * fft
Definition: avf_showfreqs.c:51
const char * s
Definition: avisynth_c.h:631
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
Definition: audio_fifo.c:60
static int plot_freqs(AVFilterLink *inlink, AVFrame *in)
This structure describes decoded (raw) audio or video data.
Definition: frame.h:181
#define av_realloc_f(p, o, n)
static av_cold int init(AVFilterContext *ctx)
AVOption.
Definition: opt.h:245
av_cold void av_fft_end(FFTContext *s)
Definition: avfft.c:48
AVFormatContext * ctx
Definition: movenc-test.c:48
Main libavfilter public API header.
#define IM(x, ch)
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
FFTSample re
Definition: avfft.h:38
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
Definition: avfft.c:38
static enum AVSampleFormat formats[]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:76
static AVRational av_make_q(int num, int den)
Create a rational.
Definition: rational.h:53
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
const char * name
Pad name.
Definition: internal.h:59
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:312
AVFilter ff_avf_showfreqs
AmplitudeScale
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:435
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1163
uint8_t
#define av_cold
Definition: attributes.h:82
mode
Definition: f_perms.c:27
AVOptions.
static const AVFilterPad showfreqs_outputs[]
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:94
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:262
static int get_sx(ShowFreqsContext *s, int f)
FFTComplex ** fft_data
Definition: avf_showfreqs.c:52
#define av_log(a,...)
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:349
A filter pad used for either input or output.
Definition: internal.h:53
static int query_formats(AVFilterContext *ctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static float get_bsize(ShowFreqsContext *s, int f)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:65
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:154
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
void * priv
private data for use by the filter
Definition: avfilter.h:319
#define cbrt
Definition: tablegen.h:35
simple assert() macros that are a bit more flexible than ISO C assert().
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
Definition: avfft.c:28
#define OFFSET(x)
Definition: avf_showfreqs.c:66
#define fail()
Definition: checkasm.h:80
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:95
Context for an Audio FIFO Buffer.
Definition: audio_fifo.c:34
AVFILTER_DEFINE_CLASS(showfreqs)
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Definition: audio_fifo.c:205
Definition: fft.h:88
audio channel layout utility functions
#define FFMIN(a, b)
Definition: common.h:96
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
int n
Definition: avisynth_c.h:547
static int config_output(AVFilterLink *outlink)
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:385
FrequencyScale
Definition: avf_showfreqs.c:39
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:401
A list of supported channel layouts.
Definition: formats.h:85
static void draw_dot(AVFrame *out, int x, int y, uint8_t fg[4])
FILE * out
Definition: movenc-test.c:54
static av_cold void uninit(AVFilterContext *ctx)
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:375
float * window_func_lut
Definition: avf_showfreqs.c:54
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:267
static const AVOption showfreqs_options[]
Definition: avf_showfreqs.c:69
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:209
FFT functions.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:141
void ff_generate_window_func(float *lut, int N, int win_func, float *overlap)
Definition: window_func.c:26
static const AVFilterPad showfreqs_inputs[]
rational number numerator/denominator
Definition: rational.h:43
const char * name
Filter name.
Definition: avfilter.h:145
offset must point to two consecutive integers
Definition: opt.h:232
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:316
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
Definition: mem.c:260
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:192
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
Definition: audio_fifo.c:113
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
Definition: audio_fifo.c:178
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:184
FFTSample im
Definition: avfft.h:38
if(ret< 0)
Definition: vf_mcdeint.c:282
ChannelMode
Definition: avf_showfreqs.c:38
#define M(a, b)
#define av_free(p)
Audio FIFO Buffer.
A list of supported formats for one end of a filter link.
Definition: formats.h:64
#define RE(x, ch)
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
Definition: audio_fifo.c:139
An instance of a filter.
Definition: avfilter.h:304
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
static void plot_freq(ShowFreqsContext *s, int ch, double a, int f, uint8_t fg[4], int *prev_y, AVFrame *out, AVFilterLink *outlink)
#define av_freep(p)
internal API functions
#define FLAGS
Definition: avf_showfreqs.c:67
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:225
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
Definition: avfft.c:43
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
AVAudioFifo * fifo
Definition: avf_showfreqs.c:62
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:235
for(j=16;j >0;--j)
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:240
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
DisplayMode