Go to the documentation of this file.
33 #define C (M_LN10 * 0.1)
35 #define RRATIO (1.0 - RATIO)
143 #define OFFSET(x) offsetof(AudioFFTDeNoiseContext, x)
144 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
173 d1 =
a /
s->band_centre[band];
174 d1 = 10.0 * log(1.0 + d1 * d1) /
M_LN10;
175 d2 =
b /
s->band_centre[band];
176 d2 = 10.0 * log(1.0 + d2 * d2) /
M_LN10;
177 d3 =
s->band_centre[band] /
c;
178 d3 = 10.0 * log(1.0 + d3 * d3) /
M_LN10;
180 return lrint(-d1 + d2 - d3);
185 for (
int i = 0;
i <
size - 1;
i++) {
186 for (
int j =
i + 1; j <
size; j++) {
190 for (
int k =
i + 1; k <
size; k++) {
197 static void solve(
double *matrix,
double *vector,
int size)
199 for (
int i = 0;
i <
size - 1;
i++) {
200 for (
int j =
i + 1; j <
size; j++) {
201 double d = matrix[j +
i *
size];
202 vector[j] -= d * vector[
i];
208 for (
int i =
size - 2;
i >= 0;
i--) {
209 double d = vector[
i];
210 for (
int j =
i + 1; j <
size; j++)
211 d -= matrix[
i + j *
size] * vector[j];
212 vector[
i] = d / matrix[
i +
i *
size];
220 double product, sum,
f;
226 for (
int j = 0; j < 5; j++) {
228 for (
int k = 0; k < 15; k++)
230 s->vector_b[j] = sum;
233 solve(
s->matrix_a,
s->vector_b, 5);
234 f = (0.5 *
s->sample_rate) /
s->band_centre[14];
235 f = 15.0 + log(
f / 1.5) / log(1.5);
238 for (
int j = 0; j < 5; j++) {
239 sum += product *
s->vector_b[j];
250 double d1 = 0.0, d2 = 1.0;
261 }
else if (d2 < 1.0
E-100) {
270 d2 = log(d2) + 230.2585 *
i;
285 return (
b *
a - 1.0) / (
b +
a - 2.0);
287 return (
b *
a - 2.0 *
a + 1.0) / (
b -
a);
293 double *prior,
double *prior_band_excit,
int track_noise)
295 double d1, d2, d3, gain;
298 d1 = fft_data[0].
re * fft_data[0].
re;
302 gain = d3 / (1.0 + d3);
303 gain *= (gain + M_PI_4 /
fmax(d2, 1.0
E-6));
304 prior[0] = (d2 * gain);
307 dnch->
gain[0] = gain;
309 for (
int i = 1;
i <
s->fft_length2;
i++) {
310 d1 = fft_data[
i].
re * fft_data[
i].
re + fft_data[
i].
im * fft_data[
i].
im;
311 if (d1 >
s->sample_floor)
317 gain = d3 / (1.0 + d3);
318 gain *= (gain + M_PI_4 /
fmax(d2, 1.0
E-6));
319 prior[
i] = d2 * gain;
322 dnch->
gain[
i] = gain;
324 d1 = fft_data[0].
im * fft_data[0].
im;
325 if (d1 >
s->sample_floor)
329 d2 = d1 / dnch->
abs_var[
s->fft_length2];
331 gain = d3 / (1.0 + d3);
332 gain *= gain + M_PI_4 /
fmax(d2, 1.0
E-6);
333 prior[
s->fft_length2] = d2 * gain;
336 dnch->
gain[
s->fft_length2] = gain;
337 if (
n >
s->fft_length2 - 2) {
339 i1 =
s->noise_band_count;
342 for (
int i = 0;
i <=
s->noise_band_count;
i++) {
343 if (
n > 1.1 *
s->noise_band_edge[
i]) {
349 if (track_noise && (i1 >
s->noise_band_count / 2)) {
350 int j =
FFMIN(
n,
s->noise_band_edge[i1]);
353 for (k = i1 - 1; k >= 0; k--) {
354 int i =
s->noise_band_edge[k];
365 double sum = 0.0,
min,
max;
368 for (
i = i1 - 1;
i > k;
i--) {
375 min = 3.0E-4 *
i *
i;
377 min = 3.0E-4 * (8 *
i - 16);
380 max = 2.0E-4 *
i *
i;
382 max = 2.0E-4 * (4 *
i - 4);
385 if (
s->track_residual) {
386 if (
s->last_noise_floor >
s->last_residual_floor + 9) {
389 }
else if (
s->last_noise_floor >
s->last_residual_floor + 6) {
392 }
else if (
s->last_noise_floor >
s->last_residual_floor + 4) {
395 }
else if (
s->last_noise_floor >
s->last_residual_floor + 2) {
398 }
else if (
s->last_noise_floor >
s->last_residual_floor) {
407 sum = av_clipd(sum, -
min,
max);
409 for (
int i = 0;
i < 15;
i++)
417 for (
int i = 0;
i <
s->number_of_bands;
i++) {
422 for (
int i = 0;
i <
s->bin_count;
i++) {
426 for (
int i = 0;
i <
s->number_of_bands;
i++) {
429 s->band_beta[
i] * prior_band_excit[
i]);
433 for (
int j = 0,
i = 0; j <
s->number_of_bands; j++) {
434 for (
int k = 0; k <
s->number_of_bands; k++) {
439 for (
int i = 0;
i <
s->bin_count;
i++)
445 double limit = sqrt(dnch->
abs_var[0] / dnch->
amt[0]);
450 if (dnch->
amt[
s->fft_length2] > dnch->
abs_var[
s->fft_length2]) {
451 dnch->
gain[
s->fft_length2] = 1.0;
453 double limit = sqrt(dnch->
abs_var[
s->fft_length2] / dnch->
amt[
s->fft_length2]);
459 for (
int i = 1;
i <
s->fft_length2;
i++) {
470 gain = dnch->
gain[0];
472 fft_data[0].
re *= gain;
473 gain = dnch->
gain[
s->fft_length2];
475 fft_data[0].
im *= gain;
476 for (
int i = 1;
i <
s->fft_length2;
i++) {
477 gain = dnch->
gain[
i];
479 fft_data[
i].
re *= gain;
480 fft_data[
i].
im *= gain;
486 double d = x / 7500.0;
488 return 13.0 * atan(7.6
E-4 * x) + 3.5 * atan(d * d);
494 return lrint(
s->band_centre[0] / 1.5);
496 return s->band_centre[band];
504 i =
lrint(
s->band_centre[14] * 1.224745);
506 i =
lrint(
s->band_centre[band] / 1.224745);
509 return FFMIN(
i,
s->sample_rate / 2);
515 double band_noise, d2, d3, d4, d5;
516 int i = 0, j = 0, k = 0;
520 for (
int m = j; m <=
s->fft_length2; m++) {
535 dnch->
rel_var[m] =
exp((d5 * d3 + band_noise * d4) *
C);
539 for (
i = 0;
i < 15;
i++)
542 for (
i = 0;
i <=
s->fft_length2;
i++) {
551 char *p, *
arg, *saveptr =
NULL;
552 int i,
ret, band_noise[15] = { 0 };
554 if (!
s->band_noise_str)
561 for (
i = 0;
i < 15;
i++) {
573 band_noise[
i] = av_clip(band_noise[
i], -24, 24);
577 memcpy(dnch->
band_noise, band_noise,
sizeof(band_noise));
582 if (
s->last_noise_floor !=
s->noise_floor)
583 s->last_noise_floor =
s->noise_floor;
585 if (
s->track_residual)
586 s->last_noise_floor =
fmaxf(
s->last_noise_floor,
s->residual_floor);
588 s->max_var =
s->floor *
exp((100.0 +
s->last_noise_floor) *
C);
590 if (
s->track_residual) {
591 s->last_residual_floor =
s->residual_floor;
592 s->last_noise_reduction =
fmax(
s->last_noise_floor -
s->last_residual_floor, 0);
593 s->max_gain =
exp(
s->last_noise_reduction * (0.5 *
C));
594 }
else if (
s->noise_reduction !=
s->last_noise_reduction) {
595 s->last_noise_reduction =
s->noise_reduction;
596 s->last_residual_floor = av_clipf(
s->last_noise_floor -
s->last_noise_reduction, -80, -20);
597 s->max_gain =
exp(
s->last_noise_reduction * (0.5 *
C));
600 s->gain_scale = 1.0 / (
s->max_gain *
s->max_gain);
602 for (
int ch = 0;
ch <
s->channels;
ch++) {
613 double wscale, sar, sum, sdiv;
621 s->channels =
inlink->channels;
622 s->sample_rate =
inlink->sample_rate;
623 s->sample_advance =
s->sample_rate / 80;
624 s->window_length = 3 *
s->sample_advance;
625 s->fft_length2 = 1 << (32 -
ff_clz(
s->window_length));
626 s->fft_length =
s->fft_length2 * 2;
627 s->buffer_length =
s->fft_length * 2;
628 s->bin_count =
s->fft_length2 + 1;
630 s->band_centre[0] = 80;
631 for (
i = 1;
i < 15;
i++) {
632 s->band_centre[
i] =
lrint(1.5 *
s->band_centre[
i - 1] + 5.0);
633 if (
s->band_centre[
i] < 1000) {
634 s->band_centre[
i] = 10 * (
s->band_centre[
i] / 10);
635 }
else if (
s->band_centre[
i] < 5000) {
636 s->band_centre[
i] = 50 * ((
s->band_centre[
i] + 20) / 50);
637 }
else if (
s->band_centre[
i] < 15000) {
638 s->band_centre[
i] = 100 * ((
s->band_centre[
i] + 45) / 100);
640 s->band_centre[
i] = 1000 * ((
s->band_centre[
i] + 495) / 1000);
644 for (j = 0; j < 5; j++) {
645 for (k = 0; k < 5; k++) {
646 s->matrix_a[j + k * 5] = 0.0;
647 for (m = 0; m < 15; m++)
648 s->matrix_a[j + k * 5] += pow(m, j + k);
655 for (j = 0; j < 5; j++)
656 for (k = 0; k < 15; k++)
657 s->matrix_b[
i++] = pow(k, j);
660 for (j = 0; j < 15; j++)
661 for (k = 0; k < 5; k++)
662 s->matrix_c[
i++] = pow(j, k);
664 s->window =
av_calloc(
s->window_length,
sizeof(*
s->window));
665 s->bin2band =
av_calloc(
s->bin_count,
sizeof(*
s->bin2band));
666 if (!
s->window || !
s->bin2band)
669 sdiv =
s->sample_rate / 17640.0;
670 for (
i = 0;
i <=
s->fft_length2;
i++)
673 s->number_of_bands =
s->bin2band[
s->fft_length2] + 1;
675 s->band_alpha =
av_calloc(
s->number_of_bands,
sizeof(*
s->band_alpha));
676 s->band_beta =
av_calloc(
s->number_of_bands,
sizeof(*
s->band_beta));
677 if (!
s->band_alpha || !
s->band_beta)
683 switch (
s->noise_type) {
685 for (
i = 0;
i < 15;
i++)
693 for (
i = 0;
i < 15;
i++)
706 for (
i = 0;
i < 512;
i++)
712 for (
i = 0;
i < 512;
i += j) {
757 double *prior = dnch->
prior;
761 p1 = pow(0.1, 2.5 / sdiv);
762 p2 = pow(0.1, 1.0 / sdiv);
764 for (m = 0; m <
s->number_of_bands; m++) {
765 for (
n = 0;
n <
s->number_of_bands;
n++) {
776 for (m = 0; m <
s->number_of_bands; m++) {
778 prior_band_excit[m] = 0.0;
781 for (m = 0; m <=
s->fft_length2; m++)
785 for (m = 0; m <
s->number_of_bands; m++) {
786 for (
n = 0;
n <
s->number_of_bands;
n++)
792 for (
int i = 0;
i <
s->number_of_bands;
i++) {
793 if (
i <
lrint(12.0 * sdiv)) {
796 dnch->
band_excit[
i] = pow(0.1, 2.5 - 0.2 * (
i / sdiv - 14.0));
801 for (
int i = 0;
i <=
s->fft_length2;
i++)
803 for (
int i = 0;
i <
s->buffer_length;
i++)
807 for (
int i = 0;
i <
s->number_of_bands;
i++)
808 for (
int k = 0; k <
s->number_of_bands; k++)
813 sar =
s->sample_advance /
s->sample_rate;
814 for (
int i = 0;
i <=
s->fft_length2;
i++) {
815 if ((
i ==
s->fft_length2) || (
s->bin2band[
i] > j)) {
816 double d6 = (
i - 1) *
s->sample_rate /
s->fft_length;
817 double d7 =
fmin(0.008 + 2.2 / d6, 0.03);
818 s->band_alpha[j] =
exp(-sar / d7);
819 s->band_beta[j] = 1.0 -
s->band_alpha[j];
824 wscale = sqrt(16.0 / (9.0 *
s->fft_length));
826 for (
int i = 0;
i <
s->window_length;
i++) {
827 double d10 = sin(
i *
M_PI /
s->window_length);
833 s->window_weight = 0.5 * sum;
834 s->floor = (1LL << 48) *
exp(-23.025558369790467) *
s->window_weight;
835 s->sample_floor =
s->floor *
exp(4.144600506562284);
836 s->auto_floor =
s->floor *
exp(6.907667510937141);
842 for (
int j = 1; j < 16; j++) {
844 if (
s->noise_band_edge[j] >
lrint(1.1 *
s->noise_band_edge[j - 1]))
846 s->noise_band_edge[16] =
i;
848 s->noise_band_count =
s->noise_band_edge[16];
859 double d1, d2, d3, d4, d5, d6, d7, d8, d9, d10;
870 for (
i = 1;
i <
len / 4;
i++) {
872 d2 = 0.5 * (
in[
i].re +
in[k].re);
873 d1 = 0.5 * (
in[
i].im -
in[k].im);
874 d4 = 0.5 * (
in[
i].im +
in[k].im);
875 d3 = 0.5 * (
in[k].re -
in[
i].re);
876 in[
i].re = d2 + d9 * d4 + d6 * d3;
877 in[
i].im = d1 + d9 * d3 - d6 * d4;
878 in[k].re = d2 - d9 * d4 - d6 * d3;
879 in[k].im = -d1 + d9 * d3 - d6 * d4;
881 d9 += d9 * d8 - d6 * d7;
882 d6 += d6 * d8 + d10 * d7;
886 in[0].re = d2 +
in[0].im;
887 in[0].im = d2 -
in[0].im;
892 double d1, d2, d3, d4, d5, d6, d7, d8, d9, d10;
902 for (
i = 1;
i <
len / 4;
i++) {
904 d2 = 0.5 * (
in[
i].re +
in[k].re);
905 d1 = 0.5 * (
in[
i].im -
in[k].im);
906 d4 = 0.5 * (
in[
i].re -
in[k].re);
907 d3 = 0.5 * (
in[
i].im +
in[k].im);
908 in[
i].re = d2 - d9 * d3 - d6 * d4;
909 in[
i].im = d1 + d9 * d4 - d6 * d3;
910 in[k].re = d2 + d9 * d3 + d6 * d4;
911 in[k].im = -d1 + d9 * d4 - d6 * d3;
913 d9 += d9 * d8 - d6 * d7;
914 d6 += d6 * d8 + d10 * d7;
917 in[0].re = 0.5 * (d2 +
in[0].im);
918 in[0].im = 0.5 * (d2 -
in[0].im);
923 for (
int i = 0;
i < 15;
i++) {
935 float *
src = (
float *)
in->extended_data[
ch];
936 double mag2, var = 0.0, avr = 0.0, avi = 0.0;
937 int edge, j, k,
n, edgemax;
939 for (
int i = 0;
i <
s->window_length;
i++) {
944 for (
int i =
s->window_length; i < s->fft_length2;
i++) {
954 edge =
s->noise_band_edge[0];
958 edgemax =
fmin(
s->fft_length2,
s->noise_band_edge[15]);
963 for (
int i = j;
i <= edgemax;
i++) {
964 if ((
i == j) && (
i < edgemax)) {
973 j =
s->noise_band_edge[k];
986 mag2 =
fmax(mag2,
s->sample_floor);
1001 double *sample_noise)
1003 for (
int i = 0;
i <
s->noise_band_count;
i++) {
1012 if (
s->noise_band_count < 15) {
1013 for (
int i =
s->noise_band_count;
i < 15;
i++)
1014 sample_noise[
i] = sample_noise[
i - 1];
1020 double *sample_noise,
1023 int new_band_noise[15];
1025 double sum = 0.0, d1;
1026 float new_noise_floor;
1029 for (
int m = 0; m < 15; m++)
1030 temp[m] = sample_noise[m];
1034 for (
int m = 0; m < 5; m++) {
1036 for (
n = 0;
n < 15;
n++)
1037 sum +=
s->matrix_b[
i++] *
temp[
n];
1038 s->vector_b[m] = sum;
1040 solve(
s->matrix_a,
s->vector_b, 5);
1042 for (
int m = 0; m < 15; m++) {
1044 for (
n = 0;
n < 5;
n++)
1045 sum +=
s->matrix_c[
i++] *
s->vector_b[
n];
1051 for (
int m = 0; m < 15; m++)
1054 d1 = (
int)(sum / 15.0 - 0.5);
1058 for (d1 -= dnch->
band_noise[7] -
i; d1 > -20.0; d1 -= 1.0)
1061 for (
int m = 0; m < 15; m++)
1064 new_noise_floor = d1 + 2.5;
1068 for (
int m = 0; m < 15; m++) {
1070 new_band_noise[m] = av_clip(new_band_noise[m], -24, 24);
1074 memcpy(dnch->
band_noise, new_band_noise,
sizeof(new_band_noise));
1078 s->noise_floor = new_noise_floor;
1095 const float *
src = (
const float *)
in->extended_data[
ch];
1098 if (
s->track_noise) {
1099 int i =
s->block_count & 0x1FF;
1108 for (
int m = 0; m <
s->window_length; m++) {
1113 for (
int m =
s->window_length; m < s->fft_length2; m++) {
1131 for (
int m = 0; m <
s->window_length; m++)
1132 dst[m] +=
s->window[m] * dnch->
fft_data[m].
re / (1LL << 24);
1142 if (
s->noise_band_count > 0) {
1143 for (
int i = 0;
i <
s->noise_band_count;
i++) {
1146 if (
s->noise_band_count < 15) {
1147 for (
int i =
s->noise_band_count;
i < 15;
i++)
1148 levels[
i] = levels[
i - 1];
1151 for (
int i = 0;
i < 15;
i++) {
1174 if (
s->track_noise) {
1183 if (
s->noise_floor !=
s->last_noise_floor)
1187 if (
s->sample_noise_start) {
1193 s->sample_noise_start = 0;
1194 s->sample_noise = 1;
1197 if (
s->sample_noise) {
1205 if (
s->sample_noise_end) {
1208 double sample_noise[15];
1214 s->sample_noise = 0;
1215 s->sample_noise_end = 0;
1232 float *orig = (
float *)
in->extended_data[
ch];
1233 float *dst = (
float *)
out->extended_data[
ch];
1235 switch (
s->output_mode) {
1237 for (
int m = 0; m <
s->sample_advance; m++)
1241 for (
int m = 0; m <
s->sample_advance; m++)
1245 for (
int m = 0; m <
s->sample_advance; m++)
1246 dst[m] = orig[m] -
src[m];
1253 memmove(
src,
src +
s->sample_advance, (
s->window_length -
s->sample_advance) *
sizeof(*
src));
1254 memset(
src + (
s->window_length -
s->sample_advance), 0,
s->sample_advance *
sizeof(*
src));
1263 s->pts +=
s->sample_advance;
1317 for (
int ch = 0;
ch <
s->channels;
ch++) {
1374 char *res,
int res_len,
int flags)
1379 if (!strcmp(cmd,
"sample_noise") ||
1380 !strcmp(cmd,
"sn")) {
1381 if (!strcmp(
args,
"start")) {
1382 s->sample_noise_start = 1;
1383 s->sample_noise_end = 0;
1384 }
else if (!strcmp(
args,
"end") ||
1385 !strcmp(
args,
"stop")) {
1386 s->sample_noise_start = 0;
1387 s->sample_noise_end = 1;
1389 }
else if (!strcmp(cmd,
"nr") ||
1390 !strcmp(cmd,
"noise_reduction")) {
1394 s->noise_reduction = av_clipf(nr, 0.01, 97);
1397 }
else if (!strcmp(cmd,
"nf") ||
1398 !strcmp(cmd,
"noise_floor")) {
1402 s->noise_floor = av_clipf(nf, -80, -20);
1405 }
else if (!strcmp(cmd,
"output_mode") ||
1406 !strcmp(cmd,
"om")) {
1407 if (!strcmp(
args,
"i")) {
1409 }
else if (!strcmp(
args,
"o")) {
1411 }
else if (!strcmp(
args,
"n")) {
1444 .priv_class = &afftdn_class,
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
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.
static void set_noise_profile(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, double *sample_noise, int new_profile)
@ AV_SAMPLE_FMT_FLTP
float, planar
A list of supported channel layouts.
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
double noise_band_avr[15]
static void calculate_sfm(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, int start, int end)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static enum AVSampleFormat sample_fmts[]
static int activate(AVFilterContext *ctx)
enum MovChannelLayoutTag * layouts
static const AVFilterPad inputs[]
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 void solve(double *matrix, double *vector, int size)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static av_cold int end(AVCodecContext *avctx)
This structure describes decoded (raw) audio or video data.
static void sample_noise_block(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, AVFrame *in, int ch)
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
const char * name
Filter name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
A link between two filters.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
int channels
Number of channels.
static void postprocess(FFTComplex *in, int len)
static void factor(double *array, int size)
static int config_input(AVFilterLink *inlink)
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Context for an Audio FIFO Buffer.
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
static double freq2bark(double x)
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
static const AVOption afftdn_options[]
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
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().
static int output_frame(AVFilterLink *inlink)
float last_noise_reduction
static int get_band_edge(AudioFFTDeNoiseContext *s, int band)
static void preprocess(FFTComplex *in, int len)
static int query_formats(AVFilterContext *ctx)
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
Describe the class of an AVClass context structure.
double noise_band_auto_var[15]
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
static void get_auto_noise_levels(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, double *levels)
static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static void set_band_parameters(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch)
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
static void init_sample_noise(DeNoiseChannel *dnch)
static void read_custom_noise(AudioFFTDeNoiseContext *s, int ch)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const AVFilterPad outputs[]
float fmaxf(float, float)
double fmin(double, double)
double noise_band_norm[15]
#define AV_NOPTS_VALUE
Undefined timestamp value.
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
static void finish_sample_noise(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, double *sample_noise)
static double limit_gain(double a, double b)
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
#define AV_LOG_INFO
Standard information.
static av_cold void uninit(AVFilterContext *ctx)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
static int get_band_noise(AudioFFTDeNoiseContext *s, int band, double a, double b, double c)
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
#define i(width, name, range_min, range_max)
double * prior_band_excit
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
AVSampleFormat
Audio sample formats.
Used for passing data between threads.
const char AVS_Value args
double noise_band_var[15]
const char * name
Pad name.
double noise_band_sample[15]
static int array[MAX_W *MAX_W]
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
double fmax(double, double)
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 process_frame(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, FFTComplex *fft_data, double *prior, double *prior_band_excit, int track_noise)
static void set_parameters(AudioFFTDeNoiseContext *s)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
char * av_strdup(const char *s)
Duplicate a string.
AVFILTER_DEFINE_CLASS(afftdn)
FF_FILTER_FORWARD_STATUS(inlink, outlink)
#define flags(name, subs,...)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
float last_residual_floor
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
static int get_band_centre(AudioFFTDeNoiseContext *s, int band)
double noise_band_avi[15]
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
static int process_get_band_noise(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, int band)