aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-01-23 01:32:27 -0800
committerChris Robinson <[email protected]>2023-01-23 01:32:27 -0800
commit1ca27df39cc7605b55ffd73cab93f6a174b8d421 (patch)
tree868c57201f009a04349ccc6446597d594697e91b
parent952446ec11422bbb7e9fee2c3f35cb68aaf68fd2 (diff)
Use a span instead of pointer+count
-rw-r--r--utils/makemhr/loaddef.cpp4
-rw-r--r--utils/makemhr/loadsofa.cpp2
-rw-r--r--utils/makemhr/makemhr.cpp26
-rw-r--r--utils/makemhr/makemhr.h4
4 files changed, 19 insertions, 17 deletions
diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp
index b6b62359..6b33d6c4 100644
--- a/utils/makemhr/loaddef.cpp
+++ b/utils/makemhr/loaddef.cpp
@@ -1239,7 +1239,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc
double distances[MAX_FD_COUNT];
uint fdCount = 0;
uint evCounts[MAX_FD_COUNT];
- std::vector<uint> azCounts(MAX_FD_COUNT * MAX_EV_COUNT);
+ auto azCounts = std::vector<uint>(MAX_FD_COUNT * MAX_EV_COUNT);
TrIndication(tr, &line, &col);
while(TrIsIdent(tr))
@@ -1450,7 +1450,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc
}
if(hData->mChannelType == CT_NONE)
hData->mChannelType = CT_MONO;
- if(!PrepareHrirData(fdCount, distances, evCounts, azCounts.data(), hData))
+ if(!PrepareHrirData({distances, fdCount}, evCounts, azCounts.data(), hData))
{
fprintf(stderr, "Error: Out of memory.\n");
exit(-1);
diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp
index 9bcb6316..f175ecc4 100644
--- a/utils/makemhr/loadsofa.cpp
+++ b/utils/makemhr/loadsofa.cpp
@@ -86,7 +86,7 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData)
++fi;
}
fprintf(stdout, "Using %u of %u IRs.\n", ir_total, m);
- return PrepareHrirData(fi, distances, evCounts, azCounts.data(), hData) != 0;
+ return PrepareHrirData({distances, fi}, evCounts, azCounts.data(), hData);
}
diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp
index dac6bd3c..1de69bb2 100644
--- a/utils/makemhr/makemhr.cpp
+++ b/utils/makemhr/makemhr.cpp
@@ -1142,42 +1142,42 @@ static void CalculateHrtds(const HeadModelT model, const double radius, HrirData
}
// Allocate and configure dynamic HRIR structures.
-int PrepareHrirData(const uint fdCount, const double (&distances)[MAX_FD_COUNT],
- const uint (&evCounts)[MAX_FD_COUNT], const uint azCounts[MAX_FD_COUNT * MAX_EV_COUNT],
- HrirDataT *hData)
+bool PrepareHrirData(const al::span<const double> distances,
+ const al::span<const uint,MAX_FD_COUNT> evCounts,
+ const uint azCounts[MAX_FD_COUNT * MAX_EV_COUNT], HrirDataT *hData)
{
- uint evTotal = 0, azTotal = 0, fi, ei, ai;
+ uint evTotal{0}, azTotal{0};
- for(fi = 0;fi < fdCount;fi++)
+ for(size_t fi{0};fi < distances.size();++fi)
{
evTotal += evCounts[fi];
- for(ei = 0;ei < evCounts[fi];ei++)
+ for(size_t ei{0};ei < evCounts[fi];++ei)
azTotal += azCounts[(fi * MAX_EV_COUNT) + ei];
}
- if(!fdCount || !evTotal || !azTotal)
- return 0;
+ if(!evTotal || !azTotal)
+ return false;
hData->mEvsBase.resize(evTotal);
hData->mAzsBase.resize(azTotal);
- hData->mFds.resize(fdCount);
+ hData->mFds.resize(distances.size());
hData->mIrCount = azTotal;
evTotal = 0;
azTotal = 0;
- for(fi = 0;fi < fdCount;fi++)
+ for(size_t fi{0};fi < distances.size();++fi)
{
hData->mFds[fi].mDistance = distances[fi];
hData->mFds[fi].mEvCount = evCounts[fi];
hData->mFds[fi].mEvStart = 0;
hData->mFds[fi].mEvs = &hData->mEvsBase[evTotal];
evTotal += evCounts[fi];
- for(ei = 0;ei < evCounts[fi];ei++)
+ for(uint ei{0};ei < evCounts[fi];++ei)
{
uint azCount = azCounts[(fi * MAX_EV_COUNT) + ei];
hData->mFds[fi].mEvs[ei].mElevation = -M_PI / 2.0 + M_PI * ei / (evCounts[fi] - 1);
hData->mFds[fi].mEvs[ei].mAzCount = azCount;
hData->mFds[fi].mEvs[ei].mAzs = &hData->mAzsBase[azTotal];
- for(ai = 0;ai < azCount;ai++)
+ for(uint ai{0};ai < azCount;ai++)
{
hData->mFds[fi].mEvs[ei].mAzs[ai].mAzimuth = 2.0 * M_PI * ai / azCount;
hData->mFds[fi].mEvs[ei].mAzs[ai].mIndex = azTotal + ai;
@@ -1189,7 +1189,7 @@ int PrepareHrirData(const uint fdCount, const double (&distances)[MAX_FD_COUNT],
azTotal += azCount;
}
}
- return 1;
+ return true;
}
diff --git a/utils/makemhr/makemhr.h b/utils/makemhr/makemhr.h
index 829ce5d6..0ac581be 100644
--- a/utils/makemhr/makemhr.h
+++ b/utils/makemhr/makemhr.h
@@ -108,7 +108,9 @@ struct HrirDataT {
};
-int PrepareHrirData(const uint fdCount, const double (&distances)[MAX_FD_COUNT], const uint (&evCounts)[MAX_FD_COUNT], const uint azCounts[MAX_FD_COUNT * MAX_EV_COUNT], HrirDataT *hData);
+bool PrepareHrirData(const al::span<const double> distances,
+ const al::span<const uint,MAX_FD_COUNT> evCounts,
+ const uint azCounts[MAX_FD_COUNT * MAX_EV_COUNT], HrirDataT *hData);
void MagnitudeResponse(const uint n, const complex_d *in, double *out);
// Performs a forward FFT.