rlm@0: /** rlm@0: * OpenAL cross platform audio library rlm@0: * Copyright (C) 2011 by Chris Robinson. rlm@0: * This library is free software; you can redistribute it and/or rlm@0: * modify it under the terms of the GNU Library General Public rlm@0: * License as published by the Free Software Foundation; either rlm@0: * version 2 of the License, or (at your option) any later version. rlm@0: * rlm@0: * This library is distributed in the hope that it will be useful, rlm@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of rlm@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU rlm@0: * Library General Public License for more details. rlm@0: * rlm@0: * You should have received a copy of the GNU Library General Public rlm@0: * License along with this library; if not, write to the rlm@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, rlm@0: * Boston, MA 02111-1307, USA. rlm@0: * Or go to http://www.gnu.org/copyleft/lgpl.html rlm@0: */ rlm@0: rlm@0: #include "config.h" rlm@0: rlm@0: #include rlm@0: rlm@0: #include "alMain.h" rlm@0: #include "alFilter.h" rlm@0: #include "alAuxEffectSlot.h" rlm@0: #include "alError.h" rlm@0: #include "alu.h" rlm@0: rlm@0: rlm@0: typedef struct ALdedicatedState { rlm@0: // Must be first in all effects! rlm@0: ALeffectState state; rlm@0: rlm@0: ALfloat gains[MAXCHANNELS]; rlm@0: } ALdedicatedState; rlm@0: rlm@0: rlm@0: static ALvoid DedicatedDestroy(ALeffectState *effect) rlm@0: { rlm@0: ALdedicatedState *state = (ALdedicatedState*)effect; rlm@0: free(state); rlm@0: } rlm@0: rlm@0: static ALboolean DedicatedDeviceUpdate(ALeffectState *effect, ALCdevice *Device) rlm@0: { rlm@0: (void)effect; rlm@0: (void)Device; rlm@0: return AL_TRUE; rlm@0: } rlm@0: rlm@0: static ALvoid DedicatedDLGUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffectslot *Slot) rlm@0: { rlm@0: ALdedicatedState *state = (ALdedicatedState*)effect; rlm@0: ALCdevice *device = Context->Device; rlm@0: const ALfloat *SpeakerGain; rlm@0: ALfloat Gain; rlm@0: ALint pos; rlm@0: ALsizei s; rlm@0: rlm@0: pos = aluCart2LUTpos(1.0f, 0.0f); rlm@0: SpeakerGain = device->PanningLUT[pos]; rlm@0: rlm@0: Gain = Slot->Gain * Slot->effect.Params.Dedicated.Gain; rlm@0: for(s = 0;s < MAXCHANNELS;s++) rlm@0: state->gains[s] = SpeakerGain[s] * Gain; rlm@0: } rlm@0: rlm@0: static ALvoid DedicatedLFEUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffectslot *Slot) rlm@0: { rlm@0: ALdedicatedState *state = (ALdedicatedState*)effect; rlm@0: ALfloat Gain; rlm@0: ALsizei s; rlm@0: (void)Context; rlm@0: rlm@0: Gain = Slot->Gain * Slot->effect.Params.Dedicated.Gain; rlm@0: for(s = 0;s < MAXCHANNELS;s++) rlm@0: state->gains[s] = 0.0f; rlm@0: state->gains[LFE] = Gain; rlm@0: } rlm@0: rlm@0: static ALvoid DedicatedProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[MAXCHANNELS]) rlm@0: { rlm@0: ALdedicatedState *state = (ALdedicatedState*)effect; rlm@0: const ALfloat *gains = state->gains; rlm@0: ALuint i, s; rlm@0: (void)Slot; rlm@0: rlm@0: for(i = 0;i < SamplesToDo;i++) rlm@0: { rlm@0: ALfloat sample; rlm@0: rlm@0: sample = SamplesIn[i]; rlm@0: for(s = 0;s < MAXCHANNELS;s++) rlm@0: SamplesOut[i][s] = sample * gains[s]; rlm@0: } rlm@0: } rlm@0: rlm@0: ALeffectState *DedicatedDLGCreate(void) rlm@0: { rlm@0: ALdedicatedState *state; rlm@0: ALsizei s; rlm@0: rlm@0: state = malloc(sizeof(*state)); rlm@0: if(!state) rlm@0: return NULL; rlm@0: rlm@0: state->state.Destroy = DedicatedDestroy; rlm@0: state->state.DeviceUpdate = DedicatedDeviceUpdate; rlm@0: state->state.Update = DedicatedDLGUpdate; rlm@0: state->state.Process = DedicatedProcess; rlm@0: rlm@0: for(s = 0;s < MAXCHANNELS;s++) rlm@0: state->gains[s] = 0.0f; rlm@0: rlm@0: return &state->state; rlm@0: } rlm@0: rlm@0: ALeffectState *DedicatedLFECreate(void) rlm@0: { rlm@0: ALdedicatedState *state; rlm@0: ALsizei s; rlm@0: rlm@0: state = malloc(sizeof(*state)); rlm@0: if(!state) rlm@0: return NULL; rlm@0: rlm@0: state->state.Destroy = DedicatedDestroy; rlm@0: state->state.DeviceUpdate = DedicatedDeviceUpdate; rlm@0: state->state.Update = DedicatedLFEUpdate; rlm@0: state->state.Process = DedicatedProcess; rlm@0: rlm@0: for(s = 0;s < MAXCHANNELS;s++) rlm@0: state->gains[s] = 0.0f; rlm@0: rlm@0: return &state->state; rlm@0: }