aboutsummaryrefslogtreecommitdiffstats
path: root/al
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-03-19 19:02:30 -0700
committerChris Robinson <[email protected]>2021-03-19 23:15:27 -0700
commit063da94bd8f4e2dc0369c283a7fa0f124764eb1c (patch)
tree974a8935401c8a04ff8619069002ac05bfe91320 /al
parentf7f29999601c7f4d0350fb43ceca8a5d84bc1432 (diff)
Load/convert samples from all channels at once for mixing
This uses a bit more memory (each voice needs to hold buffers for the deinterleaved samples of each channel, instead of just one buffer for the current channel being mixed on the device), but it will allow for handling formats that need or prefer their channels decoded together.
Diffstat (limited to 'al')
-rw-r--r--al/source.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/al/source.cpp b/al/source.cpp
index 9be79e9a..5b95e9ed 100644
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -458,9 +458,15 @@ void InitVoice(Voice *voice, ALsource *source, ALbufferQueueItem *BufferList, AL
voice->mStep = 0;
if(voice->mChans.capacity() > 2 && num_channels < voice->mChans.capacity())
- al::vector<Voice::ChannelData>{}.swap(voice->mChans);
+ {
+ decltype(voice->mChans){}.swap(voice->mChans);
+ decltype(voice->mVoiceSamples){}.swap(voice->mVoiceSamples);
+ }
voice->mChans.reserve(maxu(2, num_channels));
voice->mChans.resize(num_channels);
+ voice->mVoiceSamples.reserve(maxu(2, num_channels));
+ voice->mVoiceSamples.resize(num_channels);
+ std::fill_n(voice->mVoiceSamples.begin(), num_channels, Voice::BufferLine{});
/* Don't need to set the VOICE_IS_AMBISONIC flag if the device is not
* higher order than the voice. No HF scaling is necessary to mix it.
@@ -468,15 +474,12 @@ void InitVoice(Voice *voice, ALsource *source, ALbufferQueueItem *BufferList, AL
if(voice->mAmbiOrder && device->mAmbiOrder > voice->mAmbiOrder)
{
const uint8_t *OrderFromChan{(voice->mFmtChannels == FmtBFormat2D) ?
- AmbiIndex::OrderFrom2DChannel().data() :
- AmbiIndex::OrderFromChannel().data()};
+ AmbiIndex::OrderFrom2DChannel().data() : AmbiIndex::OrderFromChannel().data()};
const auto scales = BFormatDec::GetHFOrderScales(voice->mAmbiOrder, device->mAmbiOrder);
const BandSplitter splitter{device->mXOverFreq / static_cast<float>(device->Frequency)};
-
for(auto &chandata : voice->mChans)
{
- chandata.mPrevSamples.fill(0.0f);
chandata.mAmbiScale = scales[*(OrderFromChan++)];
chandata.mAmbiSplitter = splitter;
chandata.mDryParams = DirectParams{};
@@ -487,10 +490,8 @@ void InitVoice(Voice *voice, ALsource *source, ALbufferQueueItem *BufferList, AL
}
else
{
- /* Clear previous samples. */
for(auto &chandata : voice->mChans)
{
- chandata.mPrevSamples.fill(0.0f);
chandata.mDryParams = DirectParams{};
std::fill_n(chandata.mWetParams.begin(), device->NumAuxSends, SendParams{});
}