aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-06-09 18:13:54 -0700
committerChris Robinson <[email protected]>2019-06-09 18:13:54 -0700
commitbc8f206ee1361ec4b6e740a458bb7985bb7d1429 (patch)
tree5705d45dbedf6af324b3430654decf8388d0bd21 /OpenAL32
parent90d25e5187ca50a6e978603fabb6395035ad0db5 (diff)
Use a FlexArray for the context's voices
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alMain.h2
-rw-r--r--OpenAL32/Include/alu.h42
-rw-r--r--OpenAL32/alSource.cpp59
3 files changed, 72 insertions, 31 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 9a5b3814..80167417 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -532,7 +532,7 @@ struct AsyncEvent {
};
-void AllocateVoices(ALCcontext *context, ALsizei num_voices, ALsizei old_sends);
+void AllocateVoices(ALCcontext *context, size_t num_voices);
extern ALint RTPrioLevel;
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index 3e18f857..3135f8fd 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -278,10 +278,48 @@ struct ALvoice {
ALvoice() = default;
ALvoice(const ALvoice&) = delete;
+ ~ALvoice() { delete mUpdate.exchange(nullptr, std::memory_order_acq_rel); }
ALvoice& operator=(const ALvoice&) = delete;
-};
+ ALvoice& operator=(ALvoice&& rhs) noexcept
+ {
+ ALvoiceProps *old_update{mUpdate.load(std::memory_order_relaxed)};
+ mUpdate.store(rhs.mUpdate.exchange(old_update, std::memory_order_relaxed),
+ std::memory_order_relaxed);
+
+ mSourceID.store(rhs.mSourceID.load(std::memory_order_relaxed), std::memory_order_relaxed);
+ mPlayState.store(rhs.mPlayState.load(std::memory_order_relaxed),
+ std::memory_order_relaxed);
+
+ mProps = rhs.mProps;
+
+ mPosition.store(rhs.mPosition.load(std::memory_order_relaxed), std::memory_order_relaxed);
+ mPositionFrac.store(rhs.mPositionFrac.load(std::memory_order_relaxed),
+ std::memory_order_relaxed);
+
+ mCurrentBuffer.store(rhs.mCurrentBuffer.load(std::memory_order_relaxed),
+ std::memory_order_relaxed);
+ mLoopBuffer.store(rhs.mLoopBuffer.load(std::memory_order_relaxed),
+ std::memory_order_relaxed);
+
+ mFmtChannels = rhs.mFmtChannels;
+ mFrequency = rhs.mFrequency;
+ mNumChannels = rhs.mNumChannels;
+ mSampleSize = rhs.mSampleSize;
-void DeinitVoice(ALvoice *voice) noexcept;
+ mStep = rhs.mStep;
+ mResampler = rhs.mResampler;
+
+ mResampleState = rhs.mResampleState;
+
+ mFlags = rhs.mFlags;
+
+ mDirect = rhs.mDirect;
+ mSend = rhs.mSend;
+ mChans = rhs.mChans;
+
+ return *this;
+ }
+};
using MixerFunc = void(*)(const ALfloat *data, const al::span<FloatBufferLine> OutBuffer,
diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp
index b2878b8e..9fba7e4f 100644
--- a/OpenAL32/alSource.cpp
+++ b/OpenAL32/alSource.cpp
@@ -61,9 +61,9 @@ inline ALvoice *GetSourceVoice(ALsource *source, ALCcontext *context)
if(idx >= 0 && idx < context->VoiceCount.load(std::memory_order_relaxed))
{
ALuint sid{source->id};
- ALvoice *voice{context->Voices[idx]};
- if(voice->mSourceID.load(std::memory_order_acquire) == sid)
- return voice;
+ ALvoice &voice = (*context->Voices)[idx];
+ if(voice.mSourceID.load(std::memory_order_acquire) == sid)
+ return &voice;
}
source->VoiceIdx = -1;
return nullptr;
@@ -2777,12 +2777,13 @@ START_API_FUNC
}
/* Count the number of reusable voices. */
- auto voices_end = context->Voices + context->VoiceCount.load(std::memory_order_relaxed);
- auto free_voices = std::accumulate(context->Voices, voices_end, ALsizei{0},
- [](const ALsizei count, const ALvoice *voice) noexcept -> ALsizei
+ auto voices_end = context->Voices->begin() +
+ context->VoiceCount.load(std::memory_order_relaxed);
+ auto free_voices = std::accumulate(context->Voices->begin(), voices_end, ALsizei{0},
+ [](const ALsizei count, const ALvoice &voice) noexcept -> ALsizei
{
- if(voice->mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped &&
- voice->mSourceID.load(std::memory_order_relaxed) == 0u)
+ if(voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped &&
+ voice.mSourceID.load(std::memory_order_relaxed) == 0u)
return count + 1;
return count;
}
@@ -2790,20 +2791,21 @@ START_API_FUNC
if(UNLIKELY(n > free_voices))
{
/* Increment the number of voices to handle the request. */
- const ALsizei need_voices{n - free_voices};
- const ALsizei rem_voices{context->MaxVoices -
+ const ALuint need_voices{static_cast<ALuint>(n) - free_voices};
+ const size_t rem_voices{context->Voices->size() -
context->VoiceCount.load(std::memory_order_relaxed)};
if(UNLIKELY(need_voices > rem_voices))
{
/* Allocate more voices to get enough. */
- const ALsizei alloc_count{need_voices - rem_voices};
- if(UNLIKELY(context->MaxVoices > std::numeric_limits<ALsizei>::max()-alloc_count))
+ const size_t alloc_count{need_voices - rem_voices};
+ if(UNLIKELY(context->Voices->size() > std::numeric_limits<size_t>::max()-alloc_count))
SETERR_RETURN(context.get(), AL_OUT_OF_MEMORY,,
- "Overflow increasing voice count to %d + %d", context->MaxVoices, alloc_count);
+ "Overflow increasing voice count to %zu + %zu", context->Voices->size(),
+ alloc_count);
- const ALsizei newcount{context->MaxVoices + alloc_count};
- AllocateVoices(context.get(), newcount, device->NumAuxSends);
+ const size_t newcount{context->Voices->size() + alloc_count};
+ AllocateVoices(context.get(), newcount);
}
context->VoiceCount.fetch_add(need_voices, std::memory_order_relaxed);
@@ -2862,17 +2864,17 @@ START_API_FUNC
}
/* Look for an unused voice to play this source with. */
- auto voices_end = context->Voices + context->VoiceCount.load(std::memory_order_relaxed);
- auto voice_iter = std::find_if(context->Voices, voices_end,
- [](const ALvoice *voice) noexcept -> bool
+ auto voices_end = context->Voices->begin() +
+ context->VoiceCount.load(std::memory_order_relaxed);
+ voice = std::find_if(context->Voices->begin(), voices_end,
+ [](const ALvoice &voice) noexcept -> bool
{
- return voice->mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped &&
- voice->mSourceID.load(std::memory_order_relaxed) == 0u;
+ return voice.mPlayState.load(std::memory_order_acquire) == ALvoice::Stopped &&
+ voice.mSourceID.load(std::memory_order_relaxed) == 0u;
}
);
- assert(voice_iter != voices_end);
- auto vidx = static_cast<ALint>(std::distance(context->Voices, voice_iter));
- voice = *voice_iter;
+ assert(voice != voices_end);
+ auto vidx = static_cast<ALint>(std::distance(context->Voices->begin(), voice));
voice->mPlayState.store(ALvoice::Stopped, std::memory_order_release);
source->PropsClean.test_and_set(std::memory_order_acquire);
@@ -3557,14 +3559,15 @@ ALsource::~ALsource()
void UpdateAllSourceProps(ALCcontext *context)
{
- auto voices_end = context->Voices + context->VoiceCount.load(std::memory_order_relaxed);
- std::for_each(context->Voices, voices_end,
- [context](ALvoice *voice) -> void
+ auto voices_end = context->Voices->begin() +
+ context->VoiceCount.load(std::memory_order_relaxed);
+ std::for_each(context->Voices->begin(), voices_end,
+ [context](ALvoice &voice) -> void
{
- ALuint sid{voice->mSourceID.load(std::memory_order_acquire)};
+ ALuint sid{voice.mSourceID.load(std::memory_order_acquire)};
ALsource *source = sid ? LookupSource(context, sid) : nullptr;
if(source && !source->PropsClean.test_and_set(std::memory_order_acq_rel))
- UpdateSourceProps(source, voice, context);
+ UpdateSourceProps(source, &voice, context);
}
);
}