FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
avf_showspectrum.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013 Clément Bœsch
3  * Copyright (c) 2013 Rudolf Polzer <divverent@xonotic.org>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * audio to spectrum (video) transmedia filter, based on ffplay rdft showmode
25  * (by Michael Niedermayer) and lavfi/avf_showwaves (by Stefano Sabatini).
26  */
27 
28 #include <math.h>
29 
30 #include "libavcodec/avfft.h"
31 #include "libavutil/avassert.h"
33 #include "libavutil/opt.h"
34 #include "avfilter.h"
35 #include "internal.h"
36 
42 
43 typedef struct {
44  const AVClass *class;
45  int w, h;
50  int sliding; ///< 1 if sliding mode, 0 otherwise
51  int mode; ///< channel display mode
52  int color_mode; ///< display color scheme
53  int scale;
54  float saturation; ///< color saturation multiplier
55  int xpos; ///< x position (current column)
56  RDFTContext *rdft; ///< Real Discrete Fourier Transform context
57  int rdft_bits; ///< number of bits (RDFT window size = 1<<rdft_bits)
58  FFTSample **rdft_data; ///< bins holder for each (displayed) channels
59  float *window_func_lut; ///< Window function LUT
60  int win_func;
61  float *combine_buffer; ///< color combining buffer (3 * h items)
63 
64 #define OFFSET(x) offsetof(ShowSpectrumContext, x)
65 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
66 
67 static const AVOption showspectrum_options[] = {
68  { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x512"}, 0, 0, FLAGS },
69  { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "640x512"}, 0, 0, FLAGS },
70  { "slide", "set sliding mode", OFFSET(sliding), AV_OPT_TYPE_INT, {.i64 = 0}, 0, NB_SLIDES, FLAGS, "slide" },
71  { "replace", "replace old columns with new", 0, AV_OPT_TYPE_CONST, {.i64=REPLACE}, 0, 0, FLAGS, "slide" },
72  { "scroll", "scroll from right to left", 0, AV_OPT_TYPE_CONST, {.i64=SCROLL}, 0, 0, FLAGS, "slide" },
73  { "fullframe", "return full frames", 0, AV_OPT_TYPE_CONST, {.i64=FULLFRAME}, 0, 0, FLAGS, "slide" },
74  { "mode", "set channel display mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=COMBINED}, COMBINED, NB_MODES-1, FLAGS, "mode" },
75  { "combined", "combined mode", 0, AV_OPT_TYPE_CONST, {.i64=COMBINED}, 0, 0, FLAGS, "mode" },
76  { "separate", "separate mode", 0, AV_OPT_TYPE_CONST, {.i64=SEPARATE}, 0, 0, FLAGS, "mode" },
77  { "color", "set channel coloring", OFFSET(color_mode), AV_OPT_TYPE_INT, {.i64=CHANNEL}, CHANNEL, NB_CLMODES-1, FLAGS, "color" },
78  { "channel", "separate color for each channel", 0, AV_OPT_TYPE_CONST, {.i64=CHANNEL}, 0, 0, FLAGS, "color" },
79  { "intensity", "intensity based coloring", 0, AV_OPT_TYPE_CONST, {.i64=INTENSITY}, 0, 0, FLAGS, "color" },
80  { "scale", "set display scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64=SQRT}, LINEAR, NB_SCALES-1, FLAGS, "scale" },
81  { "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=SQRT}, 0, 0, FLAGS, "scale" },
82  { "cbrt", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64=CBRT}, 0, 0, FLAGS, "scale" },
83  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=LOG}, 0, 0, FLAGS, "scale" },
84  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0, 0, FLAGS, "scale" },
85  { "saturation", "color saturation multiplier", OFFSET(saturation), AV_OPT_TYPE_FLOAT, {.dbl = 1}, -10, 10, FLAGS },
86  { "win_func", "set window function", OFFSET(win_func), AV_OPT_TYPE_INT, {.i64 = WFUNC_HANN}, 0, NB_WFUNC-1, FLAGS, "win_func" },
87  { "hann", "Hann window", 0, AV_OPT_TYPE_CONST, {.i64 = WFUNC_HANN}, 0, 0, FLAGS, "win_func" },
88  { "hamming", "Hamming window", 0, AV_OPT_TYPE_CONST, {.i64 = WFUNC_HAMMING}, 0, 0, FLAGS, "win_func" },
89  { "blackman", "Blackman window", 0, AV_OPT_TYPE_CONST, {.i64 = WFUNC_BLACKMAN}, 0, 0, FLAGS, "win_func" },
90  { NULL }
91 };
92 
93 AVFILTER_DEFINE_CLASS(showspectrum);
94 
95 static const struct {
96  float a, y, u, v;
98  { 0, 0, 0, 0 },
99  { 0.13, .03587126228984074, .1573300977624594, -.02548747583751842 },
100  { 0.30, .18572281794568020, .1772436246393981, .17475554840414750 },
101  { 0.60, .28184980583656130, -.1593064119945782, .47132074554608920 },
102  { 0.73, .65830621175547810, -.3716070802232764, .24352759331252930 },
103  { 0.78, .76318535758242900, -.4307467689263783, .16866496622310430 },
104  { 0.91, .95336363636363640, -.2045454545454546, .03313636363636363 },
105  { 1, 1, 0, 0 }
106 };
107 
108 static av_cold void uninit(AVFilterContext *ctx)
109 {
110  ShowSpectrumContext *s = ctx->priv;
111  int i;
112 
114  av_rdft_end(s->rdft);
115  for (i = 0; i < s->nb_display_channels; i++)
116  av_freep(&s->rdft_data[i]);
117  av_freep(&s->rdft_data);
120 }
121 
123 {
126  AVFilterLink *inlink = ctx->inputs[0];
127  AVFilterLink *outlink = ctx->outputs[0];
129  static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_NONE };
130 
131  /* set input audio formats */
132  formats = ff_make_format_list(sample_fmts);
133  if (!formats)
134  return AVERROR(ENOMEM);
135  ff_formats_ref(formats, &inlink->out_formats);
136 
137  layouts = ff_all_channel_layouts();
138  if (!layouts)
139  return AVERROR(ENOMEM);
140  ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
141 
142  formats = ff_all_samplerates();
143  if (!formats)
144  return AVERROR(ENOMEM);
145  ff_formats_ref(formats, &inlink->out_samplerates);
146 
147  /* set output video format */
148  formats = ff_make_format_list(pix_fmts);
149  if (!formats)
150  return AVERROR(ENOMEM);
151  ff_formats_ref(formats, &outlink->in_formats);
152 
153  return 0;
154 }
155 
156 static int config_output(AVFilterLink *outlink)
157 {
158  AVFilterContext *ctx = outlink->src;
159  AVFilterLink *inlink = ctx->inputs[0];
160  ShowSpectrumContext *s = ctx->priv;
161  int i, rdft_bits, win_size, h;
162 
163  outlink->w = s->w;
164  outlink->h = s->h;
165 
166  h = (s->mode == COMBINED) ? outlink->h : outlink->h / inlink->channels;
167  s->channel_height = h;
168 
169  /* RDFT window size (precision) according to the requested output frame height */
170  for (rdft_bits = 1; 1 << rdft_bits < 2 * h; rdft_bits++);
171  win_size = 1 << rdft_bits;
172 
173  /* (re-)configuration if the video output changed (or first init) */
174  if (rdft_bits != s->rdft_bits) {
175  AVFrame *outpicref;
176 
177  av_rdft_end(s->rdft);
178  s->rdft = av_rdft_init(rdft_bits, DFT_R2C);
179  if (!s->rdft) {
180  av_log(ctx, AV_LOG_ERROR, "Unable to create RDFT context. "
181  "The window size might be too high.\n");
182  return AVERROR(EINVAL);
183  }
184  s->rdft_bits = rdft_bits;
185 
186  /* RDFT buffers: x2 for each (display) channel buffer.
187  * Note: we use free and malloc instead of a realloc-like function to
188  * make sure the buffer is aligned in memory for the FFT functions. */
189  for (i = 0; i < s->nb_display_channels; i++)
190  av_freep(&s->rdft_data[i]);
191  av_freep(&s->rdft_data);
192  s->nb_display_channels = inlink->channels;
193 
194  s->rdft_data = av_calloc(s->nb_display_channels, sizeof(*s->rdft_data));
195  if (!s->rdft_data)
196  return AVERROR(ENOMEM);
197  for (i = 0; i < s->nb_display_channels; i++) {
198  s->rdft_data[i] = av_calloc(win_size, sizeof(**s->rdft_data));
199  if (!s->rdft_data[i])
200  return AVERROR(ENOMEM);
201  }
202 
203  /* pre-calc windowing function */
204  s->window_func_lut =
205  av_realloc_f(s->window_func_lut, win_size,
206  sizeof(*s->window_func_lut));
207  if (!s->window_func_lut)
208  return AVERROR(ENOMEM);
209  switch (s->win_func) {
210  case WFUNC_NONE:
211  for (i = 0; i < win_size; i++)
212  s->window_func_lut[i] = 1.;
213  break;
214  case WFUNC_HANN:
215  for (i = 0; i < win_size; i++)
216  s->window_func_lut[i] = .5f * (1 - cos(2*M_PI*i / (win_size-1)));
217  break;
218  case WFUNC_HAMMING:
219  for (i = 0; i < win_size; i++)
220  s->window_func_lut[i] = .54f - .46f * cos(2*M_PI*i / (win_size-1));
221  break;
222  case WFUNC_BLACKMAN: {
223  for (i = 0; i < win_size; i++)
224  s->window_func_lut[i] = .42f - .5f*cos(2*M_PI*i / (win_size-1)) + .08f*cos(4*M_PI*i / (win_size-1));
225  break;
226  }
227  default:
228  av_assert0(0);
229  }
230 
231  /* prepare the initial picref buffer (black frame) */
233  s->outpicref = outpicref =
234  ff_get_video_buffer(outlink, outlink->w, outlink->h);
235  if (!outpicref)
236  return AVERROR(ENOMEM);
237  outlink->sample_aspect_ratio = (AVRational){1,1};
238  for (i = 0; i < outlink->h; i++) {
239  memset(outpicref->data[0] + i * outpicref->linesize[0], 0, outlink->w);
240  memset(outpicref->data[1] + i * outpicref->linesize[1], 128, outlink->w);
241  memset(outpicref->data[2] + i * outpicref->linesize[2], 128, outlink->w);
242  }
243  }
244 
245  if (s->xpos >= outlink->w)
246  s->xpos = 0;
247 
248  outlink->frame_rate = av_make_q(inlink->sample_rate, win_size);
249  if (s->sliding == FULLFRAME)
250  outlink->frame_rate.den *= outlink->w;
251 
252  inlink->min_samples = inlink->max_samples = inlink->partial_buf_size =
253  win_size;
254 
255  s->combine_buffer =
256  av_realloc_f(s->combine_buffer, outlink->h * 3,
257  sizeof(*s->combine_buffer));
258 
259  av_log(ctx, AV_LOG_VERBOSE, "s:%dx%d RDFT window size:%d\n",
260  s->w, s->h, win_size);
261  return 0;
262 }
263 
264 static int request_frame(AVFilterLink *outlink)
265 {
266  ShowSpectrumContext *s = outlink->src->priv;
267  AVFilterLink *inlink = outlink->src->inputs[0];
268  unsigned i;
269  int ret;
270 
271  s->req_fullfilled = 0;
272  do {
273  ret = ff_request_frame(inlink);
274  if (ret == AVERROR_EOF && s->sliding == FULLFRAME && s->xpos > 0 &&
275  s->outpicref) {
276  for (i = 0; i < outlink->h; i++) {
277  memset(s->outpicref->data[0] + i * s->outpicref->linesize[0] + s->xpos, 0, outlink->w - s->xpos);
278  memset(s->outpicref->data[1] + i * s->outpicref->linesize[1] + s->xpos, 128, outlink->w - s->xpos);
279  memset(s->outpicref->data[2] + i * s->outpicref->linesize[2] + s->xpos, 128, outlink->w - s->xpos);
280  }
281  ret = ff_filter_frame(outlink, s->outpicref);
282  s->outpicref = NULL;
283  s->req_fullfilled = 1;
284  }
285  } while (!s->req_fullfilled && ret >= 0);
286 
287  return ret;
288 }
289 
290 static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
291 {
292  int ret;
293  AVFilterContext *ctx = inlink->dst;
294  AVFilterLink *outlink = ctx->outputs[0];
295  ShowSpectrumContext *s = ctx->priv;
296  AVFrame *outpicref = s->outpicref;
297 
298  /* nb_freq contains the power of two superior or equal to the output image
299  * height (or half the RDFT window size) */
300  const int nb_freq = 1 << (s->rdft_bits - 1);
301  const int win_size = nb_freq << 1;
302  const double w = 1. / (sqrt(nb_freq) * 32768.);
303  int h = s->channel_height;
304 
305  int ch, plane, n, y;
306 
307  av_assert0(insamples->nb_samples == win_size);
308 
309  /* fill RDFT input with the number of samples available */
310  for (ch = 0; ch < s->nb_display_channels; ch++) {
311  const int16_t *p = (int16_t *)insamples->extended_data[ch];
312 
313  for (n = 0; n < win_size; n++)
314  s->rdft_data[ch][n] = p[n] * s->window_func_lut[n];
315  }
316 
317  /* run RDFT on each samples set */
318  for (ch = 0; ch < s->nb_display_channels; ch++)
319  av_rdft_calc(s->rdft, s->rdft_data[ch]);
320 
321  /* fill a new spectrum column */
322 #define RE(y, ch) s->rdft_data[ch][2 * (y) + 0]
323 #define IM(y, ch) s->rdft_data[ch][2 * (y) + 1]
324 #define MAGNITUDE(y, ch) hypot(RE(y, ch), IM(y, ch))
325 
326  /* initialize buffer for combining to black */
327  for (y = 0; y < outlink->h; y++) {
328  s->combine_buffer[3 * y ] = 0;
329  s->combine_buffer[3 * y + 1] = 127.5;
330  s->combine_buffer[3 * y + 2] = 127.5;
331  }
332 
333  for (ch = 0; ch < s->nb_display_channels; ch++) {
334  float yf, uf, vf;
335 
336  /* decide color range */
337  switch (s->mode) {
338  case COMBINED:
339  // reduce range by channel count
340  yf = 256.0f / s->nb_display_channels;
341  switch (s->color_mode) {
342  case INTENSITY:
343  uf = yf;
344  vf = yf;
345  break;
346  case CHANNEL:
347  /* adjust saturation for mixed UV coloring */
348  /* this factor is correct for infinite channels, an approximation otherwise */
349  uf = yf * M_PI;
350  vf = yf * M_PI;
351  break;
352  default:
353  av_assert0(0);
354  }
355  break;
356  case SEPARATE:
357  // full range
358  yf = 256.0f;
359  uf = 256.0f;
360  vf = 256.0f;
361  break;
362  default:
363  av_assert0(0);
364  }
365 
366  if (s->color_mode == CHANNEL) {
367  if (s->nb_display_channels > 1) {
368  uf *= 0.5 * sin((2 * M_PI * ch) / s->nb_display_channels);
369  vf *= 0.5 * cos((2 * M_PI * ch) / s->nb_display_channels);
370  } else {
371  uf = 0.0f;
372  vf = 0.0f;
373  }
374  }
375  uf *= s->saturation;
376  vf *= s->saturation;
377 
378  /* draw the channel */
379  for (y = 0; y < h; y++) {
380  int row = (s->mode == COMBINED) ? y : ch * h + y;
381  float *out = &s->combine_buffer[3 * row];
382 
383  /* get magnitude */
384  float a = w * MAGNITUDE(y, ch);
385 
386  /* apply scale */
387  switch (s->scale) {
388  case LINEAR:
389  break;
390  case SQRT:
391  a = sqrt(a);
392  break;
393  case CBRT:
394  a = cbrt(a);
395  break;
396  case LOG:
397  a = 1 - log(FFMAX(FFMIN(1, a), 1e-6)) / log(1e-6); // zero = -120dBFS
398  break;
399  default:
400  av_assert0(0);
401  }
402 
403  if (s->color_mode == INTENSITY) {
404  float y, u, v;
405  int i;
406 
407  for (i = 1; i < sizeof(intensity_color_table) / sizeof(*intensity_color_table) - 1; i++)
408  if (intensity_color_table[i].a >= a)
409  break;
410  // i now is the first item >= the color
411  // now we know to interpolate between item i - 1 and i
412  if (a <= intensity_color_table[i - 1].a) {
413  y = intensity_color_table[i - 1].y;
414  u = intensity_color_table[i - 1].u;
415  v = intensity_color_table[i - 1].v;
416  } else if (a >= intensity_color_table[i].a) {
417  y = intensity_color_table[i].y;
418  u = intensity_color_table[i].u;
419  v = intensity_color_table[i].v;
420  } else {
421  float start = intensity_color_table[i - 1].a;
422  float end = intensity_color_table[i].a;
423  float lerpfrac = (a - start) / (end - start);
424  y = intensity_color_table[i - 1].y * (1.0f - lerpfrac)
425  + intensity_color_table[i].y * lerpfrac;
426  u = intensity_color_table[i - 1].u * (1.0f - lerpfrac)
427  + intensity_color_table[i].u * lerpfrac;
428  v = intensity_color_table[i - 1].v * (1.0f - lerpfrac)
429  + intensity_color_table[i].v * lerpfrac;
430  }
431 
432  out[0] += y * yf;
433  out[1] += u * uf;
434  out[2] += v * vf;
435  } else {
436  out[0] += a * yf;
437  out[1] += a * uf;
438  out[2] += a * vf;
439  }
440  }
441  }
442 
443  /* copy to output */
444  if (s->sliding == SCROLL) {
445  for (plane = 0; plane < 3; plane++) {
446  for (y = 0; y < outlink->h; y++) {
447  uint8_t *p = outpicref->data[plane] +
448  y * outpicref->linesize[plane];
449  memmove(p, p + 1, outlink->w - 1);
450  }
451  }
452  s->xpos = outlink->w - 1;
453  }
454  for (plane = 0; plane < 3; plane++) {
455  uint8_t *p = outpicref->data[plane] +
456  (outlink->h - 1) * outpicref->linesize[plane] +
457  s->xpos;
458  for (y = 0; y < outlink->h; y++) {
459  *p = rint(FFMAX(0, FFMIN(s->combine_buffer[3 * y + plane], 255)));
460  p -= outpicref->linesize[plane];
461  }
462  }
463 
464  if (s->sliding != FULLFRAME || s->xpos == 0)
465  outpicref->pts = insamples->pts;
466 
467  s->xpos++;
468  if (s->xpos >= outlink->w)
469  s->xpos = 0;
470  if (s->sliding != FULLFRAME || s->xpos == 0) {
471  s->req_fullfilled = 1;
472  ret = ff_filter_frame(outlink, av_frame_clone(s->outpicref));
473  if (ret < 0)
474  return ret;
475  }
476 
477  return win_size;
478 }
479 
480 static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
481 {
482  AVFilterContext *ctx = inlink->dst;
483  ShowSpectrumContext *s = ctx->priv;
484  unsigned win_size = 1 << s->rdft_bits;
485  int ret = 0;
486 
487  av_assert0(insamples->nb_samples <= win_size);
488  if (insamples->nb_samples == win_size)
489  ret = plot_spectrum_column(inlink, insamples);
490 
491  av_frame_free(&insamples);
492  return ret;
493 }
494 
496  {
497  .name = "default",
498  .type = AVMEDIA_TYPE_AUDIO,
499  .filter_frame = filter_frame,
500  },
501  { NULL }
502 };
503 
505  {
506  .name = "default",
507  .type = AVMEDIA_TYPE_VIDEO,
508  .config_props = config_output,
509  .request_frame = request_frame,
510  },
511  { NULL }
512 };
513 
515  .name = "showspectrum",
516  .description = NULL_IF_CONFIG_SMALL("Convert input audio to a spectrum video output."),
517  .uninit = uninit,
518  .query_formats = query_formats,
519  .priv_size = sizeof(ShowSpectrumContext),
520  .inputs = showspectrum_inputs,
521  .outputs = showspectrum_outputs,
522  .priv_class = &showspectrum_class,
523 };
int plane
Definition: avisynth_c.h:291
#define NULL
Definition: coverity.c:32
DisplayMode
Definition: avf_showfreqs.c:36
float v
const char * s
Definition: avisynth_c.h:631
#define av_realloc_f(p, o, n)
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
static double rint(double x)
Definition: libm.h:141
AVOption.
Definition: opt.h:255
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
Main libavfilter public API header.
float * window_func_lut
Window function LUT.
static enum AVSampleFormat formats[]
static int query_formats(AVFilterContext *ctx)
static const struct @124 intensity_color_table[]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
int sliding
1 if sliding mode, 0 otherwise
static AVRational av_make_q(int num, int den)
Create a rational.
Definition: rational.h:53
RDFTContext * rdft
Real Discrete Fourier Transform context.
static const AVFilterPad showspectrum_outputs[]
int mode
channel display mode
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:69
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:641
#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:417
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1158
uint8_t
#define av_cold
Definition: attributes.h:74
mode
Definition: f_perms.c:27
static const AVOption showspectrum_options[]
AVOptions.
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:257
static int request_frame(AVFilterLink *outlink)
FFTSample ** rdft_data
bins holder for each (displayed) channels
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
SlideMode
#define av_log(a,...)
WindowFunc
Definition: avf_showfreqs.c:39
A filter pad used for either input or output.
Definition: internal.h:63
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static av_always_inline double cbrt(double x)
Definition: libm.h:52
#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:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
void * priv
private data for use by the filter
Definition: avfilter.h:654
float saturation
color saturation multiplier
float * combine_buffer
color combining buffer (3 * h items)
simple assert() macros that are a bit more flexible than ISO C assert().
#define FFMAX(a, b)
Definition: common.h:79
float FFTSample
Definition: avfft.h:35
void av_rdft_calc(RDFTContext *s, FFTSample *data)
audio channel layout utility functions
#define FFMIN(a, b)
Definition: common.h:81
float y
static const AVFilterPad showspectrum_inputs[]
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:422
ColorMode
#define FLAGS
Definition: avfft.h:72
void av_rdft_end(RDFTContext *s)
float u
int n
Definition: avisynth_c.h:547
#define MAGNITUDE(y, ch)
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:385
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:451
float a
A list of supported channel layouts.
Definition: formats.h:85
static int config_output(AVFilterLink *outlink)
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
FFT functions.
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
AVFILTER_DEFINE_CLASS(showspectrum)
rational number numerator/denominator
Definition: rational.h:43
const char * name
Filter name.
Definition: avfilter.h:474
offset must point to two consecutive integers
Definition: opt.h:232
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:209
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:379
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:182
static av_cold void uninit(AVFilterContext *ctx)
static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:77
int den
denominator
Definition: rational.h:45
int rdft_bits
number of bits (RDFT window size = 1<<rdft_bits)
A list of supported formats for one end of a filter link.
Definition: formats.h:64
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-> out
An instance of a filter.
Definition: avfilter.h:633
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
#define OFFSET(x)
#define av_freep(p)
void INT64 start
Definition: avisynth_c.h:553
signed 16 bits, planar
Definition: samplefmt.h:68
#define M_PI
Definition: mathematics.h:46
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:343
DisplayScale
AVFilter ff_avf_showspectrum
internal API functions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:215
int xpos
x position (current column)
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:225
for(j=16;j >0;--j)
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
int color_mode
display color scheme