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#include "Effect.h"
22
23namespace love
24{
25namespace audio
26{
27
28Effect::Effect()
29{
30}
31
32Effect::~Effect()
33{
34}
35
36Effect::Type Effect::getType() const
37{
38 return type;
39}
40
41bool Effect::getConstant(const char *in, Type &out)
42{
43 return types.find(in, out);
44}
45
46bool Effect::getConstant(Type in, const char *&out)
47{
48 return types.find(in, out);
49}
50
51std::vector<std::string> Effect::getConstants(Type)
52{
53 return types.getNames();
54}
55
56/*
57bool Effect::getConstant(const char *in, Phoneme &out)
58{
59 return phonemes.find(in, out);
60}
61
62bool Effect::getConstant(Phoneme in, const char *&out)
63{
64 return phonemes.find(in, out);
65}
66*/
67bool Effect::getConstant(const char *in, Waveform &out)
68{
69 return waveforms.find(in, out);
70}
71
72bool Effect::getConstant(Waveform in, const char *&out)
73{
74 return waveforms.find(in, out);
75}
76/*
77bool Effect::getConstant(const char *in, Direction &out)
78{
79 return directions.find(in, out);
80}
81
82bool Effect::getConstant(Direction in, const char *&out)
83{
84 return directions.find(in, out);
85}
86*/
87bool Effect::getConstant(const char *in, Parameter &out, Type t)
88{
89 return parameterNames[t].find(in, out);
90}
91
92bool Effect::getConstant(Parameter in, const char *&out, Type t)
93{
94 return parameterNames[t].find(in, out);
95}
96
97Effect::ParameterType Effect::getParameterType(Effect::Parameter in)
98{
99 return parameterTypes[in];
100}
101
102StringMap<Effect::Type, Effect::TYPE_MAX_ENUM>::Entry Effect::typeEntries[] =
103{
104 {"reverb", Effect::TYPE_REVERB},
105 {"chorus", Effect::TYPE_CHORUS},
106 {"distortion", Effect::TYPE_DISTORTION},
107 {"echo", Effect::TYPE_ECHO},
108 {"flanger", Effect::TYPE_FLANGER},
109 //{"frequencyshifter", Effect::TYPE_FREQSHIFTER},
110 //{"vocalmorpher", Effect::TYPE_MORPHER},
111 //{"pitchshifter", Effect::TYPE_PITCHSHIFTER},
112 {"ringmodulator", Effect::TYPE_MODULATOR},
113 //{"autowah", Effect::TYPE_AUTOWAH},
114 {"compressor", Effect::TYPE_COMPRESSOR},
115 {"equalizer", Effect::TYPE_EQUALIZER},
116};
117
118StringMap<Effect::Type, Effect::TYPE_MAX_ENUM> Effect::types(Effect::typeEntries, sizeof(Effect::typeEntries));
119
120StringMap<Effect::Waveform, Effect::WAVE_MAX_ENUM>::Entry Effect::waveformEntries[] =
121{
122 {"sine", Effect::WAVE_SINE},
123 {"triangle", Effect::WAVE_TRIANGLE},
124 {"sawtooth", Effect::WAVE_SAWTOOTH},
125 {"square", Effect::WAVE_SQUARE},
126};
127
128StringMap<Effect::Waveform, Effect::WAVE_MAX_ENUM> Effect::waveforms(Effect::waveformEntries, sizeof(Effect::waveformEntries));
129
130/*
131StringMap<Effect::Direction, Effect::DIR_MAX_ENUM>::Entry Effect::directionEntries[] =
132{
133 {"up", Effect::DIR_UP},
134 {"down", Effect::DIR_DOWN},
135 {"none", Effect::DIR_NONE},
136};
137
138StringMap<Effect::Direction, Effect::DIR_MAX_ENUM> Effect::directions(Effect::directionEntries, sizeof(Effect::directionEntries));
139
140StringMap<Effect::Phoneme, Effect::PHONEME_MAX_ENUM>::Entry Effect::phonemeEntries[] =
141{
142 {"a", Effect::PHONEME_A},
143 {"e", Effect::PHONEME_E},
144 {"i", Effect::PHONEME_I},
145 {"o", Effect::PHONEME_O},
146 {"u", Effect::PHONEME_U},
147 {"aa", Effect::PHONEME_AA},
148 {"ae", Effect::PHONEME_AE},
149 {"ah", Effect::PHONEME_AH},
150 {"ao", Effect::PHONEME_AO},
151 {"eh", Effect::PHONEME_EH},
152 {"er", Effect::PHONEME_ER},
153 {"ih", Effect::PHONEME_IH},
154 {"iy", Effect::PHONEME_IY},
155 {"uh", Effect::PHONEME_UH},
156 {"uw", Effect::PHONEME_UW},
157 {"b", Effect::PHONEME_B},
158 {"d", Effect::PHONEME_D},
159 {"f", Effect::PHONEME_F},
160 {"g", Effect::PHONEME_G},
161 {"j", Effect::PHONEME_J},
162 {"k", Effect::PHONEME_K},
163 {"l", Effect::PHONEME_L},
164 {"m", Effect::PHONEME_M},
165 {"n", Effect::PHONEME_N},
166 {"p", Effect::PHONEME_P},
167 {"r", Effect::PHONEME_R},
168 {"s", Effect::PHONEME_S},
169 {"t", Effect::PHONEME_T},
170 {"v", Effect::PHONEME_V},
171 {"z", Effect::PHONEME_Z},
172};
173
174StringMap<Effect::Phoneme, Effect::PHONEME_MAX_ENUM> Effect::phonemes(Effect::phonemeEntries, sizeof(Effect::phonemeEntries));
175*/
176
177#define StringMap LazierAndSlowerButEasilyArrayableStringMap
178
179std::vector<StringMap<Effect::Parameter>::Entry> Effect::basicParameters =
180{
181 {"type", Effect::EFFECT_TYPE},
182 {"volume", Effect::EFFECT_VOLUME}
183};
184
185std::vector<StringMap<Effect::Parameter>::Entry> Effect::reverbParameters =
186{
187 {"gain", Effect::REVERB_GAIN},
188 {"highgain", Effect::REVERB_HFGAIN},
189 {"density", Effect::REVERB_DENSITY},
190 {"diffusion", Effect::REVERB_DIFFUSION},
191 {"decaytime", Effect::REVERB_DECAY},
192 {"decayhighratio", Effect::REVERB_HFDECAY},
193 {"earlygain", Effect::REVERB_EARLYGAIN},
194 {"earlydelay", Effect::REVERB_EARLYDELAY},
195 {"lategain", Effect::REVERB_LATEGAIN},
196 {"latedelay", Effect::REVERB_LATEDELAY},
197 {"roomrolloff", Effect::REVERB_ROLLOFF},
198 {"airabsorption", Effect::REVERB_AIRHFGAIN},
199 {"highlimit", Effect::REVERB_HFLIMITER}
200};
201
202std::vector<StringMap<Effect::Parameter>::Entry> Effect::chorusParameters =
203{
204 {"waveform", Effect::CHORUS_WAVEFORM},
205 {"phase", Effect::CHORUS_PHASE},
206 {"rate", Effect::CHORUS_RATE},
207 {"depth", Effect::CHORUS_DEPTH},
208 {"feedback", Effect::CHORUS_FEEDBACK},
209 {"delay", Effect::CHORUS_DELAY}
210};
211
212std::vector<StringMap<Effect::Parameter>::Entry> Effect::distortionParameters =
213{
214 {"gain", Effect::DISTORTION_GAIN},
215 {"edge", Effect::DISTORTION_EDGE},
216 {"lowcut", Effect::DISTORTION_LOWCUT},
217 {"center", Effect::DISTORTION_EQCENTER},
218 {"bandwidth", Effect::DISTORTION_EQBAND}
219};
220
221std::vector<StringMap<Effect::Parameter>::Entry> Effect::echoParameters =
222{
223 {"delay", Effect::ECHO_DELAY},
224 {"tapdelay", Effect::ECHO_LRDELAY},
225 {"damping", Effect::ECHO_DAMPING},
226 {"feedback", Effect::ECHO_FEEDBACK},
227 {"spread", Effect::ECHO_SPREAD}
228};
229
230std::vector<StringMap<Effect::Parameter>::Entry> Effect::flangerParameters =
231{
232 {"waveform", Effect::FLANGER_WAVEFORM},
233 {"phase", Effect::FLANGER_PHASE},
234 {"rate", Effect::FLANGER_RATE},
235 {"depth", Effect::FLANGER_DEPTH},
236 {"feedback", Effect::FLANGER_FEEDBACK},
237 {"delay", Effect::FLANGER_DELAY}
238};
239/*
240std::vector<StringMap<Effect::Parameter>::Entry> Effect::freqshifterParameters =
241{
242 {"frequency", Effect::FREQSHIFTER_FREQ},
243 {"leftdirection", Effect::FREQSHIFTER_LEFTDIR},
244 {"rightdirection", Effect::FREQSHIFTER_RIGHTDIR}
245};
246
247std::vector<StringMap<Effect::Parameter>::Entry> Effect::morpherParameters =
248{
249 {"waveform", Effect::MORPHER_WAVEFORM},
250 {"rate", Effect::MORPHER_RATE},
251 {"phonemea", Effect::MORPHER_PHONEMEA},
252 {"phonemeb", Effect::MORPHER_PHONEMEB},
253 {"tunea", Effect::MORPHER_COARSEA},
254 {"tuneb", Effect::MORPHER_COARSEB}
255}
256;
257std::vector<StringMap<Effect::Parameter>::Entry> Effect::pitchshifterParameters =
258{
259 {"pitch", Effect::PITCHSHIFTER_PITCH}
260};
261*/
262std::vector<StringMap<Effect::Parameter>::Entry> Effect::modulatorParameters =
263{
264 {"waveform", Effect::MODULATOR_WAVEFORM},
265 {"frequency", Effect::MODULATOR_FREQ},
266 {"highcut", Effect::MODULATOR_HIGHCUT}
267};
268/*
269std::vector<StringMap<Effect::Parameter>::Entry> Effect::autowahParameters =
270{
271 {"attack", Effect::AUTOWAH_ATTACK},
272 {"release", Effect::AUTOWAH_RELEASE},
273 {"resonance", Effect::AUTOWAH_RESONANCE},
274 {"peakgain", Effect::AUTOWAH_PEAKGAIN}
275};
276*/
277std::vector<StringMap<Effect::Parameter>::Entry> Effect::compressorParameters =
278{
279 {"enable", Effect::COMPRESSOR_ENABLE}
280};
281
282std::vector<StringMap<Effect::Parameter>::Entry> Effect::equalizerParameters =
283{
284 {"lowgain", Effect::EQUALIZER_LOWGAIN},
285 {"lowcut", Effect::EQUALIZER_LOWCUT},
286 {"lowmidgain", Effect::EQUALIZER_MID1GAIN},
287 {"lowmidfrequency", Effect::EQUALIZER_MID1FREQ},
288 {"lowmidbandwidth", Effect::EQUALIZER_MID1BAND},
289 {"highmidgain", Effect::EQUALIZER_MID2GAIN},
290 {"highmidfrequency", Effect::EQUALIZER_MID2FREQ},
291 {"highmidbandwidth", Effect::EQUALIZER_MID2BAND},
292 {"highgain", Effect::EQUALIZER_HIGHGAIN},
293 {"highcut", Effect::EQUALIZER_HIGHCUT}
294};
295
296std::map<Effect::Type, StringMap<Effect::Parameter>> Effect::parameterNames =
297{
298 {Effect::TYPE_BASIC, Effect::basicParameters},
299 {Effect::TYPE_REVERB, Effect::reverbParameters},
300 {Effect::TYPE_CHORUS, Effect::chorusParameters},
301 {Effect::TYPE_DISTORTION, Effect::distortionParameters},
302 {Effect::TYPE_ECHO, Effect::echoParameters},
303 {Effect::TYPE_FLANGER, Effect::flangerParameters},
304 //{Effect::TYPE_FREQSHIFTER, Effect::freqshifterParameters},
305 //{Effect::TYPE_MORPHER, Effect::morpherbParameters},
306 //{Effect::TYPE_PITCHSHIFTER, Effect::pitchshifterParameters},
307 {Effect::TYPE_MODULATOR, Effect::modulatorParameters},
308 //{Effect::TYPE_AUTOWAH, Effect::autowahParameters},
309 {Effect::TYPE_COMPRESSOR, Effect::compressorParameters},
310 {Effect::TYPE_EQUALIZER, Effect::equalizerParameters}
311};
312#undef StringMap
313
314std::map<Effect::Parameter, Effect::ParameterType> Effect::parameterTypes =
315{
316 {Effect::EFFECT_TYPE, Effect::PARAM_TYPE},
317 {Effect::EFFECT_VOLUME, Effect::PARAM_FLOAT},
318
319 {Effect::REVERB_GAIN, Effect::PARAM_FLOAT},
320 {Effect::REVERB_HFGAIN, Effect::PARAM_FLOAT},
321 {Effect::REVERB_DENSITY, Effect::PARAM_FLOAT},
322 {Effect::REVERB_DIFFUSION, Effect::PARAM_FLOAT},
323 {Effect::REVERB_DECAY, Effect::PARAM_FLOAT},
324 {Effect::REVERB_HFDECAY, Effect::PARAM_FLOAT},
325 {Effect::REVERB_EARLYGAIN, Effect::PARAM_FLOAT},
326 {Effect::REVERB_EARLYDELAY, Effect::PARAM_FLOAT},
327 {Effect::REVERB_LATEGAIN, Effect::PARAM_FLOAT},
328 {Effect::REVERB_LATEDELAY, Effect::PARAM_FLOAT},
329 {Effect::REVERB_ROLLOFF, Effect::PARAM_FLOAT},
330 {Effect::REVERB_AIRHFGAIN, Effect::PARAM_FLOAT},
331 {Effect::REVERB_HFLIMITER, Effect::PARAM_BOOL},
332
333 {Effect::CHORUS_WAVEFORM, Effect::PARAM_WAVEFORM},
334 {Effect::CHORUS_PHASE, Effect::PARAM_FLOAT},
335 {Effect::CHORUS_RATE, Effect::PARAM_FLOAT},
336 {Effect::CHORUS_DEPTH, Effect::PARAM_FLOAT},
337 {Effect::CHORUS_FEEDBACK, Effect::PARAM_FLOAT},
338 {Effect::CHORUS_DELAY, Effect::PARAM_FLOAT},
339
340 {Effect::DISTORTION_GAIN, Effect::PARAM_FLOAT},
341 {Effect::DISTORTION_EDGE, Effect::PARAM_FLOAT},
342 {Effect::DISTORTION_LOWCUT, Effect::PARAM_FLOAT},
343 {Effect::DISTORTION_EQCENTER, Effect::PARAM_FLOAT},
344 {Effect::DISTORTION_EQBAND, Effect::PARAM_FLOAT},
345
346 {Effect::ECHO_DELAY, Effect::PARAM_FLOAT},
347 {Effect::ECHO_LRDELAY, Effect::PARAM_FLOAT},
348 {Effect::ECHO_DAMPING, Effect::PARAM_FLOAT},
349 {Effect::ECHO_FEEDBACK, Effect::PARAM_FLOAT},
350 {Effect::ECHO_SPREAD, Effect::PARAM_FLOAT},
351
352 {Effect::FLANGER_WAVEFORM, Effect::PARAM_WAVEFORM},
353 {Effect::FLANGER_PHASE, Effect::PARAM_FLOAT},
354 {Effect::FLANGER_RATE, Effect::PARAM_FLOAT},
355 {Effect::FLANGER_DEPTH, Effect::PARAM_FLOAT},
356 {Effect::FLANGER_FEEDBACK, Effect::PARAM_FLOAT},
357 {Effect::FLANGER_DELAY, Effect::PARAM_FLOAT},
358/*
359 {Effect::FREQSHIFTER_FREQ, Effect::PARAM_FLOAT},
360 {Effect::FREQSHIFTER_LEFTDIR, Effect::PARAM_DIRECTION},
361 {Effect::FREQSHIFTER_RIGHTDIR, Effect::PARAM_DIRECTION},
362
363 {Effect::MORPHER_WAVEFORM, Effect::PARAM_WAVEFORM},
364 {Effect::MORPHER_RATE, Effect::PARAM_FLOAT},
365 {Effect::MORPHER_PHONEMEA, Effect::PARAM_PHONEME},
366 {Effect::MORPHER_PHONEMEB, Effect::PARAM_PHONEME},
367 {Effect::MORPHER_TUNEA, Effect::PARAM_FLOAT},
368 {Effect::MORPHER_TUNEB, Effect::PARAM_FLOAT},
369
370 {Effect::PITCHSHIFTER_PITCH, Effect::PARAM_FLOAT},
371*/
372 {Effect::MODULATOR_WAVEFORM, Effect::PARAM_WAVEFORM},
373 {Effect::MODULATOR_FREQ, Effect::PARAM_FLOAT},
374 {Effect::MODULATOR_HIGHCUT, Effect::PARAM_FLOAT},
375/*
376 {Effect::AUTOWAH_ATTACK, Effect::PARAM_FLOAT},
377 {Effect::AUTOWAH_RELEASE, Effect::PARAM_FLOAT},
378 {Effect::AUTOWAH_RESONANCE, Effect::PARAM_FLOAT},
379 {Effect::AUTOWAH_PEAKGAIN, Effect::PARAM_FLOAT},
380*/
381 {Effect::COMPRESSOR_ENABLE, Effect::PARAM_BOOL},
382
383 {Effect::EQUALIZER_LOWGAIN, Effect::PARAM_FLOAT},
384 {Effect::EQUALIZER_LOWCUT, Effect::PARAM_FLOAT},
385 {Effect::EQUALIZER_MID1GAIN, Effect::PARAM_FLOAT},
386 {Effect::EQUALIZER_MID1FREQ, Effect::PARAM_FLOAT},
387 {Effect::EQUALIZER_MID1BAND, Effect::PARAM_FLOAT},
388 {Effect::EQUALIZER_MID2GAIN, Effect::PARAM_FLOAT},
389 {Effect::EQUALIZER_MID2FREQ, Effect::PARAM_FLOAT},
390 {Effect::EQUALIZER_MID2BAND, Effect::PARAM_FLOAT},
391 {Effect::EQUALIZER_HIGHGAIN, Effect::PARAM_FLOAT},
392 {Effect::EQUALIZER_HIGHCUT, Effect::PARAM_FLOAT}
393};
394
395} //audio
396} //love
397