| 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 "Filter.h" |
| 22 | |
| 23 | namespace love |
| 24 | { |
| 25 | namespace audio |
| 26 | { |
| 27 | |
| 28 | Filter::Filter() |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | Filter::~Filter() |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | Filter::Type Filter::getType() const |
| 37 | { |
| 38 | return type; |
| 39 | } |
| 40 | |
| 41 | bool Filter::getConstant(const char *in, Type &out) |
| 42 | { |
| 43 | return types.find(in, out); |
| 44 | } |
| 45 | |
| 46 | bool Filter::getConstant(Type in, const char *&out) |
| 47 | { |
| 48 | return types.find(in, out); |
| 49 | } |
| 50 | |
| 51 | std::vector<std::string> Filter::getConstants(Type) |
| 52 | { |
| 53 | return types.getNames(); |
| 54 | } |
| 55 | |
| 56 | bool Filter::getConstant(const char *in, Parameter &out, Type t) |
| 57 | { |
| 58 | return parameterNames[t].find(in, out); |
| 59 | } |
| 60 | |
| 61 | bool Filter::getConstant(Parameter in, const char *&out, Type t) |
| 62 | { |
| 63 | return parameterNames[t].find(in, out); |
| 64 | } |
| 65 | |
| 66 | Filter::ParameterType Filter::getParameterType(Parameter in) |
| 67 | { |
| 68 | return parameterTypes[in]; |
| 69 | } |
| 70 | |
| 71 | StringMap<Filter::Type, Filter::TYPE_MAX_ENUM>::Entry Filter::typeEntries[] = |
| 72 | { |
| 73 | {"lowpass" , Filter::TYPE_LOWPASS}, |
| 74 | {"highpass" , Filter::TYPE_HIGHPASS}, |
| 75 | {"bandpass" , Filter::TYPE_BANDPASS}, |
| 76 | }; |
| 77 | |
| 78 | StringMap<Filter::Type, Filter::TYPE_MAX_ENUM> Filter::types(Filter::typeEntries, sizeof(Filter::typeEntries)); |
| 79 | |
| 80 | #define StringMap LazierAndSlowerButEasilyArrayableStringMap2 |
| 81 | std::vector<StringMap<Filter::Parameter>::Entry> Filter::basicParameters = |
| 82 | { |
| 83 | {"type" , Filter::FILTER_TYPE}, |
| 84 | {"volume" , Filter::FILTER_VOLUME} |
| 85 | }; |
| 86 | |
| 87 | std::vector<StringMap<Filter::Parameter>::Entry> Filter::lowpassParameters = |
| 88 | { |
| 89 | {"highgain" , Filter::FILTER_HIGHGAIN} |
| 90 | }; |
| 91 | |
| 92 | std::vector<StringMap<Filter::Parameter>::Entry> Filter::highpassParameters = |
| 93 | { |
| 94 | {"lowgain" , Filter::FILTER_LOWGAIN} |
| 95 | }; |
| 96 | |
| 97 | std::vector<StringMap<Filter::Parameter>::Entry> Filter::bandpassParameters = |
| 98 | { |
| 99 | {"lowgain" , Filter::FILTER_LOWGAIN}, |
| 100 | {"highgain" , Filter::FILTER_HIGHGAIN} |
| 101 | }; |
| 102 | |
| 103 | std::map<Filter::Type, StringMap<Filter::Parameter>> Filter::parameterNames = |
| 104 | { |
| 105 | {Filter::TYPE_BASIC, Filter::basicParameters}, |
| 106 | {Filter::TYPE_LOWPASS, Filter::lowpassParameters}, |
| 107 | {Filter::TYPE_HIGHPASS, Filter::highpassParameters}, |
| 108 | {Filter::TYPE_BANDPASS, Filter::bandpassParameters}, |
| 109 | }; |
| 110 | #undef StringMap |
| 111 | |
| 112 | std::map<Filter::Parameter, Filter::ParameterType> Filter::parameterTypes = |
| 113 | { |
| 114 | {Filter::FILTER_TYPE, Filter::PARAM_TYPE}, |
| 115 | {Filter::FILTER_VOLUME, Filter::PARAM_FLOAT}, |
| 116 | {Filter::FILTER_LOWGAIN, Filter::PARAM_FLOAT}, |
| 117 | {Filter::FILTER_HIGHGAIN, Filter::PARAM_FLOAT} |
| 118 | }; |
| 119 | |
| 120 | } //audio |
| 121 | } //love |
| 122 | |