Define the CoreAudio default name only when needed
[openal-soft.git] / al / eax_eax_call.cpp
blobdfd7f7f718fe980a6fadb16d151474c2b5de3efb
1 #include "config.h"
3 #include "al/eax_eax_call.h"
5 #include "al/eax_exception.h"
8 namespace {
10 constexpr auto deferred_flag = 0x80000000U;
12 class EaxEaxCallException :
13 public EaxException
15 public:
16 explicit EaxEaxCallException(
17 const char* message)
19 EaxException{"EAX_EAX_CALL", message}
22 }; // EaxEaxCallException
24 } // namespace
27 EaxEaxCall::EaxEaxCall(
28 bool is_get,
29 const GUID& property_set_guid,
30 ALuint property_id,
31 ALuint property_source_id,
32 ALvoid* property_buffer,
33 ALuint property_size)
34 : is_get_{is_get}, is_deferred_{(property_id&deferred_flag) != 0}, version_{0}
35 , property_set_id_{EaxEaxCallPropertySetId::none}, property_id_{property_id & ~deferred_flag}
36 , property_source_id_{property_source_id}, property_buffer_{property_buffer}
37 , property_size_{property_size}
39 if (false)
42 else if (property_set_guid == EAXPROPERTYID_EAX40_Context)
44 version_ = 4;
45 property_set_id_ = EaxEaxCallPropertySetId::context;
47 else if (property_set_guid == EAXPROPERTYID_EAX50_Context)
49 version_ = 5;
50 property_set_id_ = EaxEaxCallPropertySetId::context;
52 else if (property_set_guid == DSPROPSETID_EAX20_ListenerProperties)
54 version_ = 2;
55 fx_slot_index_ = 0u;
56 property_set_id_ = EaxEaxCallPropertySetId::fx_slot_effect;
57 property_id_ = convert_eax_v2_0_listener_property_id(property_id_);
59 else if (property_set_guid == DSPROPSETID_EAX30_ListenerProperties)
61 version_ = 3;
62 fx_slot_index_ = 0u;
63 property_set_id_ = EaxEaxCallPropertySetId::fx_slot_effect;
65 else if (property_set_guid == EAXPROPERTYID_EAX40_FXSlot0)
67 version_ = 4;
68 fx_slot_index_ = 0u;
69 property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
71 else if (property_set_guid == EAXPROPERTYID_EAX50_FXSlot0)
73 version_ = 5;
74 fx_slot_index_ = 0u;
75 property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
77 else if (property_set_guid == EAXPROPERTYID_EAX40_FXSlot1)
79 version_ = 4;
80 fx_slot_index_ = 1u;
81 property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
83 else if (property_set_guid == EAXPROPERTYID_EAX50_FXSlot1)
85 version_ = 5;
86 fx_slot_index_ = 1u;
87 property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
89 else if (property_set_guid == EAXPROPERTYID_EAX40_FXSlot2)
91 version_ = 4;
92 fx_slot_index_ = 2u;
93 property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
95 else if (property_set_guid == EAXPROPERTYID_EAX50_FXSlot2)
97 version_ = 5;
98 fx_slot_index_ = 2u;
99 property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
101 else if (property_set_guid == EAXPROPERTYID_EAX40_FXSlot3)
103 version_ = 4;
104 fx_slot_index_ = 3u;
105 property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
107 else if (property_set_guid == EAXPROPERTYID_EAX50_FXSlot3)
109 version_ = 5;
110 fx_slot_index_ = 3u;
111 property_set_id_ = EaxEaxCallPropertySetId::fx_slot;
113 else if (property_set_guid == DSPROPSETID_EAX20_BufferProperties)
115 version_ = 2;
116 property_set_id_ = EaxEaxCallPropertySetId::source;
117 property_id_ = convert_eax_v2_0_buffer_property_id(property_id_);
119 else if (property_set_guid == DSPROPSETID_EAX30_BufferProperties)
121 version_ = 3;
122 property_set_id_ = EaxEaxCallPropertySetId::source;
124 else if (property_set_guid == EAXPROPERTYID_EAX40_Source)
126 version_ = 4;
127 property_set_id_ = EaxEaxCallPropertySetId::source;
129 else if (property_set_guid == EAXPROPERTYID_EAX50_Source)
131 version_ = 5;
132 property_set_id_ = EaxEaxCallPropertySetId::source;
134 else if (property_set_guid == DSPROPSETID_EAX_ReverbProperties)
136 version_ = 1;
137 fx_slot_index_ = 0u;
138 property_set_id_ = EaxEaxCallPropertySetId::fx_slot_effect;
140 else if (property_set_guid == DSPROPSETID_EAXBUFFER_ReverbProperties)
142 version_ = 1;
143 property_set_id_ = EaxEaxCallPropertySetId::source;
145 else
147 fail("Unsupported property set id.");
150 if (version_ < 1 || version_ > 5)
152 fail("EAX version out of range.");
155 if (is_deferred_)
157 if (version_ == 1)
159 fail("EAX1 does not support deferring.");
162 else
164 if (property_set_id_ != EaxEaxCallPropertySetId::fx_slot &&
165 property_id_ != 0)
167 if (!property_buffer)
169 fail("Null property buffer.");
172 if (property_size == 0)
174 fail("Empty property.");
179 if (property_set_id_ == EaxEaxCallPropertySetId::source &&
180 property_source_id_ == 0)
182 fail("Null AL source id.");
185 if (property_set_id_ == EaxEaxCallPropertySetId::fx_slot)
187 if (property_id_ < EAXFXSLOT_NONE)
189 property_set_id_ = EaxEaxCallPropertySetId::fx_slot_effect;
194 [[noreturn]]
195 void EaxEaxCall::fail(
196 const char* message)
198 throw EaxEaxCallException{message};
201 ALuint EaxEaxCall::convert_eax_v2_0_listener_property_id(
202 ALuint property_id)
204 switch (property_id)
206 case DSPROPERTY_EAX20LISTENER_NONE:
207 return EAXREVERB_NONE;
209 case DSPROPERTY_EAX20LISTENER_ALLPARAMETERS:
210 return EAXREVERB_ALLPARAMETERS;
212 case DSPROPERTY_EAX20LISTENER_ROOM:
213 return EAXREVERB_ROOM;
215 case DSPROPERTY_EAX20LISTENER_ROOMHF:
216 return EAXREVERB_ROOMHF;
218 case DSPROPERTY_EAX20LISTENER_ROOMROLLOFFFACTOR:
219 return EAXREVERB_ROOMROLLOFFFACTOR;
221 case DSPROPERTY_EAX20LISTENER_DECAYTIME:
222 return EAXREVERB_DECAYTIME;
224 case DSPROPERTY_EAX20LISTENER_DECAYHFRATIO:
225 return EAXREVERB_DECAYHFRATIO;
227 case DSPROPERTY_EAX20LISTENER_REFLECTIONS:
228 return EAXREVERB_REFLECTIONS;
230 case DSPROPERTY_EAX20LISTENER_REFLECTIONSDELAY:
231 return EAXREVERB_REFLECTIONSDELAY;
233 case DSPROPERTY_EAX20LISTENER_REVERB:
234 return EAXREVERB_REVERB;
236 case DSPROPERTY_EAX20LISTENER_REVERBDELAY:
237 return EAXREVERB_REVERBDELAY;
239 case DSPROPERTY_EAX20LISTENER_ENVIRONMENT:
240 return EAXREVERB_ENVIRONMENT;
242 case DSPROPERTY_EAX20LISTENER_ENVIRONMENTSIZE:
243 return EAXREVERB_ENVIRONMENTSIZE;
245 case DSPROPERTY_EAX20LISTENER_ENVIRONMENTDIFFUSION:
246 return EAXREVERB_ENVIRONMENTDIFFUSION;
248 case DSPROPERTY_EAX20LISTENER_AIRABSORPTIONHF:
249 return EAXREVERB_AIRABSORPTIONHF;
251 case DSPROPERTY_EAX20LISTENER_FLAGS:
252 return EAXREVERB_FLAGS;
254 default:
255 fail("Unsupported EAX 2.0 listener property id.");
259 ALuint EaxEaxCall::convert_eax_v2_0_buffer_property_id(
260 ALuint property_id)
262 switch (property_id)
264 case DSPROPERTY_EAX20BUFFER_NONE:
265 return EAXSOURCE_NONE;
267 case DSPROPERTY_EAX20BUFFER_ALLPARAMETERS:
268 return EAXSOURCE_ALLPARAMETERS;
270 case DSPROPERTY_EAX20BUFFER_DIRECT:
271 return EAXSOURCE_DIRECT;
273 case DSPROPERTY_EAX20BUFFER_DIRECTHF:
274 return EAXSOURCE_DIRECTHF;
276 case DSPROPERTY_EAX20BUFFER_ROOM:
277 return EAXSOURCE_ROOM;
279 case DSPROPERTY_EAX20BUFFER_ROOMHF:
280 return EAXSOURCE_ROOMHF;
282 case DSPROPERTY_EAX20BUFFER_ROOMROLLOFFFACTOR:
283 return EAXSOURCE_ROOMROLLOFFFACTOR;
285 case DSPROPERTY_EAX20BUFFER_OBSTRUCTION:
286 return EAXSOURCE_OBSTRUCTION;
288 case DSPROPERTY_EAX20BUFFER_OBSTRUCTIONLFRATIO:
289 return EAXSOURCE_OBSTRUCTIONLFRATIO;
291 case DSPROPERTY_EAX20BUFFER_OCCLUSION:
292 return EAXSOURCE_OCCLUSION;
294 case DSPROPERTY_EAX20BUFFER_OCCLUSIONLFRATIO:
295 return EAXSOURCE_OCCLUSIONLFRATIO;
297 case DSPROPERTY_EAX20BUFFER_OCCLUSIONROOMRATIO:
298 return EAXSOURCE_OCCLUSIONROOMRATIO;
300 case DSPROPERTY_EAX20BUFFER_OUTSIDEVOLUMEHF:
301 return EAXSOURCE_OUTSIDEVOLUMEHF;
303 case DSPROPERTY_EAX20BUFFER_AIRABSORPTIONFACTOR:
304 return EAXSOURCE_AIRABSORPTIONFACTOR;
306 case DSPROPERTY_EAX20BUFFER_FLAGS:
307 return EAXSOURCE_FLAGS;
309 default:
310 fail("Unsupported EAX 2.0 buffer property id.");
315 EaxEaxCall create_eax_call(
316 bool is_get,
317 const GUID* property_set_id,
318 ALuint property_id,
319 ALuint property_source_id,
320 ALvoid* property_buffer,
321 ALuint property_size)
323 if(!property_set_id)
324 throw EaxEaxCallException{"Null property set ID."};
326 return EaxEaxCall{
327 is_get,
328 *property_set_id,
329 property_id,
330 property_source_id,
331 property_buffer,
332 property_size