Filter.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * Copyright (c) 2006-2025 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. std::vector<std::string> Filter::getConstants(Type)
  44. {
  45. return types.getNames();
  46. }
  47. bool Filter::getConstant(const char *in, Parameter &out, Type t)
  48. {
  49. return parameterNames[t].find(in, out);
  50. }
  51. bool Filter::getConstant(Parameter in, const char *&out, Type t)
  52. {
  53. return parameterNames[t].find(in, out);
  54. }
  55. Filter::ParameterType Filter::getParameterType(Parameter in)
  56. {
  57. return parameterTypes[in];
  58. }
  59. StringMap<Filter::Type, Filter::TYPE_MAX_ENUM>::Entry Filter::typeEntries[] =
  60. {
  61. {"lowpass", Filter::TYPE_LOWPASS},
  62. {"highpass", Filter::TYPE_HIGHPASS},
  63. {"bandpass", Filter::TYPE_BANDPASS},
  64. };
  65. StringMap<Filter::Type, Filter::TYPE_MAX_ENUM> Filter::types(Filter::typeEntries, sizeof(Filter::typeEntries));
  66. #define StringMap LazierAndSlowerButEasilyArrayableStringMap2
  67. std::vector<StringMap<Filter::Parameter>::Entry> Filter::basicParameters =
  68. {
  69. {"type", Filter::FILTER_TYPE},
  70. {"volume", Filter::FILTER_VOLUME}
  71. };
  72. std::vector<StringMap<Filter::Parameter>::Entry> Filter::lowpassParameters =
  73. {
  74. {"highgain", Filter::FILTER_HIGHGAIN}
  75. };
  76. std::vector<StringMap<Filter::Parameter>::Entry> Filter::highpassParameters =
  77. {
  78. {"lowgain", Filter::FILTER_LOWGAIN}
  79. };
  80. std::vector<StringMap<Filter::Parameter>::Entry> Filter::bandpassParameters =
  81. {
  82. {"lowgain", Filter::FILTER_LOWGAIN},
  83. {"highgain", Filter::FILTER_HIGHGAIN}
  84. };
  85. std::map<Filter::Type, StringMap<Filter::Parameter>> Filter::parameterNames =
  86. {
  87. {Filter::TYPE_BASIC, Filter::basicParameters},
  88. {Filter::TYPE_LOWPASS, Filter::lowpassParameters},
  89. {Filter::TYPE_HIGHPASS, Filter::highpassParameters},
  90. {Filter::TYPE_BANDPASS, Filter::bandpassParameters},
  91. };
  92. #undef StringMap
  93. std::map<Filter::Parameter, Filter::ParameterType> Filter::parameterTypes =
  94. {
  95. {Filter::FILTER_TYPE, Filter::PARAM_TYPE},
  96. {Filter::FILTER_VOLUME, Filter::PARAM_FLOAT},
  97. {Filter::FILTER_LOWGAIN, Filter::PARAM_FLOAT},
  98. {Filter::FILTER_HIGHGAIN, Filter::PARAM_FLOAT}
  99. };
  100. } //audio
  101. } //love