autowah.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "config.h"
  2. #include <cmath>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include "AL/efx.h"
  6. #include "effects/base.h"
  7. #include "effects.h"
  8. namespace {
  9. void Autowah_setParamf(EffectProps *props, ALenum param, float val)
  10. {
  11. switch(param)
  12. {
  13. case AL_AUTOWAH_ATTACK_TIME:
  14. if(!(val >= AL_AUTOWAH_MIN_ATTACK_TIME && val <= AL_AUTOWAH_MAX_ATTACK_TIME))
  15. throw effect_exception{AL_INVALID_VALUE, "Autowah attack time out of range"};
  16. props->Autowah.AttackTime = val;
  17. break;
  18. case AL_AUTOWAH_RELEASE_TIME:
  19. if(!(val >= AL_AUTOWAH_MIN_RELEASE_TIME && val <= AL_AUTOWAH_MAX_RELEASE_TIME))
  20. throw effect_exception{AL_INVALID_VALUE, "Autowah release time out of range"};
  21. props->Autowah.ReleaseTime = val;
  22. break;
  23. case AL_AUTOWAH_RESONANCE:
  24. if(!(val >= AL_AUTOWAH_MIN_RESONANCE && val <= AL_AUTOWAH_MAX_RESONANCE))
  25. throw effect_exception{AL_INVALID_VALUE, "Autowah resonance out of range"};
  26. props->Autowah.Resonance = val;
  27. break;
  28. case AL_AUTOWAH_PEAK_GAIN:
  29. if(!(val >= AL_AUTOWAH_MIN_PEAK_GAIN && val <= AL_AUTOWAH_MAX_PEAK_GAIN))
  30. throw effect_exception{AL_INVALID_VALUE, "Autowah peak gain out of range"};
  31. props->Autowah.PeakGain = val;
  32. break;
  33. default:
  34. throw effect_exception{AL_INVALID_ENUM, "Invalid autowah float property 0x%04x", param};
  35. }
  36. }
  37. void Autowah_setParamfv(EffectProps *props, ALenum param, const float *vals)
  38. { Autowah_setParamf(props, param, vals[0]); }
  39. void Autowah_setParami(EffectProps*, ALenum param, int)
  40. { throw effect_exception{AL_INVALID_ENUM, "Invalid autowah integer property 0x%04x", param}; }
  41. void Autowah_setParamiv(EffectProps*, ALenum param, const int*)
  42. {
  43. throw effect_exception{AL_INVALID_ENUM, "Invalid autowah integer vector property 0x%04x",
  44. param};
  45. }
  46. void Autowah_getParamf(const EffectProps *props, ALenum param, float *val)
  47. {
  48. switch(param)
  49. {
  50. case AL_AUTOWAH_ATTACK_TIME:
  51. *val = props->Autowah.AttackTime;
  52. break;
  53. case AL_AUTOWAH_RELEASE_TIME:
  54. *val = props->Autowah.ReleaseTime;
  55. break;
  56. case AL_AUTOWAH_RESONANCE:
  57. *val = props->Autowah.Resonance;
  58. break;
  59. case AL_AUTOWAH_PEAK_GAIN:
  60. *val = props->Autowah.PeakGain;
  61. break;
  62. default:
  63. throw effect_exception{AL_INVALID_ENUM, "Invalid autowah float property 0x%04x", param};
  64. }
  65. }
  66. void Autowah_getParamfv(const EffectProps *props, ALenum param, float *vals)
  67. { Autowah_getParamf(props, param, vals); }
  68. void Autowah_getParami(const EffectProps*, ALenum param, int*)
  69. { throw effect_exception{AL_INVALID_ENUM, "Invalid autowah integer property 0x%04x", param}; }
  70. void Autowah_getParamiv(const EffectProps*, ALenum param, int*)
  71. {
  72. throw effect_exception{AL_INVALID_ENUM, "Invalid autowah integer vector property 0x%04x",
  73. param};
  74. }
  75. EffectProps genDefaultProps() noexcept
  76. {
  77. EffectProps props{};
  78. props.Autowah.AttackTime = AL_AUTOWAH_DEFAULT_ATTACK_TIME;
  79. props.Autowah.ReleaseTime = AL_AUTOWAH_DEFAULT_RELEASE_TIME;
  80. props.Autowah.Resonance = AL_AUTOWAH_DEFAULT_RESONANCE;
  81. props.Autowah.PeakGain = AL_AUTOWAH_DEFAULT_PEAK_GAIN;
  82. return props;
  83. }
  84. } // namespace
  85. DEFINE_ALEFFECT_VTABLE(Autowah);
  86. const EffectProps AutowahEffectProps{genDefaultProps()};