Use std::array in place of some C-style arrays
This commit is contained in:
+12
-10
@@ -1,6 +1,8 @@
|
||||
#ifndef AMBIDEFS_H
|
||||
#define AMBIDEFS_H
|
||||
|
||||
#include <array>
|
||||
|
||||
/* The maximum number of Ambisonics coefficients. For a given order (o), the
|
||||
* size needed will be (o+1)**2, thus zero-order has 1, first-order has 4,
|
||||
* second-order has 9, third-order has 16, and fourth-order has 25.
|
||||
@@ -35,11 +37,11 @@
|
||||
* coefficients should be divided by these values to get proper scalings.
|
||||
*/
|
||||
struct AmbiScale {
|
||||
static constexpr float FromN3D[MAX_AMBI_COEFFS]{
|
||||
static constexpr std::array<float,MAX_AMBI_COEFFS> FromN3D{{
|
||||
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
||||
1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f
|
||||
};
|
||||
static constexpr float FromSN3D[MAX_AMBI_COEFFS]{
|
||||
}};
|
||||
static constexpr std::array<float,MAX_AMBI_COEFFS> FromSN3D{{
|
||||
1.000000000f, /* ACN 0, sqrt(1) */
|
||||
1.732050808f, /* ACN 1, sqrt(3) */
|
||||
1.732050808f, /* ACN 2, sqrt(3) */
|
||||
@@ -56,8 +58,8 @@ struct AmbiScale {
|
||||
2.645751311f, /* ACN 13, sqrt(7) */
|
||||
2.645751311f, /* ACN 14, sqrt(7) */
|
||||
2.645751311f, /* ACN 15, sqrt(7) */
|
||||
};
|
||||
static constexpr float FromFuMa[MAX_AMBI_COEFFS]{
|
||||
}};
|
||||
static constexpr std::array<float,MAX_AMBI_COEFFS> FromFuMa{{
|
||||
1.414213562f, /* ACN 0 (W), sqrt(2) */
|
||||
1.732050808f, /* ACN 1 (Y), sqrt(3) */
|
||||
1.732050808f, /* ACN 2 (Z), sqrt(3) */
|
||||
@@ -74,11 +76,11 @@ struct AmbiScale {
|
||||
2.231093404f, /* ACN 13 (L), sqrt(224/45) */
|
||||
1.972026594f, /* ACN 14 (N), sqrt(35)/3 */
|
||||
2.091650066f, /* ACN 15 (P), sqrt(35/8) */
|
||||
};
|
||||
}};
|
||||
};
|
||||
|
||||
struct AmbiIndex {
|
||||
static constexpr int FromFuMa[MAX_AMBI_COEFFS]{
|
||||
static constexpr std::array<int,MAX_AMBI_COEFFS> FromFuMa{{
|
||||
0, /* W */
|
||||
3, /* X */
|
||||
1, /* Y */
|
||||
@@ -95,11 +97,11 @@ struct AmbiIndex {
|
||||
10, /* O */
|
||||
15, /* P */
|
||||
9, /* Q */
|
||||
};
|
||||
static constexpr int FromACN[MAX_AMBI_COEFFS]{
|
||||
}};
|
||||
static constexpr std::array<int,MAX_AMBI_COEFFS> FromACN{{
|
||||
0, 1, 2, 3, 4, 5, 6, 7,
|
||||
8, 9, 10, 11, 12, 13, 14, 15
|
||||
};
|
||||
}};
|
||||
};
|
||||
|
||||
#endif /* AMBIDEFS_H */
|
||||
|
||||
+2
-2
@@ -51,7 +51,7 @@ constexpr ALfloat Ambi3DDecoderHFScale[MAX_AMBI_COEFFS] = {
|
||||
};
|
||||
|
||||
|
||||
auto GetAmbiScales(AmbDecScale scaletype) noexcept -> const float(&)[MAX_AMBI_COEFFS]
|
||||
auto GetAmbiScales(AmbDecScale scaletype) noexcept -> const std::array<float,MAX_AMBI_COEFFS>&
|
||||
{
|
||||
if(scaletype == AmbDecScale::FuMa) return AmbiScale::FromFuMa;
|
||||
if(scaletype == AmbDecScale::SN3D) return AmbiScale::FromSN3D;
|
||||
@@ -130,7 +130,7 @@ void BFormatDec::reset(const AmbDecConf *conf, ALsizei chancount, ALuint srate,
|
||||
mUpSampler[3].Gains[LF_BAND] = 0.0f;
|
||||
}
|
||||
|
||||
const float (&coeff_scale)[MAX_AMBI_COEFFS] = GetAmbiScales(conf->CoeffScale);
|
||||
const std::array<float,MAX_AMBI_COEFFS> &coeff_scale = GetAmbiScales(conf->CoeffScale);
|
||||
const ALsizei coeff_count{periphonic ? MAX_AMBI_COEFFS : MAX_AMBI2D_COEFFS};
|
||||
|
||||
mMatrix = MatrixU{};
|
||||
|
||||
+18
-19
@@ -42,11 +42,11 @@
|
||||
#include "bs2b.h"
|
||||
|
||||
|
||||
constexpr float AmbiScale::FromN3D[MAX_AMBI_COEFFS];
|
||||
constexpr float AmbiScale::FromSN3D[MAX_AMBI_COEFFS];
|
||||
constexpr float AmbiScale::FromFuMa[MAX_AMBI_COEFFS];
|
||||
constexpr int AmbiIndex::FromFuMa[MAX_AMBI_COEFFS];
|
||||
constexpr int AmbiIndex::FromACN[MAX_AMBI_COEFFS];
|
||||
constexpr std::array<float,MAX_AMBI_COEFFS> AmbiScale::FromN3D;
|
||||
constexpr std::array<float,MAX_AMBI_COEFFS> AmbiScale::FromSN3D;
|
||||
constexpr std::array<float,MAX_AMBI_COEFFS> AmbiScale::FromFuMa;
|
||||
constexpr std::array<int,MAX_AMBI_COEFFS> AmbiIndex::FromFuMa;
|
||||
constexpr std::array<int,MAX_AMBI_COEFFS> AmbiIndex::FromACN;
|
||||
|
||||
|
||||
namespace {
|
||||
@@ -324,21 +324,21 @@ void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, const ALsizei (
|
||||
}
|
||||
}
|
||||
|
||||
auto GetAmbiScales(AmbDecScale scaletype) noexcept -> const float(&)[MAX_AMBI_COEFFS]
|
||||
auto GetAmbiScales(AmbDecScale scaletype) noexcept -> const std::array<float,MAX_AMBI_COEFFS>&
|
||||
{
|
||||
if(scaletype == AmbDecScale::FuMa) return AmbiScale::FromFuMa;
|
||||
if(scaletype == AmbDecScale::SN3D) return AmbiScale::FromSN3D;
|
||||
return AmbiScale::FromN3D;
|
||||
}
|
||||
|
||||
auto GetAmbiScales(AmbiNorm scaletype) noexcept -> const float(&)[MAX_AMBI_COEFFS]
|
||||
auto GetAmbiScales(AmbiNorm scaletype) noexcept -> const std::array<float,MAX_AMBI_COEFFS>&
|
||||
{
|
||||
if(scaletype == AmbiNorm::FuMa) return AmbiScale::FromFuMa;
|
||||
if(scaletype == AmbiNorm::SN3D) return AmbiScale::FromSN3D;
|
||||
return AmbiScale::FromN3D;
|
||||
}
|
||||
|
||||
auto GetAmbiLayout(AmbiLayout layouttype) noexcept -> const int(&)[MAX_AMBI_COEFFS]
|
||||
auto GetAmbiLayout(AmbiLayout layouttype) noexcept -> const std::array<int,MAX_AMBI_COEFFS>&
|
||||
{
|
||||
if(layouttype == AmbiLayout::FuMa) return AmbiIndex::FromFuMa;
|
||||
return AmbiIndex::FromACN;
|
||||
@@ -402,14 +402,13 @@ void InitPanning(ALCdevice *device)
|
||||
if(device->FmtChans == DevFmtAmbi3D)
|
||||
{
|
||||
const char *devname{device->DeviceName.c_str()};
|
||||
const ALsizei (&acnmap)[MAX_AMBI_COEFFS] = GetAmbiLayout(device->mAmbiLayout);
|
||||
const ALfloat (&n3dscale)[MAX_AMBI_COEFFS] = GetAmbiScales(device->mAmbiScale);
|
||||
const std::array<int,MAX_AMBI_COEFFS> &acnmap = GetAmbiLayout(device->mAmbiLayout);
|
||||
const std::array<float,MAX_AMBI_COEFFS> &n3dscale = GetAmbiScales(device->mAmbiScale);
|
||||
|
||||
count = (device->mAmbiOrder == 3) ? 16 :
|
||||
(device->mAmbiOrder == 2) ? 9 :
|
||||
(device->mAmbiOrder == 1) ? 4 : 1;
|
||||
auto acnmap_end = std::begin(acnmap) + count;
|
||||
std::transform(std::begin(acnmap), acnmap_end, std::begin(device->Dry.Ambi.Map),
|
||||
std::transform(acnmap.begin(), acnmap.begin()+count, std::begin(device->Dry.Ambi.Map),
|
||||
[&n3dscale](const ALsizei &acn) noexcept -> BFChannelConfig
|
||||
{ return BFChannelConfig{1.0f/n3dscale[acn], acn}; }
|
||||
);
|
||||
@@ -428,7 +427,7 @@ void InitPanning(ALCdevice *device)
|
||||
* The upsampler expects this and will convert it for output.
|
||||
*/
|
||||
device->FOAOut.Ambi = AmbiConfig{};
|
||||
std::transform(std::begin(AmbiIndex::FromACN), std::begin(AmbiIndex::FromACN)+4,
|
||||
std::transform(AmbiIndex::FromACN.begin(), AmbiIndex::FromACN.begin()+4,
|
||||
std::begin(device->FOAOut.Ambi.Map),
|
||||
[](const ALsizei &acn) noexcept { return BFChannelConfig{1.0f, acn}; }
|
||||
);
|
||||
@@ -463,7 +462,7 @@ void InitPanning(ALCdevice *device)
|
||||
else
|
||||
{
|
||||
device->FOAOut.Ambi = AmbiConfig{};
|
||||
std::transform(std::begin(AmbiIndex::FromACN), std::begin(AmbiIndex::FromACN)+4,
|
||||
std::transform(AmbiIndex::FromACN.begin(), AmbiIndex::FromACN.begin()+4,
|
||||
std::begin(device->FOAOut.Ambi.Map),
|
||||
[](const ALsizei &acn) noexcept { return BFChannelConfig{1.0f, acn}; }
|
||||
);
|
||||
@@ -483,7 +482,7 @@ void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei
|
||||
ERR("Basic renderer uses the high-frequency matrix as single-band (xover_freq = %.0fhz)\n",
|
||||
conf->XOverFreq);
|
||||
|
||||
const ALfloat (&coeff_scale)[MAX_AMBI_COEFFS] = GetAmbiScales(conf->CoeffScale);
|
||||
const std::array<float,MAX_AMBI_COEFFS> &coeff_scale = GetAmbiScales(conf->CoeffScale);
|
||||
ChannelMap chanmap[MAX_OUTPUT_CHANNELS]{};
|
||||
for(size_t i{0u};i < conf->Speakers.size();i++)
|
||||
{
|
||||
@@ -747,8 +746,8 @@ void InitUhjPanning(ALCdevice *device)
|
||||
{
|
||||
static constexpr ALsizei count{3};
|
||||
|
||||
auto acnmap_end = std::begin(AmbiIndex::FromFuMa) + count;
|
||||
std::transform(std::begin(AmbiIndex::FromFuMa), acnmap_end, std::begin(device->Dry.Ambi.Map),
|
||||
auto acnmap_end = AmbiIndex::FromFuMa.begin() + count;
|
||||
std::transform(AmbiIndex::FromFuMa.begin(), acnmap_end, std::begin(device->Dry.Ambi.Map),
|
||||
[](const ALsizei &acn) noexcept -> BFChannelConfig
|
||||
{ return BFChannelConfig{1.0f/AmbiScale::FromFuMa[acn], acn}; }
|
||||
);
|
||||
@@ -1146,8 +1145,8 @@ no_hrtf:
|
||||
void aluInitEffectPanning(ALeffectslot *slot)
|
||||
{
|
||||
const size_t count{countof(slot->ChanMap)};
|
||||
auto acnmap_end = std::begin(AmbiIndex::FromACN) + count;
|
||||
std::transform(std::begin(AmbiIndex::FromACN), acnmap_end, std::begin(slot->ChanMap),
|
||||
auto acnmap_end = AmbiIndex::FromACN.begin() + count;
|
||||
std::transform(AmbiIndex::FromACN.begin(), acnmap_end, std::begin(slot->ChanMap),
|
||||
[](const ALsizei &acn) noexcept { return BFChannelConfig{1.0f, acn}; }
|
||||
);
|
||||
slot->NumChannels = static_cast<ALsizei>(count);
|
||||
|
||||
Reference in New Issue
Block a user