Deluge Firmware 1.3.0
Build date: 2026.08.29
Loading...
Searching...
No Matches
filter_config.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 "gui/l10n/strings.h"
22#include "util/misc.h"
23
24// non namespaced
25enum class FilterMode {
26 TRANSISTOR_12DB,
27 TRANSISTOR_24DB,
28 TRANSISTOR_24DB_DRIVE, // filter logic relies on ladders being first and contiguous
29 SVF_BAND, // first HPF mode
30 SVF_NOTCH, // last LPF mode
31 HPLADDER,
32 OFF, // Keep last as a sentinel. Signifies that the filter is not on, used for filter reset logic
33};
34constexpr int32_t kNumFilterModes = util::to_underlying(FilterMode::OFF) + 1;
35constexpr FilterMode kLastLadder = FilterMode::TRANSISTOR_24DB_DRIVE;
36constexpr int32_t kNumLPFModes = util::to_underlying(FilterMode::SVF_NOTCH) + 1;
37constexpr FilterMode lastLpfMode = FilterMode::SVF_NOTCH;
38constexpr FilterMode firstHPFMode = FilterMode::SVF_BAND;
39constexpr int32_t kFirstHPFMode = util::to_underlying(FilterMode::SVF_BAND);
40constexpr int32_t kNumHPFModes = util::to_underlying(FilterMode::OFF) - kFirstHPFMode;
41enum class FilterRoute {
42 HIGH_TO_LOW,
43 LOW_TO_HIGH,
44 PARALLEL,
45};
46
47constexpr int32_t kNumFilterRoutes = util::to_underlying(FilterRoute::PARALLEL) + 1;
48
49FilterRoute stringToFilterRoute(char const* string);
50char const* filterRouteToString(FilterRoute route);
51
52char const* lpfTypeToString(FilterMode lpfType);
53FilterMode stringToLPFType(char const* string);
54
55namespace deluge::dsp::filter {
56
57enum class FilterFamily { LP_LADDER, SVF, HP_LADDER, NONE };
58constexpr uint8_t kNumFamilies = 3;
59enum LpLadderType { LP12, LP24, DRIVE };
60constexpr uint8_t kNumLadders = 3;
61enum SVFType { BAND, NOTCH };
62constexpr uint8_t kNumSVF = 2;
63enum HPFType { HP12 };
64constexpr uint8_t kNumHPLadders = 1;
65
66using specificFilterType = uint8_t;
67// must match order of filter family declaration for indexing to work
68constexpr uint8_t numForVariant[kNumFamilies] = {kNumLadders, kNumSVF, kNumHPLadders};
69
71class SpecificFilter {
72public:
73 SpecificFilter() = default;
75 SpecificFilter(FilterMode mode) {
76 switch (mode) {
77 case FilterMode::OFF:
78 family = FilterFamily::NONE;
79 type = LpLadderType::LP12;
80 break;
81 case FilterMode::HPLADDER:
82 family = FilterFamily::HP_LADDER;
83 type = HPFType::HP12;
84 break;
85 case FilterMode::SVF_BAND:
86 family = FilterFamily::SVF;
87 type = SVFType::BAND;
88 break;
89 case FilterMode::SVF_NOTCH:
90 family = FilterFamily::SVF;
91 type = SVFType::NOTCH;
92 break;
93 case FilterMode::TRANSISTOR_12DB:
94 family = FilterFamily::LP_LADDER;
95 type = LpLadderType::LP12;
96 break;
97 case FilterMode::TRANSISTOR_24DB:
98 family = FilterFamily::LP_LADDER;
99 type = LpLadderType::LP24;
100 break;
101 case FilterMode::TRANSISTOR_24DB_DRIVE:
102 family = FilterFamily::LP_LADDER;
103 type = LpLadderType::DRIVE;
104 break;
105 }
106 }
107
108 FilterFamily getFamily() { return family; }
109
110 specificFilterType getType() { return type; }
111
112 [[nodiscard]] l10n::String getMorphName(bool shortName = false) const {
113
114 switch (family) {
115 case FilterFamily::LP_LADDER:
116 return l10n::String::STRING_FOR_DRIVE;
117 case FilterFamily::HP_LADDER:
118 return l10n::String::STRING_FOR_FM;
119 case FilterFamily::SVF:
120 return shortName ? l10n::String::STRING_FOR_MORPH_SHORT : l10n::String::STRING_FOR_MORPH;
121 default:
122 return l10n::String::STRING_FOR_NONE;
123 };
124 };
125
126 SpecificFilter& incrementMode() {
127 type = (type + 1) % numForVariant[util::to_underlying(family)];
128 return *this;
129 }
130
131 FilterMode toMode() {
132 int32_t baseNum = util::to_underlying(family);
133 int32_t base = 0;
134 for (int32_t i = 0; i < baseNum; i++) {
135 int32_t famNum = numForVariant[i];
136 base += famNum;
137 }
138 return static_cast<FilterMode>(base + type);
139 }
140
141private:
142 FilterFamily family;
143 specificFilterType type;
144};
145
146} // namespace deluge::dsp::filter
SpecificFilter(FilterMode mode)
Construct a filtertype from a mode.
Definition filter_config.h:75