aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-03-10 15:46:46 -0700
committerChris Robinson <[email protected]>2019-03-10 15:46:46 -0700
commit030b24a40de0258ef4e9047aae6d770435060858 (patch)
treec5236476df49940e1e025a5a85a0c89aa8fbc6bb /OpenAL32
parent663a6ce4e7dbd919fa60e9f86cf6439f69789bd8 (diff)
Improve handling of voice's AmbiScales for upsampling
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alu.h2
-rw-r--r--OpenAL32/alSource.cpp27
2 files changed, 24 insertions, 5 deletions
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index 577b71f5..2b2432c4 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -256,7 +256,7 @@ struct ALvoice {
InterpState ResampleState;
- std::array<ALfloat,MAX_AMBI_ORDER+1> AmbiScales;
+ std::array<ALfloat,MAX_INPUT_CHANNELS> AmbiScales;
BandSplitter AmbiSplitter[MAX_INPUT_CHANNELS];
struct {
diff --git a/OpenAL32/alSource.cpp b/OpenAL32/alSource.cpp
index 1163fae3..ed0b813f 100644
--- a/OpenAL32/alSource.cpp
+++ b/OpenAL32/alSource.cpp
@@ -2871,13 +2871,32 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources)
/* Don't need to set the VOICE_IS_AMBISONIC flag if the device is
* mixing in first order. No HF scaling is necessary to mix it.
*/
- if(((*buffer)->mFmtChannels == FmtBFormat2D || (*buffer)->mFmtChannels == FmtBFormat3D) &&
+ if((voice->Channels == FmtBFormat2D || voice->Channels == FmtBFormat3D) &&
device->mAmbiOrder > 1)
{
- voice->AmbiScales = BFormatDec::GetHFOrderScales(1, device->mAmbiOrder);
+ auto scales = BFormatDec::GetHFOrderScales(1, device->mAmbiOrder);
+ if(voice->Channels == 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->AmbiScales.begin(),
+ [&scales](size_t idx) -> ALfloat { return scales[idx]; });
+ }
+ else
+ {
+ static constexpr int OrderFromChan[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->AmbiScales.begin(),
+ [&scales](size_t idx) -> ALfloat { return scales[idx]; });
+ }
+
voice->AmbiSplitter[0].init(400.0f / static_cast<ALfloat>(device->Frequency));
- for(ALsizei i{1};i < voice->NumChannels;++i)
- voice->AmbiSplitter[i] = voice->AmbiSplitter[0];
+ std::fill(std::begin(voice->AmbiSplitter)+1,
+ std::begin(voice->AmbiSplitter)+voice->NumChannels, voice->AmbiSplitter[0]);
voice->Flags |= VOICE_IS_AMBISONIC;
}