diff options
-rw-r--r-- | Alc/effects/autowah.c | 14 | ||||
-rw-r--r-- | Alc/effects/chorus.c | 20 | ||||
-rw-r--r-- | Alc/effects/compressor.c | 13 | ||||
-rw-r--r-- | Alc/effects/dedicated.c | 20 | ||||
-rw-r--r-- | Alc/effects/distortion.c | 20 | ||||
-rw-r--r-- | Alc/effects/echo.c | 21 | ||||
-rw-r--r-- | Alc/effects/equalizer.c | 21 | ||||
-rw-r--r-- | Alc/effects/flanger.c | 21 | ||||
-rw-r--r-- | Alc/effects/modulator.c | 21 | ||||
-rw-r--r-- | Alc/effects/null.c | 19 | ||||
-rw-r--r-- | Alc/effects/reverb.c | 21 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 7 |
12 files changed, 71 insertions, 147 deletions
diff --git a/Alc/effects/autowah.c b/Alc/effects/autowah.c index 1b2e166d..9a3f8b94 100644 --- a/Alc/effects/autowah.c +++ b/Alc/effects/autowah.c @@ -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); } diff --git a/Alc/effects/chorus.c b/Alc/effects/chorus.c index 50b5c54a..9e74f8c8 100644 --- a/Alc/effects/chorus.c +++ b/Alc/effects/chorus.c @@ -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); } diff --git a/Alc/effects/compressor.c b/Alc/effects/compressor.c index ea035fa7..8c639f43 100644 --- a/Alc/effects/compressor.c +++ b/Alc/effects/compressor.c @@ -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); } diff --git a/Alc/effects/dedicated.c b/Alc/effects/dedicated.c index ecf177cb..fe57c7d8 100644 --- a/Alc/effects/dedicated.c +++ b/Alc/effects/dedicated.c @@ -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); } diff --git a/Alc/effects/distortion.c b/Alc/effects/distortion.c index 5c6b0497..7402f0af 100644 --- a/Alc/effects/distortion.c +++ b/Alc/effects/distortion.c @@ -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); } diff --git a/Alc/effects/echo.c b/Alc/effects/echo.c index 18c32f17..7471c3dd 100644 --- a/Alc/effects/echo.c +++ b/Alc/effects/echo.c @@ -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); } diff --git a/Alc/effects/equalizer.c b/Alc/effects/equalizer.c index dba6cc3a..d5bd2caf 100644 --- a/Alc/effects/equalizer.c +++ b/Alc/effects/equalizer.c @@ -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); } diff --git a/Alc/effects/flanger.c b/Alc/effects/flanger.c index 644426ca..d3cdd250 100644 --- a/Alc/effects/flanger.c +++ b/Alc/effects/flanger.c @@ -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); } diff --git a/Alc/effects/modulator.c b/Alc/effects/modulator.c index 90fb50d3..4fdd1261 100644 --- a/Alc/effects/modulator.c +++ b/Alc/effects/modulator.c @@ -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); } diff --git a/Alc/effects/null.c b/Alc/effects/null.c index ff378960..816a2525 100644 --- a/Alc/effects/null.c +++ b/Alc/effects/null.c @@ -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); } diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c index 4a99adb7..77bf4a16 100644 --- a/Alc/effects/reverb.c +++ b/Alc/effects/reverb.c @@ -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); } diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 47f1934c..11a1e78c 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -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__ |