Mercurial > audio-send
comparison Alc/alcDedicated.c @ 0:f9476ff7637e
initial forking of open-al to create multiple listeners
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 25 Oct 2011 13:02:31 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f9476ff7637e |
---|---|
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. | |
8 * | |
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. | |
13 * | |
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 | |
19 */ | |
20 | |
21 #include "config.h" | |
22 | |
23 #include <stdlib.h> | |
24 | |
25 #include "alMain.h" | |
26 #include "alFilter.h" | |
27 #include "alAuxEffectSlot.h" | |
28 #include "alError.h" | |
29 #include "alu.h" | |
30 | |
31 | |
32 typedef struct ALdedicatedState { | |
33 // Must be first in all effects! | |
34 ALeffectState state; | |
35 | |
36 ALfloat gains[MAXCHANNELS]; | |
37 } ALdedicatedState; | |
38 | |
39 | |
40 static ALvoid DedicatedDestroy(ALeffectState *effect) | |
41 { | |
42 ALdedicatedState *state = (ALdedicatedState*)effect; | |
43 free(state); | |
44 } | |
45 | |
46 static ALboolean DedicatedDeviceUpdate(ALeffectState *effect, ALCdevice *Device) | |
47 { | |
48 (void)effect; | |
49 (void)Device; | |
50 return AL_TRUE; | |
51 } | |
52 | |
53 static ALvoid DedicatedDLGUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffectslot *Slot) | |
54 { | |
55 ALdedicatedState *state = (ALdedicatedState*)effect; | |
56 ALCdevice *device = Context->Device; | |
57 const ALfloat *SpeakerGain; | |
58 ALfloat Gain; | |
59 ALint pos; | |
60 ALsizei s; | |
61 | |
62 pos = aluCart2LUTpos(1.0f, 0.0f); | |
63 SpeakerGain = device->PanningLUT[pos]; | |
64 | |
65 Gain = Slot->Gain * Slot->effect.Params.Dedicated.Gain; | |
66 for(s = 0;s < MAXCHANNELS;s++) | |
67 state->gains[s] = SpeakerGain[s] * Gain; | |
68 } | |
69 | |
70 static ALvoid DedicatedLFEUpdate(ALeffectState *effect, ALCcontext *Context, const ALeffectslot *Slot) | |
71 { | |
72 ALdedicatedState *state = (ALdedicatedState*)effect; | |
73 ALfloat Gain; | |
74 ALsizei s; | |
75 (void)Context; | |
76 | |
77 Gain = Slot->Gain * Slot->effect.Params.Dedicated.Gain; | |
78 for(s = 0;s < MAXCHANNELS;s++) | |
79 state->gains[s] = 0.0f; | |
80 state->gains[LFE] = Gain; | |
81 } | |
82 | |
83 static ALvoid DedicatedProcess(ALeffectState *effect, const ALeffectslot *Slot, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[MAXCHANNELS]) | |
84 { | |
85 ALdedicatedState *state = (ALdedicatedState*)effect; | |
86 const ALfloat *gains = state->gains; | |
87 ALuint i, s; | |
88 (void)Slot; | |
89 | |
90 for(i = 0;i < SamplesToDo;i++) | |
91 { | |
92 ALfloat sample; | |
93 | |
94 sample = SamplesIn[i]; | |
95 for(s = 0;s < MAXCHANNELS;s++) | |
96 SamplesOut[i][s] = sample * gains[s]; | |
97 } | |
98 } | |
99 | |
100 ALeffectState *DedicatedDLGCreate(void) | |
101 { | |
102 ALdedicatedState *state; | |
103 ALsizei s; | |
104 | |
105 state = malloc(sizeof(*state)); | |
106 if(!state) | |
107 return NULL; | |
108 | |
109 state->state.Destroy = DedicatedDestroy; | |
110 state->state.DeviceUpdate = DedicatedDeviceUpdate; | |
111 state->state.Update = DedicatedDLGUpdate; | |
112 state->state.Process = DedicatedProcess; | |
113 | |
114 for(s = 0;s < MAXCHANNELS;s++) | |
115 state->gains[s] = 0.0f; | |
116 | |
117 return &state->state; | |
118 } | |
119 | |
120 ALeffectState *DedicatedLFECreate(void) | |
121 { | |
122 ALdedicatedState *state; | |
123 ALsizei s; | |
124 | |
125 state = malloc(sizeof(*state)); | |
126 if(!state) | |
127 return NULL; | |
128 | |
129 state->state.Destroy = DedicatedDestroy; | |
130 state->state.DeviceUpdate = DedicatedDeviceUpdate; | |
131 state->state.Update = DedicatedLFEUpdate; | |
132 state->state.Process = DedicatedProcess; | |
133 | |
134 for(s = 0;s < MAXCHANNELS;s++) | |
135 state->gains[s] = 0.0f; | |
136 | |
137 return &state->state; | |
138 } |