Skip to content

Commit

Permalink
Merge pull request #89 from hoene/issue-87-formative-feedback-about-f…
Browse files Browse the repository at this point in the history
…ormat-errors

Added more error types to be more informative
  • Loading branch information
hoene authored Nov 24, 2019
2 parents b2ea0ec + f9ff998 commit f8762e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/hrtf/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ MYSOFA_EXPORT int mysofa_check(struct MYSOFA_HRTF *hrtf) {
!verifyAttribute(hrtf->attributes, "DataType", "FIR")
|| !verifyAttribute(hrtf->attributes, "RoomType", "free field"))

return MYSOFA_INVALID_FORMAT;
return MYSOFA_INVALID_ATTRIBUTES;

/*==============================================================================
dimensions
============================================================================== */

if (hrtf->C != 3 || hrtf->I != 1 || hrtf->E != 1 || hrtf->R != 2)
return MYSOFA_INVALID_FORMAT;
return MYSOFA_INVALID_DIMENSIONS;

/* verify format */

if (hrtf->ListenerView.values) {
if (!verifyAttribute(hrtf->ListenerView.attributes, "DIMENSION_LIST",
"I,C"))
return MYSOFA_INVALID_FORMAT;
return MYSOFA_INVALID_DIMENSION_LIST;
if (verifyAttribute(hrtf->ListenerView.attributes, "Type",
"cartesian")) {
if (!compareValues(&hrtf->ListenerView, array100, 3))
Expand All @@ -80,7 +80,7 @@ MYSOFA_EXPORT int mysofa_check(struct MYSOFA_HRTF *hrtf) {
if (!compareValues(&hrtf->ListenerView, array001, 3))
return MYSOFA_INVALID_FORMAT;
} else
return MYSOFA_INVALID_FORMAT;
return MYSOFA_INVALID_COORDINATE_TYPE;
}

#if 0
Expand All @@ -107,30 +107,30 @@ MYSOFA_EXPORT int mysofa_check(struct MYSOFA_HRTF *hrtf) {
/* TODO: support ECM too */
if (!verifyAttribute(hrtf->EmitterPosition.attributes, "DIMENSION_LIST",
"E,C,I"))
return MYSOFA_INVALID_FORMAT;
return MYSOFA_ONLY_EMITTER_WITH_ECI_SUPPORTED;
if (!compareValues(&hrtf->EmitterPosition, array000, 3))
return MYSOFA_INVALID_FORMAT;
return MYSOFA_ONLY_EMITTER_WITH_ECI_SUPPORTED;

if (hrtf->DataDelay.values) {
if (!verifyAttribute(hrtf->DataDelay.attributes, "DIMENSION_LIST",
"I,R")
&& !verifyAttribute(hrtf->DataDelay.attributes,
"DIMENSION_LIST", "M,R"))
return MYSOFA_INVALID_FORMAT;
return MYSOFA_ONLY_DELAYS_WITH_IR_OR_MR_SUPPORTED;
}

/* TODO: Support different sampling rate per measurement, support default sampling rate of 48000
However, so far, I have not seen any sofa files with an format other and I */
if (!verifyAttribute(hrtf->DataSamplingRate.attributes, "DIMENSION_LIST",
"I"))
return MYSOFA_INVALID_FORMAT;
return MYSOFA_ONLY_THE_SAME_SAMPLING_RATE_SUPPORTED;

if (!verifyAttribute(hrtf->ReceiverPosition.attributes, "DIMENSION_LIST",
"R,C,I"))
return MYSOFA_INVALID_FORMAT;
return MYSOFA_RECEIVERS_WITH_RCI_SUPPORTED;
if (!verifyAttribute(hrtf->ReceiverPosition.attributes, "Type",
"cartesian"))
return MYSOFA_INVALID_FORMAT;
return MYSOFA_RECEIVERS_WITH_CARTESIAN_SUPPORTED;

if (!fequals(hrtf->ReceiverPosition.values[0],
0.) || hrtf->ReceiverPosition.values[1] > 0
Expand All @@ -139,13 +139,13 @@ MYSOFA_EXPORT int mysofa_check(struct MYSOFA_HRTF *hrtf) {
|| !fequals(hrtf->ReceiverPosition.values[4],
-hrtf->ReceiverPosition.values[1])
|| !fequals(hrtf->ReceiverPosition.values[5], 0.)) {
return MYSOFA_INVALID_FORMAT;
return MYSOFA_INVALID_RECEIVER_POSITIONS;
}

/* read source positions */
if (!verifyAttribute(hrtf->SourcePosition.attributes, "DIMENSION_LIST",
"M,C"))
return MYSOFA_INVALID_FORMAT;
return MYSOFA_ONLY_SOURCES_WITH_MC_SUPPORTED;

return MYSOFA_OK;
}
Expand Down
13 changes: 12 additions & 1 deletion src/hrtf/mysofa.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,18 @@ enum {
MYSOFA_INVALID_FORMAT = 10000,
MYSOFA_UNSUPPORTED_FORMAT,
MYSOFA_NO_MEMORY,
MYSOFA_READ_ERROR
MYSOFA_READ_ERROR,
MYSOFA_INVALID_ATTRIBUTES,
MYSOFA_INVALID_DIMENSIONS,
MYSOFA_INVALID_DIMENSION_LIST,
MYSOFA_INVALID_COORDINATE_TYPE,
MYSOFA_ONLY_EMITTER_WITH_ECI_SUPPORTED,
MYSOFA_ONLY_DELAYS_WITH_IR_OR_MR_SUPPORTED,
MYSOFA_ONLY_THE_SAME_SAMPLING_RATE_SUPPORTED,
MYSOFA_RECEIVERS_WITH_RCI_SUPPORTED,
MYSOFA_RECEIVERS_WITH_CARTESIAN_SUPPORTED,
MYSOFA_INVALID_RECEIVER_POSITIONS,
MYSOFA_ONLY_SOURCES_WITH_MC_SUPPORTED
};

struct MYSOFA_HRTF* mysofa_load(const char *filename, int *err);
Expand Down

0 comments on commit f8762e9

Please sign in to comment.