diff options
author | Chris Robinson <[email protected]> | 2019-05-17 20:39:28 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-05-17 20:39:28 -0700 |
commit | 515a201e30272826bd2bab58eecf42a5fa263230 (patch) | |
tree | 03ea283dbd7c9ce332282e85b19d4f1f54efd927 /OpenAL32 | |
parent | 5ac19673db211d1bee7687335af96cee4e6b40d8 (diff) |
Restructure some voice fields
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alu.h | 14 | ||||
-rw-r--r-- | OpenAL32/alSource.cpp | 45 |
2 files changed, 35 insertions, 24 deletions
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index 44083688..642aeddc 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -247,15 +247,17 @@ struct ALvoice { ResamplerFunc mResampler; + InterpState mResampleState; + ALuint mFlags; - using ResamplePaddingArray = std::array<ALfloat,MAX_RESAMPLE_PADDING*2>; - alignas(16) std::array<ResamplePaddingArray,MAX_INPUT_CHANNELS> mPrevSamples; + struct ResampleData { + alignas(16) std::array<ALfloat,MAX_RESAMPLE_PADDING*2> mPrevSamples; - InterpState mResampleState; - - std::array<ALfloat,MAX_INPUT_CHANNELS> mAmbiScales; - std::array<BandSplitter,MAX_INPUT_CHANNELS> mAmbiSplitter; + ALfloat mAmbiScale; + BandSplitter mAmbiSplitter; + }; + std::array<ResampleData,MAX_INPUT_CHANNELS> mResampleData; struct { int FilterType; diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp index 547f6a12..513adb88 100644 --- a/OpenAL32/alSource.cpp +++ b/OpenAL32/alSource.cpp @@ -2906,11 +2906,6 @@ START_API_FUNC voice->mSampleSize = BytesFromFmt((*buffer)->mFmtType); } - /* Clear previous samples. */ - std::for_each(voice->mPrevSamples.begin(), voice->mPrevSamples.begin()+voice->mNumChannels, - [](std::array<ALfloat,MAX_RESAMPLE_PADDING*2> &samples) -> void - { std::fill(std::begin(samples), std::end(samples), 0.0f); }); - /* Clear the stepping value so the mixer knows not to mix this until * the update gets applied. */ @@ -2925,31 +2920,45 @@ START_API_FUNC if((voice->mFmtChannels == FmtBFormat2D || voice->mFmtChannels == FmtBFormat3D) && device->mAmbiOrder > 1) { - auto scales = BFormatDec::GetHFOrderScales(1, device->mAmbiOrder); + const int *OrderFromChan; if(voice->mFmtChannels == FmtBFormat2D) { static constexpr int Order2DFromChan[MAX_AMBI2D_CHANNELS]{ 0, 1,1, 2,2, 3,3 }; - const size_t count{Ambi2DChannelsFromOrder(1u)}; - std::transform(Order2DFromChan, Order2DFromChan+count, voice->mAmbiScales.begin(), - [&scales](size_t idx) -> ALfloat { return scales[idx]; }); + OrderFromChan = Order2DFromChan; } else { - static constexpr int OrderFromChan[MAX_AMBI_CHANNELS]{ + static constexpr int Order3DFromChan[MAX_AMBI_CHANNELS]{ 0, 1,1,1, 2,2,2,2,2, 3,3,3,3,3,3,3, }; - const size_t count{Ambi2DChannelsFromOrder(1u)}; - std::transform(OrderFromChan, OrderFromChan+count, voice->mAmbiScales.begin(), - [&scales](size_t idx) -> ALfloat { return scales[idx]; }); + OrderFromChan = Order3DFromChan; } - voice->mAmbiSplitter[0].init(400.0f / static_cast<ALfloat>(device->Frequency)); - std::fill_n(voice->mAmbiSplitter.begin()+1, voice->mNumChannels-1, - voice->mAmbiSplitter[0]); + BandSplitter splitter; + splitter.init(400.0f / static_cast<ALfloat>(device->Frequency)); + + const auto scales = BFormatDec::GetHFOrderScales(1, device->mAmbiOrder); + auto init_ambi = [scales,&OrderFromChan,&splitter](ALvoice::ResampleData &resdata) -> void + { + resdata.mPrevSamples.fill(0.0f); + resdata.mAmbiScale = scales[*(OrderFromChan++)]; + resdata.mAmbiSplitter = splitter; + }; + std::for_each(voice->mResampleData.begin(), + voice->mResampleData.begin()+voice->mNumChannels, init_ambi); + voice->mFlags |= VOICE_IS_AMBISONIC; } + else + { + /* Clear previous samples. */ + auto clear_prevs = [](ALvoice::ResampleData &resdata) -> void + { resdata.mPrevSamples.fill(0.0f); }; + std::for_each(voice->mResampleData.begin(), + voice->mResampleData.begin()+voice->mNumChannels, clear_prevs); + } std::fill_n(std::begin(voice->mDirect.Params), voice->mNumChannels, DirectParams{}); std::for_each(voice->mSend.begin(), voice->mSend.end(), @@ -2959,8 +2968,8 @@ START_API_FUNC if(device->AvgSpeakerDist > 0.0f) { - ALfloat w1 = SPEEDOFSOUNDMETRESPERSEC / - (device->AvgSpeakerDist * device->Frequency); + const ALfloat w1{SPEEDOFSOUNDMETRESPERSEC / + (device->AvgSpeakerDist * device->Frequency)}; std::for_each(voice->mDirect.Params+0, voice->mDirect.Params+voice->mNumChannels, [w1](DirectParams &parms) noexcept -> void { parms.NFCtrlFilter.init(w1); } |