Don't increment the context reference count when locked
[openal-soft/android.git] / Alc / alcDedicated.c
blob307d60efbaa6310f36ebaa0d28b6dffd53513475
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, ALCcontext *Context, const ALeffectslot *Slot)
55 ALdedicatedState *state = (ALdedicatedState*)effect;
56 ALCdevice *device = Context->Device;
57 const ALfloat *SpeakerGain;
58 ALfloat Gain;
59 ALint pos;
60 ALsizei s;
62 Gain = Slot->Gain * Slot->effect.Dedicated.Gain;
63 for(s = 0;s < MAXCHANNELS;s++)
64 state->gains[s] = 0.0f;
66 if(Slot->effect.type == AL_EFFECT_DEDICATED_DIALOGUE)
68 pos = aluCart2LUTpos(1.0f, 0.0f);
69 SpeakerGain = device->PanningLUT[pos];
71 for(s = 0;s < MAXCHANNELS;s++)
72 state->gains[s] = SpeakerGain[s] * Gain;
74 else if(Slot->effect.type == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT)
75 state->gains[LFE] = Gain;
78 static ALvoid DedicatedProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[MAXCHANNELS])
80 ALdedicatedState *state = (ALdedicatedState*)effect;
81 const ALfloat *gains = state->gains;
82 ALuint i, s;
83 (void)Slot;
85 for(i = 0;i < SamplesToDo;i++)
87 ALfloat sample;
89 sample = SamplesIn[i];
90 for(s = 0;s < MAXCHANNELS;s++)
91 SamplesOut[i][s] = sample * gains[s];
95 ALeffectState *DedicatedCreate(void)
97 ALdedicatedState *state;
98 ALsizei s;
100 state = malloc(sizeof(*state));
101 if(!state)
102 return NULL;
104 state->state.Destroy = DedicatedDestroy;
105 state->state.DeviceUpdate = DedicatedDeviceUpdate;
106 state->state.Update = DedicatedUpdate;
107 state->state.Process = DedicatedProcess;
109 for(s = 0;s < MAXCHANNELS;s++)
110 state->gains[s] = 0.0f;
112 return &state->state;