diff options
author | Chris Robinson <[email protected]> | 2010-04-08 08:54:28 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-04-08 08:54:28 -0700 |
commit | b273d616ad5a9979cbf0b69318aded6ec821450e (patch) | |
tree | fd19d6b0a40228669960f7cb30b1e46e04bb9f26 | |
parent | c16b895460a51d9f89a8f728155e36ab1009c8c5 (diff) |
Implement a skeleton Ring Modulator effect
-rw-r--r-- | Alc/ALc.c | 1 | ||||
-rw-r--r-- | Alc/alcModulator.c | 96 | ||||
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 1 | ||||
-rw-r--r-- | OpenAL32/Include/alEffect.h | 7 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.c | 2 | ||||
-rw-r--r-- | OpenAL32/alEffect.c | 148 | ||||
-rw-r--r-- | OpenAL32/alExtension.c | 7 |
8 files changed, 262 insertions, 1 deletions
@@ -349,6 +349,7 @@ static void alc_init(void) { "eaxreverb", EAXREVERB }, { "reverb", REVERB }, { "echo", ECHO }, + { "modulator", MODULATOR }, { NULL, 0 } }; int n; diff --git a/Alc/alcModulator.c b/Alc/alcModulator.c new file mode 100644 index 00000000..558e861b --- /dev/null +++ b/Alc/alcModulator.c @@ -0,0 +1,96 @@ +/** + * OpenAL cross platform audio library + * Copyright (C) 2009 by Chris Robinson. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * Or go to http://www.gnu.org/copyleft/lgpl.html + */ + +#include "config.h" + +#include <math.h> +#include <stdlib.h> + +#include "alMain.h" +#include "alFilter.h" +#include "alAuxEffectSlot.h" +#include "alError.h" +#include "alu.h" + + +typedef struct ALmodulatorState { + // Must be first in all effects! + ALeffectState state; +} ALmodulatorState; + +static ALvoid ModulatorDestroy(ALeffectState *effect) +{ + ALmodulatorState *state = (ALmodulatorState*)effect; + free(state); +} + +static ALboolean ModulatorDeviceUpdate(ALeffectState *effect, ALCdevice *Device) +{ + return AL_TRUE; + (void)Device; + (void)effect; +} + +static ALvoid ModulatorUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffect *Effect) +{ + (void)effect; + (void)Context; + (void)Effect; +} + +static ALvoid ModulatorProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[OUTPUTCHANNELS]) +{ + ALmodulatorState *state = (ALmodulatorState*)effect; + const ALfloat gain = Slot->Gain; + ALfloat samp; + ALuint i; + (void)state; + + for(i = 0;i < SamplesToDo;i++) + { + samp = SamplesIn[i]; + + // Apply slot gain + samp *= gain; + + SamplesOut[i][FRONT_LEFT] += samp; + SamplesOut[i][FRONT_RIGHT] += samp; + SamplesOut[i][SIDE_LEFT] += samp; + SamplesOut[i][SIDE_RIGHT] += samp; + SamplesOut[i][BACK_LEFT] += samp; + SamplesOut[i][BACK_RIGHT] += samp; + } +} + +ALeffectState *ModulatorCreate(void) +{ + ALmodulatorState *state; + + state = malloc(sizeof(*state)); + if(!state) + return NULL; + + state->state.Destroy = ModulatorDestroy; + state->state.DeviceUpdate = ModulatorDeviceUpdate; + state->state.Update = ModulatorUpdate; + state->state.Process = ModulatorProcess; + + return &state->state; +} diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c5c534f..16cc0d1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,6 +300,7 @@ SET(ALC_OBJS Alc/ALc.c Alc/ALu.c Alc/alcConfig.c Alc/alcEcho.c + Alc/alcModulator.c Alc/alcReverb.c Alc/alcRing.c Alc/alcThread.c diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index 7f217dd1..9a916dd8 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -45,6 +45,7 @@ ALeffectState *NoneCreate(void); ALeffectState *EAXVerbCreate(void); ALeffectState *VerbCreate(void); ALeffectState *EchoCreate(void); +ALeffectState *ModulatorCreate(void); #define ALEffect_Destroy(a) ((a)->Destroy((a))) #define ALEffect_DeviceUpdate(a,b) ((a)->DeviceUpdate((a),(b))) diff --git a/OpenAL32/Include/alEffect.h b/OpenAL32/Include/alEffect.h index fa49e5d1..6cbf0e5d 100644 --- a/OpenAL32/Include/alEffect.h +++ b/OpenAL32/Include/alEffect.h @@ -13,6 +13,7 @@ enum { EAXREVERB = 0, REVERB, ECHO, + MODULATOR, MAX_EFFECTS }; @@ -62,6 +63,12 @@ typedef struct ALeffect ALfloat Spread; } Echo; + struct { + ALfloat Frequency; + ALfloat HighPassCutoff; + ALint Waveform; + } Modulator; + // Index to itself ALuint effect; diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index 3f76da2f..90e28431 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -497,6 +497,8 @@ static ALvoid InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, AL NewState = VerbCreate(); else if(effect->type == AL_EFFECT_ECHO) NewState = EchoCreate(); + else if(effect->type == AL_EFFECT_RING_MODULATOR) + NewState = ModulatorCreate(); /* No new state? An error occured.. */ if(NewState == NULL || ALEffect_DeviceUpdate(NewState, Context->Device) == AL_FALSE) diff --git a/OpenAL32/alEffect.c b/OpenAL32/alEffect.c index 07d2b6dc..3dbc8b3d 100644 --- a/OpenAL32/alEffect.c +++ b/OpenAL32/alEffect.c @@ -185,7 +185,8 @@ AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue) ALboolean isOk = (iValue == AL_EFFECT_NULL || (iValue == AL_EFFECT_EAXREVERB && !DisabledEffects[EAXREVERB]) || (iValue == AL_EFFECT_REVERB && !DisabledEffects[REVERB]) || - (iValue == AL_EFFECT_ECHO && !DisabledEffects[ECHO])); + (iValue == AL_EFFECT_ECHO && !DisabledEffects[ECHO]) || + (iValue == AL_EFFECT_RING_MODULATOR && !DisabledEffects[MODULATOR])); if(isOk) InitEffectParams(ALEffect, iValue); @@ -235,6 +236,28 @@ AL_API ALvoid AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint iValue) break; } } + else if(ALEffect->type == AL_EFFECT_RING_MODULATOR) + { + switch(param) + { + case AL_RING_MODULATOR_FREQUENCY: + case AL_RING_MODULATOR_HIGHPASS_CUTOFF: + alEffectf(effect, param, (ALfloat)iValue); + break; + + case AL_RING_MODULATOR_WAVEFORM: + if(iValue >= AL_RING_MODULATOR_MIN_WAVEFORM && + iValue <= AL_RING_MODULATOR_MAX_WAVEFORM) + ALEffect->Modulator.Waveform = iValue; + else + alSetError(Context, AL_INVALID_VALUE); + break; + + default: + alSetError(Context, AL_INVALID_ENUM); + break; + } + } else alSetError(Context, AL_INVALID_ENUM); } @@ -295,6 +318,21 @@ AL_API ALvoid AL_APIENTRY alEffectiv(ALuint effect, ALenum param, ALint *piValue break; } } + else if(ALEffect->type == AL_EFFECT_RING_MODULATOR) + { + switch(param) + { + case AL_RING_MODULATOR_FREQUENCY: + case AL_RING_MODULATOR_HIGHPASS_CUTOFF: + case AL_RING_MODULATOR_WAVEFORM: + alEffecti(effect, param, piValues[0]); + break; + + default: + alSetError(Context, AL_INVALID_ENUM); + break; + } + } else alSetError(Context, AL_INVALID_ENUM); } @@ -633,6 +671,31 @@ AL_API ALvoid AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat flValue break; } } + else if(ALEffect->type == AL_EFFECT_RING_MODULATOR) + { + switch(param) + { + case AL_RING_MODULATOR_FREQUENCY: + if(flValue >= AL_RING_MODULATOR_MIN_FREQUENCY && + flValue <= AL_RING_MODULATOR_MAX_FREQUENCY) + ALEffect->Modulator.Frequency = flValue; + else + alSetError(Context, AL_INVALID_VALUE); + break; + + case AL_RING_MODULATOR_HIGHPASS_CUTOFF: + if(flValue >= AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF && + flValue <= AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF) + ALEffect->Modulator.HighPassCutoff = flValue; + else + alSetError(Context, AL_INVALID_VALUE); + break; + + default: + alSetError(Context, AL_INVALID_ENUM); + break; + } + } else alSetError(Context, AL_INVALID_ENUM); } @@ -748,6 +811,20 @@ AL_API ALvoid AL_APIENTRY alEffectfv(ALuint effect, ALenum param, ALfloat *pflVa break; } } + else if(ALEffect->type == AL_EFFECT_RING_MODULATOR) + { + switch(param) + { + case AL_RING_MODULATOR_FREQUENCY: + case AL_RING_MODULATOR_HIGHPASS_CUTOFF: + alEffectf(effect, param, pflValues[0]); + break; + + default: + alSetError(Context, AL_INVALID_ENUM); + break; + } + } else alSetError(Context, AL_INVALID_ENUM); } @@ -808,6 +885,25 @@ AL_API ALvoid AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *piVal break; } } + else if(ALEffect->type == AL_EFFECT_RING_MODULATOR) + { + switch(param) + { + case AL_RING_MODULATOR_FREQUENCY: + *piValue = (ALint)ALEffect->Modulator.Frequency; + break; + case AL_RING_MODULATOR_HIGHPASS_CUTOFF: + *piValue = (ALint)ALEffect->Modulator.HighPassCutoff; + break; + case AL_RING_MODULATOR_WAVEFORM: + *piValue = ALEffect->Modulator.Waveform; + break; + + default: + alSetError(Context, AL_INVALID_ENUM); + break; + } + } else alSetError(Context, AL_INVALID_ENUM); } @@ -868,6 +964,21 @@ AL_API ALvoid AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *piVa break; } } + else if(ALEffect->type == AL_EFFECT_RING_MODULATOR) + { + switch(param) + { + case AL_RING_MODULATOR_FREQUENCY: + case AL_RING_MODULATOR_HIGHPASS_CUTOFF: + case AL_RING_MODULATOR_WAVEFORM: + alGetEffecti(effect, param, piValues); + break; + + default: + alSetError(Context, AL_INVALID_ENUM); + break; + } + } else alSetError(Context, AL_INVALID_ENUM); } @@ -1064,6 +1175,22 @@ AL_API ALvoid AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *pfl break; } } + else if(ALEffect->type == AL_EFFECT_RING_MODULATOR) + { + switch(param) + { + case AL_RING_MODULATOR_FREQUENCY: + *pflValue = ALEffect->Modulator.Frequency; + break; + case AL_RING_MODULATOR_HIGHPASS_CUTOFF: + *pflValue = ALEffect->Modulator.HighPassCutoff; + break; + + default: + alSetError(Context, AL_INVALID_ENUM); + break; + } + } else alSetError(Context, AL_INVALID_ENUM); } @@ -1169,6 +1296,20 @@ AL_API ALvoid AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *pf break; } } + else if(ALEffect->type == AL_EFFECT_RING_MODULATOR) + { + switch(param) + { + case AL_RING_MODULATOR_FREQUENCY: + case AL_RING_MODULATOR_HIGHPASS_CUTOFF: + alGetEffectf(effect, param, pflValues); + break; + + default: + alSetError(Context, AL_INVALID_ENUM); + break; + } + } else alSetError(Context, AL_INVALID_ENUM); } @@ -1241,5 +1382,10 @@ static void InitEffectParams(ALeffect *effect, ALenum type) effect->Echo.Feedback = AL_ECHO_DEFAULT_FEEDBACK; effect->Echo.Spread = AL_ECHO_DEFAULT_SPREAD; break; + case AL_EFFECT_RING_MODULATOR: + effect->Modulator.Frequency = AL_RING_MODULATOR_DEFAULT_FREQUENCY; + effect->Modulator.HighPassCutoff = AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF; + effect->Modulator.Waveform = AL_RING_MODULATOR_DEFAULT_WAVEFORM; + break; } } diff --git a/OpenAL32/alExtension.c b/OpenAL32/alExtension.c index e08c78a5..f779c6a7 100644 --- a/OpenAL32/alExtension.c +++ b/OpenAL32/alExtension.c @@ -340,7 +340,9 @@ static const ALenums enumeration[] = { { "AL_EFFECT_FREQUENCY_SHIFTER", AL_EFFECT_FREQUENCY_SHIFTER }, { "AL_EFFECT_VOCAL_MORPHER", AL_EFFECT_VOCAL_MORPHER }, { "AL_EFFECT_PITCH_SHIFTER", AL_EFFECT_PITCH_SHIFTER }, +#endif { "AL_EFFECT_RING_MODULATOR", AL_EFFECT_RING_MODULATOR }, +#if 0 { "AL_EFFECT_AUTOWAH", AL_EFFECT_AUTOWAH }, { "AL_EFFECT_COMPRESSOR", AL_EFFECT_COMPRESSOR }, { "AL_EFFECT_EQUALIZER", AL_EFFECT_EQUALIZER }, @@ -393,6 +395,11 @@ static const ALenums enumeration[] = { { "AL_ECHO_FEEDBACK", AL_ECHO_FEEDBACK }, { "AL_ECHO_SPREAD", AL_ECHO_SPREAD }, + // Ring Modulator params + { "AL_RING_MODULATOR_FREQUENCY", AL_RING_MODULATOR_FREQUENCY }, + { "AL_RING_MODULATOR_HIGHPASS_CUTOFF", AL_RING_MODULATOR_HIGHPASS_CUTOFF }, + { "AL_RING_MODULATOR_WAVEFORM", AL_RING_MODULATOR_WAVEFORM }, + // Default { NULL, (ALenum)0 } |