FFmpeg
af_afwtdn.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Paul B Mahol
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <float.h>
22 
23 #include "libavutil/avassert.h"
24 #include "libavutil/opt.h"
25 #include "avfilter.h"
26 #include "audio.h"
27 #include "filters.h"
28 
36  BL3,
38 };
39 
40 /*
41  * All wavelets coefficients are taken from: http://wavelets.pybytes.com/
42  */
43 
44 static const double bl3_lp[42] = {
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,
53  0.000146098, 0.0,
54 };
55 
56 static const double bl3_hp[42] = {
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,
65  0.000146098,
66 };
67 
68 static const double bl3_ilp[42] = {
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,
77  0.000146098,
78 };
79 
80 static const double bl3_ihp[42] = {
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,
89  0.000146098,
90 };
91 
92 static const double sym10_lp[20] = {
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,
103 };
104 
105 static const double sym10_hp[20] = {
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,
116 };
117 
118 static const double sym10_ilp[20] = {
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,
129 };
130 
131 static const double sym10_ihp[20] = {
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,
142 };
143 
144 static const double rbior68_lp[18] = {
145  0.0, 0.0, 0.0, 0.0,
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,
152 };
153 
154 static const double rbior68_hp[18] = {
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,
164 };
165 
166 static const double rbior68_ilp[18] = {
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,
176 };
177 
178 static const double rbior68_ihp[18] = {
179  0.0, 0.0, 0.0, 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,
186 };
187 
188 static const double coif5_lp[30] = {
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,
204 };
205 
206 static const double coif5_hp[30] = {
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,
222 };
223 
224 static const double coif5_ilp[30] = {
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,
240 };
241 
242 static const double coif5_ihp[30] = {
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,
258 };
259 
260 static const double deb10_lp[20] = {
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,
271 };
272 
273 static const double deb10_hp[20] = {
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,
284 };
285 
286 static const double deb10_ilp[20] = {
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,
297 };
298 
299 static const double deb10_ihp[20] = {
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,
310 };
311 
312 static const double sym4_lp[8] = {
313  -0.07576571478927333,
314  -0.02963552764599851,
315  0.49761866763201545,
316  0.8037387518059161,
317  0.29785779560527736,
318  -0.09921954357684722,
319  -0.012603967262037833,
320  0.0322231006040427,
321 };
322 
323 static const double sym4_hp[8] = {
324  -0.0322231006040427,
325  -0.012603967262037833,
326  0.09921954357684722,
327  0.29785779560527736,
328  -0.8037387518059161,
329  0.49761866763201545,
330  0.02963552764599851,
331  -0.07576571478927333,
332 };
333 
334 static const double sym4_ilp[8] = {
335  0.0322231006040427,
336  -0.012603967262037833,
337  -0.09921954357684722,
338  0.29785779560527736,
339  0.8037387518059161,
340  0.49761866763201545,
341  -0.02963552764599851,
342  -0.07576571478927333,
343 };
344 
345 static const double sym4_ihp[8] = {
346  -0.07576571478927333,
347  0.02963552764599851,
348  0.49761866763201545,
349  -0.8037387518059161,
350  0.29785779560527736,
351  0.09921954357684722,
352  -0.012603967262037833,
353  -0.0322231006040427,
354 };
355 
356 static const double sym2_lp[4] = {
357  -0.12940952255092145, 0.22414386804185735,
358  0.836516303737469, 0.48296291314469025,
359 };
360 
361 static const double sym2_hp[4] = {
362  -0.48296291314469025, 0.836516303737469,
363  -0.22414386804185735, -0.12940952255092145,
364 };
365 
366 static const double sym2_ilp[4] = {
367  0.48296291314469025, 0.836516303737469,
368  0.22414386804185735, -0.12940952255092145,
369 };
370 
371 static const double sym2_ihp[4] = {
372  -0.12940952255092145, -0.22414386804185735,
373  0.836516303737469, -0.48296291314469025,
374 };
375 
376 #define MAX_LEVELS 13
377 
378 typedef struct ChannelParams {
381  double **output_coefs;
383  double **filter_coefs;
384 
392 
393  double *tempa;
394  double *tempd;
395  double *temp_in;
396  double *buffer;
397  double *buffer2;
398  double *prev;
399  double *overlap;
400 } ChannelParams;
401 
402 typedef struct AudioFWTDNContext {
403  const AVClass *class;
404 
405  double sigma;
406  double percent;
407  double softness;
408 
409  uint64_t sn;
410  int64_t eof_pts;
411 
413  int channels;
415  int levels;
419  int adaptive;
420 
421  int delay;
427 
428  const double *lp, *hp;
429  const double *ilp, *ihp;
430 
433 
434  int (*filter_channel)(AVFilterContext *ctx, void *arg, int ch, int nb_jobs);
436 
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
440 
441 static const AVOption afwtdn_options[] = {
442  { "sigma", "set noise sigma", OFFSET(sigma), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 1, AFR },
443  { "levels", "set number of wavelet levels", OFFSET(levels), AV_OPT_TYPE_INT, {.i64=10}, 1, MAX_LEVELS-1, AF },
444  { "wavet", "set wavelet type", OFFSET(wavelet_type), AV_OPT_TYPE_INT, {.i64=SYM10}, 0, NB_WAVELET_TYPES - 1, AF, "wavet" },
445  { "sym2", "sym2", 0, AV_OPT_TYPE_CONST, {.i64=SYM2}, 0, 0, AF, "wavet" },
446  { "sym4", "sym4", 0, AV_OPT_TYPE_CONST, {.i64=SYM4}, 0, 0, AF, "wavet" },
447  { "rbior68", "rbior68", 0, AV_OPT_TYPE_CONST, {.i64=RBIOR68}, 0, 0, AF, "wavet" },
448  { "deb10", "deb10", 0, AV_OPT_TYPE_CONST, {.i64=DEB10}, 0, 0, AF, "wavet" },
449  { "sym10", "sym10", 0, AV_OPT_TYPE_CONST, {.i64=SYM10}, 0, 0, AF, "wavet" },
450  { "coif5", "coif5", 0, AV_OPT_TYPE_CONST, {.i64=COIF5}, 0, 0, AF, "wavet" },
451  { "bl3", "bl3", 0, AV_OPT_TYPE_CONST, {.i64=BL3}, 0, 0, AF, "wavet" },
452  { "percent", "set percent of full denoising", OFFSET(percent),AV_OPT_TYPE_DOUBLE, {.dbl=85}, 0, 100, AFR },
453  { "profile", "profile noise", OFFSET(need_profile), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AFR },
454  { "adaptive", "adaptive profiling of noise", OFFSET(adaptive), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AFR },
455  { "samples", "set frame size in number of samples", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64=8192}, 512, 65536, AF },
456  { "softness", "set thresholding softness", OFFSET(softness), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 10, AFR },
457  { NULL }
458 };
459 
460 AVFILTER_DEFINE_CLASS(afwtdn);
461 
462 #define pow2(x) (1U << (x))
463 #define mod_pow2(x, power_of_two) ((x) & ((power_of_two) - 1))
464 
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)
469 {
470  double thigh = 0.0, tlow = 0.0;
471  int buff_idx = 1 + skip;
472 
473  memcpy(buffer, in, buff_idx * sizeof(*buffer));
474  memset(buffer + buff_idx, 0, (buffer_length - buff_idx) * sizeof(*buffer));
475 
476  for (int i = 0; i < out_length - 1; i++) {
477  double thigh = 0.0, tlow = 0.0;
478 
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];
482 
483  thigh += btemp * hp[j];
484  tlow += btemp * lp[j];
485  }
486 
487  high[i] = thigh;
488  low[i] = tlow;
489  buffer[buff_idx++] = in[2 * i + 1 + skip];
490  buffer[buff_idx++] = in[2 * i + 2 + skip];
491  buff_idx = mod_pow2(buff_idx, buffer_length);
492  }
493 
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];
497 
498  thigh += btemp * hp[i];
499  tlow += btemp * lp[i];
500  }
501 
502  high[out_length - 1] = thigh;
503  low[out_length - 1] = tlow;
504 }
505 
506 static int left_ext(int wavelet_length, int levels, uint64_t sn)
507 {
508  if (!sn)
509  return 0;
510  return (pow2(levels) - 1) * (wavelet_length - 2) + mod_pow2(sn, pow2(levels));
511 }
512 
513 static int nb_coefs(int length, int level, uint64_t sn)
514 {
515  const int pow2_level = pow2(level);
516 
517  return (sn + length) / pow2_level - sn / pow2_level;
518 }
519 
520 static int reallocate_inputs(double **out, int *out_length,
521  int in_length, int levels, int ch, uint64_t sn)
522 {
523  const int temp_length = nb_coefs(in_length, levels, sn);
524 
525  for (int level = 0; level < levels; level++) {
526  const int temp_length = nb_coefs(in_length, level + 1, sn);
527 
528  if (temp_length > out_length[level]) {
529  av_freep(&out[level]);
530  out_length[level] = 0;
531 
532  out[level] = av_calloc(temp_length + 1, sizeof(**out));
533  if (!out[level])
534  return AVERROR(ENOMEM);
535  out_length[level] = temp_length + 1;
536  }
537 
538  memset(out[level] + temp_length, 0,
539  (out_length[level] - temp_length) * sizeof(**out));
540  out_length[level] = temp_length;
541  }
542 
543  if (temp_length > out_length[levels]) {
544  av_freep(&out[levels]);
545  out_length[levels] = 0;
546 
547  out[levels] = av_calloc(temp_length + 1, sizeof(**out));
548  if (!out[levels])
549  return AVERROR(ENOMEM);
550  out_length[levels] = temp_length + 1;
551  }
552 
553  memset(out[levels] + temp_length, 0,
554  (out_length[levels] - temp_length) * sizeof(**out));
555  out_length[levels] = temp_length;
556 
557  return 0;
558 }
559 
560 static int max_left_zeros_inverse(int levels, int level, int wavelet_length)
561 {
562  return (pow2(levels - level) - 1) * (wavelet_length - 1);
563 }
564 
566  double **out, int *out_length,
567  int in_length, int levels, int ch, uint64_t sn)
568 {
569  ChannelParams *cp = &s->cp[ch];
570  int temp_length = 0;
571  int add = 0;
572 
573  for (int level = 0; level < levels; level++) {
574  temp_length = nb_coefs(in_length, level + 1, sn);
575  if (temp_length > out_length[level]) {
577  out_length[level] = 0;
578 
579  add = max_left_zeros_inverse(levels, level + 1, s->wavelet_length);
580  cp->subbands_to_free[level] = av_calloc(add + temp_length + 1, sizeof(**out));
581  if (!cp->subbands_to_free[level])
582  return AVERROR(ENOMEM);
583  out_length[level] = add + temp_length + 1;
584  out[level] = cp->subbands_to_free[level] + add;
585  }
586 
587  memset(out[level] + temp_length, 0,
588  FFMAX(out_length[level] - temp_length - add, 0) * sizeof(**out));
589  out_length[level] = temp_length;
590  }
591 
592  temp_length = nb_coefs(in_length, levels, sn);
593  if (temp_length > out_length[levels]) {
594  av_freep(&cp->subbands_to_free[levels]);
595  out_length[levels] = 0;
596 
597  cp->subbands_to_free[levels] = av_calloc(temp_length + 1, sizeof(**out));
598  if (!cp->subbands_to_free[levels])
599  return AVERROR(ENOMEM);
600  out_length[levels] = temp_length + 1;
601  out[levels] = cp->subbands_to_free[levels];
602  }
603 
604  memset(out[levels] + temp_length, 0,
605  (out_length[levels] - temp_length) * sizeof(**out));
606  out_length[levels] = temp_length;
607 
608  return 0;
609 }
610 
611 static int discard_left_ext(int wavelet_length, int levels, int level, uint64_t sn)
612 {
613  if (levels == level || sn == 0)
614  return 0;
615  return (pow2(levels - level) - 1) * (wavelet_length - 2) + mod_pow2(sn, pow2(levels)) / pow2(level);
616 }
617 
619  const double *in, int in_length,
620  double **out, int *out_length, int ch, uint64_t sn)
621 {
622  ChannelParams *cp = &s->cp[ch];
623  int levels = s->levels;
624  int skip = sn ? s->wavelet_length - 1 : 1;
625  int leftext, ret;
626 
627  ret = reallocate_inputs(out, out_length, in_length, levels, ch, sn);
628  if (ret < 0)
629  return ret;
631  in_length, levels, ch, sn);
632  if (ret < 0)
633  return ret;
634 
635  leftext = left_ext(s->wavelet_length, levels, sn);
636 
637  if (cp->temp_in_max_length < in_length + cp->max_left_ext + skip) {
638  av_freep(&cp->temp_in);
639  cp->temp_in_max_length = in_length + cp->max_left_ext + skip;
640  cp->temp_in = av_calloc(cp->temp_in_max_length, sizeof(*cp->temp_in));
641  if (!cp->temp_in) {
642  cp->temp_in_max_length = 0;
643  return AVERROR(ENOMEM);
644  }
645  }
646 
647  memset(cp->temp_in, 0, cp->temp_in_max_length * sizeof(*cp->temp_in));
648  cp->temp_in_length = in_length + leftext;
649 
650  if (leftext)
651  memcpy(cp->temp_in, cp->prev + s->prev_length - leftext, leftext * sizeof(*cp->temp_in));
652  memcpy(cp->temp_in + leftext, in, in_length * sizeof(*in));
653 
654  if (levels == 1) {
655  conv_down(cp->temp_in, cp->temp_in_length, out[1], out[0], out_length[1],
656  s->lp, s->hp, s->wavelet_length, skip,
657  cp->buffer, cp->buffer_length);
658  } else {
659  int discard = discard_left_ext(s->wavelet_length, levels, 1, sn);
660  int tempa_length_prev;
661 
662  if (cp->tempa_len_max < (in_length + cp->max_left_ext + s->wavelet_length - 1) / 2) {
663  av_freep(&cp->tempa);
664  av_freep(&cp->tempd);
665  cp->tempa_len_max = (in_length + cp->max_left_ext + s->wavelet_length - 1) / 2;
666  cp->tempa = av_calloc(cp->tempa_len_max, sizeof(*cp->tempa));
667  cp->tempd = av_calloc(cp->tempa_len_max, sizeof(*cp->tempd));
668  if (!cp->tempa || !cp->tempd) {
669  cp->tempa_len_max = 0;
670  return AVERROR(ENOMEM);
671  }
672  }
673 
674  memset(cp->tempa, 0, cp->tempa_len_max * sizeof(*cp->tempa));
675  memset(cp->tempd, 0, cp->tempa_len_max * sizeof(*cp->tempd));
676 
677  cp->tempa_length = out_length[0] + discard;
679  cp->tempa, cp->tempd, cp->tempa_length,
680  s->lp, s->hp, s->wavelet_length, skip,
681  cp->buffer, cp->buffer_length);
682  memcpy(out[0], cp->tempd + discard, out_length[0] * sizeof(**out));
683  tempa_length_prev = cp->tempa_length;
684 
685  for (int level = 1; level < levels - 1; level++) {
686  if (out_length[level] == 0)
687  return 0;
688  discard = discard_left_ext(s->wavelet_length, levels, level + 1, sn);
689  cp->tempa_length = out_length[level] + discard;
690  conv_down(cp->tempa, tempa_length_prev,
691  cp->tempa, cp->tempd, cp->tempa_length,
692  s->lp, s->hp, s->wavelet_length, skip,
693  cp->buffer, cp->buffer_length);
694  memcpy(out[level], cp->tempd + discard, out_length[level] * sizeof(**out));
695  tempa_length_prev = cp->tempa_length;
696  }
697 
698  if (out_length[levels] == 0)
699  return 0;
700  conv_down(cp->tempa, cp->tempa_length, out[levels], out[levels - 1], out_length[levels],
701  s->lp, s->hp, s->wavelet_length, skip,
702  cp->buffer, cp->buffer_length);
703  }
704 
705  if (s->prev_length < in_length) {
706  memcpy(cp->prev, in + in_length - cp->max_left_ext, cp->max_left_ext * sizeof(*cp->prev));
707  } else {
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));
710  }
711 
712  return 0;
713 }
714 
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)
718 {
719  int shift = 0, buff_idx = 0, in_idx = 0;
720 
721  memset(buffer, 0, buffer_length * sizeof(*buffer));
722  memset(buffer2, 0, buffer_length * sizeof(*buffer2));
723 
724  for (int i = 0; i < out_length; i++) {
725  double sum = 0.0;
726 
727  if ((i & 1) == 0) {
728  if (in_idx < in_length) {
729  buffer[buff_idx] = low[in_idx];
730  buffer2[buff_idx] = high[in_idx++];
731  } else {
732  buffer[buff_idx] = 0;
733  buffer2[buff_idx] = 0;
734  }
735  buff_idx++;
736  if (buff_idx >= buffer_length)
737  buff_idx = 0;
738  shift = 0;
739  }
740 
741  for (int j = 0; j < (filter_length - shift + 1) / 2; j++) {
742  const int idx = mod_pow2(-j + buff_idx - 1, buffer_length);
743 
744  sum += buffer[idx] * lp[j * 2 + shift] + buffer2[idx] * hp[j * 2 + shift];
745  }
746  out[i] = sum;
747  shift = 1;
748  }
749 }
750 
751 static int append_left_ext(int wavelet_length, int levels, int level, uint64_t sn)
752 {
753  if (levels == level)
754  return 0;
755 
756  return (pow2(levels - level) - 1) * (wavelet_length - 2) +
757  mod_pow2(sn, pow2(levels)) / pow2(level);
758 }
759 
761  double **in, int *in_length,
762  double *out, int out_length, int ch, uint64_t sn)
763 {
764  ChannelParams *cp = &s->cp[ch];
765  const int levels = s->levels;
766  int leftext = left_ext(s->wavelet_length, levels, sn);
767  int temp_skip = 0;
768 
769  if (sn == 0)
770  temp_skip = cp->min_left_ext;
771 
772  memset(out, 0, out_length * sizeof(*out));
773 
774  if (cp->temp_in_max_length < out_length + cp->max_left_ext + s->wavelet_length - 1) {
775  av_freep(&cp->temp_in);
776  cp->temp_in_max_length = out_length + cp->max_left_ext + s->wavelet_length - 1;
777  cp->temp_in = av_calloc(cp->temp_in_max_length, sizeof(*cp->temp_in));
778  if (!cp->temp_in) {
779  cp->temp_in_max_length = 0;
780  return AVERROR(ENOMEM);
781  }
782  }
783 
784  memset(cp->temp_in, 0, cp->temp_in_max_length * sizeof(*cp->temp_in));
785  cp->temp_in_length = out_length + cp->max_left_ext;
786 
787  if (levels == 1) {
788  conv_up(in[1], in[0], in_length[1], cp->temp_in, cp->temp_in_length,
789  s->ilp, s->ihp, s->wavelet_length,
790  cp->buffer, cp->buffer2, cp->buffer_length);
791  memcpy(out + cp->max_left_ext - leftext, cp->temp_in + temp_skip,
792  FFMAX(0, out_length - (cp->max_left_ext - leftext)) * sizeof(*out));
793  } else {
794  double *hp1, *hp2;
795  int add, add2;
796 
797  if (cp->tempa_len_max < (out_length + cp->max_left_ext + s->wavelet_length - 1) / 2) {
798  av_freep(&cp->tempa);
799  cp->tempa_len_max = (out_length + cp->max_left_ext + s->wavelet_length - 1) / 2;
800  cp->tempa = av_calloc(cp->tempa_len_max, sizeof(*cp->tempa));
801  if (!cp->tempa) {
802  cp->tempa_len_max = 0;
803  return AVERROR(ENOMEM);
804  }
805  }
806 
807  memset(cp->tempa, 0, cp->tempa_len_max * sizeof(*cp->tempa));
808 
809  hp1 = levels & 1 ? cp->temp_in : cp->tempa;
810  hp2 = levels & 1 ? cp->tempa : cp->temp_in;
811 
812  add = append_left_ext(s->wavelet_length, levels, levels - 1, sn);
813  conv_up(in[levels], in[levels - 1], in_length[levels], hp1, in_length[levels - 2] + add,
814  s->ilp, s->ihp, s->wavelet_length, cp->buffer, cp->buffer2, cp->buffer_length);
815 
816  for (int level = levels - 1; level > 1; level--) {
817  add2 = append_left_ext(s->wavelet_length, levels, level - 1, sn);
818  add = append_left_ext(s->wavelet_length, levels, level, sn);
819  conv_up(hp1, in[level - 1] - add, in_length[level - 1] + add,
820  hp2, in_length[level - 2] + add2,
821  s->ilp, s->ihp, s->wavelet_length,
822  cp->buffer, cp->buffer2, cp->buffer_length);
823  FFSWAP(double *, hp1, hp2);
824  }
825 
826  add = append_left_ext(s->wavelet_length, levels, 1, sn);
827  conv_up(hp1, in[0] - add, in_length[0] + add, cp->temp_in, cp->temp_in_length,
828  s->ilp, s->ihp, s->wavelet_length,
829  cp->buffer, cp->buffer2, cp->buffer_length);
830  }
831 
832  memset(cp->temp_in, 0, temp_skip * sizeof(*cp->temp_in));
833  if (s->overlap_length <= out_length) {
834  memcpy(out + cp->max_left_ext - leftext, cp->temp_in + temp_skip,
835  FFMAX(0, out_length - (cp->max_left_ext - leftext)) * sizeof(*out));
836  for (int i = 0;i < FFMIN(s->overlap_length, out_length); i++)
837  out[i] += cp->overlap[i];
838 
839  memcpy(cp->overlap, cp->temp_in + out_length - (cp->max_left_ext - leftext),
840  s->overlap_length * sizeof(*cp->overlap));
841  } else {
842  for (int i = 0;i < s->overlap_length - (cp->max_left_ext - leftext); i++)
843  cp->overlap[i + cp->max_left_ext - leftext] += cp->temp_in[i];
844  memcpy(out, cp->overlap, out_length * sizeof(*out));
845  memmove(cp->overlap, cp->overlap + out_length,
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));
849  }
850 
851  return 0;
852 }
853 
854 static int next_pow2(int in)
855 {
856  return 1 << (av_log2(in) + 1);
857 }
858 
859 static void denoise_level(double *out, const double *in,
860  const double *filter,
861  double percent, int length)
862 {
863  const double x = percent * 0.01;
864  const double y = 1.0 - x;
865 
866  for (int i = 0; i < length; i++)
867  out[i] = x * filter[i] + in[i] * y;
868 }
869 
870 static double sqr(double in)
871 {
872  return in * in;
873 }
874 
875 static double measure_mean(const double *in, int length)
876 {
877  double sum = 0.0;
878 
879  for (int i = 0; i < length; i++)
880  sum += in[i];
881 
882  return sum / length;
883 }
884 
885 static double measure_absmean(const double *in, int length)
886 {
887  double sum = 0.0;
888 
889  for (int i = 0; i < length; i++)
890  sum += fabs(in[i]);
891 
892  return sum / length;
893 }
894 
895 static double measure_stddev(const double *in, int length, double mean)
896 {
897  double sum = 0.;
898 
899  for (int i = 0; i < length; i++) {
900  sum += sqr(in[i] - mean);
901  }
902 
903  return sqrt(sum / length);
904 }
905 
906 static void noise_filter(const double stddev, const double *in,
907  double *out, double absmean, double softness,
908  double new_stddev, int length)
909 {
910  for (int i = 0; i < length; i++) {
911  if (new_stddev <= stddev)
912  out[i] = 0.0;
913  else if (fabs(in[i]) <= absmean)
914  out[i] = 0.0;
915  else
916  out[i] = in[i] - FFSIGN(in[i]) * absmean / exp(3.0 * softness * (fabs(in[i]) - absmean) / absmean);
917  }
918 }
919 
920 typedef struct ThreadData {
921  AVFrame *in, *out;
922 } ThreadData;
923 
924 static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
925 {
926  AudioFWTDNContext *s = ctx->priv;
927  ThreadData *td = arg;
928  AVFrame *in = td->in;
929  AVFrame *out = td->out;
930  ChannelParams *cp = &s->cp[ch];
931  const double *src = (const double *)(in->extended_data[ch]);
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;
939  int ret;
940 
941  ret = forward(s, src, in->nb_samples, cp->output_coefs, cp->output_length, ch, s->sn);
942  if (ret < 0)
943  return ret;
944 
945  if (!s->got_profile && s->need_profile) {
946  for (int level = 0; level <= s->levels; level++) {
947  const int length = cp->output_length[level];
948  const double scale = sqrt(2.0 * log(length));
949 
950  stddev[level] = measure_stddev(cp->output_coefs[level], length,
951  measure_mean(cp->output_coefs[level], length)) * scale;
952  absmean[level] = measure_absmean(cp->output_coefs[level], length) * scale;
953  }
954  } else if (!s->got_profile && !s->need_profile && !s->adaptive) {
955  for (int level = 0; level <= s->levels; level++) {
956  const int length = cp->output_length[level];
957  const double scale = sqrt(2.0 * log(length));
958 
959  stddev[level] = 0.5 * s->sigma * scale;
960  absmean[level] = 0.5 * s->sigma * scale;
961  }
962  }
963 
964  for (int level = 0; level <= s->levels; level++) {
965  const int length = cp->output_length[level];
966  double vad;
967 
968  new_stddev[level] = measure_stddev(cp->output_coefs[level], length,
969  measure_mean(cp->output_coefs[level], length));
970  new_absmean[level] = measure_absmean(cp->output_coefs[level], length);
971  if (new_absmean[level] <= FLT_EPSILON)
972  vad = 1.0;
973  else
974  vad = new_stddev[level] / new_absmean[level];
975  if (level < s->levels)
976  is_noise += sqr(vad - 1.232);
977  }
978 
979  is_noise *= in->sample_rate;
980  is_noise /= s->nb_samples;
981  for (int level = 0; level <= s->levels; level++) {
982  const double percent = ctx->is_disabled ? 0. : s->percent;
983  const int length = cp->output_length[level];
984  const double scale = sqrt(2.0 * log(length));
985 
986  if (is_noise < 0.05 && s->adaptive) {
987  stddev[level] = new_stddev[level] * scale;
988  absmean[level] = new_absmean[level] * scale;
989  }
990 
991  noise_filter(stddev[level], cp->output_coefs[level], filter, absmean[level],
992  s->softness, new_stddev[level], length);
993  denoise_level(cp->filter_coefs[level], cp->output_coefs[level], filter, percent, length);
994  }
995 
996  ret = inverse(s, cp->filter_coefs, cp->filter_length, dst, out->nb_samples, ch, s->sn);
997  if (ret < 0)
998  return ret;
999 
1000  return 0;
1001 }
1002 
1004 {
1005  AVFilterContext *ctx = inlink->dst;
1006  AudioFWTDNContext *s = ctx->priv;
1007  AVFilterLink *outlink = ctx->outputs[0];
1008  ThreadData td;
1009  AVFrame *out;
1010  int eof = in == NULL;
1011 
1012  out = ff_get_audio_buffer(outlink, s->nb_samples);
1013  if (!out) {
1014  av_frame_free(&in);
1015  return AVERROR(ENOMEM);
1016  }
1017  if (in) {
1018  av_frame_copy_props(out, in);
1019  s->eof_pts = in->pts + in->nb_samples;
1020  }
1021  if (eof)
1022  out->pts = s->eof_pts - s->padd_samples;
1023 
1024  if (!in || in->nb_samples < s->nb_samples) {
1025  AVFrame *new_in = ff_get_audio_buffer(outlink, s->nb_samples);
1026 
1027  if (!new_in) {
1028  av_frame_free(&in);
1029  av_frame_free(&out);
1030  return AVERROR(ENOMEM);
1031  }
1032  if (in)
1033  av_frame_copy_props(new_in, in);
1034 
1035  s->padd_samples -= s->nb_samples - (in ? in->nb_samples: 0);
1036  if (in)
1037  av_samples_copy(new_in->extended_data, in->extended_data, 0, 0,
1038  in->nb_samples, in->ch_layout.nb_channels, in->format);
1039  av_frame_free(&in);
1040  in = new_in;
1041  }
1042 
1043  td.in = in;
1044  td.out = out;
1045  ff_filter_execute(ctx, s->filter_channel, &td, NULL, inlink->ch_layout.nb_channels);
1046  if (s->need_profile)
1047  s->got_profile = 1;
1048 
1049  s->sn += s->nb_samples;
1050 
1051  if (s->drop_samples >= in->nb_samples) {
1052  s->drop_samples -= in->nb_samples;
1053  s->delay += in->nb_samples;
1054  av_frame_free(&in);
1055  av_frame_free(&out);
1056  FF_FILTER_FORWARD_STATUS(inlink, outlink);
1057  FF_FILTER_FORWARD_WANTED(outlink, inlink);
1058  return 0;
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));
1064  }
1065 
1066  out->nb_samples = in->nb_samples - s->drop_samples;
1067  out->pts = in->pts - av_rescale_q(s->delay, (AVRational){1, outlink->sample_rate}, outlink->time_base);
1068  s->delay += s->drop_samples;
1069  s->drop_samples = 0;
1070  } else {
1071  if (s->padd_samples < 0 && eof) {
1072  out->nb_samples += s->padd_samples;
1073  s->padd_samples = 0;
1074  }
1075  if (!eof)
1076  out->pts = in->pts - av_rescale_q(s->delay, (AVRational){1, outlink->sample_rate}, outlink->time_base);
1077  }
1078 
1079  av_frame_free(&in);
1080  return ff_filter_frame(outlink, out);
1081 }
1082 
1083 static int max_left_ext(int wavelet_length, int levels)
1084 {
1085  return (pow2(levels) - 1) * (wavelet_length - 1);
1086 }
1087 
1088 static int min_left_ext(int wavelet_length, int levels)
1089 {
1090  return (pow2(levels) - 1) * (wavelet_length - 2);
1091 }
1092 
1093 static int config_output(AVFilterLink *outlink)
1094 {
1095  AVFilterContext *ctx = outlink->src;
1096  AudioFWTDNContext *s = ctx->priv;
1097 
1098  switch (s->wavelet_type) {
1099  case SYM2:
1100  s->wavelet_length = 4;
1101  s->lp = sym2_lp;
1102  s->hp = sym2_hp;
1103  s->ilp = sym2_ilp;
1104  s->ihp = sym2_ihp;
1105  break;
1106  case SYM4:
1107  s->wavelet_length = 8;
1108  s->lp = sym4_lp;
1109  s->hp = sym4_hp;
1110  s->ilp = sym4_ilp;
1111  s->ihp = sym4_ihp;
1112  break;
1113  case RBIOR68:
1114  s->wavelet_length = 18;
1115  s->lp = rbior68_lp;
1116  s->hp = rbior68_hp;
1117  s->ilp = rbior68_ilp;
1118  s->ihp = rbior68_ihp;
1119  break;
1120  case DEB10:
1121  s->wavelet_length = 20;
1122  s->lp = deb10_lp;
1123  s->hp = deb10_hp;
1124  s->ilp = deb10_ilp;
1125  s->ihp = deb10_ihp;
1126  break;
1127  case SYM10:
1128  s->wavelet_length = 20;
1129  s->lp = sym10_lp;
1130  s->hp = sym10_hp;
1131  s->ilp = sym10_ilp;
1132  s->ihp = sym10_ihp;
1133  break;
1134  case COIF5:
1135  s->wavelet_length = 30;
1136  s->lp = coif5_lp;
1137  s->hp = coif5_hp;
1138  s->ilp = coif5_ilp;
1139  s->ihp = coif5_ihp;
1140  break;
1141  case BL3:
1142  s->wavelet_length = 42;
1143  s->lp = bl3_lp;
1144  s->hp = bl3_hp;
1145  s->ilp = bl3_ilp;
1146  s->ihp = bl3_ihp;
1147  break;
1148  default:
1149  av_assert0(0);
1150  }
1151 
1152  s->levels = FFMIN(s->levels, lrint(log(s->nb_samples / (s->wavelet_length - 1.0)) / M_LN2));
1153  av_log(ctx, AV_LOG_VERBOSE, "levels: %d\n", s->levels);
1154  s->filter_channel = filter_channel;
1155 
1156  s->stddev = ff_get_audio_buffer(outlink, MAX_LEVELS);
1157  s->new_stddev = ff_get_audio_buffer(outlink, MAX_LEVELS);
1158  s->filter = ff_get_audio_buffer(outlink, s->nb_samples);
1159  s->absmean = ff_get_audio_buffer(outlink, MAX_LEVELS);
1160  s->new_absmean = ff_get_audio_buffer(outlink, MAX_LEVELS);
1161  if (!s->stddev || !s->absmean || !s->filter ||
1162  !s->new_stddev || !s->new_absmean)
1163  return AVERROR(ENOMEM);
1164 
1165  s->channels = outlink->ch_layout.nb_channels;
1166  s->overlap_length = max_left_ext(s->wavelet_length, s->levels);
1167  s->prev_length = s->overlap_length;
1168  s->drop_samples = s->overlap_length;
1169  s->padd_samples = s->overlap_length;
1170  s->sn = 1;
1171 
1172  s->cp = av_calloc(s->channels, sizeof(*s->cp));
1173  if (!s->cp)
1174  return AVERROR(ENOMEM);
1175 
1176  for (int ch = 0; ch < s->channels; ch++) {
1177  ChannelParams *cp = &s->cp[ch];
1178 
1179  cp->output_coefs = av_calloc(s->levels + 1, sizeof(*cp->output_coefs));
1180  cp->filter_coefs = av_calloc(s->levels + 1, sizeof(*cp->filter_coefs));
1181  cp->output_length = av_calloc(s->levels + 1, sizeof(*cp->output_length));
1182  cp->filter_length = av_calloc(s->levels + 1, sizeof(*cp->filter_length));
1183  cp->buffer_length = next_pow2(s->wavelet_length);
1184  cp->buffer = av_calloc(cp->buffer_length, sizeof(*cp->buffer));
1185  cp->buffer2 = av_calloc(cp->buffer_length, sizeof(*cp->buffer2));
1186  cp->subbands_to_free = av_calloc(s->levels + 1, sizeof(*cp->subbands_to_free));
1187  cp->prev = av_calloc(s->prev_length, sizeof(*cp->prev));
1188  cp->overlap = av_calloc(s->overlap_length, sizeof(*cp->overlap));
1189  cp->max_left_ext = max_left_ext(s->wavelet_length, s->levels);
1190  cp->min_left_ext = min_left_ext(s->wavelet_length, s->levels);
1191  if (!cp->output_coefs || !cp->filter_coefs || !cp->output_length ||
1192  !cp->filter_length || !cp->subbands_to_free || !cp->prev || !cp->overlap ||
1193  !cp->buffer || !cp->buffer2)
1194  return AVERROR(ENOMEM);
1195  }
1196 
1197  return 0;
1198 }
1199 
1201 {
1202  AVFilterLink *inlink = ctx->inputs[0];
1203  AVFilterLink *outlink = ctx->outputs[0];
1204  AudioFWTDNContext *s = ctx->priv;
1205  AVFrame *in = NULL;
1206  int ret, status;
1207  int64_t pts;
1208 
1210 
1211  ret = ff_inlink_consume_samples(inlink, s->nb_samples, s->nb_samples, &in);
1212  if (ret < 0)
1213  return ret;
1214  if (ret > 0)
1215  return filter_frame(inlink, in);
1216 
1218  if (status == AVERROR_EOF) {
1219  while (s->padd_samples != 0) {
1221  if (ret < 0)
1222  return ret;
1223  }
1224  ff_outlink_set_status(outlink, status, pts);
1225  return ret;
1226  }
1227  }
1228  FF_FILTER_FORWARD_WANTED(outlink, inlink);
1229 
1230  return FFERROR_NOT_READY;
1231 }
1232 
1234 {
1235  AudioFWTDNContext *s = ctx->priv;
1236 
1237  av_frame_free(&s->filter);
1238  av_frame_free(&s->new_stddev);
1239  av_frame_free(&s->stddev);
1240  av_frame_free(&s->new_absmean);
1241  av_frame_free(&s->absmean);
1242 
1243  for (int ch = 0; s->cp && ch < s->channels; ch++) {
1244  ChannelParams *cp = &s->cp[ch];
1245 
1246  av_freep(&cp->tempa);
1247  av_freep(&cp->tempd);
1248  av_freep(&cp->temp_in);
1249  av_freep(&cp->buffer);
1250  av_freep(&cp->buffer2);
1251  av_freep(&cp->prev);
1252  av_freep(&cp->overlap);
1253 
1254  av_freep(&cp->output_length);
1255  av_freep(&cp->filter_length);
1256 
1257  if (cp->output_coefs) {
1258  for (int level = 0; level <= s->levels; level++)
1259  av_freep(&cp->output_coefs[level]);
1260  }
1261 
1262  if (cp->subbands_to_free) {
1263  for (int level = 0; level <= s->levels; level++)
1265  }
1266 
1267  av_freep(&cp->subbands_to_free);
1268  av_freep(&cp->output_coefs);
1269  av_freep(&cp->filter_coefs);
1270  }
1271 
1272  av_freep(&s->cp);
1273 }
1274 
1275 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
1276  char *res, int res_len, int flags)
1277 {
1278  AudioFWTDNContext *s = ctx->priv;
1279  int ret;
1280 
1281  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
1282  if (ret < 0)
1283  return ret;
1284 
1285  if (!strcmp(cmd, "profile") && s->need_profile)
1286  s->got_profile = 0;
1287 
1288  return 0;
1289 }
1290 
1291 static const AVFilterPad outputs[] = {
1292  {
1293  .name = "default",
1294  .type = AVMEDIA_TYPE_AUDIO,
1295  .config_props = config_output,
1296  },
1297 };
1298 
1300  .name = "afwtdn",
1301  .description = NULL_IF_CONFIG_SMALL("Denoise audio stream using Wavelets."),
1302  .priv_size = sizeof(AudioFWTDNContext),
1303  .priv_class = &afwtdn_class,
1304  .activate = activate,
1305  .uninit = uninit,
1309  .process_command = process_command,
1312 };
av_samples_copy
int av_samples_copy(uint8_t *const *dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
Definition: samplefmt.c:222
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:107
coif5_ilp
static const double coif5_ilp[30]
Definition: af_afwtdn.c:224
nb_coefs
static int nb_coefs(int length, int level, uint64_t sn)
Definition: af_afwtdn.c:513
td
#define td
Definition: regdef.h:70
filter_channel
static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
Definition: af_afwtdn.c:924
AudioFWTDNContext::got_profile
int got_profile
Definition: af_afwtdn.c:418
level
uint8_t level
Definition: svq3.c:204
AVERROR
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
opt.h
ChannelParams::overlap
double * overlap
Definition: af_afwtdn.c:399
AudioFWTDNContext::padd_samples
int padd_samples
Definition: af_afwtdn.c:423
ChannelParams::temp_in_length
int temp_in_length
Definition: af_afwtdn.c:387
ChannelParams::tempa
double * tempa
Definition: af_afwtdn.c:393
out
FILE * out
Definition: movenc.c:54
AudioFWTDNContext::adaptive
int adaptive
Definition: af_afwtdn.c:419
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:978
ChannelParams::min_left_ext
int min_left_ext
Definition: af_afwtdn.c:390
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
FILTER_SINGLE_SAMPLEFMT
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
Definition: internal.h:185
inlink
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
Definition: filter_design.txt:212
normalize.log
log
Definition: normalize.py:21
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:100
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:452
SYM2
@ SYM2
Definition: af_afwtdn.c:30
AudioFWTDNContext::hp
const double * hp
Definition: af_afwtdn.c:428
AudioFWTDNContext::absmean
AVFrame * absmean
Definition: af_afwtdn.c:431
AVOption
AVOption.
Definition: opt.h:251
AudioFWTDNContext::new_stddev
AVFrame * new_stddev
Definition: af_afwtdn.c:432
AudioFWTDNContext::levels
int levels
Definition: af_afwtdn.c:415
sym4_ilp
static const double sym4_ilp[8]
Definition: af_afwtdn.c:334
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
float.h
ChannelParams::output_length
int * output_length
Definition: af_afwtdn.c:379
coif5_hp
static const double coif5_hp[30]
Definition: af_afwtdn.c:206
filter
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
Definition: filter_design.txt:228
sqr
static double sqr(double in)
Definition: af_afwtdn.c:870
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
ThreadData::out
AVFrame * out
Definition: af_adeclick.c:526
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:317
ThreadData::in
AVFrame * in
Definition: af_adecorrelate.c:153
FF_FILTER_FORWARD_STATUS_BACK
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition: filters.h:199
reallocate_outputs
static int reallocate_outputs(AudioFWTDNContext *s, double **out, int *out_length, int in_length, int levels, int ch, uint64_t sn)
Definition: af_afwtdn.c:565
sym2_ihp
static const double sym2_ihp[4]
Definition: af_afwtdn.c:371
M_LN2
#define M_LN2
Definition: mathematics.h:43
SYM4
@ SYM4
Definition: af_afwtdn.c:31
min_left_ext
static int min_left_ext(int wavelet_length, int levels)
Definition: af_afwtdn.c:1088
pow2
#define pow2(x)
Definition: af_afwtdn.c:462
conv_up
static void conv_up(double *low, double *high, int in_length, double *out, int out_length, const double *lp, const double *hp, int filter_length, double *buffer, double *buffer2, int buffer_length)
Definition: af_afwtdn.c:715
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(afwtdn)
FFSIGN
#define FFSIGN(a)
Definition: common.h:66
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:802
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
pts
static int64_t pts
Definition: transcode_aac.c:643
next_pow2
static int next_pow2(int in)
Definition: af_afwtdn.c:854
AudioFWTDNContext::nb_samples
int nb_samples
Definition: af_afwtdn.c:414
coif5_lp
static const double coif5_lp[30]
Definition: af_afwtdn.c:188
sym10_lp
static const double sym10_lp[20]
Definition: af_afwtdn.c:92
AudioFWTDNContext::sigma
double sigma
Definition: af_afwtdn.c:405
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:47
ChannelParams::buffer
double * buffer
Definition: af_afwtdn.c:396
coif5_ihp
static const double coif5_ihp[30]
Definition: af_afwtdn.c:242
avassert.h
lrint
#define lrint
Definition: tablegen.h:53
av_cold
#define av_cold
Definition: attributes.h:90
sym4_lp
static const double sym4_lp[8]
Definition: af_afwtdn.c:312
deb10_ilp
static const double deb10_ilp[20]
Definition: af_afwtdn.c:286
sym4_ihp
static const double sym4_ihp[8]
Definition: af_afwtdn.c:345
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:189
AudioFWTDNContext::eof_pts
int64_t eof_pts
Definition: af_afwtdn.c:410
s
#define s(width, name)
Definition: cbs_vp9.c:198
deb10_hp
static const double deb10_hp[20]
Definition: af_afwtdn.c:273
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
sym10_ilp
static const double sym10_ilp[20]
Definition: af_afwtdn.c:118
SYM10
@ SYM10
Definition: af_afwtdn.c:34
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
filters.h
rbior68_ihp
static const double rbior68_ihp[18]
Definition: af_afwtdn.c:178
AudioFWTDNContext::delay
int delay
Definition: af_afwtdn.c:421
noise_filter
static void noise_filter(const double stddev, const double *in, double *out, double absmean, double softness, double new_stddev, int length)
Definition: af_afwtdn.c:906
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
ChannelParams::prev
double * prev
Definition: af_afwtdn.c:398
AudioFWTDNContext::channels
int channels
Definition: af_afwtdn.c:413
AudioFWTDNContext::cp
ChannelParams * cp
Definition: af_afwtdn.c:426
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:192
arg
const char * arg
Definition: jacosubdec.c:67
sym2_lp
static const double sym2_lp[4]
Definition: af_afwtdn.c:356
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
rbior68_hp
static const double rbior68_hp[18]
Definition: af_afwtdn.c:154
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
denoise_level
static void denoise_level(double *out, const double *in, const double *filter, double percent, int length)
Definition: af_afwtdn.c:859
ff_inlink_consume_samples
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
Definition: avfilter.c:1402
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:736
OFFSET
#define OFFSET(x)
Definition: af_afwtdn.c:437
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
sym4_hp
static const double sym4_hp[8]
Definition: af_afwtdn.c:323
ff_audio_default_filterpad
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
Definition: audio.c:32
AudioFWTDNContext
Definition: af_afwtdn.c:402
NB_WAVELET_TYPES
@ NB_WAVELET_TYPES
Definition: af_afwtdn.c:37
ff_af_afwtdn
const AVFilter ff_af_afwtdn
Definition: af_afwtdn.c:1299
exp
int8_t exp
Definition: eval.c:72
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1337
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_afwtdn.c:1003
sym10_ihp
static const double sym10_ihp[20]
Definition: af_afwtdn.c:131
AudioFWTDNContext::new_absmean
AVFrame * new_absmean
Definition: af_afwtdn.c:432
sym10_hp
static const double sym10_hp[20]
Definition: af_afwtdn.c:105
bl3_ihp
static const double bl3_ihp[42]
Definition: af_afwtdn.c:80
ChannelParams::tempd
double * tempd
Definition: af_afwtdn.c:394
ChannelParams::output_coefs
double ** output_coefs
Definition: af_afwtdn.c:381
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
AudioFWTDNContext::wavelet_length
int wavelet_length
Definition: af_afwtdn.c:416
shift
static int shift(int a, int b)
Definition: bonk.c:262
bl3_hp
static const double bl3_hp[42]
Definition: af_afwtdn.c:56
measure_stddev
static double measure_stddev(const double *in, int length, double mean)
Definition: af_afwtdn.c:895
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:567
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:427
BL3
@ BL3
Definition: af_afwtdn.c:36
AudioFWTDNContext::wavelet_type
int wavelet_type
Definition: af_afwtdn.c:412
ff_filter_process_command
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.
Definition: avfilter.c:851
MAX_LEVELS
#define MAX_LEVELS
Definition: af_afwtdn.c:376
AudioFWTDNContext::sn
uint64_t sn
Definition: af_afwtdn.c:409
FF_FILTER_FORWARD_WANTED
FF_FILTER_FORWARD_WANTED(outlink, inlink)
forward
static int forward(AudioFWTDNContext *s, const double *in, int in_length, double **out, int *out_length, int ch, uint64_t sn)
Definition: af_afwtdn.c:618
max_left_ext
static int max_left_ext(int wavelet_length, int levels)
Definition: af_afwtdn.c:1083
ChannelParams::tempa_len_max
int tempa_len_max
Definition: af_afwtdn.c:386
AFR
#define AFR
Definition: af_afwtdn.c:439
AudioFWTDNContext::prev_length
int prev_length
Definition: af_afwtdn.c:425
deb10_ihp
static const double deb10_ihp[20]
Definition: af_afwtdn.c:299
AF
#define AF
Definition: af_afwtdn.c:438
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:420
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:401
ChannelParams::temp_in
double * temp_in
Definition: af_afwtdn.c:395
ThreadData
Used for passing data between threads.
Definition: dsddec.c:69
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
discard_left_ext
static int discard_left_ext(int wavelet_length, int levels, int level, uint64_t sn)
Definition: af_afwtdn.c:611
ChannelParams
sample data coding information
Definition: mlp.h:97
ChannelParams::tempa_length
int tempa_length
Definition: af_afwtdn.c:385
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:53
bl3_ilp
static const double bl3_ilp[42]
Definition: af_afwtdn.c:68
AudioFWTDNContext::need_profile
int need_profile
Definition: af_afwtdn.c:417
conv_down
static void conv_down(double *in, int in_length, double *low, double *high, int out_length, const double *lp, const double *hp, int wavelet_length, int skip, double *buffer, int buffer_length)
Definition: af_afwtdn.c:465
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
AudioFWTDNContext::drop_samples
int drop_samples
Definition: af_afwtdn.c:422
AudioFWTDNContext::ilp
const double * ilp
Definition: af_afwtdn.c:429
rbior68_lp
static const double rbior68_lp[18]
Definition: af_afwtdn.c:144
AudioFWTDNContext::filter_channel
int(* filter_channel)(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
Definition: af_afwtdn.c:434
AVFilter
Filter definition.
Definition: avfilter.h:166
AudioFWTDNContext::filter
AVFrame * filter
Definition: af_afwtdn.c:431
sym2_hp
static const double sym2_hp[4]
Definition: af_afwtdn.c:361
ret
ret
Definition: filter_design.txt:187
sym2_ilp
static const double sym2_ilp[4]
Definition: af_afwtdn.c:366
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
ChannelParams::buffer_length
int buffer_length
Definition: af_afwtdn.c:389
DEB10
@ DEB10
Definition: af_afwtdn.c:33
left_ext
static int left_ext(int wavelet_length, int levels, uint64_t sn)
Definition: af_afwtdn.c:506
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_afwtdn.c:1233
rbior68_ilp
static const double rbior68_ilp[18]
Definition: af_afwtdn.c:166
ChannelParams::subbands_to_free
double ** subbands_to_free
Definition: af_afwtdn.c:382
status
ov_status_e status
Definition: dnn_backend_openvino.c:119
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_afwtdn.c:1093
measure_mean
static double measure_mean(const double *in, int length)
Definition: af_afwtdn.c:875
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
outputs
static const AVFilterPad outputs[]
Definition: af_afwtdn.c:1291
AudioFWTDNContext::stddev
AVFrame * stddev
Definition: af_afwtdn.c:431
ChannelParams::max_left_ext
int max_left_ext
Definition: af_afwtdn.c:391
inverse
static int inverse(AudioFWTDNContext *s, double **in, int *in_length, double *out, int out_length, int ch, uint64_t sn)
Definition: af_afwtdn.c:760
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
max_left_zeros_inverse
static int max_left_zeros_inverse(int levels, int level, int wavelet_length)
Definition: af_afwtdn.c:560
append_left_ext
static int append_left_ext(int wavelet_length, int levels, int level, uint64_t sn)
Definition: af_afwtdn.c:751
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:67
WaveletTypes
WaveletTypes
Definition: af_afwtdn.c:29
mean
static float mean(const float *input, int size)
Definition: vf_nnedi.c:862
deb10_lp
static const double deb10_lp[20]
Definition: af_afwtdn.c:260
AVFilterContext
An instance of a filter.
Definition: avfilter.h:397
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
AudioFWTDNContext::ihp
const double * ihp
Definition: af_afwtdn.c:429
audio.h
ChannelParams::filter_coefs
double ** filter_coefs
Definition: af_afwtdn.c:383
ChannelParams::filter_length
int * filter_length
Definition: af_afwtdn.c:380
FF_FILTER_FORWARD_STATUS
FF_FILTER_FORWARD_STATUS(inlink, outlink)
AudioFWTDNContext::lp
const double * lp
Definition: af_afwtdn.c:428
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:193
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
reallocate_inputs
static int reallocate_inputs(double **out, int *out_length, int in_length, int levels, int ch, uint64_t sn)
Definition: af_afwtdn.c:520
bl3_lp
static const double bl3_lp[42]
Definition: af_afwtdn.c:44
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:155
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
AudioFWTDNContext::percent
double percent
Definition: af_afwtdn.c:406
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
afwtdn_options
static const AVOption afwtdn_options[]
Definition: af_afwtdn.c:441
COIF5
@ COIF5
Definition: af_afwtdn.c:35
ChannelParams::temp_in_max_length
int temp_in_max_length
Definition: af_afwtdn.c:388
activate
static int activate(AVFilterContext *ctx)
Definition: af_afwtdn.c:1200
RBIOR68
@ RBIOR68
Definition: af_afwtdn.c:32
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_afwtdn.c:1275
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:144
int
int
Definition: ffmpeg_filter.c:368
measure_absmean
static double measure_absmean(const double *in, int length)
Definition: af_afwtdn.c:885
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
mod_pow2
#define mod_pow2(x, power_of_two)
Definition: af_afwtdn.c:463
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375
AudioFWTDNContext::overlap_length
int overlap_length
Definition: af_afwtdn.c:424
ChannelParams::buffer2
double * buffer2
Definition: af_afwtdn.c:397
AudioFWTDNContext::softness
double softness
Definition: af_afwtdn.c:407