aboutsummaryrefslogtreecommitdiffstats
path: root/utils/makemhr
diff options
context:
space:
mode:
Diffstat (limited to 'utils/makemhr')
-rw-r--r--utils/makemhr/loaddef.cpp21
-rw-r--r--utils/makemhr/loadsofa.cpp19
-rw-r--r--utils/makemhr/makemhr.cpp39
3 files changed, 40 insertions, 39 deletions
diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp
index 04489173..b33dbc75 100644
--- a/utils/makemhr/loaddef.cpp
+++ b/utils/makemhr/loaddef.cpp
@@ -38,6 +38,7 @@
#include "albit.h"
#include "alfstream.h"
+#include "alnumeric.h"
#include "alspan.h"
#include "alstring.h"
#include "makemhr.h"
@@ -1153,7 +1154,7 @@ static int LoadSofaSource(SourceRefT *src, const uint hrirRate, const uint n, do
return 0;
}
- al::span<float,3> coords{&sofa->hrtf->SourcePosition.values[3 * nearest], 3};
+ al::span<float,3> coords{&sofa->hrtf->SourcePosition.values[3_z * nearest], 3};
if(std::abs(coords[0] - target[0]) > 0.001 || std::abs(coords[1] - target[1]) > 0.001
|| std::abs(coords[2] - target[2]) > 0.001)
{
@@ -1745,12 +1746,12 @@ static void AverageHrirMagnitude(const uint points, const uint n, const double *
static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate)
{
const uint channels{(hData->mChannelType == CT_STEREO) ? 2u : 1u};
- hData->mHrirsBase.resize(channels * hData->mIrCount * hData->mIrSize);
+ hData->mHrirsBase.resize(size_t{channels} * hData->mIrCount * hData->mIrSize);
double *hrirs = hData->mHrirsBase.data();
auto hrir = std::vector<double>(hData->mIrSize);
uint line, col, fi, ei, ai;
- std::vector<double> onsetSamples(OnsetRateMultiple * hData->mIrPoints);
+ std::vector<double> onsetSamples(size_t{OnsetRateMultiple} * hData->mIrPoints);
PPhaseResampler onsetResampler;
onsetResampler.init(hData->mIrRate, OnsetRateMultiple*hData->mIrRate);
@@ -1828,9 +1829,9 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate
fflush(stdout);
std::array aer{
- sofa->hrtf->SourcePosition.values[3*si],
- sofa->hrtf->SourcePosition.values[3*si + 1],
- sofa->hrtf->SourcePosition.values[3*si + 2]
+ sofa->hrtf->SourcePosition.values[3_uz*si],
+ sofa->hrtf->SourcePosition.values[3_uz*si + 1],
+ sofa->hrtf->SourcePosition.values[3_uz*si + 2]
};
mysofa_c2s(aer.data());
@@ -1869,7 +1870,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate
}
ExtractSofaHrir(sofa, si, 0, src.mOffset, hData->mIrPoints, hrir.data());
- azd->mIrs[0] = &hrirs[hData->mIrSize * azd->mIndex];
+ azd->mIrs[0] = &hrirs[size_t{hData->mIrSize} * azd->mIndex];
azd->mDelays[0] = AverageHrirOnset(onsetResampler, onsetSamples, hData->mIrRate,
hData->mIrPoints, hrir.data(), 1.0, azd->mDelays[0]);
if(resampler)
@@ -1879,7 +1880,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate
if(src.mChannel == 1)
{
ExtractSofaHrir(sofa, si, 1, src.mOffset, hData->mIrPoints, hrir.data());
- azd->mIrs[1] = &hrirs[hData->mIrSize * (hData->mIrCount + azd->mIndex)];
+ azd->mIrs[1] = &hrirs[hData->mIrSize * (size_t{hData->mIrCount}+azd->mIndex)];
azd->mDelays[1] = AverageHrirOnset(onsetResampler, onsetSamples,
hData->mIrRate, hData->mIrPoints, hrir.data(), 1.0, azd->mDelays[1]);
if(resampler)
@@ -1940,7 +1941,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate
return 0;
}
}
- azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti * hData->mIrCount + azd->mIndex)];
+ azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti*size_t{hData->mIrCount} + azd->mIndex)];
azd->mDelays[ti] = AverageHrirOnset(onsetResampler, onsetSamples, hData->mIrRate,
hData->mIrPoints, hrir.data(), 1.0 / factor[ti], azd->mDelays[ti]);
if(resampler)
@@ -2017,7 +2018,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData, const uint outRate
{
HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
- azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti * hData->mIrCount + azd->mIndex)];
+ azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti*size_t{hData->mIrCount} + azd->mIndex)];
}
}
}
diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp
index eaddd31b..c29cb45c 100644
--- a/utils/makemhr/loadsofa.cpp
+++ b/utils/makemhr/loadsofa.cpp
@@ -39,6 +39,7 @@
#include <vector>
#include "alspan.h"
+#include "alnumeric.h"
#include "makemhr.h"
#include "polyphase_resampler.h"
#include "sofa-support.h"
@@ -261,7 +262,7 @@ static bool LoadResponses(MYSOFA_HRTF *sofaHrtf, HrirDataT *hData, const DelayTy
auto load_proc = [sofaHrtf,hData,delayType,outRate,&loaded_count]() -> bool
{
const uint channels{(hData->mChannelType == CT_STEREO) ? 2u : 1u};
- hData->mHrirsBase.resize(channels * hData->mIrCount * hData->mIrSize, 0.0);
+ hData->mHrirsBase.resize(channels * size_t{hData->mIrCount} * hData->mIrSize, 0.0);
double *hrirs = hData->mHrirsBase.data();
std::vector<double> restmp;
@@ -277,9 +278,9 @@ static bool LoadResponses(MYSOFA_HRTF *sofaHrtf, HrirDataT *hData, const DelayTy
loaded_count.fetch_add(1u);
std::array aer{
- sofaHrtf->SourcePosition.values[3*si],
- sofaHrtf->SourcePosition.values[3*si + 1],
- sofaHrtf->SourcePosition.values[3*si + 2]
+ sofaHrtf->SourcePosition.values[3_uz*si],
+ sofaHrtf->SourcePosition.values[3_uz*si + 1],
+ sofaHrtf->SourcePosition.values[3_uz*si + 2]
};
mysofa_c2s(aer.data());
@@ -317,13 +318,13 @@ static bool LoadResponses(MYSOFA_HRTF *sofaHrtf, HrirDataT *hData, const DelayTy
for(uint ti{0u};ti < channels;++ti)
{
- azd->mIrs[ti] = &hrirs[hData->mIrSize * (hData->mIrCount*ti + azd->mIndex)];
+ azd->mIrs[ti] = &hrirs[(size_t{hData->mIrCount}*ti + azd->mIndex)*hData->mIrSize];
if(!resampler)
- std::copy_n(&sofaHrtf->DataIR.values[(si*sofaHrtf->R + ti)*sofaHrtf->N],
+ std::copy_n(&sofaHrtf->DataIR.values[(size_t{si}*sofaHrtf->R + ti)*sofaHrtf->N],
sofaHrtf->N, azd->mIrs[ti]);
else
{
- std::copy_n(&sofaHrtf->DataIR.values[(si*sofaHrtf->R + ti)*sofaHrtf->N],
+ std::copy_n(&sofaHrtf->DataIR.values[(size_t{si}*sofaHrtf->R + ti)*sofaHrtf->N],
sofaHrtf->N, restmp.data());
resampler->process(sofaHrtf->N, restmp.data(), hData->mIrSize, azd->mIrs[ti]);
}
@@ -520,7 +521,7 @@ bool LoadSofaFile(const char *filename, const uint numThreads, const uint fftSiz
for(uint ai{0u};ai < hData->mFds[fi].mEvs[ei].mAzs.size();ai++)
{
HrirAzT &azd = hData->mFds[fi].mEvs[ei].mAzs[ai];
- for(uint ti{0u};ti < channels;ti++)
+ for(size_t ti{0u};ti < channels;ti++)
azd.mIrs[ti] = &hrirs[hData->mIrSize * (hData->mIrCount*ti + azd.mIndex)];
}
}
@@ -533,7 +534,7 @@ bool LoadSofaFile(const char *filename, const uint numThreads, const uint fftSiz
auto onset_proc = [hData,channels,&hrir_done]() -> bool
{
/* Temporary buffer used to calculate the IR's onset. */
- auto upsampled = std::vector<double>(OnsetRateMultiple * hData->mIrPoints);
+ auto upsampled = std::vector<double>(size_t{OnsetRateMultiple} * hData->mIrPoints);
/* This resampler is used to help detect the response onset. */
PPhaseResampler rs;
rs.init(hData->mIrRate, OnsetRateMultiple*hData->mIrRate);
diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp
index 014b2967..2b6d04ce 100644
--- a/utils/makemhr/makemhr.cpp
+++ b/utils/makemhr/makemhr.cpp
@@ -91,6 +91,7 @@
#include "alcomplex.h"
#include "alfstream.h"
#include "alnumbers.h"
+#include "alnumeric.h"
#include "alspan.h"
#include "alstring.h"
#include "loaddef.h"
@@ -383,7 +384,7 @@ static int StoreMhr(const HrirDataT *hData, const char *filename)
for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzs.size();ai++)
{
HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
- std::array<double,2*MaxTruncSize> out{};
+ std::array<double,MaxTruncSize*2_uz> out{};
TpdfDither(out.data(), azd->mIrs[0], scale, n, channels, &dither_seed);
if(hData->mChannelType == CT_STEREO)
@@ -532,7 +533,7 @@ static void CalculateDiffuseFieldAverage(const HrirDataT *hData, const uint chan
const int weighted, const double limit, double *dfa)
{
std::vector<double> weights(hData->mFds.size() * MAX_EV_COUNT);
- uint count, ti, fi, ei, i, ai;
+ uint count;
if(weighted)
{
@@ -546,41 +547,41 @@ static void CalculateDiffuseFieldAverage(const HrirDataT *hData, const uint chan
// If coverage weighting is not used, the weights still need to be
// averaged by the number of existing HRIRs.
count = hData->mIrCount;
- for(fi = 0;fi < hData->mFds.size();fi++)
+ for(size_t fi{0};fi < hData->mFds.size();++fi)
{
- for(ei = 0;ei < hData->mFds[fi].mEvStart;ei++)
+ for(size_t ei{0};ei < hData->mFds[fi].mEvStart;++ei)
count -= static_cast<uint>(hData->mFds[fi].mEvs[ei].mAzs.size());
}
weight = 1.0 / count;
- for(fi = 0;fi < hData->mFds.size();fi++)
+ for(size_t fi{0};fi < hData->mFds.size();++fi)
{
- for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvs.size();ei++)
+ for(size_t ei{hData->mFds[fi].mEvStart};ei < hData->mFds[fi].mEvs.size();++ei)
weights[(fi * MAX_EV_COUNT) + ei] = weight;
}
}
- for(ti = 0;ti < channels;ti++)
+ for(size_t ti{0};ti < channels;++ti)
{
- for(i = 0;i < m;i++)
+ for(size_t i{0};i < m;++i)
dfa[(ti * m) + i] = 0.0;
- for(fi = 0;fi < hData->mFds.size();fi++)
+ for(size_t fi{0};fi < hData->mFds.size();++fi)
{
- for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvs.size();ei++)
+ for(size_t ei{hData->mFds[fi].mEvStart};ei < hData->mFds[fi].mEvs.size();++ei)
{
- for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzs.size();ai++)
+ for(size_t ai{0};ai < hData->mFds[fi].mEvs[ei].mAzs.size();++ai)
{
HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai];
// Get the weight for this HRIR's contribution.
double weight = weights[(fi * MAX_EV_COUNT) + ei];
// Add this HRIR's weighted power average to the total.
- for(i = 0;i < m;i++)
+ for(size_t i{0};i < m;++i)
dfa[(ti * m) + i] += weight * azd->mIrs[ti][i] * azd->mIrs[ti][i];
}
}
}
// Finish the average calculation and keep it from being too small.
- for(i = 0;i < m;i++)
+ for(size_t i{0};i < m;++i)
dfa[(ti * m) + i] = std::max(sqrt(dfa[(ti * m) + i]), Epsilon);
// Apply a limit to the magnitude range of the diffuse-field average
// if desired.
@@ -593,17 +594,15 @@ static void CalculateDiffuseFieldAverage(const HrirDataT *hData, const uint chan
// set using the given average response.
static void DiffuseFieldEqualize(const uint channels, const uint m, const double *dfa, const HrirDataT *hData)
{
- uint ti, fi, ei, i;
-
- for(fi = 0;fi < hData->mFds.size();fi++)
+ for(size_t fi{0};fi < hData->mFds.size();++fi)
{
- for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvs.size();ei++)
+ for(size_t ei{hData->mFds[fi].mEvStart};ei < hData->mFds[fi].mEvs.size();++ei)
{
for(auto &azd : hData->mFds[fi].mEvs[ei].mAzs)
{
- for(ti = 0;ti < channels;ti++)
+ for(size_t ti{0};ti < channels;++ti)
{
- for(i = 0;i < m;i++)
+ for(size_t i{0};i < m;++i)
azd.mIrs[ti][i] /= dfa[(ti * m) + i];
}
}
@@ -1224,7 +1223,7 @@ static int ProcessDefinition(const char *inName, const uint outRate, const Chann
{
uint c{(hData.mChannelType == CT_STEREO) ? 2u : 1u};
uint m{hData.mFftSize/2u + 1u};
- auto dfa = std::vector<double>(c * m);
+ auto dfa = std::vector<double>(size_t{c} * m);
if(hData.mFds.size() > 1)
{