From 49ac268334bf8875ff1b5baa1e79edc8b7fe15bd Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 20 Dec 2018 04:19:35 -0800 Subject: Add index maps from 2D and 3D --- Alc/ambidefs.h | 8 ++++++++ Alc/bformatdec.cpp | 14 ++++++-------- Alc/panning.cpp | 33 ++++++++++++++++----------------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/Alc/ambidefs.h b/Alc/ambidefs.h index 82eb7ee3..eeb09f75 100644 --- a/Alc/ambidefs.h +++ b/Alc/ambidefs.h @@ -102,6 +102,14 @@ struct AmbiIndex { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }}; + + static constexpr std::array From2D{{ + 0, 1,3, 4,8, 9,15 + }}; + static constexpr std::array From3D{{ + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15 + }}; }; #endif /* AMBIDEFS_H */ diff --git a/Alc/bformatdec.cpp b/Alc/bformatdec.cpp index 6a149611..d0d1325a 100644 --- a/Alc/bformatdec.cpp +++ b/Alc/bformatdec.cpp @@ -63,8 +63,6 @@ auto GetAmbiScales(AmbDecScale scaletype) noexcept -> const std::array ALfloat - { ASSUME(index > 0); return coeffs[index]; } + { ASSUME(index >= 0); return coeffs[index]; } ); } assert(chancount >= 3); for(ALsizei c{0};c < 3;c++) { - const ALsizei i{map2DTo3D[c]}; + const ALsizei i{AmbiIndex::From2D[c]}; ALdouble gain{0.0}; for(size_t k{0u};k < COUNTOF(Ambi3DDecoder);k++) gain += (ALdouble)Ambi3DDecoder[k][i] * encgains[k][c]; @@ -142,7 +140,7 @@ void BFormatDec::reset(const AmbDecConf *conf, ALsizei chancount, ALuint srate, ALfloat (&mtx)[MAX_AMBI_COEFFS] = mMatrix.Single[chanmap[i]]; for(ALsizei j{0},k{0};j < coeff_count;j++) { - const ALsizei l{periphonic ? j : map2DTo3D[j]}; + const ALsizei l{periphonic ? j : AmbiIndex::From2D[j]}; if(!(conf->ChanMask&(1<HFMatrix[i][k] / coeff_scale[l] * ((l>=9) ? conf->HFOrderGain[3] : @@ -163,7 +161,7 @@ void BFormatDec::reset(const AmbDecConf *conf, ALsizei chancount, ALuint srate, ALfloat (&mtx)[sNumBands][MAX_AMBI_COEFFS] = mMatrix.Dual[chanmap[i]]; for(ALsizei j{0},k{0};j < coeff_count;j++) { - const ALsizei l{periphonic ? j : map2DTo3D[j]}; + const ALsizei l{periphonic ? j : AmbiIndex::From2D[j]}; if(!(conf->ChanMask&(1<HFMatrix[i][k] / coeff_scale[l] * ((l>=9) ? conf->HFOrderGain[3] : diff --git a/Alc/panning.cpp b/Alc/panning.cpp index 50d1eec2..d03977b8 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -47,6 +47,8 @@ constexpr std::array AmbiScale::FromSN3D; constexpr std::array AmbiScale::FromFuMa; constexpr std::array AmbiIndex::FromFuMa; constexpr std::array AmbiIndex::FromACN; +constexpr std::array AmbiIndex::From2D; +constexpr std::array AmbiIndex::From3D; namespace { @@ -423,11 +425,8 @@ void InitPanning(ALCdevice *device) } else { - /* FOA output is always ACN+N3D for higher-order ambisonic output. - * The upsampler expects this and will convert it for output. - */ device->FOAOut.Ambi = AmbiConfig{}; - std::transform(AmbiIndex::FromACN.begin(), AmbiIndex::FromACN.begin()+4, + std::transform(AmbiIndex::From3D.begin(), AmbiIndex::From3D.begin()+4, std::begin(device->FOAOut.Ambi.Map), [](const ALsizei &acn) noexcept { return BFChannelConfig{1.0f, acn}; } ); @@ -462,7 +461,7 @@ void InitPanning(ALCdevice *device) else { device->FOAOut.Ambi = AmbiConfig{}; - std::transform(AmbiIndex::FromACN.begin(), AmbiIndex::FromACN.begin()+4, + std::transform(AmbiIndex::From3D.begin(), AmbiIndex::From3D.begin()+4, std::begin(device->FOAOut.Ambi.Map), [](const ALsizei &acn) noexcept { return BFChannelConfig{1.0f, acn}; } ); @@ -513,11 +512,11 @@ void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei } else { - static constexpr int map[4] = { 0, 1, 2, 3 }; static constexpr ALsizei count{4}; device->FOAOut.Ambi = AmbiConfig{}; - std::transform(std::begin(map), std::begin(map)+count, std::begin(device->FOAOut.Ambi.Map), + std::transform(AmbiIndex::From3D.begin(), AmbiIndex::From3D.begin()+count, + std::begin(device->FOAOut.Ambi.Map), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); device->FOAOut.CoeffCount = 0; @@ -540,19 +539,19 @@ void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&sp ALsizei count; if((conf->ChanMask&AMBI_PERIPHONIC_MASK)) { - static constexpr int map[MAX_AMBI_COEFFS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; count = (conf->ChanMask > AMBI_2ORDER_MASK) ? 16 : (conf->ChanMask > AMBI_1ORDER_MASK) ? 9 : 4; - std::transform(std::begin(map), std::begin(map)+count, std::begin(device->Dry.Ambi.Map), + std::transform(AmbiIndex::From3D.begin(), AmbiIndex::From3D.begin()+count, + std::begin(device->Dry.Ambi.Map), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); } else { - static constexpr int map[MAX_AMBI2D_COEFFS] = { 0, 1, 3, 4, 8, 9, 15 }; count = (conf->ChanMask > AMBI_2ORDER_MASK) ? 7 : (conf->ChanMask > AMBI_1ORDER_MASK) ? 5 : 3; - std::transform(std::begin(map), std::begin(map)+count, std::begin(device->Dry.Ambi.Map), + std::transform(AmbiIndex::From2D.begin(), AmbiIndex::From2D.begin()+count, + std::begin(device->Dry.Ambi.Map), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); } @@ -579,17 +578,17 @@ void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&sp device->FOAOut.Ambi = AmbiConfig{}; if((conf->ChanMask&AMBI_PERIPHONIC_MASK)) { - static constexpr int map[4] = { 0, 1, 2, 3 }; count = 4; - std::transform(std::begin(map), std::begin(map)+count, std::begin(device->FOAOut.Ambi.Map), + std::transform(AmbiIndex::From3D.begin(), AmbiIndex::From3D.begin()+count, + std::begin(device->FOAOut.Ambi.Map), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); } else { - static constexpr int map[3] = { 0, 1, 3 }; count = 3; - std::transform(std::begin(map), std::begin(map)+count, std::begin(device->FOAOut.Ambi.Map), + std::transform(AmbiIndex::From2D.begin(), AmbiIndex::From2D.begin()+count, + std::begin(device->FOAOut.Ambi.Map), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } ); } @@ -1145,8 +1144,8 @@ no_hrtf: void aluInitEffectPanning(ALeffectslot *slot) { const size_t count{countof(slot->ChanMap)}; - auto acnmap_end = AmbiIndex::FromACN.begin() + count; - std::transform(AmbiIndex::FromACN.begin(), acnmap_end, std::begin(slot->ChanMap), + auto acnmap_end = AmbiIndex::From3D.begin() + count; + std::transform(AmbiIndex::From3D.begin(), acnmap_end, std::begin(slot->ChanMap), [](const ALsizei &acn) noexcept { return BFChannelConfig{1.0f, acn}; } ); slot->NumChannels = static_cast(count); -- cgit v1.2.3