Deluge Firmware 1.3.0
Build date: 2026.07.15
Loading...
Searching...
No Matches
filter_set.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 "definitions_cxx.hpp"
21#include "dsp/filter/hpladder.h"
22#include "dsp/filter/lpladder.h"
23#include "dsp/filter/svf.h"
24#include "model/mod_controllable/filters/filter_config.h"
25#include "util/fixedpoint.h"
26#include <cstdint>
27
28class Sound;
29
30namespace deluge::dsp::filter {
31
32union LowPass {
33 LpLadderFilter ladder;
34 SVFilter svf;
35 LowPass() {}
36};
37
38union HighPass {
39 HpLadderFilter ladder;
40 SVFilter svf;
41 HighPass() {}
42};
43
44class FilterSet {
45public:
46 FilterSet() { reset(); }
47 void reset() { memset(this, 0, sizeof(FilterSet)); }
48
49 int32_t setConfig(q31_t lpfFrequency, q31_t lpfResonance, FilterMode lpfmode, q31_t lpfMorph, q31_t hpfFrequency,
50 q31_t hpfResonance, FilterMode hpfmode, q31_t hpfMorph, q31_t filterGain, FilterRoute routing,
51 bool adjustVolumeForHPFResonance, q31_t* overallOscAmplitude);
52
53 void renderLong(q31_t* startSample, q31_t* endSample, int32_t numSamples, int32_t sampleIncrememt = 1);
54
55 // expects to receive an interleaved stereo stream
56 void renderLongStereo(q31_t* startSample, q31_t* endSample);
57
58 // used to check whether the filter is used at all
59 inline bool isLPFOn() { return LPFOn; }
60 inline bool isHPFOn() { return HPFOn; }
61 inline bool isOn() { return HPFOn || LPFOn; }
62
63private:
64 FilterMode lpfMode_;
65 FilterMode lastLPFMode_;
66 FilterMode hpfMode_;
67 FilterMode lastHPFMode_;
68 FilterRoute routing_;
69
70 void renderLPFLong(q31_t* startSample, q31_t* endSample, int32_t sampleIncrement = 1);
71 void renderLPFLongStereo(q31_t* startSample, q31_t* endSample);
72 void renderHPFLongStereo(q31_t* startSample, q31_t* endSample);
73 void renderHPFLong(q31_t* startSample, q31_t* endSample, int32_t sampleIncrement = 1);
74
75 // all filters share a state. This is fine since they just hold plain data and initialization is handled by
76 // reset/configure calls. This is faster than using a variant at the cost of not throwing on incorrect access.
77 // However since there are no invariants to uphold, the worst case scenario is an audio glitch so whatever
78 // This cuts 250 bytes from the size of this class, which is fairly significant since every voice has a filterset
79 LowPass lpfilter;
80 HighPass hpfilter;
81
82 bool LPFOn;
83 bool HPFOn;
84};
85} // namespace deluge::dsp::filter
Definition sound.h:71
Definition hpladder.h:26
Definition lpladder.h:26
Definition filter_set.h:38
Definition filter_set.h:32