Avoid duplicating some initialization code
This commit is contained in:
@@ -722,6 +722,7 @@ static void alc_initconfig(void)
|
||||
} while(next++);
|
||||
}
|
||||
|
||||
InitEffect(&ForcedEffect);
|
||||
str = getenv("__ALSOFT_DEFAULT_REVERB");
|
||||
if(str && str[0])
|
||||
GetReverbEffect(str, &ForcedEffect);
|
||||
@@ -2428,7 +2429,6 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
|
||||
const ALCchar *fmt;
|
||||
ALCdevice *device;
|
||||
ALCenum err;
|
||||
ALCint i;
|
||||
|
||||
DO_INITCONFIG();
|
||||
|
||||
@@ -2507,18 +2507,8 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
|
||||
device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
|
||||
|
||||
device->DefaultSlot = (ALeffectslot*)(device+1);
|
||||
device->DefaultSlot->EffectState = NoneCreate();
|
||||
device->DefaultSlot->Gain = 1.0;
|
||||
device->DefaultSlot->AuxSendAuto = AL_TRUE;
|
||||
device->DefaultSlot->NeedsUpdate = AL_FALSE;
|
||||
for(i = 0;i < BUFFERSIZE;i++)
|
||||
device->DefaultSlot->WetBuffer[i] = 0.0f;
|
||||
for(i = 0;i < 1;i++)
|
||||
{
|
||||
device->DefaultSlot->ClickRemoval[i] = 0.0f;
|
||||
device->DefaultSlot->PendingClicks[i] = 0.0f;
|
||||
}
|
||||
device->DefaultSlot->ref = 0;
|
||||
if(InitEffectSlot(device->DefaultSlot) != AL_NO_ERROR)
|
||||
device->DefaultSlot = NULL;
|
||||
|
||||
// Find a playback device to open
|
||||
LockLists();
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+24
-14
@@ -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;
|
||||
|
||||
+8
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user