FFmpeg
asrc_sinc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2009 Rob Sykes <robs@users.sourceforge.net>
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/avassert.h"
24 #include "libavutil/opt.h"
25 
26 #include "libavcodec/avfft.h"
27 
28 #include "audio.h"
29 #include "avfilter.h"
30 #include "filters.h"
31 #include "internal.h"
32 
33 typedef struct SincContext {
34  const AVClass *class;
35 
37  float att, beta, phase, Fc0, Fc1, tbw0, tbw1;
38  int num_taps[2];
39  int round;
40 
41  int n, rdft_len;
42  float *coeffs;
43  int64_t pts;
44 
46 } SincContext;
47 
49 {
50  AVFilterLink *outlink = ctx->outputs[0];
51  SincContext *s = ctx->priv;
52  const float *coeffs = s->coeffs;
53  AVFrame *frame = NULL;
54  int nb_samples;
55 
56  if (!ff_outlink_frame_wanted(outlink))
57  return FFERROR_NOT_READY;
58 
59  nb_samples = FFMIN(s->nb_samples, s->n - s->pts);
60  if (nb_samples <= 0) {
61  ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
62  return 0;
63  }
64 
65  if (!(frame = ff_get_audio_buffer(outlink, nb_samples)))
66  return AVERROR(ENOMEM);
67 
68  memcpy(frame->data[0], coeffs + s->pts, nb_samples * sizeof(float));
69 
70  frame->pts = s->pts;
71  s->pts += nb_samples;
72 
73  return ff_filter_frame(outlink, frame);
74 }
75 
77 {
78  SincContext *s = ctx->priv;
79  static const int64_t chlayouts[] = { AV_CH_LAYOUT_MONO, -1 };
80  int sample_rates[] = { s->sample_rate, -1 };
81  static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLT,
84  if (ret < 0)
85  return ret;
86 
88  if (ret < 0)
89  return ret;
90 
92 }
93 
94 static float bessel_I_0(float x)
95 {
96  float term = 1, sum = 1, last_sum, x2 = x / 2;
97  int i = 1;
98 
99  do {
100  float y = x2 / i++;
101 
102  last_sum = sum;
103  sum += term *= y * y;
104  } while (sum != last_sum);
105 
106  return sum;
107 }
108 
109 static float *make_lpf(int num_taps, float Fc, float beta, float rho,
110  float scale, int dc_norm)
111 {
112  int i, m = num_taps - 1;
113  float *h = av_calloc(num_taps, sizeof(*h)), sum = 0;
114  float mult = scale / bessel_I_0(beta), mult1 = 1.f / (.5f * m + rho);
115 
116  av_assert0(Fc >= 0 && Fc <= 1);
117 
118  for (i = 0; i <= m / 2; i++) {
119  float z = i - .5f * m, x = z * M_PI, y = z * mult1;
120  h[i] = x ? sinf(Fc * x) / x : Fc;
121  sum += h[i] *= bessel_I_0(beta * sqrtf(1.f - y * y)) * mult;
122  if (m - i != i) {
123  h[m - i] = h[i];
124  sum += h[i];
125  }
126  }
127 
128  for (i = 0; dc_norm && i < num_taps; i++)
129  h[i] *= scale / sum;
130 
131  return h;
132 }
133 
134 static float kaiser_beta(float att, float tr_bw)
135 {
136  if (att >= 60.f) {
137  static const float coefs[][4] = {
138  {-6.784957e-10, 1.02856e-05, 0.1087556, -0.8988365 + .001},
139  {-6.897885e-10, 1.027433e-05, 0.10876, -0.8994658 + .002},
140  {-1.000683e-09, 1.030092e-05, 0.1087677, -0.9007898 + .003},
141  {-3.654474e-10, 1.040631e-05, 0.1087085, -0.8977766 + .006},
142  {8.106988e-09, 6.983091e-06, 0.1091387, -0.9172048 + .015},
143  {9.519571e-09, 7.272678e-06, 0.1090068, -0.9140768 + .025},
144  {-5.626821e-09, 1.342186e-05, 0.1083999, -0.9065452 + .05},
145  {-9.965946e-08, 5.073548e-05, 0.1040967, -0.7672778 + .085},
146  {1.604808e-07, -5.856462e-05, 0.1185998, -1.34824 + .1},
147  {-1.511964e-07, 6.363034e-05, 0.1064627, -0.9876665 + .18},
148  };
149  float realm = logf(tr_bw / .0005f) / logf(2.f);
150  float const *c0 = coefs[av_clip((int)realm, 0, FF_ARRAY_ELEMS(coefs) - 1)];
151  float const *c1 = coefs[av_clip(1 + (int)realm, 0, FF_ARRAY_ELEMS(coefs) - 1)];
152  float b0 = ((c0[0] * att + c0[1]) * att + c0[2]) * att + c0[3];
153  float b1 = ((c1[0] * att + c1[1]) * att + c1[2]) * att + c1[3];
154 
155  return b0 + (b1 - b0) * (realm - (int)realm);
156  }
157  if (att > 50.f)
158  return .1102f * (att - 8.7f);
159  if (att > 20.96f)
160  return .58417f * powf(att - 20.96f, .4f) + .07886f * (att - 20.96f);
161  return 0;
162 }
163 
164 static void kaiser_params(float att, float Fc, float tr_bw, float *beta, int *num_taps)
165 {
166  *beta = *beta < 0.f ? kaiser_beta(att, tr_bw * .5f / Fc): *beta;
167  att = att < 60.f ? (att - 7.95f) / (2.285f * M_PI * 2.f) :
168  ((.0007528358f-1.577737e-05 * *beta) * *beta + 0.6248022f) * *beta + .06186902f;
169  *num_taps = !*num_taps ? ceilf(att/tr_bw + 1) : *num_taps;
170 }
171 
172 static float *lpf(float Fn, float Fc, float tbw, int *num_taps, float att, float *beta, int round)
173 {
174  int n = *num_taps;
175 
176  if ((Fc /= Fn) <= 0.f || Fc >= 1.f) {
177  *num_taps = 0;
178  return NULL;
179  }
180 
181  att = att ? att : 120.f;
182 
183  kaiser_params(att, Fc, (tbw ? tbw / Fn : .05f) * .5f, beta, num_taps);
184 
185  if (!n) {
186  n = *num_taps;
187  *num_taps = av_clip(n, 11, 32767);
188  if (round)
189  *num_taps = 1 + 2 * (int)((int)((*num_taps / 2) * Fc + .5f) / Fc + .5f);
190  }
191 
192  return make_lpf(*num_taps |= 1, Fc, *beta, 0.f, 1.f, 0);
193 }
194 
195 static void invert(float *h, int n)
196 {
197  for (int i = 0; i < n; i++)
198  h[i] = -h[i];
199 
200  h[(n - 1) / 2] += 1;
201 }
202 
203 #define PACK(h, n) h[1] = h[n]
204 #define UNPACK(h, n) h[n] = h[1], h[n + 1] = h[1] = 0;
205 #define SQR(a) ((a) * (a))
206 
207 static float safe_log(float x)
208 {
209  av_assert0(x >= 0);
210  if (x)
211  return logf(x);
212  return -26;
213 }
214 
215 static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, float phase)
216 {
217  float *pi_wraps, *work, phase1 = (phase > 50.f ? 100.f - phase : phase) / 50.f;
218  int i, work_len, begin, end, imp_peak = 0, peak = 0;
219  float imp_sum = 0, peak_imp_sum = 0;
220  float prev_angle2 = 0, cum_2pi = 0, prev_angle1 = 0, cum_1pi = 0;
221 
222  for (i = *len, work_len = 2 * 2 * 8; i > 1; work_len <<= 1, i >>= 1);
223 
224  /* The first part is for work (+2 for (UN)PACK), the latter for pi_wraps. */
225  work = av_calloc((work_len + 2) + (work_len / 2 + 1), sizeof(float));
226  if (!work)
227  return AVERROR(ENOMEM);
228  pi_wraps = &work[work_len + 2];
229 
230  memcpy(work, *h, *len * sizeof(*work));
231 
232  av_rdft_end(s->rdft);
233  av_rdft_end(s->irdft);
234  s->rdft = s->irdft = NULL;
235  s->rdft = av_rdft_init(av_log2(work_len), DFT_R2C);
236  s->irdft = av_rdft_init(av_log2(work_len), IDFT_C2R);
237  if (!s->rdft || !s->irdft) {
238  av_free(work);
239  return AVERROR(ENOMEM);
240  }
241 
242  av_rdft_calc(s->rdft, work); /* Cepstral: */
243  UNPACK(work, work_len);
244 
245  for (i = 0; i <= work_len; i += 2) {
246  float angle = atan2f(work[i + 1], work[i]);
247  float detect = 2 * M_PI;
248  float delta = angle - prev_angle2;
249  float adjust = detect * ((delta < -detect * .7f) - (delta > detect * .7f));
250 
251  prev_angle2 = angle;
252  cum_2pi += adjust;
253  angle += cum_2pi;
254  detect = M_PI;
255  delta = angle - prev_angle1;
256  adjust = detect * ((delta < -detect * .7f) - (delta > detect * .7f));
257  prev_angle1 = angle;
258  cum_1pi += fabsf(adjust); /* fabs for when 2pi and 1pi have combined */
259  pi_wraps[i >> 1] = cum_1pi;
260 
261  work[i] = safe_log(sqrtf(SQR(work[i]) + SQR(work[i + 1])));
262  work[i + 1] = 0;
263  }
264 
265  PACK(work, work_len);
266  av_rdft_calc(s->irdft, work);
267 
268  for (i = 0; i < work_len; i++)
269  work[i] *= 2.f / work_len;
270 
271  for (i = 1; i < work_len / 2; i++) { /* Window to reject acausal components */
272  work[i] *= 2;
273  work[i + work_len / 2] = 0;
274  }
275  av_rdft_calc(s->rdft, work);
276 
277  for (i = 2; i < work_len; i += 2) /* Interpolate between linear & min phase */
278  work[i + 1] = phase1 * i / work_len * pi_wraps[work_len >> 1] + (1 - phase1) * (work[i + 1] + pi_wraps[i >> 1]) - pi_wraps[i >> 1];
279 
280  work[0] = exp(work[0]);
281  work[1] = exp(work[1]);
282  for (i = 2; i < work_len; i += 2) {
283  float x = expf(work[i]);
284 
285  work[i ] = x * cosf(work[i + 1]);
286  work[i + 1] = x * sinf(work[i + 1]);
287  }
288 
289  av_rdft_calc(s->irdft, work);
290  for (i = 0; i < work_len; i++)
291  work[i] *= 2.f / work_len;
292 
293  /* Find peak pos. */
294  for (i = 0; i <= (int) (pi_wraps[work_len >> 1] / M_PI + .5f); i++) {
295  imp_sum += work[i];
296  if (fabs(imp_sum) > fabs(peak_imp_sum)) {
297  peak_imp_sum = imp_sum;
298  peak = i;
299  }
300  if (work[i] > work[imp_peak]) /* For debug check only */
301  imp_peak = i;
302  }
303 
304  while (peak && fabsf(work[peak - 1]) > fabsf(work[peak]) && (work[peak - 1] * work[peak] > 0)) {
305  peak--;
306  }
307 
308  if (!phase1) {
309  begin = 0;
310  } else if (phase1 == 1) {
311  begin = peak - *len / 2;
312  } else {
313  begin = (.997f - (2 - phase1) * .22f) * *len + .5f;
314  end = (.997f + (0 - phase1) * .22f) * *len + .5f;
315  begin = peak - (begin & ~3);
316  end = peak + 1 + ((end + 3) & ~3);
317  *len = end - begin;
318  *h = av_realloc_f(*h, *len, sizeof(**h));
319  if (!*h) {
320  av_free(work);
321  return AVERROR(ENOMEM);
322  }
323  }
324 
325  for (i = 0; i < *len; i++) {
326  (*h)[i] = work[(begin + (phase > 50.f ? *len - 1 - i : i) + work_len) & (work_len - 1)];
327  }
328  *post_len = phase > 50 ? peak - begin : begin + *len - (peak + 1);
329 
330  av_log(s, AV_LOG_DEBUG, "%d nPI=%g peak-sum@%i=%g (val@%i=%g); len=%i post=%i (%g%%)\n",
331  work_len, pi_wraps[work_len >> 1] / M_PI, peak, peak_imp_sum, imp_peak,
332  work[imp_peak], *len, *post_len, 100.f - 100.f * *post_len / (*len - 1));
333 
334  av_free(work);
335 
336  return 0;
337 }
338 
339 static int config_output(AVFilterLink *outlink)
340 {
341  AVFilterContext *ctx = outlink->src;
342  SincContext *s = ctx->priv;
343  float Fn = s->sample_rate * .5f;
344  float *h[2];
345  int i, n, post_peak, longer;
346 
347  outlink->sample_rate = s->sample_rate;
348  s->pts = 0;
349 
350  if (s->Fc0 >= Fn || s->Fc1 >= Fn) {
352  "filter frequency must be less than %d/2.\n", s->sample_rate);
353  return AVERROR(EINVAL);
354  }
355 
356  h[0] = lpf(Fn, s->Fc0, s->tbw0, &s->num_taps[0], s->att, &s->beta, s->round);
357  h[1] = lpf(Fn, s->Fc1, s->tbw1, &s->num_taps[1], s->att, &s->beta, s->round);
358 
359  if (h[0])
360  invert(h[0], s->num_taps[0]);
361 
362  longer = s->num_taps[1] > s->num_taps[0];
363  n = s->num_taps[longer];
364 
365  if (h[0] && h[1]) {
366  for (i = 0; i < s->num_taps[!longer]; i++)
367  h[longer][i + (n - s->num_taps[!longer]) / 2] += h[!longer][i];
368 
369  if (s->Fc0 < s->Fc1)
370  invert(h[longer], n);
371 
372  av_free(h[!longer]);
373  }
374 
375  if (s->phase != 50.f) {
376  int ret = fir_to_phase(s, &h[longer], &n, &post_peak, s->phase);
377  if (ret < 0)
378  return ret;
379  } else {
380  post_peak = n >> 1;
381  }
382 
383  s->n = 1 << (av_log2(n) + 1);
384  s->rdft_len = 1 << av_log2(n);
385  s->coeffs = av_calloc(s->n, sizeof(*s->coeffs));
386  if (!s->coeffs)
387  return AVERROR(ENOMEM);
388 
389  for (i = 0; i < n; i++)
390  s->coeffs[i] = h[longer][i];
391  av_free(h[longer]);
392 
393  av_rdft_end(s->rdft);
394  av_rdft_end(s->irdft);
395  s->rdft = s->irdft = NULL;
396 
397  return 0;
398 }
399 
401 {
402  SincContext *s = ctx->priv;
403 
404  av_freep(&s->coeffs);
405  av_rdft_end(s->rdft);
406  av_rdft_end(s->irdft);
407  s->rdft = s->irdft = NULL;
408 }
409 
410 static const AVFilterPad sinc_outputs[] = {
411  {
412  .name = "default",
413  .type = AVMEDIA_TYPE_AUDIO,
414  .config_props = config_output,
415  },
416 };
417 
418 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
419 #define OFFSET(x) offsetof(SincContext, x)
420 
421 static const AVOption sinc_options[] = {
422  { "sample_rate", "set sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64=44100}, 1, INT_MAX, AF },
423  { "r", "set sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.i64=44100}, 1, INT_MAX, AF },
424  { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX, AF },
425  { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX, AF },
426  { "hp", "set high-pass filter frequency", OFFSET(Fc0), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, INT_MAX, AF },
427  { "lp", "set low-pass filter frequency", OFFSET(Fc1), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, INT_MAX, AF },
428  { "phase", "set filter phase response", OFFSET(phase), AV_OPT_TYPE_FLOAT, {.dbl=50}, 0, 100, AF },
429  { "beta", "set kaiser window beta", OFFSET(beta), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 256, AF },
430  { "att", "set stop-band attenuation", OFFSET(att), AV_OPT_TYPE_FLOAT, {.dbl=120}, 40, 180, AF },
431  { "round", "enable rounding", OFFSET(round), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AF },
432  { "hptaps", "set number of taps for high-pass filter", OFFSET(num_taps[0]), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF },
433  { "lptaps", "set number of taps for low-pass filter", OFFSET(num_taps[1]), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF },
434  { NULL }
435 };
436 
438 
440  .name = "sinc",
441  .description = NULL_IF_CONFIG_SMALL("Generate a sinc kaiser-windowed low-pass, high-pass, band-pass, or band-reject FIR coefficients."),
442  .priv_size = sizeof(SincContext),
443  .priv_class = &sinc_class,
444  .uninit = uninit,
445  .activate = activate,
446  .inputs = NULL,
449 };
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_clip
#define av_clip
Definition: common.h:96
SincContext
Definition: asrc_sinc.c:33
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:90
atan2f
#define atan2f(y, x)
Definition: libm.h:45
ff_set_common_samplerates_from_list
int ff_set_common_samplerates_from_list(AVFilterContext *ctx, const int *samplerates)
Equivalent to ff_set_common_samplerates(ctx, ff_make_format_list(samplerates))
Definition: formats.c:683
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
kaiser_beta
static float kaiser_beta(float att, float tr_bw)
Definition: asrc_sinc.c:134
AVOption
AVOption.
Definition: opt.h:247
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:168
expf
#define expf(x)
Definition: libm.h:283
PACK
#define PACK(h, n)
Definition: asrc_sinc.c:203
AF
#define AF
Definition: asrc_sinc.c:418
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:153
c1
static const uint64_t c1
Definition: murmur3.c:51
SincContext::sample_rate
int sample_rate
Definition: asrc_sinc.c:36
SincContext::att
float att
Definition: asrc_sinc.c:37
SincContext::nb_samples
int nb_samples
Definition: asrc_sinc.c:36
SincContext::coeffs
float * coeffs
Definition: asrc_sinc.c:42
ceilf
static __device__ float ceilf(float a)
Definition: cuda_runtime.h:175
sample_rate
sample_rate
Definition: ffmpeg_filter.c:156
ff_set_common_channel_layouts_from_list
int ff_set_common_channel_layouts_from_list(AVFilterContext *ctx, const int64_t *fmts)
Equivalent to ff_set_common_channel_layouts(ctx, ff_make_format64_list(fmts))
Definition: formats.c:665
SincContext::rdft
RDFTContext * rdft
Definition: asrc_sinc.c:45
lpf
static float * lpf(float Fn, float Fc, float tbw, int *num_taps, float att, float *beta, int round)
Definition: asrc_sinc.c:172
b1
static double b1(void *priv, double x, double y)
Definition: vf_xfade.c:1703
cosf
#define cosf(x)
Definition: libm.h:78
IDFT_C2R
@ IDFT_C2R
Definition: avfft.h:73
SincContext::tbw1
float tbw1
Definition: asrc_sinc.c:37
SincContext::Fc1
float Fc1
Definition: asrc_sinc.c:37
SincContext::pts
int64_t pts
Definition: asrc_sinc.c:43
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1377
make_lpf
static float * make_lpf(int num_taps, float Fc, float beta, float rho, float scale, int dc_norm)
Definition: asrc_sinc.c:109
fabsf
static __device__ float fabsf(float a)
Definition: cuda_runtime.h:181
OFFSET
#define OFFSET(x)
Definition: asrc_sinc.c:419
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
mult
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:56
avassert.h
SincContext::rdft_len
int rdft_len
Definition: asrc_sinc.c:41
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
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
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
s
#define s(width, name)
Definition: cbs_vp9.c:257
adjust
static int adjust(int x, int size)
Definition: mobiclip.c:515
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
SincContext::tbw0
float tbw0
Definition: asrc_sinc.c:37
ff_set_common_formats_from_list
int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_format_list(fmts))
Definition: formats.c:705
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
filters.h
SincContext::irdft
RDFTContext * irdft
Definition: asrc_sinc.c:45
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
f
#define f(width, name)
Definition: cbs_vp9.c:255
av_rdft_calc
void av_rdft_calc(RDFTContext *s, FFTSample *data)
SincContext::n
int n
Definition: asrc_sinc.c:41
ff_asrc_sinc
const AVFilter ff_asrc_sinc
Definition: asrc_sinc.c:439
SincContext::phase
float phase
Definition: asrc_sinc.c:37
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:33
fir_to_phase
static int fir_to_phase(SincContext *s, float **h, int *len, int *post_len, float phase)
Definition: asrc_sinc.c:215
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
NULL
#define NULL
Definition: coverity.c:32
sinc_outputs
static const AVFilterPad sinc_outputs[]
Definition: asrc_sinc.c:410
SincContext::round
int round
Definition: asrc_sinc.c:39
work
must be printed separately If there s no standard function for printing the type you the WRITE_1D_FUNC_ARGV macro is a very quick way to create one See libavcodec dv_tablegen c for an example The h file This file should the initialization functions should not do and instead of the variable declarations the generated *_tables h file should be included Since that will be generated in the build the path must be i e not Makefile changes To make the automatic table creation work
Definition: tablegen.txt:66
activate
static int activate(AVFilterContext *ctx)
Definition: asrc_sinc.c:48
DFT_R2C
@ DFT_R2C
Definition: avfft.h:72
avfft.h
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: asrc_sinc.c:400
sinf
#define sinf(x)
Definition: libm.h:419
exp
int8_t exp
Definition: eval.c:72
kaiser_params
static void kaiser_params(float att, float Fc, float tr_bw, float *beta, int *num_taps)
Definition: asrc_sinc.c:164
SQR
#define SQR(a)
Definition: asrc_sinc.c:205
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:117
powf
#define powf(x, y)
Definition: libm.h:50
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
SincContext::beta
float beta
Definition: asrc_sinc.c:37
M_PI
#define M_PI
Definition: mathematics.h:52
sample_rates
sample_rates
Definition: ffmpeg_filter.c:156
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:227
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
invert
static void invert(float *h, int n)
Definition: asrc_sinc.c:195
RDFTContext
Definition: rdft.h:28
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
delta
float delta
Definition: vorbis_enc_data.h:430
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
len
int len
Definition: vorbis_enc_data.h:426
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
AVFilter
Filter definition.
Definition: avfilter.h:149
ret
ret
Definition: filter_design.txt:187
frame
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
config_output
static int config_output(AVFilterLink *outlink)
Definition: asrc_sinc.c:339
channel_layout.h
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
SincContext::Fc0
float Fc0
Definition: asrc_sinc.c:37
AVFilterContext
An instance of a filter.
Definition: avfilter.h:386
sinc_options
static const AVOption sinc_options[]
Definition: asrc_sinc.c:421
audio.h
SincContext::num_taps
int num_taps[2]
Definition: asrc_sinc.c:38
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:241
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
safe_log
static float safe_log(float x)
Definition: asrc_sinc.c:207
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: asrc_sinc.c:76
av_rdft_end
void av_rdft_end(RDFTContext *s)
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
b0
static double b0(void *priv, double x, double y)
Definition: vf_xfade.c:1702
h
h
Definition: vp9dsp_template.c:2038
ff_outlink_frame_wanted
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(sinc)
int
int
Definition: ffmpeg_filter.c:156
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:63
bessel_I_0
static float bessel_I_0(float x)
Definition: asrc_sinc.c:94
UNPACK
#define UNPACK(h, n)
Definition: asrc_sinc.c:204