PipeWire  1.4.5
dll.h
1 /* Simple DLL */
2 /* SPDX-FileCopyrightText: Copyright © 2019 Wim Taymans */
3 /* SPDX-License-Identifier: MIT */
4 
5 #ifndef SPA_DLL_H
6 #define SPA_DLL_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 #include <stddef.h>
13 #include <math.h>
14 
15 #include <spa/utils/defs.h>
16 
17 #ifndef SPA_API_DLL
18  #ifdef SPA_API_IMPL
19  #define SPA_API_DLL SPA_API_IMPL
20  #else
21  #define SPA_API_DLL static inline
22  #endif
23 #endif
24 
25 #define SPA_DLL_BW_MAX 0.128
26 #define SPA_DLL_BW_MIN 0.016
27 
28 struct spa_dll {
29  double bw;
30  double z1, z2, z3;
31  double w0, w1, w2;
32 };
33 
34 SPA_API_DLL void spa_dll_init(struct spa_dll *dll)
35 {
36  dll->bw = 0.0;
37  dll->z1 = dll->z2 = dll->z3 = 0.0;
38 }
39 
40 SPA_API_DLL void spa_dll_set_bw(struct spa_dll *dll, double bw, unsigned period, unsigned rate)
41 {
42  double w = 2 * M_PI * bw * period / rate;
43  dll->w0 = 1.0 - exp (-20.0 * w);
44  dll->w1 = w * 1.5 / period;
45  dll->w2 = w / 1.5;
46  dll->bw = bw;
47 }
48 
49 SPA_API_DLL double spa_dll_update(struct spa_dll *dll, double err)
50 {
51  dll->z1 += dll->w0 * (dll->w1 * err - dll->z1);
52  dll->z2 += dll->w0 * (dll->z1 - dll->z2);
53  dll->z3 += dll->w2 * dll->z2;
54  return 1.0 - (dll->z2 + dll->z3);
55 }
56 
57 #ifdef __cplusplus
58 } /* extern "C" */
59 #endif
60 
61 #endif /* SPA_DLL_H */
spa/utils/defs.h
Definition: dll.h:36
double z2
Definition: dll.h:38
double z1
Definition: dll.h:38
double w2
Definition: dll.h:39
double z3
Definition: dll.h:38
double w0
Definition: dll.h:39
double bw
Definition: dll.h:37
double w1
Definition: dll.h:39