diff options
author | Sven Göthel <[email protected]> | 2024-01-05 13:52:12 +0100 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-01-05 13:52:12 +0100 |
commit | ec98cdacc85ff0202852472c7756586437912f22 (patch) | |
tree | 42414746a27ab35cb8cdbc95af521d74821e57f4 /core/context.h | |
parent | fd5269bec9a5fe4815974b1786a037e6a247bfd2 (diff) | |
parent | b82cd2e60edb8fbe5fdd3567105ae76a016a554c (diff) |
Diffstat (limited to 'core/context.h')
-rw-r--r-- | core/context.h | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/core/context.h b/core/context.h index ccb7dd3b..980514b3 100644 --- a/core/context.h +++ b/core/context.h @@ -14,6 +14,7 @@ #include "alspan.h" #include "async_event.h" #include "atomic.h" +#include "flexarray.h" #include "opthelpers.h" #include "vecmat.h" @@ -26,9 +27,9 @@ struct VoiceChange; struct VoicePropsItem; -constexpr float SpeedOfSoundMetersPerSec{343.3f}; +inline constexpr float SpeedOfSoundMetersPerSec{343.3f}; -constexpr float AirAbsorbGainHF{0.99426f}; /* -0.05dB */ +inline constexpr float AirAbsorbGainHF{0.99426f}; /* -0.05dB */ enum class DistanceModel : unsigned char { Disable, @@ -56,8 +57,6 @@ struct ContextProps { DistanceModel mDistanceModel; std::atomic<ContextProps*> next; - - DEF_NEWDEL(ContextProps) }; struct ContextParams { @@ -85,7 +84,7 @@ struct ContextBase { /* Counter for the pre-mixing updates, in 31.1 fixed point (lowest bit * indicates if updates are currently happening). */ - RefCount mUpdateCount{0u}; + std::atomic<unsigned int> mUpdateCount{0u}; std::atomic<bool> mHoldUpdates{false}; std::atomic<bool> mStopVoicesOnDisconnect{true}; @@ -96,7 +95,7 @@ struct ContextBase { */ std::atomic<ContextProps*> mFreeContextProps{nullptr}; std::atomic<VoicePropsItem*> mFreeVoiceProps{nullptr}; - std::atomic<EffectSlotProps*> mFreeEffectslotProps{nullptr}; + std::atomic<EffectSlotProps*> mFreeEffectSlotProps{nullptr}; /* The voice change tail is the beginning of the "free" elements, up to and * *excluding* the current. If tail==current, there's no free elements and @@ -108,21 +107,22 @@ struct ContextBase { void allocVoiceChanges(); void allocVoiceProps(); - + void allocEffectSlotProps(); + void allocContextProps(); ContextParams mParams; using VoiceArray = al::FlexArray<Voice*>; - std::atomic<VoiceArray*> mVoices{}; + al::atomic_unique_ptr<VoiceArray> mVoices{}; std::atomic<size_t> mActiveVoiceCount{}; void allocVoices(size_t addcount); - al::span<Voice*> getVoicesSpan() const noexcept + [[nodiscard]] auto getVoicesSpan() const noexcept -> al::span<Voice*> { return {mVoices.load(std::memory_order_relaxed)->data(), mActiveVoiceCount.load(std::memory_order_relaxed)}; } - al::span<Voice*> getVoicesSpanAcquired() const noexcept + [[nodiscard]] auto getVoicesSpanAcquired() const noexcept -> al::span<Voice*> { return {mVoices.load(std::memory_order_acquire)->data(), mActiveVoiceCount.load(std::memory_order_acquire)}; @@ -143,22 +143,30 @@ struct ContextBase { * However, to avoid allocating each object individually, they're allocated * in clusters that are stored in a vector for easy automatic cleanup. */ - using VoiceChangeCluster = std::unique_ptr<VoiceChange[]>; + using VoiceChangeCluster = std::unique_ptr<std::array<VoiceChange,128>>; std::vector<VoiceChangeCluster> mVoiceChangeClusters; - using VoiceCluster = std::unique_ptr<Voice[]>; + using VoiceCluster = std::unique_ptr<std::array<Voice,32>>; std::vector<VoiceCluster> mVoiceClusters; - using VoicePropsCluster = std::unique_ptr<VoicePropsItem[]>; + using VoicePropsCluster = std::unique_ptr<std::array<VoicePropsItem,32>>; std::vector<VoicePropsCluster> mVoicePropClusters; - static constexpr size_t EffectSlotClusterSize{4}; EffectSlot *getEffectSlot(); - using EffectSlotCluster = std::unique_ptr<EffectSlot[]>; + using EffectSlotCluster = std::unique_ptr<std::array<EffectSlot,4>>; std::vector<EffectSlotCluster> mEffectSlotClusters; + using EffectSlotPropsCluster = std::unique_ptr<std::array<EffectSlotProps,4>>; + std::vector<EffectSlotPropsCluster> mEffectSlotPropClusters; + + /* This could be greater than 2, but there should be no way there can be + * more than two context property updates in use simultaneously. + */ + using ContextPropsCluster = std::unique_ptr<std::array<ContextProps,2>>; + std::vector<ContextPropsCluster> mContextPropClusters; + ContextBase(DeviceBase *device); ContextBase(const ContextBase&) = delete; |