Filter.cpp 3.0 KB

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