33 #define C (M_LN10 * 0.1)
35 #define RRATIO (1.0 - RATIO)
143 #define OFFSET(x) offsetof(AudioFFTDeNoiseContext, x)
144 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
145 #define AFR AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
174 d1 =
a /
s->band_centre[band];
175 d1 = 10.0 * log(1.0 + d1 * d1) /
M_LN10;
176 d2 =
b /
s->band_centre[band];
177 d2 = 10.0 * log(1.0 + d2 * d2) /
M_LN10;
178 d3 =
s->band_centre[band] /
c;
179 d3 = 10.0 * log(1.0 + d3 * d3) /
M_LN10;
181 return lrint(-d1 + d2 - d3);
186 for (
int i = 0;
i <
size - 1;
i++) {
187 for (
int j =
i + 1; j <
size; j++) {
191 for (
int k =
i + 1; k <
size; k++) {
198 static void solve(
double *matrix,
double *vector,
int size)
200 for (
int i = 0;
i <
size - 1;
i++) {
201 for (
int j =
i + 1; j <
size; j++) {
202 double d = matrix[j +
i *
size];
203 vector[j] -= d * vector[
i];
209 for (
int i =
size - 2;
i >= 0;
i--) {
210 double d = vector[
i];
211 for (
int j =
i + 1; j <
size; j++)
212 d -= matrix[
i + j *
size] * vector[j];
213 vector[
i] = d / matrix[
i +
i *
size];
221 double product, sum,
f;
227 for (
int j = 0; j < 5; j++) {
229 for (
int k = 0; k < 15; k++)
231 s->vector_b[j] = sum;
234 solve(
s->matrix_a,
s->vector_b, 5);
235 f = (0.5 *
s->sample_rate) /
s->band_centre[14];
236 f = 15.0 + log(
f / 1.5) / log(1.5);
239 for (
int j = 0; j < 5; j++) {
240 sum += product *
s->vector_b[j];
251 double d1 = 0.0, d2 = 1.0;
254 for (
int k = start; k < end; k++) {
262 }
else if (d2 < 1.0E-100) {
271 d2 = log(d2) + 230.2585 *
i;
286 return (
b *
a - 1.0) / (
b +
a - 2.0);
288 return (
b *
a - 2.0 *
a + 1.0) / (
b -
a);
294 double *prior,
double *prior_band_excit,
int track_noise)
296 double d1, d2, d3, gain;
299 d1 = fft_data[0].
re * fft_data[0].
re;
303 gain = d3 / (1.0 + d3);
304 gain *= (gain + M_PI_4 /
fmax(d2, 1.0E-6));
305 prior[0] = (d2 * gain);
308 dnch->
gain[0] = gain;
310 for (
int i = 1;
i <
s->fft_length2;
i++) {
311 d1 = fft_data[
i].
re * fft_data[
i].
re + fft_data[
i].
im * fft_data[
i].
im;
312 if (d1 >
s->sample_floor)
318 gain = d3 / (1.0 + d3);
319 gain *= (gain + M_PI_4 /
fmax(d2, 1.0E-6));
320 prior[
i] = d2 * gain;
323 dnch->
gain[
i] = gain;
325 d1 = fft_data[0].
im * fft_data[0].
im;
326 if (d1 >
s->sample_floor)
330 d2 = d1 / dnch->
abs_var[
s->fft_length2];
332 gain = d3 / (1.0 + d3);
333 gain *= gain + M_PI_4 /
fmax(d2, 1.0E-6);
334 prior[
s->fft_length2] = d2 * gain;
337 dnch->
gain[
s->fft_length2] = gain;
338 if (n >
s->fft_length2 - 2) {
340 i1 =
s->noise_band_count;
343 for (
int i = 0;
i <=
s->noise_band_count;
i++) {
344 if (n > 1.1 *
s->noise_band_edge[
i]) {
350 if (track_noise && (i1 >
s->noise_band_count / 2)) {
351 int j =
FFMIN(n,
s->noise_band_edge[i1]);
354 for (k = i1 - 1; k >= 0; k--) {
355 int i =
s->noise_band_edge[k];
366 double sum = 0.0,
min,
max;
369 for (
i = i1 - 1;
i > k;
i--) {
376 min = 3.0E-4 *
i *
i;
378 min = 3.0E-4 * (8 *
i - 16);
381 max = 2.0E-4 *
i *
i;
383 max = 2.0E-4 * (4 *
i - 4);
386 if (
s->track_residual) {
387 if (
s->last_noise_floor >
s->last_residual_floor + 9) {
390 }
else if (
s->last_noise_floor >
s->last_residual_floor + 6) {
393 }
else if (
s->last_noise_floor >
s->last_residual_floor + 4) {
396 }
else if (
s->last_noise_floor >
s->last_residual_floor + 2) {
399 }
else if (
s->last_noise_floor >
s->last_residual_floor) {
410 for (
int i = 0;
i < 15;
i++)
418 for (
int i = 0;
i <
s->number_of_bands;
i++) {
423 for (
int i = 0;
i <
s->bin_count;
i++) {
427 for (
int i = 0;
i <
s->number_of_bands;
i++) {
430 s->band_beta[
i] * prior_band_excit[
i]);
434 for (
int j = 0,
i = 0; j <
s->number_of_bands; j++) {
435 for (
int k = 0; k <
s->number_of_bands; k++) {
440 for (
int i = 0;
i <
s->bin_count;
i++)
446 double limit = sqrt(dnch->
abs_var[0] / dnch->
amt[0]);
451 if (dnch->
amt[
s->fft_length2] > dnch->
abs_var[
s->fft_length2]) {
452 dnch->
gain[
s->fft_length2] = 1.0;
454 double limit = sqrt(dnch->
abs_var[
s->fft_length2] / dnch->
amt[
s->fft_length2]);
460 for (
int i = 1;
i <
s->fft_length2;
i++) {
471 gain = dnch->
gain[0];
473 fft_data[0].
re *= gain;
474 gain = dnch->
gain[
s->fft_length2];
476 fft_data[0].
im *= gain;
477 for (
int i = 1;
i <
s->fft_length2;
i++) {
478 gain = dnch->
gain[
i];
480 fft_data[
i].
re *= gain;
481 fft_data[
i].
im *= gain;
487 double d = x / 7500.0;
489 return 13.0 * atan(7.6E-4 * x) + 3.5 * atan(d * d);
495 return lrint(
s->band_centre[0] / 1.5);
497 return s->band_centre[band];
505 i =
lrint(
s->band_centre[14] * 1.224745);
507 i =
lrint(
s->band_centre[band] / 1.224745);
510 return FFMIN(
i,
s->sample_rate / 2);
516 double band_noise, d2, d3, d4, d5;
517 int i = 0, j = 0, k = 0;
521 for (
int m = j; m <=
s->fft_length2; m++) {
536 dnch->
rel_var[m] =
exp((d5 * d3 + band_noise * d4) *
C);
540 for (
i = 0;
i < 15;
i++)
543 for (
i = 0;
i <=
s->fft_length2;
i++) {
552 char *p, *
arg, *saveptr =
NULL;
553 int i, ret, band_noise[15] = { 0 };
555 if (!
s->band_noise_str)
562 for (
i = 0;
i < 15;
i++) {
574 band_noise[
i] =
av_clip(band_noise[
i], -24, 24);
578 memcpy(dnch->
band_noise, band_noise,
sizeof(band_noise));
583 if (
s->last_noise_floor !=
s->noise_floor)
584 s->last_noise_floor =
s->noise_floor;
586 if (
s->track_residual)
587 s->last_noise_floor =
fmaxf(
s->last_noise_floor,
s->residual_floor);
589 s->max_var =
s->floor *
exp((100.0 +
s->last_noise_floor) *
C);
591 if (
s->track_residual) {
592 s->last_residual_floor =
s->residual_floor;
593 s->last_noise_reduction =
fmax(
s->last_noise_floor -
s->last_residual_floor, 0);
594 s->max_gain =
exp(
s->last_noise_reduction * (0.5 *
C));
595 }
else if (
s->noise_reduction !=
s->last_noise_reduction) {
596 s->last_noise_reduction =
s->noise_reduction;
597 s->last_residual_floor =
av_clipf(
s->last_noise_floor -
s->last_noise_reduction, -80, -20);
598 s->max_gain =
exp(
s->last_noise_reduction * (0.5 *
C));
601 s->gain_scale = 1.0 / (
s->max_gain *
s->max_gain);
603 for (
int ch = 0; ch <
s->channels; ch++) {
614 double wscale, sar, sum, sdiv;
624 s->sample_advance =
s->sample_rate / 80;
625 s->window_length = 3 *
s->sample_advance;
626 s->fft_length2 = 1 << (32 -
ff_clz(
s->window_length));
627 s->fft_length =
s->fft_length2 * 2;
628 s->buffer_length =
s->fft_length * 2;
629 s->bin_count =
s->fft_length2 + 1;
631 s->band_centre[0] = 80;
632 for (
i = 1;
i < 15;
i++) {
633 s->band_centre[
i] =
lrint(1.5 *
s->band_centre[
i - 1] + 5.0);
634 if (
s->band_centre[
i] < 1000) {
635 s->band_centre[
i] = 10 * (
s->band_centre[
i] / 10);
636 }
else if (
s->band_centre[
i] < 5000) {
637 s->band_centre[
i] = 50 * ((
s->band_centre[
i] + 20) / 50);
638 }
else if (
s->band_centre[
i] < 15000) {
639 s->band_centre[
i] = 100 * ((
s->band_centre[
i] + 45) / 100);
641 s->band_centre[
i] = 1000 * ((
s->band_centre[
i] + 495) / 1000);
645 for (j = 0; j < 5; j++) {
646 for (k = 0; k < 5; k++) {
647 s->matrix_a[j + k * 5] = 0.0;
648 for (m = 0; m < 15; m++)
649 s->matrix_a[j + k * 5] += pow(m, j + k);
656 for (j = 0; j < 5; j++)
657 for (k = 0; k < 15; k++)
658 s->matrix_b[
i++] = pow(k, j);
661 for (j = 0; j < 15; j++)
662 for (k = 0; k < 5; k++)
663 s->matrix_c[
i++] = pow(j, k);
665 s->window =
av_calloc(
s->window_length,
sizeof(*
s->window));
666 s->bin2band =
av_calloc(
s->bin_count,
sizeof(*
s->bin2band));
667 if (!
s->window || !
s->bin2band)
670 sdiv =
s->sample_rate / 17640.0;
671 for (
i = 0;
i <=
s->fft_length2;
i++)
674 s->number_of_bands =
s->bin2band[
s->fft_length2] + 1;
676 s->band_alpha =
av_calloc(
s->number_of_bands,
sizeof(*
s->band_alpha));
677 s->band_beta =
av_calloc(
s->number_of_bands,
sizeof(*
s->band_beta));
678 if (!
s->band_alpha || !
s->band_beta)
681 for (
int ch = 0; ch < inlink->
channels; ch++) {
684 switch (
s->noise_type) {
686 for (
i = 0;
i < 15;
i++)
694 for (
i = 0;
i < 15;
i++)
707 for (
i = 0;
i < 512;
i++)
713 for (
i = 0;
i < 512;
i += j) {
755 for (
int ch = 0; ch < inlink->
channels; ch++) {
758 double *prior = dnch->
prior;
762 p1 = pow(0.1, 2.5 / sdiv);
763 p2 = pow(0.1, 1.0 / sdiv);
765 for (m = 0; m <
s->number_of_bands; m++) {
766 for (n = 0; n <
s->number_of_bands; n++) {
777 for (m = 0; m <
s->number_of_bands; m++) {
779 prior_band_excit[m] = 0.0;
782 for (m = 0; m <=
s->fft_length2; m++)
786 for (m = 0; m <
s->number_of_bands; m++) {
787 for (n = 0; n <
s->number_of_bands; n++)
793 for (
int i = 0;
i <
s->number_of_bands;
i++) {
794 if (
i <
lrint(12.0 * sdiv)) {
797 dnch->
band_excit[
i] = pow(0.1, 2.5 - 0.2 * (
i / sdiv - 14.0));
802 for (
int i = 0;
i <=
s->fft_length2;
i++)
804 for (
int i = 0;
i <
s->buffer_length;
i++)
808 for (
int i = 0;
i <
s->number_of_bands;
i++)
809 for (
int k = 0; k <
s->number_of_bands; k++)
814 sar =
s->sample_advance /
s->sample_rate;
815 for (
int i = 0;
i <=
s->fft_length2;
i++) {
816 if ((
i ==
s->fft_length2) || (
s->bin2band[
i] > j)) {
817 double d6 = (
i - 1) *
s->sample_rate /
s->fft_length;
818 double d7 =
fmin(0.008 + 2.2 / d6, 0.03);
819 s->band_alpha[j] =
exp(-sar / d7);
820 s->band_beta[j] = 1.0 -
s->band_alpha[j];
825 wscale = sqrt(16.0 / (9.0 *
s->fft_length));
827 for (
int i = 0;
i <
s->window_length;
i++) {
828 double d10 = sin(
i *
M_PI /
s->window_length);
834 s->window_weight = 0.5 * sum;
835 s->floor = (1LL << 48) *
exp(-23.025558369790467) *
s->window_weight;
836 s->sample_floor =
s->floor *
exp(4.144600506562284);
837 s->auto_floor =
s->floor *
exp(6.907667510937141);
843 for (
int j = 1; j < 16; j++) {
845 if (
s->noise_band_edge[j] >
lrint(1.1 *
s->noise_band_edge[j - 1]))
847 s->noise_band_edge[16] =
i;
849 s->noise_band_count =
s->noise_band_edge[16];
860 double d1, d2, d3, d4, d5, d6, d7, d8, d9, d10;
871 for (
i = 1;
i <
len / 4;
i++) {
873 d2 = 0.5 * (
in[
i].re +
in[k].re);
874 d1 = 0.5 * (
in[
i].im -
in[k].im);
875 d4 = 0.5 * (
in[
i].im +
in[k].im);
876 d3 = 0.5 * (
in[k].re -
in[
i].re);
877 in[
i].re = d2 + d9 * d4 + d6 * d3;
878 in[
i].im = d1 + d9 * d3 - d6 * d4;
879 in[k].re = d2 - d9 * d4 - d6 * d3;
880 in[k].im = -d1 + d9 * d3 - d6 * d4;
882 d9 += d9 * d8 - d6 * d7;
883 d6 += d6 * d8 + d10 * d7;
887 in[0].re = d2 +
in[0].im;
888 in[0].im = d2 -
in[0].im;
893 double d1, d2, d3, d4, d5, d6, d7, d8, d9, d10;
903 for (
i = 1;
i <
len / 4;
i++) {
905 d2 = 0.5 * (
in[
i].re +
in[k].re);
906 d1 = 0.5 * (
in[
i].im -
in[k].im);
907 d4 = 0.5 * (
in[
i].re -
in[k].re);
908 d3 = 0.5 * (
in[
i].im +
in[k].im);
909 in[
i].re = d2 - d9 * d3 - d6 * d4;
910 in[
i].im = d1 + d9 * d4 - d6 * d3;
911 in[k].re = d2 + d9 * d3 + d6 * d4;
912 in[k].im = -d1 + d9 * d4 - d6 * d3;
914 d9 += d9 * d8 - d6 * d7;
915 d6 += d6 * d8 + d10 * d7;
918 in[0].re = 0.5 * (d2 +
in[0].im);
919 in[0].im = 0.5 * (d2 -
in[0].im);
924 for (
int i = 0;
i < 15;
i++) {
936 float *
src = (
float *)
in->extended_data[ch];
937 double mag2, var = 0.0, avr = 0.0, avi = 0.0;
938 int edge, j, k, n, edgemax;
940 for (
int i = 0;
i <
s->window_length;
i++) {
945 for (
int i =
s->window_length; i < s->fft_length2;
i++) {
955 edge =
s->noise_band_edge[0];
959 edgemax =
fmin(
s->fft_length2,
s->noise_band_edge[15]);
964 for (
int i = j;
i <= edgemax;
i++) {
965 if ((
i == j) && (
i < edgemax)) {
974 j =
s->noise_band_edge[k];
987 mag2 =
fmax(mag2,
s->sample_floor);
1002 double *sample_noise)
1004 for (
int i = 0;
i <
s->noise_band_count;
i++) {
1013 if (
s->noise_band_count < 15) {
1014 for (
int i =
s->noise_band_count;
i < 15;
i++)
1015 sample_noise[
i] = sample_noise[
i - 1];
1021 double *sample_noise,
1024 int new_band_noise[15];
1026 double sum = 0.0, d1;
1027 float new_noise_floor;
1030 for (
int m = 0; m < 15; m++)
1031 temp[m] = sample_noise[m];
1035 for (
int m = 0; m < 5; m++) {
1037 for (n = 0; n < 15; n++)
1038 sum +=
s->matrix_b[
i++] *
temp[n];
1039 s->vector_b[m] = sum;
1041 solve(
s->matrix_a,
s->vector_b, 5);
1043 for (
int m = 0; m < 15; m++) {
1045 for (n = 0; n < 5; n++)
1046 sum +=
s->matrix_c[
i++] *
s->vector_b[n];
1052 for (
int m = 0; m < 15; m++)
1055 d1 = (
int)(sum / 15.0 - 0.5);
1059 for (d1 -= dnch->
band_noise[7] -
i; d1 > -20.0; d1 -= 1.0)
1062 for (
int m = 0; m < 15; m++)
1065 new_noise_floor = d1 + 2.5;
1069 for (
int m = 0; m < 15; m++) {
1071 new_band_noise[m] =
av_clip(new_band_noise[m], -24, 24);
1075 memcpy(dnch->
band_noise, new_band_noise,
sizeof(new_band_noise));
1079 s->noise_floor = new_noise_floor;
1091 const int start = (
in->
channels * jobnr) / nb_jobs;
1092 const int end = (
in->
channels * (jobnr+1)) / nb_jobs;
1094 for (
int ch = start; ch < end; ch++) {
1096 const float *
src = (
const float *)
in->extended_data[ch];
1099 if (
s->track_noise) {
1100 int i =
s->block_count & 0x1FF;
1109 for (
int m = 0; m <
s->window_length; m++) {
1114 for (
int m =
s->window_length; m < s->fft_length2; m++) {
1132 for (
int m = 0; m <
s->window_length; m++)
1133 dst[m] +=
s->window[m] * dnch->
fft_data[m].
re / (1LL << 24);
1143 if (
s->noise_band_count > 0) {
1144 for (
int i = 0;
i <
s->noise_band_count;
i++) {
1147 if (
s->noise_band_count < 15) {
1148 for (
int i =
s->noise_band_count;
i < 15;
i++)
1149 levels[
i] = levels[
i - 1];
1152 for (
int i = 0;
i < 15;
i++) {
1175 if (
s->track_noise) {
1176 for (
int ch = 0; ch < inlink->
channels; ch++) {
1184 if (
s->noise_floor !=
s->last_noise_floor)
1188 if (
s->sample_noise_start) {
1189 for (
int ch = 0; ch < inlink->
channels; ch++) {
1194 s->sample_noise_start = 0;
1195 s->sample_noise = 1;
1198 if (
s->sample_noise) {
1199 for (
int ch = 0; ch < inlink->
channels; ch++) {
1206 if (
s->sample_noise_end) {
1207 for (
int ch = 0; ch < inlink->
channels; ch++) {
1209 double sample_noise[15];
1215 s->sample_noise = 0;
1216 s->sample_noise_end = 0;
1230 for (
int ch = 0; ch < inlink->
channels; ch++) {
1233 float *orig = (
float *)
in->extended_data[ch];
1234 float *dst = (
float *)
out->extended_data[ch];
1236 switch (
s->output_mode) {
1238 for (
int m = 0; m <
s->sample_advance; m++)
1242 for (
int m = 0; m <
s->sample_advance; m++)
1246 for (
int m = 0; m <
s->sample_advance; m++)
1247 dst[m] = orig[m] -
src[m];
1254 memmove(
src,
src +
s->sample_advance, (
s->window_length -
s->sample_advance) *
sizeof(*
src));
1255 memset(
src + (
s->window_length -
s->sample_advance), 0,
s->sample_advance *
sizeof(*
src));
1318 for (
int ch = 0; ch <
s->channels; ch++) {
1375 char *res,
int res_len,
int flags)
1381 if (!strcmp(cmd,
"sample_noise") ||
1382 !strcmp(cmd,
"sn")) {
1383 if (!strcmp(args,
"start")) {
1384 s->sample_noise_start = 1;
1385 s->sample_noise_end = 0;
1386 }
else if (!strcmp(args,
"end") ||
1387 !strcmp(args,
"stop")) {
1388 s->sample_noise_start = 0;
1389 s->sample_noise_end = 1;
1426 .priv_class = &afftdn_class,
static enum AVSampleFormat sample_fmts[]
static int get_band_edge(AudioFFTDeNoiseContext *s, int band)
static void calculate_sfm(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, int start, int end)
static int get_band_noise(AudioFFTDeNoiseContext *s, int band, double a, double b, double c)
static void set_parameters(AudioFFTDeNoiseContext *s)
static void postprocess(FFTComplex *in, int len)
static void factor(double *array, int size)
static void preprocess(FFTComplex *in, int len)
static const AVOption afftdn_options[]
static int query_formats(AVFilterContext *ctx)
static int output_frame(AVFilterLink *inlink)
static int config_input(AVFilterLink *inlink)
static void set_band_parameters(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch)
static const AVFilterPad inputs[]
static void finish_sample_noise(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, double *sample_noise)
static void set_noise_profile(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, double *sample_noise, int new_profile)
static const AVFilterPad outputs[]
AVFILTER_DEFINE_CLASS(afftdn)
static void sample_noise_block(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, AVFrame *in, int ch)
static void solve(double *matrix, double *vector, int size)
static void get_auto_noise_levels(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, double *levels)
static void process_frame(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, FFTComplex *fft_data, double *prior, double *prior_band_excit, int track_noise)
static int get_band_centre(AudioFFTDeNoiseContext *s, int band)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static int activate(AVFilterContext *ctx)
static int process_get_band_noise(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, int band)
static av_cold void uninit(AVFilterContext *ctx)
static double freq2bark(double x)
static void init_sample_noise(DeNoiseChannel *dnch)
static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static void read_custom_noise(AudioFFTDeNoiseContext *s, int ch)
static double limit_gain(double a, double b)
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Main libavfilter public API header.
#define flags(name, subs,...)
audio channel layout utility functions
double fmin(double, double)
double fmax(double, double)
float fmaxf(float, float)
#define FF_FILTER_FORWARD_STATUS(inlink, outlink)
Acknowledge the status on an input link and forward it to an output link.
#define FFERROR_NOT_READY
Filters implementation helper functions.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
static int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
av_cold void av_fft_end(FFTContext *s)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
char * av_strdup(const char *s)
Duplicate a string.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
enum MovChannelLayoutTag * layouts
Context for an Audio FIFO Buffer.
Describe the class of an AVClass context structure.
A list of supported channel layouts.
A link between two filters.
int channels
Number of channels.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int sample_rate
samples per second
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t ** extended_data
pointers to the data planes/channels.
Rational number (pair of numerator and denominator).
float last_residual_floor
float last_noise_reduction
double noise_band_sample[15]
double noise_band_avr[15]
double * prior_band_excit
double noise_band_avi[15]
double noise_band_norm[15]
double noise_band_var[15]
double noise_band_auto_var[15]
Used for passing data between threads.
static int array[MAX_W *MAX_W]