Use inline initialization for effect state factory vtables

This commit is contained in:
Chris Robinson 2013-10-07 14:49:36 -07:00
parent fc31a41473
commit b42fcce014
12 changed files with 71 additions and 147 deletions

View File

@ -35,13 +35,6 @@
#define OCTAVE 2.0f
typedef struct ALautowahStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALautowahStateFactory;
static ALautowahStateFactory AutowahFactory;
/* We use a lfo with a custom low-pass filter to generate autowah
* effect and a high-pass filter to avoid distortion and aliasing.
* By adding the two filters up, we obtain a dynamic bandpass filter.
@ -171,6 +164,10 @@ static void ALautowahState_Delete(ALautowahState *state)
DEFINE_ALEFFECTSTATE_VTABLE(ALautowahState);
typedef struct ALautowahStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALautowahStateFactory;
static ALeffectState *ALautowahStateFactory_create(ALautowahStateFactory *UNUSED(factory))
{
ALautowahState *state;
@ -189,7 +186,8 @@ DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALautowahStateFactory);
ALeffectStateFactory *ALautowahStateFactory_getFactory(void)
{
SET_VTABLE2(ALautowahStateFactory, ALeffectStateFactory, &AutowahFactory);
static ALautowahStateFactory AutowahFactory = { { GET_VTABLE2(ALautowahStateFactory, ALeffectStateFactory) } };
return STATIC_CAST(ALeffectStateFactory, &AutowahFactory);
}

View File

@ -30,13 +30,6 @@
#include "alu.h"
typedef struct ALchorusStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALchorusStateFactory;
static ALchorusStateFactory ChorusFactory;
typedef struct ALchorusState {
DERIVE_FROM_TYPE(ALeffectState);
@ -244,6 +237,10 @@ static void ALchorusState_Delete(ALchorusState *state)
DEFINE_ALEFFECTSTATE_VTABLE(ALchorusState);
typedef struct ALchorusStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALchorusStateFactory;
static ALeffectState *ALchorusStateFactory_create(ALchorusStateFactory *UNUSED(factory))
{
ALchorusState *state;
@ -263,15 +260,10 @@ static ALeffectState *ALchorusStateFactory_create(ALchorusStateFactory *UNUSED(f
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);
static ALchorusStateFactory ChorusFactory = { { GET_VTABLE2(ALchorusStateFactory, ALeffectStateFactory) } };
return STATIC_CAST(ALeffectStateFactory, &ChorusFactory);
}

View File

@ -26,12 +26,6 @@
#include "alAuxEffectSlot.h"
#include "alu.h"
typedef struct ALcompressorStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALcompressorStateFactory;
static ALcompressorStateFactory CompressorFactory;
typedef struct ALcompressorState {
DERIVE_FROM_TYPE(ALeffectState);
@ -138,6 +132,10 @@ static void ALcompressorState_Delete(ALcompressorState *state)
DEFINE_ALEFFECTSTATE_VTABLE(ALcompressorState);
typedef struct ALcompressorStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALcompressorStateFactory;
static ALeffectState *ALcompressorStateFactory_create(ALcompressorStateFactory *UNUSED(factory))
{
ALcompressorState *state;
@ -153,7 +151,8 @@ DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALcompressorStateFactory);
ALeffectStateFactory *ALcompressorStateFactory_getFactory(void)
{
SET_VTABLE2(ALcompressorStateFactory, ALeffectStateFactory, &CompressorFactory);
static ALcompressorStateFactory CompressorFactory = { { GET_VTABLE2(ALcompressorStateFactory, ALeffectStateFactory) } };
return STATIC_CAST(ALeffectStateFactory, &CompressorFactory);
}

View File

@ -29,13 +29,6 @@
#include "alu.h"
typedef struct ALdedicatedStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALdedicatedStateFactory;
static ALdedicatedStateFactory DedicatedFactory;
typedef struct ALdedicatedState {
DERIVE_FROM_TYPE(ALeffectState);
@ -91,6 +84,10 @@ static void ALdedicatedState_Delete(ALdedicatedState *state)
DEFINE_ALEFFECTSTATE_VTABLE(ALdedicatedState);
typedef struct ALdedicatedStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALdedicatedStateFactory;
ALeffectState *ALdedicatedStateFactory_create(ALdedicatedStateFactory *UNUSED(factory))
{
ALdedicatedState *state;
@ -109,15 +106,10 @@ ALeffectState *ALdedicatedStateFactory_create(ALdedicatedStateFactory *UNUSED(fa
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALdedicatedStateFactory);
static void init_dedicated_factory(void)
{
SET_VTABLE2(ALdedicatedStateFactory, ALeffectStateFactory, &DedicatedFactory);
}
ALeffectStateFactory *ALdedicatedStateFactory_getFactory(void)
{
static pthread_once_t once = PTHREAD_ONCE_INIT;
pthread_once(&once, init_dedicated_factory);
static ALdedicatedStateFactory DedicatedFactory = { { GET_VTABLE2(ALdedicatedStateFactory, ALeffectStateFactory) } };
return STATIC_CAST(ALeffectStateFactory, &DedicatedFactory);
}

View File

@ -30,13 +30,6 @@
#include "alu.h"
typedef struct ALdistortionStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALdistortionStateFactory;
static ALdistortionStateFactory DistortionFactory;
typedef struct ALdistortionState {
DERIVE_FROM_TYPE(ALeffectState);
@ -185,6 +178,10 @@ static void ALdistortionState_Delete(ALdistortionState *state)
DEFINE_ALEFFECTSTATE_VTABLE(ALdistortionState);
typedef struct ALdistortionStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALdistortionStateFactory;
static ALeffectState *ALdistortionStateFactory_create(ALdistortionStateFactory *UNUSED(factory))
{
ALdistortionState *state;
@ -202,15 +199,10 @@ static ALeffectState *ALdistortionStateFactory_create(ALdistortionStateFactory *
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALdistortionStateFactory);
static void init_distortion_factory(void)
{
SET_VTABLE2(ALdistortionStateFactory, ALeffectStateFactory, &DistortionFactory);
}
ALeffectStateFactory *ALdistortionStateFactory_getFactory(void)
{
static pthread_once_t once = PTHREAD_ONCE_INIT;
pthread_once(&once, init_distortion_factory);
static ALdistortionStateFactory DistortionFactory = { { GET_VTABLE2(ALdistortionStateFactory, ALeffectStateFactory) } };
return STATIC_CAST(ALeffectStateFactory, &DistortionFactory);
}

View File

@ -30,13 +30,6 @@
#include "alu.h"
typedef struct ALechoStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALechoStateFactory;
static ALechoStateFactory EchoFactory;
typedef struct ALechoState {
DERIVE_FROM_TYPE(ALeffectState);
@ -176,6 +169,10 @@ static void ALechoState_Delete(ALechoState *state)
DEFINE_ALEFFECTSTATE_VTABLE(ALechoState);
typedef struct ALechoStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALechoStateFactory;
ALeffectState *ALechoStateFactory_create(ALechoStateFactory *UNUSED(factory))
{
ALechoState *state;
@ -198,16 +195,10 @@ ALeffectState *ALechoStateFactory_create(ALechoStateFactory *UNUSED(factory))
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALechoStateFactory);
static void init_echo_factory(void)
{
SET_VTABLE2(ALechoStateFactory, ALeffectStateFactory, &EchoFactory);
}
ALeffectStateFactory *ALechoStateFactory_getFactory(void)
{
static pthread_once_t once = PTHREAD_ONCE_INIT;
pthread_once(&once, init_echo_factory);
static ALechoStateFactory EchoFactory = { { GET_VTABLE2(ALechoStateFactory, ALeffectStateFactory) } };
return STATIC_CAST(ALeffectStateFactory, &EchoFactory);
}

View File

@ -30,13 +30,6 @@
#include "alu.h"
typedef struct ALequalizerStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALequalizerStateFactory;
static ALequalizerStateFactory EqualizerFactory;
/* The document "Effects Extension Guide.pdf" says that low and high *
* frequencies are cutoff frequencies. This is not fully correct, they *
* are corner frequencies for low and high shelf filters. If they were *
@ -170,6 +163,10 @@ static void ALequalizerState_Delete(ALequalizerState *state)
DEFINE_ALEFFECTSTATE_VTABLE(ALequalizerState);
typedef struct ALequalizerStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALequalizerStateFactory;
ALeffectState *ALequalizerStateFactory_create(ALequalizerStateFactory *UNUSED(factory))
{
ALequalizerState *state;
@ -189,16 +186,10 @@ ALeffectState *ALequalizerStateFactory_create(ALequalizerStateFactory *UNUSED(fa
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALequalizerStateFactory);
static void init_equalizer_factory(void)
{
SET_VTABLE2(ALequalizerStateFactory, ALeffectStateFactory, &EqualizerFactory);
}
ALeffectStateFactory *ALequalizerStateFactory_getFactory(void)
{
static pthread_once_t once = PTHREAD_ONCE_INIT;
pthread_once(&once, init_equalizer_factory);
static ALequalizerStateFactory EqualizerFactory = { { GET_VTABLE2(ALequalizerStateFactory, ALeffectStateFactory) } };
return STATIC_CAST(ALeffectStateFactory, &EqualizerFactory);
}

View File

@ -30,13 +30,6 @@
#include "alu.h"
typedef struct ALflangerStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALflangerStateFactory;
static ALflangerStateFactory FlangerFactory;
typedef struct ALflangerState {
DERIVE_FROM_TYPE(ALeffectState);
@ -244,6 +237,10 @@ static void ALflangerState_Delete(ALflangerState *state)
DEFINE_ALEFFECTSTATE_VTABLE(ALflangerState);
typedef struct ALflangerStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALflangerStateFactory;
ALeffectState *ALflangerStateFactory_create(ALflangerStateFactory *UNUSED(factory))
{
ALflangerState *state;
@ -262,16 +259,10 @@ ALeffectState *ALflangerStateFactory_create(ALflangerStateFactory *UNUSED(factor
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);
static ALflangerStateFactory FlangerFactory = { { GET_VTABLE2(ALflangerStateFactory, ALeffectStateFactory) } };
return STATIC_CAST(ALeffectStateFactory, &FlangerFactory);
}

View File

@ -30,13 +30,6 @@
#include "alu.h"
typedef struct ALmodulatorStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALmodulatorStateFactory;
static ALmodulatorStateFactory ModulatorFactory;
typedef struct ALmodulatorState {
DERIVE_FROM_TYPE(ALeffectState);
@ -187,6 +180,10 @@ static void ALmodulatorState_Delete(ALmodulatorState *state)
DEFINE_ALEFFECTSTATE_VTABLE(ALmodulatorState);
typedef struct ALmodulatorStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALmodulatorStateFactory;
static ALeffectState *ALmodulatorStateFactory_create(ALmodulatorStateFactory *UNUSED(factory))
{
ALmodulatorState *state;
@ -205,16 +202,10 @@ static ALeffectState *ALmodulatorStateFactory_create(ALmodulatorStateFactory *UN
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALmodulatorStateFactory);
static void init_modulator_factory(void)
{
SET_VTABLE2(ALmodulatorStateFactory, ALeffectStateFactory, &ModulatorFactory);
}
ALeffectStateFactory *ALmodulatorStateFactory_getFactory(void)
{
static pthread_once_t once = PTHREAD_ONCE_INIT;
pthread_once(&once, init_modulator_factory);
static ALmodulatorStateFactory ModulatorFactory = { { GET_VTABLE2(ALmodulatorStateFactory, ALeffectStateFactory) } };
return STATIC_CAST(ALeffectStateFactory, &ModulatorFactory);
}

View File

@ -9,15 +9,10 @@
#include "alError.h"
typedef struct ALnullStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALnullStateFactory;
typedef struct ALnullState {
DERIVE_FROM_TYPE(ALeffectState);
} ALnullState;
static ALnullStateFactory NullFactory;
/* This destructs (not free!) the effect state. It's called only when the
* effect slot is no longer used.
@ -63,6 +58,10 @@ static void ALnullState_Delete(ALnullState *state)
DEFINE_ALEFFECTSTATE_VTABLE(ALnullState);
typedef struct ALnullStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALnullStateFactory;
/* Creates ALeffectState objects of the appropriate type. */
ALeffectState *ALnullStateFactory_create(ALnullStateFactory *UNUSED(factory))
{
@ -79,16 +78,10 @@ ALeffectState *ALnullStateFactory_create(ALnullStateFactory *UNUSED(factory))
/* Define the ALeffectStateFactory vtable for this type. */
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALnullStateFactory);
static void init_none_factory(void)
{
SET_VTABLE2(ALnullStateFactory, ALeffectStateFactory, &NullFactory);
}
ALeffectStateFactory *ALnullStateFactory_getFactory(void)
{
static pthread_once_t once = PTHREAD_ONCE_INIT;
pthread_once(&once, init_none_factory);
static ALnullStateFactory NullFactory = { { GET_VTABLE2(ALnullStateFactory, ALeffectStateFactory) } };
return STATIC_CAST(ALeffectStateFactory, &NullFactory);
}

