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 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.0
E-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.0
E-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.0
E-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.0
E-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.6
E-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;
622 s->channels =
inlink->channels;
623 s->sample_rate =
inlink->sample_rate;
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,
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[]
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.
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().
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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]
Rational number (pair of numerator and denominator).
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.
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.
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
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.
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)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
#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)