Use a helper to count the number of int(64) values for a property
[openal-soft.git] / Alc / alcDedicated.c
blob1d2cbc4200b4dd7d6539329f97a0c73e021e51fa
1 /**
2 * OpenAL cross platform audio library
3 * Copyright (C) 2011 by Chris Robinson.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
21 #include "config.h"
23 #include <stdlib.h>
25 #include "alMain.h"
26 #include "alFilter.h"
27 #include "alAuxEffectSlot.h"
28 #include "alError.h"
29 #include "alu.h"
32 typedef struct ALdedicatedState {
33 // Must be first in all effects!
34 ALeffectState state;
36 ALfloat gains[MaxChannels];
37 } ALdedicatedState;
40 static ALvoid DedicatedDestroy(ALeffectState *effect)
42 ALdedicatedState *state = (ALdedicatedState*)effect;
43 free(state);
46 static ALboolean DedicatedDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
48 (void)effect;
49 (void)Device;
50 return AL_TRUE;
53 static ALvoid DedicatedUpdate(ALeffectState *effect, ALCdevice *device, const ALeffectslot *Slot)
55 ALdedicatedState *state = (ALdedicatedState*)effect;
56 ALfloat Gain;
57 ALsizei s;
59 Gain = Slot->Gain * Slot->effect.Dedicated.Gain;
60 for(s = 0;s < MaxChannels;s++)
61 state->gains[s] = 0.0f;
63 if(Slot->effect.type == AL_EFFECT_DEDICATED_DIALOGUE)
64 ComputeAngleGains(device, atan2f(0.0f, 1.0f), 0.0f, Gain, state->gains);
65 else if(Slot->effect.type == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT)
66 state->gains[LFE] = Gain;
69 static ALvoid DedicatedProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *RESTRICT SamplesIn, ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE])
71 ALdedicatedState *state = (ALdedicatedState*)effect;
72 const ALfloat *gains = state->gains;
73 ALuint i, c;
75 for(c = 0;c < MaxChannels;c++)
77 for(i = 0;i < SamplesToDo;i++)
78 SamplesOut[c][i] = SamplesIn[i] * gains[c];
82 ALeffectState *DedicatedCreate(void)
84 ALdedicatedState *state;
85 ALsizei s;
87 state = malloc(sizeof(*state));
88 if(!state)
89 return NULL;
91 state->state.Destroy = DedicatedDestroy;
92 state->state.DeviceUpdate = DedicatedDeviceUpdate;
93 state->state.Update = DedicatedUpdate;
94 state->state.Process = DedicatedProcess;
96 for(s = 0;s < MaxChannels;s++)
97 state->gains[s] = 0.0f;
99 return &state->state;