View File

@ -32,13 +32,6 @@
#include "alError.h"
typedef struct ALreverbStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALreverbStateFactory;
static ALreverbStateFactory ReverbFactory;
typedef struct DelayLine
{
// The delay lines use sample lengths that are powers of 2 to allow the
@ -1185,6 +1178,10 @@ static void ALreverbState_Delete(ALreverbState *state)
DEFINE_ALEFFECTSTATE_VTABLE(ALreverbState);
typedef struct ALreverbStateFactory {
DERIVE_FROM_TYPE(ALeffectStateFactory);
} ALreverbStateFactory;
static ALeffectState *ALreverbStateFactory_create(ALreverbStateFactory* UNUSED(factory))
{
ALreverbState *state;
@ -1278,16 +1275,10 @@ static ALeffectState *ALreverbStateFactory_create(ALreverbStateFactory* UNUSED(f
DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALreverbStateFactory);
static void init_reverb_factory(void)
{
SET_VTABLE2(ALreverbStateFactory, ALeffectStateFactory, &ReverbFactory);
}
ALeffectStateFactory *ALreverbStateFactory_getFactory(void)
{
static pthread_once_t once = PTHREAD_ONCE_INIT;
pthread_once(&once, init_reverb_factory);
static ALreverbStateFactory ReverbFactory = { { GET_VTABLE2(ALreverbStateFactory, ALeffectStateFactory) } };
return STATIC_CAST(ALeffectStateFactory, &ReverbFactory);
}

View File

@ -93,8 +93,11 @@ static const union {
#define STATIC_CAST(to, obj) (&(obj)->to##_parent)
#define STATIC_UPCAST(to, from, obj) ((to*)((char*)(obj) - offsetof(to, from##_parent)))
#define SET_VTABLE1(T1, obj) ((obj)->vtbl = &(T1##_vtable))
#define SET_VTABLE2(T1, T2, obj) SET_VTABLE1(T1##_##T2, STATIC_CAST(T2, (obj)))
#define GET_VTABLE1(T1) (&(T1##_vtable))
#define GET_VTABLE2(T1, T2) (&(T1##_##T2##_vtable))
#define SET_VTABLE1(T1, obj) ((obj)->vtbl = GET_VTABLE1(T1))
#define SET_VTABLE2(T1, T2, obj) (STATIC_CAST(T2, obj)->vtbl = GET_VTABLE2(T1, T2))
/* Helper to extract an argument list for VCALL. Not used directly. */
#define EXTRACT_VCALL_ARGS(...) __VA_ARGS__