rlm@0
|
1 /**
|
rlm@0
|
2 * OpenAL cross platform audio library
|
rlm@0
|
3 * Copyright (C) 1999-2007 by authors.
|
rlm@0
|
4 * This library is free software; you can redistribute it and/or
|
rlm@0
|
5 * modify it under the terms of the GNU Library General Public
|
rlm@0
|
6 * License as published by the Free Software Foundation; either
|
rlm@0
|
7 * version 2 of the License, or (at your option) any later version.
|
rlm@0
|
8 *
|
rlm@0
|
9 * This library is distributed in the hope that it will be useful,
|
rlm@0
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
rlm@0
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
rlm@0
|
12 * Library General Public License for more details.
|
rlm@0
|
13 *
|
rlm@0
|
14 * You should have received a copy of the GNU Library General Public
|
rlm@0
|
15 * License along with this library; if not, write to the
|
rlm@0
|
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
rlm@0
|
17 * Boston, MA 02111-1307, USA.
|
rlm@0
|
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
|
rlm@0
|
19 */
|
rlm@0
|
20
|
rlm@0
|
21 #include "config.h"
|
rlm@0
|
22
|
rlm@0
|
23 #include <math.h>
|
rlm@0
|
24 #include <stdlib.h>
|
rlm@0
|
25 #include <stdio.h>
|
rlm@0
|
26 #include <memory.h>
|
rlm@0
|
27 #include <ctype.h>
|
rlm@0
|
28
|
rlm@0
|
29 #include "alMain.h"
|
rlm@0
|
30 #include "alSource.h"
|
rlm@0
|
31 #include "AL/al.h"
|
rlm@0
|
32 #include "AL/alc.h"
|
rlm@0
|
33 #include "alThunk.h"
|
rlm@0
|
34 #include "alSource.h"
|
rlm@0
|
35 #include "alBuffer.h"
|
rlm@0
|
36 #include "alAuxEffectSlot.h"
|
rlm@0
|
37 #include "bs2b.h"
|
rlm@0
|
38 #include "alu.h"
|
rlm@0
|
39
|
rlm@0
|
40 // RLM: try to include the file here.
|
rlm@0
|
41
|
rlm@0
|
42
|
rlm@0
|
43
|
rlm@0
|
44 #define EmptyFuncs { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
rlm@0
|
45 static struct BackendInfo BackendList[] = {
|
rlm@0
|
46 #ifdef HAVE_PULSEAUDIO
|
rlm@0
|
47 { "pulse", alc_pulse_init, alc_pulse_deinit, alc_pulse_probe, EmptyFuncs },
|
rlm@0
|
48 #endif
|
rlm@0
|
49 #ifdef HAVE_ALSA
|
rlm@0
|
50 { "alsa", alc_alsa_init, alc_alsa_deinit, alc_alsa_probe, EmptyFuncs },
|
rlm@0
|
51 #endif
|
rlm@0
|
52 #ifdef HAVE_COREAUDIO
|
rlm@0
|
53 { "core", alc_ca_init, alc_ca_deinit, alc_ca_probe, EmptyFuncs },
|
rlm@0
|
54 #endif
|
rlm@0
|
55 #ifdef HAVE_OSS
|
rlm@0
|
56 { "oss", alc_oss_init, alc_oss_deinit, alc_oss_probe, EmptyFuncs },
|
rlm@0
|
57 #endif
|
rlm@0
|
58 #ifdef HAVE_SOLARIS
|
rlm@0
|
59 { "solaris", alc_solaris_init, alc_solaris_deinit, alc_solaris_probe, EmptyFuncs },
|
rlm@0
|
60 #endif
|
rlm@0
|
61 #ifdef HAVE_SNDIO
|
rlm@0
|
62 { "sndio", alc_sndio_init, alc_sndio_deinit, alc_sndio_probe, EmptyFuncs },
|
rlm@0
|
63 #endif
|
rlm@0
|
64 #ifdef HAVE_MMDEVAPI
|
rlm@0
|
65 { "mmdevapi", alcMMDevApiInit, alcMMDevApiDeinit, alcMMDevApiProbe, EmptyFuncs },
|
rlm@0
|
66 #endif
|
rlm@0
|
67 #ifdef HAVE_DSOUND
|
rlm@0
|
68 { "dsound", alcDSoundInit, alcDSoundDeinit, alcDSoundProbe, EmptyFuncs },
|
rlm@0
|
69 #endif
|
rlm@0
|
70 #ifdef HAVE_WINMM
|
rlm@0
|
71 { "winmm", alcWinMMInit, alcWinMMDeinit, alcWinMMProbe, EmptyFuncs },
|
rlm@0
|
72 #endif
|
rlm@0
|
73 #ifdef HAVE_PORTAUDIO
|
rlm@0
|
74 { "port", alc_pa_init, alc_pa_deinit, alc_pa_probe, EmptyFuncs },
|
rlm@0
|
75 #endif
|
rlm@0
|
76 #ifdef HAVE_OPENSL
|
rlm@0
|
77 { "opensl", alc_opensl_init, alc_opensl_deinit, alc_opensl_probe, EmptyFuncs },
|
rlm@0
|
78 #endif
|
rlm@0
|
79
|
rlm@0
|
80 { "null", alc_null_init, alc_null_deinit, alc_null_probe, EmptyFuncs },
|
rlm@0
|
81 #ifdef HAVE_WAVE
|
rlm@0
|
82 { "wave", alc_wave_init, alc_wave_deinit, alc_wave_probe, EmptyFuncs },
|
rlm@0
|
83 #endif
|
rlm@0
|
84 { "send", alc_send_init, alc_send_deinit, alc_send_probe, EmptyFuncs },
|
rlm@0
|
85 // this entry is so that the list is terminated by a "null" object,
|
rlm@0
|
86 // and helps things to tell when they've reached the end of the list.
|
rlm@0
|
87 { NULL, NULL, NULL, NULL, EmptyFuncs }
|
rlm@0
|
88 };
|
rlm@0
|
89 static struct BackendInfo BackendLoopback = {
|
rlm@0
|
90 "loopback", alc_loopback_init, alc_loopback_deinit, alc_loopback_probe, EmptyFuncs
|
rlm@0
|
91 };
|
rlm@0
|
92 #undef EmptyFuncs
|
rlm@0
|
93
|
rlm@0
|
94 static struct BackendInfo PlaybackBackend;
|
rlm@0
|
95 static struct BackendInfo CaptureBackend;
|
rlm@0
|
96
|
rlm@0
|
97 ///////////////////////////////////////////////////////
|
rlm@0
|
98 // STRING and EXTENSIONS
|
rlm@0
|
99
|
rlm@0
|
100 typedef struct ALCfunction {
|
rlm@0
|
101 const ALCchar *funcName;
|
rlm@0
|
102 ALCvoid *address;
|
rlm@0
|
103 } ALCfunction;
|
rlm@0
|
104
|
rlm@0
|
105 typedef struct ALCenums {
|
rlm@0
|
106 const ALCchar *enumName;
|
rlm@0
|
107 ALCenum value;
|
rlm@0
|
108 } ALCenums;
|
rlm@0
|
109
|
rlm@0
|
110
|
rlm@0
|
111 static const ALCfunction alcFunctions[] = {
|
rlm@0
|
112 { "alcCreateContext", (ALCvoid *) alcCreateContext },
|
rlm@0
|
113 { "alcMakeContextCurrent", (ALCvoid *) alcMakeContextCurrent },
|
rlm@0
|
114 { "alcProcessContext", (ALCvoid *) alcProcessContext },
|
rlm@0
|
115 { "alcSuspendContext", (ALCvoid *) alcSuspendContext },
|
rlm@0
|
116 { "alcDestroyContext", (ALCvoid *) alcDestroyContext },
|
rlm@0
|
117 { "alcGetCurrentContext", (ALCvoid *) alcGetCurrentContext },
|
rlm@0
|
118 { "alcGetContextsDevice", (ALCvoid *) alcGetContextsDevice },
|
rlm@0
|
119 { "alcOpenDevice", (ALCvoid *) alcOpenDevice },
|
rlm@0
|
120 { "alcCloseDevice", (ALCvoid *) alcCloseDevice },
|
rlm@0
|
121 { "alcGetError", (ALCvoid *) alcGetError },
|
rlm@0
|
122 { "alcIsExtensionPresent", (ALCvoid *) alcIsExtensionPresent },
|
rlm@0
|
123 { "alcGetProcAddress", (ALCvoid *) alcGetProcAddress },
|
rlm@0
|
124 { "alcGetEnumValue", (ALCvoid *) alcGetEnumValue },
|
rlm@0
|
125 { "alcGetString", (ALCvoid *) alcGetString },
|
rlm@0
|
126 { "alcGetIntegerv", (ALCvoid *) alcGetIntegerv },
|
rlm@0
|
127 { "alcCaptureOpenDevice", (ALCvoid *) alcCaptureOpenDevice },
|
rlm@0
|
128 { "alcCaptureCloseDevice", (ALCvoid *) alcCaptureCloseDevice },
|
rlm@0
|
129 { "alcCaptureStart", (ALCvoid *) alcCaptureStart },
|
rlm@0
|
130 { "alcCaptureStop", (ALCvoid *) alcCaptureStop },
|
rlm@0
|
131 { "alcCaptureSamples", (ALCvoid *) alcCaptureSamples },
|
rlm@0
|
132
|
rlm@0
|
133 { "alcSetThreadContext", (ALCvoid *) alcSetThreadContext },
|
rlm@0
|
134 { "alcGetThreadContext", (ALCvoid *) alcGetThreadContext },
|
rlm@0
|
135
|
rlm@0
|
136 { "alcLoopbackOpenDeviceSOFT", (ALCvoid *) alcLoopbackOpenDeviceSOFT},
|
rlm@0
|
137 { "alcIsRenderFormatSupportedSOFT",(ALCvoid *) alcIsRenderFormatSupportedSOFT},
|
rlm@0
|
138 { "alcRenderSamplesSOFT", (ALCvoid *) alcRenderSamplesSOFT },
|
rlm@0
|
139
|
rlm@0
|
140 { "alEnable", (ALCvoid *) alEnable },
|
rlm@0
|
141 { "alDisable", (ALCvoid *) alDisable },
|
rlm@0
|
142 { "alIsEnabled", (ALCvoid *) alIsEnabled },
|
rlm@0
|
143 { "alGetString", (ALCvoid *) alGetString },
|
rlm@0
|
144 { "alGetBooleanv", (ALCvoid *) alGetBooleanv },
|
rlm@0
|
145 { "alGetIntegerv", (ALCvoid *) alGetIntegerv },
|
rlm@0
|
146 { "alGetFloatv", (ALCvoid *) alGetFloatv },
|
rlm@0
|
147 { "alGetDoublev", (ALCvoid *) alGetDoublev },
|
rlm@0
|
148 { "alGetBoolean", (ALCvoid *) alGetBoolean },
|
rlm@0
|
149 { "alGetInteger", (ALCvoid *) alGetInteger },
|
rlm@0
|
150 { "alGetFloat", (ALCvoid *) alGetFloat },
|
rlm@0
|
151 { "alGetDouble", (ALCvoid *) alGetDouble },
|
rlm@0
|
152 { "alGetError", (ALCvoid *) alGetError },
|
rlm@0
|
153 { "alIsExtensionPresent", (ALCvoid *) alIsExtensionPresent },
|
rlm@0
|
154 { "alGetProcAddress", (ALCvoid *) alGetProcAddress },
|
rlm@0
|
155 { "alGetEnumValue", (ALCvoid *) alGetEnumValue },
|
rlm@0
|
156 { "alListenerf", (ALCvoid *) alListenerf },
|
rlm@0
|
157 { "alListener3f", (ALCvoid *) alListener3f },
|
rlm@0
|
158 { "alListenerfv", (ALCvoid *) alListenerfv },
|
rlm@0
|
159 { "alListeneri", (ALCvoid *) alListeneri },
|
rlm@0
|
160 { "alListener3i", (ALCvoid *) alListener3i },
|
rlm@0
|
161 { "alListeneriv", (ALCvoid *) alListeneriv },
|
rlm@0
|
162 { "alGetListenerf", (ALCvoid *) alGetListenerf },
|
rlm@0
|
163 { "alGetListener3f", (ALCvoid *) alGetListener3f },
|
rlm@0
|
164 { "alGetListenerfv", (ALCvoid *) alGetListenerfv },
|
rlm@0
|
165 { "alGetListeneri", (ALCvoid *) alGetListeneri },
|
rlm@0
|
166 { "alGetListener3i", (ALCvoid *) alGetListener3i },
|
rlm@0
|
167 { "alGetListeneriv", (ALCvoid *) alGetListeneriv },
|
rlm@0
|
168 { "alGenSources", (ALCvoid *) alGenSources },
|
rlm@0
|
169 { "alDeleteSources", (ALCvoid *) alDeleteSources },
|
rlm@0
|
170 { "alIsSource", (ALCvoid *) alIsSource },
|
rlm@0
|
171 { "alSourcef", (ALCvoid *) alSourcef },
|
rlm@0
|
172 { "alSource3f", (ALCvoid *) alSource3f },
|
rlm@0
|
173 { "alSourcefv", (ALCvoid *) alSourcefv },
|
rlm@0
|
174 { "alSourcei", (ALCvoid *) alSourcei },
|
rlm@0
|
175 { "alSource3i", (ALCvoid *) alSource3i },
|
rlm@0
|
176 { "alSourceiv", (ALCvoid *) alSourceiv },
|
rlm@0
|
177 { "alGetSourcef", (ALCvoid *) alGetSourcef },
|
rlm@0
|
178 { "alGetSource3f", (ALCvoid *) alGetSource3f },
|
rlm@0
|
179 { "alGetSourcefv", (ALCvoid *) alGetSourcefv },
|
rlm@0
|
180 { "alGetSourcei", (ALCvoid *) alGetSourcei },
|
rlm@0
|
181 { "alGetSource3i", (ALCvoid *) alGetSource3i },
|
rlm@0
|
182 { "alGetSourceiv", (ALCvoid *) alGetSourceiv },
|
rlm@0
|
183 { "alSourcePlayv", (ALCvoid *) alSourcePlayv },
|
rlm@0
|
184 { "alSourceStopv", (ALCvoid *) alSourceStopv },
|
rlm@0
|
185 { "alSourceRewindv", (ALCvoid *) alSourceRewindv },
|
rlm@0
|
186 { "alSourcePausev", (ALCvoid *) alSourcePausev },
|
rlm@0
|
187 { "alSourcePlay", (ALCvoid *) alSourcePlay },
|
rlm@0
|
188 { "alSourceStop", (ALCvoid *) alSourceStop },
|
rlm@0
|
189 { "alSourceRewind", (ALCvoid *) alSourceRewind },
|
rlm@0
|
190 { "alSourcePause", (ALCvoid *) alSourcePause },
|
rlm@0
|
191 { "alSourceQueueBuffers", (ALCvoid *) alSourceQueueBuffers },
|
rlm@0
|
192 { "alSourceUnqueueBuffers", (ALCvoid *) alSourceUnqueueBuffers },
|
rlm@0
|
193 { "alGenBuffers", (ALCvoid *) alGenBuffers },
|
rlm@0
|
194 { "alDeleteBuffers", (ALCvoid *) alDeleteBuffers },
|
rlm@0
|
195 { "alIsBuffer", (ALCvoid *) alIsBuffer },
|
rlm@0
|
196 { "alBufferData", (ALCvoid *) alBufferData },
|
rlm@0
|
197 { "alBufferf", (ALCvoid *) alBufferf },
|
rlm@0
|
198 { "alBuffer3f", (ALCvoid *) alBuffer3f },
|
rlm@0
|
199 { "alBufferfv", (ALCvoid *) alBufferfv },
|
rlm@0
|
200 { "alBufferi", (ALCvoid *) alBufferi },
|
rlm@0
|
201 { "alBuffer3i", (ALCvoid *) alBuffer3i },
|
rlm@0
|
202 { "alBufferiv", (ALCvoid *) alBufferiv },
|
rlm@0
|
203 { "alGetBufferf", (ALCvoid *) alGetBufferf },
|
rlm@0
|
204 { "alGetBuffer3f", (ALCvoid *) alGetBuffer3f },
|
rlm@0
|
205 { "alGetBufferfv", (ALCvoid *) alGetBufferfv },
|
rlm@0
|
206 { "alGetBufferi", (ALCvoid *) alGetBufferi },
|
rlm@0
|
207 { "alGetBuffer3i", (ALCvoid *) alGetBuffer3i },
|
rlm@0
|
208 { "alGetBufferiv", (ALCvoid *) alGetBufferiv },
|
rlm@0
|
209 { "alDopplerFactor", (ALCvoid *) alDopplerFactor },
|
rlm@0
|
210 { "alDopplerVelocity", (ALCvoid *) alDopplerVelocity },
|
rlm@0
|
211 { "alSpeedOfSound", (ALCvoid *) alSpeedOfSound },
|
rlm@0
|
212 { "alDistanceModel", (ALCvoid *) alDistanceModel },
|
rlm@0
|
213
|
rlm@0
|
214 { "alGenFilters", (ALCvoid *) alGenFilters },
|
rlm@0
|
215 { "alDeleteFilters", (ALCvoid *) alDeleteFilters },
|
rlm@0
|
216 { "alIsFilter", (ALCvoid *) alIsFilter },
|
rlm@0
|
217 { "alFilteri", (ALCvoid *) alFilteri },
|
rlm@0
|
218 { "alFilteriv", (ALCvoid *) alFilteriv },
|
rlm@0
|
219 { "alFilterf", (ALCvoid *) alFilterf },
|
rlm@0
|
220 { "alFilterfv", (ALCvoid *) alFilterfv },
|
rlm@0
|
221 { "alGetFilteri", (ALCvoid *) alGetFilteri },
|
rlm@0
|
222 { "alGetFilteriv", (ALCvoid *) alGetFilteriv },
|
rlm@0
|
223 { "alGetFilterf", (ALCvoid *) alGetFilterf },
|
rlm@0
|
224 { "alGetFilterfv", (ALCvoid *) alGetFilterfv },
|
rlm@0
|
225 { "alGenEffects", (ALCvoid *) alGenEffects },
|
rlm@0
|
226 { "alDeleteEffects", (ALCvoid *) alDeleteEffects },
|
rlm@0
|
227 { "alIsEffect", (ALCvoid *) alIsEffect },
|
rlm@0
|
228 { "alEffecti", (ALCvoid *) alEffecti },
|
rlm@0
|
229 { "alEffectiv", (ALCvoid *) alEffectiv },
|
rlm@0
|
230 { "alEffectf", (ALCvoid *) alEffectf },
|
rlm@0
|
231 { "alEffectfv", (ALCvoid *) alEffectfv },
|
rlm@0
|
232 { "alGetEffecti", (ALCvoid *) alGetEffecti },
|
rlm@0
|
233 { "alGetEffectiv", (ALCvoid *) alGetEffectiv },
|
rlm@0
|
234 { "alGetEffectf", (ALCvoid *) alGetEffectf },
|
rlm@0
|
235 { "alGetEffectfv", (ALCvoid *) alGetEffectfv },
|
rlm@0
|
236 { "alGenAuxiliaryEffectSlots", (ALCvoid *) alGenAuxiliaryEffectSlots},
|
rlm@0
|
237 { "alDeleteAuxiliaryEffectSlots",(ALCvoid *) alDeleteAuxiliaryEffectSlots},
|
rlm@0
|
238 { "alIsAuxiliaryEffectSlot", (ALCvoid *) alIsAuxiliaryEffectSlot },
|
rlm@0
|
239 { "alAuxiliaryEffectSloti", (ALCvoid *) alAuxiliaryEffectSloti },
|
rlm@0
|
240 { "alAuxiliaryEffectSlotiv", (ALCvoid *) alAuxiliaryEffectSlotiv },
|
rlm@0
|
241 { "alAuxiliaryEffectSlotf", (ALCvoid *) alAuxiliaryEffectSlotf },
|
rlm@0
|
242 { "alAuxiliaryEffectSlotfv", (ALCvoid *) alAuxiliaryEffectSlotfv },
|
rlm@0
|
243 { "alGetAuxiliaryEffectSloti", (ALCvoid *) alGetAuxiliaryEffectSloti},
|
rlm@0
|
244 { "alGetAuxiliaryEffectSlotiv", (ALCvoid *) alGetAuxiliaryEffectSlotiv},
|
rlm@0
|
245 { "alGetAuxiliaryEffectSlotf", (ALCvoid *) alGetAuxiliaryEffectSlotf},
|
rlm@0
|
246 { "alGetAuxiliaryEffectSlotfv", (ALCvoid *) alGetAuxiliaryEffectSlotfv},
|
rlm@0
|
247
|
rlm@0
|
248 { "alBufferSubDataSOFT", (ALCvoid *) alBufferSubDataSOFT },
|
rlm@0
|
249
|
rlm@0
|
250 { "alBufferSamplesSOFT", (ALCvoid *) alBufferSamplesSOFT },
|
rlm@0
|
251 { "alBufferSubSamplesSOFT", (ALCvoid *) alBufferSubSamplesSOFT },
|
rlm@0
|
252 { "alGetBufferSamplesSOFT", (ALCvoid *) alGetBufferSamplesSOFT },
|
rlm@0
|
253 { "alIsBufferFormatSupportedSOFT",(ALCvoid *) alIsBufferFormatSupportedSOFT},
|
rlm@0
|
254
|
rlm@0
|
255 { "alDeferUpdatesSOFT", (ALCvoid *) alDeferUpdatesSOFT },
|
rlm@0
|
256 { "alProcessUpdatesSOFT", (ALCvoid *) alProcessUpdatesSOFT },
|
rlm@0
|
257
|
rlm@0
|
258 { NULL, (ALCvoid *) NULL }
|
rlm@0
|
259 };
|
rlm@0
|
260
|
rlm@0
|
261 static const ALCenums enumeration[] = {
|
rlm@0
|
262 // Types
|
rlm@0
|
263 { "ALC_INVALID", ALC_INVALID },
|
rlm@0
|
264 { "ALC_FALSE", ALC_FALSE },
|
rlm@0
|
265 { "ALC_TRUE", ALC_TRUE },
|
rlm@0
|
266
|
rlm@0
|
267 // ALC Properties
|
rlm@0
|
268 { "ALC_MAJOR_VERSION", ALC_MAJOR_VERSION },
|
rlm@0
|
269 { "ALC_MINOR_VERSION", ALC_MINOR_VERSION },
|
rlm@0
|
270 { "ALC_ATTRIBUTES_SIZE", ALC_ATTRIBUTES_SIZE },
|
rlm@0
|
271 { "ALC_ALL_ATTRIBUTES", ALC_ALL_ATTRIBUTES },
|
rlm@0
|
272 { "ALC_DEFAULT_DEVICE_SPECIFIER", ALC_DEFAULT_DEVICE_SPECIFIER },
|
rlm@0
|
273 { "ALC_DEVICE_SPECIFIER", ALC_DEVICE_SPECIFIER },
|
rlm@0
|
274 { "ALC_ALL_DEVICES_SPECIFIER", ALC_ALL_DEVICES_SPECIFIER },
|
rlm@0
|
275 { "ALC_DEFAULT_ALL_DEVICES_SPECIFIER", ALC_DEFAULT_ALL_DEVICES_SPECIFIER },
|
rlm@0
|
276 { "ALC_EXTENSIONS", ALC_EXTENSIONS },
|
rlm@0
|
277 { "ALC_FREQUENCY", ALC_FREQUENCY },
|
rlm@0
|
278 { "ALC_REFRESH", ALC_REFRESH },
|
rlm@0
|
279 { "ALC_SYNC", ALC_SYNC },
|
rlm@0
|
280 { "ALC_MONO_SOURCES", ALC_MONO_SOURCES },
|
rlm@0
|
281 { "ALC_STEREO_SOURCES", ALC_STEREO_SOURCES },
|
rlm@0
|
282 { "ALC_CAPTURE_DEVICE_SPECIFIER", ALC_CAPTURE_DEVICE_SPECIFIER },
|
rlm@0
|
283 { "ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER", ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER},
|
rlm@0
|
284 { "ALC_CAPTURE_SAMPLES", ALC_CAPTURE_SAMPLES },
|
rlm@0
|
285 { "ALC_CONNECTED", ALC_CONNECTED },
|
rlm@0
|
286
|
rlm@0
|
287 // EFX Properties
|
rlm@0
|
288 { "ALC_EFX_MAJOR_VERSION", ALC_EFX_MAJOR_VERSION },
|
rlm@0
|
289 { "ALC_EFX_MINOR_VERSION", ALC_EFX_MINOR_VERSION },
|
rlm@0
|
290 { "ALC_MAX_AUXILIARY_SENDS", ALC_MAX_AUXILIARY_SENDS },
|
rlm@0
|
291
|
rlm@0
|
292 // Loopback device Properties
|
rlm@0
|
293 { "ALC_FORMAT_CHANNELS_SOFT", ALC_FORMAT_CHANNELS_SOFT },
|
rlm@0
|
294 { "ALC_FORMAT_TYPE_SOFT", ALC_FORMAT_TYPE_SOFT },
|
rlm@0
|
295
|
rlm@0
|
296 // Buffer Channel Configurations
|
rlm@0
|
297 { "ALC_MONO", ALC_MONO },
|
rlm@0
|
298 { "ALC_STEREO", ALC_STEREO },
|
rlm@0
|
299 { "ALC_QUAD", ALC_QUAD },
|
rlm@0
|
300 { "ALC_5POINT1", ALC_5POINT1 },
|
rlm@0
|
301 { "ALC_6POINT1", ALC_6POINT1 },
|
rlm@0
|
302 { "ALC_7POINT1", ALC_7POINT1 },
|
rlm@0
|
303
|
rlm@0
|
304 // Buffer Sample Types
|
rlm@0
|
305 { "ALC_BYTE", ALC_BYTE },
|
rlm@0
|
306 { "ALC_UNSIGNED_BYTE", ALC_UNSIGNED_BYTE },
|
rlm@0
|
307 { "ALC_SHORT", ALC_SHORT },
|
rlm@0
|
308 { "ALC_UNSIGNED_SHORT", ALC_UNSIGNED_SHORT },
|
rlm@0
|
309 { "ALC_INT", ALC_INT },
|
rlm@0
|
310 { "ALC_UNSIGNED_INT", ALC_UNSIGNED_INT },
|
rlm@0
|
311 { "ALC_FLOAT", ALC_FLOAT },
|
rlm@0
|
312
|
rlm@0
|
313 // ALC Error Message
|
rlm@0
|
314 { "ALC_NO_ERROR", ALC_NO_ERROR },
|
rlm@0
|
315 { "ALC_INVALID_DEVICE", ALC_INVALID_DEVICE },
|
rlm@0
|
316 { "ALC_INVALID_CONTEXT", ALC_INVALID_CONTEXT },
|
rlm@0
|
317 { "ALC_INVALID_ENUM", ALC_INVALID_ENUM },
|
rlm@0
|
318 { "ALC_INVALID_VALUE", ALC_INVALID_VALUE },
|
rlm@0
|
319 { "ALC_OUT_OF_MEMORY", ALC_OUT_OF_MEMORY },
|
rlm@0
|
320
|
rlm@0
|
321 { NULL, (ALCenum)0 }
|
rlm@0
|
322 };
|
rlm@0
|
323 // Error strings
|
rlm@0
|
324 static const ALCchar alcNoError[] = "No Error";
|
rlm@0
|
325 static const ALCchar alcErrInvalidDevice[] = "Invalid Device";
|
rlm@0
|
326 static const ALCchar alcErrInvalidContext[] = "Invalid Context";
|
rlm@0
|
327 static const ALCchar alcErrInvalidEnum[] = "Invalid Enum";
|
rlm@0
|
328 static const ALCchar alcErrInvalidValue[] = "Invalid Value";
|
rlm@0
|
329 static const ALCchar alcErrOutOfMemory[] = "Out of Memory";
|
rlm@0
|
330
|
rlm@0
|
331 /* Device lists. Sizes only include the first ending null character, not the
|
rlm@0
|
332 * second */
|
rlm@0
|
333 static ALCchar *alcDeviceList;
|
rlm@0
|
334 static size_t alcDeviceListSize;
|
rlm@0
|
335 static ALCchar *alcAllDeviceList;
|
rlm@0
|
336 static size_t alcAllDeviceListSize;
|
rlm@0
|
337 static ALCchar *alcCaptureDeviceList;
|
rlm@0
|
338 static size_t alcCaptureDeviceListSize;
|
rlm@0
|
339 /* Default is always the first in the list */
|
rlm@0
|
340 static ALCchar *alcDefaultDeviceSpecifier;
|
rlm@0
|
341 static ALCchar *alcDefaultAllDeviceSpecifier;
|
rlm@0
|
342 static ALCchar *alcCaptureDefaultDeviceSpecifier;
|
rlm@0
|
343
|
rlm@0
|
344
|
rlm@0
|
345 static const ALCchar alcNoDeviceExtList[] =
|
rlm@0
|
346 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
|
rlm@0
|
347 "ALC_EXT_thread_local_context ALC_SOFTX_loopback_device";
|
rlm@0
|
348 static const ALCchar alcExtensionList[] =
|
rlm@0
|
349 "ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE "
|
rlm@0
|
350 "ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX "
|
rlm@0
|
351 "ALC_EXT_thread_local_context ALC_SOFTX_loopback_device";
|
rlm@0
|
352 static const ALCint alcMajorVersion = 1;
|
rlm@0
|
353 static const ALCint alcMinorVersion = 1;
|
rlm@0
|
354
|
rlm@0
|
355 static const ALCint alcEFXMajorVersion = 1;
|
rlm@0
|
356 static const ALCint alcEFXMinorVersion = 0;
|
rlm@0
|
357
|
rlm@0
|
358 ///////////////////////////////////////////////////////
|
rlm@0
|
359
|
rlm@0
|
360
|
rlm@0
|
361 ///////////////////////////////////////////////////////
|
rlm@0
|
362 // Global Variables
|
rlm@0
|
363
|
rlm@0
|
364 static CRITICAL_SECTION ListLock;
|
rlm@0
|
365
|
rlm@0
|
366 /* Device List */
|
rlm@0
|
367 static ALCdevice *g_pDeviceList = NULL;
|
rlm@0
|
368 static ALCuint g_ulDeviceCount = 0;
|
rlm@0
|
369
|
rlm@0
|
370 // Context List
|
rlm@0
|
371 static ALCcontext *g_pContextList = NULL;
|
rlm@0
|
372 static ALCuint g_ulContextCount = 0;
|
rlm@0
|
373
|
rlm@0
|
374 // Thread-local current context
|
rlm@0
|
375 static tls_type LocalContext;
|
rlm@0
|
376 // Process-wide current context
|
rlm@0
|
377 static ALCcontext *GlobalContext;
|
rlm@0
|
378
|
rlm@0
|
379 // Context Error
|
rlm@0
|
380 static ALCenum g_eLastNullDeviceError = ALC_NO_ERROR;
|
rlm@0
|
381
|
rlm@0
|
382 // Default context extensions
|
rlm@0
|
383 static const ALchar alExtList[] =
|
rlm@0
|
384 "AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 "
|
rlm@0
|
385 "AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW "
|
rlm@0
|
386 "AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model "
|
rlm@0
|
387 "AL_LOKI_quadriphonic AL_SOFTX_buffer_samples AL_SOFT_buffer_sub_data "
|
rlm@0
|
388 "AL_SOFTX_deferred_updates AL_SOFT_loop_points "
|
rlm@0
|
389 "AL_SOFTX_non_virtual_channels";
|
rlm@0
|
390
|
rlm@0
|
391 // Mixing Priority Level
|
rlm@0
|
392 ALint RTPrioLevel;
|
rlm@0
|
393
|
rlm@0
|
394 // Output Log File
|
rlm@0
|
395 FILE *LogFile;
|
rlm@0
|
396
|
rlm@0
|
397 // Output Log Level
|
rlm@0
|
398 #ifdef _DEBUG
|
rlm@0
|
399 enum LogLevel LogLevel = LogWarning;
|
rlm@0
|
400 #else
|
rlm@0
|
401 enum LogLevel LogLevel = LogError;
|
rlm@0
|
402 #endif
|
rlm@0
|
403
|
rlm@0
|
404 // Cone scalar
|
rlm@0
|
405 ALdouble ConeScale = 0.5;
|
rlm@0
|
406
|
rlm@0
|
407 // Localized Z scalar for mono sources
|
rlm@0
|
408 ALdouble ZScale = 1.0;
|
rlm@0
|
409
|
rlm@0
|
410 /* One-time configuration init control */
|
rlm@0
|
411 static pthread_once_t alc_config_once = PTHREAD_ONCE_INIT;
|
rlm@0
|
412
|
rlm@0
|
413 ///////////////////////////////////////////////////////
|
rlm@0
|
414
|
rlm@0
|
415
|
rlm@0
|
416 ///////////////////////////////////////////////////////
|
rlm@0
|
417 // ALC Related helper functions
|
rlm@0
|
418 static void ReleaseALC(ALCboolean doclose);
|
rlm@0
|
419
|
rlm@0
|
420 static void alc_initconfig(void);
|
rlm@0
|
421 #define DO_INITCONFIG() pthread_once(&alc_config_once, alc_initconfig)
|
rlm@0
|
422
|
rlm@0
|
423 #if defined(_WIN32)
|
rlm@0
|
424 static void alc_init(void);
|
rlm@0
|
425 static void alc_deinit(void);
|
rlm@0
|
426 static void alc_deinit_safe(void);
|
rlm@0
|
427
|
rlm@0
|
428 #ifndef AL_LIBTYPE_STATIC
|
rlm@0
|
429 BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
|
rlm@0
|
430 {
|
rlm@0
|
431 // Perform actions based on the reason for calling.
|
rlm@0
|
432 switch(ul_reason_for_call)
|
rlm@0
|
433 {
|
rlm@0
|
434 case DLL_PROCESS_ATTACH:
|
rlm@0
|
435 DisableThreadLibraryCalls(hModule);
|
rlm@0
|
436 alc_init();
|
rlm@0
|
437 break;
|
rlm@0
|
438
|
rlm@0
|
439 case DLL_PROCESS_DETACH:
|
rlm@0
|
440 if(!lpReserved)
|
rlm@0
|
441 alc_deinit();
|
rlm@0
|
442 else
|
rlm@0
|
443 alc_deinit_safe();
|
rlm@0
|
444 break;
|
rlm@0
|
445 }
|
rlm@0
|
446 return TRUE;
|
rlm@0
|
447 }
|
rlm@0
|
448 #elif defined(_MSC_VER)
|
rlm@0
|
449 #pragma section(".CRT$XCU",read)
|
rlm@0
|
450 static void alc_constructor(void);
|
rlm@0
|
451 static void alc_destructor(void);
|
rlm@0
|
452 __declspec(allocate(".CRT$XCU")) void (__cdecl* alc_constructor_)(void) = alc_constructor;
|
rlm@0
|
453
|
rlm@0
|
454 static void alc_constructor(void)
|
rlm@0
|
455 {
|
rlm@0
|
456 atexit(alc_destructor);
|
rlm@0
|
457 alc_init();
|
rlm@0
|
458 }
|
rlm@0
|
459
|
rlm@0
|
460 static void alc_destructor(void)
|
rlm@0
|
461 {
|
rlm@0
|
462 alc_deinit();
|
rlm@0
|
463 }
|
rlm@0
|
464 #elif defined(HAVE_GCC_DESTRUCTOR)
|
rlm@0
|
465 static void alc_init(void) __attribute__((constructor));
|
rlm@0
|
466 static void alc_deinit(void) __attribute__((destructor));
|
rlm@0
|
467 #else
|
rlm@0
|
468 #error "No static initialization available on this platform!"
|
rlm@0
|
469 #endif
|
rlm@0
|
470 #elif defined(HAVE_GCC_DESTRUCTOR)
|
rlm@0
|
471 static void alc_init(void) __attribute__((constructor));
|
rlm@0
|
472 static void alc_deinit(void) __attribute__((destructor));
|
rlm@0
|
473 #else
|
rlm@0
|
474 #error "No global initialization available on this platform!"
|
rlm@0
|
475 #endif
|
rlm@0
|
476
|
rlm@0
|
477 static void alc_init(void)
|
rlm@0
|
478 {
|
rlm@0
|
479 const char *str;
|
rlm@0
|
480
|
rlm@0
|
481 LogFile = stderr;
|
rlm@0
|
482
|
rlm@0
|
483 str = getenv("__ALSOFT_HALF_ANGLE_CONES");
|
rlm@0
|
484 if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
|
rlm@0
|
485 ConeScale = 1.0;
|
rlm@0
|
486
|
rlm@0
|
487 str = getenv("__ALSOFT_REVERSE_Z");
|
rlm@0
|
488 if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
|
rlm@0
|
489 ZScale = -1.0;
|
rlm@0
|
490
|
rlm@0
|
491 tls_create(&LocalContext);
|
rlm@0
|
492 InitializeCriticalSection(&ListLock);
|
rlm@0
|
493 ThunkInit();
|
rlm@0
|
494 }
|
rlm@0
|
495
|
rlm@0
|
496 static void alc_deinit_safe(void)
|
rlm@0
|
497 {
|
rlm@0
|
498 ReleaseALC(ALC_FALSE);
|
rlm@0
|
499
|
rlm@0
|
500 FreeALConfig();
|
rlm@0
|
501
|
rlm@0
|
502 ThunkExit();
|
rlm@0
|
503 DeleteCriticalSection(&ListLock);
|
rlm@0
|
504 tls_delete(LocalContext);
|
rlm@0
|
505
|
rlm@0
|
506 if(LogFile != stderr)
|
rlm@0
|
507 fclose(LogFile);
|
rlm@0
|
508 LogFile = NULL;
|
rlm@0
|
509 }
|
rlm@0
|
510
|
rlm@0
|
511 static void alc_deinit(void)
|
rlm@0
|
512 {
|
rlm@0
|
513 int i;
|
rlm@0
|
514
|
rlm@0
|
515 ReleaseALC(ALC_TRUE);
|
rlm@0
|
516
|
rlm@0
|
517 memset(&PlaybackBackend, 0, sizeof(PlaybackBackend));
|
rlm@0
|
518 memset(&CaptureBackend, 0, sizeof(CaptureBackend));
|
rlm@0
|
519
|
rlm@0
|
520 for(i = 0;BackendList[i].Deinit;i++)
|
rlm@0
|
521 BackendList[i].Deinit();
|
rlm@0
|
522 BackendLoopback.Deinit();
|
rlm@0
|
523
|
rlm@0
|
524 alc_deinit_safe();
|
rlm@0
|
525 }
|
rlm@0
|
526
|
rlm@0
|
527 static void alc_initconfig(void)
|
rlm@0
|
528 {
|
rlm@0
|
529 printf("OPENAL-AURELLEM: alc_init_config!!\n");
|
rlm@0
|
530 const char *devs, *str;
|
rlm@0
|
531 int i, n;
|
rlm@0
|
532
|
rlm@0
|
533 str = getenv("ALSOFT_LOGLEVEL");
|
rlm@0
|
534 if(str)
|
rlm@0
|
535 {
|
rlm@0
|
536 long lvl = strtol(str, NULL, 0);
|
rlm@0
|
537 if(lvl >= NoLog && lvl <= LogTrace)
|
rlm@0
|
538 LogLevel = lvl;
|
rlm@0
|
539 }
|
rlm@0
|
540
|
rlm@0
|
541 str = getenv("ALSOFT_LOGFILE");
|
rlm@0
|
542 if(str && str[0])
|
rlm@0
|
543 {
|
rlm@0
|
544 FILE *logfile = fopen(str, "wat");
|
rlm@0
|
545 if(logfile) LogFile = logfile;
|
rlm@0
|
546 else ERR("Failed to open log file '%s'\n", str);
|
rlm@0
|
547 }
|
rlm@0
|
548
|
rlm@0
|
549 ReadALConfig();
|
rlm@0
|
550
|
rlm@0
|
551 InitHrtf();
|
rlm@0
|
552
|
rlm@0
|
553 #ifdef _WIN32
|
rlm@0
|
554 RTPrioLevel = GetConfigValueInt(NULL, "rt-prio", 1);
|
rlm@0
|
555 #else
|
rlm@0
|
556 RTPrioLevel = GetConfigValueInt(NULL, "rt-prio", 0);
|
rlm@0
|
557 #endif
|
rlm@0
|
558
|
rlm@0
|
559 DefaultResampler = GetConfigValueInt(NULL, "resampler", RESAMPLER_DEFAULT);
|
rlm@0
|
560 if(DefaultResampler >= RESAMPLER_MAX || DefaultResampler <= RESAMPLER_MIN)
|
rlm@0
|
561 DefaultResampler = RESAMPLER_DEFAULT;
|
rlm@0
|
562
|
rlm@0
|
563 ReverbBoost *= aluPow(10.0f, GetConfigValueFloat("reverb", "boost", 0.0f) /
|
rlm@0
|
564 20.0f);
|
rlm@0
|
565 EmulateEAXReverb = GetConfigValueBool("reverb", "emulate-eax", AL_FALSE);
|
rlm@0
|
566
|
rlm@0
|
567 devs = GetConfigValue(NULL, "drivers", "");
|
rlm@0
|
568 //printf("these are the devices: %s\n", devs);
|
rlm@0
|
569
|
rlm@0
|
570 if(devs[0])
|
rlm@0
|
571 {
|
rlm@0
|
572 int n;
|
rlm@0
|
573 size_t len;
|
rlm@0
|
574 const char *next = devs;
|
rlm@0
|
575 int endlist, delitem;
|
rlm@0
|
576
|
rlm@0
|
577 i = 0;
|
rlm@0
|
578 do {
|
rlm@0
|
579 devs = next;
|
rlm@0
|
580 //printf("AURELLEM: devs is %s\n",devs);
|
rlm@0
|
581 next = strchr(devs, ',');
|
rlm@0
|
582
|
rlm@0
|
583 delitem = (devs[0] == '-');
|
rlm@0
|
584 if(devs[0] == '-') devs++;
|
rlm@0
|
585
|
rlm@0
|
586 if(!devs[0] || devs[0] == ',')
|
rlm@0
|
587 {
|
rlm@0
|
588 endlist = 0;
|
rlm@0
|
589 continue;
|
rlm@0
|
590 }
|
rlm@0
|
591 endlist = 1;
|
rlm@0
|
592
|
rlm@0
|
593 len = (next ? ((size_t)(next-devs)) : strlen(devs));
|
rlm@0
|
594 for(n = i;BackendList[n].Init;n++)
|
rlm@0
|
595 {
|
rlm@0
|
596 //printf("AURELLEM: device-name -- %s\n",BackendList[n].name);
|
rlm@0
|
597 if(len == strlen(BackendList[n].name) &&
|
rlm@0
|
598 strncmp(BackendList[n].name, devs, len) == 0)
|
rlm@0
|
599 {
|
rlm@0
|
600 if(delitem)
|
rlm@0
|
601 {
|
rlm@0
|
602 do {
|
rlm@0
|
603 BackendList[n] = BackendList[n+1];
|
rlm@0
|
604 ++n;
|
rlm@0
|
605 }
|
rlm@0
|
606 // this relies on the last entry being terminated by an
|
rlm@0
|
607 // entry with all nulls.
|
rlm@0
|
608 while(BackendList[n].Init);
|
rlm@0
|
609 }
|
rlm@0
|
610 else
|
rlm@0
|
611 {
|
rlm@0
|
612 struct BackendInfo Bkp = BackendList[n];
|
rlm@0
|
613 while(n > i)
|
rlm@0
|
614 {
|
rlm@0
|
615 BackendList[n] = BackendList[n-1];
|
rlm@0
|
616 --n;
|
rlm@0
|
617 }
|
rlm@0
|
618 BackendList[n] = Bkp;
|
rlm@0
|
619
|
rlm@0
|
620 i++;
|
rlm@0
|
621 }
|
rlm@0
|
622 break;
|
rlm@0
|
623 }
|
rlm@0
|
624 }
|
rlm@0
|
625 } while(next++);
|
rlm@0
|
626
|
rlm@0
|
627 if(endlist)
|
rlm@0
|
628 {
|
rlm@0
|
629 BackendList[i].name = NULL;
|
rlm@0
|
630 BackendList[i].Init = NULL;
|
rlm@0
|
631 BackendList[i].Deinit = NULL;
|
rlm@0
|
632 BackendList[i].Probe = NULL;
|
rlm@0
|
633 }
|
rlm@0
|
634 }
|
rlm@0
|
635
|
rlm@0
|
636 for(i = 0;BackendList[i].Init && (!PlaybackBackend.name || !CaptureBackend.name);i++)
|
rlm@0
|
637 {
|
rlm@0
|
638 if(!BackendList[i].Init(&BackendList[i].Funcs))
|
rlm@0
|
639 {
|
rlm@0
|
640 WARN("Failed to initialize backend \"%s\"\n", BackendList[i].name);
|
rlm@0
|
641 continue;
|
rlm@0
|
642 }
|
rlm@0
|
643
|
rlm@0
|
644 TRACE("Initialized backend \"%s\"\n", BackendList[i].name);
|
rlm@0
|
645 if(BackendList[i].Funcs.OpenPlayback && !PlaybackBackend.name)
|
rlm@0
|
646 {
|
rlm@0
|
647 PlaybackBackend = BackendList[i];
|
rlm@0
|
648 TRACE("Added \"%s\" for playback\n", PlaybackBackend.name);
|
rlm@0
|
649 }
|
rlm@0
|
650 if(BackendList[i].Funcs.OpenCapture && !CaptureBackend.name)
|
rlm@0
|
651 {
|
rlm@0
|
652 CaptureBackend = BackendList[i];
|
rlm@0
|
653 TRACE("Added \"%s\" for capture\n", CaptureBackend.name);
|
rlm@0
|
654 }
|
rlm@0
|
655 }
|
rlm@0
|
656 BackendLoopback.Init(&BackendLoopback.Funcs);
|
rlm@0
|
657
|
rlm@0
|
658 str = GetConfigValue(NULL, "excludefx", "");
|
rlm@0
|
659 if(str[0])
|
rlm@0
|
660 {
|
rlm@0
|
661 size_t len;
|
rlm@0
|
662 const char *next = str;
|
rlm@0
|
663
|
rlm@0
|
664 do {
|
rlm@0
|
665 str = next;
|
rlm@0
|
666 next = strchr(str, ',');
|
rlm@0
|
667
|
rlm@0
|
668 if(!str[0] || next == str)
|
rlm@0
|
669 continue;
|
rlm@0
|
670
|
rlm@0
|
671 len = (next ? ((size_t)(next-str)) : strlen(str));
|
rlm@0
|
672 for(n = 0;EffectList[n].name;n++)
|
rlm@0
|
673 {
|
rlm@0
|
674 if(len == strlen(EffectList[n].name) &&
|
rlm@0
|
675 strncmp(EffectList[n].name, str, len) == 0)
|
rlm@0
|
676 DisabledEffects[EffectList[n].type] = AL_TRUE;
|
rlm@0
|
677 }
|
rlm@0
|
678 } while(next++);
|
rlm@0
|
679 }
|
rlm@0
|
680 }
|
rlm@0
|
681
|
rlm@0
|
682
|
rlm@0
|
683 static void ProbeList(ALCchar **list, size_t *listsize, enum DevProbe type)
|
rlm@0
|
684 {
|
rlm@0
|
685 free(*list);
|
rlm@0
|
686 *list = NULL;
|
rlm@0
|
687 *listsize = 0;
|
rlm@0
|
688
|
rlm@0
|
689 DO_INITCONFIG();
|
rlm@0
|
690 if(type == CAPTURE_DEVICE_PROBE)
|
rlm@0
|
691 CaptureBackend.Probe(type);
|
rlm@0
|
692 else
|
rlm@0
|
693 PlaybackBackend.Probe(type);
|
rlm@0
|
694 }
|
rlm@0
|
695
|
rlm@0
|
696 static void ProbeDeviceList(void)
|
rlm@0
|
697 { ProbeList(&alcDeviceList, &alcDeviceListSize, DEVICE_PROBE); }
|
rlm@0
|
698 static void ProbeAllDeviceList(void)
|
rlm@0
|
699 { ProbeList(&alcAllDeviceList, &alcAllDeviceListSize, ALL_DEVICE_PROBE); }
|
rlm@0
|
700 static void ProbeCaptureDeviceList(void)
|
rlm@0
|
701 { ProbeList(&alcCaptureDeviceList, &alcCaptureDeviceListSize, CAPTURE_DEVICE_PROBE); }
|
rlm@0
|
702
|
rlm@0
|
703
|
rlm@0
|
704 static void AppendList(const ALCchar *name, ALCchar **List, size_t *ListSize)
|
rlm@0
|
705 {
|
rlm@0
|
706 size_t len = strlen(name);
|
rlm@0
|
707 void *temp;
|
rlm@0
|
708
|
rlm@0
|
709 if(len == 0)
|
rlm@0
|
710 return;
|
rlm@0
|
711
|
rlm@0
|
712 temp = realloc(*List, (*ListSize) + len + 2);
|
rlm@0
|
713 if(!temp)
|
rlm@0
|
714 {
|
rlm@0
|
715 ERR("Realloc failed to add %s!\n", name);
|
rlm@0
|
716 return;
|
rlm@0
|
717 }
|
rlm@0
|
718 *List = temp;
|
rlm@0
|
719
|
rlm@0
|
720 memcpy((*List)+(*ListSize), name, len+1);
|
rlm@0
|
721 *ListSize += len+1;
|
rlm@0
|
722 (*List)[*ListSize] = 0;
|
rlm@0
|
723 }
|
rlm@0
|
724
|
rlm@0
|
725 #define DECL_APPEND_LIST_FUNC(type) \
|
rlm@0
|
726 void Append##type##List(const ALCchar *name) \
|
rlm@0
|
727 { AppendList(name, &alc##type##List, &alc##type##ListSize); }
|
rlm@0
|
728
|
rlm@0
|
729 DECL_APPEND_LIST_FUNC(Device)
|
rlm@0
|
730 DECL_APPEND_LIST_FUNC(AllDevice)
|
rlm@0
|
731 DECL_APPEND_LIST_FUNC(CaptureDevice)
|
rlm@0
|
732
|
rlm@0
|
733 #undef DECL_APPEND_LIST_FUNC
|
rlm@0
|
734
|
rlm@0
|
735
|
rlm@0
|
736 /* Sets the default channel order used by most non-WaveFormatEx-based APIs */
|
rlm@0
|
737 void SetDefaultChannelOrder(ALCdevice *device)
|
rlm@0
|
738 {
|
rlm@0
|
739 switch(device->FmtChans)
|
rlm@0
|
740 {
|
rlm@0
|
741 case DevFmtX51: device->DevChannels[0] = FRONT_LEFT;
|
rlm@0
|
742 device->DevChannels[1] = FRONT_RIGHT;
|
rlm@0
|
743 device->DevChannels[2] = BACK_LEFT;
|
rlm@0
|
744 device->DevChannels[3] = BACK_RIGHT;
|
rlm@0
|
745 device->DevChannels[4] = FRONT_CENTER;
|
rlm@0
|
746 device->DevChannels[5] = LFE;
|
rlm@0
|
747 return;
|
rlm@0
|
748
|
rlm@0
|
749 case DevFmtX71: device->DevChannels[0] = FRONT_LEFT;
|
rlm@0
|
750 device->DevChannels[1] = FRONT_RIGHT;
|
rlm@0
|
751 device->DevChannels[2] = BACK_LEFT;
|
rlm@0
|
752 device->DevChannels[3] = BACK_RIGHT;
|
rlm@0
|
753 device->DevChannels[4] = FRONT_CENTER;
|
rlm@0
|
754 device->DevChannels[5] = LFE;
|
rlm@0
|
755 device->DevChannels[6] = SIDE_LEFT;
|
rlm@0
|
756 device->DevChannels[7] = SIDE_RIGHT;
|
rlm@0
|
757 return;
|
rlm@0
|
758
|
rlm@0
|
759 /* Same as WFX order */
|
rlm@0
|
760 case DevFmtMono:
|
rlm@0
|
761 case DevFmtStereo:
|
rlm@0
|
762 case DevFmtQuad:
|
rlm@0
|
763 case DevFmtX51Side:
|
rlm@0
|
764 case DevFmtX61:
|
rlm@0
|
765 break;
|
rlm@0
|
766 }
|
rlm@0
|
767 SetDefaultWFXChannelOrder(device);
|
rlm@0
|
768 }
|
rlm@0
|
769 /* Sets the default order used by WaveFormatEx */
|
rlm@0
|
770 void SetDefaultWFXChannelOrder(ALCdevice *device)
|
rlm@0
|
771 {
|
rlm@0
|
772 switch(device->FmtChans)
|
rlm@0
|
773 {
|
rlm@0
|
774 case DevFmtMono: device->DevChannels[0] = FRONT_CENTER; break;
|
rlm@0
|
775
|
rlm@0
|
776 case DevFmtStereo: device->DevChannels[0] = FRONT_LEFT;
|
rlm@0
|
777 device->DevChannels[1] = FRONT_RIGHT; break;
|
rlm@0
|
778
|
rlm@0
|
779 case DevFmtQuad: device->DevChannels[0] = FRONT_LEFT;
|
rlm@0
|
780 device->DevChannels[1] = FRONT_RIGHT;
|
rlm@0
|
781 device->DevChannels[2] = BACK_LEFT;
|
rlm@0
|
782 device->DevChannels[3] = BACK_RIGHT; break;
|
rlm@0
|
783
|
rlm@0
|
784 case DevFmtX51: device->DevChannels[0] = FRONT_LEFT;
|
rlm@0
|
785 device->DevChannels[1] = FRONT_RIGHT;
|
rlm@0
|
786 device->DevChannels[2] = FRONT_CENTER;
|
rlm@0
|
787 device->DevChannels[3] = LFE;
|
rlm@0
|
788 device->DevChannels[4] = BACK_LEFT;
|
rlm@0
|
789 device->DevChannels[5] = BACK_RIGHT; break;
|
rlm@0
|
790
|
rlm@0
|
791 case DevFmtX51Side: device->DevChannels[0] = FRONT_LEFT;
|
rlm@0
|
792 device->DevChannels[1] = FRONT_RIGHT;
|
rlm@0
|
793 device->DevChannels[2] = FRONT_CENTER;
|
rlm@0
|
794 device->DevChannels[3] = LFE;
|
rlm@0
|
795 device->DevChannels[4] = SIDE_LEFT;
|
rlm@0
|
796 device->DevChannels[5] = SIDE_RIGHT; break;
|
rlm@0
|
797
|
rlm@0
|
798 case DevFmtX61: device->DevChannels[0] = FRONT_LEFT;
|
rlm@0
|
799 device->DevChannels[1] = FRONT_RIGHT;
|
rlm@0
|
800 device->DevChannels[2] = FRONT_CENTER;
|
rlm@0
|
801 device->DevChannels[3] = LFE;
|
rlm@0
|
802 device->DevChannels[4] = BACK_CENTER;
|
rlm@0
|
803 device->DevChannels[5] = SIDE_LEFT;
|
rlm@0
|
804 device->DevChannels[6] = SIDE_RIGHT; break;
|
rlm@0
|
805
|
rlm@0
|
806 case DevFmtX71: device->DevChannels[0] = FRONT_LEFT;
|
rlm@0
|
807 device->DevChannels[1] = FRONT_RIGHT;
|
rlm@0
|
808 device->DevChannels[2] = FRONT_CENTER;
|
rlm@0
|
809 device->DevChannels[3] = LFE;
|
rlm@0
|
810 device->DevChannels[4] = BACK_LEFT;
|
rlm@0
|
811 device->DevChannels[5] = BACK_RIGHT;
|
rlm@0
|
812 device->DevChannels[6] = SIDE_LEFT;
|
rlm@0
|
813 device->DevChannels[7] = SIDE_RIGHT; break;
|
rlm@0
|
814 }
|
rlm@0
|
815 }
|
rlm@0
|
816
|
rlm@0
|
817
|
rlm@0
|
818 const ALCchar *DevFmtTypeString(enum DevFmtType type)
|
rlm@0
|
819 {
|
rlm@0
|
820 switch(type)
|
rlm@0
|
821 {
|
rlm@0
|
822 case DevFmtByte: return "Signed Byte";
|
rlm@0
|
823 case DevFmtUByte: return "Unsigned Byte";
|
rlm@0
|
824 case DevFmtShort: return "Signed Short";
|
rlm@0
|
825 case DevFmtUShort: return "Unsigned Short";
|
rlm@0
|
826 case DevFmtFloat: return "Float";
|
rlm@0
|
827 }
|
rlm@0
|
828 return "(unknown type)";
|
rlm@0
|
829 }
|
rlm@0
|
830 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans)
|
rlm@0
|
831 {
|
rlm@0
|
832 switch(chans)
|
rlm@0
|
833 {
|
rlm@0
|
834 case DevFmtMono: return "Mono";
|
rlm@0
|
835 case DevFmtStereo: return "Stereo";
|
rlm@0
|
836 case DevFmtQuad: return "Quadraphonic";
|
rlm@0
|
837 case DevFmtX51: return "5.1 Surround";
|
rlm@0
|
838 case DevFmtX51Side: return "5.1 Side";
|
rlm@0
|
839 case DevFmtX61: return "6.1 Surround";
|
rlm@0
|
840 case DevFmtX71: return "7.1 Surround";
|
rlm@0
|
841 }
|
rlm@0
|
842 return "(unknown channels)";
|
rlm@0
|
843 }
|
rlm@0
|
844
|
rlm@0
|
845 ALuint BytesFromDevFmt(enum DevFmtType type)
|
rlm@0
|
846 {
|
rlm@0
|
847 switch(type)
|
rlm@0
|
848 {
|
rlm@0
|
849 case DevFmtByte: return sizeof(ALbyte);
|
rlm@0
|
850 case DevFmtUByte: return sizeof(ALubyte);
|
rlm@0
|
851 case DevFmtShort: return sizeof(ALshort);
|
rlm@0
|
852 case DevFmtUShort: return sizeof(ALushort);
|
rlm@0
|
853 case DevFmtFloat: return sizeof(ALfloat);
|
rlm@0
|
854 }
|
rlm@0
|
855 return 0;
|
rlm@0
|
856 }
|
rlm@0
|
857 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans)
|
rlm@0
|
858 {
|
rlm@0
|
859 switch(chans)
|
rlm@0
|
860 {
|
rlm@0
|
861 case DevFmtMono: return 1;
|
rlm@0
|
862 case DevFmtStereo: return 2;
|
rlm@0
|
863 case DevFmtQuad: return 4;
|
rlm@0
|
864 case DevFmtX51: return 6;
|
rlm@0
|
865 case DevFmtX51Side: return 6;
|
rlm@0
|
866 case DevFmtX61: return 7;
|
rlm@0
|
867 case DevFmtX71: return 8;
|
rlm@0
|
868 }
|
rlm@0
|
869 return 0;
|
rlm@0
|
870 }
|
rlm@0
|
871 ALboolean DecomposeDevFormat(ALenum format, enum DevFmtChannels *chans,
|
rlm@0
|
872 enum DevFmtType *type)
|
rlm@0
|
873 {
|
rlm@0
|
874 switch(format)
|
rlm@0
|
875 {
|
rlm@0
|
876 case AL_FORMAT_MONO8:
|
rlm@0
|
877 *chans = DevFmtMono;
|
rlm@0
|
878 *type = DevFmtUByte;
|
rlm@0
|
879 return AL_TRUE;
|
rlm@0
|
880 case AL_FORMAT_MONO16:
|
rlm@0
|
881 *chans = DevFmtMono;
|
rlm@0
|
882 *type = DevFmtShort;
|
rlm@0
|
883 return AL_TRUE;
|
rlm@0
|
884 case AL_FORMAT_MONO_FLOAT32:
|
rlm@0
|
885 *chans = DevFmtMono;
|
rlm@0
|
886 *type = DevFmtFloat;
|
rlm@0
|
887 return AL_TRUE;
|
rlm@0
|
888 case AL_FORMAT_STEREO8:
|
rlm@0
|
889 *chans = DevFmtStereo;
|
rlm@0
|
890 *type = DevFmtUByte;
|
rlm@0
|
891 return AL_TRUE;
|
rlm@0
|
892 case AL_FORMAT_STEREO16:
|
rlm@0
|
893 *chans = DevFmtStereo;
|
rlm@0
|
894 *type = DevFmtShort;
|
rlm@0
|
895 return AL_TRUE;
|
rlm@0
|
896 case AL_FORMAT_STEREO_FLOAT32:
|
rlm@0
|
897 *chans = DevFmtStereo;
|
rlm@0
|
898 *type = DevFmtFloat;
|
rlm@0
|
899 return AL_TRUE;
|
rlm@0
|
900 case AL_FORMAT_QUAD8:
|
rlm@0
|
901 *chans = DevFmtQuad;
|
rlm@0
|
902 *type = DevFmtUByte;
|
rlm@0
|
903 return AL_TRUE;
|
rlm@0
|
904 case AL_FORMAT_QUAD16:
|
rlm@0
|
905 *chans = DevFmtQuad;
|
rlm@0
|
906 *type = DevFmtShort;
|
rlm@0
|
907 return AL_TRUE;
|
rlm@0
|
908 case AL_FORMAT_QUAD32:
|
rlm@0
|
909 *chans = DevFmtQuad;
|
rlm@0
|
910 *type = DevFmtFloat;
|
rlm@0
|
911 return AL_TRUE;
|
rlm@0
|
912 case AL_FORMAT_51CHN8:
|
rlm@0
|
913 *chans = DevFmtX51;
|
rlm@0
|
914 *type = DevFmtUByte;
|
rlm@0
|
915 return AL_TRUE;
|
rlm@0
|
916 case AL_FORMAT_51CHN16:
|
rlm@0
|
917 *chans = DevFmtX51;
|
rlm@0
|
918 *type = DevFmtShort;
|
rlm@0
|
919 return AL_TRUE;
|
rlm@0
|
920 case AL_FORMAT_51CHN32:
|
rlm@0
|
921 *chans = DevFmtX51;
|
rlm@0
|
922 *type = DevFmtFloat;
|
rlm@0
|
923 return AL_TRUE;
|
rlm@0
|
924 case AL_FORMAT_61CHN8:
|
rlm@0
|
925 *chans = DevFmtX61;
|
rlm@0
|
926 *type = DevFmtUByte;
|
rlm@0
|
927 return AL_TRUE;
|
rlm@0
|
928 case AL_FORMAT_61CHN16:
|
rlm@0
|
929 *chans = DevFmtX61;
|
rlm@0
|
930 *type = DevFmtShort;
|
rlm@0
|
931 return AL_TRUE;
|
rlm@0
|
932 case AL_FORMAT_61CHN32:
|
rlm@0
|
933 *chans = DevFmtX61;
|
rlm@0
|
934 *type = DevFmtFloat;
|
rlm@0
|
935 return AL_TRUE;
|
rlm@0
|
936 case AL_FORMAT_71CHN8:
|
rlm@0
|
937 *chans = DevFmtX71;
|
rlm@0
|
938 *type = DevFmtUByte;
|
rlm@0
|
939 return AL_TRUE;
|
rlm@0
|
940 case AL_FORMAT_71CHN16:
|
rlm@0
|
941 *chans = DevFmtX71;
|
rlm@0
|
942 *type = DevFmtShort;
|
rlm@0
|
943 return AL_TRUE;
|
rlm@0
|
944 case AL_FORMAT_71CHN32:
|
rlm@0
|
945 *chans = DevFmtX71;
|
rlm@0
|
946 *type = DevFmtFloat;
|
rlm@0
|
947 return AL_TRUE;
|
rlm@0
|
948 }
|
rlm@0
|
949 return AL_FALSE;
|
rlm@0
|
950 }
|
rlm@0
|
951
|
rlm@0
|
952 static ALCboolean IsValidALCType(ALCenum type)
|
rlm@0
|
953 {
|
rlm@0
|
954 switch(type)
|
rlm@0
|
955 {
|
rlm@0
|
956 case ALC_BYTE:
|
rlm@0
|
957 case ALC_UNSIGNED_BYTE:
|
rlm@0
|
958 case ALC_SHORT:
|
rlm@0
|
959 case ALC_UNSIGNED_SHORT:
|
rlm@0
|
960 case ALC_INT:
|
rlm@0
|
961 case ALC_UNSIGNED_INT:
|
rlm@0
|
962 case ALC_FLOAT:
|
rlm@0
|
963 return ALC_TRUE;
|
rlm@0
|
964 }
|
rlm@0
|
965 return ALC_FALSE;
|
rlm@0
|
966 }
|
rlm@0
|
967
|
rlm@0
|
968 static ALCboolean IsValidALCChannels(ALCenum channels)
|
rlm@0
|
969 {
|
rlm@0
|
970 switch(channels)
|
rlm@0
|
971 {
|
rlm@0
|
972 case ALC_MONO:
|
rlm@0
|
973 case ALC_STEREO:
|
rlm@0
|
974 case ALC_QUAD:
|
rlm@0
|
975 case ALC_5POINT1:
|
rlm@0
|
976 case ALC_6POINT1:
|
rlm@0
|
977 case ALC_7POINT1:
|
rlm@0
|
978 return ALC_TRUE;
|
rlm@0
|
979 }
|
rlm@0
|
980 return ALC_FALSE;
|
rlm@0
|
981 }
|
rlm@0
|
982
|
rlm@0
|
983
|
rlm@0
|
984 static void LockLists(void)
|
rlm@0
|
985 {
|
rlm@0
|
986 EnterCriticalSection(&ListLock);
|
rlm@0
|
987 }
|
rlm@0
|
988
|
rlm@0
|
989 static void UnlockLists(void)
|
rlm@0
|
990 {
|
rlm@0
|
991 LeaveCriticalSection(&ListLock);
|
rlm@0
|
992 }
|
rlm@0
|
993
|
rlm@0
|
994 /*
|
rlm@0
|
995 IsDevice
|
rlm@0
|
996
|
rlm@0
|
997 Check pDevice is a valid Device pointer
|
rlm@0
|
998 */
|
rlm@0
|
999 static ALCboolean IsDevice(ALCdevice *pDevice)
|
rlm@0
|
1000 {
|
rlm@0
|
1001 ALCdevice *pTempDevice;
|
rlm@0
|
1002
|
rlm@0
|
1003 pTempDevice = g_pDeviceList;
|
rlm@0
|
1004 while(pTempDevice && pTempDevice != pDevice)
|
rlm@0
|
1005 pTempDevice = pTempDevice->next;
|
rlm@0
|
1006
|
rlm@0
|
1007 return (pTempDevice ? ALC_TRUE : ALC_FALSE);
|
rlm@0
|
1008 }
|
rlm@0
|
1009
|
rlm@0
|
1010 /*
|
rlm@0
|
1011 IsContext
|
rlm@0
|
1012
|
rlm@0
|
1013 Check pContext is a valid Context pointer
|
rlm@0
|
1014 */
|
rlm@0
|
1015 static ALCboolean IsContext(ALCcontext *pContext)
|
rlm@0
|
1016 {
|
rlm@0
|
1017 ALCcontext *pTempContext;
|
rlm@0
|
1018
|
rlm@0
|
1019 pTempContext = g_pContextList;
|
rlm@0
|
1020 while (pTempContext && pTempContext != pContext)
|
rlm@0
|
1021 pTempContext = pTempContext->next;
|
rlm@0
|
1022
|
rlm@0
|
1023 return (pTempContext ? ALC_TRUE : ALC_FALSE);
|
rlm@0
|
1024 }
|
rlm@0
|
1025
|
rlm@0
|
1026
|
rlm@0
|
1027 /*
|
rlm@0
|
1028 alcSetError
|
rlm@0
|
1029
|
rlm@0
|
1030 Store latest ALC Error
|
rlm@0
|
1031 */
|
rlm@0
|
1032 ALCvoid alcSetError(ALCdevice *device, ALenum errorCode)
|
rlm@0
|
1033 {
|
rlm@0
|
1034 LockLists();
|
rlm@0
|
1035 if(IsDevice(device))
|
rlm@0
|
1036 device->LastError = errorCode;
|
rlm@0
|
1037 else
|
rlm@0
|
1038 g_eLastNullDeviceError = errorCode;
|
rlm@0
|
1039 UnlockLists();
|
rlm@0
|
1040 }
|
rlm@0
|
1041
|
rlm@0
|
1042
|
rlm@0
|
1043 /* UpdateDeviceParams:
|
rlm@0
|
1044 *
|
rlm@0
|
1045 * Updates device parameters according to the attribute list.
|
rlm@0
|
1046 */
|
rlm@0
|
1047 static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
rlm@0
|
1048 {
|
rlm@0
|
1049 ALuint i;
|
rlm@0
|
1050
|
rlm@0
|
1051 // Check for attributes
|
rlm@0
|
1052 if(attrList && attrList[0])
|
rlm@0
|
1053 {
|
rlm@0
|
1054 ALCuint freq, numMono, numStereo, numSends;
|
rlm@0
|
1055 enum DevFmtChannels schans;
|
rlm@0
|
1056 enum DevFmtType stype;
|
rlm@0
|
1057 ALuint attrIdx;
|
rlm@0
|
1058
|
rlm@0
|
1059 // If a context is already running on the device, stop playback so the
|
rlm@0
|
1060 // device attributes can be updated
|
rlm@0
|
1061 if((device->Flags&DEVICE_RUNNING))
|
rlm@0
|
1062 ALCdevice_StopPlayback(device);
|
rlm@0
|
1063 device->Flags &= ~DEVICE_RUNNING;
|
rlm@0
|
1064
|
rlm@0
|
1065 freq = device->Frequency;
|
rlm@0
|
1066 schans = device->FmtChans;
|
rlm@0
|
1067 stype = device->FmtType;
|
rlm@0
|
1068 numMono = device->NumMonoSources;
|
rlm@0
|
1069 numStereo = device->NumStereoSources;
|
rlm@0
|
1070 numSends = device->NumAuxSends;
|
rlm@0
|
1071
|
rlm@0
|
1072 freq = GetConfigValueInt(NULL, "frequency", freq);
|
rlm@0
|
1073 if(freq < 8000) freq = 8000;
|
rlm@0
|
1074
|
rlm@0
|
1075 attrIdx = 0;
|
rlm@0
|
1076 while(attrList[attrIdx])
|
rlm@0
|
1077 {
|
rlm@0
|
1078 if(attrList[attrIdx] == ALC_FORMAT_CHANNELS_SOFT &&
|
rlm@0
|
1079 device->IsLoopbackDevice)
|
rlm@0
|
1080 {
|
rlm@0
|
1081 ALCint val = attrList[attrIdx + 1];
|
rlm@0
|
1082 if(!IsValidALCChannels(val) || !ChannelsFromDevFmt(val))
|
rlm@0
|
1083 {
|
rlm@0
|
1084 alcSetError(device, ALC_INVALID_VALUE);
|
rlm@0
|
1085 return ALC_FALSE;
|
rlm@0
|
1086 }
|
rlm@0
|
1087 schans = val;
|
rlm@0
|
1088 }
|
rlm@0
|
1089
|
rlm@0
|
1090 if(attrList[attrIdx] == ALC_FORMAT_TYPE_SOFT &&
|
rlm@0
|
1091 device->IsLoopbackDevice)
|
rlm@0
|
1092 {
|
rlm@0
|
1093 ALCint val = attrList[attrIdx + 1];
|
rlm@0
|
1094 if(!IsValidALCType(val) || !BytesFromDevFmt(val))
|
rlm@0
|
1095 {
|
rlm@0
|
1096 alcSetError(device, ALC_INVALID_VALUE);
|
rlm@0
|
1097 return ALC_FALSE;
|
rlm@0
|
1098 }
|
rlm@0
|
1099 stype = val;
|
rlm@0
|
1100 }
|
rlm@0
|
1101
|
rlm@0
|
1102 if(attrList[attrIdx] == ALC_FREQUENCY)
|
rlm@0
|
1103 {
|
rlm@0
|
1104 if(device->IsLoopbackDevice)
|
rlm@0
|
1105 {
|
rlm@0
|
1106 freq = attrList[attrIdx + 1];
|
rlm@0
|
1107 if(freq < 8000)
|
rlm@0
|
1108 {
|
rlm@0
|
1109 alcSetError(device, ALC_INVALID_VALUE);
|
rlm@0
|
1110 return ALC_FALSE;
|
rlm@0
|
1111 }
|
rlm@0
|
1112 }
|
rlm@0
|
1113 else if(!ConfigValueExists(NULL, "frequency"))
|
rlm@0
|
1114 {
|
rlm@0
|
1115 freq = attrList[attrIdx + 1];
|
rlm@0
|
1116 if(freq < 8000) freq = 8000;
|
rlm@0
|
1117 device->Flags |= DEVICE_FREQUENCY_REQUEST;
|
rlm@0
|
1118 }
|
rlm@0
|
1119 }
|
rlm@0
|
1120
|
rlm@0
|
1121 if(attrList[attrIdx] == ALC_STEREO_SOURCES)
|
rlm@0
|
1122 {
|
rlm@0
|
1123 numStereo = attrList[attrIdx + 1];
|
rlm@0
|
1124 if(numStereo > device->MaxNoOfSources)
|
rlm@0
|
1125 numStereo = device->MaxNoOfSources;
|
rlm@0
|
1126
|
rlm@0
|
1127 numMono = device->MaxNoOfSources - numStereo;
|
rlm@0
|
1128 }
|
rlm@0
|
1129
|
rlm@0
|
1130 if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS &&
|
rlm@0
|
1131 !ConfigValueExists(NULL, "sends"))
|
rlm@0
|
1132 {
|
rlm@0
|
1133 numSends = attrList[attrIdx + 1];
|
rlm@0
|
1134 if(numSends > MAX_SENDS)
|
rlm@0
|
1135 numSends = MAX_SENDS;
|
rlm@0
|
1136 }
|
rlm@0
|
1137
|
rlm@0
|
1138 attrIdx += 2;
|
rlm@0
|
1139 }
|
rlm@0
|
1140
|
rlm@0
|
1141 device->UpdateSize = (ALuint64)device->UpdateSize * freq /
|
rlm@0
|
1142 device->Frequency;
|
rlm@0
|
1143
|
rlm@0
|
1144 device->Frequency = freq;
|
rlm@0
|
1145 device->FmtChans = schans;
|
rlm@0
|
1146 device->FmtType = stype;
|
rlm@0
|
1147 device->NumMonoSources = numMono;
|
rlm@0
|
1148 device->NumStereoSources = numStereo;
|
rlm@0
|
1149 device->NumAuxSends = numSends;
|
rlm@0
|
1150 }
|
rlm@0
|
1151
|
rlm@0
|
1152 if((device->Flags&DEVICE_RUNNING))
|
rlm@0
|
1153 return ALC_TRUE;
|
rlm@0
|
1154
|
rlm@0
|
1155 LockDevice(device);
|
rlm@0
|
1156 TRACE("Format pre-setup: %s%s, %s, %uhz%s, %u update size x%d\n",
|
rlm@0
|
1157 DevFmtChannelsString(device->FmtChans),
|
rlm@0
|
1158 (device->Flags&DEVICE_CHANNELS_REQUEST)?" (requested)":"",
|
rlm@0
|
1159 DevFmtTypeString(device->FmtType), device->Frequency,
|
rlm@0
|
1160 (device->Flags&DEVICE_FREQUENCY_REQUEST)?" (requested)":"",
|
rlm@0
|
1161 device->UpdateSize, device->NumUpdates);
|
rlm@0
|
1162 if(ALCdevice_ResetPlayback(device) == ALC_FALSE)
|
rlm@0
|
1163 {
|
rlm@0
|
1164 UnlockDevice(device);
|
rlm@0
|
1165 return ALC_FALSE;
|
rlm@0
|
1166 }
|
rlm@0
|
1167 device->Flags |= DEVICE_RUNNING;
|
rlm@0
|
1168 TRACE("Format post-setup: %s%s, %s, %uhz%s, %u update size x%d\n",
|
rlm@0
|
1169 DevFmtChannelsString(device->FmtChans),
|
rlm@0
|
1170 (device->Flags&DEVICE_CHANNELS_REQUEST)?" (requested)":"",
|
rlm@0
|
1171 DevFmtTypeString(device->FmtType), device->Frequency,
|
rlm@0
|
1172 (device->Flags&DEVICE_FREQUENCY_REQUEST)?" (requested)":"",
|
rlm@0
|
1173 device->UpdateSize, device->NumUpdates);
|
rlm@0
|
1174
|
rlm@0
|
1175 aluInitPanning(device);
|
rlm@0
|
1176
|
rlm@0
|
1177 for(i = 0;i < MAXCHANNELS;i++)
|
rlm@0
|
1178 {
|
rlm@0
|
1179 device->ClickRemoval[i] = 0.0f;
|
rlm@0
|
1180 device->PendingClicks[i] = 0.0f;
|
rlm@0
|
1181 }
|
rlm@0
|
1182
|
rlm@0
|
1183 if(!device->IsLoopbackDevice && GetConfigValueBool(NULL, "hrtf", AL_FALSE))
|
rlm@0
|
1184 device->Flags |= DEVICE_USE_HRTF;
|
rlm@0
|
1185 if((device->Flags&DEVICE_USE_HRTF) && !IsHrtfCompatible(device))
|
rlm@0
|
1186 device->Flags &= ~DEVICE_USE_HRTF;
|
rlm@0
|
1187 TRACE("HRTF %s\n", (device->Flags&DEVICE_USE_HRTF)?"enabled":"disabled");
|
rlm@0
|
1188
|
rlm@0
|
1189 if(!(device->Flags&DEVICE_USE_HRTF) && device->Bs2bLevel > 0 && device->Bs2bLevel <= 6)
|
rlm@0
|
1190 {
|
rlm@0
|
1191 if(!device->Bs2b)
|
rlm@0
|
1192 {
|
rlm@0
|
1193 device->Bs2b = calloc(1, sizeof(*device->Bs2b));
|
rlm@0
|
1194 bs2b_clear(device->Bs2b);
|
rlm@0
|
1195 }
|
rlm@0
|
1196 bs2b_set_srate(device->Bs2b, device->Frequency);
|
rlm@0
|
1197 bs2b_set_level(device->Bs2b, device->Bs2bLevel);
|
rlm@0
|
1198 TRACE("BS2B level %d\n", device->Bs2bLevel);
|
rlm@0
|
1199 }
|
rlm@0
|
1200 else
|
rlm@0
|
1201 {
|
rlm@0
|
1202 free(device->Bs2b);
|
rlm@0
|
1203 device->Bs2b = NULL;
|
rlm@0
|
1204 TRACE("BS2B disabled\n");
|
rlm@0
|
1205 }
|
rlm@0
|
1206
|
rlm@0
|
1207 device->Flags &= ~DEVICE_DUPLICATE_STEREO;
|
rlm@0
|
1208 switch(device->FmtChans)
|
rlm@0
|
1209 {
|
rlm@0
|
1210 case DevFmtMono:
|
rlm@0
|
1211 case DevFmtStereo:
|
rlm@0
|
1212 break;
|
rlm@0
|
1213 case DevFmtQuad:
|
rlm@0
|
1214 case DevFmtX51:
|
rlm@0
|
1215 case DevFmtX51Side:
|
rlm@0
|
1216 case DevFmtX61:
|
rlm@0
|
1217 case DevFmtX71:
|
rlm@0
|
1218 if(GetConfigValueBool(NULL, "stereodup", AL_TRUE))
|
rlm@0
|
1219 device->Flags |= DEVICE_DUPLICATE_STEREO;
|
rlm@0
|
1220 break;
|
rlm@0
|
1221 }
|
rlm@0
|
1222 TRACE("Stereo duplication %s\n", (device->Flags&DEVICE_DUPLICATE_STEREO)?"enabled":"disabled");
|
rlm@0
|
1223
|
rlm@0
|
1224 for(i = 0;i < device->NumContexts;i++)
|
rlm@0
|
1225 {
|
rlm@0
|
1226 ALCcontext *context = device->Contexts[i];
|
rlm@0
|
1227 ALsizei pos;
|
rlm@0
|
1228
|
rlm@0
|
1229 context->UpdateSources = AL_FALSE;
|
rlm@0
|
1230 for(pos = 0;pos < context->EffectSlotMap.size;pos++)
|
rlm@0
|
1231 {
|
rlm@0
|
1232 ALeffectslot *slot = context->EffectSlotMap.array[pos].value;
|
rlm@0
|
1233
|
rlm@0
|
1234 if(ALEffect_DeviceUpdate(slot->EffectState, device) == AL_FALSE)
|
rlm@0
|
1235 {
|
rlm@0
|
1236 UnlockDevice(device);
|
rlm@0
|
1237 ALCdevice_StopPlayback(device);
|
rlm@0
|
1238 device->Flags &= ~DEVICE_RUNNING;
|
rlm@0
|
1239 return ALC_FALSE;
|
rlm@0
|
1240 }
|
rlm@0
|
1241 slot->NeedsUpdate = AL_FALSE;
|
rlm@0
|
1242 ALEffect_Update(slot->EffectState, context, slot);
|
rlm@0
|
1243 }
|
rlm@0
|
1244
|
rlm@0
|
1245 for(pos = 0;pos < context->SourceMap.size;pos++)
|
rlm@0
|
1246 {
|
rlm@0
|
1247 ALsource *source = context->SourceMap.array[pos].value;
|
rlm@0
|
1248 ALuint s = device->NumAuxSends;
|
rlm@0
|
1249 while(s < MAX_SENDS)
|
rlm@0
|
1250 {
|
rlm@0
|
1251 if(source->Send[s].Slot)
|
rlm@0
|
1252 source->Send[s].Slot->refcount--;
|
rlm@0
|
1253 source->Send[s].Slot = NULL;
|
rlm@0
|
1254 source->Send[s].WetFilter.type = 0;
|
rlm@0
|
1255 source->Send[s].WetFilter.filter = 0;
|
rlm@0
|
1256 s++;
|
rlm@0
|
1257 }
|
rlm@0
|
1258 source->NeedsUpdate = AL_FALSE;
|
rlm@0
|
1259 ALsource_Update(source, context);
|
rlm@0
|
1260 }
|
rlm@0
|
1261 }
|
rlm@0
|
1262 UnlockDevice(device);
|
rlm@0
|
1263
|
rlm@0
|
1264 return ALC_TRUE;
|
rlm@0
|
1265 }
|
rlm@0
|
1266
|
rlm@0
|
1267
|
rlm@0
|
1268 ALCvoid LockDevice(ALCdevice *device)
|
rlm@0
|
1269 {
|
rlm@0
|
1270 EnterCriticalSection(&device->Mutex);
|
rlm@0
|
1271 }
|
rlm@0
|
1272
|
rlm@0
|
1273 ALCvoid UnlockDevice(ALCdevice *device)
|
rlm@0
|
1274 {
|
rlm@0
|
1275 LeaveCriticalSection(&device->Mutex);
|
rlm@0
|
1276 }
|
rlm@0
|
1277
|
rlm@0
|
1278 /*
|
rlm@0
|
1279 LockContext
|
rlm@0
|
1280
|
rlm@0
|
1281 Thread-safe entry
|
rlm@0
|
1282 */
|
rlm@0
|
1283 ALCvoid LockContext(ALCcontext *context)
|
rlm@0
|
1284 {
|
rlm@0
|
1285 EnterCriticalSection(&context->Device->Mutex);
|
rlm@0
|
1286 }
|
rlm@0
|
1287
|
rlm@0
|
1288
|
rlm@0
|
1289 /*
|
rlm@0
|
1290 UnlockContext
|
rlm@0
|
1291
|
rlm@0
|
1292 Thread-safe exit
|
rlm@0
|
1293 */
|
rlm@0
|
1294 ALCvoid UnlockContext(ALCcontext *context)
|
rlm@0
|
1295 {
|
rlm@0
|
1296 LeaveCriticalSection(&context->Device->Mutex);
|
rlm@0
|
1297 }
|
rlm@0
|
1298
|
rlm@0
|
1299
|
rlm@0
|
1300 /*
|
rlm@0
|
1301 GetLockedContext
|
rlm@0
|
1302
|
rlm@0
|
1303 Returns the currently active Context, in a locked state
|
rlm@0
|
1304 */
|
rlm@0
|
1305 ALCcontext *GetLockedContext(void)
|
rlm@0
|
1306 {
|
rlm@0
|
1307 ALCcontext *pContext = NULL;
|
rlm@0
|
1308
|
rlm@0
|
1309 LockLists();
|
rlm@0
|
1310
|
rlm@0
|
1311 pContext = tls_get(LocalContext);
|
rlm@0
|
1312 if(pContext && !IsContext(pContext))
|
rlm@0
|
1313 {
|
rlm@0
|
1314 tls_set(LocalContext, NULL);
|
rlm@0
|
1315 pContext = NULL;
|
rlm@0
|
1316 }
|
rlm@0
|
1317 if(!pContext)
|
rlm@0
|
1318 pContext = GlobalContext;
|
rlm@0
|
1319 if(pContext)
|
rlm@0
|
1320 LockContext(pContext);
|
rlm@0
|
1321
|
rlm@0
|
1322 UnlockLists();
|
rlm@0
|
1323
|
rlm@0
|
1324 return pContext;
|
rlm@0
|
1325 }
|
rlm@0
|
1326
|
rlm@0
|
1327
|
rlm@0
|
1328 /*
|
rlm@0
|
1329 InitContext
|
rlm@0
|
1330
|
rlm@0
|
1331 Initialize Context variables
|
rlm@0
|
1332 */
|
rlm@0
|
1333 static ALvoid InitContext(ALCcontext *pContext)
|
rlm@0
|
1334 {
|
rlm@0
|
1335 //Initialise listener
|
rlm@0
|
1336 pContext->Listener.Gain = 1.0f;
|
rlm@0
|
1337 pContext->Listener.MetersPerUnit = 1.0f;
|
rlm@0
|
1338 pContext->Listener.Position[0] = 0.0f;
|
rlm@0
|
1339 pContext->Listener.Position[1] = 0.0f;
|
rlm@0
|
1340 pContext->Listener.Position[2] = 0.0f;
|
rlm@0
|
1341 pContext->Listener.Velocity[0] = 0.0f;
|
rlm@0
|
1342 pContext->Listener.Velocity[1] = 0.0f;
|
rlm@0
|
1343 pContext->Listener.Velocity[2] = 0.0f;
|
rlm@0
|
1344 pContext->Listener.Forward[0] = 0.0f;
|
rlm@0
|
1345 pContext->Listener.Forward[1] = 0.0f;
|
rlm@0
|
1346 pContext->Listener.Forward[2] = -1.0f;
|
rlm@0
|
1347 pContext->Listener.Up[0] = 0.0f;
|
rlm@0
|
1348 pContext->Listener.Up[1] = 1.0f;
|
rlm@0
|
1349 pContext->Listener.Up[2] = 0.0f;
|
rlm@0
|
1350
|
rlm@0
|
1351 //Validate pContext
|
rlm@0
|
1352 pContext->LastError = AL_NO_ERROR;
|
rlm@0
|
1353 pContext->UpdateSources = AL_FALSE;
|
rlm@0
|
1354 pContext->ActiveSourceCount = 0;
|
rlm@0
|
1355 InitUIntMap(&pContext->SourceMap);
|
rlm@0
|
1356 InitUIntMap(&pContext->EffectSlotMap);
|
rlm@0
|
1357
|
rlm@0
|
1358 //Set globals
|
rlm@0
|
1359 pContext->DistanceModel = AL_INVERSE_DISTANCE_CLAMPED;
|
rlm@0
|
1360 pContext->SourceDistanceModel = AL_FALSE;
|
rlm@0
|
1361 pContext->DopplerFactor = 1.0f;
|
rlm@0
|
1362 pContext->DopplerVelocity = 1.0f;
|
rlm@0
|
1363 pContext->flSpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
|
rlm@0
|
1364 pContext->DeferUpdates = AL_FALSE;
|
rlm@0
|
1365
|
rlm@0
|
1366 pContext->ExtensionList = alExtList;
|
rlm@0
|
1367 }
|
rlm@0
|
1368
|
rlm@0
|
1369
|
rlm@0
|
1370 /*
|
rlm@0
|
1371 FreeContext
|
rlm@0
|
1372
|
rlm@0
|
1373 Clean up Context, destroy any remaining Sources
|
rlm@0
|
1374 */
|
rlm@0
|
1375 static ALCvoid FreeContext(ALCcontext *context)
|
rlm@0
|
1376 {
|
rlm@0
|
1377 //Invalidate context
|
rlm@0
|
1378 memset(context, 0, sizeof(ALCcontext));
|
rlm@0
|
1379 free(context);
|
rlm@0
|
1380 }
|
rlm@0
|
1381
|
rlm@0
|
1382 ///////////////////////////////////////////////////////
|
rlm@0
|
1383
|
rlm@0
|
1384
|
rlm@0
|
1385 ///////////////////////////////////////////////////////
|
rlm@0
|
1386 // ALC Functions calls
|
rlm@0
|
1387
|
rlm@0
|
1388
|
rlm@0
|
1389 // This should probably move to another c file but for now ...
|
rlm@0
|
1390 ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei SampleSize)
|
rlm@0
|
1391 {
|
rlm@0
|
1392 ALCdevice *device = NULL;
|
rlm@0
|
1393
|
rlm@0
|
1394 DO_INITCONFIG();
|
rlm@0
|
1395
|
rlm@0
|
1396 if(!CaptureBackend.name)
|
rlm@0
|
1397 {
|
rlm@0
|
1398 alcSetError(NULL, ALC_INVALID_VALUE);
|
rlm@0
|
1399 return NULL;
|
rlm@0
|
1400 }
|
rlm@0
|
1401
|
rlm@0
|
1402 if(SampleSize <= 0)
|
rlm@0
|
1403 {
|
rlm@0
|
1404 alcSetError(NULL, ALC_INVALID_VALUE);
|
rlm@0
|
1405 return NULL;
|
rlm@0
|
1406 }
|
rlm@0
|
1407
|
rlm@0
|
1408 if(deviceName && (!deviceName[0] || strcasecmp(deviceName, "openal soft") == 0 || strcasecmp(deviceName, "openal-soft") == 0))
|
rlm@0
|
1409 deviceName = NULL;
|
rlm@0
|
1410
|
rlm@0
|
1411 device = calloc(1, sizeof(ALCdevice));
|
rlm@0
|
1412 if(!device)
|
rlm@0
|
1413 {
|
rlm@0
|
1414 alcSetError(NULL, ALC_OUT_OF_MEMORY);
|
rlm@0
|
1415 return NULL;
|
rlm@0
|
1416 }
|
rlm@0
|
1417
|
rlm@0
|
1418 //Validate device
|
rlm@0
|
1419 device->Funcs = &CaptureBackend.Funcs;
|
rlm@0
|
1420 device->Connected = ALC_TRUE;
|
rlm@0
|
1421 device->IsCaptureDevice = AL_TRUE;
|
rlm@0
|
1422 device->IsLoopbackDevice = AL_FALSE;
|
rlm@0
|
1423 InitializeCriticalSection(&device->Mutex);
|
rlm@0
|
1424
|
rlm@0
|
1425 device->szDeviceName = NULL;
|
rlm@0
|
1426
|
rlm@0
|
1427 device->Flags |= DEVICE_FREQUENCY_REQUEST;
|
rlm@0
|
1428 device->Frequency = frequency;
|
rlm@0
|
1429
|
rlm@0
|
1430 device->Flags |= DEVICE_CHANNELS_REQUEST;
|
rlm@0
|
1431 if(DecomposeDevFormat(format, &device->FmtChans, &device->FmtType) == AL_FALSE)
|
rlm@0
|
1432 {
|
rlm@0
|
1433 free(device);
|
rlm@0
|
1434 alcSetError(NULL, ALC_INVALID_ENUM);
|
rlm@0
|
1435 return NULL;
|
rlm@0
|
1436 }
|
rlm@0
|
1437
|
rlm@0
|
1438 device->UpdateSize = SampleSize;
|
rlm@0
|
1439 device->NumUpdates = 1;
|
rlm@0
|
1440
|
rlm@0
|
1441 LockLists();
|
rlm@0
|
1442 if(ALCdevice_OpenCapture(device, deviceName))
|
rlm@0
|
1443 {
|
rlm@0
|
1444 device->next = g_pDeviceList;
|
rlm@0
|
1445 g_pDeviceList = device;
|
rlm@0
|
1446 g_ulDeviceCount++;
|
rlm@0
|
1447 }
|
rlm@0
|
1448 else
|
rlm@0
|
1449 {
|
rlm@0
|
1450 DeleteCriticalSection(&device->Mutex);
|
rlm@0
|
1451 free(device);
|
rlm@0
|
1452 device = NULL;
|
rlm@0
|
1453 alcSetError(NULL, ALC_INVALID_VALUE);
|
rlm@0
|
1454 }
|
rlm@0
|
1455 UnlockLists();
|
rlm@0
|
1456
|
rlm@0
|
1457 return device;
|
rlm@0
|
1458 }
|
rlm@0
|
1459
|
rlm@0
|
1460 ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *pDevice)
|
rlm@0
|
1461 {
|
rlm@0
|
1462 ALCdevice **list;
|
rlm@0
|
1463
|
rlm@0
|
1464 LockLists();
|
rlm@0
|
1465 list = &g_pDeviceList;
|
rlm@0
|
1466 while(*list && *list != pDevice)
|
rlm@0
|
1467 list = &(*list)->next;
|
rlm@0
|
1468
|
rlm@0
|
1469 if(!*list || !(*list)->IsCaptureDevice)
|
rlm@0
|
1470 {
|
rlm@0
|
1471 alcSetError(*list, ALC_INVALID_DEVICE);
|
rlm@0
|
1472 UnlockLists();
|
rlm@0
|
1473 return ALC_FALSE;
|
rlm@0
|
1474 }
|
rlm@0
|
1475
|
rlm@0
|
1476 *list = (*list)->next;
|
rlm@0
|
1477 g_ulDeviceCount--;
|
rlm@0
|
1478
|
rlm@0
|
1479 UnlockLists();
|
rlm@0
|
1480
|
rlm@0
|
1481 LockDevice(pDevice);
|
rlm@0
|
1482 ALCdevice_CloseCapture(pDevice);
|
rlm@0
|
1483 UnlockDevice(pDevice);
|
rlm@0
|
1484
|
rlm@0
|
1485 free(pDevice->szDeviceName);
|
rlm@0
|
1486 pDevice->szDeviceName = NULL;
|
rlm@0
|
1487
|
rlm@0
|
1488 DeleteCriticalSection(&pDevice->Mutex);
|
rlm@0
|
1489
|
rlm@0
|
1490 free(pDevice);
|
rlm@0
|
1491
|
rlm@0
|
1492 return ALC_TRUE;
|
rlm@0
|
1493 }
|
rlm@0
|
1494
|
rlm@0
|
1495 ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
|
rlm@0
|
1496 {
|
rlm@0
|
1497 LockLists();
|
rlm@0
|
1498 if(!IsDevice(device) || !device->IsCaptureDevice)
|
rlm@0
|
1499 {
|
rlm@0
|
1500 alcSetError(device, ALC_INVALID_DEVICE);
|
rlm@0
|
1501 UnlockLists();
|
rlm@0
|
1502 return;
|
rlm@0
|
1503 }
|
rlm@0
|
1504 LockDevice(device);
|
rlm@0
|
1505 UnlockLists();
|
rlm@0
|
1506 if(device->Connected)
|
rlm@0
|
1507 ALCdevice_StartCapture(device);
|
rlm@0
|
1508 UnlockDevice(device);
|
rlm@0
|
1509 }
|
rlm@0
|
1510
|
rlm@0
|
1511 ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
|
rlm@0
|
1512 {
|
rlm@0
|
1513 LockLists();
|
rlm@0
|
1514 if(!IsDevice(device) || !device->IsCaptureDevice)
|
rlm@0
|
1515 {
|
rlm@0
|
1516 alcSetError(device, ALC_INVALID_DEVICE);
|
rlm@0
|
1517 UnlockLists();
|
rlm@0
|
1518 return;
|
rlm@0
|
1519 }
|
rlm@0
|
1520 LockDevice(device);
|
rlm@0
|
1521 UnlockLists();
|
rlm@0
|
1522 if(device->Connected)
|
rlm@0
|
1523 ALCdevice_StopCapture(device);
|
rlm@0
|
1524 UnlockDevice(device);
|
rlm@0
|
1525 }
|
rlm@0
|
1526
|
rlm@0
|
1527 ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
|
rlm@0
|
1528 {
|
rlm@0
|
1529 LockLists();
|
rlm@0
|
1530 if(!IsDevice(device) || !device->IsCaptureDevice)
|
rlm@0
|
1531 {
|
rlm@0
|
1532 alcSetError(device, ALC_INVALID_DEVICE);
|
rlm@0
|
1533 UnlockLists();
|
rlm@0
|
1534 return;
|
rlm@0
|
1535 }
|
rlm@0
|
1536 LockDevice(device);
|
rlm@0
|
1537 UnlockLists();
|
rlm@0
|
1538 if(device->Connected)
|
rlm@0
|
1539 ALCdevice_CaptureSamples(device, buffer, samples);
|
rlm@0
|
1540 UnlockDevice(device);
|
rlm@0
|
1541 }
|
rlm@0
|
1542
|
rlm@0
|
1543 /*
|
rlm@0
|
1544 alcGetError
|
rlm@0
|
1545
|
rlm@0
|
1546 Return last ALC generated error code
|
rlm@0
|
1547 */
|
rlm@0
|
1548 ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
|
rlm@0
|
1549 {
|
rlm@0
|
1550 ALCenum errorCode;
|
rlm@0
|
1551
|
rlm@0
|
1552 LockLists();
|
rlm@0
|
1553 if(IsDevice(device))
|
rlm@0
|
1554 {
|
rlm@0
|
1555 errorCode = device->LastError;
|
rlm@0
|
1556 device->LastError = ALC_NO_ERROR;
|
rlm@0
|
1557 }
|
rlm@0
|
1558 else
|
rlm@0
|
1559 {
|
rlm@0
|
1560 errorCode = g_eLastNullDeviceError;
|
rlm@0
|
1561 g_eLastNullDeviceError = ALC_NO_ERROR;
|
rlm@0
|
1562 }
|
rlm@0
|
1563 UnlockLists();
|
rlm@0
|
1564 return errorCode;
|
rlm@0
|
1565 }
|
rlm@0
|
1566
|
rlm@0
|
1567
|
rlm@0
|
1568 /*
|
rlm@0
|
1569 alcSuspendContext
|
rlm@0
|
1570
|
rlm@0
|
1571 Not functional
|
rlm@0
|
1572 */
|
rlm@0
|
1573 ALC_API ALCvoid ALC_APIENTRY alcSuspendContext(ALCcontext *Context)
|
rlm@0
|
1574 {
|
rlm@0
|
1575 (void)Context;
|
rlm@0
|
1576 }
|
rlm@0
|
1577
|
rlm@0
|
1578
|
rlm@0
|
1579 /*
|
rlm@0
|
1580 alcProcessContext
|
rlm@0
|
1581
|
rlm@0
|
1582 Not functional
|
rlm@0
|
1583 */
|
rlm@0
|
1584 ALC_API ALCvoid ALC_APIENTRY alcProcessContext(ALCcontext *Context)
|
rlm@0
|
1585 {
|
rlm@0
|
1586 (void)Context;
|
rlm@0
|
1587 }
|
rlm@0
|
1588
|
rlm@0
|
1589
|
rlm@0
|
1590 /*
|
rlm@0
|
1591 alcGetString
|
rlm@0
|
1592
|
rlm@0
|
1593 Returns information about the Device, and error strings
|
rlm@0
|
1594 */
|
rlm@0
|
1595 ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *pDevice,ALCenum param)
|
rlm@0
|
1596 {
|
rlm@0
|
1597 const ALCchar *value = NULL;
|
rlm@0
|
1598
|
rlm@0
|
1599 switch(param)
|
rlm@0
|
1600 {
|
rlm@0
|
1601 case ALC_NO_ERROR:
|
rlm@0
|
1602 value = alcNoError;
|
rlm@0
|
1603 break;
|
rlm@0
|
1604
|
rlm@0
|
1605 case ALC_INVALID_ENUM:
|
rlm@0
|
1606 value = alcErrInvalidEnum;
|
rlm@0
|
1607 break;
|
rlm@0
|
1608
|
rlm@0
|
1609 case ALC_INVALID_VALUE:
|
rlm@0
|
1610 value = alcErrInvalidValue;
|
rlm@0
|
1611 break;
|
rlm@0
|
1612
|
rlm@0
|
1613 case ALC_INVALID_DEVICE:
|
rlm@0
|
1614 value = alcErrInvalidDevice;
|
rlm@0
|
1615 break;
|
rlm@0
|
1616
|
rlm@0
|
1617 case ALC_INVALID_CONTEXT:
|
rlm@0
|
1618 value = alcErrInvalidContext;
|
rlm@0
|
1619 break;
|
rlm@0
|
1620
|
rlm@0
|
1621 case ALC_OUT_OF_MEMORY:
|
rlm@0
|
1622 value = alcErrOutOfMemory;
|
rlm@0
|
1623 break;
|
rlm@0
|
1624
|
rlm@0
|
1625 case ALC_DEVICE_SPECIFIER:
|
rlm@0
|
1626 LockLists();
|
rlm@0
|
1627 if(IsDevice(pDevice))
|
rlm@0
|
1628 value = pDevice->szDeviceName;
|
rlm@0
|
1629 else
|
rlm@0
|
1630 {
|
rlm@0
|
1631 ProbeDeviceList();
|
rlm@0
|
1632 value = alcDeviceList;
|
rlm@0
|
1633 }
|
rlm@0
|
1634 UnlockLists();
|
rlm@0
|
1635 break;
|
rlm@0
|
1636
|
rlm@0
|
1637 case ALC_ALL_DEVICES_SPECIFIER:
|
rlm@0
|
1638 ProbeAllDeviceList();
|
rlm@0
|
1639 value = alcAllDeviceList;
|
rlm@0
|
1640 break;
|
rlm@0
|
1641
|
rlm@0
|
1642 case ALC_CAPTURE_DEVICE_SPECIFIER:
|
rlm@0
|
1643 LockLists();
|
rlm@0
|
1644 if(IsDevice(pDevice))
|
rlm@0
|
1645 value = pDevice->szDeviceName;
|
rlm@0
|
1646 else
|
rlm@0
|
1647 {
|
rlm@0
|
1648 ProbeCaptureDeviceList();
|
rlm@0
|
1649 value = alcCaptureDeviceList;
|
rlm@0
|
1650 }
|
rlm@0
|
1651 UnlockLists();
|
rlm@0
|
1652 break;
|
rlm@0
|
1653
|
rlm@0
|
1654 /* Default devices are always first in the list */
|
rlm@0
|
1655 case ALC_DEFAULT_DEVICE_SPECIFIER:
|
rlm@0
|
1656 if(!alcDeviceList)
|
rlm@0
|
1657 ProbeDeviceList();
|
rlm@0
|
1658
|
rlm@0
|
1659 free(alcDefaultDeviceSpecifier);
|
rlm@0
|
1660 alcDefaultDeviceSpecifier = strdup(alcDeviceList ? alcDeviceList : "");
|
rlm@0
|
1661 if(!alcDefaultDeviceSpecifier)
|
rlm@0
|
1662 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
|
rlm@0
|
1663 value = alcDefaultDeviceSpecifier;
|
rlm@0
|
1664 break;
|
rlm@0
|
1665
|
rlm@0
|
1666 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER:
|
rlm@0
|
1667 if(!alcAllDeviceList)
|
rlm@0
|
1668 ProbeAllDeviceList();
|
rlm@0
|
1669
|
rlm@0
|
1670 free(alcDefaultAllDeviceSpecifier);
|
rlm@0
|
1671 alcDefaultAllDeviceSpecifier = strdup(alcAllDeviceList ?
|
rlm@0
|
1672 alcAllDeviceList : "");
|
rlm@0
|
1673 if(!alcDefaultAllDeviceSpecifier)
|
rlm@0
|
1674 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
|
rlm@0
|
1675 value = alcDefaultAllDeviceSpecifier;
|
rlm@0
|
1676 break;
|
rlm@0
|
1677
|
rlm@0
|
1678 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER:
|
rlm@0
|
1679 if(!alcCaptureDeviceList)
|
rlm@0
|
1680 ProbeCaptureDeviceList();
|
rlm@0
|
1681
|
rlm@0
|
1682 free(alcCaptureDefaultDeviceSpecifier);
|
rlm@0
|
1683 alcCaptureDefaultDeviceSpecifier = strdup(alcCaptureDeviceList ?
|
rlm@0
|
1684 alcCaptureDeviceList : "");
|
rlm@0
|
1685 if(!alcCaptureDefaultDeviceSpecifier)
|
rlm@0
|
1686 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
|
rlm@0
|
1687 value = alcCaptureDefaultDeviceSpecifier;
|
rlm@0
|
1688 break;
|
rlm@0
|
1689
|
rlm@0
|
1690 case ALC_EXTENSIONS:
|
rlm@0
|
1691 LockLists();
|
rlm@0
|
1692 if(IsDevice(pDevice))
|
rlm@0
|
1693 value = alcExtensionList;
|
rlm@0
|
1694 else
|
rlm@0
|
1695 value = alcNoDeviceExtList;
|
rlm@0
|
1696 UnlockLists();
|
rlm@0
|
1697 break;
|
rlm@0
|
1698
|
rlm@0
|
1699 default:
|
rlm@0
|
1700 alcSetError(pDevice, ALC_INVALID_ENUM);
|
rlm@0
|
1701 break;
|
rlm@0
|
1702 }
|
rlm@0
|
1703
|
rlm@0
|
1704 return value;
|
rlm@0
|
1705 }
|
rlm@0
|
1706
|
rlm@0
|
1707
|
rlm@0
|
1708 /*
|
rlm@0
|
1709 alcGetIntegerv
|
rlm@0
|
1710
|
rlm@0
|
1711 Returns information about the Device and the version of Open AL
|
rlm@0
|
1712 */
|
rlm@0
|
1713 ALC_API ALCvoid ALC_APIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsizei size,ALCint *data)
|
rlm@0
|
1714 {
|
rlm@0
|
1715 if(size == 0 || data == NULL)
|
rlm@0
|
1716 {
|
rlm@0
|
1717 alcSetError(device, ALC_INVALID_VALUE);
|
rlm@0
|
1718 return;
|
rlm@0
|
1719 }
|
rlm@0
|
1720
|
rlm@0
|
1721 LockLists();
|
rlm@0
|
1722 if(!IsDevice(device))
|
rlm@0
|
1723 {
|
rlm@0
|
1724 switch(param)
|
rlm@0
|
1725 {
|
rlm@0
|
1726 case ALC_MAJOR_VERSION:
|
rlm@0
|
1727 *data = alcMajorVersion;
|
rlm@0
|
1728 break;
|
rlm@0
|
1729 case ALC_MINOR_VERSION:
|
rlm@0
|
1730 *data = alcMinorVersion;
|
rlm@0
|
1731 break;
|
rlm@0
|
1732
|
rlm@0
|
1733 case ALC_ATTRIBUTES_SIZE:
|
rlm@0
|
1734 case ALC_ALL_ATTRIBUTES:
|
rlm@0
|
1735 case ALC_FREQUENCY:
|
rlm@0
|
1736 case ALC_REFRESH:
|
rlm@0
|
1737 case ALC_SYNC:
|
rlm@0
|
1738 case ALC_MONO_SOURCES:
|
rlm@0
|
1739 case ALC_STEREO_SOURCES:
|
rlm@0
|
1740 case ALC_CAPTURE_SAMPLES:
|
rlm@0
|
1741 case ALC_FORMAT_CHANNELS_SOFT:
|
rlm@0
|
1742 case ALC_FORMAT_TYPE_SOFT:
|
rlm@0
|
1743 alcSetError(NULL, ALC_INVALID_DEVICE);
|
rlm@0
|
1744 break;
|
rlm@0
|
1745
|
rlm@0
|
1746 default:
|
rlm@0
|
1747 alcSetError(NULL, ALC_INVALID_ENUM);
|
rlm@0
|
1748 break;
|
rlm@0
|
1749 }
|
rlm@0
|
1750 }
|
rlm@0
|
1751 else if(device->IsCaptureDevice)
|
rlm@0
|
1752 {
|
rlm@0
|
1753 switch(param)
|
rlm@0
|
1754 {
|
rlm@0
|
1755 case ALC_CAPTURE_SAMPLES:
|
rlm@0
|
1756 LockDevice(device);
|
rlm@0
|
1757 *data = ALCdevice_AvailableSamples(device);
|
rlm@0
|
1758 UnlockDevice(device);
|
rlm@0
|
1759 break;
|
rlm@0
|
1760
|
rlm@0
|
1761 case ALC_CONNECTED:
|
rlm@0
|
1762 *data = device->Connected;
|
rlm@0
|
1763 break;
|
rlm@0
|
1764
|
rlm@0
|
1765 default:
|
rlm@0
|
1766 alcSetError(device, ALC_INVALID_ENUM);
|
rlm@0
|
1767 break;
|
rlm@0
|
1768 }
|
rlm@0
|
1769 }
|
rlm@0
|
1770 else /* render device */
|
rlm@0
|
1771 {
|
rlm@0
|
1772 switch(param)
|
rlm@0
|
1773 {
|
rlm@0
|
1774 case ALC_MAJOR_VERSION:
|
rlm@0
|
1775 *data = alcMajorVersion;
|
rlm@0
|
1776 break;
|
rlm@0
|
1777
|
rlm@0
|
1778 case ALC_MINOR_VERSION:
|
rlm@0
|
1779 *data = alcMinorVersion;
|
rlm@0
|
1780 break;
|
rlm@0
|
1781
|
rlm@0
|
1782 case ALC_EFX_MAJOR_VERSION:
|
rlm@0
|
1783 *data = alcEFXMajorVersion;
|
rlm@0
|
1784 break;
|
rlm@0
|
1785
|
rlm@0
|
1786 case ALC_EFX_MINOR_VERSION:
|
rlm@0
|
1787 *data = alcEFXMinorVersion;
|
rlm@0
|
1788 break;
|
rlm@0
|
1789
|
rlm@0
|
1790 case ALC_ATTRIBUTES_SIZE:
|
rlm@0
|
1791 *data = 13;
|
rlm@0
|
1792 break;
|
rlm@0
|
1793
|
rlm@0
|
1794 case ALC_ALL_ATTRIBUTES:
|
rlm@0
|
1795 if(size < 13)
|
rlm@0
|
1796 alcSetError(device, ALC_INVALID_VALUE);
|
rlm@0
|
1797 else
|
rlm@0
|
1798 {
|
rlm@0
|
1799 int i = 0;
|
rlm@0
|
1800
|
rlm@0
|
1801 data[i++] = ALC_FREQUENCY;
|
rlm@0
|
1802 data[i++] = device->Frequency;
|
rlm@0
|
1803
|
rlm@0
|
1804 if(!device->IsLoopbackDevice)
|
rlm@0
|
1805 {
|
rlm@0
|
1806 data[i++] = ALC_REFRESH;
|
rlm@0
|
1807 data[i++] = device->Frequency / device->UpdateSize;
|
rlm@0
|
1808
|
rlm@0
|
1809 data[i++] = ALC_SYNC;
|
rlm@0
|
1810 data[i++] = ALC_FALSE;
|
rlm@0
|
1811 }
|
rlm@0
|
1812 else
|
rlm@0
|
1813 {
|
rlm@0
|
1814 data[i++] = ALC_FORMAT_CHANNELS_SOFT;
|
rlm@0
|
1815 data[i++] = device->FmtChans;
|
rlm@0
|
1816
|
rlm@0
|
1817 data[i++] = ALC_FORMAT_TYPE_SOFT;
|
rlm@0
|
1818 data[i++] = device->FmtType;
|
rlm@0
|
1819 }
|
rlm@0
|
1820
|
rlm@0
|
1821 data[i++] = ALC_MONO_SOURCES;
|
rlm@0
|
1822 data[i++] = device->NumMonoSources;
|
rlm@0
|
1823
|
rlm@0
|
1824 data[i++] = ALC_STEREO_SOURCES;
|
rlm@0
|
1825 data[i++] = device->NumStereoSources;
|
rlm@0
|
1826
|
rlm@0
|
1827 data[i++] = ALC_MAX_AUXILIARY_SENDS;
|
rlm@0
|
1828 data[i++] = device->NumAuxSends;
|
rlm@0
|
1829
|
rlm@0
|
1830 data[i++] = 0;
|
rlm@0
|
1831 }
|
rlm@0
|
1832 break;
|
rlm@0
|
1833
|
rlm@0
|
1834 case ALC_FREQUENCY:
|
rlm@0
|
1835 *data = device->Frequency;
|
rlm@0
|
1836 break;
|
rlm@0
|
1837
|
rlm@0
|
1838 case ALC_REFRESH:
|
rlm@0
|
1839 if(device->IsLoopbackDevice)
|
rlm@0
|
1840 alcSetError(device, ALC_INVALID_DEVICE);
|
rlm@0
|
1841 else
|
rlm@0
|
1842 *data = device->Frequency / device->UpdateSize;
|
rlm@0
|
1843 break;
|
rlm@0
|
1844
|
rlm@0
|
1845 case ALC_SYNC:
|
rlm@0
|
1846 if(device->IsLoopbackDevice)
|
rlm@0
|
1847 alcSetError(device, ALC_INVALID_DEVICE);
|
rlm@0
|
1848 else
|
rlm@0
|
1849 *data = ALC_FALSE;
|
rlm@0
|
1850 break;
|
rlm@0
|
1851
|
rlm@0
|
1852 case ALC_FORMAT_CHANNELS_SOFT:
|
rlm@0
|
1853 if(!device->IsLoopbackDevice)
|
rlm@0
|
1854 alcSetError(device, ALC_INVALID_DEVICE);
|
rlm@0
|
1855 else
|
rlm@0
|
1856 *data = device->FmtChans;
|
rlm@0
|
1857 break;
|
rlm@0
|
1858
|
rlm@0
|
1859 case ALC_FORMAT_TYPE_SOFT:
|
rlm@0
|
1860 if(!device->IsLoopbackDevice)
|
rlm@0
|
1861 alcSetError(device, ALC_INVALID_DEVICE);
|
rlm@0
|
1862 else
|
rlm@0
|
1863 *data = device->FmtType;
|
rlm@0
|
1864 break;
|
rlm@0
|
1865
|
rlm@0
|
1866 case ALC_MONO_SOURCES:
|
rlm@0
|
1867 *data = device->NumMonoSources;
|
rlm@0
|
1868 break;
|
rlm@0
|
1869
|
rlm@0
|
1870 case ALC_STEREO_SOURCES:
|
rlm@0
|
1871 *data = device->NumStereoSources;
|
rlm@0
|
1872 break;
|
rlm@0
|
1873
|
rlm@0
|
1874 case ALC_MAX_AUXILIARY_SENDS:
|
rlm@0
|
1875 *data = device->NumAuxSends;
|
rlm@0
|
1876 break;
|
rlm@0
|
1877
|
rlm@0
|
1878 case ALC_CONNECTED:
|
rlm@0
|
1879 *data = device->Connected;
|
rlm@0
|
1880 break;
|
rlm@0
|
1881
|
rlm@0
|
1882 default:
|
rlm@0
|
1883 alcSetError(device, ALC_INVALID_ENUM);
|
rlm@0
|
1884 break;
|
rlm@0
|
1885 }
|
rlm@0
|
1886 }
|
rlm@0
|
1887 UnlockLists();
|
rlm@0
|
1888 }
|
rlm@0
|
1889
|
rlm@0
|
1890
|
rlm@0
|
1891 /*
|
rlm@0
|
1892 alcIsExtensionPresent
|
rlm@0
|
1893
|
rlm@0
|
1894 Determines if there is support for a particular extension
|
rlm@0
|
1895 */
|
rlm@0
|
1896 ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extName)
|
rlm@0
|
1897 {
|
rlm@0
|
1898 ALCboolean bResult = ALC_FALSE;
|
rlm@0
|
1899 const char *ptr;
|
rlm@0
|
1900 size_t len;
|
rlm@0
|
1901
|
rlm@0
|
1902 if(!extName)
|
rlm@0
|
1903 {
|
rlm@0
|
1904 alcSetError(device, ALC_INVALID_VALUE);
|
rlm@0
|
1905 return ALC_FALSE;
|
rlm@0
|
1906 }
|
rlm@0
|
1907
|
rlm@0
|
1908 len = strlen(extName);
|
rlm@0
|
1909 LockLists();
|
rlm@0
|
1910 ptr = (IsDevice(device) ? alcExtensionList : alcNoDeviceExtList);
|
rlm@0
|
1911 UnlockLists();
|
rlm@0
|
1912 while(ptr && *ptr)
|
rlm@0
|
1913 {
|
rlm@0
|
1914 if(strncasecmp(ptr, extName, len) == 0 &&
|
rlm@0
|
1915 (ptr[len] == '\0' || isspace(ptr[len])))
|
rlm@0
|
1916 {
|
rlm@0
|
1917 bResult = ALC_TRUE;
|
rlm@0
|
1918 break;
|
rlm@0
|
1919 }
|
rlm@0
|
1920 if((ptr=strchr(ptr, ' ')) != NULL)
|
rlm@0
|
1921 {
|
rlm@0
|
1922 do {
|
rlm@0
|
1923 ++ptr;
|
rlm@0
|
1924 } while(isspace(*ptr));
|
rlm@0
|
1925 }
|
rlm@0
|
1926 }
|
rlm@0
|
1927
|
rlm@0
|
1928 return bResult;
|
rlm@0
|
1929 }
|
rlm@0
|
1930
|
rlm@0
|
1931
|
rlm@0
|
1932 /*
|
rlm@0
|
1933 alcGetProcAddress
|
rlm@0
|
1934
|
rlm@0
|
1935 Retrieves the function address for a particular extension function
|
rlm@0
|
1936 */
|
rlm@0
|
1937 ALC_API ALCvoid* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcName)
|
rlm@0
|
1938 {
|
rlm@0
|
1939 ALsizei i = 0;
|
rlm@0
|
1940
|
rlm@0
|
1941 if(!funcName)
|
rlm@0
|
1942 {
|
rlm@0
|
1943 alcSetError(device, ALC_INVALID_VALUE);
|
rlm@0
|
1944 return NULL;
|
rlm@0
|
1945 }
|
rlm@0
|
1946
|
rlm@0
|
1947 while(alcFunctions[i].funcName && strcmp(alcFunctions[i].funcName,funcName) != 0)
|
rlm@0
|
1948 i++;
|
rlm@0
|
1949 return alcFunctions[i].address;
|
rlm@0
|
1950 }
|
rlm@0
|
1951
|
rlm@0
|
1952
|
rlm@0
|
1953 /*
|
rlm@0
|
1954 alcGetEnumValue
|
rlm@0
|
1955
|
rlm@0
|
1956 Get the value for a particular ALC Enumerated Value
|
rlm@0
|
1957 */
|
rlm@0
|
1958 ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumName)
|
rlm@0
|
1959 {
|
rlm@0
|
1960 ALsizei i = 0;
|
rlm@0
|
1961
|
rlm@0
|
1962 if(!enumName)
|
rlm@0
|
1963 {
|
rlm@0
|
1964 alcSetError(device, ALC_INVALID_VALUE);
|
rlm@0
|
1965 return (ALCenum)0;
|
rlm@0
|
1966 }
|
rlm@0
|
1967
|
rlm@0
|
1968 while(enumeration[i].enumName && strcmp(enumeration[i].enumName,enumName) != 0)
|
rlm@0
|
1969 i++;
|
rlm@0
|
1970 return enumeration[i].value;
|
rlm@0
|
1971 }
|
rlm@0
|
1972
|
rlm@0
|
1973
|
rlm@0
|
1974 /*
|
rlm@0
|
1975 alcCreateContext
|
rlm@0
|
1976
|
rlm@0
|
1977 Create and attach a Context to a particular Device.
|
rlm@0
|
1978 */
|
rlm@0
|
1979 ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList)
|
rlm@0
|
1980 {
|
rlm@0
|
1981 ALCcontext *ALContext;
|
rlm@0
|
1982 void *temp;
|
rlm@0
|
1983
|
rlm@0
|
1984 LockLists();
|
rlm@0
|
1985 if(!IsDevice(device) || device->IsCaptureDevice || !device->Connected)
|
rlm@0
|
1986 {
|
rlm@0
|
1987 alcSetError(device, ALC_INVALID_DEVICE);
|
rlm@0
|
1988 UnlockLists();
|
rlm@0
|
1989 return NULL;
|
rlm@0
|
1990 }
|
rlm@0
|
1991
|
rlm@0
|
1992 // Reset Context Last Error code
|
rlm@0
|
1993 device->LastError = ALC_NO_ERROR;
|
rlm@0
|
1994
|
rlm@0
|
1995 if(UpdateDeviceParams(device, attrList) == ALC_FALSE)
|
rlm@0
|
1996 {
|
rlm@0
|
1997 alcSetError(device, ALC_INVALID_DEVICE);
|
rlm@0
|
1998 aluHandleDisconnect(device);
|
rlm@0
|
1999 UnlockLists();
|
rlm@0
|
2000 return NULL;
|
rlm@0
|
2001 }
|
rlm@0
|
2002
|
rlm@0
|
2003 LockDevice(device);
|
rlm@0
|
2004 ALContext = NULL;
|
rlm@0
|
2005 temp = realloc(device->Contexts, (device->NumContexts+1) * sizeof(*device->Contexts));
|
rlm@0
|
2006 if(temp)
|
rlm@0
|
2007 {
|
rlm@0
|
2008 device->Contexts = temp;
|
rlm@0
|
2009
|
rlm@0
|
2010 ALContext = calloc(1, sizeof(ALCcontext));
|
rlm@0
|
2011 if(ALContext)
|
rlm@0
|
2012 {
|
rlm@0
|
2013 ALContext->MaxActiveSources = 256;
|
rlm@0
|
2014 ALContext->ActiveSources = malloc(sizeof(ALContext->ActiveSources[0]) *
|
rlm@0
|
2015 ALContext->MaxActiveSources);
|
rlm@0
|
2016 }
|
rlm@0
|
2017 }
|
rlm@0
|
2018 if(!ALContext || !ALContext->ActiveSources)
|
rlm@0
|
2019 {
|
rlm@0
|
2020 free(ALContext);
|
rlm@0
|
2021 alcSetError(device, ALC_OUT_OF_MEMORY);
|
rlm@0
|
2022 UnlockDevice(device);
|
rlm@0
|
2023 if(device->NumContexts == 0)
|
rlm@0
|
2024 {
|
rlm@0
|
2025 ALCdevice_StopPlayback(device);
|
rlm@0
|
2026 device->Flags &= ~DEVICE_RUNNING;
|
rlm@0
|
2027 }
|
rlm@0
|
2028 UnlockLists();
|
rlm@0
|
2029 return NULL;
|
rlm@0
|
2030 }
|
rlm@0
|
2031
|
rlm@0
|
2032 device->Contexts[device->NumContexts++] = ALContext;
|
rlm@0
|
2033 ALContext->Device = device;
|
rlm@0
|
2034
|
rlm@0
|
2035 InitContext(ALContext);
|
rlm@0
|
2036 UnlockDevice(device);
|
rlm@0
|
2037
|
rlm@0
|
2038 ALContext->next = g_pContextList;
|
rlm@0
|
2039 g_pContextList = ALContext;
|
rlm@0
|
2040 g_ulContextCount++;
|
rlm@0
|
2041
|
rlm@0
|
2042 UnlockLists();
|
rlm@0
|
2043
|
rlm@0
|
2044 return ALContext;
|
rlm@0
|
2045 }
|
rlm@0
|
2046
|
rlm@0
|
2047
|
rlm@0
|
2048 /*
|
rlm@0
|
2049 alcDestroyContext
|
rlm@0
|
2050
|
rlm@0
|
2051 Remove a Context
|
rlm@0
|
2052 */
|
rlm@0
|
2053 ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
|
rlm@0
|
2054 {
|
rlm@0
|
2055 ALCdevice *Device;
|
rlm@0
|
2056 ALCcontext **list;
|
rlm@0
|
2057 ALuint i;
|
rlm@0
|
2058
|
rlm@0
|
2059 LockLists();
|
rlm@0
|
2060 list = &g_pContextList;
|
rlm@0
|
2061 while(*list && *list != context)
|
rlm@0
|
2062 list = &(*list)->next;
|
rlm@0
|
2063
|
rlm@0
|
2064 if(!*list)
|
rlm@0
|
2065 {
|
rlm@0
|
2066 alcSetError(NULL, ALC_INVALID_CONTEXT);
|
rlm@0
|
2067 UnlockLists();
|
rlm@0
|
2068 return;
|
rlm@0
|
2069 }
|
rlm@0
|
2070
|
rlm@0
|
2071 *list = (*list)->next;
|
rlm@0
|
2072 g_ulContextCount--;
|
rlm@0
|
2073
|
rlm@0
|
2074 if(context == tls_get(LocalContext))
|
rlm@0
|
2075 tls_set(LocalContext, NULL);
|
rlm@0
|
2076 if(context == GlobalContext)
|
rlm@0
|
2077 GlobalContext = NULL;
|
rlm@0
|
2078
|
rlm@0
|
2079 Device = context->Device;
|
rlm@0
|
2080 LockDevice(Device);
|
rlm@0
|
2081 for(i = 0;i < Device->NumContexts;i++)
|
rlm@0
|
2082 {
|
rlm@0
|
2083 if(Device->Contexts[i] == context)
|
rlm@0
|
2084 {
|
rlm@0
|
2085 Device->Contexts[i] = Device->Contexts[Device->NumContexts-1];
|
rlm@0
|
2086 Device->NumContexts--;
|
rlm@0
|
2087 break;
|
rlm@0
|
2088 }
|
rlm@0
|
2089 }
|
rlm@0
|
2090 UnlockDevice(Device);
|
rlm@0
|
2091
|
rlm@0
|
2092 if(Device->NumContexts == 0)
|
rlm@0
|
2093 {
|
rlm@0
|
2094 ALCdevice_StopPlayback(Device);
|
rlm@0
|
2095 Device->Flags &= ~DEVICE_RUNNING;
|
rlm@0
|
2096 }
|
rlm@0
|
2097 UnlockLists();
|
rlm@0
|
2098
|
rlm@0
|
2099 if(context->SourceMap.size > 0)
|
rlm@0
|
2100 {
|
rlm@0
|
2101 ERR("alcDestroyContext(): deleting %d Source(s)\n", context->SourceMap.size);
|
rlm@0
|
2102 ReleaseALSources(context);
|
rlm@0
|
2103 }
|
rlm@0
|
2104 ResetUIntMap(&context->SourceMap);
|
rlm@0
|
2105
|
rlm@0
|
2106 if(context->EffectSlotMap.size > 0)
|
rlm@0
|
2107 {
|
rlm@0
|
2108 ERR("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context->EffectSlotMap.size);
|
rlm@0
|
2109 ReleaseALAuxiliaryEffectSlots(context);
|
rlm@0
|
2110 }
|
rlm@0
|
2111 ResetUIntMap(&context->EffectSlotMap);
|
rlm@0
|
2112
|
rlm@0
|
2113 free(context->ActiveSources);
|
rlm@0
|
2114 context->ActiveSources = NULL;
|
rlm@0
|
2115 context->MaxActiveSources = 0;
|
rlm@0
|
2116 context->ActiveSourceCount = 0;
|
rlm@0
|
2117
|
rlm@0
|
2118 FreeContext(context);
|
rlm@0
|
2119 }
|
rlm@0
|
2120
|
rlm@0
|
2121
|
rlm@0
|
2122 /*
|
rlm@0
|
2123 alcGetCurrentContext
|
rlm@0
|
2124
|
rlm@0
|
2125 Returns the currently active Context
|
rlm@0
|
2126 */
|
rlm@0
|
2127 ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(ALCvoid)
|
rlm@0
|
2128 {
|
rlm@0
|
2129 ALCcontext *Context;
|
rlm@0
|
2130
|
rlm@0
|
2131 LockLists();
|
rlm@0
|
2132 Context = tls_get(LocalContext);
|
rlm@0
|
2133 if(Context && !IsContext(Context))
|
rlm@0
|
2134 {
|
rlm@0
|
2135 tls_set(LocalContext, NULL);
|
rlm@0
|
2136 Context = NULL;
|
rlm@0
|
2137 }
|
rlm@0
|
2138 if(!Context)
|
rlm@0
|
2139 Context = GlobalContext;
|
rlm@0
|
2140 UnlockLists();
|
rlm@0
|
2141
|
rlm@0
|
2142 return Context;
|
rlm@0
|
2143 }
|
rlm@0
|
2144
|
rlm@0
|
2145 /*
|
rlm@0
|
2146 alcGetThreadContext
|
rlm@0
|
2147
|
rlm@0
|
2148 Returns the currently active thread-local Context
|
rlm@0
|
2149 */
|
rlm@0
|
2150 ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
|
rlm@0
|
2151 {
|
rlm@0
|
2152 ALCcontext *pContext = NULL;
|
rlm@0
|
2153
|
rlm@0
|
2154 LockLists();
|
rlm@0
|
2155
|
rlm@0
|
2156 pContext = tls_get(LocalContext);
|
rlm@0
|
2157 if(pContext && !IsContext(pContext))
|
rlm@0
|
2158 {
|
rlm@0
|
2159 tls_set(LocalContext, NULL);
|
rlm@0
|
2160 pContext = NULL;
|
rlm@0
|
2161 }
|
rlm@0
|
2162
|
rlm@0
|
2163 UnlockLists();
|
rlm@0
|
2164
|
rlm@0
|
2165 return pContext;
|
rlm@0
|
2166 }
|
rlm@0
|
2167
|
rlm@0
|
2168
|
rlm@0
|
2169 /*
|
rlm@0
|
2170 alcGetContextsDevice
|
rlm@0
|
2171
|
rlm@0
|
2172 Returns the Device that a particular Context is attached to
|
rlm@0
|
2173 */
|
rlm@0
|
2174 ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *pContext)
|
rlm@0
|
2175 {
|
rlm@0
|
2176 ALCdevice *pDevice = NULL;
|
rlm@0
|
2177
|
rlm@0
|
2178 LockLists();
|
rlm@0
|
2179 if(IsContext(pContext))
|
rlm@0
|
2180 pDevice = pContext->Device;
|
rlm@0
|
2181 else
|
rlm@0
|
2182 alcSetError(NULL, ALC_INVALID_CONTEXT);
|
rlm@0
|
2183 UnlockLists();
|
rlm@0
|
2184
|
rlm@0
|
2185 return pDevice;
|
rlm@0
|
2186 }
|
rlm@0
|
2187
|
rlm@0
|
2188
|
rlm@0
|
2189 /*
|
rlm@0
|
2190 alcMakeContextCurrent
|
rlm@0
|
2191
|
rlm@0
|
2192 Makes the given Context the active Context
|
rlm@0
|
2193 */
|
rlm@0
|
2194 ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
|
rlm@0
|
2195 {
|
rlm@0
|
2196 ALboolean bReturn = AL_TRUE;
|
rlm@0
|
2197
|
rlm@0
|
2198 LockLists();
|
rlm@0
|
2199
|
rlm@0
|
2200 // context must be a valid Context or NULL
|
rlm@0
|
2201 if(context == NULL || IsContext(context))
|
rlm@0
|
2202 {
|
rlm@0
|
2203 GlobalContext = context;
|
rlm@0
|
2204 tls_set(LocalContext, NULL);
|
rlm@0
|
2205 }
|
rlm@0
|
2206 else
|
rlm@0
|
2207 {
|
rlm@0
|
2208 alcSetError(NULL, ALC_INVALID_CONTEXT);
|
rlm@0
|
2209 bReturn = AL_FALSE;
|
rlm@0
|
2210 }
|
rlm@0
|
2211
|
rlm@0
|
2212 UnlockLists();
|
rlm@0
|
2213
|
rlm@0
|
2214 return bReturn;
|
rlm@0
|
2215 }
|
rlm@0
|
2216
|
rlm@0
|
2217 /*
|
rlm@0
|
2218 alcSetThreadContext
|
rlm@0
|
2219
|
rlm@0
|
2220 Makes the given Context the active Context for the current thread
|
rlm@0
|
2221 */
|
rlm@0
|
2222 ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
|
rlm@0
|
2223 {
|
rlm@0
|
2224 ALboolean bReturn = AL_TRUE;
|
rlm@0
|
2225
|
rlm@0
|
2226 LockLists();
|
rlm@0
|
2227
|
rlm@0
|
2228 // context must be a valid Context or NULL
|
rlm@0
|
2229 if(context == NULL || IsContext(context))
|
rlm@0
|
2230 tls_set(LocalContext, context);
|
rlm@0
|
2231 else
|
rlm@0
|
2232 {
|
rlm@0
|
2233 alcSetError(NULL, ALC_INVALID_CONTEXT);
|
rlm@0
|
2234 bReturn = AL_FALSE;
|
rlm@0
|
2235 }
|
rlm@0
|
2236
|
rlm@0
|
2237 UnlockLists();
|
rlm@0
|
2238
|
rlm@0
|
2239 return bReturn;
|
rlm@0
|
2240 }
|
rlm@0
|
2241
|
rlm@0
|
2242
|
rlm@0
|
2243 static void GetFormatFromString(const char *str, enum DevFmtChannels *chans, enum DevFmtType *type)
|
rlm@0
|
2244 {
|
rlm@0
|
2245 if(strcasecmp(str, "AL_FORMAT_MONO32") == 0)
|
rlm@0
|
2246 {
|
rlm@0
|
2247 *chans = DevFmtMono;
|
rlm@0
|
2248 *type = DevFmtFloat;
|
rlm@0
|
2249 return;
|
rlm@0
|
2250 }
|
rlm@0
|
2251 if(strcasecmp(str, "AL_FORMAT_STEREO32") == 0)
|
rlm@0
|
2252 {
|
rlm@0
|
2253 *chans = DevFmtStereo;
|
rlm@0
|
2254 *type = DevFmtFloat;
|
rlm@0
|
2255 return;
|
rlm@0
|
2256 }
|
rlm@0
|
2257 if(strcasecmp(str, "AL_FORMAT_QUAD32") == 0)
|
rlm@0
|
2258 {
|
rlm@0
|
2259 *chans = DevFmtQuad;
|
rlm@0
|
2260 *type = DevFmtFloat;
|
rlm@0
|
2261 return;
|
rlm@0
|
2262 }
|
rlm@0
|
2263 if(strcasecmp(str, "AL_FORMAT_51CHN32") == 0)
|
rlm@0
|
2264 {
|
rlm@0
|
2265 *chans = DevFmtX51;
|
rlm@0
|
2266 *type = DevFmtFloat;
|
rlm@0
|
2267 return;
|
rlm@0
|
2268 }
|
rlm@0
|
2269 if(strcasecmp(str, "AL_FORMAT_61CHN32") == 0)
|
rlm@0
|
2270 {
|
rlm@0
|
2271 *chans = DevFmtX61;
|
rlm@0
|
2272 *type = DevFmtFloat;
|
rlm@0
|
2273 return;
|
rlm@0
|
2274 }
|
rlm@0
|
2275 if(strcasecmp(str, "AL_FORMAT_71CHN32") == 0)
|
rlm@0
|
2276 {
|
rlm@0
|
2277 *chans = DevFmtX71;
|
rlm@0
|
2278 *type = DevFmtFloat;
|
rlm@0
|
2279 return;
|
rlm@0
|
2280 }
|
rlm@0
|
2281
|
rlm@0
|
2282 if(strcasecmp(str, "AL_FORMAT_MONO16") == 0)
|
rlm@0
|
2283 {
|
rlm@0
|
2284 *chans = DevFmtMono;
|
rlm@0
|
2285 *type = DevFmtShort;
|
rlm@0
|
2286 return;
|
rlm@0
|
2287 }
|
rlm@0
|
2288 if(strcasecmp(str, "AL_FORMAT_STEREO16") == 0)
|
rlm@0
|
2289 {
|
rlm@0
|
2290 *chans = DevFmtStereo;
|
rlm@0
|
2291 *type = DevFmtShort;
|
rlm@0
|
2292 return;
|
rlm@0
|
2293 }
|
rlm@0
|
2294 if(strcasecmp(str, "AL_FORMAT_QUAD16") == 0)
|
rlm@0
|
2295 {
|
rlm@0
|
2296 *chans = DevFmtQuad;
|
rlm@0
|
2297 *type = DevFmtShort;
|
rlm@0
|
2298 return;
|
rlm@0
|
2299 }
|
rlm@0
|
2300 if(strcasecmp(str, "AL_FORMAT_51CHN16") == 0)
|
rlm@0
|
2301 {
|
rlm@0
|
2302 *chans = DevFmtX51;
|
rlm@0
|
2303 *type = DevFmtShort;
|
rlm@0
|
2304 return;
|
rlm@0
|
2305 }
|
rlm@0
|
2306 if(strcasecmp(str, "AL_FORMAT_61CHN16") == 0)
|
rlm@0
|
2307 {
|
rlm@0
|
2308 *chans = DevFmtX61;
|
rlm@0
|
2309 *type = DevFmtShort;
|
rlm@0
|
2310 return;
|
rlm@0
|
2311 }
|
rlm@0
|
2312 if(strcasecmp(str, "AL_FORMAT_71CHN16") == 0)
|
rlm@0
|
2313 {
|
rlm@0
|
2314 *chans = DevFmtX71;
|
rlm@0
|
2315 *type = DevFmtShort;
|
rlm@0
|
2316 return;
|
rlm@0
|
2317 }
|
rlm@0
|
2318
|
rlm@0
|
2319 if(strcasecmp(str, "AL_FORMAT_MONO8") == 0)
|
rlm@0
|
2320 {
|
rlm@0
|
2321 *chans = DevFmtMono;
|
rlm@0
|
2322 *type = DevFmtByte;
|
rlm@0
|
2323 return;
|
rlm@0
|
2324 }
|
rlm@0
|
2325 if(strcasecmp(str, "AL_FORMAT_STEREO8") == 0)
|
rlm@0
|
2326 {
|
rlm@0
|
2327 *chans = DevFmtStereo;
|
rlm@0
|
2328 *type = DevFmtByte;
|
rlm@0
|
2329 return;
|
rlm@0
|
2330 }
|
rlm@0
|
2331 if(strcasecmp(str, "AL_FORMAT_QUAD8") == 0)
|
rlm@0
|
2332 {
|
rlm@0
|
2333 *chans = DevFmtQuad;
|
rlm@0
|
2334 *type = DevFmtByte;
|
rlm@0
|
2335 return;
|
rlm@0
|
2336 }
|
rlm@0
|
2337 if(strcasecmp(str, "AL_FORMAT_51CHN8") == 0)
|
rlm@0
|
2338 {
|
rlm@0
|
2339 *chans = DevFmtX51;
|
rlm@0
|
2340 *type = DevFmtByte;
|
rlm@0
|
2341 return;
|
rlm@0
|
2342 }
|
rlm@0
|
2343 if(strcasecmp(str, "AL_FORMAT_61CHN8") == 0)
|
rlm@0
|
2344 {
|
rlm@0
|
2345 *chans = DevFmtX61;
|
rlm@0
|
2346 *type = DevFmtByte;
|
rlm@0
|
2347 return;
|
rlm@0
|
2348 }
|
rlm@0
|
2349 if(strcasecmp(str, "AL_FORMAT_71CHN8") == 0)
|
rlm@0
|
2350 {
|
rlm@0
|
2351 *chans = DevFmtX71;
|
rlm@0
|
2352 *type = DevFmtByte;
|
rlm@0
|
2353 return;
|
rlm@0
|
2354 }
|
rlm@0
|
2355
|
rlm@0
|
2356 ERR("Unknown format: \"%s\"\n", str);
|
rlm@0
|
2357 *chans = DevFmtStereo;
|
rlm@0
|
2358 *type = DevFmtShort;
|
rlm@0
|
2359 }
|
rlm@0
|
2360
|
rlm@0
|
2361 /*
|
rlm@0
|
2362 alcOpenDevice
|
rlm@0
|
2363
|
rlm@0
|
2364 Open the Device specified.
|
rlm@0
|
2365 */
|
rlm@0
|
2366 ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
|
rlm@0
|
2367 {
|
rlm@0
|
2368 const ALCchar *fmt;
|
rlm@0
|
2369 ALCdevice *device;
|
rlm@0
|
2370
|
rlm@0
|
2371 DO_INITCONFIG();
|
rlm@0
|
2372
|
rlm@0
|
2373 if(!PlaybackBackend.name)
|
rlm@0
|
2374 {
|
rlm@0
|
2375 alcSetError(NULL, ALC_INVALID_VALUE);
|
rlm@0
|
2376 return NULL;
|
rlm@0
|
2377 }
|
rlm@0
|
2378
|
rlm@0
|
2379 if(deviceName && (!deviceName[0] || strcasecmp(deviceName, "openal soft") == 0 || strcasecmp(deviceName, "openal-soft") == 0))
|
rlm@0
|
2380 deviceName = NULL;
|
rlm@0
|
2381
|
rlm@0
|
2382 device = calloc(1, sizeof(ALCdevice));
|
rlm@0
|
2383 if(!device)
|
rlm@0
|
2384 {
|
rlm@0
|
2385 alcSetError(NULL, ALC_OUT_OF_MEMORY);
|
rlm@0
|
2386 return NULL;
|
rlm@0
|
2387 }
|
rlm@0
|
2388
|
rlm@0
|
2389 //Validate device
|
rlm@0
|
2390 device->Funcs = &PlaybackBackend.Funcs;
|
rlm@0
|
2391 device->Connected = ALC_TRUE;
|
rlm@0
|
2392 device->IsCaptureDevice = AL_FALSE;
|
rlm@0
|
2393 device->IsLoopbackDevice = AL_FALSE;
|
rlm@0
|
2394 InitializeCriticalSection(&device->Mutex);
|
rlm@0
|
2395 device->LastError = ALC_NO_ERROR;
|
rlm@0
|
2396
|
rlm@0
|
2397 device->Flags = 0;
|
rlm@0
|
2398 device->Bs2b = NULL;
|
rlm@0
|
2399 device->szDeviceName = NULL;
|
rlm@0
|
2400
|
rlm@0
|
2401 device->Contexts = NULL;
|
rlm@0
|
2402 device->NumContexts = 0;
|
rlm@0
|
2403
|
rlm@0
|
2404 InitUIntMap(&device->BufferMap);
|
rlm@0
|
2405 InitUIntMap(&device->EffectMap);
|
rlm@0
|
2406 InitUIntMap(&device->FilterMap);
|
rlm@0
|
2407
|
rlm@0
|
2408 //Set output format
|
rlm@0
|
2409 if(ConfigValueExists(NULL, "frequency"))
|
rlm@0
|
2410 device->Flags |= DEVICE_FREQUENCY_REQUEST;
|
rlm@0
|
2411 device->Frequency = GetConfigValueInt(NULL, "frequency", DEFAULT_OUTPUT_RATE);
|
rlm@0
|
2412 if(device->Frequency < 8000)
|
rlm@0
|
2413 device->Frequency = 8000;
|
rlm@0
|
2414
|
rlm@0
|
2415 if(ConfigValueExists(NULL, "format"))
|
rlm@0
|
2416 device->Flags |= DEVICE_CHANNELS_REQUEST;
|
rlm@0
|
2417 fmt = GetConfigValue(NULL, "format", "AL_FORMAT_STEREO16");
|
rlm@0
|
2418 GetFormatFromString(fmt, &device->FmtChans, &device->FmtType);
|
rlm@0
|
2419
|
rlm@0
|
2420 device->NumUpdates = GetConfigValueInt(NULL, "periods", 4);
|
rlm@0
|
2421 if(device->NumUpdates < 2)
|
rlm@0
|
2422 device->NumUpdates = 4;
|
rlm@0
|
2423
|
rlm@0
|
2424 device->UpdateSize = GetConfigValueInt(NULL, "period_size", 1024);
|
rlm@0
|
2425 if(device->UpdateSize <= 0)
|
rlm@0
|
2426 device->UpdateSize = 1024;
|
rlm@0
|
2427
|
rlm@0
|
2428 device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
|
rlm@0
|
2429 if(device->MaxNoOfSources <= 0)
|
rlm@0
|
2430 device->MaxNoOfSources = 256;
|
rlm@0
|
2431
|
rlm@0
|
2432 device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4);
|
rlm@0
|
2433 if(device->AuxiliaryEffectSlotMax <= 0)
|
rlm@0
|
2434 device->AuxiliaryEffectSlotMax = 4;
|
rlm@0
|
2435
|
rlm@0
|
2436 device->NumStereoSources = 1;
|
rlm@0
|
2437 device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
|
rlm@0
|
2438
|
rlm@0
|
2439 device->NumAuxSends = GetConfigValueInt(NULL, "sends", MAX_SENDS);
|
rlm@0
|
2440 if(device->NumAuxSends > MAX_SENDS)
|
rlm@0
|
2441 device->NumAuxSends = MAX_SENDS;
|
rlm@0
|
2442
|
rlm@0
|
2443 device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
|
rlm@0
|
2444
|
rlm@0
|
2445 // Find a playback device to open
|
rlm@0
|
2446 LockLists();
|
rlm@0
|
2447 if(ALCdevice_OpenPlayback(device, deviceName))
|
rlm@0
|
2448 {
|
rlm@0
|
2449 device->next = g_pDeviceList;
|
rlm@0
|
2450 g_pDeviceList = device;
|
rlm@0
|
2451 g_ulDeviceCount++;
|
rlm@0
|
2452 }
|
rlm@0
|
2453 else
|
rlm@0
|
2454 {
|
rlm@0
|
2455 // No suitable output device found
|
rlm@0
|
2456 DeleteCriticalSection(&device->Mutex);
|
rlm@0
|
2457 free(device);
|
rlm@0
|
2458 device = NULL;
|
rlm@0
|
2459 alcSetError(NULL, ALC_INVALID_VALUE);
|
rlm@0
|
2460 }
|
rlm@0
|
2461 UnlockLists();
|
rlm@0
|
2462
|
rlm@0
|
2463 return device;
|
rlm@0
|
2464 }
|
rlm@0
|
2465
|
rlm@0
|
2466
|
rlm@0
|
2467 /*
|
rlm@0
|
2468 alcCloseDevice
|
rlm@0
|
2469
|
rlm@0
|
2470 Close the specified Device
|
rlm@0
|
2471 */
|
rlm@0
|
2472 ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice)
|
rlm@0
|
2473 {
|
rlm@0
|
2474 ALCdevice **list;
|
rlm@0
|
2475
|
rlm@0
|
2476 LockLists();
|
rlm@0
|
2477 list = &g_pDeviceList;
|
rlm@0
|
2478 while(*list && *list != pDevice)
|
rlm@0
|
2479 list = &(*list)->next;
|
rlm@0
|
2480
|
rlm@0
|
2481 if(!*list || (*list)->IsCaptureDevice)
|
rlm@0
|
2482 {
|
rlm@0
|
2483 alcSetError(*list, ALC_INVALID_DEVICE);
|
rlm@0
|
2484 UnlockLists();
|
rlm@0
|
2485 return ALC_FALSE;
|
rlm@0
|
2486 }
|
rlm@0
|
2487
|
rlm@0
|
2488 *list = (*list)->next;
|
rlm@0
|
2489 g_ulDeviceCount--;
|
rlm@0
|
2490
|
rlm@0
|
2491 UnlockLists();
|
rlm@0
|
2492
|
rlm@0
|
2493 if(pDevice->NumContexts > 0)
|
rlm@0
|
2494 {
|
rlm@0
|
2495 WARN("alcCloseDevice(): destroying %u Context(s)\n", pDevice->NumContexts);
|
rlm@0
|
2496 while(pDevice->NumContexts > 0)
|
rlm@0
|
2497 alcDestroyContext(pDevice->Contexts[0]);
|
rlm@0
|
2498 }
|
rlm@0
|
2499 ALCdevice_ClosePlayback(pDevice);
|
rlm@0
|
2500
|
rlm@0
|
2501 if(pDevice->BufferMap.size > 0)
|
rlm@0
|
2502 {
|
rlm@0
|
2503 WARN("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice->BufferMap.size);
|
rlm@0
|
2504 ReleaseALBuffers(pDevice);
|
rlm@0
|
2505 }
|
rlm@0
|
2506 ResetUIntMap(&pDevice->BufferMap);
|
rlm@0
|
2507
|
rlm@0
|
2508 if(pDevice->EffectMap.size > 0)
|
rlm@0
|
2509 {
|
rlm@0
|
2510 WARN("alcCloseDevice(): deleting %d Effect(s)\n", pDevice->EffectMap.size);
|
rlm@0
|
2511 ReleaseALEffects(pDevice);
|
rlm@0
|
2512 }
|
rlm@0
|
2513 ResetUIntMap(&pDevice->EffectMap);
|
rlm@0
|
2514
|
rlm@0
|
2515 if(pDevice->FilterMap.size > 0)
|
rlm@0
|
2516 {
|
rlm@0
|
2517 WARN("alcCloseDevice(): deleting %d Filter(s)\n", pDevice->FilterMap.size);
|
rlm@0
|
2518 ReleaseALFilters(pDevice);
|
rlm@0
|
2519 }
|
rlm@0
|
2520 ResetUIntMap(&pDevice->FilterMap);
|
rlm@0
|
2521
|
rlm@0
|
2522 free(pDevice->Bs2b);
|
rlm@0
|
2523 pDevice->Bs2b = NULL;
|
rlm@0
|
2524
|
rlm@0
|
2525 free(pDevice->szDeviceName);
|
rlm@0
|
2526 pDevice->szDeviceName = NULL;
|
rlm@0
|
2527
|
rlm@0
|
2528 free(pDevice->Contexts);
|
rlm@0
|
2529 pDevice->Contexts = NULL;
|
rlm@0
|
2530
|
rlm@0
|
2531 DeleteCriticalSection(&pDevice->Mutex);
|
rlm@0
|
2532
|
rlm@0
|
2533 //Release device structure
|
rlm@0
|
2534 memset(pDevice, 0, sizeof(ALCdevice));
|
rlm@0
|
2535 free(pDevice);
|
rlm@0
|
2536
|
rlm@0
|
2537 return ALC_TRUE;
|
rlm@0
|
2538 }
|
rlm@0
|
2539
|
rlm@0
|
2540
|
rlm@0
|
2541 ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(void)
|
rlm@0
|
2542 {
|
rlm@0
|
2543 ALCdevice *device;
|
rlm@0
|
2544
|
rlm@0
|
2545 DO_INITCONFIG();
|
rlm@0
|
2546
|
rlm@0
|
2547 device = calloc(1, sizeof(ALCdevice));
|
rlm@0
|
2548 if(!device)
|
rlm@0
|
2549 {
|
rlm@0
|
2550 alcSetError(NULL, ALC_OUT_OF_MEMORY);
|
rlm@0
|
2551 return NULL;
|
rlm@0
|
2552 }
|
rlm@0
|
2553
|
rlm@0
|
2554 //Validate device
|
rlm@0
|
2555 device->Funcs = &BackendLoopback.Funcs;
|
rlm@0
|
2556 device->Connected = ALC_TRUE;
|
rlm@0
|
2557 device->IsCaptureDevice = AL_FALSE;
|
rlm@0
|
2558 device->IsLoopbackDevice = AL_TRUE;
|
rlm@0
|
2559 InitializeCriticalSection(&device->Mutex);
|
rlm@0
|
2560 device->LastError = ALC_NO_ERROR;
|
rlm@0
|
2561
|
rlm@0
|
2562 device->Flags = 0;
|
rlm@0
|
2563 device->Bs2b = NULL;
|
rlm@0
|
2564 device->szDeviceName = NULL;
|
rlm@0
|
2565
|
rlm@0
|
2566 device->Contexts = NULL;
|
rlm@0
|
2567 device->NumContexts = 0;
|
rlm@0
|
2568
|
rlm@0
|
2569 InitUIntMap(&device->BufferMap);
|
rlm@0
|
2570 InitUIntMap(&device->EffectMap);
|
rlm@0
|
2571 InitUIntMap(&device->FilterMap);
|
rlm@0
|
2572
|
rlm@0
|
2573 //Set output format
|
rlm@0
|
2574 device->Frequency = 44100;
|
rlm@0
|
2575 device->FmtChans = DevFmtStereo;
|
rlm@0
|
2576 device->FmtType = DevFmtShort;
|
rlm@0
|
2577
|
rlm@0
|
2578 device->NumUpdates = 0;
|
rlm@0
|
2579 device->UpdateSize = 0;
|
rlm@0
|
2580
|
rlm@0
|
2581 device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
|
rlm@0
|
2582 if(device->MaxNoOfSources <= 0)
|
rlm@0
|
2583 device->MaxNoOfSources = 256;
|
rlm@0
|
2584
|
rlm@0
|
2585 device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4);
|
rlm@0
|
2586 if(device->AuxiliaryEffectSlotMax <= 0)
|
rlm@0
|
2587 device->AuxiliaryEffectSlotMax = 4;
|
rlm@0
|
2588
|
rlm@0
|
2589 device->NumStereoSources = 1;
|
rlm@0
|
2590 device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
|
rlm@0
|
2591
|
rlm@0
|
2592 device->NumAuxSends = GetConfigValueInt(NULL, "sends", MAX_SENDS);
|
rlm@0
|
2593 if(device->NumAuxSends > MAX_SENDS)
|
rlm@0
|
2594 device->NumAuxSends = MAX_SENDS;
|
rlm@0
|
2595
|
rlm@0
|
2596 device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
|
rlm@0
|
2597
|
rlm@0
|
2598 // Open the "backend"
|
rlm@0
|
2599 LockLists();
|
rlm@0
|
2600 ALCdevice_OpenPlayback(device, "Loopback");
|
rlm@0
|
2601
|
rlm@0
|
2602 device->next = g_pDeviceList;
|
rlm@0
|
2603 g_pDeviceList = device;
|
rlm@0
|
2604 g_ulDeviceCount++;
|
rlm@0
|
2605 UnlockLists();
|
rlm@0
|
2606
|
rlm@0
|
2607 return device;
|
rlm@0
|
2608 }
|
rlm@0
|
2609
|
rlm@0
|
2610 ALC_API ALCboolean ALC_APIENTRY alcIsRenderFormatSupportedSOFT(ALCdevice *device, ALCsizei freq, ALCenum channels, ALCenum type)
|
rlm@0
|
2611 {
|
rlm@0
|
2612 ALCboolean ret = ALC_FALSE;
|
rlm@0
|
2613
|
rlm@0
|
2614 LockLists();
|
rlm@0
|
2615 if(!IsDevice(device) || !device->IsLoopbackDevice)
|
rlm@0
|
2616 alcSetError(device, ALC_INVALID_DEVICE);
|
rlm@0
|
2617 else if(freq <= 0)
|
rlm@0
|
2618 alcSetError(device, ALC_INVALID_VALUE);
|
rlm@0
|
2619 else if(!IsValidALCType(type) || !IsValidALCChannels(channels))
|
rlm@0
|
2620 alcSetError(device, ALC_INVALID_ENUM);
|
rlm@0
|
2621 else
|
rlm@0
|
2622 {
|
rlm@0
|
2623 if(BytesFromDevFmt(type) > 0 && ChannelsFromDevFmt(channels) > 0 &&
|
rlm@0
|
2624 freq >= 8000)
|
rlm@0
|
2625 ret = ALC_TRUE;
|
rlm@0
|
2626 }
|
rlm@0
|
2627 UnlockLists();
|
rlm@0
|
2628
|
rlm@0
|
2629 return ret;
|
rlm@0
|
2630 }
|
rlm@0
|
2631
|
rlm@0
|
2632 ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
|
rlm@0
|
2633 {
|
rlm@0
|
2634 LockLists();
|
rlm@0
|
2635 if(!IsDevice(device) || !device->IsLoopbackDevice)
|
rlm@0
|
2636 alcSetError(device, ALC_INVALID_DEVICE);
|
rlm@0
|
2637 else if(samples < 0 || (samples > 0 && buffer == NULL))
|
rlm@0
|
2638 alcSetError(device, ALC_INVALID_VALUE);
|
rlm@0
|
2639 else
|
rlm@0
|
2640 aluMixData(device, buffer, samples);
|
rlm@0
|
2641 UnlockLists();
|
rlm@0
|
2642 }
|
rlm@0
|
2643
|
rlm@0
|
2644
|
rlm@0
|
2645 static void ReleaseALC(ALCboolean doclose)
|
rlm@0
|
2646 {
|
rlm@0
|
2647 free(alcDeviceList); alcDeviceList = NULL;
|
rlm@0
|
2648 alcDeviceListSize = 0;
|
rlm@0
|
2649 free(alcAllDeviceList); alcAllDeviceList = NULL;
|
rlm@0
|
2650 alcAllDeviceListSize = 0;
|
rlm@0
|
2651 free(alcCaptureDeviceList); alcCaptureDeviceList = NULL;
|
rlm@0
|
2652 alcCaptureDeviceListSize = 0;
|
rlm@0
|
2653
|
rlm@0
|
2654 free(alcDefaultDeviceSpecifier);
|
rlm@0
|
2655 alcDefaultDeviceSpecifier = NULL;
|
rlm@0
|
2656 free(alcDefaultAllDeviceSpecifier);
|
rlm@0
|
2657 alcDefaultAllDeviceSpecifier = NULL;
|
rlm@0
|
2658 free(alcCaptureDefaultDeviceSpecifier);
|
rlm@0
|
2659 alcCaptureDefaultDeviceSpecifier = NULL;
|
rlm@0
|
2660
|
rlm@0
|
2661 if(doclose)
|
rlm@0
|
2662 {
|
rlm@0
|
2663 if(g_ulDeviceCount > 0)
|
rlm@0
|
2664 WARN("ReleaseALC(): closing %u Device%s\n", g_ulDeviceCount, (g_ulDeviceCount>1)?"s":"");
|
rlm@0
|
2665
|
rlm@0
|
2666 while(g_pDeviceList)
|
rlm@0
|
2667 {
|
rlm@0
|
2668 if(g_pDeviceList->IsCaptureDevice)
|
rlm@0
|
2669 alcCaptureCloseDevice(g_pDeviceList);
|
rlm@0
|
2670 else
|
rlm@0
|
2671 alcCloseDevice(g_pDeviceList);
|
rlm@0
|
2672 }
|
rlm@0
|
2673 }
|
rlm@0
|
2674 else
|
rlm@0
|
2675 {
|
rlm@0
|
2676 if(g_ulDeviceCount > 0)
|
rlm@0
|
2677 WARN("ReleaseALC(): %u Device%s not closed\n", g_ulDeviceCount, (g_ulDeviceCount>1)?"s":"");
|
rlm@0
|
2678 }
|
rlm@0
|
2679 }
|
rlm@0
|
2680
|
rlm@0
|
2681 ///////////////////////////////////////////////////////
|