1 | /** |
2 | * Copyright (c) 2006-2023 LOVE Development Team |
3 | * |
4 | * This software is provided 'as-is', without any express or implied |
5 | * warranty. In no event will the authors be held liable for any damages |
6 | * arising from the use of this software. |
7 | * |
8 | * Permission is granted to anyone to use this software for any purpose, |
9 | * including commercial applications, and to alter it and redistribute it |
10 | * freely, subject to the following restrictions: |
11 | * |
12 | * 1. The origin of this software must not be misrepresented; you must not |
13 | * claim that you wrote the original software. If you use this software |
14 | * in a product, an acknowledgment in the product documentation would be |
15 | * appreciated but is not required. |
16 | * 2. Altered source versions must be plainly marked as such, and must not be |
17 | * misrepresented as being the original software. |
18 | * 3. This notice may not be removed or altered from any source distribution. |
19 | **/ |
20 | |
21 | #ifndef LOVE_AUDIO_EFFECTS_H |
22 | #define LOVE_AUDIO_EFFECTS_H |
23 | |
24 | #include "common/Object.h" |
25 | #include "common/StringMap.h" |
26 | #include <map> |
27 | #include <vector> |
28 | |
29 | template<typename T> |
30 | class LazierAndSlowerButEasilyArrayableStringMap |
31 | { |
32 | public: |
33 | struct Entry |
34 | { |
35 | const char *key; |
36 | T value; |
37 | }; |
38 | LazierAndSlowerButEasilyArrayableStringMap() |
39 | { |
40 | } |
41 | |
42 | LazierAndSlowerButEasilyArrayableStringMap(const std::vector<Entry> &entries) |
43 | { |
44 | for (auto entry : entries) |
45 | { |
46 | forward[entry.key] = entry.value; |
47 | reverse[entry.value] = entry.key; |
48 | } |
49 | } |
50 | |
51 | bool find(const char *key, T &t) |
52 | { |
53 | if (forward.find(key) == forward.end()) |
54 | return false; |
55 | t = forward[key]; |
56 | return true; |
57 | } |
58 | |
59 | bool find(T key, const char *&str) |
60 | { |
61 | if (reverse.find(key) == reverse.end()) |
62 | return false; |
63 | str = reverse[key]; |
64 | return true; |
65 | } |
66 | |
67 | private: |
68 | std::map<std::string, T> forward; |
69 | std::map<T, const char*> reverse; |
70 | }; |
71 | |
72 | namespace love |
73 | { |
74 | namespace audio |
75 | { |
76 | |
77 | class Effect |
78 | { |
79 | public: |
80 | enum Type |
81 | { |
82 | TYPE_BASIC, //not a real type |
83 | TYPE_REVERB, |
84 | TYPE_CHORUS, |
85 | TYPE_DISTORTION, |
86 | TYPE_ECHO, |
87 | TYPE_FLANGER, |
88 | //TYPE_FREQSHIFTER, |
89 | //TYPE_MORPHER, |
90 | //TYPE_PITCHSHIFTER, |
91 | TYPE_MODULATOR, |
92 | //TYPE_AUTOWAH, |
93 | TYPE_COMPRESSOR, |
94 | TYPE_EQUALIZER, |
95 | TYPE_MAX_ENUM |
96 | }; |
97 | |
98 | enum Parameter |
99 | { |
100 | EFFECT_TYPE, |
101 | EFFECT_VOLUME, |
102 | |
103 | REVERB_GAIN, |
104 | REVERB_HFGAIN, |
105 | REVERB_DENSITY, |
106 | REVERB_DIFFUSION, |
107 | REVERB_DECAY, |
108 | REVERB_HFDECAY, |
109 | REVERB_EARLYGAIN, |
110 | REVERB_EARLYDELAY, |
111 | REVERB_LATEGAIN, |
112 | REVERB_LATEDELAY, |
113 | REVERB_ROLLOFF, |
114 | REVERB_AIRHFGAIN, |
115 | REVERB_HFLIMITER, |
116 | |
117 | CHORUS_WAVEFORM, |
118 | CHORUS_PHASE, |
119 | CHORUS_RATE, |
120 | CHORUS_DEPTH, |
121 | CHORUS_FEEDBACK, |
122 | CHORUS_DELAY, |
123 | |
124 | DISTORTION_GAIN, |
125 | DISTORTION_EDGE, |
126 | DISTORTION_LOWCUT, |
127 | DISTORTION_EQCENTER, |
128 | DISTORTION_EQBAND, |
129 | |
130 | ECHO_DELAY, |
131 | ECHO_LRDELAY, |
132 | ECHO_DAMPING, |
133 | ECHO_FEEDBACK, |
134 | ECHO_SPREAD, |
135 | |
136 | FLANGER_WAVEFORM, |
137 | FLANGER_PHASE, |
138 | FLANGER_RATE, |
139 | FLANGER_DEPTH, |
140 | FLANGER_FEEDBACK, |
141 | FLANGER_DELAY, |
142 | /* |
143 | FREQSHIFTER_FREQ, |
144 | FREQSHIFTER_LEFTDIR, |
145 | FREQSHIFTER_RIGHTDIR, |
146 | |
147 | MORPHER_WAVEFORM, |
148 | MORPHER_RATE, |
149 | MORPHER_PHONEMEA, |
150 | MORPHER_PHONEMEB, |
151 | MORPHER_TUNEA, |
152 | MORPHER_TUNEB, |
153 | |
154 | PITCHSHIFTER_PITCH, |
155 | */ |
156 | MODULATOR_WAVEFORM, |
157 | MODULATOR_FREQ, |
158 | MODULATOR_HIGHCUT, |
159 | /* |
160 | AUTOWAH_ATTACK, |
161 | AUTOWAH_RELEASE, |
162 | AUTOWAH_RESONANCE, |
163 | AUTOWAH_PEAKGAIN, |
164 | */ |
165 | COMPRESSOR_ENABLE, |
166 | |
167 | EQUALIZER_LOWGAIN, |
168 | EQUALIZER_LOWCUT, |
169 | EQUALIZER_MID1GAIN, |
170 | EQUALIZER_MID1FREQ, |
171 | EQUALIZER_MID1BAND, |
172 | EQUALIZER_MID2GAIN, |
173 | EQUALIZER_MID2FREQ, |
174 | EQUALIZER_MID2BAND, |
175 | EQUALIZER_HIGHGAIN, |
176 | EQUALIZER_HIGHCUT, |
177 | |
178 | EFFECT_MAX_ENUM |
179 | }; |
180 | |
181 | enum ParameterType |
182 | { |
183 | PARAM_TYPE, |
184 | PARAM_FLOAT, |
185 | PARAM_BOOL, |
186 | PARAM_WAVEFORM, |
187 | //PARAM_DIRECTION, |
188 | //PARAM_PHONEME, |
189 | PARAM_MAX_ENUM |
190 | }; |
191 | |
192 | enum Waveform |
193 | { |
194 | WAVE_SINE, |
195 | WAVE_TRIANGLE, |
196 | WAVE_SAWTOOTH, |
197 | WAVE_SQUARE, |
198 | WAVE_MAX_ENUM |
199 | }; |
200 | /* |
201 | enum Direction |
202 | { |
203 | DIR_NONE, |
204 | DIR_UP, |
205 | DIR_DOWN, |
206 | DIR_MAX_ENUM |
207 | }; |
208 | |
209 | enum Phoneme |
210 | { |
211 | PHONEME_A, |
212 | PHONEME_E, |
213 | PHONEME_I, |
214 | PHONEME_O, |
215 | PHONEME_U, |
216 | PHONEME_AA, |
217 | PHONEME_AE, |
218 | PHONEME_AH, |
219 | PHONEME_AO, |
220 | PHONEME_EH, |
221 | PHONEME_ER, |
222 | PHONEME_IH, |
223 | PHONEME_IY, |
224 | PHONEME_UH, |
225 | PHONEME_UW, |
226 | PHONEME_B, |
227 | PHONEME_D, |
228 | PHONEME_F, |
229 | PHONEME_G, |
230 | PHONEME_J, |
231 | PHONEME_K, |
232 | PHONEME_L, |
233 | PHONEME_M, |
234 | PHONEME_N, |
235 | PHONEME_P, |
236 | PHONEME_R, |
237 | PHONEME_S, |
238 | PHONEME_T, |
239 | PHONEME_V, |
240 | PHONEME_Z, |
241 | PHONEME_MAX_ENUM |
242 | }; |
243 | */ |
244 | |
245 | Effect(); |
246 | virtual ~Effect(); |
247 | Type getType() const; |
248 | |
249 | static bool getConstant(const char *in, Type &out); |
250 | static bool getConstant(Type in, const char *&out); |
251 | static std::vector<std::string> getConstants(Type); |
252 | static bool getConstant(const char *in, Waveform &out); |
253 | static bool getConstant(Waveform in, const char *&out); |
254 | //static bool getConstant(const char *in, Direction &out); |
255 | //static bool getConstant(Direction in, const char *&out); |
256 | //static bool getConstant(const char *in, Phoneme &out); |
257 | //static bool getConstant(Phoneme in, const char *&out); |
258 | static bool getConstant(const char *in, Parameter &out, Type t); |
259 | static bool getConstant(Parameter in, const char *&out, Type t); |
260 | static ParameterType getParameterType(Parameter in); |
261 | |
262 | protected: |
263 | Type type; |
264 | |
265 | private: |
266 | static StringMap<Type, TYPE_MAX_ENUM>::Entry typeEntries[]; |
267 | static StringMap<Type, TYPE_MAX_ENUM> types; |
268 | static StringMap<Waveform, WAVE_MAX_ENUM>::Entry waveformEntries[]; |
269 | static StringMap<Waveform, WAVE_MAX_ENUM> waveforms; |
270 | //static StringMap<Direction, DIR_MAX_ENUM>::Entry directionEntries[]; |
271 | //static StringMap<Direction, DIR_MAX_ENUM> directions; |
272 | //static StringMap<Phoneme, PHONEME_MAX_ENUM>::Entry phonemeEntries[]; |
273 | //static StringMap<Phoneme, PHONEME_MAX_ENUM> phonemes; |
274 | #define StringMap LazierAndSlowerButEasilyArrayableStringMap |
275 | static std::vector<StringMap<Effect::Parameter>::Entry> basicParameters; |
276 | static std::vector<StringMap<Effect::Parameter>::Entry> reverbParameters; |
277 | static std::vector<StringMap<Effect::Parameter>::Entry> chorusParameters; |
278 | static std::vector<StringMap<Effect::Parameter>::Entry> distortionParameters; |
279 | static std::vector<StringMap<Effect::Parameter>::Entry> echoParameters; |
280 | static std::vector<StringMap<Effect::Parameter>::Entry> flangerParameters; |
281 | //static std::vector<StringMap<Effect::Parameter>::Entry> freqshifterParameters; |
282 | //static std::vector<StringMap<Effect::Parameter>::Entry> morpherParameters; |
283 | //static std::vector<StringMap<Effect::Parameter>::Entry> pitchshifterParameters; |
284 | static std::vector<StringMap<Effect::Parameter>::Entry> modulatorParameters; |
285 | //static std::vector<StringMap<Effect::Parameter>::Entry> autowahParameters; |
286 | static std::vector<StringMap<Effect::Parameter>::Entry> compressorParameters; |
287 | static std::vector<StringMap<Effect::Parameter>::Entry> equalizerParameters; |
288 | static std::map<Type, StringMap<Parameter>> parameterNames; |
289 | #undef StringMap |
290 | static std::map<Parameter, ParameterType> parameterTypes; |
291 | |
292 | }; |
293 | |
294 | } //audio |
295 | } //love |
296 | |
297 | #endif //LOVE_AUDIO_EFFECTS_H |
298 | |