Convert the remaining effects to C++

This commit is contained in:
Chris Robinson 2018-11-17 07:08:41 -08:00
parent 93d96ced9c
commit 13478126cb
4 changed files with 51 additions and 36 deletions

View File

@ -33,9 +33,7 @@
#define MAX_FREQ 2500.0f
#define Q_FACTOR 5.0f
typedef struct ALautowahState {
DERIVE_FROM_TYPE(ALeffectState);
struct ALautowahState final : public ALeffectState {
/* Effect parameters */
ALfloat AttackRate;
ALfloat ReleaseRate;
@ -64,7 +62,7 @@ typedef struct ALautowahState {
/* Effects buffers */
alignas(16) ALfloat BufferOut[BUFFERSIZE];
} ALautowahState;
};
static ALvoid ALautowahState_Destruct(ALautowahState *state);
static ALboolean ALautowahState_deviceUpdate(ALautowahState *state, ALCdevice *device);
@ -76,6 +74,7 @@ DEFINE_ALEFFECTSTATE_VTABLE(ALautowahState);
static void ALautowahState_Construct(ALautowahState *state)
{
new (state) ALautowahState{};
ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
SET_VTABLE2(ALautowahState, ALeffectState, state);
}
@ -83,6 +82,7 @@ static void ALautowahState_Construct(ALautowahState *state)
static ALvoid ALautowahState_Destruct(ALautowahState *state)
{
ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
state->~ALautowahState();
}
static ALboolean ALautowahState_deviceUpdate(ALautowahState *state, ALCdevice *UNUSED(device))
@ -204,9 +204,9 @@ static ALvoid ALautowahState_process(ALautowahState *state, ALsizei SamplesToDo,
}
}
typedef struct AutowahStateFactory {
DERIVE_FROM_TYPE(EffectStateFactory);
} AutowahStateFactory;
struct AutowahStateFactory final : public EffectStateFactory {
AutowahStateFactory() noexcept;
};
static ALeffectState *AutowahStateFactory_create(AutowahStateFactory *UNUSED(factory))
{
@ -220,9 +220,14 @@ static ALeffectState *AutowahStateFactory_create(AutowahStateFactory *UNUSED(fac
DEFINE_EFFECTSTATEFACTORY_VTABLE(AutowahStateFactory);
AutowahStateFactory::AutowahStateFactory() noexcept
: EffectStateFactory{GET_VTABLE2(AutowahStateFactory, EffectStateFactory)}
{
}
EffectStateFactory *AutowahStateFactory_getFactory(void)
{
static AutowahStateFactory AutowahFactory = { { GET_VTABLE2(AutowahStateFactory, EffectStateFactory) } };
static AutowahStateFactory AutowahFactory{};
return STATIC_CAST(EffectStateFactory, &AutowahFactory);
}

View File

@ -38,9 +38,7 @@ enum WaveForm {
WF_Triangle
};
typedef struct ALchorusState {
DERIVE_FROM_TYPE(ALeffectState);
struct ALchorusState final : public ALeffectState {
ALfloat *SampleBuffer;
ALsizei BufferLength;
ALsizei offset;
@ -61,7 +59,7 @@ typedef struct ALchorusState {
ALint delay;
ALfloat depth;
ALfloat feedback;
} ALchorusState;
};
static ALvoid ALchorusState_Destruct(ALchorusState *state);
static ALboolean ALchorusState_deviceUpdate(ALchorusState *state, ALCdevice *Device);
@ -74,6 +72,7 @@ DEFINE_ALEFFECTSTATE_VTABLE(ALchorusState);
static void ALchorusState_Construct(ALchorusState *state)
{
new (state) ALchorusState{};
ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
SET_VTABLE2(ALchorusState, ALeffectState, state);
@ -91,6 +90,7 @@ static ALvoid ALchorusState_Destruct(ALchorusState *state)
state->SampleBuffer = NULL;
ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
state->~ALchorusState();
}
static ALboolean ALchorusState_deviceUpdate(ALchorusState *state, ALCdevice *Device)
@ -107,8 +107,7 @@ static ALboolean ALchorusState_deviceUpdate(ALchorusState *state, ALCdevice *Dev
if(!temp) return AL_FALSE;
al_free(state->SampleBuffer);
state->SampleBuffer = temp;
state->SampleBuffer = static_cast<float*>(temp);
state->BufferLength = maxlen;
}
@ -285,9 +284,9 @@ static ALvoid ALchorusState_process(ALchorusState *state, ALsizei SamplesToDo, c
}
typedef struct ChorusStateFactory {
DERIVE_FROM_TYPE(EffectStateFactory);
} ChorusStateFactory;
struct ChorusStateFactory final : public EffectStateFactory {
ChorusStateFactory() noexcept;
};
static ALeffectState *ChorusStateFactory_create(ChorusStateFactory *UNUSED(factory))
{
@ -301,11 +300,14 @@ static ALeffectState *ChorusStateFactory_create(ChorusStateFactory *UNUSED(facto
DEFINE_EFFECTSTATEFACTORY_VTABLE(ChorusStateFactory);
ChorusStateFactory::ChorusStateFactory() noexcept
: EffectStateFactory{GET_VTABLE2(ChorusStateFactory, EffectStateFactory)}
{
}
EffectStateFactory *ChorusStateFactory_getFactory(void)
{
static ChorusStateFactory ChorusFactory = { { GET_VTABLE2(ChorusStateFactory, EffectStateFactory) } };
static ChorusStateFactory ChorusFactory{};
return STATIC_CAST(EffectStateFactory, &ChorusFactory);
}
@ -422,9 +424,9 @@ DEFINE_ALEFFECT_VTABLE(ALchorus);
/* Flanger is basically a chorus with a really short delay. They can both use
* the same processing functions, so piggyback flanger on the chorus functions.
*/
typedef struct FlangerStateFactory {
DERIVE_FROM_TYPE(EffectStateFactory);
} FlangerStateFactory;
struct FlangerStateFactory final : public EffectStateFactory {
FlangerStateFactory() noexcept;
};
ALeffectState *FlangerStateFactory_create(FlangerStateFactory *UNUSED(factory))
{
@ -438,10 +440,14 @@ ALeffectState *FlangerStateFactory_create(FlangerStateFactory *UNUSED(factory))
DEFINE_EFFECTSTATEFACTORY_VTABLE(FlangerStateFactory);
FlangerStateFactory::FlangerStateFactory() noexcept
: EffectStateFactory{GET_VTABLE2(FlangerStateFactory, EffectStateFactory)}
{
}
EffectStateFactory *FlangerStateFactory_getFactory(void)
{
static FlangerStateFactory FlangerFactory = { { GET_VTABLE2(FlangerStateFactory, EffectStateFactory) } };
static FlangerStateFactory FlangerFactory{};
return STATIC_CAST(EffectStateFactory, &FlangerFactory);
}

View File

@ -34,9 +34,7 @@
#define RELEASE_TIME 0.2f /* 200ms to drop from max to min */
typedef struct ALcompressorState {
DERIVE_FROM_TYPE(ALeffectState);
struct ALcompressorState final : public ALeffectState {
/* Effect gains for each channel */
ALfloat Gain[MAX_EFFECT_CHANNELS][MAX_OUTPUT_CHANNELS];
@ -45,7 +43,7 @@ typedef struct ALcompressorState {
ALfloat AttackMult;
ALfloat ReleaseMult;
ALfloat EnvFollower;
} ALcompressorState;
};
static ALvoid ALcompressorState_Destruct(ALcompressorState *state);
static ALboolean ALcompressorState_deviceUpdate(ALcompressorState *state, ALCdevice *device);
@ -58,6 +56,7 @@ DEFINE_ALEFFECTSTATE_VTABLE(ALcompressorState);
static void ALcompressorState_Construct(ALcompressorState *state)
{
new (state) ALcompressorState{};
ALeffectState_Construct(STATIC_CAST(ALeffectState, state));
SET_VTABLE2(ALcompressorState, ALeffectState, state);
@ -70,6 +69,7 @@ static void ALcompressorState_Construct(ALcompressorState *state)
static ALvoid ALcompressorState_Destruct(ALcompressorState *state)
{
ALeffectState_Destruct(STATIC_CAST(ALeffectState,state));
state->~ALcompressorState();
}
static ALboolean ALcompressorState_deviceUpdate(ALcompressorState *state, ALCdevice *device)
@ -172,9 +172,9 @@ static ALvoid ALcompressorState_process(ALcompressorState *state, ALsizei Sample
}
typedef struct CompressorStateFactory {
DERIVE_FROM_TYPE(EffectStateFactory);
} CompressorStateFactory;
struct CompressorStateFactory final : public EffectStateFactory {
CompressorStateFactory() noexcept;
};
static ALeffectState *CompressorStateFactory_create(CompressorStateFactory *UNUSED(factory))
{
@ -188,10 +188,14 @@ static ALeffectState *CompressorStateFactory_create(CompressorStateFactory *UNUS
DEFINE_EFFECTSTATEFACTORY_VTABLE(CompressorStateFactory);
CompressorStateFactory::CompressorStateFactory() noexcept
: EffectStateFactory{GET_VTABLE2(CompressorStateFactory, EffectStateFactory)}
{
}
EffectStateFactory *CompressorStateFactory_getFactory(void)
{
static CompressorStateFactory CompressorFactory = { { GET_VTABLE2(CompressorStateFactory, EffectStateFactory) } };
static CompressorStateFactory CompressorFactory{};
return STATIC_CAST(EffectStateFactory, &CompressorFactory);
}

View File

@ -808,9 +808,9 @@ SET(ALC_OBJS
Alc/mastering.h
Alc/ringbuffer.c
Alc/ringbuffer.h
Alc/effects/autowah.c
Alc/effects/chorus.c
Alc/effects/compressor.c
Alc/effects/autowah.cpp
Alc/effects/chorus.cpp
Alc/effects/compressor.cpp
Alc/effects/dedicated.cpp
Alc/effects/distortion.cpp
Alc/effects/echo.cpp