PipeWire  0.3.61
dll.h
1 /* Simple DLL
2  *
3  * Copyright © 2019 Wim Taymans
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef SPA_DLL_H
26 #define SPA_DLL_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <stddef.h>
33 #include <math.h>
34 
35 #define SPA_DLL_BW_MAX 0.128
36 #define SPA_DLL_BW_MIN 0.016
37 
38 struct spa_dll {
39  double bw;
40  double z1, z2, z3;
41  double w0, w1, w2;
42 };
43 
44 static inline void spa_dll_init(struct spa_dll *dll)
45 {
46  dll->bw = 0.0;
47  dll->z1 = dll->z2 = dll->z3 = 0.0;
48 }
49 
50 static inline void spa_dll_set_bw(struct spa_dll *dll, double bw, unsigned period, unsigned rate)
51 {
52  double w = 2 * M_PI * bw * period / rate;
53  dll->w0 = 1.0 - exp (-20.0 * w);
54  dll->w1 = w * 1.5 / period;
55  dll->w2 = w / 1.5;
56  dll->bw = bw;
57 }
58 
59 static inline double spa_dll_update(struct spa_dll *dll, double err)
60 {
61  dll->z1 += dll->w0 * (dll->w1 * err - dll->z1);
62  dll->z2 += dll->w0 * (dll->z1 - dll->z2);
63  dll->z3 += dll->w2 * dll->z2;
64  return 1.0 - (dll->z2 + dll->z3);
65 }
66 
67 #ifdef __cplusplus
68 } /* extern "C" */
69 #endif
70 
71 #endif /* SPA_DLL_H */
Definition: dll.h:44
double z2
Definition: dll.h:46
double z1
Definition: dll.h:46
double w2
Definition: dll.h:47
double z3
Definition: dll.h:46
double w0
Definition: dll.h:47
double bw
Definition: dll.h:45
double w1
Definition: dll.h:47