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
437 #define OFFSET(x) offsetof(AudioFWTDNContext, x)
438 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
439 #define AFR AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
455 {
"samples",
"set frame size in number of samples",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64=8192}, 512, 65536,
AF },
462 #define pow2(x) (1U << (x))
463 #define mod_pow2(x, power_of_two) ((x) & ((power_of_two) - 1))
465 static void conv_down(
double *in,
int in_length,
double *low,
double *high,
466 int out_length,
const double *lp,
const double *hp,
467 int wavelet_length,
int skip,
468 double *
buffer,
int buffer_length)
470 double thigh = 0.0, tlow = 0.0;
471 int buff_idx = 1 +
skip;
474 memset(
buffer + buff_idx, 0, (buffer_length - buff_idx) *
sizeof(*
buffer));
476 for (
int i = 0;
i < out_length - 1;
i++) {
477 double thigh = 0.0, tlow = 0.0;
479 for (
int j = 0; j < wavelet_length; j++) {
480 const int idx =
mod_pow2(-j + buff_idx - 1, buffer_length);
481 const double btemp =
buffer[idx];
483 thigh += btemp * hp[j];
484 tlow += btemp * lp[j];
491 buff_idx =
mod_pow2(buff_idx, buffer_length);
494 for (
int i = 0;
i < wavelet_length;
i++) {
495 const int idx =
mod_pow2(-
i + buff_idx - 1, buffer_length);
496 const double btemp =
buffer[idx];
498 thigh += btemp * hp[
i];
499 tlow += btemp * lp[
i];
502 high[out_length - 1] = thigh;
503 low[out_length - 1] = tlow;
506 static int left_ext(
int wavelet_length,
int levels, uint64_t sn)
510 return (
pow2(levels) - 1) * (wavelet_length - 2) +
mod_pow2(sn,
pow2(levels));
517 return (sn + length) / pow2_level - sn / pow2_level;
521 int in_length,
int levels,
int ch, uint64_t sn)
523 const int temp_length =
nb_coefs(in_length, levels, sn);
528 if (temp_length > out_length[
level]) {
530 out_length[
level] = 0;
535 out_length[
level] = temp_length + 1;
539 (out_length[
level] - temp_length) *
sizeof(**
out));
540 out_length[
level] = temp_length;
543 if (temp_length > out_length[levels]) {
545 out_length[levels] = 0;
550 out_length[levels] = temp_length + 1;
553 memset(
out[levels] + temp_length, 0,
554 (out_length[levels] - temp_length) *
sizeof(**
out));
555 out_length[levels] = temp_length;
562 return (
pow2(levels -
level) - 1) * (wavelet_length - 1);
566 double **
out,
int *out_length,
567 int in_length,
int levels,
int ch, uint64_t sn)
575 if (temp_length > out_length[
level]) {
577 out_length[
level] = 0;
583 out_length[
level] = add + temp_length + 1;
588 FFMAX(out_length[
level] - temp_length - add, 0) *
sizeof(**
out));
589 out_length[
level] = temp_length;
592 temp_length =
nb_coefs(in_length, levels, sn);
593 if (temp_length > out_length[levels]) {
595 out_length[levels] = 0;
600 out_length[levels] = temp_length + 1;
604 memset(
out[levels] + temp_length, 0,
605 (out_length[levels] - temp_length) *
sizeof(**
out));
606 out_length[levels] = temp_length;
613 if (levels ==
level || sn == 0)
619 const double *in,
int in_length,
620 double **
out,
int *out_length,
int ch, uint64_t sn)
623 int levels =
s->levels;
624 int skip = sn ?
s->wavelet_length - 1 : 1;
631 in_length, levels, ch, sn);
635 leftext =
left_ext(
s->wavelet_length, levels, sn);
652 memcpy(cp->
temp_in + leftext, in, in_length *
sizeof(*in));
656 s->lp,
s->hp,
s->wavelet_length,
skip,
660 int tempa_length_prev;
680 s->lp,
s->hp,
s->wavelet_length,
skip,
682 memcpy(
out[0], cp->
tempd + discard, out_length[0] *
sizeof(**
out));
686 if (out_length[
level] == 0)
692 s->lp,
s->hp,
s->wavelet_length,
skip,
698 if (out_length[levels] == 0)
701 s->lp,
s->hp,
s->wavelet_length,
skip,
705 if (
s->prev_length < in_length) {
708 memmove(cp->
prev, cp->
prev + in_length, (
s->prev_length - in_length) *
sizeof(*cp->
prev));
709 memcpy(cp->
prev +
s->prev_length - in_length, in, in_length *
sizeof(*cp->
prev));
715 static void conv_up(
double *low,
double *high,
int in_length,
double *
out,
int out_length,
716 const double *lp,
const double *hp,
int filter_length,
717 double *
buffer,
double *buffer2,
int buffer_length)
719 int shift = 0, buff_idx = 0, in_idx = 0;
722 memset(buffer2, 0, buffer_length *
sizeof(*buffer2));
724 for (
int i = 0;
i < out_length;
i++) {
728 if (in_idx < in_length) {
729 buffer[buff_idx] = low[in_idx];
730 buffer2[buff_idx] = high[in_idx++];
733 buffer2[buff_idx] = 0;
736 if (buff_idx >= buffer_length)
741 for (
int j = 0; j < (filter_length -
shift + 1) / 2; j++) {
742 const int idx =
mod_pow2(-j + buff_idx - 1, buffer_length);
756 return (
pow2(levels -
level) - 1) * (wavelet_length - 2) +
761 double **in,
int *in_length,
762 double *
out,
int out_length,
int ch, uint64_t sn)
765 const int levels =
s->levels;
766 int leftext =
left_ext(
s->wavelet_length, levels, sn);
772 memset(
out, 0, out_length *
sizeof(*
out));
789 s->ilp,
s->ihp,
s->wavelet_length,
813 conv_up(in[levels], in[levels - 1], in_length[levels], hp1, in_length[levels - 2] + add,
820 hp2, in_length[
level - 2] + add2,
821 s->ilp,
s->ihp,
s->wavelet_length,
823 FFSWAP(
double *, hp1, hp2);
828 s->ilp,
s->ihp,
s->wavelet_length,
833 if (
s->overlap_length <= out_length) {
836 for (
int i = 0;
i <
FFMIN(
s->overlap_length, out_length);
i++)
840 s->overlap_length *
sizeof(*cp->
overlap));
846 (
s->overlap_length - out_length) *
sizeof(*cp->
overlap));
847 memcpy(cp->
overlap +
s->overlap_length - out_length, cp->
temp_in + leftext,
848 out_length *
sizeof(*cp->
overlap));
861 double percent,
int length)
863 const double x = percent * 0.01;
864 const double y = 1.0 - x;
866 for (
int i = 0;
i < length;
i++)
870 static double sqr(
double in)
879 for (
int i = 0;
i < length;
i++)
889 for (
int i = 0;
i < length;
i++)
899 for (
int i = 0;
i < length;
i++) {
903 return sqrt(sum / length);
907 double *
out,
double absmean,
double softness,
908 double new_stddev,
int length)
910 for (
int i = 0;
i < length;
i++) {
911 if (new_stddev <= stddev)
913 else if (
fabs(in[
i]) <= absmean)
916 out[
i] = in[
i] -
FFSIGN(in[
i]) * absmean /
exp(3.0 * softness * (
fabs(in[
i]) - absmean) / absmean);
932 double *dst = (
double *)
out->extended_data[ch];
933 double *absmean = (
double *)
s->absmean->extended_data[ch];
934 double *new_absmean = (
double *)
s->new_absmean->extended_data[ch];
935 double *stddev = (
double *)
s->stddev->extended_data[ch];
936 double *new_stddev = (
double *)
s->new_stddev->extended_data[ch];
937 double *
filter = (
double *)
s->filter->extended_data[ch];
938 double is_noise = 0.0;
945 if (!
s->got_profile &&
s->need_profile) {
948 const double scale = sqrt(2.0 *
log(length));
954 }
else if (!
s->got_profile && !
s->need_profile && !
s->adaptive) {
957 const double scale = sqrt(2.0 *
log(length));
971 if (new_absmean[
level] <= FLT_EPSILON)
975 if (level < s->levels)
976 is_noise +=
sqr(vad - 1.232);
980 is_noise /=
s->nb_samples;
982 const double percent =
ctx->is_disabled ? 0. :
s->percent;
984 const double scale = sqrt(2.0 *
log(length));
986 if (is_noise < 0.05 && s->adaptive) {
992 s->softness, new_stddev[
level], length);
1010 int eof = in ==
NULL;
1022 out->pts =
s->eof_pts -
s->padd_samples;
1035 s->padd_samples -=
s->nb_samples - (in ? in->
nb_samples: 0);
1046 if (
s->need_profile)
1049 s->sn +=
s->nb_samples;
1059 }
else if (
s->drop_samples > 0) {
1060 for (
int ch = 0; ch <
out->ch_layout.nb_channels; ch++) {
1061 memmove(
out->extended_data[ch],
1062 out->extended_data[ch] +
s->drop_samples *
sizeof(
double),
1063 (in->
nb_samples -
s->drop_samples) *
sizeof(
double));
1068 s->delay +=
s->drop_samples;
1069 s->drop_samples = 0;
1071 if (
s->padd_samples < 0 && eof) {
1072 out->nb_samples +=
s->padd_samples;
1073 s->padd_samples = 0;
1085 return (
pow2(levels) - 1) * (wavelet_length - 1);
1090 return (
pow2(levels) - 1) * (wavelet_length - 2);
1098 switch (
s->wavelet_type) {
1100 s->wavelet_length = 4;
1107 s->wavelet_length = 8;
1114 s->wavelet_length = 18;
1121 s->wavelet_length = 20;
1128 s->wavelet_length = 20;
1135 s->wavelet_length = 30;
1142 s->wavelet_length = 42;
1161 if (!
s->stddev || !
s->absmean || !
s->filter ||
1162 !
s->new_stddev || !
s->new_absmean)
1167 s->prev_length =
s->overlap_length;
1168 s->drop_samples =
s->overlap_length;
1169 s->padd_samples =
s->overlap_length;
1176 for (
int ch = 0; ch <
s->channels; ch++) {
1219 while (
s->padd_samples != 0) {
1243 for (
int ch = 0;
s->cp && ch <
s->channels; ch++) {
1276 char *res,
int res_len,
int flags)
1285 if (!strcmp(cmd,
"profile") &&
s->need_profile)
1303 .priv_class = &afwtdn_class,