call.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. : mCallType{type}, mIsDeferred{(property_id & deferred_flag) != 0}
  21. , mPropertyId{property_id & ~deferred_flag}, mPropertySourceId{property_source_id}
  22. , mPropertyBuffer{property_buffer}, mPropertyBufferSize{property_size}
  23. {
  24. switch(mCallType)
  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. mVersion = 4;
  38. mPropertySetId = EaxCallPropertySetId::context;
  39. }
  40. else if (property_set_guid == EAXPROPERTYID_EAX50_Context)
  41. {
  42. mVersion = 5;
  43. mPropertySetId = EaxCallPropertySetId::context;
  44. }
  45. else if (property_set_guid == DSPROPSETID_EAX20_ListenerProperties)
  46. {
  47. mVersion = 2;
  48. mFxSlotIndex = 0u;
  49. mPropertySetId = EaxCallPropertySetId::fx_slot_effect;
  50. }
  51. else if (property_set_guid == DSPROPSETID_EAX30_ListenerProperties)
  52. {
  53. mVersion = 3;
  54. mFxSlotIndex = 0u;
  55. mPropertySetId = EaxCallPropertySetId::fx_slot_effect;
  56. }
  57. else if (property_set_guid == EAXPROPERTYID_EAX40_FXSlot0)
  58. {
  59. mVersion = 4;
  60. mFxSlotIndex = 0u;
  61. mPropertySetId = EaxCallPropertySetId::fx_slot;
  62. }
  63. else if (property_set_guid == EAXPROPERTYID_EAX50_FXSlot0)
  64. {
  65. mVersion = 5;
  66. mFxSlotIndex = 0u;
  67. mPropertySetId = EaxCallPropertySetId::fx_slot;
  68. }
  69. else if (property_set_guid == EAXPROPERTYID_EAX40_FXSlot1)
  70. {
  71. mVersion = 4;
  72. mFxSlotIndex = 1u;
  73. mPropertySetId = EaxCallPropertySetId::fx_slot;
  74. }
  75. else if (property_set_guid == EAXPROPERTYID_EAX50_FXSlot1)
  76. {
  77. mVersion = 5;
  78. mFxSlotIndex = 1u;
  79. mPropertySetId = EaxCallPropertySetId::fx_slot;
  80. }
  81. else if (property_set_guid == EAXPROPERTYID_EAX40_FXSlot2)
  82. {
  83. mVersion = 4;
  84. mFxSlotIndex = 2u;
  85. mPropertySetId = EaxCallPropertySetId::fx_slot;
  86. }
  87. else if (property_set_guid == EAXPROPERTYID_EAX50_FXSlot2)
  88. {
  89. mVersion = 5;
  90. mFxSlotIndex = 2u;
  91. mPropertySetId = EaxCallPropertySetId::fx_slot;
  92. }
  93. else if (property_set_guid == EAXPROPERTYID_EAX40_FXSlot3)
  94. {
  95. mVersion = 4;
  96. mFxSlotIndex = 3u;
  97. mPropertySetId = EaxCallPropertySetId::fx_slot;
  98. }
  99. else if (property_set_guid == EAXPROPERTYID_EAX50_FXSlot3)
  100. {
  101. mVersion = 5;
  102. mFxSlotIndex = 3u;
  103. mPropertySetId = EaxCallPropertySetId::fx_slot;
  104. }
  105. else if (property_set_guid == DSPROPSETID_EAX20_BufferProperties)
  106. {
  107. mVersion = 2;
  108. mPropertySetId = EaxCallPropertySetId::source;
  109. }
  110. else if (property_set_guid == DSPROPSETID_EAX30_BufferProperties)
  111. {
  112. mVersion = 3;
  113. mPropertySetId = EaxCallPropertySetId::source;
  114. }
  115. else if (property_set_guid == EAXPROPERTYID_EAX40_Source)
  116. {
  117. mVersion = 4;
  118. mPropertySetId = EaxCallPropertySetId::source;
  119. }
  120. else if (property_set_guid == EAXPROPERTYID_EAX50_Source)
  121. {
  122. mVersion = 5;
  123. mPropertySetId = EaxCallPropertySetId::source;
  124. }
  125. else if (property_set_guid == DSPROPSETID_EAX_ReverbProperties)
  126. {
  127. mVersion = 1;
  128. mFxSlotIndex = 0u;
  129. mPropertySetId = EaxCallPropertySetId::fx_slot_effect;
  130. }
  131. else if (property_set_guid == DSPROPSETID_EAXBUFFER_ReverbProperties)
  132. {
  133. mVersion = 1;
  134. mPropertySetId = EaxCallPropertySetId::source;
  135. }
  136. else
  137. {
  138. fail("Unsupported property set id.");
  139. }
  140. switch(mPropertyId)
  141. {
  142. case EAXCONTEXT_LASTERROR:
  143. case EAXCONTEXT_SPEAKERCONFIG:
  144. case EAXCONTEXT_EAXSESSION:
  145. case EAXFXSLOT_NONE:
  146. case EAXFXSLOT_ALLPARAMETERS:
  147. case EAXFXSLOT_LOADEFFECT:
  148. case EAXFXSLOT_VOLUME:
  149. case EAXFXSLOT_LOCK:
  150. case EAXFXSLOT_FLAGS:
  151. case EAXFXSLOT_OCCLUSION:
  152. case EAXFXSLOT_OCCLUSIONLFRATIO:
  153. // EAX allow to set "defer" flag on immediate-only properties.
  154. // If we don't clear our flag then "applyAllUpdates" in EAX context won't be called.
  155. mIsDeferred = false;
  156. break;
  157. }
  158. if(!mIsDeferred)
  159. {
  160. if(mPropertySetId != EaxCallPropertySetId::fx_slot && mPropertyId != 0)
  161. {
  162. if(mPropertyBuffer == nullptr)
  163. fail("Null property buffer.");
  164. if(mPropertyBufferSize == 0)
  165. fail("Empty property.");
  166. }
  167. }
  168. if(mPropertySetId == EaxCallPropertySetId::source && mPropertySourceId == 0)
  169. fail("Null AL source id.");
  170. if(mPropertySetId == EaxCallPropertySetId::fx_slot)
  171. {
  172. if(mPropertyId < EAXFXSLOT_NONE)
  173. mPropertySetId = EaxCallPropertySetId::fx_slot_effect;
  174. }
  175. }
  176. [[noreturn]] void EaxCall::fail(const char* message)
  177. {
  178. throw EaxCallException{message};
  179. }
  180. [[noreturn]] void EaxCall::fail_too_small()
  181. {
  182. fail("Property buffer too small.");
  183. }
  184. EaxCall create_eax_call(
  185. EaxCallType type,
  186. const GUID* property_set_id,
  187. ALuint property_id,
  188. ALuint property_source_id,
  189. ALvoid* property_buffer,
  190. ALuint property_size)
  191. {
  192. if(!property_set_id)
  193. throw EaxCallException{"Null property set ID."};
  194. return EaxCall{
  195. type,
  196. *property_set_id,
  197. property_id,
  198. property_source_id,
  199. property_buffer,
  200. property_size
  201. };
  202. }