Add a command-line option to force mono input with makemhr
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user