diff options
author | Chris Robinson <[email protected]> | 2018-11-09 18:08:42 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-11-09 18:08:42 -0800 |
commit | db56fd5e3df68808b44880012397dd18a644cba5 (patch) | |
tree | 893049501c56e239d39849d192251301e1a1a22d /Alc | |
parent | e8679e72140438b7fb9d2fe672914b056d1a3171 (diff) |
Convert hrtf.c to C++
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/hrtf.cpp (renamed from Alc/hrtf.c) | 325 |
1 files changed, 135 insertions, 190 deletions
diff --git a/Alc/hrtf.c b/Alc/hrtf.cpp index ce602ee1..ce7c46f3 100644 --- a/Alc/hrtf.c +++ b/Alc/hrtf.cpp @@ -23,6 +23,10 @@ #include <stdlib.h> #include <ctype.h> +#include <array> +#include <vector> +#include <algorithm> + #include "AL/al.h" #include "AL/alc.h" #include "alMain.h" @@ -36,6 +40,14 @@ #include "almalloc.h" +struct HrtfEntry { + struct HrtfEntry *next; + struct Hrtf *handle; + char filename[]; +}; + +namespace { + /* Current data set limits defined by the makehrtf utility. */ #define MIN_IR_SIZE (8) #define MAX_IR_SIZE (512) @@ -55,28 +67,22 @@ #define MAX_HRIR_DELAY (HRTF_HISTORY_LENGTH-1) -struct HrtfEntry { - struct HrtfEntry *next; - struct Hrtf *handle; - char filename[]; -}; - -static const ALchar magicMarker00[8] = "MinPHR00"; -static const ALchar magicMarker01[8] = "MinPHR01"; -static const ALchar magicMarker02[8] = "MinPHR02"; +constexpr ALchar magicMarker00[8]{'M','i','n','P','H','R','0','0'}; +constexpr ALchar magicMarker01[8]{'M','i','n','P','H','R','0','1'}; +constexpr ALchar magicMarker02[8]{'M','i','n','P','H','R','0','2'}; /* First value for pass-through coefficients (remaining are 0), used for omni- * directional sounds. */ -static const ALfloat PassthruCoeff = 0.707106781187f/*sqrt(0.5)*/; +constexpr ALfloat PassthruCoeff = 0.707106781187f/*sqrt(0.5)*/; -static ATOMIC_FLAG LoadedHrtfLock = ATOMIC_FLAG_INIT; -static struct HrtfEntry *LoadedHrtfs = NULL; +ATOMIC_FLAG LoadedHrtfLock = ATOMIC_FLAG_INIT; +struct HrtfEntry *LoadedHrtfs = NULL; /* Calculate the elevation index given the polar elevation in radians. This * will return an index between 0 and (evcount - 1). */ -static ALsizei CalcEvIndex(ALsizei evcount, ALfloat ev, ALfloat *mu) +ALsizei CalcEvIndex(ALsizei evcount, ALfloat ev, ALfloat *mu) { ALsizei idx; ev = (F_PI_2+ev) * (evcount-1) / F_PI; @@ -89,7 +95,7 @@ static ALsizei CalcEvIndex(ALsizei evcount, ALfloat ev, ALfloat *mu) /* Calculate the azimuth index given the polar azimuth in radians. This will * return an index between 0 and (azcount - 1). */ -static ALsizei CalcAzIndex(ALsizei azcount, ALfloat az, ALfloat *mu) +ALsizei CalcAzIndex(ALsizei azcount, ALfloat az, ALfloat *mu) { ALsizei idx; az = (F_TAU+az) * azcount / F_TAU; @@ -99,6 +105,9 @@ static ALsizei CalcAzIndex(ALsizei azcount, ALfloat az, ALfloat *mu) return idx % azcount; } +} // namespace + + /* Calculates static HRIR coefficients and delays for the given polar elevation * and azimuth in radians. The coefficients are normalized. */ @@ -172,7 +181,7 @@ void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, idx[3] *= Hrtf->irSize; ASSUME(Hrtf->irSize >= MIN_IR_SIZE && (Hrtf->irSize%MOD_IR_SIZE) == 0); - coeffs = ASSUME_ALIGNED(coeffs, 16); + /* Calculate the blended HRIR coefficients. */ coeffs[0][0] = PassthruCoeff * (1.0f-dirfact); coeffs[0][1] = PassthruCoeff * (1.0f-dirfact); @@ -183,7 +192,7 @@ void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, } for(c = 0;c < 4;c++) { - const ALfloat (*RESTRICT srccoeffs)[2] = ASSUME_ALIGNED(Hrtf->coeffs+idx[c], 16); + const ALfloat (*RESTRICT srccoeffs)[2] = Hrtf->coeffs + idx[c]; for(i = 0;i < Hrtf->irSize;i++) { coeffs[i][0] += srccoeffs[i][0] * blend[c]; @@ -200,18 +209,10 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N * tail generated by the filter. */ #define NUM_BANDS 2 - BandSplitter splitter; - ALdouble (*tmpres)[HRIR_LENGTH][2]; - ALsizei *RESTRICT idx; - ALsizei min_delay = HRTF_HISTORY_LENGTH; - ALsizei max_delay = 0; - ALfloat temps[3][HRIR_LENGTH]; - ALsizei max_length; - ALsizei i, c, b; - - idx = al_calloc(DEF_ALIGN, AmbiCount*sizeof(*idx)); - - for(c = 0;c < AmbiCount;c++) + ALsizei min_delay{HRTF_HISTORY_LENGTH}; + ALsizei max_delay{0}; + std::vector<ALsizei> idx(AmbiCount); + for(ALsizei c{0};c < AmbiCount;c++) { ALuint evidx, azidx; ALuint evoffset; @@ -234,11 +235,12 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N max_delay = maxi(max_delay, maxi(Hrtf->delays[idx[c]][0], Hrtf->delays[idx[c]][1])); } - tmpres = al_calloc(16, NumChannels * sizeof(*tmpres)); + std::vector<std::array<std::array<ALdouble,2>,HRIR_LENGTH>> tmpres(NumChannels); + ALfloat temps[3][HRIR_LENGTH]{}; - memset(temps, 0, sizeof(temps)); + BandSplitter splitter; bandsplit_init(&splitter, 400.0f / (ALfloat)Hrtf->sampleRate); - for(c = 0;c < AmbiCount;c++) + for(ALsizei c{0};c < AmbiCount;++c) { const ALfloat (*fir)[2] = &Hrtf->coeffs[idx[c] * Hrtf->irSize]; ALsizei ldelay = Hrtf->delays[idx[c]][0] - min_delay; @@ -246,7 +248,7 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N if(NUM_BANDS == 1) { - for(i = 0;i < NumChannels;++i) + for(ALsizei i{0};i < NumChannels;++i) { ALdouble mult = (ALdouble)AmbiOrderHFGain[(ALsizei)sqrt(i)] * AmbiMatrix[c][i]; ALsizei lidx = ldelay, ridx = rdelay; @@ -263,17 +265,17 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N { /* Band-split left HRIR into low and high frequency responses. */ bandsplit_clear(&splitter); - for(i = 0;i < Hrtf->irSize;i++) + for(ALsizei i{0};i < Hrtf->irSize;++i) temps[2][i] = fir[i][0]; bandsplit_process(&splitter, temps[0], temps[1], temps[2], HRIR_LENGTH); /* Apply left ear response with delay. */ - for(i = 0;i < NumChannels;++i) + for(ALsizei i{0};i < NumChannels;++i) { - ALfloat hfgain = AmbiOrderHFGain[(ALsizei)sqrt(i)]; - for(b = 0;b < NUM_BANDS;b++) + ALdouble hfgain = AmbiOrderHFGain[(ALsizei)sqrt(i)]; + for(ALsizei b{0};b < NUM_BANDS;++b) { - ALdouble mult = AmbiMatrix[c][i] * (ALdouble)((b==0) ? hfgain : 1.0); + ALdouble mult = AmbiMatrix[c][i] * ((b==0) ? hfgain : 1.0); ALsizei lidx = ldelay; ALsizei j = 0; while(lidx < HRIR_LENGTH) @@ -283,17 +285,17 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N /* Band-split right HRIR into low and high frequency responses. */ bandsplit_clear(&splitter); - for(i = 0;i < Hrtf->irSize;i++) + for(ALsizei i{0};i < Hrtf->irSize;++i) temps[2][i] = fir[i][1]; bandsplit_process(&splitter, temps[0], temps[1], temps[2], HRIR_LENGTH); /* Apply right ear response with delay. */ - for(i = 0;i < NumChannels;++i) + for(ALsizei i{0};i < NumChannels;++i) { - ALfloat hfgain = AmbiOrderHFGain[(ALsizei)sqrt(i)]; - for(b = 0;b < NUM_BANDS;b++) + ALdouble hfgain = AmbiOrderHFGain[(ALsizei)sqrt(i)]; + for(ALsizei b{0};b < NUM_BANDS;++b) { - ALdouble mult = AmbiMatrix[c][i] * (ALdouble)((b==0) ? hfgain : 1.0); + ALdouble mult = AmbiMatrix[c][i] * ((b==0) ? hfgain : 1.0); ALsizei ridx = rdelay; ALsizei j = 0; while(ridx < HRIR_LENGTH) @@ -303,20 +305,18 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N } } - for(i = 0;i < NumChannels;++i) + for(ALsizei i{0};i < NumChannels;++i) { - int idx; - for(idx = 0;idx < HRIR_LENGTH;idx++) + for(ALsizei idx{0};idx < HRIR_LENGTH;idx++) { state->Chan[i].Coeffs[idx][0] = (ALfloat)tmpres[i][idx][0]; state->Chan[i].Coeffs[idx][1] = (ALfloat)tmpres[i][idx][1]; } } - al_free(tmpres); - tmpres = NULL; - al_free(idx); - idx = NULL; + tmpres.clear(); + idx.clear(); + ALsizei max_length; if(NUM_BANDS == 1) max_length = mini(max_delay-min_delay + Hrtf->irSize, HRIR_LENGTH); else @@ -354,7 +354,7 @@ static struct Hrtf *CreateHrtfStore(ALuint rate, ALsizei irSize, total += sizeof(Hrtf->coeffs[0])*irSize*irCount; total += sizeof(Hrtf->delays[0])*irCount; - Hrtf = al_calloc(16, total); + Hrtf = static_cast<struct Hrtf*>(al_calloc(16, total)); if(Hrtf == NULL) ERR("Out of memory allocating storage for %s.\n", filename); else @@ -374,18 +374,18 @@ static struct Hrtf *CreateHrtfStore(ALuint rate, ALsizei irSize, Hrtf->evCount = evCount; /* Set up pointers to storage following the main HRTF struct. */ - _azCount = (ALubyte*)(base + offset); + _azCount = reinterpret_cast<ALubyte*>(base + offset); offset += sizeof(_azCount[0])*evCount; offset = RoundUp(offset, sizeof(ALushort)); /* Align for ushort fields */ - _evOffset = (ALushort*)(base + offset); + _evOffset = reinterpret_cast<ALushort*>(base + offset); offset += sizeof(_evOffset[0])*evCount; offset = RoundUp(offset, 16); /* Align for coefficients using SIMD */ - _coeffs = (ALfloat(*)[2])(base + offset); + _coeffs = reinterpret_cast<ALfloat(*)[2]>(base + offset); offset += sizeof(_coeffs[0])*irSize*irCount; - _delays = (ALubyte(*)[2])(base + offset); + _delays = reinterpret_cast<ALubyte(*)[2]>(base + offset); offset += sizeof(_delays[0])*irCount; assert(offset == total); @@ -464,15 +464,15 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char * ALushort irCount = 0; ALushort irSize = 0; ALubyte evCount = 0; - ALubyte *azCount = NULL; - ALushort *evOffset = NULL; - ALfloat (*coeffs)[2] = NULL; - ALubyte (*delays)[2] = NULL; + std::vector<ALubyte> azCount; + std::vector<ALushort> evOffset; + std::vector<std::array<ALfloat,2>> coeffs; + std::vector<std::array<ALubyte,2>> delays; ALsizei i, j; if(datalen < 9) { - ERR("Unexpected end of %s data (req %d, rem "SZFMT")\n", filename, 9, datalen); + ERR("Unexpected end of %s data (req %d, rem " SZFMT ")\n", filename, 9, datalen); return NULL; } @@ -501,47 +501,25 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char * if(datalen < evCount*2u) { - ERR("Unexpected end of %s data (req %d, rem "SZFMT")\n", filename, evCount*2, datalen); + ERR("Unexpected end of %s data (req %d, rem " SZFMT ")\n", filename, evCount*2, datalen); return NULL; } - azCount = malloc(sizeof(azCount[0])*evCount); - evOffset = malloc(sizeof(evOffset[0])*evCount); - if(azCount == NULL || evOffset == NULL) - { - ERR("Out of memory.\n"); - failed = AL_TRUE; - } + azCount.resize(evCount); + evOffset.resize(evCount); - if(!failed) + evOffset[0] = GetLE_ALushort(&data, &datalen); + for(i = 1;i < evCount;i++) { - evOffset[0] = GetLE_ALushort(&data, &datalen); - for(i = 1;i < evCount;i++) - { - evOffset[i] = GetLE_ALushort(&data, &datalen); - if(evOffset[i] <= evOffset[i-1]) - { - ERR("Invalid evOffset: evOffset[%d]=%d (last=%d)\n", - i, evOffset[i], evOffset[i-1]); - failed = AL_TRUE; - } - - azCount[i-1] = evOffset[i] - evOffset[i-1]; - if(azCount[i-1] < MIN_AZ_COUNT || azCount[i-1] > MAX_AZ_COUNT) - { - ERR("Unsupported azimuth count: azCount[%d]=%d (%d to %d)\n", - i-1, azCount[i-1], MIN_AZ_COUNT, MAX_AZ_COUNT); - failed = AL_TRUE; - } - } - if(irCount <= evOffset[i-1]) + evOffset[i] = GetLE_ALushort(&data, &datalen); + if(evOffset[i] <= evOffset[i-1]) { - ERR("Invalid evOffset: evOffset[%d]=%d (irCount=%d)\n", - i-1, evOffset[i-1], irCount); + ERR("Invalid evOffset: evOffset[%d]=%d (last=%d)\n", + i, evOffset[i], evOffset[i-1]); failed = AL_TRUE; } - azCount[i-1] = irCount - evOffset[i-1]; + azCount[i-1] = evOffset[i] - evOffset[i-1]; if(azCount[i-1] < MIN_AZ_COUNT || azCount[i-1] > MAX_AZ_COUNT) { ERR("Unsupported azimuth count: azCount[%d]=%d (%d to %d)\n", @@ -549,24 +527,30 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char * failed = AL_TRUE; } } + if(irCount <= evOffset[i-1]) + { + ERR("Invalid evOffset: evOffset[%d]=%d (irCount=%d)\n", + i-1, evOffset[i-1], irCount); + failed = AL_TRUE; + } - if(!failed) + azCount[i-1] = irCount - evOffset[i-1]; + if(azCount[i-1] < MIN_AZ_COUNT || azCount[i-1] > MAX_AZ_COUNT) { - coeffs = malloc(sizeof(coeffs[0])*irSize*irCount); - delays = malloc(sizeof(delays[0])*irCount); - if(coeffs == NULL || delays == NULL) - { - ERR("Out of memory.\n"); - failed = AL_TRUE; - } + ERR("Unsupported azimuth count: azCount[%d]=%d (%d to %d)\n", + i-1, azCount[i-1], MIN_AZ_COUNT, MAX_AZ_COUNT); + failed = AL_TRUE; } if(!failed) { + coeffs.resize(irSize*irCount); + delays.resize(irCount); + size_t reqsize = 2*irSize*irCount + irCount; if(datalen < reqsize) { - ERR("Unexpected end of %s data (req "SZFMT", rem "SZFMT")\n", + ERR("Unexpected end of %s data (req " SZFMT ", rem " SZFMT ")\n", filename, reqsize, datalen); failed = AL_TRUE; } @@ -610,14 +594,11 @@ static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const char * } } - Hrtf = CreateHrtfStore(rate, irSize, 0.0f, evCount, irCount, azCount, - evOffset, coeffs, delays, filename); + Hrtf = CreateHrtfStore(rate, irSize, 0.0f, evCount, irCount, azCount.data(), + evOffset.data(), &reinterpret_cast<ALfloat(&)[2]>(coeffs[0]), + &reinterpret_cast<ALubyte(&)[2]>(delays[0]), filename); } - free(azCount); - free(evOffset); - free(coeffs); - free(delays); return Hrtf; } @@ -630,14 +611,14 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char * ALushort irSize = 0; ALubyte evCount = 0; const ALubyte *azCount = NULL; - ALushort *evOffset = NULL; - ALfloat (*coeffs)[2] = NULL; - ALubyte (*delays)[2] = NULL; + std::vector<ALushort> evOffset; + std::vector<std::array<ALfloat,2>> coeffs; + std::vector<std::array<ALubyte,2>> delays; ALsizei i, j; if(datalen < 6) { - ERR("Unexpected end of %s data (req %d, rem "SZFMT"\n", filename, 6, datalen); + ERR("Unexpected end of %s data (req %d, rem " SZFMT "\n", filename, 6, datalen); return NULL; } @@ -664,29 +645,21 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char * if(datalen < evCount) { - ERR("Unexpected end of %s data (req %d, rem "SZFMT"\n", filename, evCount, datalen); + ERR("Unexpected end of %s data (req %d, rem " SZFMT "\n", filename, evCount, datalen); return NULL; } azCount = Get_ALubytePtr(&data, &datalen, evCount); - evOffset = malloc(sizeof(evOffset[0])*evCount); - if(azCount == NULL || evOffset == NULL) - { - ERR("Out of memory.\n"); - failed = AL_TRUE; - } + evOffset.resize(evCount); - if(!failed) + for(i = 0;i < evCount;i++) { - for(i = 0;i < evCount;i++) + if(azCount[i] < MIN_AZ_COUNT || azCount[i] > MAX_AZ_COUNT) { - if(azCount[i] < MIN_AZ_COUNT || azCount[i] > MAX_AZ_COUNT) - { - ERR("Unsupported azimuth count: azCount[%d]=%d (%d to %d)\n", - i, azCount[i], MIN_AZ_COUNT, MAX_AZ_COUNT); - failed = AL_TRUE; - } + ERR("Unsupported azimuth count: azCount[%d]=%d (%d to %d)\n", + i, azCount[i], MIN_AZ_COUNT, MAX_AZ_COUNT); + failed = AL_TRUE; } } @@ -700,21 +673,13 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char * irCount += azCount[i]; } - coeffs = malloc(sizeof(coeffs[0])*irSize*irCount); - delays = malloc(sizeof(delays[0])*irCount); - if(coeffs == NULL || delays == NULL) - { - ERR("Out of memory.\n"); - failed = AL_TRUE; - } - } + coeffs.resize(irSize*irCount); + delays.resize(irCount); - if(!failed) - { size_t reqsize = 2*irSize*irCount + irCount; if(datalen < reqsize) { - ERR("Unexpected end of %s data (req "SZFMT", rem "SZFMT"\n", + ERR("Unexpected end of %s data (req " SZFMT ", rem " SZFMT "\n", filename, reqsize, datalen); failed = AL_TRUE; } @@ -758,13 +723,11 @@ static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const char * } } - Hrtf = CreateHrtfStore(rate, irSize, 0.0f, evCount, irCount, azCount, - evOffset, coeffs, delays, filename); + Hrtf = CreateHrtfStore(rate, irSize, 0.0f, evCount, irCount, azCount, evOffset.data(), + &reinterpret_cast<ALfloat(&)[2]>(coeffs[0]), + &reinterpret_cast<ALubyte(&)[2]>(delays[0]), filename); } - free(evOffset); - free(coeffs); - free(delays); return Hrtf; } @@ -787,14 +750,14 @@ static struct Hrtf *LoadHrtf02(const ALubyte *data, size_t datalen, const char * ALushort distance = 0; ALubyte evCount = 0; const ALubyte *azCount = NULL; - ALushort *evOffset = NULL; - ALfloat (*coeffs)[2] = NULL; - ALubyte (*delays)[2] = NULL; + std::vector<ALushort> evOffset; + std::vector<std::array<ALfloat,2>> coeffs; + std::vector<std::array<ALubyte,2>> delays; ALsizei i, j; if(datalen < 8) { - ERR("Unexpected end of %s data (req %d, rem "SZFMT"\n", filename, 8, datalen); + ERR("Unexpected end of %s data (req %d, rem " SZFMT "\n", filename, 8, datalen); return NULL; } @@ -836,7 +799,7 @@ static struct Hrtf *LoadHrtf02(const ALubyte *data, size_t datalen, const char * { if(datalen < 3) { - ERR("Unexpected end of %s data (req %d, rem "SZFMT"\n", filename, 3, datalen); + ERR("Unexpected end of %s data (req %d, rem " SZFMT "\n", filename, 3, datalen); return NULL; } @@ -860,7 +823,7 @@ static struct Hrtf *LoadHrtf02(const ALubyte *data, size_t datalen, const char * if(datalen < evCount) { - ERR("Unexpected end of %s data (req %d, rem "SZFMT"\n", filename, evCount, datalen); + ERR("Unexpected end of %s data (req %d, rem " SZFMT "\n", filename, evCount, datalen); return NULL; } @@ -878,41 +841,25 @@ static struct Hrtf *LoadHrtf02(const ALubyte *data, size_t datalen, const char * if(failed) return NULL; - evOffset = malloc(sizeof(evOffset[0])*evCount); - if(azCount == NULL || evOffset == NULL) - { - ERR("Out of memory.\n"); - failed = AL_TRUE; - } + evOffset.resize(evCount); - if(!failed) + evOffset[0] = 0; + irCount = azCount[0]; + for(i = 1;i < evCount;i++) { - evOffset[0] = 0; - irCount = azCount[0]; - for(i = 1;i < evCount;i++) - { - evOffset[i] = evOffset[i-1] + azCount[i-1]; - irCount += azCount[i]; - } - - coeffs = malloc(sizeof(coeffs[0])*irSize*irCount); - delays = malloc(sizeof(delays[0])*irCount); - if(coeffs == NULL || delays == NULL) - { - ERR("Out of memory.\n"); - failed = AL_TRUE; - } + evOffset[i] = evOffset[i-1] + azCount[i-1]; + irCount += azCount[i]; } - if(!failed) + coeffs.resize(irSize*irCount); + delays.resize(irCount); + + size_t reqsize = 2*irSize*irCount + irCount; + if(datalen < reqsize) { - size_t reqsize = 2*irSize*irCount + irCount; - if(datalen < reqsize) - { - ERR("Unexpected end of %s data (req "SZFMT", rem "SZFMT"\n", - filename, reqsize, datalen); - failed = AL_TRUE; - } + ERR("Unexpected end of %s data (req " SZFMT ", rem " SZFMT "\n", + filename, reqsize, datalen); + failed = AL_TRUE; } if(!failed) @@ -1004,14 +951,12 @@ static struct Hrtf *LoadHrtf02(const ALubyte *data, size_t datalen, const char * } Hrtf = CreateHrtfStore(rate, irSize, - (ALfloat)distance / 1000.0f, evCount, irCount, azCount, evOffset, - coeffs, delays, filename + (ALfloat)distance / 1000.0f, evCount, irCount, azCount, evOffset.data(), + &reinterpret_cast<ALfloat(&)[2]>(coeffs[0]), + &reinterpret_cast<ALubyte(&)[2]>(delays[0]), filename ); } - free(evOffset); - free(coeffs); - free(delays); return Hrtf; } @@ -1019,7 +964,7 @@ static struct Hrtf *LoadHrtf02(const ALubyte *data, size_t datalen, const char * static void AddFileEntry(vector_EnumeratedHrtf *list, const_al_string filename) { EnumeratedHrtf entry = { AL_STRING_INIT_STATIC(), NULL }; - struct HrtfEntry *loaded_entry; + HrtfEntry *loaded_entry; const EnumeratedHrtf *iter; const char *name; const char *ext; @@ -1050,9 +995,9 @@ static void AddFileEntry(vector_EnumeratedHrtf *list, const_al_string filename) { TRACE("Got new file \"%s\"\n", alstr_get_cstr(filename)); - loaded_entry = al_calloc(DEF_ALIGN, + loaded_entry = static_cast<HrtfEntry*>(al_calloc(DEF_ALIGN, FAM_SIZE(struct HrtfEntry, filename, alstr_length(filename)+1) - ); + )); loaded_entry->next = LoadedHrtfs; loaded_entry->handle = NULL; strcpy(loaded_entry->filename, alstr_get_cstr(filename)); @@ -1099,7 +1044,7 @@ static void AddFileEntry(vector_EnumeratedHrtf *list, const_al_string filename) static void AddBuiltInEntry(vector_EnumeratedHrtf *list, const_al_string filename, ALuint residx) { EnumeratedHrtf entry = { AL_STRING_INIT_STATIC(), NULL }; - struct HrtfEntry *loaded_entry; + HrtfEntry *loaded_entry; struct Hrtf *hrtf = NULL; const EnumeratedHrtf *iter; const char *name; @@ -1131,9 +1076,9 @@ static void AddBuiltInEntry(vector_EnumeratedHrtf *list, const_al_string filenam TRACE("Got new file \"%s\"\n", alstr_get_cstr(filename)); - loaded_entry = al_calloc(DEF_ALIGN, + loaded_entry = static_cast<HrtfEntry*>(al_calloc(DEF_ALIGN, FAM_SIZE(struct HrtfEntry, filename, namelen) - ); + )); loaded_entry->next = LoadedHrtfs; loaded_entry->handle = hrtf; snprintf(loaded_entry->filename, namelen, "!%u_%s", @@ -1364,12 +1309,12 @@ struct Hrtf *GetLoadedHrtf(struct HrtfEntry *entry) goto done; } - rdata = fmap.ptr; + rdata = static_cast<const ALubyte*>(fmap.ptr); rsize = fmap.len; } if(rsize < sizeof(magicMarker02)) - ERR("%s data is too short ("SZFMT" bytes)\n", name, rsize); + ERR("%s data is too short (" SZFMT " bytes)\n", name, rsize); else if(memcmp(rdata, magicMarker02, sizeof(magicMarker02)) == 0) { TRACE("Detected data set format v2\n"); |