45 0.000146098, -0.000232304, -0.000285414, 0.000462093, 0.000559952,
46 -0.000927187, -0.001103748, 0.00188212, 0.002186714, -0.003882426,
47 -0.00435384, 0.008201477, 0.008685294, -0.017982291, -0.017176331,
48 0.042068328, 0.032080869, -0.110036987, -0.050201753, 0.433923147,
49 0.766130398, 0.433923147, -0.050201753, -0.110036987, 0.032080869,
50 0.042068328, -0.017176331, -0.017982291, 0.008685294, 0.008201477,
51 -0.00435384, -0.003882426, 0.002186714, 0.00188212, -0.001103748,
52 -0.000927187, 0.000559952, 0.000462093, -0.000285414, -0.000232304,
57 0.0, 0.000146098, 0.000232304, -0.000285414, -0.000462093, 0.000559952,
58 0.000927187, -0.001103748, -0.00188212, 0.002186714, 0.003882426,
59 -0.00435384, -0.008201477, 0.008685294, 0.017982291, -0.017176331,
60 -0.042068328, 0.032080869, 0.110036987, -0.050201753, -0.433923147,
61 0.766130398, -0.433923147, -0.050201753, 0.110036987, 0.032080869,
62 -0.042068328, -0.017176331, 0.017982291, 0.008685294, -0.008201477,
63 -0.00435384, 0.003882426, 0.002186714, -0.00188212, -0.001103748,
64 0.000927187, 0.000559952, -0.000462093, -0.000285414, 0.000232304,
69 0.0, 0.000146098, -0.000232304, -0.000285414, 0.000462093, 0.000559952,
70 -0.000927187, -0.001103748, 0.00188212, 0.002186714, -0.003882426,
71 -0.00435384, 0.008201477, 0.008685294, -0.017982291, -0.017176331,
72 0.042068328, 0.032080869, -0.110036987, -0.050201753, 0.433923147,
73 0.766130398, 0.433923147, -0.050201753, -0.110036987, 0.032080869,
74 0.042068328, -0.017176331, -0.017982291, 0.008685294, 0.008201477,
75 -0.00435384, -0.003882426, 0.002186714, 0.00188212, -0.001103748,
76 -0.000927187, 0.000559952, 0.000462093, -0.000285414, -0.000232304,
81 0.000146098, 0.000232304, -0.000285414, -0.000462093, 0.000559952,
82 0.000927187, -0.001103748, -0.00188212, 0.002186714, 0.003882426,
83 -0.00435384, -0.008201477, 0.008685294, 0.017982291, -0.017176331,
84 -0.042068328, 0.032080869, 0.110036987, -0.050201753, -0.433923147,
85 0.766130398, -0.433923147, -0.050201753, 0.110036987, 0.032080869,
86 -0.042068328, -0.017176331, 0.017982291, 0.008685294, -0.008201477,
87 -0.00435384, 0.003882426, 0.002186714, -0.00188212, -0.001103748,
88 0.000927187, 0.000559952, -0.000462093, -0.000285414, 0.000232304,
93 0.0007701598091144901, 9.563267072289475e-05,
94 -0.008641299277022422, -0.0014653825813050513,
95 0.0459272392310922, 0.011609893903711381,
96 -0.15949427888491757, -0.07088053578324385,
97 0.47169066693843925, 0.7695100370211071,
98 0.38382676106708546, -0.03553674047381755,
99 -0.0319900568824278, 0.04999497207737669,
100 0.005764912033581909, -0.02035493981231129,
101 -0.0008043589320165449, 0.004593173585311828,
102 5.7036083618494284e-05, -0.0004593294210046588,
106 0.0004593294210046588, 5.7036083618494284e-05,
107 -0.004593173585311828, -0.0008043589320165449,
108 0.02035493981231129, 0.005764912033581909,
109 -0.04999497207737669, -0.0319900568824278,
110 0.03553674047381755, 0.38382676106708546,
111 -0.7695100370211071, 0.47169066693843925,
112 0.07088053578324385, -0.15949427888491757,
113 -0.011609893903711381, 0.0459272392310922,
114 0.0014653825813050513, -0.008641299277022422,
115 -9.563267072289475e-05, 0.0007701598091144901,
119 -0.0004593294210046588, 5.7036083618494284e-05,
120 0.004593173585311828, -0.0008043589320165449,
121 -0.02035493981231129, 0.005764912033581909,
122 0.04999497207737669, -0.0319900568824278,
123 -0.03553674047381755, 0.38382676106708546,
124 0.7695100370211071, 0.47169066693843925,
125 -0.07088053578324385, -0.15949427888491757,
126 0.011609893903711381, 0.0459272392310922,
127 -0.0014653825813050513, -0.008641299277022422,
128 9.563267072289475e-05, 0.0007701598091144901,
132 0.0007701598091144901, -9.563267072289475e-05,
133 -0.008641299277022422, 0.0014653825813050513,
134 0.0459272392310922, -0.011609893903711381,
135 -0.15949427888491757, 0.07088053578324385,
136 0.47169066693843925, -0.7695100370211071,
137 0.38382676106708546, 0.03553674047381755,
138 -0.0319900568824278, -0.04999497207737669,
139 0.005764912033581909, 0.02035493981231129,
140 -0.0008043589320165449, -0.004593173585311828,
141 5.7036083618494284e-05, 0.0004593294210046588,
146 0.014426282505624435, 0.014467504896790148,
147 -0.07872200106262882, -0.04036797903033992,
148 0.41784910915027457, 0.7589077294536541,
149 0.41784910915027457, -0.04036797903033992,
150 -0.07872200106262882, 0.014467504896790148,
151 0.014426282505624435, 0.0, 0.0, 0.0,
155 -0.0019088317364812906, -0.0019142861290887667,
156 0.016990639867602342, 0.01193456527972926,
157 -0.04973290349094079, -0.07726317316720414,
158 0.09405920349573646, 0.4207962846098268,
159 -0.8259229974584023, 0.4207962846098268,
160 0.09405920349573646, -0.07726317316720414,
161 -0.04973290349094079, 0.01193456527972926,
162 0.016990639867602342, -0.0019142861290887667,
163 -0.0019088317364812906, 0.0,
167 0.0019088317364812906, -0.0019142861290887667,
168 -0.016990639867602342, 0.01193456527972926,
169 0.04973290349094079, -0.07726317316720414,
170 -0.09405920349573646, 0.4207962846098268,
171 0.8259229974584023, 0.4207962846098268,
172 -0.09405920349573646, -0.07726317316720414,
173 0.04973290349094079, 0.01193456527972926,
174 -0.016990639867602342, -0.0019142861290887667,
175 0.0019088317364812906, 0.0,
180 0.014426282505624435, -0.014467504896790148,
181 -0.07872200106262882, 0.04036797903033992,
182 0.41784910915027457, -0.7589077294536541,
183 0.41784910915027457, 0.04036797903033992,
184 -0.07872200106262882, -0.014467504896790148,
185 0.014426282505624435, 0.0, 0.0, 0.0,
189 -9.517657273819165e-08, -1.6744288576823017e-07,
190 2.0637618513646814e-06, 3.7346551751414047e-06,
191 -2.1315026809955787e-05, -4.134043227251251e-05,
192 0.00014054114970203437, 0.00030225958181306315,
193 -0.0006381313430451114, -0.0016628637020130838,
194 0.0024333732126576722, 0.006764185448053083,
195 -0.009164231162481846, -0.01976177894257264,
196 0.03268357426711183, 0.0412892087501817,
197 -0.10557420870333893, -0.06203596396290357,
198 0.4379916261718371, 0.7742896036529562,
199 0.4215662066908515, -0.05204316317624377,
200 -0.09192001055969624, 0.02816802897093635,
201 0.023408156785839195, -0.010131117519849788,
202 -0.004159358781386048, 0.0021782363581090178,
203 0.00035858968789573785, -0.00021208083980379827,
207 0.00021208083980379827, 0.00035858968789573785,
208 -0.0021782363581090178, -0.004159358781386048,
209 0.010131117519849788, 0.023408156785839195,
210 -0.02816802897093635, -0.09192001055969624,
211 0.05204316317624377, 0.4215662066908515,
212 -0.7742896036529562, 0.4379916261718371,
213 0.06203596396290357, -0.10557420870333893,
214 -0.0412892087501817, 0.03268357426711183,
215 0.01976177894257264, -0.009164231162481846,
216 -0.006764185448053083, 0.0024333732126576722,
217 0.0016628637020130838, -0.0006381313430451114,
218 -0.00030225958181306315, 0.00014054114970203437,
219 4.134043227251251e-05, -2.1315026809955787e-05,
220 -3.7346551751414047e-06, 2.0637618513646814e-06,
221 1.6744288576823017e-07, -9.517657273819165e-08,
225 -0.00021208083980379827, 0.00035858968789573785,
226 0.0021782363581090178, -0.004159358781386048,
227 -0.010131117519849788, 0.023408156785839195,
228 0.02816802897093635, -0.09192001055969624,
229 -0.05204316317624377, 0.4215662066908515,
230 0.7742896036529562, 0.4379916261718371,
231 -0.06203596396290357, -0.10557420870333893,
232 0.0412892087501817, 0.03268357426711183,
233 -0.01976177894257264, -0.009164231162481846,
234 0.006764185448053083, 0.0024333732126576722,
235 -0.0016628637020130838, -0.0006381313430451114,
236 0.00030225958181306315, 0.00014054114970203437,
237 -4.134043227251251e-05, -2.1315026809955787e-05,
238 3.7346551751414047e-06, 2.0637618513646814e-06,
239 -1.6744288576823017e-07, -9.517657273819165e-08,
243 -9.517657273819165e-08, 1.6744288576823017e-07,
244 2.0637618513646814e-06, -3.7346551751414047e-06,
245 -2.1315026809955787e-05, 4.134043227251251e-05,
246 0.00014054114970203437, -0.00030225958181306315,
247 -0.0006381313430451114, 0.0016628637020130838,
248 0.0024333732126576722, -0.006764185448053083,
249 -0.009164231162481846, 0.01976177894257264,
250 0.03268357426711183, -0.0412892087501817,
251 -0.10557420870333893, 0.06203596396290357,
252 0.4379916261718371, -0.7742896036529562,
253 0.4215662066908515, 0.05204316317624377,
254 -0.09192001055969624, -0.02816802897093635,
255 0.023408156785839195, 0.010131117519849788,
256 -0.004159358781386048, -0.0021782363581090178,
257 0.00035858968789573785, 0.00021208083980379827,
261 -1.326420300235487e-05, 9.358867000108985e-05,
262 -0.0001164668549943862, -0.0006858566950046825,
263 0.00199240529499085, 0.0013953517469940798,
264 -0.010733175482979604, 0.0036065535669883944,
265 0.03321267405893324, -0.02945753682194567,
266 -0.07139414716586077, 0.09305736460380659,
267 0.12736934033574265, -0.19594627437659665,
268 -0.24984642432648865, 0.2811723436604265,
269 0.6884590394525921, 0.5272011889309198,
270 0.18817680007762133, 0.026670057900950818,
274 -0.026670057900950818, 0.18817680007762133,
275 -0.5272011889309198, 0.6884590394525921,
276 -0.2811723436604265, -0.24984642432648865,
277 0.19594627437659665, 0.12736934033574265,
278 -0.09305736460380659, -0.07139414716586077,
279 0.02945753682194567, 0.03321267405893324,
280 -0.0036065535669883944, -0.010733175482979604,
281 -0.0013953517469940798, 0.00199240529499085,
282 0.0006858566950046825, -0.0001164668549943862,
283 -9.358867000108985e-05, -1.326420300235487e-05,
287 0.026670057900950818, 0.18817680007762133,
288 0.5272011889309198, 0.6884590394525921,
289 0.2811723436604265, -0.24984642432648865,
290 -0.19594627437659665, 0.12736934033574265,
291 0.09305736460380659, -0.07139414716586077,
292 -0.02945753682194567, 0.03321267405893324,
293 0.0036065535669883944, -0.010733175482979604,
294 0.0013953517469940798, 0.00199240529499085,
295 -0.0006858566950046825, -0.0001164668549943862,
296 9.358867000108985e-05, -1.326420300235487e-05,
300 -1.326420300235487e-05, -9.358867000108985e-05,
301 -0.0001164668549943862, 0.0006858566950046825,
302 0.00199240529499085, -0.0013953517469940798,
303 -0.010733175482979604, -0.0036065535669883944,
304 0.03321267405893324, 0.02945753682194567,
305 -0.07139414716586077, -0.09305736460380659,
306 0.12736934033574265, 0.19594627437659665,
307 -0.24984642432648865, -0.2811723436604265,
308 0.6884590394525921, -0.5272011889309198,
309 0.18817680007762133, -0.026670057900950818,
313 -0.07576571478927333,
314 -0.02963552764599851,
318 -0.09921954357684722,
319 -0.012603967262037833,
325 -0.012603967262037833,
331 -0.07576571478927333,
336 -0.012603967262037833,
337 -0.09921954357684722,
341 -0.02963552764599851,
342 -0.07576571478927333,
346 -0.07576571478927333,
352 -0.012603967262037833,
357 -0.12940952255092145, 0.22414386804185735,
358 0.836516303737469, 0.48296291314469025,
362 -0.48296291314469025, 0.836516303737469,
363 -0.22414386804185735, -0.12940952255092145,
367 0.48296291314469025, 0.836516303737469,
368 0.22414386804185735, -0.12940952255092145,
372 -0.12940952255092145, -0.22414386804185735,
373 0.836516303737469, -0.48296291314469025,
376 #define MAX_LEVELS 13
438 #define OFFSET(x) offsetof(AudioFWTDNContext, x)
439 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
440 #define AFR AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
456 {
"samples",
"set frame size in number of samples",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=8192}, 512, 65536,
AF },
463 #define pow2(x) (1U << (x))
464 #define mod_pow2(x, power_of_two) ((x) & ((power_of_two) - 1))
466 static void conv_down(
double *in,
int in_length,
double *low,
double *high,
467 int out_length,
const double *lp,
const double *hp,
468 int wavelet_length,
int skip,
469 double *
buffer,
int buffer_length)
471 double thigh = 0.0, tlow = 0.0;
472 int buff_idx = 1 +
skip;
475 memset(
buffer + buff_idx, 0, (buffer_length - buff_idx) *
sizeof(*
buffer));
477 for (
int i = 0;
i < out_length - 1;
i++) {
478 double thigh = 0.0, tlow = 0.0;
480 for (
int j = 0; j < wavelet_length; j++) {
481 const int idx =
mod_pow2(-j + buff_idx - 1, buffer_length);
482 const double btemp =
buffer[idx];
484 thigh += btemp * hp[j];
485 tlow += btemp * lp[j];
492 buff_idx =
mod_pow2(buff_idx, buffer_length);
495 for (
int i = 0;
i < wavelet_length;
i++) {
496 const int idx =
mod_pow2(-
i + buff_idx - 1, buffer_length);
497 const double btemp =
buffer[idx];
499 thigh += btemp * hp[
i];
500 tlow += btemp * lp[
i];
503 high[out_length - 1] = thigh;
504 low[out_length - 1] = tlow;
507 static int left_ext(
int wavelet_length,
int levels, uint64_t sn)
511 return (
pow2(levels) - 1) * (wavelet_length - 2) +
mod_pow2(sn,
pow2(levels));
518 return (sn + length) / pow2_level - sn / pow2_level;
522 int in_length,
int levels,
int ch, uint64_t sn)
524 const int temp_length =
nb_coefs(in_length, levels, sn);
529 if (temp_length > out_length[
level]) {
531 out_length[
level] = 0;
536 out_length[
level] = temp_length + 1;
540 (out_length[
level] - temp_length) *
sizeof(**
out));
541 out_length[
level] = temp_length;
544 if (temp_length > out_length[levels]) {
546 out_length[levels] = 0;
551 out_length[levels] = temp_length + 1;
554 memset(
out[levels] + temp_length, 0,
555 (out_length[levels] - temp_length) *
sizeof(**
out));
556 out_length[levels] = temp_length;
563 return (
pow2(levels -
level) - 1) * (wavelet_length - 1);
567 double **
out,
int *out_length,
568 int in_length,
int levels,
int ch, uint64_t sn)
576 if (temp_length > out_length[
level]) {
578 out_length[
level] = 0;
584 out_length[
level] = add + temp_length + 1;
589 FFMAX(out_length[
level] - temp_length - add, 0) *
sizeof(**
out));
590 out_length[
level] = temp_length;
593 temp_length =
nb_coefs(in_length, levels, sn);
594 if (temp_length > out_length[levels]) {
596 out_length[levels] = 0;
601 out_length[levels] = temp_length + 1;
605 memset(
out[levels] + temp_length, 0,
606 (out_length[levels] - temp_length) *
sizeof(**
out));
607 out_length[levels] = temp_length;
614 if (levels ==
level || sn == 0)
620 const double *in,
int in_length,
621 double **
out,
int *out_length,
int ch, uint64_t sn)
624 int levels =
s->levels;
625 int skip = sn ?
s->wavelet_length - 1 : 1;
632 in_length, levels, ch, sn);
636 leftext =
left_ext(
s->wavelet_length, levels, sn);
653 memcpy(cp->
temp_in + leftext, in, in_length *
sizeof(*in));
657 s->lp,
s->hp,
s->wavelet_length,
skip,
661 int tempa_length_prev;
681 s->lp,
s->hp,
s->wavelet_length,
skip,
683 memcpy(
out[0], cp->
tempd + discard, out_length[0] *
sizeof(**
out));
687 if (out_length[
level] == 0)
693 s->lp,
s->hp,
s->wavelet_length,
skip,
699 if (out_length[levels] == 0)
702 s->lp,
s->hp,
s->wavelet_length,
skip,
706 if (
s->prev_length < in_length) {
709 memmove(cp->
prev, cp->
prev + in_length, (
s->prev_length - in_length) *
sizeof(*cp->
prev));
710 memcpy(cp->
prev +
s->prev_length - in_length, in, in_length *
sizeof(*cp->
prev));
716 static void conv_up(
double *low,
double *high,
int in_length,
double *
out,
int out_length,
717 const double *lp,
const double *hp,
int filter_length,
718 double *
buffer,
double *buffer2,
int buffer_length)
720 int shift = 0, buff_idx = 0, in_idx = 0;
723 memset(buffer2, 0, buffer_length *
sizeof(*buffer2));
725 for (
int i = 0;
i < out_length;
i++) {
729 if (in_idx < in_length) {
730 buffer[buff_idx] = low[in_idx];
731 buffer2[buff_idx] = high[in_idx++];
734 buffer2[buff_idx] = 0;
737 if (buff_idx >= buffer_length)
742 for (
int j = 0; j < (filter_length -
shift + 1) / 2; j++) {
743 const int idx =
mod_pow2(-j + buff_idx - 1, buffer_length);
757 return (
pow2(levels -
level) - 1) * (wavelet_length - 2) +
762 double **in,
int *in_length,
763 double *
out,
int out_length,
int ch, uint64_t sn)
766 const int levels =
s->levels;
767 int leftext =
left_ext(
s->wavelet_length, levels, sn);
773 memset(
out, 0, out_length *
sizeof(*
out));
790 s->ilp,
s->ihp,
s->wavelet_length,
814 conv_up(in[levels], in[levels - 1], in_length[levels], hp1, in_length[levels - 2] + add,
821 hp2, in_length[
level - 2] + add2,
822 s->ilp,
s->ihp,
s->wavelet_length,
824 FFSWAP(
double *, hp1, hp2);
829 s->ilp,
s->ihp,
s->wavelet_length,
834 if (
s->overlap_length <= out_length) {
837 for (
int i = 0;
i <
FFMIN(
s->overlap_length, out_length);
i++)
841 s->overlap_length *
sizeof(*cp->
overlap));
847 (
s->overlap_length - out_length) *
sizeof(*cp->
overlap));
848 memcpy(cp->
overlap +
s->overlap_length - out_length, cp->
temp_in + leftext,
849 out_length *
sizeof(*cp->
overlap));
862 double percent,
int length)
864 const double x = percent * 0.01;
865 const double y = 1.0 - x;
867 for (
int i = 0;
i < length;
i++)
871 static double sqr(
double in)
880 for (
int i = 0;
i < length;
i++)
890 for (
int i = 0;
i < length;
i++)
900 for (
int i = 0;
i < length;
i++) {
904 return sqrt(sum / length);
908 double *
out,
double absmean,
double softness,
909 double new_stddev,
int length)
911 for (
int i = 0;
i < length;
i++) {
912 if (new_stddev <= stddev)
914 else if (
fabs(in[
i]) <= absmean)
917 out[
i] = in[
i] -
FFSIGN(in[
i]) * absmean /
exp(3.0 * softness * (
fabs(in[
i]) - absmean) / absmean);
933 double *dst = (
double *)
out->extended_data[ch];
934 double *absmean = (
double *)
s->absmean->extended_data[ch];
935 double *new_absmean = (
double *)
s->new_absmean->extended_data[ch];
936 double *stddev = (
double *)
s->stddev->extended_data[ch];
937 double *new_stddev = (
double *)
s->new_stddev->extended_data[ch];
938 double *
filter = (
double *)
s->filter->extended_data[ch];
939 double is_noise = 0.0;
946 if (!
s->got_profile &&
s->need_profile) {
949 const double scale = sqrt(2.0 *
log(length));
955 }
else if (!
s->got_profile && !
s->need_profile && !
s->adaptive) {
958 const double scale = sqrt(2.0 *
log(length));
972 if (new_absmean[
level] <= FLT_EPSILON)
976 if (level < s->levels)
977 is_noise +=
sqr(vad - 1.232);
981 is_noise /=
s->nb_samples;
983 const double percent =
ctx->is_disabled ? 0. :
s->percent;
985 const double scale = sqrt(2.0 *
log(length));
987 if (is_noise < 0.05 && s->adaptive) {
993 s->softness, new_stddev[
level], length);
1011 int eof = in ==
NULL;
1023 out->pts =
s->eof_pts -
s->padd_samples;
1036 s->padd_samples -=
s->nb_samples - (in ? in->
nb_samples: 0);
1047 if (
s->need_profile)
1050 s->sn +=
s->nb_samples;
1060 }
else if (
s->drop_samples > 0) {
1061 for (
int ch = 0; ch <
out->ch_layout.nb_channels; ch++) {
1062 memmove(
out->extended_data[ch],
1063 out->extended_data[ch] +
s->drop_samples *
sizeof(
double),
1064 (in->
nb_samples -
s->drop_samples) *
sizeof(
double));
1069 s->delay +=
s->drop_samples;
1070 s->drop_samples = 0;
1072 if (
s->padd_samples < 0 && eof) {
1073 out->nb_samples =
FFMAX(0,
out->nb_samples +
s->padd_samples);
1074 s->padd_samples = 0;
1086 return (
pow2(levels) - 1) * (wavelet_length - 1);
1091 return (
pow2(levels) - 1) * (wavelet_length - 2);
1099 switch (
s->wavelet_type) {
1101 s->wavelet_length = 4;
1108 s->wavelet_length = 8;
1115 s->wavelet_length = 18;
1122 s->wavelet_length = 20;
1129 s->wavelet_length = 20;
1136 s->wavelet_length = 30;
1143 s->wavelet_length = 42;
1162 if (!
s->stddev || !
s->absmean || !
s->filter ||
1163 !
s->new_stddev || !
s->new_absmean)
1168 s->prev_length =
s->overlap_length;
1169 s->drop_samples =
s->overlap_length;
1170 s->padd_samples =
s->overlap_length;
1177 for (
int ch = 0; ch <
s->channels; ch++) {
1225 if (
s->eof &&
s->padd_samples != 0) {
1227 }
else if (
s->eof) {
1247 for (
int ch = 0;
s->cp && ch <
s->channels; ch++) {
1280 char *res,
int res_len,
int flags)
1289 if (!strcmp(cmd,
"profile") &&
s->need_profile)
1307 .priv_class = &afwtdn_class,