diff options
author | Chris Robinson <[email protected]> | 2020-11-19 04:18:25 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-11-19 04:18:25 -0800 |
commit | 03f97000719ccc28259ceda76822dd42d95b5cf1 (patch) | |
tree | a4f56bc05dda09ab00b603706c29d6fef6832cb1 /alc | |
parent | 537510afc83a43d396a3c8658da384013aade448 (diff) |
Use BufferStorage for the buffer queue
Diffstat (limited to 'alc')
-rw-r--r-- | alc/alu.h | 1 | ||||
-rw-r--r-- | alc/buffer_storage.h | 18 | ||||
-rw-r--r-- | alc/voice.cpp | 36 | ||||
-rw-r--r-- | alc/voice.h | 5 |
4 files changed, 36 insertions, 24 deletions
@@ -12,7 +12,6 @@ #include "alspan.h" struct ALCcontext; -struct ALbufferlistitem; struct ALeffectslot; diff --git a/alc/buffer_storage.h b/alc/buffer_storage.h index 6b1f1ba3..434d5ed0 100644 --- a/alc/buffer_storage.h +++ b/alc/buffer_storage.h @@ -1,10 +1,13 @@ -#ifndef ALC_BUFFER_FORMATS_H -#define ALC_BUFFER_FORMATS_H +#ifndef ALC_BUFFER_STORAGE_H +#define ALC_BUFFER_STORAGE_H + +#include <atomic> #include "AL/al.h" #include "AL/alext.h" #include "albyte.h" +#include "almalloc.h" #include "inprogext.h" #include "vector.h" @@ -73,4 +76,13 @@ struct BufferStorage { { return mChannels == FmtBFormat2D || mChannels == FmtBFormat3D; } }; -#endif /* ALC_BUFFER_FORMATS_H */ + +struct BufferlistItem { + std::atomic<BufferlistItem*> mNext{nullptr}; + ALuint mSampleLen{0u}; + BufferStorage *mBuffer{nullptr}; + + DEF_NEWDEL(BufferlistItem) +}; + +#endif /* ALC_BUFFER_STORAGE_H */ diff --git a/alc/voice.cpp b/alc/voice.cpp index 671f8fff..5d23f376 100644 --- a/alc/voice.cpp +++ b/alc/voice.cpp @@ -241,11 +241,11 @@ void LoadSamples(float *RESTRICT dst, const al::byte *src, const size_t srcstep, #undef HANDLE_FMT } -float *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&BufferLoopItem, +float *LoadBufferStatic(BufferlistItem *BufferListItem, BufferlistItem *&BufferLoopItem, const size_t NumChannels, const size_t SampleSize, const size_t chan, size_t DataPosInt, al::span<float> SrcBuffer) { - const BufferStorage &Buffer = BufferListItem->mBuffer->mBuffer; + const BufferStorage &Buffer = *BufferListItem->mBuffer; const ALuint LoopStart{Buffer.mLoopStart}; const ALuint LoopEnd{Buffer.mLoopEnd}; ASSUME(LoopEnd > LoopStart); @@ -290,11 +290,11 @@ float *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&Buf return SrcBuffer.begin(); } -float *LoadBufferCallback(ALbufferlistitem *BufferListItem, const size_t NumChannels, +float *LoadBufferCallback(BufferlistItem *BufferListItem, const size_t NumChannels, const size_t SampleSize, const size_t chan, size_t NumCallbackSamples, al::span<float> SrcBuffer) { - const BufferStorage &Buffer = BufferListItem->mBuffer->mBuffer; + const BufferStorage &Buffer = *BufferListItem->mBuffer; /* Load what's left to play from the buffer */ const size_t DataRem{minz(SrcBuffer.size(), NumCallbackSamples)}; @@ -307,28 +307,28 @@ float *LoadBufferCallback(ALbufferlistitem *BufferListItem, const size_t NumChan return SrcBuffer.begin(); } -float *LoadBufferQueue(ALbufferlistitem *BufferListItem, ALbufferlistitem *BufferLoopItem, +float *LoadBufferQueue(BufferlistItem *BufferListItem, BufferlistItem *BufferLoopItem, const size_t NumChannels, const size_t SampleSize, const size_t chan, size_t DataPosInt, al::span<float> SrcBuffer) { /* Crawl the buffer queue to fill in the temp buffer */ while(BufferListItem && !SrcBuffer.empty()) { - ALbuffer *Buffer{BufferListItem->mBuffer}; - if(!(Buffer && DataPosInt < Buffer->mBuffer.mSampleLen)) + BufferStorage *Buffer{BufferListItem->mBuffer}; + if(!(Buffer && DataPosInt < Buffer->mSampleLen)) { - if(Buffer) DataPosInt -= Buffer->mBuffer.mSampleLen; + if(Buffer) DataPosInt -= Buffer->mSampleLen; BufferListItem = BufferListItem->mNext.load(std::memory_order_acquire); if(!BufferListItem) BufferListItem = BufferLoopItem; continue; } - const size_t DataSize{minz(SrcBuffer.size(), Buffer->mBuffer.mSampleLen-DataPosInt)}; + const size_t DataSize{minz(SrcBuffer.size(), Buffer->mSampleLen-DataPosInt)}; - const al::byte *Data{Buffer->mBuffer.mData.data()}; + const al::byte *Data{Buffer->mData.data()}; Data += (DataPosInt*NumChannels + chan)*SampleSize; - LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mBuffer.mType, DataSize); + LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mType, DataSize); SrcBuffer = SrcBuffer.subspan(DataSize); if(SrcBuffer.empty()) break; @@ -454,8 +454,8 @@ void Voice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesToD /* Get voice info */ ALuint DataPosInt{mPosition.load(std::memory_order_relaxed)}; ALuint DataPosFrac{mPositionFrac.load(std::memory_order_relaxed)}; - ALbufferlistitem *BufferListItem{mCurrentBuffer.load(std::memory_order_relaxed)}; - ALbufferlistitem *BufferLoopItem{mLoopBuffer.load(std::memory_order_relaxed)}; + BufferlistItem *BufferListItem{mCurrentBuffer.load(std::memory_order_relaxed)}; + BufferlistItem *BufferLoopItem{mLoopBuffer.load(std::memory_order_relaxed)}; const ALuint SampleSize{mSampleSize}; const ALuint increment{mStep}; if UNLIKELY(increment < 1) @@ -555,7 +555,7 @@ void Voice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesToD if((mFlags&(VoiceIsCallback|VoiceCallbackStopped)) == VoiceIsCallback && BufferListItem) { - ALbuffer *buffer{BufferListItem->mBuffer}; + BufferStorage *buffer{BufferListItem->mBuffer}; /* Exclude resampler pre-padding from the needed size. */ const ALuint toLoad{SrcBufferSize - (MAX_RESAMPLER_PADDING>>1)}; @@ -564,8 +564,8 @@ void Voice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesToD const size_t byteOffset{mNumCallbackSamples*FrameSize}; const size_t needBytes{toLoad*FrameSize - byteOffset}; - const ALsizei gotBytes{buffer->mBuffer.mCallback(buffer->mBuffer.mUserData, - &buffer->mBuffer.mData[byteOffset], static_cast<ALsizei>(needBytes))}; + const ALsizei gotBytes{buffer->mCallback(buffer->mUserData, + &buffer->mData[byteOffset], static_cast<ALsizei>(needBytes))}; if(gotBytes < 1) mFlags |= VoiceCallbackStopped; else if(static_cast<ALuint>(gotBytes) < needBytes) @@ -701,7 +701,7 @@ void Voice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesToD if(BufferLoopItem) { /* Handle looping static source */ - const BufferStorage &Buffer = BufferListItem->mBuffer->mBuffer; + const BufferStorage &Buffer = *BufferListItem->mBuffer; const ALuint LoopStart{Buffer.mLoopStart}; const ALuint LoopEnd{Buffer.mLoopEnd}; if(DataPosInt >= LoopEnd) @@ -722,7 +722,7 @@ void Voice::mix(const State vstate, ALCcontext *Context, const ALuint SamplesToD } else if((mFlags&VoiceIsCallback)) { - BufferStorage &buffer = BufferListItem->mBuffer->mBuffer; + BufferStorage &buffer = *BufferListItem->mBuffer; if(SrcSamplesDone < mNumCallbackSamples) { const size_t byteOffset{SrcSamplesDone*FrameSize}; diff --git a/alc/voice.h b/alc/voice.h index 7822ea39..69efbf82 100644 --- a/alc/voice.h +++ b/alc/voice.h @@ -18,6 +18,7 @@ #include "hrtf.h" struct EffectSlot; +struct BufferlistItem; enum class DistanceModel; @@ -209,12 +210,12 @@ struct Voice { std::atomic<ALuint> mPositionFrac; /* Current buffer queue item being played. */ - std::atomic<ALbufferlistitem*> mCurrentBuffer; + std::atomic<BufferlistItem*> mCurrentBuffer; /* Buffer queue item to loop to at end of queue (will be NULL for non- * looping voices). */ - std::atomic<ALbufferlistitem*> mLoopBuffer; + std::atomic<BufferlistItem*> mLoopBuffer; /* Properties for the attached buffer(s). */ FmtChannels mFmtChannels; |