aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/effects/modulator.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-19 22:43:28 -0800
committerChris Robinson <[email protected]>2018-11-19 22:43:28 -0800
commit8995306203f022cb5042f490044373f09caac177 (patch)
treee58f31afbda9aeedec7c5664028d1fa877605d68 /Alc/effects/modulator.cpp
parent8472a9d916eae13771455c2b527c1148aa71d8fb (diff)
Use proper templating for the modulator's Modulate function
Diffstat (limited to 'Alc/effects/modulator.cpp')
-rw-r--r--Alc/effects/modulator.cpp75
1 files changed, 33 insertions, 42 deletions
diff --git a/Alc/effects/modulator.cpp b/Alc/effects/modulator.cpp
index f714f94f..ac71e444 100644
--- a/Alc/effects/modulator.cpp
+++ b/Alc/effects/modulator.cpp
@@ -37,28 +37,6 @@
#define MAX_UPDATE_SAMPLES 128
-struct ALmodulatorState final : public EffectState {
- void (*mGetSamples)(ALfloat*RESTRICT, ALsizei, const ALsizei, ALsizei){};
-
- ALsizei mIndex{0};
- ALsizei mStep{1};
-
- struct {
- BiquadFilter Filter;
-
- ALfloat CurrentGains[MAX_OUTPUT_CHANNELS]{};
- ALfloat TargetGains[MAX_OUTPUT_CHANNELS]{};
- } mChans[MAX_EFFECT_CHANNELS];
-
-
- ALboolean deviceUpdate(ALCdevice *device) override;
- void update(const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props) override;
- void process(ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], ALsizei numChannels) override;
-
- DEF_NEWDEL(ALmodulatorState)
-};
-
-
#define WAVEFORM_FRACBITS 24
#define WAVEFORM_FRACONE (1<<WAVEFORM_FRACBITS)
#define WAVEFORM_FRACMASK (WAVEFORM_FRACONE-1)
@@ -83,26 +61,39 @@ static inline ALfloat One(ALsizei UNUSED(index))
return 1.0f;
}
-#define DECL_TEMPLATE(func) \
-static void Modulate##func(ALfloat *RESTRICT dst, ALsizei index, \
- const ALsizei step, ALsizei todo) \
-{ \
- ALsizei i; \
- for(i = 0;i < todo;i++) \
- { \
- index += step; \
- index &= WAVEFORM_FRACMASK; \
- dst[i] = func(index); \
- } \
+template<ALfloat func(ALsizei)>
+static void Modulate(ALfloat *RESTRICT dst, ALsizei index, const ALsizei step, ALsizei todo)
+{
+ ALsizei i;
+ for(i = 0;i < todo;i++)
+ {
+ index += step;
+ index &= WAVEFORM_FRACMASK;
+ dst[i] = func(index);
+ }
}
-DECL_TEMPLATE(Sin)
-DECL_TEMPLATE(Saw)
-DECL_TEMPLATE(Square)
-DECL_TEMPLATE(One)
-#undef DECL_TEMPLATE
+struct ALmodulatorState final : public EffectState {
+ void (*mGetSamples)(ALfloat*RESTRICT, ALsizei, const ALsizei, ALsizei){};
+
+ ALsizei mIndex{0};
+ ALsizei mStep{1};
+
+ struct {
+ BiquadFilter Filter;
+
+ ALfloat CurrentGains[MAX_OUTPUT_CHANNELS]{};
+ ALfloat TargetGains[MAX_OUTPUT_CHANNELS]{};
+ } mChans[MAX_EFFECT_CHANNELS];
+
+ ALboolean deviceUpdate(ALCdevice *device) override;
+ void update(const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props) override;
+ void process(ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], ALsizei numChannels) override;
+
+ DEF_NEWDEL(ALmodulatorState)
+};
ALboolean ALmodulatorState::deviceUpdate(ALCdevice *UNUSED(device))
{
@@ -124,13 +115,13 @@ void ALmodulatorState::update(const ALCcontext *context, const ALeffectslot *slo
mStep = clampi(mStep, 0, WAVEFORM_FRACONE-1);
if(mStep == 0)
- mGetSamples = ModulateOne;
+ mGetSamples = Modulate<One>;
else if(props->Modulator.Waveform == AL_RING_MODULATOR_SINUSOID)
- mGetSamples = ModulateSin;
+ mGetSamples = Modulate<Sin>;
else if(props->Modulator.Waveform == AL_RING_MODULATOR_SAWTOOTH)
- mGetSamples = ModulateSaw;
+ mGetSamples = Modulate<Saw>;
else /*if(Slot->Params.EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SQUARE)*/
- mGetSamples = ModulateSquare;
+ mGetSamples = Modulate<Square>;
f0norm = props->Modulator.HighPassCutoff / (ALfloat)device->Frequency;
f0norm = clampf(f0norm, 1.0f/512.0f, 0.49f);