annotate Alc/ALc.c @ 29:cdf320cb5949

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