Deluge Firmware 1.3.0
Build date: 2025.04.16
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 void reset();
47 int32_t setConfig(q31_t lpfFrequency, q31_t lpfResonance, FilterMode lpfmode, q31_t lpfMorph, q31_t hpfFrequency,
48 q31_t hpfResonance, FilterMode hpfmode, q31_t hpfMorph, q31_t filterGain, FilterRoute routing,
49 bool adjustVolumeForHPFResonance, q31_t* overallOscAmplitude);
50
51 void renderLong(q31_t* startSample, q31_t* endSample, int32_t numSamples, int32_t sampleIncrememt = 1);
52
53 // expects to receive an interleaved stereo stream
54 void renderLongStereo(q31_t* startSample, q31_t* endSample);
55
56 // used to check whether the filter is used at all
57 inline bool isLPFOn() { return LPFOn; }
58 inline bool isHPFOn() { return HPFOn; }
59 inline bool isOn() { return HPFOn || LPFOn; }
60
61private:
62 FilterMode lpfMode_;
63 FilterMode lastLPFMode_;
64 FilterMode hpfMode_;
65 FilterMode lastHPFMode_;
66 FilterRoute routing_;
67
68 void renderLPFLong(q31_t* startSample, q31_t* endSample, int32_t sampleIncrement = 1);
69 void renderLPFLongStereo(q31_t* startSample, q31_t* endSample);
70 void renderHPFLongStereo(q31_t* startSample, q31_t* endSample);
71 void renderHPFLong(q31_t* startSample, q31_t* endSample, int32_t sampleIncrement = 1);
72
73 // all filters share a state. This is fine since they just hold plain data and initialization is handled by
74 // reset/configure calls. This is faster than using a variant at the cost of not throwing on incorrect access.
75 // However since there are no invariants to uphold, the worst case scenario is an audio glitch so whatever
76 // This cuts 250 bytes from the size of this class, which is fairly significant since every voice has a filterset
77 LowPass lpfilter;
78 HighPass hpfilter;
79
80 bool LPFOn;
81 bool HPFOn;
82};
83} // namespace deluge::dsp::filter
Definition sound.h:71
Definition filter_set.h:44
Definition hpladder.h:26
Definition lpladder.h:26
Definition filter_set.h:38
Definition filter_set.h:32