distortion.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "config.h"
  2. #include "AL/al.h"
  3. #include "AL/efx.h"
  4. #include "effects.h"
  5. #include "effects/base.h"
  6. namespace {
  7. void Distortion_setParami(EffectProps*, ALenum param, int)
  8. { throw effect_exception{AL_INVALID_ENUM, "Invalid distortion integer property 0x%04x", param}; }
  9. void Distortion_setParamiv(EffectProps*, ALenum param, const int*)
  10. {
  11. throw effect_exception{AL_INVALID_ENUM, "Invalid distortion integer-vector property 0x%04x",
  12. param};
  13. }
  14. void Distortion_setParamf(EffectProps *props, ALenum param, float val)
  15. {
  16. switch(param)
  17. {
  18. case AL_DISTORTION_EDGE:
  19. if(!(val >= AL_DISTORTION_MIN_EDGE && val <= AL_DISTORTION_MAX_EDGE))
  20. throw effect_exception{AL_INVALID_VALUE, "Distortion edge out of range"};
  21. props->Distortion.Edge = val;
  22. break;
  23. case AL_DISTORTION_GAIN:
  24. if(!(val >= AL_DISTORTION_MIN_GAIN && val <= AL_DISTORTION_MAX_GAIN))
  25. throw effect_exception{AL_INVALID_VALUE, "Distortion gain out of range"};
  26. props->Distortion.Gain = val;
  27. break;
  28. case AL_DISTORTION_LOWPASS_CUTOFF:
  29. if(!(val >= AL_DISTORTION_MIN_LOWPASS_CUTOFF && val <= AL_DISTORTION_MAX_LOWPASS_CUTOFF))
  30. throw effect_exception{AL_INVALID_VALUE, "Distortion low-pass cutoff out of range"};
  31. props->Distortion.LowpassCutoff = val;
  32. break;
  33. case AL_DISTORTION_EQCENTER:
  34. if(!(val >= AL_DISTORTION_MIN_EQCENTER && val <= AL_DISTORTION_MAX_EQCENTER))
  35. throw effect_exception{AL_INVALID_VALUE, "Distortion EQ center out of range"};
  36. props->Distortion.EQCenter = val;
  37. break;
  38. case AL_DISTORTION_EQBANDWIDTH:
  39. if(!(val >= AL_DISTORTION_MIN_EQBANDWIDTH && val <= AL_DISTORTION_MAX_EQBANDWIDTH))
  40. throw effect_exception{AL_INVALID_VALUE, "Distortion EQ bandwidth out of range"};
  41. props->Distortion.EQBandwidth = val;
  42. break;
  43. default:
  44. throw effect_exception{AL_INVALID_ENUM, "Invalid distortion float property 0x%04x", param};
  45. }
  46. }
  47. void Distortion_setParamfv(EffectProps *props, ALenum param, const float *vals)
  48. { Distortion_setParamf(props, param, vals[0]); }
  49. void Distortion_getParami(const EffectProps*, ALenum param, int*)
  50. { throw effect_exception{AL_INVALID_ENUM, "Invalid distortion integer property 0x%04x", param}; }
  51. void Distortion_getParamiv(const EffectProps*, ALenum param, int*)
  52. {
  53. throw effect_exception{AL_INVALID_ENUM, "Invalid distortion integer-vector property 0x%04x",
  54. param};
  55. }
  56. void Distortion_getParamf(const EffectProps *props, ALenum param, float *val)
  57. {
  58. switch(param)
  59. {
  60. case AL_DISTORTION_EDGE:
  61. *val = props->Distortion.Edge;
  62. break;
  63. case AL_DISTORTION_GAIN:
  64. *val = props->Distortion.Gain;
  65. break;
  66. case AL_DISTORTION_LOWPASS_CUTOFF:
  67. *val = props->Distortion.LowpassCutoff;
  68. break;
  69. case AL_DISTORTION_EQCENTER:
  70. *val = props->Distortion.EQCenter;
  71. break;
  72. case AL_DISTORTION_EQBANDWIDTH:
  73. *val = props->Distortion.EQBandwidth;
  74. break;
  75. default:
  76. throw effect_exception{AL_INVALID_ENUM, "Invalid distortion float property 0x%04x", param};
  77. }
  78. }
  79. void Distortion_getParamfv(const EffectProps *props, ALenum param, float *vals)
  80. { Distortion_getParamf(props, param, vals); }
  81. EffectProps genDefaultProps() noexcept
  82. {
  83. EffectProps props{};
  84. props.Distortion.Edge = AL_DISTORTION_DEFAULT_EDGE;
  85. props.Distortion.Gain = AL_DISTORTION_DEFAULT_GAIN;
  86. props.Distortion.LowpassCutoff = AL_DISTORTION_DEFAULT_LOWPASS_CUTOFF;
  87. props.Distortion.EQCenter = AL_DISTORTION_DEFAULT_EQCENTER;
  88. props.Distortion.EQBandwidth = AL_DISTORTION_DEFAULT_EQBANDWIDTH;
  89. return props;
  90. }
  91. } // namespace
  92. DEFINE_ALEFFECT_VTABLE(Distortion);
  93. const EffectProps DistortionEffectProps{genDefaultProps()};