47 0.000146098, -0.000232304, -0.000285414, 0.000462093, 0.000559952,
48 -0.000927187, -0.001103748, 0.00188212, 0.002186714, -0.003882426,
49 -0.00435384, 0.008201477, 0.008685294, -0.017982291, -0.017176331,
50 0.042068328, 0.032080869, -0.110036987, -0.050201753, 0.433923147,
51 0.766130398, 0.433923147, -0.050201753, -0.110036987, 0.032080869,
52 0.042068328, -0.017176331, -0.017982291, 0.008685294, 0.008201477,
53 -0.00435384, -0.003882426, 0.002186714, 0.00188212, -0.001103748,
54 -0.000927187, 0.000559952, 0.000462093, -0.000285414, -0.000232304,
59 0.0, 0.000146098, 0.000232304, -0.000285414, -0.000462093, 0.000559952,
60 0.000927187, -0.001103748, -0.00188212, 0.002186714, 0.003882426,
61 -0.00435384, -0.008201477, 0.008685294, 0.017982291, -0.017176331,
62 -0.042068328, 0.032080869, 0.110036987, -0.050201753, -0.433923147,
63 0.766130398, -0.433923147, -0.050201753, 0.110036987, 0.032080869,
64 -0.042068328, -0.017176331, 0.017982291, 0.008685294, -0.008201477,
65 -0.00435384, 0.003882426, 0.002186714, -0.00188212, -0.001103748,
66 0.000927187, 0.000559952, -0.000462093, -0.000285414, 0.000232304,
71 0.0, 0.000146098, -0.000232304, -0.000285414, 0.000462093, 0.000559952,
72 -0.000927187, -0.001103748, 0.00188212, 0.002186714, -0.003882426,
73 -0.00435384, 0.008201477, 0.008685294, -0.017982291, -0.017176331,
74 0.042068328, 0.032080869, -0.110036987, -0.050201753, 0.433923147,
75 0.766130398, 0.433923147, -0.050201753, -0.110036987, 0.032080869,
76 0.042068328, -0.017176331, -0.017982291, 0.008685294, 0.008201477,
77 -0.00435384, -0.003882426, 0.002186714, 0.00188212, -0.001103748,
78 -0.000927187, 0.000559952, 0.000462093, -0.000285414, -0.000232304,
83 0.000146098, 0.000232304, -0.000285414, -0.000462093, 0.000559952,
84 0.000927187, -0.001103748, -0.00188212, 0.002186714, 0.003882426,
85 -0.00435384, -0.008201477, 0.008685294, 0.017982291, -0.017176331,
86 -0.042068328, 0.032080869, 0.110036987, -0.050201753, -0.433923147,
87 0.766130398, -0.433923147, -0.050201753, 0.110036987, 0.032080869,
88 -0.042068328, -0.017176331, 0.017982291, 0.008685294, -0.008201477,
89 -0.00435384, 0.003882426, 0.002186714, -0.00188212, -0.001103748,
90 0.000927187, 0.000559952, -0.000462093, -0.000285414, 0.000232304,
95 0.0007701598091144901, 9.563267072289475e-05,
96 -0.008641299277022422, -0.0014653825813050513,
97 0.0459272392310922, 0.011609893903711381,
98 -0.15949427888491757, -0.07088053578324385,
99 0.47169066693843925, 0.7695100370211071,
100 0.38382676106708546, -0.03553674047381755,
101 -0.0319900568824278, 0.04999497207737669,
102 0.005764912033581909, -0.02035493981231129,
103 -0.0008043589320165449, 0.004593173585311828,
104 5.7036083618494284e-05, -0.0004593294210046588,
108 0.0004593294210046588, 5.7036083618494284e-05,
109 -0.004593173585311828, -0.0008043589320165449,
110 0.02035493981231129, 0.005764912033581909,
111 -0.04999497207737669, -0.0319900568824278,
112 0.03553674047381755, 0.38382676106708546,
113 -0.7695100370211071, 0.47169066693843925,
114 0.07088053578324385, -0.15949427888491757,
115 -0.011609893903711381, 0.0459272392310922,
116 0.0014653825813050513, -0.008641299277022422,
117 -9.563267072289475e-05, 0.0007701598091144901,
121 -0.0004593294210046588, 5.7036083618494284e-05,
122 0.004593173585311828, -0.0008043589320165449,
123 -0.02035493981231129, 0.005764912033581909,
124 0.04999497207737669, -0.0319900568824278,
125 -0.03553674047381755, 0.38382676106708546,
126 0.7695100370211071, 0.47169066693843925,
127 -0.07088053578324385, -0.15949427888491757,
128 0.011609893903711381, 0.0459272392310922,
129 -0.0014653825813050513, -0.008641299277022422,
130 9.563267072289475e-05, 0.0007701598091144901,
134 0.0007701598091144901, -9.563267072289475e-05,
135 -0.008641299277022422, 0.0014653825813050513,
136 0.0459272392310922, -0.011609893903711381,
137 -0.15949427888491757, 0.07088053578324385,
138 0.47169066693843925, -0.7695100370211071,
139 0.38382676106708546, 0.03553674047381755,
140 -0.0319900568824278, -0.04999497207737669,
141 0.005764912033581909, 0.02035493981231129,
142 -0.0008043589320165449, -0.004593173585311828,
143 5.7036083618494284e-05, 0.0004593294210046588,
148 0.014426282505624435, 0.014467504896790148,
149 -0.07872200106262882, -0.04036797903033992,
150 0.41784910915027457, 0.7589077294536541,
151 0.41784910915027457, -0.04036797903033992,
152 -0.07872200106262882, 0.014467504896790148,
153 0.014426282505624435, 0.0, 0.0, 0.0,
157 -0.0019088317364812906, -0.0019142861290887667,
158 0.016990639867602342, 0.01193456527972926,
159 -0.04973290349094079, -0.07726317316720414,
160 0.09405920349573646, 0.4207962846098268,
161 -0.8259229974584023, 0.4207962846098268,
162 0.09405920349573646, -0.07726317316720414,
163 -0.04973290349094079, 0.01193456527972926,
164 0.016990639867602342, -0.0019142861290887667,
165 -0.0019088317364812906, 0.0,
169 0.0019088317364812906, -0.0019142861290887667,
170 -0.016990639867602342, 0.01193456527972926,
171 0.04973290349094079, -0.07726317316720414,
172 -0.09405920349573646, 0.4207962846098268,
173 0.8259229974584023, 0.4207962846098268,
174 -0.09405920349573646, -0.07726317316720414,
175 0.04973290349094079, 0.01193456527972926,
176 -0.016990639867602342, -0.0019142861290887667,
177 0.0019088317364812906, 0.0,
182 0.014426282505624435, -0.014467504896790148,
183 -0.07872200106262882, 0.04036797903033992,
184 0.41784910915027457, -0.7589077294536541,
185 0.41784910915027457, 0.04036797903033992,
186 -0.07872200106262882, -0.014467504896790148,
187 0.014426282505624435, 0.0, 0.0, 0.0,
191 -9.517657273819165e-08, -1.6744288576823017e-07,
192 2.0637618513646814e-06, 3.7346551751414047e-06,
193 -2.1315026809955787e-05, -4.134043227251251e-05,
194 0.00014054114970203437, 0.00030225958181306315,
195 -0.0006381313430451114, -0.0016628637020130838,
196 0.0024333732126576722, 0.006764185448053083,
197 -0.009164231162481846, -0.01976177894257264,
198 0.03268357426711183, 0.0412892087501817,
199 -0.10557420870333893, -0.06203596396290357,
200 0.4379916261718371, 0.7742896036529562,
201 0.4215662066908515, -0.05204316317624377,
202 -0.09192001055969624, 0.02816802897093635,
203 0.023408156785839195, -0.010131117519849788,
204 -0.004159358781386048, 0.0021782363581090178,
205 0.00035858968789573785, -0.00021208083980379827,
209 0.00021208083980379827, 0.00035858968789573785,
210 -0.0021782363581090178, -0.004159358781386048,
211 0.010131117519849788, 0.023408156785839195,
212 -0.02816802897093635, -0.09192001055969624,
213 0.05204316317624377, 0.4215662066908515,
214 -0.7742896036529562, 0.4379916261718371,
215 0.06203596396290357, -0.10557420870333893,
216 -0.0412892087501817, 0.03268357426711183,
217 0.01976177894257264, -0.009164231162481846,
218 -0.006764185448053083, 0.0024333732126576722,
219 0.0016628637020130838, -0.0006381313430451114,
220 -0.00030225958181306315, 0.00014054114970203437,
221 4.134043227251251e-05, -2.1315026809955787e-05,
222 -3.7346551751414047e-06, 2.0637618513646814e-06,
223 1.6744288576823017e-07, -9.517657273819165e-08,
227 -0.00021208083980379827, 0.00035858968789573785,
228 0.0021782363581090178, -0.004159358781386048,
229 -0.010131117519849788, 0.023408156785839195,
230 0.02816802897093635, -0.09192001055969624,
231 -0.05204316317624377, 0.4215662066908515,
232 0.7742896036529562, 0.4379916261718371,
233 -0.06203596396290357, -0.10557420870333893,
234 0.0412892087501817, 0.03268357426711183,
235 -0.01976177894257264, -0.009164231162481846,
236 0.006764185448053083, 0.0024333732126576722,
237 -0.0016628637020130838, -0.0006381313430451114,
238 0.00030225958181306315, 0.00014054114970203437,
239 -4.134043227251251e-05, -2.1315026809955787e-05,
240 3.7346551751414047e-06, 2.0637618513646814e-06,
241 -1.6744288576823017e-07, -9.517657273819165e-08,
245 -9.517657273819165e-08, 1.6744288576823017e-07,
246 2.0637618513646814e-06, -3.7346551751414047e-06,
247 -2.1315026809955787e-05, 4.134043227251251e-05,
248 0.00014054114970203437, -0.00030225958181306315,
249 -0.0006381313430451114, 0.0016628637020130838,
250 0.0024333732126576722, -0.006764185448053083,
251 -0.009164231162481846, 0.01976177894257264,
252 0.03268357426711183, -0.0412892087501817,
253 -0.10557420870333893, 0.06203596396290357,
254 0.4379916261718371, -0.7742896036529562,
255 0.4215662066908515, 0.05204316317624377,
256 -0.09192001055969624, -0.02816802897093635,
257 0.023408156785839195, 0.010131117519849788,
258 -0.004159358781386048, -0.0021782363581090178,
259 0.00035858968789573785, 0.00021208083980379827,
263 -1.326420300235487e-05, 9.358867000108985e-05,
264 -0.0001164668549943862, -0.0006858566950046825,
265 0.00199240529499085, 0.0013953517469940798,
266 -0.010733175482979604, 0.0036065535669883944,
267 0.03321267405893324, -0.02945753682194567,
268 -0.07139414716586077, 0.09305736460380659,
269 0.12736934033574265, -0.19594627437659665,
270 -0.24984642432648865, 0.2811723436604265,
271 0.6884590394525921, 0.5272011889309198,
272 0.18817680007762133, 0.026670057900950818,
276 -0.026670057900950818, 0.18817680007762133,
277 -0.5272011889309198, 0.6884590394525921,
278 -0.2811723436604265, -0.24984642432648865,
279 0.19594627437659665, 0.12736934033574265,
280 -0.09305736460380659, -0.07139414716586077,
281 0.02945753682194567, 0.03321267405893324,
282 -0.0036065535669883944, -0.010733175482979604,
283 -0.0013953517469940798, 0.00199240529499085,
284 0.0006858566950046825, -0.0001164668549943862,
285 -9.358867000108985e-05, -1.326420300235487e-05,
289 0.026670057900950818, 0.18817680007762133,
290 0.5272011889309198, 0.6884590394525921,
291 0.2811723436604265, -0.24984642432648865,
292 -0.19594627437659665, 0.12736934033574265,
293 0.09305736460380659, -0.07139414716586077,
294 -0.02945753682194567, 0.03321267405893324,
295 0.0036065535669883944, -0.010733175482979604,
296 0.0013953517469940798, 0.00199240529499085,
297 -0.0006858566950046825, -0.0001164668549943862,
298 9.358867000108985e-05, -1.326420300235487e-05,
302 -1.326420300235487e-05, -9.358867000108985e-05,
303 -0.0001164668549943862, 0.0006858566950046825,
304 0.00199240529499085, -0.0013953517469940798,
305 -0.010733175482979604, -0.0036065535669883944,
306 0.03321267405893324, 0.02945753682194567,
307 -0.07139414716586077, -0.09305736460380659,
308 0.12736934033574265, 0.19594627437659665,
309 -0.24984642432648865, -0.2811723436604265,
310 0.6884590394525921, -0.5272011889309198,
311 0.18817680007762133, -0.026670057900950818,
315 -0.07576571478927333,
316 -0.02963552764599851,
320 -0.09921954357684722,
321 -0.012603967262037833,
327 -0.012603967262037833,
333 -0.07576571478927333,
338 -0.012603967262037833,
339 -0.09921954357684722,
343 -0.02963552764599851,
344 -0.07576571478927333,
348 -0.07576571478927333,
354 -0.012603967262037833,
359 -0.12940952255092145, 0.22414386804185735,
360 0.836516303737469, 0.48296291314469025,
364 -0.48296291314469025, 0.836516303737469,
365 -0.22414386804185735, -0.12940952255092145,
369 0.48296291314469025, 0.836516303737469,
370 0.22414386804185735, -0.12940952255092145,
374 -0.12940952255092145, -0.22414386804185735,
375 0.836516303737469, -0.48296291314469025,
378 #define MAX_LEVELS 13
439 #define OFFSET(x) offsetof(AudioFWTDNContext, x)
440 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
441 #define AFR AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
457 {
"samples",
"set frame size in number of samples",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=8192}, 512, 65536,
AF },
464 #define pow2(x) (1U << (x))
465 #define mod_pow2(x, power_of_two) ((x) & ((power_of_two) - 1))
467 static void conv_down(
double *in,
int in_length,
double *low,
double *high,
468 int out_length,
const double *lp,
const double *hp,
469 int wavelet_length,
int skip,
470 double *
buffer,
int buffer_length)
472 double thigh = 0.0, tlow = 0.0;
473 int buff_idx = 1 +
skip;
476 memset(
buffer + buff_idx, 0, (buffer_length - buff_idx) *
sizeof(*
buffer));
478 for (
int i = 0;
i < out_length - 1;
i++) {
479 double thigh = 0.0, tlow = 0.0;
481 for (
int j = 0; j < wavelet_length; j++) {
482 const int idx =
mod_pow2(-j + buff_idx - 1, buffer_length);
483 const double btemp =
buffer[idx];
485 thigh += btemp * hp[j];
486 tlow += btemp * lp[j];
493 buff_idx =
mod_pow2(buff_idx, buffer_length);
496 for (
int i = 0;
i < wavelet_length;
i++) {
497 const int idx =
mod_pow2(-
i + buff_idx - 1, buffer_length);
498 const double btemp =
buffer[idx];
500 thigh += btemp * hp[
i];
501 tlow += btemp * lp[
i];
504 high[out_length - 1] = thigh;
505 low[out_length - 1] = tlow;
508 static int left_ext(
int wavelet_length,
int levels, uint64_t sn)
512 return (
pow2(levels) - 1) * (wavelet_length - 2) +
mod_pow2(sn,
pow2(levels));
519 return (sn + length) / pow2_level - sn / pow2_level;
523 int in_length,
int levels,
int ch, uint64_t sn)
525 const int temp_length =
nb_coefs(in_length, levels, sn);
530 if (temp_length > out_length[
level]) {
532 out_length[
level] = 0;
537 out_length[
level] = temp_length + 1;
541 (out_length[
level] - temp_length) *
sizeof(**
out));
542 out_length[
level] = temp_length;
545 if (temp_length > out_length[levels]) {
547 out_length[levels] = 0;
552 out_length[levels] = temp_length + 1;
555 memset(
out[levels] + temp_length, 0,
556 (out_length[levels] - temp_length) *
sizeof(**
out));
557 out_length[levels] = temp_length;
564 return (
pow2(levels -
level) - 1) * (wavelet_length - 1);
568 double **
out,
int *out_length,
569 int in_length,
int levels,
int ch, uint64_t sn)
577 if (temp_length > out_length[
level]) {
579 out_length[
level] = 0;
585 out_length[
level] =
add + temp_length + 1;
591 out_length[
level] = temp_length;
594 temp_length =
nb_coefs(in_length, levels, sn);
595 if (temp_length > out_length[levels]) {
597 out_length[levels] = 0;
602 out_length[levels] = temp_length + 1;
606 memset(
out[levels] + temp_length, 0,
607 (out_length[levels] - temp_length) *
sizeof(**
out));
608 out_length[levels] = temp_length;
615 if (levels ==
level || sn == 0)
621 const double *in,
int in_length,
622 double **
out,
int *out_length,
int ch, uint64_t sn)
625 int levels =
s->levels;
626 int skip = sn ?
s->wavelet_length - 1 : 1;
633 in_length, levels, ch, sn);
637 leftext =
left_ext(
s->wavelet_length, levels, sn);
654 memcpy(cp->
temp_in + leftext, in, in_length *
sizeof(*in));
658 s->lp,
s->hp,
s->wavelet_length,
skip,
662 int tempa_length_prev;
682 s->lp,
s->hp,
s->wavelet_length,
skip,
684 memcpy(
out[0], cp->
tempd + discard, out_length[0] *
sizeof(**
out));
688 if (out_length[
level] == 0)
694 s->lp,
s->hp,
s->wavelet_length,
skip,
700 if (out_length[levels] == 0)
703 s->lp,
s->hp,
s->wavelet_length,
skip,
707 if (
s->prev_length < in_length) {
710 memmove(cp->
prev, cp->
prev + in_length, (
s->prev_length - in_length) *
sizeof(*cp->
prev));
711 memcpy(cp->
prev +
s->prev_length - in_length, in, in_length *
sizeof(*cp->
prev));
717 static void conv_up(
double *low,
double *high,
int in_length,
double *
out,
int out_length,
718 const double *lp,
const double *hp,
int filter_length,
719 double *
buffer,
double *buffer2,
int buffer_length)
721 int shift = 0, buff_idx = 0, in_idx = 0;
724 memset(buffer2, 0, buffer_length *
sizeof(*buffer2));
726 for (
int i = 0;
i < out_length;
i++) {
730 if (in_idx < in_length) {
731 buffer[buff_idx] = low[in_idx];
732 buffer2[buff_idx] = high[in_idx++];
735 buffer2[buff_idx] = 0;
738 if (buff_idx >= buffer_length)
743 for (
int j = 0; j < (filter_length -
shift + 1) / 2; j++) {
744 const int idx =
mod_pow2(-j + buff_idx - 1, buffer_length);
758 return (
pow2(levels -
level) - 1) * (wavelet_length - 2) +
763 double **in,
int *in_length,
764 double *
out,
int out_length,
int ch, uint64_t sn)
767 const int levels =
s->levels;
768 int leftext =
left_ext(
s->wavelet_length, levels, sn);
774 memset(
out, 0, out_length *
sizeof(*
out));
791 s->ilp,
s->ihp,
s->wavelet_length,
815 conv_up(in[levels], in[levels - 1], in_length[levels], hp1, in_length[levels - 2] +
add,
822 hp2, in_length[
level - 2] + add2,
823 s->ilp,
s->ihp,
s->wavelet_length,
825 FFSWAP(
double *, hp1, hp2);
830 s->ilp,
s->ihp,
s->wavelet_length,
835 if (
s->overlap_length <= out_length) {
838 for (
int i = 0;
i <
FFMIN(
s->overlap_length, out_length);
i++)
842 s->overlap_length *
sizeof(*cp->
overlap));
848 (
s->overlap_length - out_length) *
sizeof(*cp->
overlap));
849 memcpy(cp->
overlap +
s->overlap_length - out_length, cp->
temp_in + leftext,
850 out_length *
sizeof(*cp->
overlap));
863 double percent,
int length)
865 const double x = percent * 0.01;
866 const double y = 1.0 - x;
868 for (
int i = 0;
i < length;
i++)
872 static double sqr(
double in)
881 for (
int i = 0;
i < length;
i++)
891 for (
int i = 0;
i < length;
i++)
901 for (
int i = 0;
i < length;
i++) {
905 return sqrt(sum / length);
909 double *
out,
double absmean,
double softness,
910 double new_stddev,
int length)
912 for (
int i = 0;
i < length;
i++) {
913 if (new_stddev <= stddev)
915 else if (
fabs(in[
i]) <= absmean)
918 out[
i] = in[
i] -
FFSIGN(in[
i]) * absmean /
exp(3.0 * softness * (
fabs(in[
i]) - absmean) / absmean);
934 double *dst = (
double *)
out->extended_data[ch];
935 double *absmean = (
double *)
s->absmean->extended_data[ch];
936 double *new_absmean = (
double *)
s->new_absmean->extended_data[ch];
937 double *stddev = (
double *)
s->stddev->extended_data[ch];
938 double *new_stddev = (
double *)
s->new_stddev->extended_data[ch];
939 double *
filter = (
double *)
s->filter->extended_data[ch];
940 double is_noise = 0.0;
947 if (!
s->got_profile &&
s->need_profile) {
950 const double scale = sqrt(2.0 * log(length));
956 }
else if (!
s->got_profile && !
s->need_profile && !
s->adaptive) {
959 const double scale = sqrt(2.0 * log(length));
973 if (new_absmean[
level] <= FLT_EPSILON)
977 if (level < s->levels)
978 is_noise +=
sqr(vad - 1.232);
982 is_noise /=
s->nb_samples;
984 const double percent =
ctx->is_disabled ? 0. :
s->percent;
986 const double scale = sqrt(2.0 * log(length));
988 if (is_noise < 0.05 && s->adaptive) {
994 s->softness, new_stddev[
level], length);
1012 int eof = in ==
NULL;
1024 out->pts =
s->eof_pts -
s->padd_samples;
1037 s->padd_samples -=
s->nb_samples - (in ? in->
nb_samples: 0);
1048 if (
s->need_profile)
1051 s->sn +=
s->nb_samples;
1061 }
else if (
s->drop_samples > 0) {
1062 for (
int ch = 0; ch <
out->ch_layout.nb_channels; ch++) {
1063 memmove(
out->extended_data[ch],
1064 out->extended_data[ch] +
s->drop_samples *
sizeof(
double),
1065 (in->
nb_samples -
s->drop_samples) *
sizeof(
double));
1070 s->delay +=
s->drop_samples;
1071 s->drop_samples = 0;
1073 if (
s->padd_samples < 0 && eof) {
1074 out->nb_samples +=
s->padd_samples;
1075 s->padd_samples = 0;
1087 return (
pow2(levels) - 1) * (wavelet_length - 1);
1092 return (
pow2(levels) - 1) * (wavelet_length - 2);
1100 switch (
s->wavelet_type) {
1102 s->wavelet_length = 4;
1109 s->wavelet_length = 8;
1116 s->wavelet_length = 18;
1123 s->wavelet_length = 20;
1130 s->wavelet_length = 20;
1137 s->wavelet_length = 30;
1144 s->wavelet_length = 42;
1154 s->levels =
FFMIN(
s->levels,
lrint(log(
s->nb_samples / (
s->wavelet_length - 1.0)) /
M_LN2));
1163 if (!
s->stddev || !
s->absmean || !
s->filter ||
1164 !
s->new_stddev || !
s->new_absmean)
1169 s->prev_length =
s->overlap_length;
1170 s->drop_samples =
s->overlap_length;
1171 s->padd_samples =
s->overlap_length;
1178 for (
int ch = 0; ch <
s->channels; ch++) {
1221 while (
s->padd_samples != 0) {
1245 for (
int ch = 0;
s->cp && ch <
s->channels; ch++) {
1278 char *res,
int res_len,
int flags)
1287 if (!strcmp(cmd,
"profile") &&
s->need_profile)
1312 .priv_class = &afwtdn_class,