diff options
Diffstat (limited to 'alc')
-rw-r--r-- | alc/alc.cpp | 25 | ||||
-rw-r--r-- | alc/alcontext.h | 16 | ||||
-rw-r--r-- | alc/alu.cpp | 65 | ||||
-rw-r--r-- | alc/voice.cpp | 26 | ||||
-rw-r--r-- | alc/voice.h | 24 |
5 files changed, 77 insertions, 79 deletions
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<ALvoice[]>(clustersize)); + mVoiceClusters.emplace_back(std::make_unique<Voice[]>(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<ALCcontext> { */ std::atomic<ALcontextProps*> mFreeContextProps{nullptr}; std::atomic<ALlistenerProps*> mFreeListenerProps{nullptr}; - std::atomic<ALvoiceProps*> mFreeVoiceProps{nullptr}; + std::atomic<VoicePropsItem*> mFreeVoiceProps{nullptr}; std::atomic<ALeffectslotProps*> mFreeEffectslotProps{nullptr}; /* Asynchronous voice change actions are processed as a linked list of @@ -159,20 +159,20 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext> { void allocVoiceChanges(size_t addcount); - using VoiceCluster = std::unique_ptr<ALvoice[]>; + using VoiceCluster = std::unique_ptr<Voice[]>; al::vector<VoiceCluster> mVoiceClusters; - using ALvoiceArray = al::FlexArray<ALvoice*>; - std::atomic<ALvoiceArray*> mVoices{}; + using VoiceArray = al::FlexArray<Voice*>; + std::atomic<VoiceArray*> mVoices{}; std::atomic<size_t> mActiveVoiceCount{}; void allocVoices(size_t addcount); - al::span<ALvoice*> getVoicesSpan() const noexcept + al::span<Voice*> getVoicesSpan() const noexcept { return {mVoices.load(std::memory_order_relaxed)->data(), mActiveVoiceCount.load(std::memory_order_relaxed)}; } - al::span<ALvoice*> getVoicesSpanAcquired() const noexcept + al::span<Voice*> 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<std::array<float,MAX_AMBI_CHANNELS>,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<const GainTriplet,MAX_SENDS> 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<ALvoice*> voices) + const al::span<Voice*> 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<ALvoice*> voices{ctx->getVoicesSpanAcquired()}; + const al::span<Voice*> 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<const float> 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<float,MAX_OUTPUT_CHANNELS> 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<ALvoiceProps*> next{nullptr}; +struct VoicePropsItem : public VoiceProps { + std::atomic<VoicePropsItem*> 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<ALvoiceProps*> mUpdate{nullptr}; + std::atomic<VoicePropsItem*> mUpdate{nullptr}; - ALvoicePropsBase mProps; + VoiceProps mProps; std::atomic<ALuint> mSourceID{0u}; std::atomic<State> mPlayState{Stopped}; @@ -259,14 +259,14 @@ struct ALvoice { }; al::vector<ChannelData> 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 */ |