Go to the documentation of this file.
29 #define RDFT_BITS_MIN 4
30 #define RDFT_BITS_MAX 16
54 #define NB_GAIN_ENTRY_MAX 4096
113 #define OFFSET(x) offsetof(FIREqualizerContext, x)
114 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
158 s->analysis_rdft =
s->analysis_irdft =
s->rdft =
s->irdft =
NULL;
160 s->cepstrum_rdft =
NULL;
161 s->cepstrum_irdft =
NULL;
214 if (nsamples <= s->nsamples_max) {
215 float *
buf = conv_buf + idx->buf_idx *
s->rdft_len;
216 float *obuf = conv_buf + !idx->buf_idx *
s->rdft_len + idx->overlap_idx;
217 int center =
s->fir_len/2;
220 memset(
buf, 0, center *
sizeof(*
data));
221 memcpy(
buf + center,
data, nsamples *
sizeof(*
data));
222 memset(
buf + center + nsamples, 0, (
s->rdft_len - nsamples - center) *
sizeof(*
data));
225 buf[0] *= kernel_buf[0];
226 buf[1] *= kernel_buf[
s->rdft_len/2];
227 for (k = 1; k <
s->rdft_len/2; k++) {
228 buf[2*k] *= kernel_buf[k];
229 buf[2*k+1] *= kernel_buf[k];
233 for (k = 0; k <
s->rdft_len - idx->overlap_idx; k++)
236 idx->buf_idx = !idx->buf_idx;
237 idx->overlap_idx = nsamples;
239 while (nsamples >
s->nsamples_max * 2) {
241 data +=
s->nsamples_max;
242 nsamples -=
s->nsamples_max;
250 float *av_restrict conv_buf,
OverlapIndex *av_restrict idx,
251 float *av_restrict
data,
int nsamples)
253 if (nsamples <= s->nsamples_max) {
254 float *
buf = conv_buf + idx->buf_idx *
s->rdft_len;
255 float *obuf = conv_buf + !idx->buf_idx *
s->rdft_len + idx->overlap_idx;
259 memset(
buf + nsamples, 0, (
s->rdft_len - nsamples) *
sizeof(*
data));
262 buf[0] *= kernel_buf[0];
263 buf[1] *= kernel_buf[1];
264 for (k = 2; k <
s->rdft_len; k += 2) {
266 re =
buf[k] * kernel_buf[k] -
buf[k+1] * kernel_buf[k+1];
267 im =
buf[k] * kernel_buf[k+1] +
buf[k+1] * kernel_buf[k];
273 for (k = 0; k <
s->rdft_len - idx->overlap_idx; k++)
276 idx->buf_idx = !idx->buf_idx;
277 idx->overlap_idx = nsamples;
279 while (nsamples >
s->nsamples_max * 2) {
281 data +=
s->nsamples_max;
282 nsamples -=
s->nsamples_max;
290 OverlapIndex *av_restrict idx,
float *av_restrict data0,
float *av_restrict data1,
int nsamples)
292 if (nsamples <= s->nsamples_max) {
294 FFTComplex *obuf = conv_buf + !idx->buf_idx *
s->rdft_len + idx->overlap_idx;
295 int center =
s->fir_len/2;
299 memset(
buf, 0, center *
sizeof(*
buf));
300 for (k = 0; k < nsamples; k++) {
301 buf[center+k].re = data0[k];
302 buf[center+k].im = data1[k];
304 memset(
buf + center + nsamples, 0, (
s->rdft_len - nsamples - center) *
sizeof(*
buf));
311 buf[0].re = 0.5f * kernel_buf[0] *
buf[0].im;
312 buf[0].im = 0.5f * kernel_buf[0] *
tmp;
313 for (k = 1; k <
s->rdft_len/2; k++) {
314 int m =
s->rdft_len - k;
316 buf[k].re = 0.5f * kernel_buf[k] *
buf[k].im;
317 buf[k].im = 0.5f * kernel_buf[k] *
tmp;
319 buf[m].re = 0.5f * kernel_buf[k] *
buf[m].im;
320 buf[m].im = 0.5f * kernel_buf[k] *
tmp;
323 buf[k].re = 0.5f * kernel_buf[k] *
buf[k].im;
324 buf[k].im = 0.5f * kernel_buf[k] *
tmp;
329 for (k = 0; k <
s->rdft_len - idx->overlap_idx; k++) {
330 buf[k].re += obuf[k].
re;
331 buf[k].im += obuf[k].
im;
335 for (k = 0; k < nsamples; k++) {
336 data0[k] =
buf[k].im;
337 data1[k] =
buf[k].re;
339 idx->buf_idx = !idx->buf_idx;
340 idx->overlap_idx = nsamples;
342 while (nsamples >
s->nsamples_max * 2) {
344 data0 +=
s->nsamples_max;
345 data1 +=
s->nsamples_max;
346 nsamples -=
s->nsamples_max;
349 fast_convolute2(
s, kernel_buf, conv_buf, idx, data0 + nsamples/2, data1 + nsamples/2, nsamples - nsamples/2);
356 int rate =
ctx->inputs[0]->sample_rate;
360 int center =
s->fir_len / 2;
361 double delay =
s->zero_phase ? 0.0 : (double) center / rate;
365 s->analysis_buf[0] *=
s->rdft_len/2;
366 for (x = 1; x <= center; x++) {
367 s->analysis_buf[x] *=
s->rdft_len/2;
368 s->analysis_buf[
s->analysis_rdft_len - x] *=
s->rdft_len/2;
371 for (x = 0; x <
s->fir_len; x++)
372 s->analysis_buf[x] *=
s->rdft_len/2;
378 fprintf(
fp,
"# time[%d] (time amplitude)\n",
ch);
381 for (x = center; x > 0; x--)
382 fprintf(
fp,
"%15.10f %15.10f\n", delay - (
double) x / rate, (
double)
s->analysis_buf[
s->analysis_rdft_len - x]);
384 for (x = 0; x <= center; x++)
385 fprintf(
fp,
"%15.10f %15.10f\n", delay + (
double)x / rate , (
double)
s->analysis_buf[x]);
387 for (x = 0; x <
s->fir_len; x++)
388 fprintf(
fp,
"%15.10f %15.10f\n", (
double)x / rate, (
double)
s->analysis_buf[x]);
393 fprintf(
fp,
"\n\n# freq[%d] (frequency desired_gain actual_gain)\n",
ch);
395 for (x = 0; x <=
s->analysis_rdft_len/2; x++) {
396 int i = (x ==
s->analysis_rdft_len/2) ? 1 : 2 * x;
397 vx = (double)x * rate /
s->analysis_rdft_len;
401 yb =
s->min_phase && (
i > 1) ? hypotf(
s->analysis_buf[
i],
s->analysis_buf[
i+1]) :
s->analysis_buf[
i];
405 ya = 20.0 * log10(fabs(ya));
406 yb = 20.0 * log10(fabs(yb));
408 fprintf(
fp,
"%17.10f %17.10f %17.10f\n", vx, ya, yb);
419 s->gain_entry_err =
AVERROR(EINVAL);
425 s->gain_entry_err =
AVERROR(EINVAL);
429 if (
s->nb_gain_entry > 0 && freq <= s->gain_entry_tbl[
s->nb_gain_entry - 1].freq) {
431 s->gain_entry_err =
AVERROR(EINVAL);
435 s->gain_entry_tbl[
s->nb_gain_entry].freq = freq;
436 s->gain_entry_tbl[
s->nb_gain_entry].gain = gain;
443 const double *freq =
key;
446 if (*freq < entry[0].freq)
448 if (*freq > entry[1].freq)
463 if (!
s->nb_gain_entry)
466 if (freq <= s->gain_entry_tbl[0].freq)
467 return s->gain_entry_tbl[0].gain;
469 if (freq >=
s->gain_entry_tbl[
s->nb_gain_entry-1].freq)
470 return s->gain_entry_tbl[
s->nb_gain_entry-1].gain;
472 res = bsearch(&freq, &
s->gain_entry_tbl,
s->nb_gain_entry - 1,
sizeof(*res),
gain_entry_compare);
476 d0 = freq - res[0].
freq;
477 d1 = res[1].
freq - freq;
480 return (d0 * res[1].gain + d1 * res[0].gain) / d;
495 double m0, m1, m2, msum, unit;
497 if (!
s->nb_gain_entry)
500 if (freq <= s->gain_entry_tbl[0].freq)
501 return s->gain_entry_tbl[0].gain;
503 if (freq >=
s->gain_entry_tbl[
s->nb_gain_entry-1].freq)
504 return s->gain_entry_tbl[
s->nb_gain_entry-1].gain;
506 res = bsearch(&freq, &
s->gain_entry_tbl,
s->nb_gain_entry - 1,
sizeof(*res),
gain_entry_compare);
510 m0 = res !=
s->gain_entry_tbl ?
511 unit * (res[0].
gain - res[-1].
gain) / (res[0].freq - res[-1].freq) : 0;
513 m2 = res !=
s->gain_entry_tbl +
s->nb_gain_entry - 2 ?
514 unit * (res[2].
gain - res[1].
gain) / (res[2].freq - res[1].freq) : 0;
516 msum = fabs(m0) + fabs(m1);
517 m0 = msum > 0 ? (fabs(m0) * m1 + fabs(m1) * m0) / msum : 0;
518 msum = fabs(m1) + fabs(m2);
519 m1 = msum > 0 ? (fabs(m1) * m2 + fabs(m2) * m1) / msum : 0;
523 b = 3 * res[1].
gain - m1 - 2 *
c - 3 * d;
526 x = (freq - res[0].
freq) / unit;
530 return a * x3 +
b * x2 +
c * x + d;
555 int k, cepstrum_len =
s->cepstrum_len, rdft_len =
s->rdft_len;
556 double norm = 2.0 / cepstrum_len;
557 double minval = 1e-7 / rdft_len;
559 memset(
s->cepstrum_buf, 0, cepstrum_len *
sizeof(*
s->cepstrum_buf));
560 memcpy(
s->cepstrum_buf, rdft_buf, rdft_len/2 *
sizeof(*rdft_buf));
561 memcpy(
s->cepstrum_buf + cepstrum_len - rdft_len/2, rdft_buf + rdft_len/2, rdft_len/2 *
sizeof(*rdft_buf));
565 s->cepstrum_buf[0] = log(
FFMAX(
s->cepstrum_buf[0], minval));
566 s->cepstrum_buf[1] = log(
FFMAX(
s->cepstrum_buf[1], minval));
568 for (k = 2; k < cepstrum_len; k += 2) {
569 s->cepstrum_buf[k] = log(
FFMAX(
s->cepstrum_buf[k], minval));
570 s->cepstrum_buf[k+1] = 0;
575 memset(
s->cepstrum_buf + cepstrum_len/2 + 1, 0, (cepstrum_len/2 - 1) *
sizeof(*
s->cepstrum_buf));
576 for (k = 1; k < cepstrum_len/2; k++)
577 s->cepstrum_buf[k] *= 2;
581 s->cepstrum_buf[0] =
exp(
s->cepstrum_buf[0] * norm) * norm;
582 s->cepstrum_buf[1] =
exp(
s->cepstrum_buf[1] * norm) * norm;
583 for (k = 2; k < cepstrum_len; k += 2) {
584 double mag =
exp(
s->cepstrum_buf[k] * norm) * norm;
585 double ph =
s->cepstrum_buf[k+1] * norm;
586 s->cepstrum_buf[k] = mag * cos(ph);
587 s->cepstrum_buf[k+1] = mag * sin(ph);
591 memset(rdft_buf, 0,
s->rdft_len *
sizeof(*rdft_buf));
592 memcpy(rdft_buf,
s->cepstrum_buf,
s->fir_len *
sizeof(*rdft_buf));
595 memset(
s->analysis_buf, 0,
s->analysis_rdft_len *
sizeof(*
s->analysis_buf));
596 memcpy(
s->analysis_buf,
s->cepstrum_buf,
s->fir_len *
sizeof(*
s->analysis_buf));
605 const char *gain_entry_func_names[] = {
"entry",
NULL };
606 const char *gain_func_names[] = {
"gain_interpolate",
"cubic_interpolate",
NULL };
607 double (*gain_entry_funcs[])(
void *, double, double) = {
entry_func,
NULL };
611 int ret, k, center,
ch;
614 FILE *dump_fp =
NULL;
616 s->nb_gain_entry = 0;
617 s->gain_entry_err = 0;
621 gain_entry_func_names, gain_entry_funcs,
ctx, 0,
ctx);
624 if (
s->gain_entry_err < 0)
625 return s->gain_entry_err;
635 if (
s->dumpfile && (!
s->dump_buf || !
s->analysis_rdft || !(dump_fp = fopen(
s->dumpfile,
"w"))))
642 float *rdft_buf =
s->kernel_tmp_buf +
ch *
s->rdft_len;
650 s->analysis_buf[0] = ylog ? pow(10.0, 0.05 *
result) :
result;
656 s->analysis_buf[1] = ylog ? pow(10.0, 0.05 *
result) :
result;
658 for (k = 1; k <
s->analysis_rdft_len/2; k++) {
659 vars[
VAR_F] = k * ((double)
inlink->sample_rate /(
double)
s->analysis_rdft_len);
664 s->analysis_buf[2*k+1] = 0.0;
668 memcpy(
s->dump_buf,
s->analysis_buf,
s->analysis_rdft_len *
sizeof(*
s->analysis_buf));
671 center =
s->fir_len / 2;
673 for (k = 0; k <= center; k++) {
674 double u = k * (
M_PI/center);
681 win = 0.5 + 0.5 * cos(
u);
684 win = 0.53836 + 0.46164 * cos(
u);
687 win = 0.42 + 0.5 * cos(
u) + 0.08 * cos(2*
u);
690 win = 0.40897 + 0.5 * cos(
u) + 0.09103 * cos(2*
u);
693 win = 0.4243801 + 0.4973406 * cos(
u) + 0.0782793 * cos(2*
u);
696 win = 0.355768 + 0.487396 * cos(
u) + 0.144232 * cos(2*
u) + 0.012604 * cos(3*
u);
699 win = 0.3635819 + 0.4891775 * cos(
u) + 0.1365995 * cos(2*
u) + 0.0106411 * cos(3*
u);
702 win = 0.35875 + 0.48829 * cos(
u) + 0.14128 * cos(2*
u) + 0.01168 * cos(3*
u);
705 win = (
u <= 0.5 *
M_PI) ? 1.0 : (0.5 + 0.5 * cos(2*
u -
M_PI));
710 s->analysis_buf[k] *= (2.0/
s->analysis_rdft_len) * (2.0/
s->rdft_len) *
win;
712 s->analysis_buf[
s->analysis_rdft_len - k] =
s->analysis_buf[k];
715 memset(
s->analysis_buf + center + 1, 0, (
s->analysis_rdft_len -
s->fir_len) *
sizeof(*
s->analysis_buf));
716 memcpy(rdft_buf,
s->analysis_buf,
s->rdft_len/2 *
sizeof(*
s->analysis_buf));
717 memcpy(rdft_buf +
s->rdft_len/2,
s->analysis_buf +
s->analysis_rdft_len -
s->rdft_len/2,
s->rdft_len/2 *
sizeof(*
s->analysis_buf));
722 for (k = 0; k <
s->rdft_len; k++) {
723 if (
isnan(rdft_buf[k]) ||
isinf(rdft_buf[k])) {
733 rdft_buf[
s->rdft_len-1] = rdft_buf[1];
734 for (k = 0; k <
s->rdft_len/2; k++)
735 rdft_buf[k] = rdft_buf[2*k];
736 rdft_buf[
s->rdft_len/2] = rdft_buf[
s->rdft_len-1];
746 memcpy(
s->kernel_buf,
s->kernel_tmp_buf, (
s->multi ?
inlink->channels : 1) *
s->rdft_len *
sizeof(*
s->kernel_buf));
753 #define SELECT_GAIN(s) (s->gain_cmd ? s->gain_cmd : s->gain)
754 #define SELECT_GAIN_ENTRY(s) (s->gain_entry_cmd ? s->gain_entry_cmd : s->gain_entry)
765 s->frame_nsamples_max = 0;
767 s->fir_len =
FFMAX(2 * (
int)(
inlink->sample_rate *
s->delay) + 1, 3);
768 s->remaining =
s->fir_len - 1;
771 s->rdft_len = 1 << rdft_bits;
772 s->nsamples_max =
s->rdft_len -
s->fir_len + 1;
773 if (
s->nsamples_max * 2 >=
s->fir_len)
789 int cepstrum_bits = rdft_bits + 2;
798 if (!
s->cepstrum_rdft || !
s->cepstrum_irdft)
801 s->cepstrum_len = 1 << cepstrum_bits;
803 if (!
s->cepstrum_buf)
808 s->analysis_rdft_len = 1 << rdft_bits;
809 if (
inlink->sample_rate <=
s->accuracy *
s->analysis_rdft_len)
831 if (!
s->analysis_buf || !
s->kernel_tmp_buf || !
s->kernel_buf || !
s->conv_buf || !
s->conv_idx)
834 av_log(
ctx,
AV_LOG_DEBUG,
"sample_rate = %d, channels = %d, analysis_rdft_len = %d, rdft_len = %d, fir_len = %d, nsamples_max = %d.\n",
835 inlink->sample_rate,
inlink->channels,
s->analysis_rdft_len,
s->rdft_len,
s->fir_len,
s->nsamples_max);
850 for (
ch = 0;
ch + 1 <
inlink->channels &&
s->fft_ctx;
ch += 2) {
852 s->conv_idx +
ch, (
float *)
frame->extended_data[
ch],
853 (
float *)
frame->extended_data[
ch+1],
frame->nb_samples);
858 s->conv_buf + 2 *
ch *
s->rdft_len,
s->conv_idx +
ch,
864 s->conv_buf + 2 *
ch *
s->rdft_len,
s->conv_idx +
ch,
872 if (
s->zero_phase && !
s->min_phase)
875 s->frame_nsamples_max =
FFMAX(
s->frame_nsamples_max,
frame->nb_samples);
894 s->remaining -=
frame->nb_samples;
902 char *res,
int res_len,
int flags)
907 if (!strcmp(cmd,
"gain")) {
922 s->gain_cmd = gain_cmd;
926 }
else if (!strcmp(cmd,
"gain_entry")) {
927 char *gain_entry_cmd;
941 s->gain_entry_cmd = gain_entry_cmd;
971 .
name =
"firequalizer",
979 .priv_class = &firequalizer_class,
av_cold void av_fft_end(FFTContext *s)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
@ AV_SAMPLE_FMT_FLTP
float, planar
A list of supported channel layouts.
#define AV_LOG_WARNING
Something somehow does not look correct.
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
static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *gain_entry)
#define u(width, name, range_min, range_max)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static enum AVSampleFormat sample_fmts[]
enum MovChannelLayoutTag * layouts
#define AVERROR_EOF
End of file.
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
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
static double gain_interpolate_func(void *p, double freq)
RDFTContext * analysis_irdft
This structure describes decoded (raw) audio or video data.
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
const char * name
Filter name.
static int query_formats(AVFilterContext *ctx)
A link between two filters.
int channels
Number of channels.
RDFTContext * cepstrum_irdft
#define SELECT_GAIN_ENTRY(s)
static float win(SuperEqualizerContext *s, float n, int N)
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
#define NB_GAIN_ENTRY_MAX
static void generate_min_phase_kernel(FIREqualizerContext *s, float *rdft_buf)
static const AVFilterPad firequalizer_outputs[]
static const AVFilterPad firequalizer_inputs[]
static int request_frame(AVFilterLink *outlink)
static double cubic_interpolate_func(void *p, double freq)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
AVFilter ff_af_firequalizer
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_cold void uninit(AVFilterContext *ctx)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const AVFilterPad outputs[]
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void av_rdft_calc(RDFTContext *s, FFTSample *data)
Describe the class of an AVClass context structure.
and forward the result(frame or status change) to the corresponding input. If nothing is possible
static const uint8_t vars[2][12]
static double entry_func(void *p, double freq, double gain)
AVFILTER_DEFINE_CLASS(firequalizer)
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
static const char *const var_names[]
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
static void fast_convolute2(FIREqualizerContext *av_restrict s, const float *av_restrict kernel_buf, FFTComplex *av_restrict conv_buf, OverlapIndex *av_restrict idx, float *av_restrict data0, float *av_restrict data1, int nsamples)
static AVRational av_make_q(int num, int den)
Create an AVRational.
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVFilterContext * src
source filter
static const AVOption firequalizer_options[]
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
RDFTContext * cepstrum_rdft
#define i(width, name, range_min, range_max)
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
Get the channel with the given index in channel_layout.
#define av_malloc_array(a, b)
AVSampleFormat
Audio sample formats.
const char AVS_Value args
GainEntry gain_entry_tbl[NB_GAIN_ENTRY_MAX]
const char * name
Pad name.
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static void fast_convolute(FIREqualizerContext *av_restrict s, const float *av_restrict kernel_buf, float *av_restrict conv_buf, OverlapIndex *av_restrict idx, float *av_restrict data, int nsamples)
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
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
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
static void common_uninit(FIREqualizerContext *s)
char * av_strdup(const char *s)
Duplicate a string.
static void fast_convolute_nonlinear(FIREqualizerContext *av_restrict s, const float *av_restrict kernel_buf, float *av_restrict conv_buf, OverlapIndex *av_restrict idx, float *av_restrict data, int nsamples)
static int gain_entry_compare(const void *key, const void *memb)
RDFTContext * analysis_rdft
#define fixed(width, name, value)
#define flags(name, subs,...)
void av_rdft_end(RDFTContext *s)
static int config_input(AVFilterLink *inlink)
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
static void dump_fir(AVFilterContext *ctx, FILE *fp, int ch)