+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 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 | #include <stddef.h> |
| 9 | #include <math.h> |
| 10 | |
| 11 | #include <spa/utils/defs.h> |
| 12 | |
| 13 | #ifdef __cplusplus |
| 14 | extern "C" { |
| 15 | #endif |
| 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 */ |