🛠️🐜 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.

212 lines
5.5 KiB

  1. #include "config.h"
  2. #include "call.h"
  3. #include "exception.h"
  4. namespace {
  5. constexpr auto deferred_flag = 0x80000000U;
  6. class EaxCallException : public EaxException {
  7. public:
  8. explicit EaxCallException(const char* message)
  9. : EaxException{"EAX_CALL", message}
  10. {}
  11. }; // EaxCallException
  12. } // namespace
  13. EaxCall::EaxCall(
  14. EaxCallType type,
  15. const GUID& property_set_guid,
  16. ALuint property_id,
  17. ALuint property_source_id,
  18. ALvoid* property_buffer,
  19. ALuint property_size)
  20. : type_{type}, version_{0}, property_set_id_{EaxCallPropertySetId::none}
  21. , property_id_{property_id & ~deferred_flag}, property_source_id_{property_source_id}
  22. , property_buffer_{property_buffer}, property_size_{property_size}
  23. {
  24. switch (type_)
  25. {
  26. case EaxCallType::get:
  27. case EaxCallType::set:
  28. break;
  29. default:
  30. fail("Invalid type.");
  31. }
  32. if (false)
  33. {
  34. }
  35. else if (property_set_guid == EAXPROPERTYID_EAX40_Context)
  36. {
  37. version_ = 4;
  38. property_set_id_ = EaxCallPropertySetId::context;
  39. }
  40. else if (property_set_guid == EAXPROPERTYID_EAX50_Context)
  41. {
  42. version_ = 5;
  43. property_set_id_ = EaxCallPropertySetId::context;
  44. }
  45. else if (property_set_guid == DSPROPSETID_EAX20_ListenerProperties)
  46. {
  47. version_ = 2;
  48. fx_slot_index_ = 0u;
  49. property_set_id_ = EaxCallPropertySetId::fx_slot_effect;
  50. }
  51. else if (property_set_guid == DSPROPSETID_EAX30_ListenerProperties)
  52. {
  53. version_ = 3;
  54. fx_slot_index_ = 0u;
  55. property_set_id_ = EaxCallPropertySetId::fx_slot_effect;
  56. }
  57. else if (property_set_guid == EAXPROPERTYID_EAX40_FXSlot0)
  58. {
  59. version_ = 4;
  60. fx_slot_index_ = 0u;
  61. property_set_id_ = EaxCallPropertySetId::fx_slot;
  62. }
  63. else if (property_set_guid == EAXPROPERTYID_EAX50_FXSlot0)
  64. {
  65. version_ = 5;
  66. fx_slot_index_ = 0u;
  67. property_set_id_ = EaxCallPropertySetId::fx_slot;
  68. }
  69. else if (property_set_guid == EAXPROPERTYID_EAX40_FXSlot1)
  70. {
  71. version_ = 4;
  72. fx_slot_index_ = 1u;
  73. property_set_id_ = EaxCallPropertySetId::fx_slot;
  74. }
  75. else if (property_set_guid == EAXPROPERTYID_EAX50_FXSlot1)
  76. {
  77. version_ = 5;
  78. fx_slot_index_ = 1u;
  79. property_set_id_ = EaxCallPropertySetId::fx_slot;
  80. }
  81. else if (property_set_guid == EAXPROPERTYID_EAX40_FXSlot2)
  82. {
  83. version_ = 4;
  84. fx_slot_index_ = 2u;
  85. property_set_id_ = EaxCallPropertySetId::fx_slot;
  86. }
  87. else if (property_set_guid == EAXPROPERTYID_EAX50_FXSlot2)
  88. {
  89. version_ = 5;
  90. fx_slot_index_ = 2u;
  91. property_set_id_ = EaxCallPropertySetId::fx_slot;
  92. }
  93. else if (property_set_guid == EAXPROPERTYID_EAX40_FXSlot3)
  94. {
  95. version_ = 4;
  96. fx_slot_index_ = 3u;
  97. property_set_id_ = EaxCallPropertySetId::fx_slot;
  98. }
  99. else if (property_set_guid == EAXPROPERTYID_EAX50_FXSlot3)
  100. {
  101. version_ = 5;
  102. fx_slot_index_ = 3u;
  103. property_set_id_ = EaxCallPropertySetId::fx_slot;
  104. }
  105. else if (property_set_guid == DSPROPSETID_EAX20_BufferProperties)
  106. {
  107. version_ = 2;
  108. property_set_id_ = EaxCallPropertySetId::source;
  109. }
  110. else if (property_set_guid == DSPROPSETID_EAX30_BufferProperties)
  111. {
  112. version_ = 3;
  113. property_set_id_ = EaxCallPropertySetId::source;
  114. }
  115. else if (property_set_guid == EAXPROPERTYID_EAX40_Source)
  116. {
  117. version_ = 4;
  118. property_set_id_ = EaxCallPropertySetId::source;
  119. }
  120. else if (property_set_guid == EAXPROPERTYID_EAX50_Source)
  121. {
  122. version_ = 5;
  123. property_set_id_ = EaxCallPropertySetId::source;
  124. }
  125. else if (property_set_guid == DSPROPSETID_EAX_ReverbProperties)
  126. {
  127. version_ = 1;
  128. fx_slot_index_ = 0u;
  129. property_set_id_ = EaxCallPropertySetId::fx_slot_effect;
  130. }
  131. else if (property_set_guid == DSPROPSETID_EAXBUFFER_ReverbProperties)
  132. {
  133. version_ = 1;
  134. property_set_id_ = EaxCallPropertySetId::source;
  135. }
  136. else
  137. {
  138. fail("Unsupported property set id.");
  139. }
  140. if (version_ < 1 || version_ > 5)
  141. {
  142. fail("EAX version out of range.");
  143. }
  144. if(!(property_id&deferred_flag))
  145. {
  146. if(property_set_id_ != EaxCallPropertySetId::fx_slot && property_id_ != 0)
  147. {
  148. if (property_buffer == nullptr)
  149. {
  150. fail("Null property buffer.");
  151. }
  152. if (property_size == 0)
  153. {
  154. fail("Empty property.");
  155. }
  156. }
  157. }
  158. if(property_set_id_ == EaxCallPropertySetId::source && property_source_id_ == 0)
  159. {
  160. fail("Null AL source id.");
  161. }
  162. if (property_set_id_ == EaxCallPropertySetId::fx_slot)
  163. {
  164. if (property_id_ < EAXFXSLOT_NONE)
  165. {
  166. property_set_id_ = EaxCallPropertySetId::fx_slot_effect;
  167. }
  168. }
  169. }
  170. [[noreturn]] void EaxCall::fail(const char* message)
  171. {
  172. throw EaxCallException{message};
  173. }
  174. [[noreturn]] void EaxCall::fail_too_small()
  175. {
  176. fail("Property buffer too small.");
  177. }
  178. EaxCall create_eax_call(
  179. EaxCallType type,
  180. const GUID* property_set_id,
  181. ALuint property_id,
  182. ALuint property_source_id,
  183. ALvoid* property_buffer,
  184. ALuint property_size)
  185. {
  186. if(!property_set_id)
  187. throw EaxCallException{"Null property set ID."};
  188. return EaxCall{
  189. type,
  190. *property_set_id,
  191. property_id,
  192. property_source_id,
  193. property_buffer,
  194. property_size
  195. };
  196. }