convolution.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "config.h"
  2. #include <algorithm>
  3. #include <array>
  4. #include <cmath>
  5. #include "AL/al.h"
  6. #include "alc/inprogext.h"
  7. #include "alnumeric.h"
  8. #include "alspan.h"
  9. #include "core/effects/base.h"
  10. #include "effects.h"
  11. namespace {
  12. constexpr EffectProps genDefaultProps() noexcept
  13. {
  14. ConvolutionProps props{};
  15. props.OrientAt = {0.0f, 0.0f, -1.0f};
  16. props.OrientUp = {0.0f, 1.0f, 0.0f};
  17. return props;
  18. }
  19. } // namespace
  20. const EffectProps ConvolutionEffectProps{genDefaultProps()};
  21. void ConvolutionEffectHandler::SetParami(ConvolutionProps& /*props*/, ALenum param, int /*val*/)
  22. {
  23. switch(param)
  24. {
  25. default:
  26. throw effect_exception{AL_INVALID_ENUM, "Invalid convolution effect integer property 0x%04x",
  27. param};
  28. }
  29. }
  30. void ConvolutionEffectHandler::SetParamiv(ConvolutionProps &props, ALenum param, const int *vals)
  31. {
  32. switch(param)
  33. {
  34. default:
  35. SetParami(props, param, *vals);
  36. }
  37. }
  38. void ConvolutionEffectHandler::SetParamf(ConvolutionProps& /*props*/, ALenum param, float /*val*/)
  39. {
  40. switch(param)
  41. {
  42. default:
  43. throw effect_exception{AL_INVALID_ENUM, "Invalid convolution effect float property 0x%04x",
  44. param};
  45. }
  46. }
  47. void ConvolutionEffectHandler::SetParamfv(ConvolutionProps &props, ALenum param, const float *values)
  48. {
  49. static constexpr auto finite_checker = [](float val) -> bool { return std::isfinite(val); };
  50. al::span<const float> vals;
  51. switch(param)
  52. {
  53. case AL_CONVOLUTION_ORIENTATION_SOFT:
  54. vals = {values, 6_uz};
  55. if(!std::all_of(vals.cbegin(), vals.cend(), finite_checker))
  56. throw effect_exception{AL_INVALID_VALUE, "Property 0x%04x value out of range", param};
  57. std::copy_n(vals.cbegin(), props.OrientAt.size(), props.OrientAt.begin());
  58. std::copy_n(vals.cbegin()+3, props.OrientUp.size(), props.OrientUp.begin());
  59. break;
  60. default:
  61. SetParamf(props, param, *values);
  62. }
  63. }
  64. void ConvolutionEffectHandler::GetParami(const ConvolutionProps& /*props*/, ALenum param, int* /*val*/)
  65. {
  66. switch(param)
  67. {
  68. default:
  69. throw effect_exception{AL_INVALID_ENUM, "Invalid convolution effect integer property 0x%04x",
  70. param};
  71. }
  72. }
  73. void ConvolutionEffectHandler::GetParamiv(const ConvolutionProps &props, ALenum param, int *vals)
  74. {
  75. switch(param)
  76. {
  77. default:
  78. GetParami(props, param, vals);
  79. }
  80. }
  81. void ConvolutionEffectHandler::GetParamf(const ConvolutionProps& /*props*/, ALenum param, float* /*val*/)
  82. {
  83. switch(param)
  84. {
  85. default:
  86. throw effect_exception{AL_INVALID_ENUM, "Invalid convolution effect float property 0x%04x",
  87. param};
  88. }
  89. }
  90. void ConvolutionEffectHandler::GetParamfv(const ConvolutionProps &props, ALenum param, float *values)
  91. {
  92. al::span<float> vals;
  93. switch(param)
  94. {
  95. case AL_CONVOLUTION_ORIENTATION_SOFT:
  96. vals = {values, 6_uz};
  97. std::copy(props.OrientAt.cbegin(), props.OrientAt.cend(), vals.begin());
  98. std::copy(props.OrientUp.cbegin(), props.OrientUp.cend(), vals.begin()+3);
  99. break;
  100. default:
  101. GetParamf(props, param, values);
  102. }
  103. }