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/avstring.h"
25 #include "libavutil/opt.h"
26 #include "avfilter.h"
27 #include "audio.h"
28 #include "filters.h"
29 #include "formats.h"
30 
38  BL3,
40 };
41 
42 /*
43  * All wavelets coefficients are taken from: http://wavelets.pybytes.com/
44  */
45 
46 static const double bl3_lp[42] = {
47  0.000146098, -0.000232304, -0.000285414, 0.000462093, 0.000559952,
48  -0.000927187, -0.001103748, 0.00188212, 0.002186714, -0.003882426,
49  -0.00435384, 0.008201477, 0.008685294, -0.017982291, -0.017176331,
50  0.042068328, 0.032080869, -0.110036987, -0.050201753, 0.433923147,
51  0.766130398, 0.433923147, -0.050201753, -0.110036987, 0.032080869,
52  0.042068328, -0.017176331, -0.017982291, 0.008685294, 0.008201477,
53  -0.00435384, -0.003882426, 0.002186714, 0.00188212, -0.001103748,
54  -0.000927187, 0.000559952, 0.000462093, -0.000285414, -0.000232304,
55  0.000146098, 0.0,
56 };
57 
58 static const double bl3_hp[42] = {
59  0.0, 0.000146098, 0.000232304, -0.000285414, -0.000462093, 0.000559952,
60  0.000927187, -0.001103748, -0.00188212, 0.002186714, 0.003882426,
61  -0.00435384, -0.008201477, 0.008685294, 0.017982291, -0.017176331,
62  -0.042068328, 0.032080869, 0.110036987, -0.050201753, -0.433923147,
63  0.766130398, -0.433923147, -0.050201753, 0.110036987, 0.032080869,
64  -0.042068328, -0.017176331, 0.017982291, 0.008685294, -0.008201477,
65  -0.00435384, 0.003882426, 0.002186714, -0.00188212, -0.001103748,
66  0.000927187, 0.000559952, -0.000462093, -0.000285414, 0.000232304,
67  0.000146098,
68 };
69 
70 static const double bl3_ilp[42] = {
71  0.0, 0.000146098, -0.000232304, -0.000285414, 0.000462093, 0.000559952,
72  -0.000927187, -0.001103748, 0.00188212, 0.002186714, -0.003882426,
73  -0.00435384, 0.008201477, 0.008685294, -0.017982291, -0.017176331,
74  0.042068328, 0.032080869, -0.110036987, -0.050201753, 0.433923147,
75  0.766130398, 0.433923147, -0.050201753, -0.110036987, 0.032080869,
76  0.042068328, -0.017176331, -0.017982291, 0.008685294, 0.008201477,
77  -0.00435384, -0.003882426, 0.002186714, 0.00188212, -0.001103748,
78  -0.000927187, 0.000559952, 0.000462093, -0.000285414, -0.000232304,
79  0.000146098,
80 };
81 
82 static const double bl3_ihp[42] = {
83  0.000146098, 0.000232304, -0.000285414, -0.000462093, 0.000559952,
84  0.000927187, -0.001103748, -0.00188212, 0.002186714, 0.003882426,
85  -0.00435384, -0.008201477, 0.008685294, 0.017982291, -0.017176331,
86  -0.042068328, 0.032080869, 0.110036987, -0.050201753, -0.433923147,
87  0.766130398, -0.433923147, -0.050201753, 0.110036987, 0.032080869,
88  -0.042068328, -0.017176331, 0.017982291, 0.008685294, -0.008201477,
89  -0.00435384, 0.003882426, 0.002186714, -0.00188212, -0.001103748,
90  0.000927187, 0.000559952, -0.000462093, -0.000285414, 0.000232304,
91  0.000146098,
92 };
93 
94 static const double sym10_lp[20] = {
95  0.0007701598091144901, 9.563267072289475e-05,
96  -0.008641299277022422, -0.0014653825813050513,
97  0.0459272392310922, 0.011609893903711381,
98  -0.15949427888491757, -0.07088053578324385,
99  0.47169066693843925, 0.7695100370211071,
100  0.38382676106708546, -0.03553674047381755,
101  -0.0319900568824278, 0.04999497207737669,
102  0.005764912033581909, -0.02035493981231129,
103  -0.0008043589320165449, 0.004593173585311828,
104  5.7036083618494284e-05, -0.0004593294210046588,
105 };
106 
107 static const double sym10_hp[20] = {
108  0.0004593294210046588, 5.7036083618494284e-05,
109  -0.004593173585311828, -0.0008043589320165449,
110  0.02035493981231129, 0.005764912033581909,
111  -0.04999497207737669, -0.0319900568824278,
112  0.03553674047381755, 0.38382676106708546,
113  -0.7695100370211071, 0.47169066693843925,
114  0.07088053578324385, -0.15949427888491757,
115  -0.011609893903711381, 0.0459272392310922,
116  0.0014653825813050513, -0.008641299277022422,
117  -9.563267072289475e-05, 0.0007701598091144901,
118 };
119 
120 static const double sym10_ilp[20] = {
121  -0.0004593294210046588, 5.7036083618494284e-05,
122  0.004593173585311828, -0.0008043589320165449,
123  -0.02035493981231129, 0.005764912033581909,
124  0.04999497207737669, -0.0319900568824278,
125  -0.03553674047381755, 0.38382676106708546,
126  0.7695100370211071, 0.47169066693843925,
127  -0.07088053578324385, -0.15949427888491757,
128  0.011609893903711381, 0.0459272392310922,
129  -0.0014653825813050513, -0.008641299277022422,
130  9.563267072289475e-05, 0.0007701598091144901,
131 };
132 
133 static const double sym10_ihp[20] = {
134  0.0007701598091144901, -9.563267072289475e-05,
135  -0.008641299277022422, 0.0014653825813050513,
136  0.0459272392310922, -0.011609893903711381,
137  -0.15949427888491757, 0.07088053578324385,
138  0.47169066693843925, -0.7695100370211071,
139  0.38382676106708546, 0.03553674047381755,
140  -0.0319900568824278, -0.04999497207737669,
141  0.005764912033581909, 0.02035493981231129,
142  -0.0008043589320165449, -0.004593173585311828,
143  5.7036083618494284e-05, 0.0004593294210046588,
144 };
145 
146 static const double rbior68_lp[18] = {
147  0.0, 0.0, 0.0, 0.0,
148  0.014426282505624435, 0.014467504896790148,
149  -0.07872200106262882, -0.04036797903033992,
150  0.41784910915027457, 0.7589077294536541,
151  0.41784910915027457, -0.04036797903033992,
152  -0.07872200106262882, 0.014467504896790148,
153  0.014426282505624435, 0.0, 0.0, 0.0,
154 };
155 
156 static const double rbior68_hp[18] = {
157  -0.0019088317364812906, -0.0019142861290887667,
158  0.016990639867602342, 0.01193456527972926,
159  -0.04973290349094079, -0.07726317316720414,
160  0.09405920349573646, 0.4207962846098268,
161  -0.8259229974584023, 0.4207962846098268,
162  0.09405920349573646, -0.07726317316720414,
163  -0.04973290349094079, 0.01193456527972926,
164  0.016990639867602342, -0.0019142861290887667,
165  -0.0019088317364812906, 0.0,
166 };
167 
168 static const double rbior68_ilp[18] = {
169  0.0019088317364812906, -0.0019142861290887667,
170  -0.016990639867602342, 0.01193456527972926,
171  0.04973290349094079, -0.07726317316720414,
172  -0.09405920349573646, 0.4207962846098268,
173  0.8259229974584023, 0.4207962846098268,
174  -0.09405920349573646, -0.07726317316720414,
175  0.04973290349094079, 0.01193456527972926,
176  -0.016990639867602342, -0.0019142861290887667,
177  0.0019088317364812906, 0.0,
178 };
179 
180 static const double rbior68_ihp[18] = {
181  0.0, 0.0, 0.0, 0.0,
182  0.014426282505624435, -0.014467504896790148,
183  -0.07872200106262882, 0.04036797903033992,
184  0.41784910915027457, -0.7589077294536541,
185  0.41784910915027457, 0.04036797903033992,
186  -0.07872200106262882, -0.014467504896790148,
187  0.014426282505624435, 0.0, 0.0, 0.0,
188 };
189 
190 static const double coif5_lp[30] = {
191  -9.517657273819165e-08, -1.6744288576823017e-07,
192  2.0637618513646814e-06, 3.7346551751414047e-06,
193  -2.1315026809955787e-05, -4.134043227251251e-05,
194  0.00014054114970203437, 0.00030225958181306315,
195  -0.0006381313430451114, -0.0016628637020130838,
196  0.0024333732126576722, 0.006764185448053083,
197  -0.009164231162481846, -0.01976177894257264,
198  0.03268357426711183, 0.0412892087501817,
199  -0.10557420870333893, -0.06203596396290357,
200  0.4379916261718371, 0.7742896036529562,
201  0.4215662066908515, -0.05204316317624377,
202  -0.09192001055969624, 0.02816802897093635,
203  0.023408156785839195, -0.010131117519849788,
204  -0.004159358781386048, 0.0021782363581090178,
205  0.00035858968789573785, -0.00021208083980379827,
206 };
207 
208 static const double coif5_hp[30] = {
209  0.00021208083980379827, 0.00035858968789573785,
210  -0.0021782363581090178, -0.004159358781386048,
211  0.010131117519849788, 0.023408156785839195,
212  -0.02816802897093635, -0.09192001055969624,
213  0.05204316317624377, 0.4215662066908515,
214  -0.7742896036529562, 0.4379916261718371,
215  0.06203596396290357, -0.10557420870333893,
216  -0.0412892087501817, 0.03268357426711183,
217  0.01976177894257264, -0.009164231162481846,
218  -0.006764185448053083, 0.0024333732126576722,
219  0.0016628637020130838, -0.0006381313430451114,
220  -0.00030225958181306315, 0.00014054114970203437,
221  4.134043227251251e-05, -2.1315026809955787e-05,
222  -3.7346551751414047e-06, 2.0637618513646814e-06,
223  1.6744288576823017e-07, -9.517657273819165e-08,
224 };
225 
226 static const double coif5_ilp[30] = {
227  -0.00021208083980379827, 0.00035858968789573785,
228  0.0021782363581090178, -0.004159358781386048,
229  -0.010131117519849788, 0.023408156785839195,
230  0.02816802897093635, -0.09192001055969624,
231  -0.05204316317624377, 0.4215662066908515,
232  0.7742896036529562, 0.4379916261718371,
233  -0.06203596396290357, -0.10557420870333893,
234  0.0412892087501817, 0.03268357426711183,
235  -0.01976177894257264, -0.009164231162481846,
236  0.006764185448053083, 0.0024333732126576722,
237  -0.0016628637020130838, -0.0006381313430451114,
238  0.00030225958181306315, 0.00014054114970203437,
239  -4.134043227251251e-05, -2.1315026809955787e-05,
240  3.7346551751414047e-06, 2.0637618513646814e-06,
241  -1.6744288576823017e-07, -9.517657273819165e-08,
242 };
243 
244 static const double coif5_ihp[30] = {
245  -9.517657273819165e-08, 1.6744288576823017e-07,
246  2.0637618513646814e-06, -3.7346551751414047e-06,
247  -2.1315026809955787e-05, 4.134043227251251e-05,
248  0.00014054114970203437, -0.00030225958181306315,
249  -0.0006381313430451114, 0.0016628637020130838,
250  0.0024333732126576722, -0.006764185448053083,
251  -0.009164231162481846, 0.01976177894257264,
252  0.03268357426711183, -0.0412892087501817,
253  -0.10557420870333893, 0.06203596396290357,
254  0.4379916261718371, -0.7742896036529562,
255  0.4215662066908515, 0.05204316317624377,
256  -0.09192001055969624, -0.02816802897093635,
257  0.023408156785839195, 0.010131117519849788,
258  -0.004159358781386048, -0.0021782363581090178,
259  0.00035858968789573785, 0.00021208083980379827,
260 };
261 
262 static const double deb10_lp[20] = {
263  -1.326420300235487e-05, 9.358867000108985e-05,
264  -0.0001164668549943862, -0.0006858566950046825,
265  0.00199240529499085, 0.0013953517469940798,
266  -0.010733175482979604, 0.0036065535669883944,
267  0.03321267405893324, -0.02945753682194567,
268  -0.07139414716586077, 0.09305736460380659,
269  0.12736934033574265, -0.19594627437659665,
270  -0.24984642432648865, 0.2811723436604265,
271  0.6884590394525921, 0.5272011889309198,
272  0.18817680007762133, 0.026670057900950818,
273 };
274 
275 static const double deb10_hp[20] = {
276  -0.026670057900950818, 0.18817680007762133,
277  -0.5272011889309198, 0.6884590394525921,
278  -0.2811723436604265, -0.24984642432648865,
279  0.19594627437659665, 0.12736934033574265,
280  -0.09305736460380659, -0.07139414716586077,
281  0.02945753682194567, 0.03321267405893324,
282  -0.0036065535669883944, -0.010733175482979604,
283  -0.0013953517469940798, 0.00199240529499085,
284  0.0006858566950046825, -0.0001164668549943862,
285  -9.358867000108985e-05, -1.326420300235487e-05,
286 };
287 
288 static const double deb10_ilp[20] = {
289  0.026670057900950818, 0.18817680007762133,
290  0.5272011889309198, 0.6884590394525921,
291  0.2811723436604265, -0.24984642432648865,
292  -0.19594627437659665, 0.12736934033574265,
293  0.09305736460380659, -0.07139414716586077,
294  -0.02945753682194567, 0.03321267405893324,
295  0.0036065535669883944, -0.010733175482979604,
296  0.0013953517469940798, 0.00199240529499085,
297  -0.0006858566950046825, -0.0001164668549943862,
298  9.358867000108985e-05, -1.326420300235487e-05,
299 };
300 
301 static const double deb10_ihp[20] = {
302  -1.326420300235487e-05, -9.358867000108985e-05,
303  -0.0001164668549943862, 0.0006858566950046825,
304  0.00199240529499085, -0.0013953517469940798,
305  -0.010733175482979604, -0.0036065535669883944,
306  0.03321267405893324, 0.02945753682194567,
307  -0.07139414716586077, -0.09305736460380659,
308  0.12736934033574265, 0.19594627437659665,
309  -0.24984642432648865, -0.2811723436604265,
310  0.6884590394525921, -0.5272011889309198,
311  0.18817680007762133, -0.026670057900950818,
312 };
313 
314 static const double sym4_lp[8] = {
315  -0.07576571478927333,
316  -0.02963552764599851,
317  0.49761866763201545,
318  0.8037387518059161,
319  0.29785779560527736,
320  -0.09921954357684722,
321  -0.012603967262037833,
322  0.0322231006040427,
323 };
324 
325 static const double sym4_hp[8] = {
326  -0.0322231006040427,
327  -0.012603967262037833,
328  0.09921954357684722,
329  0.29785779560527736,
330  -0.8037387518059161,
331  0.49761866763201545,
332  0.02963552764599851,
333  -0.07576571478927333,
334 };
335 
336 static const double sym4_ilp[8] = {
337  0.0322231006040427,
338  -0.012603967262037833,
339  -0.09921954357684722,
340  0.29785779560527736,
341  0.8037387518059161,
342  0.49761866763201545,
343  -0.02963552764599851,
344  -0.07576571478927333,
345 };
346 
347 static const double sym4_ihp[8] = {
348  -0.07576571478927333,
349  0.02963552764599851,
350  0.49761866763201545,
351  -0.8037387518059161,
352  0.29785779560527736,
353  0.09921954357684722,
354  -0.012603967262037833,
355  -0.0322231006040427,
356 };
357 
358 static const double sym2_lp[4] = {
359  -0.12940952255092145, 0.22414386804185735,
360  0.836516303737469, 0.48296291314469025,
361 };
362 
363 static const double sym2_hp[4] = {
364  -0.48296291314469025, 0.836516303737469,
365  -0.22414386804185735, -0.12940952255092145,
366 };
367 
368 static const double sym2_ilp[4] = {
369  0.48296291314469025, 0.836516303737469,
370  0.22414386804185735, -0.12940952255092145,
371 };
372 
373 static const double sym2_ihp[4] = {
374  -0.12940952255092145, -0.22414386804185735,
375  0.836516303737469, -0.48296291314469025,
376 };
377 
378 #define MAX_LEVELS 13
379 
380 typedef struct ChannelParams {
383  double **output_coefs;
385  double **filter_coefs;
386 
394 
395  double *tempa;
396  double *tempd;
397  double *temp_in;
398  double *buffer;
399  double *buffer2;
400  double *prev;
401  double *overlap;
402 } ChannelParams;
403 
404 typedef struct AudioFWTDNContext {
405  const AVClass *class;
406 
407  double sigma;
408  double percent;
409  double softness;
410 
411  uint64_t sn;
412  int64_t eof_pts;
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, "wavet" },
447  { "sym2", "sym2", 0, AV_OPT_TYPE_CONST, {.i64=SYM2}, 0, 0, AF, "wavet" },
448  { "sym4", "sym4", 0, AV_OPT_TYPE_CONST, {.i64=SYM4}, 0, 0, AF, "wavet" },
449  { "rbior68", "rbior68", 0, AV_OPT_TYPE_CONST, {.i64=RBIOR68}, 0, 0, AF, "wavet" },
450  { "deb10", "deb10", 0, AV_OPT_TYPE_CONST, {.i64=DEB10}, 0, 0, AF, "wavet" },
451  { "sym10", "sym10", 0, AV_OPT_TYPE_CONST, {.i64=SYM10}, 0, 0, AF, "wavet" },
452  { "coif5", "coif5", 0, AV_OPT_TYPE_CONST, {.i64=COIF5}, 0, 0, AF, "wavet" },
453  { "bl3", "bl3", 0, AV_OPT_TYPE_CONST, {.i64=BL3}, 0, 0, AF, "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 
465 {
466  static const enum AVSampleFormat sample_fmts[] = {
469  };
471  if (ret < 0)
472  return ret;
473 
475  if (ret < 0)
476  return ret;
477 
479 }
480 
481 #define pow2(x) (1U << (x))
482 #define mod_pow2(x, power_of_two) ((x) & ((power_of_two) - 1))
483 
484 static void conv_down(double *in, int in_length, double *low, double *high,
485  int out_length, const double *lp, const double *hp,
486  int wavelet_length, int skip,
487  double *buffer, int buffer_length)
488 {
489  double thigh = 0.0, tlow = 0.0;
490  int buff_idx = 1 + skip;
491 
492  memcpy(buffer, in, buff_idx * sizeof(*buffer));
493  memset(buffer + buff_idx, 0, (buffer_length - buff_idx) * sizeof(*buffer));
494 
495  for (int i = 0; i < out_length - 1; i++) {
496  double thigh = 0.0, tlow = 0.0;
497 
498  for (int j = 0; j < wavelet_length; j++) {
499  const int idx = mod_pow2(-j + buff_idx - 1, buffer_length);
500  const double btemp = buffer[idx];
501 
502  thigh += btemp * hp[j];
503  tlow += btemp * lp[j];
504  }
505 
506  high[i] = thigh;
507  low[i] = tlow;
508  buffer[buff_idx++] = in[2 * i + 1 + skip];
509  buffer[buff_idx++] = in[2 * i + 2 + skip];
510  buff_idx = mod_pow2(buff_idx, buffer_length);
511  }
512 
513  for (int i = 0; i < wavelet_length; i++) {
514  const int idx = mod_pow2(-i + buff_idx - 1, buffer_length);
515  const double btemp = buffer[idx];
516 
517  thigh += btemp * hp[i];
518  tlow += btemp * lp[i];
519  }
520 
521  high[out_length - 1] = thigh;
522  low[out_length - 1] = tlow;
523 }
524 
525 static int left_ext(int wavelet_length, int levels, uint64_t sn)
526 {
527  if (!sn)
528  return 0;
529  return (pow2(levels) - 1) * (wavelet_length - 2) + mod_pow2(sn, pow2(levels));
530 }
531 
532 static int nb_coefs(int length, int level, uint64_t sn)
533 {
534  const int pow2_level = pow2(level);
535 
536  return (sn + length) / pow2_level - sn / pow2_level;
537 }
538 
539 static int reallocate_inputs(double **out, int *out_length,
540  int in_length, int levels, int ch, uint64_t sn)
541 {
542  const int temp_length = nb_coefs(in_length, levels, sn);
543 
544  for (int level = 0; level < levels; level++) {
545  const int temp_length = nb_coefs(in_length, level + 1, sn);
546 
547  if (temp_length > out_length[level]) {
548  av_freep(&out[level]);
549  out_length[level] = 0;
550 
551  out[level] = av_calloc(temp_length + 1, sizeof(**out));
552  if (!out[level])
553  return AVERROR(ENOMEM);
554  out_length[level] = temp_length + 1;
555  }
556 
557  memset(out[level] + temp_length, 0,
558  (out_length[level] - temp_length) * sizeof(**out));
559  out_length[level] = temp_length;
560  }
561 
562  if (temp_length > out_length[levels]) {
563  av_freep(&out[levels]);
564  out_length[levels] = 0;
565 
566  out[levels] = av_calloc(temp_length + 1, sizeof(**out));
567  if (!out[levels])
568  return AVERROR(ENOMEM);
569  out_length[levels] = temp_length + 1;
570  }
571 
572  memset(out[levels] + temp_length, 0,
573  (out_length[levels] - temp_length) * sizeof(**out));
574  out_length[levels] = temp_length;
575 
576  return 0;
577 }
578 
579 static int max_left_zeros_inverse(int levels, int level, int wavelet_length)
580 {
581  return (pow2(levels - level) - 1) * (wavelet_length - 1);
582 }
583 
585  double **out, int *out_length,
586  int in_length, int levels, int ch, uint64_t sn)
587 {
588  ChannelParams *cp = &s->cp[ch];
589  int temp_length = 0;
590  int add = 0;
591 
592  for (int level = 0; level < levels; level++) {
593  temp_length = nb_coefs(in_length, level + 1, sn);
594  if (temp_length > out_length[level]) {
596  out_length[level] = 0;
597 
598  add = max_left_zeros_inverse(levels, level + 1, s->wavelet_length);
599  cp->subbands_to_free[level] = av_calloc(add + temp_length + 1, sizeof(**out));
600  if (!cp->subbands_to_free[level])
601  return AVERROR(ENOMEM);
602  out_length[level] = add + temp_length + 1;
603  out[level] = cp->subbands_to_free[level] + add;
604  }
605 
606  memset(out[level] + temp_length, 0,
607  FFMAX(out_length[level] - temp_length - add, 0) * sizeof(**out));
608  out_length[level] = temp_length;
609  }
610 
611  temp_length = nb_coefs(in_length, levels, sn);
612  if (temp_length > out_length[levels]) {
613  av_freep(&cp->subbands_to_free[levels]);
614  out_length[levels] = 0;
615 
616  cp->subbands_to_free[levels] = av_calloc(temp_length + 1, sizeof(**out));
617  if (!cp->subbands_to_free[levels])
618  return AVERROR(ENOMEM);
619  out_length[levels] = temp_length + 1;
620  out[levels] = cp->subbands_to_free[levels];
621  }
622 
623  memset(out[levels] + temp_length, 0,
624  (out_length[levels] - temp_length) * sizeof(**out));
625  out_length[levels] = temp_length;
626 
627  return 0;
628 }
629 
630 static int discard_left_ext(int wavelet_length, int levels, int level, uint64_t sn)
631 {
632  if (levels == level || sn == 0)
633  return 0;
634  return (pow2(levels - level) - 1) * (wavelet_length - 2) + mod_pow2(sn, pow2(levels)) / pow2(level);
635 }
636 
638  const double *in, int in_length,
639  double **out, int *out_length, int ch, uint64_t sn)
640 {
641  ChannelParams *cp = &s->cp[ch];
642  int levels = s->levels;
643  int skip = sn ? s->wavelet_length - 1 : 1;
644  int leftext, ret;
645 
646  ret = reallocate_inputs(out, out_length, in_length, levels, ch, sn);
647  if (ret < 0)
648  return ret;
650  in_length, levels, ch, sn);
651  if (ret < 0)
652  return ret;
653 
654  leftext = left_ext(s->wavelet_length, levels, sn);
655 
656  if (cp->temp_in_max_length < in_length + cp->max_left_ext + skip) {
657  av_freep(&cp->temp_in);
658  cp->temp_in_max_length = in_length + cp->max_left_ext + skip;
659  cp->temp_in = av_calloc(cp->temp_in_max_length, sizeof(*cp->temp_in));
660  if (!cp->temp_in) {
661  cp->temp_in_max_length = 0;
662  return AVERROR(ENOMEM);
663  }
664  }
665 
666  memset(cp->temp_in, 0, cp->temp_in_max_length * sizeof(*cp->temp_in));
667  cp->temp_in_length = in_length + leftext;
668 
669  if (leftext)
670  memcpy(cp->temp_in, cp->prev + s->prev_length - leftext, leftext * sizeof(*cp->temp_in));
671  memcpy(cp->temp_in + leftext, in, in_length * sizeof(*in));
672 
673  if (levels == 1) {
674  conv_down(cp->temp_in, cp->temp_in_length, out[1], out[0], out_length[1],
675  s->lp, s->hp, s->wavelet_length, skip,
676  cp->buffer, cp->buffer_length);
677  } else {
678  int discard = discard_left_ext(s->wavelet_length, levels, 1, sn);
679  int tempa_length_prev;
680 
681  if (cp->tempa_len_max < (in_length + cp->max_left_ext + s->wavelet_length - 1) / 2) {
682  av_freep(&cp->tempa);
683  av_freep(&cp->tempd);
684  cp->tempa_len_max = (in_length + cp->max_left_ext + s->wavelet_length - 1) / 2;
685  cp->tempa = av_calloc(cp->tempa_len_max, sizeof(*cp->tempa));
686  cp->tempd = av_calloc(cp->tempa_len_max, sizeof(*cp->tempd));
687  if (!cp->tempa || !cp->tempd) {
688  cp->tempa_len_max = 0;
689  return AVERROR(ENOMEM);
690  }
691  }
692 
693  memset(cp->tempa, 0, cp->tempa_len_max * sizeof(*cp->tempa));
694  memset(cp->tempd, 0, cp->tempa_len_max * sizeof(*cp->tempd));
695 
696  cp->tempa_length = out_length[0] + discard;
698  cp->tempa, cp->tempd, cp->tempa_length,
699  s->lp, s->hp, s->wavelet_length, skip,
700  cp->buffer, cp->buffer_length);
701  memcpy(out[0], cp->tempd + discard, out_length[0] * sizeof(**out));
702  tempa_length_prev = cp->tempa_length;
703 
704  for (int level = 1; level < levels - 1; level++) {
705  if (out_length[level] == 0)
706  return 0;
707  discard = discard_left_ext(s->wavelet_length, levels, level + 1, sn);
708  cp->tempa_length = out_length[level] + discard;
709  conv_down(cp->tempa, tempa_length_prev,
710  cp->tempa, cp->tempd, cp->tempa_length,
711  s->lp, s->hp, s->wavelet_length, skip,
712  cp->buffer, cp->buffer_length);
713  memcpy(out[level], cp->tempd + discard, out_length[level] * sizeof(**out));
714  tempa_length_prev = cp->tempa_length;
715  }
716 
717  if (out_length[levels] == 0)
718  return 0;
719  conv_down(cp->tempa, cp->tempa_length, out[levels], out[levels - 1], out_length[levels],
720  s->lp, s->hp, s->wavelet_length, skip,
721  cp->buffer, cp->buffer_length);
722  }
723 
724  if (s->prev_length < in_length) {
725  memcpy(cp->prev, in + in_length - cp->max_left_ext, cp->max_left_ext * sizeof(*cp->prev));
726  } else {
727  memmove(cp->prev, cp->prev + in_length, (s->prev_length - in_length) * sizeof(*cp->prev));
728  memcpy(cp->prev + s->prev_length - in_length, in, in_length * sizeof(*cp->prev));
729  }
730 
731  return 0;
732 }
733 
734 static void conv_up(double *low, double *high, int in_length, double *out, int out_length,
735  const double *lp, const double *hp, int filter_length,
736  double *buffer, double *buffer2, int buffer_length)
737 {
738  int shift = 0, buff_idx = 0, in_idx = 0;
739 
740  memset(buffer, 0, buffer_length * sizeof(*buffer));
741  memset(buffer2, 0, buffer_length * sizeof(*buffer2));
742 
743  for (int i = 0; i < out_length; i++) {
744  double sum = 0.0;
745 
746  if ((i & 1) == 0) {
747  if (in_idx < in_length) {
748  buffer[buff_idx] = low[in_idx];
749  buffer2[buff_idx] = high[in_idx++];
750  } else {
751  buffer[buff_idx] = 0;
752  buffer2[buff_idx] = 0;
753  }
754  buff_idx++;
755  if (buff_idx >= buffer_length)
756  buff_idx = 0;
757  shift = 0;
758  }
759 
760  for (int j = 0; j < (filter_length - shift + 1) / 2; j++) {
761  const int idx = mod_pow2(-j + buff_idx - 1, buffer_length);
762 
763  sum += buffer[idx] * lp[j * 2 + shift] + buffer2[idx] * hp[j * 2 + shift];
764  }
765  out[i] = sum;
766  shift = 1;
767  }
768 }
769 
770 static int append_left_ext(int wavelet_length, int levels, int level, uint64_t sn)
771 {
772  if (levels == level)
773  return 0;
774 
775  return (pow2(levels - level) - 1) * (wavelet_length - 2) +
776  mod_pow2(sn, pow2(levels)) / pow2(level);
777 }
778 
780  double **in, int *in_length,
781  double *out, int out_length, int ch, uint64_t sn)
782 {
783  ChannelParams *cp = &s->cp[ch];
784  const int levels = s->levels;
785  int leftext = left_ext(s->wavelet_length, levels, sn);
786  int temp_skip = 0;
787 
788  if (sn == 0)
789  temp_skip = cp->min_left_ext;
790 
791  memset(out, 0, out_length * sizeof(*out));
792 
793  if (cp->temp_in_max_length < out_length + cp->max_left_ext + s->wavelet_length - 1) {
794  av_freep(&cp->temp_in);
795  cp->temp_in_max_length = out_length + cp->max_left_ext + s->wavelet_length - 1;
796  cp->temp_in = av_calloc(cp->temp_in_max_length, sizeof(*cp->temp_in));
797  if (!cp->temp_in) {
798  cp->temp_in_max_length = 0;
799  return AVERROR(ENOMEM);
800  }
801  }
802 
803  memset(cp->temp_in, 0, cp->temp_in_max_length * sizeof(*cp->temp_in));
804  cp->temp_in_length = out_length + cp->max_left_ext;
805 
806  if (levels == 1) {
807  conv_up(in[1], in[0], in_length[1], cp->temp_in, cp->temp_in_length,
808  s->ilp, s->ihp, s->wavelet_length,
809  cp->buffer, cp->buffer2, cp->buffer_length);
810  memcpy(out + cp->max_left_ext - leftext, cp->temp_in + temp_skip,
811  FFMAX(0, out_length - (cp->max_left_ext - leftext)) * sizeof(*out));
812  } else {
813  double *hp1, *hp2;
814  int add, add2;
815 
816  if (cp->tempa_len_max < (out_length + cp->max_left_ext + s->wavelet_length - 1) / 2) {
817  av_freep(&cp->tempa);
818  cp->tempa_len_max = (out_length + cp->max_left_ext + s->wavelet_length - 1) / 2;
819  cp->tempa = av_calloc(cp->tempa_len_max, sizeof(*cp->tempa));
820  if (!cp->tempa) {
821  cp->tempa_len_max = 0;
822  return AVERROR(ENOMEM);
823  }
824  }
825 
826  memset(cp->tempa, 0, cp->tempa_len_max * sizeof(*cp->tempa));
827 
828  hp1 = levels & 1 ? cp->temp_in : cp->tempa;
829  hp2 = levels & 1 ? cp->tempa : cp->temp_in;
830 
831  add = append_left_ext(s->wavelet_length, levels, levels - 1, sn);
832  conv_up(in[levels], in[levels - 1], in_length[levels], hp1, in_length[levels - 2] + add,
833  s->ilp, s->ihp, s->wavelet_length, cp->buffer, cp->buffer2, cp->buffer_length);
834 
835  for (int level = levels - 1; level > 1; level--) {
836  add2 = append_left_ext(s->wavelet_length, levels, level - 1, sn);
837  add = append_left_ext(s->wavelet_length, levels, level, sn);
838  conv_up(hp1, in[level - 1] - add, in_length[level - 1] + add,
839  hp2, in_length[level - 2] + add2,
840  s->ilp, s->ihp, s->wavelet_length,
841  cp->buffer, cp->buffer2, cp->buffer_length);
842  FFSWAP(double *, hp1, hp2);
843  }
844 
845  add = append_left_ext(s->wavelet_length, levels, 1, sn);
846  conv_up(hp1, in[0] - add, in_length[0] + add, cp->temp_in, cp->temp_in_length,
847  s->ilp, s->ihp, s->wavelet_length,
848  cp->buffer, cp->buffer2, cp->buffer_length);
849  }
850 
851  memset(cp->temp_in, 0, temp_skip * sizeof(*cp->temp_in));
852  if (s->overlap_length <= out_length) {
853  memcpy(out + cp->max_left_ext - leftext, cp->temp_in + temp_skip,
854  FFMAX(0, out_length - (cp->max_left_ext - leftext)) * sizeof(*out));
855  for (int i = 0;i < FFMIN(s->overlap_length, out_length); i++)
856  out[i] += cp->overlap[i];
857 
858  memcpy(cp->overlap, cp->temp_in + out_length - (cp->max_left_ext - leftext),
859  s->overlap_length * sizeof(*cp->overlap));
860  } else {
861  for (int i = 0;i < s->overlap_length - (cp->max_left_ext - leftext); i++)
862  cp->overlap[i + cp->max_left_ext - leftext] += cp->temp_in[i];
863  memcpy(out, cp->overlap, out_length * sizeof(*out));
864  memmove(cp->overlap, cp->overlap + out_length,
865  (s->overlap_length - out_length) * sizeof(*cp->overlap));
866  memcpy(cp->overlap + s->overlap_length - out_length, cp->temp_in + leftext,
867  out_length * sizeof(*cp->overlap));
868  }
869 
870  return 0;
871 }
872 
873 static int next_pow2(int in)
874 {
875  return 1 << (av_log2(in) + 1);
876 }
877 
878 static void denoise_level(double *out, const double *in,
879  const double *filter,
880  double percent, int length)
881 {
882  const double x = percent * 0.01;
883  const double y = 1.0 - x;
884 
885  for (int i = 0; i < length; i++)
886  out[i] = x * filter[i] + in[i] * y;
887 }
888 
889 static double sqr(double in)
890 {
891  return in * in;
892 }
893 
894 static double measure_mean(const double *in, int length)
895 {
896  double sum = 0.0;
897 
898  for (int i = 0; i < length; i++)
899  sum += in[i];
900 
901  return sum / length;
902 }
903 
904 static double measure_absmean(const double *in, int length)
905 {
906  double sum = 0.0;
907 
908  for (int i = 0; i < length; i++)
909  sum += fabs(in[i]);
910 
911  return sum / length;
912 }
913 
914 static double measure_stddev(const double *in, int length, double mean)
915 {
916  double sum = 0.;
917 
918  for (int i = 0; i < length; i++) {
919  sum += sqr(in[i] - mean);
920  }
921 
922  return sqrt(sum / length);
923 }
924 
925 static void noise_filter(const double stddev, const double *in,
926  double *out, double absmean, double softness,
927  double new_stddev, int length)
928 {
929  for (int i = 0; i < length; i++) {
930  if (new_stddev <= stddev)
931  out[i] = 0.0;
932  else if (fabs(in[i]) <= absmean)
933  out[i] = 0.0;
934  else
935  out[i] = in[i] - FFSIGN(in[i]) * absmean / exp(3.0 * softness * (fabs(in[i]) - absmean) / absmean);
936  }
937 }
938 
939 typedef struct ThreadData {
940  AVFrame *in, *out;
941 } ThreadData;
942 
943 static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
944 {
945  AudioFWTDNContext *s = ctx->priv;
946  ThreadData *td = arg;
947  AVFrame *in = td->in;
948  AVFrame *out = td->out;
949  ChannelParams *cp = &s->cp[ch];
950  const double *src = (const double *)(in->extended_data[ch]);
951  double *dst = (double *)out->extended_data[ch];
952  double *absmean = (double *)s->absmean->extended_data[ch];
953  double *new_absmean = (double *)s->new_absmean->extended_data[ch];
954  double *stddev = (double *)s->stddev->extended_data[ch];
955  double *new_stddev = (double *)s->new_stddev->extended_data[ch];
956  double *filter = (double *)s->filter->extended_data[ch];
957  double is_noise = 0.0;
958  int ret;
959 
960  ret = forward(s, src, in->nb_samples, cp->output_coefs, cp->output_length, ch, s->sn);
961  if (ret < 0)
962  return ret;
963 
964  if (!s->got_profile && s->need_profile) {
965  for (int level = 0; level <= s->levels; level++) {
966  const int length = cp->output_length[level];
967  const double scale = sqrt(2.0 * log(length));
968 
969  stddev[level] = measure_stddev(cp->output_coefs[level], length,
970  measure_mean(cp->output_coefs[level], length)) * scale;
971  absmean[level] = measure_absmean(cp->output_coefs[level], length) * scale;
972  }
973  } else if (!s->got_profile && !s->need_profile && !s->adaptive) {
974  for (int level = 0; level <= s->levels; level++) {
975  const int length = cp->output_length[level];
976  const double scale = sqrt(2.0 * log(length));
977 
978  stddev[level] = 0.5 * s->sigma * scale;
979  absmean[level] = 0.5 * s->sigma * scale;
980  }
981  }
982 
983  for (int level = 0; level <= s->levels; level++) {
984  const int length = cp->output_length[level];
985  double vad;
986 
987  new_stddev[level] = measure_stddev(cp->output_coefs[level], length,
988  measure_mean(cp->output_coefs[level], length));
989  new_absmean[level] = measure_absmean(cp->output_coefs[level], length);
990  if (new_absmean[level] <= FLT_EPSILON)
991  vad = 1.0;
992  else
993  vad = new_stddev[level] / new_absmean[level];
994  if (level < s->levels)
995  is_noise += sqr(vad - 1.232);
996  }
997 
998  is_noise *= in->sample_rate;
999  is_noise /= s->nb_samples;
1000  for (int level = 0; level <= s->levels; level++) {
1001  const int length = cp->output_length[level];
1002  const double scale = sqrt(2.0 * log(length));
1003 
1004  if (is_noise < 0.05 && s->adaptive) {
1005  stddev[level] = new_stddev[level] * scale;
1006  absmean[level] = new_absmean[level] * scale;
1007  }
1008 
1009  noise_filter(stddev[level], cp->output_coefs[level], filter, absmean[level],
1010  s->softness, new_stddev[level], length);
1011  denoise_level(cp->filter_coefs[level], cp->output_coefs[level], filter, s->percent, length);
1012  }
1013 
1014  ret = inverse(s, cp->filter_coefs, cp->filter_length, dst, out->nb_samples, ch, s->sn);
1015  if (ret < 0)
1016  return ret;
1017 
1018  return 0;
1019 }
1020 
1022 {
1023  AVFilterContext *ctx = inlink->dst;
1024  AudioFWTDNContext *s = ctx->priv;
1025  AVFilterLink *outlink = ctx->outputs[0];
1026  ThreadData td;
1027  AVFrame *out;
1028  int eof = in == NULL;
1029 
1030  out = ff_get_audio_buffer(outlink, s->nb_samples);
1031  if (!out) {
1032  av_frame_free(&in);
1033  return AVERROR(ENOMEM);
1034  }
1035  if (in) {
1036  av_frame_copy_props(out, in);
1037  s->eof_pts = in->pts + in->nb_samples;
1038  }
1039  if (eof)
1040  out->pts = s->eof_pts - s->padd_samples;
1041 
1042  if (!in || in->nb_samples < s->nb_samples) {
1043  AVFrame *new_in = ff_get_audio_buffer(outlink, s->nb_samples);
1044 
1045  if (!new_in) {
1046  av_frame_free(&in);
1047  av_frame_free(&out);
1048  return AVERROR(ENOMEM);
1049  }
1050  if (in)
1051  av_frame_copy_props(new_in, in);
1052 
1053  s->padd_samples -= s->nb_samples - (in ? in->nb_samples: 0);
1054  if (in)
1055  av_samples_copy(new_in->extended_data, in->extended_data, 0, 0,
1056  in->nb_samples, in->channels, in->format);
1057  av_frame_free(&in);
1058  in = new_in;
1059  }
1060 
1061  td.in = in;
1062  td.out = out;
1063  ff_filter_execute(ctx, s->filter_channel, &td, NULL, inlink->channels);
1064  if (s->need_profile)
1065  s->got_profile = 1;
1066 
1067  s->sn += s->nb_samples;
1068 
1069  if (s->drop_samples >= in->nb_samples) {
1070  s->drop_samples -= in->nb_samples;
1071  s->delay += in->nb_samples;
1072  av_frame_free(&in);
1073  av_frame_free(&out);
1074  FF_FILTER_FORWARD_STATUS(inlink, outlink);
1075  FF_FILTER_FORWARD_WANTED(outlink, inlink);
1076  return 0;
1077  } else if (s->drop_samples > 0) {
1078  for (int ch = 0; ch < out->channels; ch++) {
1079  memmove(out->extended_data[ch],
1080  out->extended_data[ch] + s->drop_samples * sizeof(double),
1081  (in->nb_samples - s->drop_samples) * sizeof(double));
1082  }
1083 
1084  out->nb_samples = in->nb_samples - s->drop_samples;
1085  out->pts = in->pts - av_rescale_q(s->delay, (AVRational){1, outlink->sample_rate}, outlink->time_base);
1086  s->delay += s->drop_samples;
1087  s->drop_samples = 0;
1088  } else {
1089  if (s->padd_samples < 0 && eof) {
1090  out->nb_samples += s->padd_samples;
1091  s->padd_samples = 0;
1092  }
1093  if (!eof)
1094  out->pts = in->pts - av_rescale_q(s->delay, (AVRational){1, outlink->sample_rate}, outlink->time_base);
1095  }
1096 
1097  av_frame_free(&in);
1098  return ff_filter_frame(outlink, out);
1099 }
1100 
1101 static int max_left_ext(int wavelet_length, int levels)
1102 {
1103  return (pow2(levels) - 1) * (wavelet_length - 1);
1104 }
1105 
1106 static int min_left_ext(int wavelet_length, int levels)
1107 {
1108  return (pow2(levels) - 1) * (wavelet_length - 2);
1109 }
1110 
1111 static int config_output(AVFilterLink *outlink)
1112 {
1113  AVFilterContext *ctx = outlink->src;
1114  AudioFWTDNContext *s = ctx->priv;
1115 
1116  switch (s->wavelet_type) {
1117  case SYM2:
1118  s->wavelet_length = 4;
1119  s->lp = sym2_lp;
1120  s->hp = sym2_hp;
1121  s->ilp = sym2_ilp;
1122  s->ihp = sym2_ihp;
1123  break;
1124  case SYM4:
1125  s->wavelet_length = 8;
1126  s->lp = sym4_lp;
1127  s->hp = sym4_hp;
1128  s->ilp = sym4_ilp;
1129  s->ihp = sym4_ihp;
1130  break;
1131  case RBIOR68:
1132  s->wavelet_length = 18;
1133  s->lp = rbior68_lp;
1134  s->hp = rbior68_hp;
1135  s->ilp = rbior68_ilp;
1136  s->ihp = rbior68_ihp;
1137  break;
1138  case DEB10:
1139  s->wavelet_length = 20;
1140  s->lp = deb10_lp;
1141  s->hp = deb10_hp;
1142  s->ilp = deb10_ilp;
1143  s->ihp = deb10_ihp;
1144  break;
1145  case SYM10:
1146  s->wavelet_length = 20;
1147  s->lp = sym10_lp;
1148  s->hp = sym10_hp;
1149  s->ilp = sym10_ilp;
1150  s->ihp = sym10_ihp;
1151  break;
1152  case COIF5:
1153  s->wavelet_length = 30;
1154  s->lp = coif5_lp;
1155  s->hp = coif5_hp;
1156  s->ilp = coif5_ilp;
1157  s->ihp = coif5_ihp;
1158  break;
1159  case BL3:
1160  s->wavelet_length = 42;
1161  s->lp = bl3_lp;
1162  s->hp = bl3_hp;
1163  s->ilp = bl3_ilp;
1164  s->ihp = bl3_ihp;
1165  break;
1166  default:
1167  av_assert0(0);
1168  }
1169 
1170  s->levels = FFMIN(s->levels, lrint(log(s->nb_samples / (s->wavelet_length - 1.0)) / M_LN2));
1171  av_log(ctx, AV_LOG_VERBOSE, "levels: %d\n", s->levels);
1172  s->filter_channel = filter_channel;
1173 
1174  s->stddev = ff_get_audio_buffer(outlink, MAX_LEVELS);
1175  s->new_stddev = ff_get_audio_buffer(outlink, MAX_LEVELS);
1176  s->filter = ff_get_audio_buffer(outlink, s->nb_samples);
1177  s->absmean = ff_get_audio_buffer(outlink, MAX_LEVELS);
1178  s->new_absmean = ff_get_audio_buffer(outlink, MAX_LEVELS);
1179  if (!s->stddev || !s->absmean || !s->filter ||
1180  !s->new_stddev || !s->new_absmean)
1181  return AVERROR(ENOMEM);
1182 
1183  s->channels = outlink->channels;
1184  s->overlap_length = max_left_ext(s->wavelet_length, s->levels);
1185  s->prev_length = s->overlap_length;
1186  s->drop_samples = s->overlap_length;
1187  s->padd_samples = s->overlap_length;
1188  s->sn = 1;
1189 
1190  s->cp = av_calloc(s->channels, sizeof(*s->cp));
1191  if (!s->cp)
1192  return AVERROR(ENOMEM);
1193 
1194  for (int ch = 0; ch < s->channels; ch++) {
1195  ChannelParams *cp = &s->cp[ch];
1196 
1197  cp->output_coefs = av_calloc(s->levels + 1, sizeof(*cp->output_coefs));
1198  cp->filter_coefs = av_calloc(s->levels + 1, sizeof(*cp->filter_coefs));
1199  cp->output_length = av_calloc(s->levels + 1, sizeof(*cp->output_length));
1200  cp->filter_length = av_calloc(s->levels + 1, sizeof(*cp->filter_length));
1201  cp->buffer_length = next_pow2(s->wavelet_length);
1202  cp->buffer = av_calloc(cp->buffer_length, sizeof(*cp->buffer));
1203  cp->buffer2 = av_calloc(cp->buffer_length, sizeof(*cp->buffer2));
1204  cp->subbands_to_free = av_calloc(s->levels + 1, sizeof(*cp->subbands_to_free));
1205  cp->prev = av_calloc(s->prev_length, sizeof(*cp->prev));
1206  cp->overlap = av_calloc(s->overlap_length, sizeof(*cp->overlap));
1207  cp->max_left_ext = max_left_ext(s->wavelet_length, s->levels);
1208  cp->min_left_ext = min_left_ext(s->wavelet_length, s->levels);
1209  if (!cp->output_coefs || !cp->filter_coefs || !cp->output_length ||
1210  !cp->filter_length || !cp->subbands_to_free || !cp->prev || !cp->overlap ||
1211  !cp->buffer || !cp->buffer2)
1212  return AVERROR(ENOMEM);
1213  }
1214 
1215  return 0;
1216 }
1217 
1219 {
1220  AVFilterLink *inlink = ctx->inputs[0];
1221  AVFilterLink *outlink = ctx->outputs[0];
1222  AudioFWTDNContext *s = ctx->priv;
1223  AVFrame *in = NULL;
1224  int ret, status;
1225  int64_t pts;
1226 
1228 
1229  ret = ff_inlink_consume_samples(inlink, s->nb_samples, s->nb_samples, &in);
1230  if (ret < 0)
1231  return ret;
1232  if (ret > 0)
1233  return filter_frame(inlink, in);
1234 
1236  if (status == AVERROR_EOF) {
1237  while (s->padd_samples != 0) {
1239  if (ret < 0)
1240  return ret;
1241  }
1242  ff_outlink_set_status(outlink, status, pts);
1243  return ret;
1244  }
1245  }
1246  FF_FILTER_FORWARD_WANTED(outlink, inlink);
1247 
1248  return FFERROR_NOT_READY;
1249 }
1250 
1252 {
1253  AudioFWTDNContext *s = ctx->priv;
1254 
1255  av_frame_free(&s->filter);
1256  av_frame_free(&s->new_stddev);
1257  av_frame_free(&s->stddev);
1258  av_frame_free(&s->new_absmean);
1259  av_frame_free(&s->absmean);
1260 
1261  for (int ch = 0; s->cp && ch < s->channels; ch++) {
1262  ChannelParams *cp = &s->cp[ch];
1263 
1264  av_freep(&cp->tempa);
1265  av_freep(&cp->tempd);
1266  av_freep(&cp->temp_in);
1267  av_freep(&cp->buffer);
1268  av_freep(&cp->buffer2);
1269  av_freep(&cp->prev);
1270  av_freep(&cp->overlap);
1271 
1272  av_freep(&cp->output_length);
1273  av_freep(&cp->filter_length);
1274 
1275  if (cp->output_coefs) {
1276  for (int level = 0; level <= s->levels; level++)
1277  av_freep(&cp->output_coefs[level]);
1278  }
1279 
1280  if (cp->subbands_to_free) {
1281  for (int level = 0; level <= s->levels; level++)
1283  }
1284 
1285  av_freep(&cp->subbands_to_free);
1286  av_freep(&cp->output_coefs);
1287  av_freep(&cp->filter_coefs);
1288  }
1289 
1290  av_freep(&s->cp);
1291 }
1292 
1293 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
1294  char *res, int res_len, int flags)
1295 {
1296  AudioFWTDNContext *s = ctx->priv;
1297  int ret;
1298 
1299  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
1300  if (ret < 0)
1301  return ret;
1302 
1303  if (!strcmp(cmd, "profile") && s->need_profile)
1304  s->got_profile = 0;
1305 
1306  return 0;
1307 }
1308 
1309 static const AVFilterPad inputs[] = {
1310  {
1311  .name = "default",
1312  .type = AVMEDIA_TYPE_AUDIO,
1313  },
1314 };
1315 
1316 static const AVFilterPad outputs[] = {
1317  {
1318  .name = "default",
1319  .type = AVMEDIA_TYPE_AUDIO,
1320  .config_props = config_output,
1321  },
1322 };
1323 
1325  .name = "afwtdn",
1326  .description = NULL_IF_CONFIG_SMALL("Denoise audio stream using Wavelets."),
1327  .query_formats = query_formats,
1328  .priv_size = sizeof(AudioFWTDNContext),
1329  .priv_class = &afwtdn_class,
1330  .activate = activate,
1331  .uninit = uninit,
1334  .process_command = process_command,
1335  .flags = AVFILTER_FLAG_SLICE_THREADS,
1336 };
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:88
coif5_ilp
static const double coif5_ilp[30]
Definition: af_afwtdn.c:226
nb_coefs
static int nb_coefs(int length, int level, uint64_t sn)
Definition: af_afwtdn.c:532
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:943
AudioFWTDNContext::got_profile
int got_profile
Definition: af_afwtdn.c:420
status
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
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:401
AudioFWTDNContext::padd_samples
int padd_samples
Definition: af_afwtdn.c:425
ChannelParams::temp_in_length
int temp_in_length
Definition: af_afwtdn.c:389
ChannelParams::tempa
double * tempa
Definition: af_afwtdn.c:395
out
FILE * out
Definition: movenc.c:54
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:1019
ChannelParams::min_left_ext
int min_left_ext
Definition: af_afwtdn.c:392
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
FFERROR_NOT_READY
return FFERROR_NOT_READY
Definition: filter_design.txt:204
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
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:112
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:396
SYM2
@ SYM2
Definition: af_afwtdn.c:32
AudioFWTDNContext::hp
const double * hp
Definition: af_afwtdn.c:430
AudioFWTDNContext::absmean
AVFrame * absmean
Definition: af_afwtdn.c:433
AVOption
AVOption.
Definition: opt.h:247
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:336
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
ff_set_common_all_samplerates
int ff_set_common_all_samplerates(AVFilterContext *ctx)
Equivalent to ff_set_common_samplerates(ctx, ff_all_samplerates())
Definition: formats.c:687
float.h
ChannelParams::output_length
int * output_length
Definition: af_afwtdn.c:381
coif5_hp
static const double coif5_hp[30]
Definition: af_afwtdn.c:208
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:889
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:153
ThreadData::out
AVFrame * out
Definition: af_adeclick.c:492
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:584
sym2_ihp
static const double sym2_ihp[4]
Definition: af_afwtdn.c:373
formats.h
M_LN2
#define M_LN2
Definition: mathematics.h:40
inputs
static const AVFilterPad inputs[]
Definition: af_afwtdn.c:1309
SYM4
@ SYM4
Definition: af_afwtdn.c:33
min_left_ext
static int min_left_ext(int wavelet_length, int levels)
Definition: af_afwtdn.c:1106
pow2
#define pow2(x)
Definition: af_afwtdn.c:481
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:734
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(afwtdn)
FFSIGN
#define FFSIGN(a)
Definition: common.h:66
pts
static int64_t pts
Definition: transcode_aac.c:653
next_pow2
static int next_pow2(int in)
Definition: af_afwtdn.c:873
AudioFWTDNContext::nb_samples
int nb_samples
Definition: af_afwtdn.c:416
coif5_lp
static const double coif5_lp[30]
Definition: af_afwtdn.c:190
sym10_lp
static const double sym10_lp[20]
Definition: af_afwtdn.c:94
AudioFWTDNContext::sigma
double sigma
Definition: af_afwtdn.c:407
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
ChannelParams::buffer
double * buffer
Definition: af_afwtdn.c:398
coif5_ihp
static const double coif5_ihp[30]
Definition: af_afwtdn.c:244
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:314
deb10_ilp
static const double deb10_ilp[20]
Definition: af_afwtdn.c:288
sym4_ihp
static const double sym4_ihp[8]
Definition: af_afwtdn.c:347
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:412
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVFrame::channels
int channels
number of audio channels, only used for audio.
Definition: frame.h:592
deb10_hp
static const double deb10_hp[20]
Definition: af_afwtdn.c:275
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:226
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
sym10_ilp
static const double sym10_ilp[20]
Definition: af_afwtdn.c:120
SYM10
@ SYM10
Definition: af_afwtdn.c:36
ff_set_common_formats_from_list
int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_format_list(fmts))
Definition: formats.c:703
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_afwtdn.c:464
filters.h
rbior68_ihp
static const double rbior68_ihp[18]
Definition: af_afwtdn.c:180
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:925
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:141
ChannelParams::prev
double * prev
Definition: af_afwtdn.c:400
AudioFWTDNContext::channels
int channels
Definition: af_afwtdn.c:415
AudioFWTDNContext::cp
ChannelParams * cp
Definition: af_afwtdn.c:428
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:152
arg
const char * arg
Definition: jacosubdec.c:67
sym2_lp
static const double sym2_lp[4]
Definition: af_afwtdn.c:358
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:156
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:878
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:1437
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:537
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:325
src
#define src
Definition: vp8dsp.c:255
AudioFWTDNContext
Definition: af_afwtdn.c:404
ff_set_common_all_channel_counts
int ff_set_common_all_channel_counts(AVFilterContext *ctx)
Equivalent to ff_set_common_channel_layouts(ctx, ff_all_channel_counts())
Definition: formats.c:669
NB_WAVELET_TYPES
@ NB_WAVELET_TYPES
Definition: af_afwtdn.c:39
ff_af_afwtdn
const AVFilter ff_af_afwtdn
Definition: af_afwtdn.c:1324
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:1372
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_afwtdn.c:1021
sym10_ihp
static const double sym10_ihp[20]
Definition: af_afwtdn.c:133
AudioFWTDNContext::new_absmean
AVFrame * new_absmean
Definition: af_afwtdn.c:434
sym10_hp
static const double sym10_hp[20]
Definition: af_afwtdn.c:107
bl3_ihp
static const double bl3_ihp[42]
Definition: af_afwtdn.c:82
ChannelParams::tempd
double * tempd
Definition: af_afwtdn.c:396
ChannelParams::output_coefs
double ** output_coefs
Definition: af_afwtdn.c:383
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:117
AudioFWTDNContext::wavelet_length
int wavelet_length
Definition: af_afwtdn.c:418
bl3_hp
static const double bl3_hp[42]
Definition: af_afwtdn.c:58
measure_stddev
static double measure_stddev(const double *in, int length, double mean)
Definition: af_afwtdn.c:914
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:458
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:376
BL3
@ BL3
Definition: af_afwtdn.c:38
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:883
MAX_LEVELS
#define MAX_LEVELS
Definition: af_afwtdn.c:378
AudioFWTDNContext::sn
uint64_t sn
Definition: af_afwtdn.c:411
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:637
max_left_ext
static int max_left_ext(int wavelet_length, int levels)
Definition: af_afwtdn.c:1101
ChannelParams::tempa_len_max
int tempa_len_max
Definition: af_afwtdn.c:388
AFR
#define AFR
Definition: af_afwtdn.c:441
AudioFWTDNContext::prev_length
int prev_length
Definition: af_afwtdn.c:427
av_samples_copy
int av_samples_copy(uint8_t **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:220
deb10_ihp
static const double deb10_ihp[20]
Definition: af_afwtdn.c:301
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:369
i
int i
Definition: input.c:406
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:350
ChannelParams::temp_in
double * temp_in
Definition: af_afwtdn.c:397
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
ThreadData
Used for passing data between threads.
Definition: dsddec.c:67
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:630
ChannelParams
sample data coding information
Definition: mlp.h:86
ChannelParams::tempa_length
int tempa_length
Definition: af_afwtdn.c:387
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
bl3_ilp
static const double bl3_ilp[42]
Definition: af_afwtdn.c:70
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:484
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
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:146
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:149
AudioFWTDNContext::filter
AVFrame * filter
Definition: af_afwtdn.c:433
sym2_hp
static const double sym2_hp[4]
Definition: af_afwtdn.c:363
ret
ret
Definition: filter_design.txt:187
sym2_ilp
static const double sym2_ilp[4]
Definition: af_afwtdn.c:368
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
ChannelParams::buffer_length
int buffer_length
Definition: af_afwtdn.c:391
DEB10
@ DEB10
Definition: af_afwtdn.c:35
left_ext
static int left_ext(int wavelet_length, int levels, uint64_t sn)
Definition: af_afwtdn.c:525
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_afwtdn.c:1251
rbior68_ilp
static const double rbior68_ilp[18]
Definition: af_afwtdn.c:168
ChannelParams::subbands_to_free
double ** subbands_to_free
Definition: af_afwtdn.c:384
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_afwtdn.c:1111
measure_mean
static double measure_mean(const double *in, int length)
Definition: af_afwtdn.c:894
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:1316
AudioFWTDNContext::stddev
AVFrame * stddev
Definition: af_afwtdn.c:433
ChannelParams::max_left_ext
int max_left_ext
Definition: af_afwtdn.c:393
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:779
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
max_left_zeros_inverse
static int max_left_zeros_inverse(int levels, int level, int wavelet_length)
Definition: af_afwtdn.c:579
append_left_ext
static int append_left_ext(int wavelet_length, int levels, int level, uint64_t sn)
Definition: af_afwtdn.c:770
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:70
WaveletTypes
WaveletTypes
Definition: af_afwtdn.c:31
mean
static float mean(const float *input, int size)
Definition: vf_nnedi.c:860
deb10_lp
static const double deb10_lp[20]
Definition: af_afwtdn.c:262
AVFilterContext
An instance of a filter.
Definition: avfilter.h:346
shift
static int shift(int a, int b)
Definition: sonic.c:83
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:121
add
static float add(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:35
AudioFWTDNContext::ihp
const double * ihp
Definition: af_afwtdn.c:431
audio.h
ChannelParams::filter_coefs
double ** filter_coefs
Definition: af_afwtdn.c:385
ThreadData::in
AVFrame * in
Definition: af_adecorrelate.c:171
ChannelParams::filter_length
int * filter_length
Definition: af_afwtdn.c:382
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
Definition: opt.h:241
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:153
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
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:539
bl3_lp
static const double bl3_lp[42]
Definition: af_afwtdn.c:46
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AudioFWTDNContext::percent
double percent
Definition: af_afwtdn.c:408
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
afwtdn_options
static const AVOption afwtdn_options[]
Definition: af_afwtdn.c:443
COIF5
@ COIF5
Definition: af_afwtdn.c:37
ChannelParams::temp_in_max_length
int temp_in_max_length
Definition: af_afwtdn.c:390
activate
static int activate(AVFilterContext *ctx)
Definition: af_afwtdn.c:1218
RBIOR68
@ RBIOR68
Definition: af_afwtdn.c:34
avstring.h
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:1293
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:143
int
int
Definition: ffmpeg_filter.c:156
measure_absmean
static double measure_absmean(const double *in, int length)
Definition: af_afwtdn.c:904
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
mod_pow2
#define mod_pow2(x, power_of_two)
Definition: af_afwtdn.c:482
AudioFWTDNContext::overlap_length
int overlap_length
Definition: af_afwtdn.c:426
ChannelParams::buffer2
double * buffer2
Definition: af_afwtdn.c:399
AudioFWTDNContext::softness
double softness
Definition: af_afwtdn.c:409