Deluge Firmware 1.3.0
Build date: 2025.04.16
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(q31_t* outputSample, q31_t* endSample, int32_t sampleIncrememt);
32 void doFilterStereo(q31_t* startSample, q31_t* endSample);
33 void resetFilter() {
34 l.reset();
35 r.reset();
36 }
37
38private:
40 q31_t noiseLastValue;
45 void reset() {
46 lpfLPF1.reset();
47 lpfLPF2.reset();
48 lpfLPF3.reset();
49 lpfLPF4.reset();
50 }
51 };
52 [[gnu::always_inline]] inline q31_t scaleInput(q31_t input, q31_t feedbacksSum) {
53 q31_t temp;
54 if (morph > 0 || processedResonance > 510000000) {
55 temp = multiply_32x32_rshift32_rounded(
56 (input - (multiply_32x32_rshift32_rounded(feedbacksSum, processedResonance) << 3)),
57 divideByTotalMoveabilityAndProcessedResonance)
58 << 2;
59 q31_t extra = 2 * multiply_32x32_rshift32(input, morph);
60 temp = getTanHUnknown(temp + extra, 2);
61 }
62 else {
63 temp = multiply_32x32_rshift32_rounded(
64 (input - (multiply_32x32_rshift32_rounded(feedbacksSum, processedResonance) << 3)),
65 divideByTotalMoveabilityAndProcessedResonance)
66 << 2;
67 }
68
69 return temp;
70 }
71 [[gnu::always_inline]] inline q31_t do24dBLPFOnSample(q31_t input, LpLadderState& state);
72 [[gnu::always_inline]] inline q31_t do12dBLPFOnSample(q31_t input, LpLadderState& state);
73 [[gnu::always_inline]] inline q31_t doDriveLPFOnSample(q31_t input, LpLadderState& state);
74 // all ladders are in this class to share the basic components
75 // this differentiates between them
76 FilterMode lpfMode;
77
78 // state
79 LpLadderState l;
80 LpLadderState r;
81
82 // configuration
83 q31_t processedResonance;
84 q31_t divideByTotalMoveabilityAndProcessedResonance;
85
86 // moveability is tan(f)/(1+tan(f))
87 q31_t moveability;
88
89 q31_t morph;
90
91 // All feedbacks have 1 represented as 1073741824
92 q31_t lpf1Feedback;
93 q31_t lpf2Feedback;
94 q31_t lpf3Feedback;
95
96 bool doOversampling;
97};
98} // namespace deluge::dsp::filter
Definition ladder_components.h:23