FFmpeg
af_superequalizer.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 Naoki Shibata
3  * Copyright (c) 2017 Paul B Mahol
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 #include "libavutil/opt.h"
23 
24 #include "libavcodec/avfft.h"
25 
26 #include "audio.h"
27 #include "avfilter.h"
28 #include "filters.h"
29 #include "internal.h"
30 
31 #define NBANDS 17
32 #define M 15
33 
34 typedef struct EqParameter {
35  float lower, upper, gain;
36 } EqParameter;
37 
38 typedef struct SuperEqualizerContext {
39  const AVClass *class;
40 
42 
43  float gains[NBANDS + 1];
44 
45  float fact[M + 1];
46  float aa;
47  float iza;
48  float *ires, *irest;
49  float *fsamples;
51 
55 
56 static const float bands[] = {
57  65.406392, 92.498606, 130.81278, 184.99721, 261.62557, 369.99442, 523.25113, 739.9884, 1046.5023,
58  1479.9768, 2093.0045, 2959.9536, 4186.0091, 5919.9072, 8372.0181, 11839.814, 16744.036
59 };
60 
61 static float izero(SuperEqualizerContext *s, float x)
62 {
63  float ret = 1;
64  int m;
65 
66  for (m = 1; m <= M; m++) {
67  float t;
68 
69  t = pow(x / 2, m) / s->fact[m];
70  ret += t*t;
71  }
72 
73  return ret;
74 }
75 
76 static float hn_lpf(int n, float f, float fs)
77 {
78  float t = 1 / fs;
79  float omega = 2 * M_PI * f;
80 
81  if (n * omega * t == 0)
82  return 2 * f * t;
83  return 2 * f * t * sinf(n * omega * t) / (n * omega * t);
84 }
85 
86 static float hn_imp(int n)
87 {
88  return n == 0 ? 1.f : 0.f;
89 }
90 
91 static float hn(int n, EqParameter *param, float fs)
92 {
93  float ret, lhn;
94  int i;
95 
96  lhn = hn_lpf(n, param[0].upper, fs);
97  ret = param[0].gain*lhn;
98 
99  for (i = 1; i < NBANDS + 1 && param[i].upper < fs / 2; i++) {
100  float lhn2 = hn_lpf(n, param[i].upper, fs);
101  ret += param[i].gain * (lhn2 - lhn);
102  lhn = lhn2;
103  }
104 
105  ret += param[i].gain * (hn_imp(n) - lhn);
106 
107  return ret;
108 }
109 
110 static float alpha(float a)
111 {
112  if (a <= 21)
113  return 0;
114  if (a <= 50)
115  return .5842f * pow(a - 21, 0.4f) + 0.07886f * (a - 21);
116  return .1102f * (a - 8.7f);
117 }
118 
119 static float win(SuperEqualizerContext *s, float n, int N)
120 {
121  return izero(s, alpha(s->aa) * sqrtf(1 - 4 * n * n / ((N - 1) * (N - 1)))) / s->iza;
122 }
123 
124 static void process_param(float *bc, EqParameter *param, float fs)
125 {
126  int i;
127 
128  for (i = 0; i <= NBANDS; i++) {
129  param[i].lower = i == 0 ? 0 : bands[i - 1];
130  param[i].upper = i == NBANDS ? fs : bands[i];
131  param[i].gain = bc[i];
132  }
133 }
134 
135 static int equ_init(SuperEqualizerContext *s, int wb)
136 {
137  int i,j;
138 
139  s->rdft = av_rdft_init(wb, DFT_R2C);
140  s->irdft = av_rdft_init(wb, IDFT_C2R);
141  if (!s->rdft || !s->irdft)
142  return AVERROR(ENOMEM);
143 
144  s->aa = 96;
145  s->winlen = (1 << (wb-1))-1;
146  s->tabsize = 1 << wb;
147 
148  s->ires = av_calloc(s->tabsize, sizeof(float));
149  s->irest = av_calloc(s->tabsize, sizeof(float));
150  s->fsamples = av_calloc(s->tabsize, sizeof(float));
151 
152  for (i = 0; i <= M; i++) {
153  s->fact[i] = 1;
154  for (j = 1; j <= i; j++)
155  s->fact[i] *= j;
156  }
157 
158  s->iza = izero(s, alpha(s->aa));
159 
160  return 0;
161 }
162 
163 static void make_fir(SuperEqualizerContext *s, float *lbc, float *rbc, EqParameter *param, float fs)
164 {
165  const int winlen = s->winlen;
166  const int tabsize = s->tabsize;
167  float *nires;
168  int i;
169 
170  if (fs <= 0)
171  return;
172 
173  process_param(lbc, param, fs);
174  for (i = 0; i < winlen; i++)
175  s->irest[i] = hn(i - winlen / 2, param, fs) * win(s, i - winlen / 2, winlen);
176  for (; i < tabsize; i++)
177  s->irest[i] = 0;
178 
179  av_rdft_calc(s->rdft, s->irest);
180  nires = s->ires;
181  for (i = 0; i < tabsize; i++)
182  nires[i] = s->irest[i];
183 }
184 
186 {
187  AVFilterContext *ctx = inlink->dst;
188  SuperEqualizerContext *s = ctx->priv;
189  AVFilterLink *outlink = ctx->outputs[0];
190  const float *ires = s->ires;
191  float *fsamples = s->fsamples;
192  int ch, i;
193 
194  AVFrame *out = ff_get_audio_buffer(outlink, s->winlen);
195  float *src, *dst, *ptr;
196 
197  if (!out) {
198  av_frame_free(&in);
199  return AVERROR(ENOMEM);
200  }
201 
202  for (ch = 0; ch < in->channels; ch++) {
203  ptr = (float *)out->extended_data[ch];
204  dst = (float *)s->out->extended_data[ch];
205  src = (float *)in->extended_data[ch];
206 
207  for (i = 0; i < in->nb_samples; i++)
208  fsamples[i] = src[i];
209  for (; i < s->tabsize; i++)
210  fsamples[i] = 0;
211 
212  av_rdft_calc(s->rdft, fsamples);
213 
214  fsamples[0] = ires[0] * fsamples[0];
215  fsamples[1] = ires[1] * fsamples[1];
216  for (i = 1; i < s->tabsize / 2; i++) {
217  float re, im;
218 
219  re = ires[i*2 ] * fsamples[i*2] - ires[i*2+1] * fsamples[i*2+1];
220  im = ires[i*2+1] * fsamples[i*2] + ires[i*2 ] * fsamples[i*2+1];
221 
222  fsamples[i*2 ] = re;
223  fsamples[i*2+1] = im;
224  }
225 
226  av_rdft_calc(s->irdft, fsamples);
227 
228  for (i = 0; i < s->winlen; i++)
229  dst[i] += fsamples[i] / s->tabsize * 2;
230  for (i = s->winlen; i < s->tabsize; i++)
231  dst[i] = fsamples[i] / s->tabsize * 2;
232  for (i = 0; i < s->winlen; i++)
233  ptr[i] = dst[i];
234  for (i = 0; i < s->winlen; i++)
235  dst[i] = dst[i+s->winlen];
236  }
237 
238  out->pts = in->pts;
239  av_frame_free(&in);
240 
241  return ff_filter_frame(outlink, out);
242 }
243 
245 {
246  AVFilterLink *inlink = ctx->inputs[0];
247  AVFilterLink *outlink = ctx->outputs[0];
248  SuperEqualizerContext *s = ctx->priv;
249  AVFrame *in = NULL;
250  int ret;
251 
253 
254  ret = ff_inlink_consume_samples(inlink, s->winlen, s->winlen, &in);
255  if (ret < 0)
256  return ret;
257  if (ret > 0)
258  return filter_frame(inlink, in);
259 
262 
263  return FFERROR_NOT_READY;
264 }
265 
267 {
268  SuperEqualizerContext *s = ctx->priv;
269 
270  return equ_init(s, 14);
271 }
272 
274 {
277  static const enum AVSampleFormat sample_fmts[] = {
280  };
281  int ret;
282 
284  if (!layouts)
285  return AVERROR(ENOMEM);
287  if (ret < 0)
288  return ret;
289 
291  if ((ret = ff_set_common_formats(ctx, formats)) < 0)
292  return ret;
293 
296 }
297 
299 {
300  AVFilterContext *ctx = inlink->dst;
301  SuperEqualizerContext *s = ctx->priv;
302 
303  s->out = ff_get_audio_buffer(inlink, s->tabsize);
304  if (!s->out)
305  return AVERROR(ENOMEM);
306 
307  return 0;
308 }
309 
310 static int config_output(AVFilterLink *outlink)
311 {
312  AVFilterContext *ctx = outlink->src;
313  SuperEqualizerContext *s = ctx->priv;
314 
315  make_fir(s, s->gains, s->gains, s->params, outlink->sample_rate);
316 
317  return 0;
318 }
319 
321 {
322  SuperEqualizerContext *s = ctx->priv;
323 
324  av_frame_free(&s->out);
325  av_freep(&s->irest);
326  av_freep(&s->ires);
327  av_freep(&s->fsamples);
328  av_rdft_end(s->rdft);
329  av_rdft_end(s->irdft);
330 }
331 
333  {
334  .name = "default",
335  .type = AVMEDIA_TYPE_AUDIO,
336  .config_props = config_input,
337  },
338  { NULL }
339 };
340 
342  {
343  .name = "default",
344  .type = AVMEDIA_TYPE_AUDIO,
345  .config_props = config_output,
346  },
347  { NULL }
348 };
349 
350 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
351 #define OFFSET(x) offsetof(SuperEqualizerContext, x)
352 
354  { "1b", "set 65Hz band gain", OFFSET(gains [0]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
355  { "2b", "set 92Hz band gain", OFFSET(gains [1]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
356  { "3b", "set 131Hz band gain", OFFSET(gains [2]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
357  { "4b", "set 185Hz band gain", OFFSET(gains [3]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
358  { "5b", "set 262Hz band gain", OFFSET(gains [4]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
359  { "6b", "set 370Hz band gain", OFFSET(gains [5]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
360  { "7b", "set 523Hz band gain", OFFSET(gains [6]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
361  { "8b", "set 740Hz band gain", OFFSET(gains [7]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
362  { "9b", "set 1047Hz band gain", OFFSET(gains [8]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
363  { "10b", "set 1480Hz band gain", OFFSET(gains [9]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
364  { "11b", "set 2093Hz band gain", OFFSET(gains[10]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
365  { "12b", "set 2960Hz band gain", OFFSET(gains[11]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
366  { "13b", "set 4186Hz band gain", OFFSET(gains[12]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
367  { "14b", "set 5920Hz band gain", OFFSET(gains[13]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
368  { "15b", "set 8372Hz band gain", OFFSET(gains[14]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
369  { "16b", "set 11840Hz band gain", OFFSET(gains[15]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
370  { "17b", "set 16744Hz band gain", OFFSET(gains[16]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
371  { "18b", "set 20000Hz band gain", OFFSET(gains[17]), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 20, AF },
372  { NULL }
373 };
374 
375 AVFILTER_DEFINE_CLASS(superequalizer);
376 
378  .name = "superequalizer",
379  .description = NULL_IF_CONFIG_SMALL("Apply 18 band equalization filter."),
380  .priv_size = sizeof(SuperEqualizerContext),
381  .priv_class = &superequalizer_class,
383  .init = init,
384  .activate = activate,
385  .uninit = uninit,
388 };
formats
formats
Definition: signature.h:48
hn_lpf
static float hn_lpf(int n, float f, float fs)
Definition: af_superequalizer.c:76
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:86
SuperEqualizerContext::fsamples
float * fsamples
Definition: af_superequalizer.c:49
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
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_superequalizer.c:320
superequalizer_options
static const AVOption superequalizer_options[]
Definition: af_superequalizer.c:353
SuperEqualizerContext::in
AVFrame * in
Definition: af_superequalizer.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
SuperEqualizerContext::irdft
RDFTContext * irdft
Definition: af_superequalizer.c:53
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
out
FILE * out
Definition: movenc.c:54
n
int n
Definition: avisynth_c.h:760
ff_set_common_channel_layouts
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates.
Definition: formats.c:549
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:686
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
alpha
static float alpha(float a)
Definition: af_superequalizer.c:110
ch
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
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
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
ff_all_channel_counts
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition.
Definition: formats.c:410
AudioConvert::channels
int channels
Definition: audio_convert.c:54
im
float im
Definition: fft.c:82
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
AVOption
AVOption.
Definition: opt.h:246
SuperEqualizerContext
Definition: af_superequalizer.c:38
SuperEqualizerContext::params
EqParameter params[NBANDS+1]
Definition: af_superequalizer.c:41
AF
#define AF
Definition: af_superequalizer.c:350
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
make_fir
static void make_fir(SuperEqualizerContext *s, float *lbc, float *rbc, EqParameter *param, float fs)
Definition: af_superequalizer.c:163
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
SuperEqualizerContext::irest
float * irest
Definition: af_superequalizer.c:48
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
win
static float win(SuperEqualizerContext *s, float n, int N)
Definition: af_superequalizer.c:119
SuperEqualizerContext::ires
float * ires
Definition: af_superequalizer.c:48
IDFT_C2R
@ IDFT_C2R
Definition: avfft.h:73
SuperEqualizerContext::fact
float fact[M+1]
Definition: af_superequalizer.c:45
src
#define src
Definition: vp8dsp.c:254
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
av_cold
#define av_cold
Definition: attributes.h:84
ff_set_common_formats
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:568
SuperEqualizerContext::winlen
int winlen
Definition: af_superequalizer.c:50
init
static av_cold int init(AVFilterContext *ctx)
Definition: af_superequalizer.c:266
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_superequalizer.c:310
NBANDS
#define NBANDS
Definition: af_superequalizer.c:31
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
process_param
static void process_param(float *bc, EqParameter *param, float fs)
Definition: af_superequalizer.c:124
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:48
bands
static const float bands[]
Definition: af_superequalizer.c:56
superequalizer_outputs
static const AVFilterPad superequalizer_outputs[]
Definition: af_superequalizer.c:341
f
#define f(width, name)
Definition: cbs_vp9.c:255
av_rdft_calc
void av_rdft_calc(RDFTContext *s, FFTSample *data)
izero
static float izero(SuperEqualizerContext *s, float x)
Definition: af_superequalizer.c:61
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
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:1500
NULL
#define NULL
Definition: coverity.c:32
fs
#define fs(width, name, subs,...)
Definition: cbs_vp9.c:259
OFFSET
#define OFFSET(x)
Definition: af_superequalizer.c:351
SuperEqualizerContext::out
AVFrame * out
Definition: af_superequalizer.c:52
DFT_R2C
@ DFT_R2C
Definition: avfft.h:72
avfft.h
sinf
#define sinf(x)
Definition: libm.h:419
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
av_rdft_init
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
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:188
hn
static float hn(int n, EqParameter *param, float fs)
Definition: af_superequalizer.c:91
EqParameter::gain
float gain
Definition: af_superequalizer.c:35
SuperEqualizerContext::tabsize
int tabsize
Definition: af_superequalizer.c:50
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
EqParameter::lower
float lower
Definition: af_superequalizer.c:35
equ_init
static int equ_init(SuperEqualizerContext *s, int wb)
Definition: af_superequalizer.c:135
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
SuperEqualizerContext::iza
float iza
Definition: af_superequalizer.c:47
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
N
#define N
Definition: af_mcompand.c:54
superequalizer_inputs
static const AVFilterPad superequalizer_inputs[]
Definition: af_superequalizer.c:332
M_PI
#define M_PI
Definition: mathematics.h:52
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:226
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
EqParameter::upper
float upper
Definition: af_superequalizer.c:35
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
M
#define M
Definition: af_superequalizer.c:32
SuperEqualizerContext::gains
float gains[NBANDS+1]
Definition: af_superequalizer.c:43
RDFTContext
Definition: rdft.h:28
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
AVFilter
Filter definition.
Definition: avfilter.h:144
SuperEqualizerContext::rdft
RDFTContext * rdft
Definition: af_superequalizer.c:53
ret
ret
Definition: filter_design.txt:187
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_superequalizer.c:273
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_superequalizer.c:298
SuperEqualizerContext::aa
float aa
Definition: af_superequalizer.c:46
avfilter.h
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
audio.h
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_superequalizer.c:185
ff_af_superequalizer
AVFilter ff_af_superequalizer
Definition: af_superequalizer.c:377
FF_FILTER_FORWARD_STATUS
FF_FILTER_FORWARD_STATUS(inlink, outlink)
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
EqParameter
Definition: af_superequalizer.c:34
av_rdft_end
void av_rdft_end(RDFTContext *s)
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(superequalizer)
hn_imp
static float hn_imp(int n)
Definition: af_superequalizer.c:86
activate
static int activate(AVFilterContext *ctx)
Definition: af_superequalizer.c:244
re
float re
Definition: fft.c:82