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