diff options
author | Chris Robinson <[email protected]> | 2017-04-07 06:40:42 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-04-07 06:40:42 -0700 |
commit | b551291840ee0b670fb54c41ec385702d51604d8 (patch) | |
tree | 1961622bbb8a3e43d6c3fe15a25b085d5bcd2d1d /Alc/hrtf.c | |
parent | 36f7dda1caafaef886ccd520ec3216c2689a062e (diff) |
Allocate temp storage for delays when loading HRTFs
Diffstat (limited to 'Alc/hrtf.c')
-rw-r--r-- | Alc/hrtf.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -317,7 +317,7 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char * ALubyte *azCount = NULL; ALushort *evOffset = NULL; ALshort *coeffs = NULL; - const ALubyte *delays = NULL; + ALubyte *delays = NULL; ALuint i, j; if(datalen < 9) @@ -416,6 +416,7 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char * if(!failed) { coeffs = malloc(sizeof(coeffs[0])*irSize*irCount); + delays = malloc(sizeof(delays[0])*irCount); if(coeffs == NULL) { ERR("Out of memory.\n"); @@ -446,11 +447,10 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char * } } - delays = data; - data += irCount; - datalen -= irCount; for(i = 0;i < irCount;i++) { + delays[i] = *(data++); + datalen -= 1; if(delays[i] > maxDelay) { ERR("Invalid delays[%d]: %d (%d)\n", i, delays[i], maxDelay); @@ -466,6 +466,7 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char * free(azCount); free(evOffset); free(coeffs); + free(delays); return Hrtf; } @@ -479,7 +480,7 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char * const ALubyte *azCount = NULL; ALushort *evOffset = NULL; ALshort *coeffs = NULL; - const ALubyte *delays = NULL; + ALubyte *delays = NULL; ALuint i, j; if(datalen < 6) @@ -556,6 +557,7 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char * } coeffs = malloc(sizeof(coeffs[0])*irSize*irCount); + delays = malloc(sizeof(delays[0])*irCount); if(coeffs == NULL) { ERR("Out of memory.\n"); @@ -588,11 +590,10 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char * } } - delays = data; - data += irCount; - datalen -= irCount; for(i = 0;i < irCount;i++) { + delays[i] = *(data++); + datalen -= 1; if(delays[i] > maxDelay) { ERR("Invalid delays[%d]: %d (%d)\n", i, delays[i], maxDelay); @@ -607,9 +608,11 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char * free(evOffset); free(coeffs); + free(delays); return Hrtf; } + static void AddFileEntry(vector_EnumeratedHrtf *list, const_al_string filename) { EnumeratedHrtf entry = { AL_STRING_INIT_STATIC(), NULL }; |