Add helpers to get the channel count from an ambisonic order

This commit is contained in:
Chris Robinson
2019-02-21 04:05:49 -08:00
parent a35255291f
commit a964890537
3 changed files with 20 additions and 16 deletions
+6 -2
View File
@@ -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
+7 -7
View File
@@ -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] :
+7 -7
View File
@@ -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),