42 const
char* encoded = path;
47 VAE_DEBUG(
"Started loading HRTF %s", path)
53 fs::
File file(folder.c_str());
54 jsonText.resize(file.size());
55 if (!file.readAll(jsonText.data())) {
58 length = jsonText.size();
59 encoded = jsonText.c_str();
68 json_settings settings = { };
75 json = json_parse_ex(&settings, encoded, length, 0);
77 if (json ==
nullptr) {
79 return
Result::BankFormatError;
81 json_value& data = (*json);
83 hrtf.
rate = sampleRate;
84 hrtf.originalRate = (json_int_t) data["samplerate"];
87 float((
double) data[
"up"][0]),
88 float((
double) data[
"up"][1]),
89 float((
double) data[
"up"][2]),
93 float((
double) data[
"front"][0]),
94 float((
double) data[
"front"][1]),
95 float((
double) data[
"front"][2]),
98 LocationOrientation ref;
99 Vec3 frontNeed =
Vec3(ref.front.x, ref.front.y, ref.front.z);
100 Vec3 upNeed =
Vec3(ref.up.x, ref.up.y, ref.up.z);
102 glm::mat4x4 matchCoord = glm::lookAt(
108 Vec3 up1 = (matchCoord * glm::vec4(up, 1.f));
109 Vec3 front1 = (matchCoord * glm::vec4(front, 1.f));
112 auto& positions = data[
"positions"].u.array;
113 const Size positionCount = positions.length;
114 hrtf.positions.resize(positionCount);
116 const bool needsResample = hrtf.originalRate != sampleRate;
119 VAE_ERROR(
"Can't open HRTF, resampling needed!")
120 return
Result::GenericFailure;
123 Size maxIrLength = 0;
126 for (
Size i = 0; i < positionCount; i++) {
127 HRTF::Position& p = hrtf.positions[i];
128 auto& pi = *positions.values[i];
129 glm::vec4 pos((
double) pi[
"x"], (
double)pi[
"y"], (
double)pi[
"z"], 1.0);
130 p.pos = matchCoord * pos;
131 json_value irSamples[2] = { pi[
"left"], pi[
"right"]};
132 const Size irLength = irSamples[0].u.array.length;
133 maxIrLength =
std::max(maxIrLength, irLength);
134 for (
int c = 0; c < 2; c++) {
135 p.ir[c].resize(irLength, 1);
136 for (
Size j = 0; j < irLength; j++) {
137 p.ir[c][0][j] = (double) *(irSamples[c].u.array.values[j]);
143 hrtf.irLength = maxIrLength;
146 json_value_free_ex(&settings, json);
149 VAE_DEBUG("Finished loading HRTF %s", path)
static void * allocate(size_t size, int zero, void *context)
static void deallocate(void *ptr, void *context)
T max(const T &v1, const T &v2)
tklb::String< HeapBuffer< char > > PathString
Non optional string used for locations, maybe replaceable with a unique_ptr or something.
unsigned int Size
How the elements are addressed in the heapbuffer.
Result
Return Types for most engine functions.
@ FileOpenError
File system could not load file.
HeapBuffer< char > String
#define VAE_ERROR(msg,...)
#define VAE_DEBUG(msg,...)
#define VAE_PROFILER_SCOPE_NAMED(name)
Profiles a scope and names it.
#define VAE_PROFILER_SCOPE()
Profiles a scope.