diff options
author | Chris Robinson <[email protected]> | 2019-03-25 00:21:45 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-03-25 00:21:45 -0700 |
commit | a3687db015d4b5942d955e493b2ea4292127ef80 (patch) | |
tree | a3f59f9923e403d4ef72f4d759f06c483fa939b8 /utils | |
parent | 78aeca10c9913a9bf0a42cc86cf641006031b6ba (diff) |
Use only a single function to load the HrirDataT
Diffstat (limited to 'utils')
-rw-r--r-- | utils/makemhr/loaddef.cpp | 45 | ||||
-rw-r--r-- | utils/makemhr/loaddef.h | 22 | ||||
-rw-r--r-- | utils/makemhr/makemhr.cpp | 29 |
3 files changed, 55 insertions, 41 deletions
diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index e26d0c5c..f037689b 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -29,9 +29,26 @@ #include "loaddef.h" +// Constants for accessing the token reader's ring buffer. +#define TR_RING_BITS (16) +#define TR_RING_SIZE (1 << TR_RING_BITS) +#define TR_RING_MASK (TR_RING_SIZE - 1) + // The token reader's load interval in bytes. #define TR_LOAD_SIZE (TR_RING_SIZE >> 2) +// Token reader state for parsing the data set definition. +struct TokenReaderT { + FILE *mFile; + const char *mName; + uint mLine; + uint mColumn; + char mRing[TR_RING_SIZE]; + size_t mIn; + size_t mOut; +}; + + // The maximum identifier length used when processing the data set // definition. #define MAX_IDENT_LEN (16) @@ -120,7 +137,7 @@ struct SourceRefT { // Setup the reader on the given file. The filename can be NULL if no error // output is desired. -void TrSetup(FILE *fp, const char *filename, TokenReaderT *tr) +static void TrSetup(FILE *fp, const char *filename, TokenReaderT *tr) { const char *name = nullptr; @@ -1181,7 +1198,7 @@ static ChannelTypeT MatchChannelType(const char *ident) // Process the data set definition to read and validate the data set metrics. -int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint truncSize, const ChannelModeT chanMode, HrirDataT *hData) +static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint truncSize, const ChannelModeT chanMode, HrirDataT *hData) { int hasRate = 0, hasType = 0, hasPoints = 0, hasRadius = 0; int hasDistance = 0, hasAzimuths = 0; @@ -1706,7 +1723,7 @@ static void AverageHrirMagnitude(const uint points, const uint n, const double * } // Process the list of sources in the data set definition. -int ProcessSources(TokenReaderT *tr, HrirDataT *hData) +static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) { uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1; hData->mHrirsBase.resize(channels * hData->mIrCount * hData->mIrSize); @@ -1976,3 +1993,25 @@ int ProcessSources(TokenReaderT *tr, HrirDataT *hData) mysofa_cache_release_all(); return 0; } + + +bool LoadDefInput(FILE *fp, const char *filename, const uint fftSize, const uint truncSize, const ChannelModeT chanMode, HrirDataT *hData) +{ + TokenReaderT tr; + + TrSetup(fp, filename, &tr); + if(!ProcessMetrics(&tr, fftSize, truncSize, chanMode, hData)) + { + if(fp != stdin) + fclose(fp); + return false; + } + if(!ProcessSources(&tr, hData)) + { + if(fp != stdin) + fclose(fp); + return false; + } + + return true; +} diff --git a/utils/makemhr/loaddef.h b/utils/makemhr/loaddef.h index 24d75a65..7d37fadc 100644 --- a/utils/makemhr/loaddef.h +++ b/utils/makemhr/loaddef.h @@ -6,25 +6,7 @@ #include "makemhr.h" -// Constants for accessing the token reader's ring buffer. -#define TR_RING_BITS (16) -#define TR_RING_SIZE (1 << TR_RING_BITS) -#define TR_RING_MASK (TR_RING_SIZE - 1) - - -// Token reader state for parsing the data set definition. -struct TokenReaderT { - FILE *mFile; - const char *mName; - uint mLine; - uint mColumn; - char mRing[TR_RING_SIZE]; - size_t mIn; - size_t mOut; -}; - -void TrSetup(FILE *fp, const char *filename, TokenReaderT *tr); -int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint truncSize, const ChannelModeT chanMode, HrirDataT *hData); -int ProcessSources(TokenReaderT *tr, HrirDataT *hData); +bool LoadDefInput(FILE *fp, const char *filename, const uint fftSize, const uint truncSize, + const ChannelModeT chanMode, HrirDataT *hData); #endif /* LOADDEF_H */ diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index 327d6992..11f04eb6 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -1534,41 +1534,34 @@ int PrepareHrirData(const uint fdCount, const double distances[MAX_FD_COUNT], co static int ProcessDefinition(const char *inName, const uint outRate, const ChannelModeT chanMode, const uint fftSize, const int equalize, const int surface, const double limit, const uint truncSize, const HeadModelT model, const double radius, const char *outName) { char rateStr[8+1], expName[MAX_PATH_LEN]; - TokenReaderT tr; HrirDataT hData; FILE *fp; int ret; - fprintf(stdout, "Reading HRIR definition from %s...\n", inName?inName:"stdin"); - if(inName != nullptr) + if(!inName) + { + inName = "stdin"; + fp = stdin; + } + else { fp = fopen(inName, "r"); if(fp == nullptr) { - fprintf(stderr, "\nError: Could not open definition file '%s'\n", inName); + fprintf(stderr, "Error: Could not open input file '%s'\n", inName); return 0; } - TrSetup(fp, inName, &tr); } - else + fprintf(stdout, "Reading HRIR definition from %s...\n", inName); + if(!LoadDefInput(fp, inName, fftSize, truncSize, chanMode, &hData)) { - fp = stdin; - TrSetup(fp, "<stdin>", &tr); - } - if(!ProcessMetrics(&tr, fftSize, truncSize, chanMode, &hData)) - { - if(inName != nullptr) - fclose(fp); - return 0; - } - if(!ProcessSources(&tr, &hData)) - { - if(inName) + if(fp != stdin) fclose(fp); return 0; } if(fp != stdin) fclose(fp); + if(equalize) { uint c = (hData.mChannelType == CT_STEREO) ? 2 : 1; |