46 0.000146098, -0.000232304, -0.000285414, 0.000462093, 0.000559952,
47 -0.000927187, -0.001103748, 0.00188212, 0.002186714, -0.003882426,
48 -0.00435384, 0.008201477, 0.008685294, -0.017982291, -0.017176331,
49 0.042068328, 0.032080869, -0.110036987, -0.050201753, 0.433923147,
50 0.766130398, 0.433923147, -0.050201753, -0.110036987, 0.032080869,
51 0.042068328, -0.017176331, -0.017982291, 0.008685294, 0.008201477,
52 -0.00435384, -0.003882426, 0.002186714, 0.00188212, -0.001103748,
53 -0.000927187, 0.000559952, 0.000462093, -0.000285414, -0.000232304,
58 0.0, 0.000146098, 0.000232304, -0.000285414, -0.000462093, 0.000559952,
59 0.000927187, -0.001103748, -0.00188212, 0.002186714, 0.003882426,
60 -0.00435384, -0.008201477, 0.008685294, 0.017982291, -0.017176331,
61 -0.042068328, 0.032080869, 0.110036987, -0.050201753, -0.433923147,
62 0.766130398, -0.433923147, -0.050201753, 0.110036987, 0.032080869,
63 -0.042068328, -0.017176331, 0.017982291, 0.008685294, -0.008201477,
64 -0.00435384, 0.003882426, 0.002186714, -0.00188212, -0.001103748,
65 0.000927187, 0.000559952, -0.000462093, -0.000285414, 0.000232304,
70 0.0, 0.000146098, -0.000232304, -0.000285414, 0.000462093, 0.000559952,
71 -0.000927187, -0.001103748, 0.00188212, 0.002186714, -0.003882426,
72 -0.00435384, 0.008201477, 0.008685294, -0.017982291, -0.017176331,
73 0.042068328, 0.032080869, -0.110036987, -0.050201753, 0.433923147,
74 0.766130398, 0.433923147, -0.050201753, -0.110036987, 0.032080869,
75 0.042068328, -0.017176331, -0.017982291, 0.008685294, 0.008201477,
76 -0.00435384, -0.003882426, 0.002186714, 0.00188212, -0.001103748,
77 -0.000927187, 0.000559952, 0.000462093, -0.000285414, -0.000232304,
82 0.000146098, 0.000232304, -0.000285414, -0.000462093, 0.000559952,
83 0.000927187, -0.001103748, -0.00188212, 0.002186714, 0.003882426,
84 -0.00435384, -0.008201477, 0.008685294, 0.017982291, -0.017176331,
85 -0.042068328, 0.032080869, 0.110036987, -0.050201753, -0.433923147,
86 0.766130398, -0.433923147, -0.050201753, 0.110036987, 0.032080869,
87 -0.042068328, -0.017176331, 0.017982291, 0.008685294, -0.008201477,
88 -0.00435384, 0.003882426, 0.002186714, -0.00188212, -0.001103748,
89 0.000927187, 0.000559952, -0.000462093, -0.000285414, 0.000232304,
94 0.0007701598091144901, 9.563267072289475e-05,
95 -0.008641299277022422, -0.0014653825813050513,
96 0.0459272392310922, 0.011609893903711381,
97 -0.15949427888491757, -0.07088053578324385,
98 0.47169066693843925, 0.7695100370211071,
99 0.38382676106708546, -0.03553674047381755,
100 -0.0319900568824278, 0.04999497207737669,
101 0.005764912033581909, -0.02035493981231129,
102 -0.0008043589320165449, 0.004593173585311828,
103 5.7036083618494284e-05, -0.0004593294210046588,
107 0.0004593294210046588, 5.7036083618494284e-05,
108 -0.004593173585311828, -0.0008043589320165449,
109 0.02035493981231129, 0.005764912033581909,
110 -0.04999497207737669, -0.0319900568824278,
111 0.03553674047381755, 0.38382676106708546,
112 -0.7695100370211071, 0.47169066693843925,
113 0.07088053578324385, -0.15949427888491757,
114 -0.011609893903711381, 0.0459272392310922,
115 0.0014653825813050513, -0.008641299277022422,
116 -9.563267072289475e-05, 0.0007701598091144901,
120 -0.0004593294210046588, 5.7036083618494284e-05,
121 0.004593173585311828, -0.0008043589320165449,
122 -0.02035493981231129, 0.005764912033581909,
123 0.04999497207737669, -0.0319900568824278,
124 -0.03553674047381755, 0.38382676106708546,
125 0.7695100370211071, 0.47169066693843925,
126 -0.07088053578324385, -0.15949427888491757,
127 0.011609893903711381, 0.0459272392310922,
128 -0.0014653825813050513, -0.008641299277022422,
129 9.563267072289475e-05, 0.0007701598091144901,
133 0.0007701598091144901, -9.563267072289475e-05,
134 -0.008641299277022422, 0.0014653825813050513,
135 0.0459272392310922, -0.011609893903711381,
136 -0.15949427888491757, 0.07088053578324385,
137 0.47169066693843925, -0.7695100370211071,
138 0.38382676106708546, 0.03553674047381755,
139 -0.0319900568824278, -0.04999497207737669,
140 0.005764912033581909, 0.02035493981231129,
141 -0.0008043589320165449, -0.004593173585311828,
142 5.7036083618494284e-05, 0.0004593294210046588,
147 0.014426282505624435, 0.014467504896790148,
148 -0.07872200106262882, -0.04036797903033992,
149 0.41784910915027457, 0.7589077294536541,
150 0.41784910915027457, -0.04036797903033992,
151 -0.07872200106262882, 0.014467504896790148,
152 0.014426282505624435, 0.0, 0.0, 0.0,
156 -0.0019088317364812906, -0.0019142861290887667,
157 0.016990639867602342, 0.01193456527972926,
158 -0.04973290349094079, -0.07726317316720414,
159 0.09405920349573646, 0.4207962846098268,
160 -0.8259229974584023, 0.4207962846098268,
161 0.09405920349573646, -0.07726317316720414,
162 -0.04973290349094079, 0.01193456527972926,
163 0.016990639867602342, -0.0019142861290887667,
164 -0.0019088317364812906, 0.0,
168 0.0019088317364812906, -0.0019142861290887667,
169 -0.016990639867602342, 0.01193456527972926,
170 0.04973290349094079, -0.07726317316720414,
171 -0.09405920349573646, 0.4207962846098268,
172 0.8259229974584023, 0.4207962846098268,
173 -0.09405920349573646, -0.07726317316720414,
174 0.04973290349094079, 0.01193456527972926,
175 -0.016990639867602342, -0.0019142861290887667,
176 0.0019088317364812906, 0.0,
181 0.014426282505624435, -0.014467504896790148,
182 -0.07872200106262882, 0.04036797903033992,
183 0.41784910915027457, -0.7589077294536541,
184 0.41784910915027457, 0.04036797903033992,
185 -0.07872200106262882, -0.014467504896790148,
186 0.014426282505624435, 0.0, 0.0, 0.0,
190 -9.517657273819165e-08, -1.6744288576823017e-07,
191 2.0637618513646814e-06, 3.7346551751414047e-06,
192 -2.1315026809955787e-05, -4.134043227251251e-05,
193 0.00014054114970203437, 0.00030225958181306315,
194 -0.0006381313430451114, -0.0016628637020130838,
195 0.0024333732126576722, 0.006764185448053083,
196 -0.009164231162481846, -0.01976177894257264,
197 0.03268357426711183, 0.0412892087501817,
198 -0.10557420870333893, -0.06203596396290357,
199 0.4379916261718371, 0.7742896036529562,
200 0.4215662066908515, -0.05204316317624377,
201 -0.09192001055969624, 0.02816802897093635,
202 0.023408156785839195, -0.010131117519849788,
203 -0.004159358781386048, 0.0021782363581090178,
204 0.00035858968789573785, -0.00021208083980379827,
208 0.00021208083980379827, 0.00035858968789573785,
209 -0.0021782363581090178, -0.004159358781386048,
210 0.010131117519849788, 0.023408156785839195,
211 -0.02816802897093635, -0.09192001055969624,
212 0.05204316317624377, 0.4215662066908515,
213 -0.7742896036529562, 0.4379916261718371,
214 0.06203596396290357, -0.10557420870333893,
215 -0.0412892087501817, 0.03268357426711183,
216 0.01976177894257264, -0.009164231162481846,
217 -0.006764185448053083, 0.0024333732126576722,
218 0.0016628637020130838, -0.0006381313430451114,
219 -0.00030225958181306315, 0.00014054114970203437,
220 4.134043227251251e-05, -2.1315026809955787e-05,
221 -3.7346551751414047e-06, 2.0637618513646814e-06,
222 1.6744288576823017e-07, -9.517657273819165e-08,
226 -0.00021208083980379827, 0.00035858968789573785,
227 0.0021782363581090178, -0.004159358781386048,
228 -0.010131117519849788, 0.023408156785839195,
229 0.02816802897093635, -0.09192001055969624,
230 -0.05204316317624377, 0.4215662066908515,
231 0.7742896036529562, 0.4379916261718371,
232 -0.06203596396290357, -0.10557420870333893,
233 0.0412892087501817, 0.03268357426711183,
234 -0.01976177894257264, -0.009164231162481846,
235 0.006764185448053083, 0.0024333732126576722,
236 -0.0016628637020130838, -0.0006381313430451114,
237 0.00030225958181306315, 0.00014054114970203437,
238 -4.134043227251251e-05, -2.1315026809955787e-05,
239 3.7346551751414047e-06, 2.0637618513646814e-06,
240 -1.6744288576823017e-07, -9.517657273819165e-08,
244 -9.517657273819165e-08, 1.6744288576823017e-07,
245 2.0637618513646814e-06, -3.7346551751414047e-06,
246 -2.1315026809955787e-05, 4.134043227251251e-05,
247 0.00014054114970203437, -0.00030225958181306315,
248 -0.0006381313430451114, 0.0016628637020130838,
249 0.0024333732126576722, -0.006764185448053083,
250 -0.009164231162481846, 0.01976177894257264,
251 0.03268357426711183, -0.0412892087501817,
252 -0.10557420870333893, 0.06203596396290357,
253 0.4379916261718371, -0.7742896036529562,
254 0.4215662066908515, 0.05204316317624377,
255 -0.09192001055969624, -0.02816802897093635,
256 0.023408156785839195, 0.010131117519849788,
257 -0.004159358781386048, -0.0021782363581090178,
258 0.00035858968789573785, 0.00021208083980379827,
262 -1.326420300235487e-05, 9.358867000108985e-05,
263 -0.0001164668549943862, -0.0006858566950046825,
264 0.00199240529499085, 0.0013953517469940798,
265 -0.010733175482979604, 0.0036065535669883944,
266 0.03321267405893324, -0.02945753682194567,
267 -0.07139414716586077, 0.09305736460380659,
268 0.12736934033574265, -0.19594627437659665,
269 -0.24984642432648865, 0.2811723436604265,
270 0.6884590394525921, 0.5272011889309198,
271 0.18817680007762133, 0.026670057900950818,
275 -0.026670057900950818, 0.18817680007762133,
276 -0.5272011889309198, 0.6884590394525921,
277 -0.2811723436604265, -0.24984642432648865,
278 0.19594627437659665, 0.12736934033574265,
279 -0.09305736460380659, -0.07139414716586077,
280 0.02945753682194567, 0.03321267405893324,
281 -0.0036065535669883944, -0.010733175482979604,
282 -0.0013953517469940798, 0.00199240529499085,
283 0.0006858566950046825, -0.0001164668549943862,
284 -9.358867000108985e-05, -1.326420300235487e-05,
288 0.026670057900950818, 0.18817680007762133,
289 0.5272011889309198, 0.6884590394525921,
290 0.2811723436604265, -0.24984642432648865,
291 -0.19594627437659665, 0.12736934033574265,
292 0.09305736460380659, -0.07139414716586077,
293 -0.02945753682194567, 0.03321267405893324,
294 0.0036065535669883944, -0.010733175482979604,
295 0.0013953517469940798, 0.00199240529499085,
296 -0.0006858566950046825, -0.0001164668549943862,
297 9.358867000108985e-05, -1.326420300235487e-05,
301 -1.326420300235487e-05, -9.358867000108985e-05,
302 -0.0001164668549943862, 0.0006858566950046825,
303 0.00199240529499085, -0.0013953517469940798,
304 -0.010733175482979604, -0.0036065535669883944,
305 0.03321267405893324, 0.02945753682194567,
306 -0.07139414716586077, -0.09305736460380659,
307 0.12736934033574265, 0.19594627437659665,
308 -0.24984642432648865, -0.2811723436604265,
309 0.6884590394525921, -0.5272011889309198,
310 0.18817680007762133, -0.026670057900950818,
314 -0.07576571478927333,
315 -0.02963552764599851,
319 -0.09921954357684722,
320 -0.012603967262037833,
326 -0.012603967262037833,
332 -0.07576571478927333,
337 -0.012603967262037833,
338 -0.09921954357684722,
342 -0.02963552764599851,
343 -0.07576571478927333,
347 -0.07576571478927333,
353 -0.012603967262037833,
358 -0.12940952255092145, 0.22414386804185735,
359 0.836516303737469, 0.48296291314469025,
363 -0.48296291314469025, 0.836516303737469,
364 -0.22414386804185735, -0.12940952255092145,
368 0.48296291314469025, 0.836516303737469,
369 0.22414386804185735, -0.12940952255092145,
373 -0.12940952255092145, -0.22414386804185735,
374 0.836516303737469, -0.48296291314469025,
377 #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))
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;
590 FFMAX(out_length[
level] - temp_length - add, 0) *
sizeof(**
out));
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 =
FFMAX(0,
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;
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++) {
1226 if (
s->eof &&
s->padd_samples != 0) {
1228 }
else if (
s->eof) {
1248 for (
int ch = 0;
s->cp && ch <
s->channels; ch++) {
1281 char *res,
int res_len,
int flags)
1290 if (!strcmp(cmd,
"profile") &&
s->need_profile)
1308 .priv_class = &afwtdn_class,