From 963d9b761b53c270fc8b7e91e32b2fe7b79b51be Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 28 Mar 2020 17:20:38 -0700 Subject: Rename ALvoice and related structs to Voice --- al/source.cpp | 90 ++++++++++++++++++++++++++++----------------------------- alc/alc.cpp | 25 ++++++++-------- alc/alcontext.h | 16 +++++----- alc/alu.cpp | 65 ++++++++++++++++++++--------------------- alc/voice.cpp | 26 ++++++++--------- alc/voice.h | 24 +++++++-------- 6 files changed, 122 insertions(+), 124 deletions(-) diff --git a/al/source.cpp b/al/source.cpp index 3d3e3d8c..57ad151d 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -76,14 +76,14 @@ namespace { using namespace std::placeholders; using std::chrono::nanoseconds; -ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context) +Voice *GetSourceVoice(ALsource *source, ALCcontext *context) { auto voicelist = context->getVoicesSpan(); ALuint idx{source->VoiceIdx}; if(idx < voicelist.size()) { ALuint sid{source->id}; - ALvoice *voice = voicelist[idx]; + Voice *voice = voicelist[idx]; if(voice->mSourceID.load(std::memory_order_acquire) == sid) return voice; } @@ -92,15 +92,15 @@ ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context) } -void UpdateSourceProps(const ALsource *source, ALvoice *voice, ALCcontext *context) +void UpdateSourceProps(const ALsource *source, Voice *voice, ALCcontext *context) { /* Get an unused property container, or allocate a new one as needed. */ - ALvoiceProps *props{context->mFreeVoiceProps.load(std::memory_order_acquire)}; + VoicePropsItem *props{context->mFreeVoiceProps.load(std::memory_order_acquire)}; if(!props) - props = new ALvoiceProps{}; + props = new VoicePropsItem{}; else { - ALvoiceProps *next; + VoicePropsItem *next; do { next = props->next.load(std::memory_order_relaxed); } while(context->mFreeVoiceProps.compare_exchange_weak(props, next, @@ -147,9 +147,9 @@ void UpdateSourceProps(const ALsource *source, ALvoice *voice, ALCcontext *conte props->Direct.GainLF = source->Direct.GainLF; props->Direct.LFReference = source->Direct.LFReference; - auto copy_send = [](const ALsource::SendData &srcsend) noexcept -> ALvoicePropsBase::SendData + auto copy_send = [](const ALsource::SendData &srcsend) noexcept -> VoiceProps::SendData { - ALvoicePropsBase::SendData ret; + VoiceProps::SendData ret; ret.Slot = srcsend.Slot; ret.Gain = srcsend.Gain; ret.GainHF = srcsend.GainHF; @@ -183,7 +183,7 @@ int64_t GetSourceSampleOffset(ALsource *Source, ALCcontext *context, nanoseconds const ALbufferlistitem *Current{}; uint64_t readPos{}; ALuint refcount; - ALvoice *voice; + Voice *voice; do { refcount = device->waitForMix(); @@ -223,7 +223,7 @@ double GetSourceSecOffset(ALsource *Source, ALCcontext *context, nanoseconds *cl const ALbufferlistitem *Current{}; uint64_t readPos{}; ALuint refcount; - ALvoice *voice; + Voice *voice; do { refcount = device->waitForMix(); @@ -273,7 +273,7 @@ double GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context) ALuint readPos{}; ALuint readPosFrac{}; ALuint refcount; - ALvoice *voice; + Voice *voice; do { refcount = device->waitForMix(); @@ -435,7 +435,7 @@ al::optional GetSampleOffset(ALbufferlistitem *BufferList, ALenum Offs } -void InitVoice(ALvoice *voice, ALsource *source, ALbufferlistitem *BufferList, ALCcontext *context, +void InitVoice(Voice *voice, ALsource *source, ALbufferlistitem *BufferList, ALCcontext *context, ALCdevice *device) { voice->mLoopBuffer.store(source->Looping ? source->queue : nullptr, std::memory_order_relaxed); @@ -459,7 +459,7 @@ void InitVoice(ALvoice *voice, ALsource *source, ALbufferlistitem *BufferList, A voice->mStep = 0; if(voice->mChans.capacity() > 2 && num_channels < voice->mChans.capacity()) - al::vector{}.swap(voice->mChans); + al::vector{}.swap(voice->mChans); voice->mChans.reserve(maxu(2, num_channels)); voice->mChans.resize(num_channels); @@ -545,7 +545,7 @@ void SendVoiceChanges(ALCcontext *ctx, VoiceChange *tail) while(VoiceChange *next{cur->mNext.load(std::memory_order_acquire)}) { cur = next; - if(ALvoice *voice{cur->mVoice}) + if(Voice *voice{cur->mVoice}) voice->mSourceID.store(0, std::memory_order_relaxed); } ctx->mCurrentVoiceChange.store(cur, std::memory_order_release); @@ -553,16 +553,16 @@ void SendVoiceChanges(ALCcontext *ctx, VoiceChange *tail) } -bool SetVoiceOffset(ALvoice *oldvoice, const VoicePos &vpos, ALsource *source, ALCcontext *context, +bool SetVoiceOffset(Voice *oldvoice, const VoicePos &vpos, ALsource *source, ALCcontext *context, ALCdevice *device) { /* First, get a free voice to start at the new offset. */ auto voicelist = context->getVoicesSpan(); - ALvoice *newvoice{}; + Voice *newvoice{}; ALuint vidx{0}; - for(ALvoice *voice : voicelist) + for(Voice *voice : voicelist) { - if(voice->mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped + if(voice->mPlayState.load(std::memory_order_acquire) == Voice::Stopped && voice->mSourceID.load(std::memory_order_relaxed) == 0u && voice->mPendingChange.load(std::memory_order_relaxed) == false) { @@ -580,9 +580,9 @@ bool SetVoiceOffset(ALvoice *oldvoice, const VoicePos &vpos, ALsource *source, A voicelist = context->getVoicesSpan(); vidx = 0; - for(ALvoice *voice : voicelist) + for(Voice *voice : voicelist) { - if(voice->mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped + if(voice->mPlayState.load(std::memory_order_acquire) == Voice::Stopped && voice->mSourceID.load(std::memory_order_relaxed) == 0u && voice->mPendingChange.load(std::memory_order_relaxed) == false) { @@ -600,7 +600,7 @@ bool SetVoiceOffset(ALvoice *oldvoice, const VoicePos &vpos, ALsource *source, A * voice to the source and its position-dependent properties (including the * fading flag). */ - newvoice->mPlayState.store(ALvoice::Pending, std::memory_order_relaxed); + newvoice->mPlayState.store(Voice::Pending, std::memory_order_relaxed); newvoice->mPosition.store(vpos.pos, std::memory_order_relaxed); newvoice->mPositionFrac.store(vpos.frac, std::memory_order_relaxed); newvoice->mCurrentBuffer.store(vpos.bufferitem, std::memory_order_relaxed); @@ -630,12 +630,12 @@ bool SetVoiceOffset(ALvoice *oldvoice, const VoicePos &vpos, ALsource *source, A /* Otherwise, if the new voice's state is not pending, the change-over * already happened. */ - if(newvoice->mPlayState.load(std::memory_order_acquire) != ALvoice::Pending) + if(newvoice->mPlayState.load(std::memory_order_acquire) != Voice::Pending) return true; /* Otherwise, wait for any current mix to finish and check one last time. */ device->waitForMix(); - if(newvoice->mPlayState.load(std::memory_order_acquire) != ALvoice::Pending) + if(newvoice->mPlayState.load(std::memory_order_acquire) != Voice::Pending) return true; /* The change-over failed because the old voice stopped before the new * voice could start at the new offset. Let go of the new voice and have @@ -644,7 +644,7 @@ bool SetVoiceOffset(ALvoice *oldvoice, const VoicePos &vpos, ALsource *source, A newvoice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed); newvoice->mLoopBuffer.store(nullptr, std::memory_order_relaxed); newvoice->mSourceID.store(0u, std::memory_order_relaxed); - newvoice->mPlayState.store(ALvoice::Stopped, std::memory_order_relaxed); + newvoice->mPlayState.store(Voice::Stopped, std::memory_order_relaxed); return false; } @@ -660,7 +660,7 @@ inline bool IsPlayingOrPaused(ALsource *source) * Returns an updated source state using the matching voice's status (or lack * thereof). */ -inline ALenum GetSourceState(ALsource *source, ALvoice *voice) +inline ALenum GetSourceState(ALsource *source, Voice *voice) { if(!voice && source->state == AL_PLAYING) source->state = AL_STOPPED; @@ -733,7 +733,7 @@ void FreeSource(ALCcontext *context, ALsource *source) if(IsPlayingOrPaused(source)) { - if(ALvoice *voice{GetSourceVoice(source, context)}) + if(Voice *voice{GetSourceVoice(source, context)}) { VoiceChange *vchg{GetVoiceChanger(context)}; @@ -1020,7 +1020,7 @@ bool SetSourcei64v(ALsource *Source, ALCcontext *Context, SourceProp prop, const bool UpdateSourceProps(ALsource *source, ALCcontext *context) { - ALvoice *voice; + Voice *voice; if(SourceShouldUpdate(source, context) && (voice=GetSourceVoice(source, context)) != nullptr) UpdateSourceProps(source, voice, context); else @@ -1144,7 +1144,7 @@ bool SetSourcefv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a CHECKSIZE(values, 1); CHECKVAL(values[0] >= 0.0f); - if(ALvoice *voice{GetSourceVoice(Source, Context)}) + if(Voice *voice{GetSourceVoice(Source, Context)}) { if((voice->mFlags&VOICE_IS_CALLBACK)) SETERR_RETURN(Context, AL_INVALID_VALUE, false, @@ -1286,7 +1286,7 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a Source->Looping = values[0] != AL_FALSE; if(IsPlayingOrPaused(Source)) { - if(ALvoice *voice{GetSourceVoice(Source, Context)}) + if(Voice *voice{GetSourceVoice(Source, Context)}) { if(Source->Looping) voice->mLoopBuffer.store(Source->queue, std::memory_order_release); @@ -1361,7 +1361,7 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a CHECKSIZE(values, 1); CHECKVAL(values[0] >= 0); - if(ALvoice *voice{GetSourceVoice(Source, Context)}) + if(Voice *voice{GetSourceVoice(Source, Context)}) { if((voice->mFlags&VOICE_IS_CALLBACK)) SETERR_RETURN(Context, AL_INVALID_VALUE, false, @@ -1502,7 +1502,7 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a /* We must force an update if the auxiliary slot changed on an * active source, in case the slot is about to be deleted. */ - ALvoice *voice{GetSourceVoice(Source, Context)}; + Voice *voice{GetSourceVoice(Source, Context)}; if(voice) UpdateSourceProps(Source, voice, Context); else Source->PropsClean.clear(std::memory_order_release); } @@ -1939,7 +1939,7 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a const ALbufferlistitem *Current{nullptr}; ALsizei played{0}; - ALvoice *voice{GetSourceVoice(Source, Context)}; + Voice *voice{GetSourceVoice(Source, Context)}; if(voice != nullptr) Current = voice->mCurrentBuffer.load(std::memory_order_relaxed); else if(Source->state == AL_INITIAL) @@ -2826,9 +2826,9 @@ START_API_FUNC /* Count the number of reusable voices. */ auto voicelist = context->getVoicesSpan(); size_t free_voices{0}; - for(const ALvoice *voice : voicelist) + for(const Voice *voice : voicelist) { - free_voices += (voice->mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped + free_voices += (voice->mPlayState.load(std::memory_order_acquire) == Voice::Stopped && voice->mSourceID.load(std::memory_order_relaxed) == 0u && voice->mPendingChange.load(std::memory_order_relaxed) == false); if(free_voices == srchandles.size()) @@ -2867,8 +2867,8 @@ START_API_FUNC /* If there's nothing to play, go right to stopped. */ if UNLIKELY(!BufferList) { - /* NOTE: A source without any playable buffers should not have an - * ALvoice since it shouldn't be in a playing or paused state. So + /* NOTE: A source without any playable buffers should not have a + * Voice since it shouldn't be in a playing or paused state. So * there's no need to look up its voice and clear the source. */ source->Offset = 0.0; @@ -2884,7 +2884,7 @@ START_API_FUNC cur->mNext.store(GetVoiceChanger(context.get()), std::memory_order_relaxed); cur = cur->mNext.load(std::memory_order_relaxed); } - ALvoice *voice{GetSourceVoice(source, context.get())}; + Voice *voice{GetSourceVoice(source, context.get())}; switch(GetSourceState(source, voice)) { case AL_PAUSED: @@ -2919,8 +2919,8 @@ START_API_FUNC /* Find the next unused voice to play this source with. */ for(;voiceiter != voicelist.end();++voiceiter,++vidx) { - ALvoice *v{*voiceiter}; - if(v->mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped + Voice *v{*voiceiter}; + if(v->mPlayState.load(std::memory_order_acquire) == Voice::Stopped && v->mSourceID.load(std::memory_order_relaxed) == 0u && v->mPendingChange.load(std::memory_order_relaxed) == false) { @@ -3007,7 +3007,7 @@ START_API_FUNC VoiceChange *tail{}, *cur{}; for(ALsource *source : srchandles) { - ALvoice *voice{GetSourceVoice(source, context.get())}; + Voice *voice{GetSourceVoice(source, context.get())}; if(GetSourceState(source, voice) == AL_PLAYING) { if(!cur) @@ -3032,7 +3032,7 @@ START_API_FUNC */ for(ALsource *source : srchandles) { - ALvoice *voice{GetSourceVoice(source, context.get())}; + Voice *voice{GetSourceVoice(source, context.get())}; if(GetSourceState(source, voice) == AL_PLAYING) source->state = AL_PAUSED; } @@ -3079,7 +3079,7 @@ START_API_FUNC VoiceChange *tail{}, *cur{}; for(ALsource *source : srchandles) { - if(ALvoice *voice{GetSourceVoice(source, context.get())}) + if(Voice *voice{GetSourceVoice(source, context.get())}) { if(!cur) cur = tail = GetVoiceChanger(context.get()); @@ -3142,7 +3142,7 @@ START_API_FUNC VoiceChange *tail{}, *cur{}; for(ALsource *source : srchandles) { - ALvoice *voice{GetSourceVoice(source, context.get())}; + Voice *voice{GetSourceVoice(source, context.get())}; if(source->state != AL_INITIAL) { if(!cur) @@ -3306,7 +3306,7 @@ START_API_FUNC /* Make sure enough buffers have been processed to unqueue. */ ALbufferlistitem *BufferList{source->queue}; - ALvoice *voice{GetSourceVoice(source, context.get())}; + Voice *voice{GetSourceVoice(source, context.get())}; ALbufferlistitem *Current{nullptr}; if(voice) Current = voice->mCurrentBuffer.load(std::memory_order_relaxed); @@ -3386,7 +3386,7 @@ void UpdateAllSourceProps(ALCcontext *context) std::lock_guard _{context->mSourceLock}; auto voicelist = context->getVoicesSpan(); std::for_each(voicelist.begin(), voicelist.end(), - [context](ALvoice *voice) -> void + [context](Voice *voice) -> void { ALuint sid{voice->mSourceID.load(std::memory_order_acquire)}; ALsource *source = sid ? LookupSource(context, sid) : nullptr; diff --git a/alc/alc.cpp b/alc/alc.cpp index fc4af2b0..880d2781 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -1665,10 +1665,10 @@ void ALCcontext::allocVoices(size_t addcount) const size_t totalcount{(mVoiceClusters.size()+addcount) * clustersize}; TRACE("Increasing allocated voices to %zu\n", totalcount); - auto newarray = ALvoiceArray::Create(totalcount); + auto newarray = VoiceArray::Create(totalcount); while(addcount) { - mVoiceClusters.emplace_back(std::make_unique(clustersize)); + mVoiceClusters.emplace_back(std::make_unique(clustersize)); --addcount; } @@ -2285,10 +2285,10 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) * auxiliary sends is changing. Active sources will have updates * respecified in UpdateAllSourceProps. */ - ALvoiceProps *vprops{context->mFreeVoiceProps.exchange(nullptr, std::memory_order_acq_rel)}; + VoicePropsItem *vprops{context->mFreeVoiceProps.exchange(nullptr, std::memory_order_acq_rel)}; while(vprops) { - ALvoiceProps *next = vprops->next.load(std::memory_order_relaxed); + VoicePropsItem *next = vprops->next.load(std::memory_order_relaxed); delete vprops; vprops = next; } @@ -2298,13 +2298,12 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) { const ALuint num_sends{device->NumAuxSends}; /* Clear extraneous property set sends. */ - for(ALvoice *voice : voicelist) + for(Voice *voice : voicelist) { std::fill(std::begin(voice->mProps.Send)+num_sends, std::end(voice->mProps.Send), - ALvoiceProps::SendData{}); + VoiceProps::SendData{}); - std::fill(voice->mSend.begin()+num_sends, voice->mSend.end(), - ALvoice::TargetData{}); + std::fill(voice->mSend.begin()+num_sends, voice->mSend.end(), Voice::TargetData{}); for(auto &chandata : voice->mChans) { std::fill(chandata.mWetParams.begin()+num_sends, chandata.mWetParams.end(), @@ -2312,13 +2311,13 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) } } } - for(ALvoice *voice : voicelist) + for(Voice *voice : voicelist) { delete voice->mUpdate.exchange(nullptr, std::memory_order_acq_rel); /* Force the voice to stopped if it was stopping. */ - ALvoice::State vstate{ALvoice::Stopping}; - voice->mPlayState.compare_exchange_strong(vstate, ALvoice::Stopped, + Voice::State vstate{Voice::Stopping}; + voice->mPlayState.compare_exchange_strong(vstate, Voice::Stopped, std::memory_order_acquire, std::memory_order_acquire); if(voice->mSourceID.load(std::memory_order_relaxed) == 0u) continue; @@ -2524,10 +2523,10 @@ ALCcontext::~ALCcontext() mNumEffectSlots = 0; count = 0; - ALvoiceProps *vprops{mFreeVoiceProps.exchange(nullptr, std::memory_order_acquire)}; + VoicePropsItem *vprops{mFreeVoiceProps.exchange(nullptr, std::memory_order_acquire)}; while(vprops) { - ALvoiceProps *next{vprops->next.load(std::memory_order_relaxed)}; + VoicePropsItem *next{vprops->next.load(std::memory_order_relaxed)}; delete vprops; vprops = next; ++count; diff --git a/alc/alcontext.h b/alc/alcontext.h index 2ec3cf25..7b67bff7 100644 --- a/alc/alcontext.h +++ b/alc/alcontext.h @@ -57,8 +57,8 @@ struct ALcontextProps { struct VoiceChange { - ALvoice *mOldVoice{nullptr}; - ALvoice *mVoice{nullptr}; + Voice *mOldVoice{nullptr}; + Voice *mVoice{nullptr}; ALuint mSourceID{0}; ALenum mState{0}; @@ -137,7 +137,7 @@ struct ALCcontext : public al::intrusive_ref { */ std::atomic mFreeContextProps{nullptr}; std::atomic mFreeListenerProps{nullptr}; - std::atomic mFreeVoiceProps{nullptr}; + std::atomic mFreeVoiceProps{nullptr}; std::atomic mFreeEffectslotProps{nullptr}; /* Asynchronous voice change actions are processed as a linked list of @@ -159,20 +159,20 @@ struct ALCcontext : public al::intrusive_ref { void allocVoiceChanges(size_t addcount); - using VoiceCluster = std::unique_ptr; + using VoiceCluster = std::unique_ptr; al::vector mVoiceClusters; - using ALvoiceArray = al::FlexArray; - std::atomic mVoices{}; + using VoiceArray = al::FlexArray; + std::atomic mVoices{}; std::atomic mActiveVoiceCount{}; void allocVoices(size_t addcount); - al::span getVoicesSpan() const noexcept + al::span getVoicesSpan() const noexcept { return {mVoices.load(std::memory_order_relaxed)->data(), mActiveVoiceCount.load(std::memory_order_relaxed)}; } - al::span getVoicesSpanAcquired() const noexcept + al::span getVoicesSpanAcquired() const noexcept { return {mVoices.load(std::memory_order_acquire)->data(), mActiveVoiceCount.load(std::memory_order_acquire)}; diff --git a/alc/alu.cpp b/alc/alu.cpp index 787cece0..889c2271 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -664,10 +664,10 @@ void AmbiRotator(std::array,MAX_AMBI_CHANNEL struct GainTriplet { float Base, HF, LF; }; -void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypos, +void CalcPanningAndFilters(Voice *voice, const ALfloat xpos, const ALfloat ypos, const ALfloat zpos, const ALfloat Distance, const ALfloat Spread, const GainTriplet &DryGain, const al::span WetGain, ALeffectslot *(&SendSlots)[MAX_SENDS], - const ALvoicePropsBase *props, const ALlistener &Listener, const ALCdevice *Device) + const VoiceProps *props, const ALlistener &Listener, const ALCdevice *Device) { static const ChanMap MonoMap[1]{ { FrontCenter, 0.0f, 0.0f } @@ -1188,7 +1188,7 @@ void CalcPanningAndFilters(ALvoice *voice, const ALfloat xpos, const ALfloat ypo } } -void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const ALCcontext *ALContext) +void CalcNonAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontext *ALContext) { const ALCdevice *Device{ALContext->mDevice.get()}; ALeffectslot *SendSlots[MAX_SENDS]; @@ -1237,7 +1237,7 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons Listener, Device); } -void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const ALCcontext *ALContext) +void CalcAttnSourceParams(Voice *voice, const VoiceProps *props, const ALCcontext *ALContext) { const ALCdevice *Device{ALContext->mDevice.get()}; const ALuint NumSends{Device->NumAuxSends}; @@ -1541,9 +1541,9 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A Listener, Device); } -void CalcSourceParams(ALvoice *voice, ALCcontext *context, bool force) +void CalcSourceParams(Voice *voice, ALCcontext *context, bool force) { - ALvoiceProps *props{voice->mUpdate.exchange(nullptr, std::memory_order_acq_rel)}; + VoicePropsItem *props{voice->mUpdate.exchange(nullptr, std::memory_order_acq_rel)}; if(!props && !force) return; if(props) @@ -1589,13 +1589,13 @@ void ProcessVoiceChanges(ALCcontext *ctx) bool sendevt{false}; if(cur->mState == AL_INITIAL || cur->mState == AL_STOPPED) { - if(ALvoice *voice{cur->mVoice}) + if(Voice *voice{cur->mVoice}) { voice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed); voice->mLoopBuffer.store(nullptr, std::memory_order_relaxed); voice->mSourceID.store(0u, std::memory_order_relaxed); - ALvoice::State oldvstate{ALvoice::Playing}; - sendevt = voice->mPlayState.compare_exchange_strong(oldvstate, ALvoice::Stopping, + Voice::State oldvstate{Voice::Playing}; + sendevt = voice->mPlayState.compare_exchange_strong(oldvstate, Voice::Stopping, std::memory_order_relaxed, std::memory_order_acquire); voice->mPendingChange.store(false, std::memory_order_release); } @@ -1606,9 +1606,9 @@ void ProcessVoiceChanges(ALCcontext *ctx) } else if(cur->mState == AL_PAUSED) { - ALvoice *voice{cur->mVoice}; - ALvoice::State oldvstate{ALvoice::Playing}; - sendevt = voice->mPlayState.compare_exchange_strong(oldvstate, ALvoice::Stopping, + Voice *voice{cur->mVoice}; + Voice::State oldvstate{Voice::Playing}; + sendevt = voice->mPlayState.compare_exchange_strong(oldvstate, Voice::Stopping, std::memory_order_release, std::memory_order_acquire); } else if(cur->mState == AL_PLAYING) @@ -1619,26 +1619,26 @@ void ProcessVoiceChanges(ALCcontext *ctx) * sent. If there is an old voice, an event is sent only if the * voice is already stopped. */ - if(ALvoice *oldvoice{cur->mOldVoice}) + if(Voice *oldvoice{cur->mOldVoice}) { oldvoice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed); oldvoice->mLoopBuffer.store(nullptr, std::memory_order_relaxed); oldvoice->mSourceID.store(0u, std::memory_order_relaxed); - ALvoice::State oldvstate{ALvoice::Playing}; - sendevt = !oldvoice->mPlayState.compare_exchange_strong(oldvstate, - ALvoice::Stopping, std::memory_order_relaxed, std::memory_order_acquire); + Voice::State oldvstate{Voice::Playing}; + sendevt = !oldvoice->mPlayState.compare_exchange_strong(oldvstate, Voice::Stopping, + std::memory_order_relaxed, std::memory_order_acquire); oldvoice->mPendingChange.store(false, std::memory_order_release); } else sendevt = true; - ALvoice *voice{cur->mVoice}; - voice->mPlayState.store(ALvoice::Playing, std::memory_order_release); + Voice *voice{cur->mVoice}; + voice->mPlayState.store(Voice::Playing, std::memory_order_release); } else if(cur->mState == AL_SAMPLE_OFFSET) { /* Changing a voice offset never sends a source change event. */ - ALvoice *oldvoice{cur->mOldVoice}; + Voice *oldvoice{cur->mOldVoice}; oldvoice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed); oldvoice->mLoopBuffer.store(nullptr, std::memory_order_relaxed); /* If there's no sourceID, the old voice finished so don't start @@ -1650,14 +1650,13 @@ void ProcessVoiceChanges(ALCcontext *ctx) * might already be, if paused), and play the new voice as * appropriate. */ - ALvoice::State oldvstate{ALvoice::Playing}; - oldvoice->mPlayState.compare_exchange_strong(oldvstate, ALvoice::Stopping, + Voice::State oldvstate{Voice::Playing}; + oldvoice->mPlayState.compare_exchange_strong(oldvstate, Voice::Stopping, std::memory_order_relaxed, std::memory_order_acquire); - ALvoice *voice{cur->mVoice}; - voice->mPlayState.store( - (oldvstate == ALvoice::Playing) ? ALvoice::Playing : ALvoice::Stopped, - std::memory_order_release); + Voice *voice{cur->mVoice}; + voice->mPlayState.store((oldvstate == Voice::Playing) ? Voice::Playing + : Voice::Stopped, std::memory_order_release); } oldvoice->mPendingChange.store(false, std::memory_order_release); } @@ -1670,7 +1669,7 @@ void ProcessVoiceChanges(ALCcontext *ctx) } void ProcessParamUpdates(ALCcontext *ctx, const ALeffectslotArray &slots, - const al::span voices) + const al::span voices) { ProcessVoiceChanges(ctx); @@ -1683,7 +1682,7 @@ void ProcessParamUpdates(ALCcontext *ctx, const ALeffectslotArray &slots, for(ALeffectslot *slot : slots) force |= CalcEffectSlotParams(slot, sorted_slots, ctx); - for(ALvoice *voice : voices) + for(Voice *voice : voices) { /* Only update voices that have a source. */ if(voice->mSourceID.load(std::memory_order_relaxed) != 0) @@ -1700,7 +1699,7 @@ void ProcessContexts(ALCdevice *device, const ALuint SamplesToDo) for(ALCcontext *ctx : *device->mContexts.load(std::memory_order_acquire)) { const ALeffectslotArray &auxslots = *ctx->mActiveAuxSlots.load(std::memory_order_acquire); - const al::span voices{ctx->getVoicesSpanAcquired()}; + const al::span voices{ctx->getVoicesSpanAcquired()}; /* Process pending propery updates for objects on the context. */ ProcessParamUpdates(ctx, auxslots, voices); @@ -1713,10 +1712,10 @@ void ProcessContexts(ALCdevice *device, const ALuint SamplesToDo) } /* Process voices that have a playing source. */ - for(ALvoice *voice : voices) + for(Voice *voice : voices) { - const ALvoice::State vstate{voice->mPlayState.load(std::memory_order_acquire)}; - if(vstate != ALvoice::Stopped && vstate != ALvoice::Pending) + const Voice::State vstate{voice->mPlayState.load(std::memory_order_acquire)}; + if(vstate != Voice::Stopped && vstate != Voice::Pending) voice->mix(vstate, ctx, SamplesToDo); } @@ -2107,12 +2106,12 @@ void aluHandleDisconnect(ALCdevice *device, const char *msg, ...) } auto voicelist = ctx->getVoicesSpanAcquired(); - auto stop_voice = [](ALvoice *voice) -> void + auto stop_voice = [](Voice *voice) -> void { voice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed); voice->mLoopBuffer.store(nullptr, std::memory_order_relaxed); voice->mSourceID.store(0u, std::memory_order_relaxed); - voice->mPlayState.store(ALvoice::Stopped, std::memory_order_release); + voice->mPlayState.store(Voice::Stopped, std::memory_order_release); }; std::for_each(voicelist.begin(), voicelist.end(), stop_voice); } diff --git a/alc/voice.cpp b/alc/voice.cpp index d09aa700..64e0bde4 100644 --- a/alc/voice.cpp +++ b/alc/voice.cpp @@ -573,7 +573,7 @@ void DoNfcMix(const al::span samples, FloatBufferLine *OutBuffer, D } // namespace -void ALvoice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesToDo) +void Voice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesToDo) { static constexpr std::array SilentTarget{}; @@ -591,8 +591,8 @@ void ALvoice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesT /* If the voice is supposed to be stopping but can't be mixed, just * stop it before bailing. */ - if(vstate == ALvoice::Stopping) - mPlayState.store(ALvoice::Stopped, std::memory_order_release); + if(vstate == Stopping) + mPlayState.store(Stopped, std::memory_order_release); return; } @@ -776,22 +776,22 @@ void ALvoice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesT if((mFlags&VOICE_HAS_HRTF)) { - const ALfloat TargetGain{UNLIKELY(vstate == ALvoice::Stopping) ? 0.0f : + const ALfloat TargetGain{UNLIKELY(vstate == Stopping) ? 0.0f : parms.Hrtf.Target.Gain}; DoHrtfMix(samples, DstBufferSize, parms, TargetGain, Counter, OutPos, IrSize, Device); } else if((mFlags&VOICE_HAS_NFC)) { - const float *TargetGains{UNLIKELY(vstate == ALvoice::Stopping) ? - SilentTarget.data() : parms.Gains.Target.data()}; + const float *TargetGains{UNLIKELY(vstate == Stopping) ? SilentTarget.data() + : parms.Gains.Target.data()}; DoNfcMix({samples, DstBufferSize}, mDirect.Buffer.data(), parms, TargetGains, Counter, OutPos, Device); } else { - const float *TargetGains{UNLIKELY(vstate == ALvoice::Stopping) ? - SilentTarget.data() : parms.Gains.Target.data()}; + const float *TargetGains{UNLIKELY(vstate == Stopping) ? SilentTarget.data() + : parms.Gains.Target.data()}; MixSamples({samples, DstBufferSize}, mDirect.Buffer, parms.Gains.Current.data(), TargetGains, Counter, OutPos); } @@ -806,8 +806,8 @@ void ALvoice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesT const ALfloat *samples{DoFilters(&parms.LowPass, &parms.HighPass, FilterBuf, {ResampledData, DstBufferSize}, mSend[send].FilterType)}; - const float *TargetGains{UNLIKELY(vstate == ALvoice::Stopping) ? - SilentTarget.data() : parms.Gains.Target.data()}; + const float *TargetGains{UNLIKELY(vstate == Stopping) ? SilentTarget.data() + : parms.Gains.Target.data()}; MixSamples({samples, DstBufferSize}, mSend[send].Buffer, parms.Gains.Current.data(), TargetGains, Counter, OutPos); } @@ -885,9 +885,9 @@ void ALvoice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesT mFlags |= VOICE_IS_FADING; /* Don't update positions and buffers if we were stopping. */ - if UNLIKELY(vstate == ALvoice::Stopping) + if UNLIKELY(vstate == Stopping) { - mPlayState.store(ALvoice::Stopped, std::memory_order_release); + mPlayState.store(Stopped, std::memory_order_release); return; } @@ -925,7 +925,7 @@ void ALvoice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesT /* If the voice just ended, set it to Stopping so the next render * ensures any residual noise fades to 0 amplitude. */ - mPlayState.store(ALvoice::Stopping, std::memory_order_release); + mPlayState.store(Stopping, std::memory_order_release); if((enabledevt&EventType_SourceStateChange)) SendSourceStoppedEvent(Context, SourceID); } diff --git a/alc/voice.h b/alc/voice.h index 6583d4f1..7adffe7f 100644 --- a/alc/voice.h +++ b/alc/voice.h @@ -122,7 +122,7 @@ struct SendParams { }; -struct ALvoicePropsBase { +struct VoiceProps { float Pitch; float Gain; float OuterGain; @@ -175,10 +175,10 @@ struct ALvoicePropsBase { } Send[MAX_SENDS]; }; -struct ALvoiceProps : public ALvoicePropsBase { - std::atomic next{nullptr}; +struct VoicePropsItem : public VoiceProps { + std::atomic next{nullptr}; - DEF_NEWDEL(ALvoiceProps) + DEF_NEWDEL(VoicePropsItem) }; #define VOICE_IS_STATIC (1u<<0) @@ -191,7 +191,7 @@ struct ALvoiceProps : public ALvoicePropsBase { #define VOICE_TYPE_MASK (VOICE_IS_STATIC | VOICE_IS_CALLBACK) -struct ALvoice { +struct Voice { enum State { Stopped, Playing, @@ -199,9 +199,9 @@ struct ALvoice { Pending }; - std::atomic mUpdate{nullptr}; + std::atomic mUpdate{nullptr}; - ALvoicePropsBase mProps; + VoiceProps mProps; std::atomic mSourceID{0u}; std::atomic mPlayState{Stopped}; @@ -259,14 +259,14 @@ struct ALvoice { }; al::vector mChans{2}; - ALvoice() = default; - ALvoice(const ALvoice&) = delete; - ~ALvoice() { delete mUpdate.exchange(nullptr, std::memory_order_acq_rel); } - ALvoice& operator=(const ALvoice&) = delete; + Voice() = default; + Voice(const Voice&) = delete; + ~Voice() { delete mUpdate.exchange(nullptr, std::memory_order_acq_rel); } + Voice& operator=(const Voice&) = delete; void mix(const State vstate, ALCcontext *Context, const ALuint SamplesToDo); - DEF_NEWDEL(ALvoice) + DEF_NEWDEL(Voice) }; #endif /* VOICE_H */ -- cgit v1.2.3