FFmpeg
af_aspectralstats.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 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/audio_fifo.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/tx.h"
27 #include "audio.h"
28 #include "avfilter.h"
29 #include "filters.h"
30 #include "internal.h"
31 #include "window_func.h"
32 
33 typedef struct ChannelSpectralStats {
34  float mean;
35  float variance;
36  float centroid;
37  float spread;
38  float skewness;
39  float kurtosis;
40  float entropy;
41  float flatness;
42  float crest;
43  float flux;
44  float slope;
45  float decrease;
46  float rolloff;
48 
49 typedef struct AudioSpectralStatsContext {
50  const AVClass *class;
51  int win_size;
52  int win_func;
53  float overlap;
55  int hop_size;
59  int64_t pts;
60  int eof;
65  float **prev_magnitude;
66  float **magnitude;
68 
69 #define OFFSET(x) offsetof(AudioSpectralStatsContext, x)
70 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
71 
72 static const AVOption aspectralstats_options[] = {
73  { "win_size", "set the window size", OFFSET(win_size), AV_OPT_TYPE_INT, {.i64=2048}, 32, 65536, A },
74  WIN_FUNC_OPTION("win_func", OFFSET(win_func), A, WFUNC_HANNING),
75  { "overlap", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, A },
76  { NULL }
77 };
78 
79 AVFILTER_DEFINE_CLASS(aspectralstats);
80 
81 static int config_output(AVFilterLink *outlink)
82 {
83  AudioSpectralStatsContext *s = outlink->src->priv;
84  float overlap, scale;
85  int ret;
86 
87  s->nb_channels = outlink->channels;
88  s->fifo = av_audio_fifo_alloc(outlink->format, s->nb_channels, s->win_size);
89  if (!s->fifo)
90  return AVERROR(ENOMEM);
91 
92  s->window_func_lut = av_realloc_f(s->window_func_lut, s->win_size,
93  sizeof(*s->window_func_lut));
94  if (!s->window_func_lut)
95  return AVERROR(ENOMEM);
96  generate_window_func(s->window_func_lut, s->win_size, s->win_func, &overlap);
97  if (s->overlap == 1.f)
98  s->overlap = overlap;
99 
100  s->hop_size = s->win_size * (1.f - s->overlap);
101  if (s->hop_size <= 0)
102  return AVERROR(EINVAL);
103 
104  s->stats = av_calloc(s->nb_channels, sizeof(*s->stats));
105  if (!s->stats)
106  return AVERROR(ENOMEM);
107 
108  s->fft = av_calloc(s->nb_channels, sizeof(*s->fft));
109  if (!s->fft)
110  return AVERROR(ENOMEM);
111 
112  s->magnitude = av_calloc(s->nb_channels, sizeof(*s->magnitude));
113  if (!s->magnitude)
114  return AVERROR(ENOMEM);
115 
116  s->prev_magnitude = av_calloc(s->nb_channels, sizeof(*s->prev_magnitude));
117  if (!s->prev_magnitude)
118  return AVERROR(ENOMEM);
119 
120  s->fft_in = av_calloc(s->nb_channels, sizeof(*s->fft_in));
121  if (!s->fft_in)
122  return AVERROR(ENOMEM);
123 
124  s->fft_out = av_calloc(s->nb_channels, sizeof(*s->fft_out));
125  if (!s->fft_out)
126  return AVERROR(ENOMEM);
127 
128  for (int ch = 0; ch < s->nb_channels; ch++) {
129  ret = av_tx_init(&s->fft[ch], &s->tx_fn, AV_TX_FLOAT_FFT, 0, s->win_size, &scale, 0);
130  if (ret < 0)
131  return ret;
132 
133  s->fft_in[ch] = av_calloc(s->win_size, sizeof(**s->fft_in));
134  if (!s->fft_in[ch])
135  return AVERROR(ENOMEM);
136 
137  s->fft_out[ch] = av_calloc(s->win_size, sizeof(**s->fft_out));
138  if (!s->fft_out[ch])
139  return AVERROR(ENOMEM);
140 
141  s->magnitude[ch] = av_calloc(s->win_size, sizeof(**s->magnitude));
142  if (!s->magnitude[ch])
143  return AVERROR(ENOMEM);
144 
145  s->prev_magnitude[ch] = av_calloc(s->win_size, sizeof(**s->prev_magnitude));
146  if (!s->prev_magnitude[ch])
147  return AVERROR(ENOMEM);
148  }
149 
150  return 0;
151 }
152 
153 static void set_meta(AVDictionary **metadata, int chan, const char *key,
154  const char *fmt, float val)
155 {
156  uint8_t value[128];
157  uint8_t key2[128];
158 
159  snprintf(value, sizeof(value), fmt, val);
160  if (chan)
161  snprintf(key2, sizeof(key2), "lavfi.aspectralstats.%d.%s", chan, key);
162  else
163  snprintf(key2, sizeof(key2), "lavfi.aspectralstats.%s", key);
164  av_dict_set(metadata, key2, value, 0);
165 }
166 
168 {
169  for (int ch = 0; ch < s->nb_channels; ch++) {
170  ChannelSpectralStats *stats = &s->stats[ch];
171 
172  set_meta(metadata, ch + 1, "mean", "%g", stats->mean);
173  set_meta(metadata, ch + 1, "variance", "%g", stats->variance);
174  set_meta(metadata, ch + 1, "centroid", "%g", stats->centroid);
175  set_meta(metadata, ch + 1, "spread", "%g", stats->spread);
176  set_meta(metadata, ch + 1, "skewness", "%g", stats->skewness);
177  set_meta(metadata, ch + 1, "kurtosis", "%g", stats->kurtosis);
178  set_meta(metadata, ch + 1, "entropy", "%g", stats->entropy);
179  set_meta(metadata, ch + 1, "flatness", "%g", stats->flatness);
180  set_meta(metadata, ch + 1, "crest", "%g", stats->crest);
181  set_meta(metadata, ch + 1, "flux", "%g", stats->flux);
182  set_meta(metadata, ch + 1, "slope", "%g", stats->slope);
183  set_meta(metadata, ch + 1, "decrease", "%g", stats->decrease);
184  set_meta(metadata, ch + 1, "rolloff", "%g", stats->rolloff);
185  }
186 }
187 
188 static float spectral_mean(const float *const spectral, int size, int max_freq)
189 {
190  float sum = 0.f;
191 
192  for (int n = 0; n < size; n++)
193  sum += spectral[n];
194 
195  return sum / size;
196 }
197 
198 static float sqrf(float a)
199 {
200  return a * a;
201 }
202 
203 static float spectral_variance(const float *const spectral, int size, int max_freq, float mean)
204 {
205  float sum = 0.f;
206 
207  for (int n = 0; n < size; n++)
208  sum += sqrf(spectral[n] - mean);
209 
210  return sum / size;
211 }
212 
213 static float spectral_centroid(const float *const spectral, int size, int max_freq)
214 {
215  const float scale = max_freq / (float)size;
216  float num = 0.f, den = 0.f;
217 
218  for (int n = 0; n < size; n++) {
219  num += spectral[n] * n * scale;
220  den += spectral[n];
221  }
222 
223  if (den <= FLT_EPSILON)
224  return 1.f;
225  return num / den;
226 }
227 
228 static float spectral_spread(const float *const spectral, int size, int max_freq, float centroid)
229 {
230  const float scale = max_freq / (float)size;
231  float num = 0.f, den = 0.f;
232 
233  for (int n = 0; n < size; n++) {
234  num += spectral[n] * sqrf(n * scale - centroid);
235  den += spectral[n];
236  }
237 
238  if (den <= FLT_EPSILON)
239  return 1.f;
240  return sqrtf(num / den);
241 }
242 
243 static float cbrf(float a)
244 {
245  return a * a * a;
246 }
247 
248 static float spectral_skewness(const float *const spectral, int size, int max_freq, float centroid, float spread)
249 {
250  const float scale = max_freq / (float)size;
251  float num = 0.f, den = 0.f;
252 
253  for (int n = 0; n < size; n++) {
254  num += spectral[n] * cbrf(n * scale - centroid);
255  den += spectral[n];
256  }
257 
258  den *= cbrf(spread);
259  if (den <= FLT_EPSILON)
260  return 1.f;
261  return num / den;
262 }
263 
264 static float spectral_kurtosis(const float *const spectral, int size, int max_freq, float centroid, float spread)
265 {
266  const float scale = max_freq / (float)size;
267  float num = 0.f, den = 0.f;
268 
269  for (int n = 0; n < size; n++) {
270  num += spectral[n] * sqrf(sqrf(n * scale - centroid));
271  den += spectral[n];
272  }
273 
274  den *= sqrf(sqrf(spread));
275  if (den <= FLT_EPSILON)
276  return 1.f;
277  return num / den;
278 }
279 
280 static float spectral_entropy(const float *const spectral, int size, int max_freq)
281 {
282  float num = 0.f, den = 0.f;
283 
284  for (int n = 0; n < size; n++) {
285  num += spectral[n] * logf(spectral[n] + FLT_EPSILON);
286  }
287 
288  den = logf(size);
289  if (den <= FLT_EPSILON)
290  return 1.f;
291  return -num / den;
292 }
293 
294 static float spectral_flatness(const float *const spectral, int size, int max_freq)
295 {
296  float num = 0.f, den = 0.f;
297 
298  for (int n = 0; n < size; n++) {
299  float v = FLT_EPSILON + spectral[n];
300  num += logf(v);
301  den += v;
302  }
303 
304  num /= size;
305  den /= size;
306  num = expf(num);
307  if (den <= FLT_EPSILON)
308  return 0.f;
309  return num / den;
310 }
311 
312 static float spectral_crest(const float *const spectral, int size, int max_freq)
313 {
314  float max = 0.f, mean = 0.f;
315 
316  for (int n = 0; n < size; n++) {
317  max = fmaxf(max, spectral[n]);
318  mean += spectral[n];
319  }
320 
321  mean /= size;
322  if (mean <= FLT_EPSILON)
323  return 0.f;
324  return max / mean;
325 }
326 
327 static float spectral_flux(const float *const spectral, const float *const prev_spectral,
328  int size, int max_freq)
329 {
330  float sum = 0.f;
331 
332  for (int n = 0; n < size; n++)
333  sum += sqrf(spectral[n] - prev_spectral[n]);
334 
335  return sqrtf(sum);
336 }
337 
338 static float spectral_slope(const float *const spectral, int size, int max_freq)
339 {
340  const float mean_freq = size * 0.5f;
341  float mean_spectral = 0.f, num = 0.f, den = 0.f;
342 
343  for (int n = 0; n < size; n++)
344  mean_spectral += spectral[n];
345  mean_spectral /= size;
346 
347  for (int n = 0; n < size; n++) {
348  num += ((n - mean_freq) / mean_freq) * (spectral[n] - mean_spectral);
349  den += sqrf((n - mean_freq) / mean_freq);
350  }
351 
352  if (fabsf(den) <= FLT_EPSILON)
353  return 0.f;
354  return num / den;
355 }
356 
357 static float spectral_decrease(const float *const spectral, int size, int max_freq)
358 {
359  float num = 0.f, den = 0.f;
360 
361  for (int n = 1; n < size; n++) {
362  num += (spectral[n] - spectral[0]) / n;
363  den += spectral[n];
364  }
365 
366  if (den <= FLT_EPSILON)
367  return 0.f;
368  return num / den;
369 }
370 
371 static float spectral_rolloff(const float *const spectral, int size, int max_freq)
372 {
373  const float scale = max_freq / (float)size;
374  float norm = 0.f, sum = 0.f;
375  int idx = 0.f;
376 
377  for (int n = 0; n < size; n++)
378  norm += spectral[n];
379  norm *= 0.85f;
380 
381  for (int n = 0; n < size; n++) {
382  sum += spectral[n];
383  if (sum >= norm) {
384  idx = n;
385  break;
386  }
387  }
388 
389  return idx * scale;
390 }
391 
392 static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
393 {
395  AVFrame *in = arg;
396  const int channels = s->nb_channels;
397  const int samples = in->nb_samples;
398  const int start = (channels * jobnr) / nb_jobs;
399  const int end = (channels * (jobnr+1)) / nb_jobs;
400 
401  for (int ch = start; ch < end; ch++) {
402  const float *const src = (const float *const)in->extended_data[ch];
403  ChannelSpectralStats *stats = &s->stats[ch];
404  AVComplexFloat *fft_out = s->fft_out[ch];
405  AVComplexFloat *fft_in = s->fft_in[ch];
406  float *magnitude = s->magnitude[ch];
407  float *prev_magnitude = s->prev_magnitude[ch];
408  const float scale = 1.f / s->win_size;
409 
410  for (int n = 0; n < samples; n++) {
411  fft_in[n].re = src[n] * s->window_func_lut[n];
412  fft_in[n].im = 0;
413  }
414 
415  for (int n = in->nb_samples; n < s->win_size; n++) {
416  fft_in[n].re = 0;
417  fft_in[n].im = 0;
418  }
419 
420  s->tx_fn(s->fft[ch], fft_out, fft_in, sizeof(float));
421 
422  for (int n = 0; n < s->win_size / 2; n++) {
423  fft_out[n].re *= scale;
424  fft_out[n].im *= scale;
425  }
426 
427  for (int n = 0; n < s->win_size / 2; n++)
428  magnitude[n] = hypotf(fft_out[n].re, fft_out[n].im);
429 
430  stats->mean = spectral_mean(magnitude, s->win_size / 2, in->sample_rate / 2);
431  stats->variance = spectral_variance(magnitude, s->win_size / 2, in->sample_rate / 2, stats->mean);
432  stats->centroid = spectral_centroid(magnitude, s->win_size / 2, in->sample_rate / 2);
433  stats->spread = spectral_spread(magnitude, s->win_size / 2, in->sample_rate / 2, stats->centroid);
434  stats->skewness = spectral_skewness(magnitude, s->win_size / 2, in->sample_rate / 2, stats->centroid, stats->spread);
435  stats->kurtosis = spectral_kurtosis(magnitude, s->win_size / 2, in->sample_rate / 2, stats->centroid, stats->spread);
436  stats->entropy = spectral_entropy(magnitude, s->win_size / 2, in->sample_rate / 2);
437  stats->flatness = spectral_flatness(magnitude, s->win_size / 2, in->sample_rate / 2);
438  stats->crest = spectral_crest(magnitude, s->win_size / 2, in->sample_rate / 2);
439  stats->flux = spectral_flux(magnitude, prev_magnitude, s->win_size / 2, in->sample_rate / 2);
440  stats->slope = spectral_slope(magnitude, s->win_size / 2, in->sample_rate / 2);
441  stats->decrease = spectral_decrease(magnitude, s->win_size / 2, in->sample_rate / 2);
442  stats->rolloff = spectral_rolloff(magnitude, s->win_size / 2, in->sample_rate / 2);
443 
444  memcpy(prev_magnitude, magnitude, s->win_size * sizeof(float));
445  }
446 
447  return 0;
448 }
449 
451 {
452  AVFilterContext *ctx = inlink->dst;
453  AVFilterLink *outlink = ctx->outputs[0];
455  AVDictionary **metadata;
456  AVFrame *out, *in = NULL;
457  int ret = 0;
458 
459  out = ff_get_audio_buffer(outlink, s->hop_size);
460  if (!out) {
461  ret = AVERROR(ENOMEM);
462  goto fail;
463  }
464 
465  if (!in) {
466  in = ff_get_audio_buffer(outlink, s->win_size);
467  if (!in)
468  return AVERROR(ENOMEM);
469  }
470 
471  ret = av_audio_fifo_peek(s->fifo, (void **)in->extended_data, s->win_size);
472  if (ret < 0)
473  goto fail;
474 
475  metadata = &out->metadata;
478 
479  set_metadata(s, metadata);
480 
481  out->pts = s->pts;
482  s->pts += av_rescale_q(s->hop_size, (AVRational){1, outlink->sample_rate}, outlink->time_base);
483 
484  av_audio_fifo_read(s->fifo, (void **)out->extended_data, s->hop_size);
485 
486  av_frame_free(&in);
487  return ff_filter_frame(outlink, out);
488 fail:
489  av_frame_free(&in);
490  return ret < 0 ? ret : 0;
491 }
492 
494 {
495  AVFilterLink *inlink = ctx->inputs[0];
496  AVFilterLink *outlink = ctx->outputs[0];
498  AVFrame *in = NULL;
499  int ret = 0, status;
500  int64_t pts;
501 
503 
504  if (!s->eof && av_audio_fifo_size(s->fifo) < s->win_size) {
506  if (ret < 0)
507  return ret;
508 
509  if (ret > 0) {
510  ret = av_audio_fifo_write(s->fifo, (void **)in->extended_data,
511  in->nb_samples);
512  if (ret >= 0 && s->pts == AV_NOPTS_VALUE)
513  s->pts = in->pts;
514 
515  av_frame_free(&in);
516  if (ret < 0)
517  return ret;
518  }
519  }
520 
521  if ((av_audio_fifo_size(s->fifo) >= s->win_size) ||
522  (av_audio_fifo_size(s->fifo) > 0 && s->eof)) {
524  if (av_audio_fifo_size(s->fifo) >= s->win_size)
525  ff_filter_set_ready(ctx, 100);
526  return ret;
527  }
528 
529  if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) {
530  if (status == AVERROR_EOF) {
531  s->eof = 1;
532  if (av_audio_fifo_size(s->fifo) >= 0) {
533  ff_filter_set_ready(ctx, 100);
534  return 0;
535  }
536  }
537  }
538 
539  if (s->eof && av_audio_fifo_size(s->fifo) <= 0) {
540  ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
541  return 0;
542  }
543 
544  if (!s->eof)
546 
547  return FFERROR_NOT_READY;
548 }
549 
551 {
553 
554  for (int ch = 0; ch < s->nb_channels; ch++) {
555  if (s->fft)
556  av_tx_uninit(&s->fft[ch]);
557  if (s->fft_in)
558  av_freep(&s->fft_in[ch]);
559  if (s->fft_out)
560  av_freep(&s->fft_out[ch]);
561  if (s->magnitude)
562  av_freep(&s->magnitude[ch]);
563  if (s->prev_magnitude)
564  av_freep(&s->prev_magnitude[ch]);
565  }
566 
567  av_freep(&s->fft);
568  av_freep(&s->magnitude);
569  av_freep(&s->prev_magnitude);
570  av_freep(&s->fft_in);
571  av_freep(&s->fft_out);
572  av_freep(&s->stats);
573 
574  av_freep(&s->window_func_lut);
575  av_audio_fifo_free(s->fifo);
576  s->fifo = NULL;
577 }
578 
580  {
581  .name = "default",
582  .type = AVMEDIA_TYPE_AUDIO,
583  },
584 };
585 
587  {
588  .name = "default",
589  .type = AVMEDIA_TYPE_AUDIO,
590  .config_props = config_output,
591  },
592 };
593 
595  .name = "aspectralstats",
596  .description = NULL_IF_CONFIG_SMALL("Show frequency domain statistics about audio frames."),
597  .priv_size = sizeof(AudioSpectralStatsContext),
598  .priv_class = &aspectralstats_class,
599  .uninit = uninit,
600  .activate = activate,
605 };
av_audio_fifo_free
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
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
ChannelSpectralStats::slope
float slope
Definition: af_aspectralstats.c:44
status
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
spectral_mean
static float spectral_mean(const float *const spectral, int size, int max_freq)
Definition: af_aspectralstats.c:188
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
out
FILE * out
Definition: movenc.c:54
AudioSpectralStatsContext::pts
int64_t pts
Definition: af_aspectralstats.c:59
stats
static void stats(AVPacket *const *in, int n_in, unsigned *_max, unsigned *_sum)
Definition: vp9_superframe_bsf.c:34
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
AudioSpectralStatsContext
Definition: af_aspectralstats.c:49
AVTXContext
Definition: tx_priv.h:110
FILTER_SINGLE_SAMPLEFMT
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
Definition: internal.h:184
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
AudioSpectralStatsContext::prev_magnitude
float ** prev_magnitude
Definition: af_aspectralstats.c:65
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:109
im
float im
Definition: fft.c:78
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:424
AVOption
AVOption.
Definition: opt.h:247
expf
#define expf(x)
Definition: libm.h:283
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
max
#define max(a, b)
Definition: cuda_runtime.h:33
AVDictionary
Definition: dict.c:30
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:169
aspectralstats_outputs
static const AVFilterPad aspectralstats_outputs[]
Definition: af_aspectralstats.c:586
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
spectral_entropy
static float spectral_entropy(const float *const spectral, int size, int max_freq)
Definition: af_aspectralstats.c:280
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
AudioSpectralStatsContext::fft_out
AVComplexFloat ** fft_out
Definition: af_aspectralstats.c:64
AVAudioFifo
Context for an Audio FIFO Buffer.
Definition: audio_fifo.c:34
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:417
AudioSpectralStatsContext::fifo
AVAudioFifo * fifo
Definition: af_aspectralstats.c:57
fail
#define fail()
Definition: checkasm.h:127
spectral_variance
static float spectral_variance(const float *const spectral, int size, int max_freq, float mean)
Definition: af_aspectralstats.c:203
AudioSpectralStatsContext::magnitude
float ** magnitude
Definition: af_aspectralstats.c:66
AudioSpectralStatsContext::tx_fn
av_tx_fn tx_fn
Definition: af_aspectralstats.c:61
val
static double val(void *priv, double ch)
Definition: aeval.c:76
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1388
pts
static int64_t pts
Definition: transcode_aac.c:653
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
ChannelSpectralStats::decrease
float decrease
Definition: af_aspectralstats.c:45
ff_af_aspectralstats
const AVFilter ff_af_aspectralstats
Definition: af_aspectralstats.c:594
ChannelSpectralStats::kurtosis
float kurtosis
Definition: af_aspectralstats.c:39
spectral_crest
static float spectral_crest(const float *const spectral, int size, int max_freq)
Definition: af_aspectralstats.c:312
av_cold
#define av_cold
Definition: attributes.h:90
filter_channel
static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: af_aspectralstats.c:392
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
spectral_flatness
static float spectral_flatness(const float *const spectral, int size, int max_freq)
Definition: af_aspectralstats.c:294
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
ChannelSpectralStats::centroid
float centroid
Definition: af_aspectralstats.c:36
s
#define s(width, name)
Definition: cbs_vp9.c:257
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
AudioSpectralStatsContext::win_func
int win_func
Definition: af_aspectralstats.c:52
filters.h
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
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:141
ChannelSpectralStats
Definition: af_aspectralstats.c:33
key
const char * key
Definition: hwcontext_opencl.c:168
AudioSpectralStatsContext::overlap
float overlap
Definition: af_aspectralstats.c:53
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
arg
const char * arg
Definition: jacosubdec.c:67
AudioSpectralStatsContext::fft
AVTXContext ** fft
Definition: af_aspectralstats.c:62
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:33
spectral_slope
static float spectral_slope(const float *const spectral, int size, int max_freq)
Definition: af_aspectralstats.c:338
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
ChannelSpectralStats::spread
float spread
Definition: af_aspectralstats.c:37
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
src
#define src
Definition: vp8dsp.c:255
ChannelSpectralStats::entropy
float entropy
Definition: af_aspectralstats.c:40
ChannelSpectralStats::flatness
float flatness
Definition: af_aspectralstats.c:41
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
AudioSpectralStatsContext::eof
int eof
Definition: af_aspectralstats.c:60
aspectralstats_options
static const AVOption aspectralstats_options[]
Definition: af_aspectralstats.c:72
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
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
filter_frame
static int filter_frame(AVFilterLink *inlink)
Definition: af_aspectralstats.c:450
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
ChannelSpectralStats::skewness
float skewness
Definition: af_aspectralstats.c:38
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:494
fmaxf
float fmaxf(float, float)
size
int size
Definition: twinvq_data.h:10344
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
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
spectral_decrease
static float spectral_decrease(const float *const spectral, int size, int max_freq)
Definition: af_aspectralstats.c:357
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
activate
static int activate(AVFilterContext *ctx)
Definition: af_aspectralstats.c:493
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
spectral_centroid
static float spectral_centroid(const float *const spectral, int size, int max_freq)
Definition: af_aspectralstats.c:213
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
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_aspectralstats.c:550
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:227
spectral_rolloff
static float spectral_rolloff(const float *const spectral, int size, int max_freq)
Definition: af_aspectralstats.c:371
av_audio_fifo_read
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
Definition: audio_fifo.c:181
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:397
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:378
ChannelSpectralStats::mean
float mean
Definition: af_aspectralstats.c:34
cbrf
static float cbrf(float a)
Definition: af_aspectralstats.c:243
spectral_flux
static float spectral_flux(const float *const spectral, const float *const prev_spectral, int size, int max_freq)
Definition: af_aspectralstats.c:327
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:803
AudioSpectralStatsContext::fft_in
AVComplexFloat ** fft_in
Definition: af_aspectralstats.c:63
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ChannelSpectralStats::crest
float crest
Definition: af_aspectralstats.c:42
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
ChannelSpectralStats::flux
float flux
Definition: af_aspectralstats.c:43
ChannelSpectralStats::variance
float variance
Definition: af_aspectralstats.c:35
AVFilter
Filter definition.
Definition: avfilter.h:165
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_aspectralstats.c:81
ret
ret
Definition: filter_design.txt:187
aspectralstats_inputs
static const AVFilterPad aspectralstats_inputs[]
Definition: af_aspectralstats.c:579
window_func.h
set_meta
static void set_meta(AVDictionary **metadata, int chan, const char *key, const char *fmt, float val)
Definition: af_aspectralstats.c:153
spectral_spread
static float spectral_spread(const float *const spectral, int size, int max_freq, float centroid)
Definition: af_aspectralstats.c:228
AudioSpectralStatsContext::hop_size
int hop_size
Definition: af_aspectralstats.c:55
AudioSpectralStatsContext::nb_channels
int nb_channels
Definition: af_aspectralstats.c:54
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
mean
static float mean(const float *input, int size)
Definition: vf_nnedi.c:855
spectral_skewness
static float spectral_skewness(const float *const spectral, int size, int max_freq, float centroid, float spread)
Definition: af_aspectralstats.c:248
AVFilterContext
An instance of a filter.
Definition: avfilter.h:402
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:121
audio.h
ChannelSpectralStats::rolloff
float rolloff
Definition: af_aspectralstats.c:46
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
set_metadata
static void set_metadata(AudioSpectralStatsContext *s, AVDictionary **metadata)
Definition: af_aspectralstats.c:167
sqrf
static float sqrf(float a)
Definition: af_aspectralstats.c:198
AudioSpectralStatsContext::win_size
int win_size
Definition: af_aspectralstats.c:51
AudioSpectralStatsContext::stats
ChannelSpectralStats * stats
Definition: af_aspectralstats.c:56
A
#define A
Definition: af_aspectralstats.c:70
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(aspectralstats)
AudioSpectralStatsContext::window_func_lut
float * window_func_lut
Definition: af_aspectralstats.c:58
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:143
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
snprintf
#define snprintf
Definition: snprintf.h:34
spectral_kurtosis
static float spectral_kurtosis(const float *const spectral, int size, int max_freq, float centroid, float spread)
Definition: af_aspectralstats.c:264
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
re
float re
Definition: fft.c:78
OFFSET
#define OFFSET(x)
Definition: af_aspectralstats.c:69