Deluge Firmware 1.3.0
Build date: 2025.06.05
Loading...
Searching...
No Matches
lpladder.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 "dsp/filter/filter.h"
21#include "dsp/filter/ladder_components.h"
22#include "util/fixedpoint.h"
23
24namespace deluge::dsp::filter {
25
26class LpLadderFilter : public Filter<LpLadderFilter> {
27public:
28 LpLadderFilter() = default;
29 // returns a compensatory gain value
30 q31_t setConfig(q31_t hpfFrequency, q31_t hpfResonance, FilterMode lpfMode, q31_t lpfMorph, q31_t filterGain);
31 void doFilter(std::span<q31_t> buffer);
32 void doFilterStereo(std::span<StereoSample> buffer);
33 void resetFilter() {
34 l.reset();
35 r.reset();
36 }
37
38private:
40 q31_t noiseLastValue;
45
46 void reset() {
47 lpfLPF1.reset();
48 lpfLPF2.reset();
49 lpfLPF3.reset();
50 lpfLPF4.reset();
51 }
52 };
53
54 [[gnu::always_inline]] q31_t scaleInput(q31_t input, q31_t feedbacksSum) {
55 q31_t temp;
56 if (morph > 0 || processedResonance > 510000000) {
57 temp = multiply_32x32_rshift32_rounded(
58 (input - (multiply_32x32_rshift32_rounded(feedbacksSum, processedResonance) << 3)),
59 divideByTotalMoveabilityAndProcessedResonance)
60 << 2;
61 q31_t extra = 2 * multiply_32x32_rshift32(input, morph);
62 temp = getTanHUnknown(temp + extra, 2);
63 }
64 else {
65 temp = multiply_32x32_rshift32_rounded(
66 (input - (multiply_32x32_rshift32_rounded(feedbacksSum, processedResonance) << 3)),
67 divideByTotalMoveabilityAndProcessedResonance)
68 << 2;
69 }
70
71 return temp;
72 }
73
74 [[gnu::always_inline]] inline q31_t do24dBLPFOnSample(q31_t input, LpLadderState& state);
75 [[gnu::always_inline]] inline q31_t do12dBLPFOnSample(q31_t input, LpLadderState& state);
76 [[gnu::always_inline]] inline q31_t doDriveLPFOnSample(q31_t input, LpLadderState& state);
77 // all ladders are in this class to share the basic components
78 // this differentiates between them
79 FilterMode lpfMode;
80
81 // state
82 LpLadderState l;
83 LpLadderState r;
84
85 // configuration
86 q31_t processedResonance;
87 q31_t divideByTotalMoveabilityAndProcessedResonance;
88
89 // moveability is tan(f)/(1+tan(f))
90 q31_t moveability;
91
92 q31_t morph;
93
94 // All feedbacks have 1 represented as 1073741824
95 q31_t lpf1Feedback;
96 q31_t lpf2Feedback;
97 q31_t lpf3Feedback;
98
99 bool doOversampling;
100};
101} // namespace deluge::dsp::filter
Definition ladder_components.h:23