15 #include "al/auxeffectslot.h"
16 #include "al/source.h"
17 #include "al/effect.h"
19 #include "al/listener.h"
22 #include "core/async_event.h"
23 #include "core/device.h"
24 #include "core/effectslot.h"
25 #include "core/logging.h"
26 #include "core/voice.h"
27 #include "core/voice_change.h"
29 #include "ringbuffer.h"
37 #include "al/eax/exception.h"
38 #include "al/eax/globals.h"
43 using namespace std::placeholders
;
47 /* Default context extensions */
48 constexpr ALchar alExtList
[] =
52 "AL_EXT_EXPONENT_DISTANCE "
55 "AL_EXT_LINEAR_DISTANCE "
58 "AL_EXT_MULAW_BFORMAT "
59 "AL_EXT_MULAW_MCFORMATS "
61 "AL_EXT_source_distance_model "
62 "AL_EXT_SOURCE_RADIUS "
63 "AL_EXT_STEREO_ANGLES "
64 "AL_LOKI_quadriphonic "
66 "AL_SOFTX_bformat_hoa "
67 "AL_SOFT_block_alignment "
68 "AL_SOFT_callback_buffer "
69 "AL_SOFTX_convolution_reverb "
70 "AL_SOFT_deferred_updates "
71 "AL_SOFT_direct_channels "
72 "AL_SOFT_direct_channels_remix "
73 "AL_SOFT_effect_target "
75 "AL_SOFT_gain_clamp_ex "
76 "AL_SOFTX_hold_on_disconnect "
77 "AL_SOFT_loop_points "
78 "AL_SOFTX_map_buffer "
80 "AL_SOFT_source_latency "
81 "AL_SOFT_source_length "
82 "AL_SOFT_source_resampler "
83 "AL_SOFT_source_spatialize "
89 std::atomic
<ALCcontext
*> ALCcontext::sGlobalContext
{nullptr};
91 thread_local ALCcontext
*ALCcontext::sLocalContext
{nullptr};
92 ALCcontext::ThreadCtx::~ThreadCtx()
94 if(ALCcontext
*ctx
{ALCcontext::sLocalContext
})
96 const bool result
{ctx
->releaseIfNoDelete()};
97 ERR("Context %p current for thread being destroyed%s!\n", voidp
{ctx
},
98 result
? "" : ", leak detected");
101 thread_local
ALCcontext::ThreadCtx
ALCcontext::sThreadContext
;
103 ALeffect
ALCcontext::sDefaultEffect
;
107 ALCcontext
*ALCcontext::getThreadContext() noexcept
108 { return sLocalContext
; }
109 void ALCcontext::setThreadContext(ALCcontext
*context
) noexcept
110 { sThreadContext
.set(context
); }
113 ALCcontext::ALCcontext(al::intrusive_ptr
<ALCdevice
> device
)
114 : ContextBase
{device
.get()}, mALDevice
{std::move(device
)}
118 ALCcontext::~ALCcontext()
120 TRACE("Freeing context %p\n", voidp
{this});
122 size_t count
{std::accumulate(mSourceList
.cbegin(), mSourceList
.cend(), size_t{0u},
123 [](size_t cur
, const SourceSubList
&sublist
) noexcept
-> size_t
124 { return cur
+ static_cast<uint
>(al::popcount(~sublist
.FreeMask
)); })};
126 WARN("%zu Source%s not deleted\n", count
, (count
==1)?"":"s");
134 mDefaultSlot
= nullptr;
135 count
= std::accumulate(mEffectSlotList
.cbegin(), mEffectSlotList
.cend(), size_t{0u},
136 [](size_t cur
, const EffectSlotSubList
&sublist
) noexcept
-> size_t
137 { return cur
+ static_cast<uint
>(al::popcount(~sublist
.FreeMask
)); });
139 WARN("%zu AuxiliaryEffectSlot%s not deleted\n", count
, (count
==1)?"":"s");
140 mEffectSlotList
.clear();
144 void ALCcontext::init()
146 if(sDefaultEffect
.type
!= AL_EFFECT_NULL
&& mDevice
->Type
== DeviceType::Playback
)
148 mDefaultSlot
= std::make_unique
<ALeffectslot
>();
149 aluInitEffectPanning(&mDefaultSlot
->mSlot
, this);
152 EffectSlotArray
*auxslots
;
154 auxslots
= EffectSlot::CreatePtrArray(0);
157 auxslots
= EffectSlot::CreatePtrArray(1);
158 (*auxslots
)[0] = &mDefaultSlot
->mSlot
;
159 mDefaultSlot
->mState
= SlotState::Playing
;
161 mActiveAuxSlots
.store(auxslots
, std::memory_order_relaxed
);
165 VoiceChange
*cur
{mVoiceChangeTail
};
166 while(VoiceChange
*next
{cur
->mNext
.load(std::memory_order_relaxed
)})
168 mCurrentVoiceChange
.store(cur
, std::memory_order_relaxed
);
171 mExtensionList
= alExtList
;
174 eax_initialize_extensions();
177 mParams
.Position
= alu::Vector
{0.0f
, 0.0f
, 0.0f
, 1.0f
};
178 mParams
.Matrix
= alu::Matrix::Identity();
179 mParams
.Velocity
= alu::Vector
{};
180 mParams
.Gain
= mListener
.Gain
;
181 mParams
.MetersPerUnit
= mListener
.mMetersPerUnit
;
182 mParams
.AirAbsorptionGainHF
= mAirAbsorptionGainHF
;
183 mParams
.DopplerFactor
= mDopplerFactor
;
184 mParams
.SpeedOfSound
= mSpeedOfSound
* mDopplerVelocity
;
185 mParams
.SourceDistanceModel
= mSourceDistanceModel
;
186 mParams
.mDistanceModel
= mDistanceModel
;
189 mAsyncEvents
= RingBuffer::Create(511, sizeof(AsyncEvent
), false);
190 StartEventThrd(this);
194 mActiveVoiceCount
.store(64, std::memory_order_relaxed
);
197 bool ALCcontext::deinit()
199 if(sLocalContext
== this)
201 WARN("%p released while current on thread\n", voidp
{this});
202 sThreadContext
.set(nullptr);
206 ALCcontext
*origctx
{this};
207 if(sGlobalContext
.compare_exchange_strong(origctx
, nullptr))
211 /* First make sure this context exists in the device's list. */
212 auto *oldarray
= mDevice
->mContexts
.load(std::memory_order_acquire
);
213 if(auto toremove
= static_cast<size_t>(std::count(oldarray
->begin(), oldarray
->end(), this)))
215 using ContextArray
= al::FlexArray
<ContextBase
*>;
216 auto alloc_ctx_array
= [](const size_t count
) -> ContextArray
*
218 if(count
== 0) return &DeviceBase::sEmptyContextArray
;
219 return ContextArray::Create(count
).release();
221 auto *newarray
= alloc_ctx_array(oldarray
->size() - toremove
);
223 /* Copy the current/old context handles to the new array, excluding the
226 std::copy_if(oldarray
->begin(), oldarray
->end(), newarray
->begin(),
227 std::bind(std::not_equal_to
<>{}, _1
, this));
229 /* Store the new context array in the device. Wait for any current mix
230 * to finish before deleting the old array.
232 mDevice
->mContexts
.store(newarray
);
233 if(oldarray
!= &DeviceBase::sEmptyContextArray
)
235 mDevice
->waitForMix();
239 ret
= !newarray
->empty();
242 ret
= !oldarray
->empty();
249 void ALCcontext::applyAllUpdates()
251 /* Tell the mixer to stop applying updates, then wait for any active
252 * updating to finish, before providing updates.
254 mHoldUpdates
.store(true, std::memory_order_release
);
255 while((mUpdateCount
.load(std::memory_order_acquire
)&1) != 0) {
260 eax_apply_deferred();
262 if(std::exchange(mPropsDirty
, false))
263 UpdateContextProps(this);
264 UpdateAllEffectSlotProps(this);
265 UpdateAllSourceProps(this);
267 /* Now with all updates declared, let the mixer continue applying them so
268 * they all happen at once.
270 mHoldUpdates
.store(false, std::memory_order_release
);
276 class ContextException
:
280 explicit ContextException(
283 EaxException
{"EAX_CONTEXT", message
}
286 }; // ContextException
290 void ForEachSource(ALCcontext
*context
, F func
)
292 for(auto &sublist
: context
->mSourceList
)
294 uint64_t usemask
{~sublist
.FreeMask
};
297 const int idx
{al::countr_zero(usemask
)};
298 usemask
&= ~(1_u64
<< idx
);
300 func(sublist
.Sources
[idx
]);
308 bool ALCcontext::eax_is_capable() const noexcept
310 return eax_has_enough_aux_sends();
313 void ALCcontext::eax_uninitialize() noexcept
315 if (!eax_is_initialized_
)
320 eax_is_initialized_
= true;
321 eax_is_tried_
= false;
323 eax_fx_slots_
.uninitialize();
326 ALenum
ALCcontext::eax_eax_set(
327 const GUID
* property_set_id
,
329 ALuint property_source_id
,
330 ALvoid
* property_value
,
331 ALuint property_value_size
)
333 const auto call
= create_eax_call(
339 property_value_size
);
340 eax_initialize(call
);
341 eax_unlock_legacy_fx_slots(call
);
343 switch (call
.get_property_set_id())
345 case EaxCallPropertySetId::context
:
349 case EaxCallPropertySetId::fx_slot
:
350 case EaxCallPropertySetId::fx_slot_effect
:
351 eax_dispatch_fx_slot(call
);
354 case EaxCallPropertySetId::source
:
355 eax_dispatch_source(call
);
359 eax_fail("Unsupported property set id.");
362 static constexpr auto deferred_flag
= 0x80000000u
;
363 if(!(property_id
&deferred_flag
) && !mDeferUpdates
)
369 ALenum
ALCcontext::eax_eax_get(
370 const GUID
* property_set_id
,
372 ALuint property_source_id
,
373 ALvoid
* property_value
,
374 ALuint property_value_size
)
376 const auto call
= create_eax_call(
382 property_value_size
);
383 eax_initialize(call
);
384 eax_unlock_legacy_fx_slots(call
);
386 switch (call
.get_property_set_id())
388 case EaxCallPropertySetId::context
:
392 case EaxCallPropertySetId::fx_slot
:
393 case EaxCallPropertySetId::fx_slot_effect
:
394 eax_dispatch_fx_slot(call
);
397 case EaxCallPropertySetId::source
:
398 eax_dispatch_source(call
);
402 eax_fail("Unsupported property set id.");
408 void ALCcontext::eax_update_filters()
410 ForEachSource(this, std::mem_fn(&ALsource::eax_update_filters
));
413 void ALCcontext::eax_commit_and_update_sources()
415 std::unique_lock
<std::mutex
> source_lock
{mSourceLock
};
416 ForEachSource(this, std::mem_fn(&ALsource::eax_commit_and_update
));
419 void ALCcontext::eax_set_last_error() noexcept
421 eax_last_error_
= EAXERR_INVALID_OPERATION
;
425 void ALCcontext::eax_fail(
428 throw ContextException
{message
};
431 void ALCcontext::eax_initialize_extensions()
433 if (!eax_g_is_enabled
)
438 const auto string_max_capacity
=
439 std::strlen(mExtensionList
) + 1 +
440 std::strlen(eax1_ext_name
) + 1 +
441 std::strlen(eax2_ext_name
) + 1 +
442 std::strlen(eax3_ext_name
) + 1 +
443 std::strlen(eax4_ext_name
) + 1 +
444 std::strlen(eax5_ext_name
) + 1 +
445 std::strlen(eax_x_ram_ext_name
) + 1 +
448 eax_extension_list_
.reserve(string_max_capacity
);
450 if (eax_is_capable())
452 eax_extension_list_
+= eax1_ext_name
;
453 eax_extension_list_
+= ' ';
455 eax_extension_list_
+= eax2_ext_name
;
456 eax_extension_list_
+= ' ';
458 eax_extension_list_
+= eax3_ext_name
;
459 eax_extension_list_
+= ' ';
461 eax_extension_list_
+= eax4_ext_name
;
462 eax_extension_list_
+= ' ';
464 eax_extension_list_
+= eax5_ext_name
;
465 eax_extension_list_
+= ' ';
468 eax_extension_list_
+= eax_x_ram_ext_name
;
469 eax_extension_list_
+= ' ';
471 eax_extension_list_
+= mExtensionList
;
472 mExtensionList
= eax_extension_list_
.c_str();
475 void ALCcontext::eax_initialize(const EaxCall
& call
)
477 if (eax_is_initialized_
)
487 eax_is_tried_
= true;
489 if (!eax_g_is_enabled
)
491 eax_fail("EAX disabled by a configuration.");
494 eax_ensure_compatibility();
496 eax_set_air_absorbtion_hf();
497 eax_update_speaker_configuration();
498 eax_initialize_fx_slots(call
);
499 eax_initialize_sources();
501 eax_is_initialized_
= true;
504 bool ALCcontext::eax_has_no_default_effect_slot() const noexcept
506 return mDefaultSlot
== nullptr;
509 void ALCcontext::eax_ensure_no_default_effect_slot() const
511 if (!eax_has_no_default_effect_slot())
513 eax_fail("There is a default effect slot in the context.");
517 bool ALCcontext::eax_has_enough_aux_sends() const noexcept
519 return mALDevice
->NumAuxSends
>= EAX_MAX_FXSLOTS
;
522 void ALCcontext::eax_ensure_enough_aux_sends() const
524 if (!eax_has_enough_aux_sends())
526 eax_fail("Not enough aux sends.");
530 void ALCcontext::eax_ensure_compatibility()
532 eax_ensure_enough_aux_sends();
535 unsigned long ALCcontext::eax_detect_speaker_configuration() const
537 #define EAX_PREFIX "[EAX_DETECT_SPEAKER_CONFIG]"
539 switch(mDevice
->FmtChans
)
541 case DevFmtMono
: return SPEAKERS_2
;
543 /* Pretend 7.1 if using UHJ output, since they both provide full
544 * horizontal surround.
546 if(mDevice
->mUhjEncoder
)
548 if(mDevice
->Flags
.test(DirectEar
))
551 case DevFmtQuad
: return SPEAKERS_4
;
552 case DevFmtX51
: return SPEAKERS_5
;
553 case DevFmtX61
: return SPEAKERS_6
;
554 case DevFmtX71
: return SPEAKERS_7
;
555 /* 3D7.1 is only compatible with 5.1. This could instead be HEADPHONES to
556 * suggest full-sphere surround sound (like HRTF).
558 case DevFmtX3D71
: return SPEAKERS_5
;
559 /* This could also be HEADPHONES, since headphones-based HRTF and Ambi3D
560 * provide full-sphere surround sound. Depends if apps are more likely to
561 * consider headphones or 7.1 for surround sound support.
563 case DevFmtAmbi3D
: return SPEAKERS_7
;
565 ERR(EAX_PREFIX
"Unexpected device channel format 0x%x.\n", mDevice
->FmtChans
);
571 void ALCcontext::eax_update_speaker_configuration()
573 eax_speaker_config_
= eax_detect_speaker_configuration();
576 void ALCcontext::eax_set_last_error_defaults() noexcept
578 eax_last_error_
= EAX_OK
;
581 void ALCcontext::eax_set_session_defaults() noexcept
583 eax_session_
.ulEAXVersion
= EAXCONTEXT_MINEAXSESSION
;
584 eax_session_
.ulMaxActiveSends
= EAXCONTEXT_DEFAULTMAXACTIVESENDS
;
587 void ALCcontext::eax_set_context_defaults() noexcept
589 eax_
.context
.guidPrimaryFXSlotID
= EAXCONTEXT_DEFAULTPRIMARYFXSLOTID
;
590 eax_
.context
.flDistanceFactor
= EAXCONTEXT_DEFAULTDISTANCEFACTOR
;
591 eax_
.context
.flAirAbsorptionHF
= EAXCONTEXT_DEFAULTAIRABSORPTIONHF
;
592 eax_
.context
.flHFReference
= EAXCONTEXT_DEFAULTHFREFERENCE
;
595 void ALCcontext::eax_set_defaults() noexcept
597 eax_set_last_error_defaults();
598 eax_set_session_defaults();
599 eax_set_context_defaults();
604 void ALCcontext::eax_unlock_legacy_fx_slots(const EaxCall
& call
) noexcept
606 if (call
.get_version() != 5 || eax_are_legacy_fx_slots_unlocked_
)
609 eax_are_legacy_fx_slots_unlocked_
= true;
610 eax_fx_slots_
.unlock_legacy();
613 void ALCcontext::eax_dispatch_fx_slot(const EaxCall
& call
)
615 const auto fx_slot_index
= call
.get_fx_slot_index();
616 if(!fx_slot_index
.has_value())
617 eax_fail("Invalid fx slot index.");
619 auto& fx_slot
= eax_get_fx_slot(*fx_slot_index
);
620 if(fx_slot
.eax_dispatch(call
))
622 std::lock_guard
<std::mutex
> source_lock
{mSourceLock
};
623 eax_update_filters();
627 void ALCcontext::eax_dispatch_source(const EaxCall
& call
)
629 const auto source_id
= call
.get_property_al_name();
631 std::lock_guard
<std::mutex
> source_lock
{mSourceLock
};
633 const auto source
= ALsource::eax_lookup_source(*this, source_id
);
637 eax_fail("Source not found.");
640 source
->eax_dispatch(call
);
643 void ALCcontext::eax_get_primary_fx_slot_id(const EaxCall
& call
)
645 call
.set_value
<ContextException
>(eax_
.context
.guidPrimaryFXSlotID
);
648 void ALCcontext::eax_get_distance_factor(const EaxCall
& call
)
650 call
.set_value
<ContextException
>(eax_
.context
.flDistanceFactor
);
653 void ALCcontext::eax_get_air_absorption_hf(const EaxCall
& call
)
655 call
.set_value
<ContextException
>(eax_
.context
.flAirAbsorptionHF
);
658 void ALCcontext::eax_get_hf_reference(const EaxCall
& call
)
660 call
.set_value
<ContextException
>(eax_
.context
.flHFReference
);
663 void ALCcontext::eax_get_last_error(const EaxCall
& call
)
665 const auto eax_last_error
= eax_last_error_
;
666 eax_last_error_
= EAX_OK
;
667 call
.set_value
<ContextException
>(eax_last_error
);
670 void ALCcontext::eax_get_speaker_config(const EaxCall
& call
)
672 call
.set_value
<ContextException
>(eax_speaker_config_
);
675 void ALCcontext::eax_get_session(const EaxCall
& call
)
677 call
.set_value
<ContextException
>(eax_session_
);
680 void ALCcontext::eax_get_macro_fx_factor(const EaxCall
& call
)
682 call
.set_value
<ContextException
>(eax_
.context
.flMacroFXFactor
);
685 void ALCcontext::eax_get_context_all(const EaxCall
& call
)
687 switch (call
.get_version())
690 call
.set_value
<ContextException
>(static_cast<const EAX40CONTEXTPROPERTIES
&>(eax_
.context
));
694 call
.set_value
<ContextException
>(static_cast<const EAX50CONTEXTPROPERTIES
&>(eax_
.context
));
698 eax_fail("Unsupported EAX version.");
702 void ALCcontext::eax_get(const EaxCall
& call
)
704 switch (call
.get_property_id())
706 case EAXCONTEXT_NONE
:
709 case EAXCONTEXT_ALLPARAMETERS
:
710 eax_get_context_all(call
);
713 case EAXCONTEXT_PRIMARYFXSLOTID
:
714 eax_get_primary_fx_slot_id(call
);
717 case EAXCONTEXT_DISTANCEFACTOR
:
718 eax_get_distance_factor(call
);
721 case EAXCONTEXT_AIRABSORPTIONHF
:
722 eax_get_air_absorption_hf(call
);
725 case EAXCONTEXT_HFREFERENCE
:
726 eax_get_hf_reference(call
);
729 case EAXCONTEXT_LASTERROR
:
730 eax_get_last_error(call
);
733 case EAXCONTEXT_SPEAKERCONFIG
:
734 eax_get_speaker_config(call
);
737 case EAXCONTEXT_EAXSESSION
:
738 eax_get_session(call
);
741 case EAXCONTEXT_MACROFXFACTOR
:
742 eax_get_macro_fx_factor(call
);
746 eax_fail("Unsupported property id.");
750 void ALCcontext::eax_set_primary_fx_slot_id()
752 eax_previous_primary_fx_slot_index_
= eax_primary_fx_slot_index_
;
753 eax_primary_fx_slot_index_
= eax_
.context
.guidPrimaryFXSlotID
;
756 void ALCcontext::eax_set_distance_factor()
758 mListener
.mMetersPerUnit
= eax_
.context
.flDistanceFactor
;
762 void ALCcontext::eax_set_air_absorbtion_hf()
764 mAirAbsorptionGainHF
= level_mb_to_gain(eax_
.context
.flAirAbsorptionHF
);
768 void ALCcontext::eax_set_hf_reference()
773 void ALCcontext::eax_set_macro_fx_factor()
778 void ALCcontext::eax_set_context()
780 eax_set_primary_fx_slot_id();
781 eax_set_distance_factor();
782 eax_set_air_absorbtion_hf();
783 eax_set_hf_reference();
786 void ALCcontext::eax_initialize_fx_slots(const EaxCall
& call
)
788 eax_fx_slots_
.initialize(call
, *this);
789 eax_previous_primary_fx_slot_index_
= eax_
.context
.guidPrimaryFXSlotID
;
790 eax_primary_fx_slot_index_
= eax_
.context
.guidPrimaryFXSlotID
;
793 void ALCcontext::eax_initialize_sources()
795 std::unique_lock
<std::mutex
> source_lock
{mSourceLock
};
796 auto init_source
= [this](ALsource
&source
) noexcept
797 { source
.eax_initialize(this); };
798 ForEachSource(this, init_source
);
801 void ALCcontext::eax_update_sources()
803 std::unique_lock
<std::mutex
> source_lock
{mSourceLock
};
804 auto update_source
= [this](ALsource
&source
)
805 { source
.eax_update(eax_context_shared_dirty_flags_
); };
806 ForEachSource(this, update_source
);
809 void ALCcontext::eax_validate_primary_fx_slot_id(
810 const GUID
& primary_fx_slot_id
)
812 if (primary_fx_slot_id
!= EAX_NULL_GUID
&&
813 primary_fx_slot_id
!= EAXPROPERTYID_EAX40_FXSlot0
&&
814 primary_fx_slot_id
!= EAXPROPERTYID_EAX50_FXSlot0
&&
815 primary_fx_slot_id
!= EAXPROPERTYID_EAX40_FXSlot1
&&
816 primary_fx_slot_id
!= EAXPROPERTYID_EAX50_FXSlot1
&&
817 primary_fx_slot_id
!= EAXPROPERTYID_EAX40_FXSlot2
&&
818 primary_fx_slot_id
!= EAXPROPERTYID_EAX50_FXSlot2
&&
819 primary_fx_slot_id
!= EAXPROPERTYID_EAX40_FXSlot3
&&
820 primary_fx_slot_id
!= EAXPROPERTYID_EAX50_FXSlot3
)
822 eax_fail("Unsupported primary FX slot id.");
826 void ALCcontext::eax_validate_distance_factor(
827 float distance_factor
)
829 eax_validate_range
<ContextException
>(
832 EAXCONTEXT_MINDISTANCEFACTOR
,
833 EAXCONTEXT_MAXDISTANCEFACTOR
);
836 void ALCcontext::eax_validate_air_absorption_hf(
837 float air_absorption_hf
)
839 eax_validate_range
<ContextException
>(
842 EAXCONTEXT_MINAIRABSORPTIONHF
,
843 EAXCONTEXT_MAXAIRABSORPTIONHF
);
846 void ALCcontext::eax_validate_hf_reference(
849 eax_validate_range
<ContextException
>(
852 EAXCONTEXT_MINHFREFERENCE
,
853 EAXCONTEXT_MAXHFREFERENCE
);
856 void ALCcontext::eax_validate_speaker_config(
857 unsigned long speaker_config
)
859 switch (speaker_config
)
870 eax_fail("Unsupported speaker configuration.");
874 void ALCcontext::eax_validate_session_eax_version(
875 unsigned long eax_version
)
884 eax_fail("Unsupported session EAX version.");
888 void ALCcontext::eax_validate_session_max_active_sends(
889 unsigned long max_active_sends
)
891 eax_validate_range
<ContextException
>(
894 EAXCONTEXT_MINMAXACTIVESENDS
,
895 EAXCONTEXT_MAXMAXACTIVESENDS
);
898 void ALCcontext::eax_validate_session(
899 const EAXSESSIONPROPERTIES
& eax_session
)
901 eax_validate_session_eax_version(eax_session
.ulEAXVersion
);
902 eax_validate_session_max_active_sends(eax_session
.ulMaxActiveSends
);
905 void ALCcontext::eax_validate_macro_fx_factor(
906 float macro_fx_factor
)
908 eax_validate_range
<ContextException
>(
911 EAXCONTEXT_MINMACROFXFACTOR
,
912 EAXCONTEXT_MAXMACROFXFACTOR
);
915 void ALCcontext::eax_validate_context_all(
916 const EAX40CONTEXTPROPERTIES
& context_all
)
918 eax_validate_primary_fx_slot_id(context_all
.guidPrimaryFXSlotID
);
919 eax_validate_distance_factor(context_all
.flDistanceFactor
);
920 eax_validate_air_absorption_hf(context_all
.flAirAbsorptionHF
);
921 eax_validate_hf_reference(context_all
.flHFReference
);
924 void ALCcontext::eax_validate_context_all(
925 const EAX50CONTEXTPROPERTIES
& context_all
)
927 eax_validate_context_all(static_cast<const EAX40CONTEXTPROPERTIES
>(context_all
));
928 eax_validate_macro_fx_factor(context_all
.flMacroFXFactor
);
931 void ALCcontext::eax_defer_primary_fx_slot_id(
932 const GUID
& primary_fx_slot_id
)
934 eax_d_
.context
.guidPrimaryFXSlotID
= primary_fx_slot_id
;
936 eax_context_dirty_flags_
.guidPrimaryFXSlotID
=
937 (eax_
.context
.guidPrimaryFXSlotID
!= eax_d_
.context
.guidPrimaryFXSlotID
);
940 void ALCcontext::eax_defer_distance_factor(
941 float distance_factor
)
943 eax_d_
.context
.flDistanceFactor
= distance_factor
;
945 eax_context_dirty_flags_
.flDistanceFactor
=
946 (eax_
.context
.flDistanceFactor
!= eax_d_
.context
.flDistanceFactor
);
949 void ALCcontext::eax_defer_air_absorption_hf(
950 float air_absorption_hf
)
952 eax_d_
.context
.flAirAbsorptionHF
= air_absorption_hf
;
954 eax_context_dirty_flags_
.flAirAbsorptionHF
=
955 (eax_
.context
.flAirAbsorptionHF
!= eax_d_
.context
.flAirAbsorptionHF
);
958 void ALCcontext::eax_defer_hf_reference(
961 eax_d_
.context
.flHFReference
= hf_reference
;
963 eax_context_dirty_flags_
.flHFReference
=
964 (eax_
.context
.flHFReference
!= eax_d_
.context
.flHFReference
);
967 void ALCcontext::eax_defer_macro_fx_factor(
968 float macro_fx_factor
)
970 eax_d_
.context
.flMacroFXFactor
= macro_fx_factor
;
972 eax_context_dirty_flags_
.flMacroFXFactor
=
973 (eax_
.context
.flMacroFXFactor
!= eax_d_
.context
.flMacroFXFactor
);
976 void ALCcontext::eax_defer_context_all(
977 const EAX40CONTEXTPROPERTIES
& context_all
)
979 eax_defer_primary_fx_slot_id(context_all
.guidPrimaryFXSlotID
);
980 eax_defer_distance_factor(context_all
.flDistanceFactor
);
981 eax_defer_air_absorption_hf(context_all
.flAirAbsorptionHF
);
982 eax_defer_hf_reference(context_all
.flHFReference
);
985 void ALCcontext::eax_defer_context_all(
986 const EAX50CONTEXTPROPERTIES
& context_all
)
988 eax_defer_context_all(static_cast<const EAX40CONTEXTPROPERTIES
&>(context_all
));
989 eax_defer_macro_fx_factor(context_all
.flMacroFXFactor
);
992 void ALCcontext::eax_defer_context_all(const EaxCall
& call
)
994 switch(call
.get_version())
998 const auto& context_all
=
999 call
.get_value
<ContextException
, EAX40CONTEXTPROPERTIES
>();
1001 eax_validate_context_all(context_all
);
1002 eax_defer_context_all(context_all
);
1008 const auto& context_all
=
1009 call
.get_value
<ContextException
, EAX50CONTEXTPROPERTIES
>();
1011 eax_validate_context_all(context_all
);
1012 eax_defer_context_all(context_all
);
1017 eax_fail("Unsupported EAX version.");
1021 void ALCcontext::eax_defer_primary_fx_slot_id(const EaxCall
& call
)
1023 const auto& primary_fx_slot_id
=
1024 call
.get_value
<ContextException
, const decltype(EAX50CONTEXTPROPERTIES::guidPrimaryFXSlotID
)>();
1026 eax_validate_primary_fx_slot_id(primary_fx_slot_id
);
1027 eax_defer_primary_fx_slot_id(primary_fx_slot_id
);
1030 void ALCcontext::eax_defer_distance_factor(const EaxCall
& call
)
1032 const auto& distance_factor
=
1033 call
.get_value
<ContextException
, const decltype(EAX50CONTEXTPROPERTIES::flDistanceFactor
)>();
1035 eax_validate_distance_factor(distance_factor
);
1036 eax_defer_distance_factor(distance_factor
);
1039 void ALCcontext::eax_defer_air_absorption_hf(const EaxCall
& call
)
1041 const auto& air_absorption_hf
=
1042 call
.get_value
<ContextException
, const decltype(EAX50CONTEXTPROPERTIES::flAirAbsorptionHF
)>();
1044 eax_validate_air_absorption_hf(air_absorption_hf
);
1045 eax_defer_air_absorption_hf(air_absorption_hf
);
1048 void ALCcontext::eax_defer_hf_reference(const EaxCall
& call
)
1050 const auto& hf_reference
=
1051 call
.get_value
<ContextException
, const decltype(EAX50CONTEXTPROPERTIES::flHFReference
)>();
1053 eax_validate_hf_reference(hf_reference
);
1054 eax_defer_hf_reference(hf_reference
);
1057 void ALCcontext::eax_set_session(const EaxCall
& call
)
1059 const auto& eax_session
=
1060 call
.get_value
<ContextException
, const EAXSESSIONPROPERTIES
>();
1062 eax_validate_session(eax_session
);
1064 eax_session_
= eax_session
;
1067 void ALCcontext::eax_defer_macro_fx_factor(const EaxCall
& call
)
1069 const auto& macro_fx_factor
=
1070 call
.get_value
<ContextException
, const decltype(EAX50CONTEXTPROPERTIES::flMacroFXFactor
)>();
1072 eax_validate_macro_fx_factor(macro_fx_factor
);
1073 eax_defer_macro_fx_factor(macro_fx_factor
);
1076 void ALCcontext::eax_set(const EaxCall
& call
)
1078 switch (call
.get_property_id())
1080 case EAXCONTEXT_NONE
:
1083 case EAXCONTEXT_ALLPARAMETERS
:
1084 eax_defer_context_all(call
);
1087 case EAXCONTEXT_PRIMARYFXSLOTID
:
1088 eax_defer_primary_fx_slot_id(call
);
1091 case EAXCONTEXT_DISTANCEFACTOR
:
1092 eax_defer_distance_factor(call
);
1095 case EAXCONTEXT_AIRABSORPTIONHF
:
1096 eax_defer_air_absorption_hf(call
);
1099 case EAXCONTEXT_HFREFERENCE
:
1100 eax_defer_hf_reference(call
);
1103 case EAXCONTEXT_LASTERROR
:
1104 eax_fail("Last error is read-only.");
1106 case EAXCONTEXT_SPEAKERCONFIG
:
1107 eax_fail("Speaker configuration is read-only.");
1109 case EAXCONTEXT_EAXSESSION
:
1110 eax_set_session(call
);
1113 case EAXCONTEXT_MACROFXFACTOR
:
1114 eax_defer_macro_fx_factor(call
);
1118 eax_fail("Unsupported property id.");
1122 void ALCcontext::eax_apply_deferred()
1124 if (eax_context_dirty_flags_
== ContextDirtyFlags
{})
1131 if (eax_context_dirty_flags_
.guidPrimaryFXSlotID
)
1133 eax_context_shared_dirty_flags_
.primary_fx_slot_id
= true;
1134 eax_set_primary_fx_slot_id();
1137 if (eax_context_dirty_flags_
.flDistanceFactor
)
1139 eax_set_distance_factor();
1142 if (eax_context_dirty_flags_
.flAirAbsorptionHF
)
1144 eax_set_air_absorbtion_hf();
1147 if (eax_context_dirty_flags_
.flHFReference
)
1149 eax_set_hf_reference();
1152 if (eax_context_dirty_flags_
.flMacroFXFactor
)
1154 eax_set_macro_fx_factor();
1157 if (eax_context_shared_dirty_flags_
!= EaxContextSharedDirtyFlags
{})
1159 eax_update_sources();
1162 eax_context_shared_dirty_flags_
= EaxContextSharedDirtyFlags
{};
1163 eax_context_dirty_flags_
= ContextDirtyFlags
{};
1171 class EaxSetException
:
1175 explicit EaxSetException(
1176 const char* message
)
1178 EaxException
{"EAX_SET", message
}
1181 }; // EaxSetException
1186 const char* message
)
1188 throw EaxSetException
{message
};
1192 class EaxGetException
:
1196 explicit EaxGetException(
1197 const char* message
)
1199 EaxException
{"EAX_GET", message
}
1202 }; // EaxGetException
1207 const char* message
)
1209 throw EaxGetException
{message
};
1216 FORCE_ALIGN ALenum AL_APIENTRY
EAXSet(
1217 const GUID
* property_set_id
,
1219 ALuint property_source_id
,
1220 ALvoid
* property_value
,
1221 ALuint property_value_size
) noexcept
1224 auto context
= GetContextRef();
1228 eax_fail_set("No current context.");
1231 std::lock_guard
<std::mutex
> prop_lock
{context
->mPropLock
};
1233 return context
->eax_eax_set(
1243 eax_log_exception(__func__
);
1244 return AL_INVALID_OPERATION
;
1247 FORCE_ALIGN ALenum AL_APIENTRY
EAXGet(
1248 const GUID
* property_set_id
,
1250 ALuint property_source_id
,
1251 ALvoid
* property_value
,
1252 ALuint property_value_size
) noexcept
1255 auto context
= GetContextRef();
1259 eax_fail_get("No current context.");
1262 std::lock_guard
<std::mutex
> prop_lock
{context
->mPropLock
};
1264 return context
->eax_eax_get(
1274 eax_log_exception(__func__
);
1275 return AL_INVALID_OPERATION
;
1277 #endif // ALSOFT_EAX