Deluge Firmware
1.3.0
Build date: 2026.11.28
Toggle main menu visibility
Loading...
Searching...
No Matches
hpladder.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
24
namespace
deluge::dsp::filter {
25
26
class
HpLadderFilter :
public
Filter<HpLadderFilter> {
27
public
:
28
HpLadderFilter() =
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* startSample, 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
38
private
:
39
struct
HPLadderState
{
40
BasicFilterComponent
hpfHPF1;
41
BasicFilterComponent
hpfLPF1;
42
BasicFilterComponent
hpfHPF3;
43
uint32_t hpfLastWorkingValue;
44
void
reset() {
45
hpfHPF1.reset();
46
hpfLPF1.reset();
47
hpfHPF3.reset();
48
}
49
};
50
// Per-buffer copy of the coefficients. The loops work on locals so stores to the q31_t sample buffer can't force
51
// the compiler to reload the q31_t members and store the state back every sample.
52
struct
Coeffs
{
53
q31_t fc;
54
q31_t morph;
55
q31_t hpfHPF3Feedback;
56
q31_t hpfLPF1Feedback;
57
q31_t divideByTotalMoveability;
58
q31_t hpfDivideByProcessedResonance;
59
};
60
[[gnu::always_inline]]
Coeffs
getCoeffs()
const
{
61
return
Coeffs
{
62
fc, morph_, hpfHPF3Feedback, hpfLPF1Feedback, divideByTotalMoveability, hpfDivideByProcessedResonance};
63
}
64
// kSaturation: 0 none, 1 tanh, 2 antialiased tanh (from hpfProcessedResonance, loop invariant)
65
// kMorph: false when morph_ == 0, where the cutoff modulation term is exactly 0
66
template
<
int
kSaturation,
bool
kMorph>
67
[[gnu::always_inline]]
static
inline
q31_t doHPF(q31_t input, HPLadderState& state,
const
Coeffs& c);
68
template
<
int
kSaturation,
bool
kMorph>
69
void
doFilterT(q31_t* startSample, q31_t* endSample, int32_t sampleIncrement);
70
template
<
int
kSaturation,
bool
kMorph>
71
void
doFilterStereoT(q31_t* startSample, q31_t* endSample);
72
template
<
typename
F>
73
[[gnu::always_inline]]
inline
void
dispatch(F&& f);
74
75
bool
hpfDoingAntialiasingNow;
76
int32_t hpfDivideByTotalMoveabilityLastTime;
77
int32_t hpfDivideByProcessedResonanceLastTime;
78
79
// All feedbacks have 1 represented as 1073741824
80
q31_t hpfLPF1Feedback;
81
q31_t hpfHPF3Feedback;
82
83
q31_t hpfProcessedResonance;
// 1 represented as 1073741824
84
bool
hpfDoAntialiasing;
85
q31_t hpfDivideByProcessedResonance;
86
87
q31_t divideByTotalMoveability;
// 1 represented as 268435456
88
89
q31_t alteredHpfMomentumMultiplier;
90
q31_t thisHpfResonance;
91
q31_t morph_;
92
HPLadderState l;
93
HPLadderState r;
94
};
95
}
// namespace deluge::dsp::filter
deluge::dsp::filter::BasicFilterComponent
Definition
ladder_components.h:23
deluge::dsp::filter::HpLadderFilter::Coeffs
Definition
hpladder.h:52
deluge::dsp::filter::HpLadderFilter::HPLadderState
Definition
hpladder.h:39