diff options
author | Chris Robinson <[email protected]> | 2019-03-24 22:43:43 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-03-24 22:43:43 -0700 |
commit | 78aeca10c9913a9bf0a42cc86cf641006031b6ba (patch) | |
tree | 074e817097e2687baceb4966e0ca3e36d8691acd /utils/makemhr | |
parent | 6edfa6e6e0260910576e073288633cdbd3094503 (diff) |
Add a command-line option to force mono input with makemhr
Diffstat (limited to 'utils/makemhr')
-rw-r--r-- | utils/makemhr/loaddef.cpp | 7 | ||||
-rw-r--r-- | utils/makemhr/loaddef.h | 2 | ||||
-rw-r--r-- | utils/makemhr/makemhr.cpp | 20 | ||||
-rw-r--r-- | utils/makemhr/makemhr.h | 5 |
4 files changed, 26 insertions, 8 deletions
diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index 904fdc00..e26d0c5c 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -1181,7 +1181,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, HrirDataT *hData) +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; @@ -1235,6 +1235,11 @@ int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint truncSize, H TrErrorAt(tr, line, col, "Expected a channel type.\n"); return 0; } + else if(hData->mChannelType == CT_STEREO) + { + if(chanMode == CM_ForceMono) + hData->mChannelType = CT_MONO; + } hasType = 1; } else if(strcasecmp(ident, "points") == 0) diff --git a/utils/makemhr/loaddef.h b/utils/makemhr/loaddef.h index 18868967..24d75a65 100644 --- a/utils/makemhr/loaddef.h +++ b/utils/makemhr/loaddef.h @@ -24,7 +24,7 @@ struct TokenReaderT { }; void TrSetup(FILE *fp, const char *filename, TokenReaderT *tr); -int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint truncSize, HrirDataT *hData); +int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint truncSize, const ChannelModeT chanMode, HrirDataT *hData); int ProcessSources(TokenReaderT *tr, HrirDataT *hData); #endif /* LOADDEF_H */ diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index 1d3a9897..327d6992 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -1531,7 +1531,7 @@ int PrepareHrirData(const uint fdCount, const double distances[MAX_FD_COUNT], co * resulting data set as desired. If the input name is NULL it will read * from standard input. */ -static int ProcessDefinition(const char *inName, const uint outRate, const uint fftSize, const int equalize, const int surface, const double limit, const uint truncSize, const HeadModelT model, const double radius, const char *outName) +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; @@ -1555,7 +1555,7 @@ static int ProcessDefinition(const char *inName, const uint outRate, const uint fp = stdin; TrSetup(fp, "<stdin>", &tr); } - if(!ProcessMetrics(&tr, fftSize, truncSize, &hData)) + if(!ProcessMetrics(&tr, fftSize, truncSize, chanMode, &hData)) { if(inName != nullptr) fclose(fp); @@ -1616,6 +1616,8 @@ static void PrintHelp(const char *argv0, FILE *ofile) fprintf(ofile, "Options:\n"); fprintf(ofile, " -r <rate> Change the data set sample rate to the specified value and\n"); fprintf(ofile, " resample the HRIRs accordingly.\n"); + fprintf(ofile, " -m Change the data set to mono, mirroring the left ear for the\n"); + fprintf(ofile, " right ear.\n"); fprintf(ofile, " -f <points> Override the FFT window size (default: %u).\n", DEFAULT_FFTSIZE); fprintf(ofile, " -e {on|off} Toggle diffuse-field equalization (default: %s).\n", (DEFAULT_EQUALIZE ? "on" : "off")); fprintf(ofile, " -s {on|off} Toggle surface-weighted diffuse-field average (default: %s).\n", (DEFAULT_SURFACE ? "on" : "off")); @@ -1638,6 +1640,7 @@ int main(int argc, char *argv[]) uint outRate, fftSize; int equalize, surface; char *end = nullptr; + ChannelModeT chanMode; HeadModelT model; uint truncSize; double radius; @@ -1655,6 +1658,7 @@ int main(int argc, char *argv[]) outName = "./oalsoft_hrtf_%r.mhr"; outRate = 0; + chanMode = CM_AllowStereo; fftSize = DEFAULT_FFTSIZE; equalize = DEFAULT_EQUALIZE; surface = DEFAULT_SURFACE; @@ -1663,7 +1667,7 @@ int main(int argc, char *argv[]) model = DEFAULT_HEAD_MODEL; radius = DEFAULT_CUSTOM_RADIUS; - while((opt=getopt(argc, argv, "r:f:e:s:l:w:d:c:e:i:o:h")) != -1) + while((opt=getopt(argc, argv, "r:m:f:e:s:l:w:d:c:e:i:o:h")) != -1) { switch(opt) { @@ -1676,6 +1680,10 @@ int main(int argc, char *argv[]) } break; + case 'm': + chanMode = CM_ForceMono; + break; + case 'f': fftSize = strtoul(optarg, &end, 10); if(end[0] != '\0' || (fftSize&(fftSize-1)) || fftSize < MIN_FFTSIZE || fftSize > MAX_FFTSIZE) @@ -1771,9 +1779,9 @@ int main(int argc, char *argv[]) } } - if(!ProcessDefinition(inName, outRate, fftSize, equalize, surface, limit, - truncSize, model, radius, outName)) - return -1; + int ret = ProcessDefinition(inName, outRate, chanMode, fftSize, equalize, surface, limit, + truncSize, model, radius, outName); + if(!ret) return -1; fprintf(stdout, "Operation completed.\n"); return EXIT_SUCCESS; diff --git a/utils/makemhr/makemhr.h b/utils/makemhr/makemhr.h index e22c88e9..047813d8 100644 --- a/utils/makemhr/makemhr.h +++ b/utils/makemhr/makemhr.h @@ -40,6 +40,11 @@ using uint = unsigned int; using complex_d = std::complex<double>; +enum ChannelModeT : bool { + CM_AllowStereo = false, + CM_ForceMono = true +}; + // Sample and channel type enum values. enum SampleTypeT { ST_S16 = 0, |