aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/hrtf.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-09-07 05:37:01 -0700
committerChris Robinson <[email protected]>2016-09-07 05:38:22 -0700
commit3af1d5b72226971f08fca869875c4348314dae5c (patch)
tree8b38274a7b8d4f37a4de45f21b31289c64b54c73 /Alc/hrtf.c
parent7973c5abf8f3097b795601c9619113d080792768 (diff)
Properly align 16-bit fields in the Hrtf struct
Diffstat (limited to 'Alc/hrtf.c')
-rw-r--r--Alc/hrtf.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/Alc/hrtf.c b/Alc/hrtf.c
index 16db0c33..b94faf9d 100644
--- a/Alc/hrtf.c
+++ b/Alc/hrtf.c
@@ -468,6 +468,7 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const_al_str
{
size_t total = sizeof(struct Hrtf);
total += sizeof(azCount[0])*evCount;
+ total = (total+1)&~1; /* Align for (u)short fields */
total += sizeof(evOffset[0])*evCount;
total += sizeof(coeffs[0])*irSize*irCount;
total += sizeof(delays[0])*irCount;
@@ -483,14 +484,18 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const_al_str
if(!failed)
{
+ char *base = (char*)Hrtf;
+ uintptr_t offset = sizeof(*Hrtf);
+
Hrtf->sampleRate = rate;
Hrtf->irSize = irSize;
Hrtf->evCount = evCount;
- Hrtf->azCount = ((ALubyte*)(Hrtf+1));
- Hrtf->evOffset = ((ALushort*)(Hrtf->azCount + evCount));
- Hrtf->coeffs = ((ALshort*)(Hrtf->evOffset + evCount));
- Hrtf->delays = ((ALubyte*)(Hrtf->coeffs + irSize*irCount));
- Hrtf->filename = ((char*)(Hrtf->delays + irCount));
+ Hrtf->azCount = ((ALubyte*)(base + offset)); offset += evCount*sizeof(Hrtf->azCount[0]);
+ offset = (offset+1)&~1; /* Align for (u)short fields */
+ Hrtf->evOffset = ((ALushort*)(base + offset)); offset += evCount*sizeof(Hrtf->evOffset[0]);
+ Hrtf->coeffs = ((ALshort*)(base + offset)); offset += irSize*irCount*sizeof(Hrtf->coeffs[0]);
+ Hrtf->delays = ((ALubyte*)(base + offset)); offset += irCount*sizeof(Hrtf->delays[0]);
+ Hrtf->filename = ((char*)(base + offset));
Hrtf->next = NULL;
memcpy((void*)Hrtf->azCount, azCount, sizeof(azCount[0])*evCount);
@@ -644,6 +649,7 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const_al_str
{
size_t total = sizeof(struct Hrtf);
total += sizeof(azCount[0])*evCount;
+ total = (total+1)&~1; /* Align for (u)short fields */
total += sizeof(evOffset[0])*evCount;
total += sizeof(coeffs[0])*irSize*irCount;
total += sizeof(delays[0])*irCount;
@@ -659,14 +665,18 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const_al_str
if(!failed)
{
+ char *base = (char*)Hrtf;
+ uintptr_t offset = sizeof(*Hrtf);
+
Hrtf->sampleRate = rate;
Hrtf->irSize = irSize;
Hrtf->evCount = evCount;
- Hrtf->azCount = ((ALubyte*)(Hrtf+1));
- Hrtf->evOffset = ((ALushort*)(Hrtf->azCount + evCount));
- Hrtf->coeffs = ((ALshort*)(Hrtf->evOffset + evCount));
- Hrtf->delays = ((ALubyte*)(Hrtf->coeffs + irSize*irCount));
- Hrtf->filename = ((char*)(Hrtf->delays + irCount));
+ Hrtf->azCount = ((ALubyte*)(base + offset)); offset += evCount*sizeof(Hrtf->azCount[0]);
+ offset = (offset+1)&~1; /* Align for (u)short fields */
+ Hrtf->evOffset = ((ALushort*)(base + offset)); offset += evCount*sizeof(Hrtf->evOffset[0]);
+ Hrtf->coeffs = ((ALshort*)(base + offset)); offset += irSize*irCount*sizeof(Hrtf->coeffs[0]);
+ Hrtf->delays = ((ALubyte*)(base + offset)); offset += irCount*sizeof(Hrtf->delays[0]);
+ Hrtf->filename = ((char*)(base + offset));
Hrtf->next = NULL;
memcpy((void*)Hrtf->azCount, azCount, sizeof(azCount[0])*evCount);