diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/makemhr/loaddef.cpp | 11 | ||||
-rw-r--r-- | utils/makemhr/loaddef.h | 2 | ||||
-rw-r--r-- | utils/makemhr/makemhr.cpp | 57 | ||||
-rw-r--r-- | utils/makemhr/makemhr.h | 8 |
4 files changed, 29 insertions, 49 deletions
diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index d4e8db27..904fdc00 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -1701,7 +1701,7 @@ static void AverageHrirMagnitude(const uint points, const uint n, const double * } // Process the list of sources in the data set definition. -int ProcessSources(const HeadModelT model, TokenReaderT *tr, HrirDataT *hData) +int ProcessSources(TokenReaderT *tr, HrirDataT *hData) { uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1; hData->mHrirsBase.resize(channels * hData->mIrCount * hData->mIrSize); @@ -1826,16 +1826,14 @@ int ProcessSources(const HeadModelT model, TokenReaderT *tr, HrirDataT *hData) ExtractSofaHrir(sofa, si, 0, src.mOffset, hData->mIrPoints, hrir.data()); azd->mIrs[0] = &hrirs[hData->mIrSize * azd->mIndex]; - if(model == HM_DATASET) - azd->mDelays[0] = AverageHrirOnset(hData->mIrRate, hData->mIrPoints, hrir.data(), 1.0, azd->mDelays[0]); + azd->mDelays[0] = AverageHrirOnset(hData->mIrRate, hData->mIrPoints, hrir.data(), 1.0, azd->mDelays[0]); AverageHrirMagnitude(hData->mIrPoints, hData->mFftSize, hrir.data(), 1.0, azd->mIrs[0]); if(src.mChannel == 1) { ExtractSofaHrir(sofa, si, 1, src.mOffset, hData->mIrPoints, hrir.data()); azd->mIrs[1] = &hrirs[hData->mIrSize * (hData->mIrCount + azd->mIndex)]; - if(model == HM_DATASET) - azd->mDelays[1] = AverageHrirOnset(hData->mIrRate, hData->mIrPoints, hrir.data(), 1.0, azd->mDelays[1]); + azd->mDelays[1] = AverageHrirOnset(hData->mIrRate, hData->mIrPoints, hrir.data(), 1.0, azd->mDelays[1]); AverageHrirMagnitude(hData->mIrPoints, hData->mFftSize, hrir.data(), 1.0, azd->mIrs[1]); } @@ -1893,8 +1891,7 @@ int ProcessSources(const HeadModelT model, TokenReaderT *tr, HrirDataT *hData) } } azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti * hData->mIrCount + azd->mIndex)]; - if(model == HM_DATASET) - azd->mDelays[ti] = AverageHrirOnset(hData->mIrRate, hData->mIrPoints, hrir.data(), 1.0 / factor[ti], azd->mDelays[ti]); + azd->mDelays[ti] = AverageHrirOnset(hData->mIrRate, hData->mIrPoints, hrir.data(), 1.0 / factor[ti], azd->mDelays[ti]); AverageHrirMagnitude(hData->mIrPoints, hData->mFftSize, hrir.data(), 1.0 / factor[ti], azd->mIrs[ti]); factor[ti] += 1.0; if(!TrIsOperator(tr, "+")) diff --git a/utils/makemhr/loaddef.h b/utils/makemhr/loaddef.h index 5e8c5313..18868967 100644 --- a/utils/makemhr/loaddef.h +++ b/utils/makemhr/loaddef.h @@ -25,6 +25,6 @@ struct TokenReaderT { void TrSetup(FILE *fp, const char *filename, TokenReaderT *tr); int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint truncSize, HrirDataT *hData); -int ProcessSources(const HeadModelT model, TokenReaderT *tr, HrirDataT *hData); +int ProcessSources(TokenReaderT *tr, HrirDataT *hData); #endif /* LOADDEF_H */ diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index 0c2c398c..1d3a9897 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -109,6 +109,14 @@ using namespace std::placeholders; #endif +// Head model used for calculating the impulse delays. +enum HeadModelT { + HM_NONE, + HM_DATASET, // Measure the onset from the dataset. + HM_SPHERE // Calculate the onset using a spherical head model. +}; + + // The epsilon used to maintain signal stability. #define EPSILON (1e-9) @@ -148,13 +156,6 @@ using namespace std::placeholders; // response protocol 02. #define MHR_FORMAT ("MinPHR02") -// Byte order for the serialization routines. -enum ByteOrderT { - BO_NONE, - BO_LITTLE, - BO_BIG -}; - /* Channel index enums. Mono uses LeftChannel only. */ enum ChannelIndex : uint { LeftChannel = 0u, @@ -653,24 +654,14 @@ static int WriteAscii(const char *out, FILE *fp, const char *filename) // Write a binary value of the given byte order and byte size to a file, // loading it from a 32-bit unsigned integer. -static int WriteBin4(const ByteOrderT order, const uint bytes, const uint32_t in, FILE *fp, const char *filename) +static int WriteBin4(const uint bytes, const uint32_t in, FILE *fp, const char *filename) { uint8_t out[4]; uint i; - switch(order) - { - case BO_LITTLE: - for(i = 0;i < bytes;i++) - out[i] = (in>>(i*8)) & 0x000000FF; - break; - case BO_BIG: - for(i = 0;i < bytes;i++) - out[bytes - i - 1] = (in>>(i*8)) & 0x000000FF; - break; - default: - break; - } + for(i = 0;i < bytes;i++) + out[i] = (in>>(i*8)) & 0x000000FF; + if(fwrite(out, 1, bytes, fp) != bytes) { fprintf(stderr, "\nError: Bad write to file '%s'.\n", filename); @@ -695,26 +686,26 @@ static int StoreMhr(const HrirDataT *hData, const char *filename) } if(!WriteAscii(MHR_FORMAT, fp, filename)) return 0; - if(!WriteBin4(BO_LITTLE, 4, hData->mIrRate, fp, filename)) + if(!WriteBin4(4, hData->mIrRate, fp, filename)) return 0; - if(!WriteBin4(BO_LITTLE, 1, static_cast<uint32_t>(hData->mSampleType), fp, filename)) + if(!WriteBin4(1, static_cast<uint32_t>(hData->mSampleType), fp, filename)) return 0; - if(!WriteBin4(BO_LITTLE, 1, static_cast<uint32_t>(hData->mChannelType), fp, filename)) + if(!WriteBin4(1, static_cast<uint32_t>(hData->mChannelType), fp, filename)) return 0; - if(!WriteBin4(BO_LITTLE, 1, hData->mIrPoints, fp, filename)) + if(!WriteBin4(1, hData->mIrPoints, fp, filename)) return 0; - if(!WriteBin4(BO_LITTLE, 1, hData->mFdCount, fp, filename)) + if(!WriteBin4(1, hData->mFdCount, fp, filename)) return 0; for(fi = 0;fi < hData->mFdCount;fi++) { auto fdist = static_cast<uint32_t>(std::round(1000.0 * hData->mFds[fi].mDistance)); - if(!WriteBin4(BO_LITTLE, 2, fdist, fp, filename)) + if(!WriteBin4(2, fdist, fp, filename)) return 0; - if(!WriteBin4(BO_LITTLE, 1, hData->mFds[fi].mEvCount, fp, filename)) + if(!WriteBin4(1, hData->mFds[fi].mEvCount, fp, filename)) return 0; for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) { - if(!WriteBin4(BO_LITTLE, 1, hData->mFds[fi].mEvs[ei].mAzCount, fp, filename)) + if(!WriteBin4(1, hData->mFds[fi].mEvs[ei].mAzCount, fp, filename)) return 0; } } @@ -739,7 +730,7 @@ static int StoreMhr(const HrirDataT *hData, const char *filename) for(i = 0;i < (channels * n);i++) { int v = static_cast<int>(Clamp(out[i], -scale-1.0, scale)); - if(!WriteBin4(BO_LITTLE, bps, static_cast<uint32_t>(v), fp, filename)) + if(!WriteBin4(bps, static_cast<uint32_t>(v), fp, filename)) return 0; } } @@ -754,13 +745,13 @@ static int StoreMhr(const HrirDataT *hData, const char *filename) const HrirAzT &azd = hData->mFds[fi].mEvs[ei].mAzs[ai]; int v = static_cast<int>(std::min(std::round(hData->mIrRate * azd.mDelays[0]), MAX_HRTD)); - if(!WriteBin4(BO_LITTLE, 1, static_cast<uint32_t>(v), fp, filename)) + if(!WriteBin4(1, static_cast<uint32_t>(v), fp, filename)) return 0; if(hData->mChannelType == CT_STEREO) { v = static_cast<int>(std::min(std::round(hData->mIrRate * azd.mDelays[1]), MAX_HRTD)); - if(!WriteBin4(BO_LITTLE, 1, static_cast<uint32_t>(v), fp, filename)) + if(!WriteBin4(1, static_cast<uint32_t>(v), fp, filename)) return 0; } } @@ -1570,7 +1561,7 @@ static int ProcessDefinition(const char *inName, const uint outRate, const uint fclose(fp); return 0; } - if(!ProcessSources(model, &tr, &hData)) + if(!ProcessSources(&tr, &hData)) { if(inName) fclose(fp); diff --git a/utils/makemhr/makemhr.h b/utils/makemhr/makemhr.h index d60aa300..e22c88e9 100644 --- a/utils/makemhr/makemhr.h +++ b/utils/makemhr/makemhr.h @@ -40,14 +40,6 @@ using uint = unsigned int; using complex_d = std::complex<double>; -// Head model used for calculating the impulse delays. -enum HeadModelT { - HM_NONE, - HM_DATASET, // Measure the onset from the dataset. - HM_SPHERE // Calculate the onset using a spherical head model. -}; - - // Sample and channel type enum values. enum SampleTypeT { ST_S16 = 0, |