Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
ladder_components.h
1/*
2 * Copyright © 2015-2023 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include "util/fixedpoint.h"
21#include <cstdint>
22namespace deluge::dsp::filter {
23class BasicFilterComponent {
24public:
25 BasicFilterComponent() { reset(); }
26 // moveability is tan(f)/(1+tan(f))
27 [[gnu::always_inline]] inline q31_t doFilter(q31_t input, q31_t moveability) {
28 // b = memory + 2t, memory' = b + 2t = memory + 4t. Written so both adds can use a shifted operand and don't
29 // depend on each other. Identical result (two's complement wraparound).
30 q31_t t = multiply_32x32_rshift32_rounded(input - memory, moveability);
31 q31_t b = (q31_t)((uint32_t)memory + ((uint32_t)t << 1));
32 memory = (q31_t)((uint32_t)memory + ((uint32_t)t << 2));
33 return b;
34 }
35 [[gnu::always_inline]] inline int32_t doAPF(q31_t input, int32_t moveability) {
36 q31_t a = multiply_32x32_rshift32_rounded(input - memory, moveability) << 1;
37 q31_t b = a + memory;
38 memory = a + b;
39 return b * 2 - input;
40 }
41 [[gnu::always_inline]] inline void affectFilter(q31_t input, int32_t moveability) {
42 memory += multiply_32x32_rshift32_rounded(input - memory, moveability) << 2;
43 }
44 [[gnu::always_inline]] inline void reset() { memory = 0; }
45 [[gnu::always_inline]] inline q31_t getFeedbackOutput(int32_t feedbackAmount) {
46 return multiply_32x32_rshift32_rounded(memory, feedbackAmount) << 2;
47 }
48 [[gnu::always_inline]] inline q31_t getFeedbackOutputWithoutLshift(int32_t feedbackAmount) {
49 return multiply_32x32_rshift32_rounded(memory, feedbackAmount);
50 }
51
52 q31_t memory = 0;
53};
54} // namespace deluge::dsp::filter