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