aboutsummaryrefslogtreecommitdiffstats
path: root/alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-11-28 09:46:16 -0800
committerChris Robinson <[email protected]>2019-11-28 09:46:16 -0800
commit576adf06b16f6b1c88991970dce06fcabbb04f28 (patch)
tree1306e20b0f9f13b6db2eda43479764a0ac8f5a73 /alc
parent925e6e979c85a1e8f36d5fb01ce3a4409e38927c (diff)
Store HRIR coefficients using HrirArray
Diffstat (limited to 'alc')
-rw-r--r--alc/hrtf.cpp28
-rw-r--r--alc/hrtf.h8
2 files changed, 15 insertions, 21 deletions
diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp
index ee2510ab..b02e5e41 100644
--- a/alc/hrtf.cpp
+++ b/alc/hrtf.cpp
@@ -260,12 +260,6 @@ void GetHrtfCoeffs(const HrtfStore *Hrtf, ALfloat elevation, ALfloat azimuth, AL
const ALuint irSize{Hrtf->irSize};
ASSUME(irSize >= MIN_IR_SIZE);
- /* Calculate the sample offsets for the HRIR indices. */
- idx[0] *= HRIR_LENGTH;
- idx[1] *= HRIR_LENGTH;
- idx[2] *= HRIR_LENGTH;
- idx[3] *= HRIR_LENGTH;
-
/* Calculate the blended HRIR coefficients. */
ALfloat *coeffout{al::assume_aligned<16>(&coeffs[0][0])};
coeffout[0] = PassthruCoeff * (1.0f-dirfact);
@@ -273,8 +267,8 @@ void GetHrtfCoeffs(const HrtfStore *Hrtf, ALfloat elevation, ALfloat azimuth, AL
std::fill(coeffout+2, coeffout + HRIR_LENGTH*2, 0.0f);
for(ALsizei c{0};c < 4;c++)
{
- const ALfloat *srccoeffs{al::assume_aligned<16>(Hrtf->coeffs[idx[c]])};
- const ALfloat mult{blend[c]};
+ const float *srccoeffs{al::assume_aligned<16>(Hrtf->coeffs[idx[c]][0].data())};
+ const float mult{blend[c]};
auto blend_coeffs = [mult](const ALfloat src, const ALfloat coeff) noexcept -> ALfloat
{ return src*mult + coeff; };
std::transform(srccoeffs, srccoeffs + irSize*2, coeffout, coeffout, blend_coeffs);
@@ -355,8 +349,8 @@ void BuildBFormatHrtf(const HrtfStore *Hrtf, DirectHrtfState *state,
std::fill(coeffout, coeffout + HRIR_LENGTH*2, 0.0);
for(ALsizei c{0};c < 4;c++)
{
- const ALfloat *srccoeffs{al::assume_aligned<16>(Hrtf->coeffs[idx[c]*HRIR_LENGTH])};
- const ALfloat mult{blend[c]};
+ const float *srccoeffs{al::assume_aligned<16>(Hrtf->coeffs[idx[c]][0].data())};
+ const float mult{blend[c]};
auto blend_coeffs = [mult](const float src, const double coeff) noexcept -> double
{ return src*mult + coeff; };
std::transform(srccoeffs, srccoeffs + HRIR_LENGTH*2, coeffout, coeffout, blend_coeffs);
@@ -501,7 +495,7 @@ std::unique_ptr<HrtfStore> CreateHrtfStore(ALuint rate, ALushort irSize, const A
total = RoundUp(total, alignof(HrtfStore::Elevation)); /* Align for elevation infos */
total += sizeof(Hrtf->elev[0])*evTotal;
total = RoundUp(total, 16); /* Align for coefficients using SIMD */
- total += sizeof(Hrtf->coeffs[0])*HRIR_LENGTH*irCount;
+ total += sizeof(Hrtf->coeffs[0])*irCount;
total += sizeof(Hrtf->delays[0])*irCount;
Hrtf.reset(new (al_calloc(16, total)) HrtfStore{});
@@ -527,8 +521,8 @@ std::unique_ptr<HrtfStore> CreateHrtfStore(ALuint rate, ALushort irSize, const A
offset += sizeof(elev_[0])*evTotal;
offset = RoundUp(offset, 16); /* Align for coefficients using SIMD */
- auto coeffs_ = reinterpret_cast<ALfloat(*)[2]>(base + offset);
- offset += sizeof(coeffs_[0])*HRIR_LENGTH*irCount;
+ auto coeffs_ = reinterpret_cast<HrirArray*>(base + offset);
+ offset += sizeof(coeffs_[0])*irCount;
auto delays_ = reinterpret_cast<ALubyte(*)[2]>(base + offset);
offset += sizeof(delays_[0])*irCount;
@@ -550,13 +544,13 @@ std::unique_ptr<HrtfStore> CreateHrtfStore(ALuint rate, ALushort irSize, const A
{
for(ALuint j{0};j < ALuint{irSize};j++)
{
- coeffs_[i*HRIR_LENGTH + j][0] = coeffs[i*irSize + j][0];
- coeffs_[i*HRIR_LENGTH + j][1] = coeffs[i*irSize + j][1];
+ coeffs_[i][j][0] = coeffs[i*irSize + j][0];
+ coeffs_[i][j][1] = coeffs[i*irSize + j][1];
}
for(ALuint j{irSize};j < HRIR_LENGTH;j++)
{
- coeffs_[i*HRIR_LENGTH + j][0] = 0.0f;
- coeffs_[i*HRIR_LENGTH + j][1] = 0.0f;
+ coeffs_[i][j][0] = 0.0f;
+ coeffs_[i][j][1] = 0.0f;
}
}
for(ALuint i{0};i < irCount;i++)
diff --git a/alc/hrtf.h b/alc/hrtf.h
index d6985142..41bee19a 100644
--- a/alc/hrtf.h
+++ b/alc/hrtf.h
@@ -23,6 +23,9 @@
#define HRIR_LENGTH (1<<HRIR_BITS)
#define HRIR_MASK (HRIR_LENGTH-1)
+using float2 = std::array<float,2>;
+using HrirArray = std::array<float2,HRIR_LENGTH>;
+
struct HrtfStore {
RefCount mRef;
@@ -45,7 +48,7 @@ struct HrtfStore {
ALushort irOffset;
};
Elevation *elev;
- const ALfloat (*coeffs)[2];
+ const HrirArray *coeffs;
const ALubyte (*delays)[2];
void IncRef();
@@ -55,9 +58,6 @@ struct HrtfStore {
};
-using float2 = std::array<float,2>;
-using HrirArray = std::array<float2,HRIR_LENGTH>;
-
struct HrtfState {
alignas(16) std::array<ALfloat,HRTF_HISTORY_LENGTH> History;
};