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/alcChorus.c | |
parent | af1936be5dd4724367bfb7a90965f8769aa4f705 (diff) |
Use factories to create and destroy effect states
Diffstat (limited to 'Alc/alcChorus.c')
-rw-r--r-- | Alc/alcChorus.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/Alc/alcChorus.c b/Alc/alcChorus.c index ff1c9492..018caac5 100644 --- a/Alc/alcChorus.c +++ b/Alc/alcChorus.c @@ -30,6 +30,13 @@ #include "alu.h" +typedef struct ALchorusStateFactory { + DERIVE_FROM_TYPE(ALeffectStateFactory); +} ALchorusStateFactory; + +static ALchorusStateFactory ChorusFactory; + + typedef struct ALchorusState { DERIVE_FROM_TYPE(ALeffectState); @@ -57,8 +64,6 @@ static ALvoid ALchorusState_Destroy(ALchorusState *state) free(state->SampleBufferRight); state->SampleBufferRight = NULL; - - free(state); } static ALboolean ALchorusState_DeviceUpdate(ALchorusState *state, ALCdevice *Device) @@ -238,9 +243,15 @@ static ALvoid ALchorusState_Process(ALchorusState *state, ALuint SamplesToDo, co ProcessSinusoid(state, SamplesToDo, SamplesIn, SamplesOut); } +static ALeffectStateFactory *ALchorusState_getCreator(void) +{ + return STATIC_CAST(ALeffectStateFactory, &ChorusFactory); +} + DEFINE_ALEFFECTSTATE_VTABLE(ALchorusState); -ALeffectState *ChorusCreate(void) + +static ALeffectState *ALchorusStateFactory_create(void) { ALchorusState *state; @@ -256,6 +267,29 @@ ALeffectState *ChorusCreate(void) return STATIC_CAST(ALeffectState, state); } +static ALvoid ALchorusStateFactory_destroy(ALeffectState *effect) +{ + ALchorusState *state = STATIC_UPCAST(ALchorusState, ALeffectState, effect); + ALchorusState_Destroy(state); + free(state); +} + +DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALchorusStateFactory); + + +static void init_chorus_factory(void) +{ + SET_VTABLE2(ALchorusStateFactory, ALeffectStateFactory, &ChorusFactory); +} + +ALeffectStateFactory *ALchorusStateFactory_getFactory(void) +{ + static pthread_once_t once = PTHREAD_ONCE_INIT; + pthread_once(&once, init_chorus_factory); + return STATIC_CAST(ALeffectStateFactory, &ChorusFactory); +} + + void chorus_SetParami(ALeffect *effect, ALCcontext *context, ALenum param, ALint val) { switch(param) |