aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-02-25 06:39:03 -0800
committerChris Robinson <[email protected]>2020-02-25 06:39:03 -0800
commit795c4fcecc05132e550fa8b797e129823b230cdf (patch)
treec0932e6e80ad561067e2467a372fa4e7060948cd
parent9ddfcd6a1bbc04ec399643a1ae2ddea546b69ef1 (diff)
Make the source's send array static instead of dynamic
-rw-r--r--al/source.cpp23
-rw-r--r--al/source.h4
-rw-r--r--alc/alc.cpp30
3 files changed, 22 insertions, 35 deletions
diff --git a/al/source.cpp b/al/source.cpp
index 8ee1f4e0..ba56b45c 100644
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -556,7 +556,7 @@ bool EnsureSources(ALCcontext *context, size_t needed)
return true;
}
-ALsource *AllocSource(ALCcontext *context, ALuint num_sends)
+ALsource *AllocSource(ALCcontext *context)
{
auto sublist = std::find_if(context->mSourceList.begin(), context->mSourceList.end(),
[](const SourceSubList &entry) noexcept -> bool
@@ -565,7 +565,7 @@ ALsource *AllocSource(ALCcontext *context, ALuint num_sends)
auto lidx = static_cast<ALuint>(std::distance(context->mSourceList.begin(), sublist));
auto slidx = static_cast<ALuint>(CTZ64(sublist->FreeMask));
- ALsource *source{::new (sublist->Sources + slidx) ALsource{num_sends}};
+ ALsource *source{::new(sublist->Sources + slidx) ALsource{}};
/* Add 1 to avoid source ID 0. */
source->id = ((lidx<<6) | slidx) + 1;
@@ -2100,16 +2100,15 @@ START_API_FUNC
if(n == 1)
{
- ALsource *source{AllocSource(context.get(), device->NumAuxSends)};
+ ALsource *source{AllocSource(context.get())};
sources[0] = source->id;
}
else
{
- const ALuint num_sends{device->NumAuxSends};
al::vector<ALuint> ids;
ids.reserve(static_cast<ALuint>(n));
do {
- ALsource *source{AllocSource(context.get(), num_sends)};
+ ALsource *source{AllocSource(context.get())};
ids.emplace_back(source->id);
} while(--n);
std::copy(ids.cbegin(), ids.cend(), sources);
@@ -3283,7 +3282,7 @@ START_API_FUNC
END_API_FUNC
-ALsource::ALsource(ALuint num_sends)
+ALsource::ALsource()
{
InnerAngle = 360.0f;
OuterAngle = 360.0f;
@@ -3335,7 +3334,6 @@ ALsource::ALsource(ALuint num_sends)
Direct.HFReference = LOWPASSFREQREF;
Direct.GainLF = 1.0f;
Direct.LFReference = HIGHPASSFREQREF;
- Send.resize(num_sends);
for(auto &send : Send)
{
send.Slot = nullptr;
@@ -3360,14 +3358,9 @@ ALsource::~ALsource()
}
queue = nullptr;
- std::for_each(Send.begin(), Send.end(),
- [](ALsource::SendData &send) -> void
- {
- if(send.Slot)
- DecrementRef(send.Slot->ref);
- send.Slot = nullptr;
- }
- );
+ auto clear_send = [](ALsource::SendData &send) -> void
+ { if(send.Slot) DecrementRef(send.Slot->ref); };
+ std::for_each(Send.begin(), Send.end(), clear_send);
}
void UpdateAllSourceProps(ALCcontext *context)
diff --git a/al/source.h b/al/source.h
index 40bd0846..4a6a2531 100644
--- a/al/source.h
+++ b/al/source.h
@@ -88,7 +88,7 @@ struct ALsource {
ALfloat GainLF;
ALfloat LFReference;
};
- al::vector<SendData> Send;
+ std::array<SendData,MAX_SENDS> Send;
/**
* Last user-specified offset, and the offset type (bytes, samples, or
@@ -117,7 +117,7 @@ struct ALsource {
ALuint id{0};
- ALsource(ALuint num_sends);
+ ALsource();
~ALsource();
ALsource(const ALsource&) = delete;
diff --git a/alc/alc.cpp b/alc/alc.cpp
index 72ae1b1c..3791c7fd 100644
--- a/alc/alc.cpp
+++ b/alc/alc.cpp
@@ -2269,25 +2269,19 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
usemask &= ~(1_u64 << idx);
- if(old_sends != device->NumAuxSends)
+ auto clear_send = [](ALsource::SendData &send) -> void
{
- if(source->Send.size() > device->NumAuxSends)
- {
- auto clear_send = [](ALsource::SendData &send) -> void
- {
- if(send.Slot)
- DecrementRef(send.Slot->ref);
- send.Slot = nullptr;
- };
- auto send_begin = source->Send.begin() +
- static_cast<ptrdiff_t>(device->NumAuxSends);
- std::for_each(send_begin, source->Send.end(), clear_send);
- }
-
- source->Send.resize(device->NumAuxSends,
- {nullptr, 1.0f, 1.0f, LOWPASSFREQREF, 1.0f, HIGHPASSFREQREF});
- source->Send.shrink_to_fit();
- }
+ if(send.Slot)
+ DecrementRef(send.Slot->ref);
+ send.Slot = nullptr;
+ send.Gain = 1.0f;
+ send.GainHF = 1.0f;
+ send.HFReference = LOWPASSFREQREF;
+ send.GainLF = 1.0f;
+ send.LFReference = HIGHPASSFREQREF;
+ };
+ auto send_begin = source->Send.begin()+static_cast<ptrdiff_t>(device->NumAuxSends);
+ std::for_each(send_begin, source->Send.end(), clear_send);
source->PropsClean.clear(std::memory_order_release);
}