diff options
author | Chris Robinson <[email protected]> | 2012-01-20 16:23:15 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2012-01-20 16:23:15 -0800 |
commit | f520257463635f1fb93d4885673714bde146cf36 (patch) | |
tree | 993802f7d6f0de90f417df84cb1d79fadf4d83bd /OpenAL32 | |
parent | 00dc3088c8eee5a1ee519f16d1ce4ca367259050 (diff) |
Avoid duplicating some initialization code
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 4 | ||||
-rw-r--r-- | OpenAL32/Include/alEffect.h | 4 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.c | 38 | ||||
-rw-r--r-- | OpenAL32/alEffect.c | 10 |
4 files changed, 37 insertions, 19 deletions
diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index 1646031c..6323f6f5 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -35,10 +35,9 @@ typedef struct ALeffectslot } ALeffectslot; -ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect); +ALenum InitEffectSlot(ALeffectslot *slot); ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context); - struct ALeffectState { ALvoid (*Destroy)(ALeffectState *State); ALboolean (*DeviceUpdate)(ALeffectState *State, ALCdevice *Device); @@ -57,6 +56,7 @@ ALeffectState *DedicatedCreate(void); #define ALeffectState_Update(a,b,c) ((a)->Update((a),(b),(c))) #define ALeffectState_Process(a,b,c,d) ((a)->Process((a),(b),(c),(d))) +ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect *effect); #ifdef __cplusplus } diff --git a/OpenAL32/Include/alEffect.h b/OpenAL32/Include/alEffect.h index 97def48a..a52eee23 100644 --- a/OpenAL32/Include/alEffect.h +++ b/OpenAL32/Include/alEffect.h @@ -102,9 +102,11 @@ typedef struct ALeffect static __inline ALboolean IsReverbEffect(ALenum type) { return type == AL_EFFECT_REVERB || type == AL_EFFECT_EAXREVERB; } -ALvoid GetReverbEffect(const char *name, ALeffect *effect); +ALenum InitEffect(ALeffect *effect); ALvoid ReleaseALEffects(ALCdevice *device); +ALvoid GetReverbEffect(const char *name, ALeffect *effect); + #ifdef __cplusplus } #endif diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index 6c4a31f2..fdabaeb2 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -50,7 +50,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo else { ALenum err; - ALsizei i, j; + ALsizei i; err = ResizeEffectSlotArray(Context, n); if(err != AL_NO_ERROR) @@ -62,7 +62,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo for(i = 0;i < n;i++) { ALeffectslot *slot = calloc(1, sizeof(ALeffectslot)); - if(!slot || !(slot->EffectState=NoneCreate())) + if(!slot || InitEffectSlot(slot) != AL_NO_ERROR) { free(slot); // We must have run out or memory @@ -71,18 +71,6 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo break; } - slot->Gain = 1.0; - slot->AuxSendAuto = AL_TRUE; - slot->NeedsUpdate = AL_FALSE; - for(j = 0;j < BUFFERSIZE;j++) - slot->WetBuffer[j] = 0.0f; - for(j = 0;j < 1;j++) - { - slot->ClickRemoval[j] = 0.0f; - slot->PendingClicks[j] = 0.0f; - } - slot->ref = 0; - LockContext(Context); err = ResizeEffectSlotArray(Context, 1); if(err == AL_NO_ERROR) @@ -599,6 +587,28 @@ ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect } +ALenum InitEffectSlot(ALeffectslot *slot) +{ + ALint i; + + if(!(slot->EffectState=NoneCreate())) + return AL_OUT_OF_MEMORY; + + slot->Gain = 1.0; + slot->AuxSendAuto = AL_TRUE; + slot->NeedsUpdate = AL_FALSE; + for(i = 0;i < BUFFERSIZE;i++) + slot->WetBuffer[i] = 0.0f; + for(i = 0;i < 1;i++) + { + slot->ClickRemoval[i] = 0.0f; + slot->PendingClicks[i] = 0.0f; + } + slot->ref = 0; + + return AL_NO_ERROR; +} + ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context) { ALsizei pos; diff --git a/OpenAL32/alEffect.c b/OpenAL32/alEffect.c index 3446fbd7..ff7195aa 100644 --- a/OpenAL32/alEffect.c +++ b/OpenAL32/alEffect.c @@ -55,13 +55,13 @@ AL_API ALvoid AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects) for(i = 0;i < n;i++) { ALeffect *effect = calloc(1, sizeof(ALeffect)); - if(!effect) + if(!effect || InitEffect(effect) != AL_NO_ERROR) { + free(effect); alSetError(Context, AL_OUT_OF_MEMORY); alDeleteEffects(i, effects); break; } - InitEffectParams(effect, AL_EFFECT_NULL); err = NewThunkEntry(&effect->effect); if(err == AL_NO_ERROR) @@ -1173,6 +1173,12 @@ static void null_GetParamfv(ALeffect *effect, ALCcontext *context, ALenum param, { (void)effect;(void)param;(void)vals; alSetError(context, AL_INVALID_ENUM); } +ALenum InitEffect(ALeffect *effect) +{ + InitEffectParams(effect, AL_EFFECT_NULL); + return AL_NO_ERROR; +} + ALvoid ReleaseALEffects(ALCdevice *device) { ALsizei i; |