🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
5.1 KiB

  1. #include "config.h"
  2. #include "AL/al.h"
  3. #include "AL/efx.h"
  4. #include "alc/effects/base.h"
  5. #include "effects.h"
  6. #ifdef ALSOFT_EAX
  7. #include "alnumeric.h"
  8. #include "al/eax/exception.h"
  9. #include "al/eax/utils.h"
  10. #endif // ALSOFT_EAX
  11. namespace {
  12. void Compressor_setParami(EffectProps *props, ALenum param, int val)
  13. {
  14. switch(param)
  15. {
  16. case AL_COMPRESSOR_ONOFF:
  17. if(!(val >= AL_COMPRESSOR_MIN_ONOFF && val <= AL_COMPRESSOR_MAX_ONOFF))
  18. throw effect_exception{AL_INVALID_VALUE, "Compressor state out of range"};
  19. props->Compressor.OnOff = (val != AL_FALSE);
  20. break;
  21. default:
  22. throw effect_exception{AL_INVALID_ENUM, "Invalid compressor integer property 0x%04x",
  23. param};
  24. }
  25. }
  26. void Compressor_setParamiv(EffectProps *props, ALenum param, const int *vals)
  27. { Compressor_setParami(props, param, vals[0]); }
  28. void Compressor_setParamf(EffectProps*, ALenum param, float)
  29. { throw effect_exception{AL_INVALID_ENUM, "Invalid compressor float property 0x%04x", param}; }
  30. void Compressor_setParamfv(EffectProps*, ALenum param, const float*)
  31. {
  32. throw effect_exception{AL_INVALID_ENUM, "Invalid compressor float-vector property 0x%04x",
  33. param};
  34. }
  35. void Compressor_getParami(const EffectProps *props, ALenum param, int *val)
  36. {
  37. switch(param)
  38. {
  39. case AL_COMPRESSOR_ONOFF:
  40. *val = props->Compressor.OnOff;
  41. break;
  42. default:
  43. throw effect_exception{AL_INVALID_ENUM, "Invalid compressor integer property 0x%04x",
  44. param};
  45. }
  46. }
  47. void Compressor_getParamiv(const EffectProps *props, ALenum param, int *vals)
  48. { Compressor_getParami(props, param, vals); }
  49. void Compressor_getParamf(const EffectProps*, ALenum param, float*)
  50. { throw effect_exception{AL_INVALID_ENUM, "Invalid compressor float property 0x%04x", param}; }
  51. void Compressor_getParamfv(const EffectProps*, ALenum param, float*)
  52. {
  53. throw effect_exception{AL_INVALID_ENUM, "Invalid compressor float-vector property 0x%04x",
  54. param};
  55. }
  56. EffectProps genDefaultProps() noexcept
  57. {
  58. EffectProps props{};
  59. props.Compressor.OnOff = AL_COMPRESSOR_DEFAULT_ONOFF;
  60. return props;
  61. }
  62. } // namespace
  63. DEFINE_ALEFFECT_VTABLE(Compressor);
  64. const EffectProps CompressorEffectProps{genDefaultProps()};
  65. #ifdef ALSOFT_EAX
  66. namespace {
  67. class EaxCompressorEffectException : public EaxException
  68. {
  69. public:
  70. explicit EaxCompressorEffectException(const char* message)
  71. : EaxException{"EAX_COMPRESSOR_EFFECT", message}
  72. {}
  73. }; // EaxCompressorEffectException
  74. class EaxCompressorEffect final : public EaxEffect4<EaxCompressorEffectException, EAXAGCCOMPRESSORPROPERTIES>
  75. {
  76. public:
  77. EaxCompressorEffect(const EaxCall& call);
  78. private:
  79. struct OnOffValidator {
  80. void operator()(unsigned long ulOnOff) const
  81. {
  82. eax_validate_range<Exception>(
  83. "On-Off",
  84. ulOnOff,
  85. EAXAGCCOMPRESSOR_MINONOFF,
  86. EAXAGCCOMPRESSOR_MAXONOFF);
  87. }
  88. }; // OnOffValidator
  89. struct AllValidator {
  90. void operator()(const Props& all) const
  91. {
  92. OnOffValidator{}(all.ulOnOff);
  93. }
  94. }; // AllValidator
  95. void set_defaults(Props& props) override;
  96. void set_efx_on_off() noexcept;
  97. void set_efx_defaults() override;
  98. void get(const EaxCall& call, const Props& props) override;
  99. void set(const EaxCall& call, Props& props) override;
  100. bool commit_props(const Props& props) override;
  101. }; // EaxCompressorEffect
  102. EaxCompressorEffect::EaxCompressorEffect(const EaxCall& call)
  103. : EaxEffect4{AL_EFFECT_COMPRESSOR, call}
  104. {}
  105. void EaxCompressorEffect::set_defaults(Props& props)
  106. {
  107. props.ulOnOff = EAXAGCCOMPRESSOR_DEFAULTONOFF;
  108. }
  109. void EaxCompressorEffect::set_efx_on_off() noexcept
  110. {
  111. const auto on_off = clamp(
  112. static_cast<ALint>(props_.ulOnOff),
  113. AL_COMPRESSOR_MIN_ONOFF,
  114. AL_COMPRESSOR_MAX_ONOFF);
  115. al_effect_props_.Compressor.OnOff = (on_off != AL_FALSE);
  116. }
  117. void EaxCompressorEffect::set_efx_defaults()
  118. {
  119. set_efx_on_off();
  120. }
  121. void EaxCompressorEffect::get(const EaxCall& call, const Props& props)
  122. {
  123. switch(call.get_property_id())
  124. {
  125. case EAXAGCCOMPRESSOR_NONE: break;
  126. case EAXAGCCOMPRESSOR_ALLPARAMETERS: call.set_value<Exception>(props); break;
  127. case EAXAGCCOMPRESSOR_ONOFF: call.set_value<Exception>(props.ulOnOff); break;
  128. default: fail_unknown_property_id();
  129. }
  130. }
  131. void EaxCompressorEffect::set(const EaxCall& call, Props& props)
  132. {
  133. switch(call.get_property_id())
  134. {
  135. case EAXAGCCOMPRESSOR_NONE: break;
  136. case EAXAGCCOMPRESSOR_ALLPARAMETERS: defer<AllValidator>(call, props); break;
  137. case EAXAGCCOMPRESSOR_ONOFF: defer<OnOffValidator>(call, props.ulOnOff); break;
  138. default: fail_unknown_property_id();
  139. }
  140. }
  141. bool EaxCompressorEffect::commit_props(const Props& props)
  142. {
  143. auto is_dirty = false;
  144. if (props_.ulOnOff != props.ulOnOff)
  145. {
  146. is_dirty = true;
  147. set_efx_on_off();
  148. }
  149. return is_dirty;
  150. }
  151. } // namespace
  152. EaxEffectUPtr eax_create_eax_compressor_effect(const EaxCall& call)
  153. {
  154. return eax_create_eax4_effect<EaxCompressorEffect>(call);
  155. }
  156. #endif // ALSOFT_EAX