diff options
author | Chris Robinson <[email protected]> | 2019-02-21 04:05:49 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-02-21 04:05:49 -0800 |
commit | a9648905378b8a3321742bb0e498227cfc6ee5f6 (patch) | |
tree | e9f3c91b810b1e042d3153ceb512896195bf23d7 | |
parent | a35255291f946c634219da71b287339654eeff3c (diff) |
Add helpers to get the channel count from an ambisonic order
-rw-r--r-- | Alc/ambidefs.h | 8 | ||||
-rw-r--r-- | Alc/bformatdec.cpp | 14 | ||||
-rw-r--r-- | Alc/panning.cpp | 14 |
3 files changed, 20 insertions, 16 deletions
diff --git a/Alc/ambidefs.h b/Alc/ambidefs.h index 2b04d70b..bdecfae0 100644 --- a/Alc/ambidefs.h +++ b/Alc/ambidefs.h @@ -8,7 +8,9 @@ * order has 9, third-order has 16, and fourth-order has 25. */ #define MAX_AMBI_ORDER 3 -#define MAX_AMBI_CHANNELS ((MAX_AMBI_ORDER+1) * (MAX_AMBI_ORDER+1)) +constexpr inline size_t AmbiChannelsFromOrder(size_t order) noexcept +{ return (order+1) * (order+1); } +#define MAX_AMBI_CHANNELS AmbiChannelsFromOrder(MAX_AMBI_ORDER) /* A bitmask of ambisonic channels for 0 to 4th order. This only specifies up * to 4th order, which is the highest order a 32-bit mask value can specify (a @@ -30,7 +32,9 @@ * representation. This is 2 per each order above zero-order, plus 1 for zero- * order. Or simply, o*2 + 1. */ -#define MAX_AMBI2D_CHANNELS (MAX_AMBI_ORDER*2 + 1) +constexpr inline size_t Ambi2DChannelsFromOrder(size_t order) noexcept +{ return order*2 + 1; } +#define MAX_AMBI2D_CHANNELS Ambi2DChannelsFromOrder(MAX_AMBI_CHANNELS) /* NOTE: These are scale factors as applied to Ambisonics content. Decoder diff --git a/Alc/bformatdec.cpp b/Alc/bformatdec.cpp index d735b94c..efac73ca 100644 --- a/Alc/bformatdec.cpp +++ b/Alc/bformatdec.cpp @@ -92,17 +92,17 @@ void BFormatDec::reset(const AmbDecConf *conf, bool allow_2band, ALsizei inchans const bool periphonic{(conf->ChanMask&AMBI_PERIPHONIC_MASK) != 0}; const std::array<float,MAX_AMBI_CHANNELS> &coeff_scale = GetAmbiScales(conf->CoeffScale); - const ALsizei coeff_count{periphonic ? MAX_AMBI_CHANNELS : MAX_AMBI2D_CHANNELS}; + const size_t coeff_count{periphonic ? MAX_AMBI_CHANNELS : MAX_AMBI2D_CHANNELS}; if(!mDualBand) { for(size_t i{0u};i < conf->Speakers.size();i++) { ALfloat (&mtx)[MAX_AMBI_CHANNELS] = mMatrix.Single[chanmap[i]]; - for(ALsizei j{0},k{0};j < coeff_count;j++) + for(size_t j{0},k{0};j < coeff_count;j++) { - const ALsizei l{periphonic ? j : AmbiIndex::From2D[j]}; - if(!(conf->ChanMask&(1<<l))) continue; + const size_t l{periphonic ? j : AmbiIndex::From2D[j]}; + if(!(conf->ChanMask&(1u<<l))) continue; mtx[j] = conf->HFMatrix[i][k] / coeff_scale[l] * ((l>=9) ? conf->HFOrderGain[3] : (l>=4) ? conf->HFOrderGain[2] : @@ -120,10 +120,10 @@ void BFormatDec::reset(const AmbDecConf *conf, bool allow_2band, ALsizei inchans for(size_t i{0u};i < conf->Speakers.size();i++) { ALfloat (&mtx)[sNumBands][MAX_AMBI_CHANNELS] = mMatrix.Dual[chanmap[i]]; - for(ALsizei j{0},k{0};j < coeff_count;j++) + for(size_t j{0},k{0};j < coeff_count;j++) { - const ALsizei l{periphonic ? j : AmbiIndex::From2D[j]}; - if(!(conf->ChanMask&(1<<l))) continue; + const size_t l{periphonic ? j : AmbiIndex::From2D[j]}; + if(!(conf->ChanMask&(1u<<l))) continue; mtx[sHFBand][j] = conf->HFMatrix[i][k] / coeff_scale[l] * ((l>=9) ? conf->HFOrderGain[3] : (l>=4) ? conf->HFOrderGain[2] : diff --git a/Alc/panning.cpp b/Alc/panning.cpp index af480184..7e8accff 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -496,7 +496,7 @@ void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei ALsizei count; if((conf->ChanMask&AMBI_PERIPHONIC_MASK)) { - count = (order+1) * (order+1); + count = AmbiChannelsFromOrder(order); std::transform(AmbiIndex::From3D.begin(), AmbiIndex::From3D.begin()+count, std::begin(device->Dry.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } @@ -504,7 +504,7 @@ void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei } else { - count = order*2 + 1; + count = Ambi2DChannelsFromOrder(order); std::transform(AmbiIndex::From2D.begin(), AmbiIndex::From2D.begin()+count, std::begin(device->Dry.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } @@ -567,7 +567,7 @@ void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&sp ALsizei count; if((conf->ChanMask&AMBI_PERIPHONIC_MASK)) { - count = (order+1) * (order+1); + count = AmbiChannelsFromOrder(order); std::transform(AmbiIndex::From3D.begin(), AmbiIndex::From3D.begin()+count, std::begin(device->Dry.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } @@ -575,7 +575,7 @@ void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&sp } else { - count = order*2 + 1; + count = Ambi2DChannelsFromOrder(order); std::transform(AmbiIndex::From2D.begin(), AmbiIndex::From2D.begin()+count, std::begin(device->Dry.AmbiMap), [](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; } @@ -714,7 +714,7 @@ void InitHrtfPanning(ALCdevice *device) } device->mAmbiOrder = ambi_order; - const ALsizei count{(ambi_order+1) * (ambi_order+1)}; + const size_t count{AmbiChannelsFromOrder(ambi_order)}; device->mHrtfState = DirectHrtfState::Create(count); std::transform(std::begin(IndexMap), std::begin(IndexMap)+count, std::begin(device->Dry.AmbiMap), @@ -749,9 +749,9 @@ void InitHrtfPanning(ALCdevice *device) void InitUhjPanning(ALCdevice *device) { /* UHJ is always 2D first-order. */ - static constexpr ALsizei count{3}; + static constexpr size_t count{Ambi2DChannelsFromOrder(1)}; - device->mAmbiOrder = (count-1) / 2; + device->mAmbiOrder = 1; auto acnmap_end = AmbiIndex::FromFuMa.begin() + count; std::transform(AmbiIndex::FromFuMa.begin(), acnmap_end, std::begin(device->Dry.AmbiMap), |