diff options
author | Chris Robinson <[email protected]> | 2013-05-21 12:47:18 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2013-05-21 12:47:18 -0700 |
commit | a5d94f5d09be24bf34cbf8433a288cfd9ca396fb (patch) | |
tree | 456165199302b1b30bc68aadd4913f5d4ecf1572 /Alc/alcFlanger.c | |
parent | af1936be5dd4724367bfb7a90965f8769aa4f705 (diff) |
Use factories to create and destroy effect states
Diffstat (limited to 'Alc/alcFlanger.c')
-rw-r--r-- | Alc/alcFlanger.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/Alc/alcFlanger.c b/Alc/alcFlanger.c index 574fa9d7..953828f6 100644 --- a/Alc/alcFlanger.c +++ b/Alc/alcFlanger.c @@ -30,6 +30,13 @@ #include "alu.h" +typedef struct ALflangerStateFactory { + DERIVE_FROM_TYPE(ALeffectStateFactory); +} ALflangerStateFactory; + +static ALflangerStateFactory FlangerFactory; + + typedef struct ALflangerState { DERIVE_FROM_TYPE(ALeffectState); @@ -57,8 +64,6 @@ static ALvoid ALflangerState_Destroy(ALflangerState *state) free(state->SampleBufferRight); state->SampleBufferRight = NULL; - - free(state); } static ALboolean ALflangerState_DeviceUpdate(ALflangerState *state, ALCdevice *Device) @@ -238,9 +243,15 @@ static ALvoid ALflangerState_Process(ALflangerState *state, ALuint SamplesToDo, ProcessSinusoid(state, SamplesToDo, SamplesIn, SamplesOut); } +static ALeffectStateFactory *ALflangerState_getCreator(void) +{ + return STATIC_CAST(ALeffectStateFactory, &FlangerFactory); +} + DEFINE_ALEFFECTSTATE_VTABLE(ALflangerState); -ALeffectState *FlangerCreate(void) + +ALeffectState *ALflangerStateFactory_create(void) { ALflangerState *state; @@ -256,6 +267,29 @@ ALeffectState *FlangerCreate(void) return STATIC_CAST(ALeffectState, state); } +static ALvoid ALflangerStateFactory_destroy(ALeffectState *effect) +{ + ALflangerState *state = STATIC_UPCAST(ALflangerState, ALeffectState, effect); + ALflangerState_Destroy(state); + free(state); +} + +DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALflangerStateFactory); + + +static void init_flanger_factory(void) +{ + SET_VTABLE2(ALflangerStateFactory, ALeffectStateFactory, &FlangerFactory); +} + +ALeffectStateFactory *ALflangerStateFactory_getFactory(void) +{ + static pthread_once_t once = PTHREAD_ONCE_INIT; + pthread_once(&once, init_flanger_factory); + return STATIC_CAST(ALeffectStateFactory, &FlangerFactory); +} + + void flanger_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val) { switch(param) |