aboutsummaryrefslogtreecommitdiffstats
path: root/utils/makemhr
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-03-25 13:01:44 -0700
committerChris Robinson <[email protected]>2019-03-25 13:01:44 -0700
commitcb02bb00bebefce11092eeb7efaafa8a16a090af (patch)
tree7b4916de7c2b282c9425dbb4be661a02c2aec58d /utils/makemhr
parenta3687db015d4b5942d955e493b2ea4292127ef80 (diff)
Detect SOFA files for makemhr input
Diffstat (limited to 'utils/makemhr')
-rw-r--r--utils/makemhr/loaddef.cpp15
-rw-r--r--utils/makemhr/loaddef.h4
-rw-r--r--utils/makemhr/makemhr.cpp31
3 files changed, 38 insertions, 12 deletions
diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp
index f037689b..b4773e17 100644
--- a/utils/makemhr/loaddef.cpp
+++ b/utils/makemhr/loaddef.cpp
@@ -137,7 +137,7 @@ struct SourceRefT {
// Setup the reader on the given file. The filename can be NULL if no error
// output is desired.
-static void TrSetup(FILE *fp, const char *filename, TokenReaderT *tr)
+static void TrSetup(FILE *fp, const char *startbytes, size_t startbytecount, const char *filename, TokenReaderT *tr)
{
const char *name = nullptr;
@@ -164,6 +164,12 @@ static void TrSetup(FILE *fp, const char *filename, TokenReaderT *tr)
tr->mColumn = 1;
tr->mIn = 0;
tr->mOut = 0;
+
+ if(startbytecount > 0)
+ {
+ memcpy(tr->mRing, startbytes, startbytecount);
+ tr->mIn += startbytecount;
+ }
}
// Prime the reader's ring buffer, and return a result indicating that there
@@ -966,7 +972,7 @@ static int LoadAsciiSource(FILE *fp, const SourceRefT *src, const uint n, double
uint i, j;
double dummy;
- TrSetup(fp, nullptr, &tr);
+ TrSetup(fp, nullptr, 0, nullptr, &tr);
for(i = 0;i < src->mOffset;i++)
{
if(!ReadAsciiAsDouble(&tr, src->mPath, src->mType, static_cast<uint>(src->mBits), &dummy))
@@ -1995,11 +2001,12 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData)
}
-bool LoadDefInput(FILE *fp, const char *filename, const uint fftSize, const uint truncSize, const ChannelModeT chanMode, HrirDataT *hData)
+bool LoadDefInput(FILE *fp, const char *startbytes, size_t startbytecount, const char *filename,
+ const uint fftSize, const uint truncSize, const ChannelModeT chanMode, HrirDataT *hData)
{
TokenReaderT tr;
- TrSetup(fp, filename, &tr);
+ TrSetup(fp, startbytes, startbytecount, filename, &tr);
if(!ProcessMetrics(&tr, fftSize, truncSize, chanMode, hData))
{
if(fp != stdin)
diff --git a/utils/makemhr/loaddef.h b/utils/makemhr/loaddef.h
index 7d37fadc..05862228 100644
--- a/utils/makemhr/loaddef.h
+++ b/utils/makemhr/loaddef.h
@@ -6,7 +6,7 @@
#include "makemhr.h"
-bool LoadDefInput(FILE *fp, const char *filename, const uint fftSize, const uint truncSize,
- const ChannelModeT chanMode, HrirDataT *hData);
+bool LoadDefInput(FILE *fp, const char *startbytes, size_t startbytecount, 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 11f04eb6..6824c542 100644
--- a/utils/makemhr/makemhr.cpp
+++ b/utils/makemhr/makemhr.cpp
@@ -1534,6 +1534,8 @@ 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];
+ char startbytes[4]{};
+ size_t startbytecount{0u};
HrirDataT hData;
FILE *fp;
int ret;
@@ -1551,16 +1553,33 @@ static int ProcessDefinition(const char *inName, const uint outRate, const Chann
fprintf(stderr, "Error: Could not open input file '%s'\n", inName);
return 0;
}
+
+ startbytecount = fread(startbytes, 1, sizeof(startbytes), fp);
+ if(startbytecount != sizeof(startbytes))
+ {
+ fclose(fp);
+ fprintf(stderr, "Error: Could not read input file '%s'\n", inName);
+ return 0;
+ }
+
+ if(startbytes[0] == '\x89' && startbytes[1] == 'H' && startbytes[2] == 'D' &&
+ startbytes[3] == 'F')
+ {
+ fclose(fp);
+ fprintf(stderr, "Error: Direct SOFA input not yet supported\n");
+ return 0;
+ }
}
- fprintf(stdout, "Reading HRIR definition from %s...\n", inName);
- if(!LoadDefInput(fp, inName, fftSize, truncSize, chanMode, &hData))
+ if(fp != nullptr)
{
+ fprintf(stdout, "Reading HRIR definition from %s...\n", inName);
+ const bool success{LoadDefInput(fp, startbytes, startbytecount, inName, fftSize, truncSize,
+ chanMode, &hData)};
if(fp != stdin)
fclose(fp);
- return 0;
+ if(!success)
+ return 0;
}
- if(fp != stdin)
- fclose(fp);
if(equalize)
{
@@ -1660,7 +1679,7 @@ int main(int argc, char *argv[])
model = DEFAULT_HEAD_MODEL;
radius = DEFAULT_CUSTOM_RADIUS;
- while((opt=getopt(argc, argv, "r:m:f:e:s:l:w:d:c:e:i:o:h")) != -1)
+ while((opt=getopt(argc, argv, "r:mf:e:s:l:w:d:c:e:i:o:h")) != -1)
{
switch(opt)
{