diff options
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/effects/chorus.c | 8 | ||||
-rw-r--r-- | Alc/effects/echo.c | 8 | ||||
-rw-r--r-- | Alc/effects/flanger.c | 8 | ||||
-rw-r--r-- | Alc/effects/reverb.c | 12 | ||||
-rw-r--r-- | Alc/helpers.c | 5 | ||||
-rw-r--r-- | Alc/vector.h | 4 |
6 files changed, 26 insertions, 19 deletions
diff --git a/Alc/effects/chorus.c b/Alc/effects/chorus.c index e1cbba2d..7877ff6f 100644 --- a/Alc/effects/chorus.c +++ b/Alc/effects/chorus.c @@ -57,7 +57,7 @@ typedef struct ALchorusState { static ALvoid ALchorusState_Destruct(ALchorusState *state) { - free(state->SampleBuffer[0]); + al_free(state->SampleBuffer[0]); state->SampleBuffer[0] = NULL; state->SampleBuffer[1] = NULL; ALeffectState_Destruct(STATIC_CAST(ALeffectState,state)); @@ -73,10 +73,10 @@ static ALboolean ALchorusState_deviceUpdate(ALchorusState *state, ALCdevice *Dev if(maxlen != state->BufferLength) { - void *temp; - - temp = realloc(state->SampleBuffer[0], maxlen * sizeof(ALfloat) * 2); + void *temp = al_calloc(16, maxlen * sizeof(ALfloat) * 2); if(!temp) return AL_FALSE; + + al_free(state->SampleBuffer[0]); state->SampleBuffer[0] = temp; state->SampleBuffer[1] = state->SampleBuffer[0] + maxlen; diff --git a/Alc/effects/echo.c b/Alc/effects/echo.c index 0632a44d..163b6ecb 100644 --- a/Alc/effects/echo.c +++ b/Alc/effects/echo.c @@ -52,7 +52,7 @@ typedef struct ALechoState { static ALvoid ALechoState_Destruct(ALechoState *state) { - free(state->SampleBuffer); + al_free(state->SampleBuffer); state->SampleBuffer = NULL; ALeffectState_Destruct(STATIC_CAST(ALeffectState,state)); } @@ -69,10 +69,10 @@ static ALboolean ALechoState_deviceUpdate(ALechoState *state, ALCdevice *Device) if(maxlen != state->BufferLength) { - void *temp; - - temp = realloc(state->SampleBuffer, maxlen * sizeof(ALfloat)); + void *temp = al_calloc(16, maxlen * sizeof(ALfloat)); if(!temp) return AL_FALSE; + + al_free(state->SampleBuffer); state->SampleBuffer = temp; state->BufferLength = maxlen; } diff --git a/Alc/effects/flanger.c b/Alc/effects/flanger.c index 7b55977e..f18b2b0f 100644 --- a/Alc/effects/flanger.c +++ b/Alc/effects/flanger.c @@ -57,7 +57,7 @@ typedef struct ALflangerState { static ALvoid ALflangerState_Destruct(ALflangerState *state) { - free(state->SampleBuffer[0]); + al_free(state->SampleBuffer[0]); state->SampleBuffer[0] = NULL; state->SampleBuffer[1] = NULL; ALeffectState_Destruct(STATIC_CAST(ALeffectState,state)); @@ -73,10 +73,10 @@ static ALboolean ALflangerState_deviceUpdate(ALflangerState *state, ALCdevice *D if(maxlen != state->BufferLength) { - void *temp; - - temp = realloc(state->SampleBuffer[0], maxlen * sizeof(ALfloat) * 2); + void *temp = al_calloc(16, maxlen * sizeof(ALfloat) * 2); if(!temp) return AL_FALSE; + + al_free(state->SampleBuffer[0]); state->SampleBuffer[0] = temp; state->SampleBuffer[1] = state->SampleBuffer[0] + maxlen; diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c index 3f22b787..f8680d24 100644 --- a/Alc/effects/reverb.c +++ b/Alc/effects/reverb.c @@ -170,7 +170,7 @@ typedef struct ALreverbState { static ALvoid ALreverbState_Destruct(ALreverbState *State) { - free(State->SampleBuffer); + al_free(State->SampleBuffer); State->SampleBuffer = NULL; ALeffectState_Destruct(STATIC_CAST(ALeffectState,State)); } @@ -295,7 +295,6 @@ static ALboolean AllocLines(ALuint frequency, ALreverbState *State) { ALuint totalSamples, index; ALfloat length; - ALfloat *newBuffer = NULL; // All delay line lengths are calculated to accomodate the full range of // lengths given their respective paramters. @@ -352,10 +351,13 @@ static ALboolean AllocLines(ALuint frequency, ALreverbState *State) if(totalSamples != State->TotalSamples) { + ALfloat *newBuffer; + TRACE("New reverb buffer length: %u samples (%f sec)\n", totalSamples, totalSamples/(float)frequency); - newBuffer = realloc(State->SampleBuffer, sizeof(ALfloat) * totalSamples); - if(newBuffer == NULL) - return AL_FALSE; + newBuffer = al_calloc(16, sizeof(ALfloat) * totalSamples); + if(!newBuffer) return AL_FALSE; + + al_free(State->SampleBuffer); State->SampleBuffer = newBuffer; State->TotalSamples = totalSamples; } diff --git a/Alc/helpers.c b/Alc/helpers.c index 950a67bf..38a34939 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -759,9 +759,12 @@ ALboolean vector_reserve(char *ptr, size_t base_size, size_t obj_size, size_t ob /* Need to be explicit with the caller type's base size, because it * could have extra padding before the start of the array (that is, * sizeof(*vector_) may not equal base_size). */ - temp = realloc(*vecptr, base_size + obj_size*obj_count); + temp = al_calloc(16, base_size + obj_size*obj_count); if(temp == NULL) return AL_FALSE; + memcpy(((ALubyte*)temp)+base_size, ((ALubyte*)*vecptr)+base_size, + obj_size*old_size); + al_free(*vecptr); *vecptr = temp; (*vecptr)->Capacity = obj_count; (*vecptr)->Size = old_size; diff --git a/Alc/vector.h b/Alc/vector.h index cb64b5a9..5a0219c0 100644 --- a/Alc/vector.h +++ b/Alc/vector.h @@ -5,6 +5,8 @@ #include <AL/al.h> +#include "almalloc.h" + /* "Base" vector type, designed to alias with the actual vector types. */ typedef struct vector__s { size_t Capacity; @@ -27,7 +29,7 @@ typedef const _##N* const_##N; #define VECTOR_INIT(_x) do { (_x) = NULL; } while(0) #define VECTOR_INIT_STATIC() NULL -#define VECTOR_DEINIT(_x) do { free((_x)); (_x) = NULL; } while(0) +#define VECTOR_DEINIT(_x) do { al_free((_x)); (_x) = NULL; } while(0) /* Helper to increase a vector's reserve. Do not call directly. */ ALboolean vector_reserve(char *ptr, size_t base_size, size_t obj_size, size_t obj_count, ALboolean exact); |