annotate Alc/ALc.c @ 4:ed256a687dfe

removed very old crufty java program
author Robert McIntyre <rlm@mit.edu>
date Tue, 25 Oct 2011 13:17:37 -0700
parents 96298d83959c
children 99df34265b40
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@0 530 devs = GetConfigValue(NULL, "drivers", "");
rlm@0 531 //printf("these are the devices: %s\n", devs);
rlm@0 532
rlm@0 533 if(devs[0])
rlm@0 534 {
rlm@0 535 int n;
rlm@0 536 size_t len;
rlm@0 537 const char *next = devs;
rlm@0 538 int endlist, delitem;
rlm@0 539
rlm@0 540 i = 0;
rlm@0 541 do {
rlm@0 542 devs = next;
rlm@0 543 //printf("AURELLEM: devs is %s\n",devs);
rlm@0 544 next = strchr(devs, ',');
rlm@0 545
rlm@0 546 delitem = (devs[0] == '-');
rlm@0 547 if(devs[0] == '-') devs++;
rlm@0 548
rlm@0 549 if(!devs[0] || devs[0] == ',')
rlm@0 550 {
rlm@0 551 endlist = 0;
rlm@0 552 continue;
rlm@0 553 }
rlm@0 554 endlist = 1;
rlm@0 555
rlm@0 556 len = (next ? ((size_t)(next-devs)) : strlen(devs));
rlm@0 557 for(n = i;BackendList[n].Init;n++)
rlm@0 558 {
rlm@0 559 //printf("AURELLEM: device-name -- %s\n",BackendList[n].name);
rlm@0 560 if(len == strlen(BackendList[n].name) &&
rlm@0 561 strncmp(BackendList[n].name, devs, len) == 0)
rlm@0 562 {
rlm@0 563 if(delitem)
rlm@0 564 {
rlm@0 565 do {
rlm@0 566 BackendList[n] = BackendList[n+1];
rlm@0 567 ++n;
rlm@0 568 }
rlm@0 569 // this relies on the last entry being terminated by an
rlm@0 570 // entry with all nulls.
rlm@0 571 while(BackendList[n].Init);
rlm@0 572 }
rlm@0 573 else
rlm@0 574 {
rlm@0 575 struct BackendInfo Bkp = BackendList[n];
rlm@0 576 while(n > i)
rlm@0 577 {
rlm@0 578 BackendList[n] = BackendList[n-1];
rlm@0 579 --n;
rlm@0 580 }
rlm@0 581 BackendList[n] = Bkp;
rlm@0 582
rlm@0 583 i++;
rlm@0 584 }
rlm@0 585 break;
rlm@0 586 }
rlm@0 587 }
rlm@0 588 } while(next++);
rlm@0 589
rlm@0 590 if(endlist)
rlm@0 591 {
rlm@0 592 BackendList[i].name = NULL;
rlm@0 593 BackendList[i].Init = NULL;
rlm@0 594 BackendList[i].Deinit = NULL;
rlm@0 595 BackendList[i].Probe = NULL;
rlm@0 596 }
rlm@0 597 }
rlm@0 598
rlm@0 599 for(i = 0;BackendList[i].Init && (!PlaybackBackend.name || !CaptureBackend.name);i++)
rlm@0 600 {
rlm@0 601 if(!BackendList[i].Init(&BackendList[i].Funcs))
rlm@0 602 {
rlm@0 603 WARN("Failed to initialize backend \"%s\"\n", BackendList[i].name);
rlm@0 604 continue;
rlm@0 605 }
rlm@0 606
rlm@0 607 TRACE("Initialized backend \"%s\"\n", BackendList[i].name);
rlm@0 608 if(BackendList[i].Funcs.OpenPlayback && !PlaybackBackend.name)
rlm@0 609 {
rlm@0 610 PlaybackBackend = BackendList[i];
rlm@0 611 TRACE("Added \"%s\" for playback\n", PlaybackBackend.name);
rlm@0 612 }
rlm@0 613 if(BackendList[i].Funcs.OpenCapture && !CaptureBackend.name)
rlm@0 614 {
rlm@0 615 CaptureBackend = BackendList[i];
rlm@0 616 TRACE("Added \"%s\" for capture\n", CaptureBackend.name);
rlm@0 617 }
rlm@0 618 }
rlm@0 619 BackendLoopback.Init(&BackendLoopback.Funcs);
rlm@0 620
rlm@0 621 str = GetConfigValue(NULL, "excludefx", "");
rlm@0 622 if(str[0])
rlm@0 623 {
rlm@0 624 size_t len;
rlm@0 625 const char *next = str;
rlm@0 626
rlm@0 627 do {
rlm@0 628 str = next;
rlm@0 629 next = strchr(str, ',');
rlm@0 630
rlm@0 631 if(!str[0] || next == str)
rlm@0 632 continue;
rlm@0 633
rlm@0 634 len = (next ? ((size_t)(next-str)) : strlen(str));
rlm@0 635 for(n = 0;EffectList[n].name;n++)
rlm@0 636 {
rlm@0 637 if(len == strlen(EffectList[n].name) &&
rlm@0 638 strncmp(EffectList[n].name, str, len) == 0)
rlm@0 639 DisabledEffects[EffectList[n].type] = AL_TRUE;
rlm@0 640 }
rlm@0 641 } while(next++);
rlm@0 642 }
rlm@0 643 }
rlm@0 644
rlm@0 645
rlm@0 646 static void ProbeList(ALCchar **list, size_t *listsize, enum DevProbe type)
rlm@0 647 {
rlm@0 648 free(*list);
rlm@0 649 *list = NULL;
rlm@0 650 *listsize = 0;
rlm@0 651
rlm@0 652 DO_INITCONFIG();
rlm@0 653 if(type == CAPTURE_DEVICE_PROBE)
rlm@0 654 CaptureBackend.Probe(type);
rlm@0 655 else
rlm@0 656 PlaybackBackend.Probe(type);
rlm@0 657 }
rlm@0 658
rlm@0 659 static void ProbeDeviceList(void)
rlm@0 660 { ProbeList(&alcDeviceList, &alcDeviceListSize, DEVICE_PROBE); }
rlm@0 661 static void ProbeAllDeviceList(void)
rlm@0 662 { ProbeList(&alcAllDeviceList, &alcAllDeviceListSize, ALL_DEVICE_PROBE); }
rlm@0 663 static void ProbeCaptureDeviceList(void)
rlm@0 664 { ProbeList(&alcCaptureDeviceList, &alcCaptureDeviceListSize, CAPTURE_DEVICE_PROBE); }
rlm@0 665
rlm@0 666
rlm@0 667 static void AppendList(const ALCchar *name, ALCchar **List, size_t *ListSize)
rlm@0 668 {
rlm@0 669 size_t len = strlen(name);
rlm@0 670 void *temp;
rlm@0 671
rlm@0 672 if(len == 0)
rlm@0 673 return;
rlm@0 674
rlm@0 675 temp = realloc(*List, (*ListSize) + len + 2);
rlm@0 676 if(!temp)
rlm@0 677 {
rlm@0 678 ERR("Realloc failed to add %s!\n", name);
rlm@0 679 return;
rlm@0 680 }
rlm@0 681 *List = temp;
rlm@0 682
rlm@0 683 memcpy((*List)+(*ListSize), name, len+1);
rlm@0 684 *ListSize += len+1;
rlm@0 685 (*List)[*ListSize] = 0;
rlm@0 686 }
rlm@0 687
rlm@0 688 #define DECL_APPEND_LIST_FUNC(type) \
rlm@0 689 void Append##type##List(const ALCchar *name) \
rlm@0 690 { AppendList(name, &alc##type##List, &alc##type##ListSize); }
rlm@0 691
rlm@0 692 DECL_APPEND_LIST_FUNC(Device)
rlm@0 693 DECL_APPEND_LIST_FUNC(AllDevice)
rlm@0 694 DECL_APPEND_LIST_FUNC(CaptureDevice)
rlm@0 695
rlm@0 696 #undef DECL_APPEND_LIST_FUNC
rlm@0 697
rlm@0 698
rlm@0 699 /* Sets the default channel order used by most non-WaveFormatEx-based APIs */
rlm@0 700 void SetDefaultChannelOrder(ALCdevice *device)
rlm@0 701 {
rlm@0 702 switch(device->FmtChans)
rlm@0 703 {
rlm@0 704 case DevFmtX51: device->DevChannels[0] = FRONT_LEFT;
rlm@0 705 device->DevChannels[1] = FRONT_RIGHT;
rlm@0 706 device->DevChannels[2] = BACK_LEFT;
rlm@0 707 device->DevChannels[3] = BACK_RIGHT;
rlm@0 708 device->DevChannels[4] = FRONT_CENTER;
rlm@0 709 device->DevChannels[5] = LFE;
rlm@0 710 return;
rlm@0 711
rlm@0 712 case DevFmtX71: device->DevChannels[0] = FRONT_LEFT;
rlm@0 713 device->DevChannels[1] = FRONT_RIGHT;
rlm@0 714 device->DevChannels[2] = BACK_LEFT;
rlm@0 715 device->DevChannels[3] = BACK_RIGHT;
rlm@0 716 device->DevChannels[4] = FRONT_CENTER;
rlm@0 717 device->DevChannels[5] = LFE;
rlm@0 718 device->DevChannels[6] = SIDE_LEFT;
rlm@0 719 device->DevChannels[7] = SIDE_RIGHT;
rlm@0 720 return;
rlm@0 721
rlm@0 722 /* Same as WFX order */
rlm@0 723 case DevFmtMono:
rlm@0 724 case DevFmtStereo:
rlm@0 725 case DevFmtQuad:
rlm@0 726 case DevFmtX51Side:
rlm@0 727 case DevFmtX61:
rlm@0 728 break;
rlm@0 729 }
rlm@0 730 SetDefaultWFXChannelOrder(device);
rlm@0 731 }
rlm@0 732 /* Sets the default order used by WaveFormatEx */
rlm@0 733 void SetDefaultWFXChannelOrder(ALCdevice *device)
rlm@0 734 {
rlm@0 735 switch(device->FmtChans)
rlm@0 736 {
rlm@0 737 case DevFmtMono: device->DevChannels[0] = FRONT_CENTER; break;
rlm@0 738
rlm@0 739 case DevFmtStereo: device->DevChannels[0] = FRONT_LEFT;
rlm@0 740 device->DevChannels[1] = FRONT_RIGHT; break;
rlm@0 741
rlm@0 742 case DevFmtQuad: device->DevChannels[0] = FRONT_LEFT;
rlm@0 743 device->DevChannels[1] = FRONT_RIGHT;
rlm@0 744 device->DevChannels[2] = BACK_LEFT;
rlm@0 745 device->DevChannels[3] = BACK_RIGHT; break;
rlm@0 746
rlm@0 747 case DevFmtX51: device->DevChannels[0] = FRONT_LEFT;
rlm@0 748 device->DevChannels[1] = FRONT_RIGHT;
rlm@0 749 device->DevChannels[2] = FRONT_CENTER;
rlm@0 750 device->DevChannels[3] = LFE;
rlm@0 751 device->DevChannels[4] = BACK_LEFT;
rlm@0 752 device->DevChannels[5] = BACK_RIGHT; break;
rlm@0 753
rlm@0 754 case DevFmtX51Side: device->DevChannels[0] = FRONT_LEFT;
rlm@0 755 device->DevChannels[1] = FRONT_RIGHT;
rlm@0 756 device->DevChannels[2] = FRONT_CENTER;
rlm@0 757 device->DevChannels[3] = LFE;
rlm@0 758 device->DevChannels[4] = SIDE_LEFT;
rlm@0 759 device->DevChannels[5] = SIDE_RIGHT; break;
rlm@0 760
rlm@0 761 case DevFmtX61: device->DevChannels[0] = FRONT_LEFT;
rlm@0 762 device->DevChannels[1] = FRONT_RIGHT;
rlm@0 763 device->DevChannels[2] = FRONT_CENTER;
rlm@0 764 device->DevChannels[3] = LFE;
rlm@0 765 device->DevChannels[4] = BACK_CENTER;
rlm@0 766 device->DevChannels[5] = SIDE_LEFT;
rlm@0 767 device->DevChannels[6] = SIDE_RIGHT; break;
rlm@0 768
rlm@0 769 case DevFmtX71: device->DevChannels[0] = FRONT_LEFT;
rlm@0 770 device->DevChannels[1] = FRONT_RIGHT;
rlm@0 771 device->DevChannels[2] = FRONT_CENTER;
rlm@0 772 device->DevChannels[3] = LFE;
rlm@0 773 device->DevChannels[4] = BACK_LEFT;
rlm@0 774 device->DevChannels[5] = BACK_RIGHT;
rlm@0 775 device->DevChannels[6] = SIDE_LEFT;
rlm@0 776 device->DevChannels[7] = SIDE_RIGHT; break;
rlm@0 777 }
rlm@0 778 }
rlm@0 779
rlm@0 780
rlm@0 781 const ALCchar *DevFmtTypeString(enum DevFmtType type)
rlm@0 782 {
rlm@0 783 switch(type)
rlm@0 784 {
rlm@0 785 case DevFmtByte: return "Signed Byte";
rlm@0 786 case DevFmtUByte: return "Unsigned Byte";
rlm@0 787 case DevFmtShort: return "Signed Short";
rlm@0 788 case DevFmtUShort: return "Unsigned Short";
rlm@0 789 case DevFmtFloat: return "Float";
rlm@0 790 }
rlm@0 791 return "(unknown type)";
rlm@0 792 }
rlm@0 793 const ALCchar *DevFmtChannelsString(enum DevFmtChannels chans)
rlm@0 794 {
rlm@0 795 switch(chans)
rlm@0 796 {
rlm@0 797 case DevFmtMono: return "Mono";
rlm@0 798 case DevFmtStereo: return "Stereo";
rlm@0 799 case DevFmtQuad: return "Quadraphonic";
rlm@0 800 case DevFmtX51: return "5.1 Surround";
rlm@0 801 case DevFmtX51Side: return "5.1 Side";
rlm@0 802 case DevFmtX61: return "6.1 Surround";
rlm@0 803 case DevFmtX71: return "7.1 Surround";
rlm@0 804 }
rlm@0 805 return "(unknown channels)";
rlm@0 806 }
rlm@0 807
rlm@0 808 ALuint BytesFromDevFmt(enum DevFmtType type)
rlm@0 809 {
rlm@0 810 switch(type)
rlm@0 811 {
rlm@0 812 case DevFmtByte: return sizeof(ALbyte);
rlm@0 813 case DevFmtUByte: return sizeof(ALubyte);
rlm@0 814 case DevFmtShort: return sizeof(ALshort);
rlm@0 815 case DevFmtUShort: return sizeof(ALushort);
rlm@0 816 case DevFmtFloat: return sizeof(ALfloat);
rlm@0 817 }
rlm@0 818 return 0;
rlm@0 819 }
rlm@0 820 ALuint ChannelsFromDevFmt(enum DevFmtChannels chans)
rlm@0 821 {
rlm@0 822 switch(chans)
rlm@0 823 {
rlm@0 824 case DevFmtMono: return 1;
rlm@0 825 case DevFmtStereo: return 2;
rlm@0 826 case DevFmtQuad: return 4;
rlm@0 827 case DevFmtX51: return 6;
rlm@0 828 case DevFmtX51Side: return 6;
rlm@0 829 case DevFmtX61: return 7;
rlm@0 830 case DevFmtX71: return 8;
rlm@0 831 }
rlm@0 832 return 0;
rlm@0 833 }
rlm@0 834 ALboolean DecomposeDevFormat(ALenum format, enum DevFmtChannels *chans,
rlm@0 835 enum DevFmtType *type)
rlm@0 836 {
rlm@0 837 switch(format)
rlm@0 838 {
rlm@0 839 case AL_FORMAT_MONO8:
rlm@0 840 *chans = DevFmtMono;
rlm@0 841 *type = DevFmtUByte;
rlm@0 842 return AL_TRUE;
rlm@0 843 case AL_FORMAT_MONO16:
rlm@0 844 *chans = DevFmtMono;
rlm@0 845 *type = DevFmtShort;
rlm@0 846 return AL_TRUE;
rlm@0 847 case AL_FORMAT_MONO_FLOAT32:
rlm@0 848 *chans = DevFmtMono;
rlm@0 849 *type = DevFmtFloat;
rlm@0 850 return AL_TRUE;
rlm@0 851 case AL_FORMAT_STEREO8:
rlm@0 852 *chans = DevFmtStereo;
rlm@0 853 *type = DevFmtUByte;
rlm@0 854 return AL_TRUE;
rlm@0 855 case AL_FORMAT_STEREO16:
rlm@0 856 *chans = DevFmtStereo;
rlm@0 857 *type = DevFmtShort;
rlm@0 858 return AL_TRUE;
rlm@0 859 case AL_FORMAT_STEREO_FLOAT32:
rlm@0 860 *chans = DevFmtStereo;
rlm@0 861 *type = DevFmtFloat;
rlm@0 862 return AL_TRUE;
rlm@0 863 case AL_FORMAT_QUAD8:
rlm@0 864 *chans = DevFmtQuad;
rlm@0 865 *type = DevFmtUByte;
rlm@0 866 return AL_TRUE;
rlm@0 867 case AL_FORMAT_QUAD16:
rlm@0 868 *chans = DevFmtQuad;
rlm@0 869 *type = DevFmtShort;
rlm@0 870 return AL_TRUE;
rlm@0 871 case AL_FORMAT_QUAD32:
rlm@0 872 *chans = DevFmtQuad;
rlm@0 873 *type = DevFmtFloat;
rlm@0 874 return AL_TRUE;
rlm@0 875 case AL_FORMAT_51CHN8:
rlm@0 876 *chans = DevFmtX51;
rlm@0 877 *type = DevFmtUByte;
rlm@0 878 return AL_TRUE;
rlm@0 879 case AL_FORMAT_51CHN16:
rlm@0 880 *chans = DevFmtX51;
rlm@0 881 *type = DevFmtShort;
rlm@0 882 return AL_TRUE;
rlm@0 883 case AL_FORMAT_51CHN32:
rlm@0 884 *chans = DevFmtX51;
rlm@0 885 *type = DevFmtFloat;
rlm@0 886 return AL_TRUE;
rlm@0 887 case AL_FORMAT_61CHN8:
rlm@0 888 *chans = DevFmtX61;
rlm@0 889 *type = DevFmtUByte;
rlm@0 890 return AL_TRUE;
rlm@0 891 case AL_FORMAT_61CHN16:
rlm@0 892 *chans = DevFmtX61;
rlm@0 893 *type = DevFmtShort;
rlm@0 894 return AL_TRUE;
rlm@0 895 case AL_FORMAT_61CHN32:
rlm@0 896 *chans = DevFmtX61;
rlm@0 897 *type = DevFmtFloat;
rlm@0 898 return AL_TRUE;
rlm@0 899 case AL_FORMAT_71CHN8:
rlm@0 900 *chans = DevFmtX71;
rlm@0 901 *type = DevFmtUByte;
rlm@0 902 return AL_TRUE;
rlm@0 903 case AL_FORMAT_71CHN16:
rlm@0 904 *chans = DevFmtX71;
rlm@0 905 *type = DevFmtShort;
rlm@0 906 return AL_TRUE;
rlm@0 907 case AL_FORMAT_71CHN32:
rlm@0 908 *chans = DevFmtX71;
rlm@0 909 *type = DevFmtFloat;
rlm@0 910 return AL_TRUE;
rlm@0 911 }
rlm@0 912 return AL_FALSE;
rlm@0 913 }
rlm@0 914
rlm@0 915 static ALCboolean IsValidALCType(ALCenum type)
rlm@0 916 {
rlm@0 917 switch(type)
rlm@0 918 {
rlm@0 919 case ALC_BYTE:
rlm@0 920 case ALC_UNSIGNED_BYTE:
rlm@0 921 case ALC_SHORT:
rlm@0 922 case ALC_UNSIGNED_SHORT:
rlm@0 923 case ALC_INT:
rlm@0 924 case ALC_UNSIGNED_INT:
rlm@0 925 case ALC_FLOAT:
rlm@0 926 return ALC_TRUE;
rlm@0 927 }
rlm@0 928 return ALC_FALSE;
rlm@0 929 }
rlm@0 930
rlm@0 931 static ALCboolean IsValidALCChannels(ALCenum channels)
rlm@0 932 {
rlm@0 933 switch(channels)
rlm@0 934 {
rlm@0 935 case ALC_MONO:
rlm@0 936 case ALC_STEREO:
rlm@0 937 case ALC_QUAD:
rlm@0 938 case ALC_5POINT1:
rlm@0 939 case ALC_6POINT1:
rlm@0 940 case ALC_7POINT1:
rlm@0 941 return ALC_TRUE;
rlm@0 942 }
rlm@0 943 return ALC_FALSE;
rlm@0 944 }
rlm@0 945
rlm@0 946
rlm@0 947 static void LockLists(void)
rlm@0 948 {
rlm@0 949 EnterCriticalSection(&ListLock);
rlm@0 950 }
rlm@0 951
rlm@0 952 static void UnlockLists(void)
rlm@0 953 {
rlm@0 954 LeaveCriticalSection(&ListLock);
rlm@0 955 }
rlm@0 956
rlm@0 957 /*
rlm@0 958 IsDevice
rlm@0 959
rlm@0 960 Check pDevice is a valid Device pointer
rlm@0 961 */
rlm@0 962 static ALCboolean IsDevice(ALCdevice *pDevice)
rlm@0 963 {
rlm@0 964 ALCdevice *pTempDevice;
rlm@0 965
rlm@0 966 pTempDevice = g_pDeviceList;
rlm@0 967 while(pTempDevice && pTempDevice != pDevice)
rlm@0 968 pTempDevice = pTempDevice->next;
rlm@0 969
rlm@0 970 return (pTempDevice ? ALC_TRUE : ALC_FALSE);
rlm@0 971 }
rlm@0 972
rlm@0 973 /*
rlm@0 974 IsContext
rlm@0 975
rlm@0 976 Check pContext is a valid Context pointer
rlm@0 977 */
rlm@0 978 static ALCboolean IsContext(ALCcontext *pContext)
rlm@0 979 {
rlm@0 980 ALCcontext *pTempContext;
rlm@0 981
rlm@0 982 pTempContext = g_pContextList;
rlm@0 983 while (pTempContext && pTempContext != pContext)
rlm@0 984 pTempContext = pTempContext->next;
rlm@0 985
rlm@0 986 return (pTempContext ? ALC_TRUE : ALC_FALSE);
rlm@0 987 }
rlm@0 988
rlm@0 989
rlm@0 990 /*
rlm@0 991 alcSetError
rlm@0 992
rlm@0 993 Store latest ALC Error
rlm@0 994 */
rlm@0 995 ALCvoid alcSetError(ALCdevice *device, ALenum errorCode)
rlm@0 996 {
rlm@0 997 LockLists();
rlm@0 998 if(IsDevice(device))
rlm@0 999 device->LastError = errorCode;
rlm@0 1000 else
rlm@0 1001 g_eLastNullDeviceError = errorCode;
rlm@0 1002 UnlockLists();
rlm@0 1003 }
rlm@0 1004
rlm@0 1005
rlm@0 1006 /* UpdateDeviceParams:
rlm@0 1007 *
rlm@0 1008 * Updates device parameters according to the attribute list.
rlm@0 1009 */
rlm@0 1010 static ALCboolean UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
rlm@0 1011 {
rlm@0 1012 ALuint i;
rlm@0 1013
rlm@0 1014 // Check for attributes
rlm@0 1015 if(attrList && attrList[0])
rlm@0 1016 {
rlm@0 1017 ALCuint freq, numMono, numStereo, numSends;
rlm@0 1018 enum DevFmtChannels schans;
rlm@0 1019 enum DevFmtType stype;
rlm@0 1020 ALuint attrIdx;
rlm@0 1021
rlm@0 1022 // If a context is already running on the device, stop playback so the
rlm@0 1023 // device attributes can be updated
rlm@0 1024 if((device->Flags&DEVICE_RUNNING))
rlm@0 1025 ALCdevice_StopPlayback(device);
rlm@0 1026 device->Flags &= ~DEVICE_RUNNING;
rlm@0 1027
rlm@0 1028 freq = device->Frequency;
rlm@0 1029 schans = device->FmtChans;
rlm@0 1030 stype = device->FmtType;
rlm@0 1031 numMono = device->NumMonoSources;
rlm@0 1032 numStereo = device->NumStereoSources;
rlm@0 1033 numSends = device->NumAuxSends;
rlm@0 1034
rlm@0 1035 freq = GetConfigValueInt(NULL, "frequency", freq);
rlm@0 1036 if(freq < 8000) freq = 8000;
rlm@0 1037
rlm@0 1038 attrIdx = 0;
rlm@0 1039 while(attrList[attrIdx])
rlm@0 1040 {
rlm@0 1041 if(attrList[attrIdx] == ALC_FORMAT_CHANNELS_SOFT &&
rlm@0 1042 device->IsLoopbackDevice)
rlm@0 1043 {
rlm@0 1044 ALCint val = attrList[attrIdx + 1];
rlm@0 1045 if(!IsValidALCChannels(val) || !ChannelsFromDevFmt(val))
rlm@0 1046 {
rlm@0 1047 alcSetError(device, ALC_INVALID_VALUE);
rlm@0 1048 return ALC_FALSE;
rlm@0 1049 }
rlm@0 1050 schans = val;
rlm@0 1051 }
rlm@0 1052
rlm@0 1053 if(attrList[attrIdx] == ALC_FORMAT_TYPE_SOFT &&
rlm@0 1054 device->IsLoopbackDevice)
rlm@0 1055 {
rlm@0 1056 ALCint val = attrList[attrIdx + 1];
rlm@0 1057 if(!IsValidALCType(val) || !BytesFromDevFmt(val))
rlm@0 1058 {
rlm@0 1059 alcSetError(device, ALC_INVALID_VALUE);
rlm@0 1060 return ALC_FALSE;
rlm@0 1061 }
rlm@0 1062 stype = val;
rlm@0 1063 }
rlm@0 1064
rlm@0 1065 if(attrList[attrIdx] == ALC_FREQUENCY)
rlm@0 1066 {
rlm@0 1067 if(device->IsLoopbackDevice)
rlm@0 1068 {
rlm@0 1069 freq = attrList[attrIdx + 1];
rlm@0 1070 if(freq < 8000)
rlm@0 1071 {
rlm@0 1072 alcSetError(device, ALC_INVALID_VALUE);
rlm@0 1073 return ALC_FALSE;
rlm@0 1074 }
rlm@0 1075 }
rlm@0 1076 else if(!ConfigValueExists(NULL, "frequency"))
rlm@0 1077 {
rlm@0 1078 freq = attrList[attrIdx + 1];
rlm@0 1079 if(freq < 8000) freq = 8000;
rlm@0 1080 device->Flags |= DEVICE_FREQUENCY_REQUEST;
rlm@0 1081 }
rlm@0 1082 }
rlm@0 1083
rlm@0 1084 if(attrList[attrIdx] == ALC_STEREO_SOURCES)
rlm@0 1085 {
rlm@0 1086 numStereo = attrList[attrIdx + 1];
rlm@0 1087 if(numStereo > device->MaxNoOfSources)
rlm@0 1088 numStereo = device->MaxNoOfSources;
rlm@0 1089
rlm@0 1090 numMono = device->MaxNoOfSources - numStereo;
rlm@0 1091 }
rlm@0 1092
rlm@0 1093 if(attrList[attrIdx] == ALC_MAX_AUXILIARY_SENDS &&
rlm@0 1094 !ConfigValueExists(NULL, "sends"))
rlm@0 1095 {
rlm@0 1096 numSends = attrList[attrIdx + 1];
rlm@0 1097 if(numSends > MAX_SENDS)
rlm@0 1098 numSends = MAX_SENDS;
rlm@0 1099 }
rlm@0 1100
rlm@0 1101 attrIdx += 2;
rlm@0 1102 }
rlm@0 1103
rlm@0 1104 device->UpdateSize = (ALuint64)device->UpdateSize * freq /
rlm@0 1105 device->Frequency;
rlm@0 1106
rlm@0 1107 device->Frequency = freq;
rlm@0 1108 device->FmtChans = schans;
rlm@0 1109 device->FmtType = stype;
rlm@0 1110 device->NumMonoSources = numMono;
rlm@0 1111 device->NumStereoSources = numStereo;
rlm@0 1112 device->NumAuxSends = numSends;
rlm@0 1113 }
rlm@0 1114
rlm@0 1115 if((device->Flags&DEVICE_RUNNING))
rlm@0 1116 return ALC_TRUE;
rlm@0 1117
rlm@0 1118 LockDevice(device);
rlm@0 1119 TRACE("Format pre-setup: %s%s, %s, %uhz%s, %u update size x%d\n",
rlm@0 1120 DevFmtChannelsString(device->FmtChans),
rlm@0 1121 (device->Flags&DEVICE_CHANNELS_REQUEST)?" (requested)":"",
rlm@0 1122 DevFmtTypeString(device->FmtType), device->Frequency,
rlm@0 1123 (device->Flags&DEVICE_FREQUENCY_REQUEST)?" (requested)":"",
rlm@0 1124 device->UpdateSize, device->NumUpdates);
rlm@0 1125 if(ALCdevice_ResetPlayback(device) == ALC_FALSE)
rlm@0 1126 {
rlm@0 1127 UnlockDevice(device);
rlm@0 1128 return ALC_FALSE;
rlm@0 1129 }
rlm@0 1130 device->Flags |= DEVICE_RUNNING;
rlm@0 1131 TRACE("Format post-setup: %s%s, %s, %uhz%s, %u update size x%d\n",
rlm@0 1132 DevFmtChannelsString(device->FmtChans),
rlm@0 1133 (device->Flags&DEVICE_CHANNELS_REQUEST)?" (requested)":"",
rlm@0 1134 DevFmtTypeString(device->FmtType), device->Frequency,
rlm@0 1135 (device->Flags&DEVICE_FREQUENCY_REQUEST)?" (requested)":"",
rlm@0 1136 device->UpdateSize, device->NumUpdates);
rlm@0 1137
rlm@0 1138 aluInitPanning(device);
rlm@0 1139
rlm@0 1140 for(i = 0;i < MAXCHANNELS;i++)
rlm@0 1141 {
rlm@0 1142 device->ClickRemoval[i] = 0.0f;
rlm@0 1143 device->PendingClicks[i] = 0.0f;
rlm@0 1144 }
rlm@0 1145
rlm@0 1146 if(!device->IsLoopbackDevice && GetConfigValueBool(NULL, "hrtf", AL_FALSE))
rlm@0 1147 device->Flags |= DEVICE_USE_HRTF;
rlm@0 1148 if((device->Flags&DEVICE_USE_HRTF) && !IsHrtfCompatible(device))
rlm@0 1149 device->Flags &= ~DEVICE_USE_HRTF;
rlm@0 1150 TRACE("HRTF %s\n", (device->Flags&DEVICE_USE_HRTF)?"enabled":"disabled");
rlm@0 1151
rlm@0 1152 if(!(device->Flags&DEVICE_USE_HRTF) && device->Bs2bLevel > 0 && device->Bs2bLevel <= 6)
rlm@0 1153 {
rlm@0 1154 if(!device->Bs2b)
rlm@0 1155 {
rlm@0 1156 device->Bs2b = calloc(1, sizeof(*device->Bs2b));
rlm@0 1157 bs2b_clear(device->Bs2b);
rlm@0 1158 }
rlm@0 1159 bs2b_set_srate(device->Bs2b, device->Frequency);
rlm@0 1160 bs2b_set_level(device->Bs2b, device->Bs2bLevel);
rlm@0 1161 TRACE("BS2B level %d\n", device->Bs2bLevel);
rlm@0 1162 }
rlm@0 1163 else
rlm@0 1164 {
rlm@0 1165 free(device->Bs2b);
rlm@0 1166 device->Bs2b = NULL;
rlm@0 1167 TRACE("BS2B disabled\n");
rlm@0 1168 }
rlm@0 1169
rlm@0 1170 device->Flags &= ~DEVICE_DUPLICATE_STEREO;
rlm@0 1171 switch(device->FmtChans)
rlm@0 1172 {
rlm@0 1173 case DevFmtMono:
rlm@0 1174 case DevFmtStereo:
rlm@0 1175 break;
rlm@0 1176 case DevFmtQuad:
rlm@0 1177 case DevFmtX51:
rlm@0 1178 case DevFmtX51Side:
rlm@0 1179 case DevFmtX61:
rlm@0 1180 case DevFmtX71:
rlm@0 1181 if(GetConfigValueBool(NULL, "stereodup", AL_TRUE))
rlm@0 1182 device->Flags |= DEVICE_DUPLICATE_STEREO;
rlm@0 1183 break;
rlm@0 1184 }
rlm@0 1185 TRACE("Stereo duplication %s\n", (device->Flags&DEVICE_DUPLICATE_STEREO)?"enabled":"disabled");
rlm@0 1186
rlm@0 1187 for(i = 0;i < device->NumContexts;i++)
rlm@0 1188 {
rlm@0 1189 ALCcontext *context = device->Contexts[i];
rlm@0 1190 ALsizei pos;
rlm@0 1191
rlm@0 1192 context->UpdateSources = AL_FALSE;
rlm@0 1193 for(pos = 0;pos < context->EffectSlotMap.size;pos++)
rlm@0 1194 {
rlm@0 1195 ALeffectslot *slot = context->EffectSlotMap.array[pos].value;
rlm@0 1196
rlm@0 1197 if(ALEffect_DeviceUpdate(slot->EffectState, device) == AL_FALSE)
rlm@0 1198 {
rlm@0 1199 UnlockDevice(device);
rlm@0 1200 ALCdevice_StopPlayback(device);
rlm@0 1201 device->Flags &= ~DEVICE_RUNNING;
rlm@0 1202 return ALC_FALSE;
rlm@0 1203 }
rlm@0 1204 slot->NeedsUpdate = AL_FALSE;
rlm@0 1205 ALEffect_Update(slot->EffectState, context, slot);
rlm@0 1206 }
rlm@0 1207
rlm@0 1208 for(pos = 0;pos < context->SourceMap.size;pos++)
rlm@0 1209 {
rlm@0 1210 ALsource *source = context->SourceMap.array[pos].value;
rlm@0 1211 ALuint s = device->NumAuxSends;
rlm@0 1212 while(s < MAX_SENDS)
rlm@0 1213 {
rlm@0 1214 if(source->Send[s].Slot)
rlm@0 1215 source->Send[s].Slot->refcount--;
rlm@0 1216 source->Send[s].Slot = NULL;
rlm@0 1217 source->Send[s].WetFilter.type = 0;
rlm@0 1218 source->Send[s].WetFilter.filter = 0;
rlm@0 1219 s++;
rlm@0 1220 }
rlm@0 1221 source->NeedsUpdate = AL_FALSE;
rlm@0 1222 ALsource_Update(source, context);
rlm@0 1223 }
rlm@0 1224 }
rlm@0 1225 UnlockDevice(device);
rlm@0 1226
rlm@0 1227 return ALC_TRUE;
rlm@0 1228 }
rlm@0 1229
rlm@0 1230
rlm@0 1231 ALCvoid LockDevice(ALCdevice *device)
rlm@0 1232 {
rlm@0 1233 EnterCriticalSection(&device->Mutex);
rlm@0 1234 }
rlm@0 1235
rlm@0 1236 ALCvoid UnlockDevice(ALCdevice *device)
rlm@0 1237 {
rlm@0 1238 LeaveCriticalSection(&device->Mutex);
rlm@0 1239 }
rlm@0 1240
rlm@0 1241 /*
rlm@0 1242 LockContext
rlm@0 1243
rlm@0 1244 Thread-safe entry
rlm@0 1245 */
rlm@0 1246 ALCvoid LockContext(ALCcontext *context)
rlm@0 1247 {
rlm@0 1248 EnterCriticalSection(&context->Device->Mutex);
rlm@0 1249 }
rlm@0 1250
rlm@0 1251
rlm@0 1252 /*
rlm@0 1253 UnlockContext
rlm@0 1254
rlm@0 1255 Thread-safe exit
rlm@0 1256 */
rlm@0 1257 ALCvoid UnlockContext(ALCcontext *context)
rlm@0 1258 {
rlm@0 1259 LeaveCriticalSection(&context->Device->Mutex);
rlm@0 1260 }
rlm@0 1261
rlm@0 1262
rlm@0 1263 /*
rlm@0 1264 GetLockedContext
rlm@0 1265
rlm@0 1266 Returns the currently active Context, in a locked state
rlm@0 1267 */
rlm@0 1268 ALCcontext *GetLockedContext(void)
rlm@0 1269 {
rlm@0 1270 ALCcontext *pContext = NULL;
rlm@0 1271
rlm@0 1272 LockLists();
rlm@0 1273
rlm@0 1274 pContext = tls_get(LocalContext);
rlm@0 1275 if(pContext && !IsContext(pContext))
rlm@0 1276 {
rlm@0 1277 tls_set(LocalContext, NULL);
rlm@0 1278 pContext = NULL;
rlm@0 1279 }
rlm@0 1280 if(!pContext)
rlm@0 1281 pContext = GlobalContext;
rlm@0 1282 if(pContext)
rlm@0 1283 LockContext(pContext);
rlm@0 1284
rlm@0 1285 UnlockLists();
rlm@0 1286
rlm@0 1287 return pContext;
rlm@0 1288 }
rlm@0 1289
rlm@0 1290
rlm@0 1291 /*
rlm@0 1292 InitContext
rlm@0 1293
rlm@0 1294 Initialize Context variables
rlm@0 1295 */
rlm@0 1296 static ALvoid InitContext(ALCcontext *pContext)
rlm@0 1297 {
rlm@0 1298 //Initialise listener
rlm@0 1299 pContext->Listener.Gain = 1.0f;
rlm@0 1300 pContext->Listener.MetersPerUnit = 1.0f;
rlm@0 1301 pContext->Listener.Position[0] = 0.0f;
rlm@0 1302 pContext->Listener.Position[1] = 0.0f;
rlm@0 1303 pContext->Listener.Position[2] = 0.0f;
rlm@0 1304 pContext->Listener.Velocity[0] = 0.0f;
rlm@0 1305 pContext->Listener.Velocity[1] = 0.0f;
rlm@0 1306 pContext->Listener.Velocity[2] = 0.0f;
rlm@0 1307 pContext->Listener.Forward[0] = 0.0f;
rlm@0 1308 pContext->Listener.Forward[1] = 0.0f;
rlm@0 1309 pContext->Listener.Forward[2] = -1.0f;
rlm@0 1310 pContext->Listener.Up[0] = 0.0f;
rlm@0 1311 pContext->Listener.Up[1] = 1.0f;
rlm@0 1312 pContext->Listener.Up[2] = 0.0f;
rlm@0 1313
rlm@0 1314 //Validate pContext
rlm@0 1315 pContext->LastError = AL_NO_ERROR;
rlm@0 1316 pContext->UpdateSources = AL_FALSE;
rlm@0 1317 pContext->ActiveSourceCount = 0;
rlm@0 1318 InitUIntMap(&pContext->SourceMap);
rlm@0 1319 InitUIntMap(&pContext->EffectSlotMap);
rlm@0 1320
rlm@0 1321 //Set globals
rlm@0 1322 pContext->DistanceModel = AL_INVERSE_DISTANCE_CLAMPED;
rlm@0 1323 pContext->SourceDistanceModel = AL_FALSE;
rlm@0 1324 pContext->DopplerFactor = 1.0f;
rlm@0 1325 pContext->DopplerVelocity = 1.0f;
rlm@0 1326 pContext->flSpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
rlm@0 1327 pContext->DeferUpdates = AL_FALSE;
rlm@0 1328
rlm@0 1329 pContext->ExtensionList = alExtList;
rlm@0 1330 }
rlm@0 1331
rlm@0 1332
rlm@0 1333 /*
rlm@0 1334 FreeContext
rlm@0 1335
rlm@0 1336 Clean up Context, destroy any remaining Sources
rlm@0 1337 */
rlm@0 1338 static ALCvoid FreeContext(ALCcontext *context)
rlm@0 1339 {
rlm@0 1340 //Invalidate context
rlm@0 1341 memset(context, 0, sizeof(ALCcontext));
rlm@0 1342 free(context);
rlm@0 1343 }
rlm@0 1344
rlm@0 1345 ///////////////////////////////////////////////////////
rlm@0 1346
rlm@0 1347
rlm@0 1348 ///////////////////////////////////////////////////////
rlm@0 1349 // ALC Functions calls
rlm@0 1350
rlm@0 1351
rlm@0 1352 // This should probably move to another c file but for now ...
rlm@0 1353 ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, ALCuint frequency, ALCenum format, ALCsizei SampleSize)
rlm@0 1354 {
rlm@0 1355 ALCdevice *device = NULL;
rlm@0 1356
rlm@0 1357 DO_INITCONFIG();
rlm@0 1358
rlm@0 1359 if(!CaptureBackend.name)
rlm@0 1360 {
rlm@0 1361 alcSetError(NULL, ALC_INVALID_VALUE);
rlm@0 1362 return NULL;
rlm@0 1363 }
rlm@0 1364
rlm@0 1365 if(SampleSize <= 0)
rlm@0 1366 {
rlm@0 1367 alcSetError(NULL, ALC_INVALID_VALUE);
rlm@0 1368 return NULL;
rlm@0 1369 }
rlm@0 1370
rlm@0 1371 if(deviceName && (!deviceName[0] || strcasecmp(deviceName, "openal soft") == 0 || strcasecmp(deviceName, "openal-soft") == 0))
rlm@0 1372 deviceName = NULL;
rlm@0 1373
rlm@0 1374 device = calloc(1, sizeof(ALCdevice));
rlm@0 1375 if(!device)
rlm@0 1376 {
rlm@0 1377 alcSetError(NULL, ALC_OUT_OF_MEMORY);
rlm@0 1378 return NULL;
rlm@0 1379 }
rlm@0 1380
rlm@0 1381 //Validate device
rlm@0 1382 device->Funcs = &CaptureBackend.Funcs;
rlm@0 1383 device->Connected = ALC_TRUE;
rlm@0 1384 device->IsCaptureDevice = AL_TRUE;
rlm@0 1385 device->IsLoopbackDevice = AL_FALSE;
rlm@0 1386 InitializeCriticalSection(&device->Mutex);
rlm@0 1387
rlm@0 1388 device->szDeviceName = NULL;
rlm@0 1389
rlm@0 1390 device->Flags |= DEVICE_FREQUENCY_REQUEST;
rlm@0 1391 device->Frequency = frequency;
rlm@0 1392
rlm@0 1393 device->Flags |= DEVICE_CHANNELS_REQUEST;
rlm@0 1394 if(DecomposeDevFormat(format, &device->FmtChans, &device->FmtType) == AL_FALSE)
rlm@0 1395 {
rlm@0 1396 free(device);
rlm@0 1397 alcSetError(NULL, ALC_INVALID_ENUM);
rlm@0 1398 return NULL;
rlm@0 1399 }
rlm@0 1400
rlm@0 1401 device->UpdateSize = SampleSize;
rlm@0 1402 device->NumUpdates = 1;
rlm@0 1403
rlm@0 1404 LockLists();
rlm@0 1405 if(ALCdevice_OpenCapture(device, deviceName))
rlm@0 1406 {
rlm@0 1407 device->next = g_pDeviceList;
rlm@0 1408 g_pDeviceList = device;
rlm@0 1409 g_ulDeviceCount++;
rlm@0 1410 }
rlm@0 1411 else
rlm@0 1412 {
rlm@0 1413 DeleteCriticalSection(&device->Mutex);
rlm@0 1414 free(device);
rlm@0 1415 device = NULL;
rlm@0 1416 alcSetError(NULL, ALC_INVALID_VALUE);
rlm@0 1417 }
rlm@0 1418 UnlockLists();
rlm@0 1419
rlm@0 1420 return device;
rlm@0 1421 }
rlm@0 1422
rlm@0 1423 ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *pDevice)
rlm@0 1424 {
rlm@0 1425 ALCdevice **list;
rlm@0 1426
rlm@0 1427 LockLists();
rlm@0 1428 list = &g_pDeviceList;
rlm@0 1429 while(*list && *list != pDevice)
rlm@0 1430 list = &(*list)->next;
rlm@0 1431
rlm@0 1432 if(!*list || !(*list)->IsCaptureDevice)
rlm@0 1433 {
rlm@0 1434 alcSetError(*list, ALC_INVALID_DEVICE);
rlm@0 1435 UnlockLists();
rlm@0 1436 return ALC_FALSE;
rlm@0 1437 }
rlm@0 1438
rlm@0 1439 *list = (*list)->next;
rlm@0 1440 g_ulDeviceCount--;
rlm@0 1441
rlm@0 1442 UnlockLists();
rlm@0 1443
rlm@0 1444 LockDevice(pDevice);
rlm@0 1445 ALCdevice_CloseCapture(pDevice);
rlm@0 1446 UnlockDevice(pDevice);
rlm@0 1447
rlm@0 1448 free(pDevice->szDeviceName);
rlm@0 1449 pDevice->szDeviceName = NULL;
rlm@0 1450
rlm@0 1451 DeleteCriticalSection(&pDevice->Mutex);
rlm@0 1452
rlm@0 1453 free(pDevice);
rlm@0 1454
rlm@0 1455 return ALC_TRUE;
rlm@0 1456 }
rlm@0 1457
rlm@0 1458 ALC_API void ALC_APIENTRY alcCaptureStart(ALCdevice *device)
rlm@0 1459 {
rlm@0 1460 LockLists();
rlm@0 1461 if(!IsDevice(device) || !device->IsCaptureDevice)
rlm@0 1462 {
rlm@0 1463 alcSetError(device, ALC_INVALID_DEVICE);
rlm@0 1464 UnlockLists();
rlm@0 1465 return;
rlm@0 1466 }
rlm@0 1467 LockDevice(device);
rlm@0 1468 UnlockLists();
rlm@0 1469 if(device->Connected)
rlm@0 1470 ALCdevice_StartCapture(device);
rlm@0 1471 UnlockDevice(device);
rlm@0 1472 }
rlm@0 1473
rlm@0 1474 ALC_API void ALC_APIENTRY alcCaptureStop(ALCdevice *device)
rlm@0 1475 {
rlm@0 1476 LockLists();
rlm@0 1477 if(!IsDevice(device) || !device->IsCaptureDevice)
rlm@0 1478 {
rlm@0 1479 alcSetError(device, ALC_INVALID_DEVICE);
rlm@0 1480 UnlockLists();
rlm@0 1481 return;
rlm@0 1482 }
rlm@0 1483 LockDevice(device);
rlm@0 1484 UnlockLists();
rlm@0 1485 if(device->Connected)
rlm@0 1486 ALCdevice_StopCapture(device);
rlm@0 1487 UnlockDevice(device);
rlm@0 1488 }
rlm@0 1489
rlm@0 1490 ALC_API void ALC_APIENTRY alcCaptureSamples(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
rlm@0 1491 {
rlm@0 1492 LockLists();
rlm@0 1493 if(!IsDevice(device) || !device->IsCaptureDevice)
rlm@0 1494 {
rlm@0 1495 alcSetError(device, ALC_INVALID_DEVICE);
rlm@0 1496 UnlockLists();
rlm@0 1497 return;
rlm@0 1498 }
rlm@0 1499 LockDevice(device);
rlm@0 1500 UnlockLists();
rlm@0 1501 if(device->Connected)
rlm@0 1502 ALCdevice_CaptureSamples(device, buffer, samples);
rlm@0 1503 UnlockDevice(device);
rlm@0 1504 }
rlm@0 1505
rlm@0 1506 /*
rlm@0 1507 alcGetError
rlm@0 1508
rlm@0 1509 Return last ALC generated error code
rlm@0 1510 */
rlm@0 1511 ALC_API ALCenum ALC_APIENTRY alcGetError(ALCdevice *device)
rlm@0 1512 {
rlm@0 1513 ALCenum errorCode;
rlm@0 1514
rlm@0 1515 LockLists();
rlm@0 1516 if(IsDevice(device))
rlm@0 1517 {
rlm@0 1518 errorCode = device->LastError;
rlm@0 1519 device->LastError = ALC_NO_ERROR;
rlm@0 1520 }
rlm@0 1521 else
rlm@0 1522 {
rlm@0 1523 errorCode = g_eLastNullDeviceError;
rlm@0 1524 g_eLastNullDeviceError = ALC_NO_ERROR;
rlm@0 1525 }
rlm@0 1526 UnlockLists();
rlm@0 1527 return errorCode;
rlm@0 1528 }
rlm@0 1529
rlm@0 1530
rlm@0 1531 /*
rlm@0 1532 alcSuspendContext
rlm@0 1533
rlm@0 1534 Not functional
rlm@0 1535 */
rlm@0 1536 ALC_API ALCvoid ALC_APIENTRY alcSuspendContext(ALCcontext *Context)
rlm@0 1537 {
rlm@0 1538 (void)Context;
rlm@0 1539 }
rlm@0 1540
rlm@0 1541
rlm@0 1542 /*
rlm@0 1543 alcProcessContext
rlm@0 1544
rlm@0 1545 Not functional
rlm@0 1546 */
rlm@0 1547 ALC_API ALCvoid ALC_APIENTRY alcProcessContext(ALCcontext *Context)
rlm@0 1548 {
rlm@0 1549 (void)Context;
rlm@0 1550 }
rlm@0 1551
rlm@0 1552
rlm@0 1553 /*
rlm@0 1554 alcGetString
rlm@0 1555
rlm@0 1556 Returns information about the Device, and error strings
rlm@0 1557 */
rlm@0 1558 ALC_API const ALCchar* ALC_APIENTRY alcGetString(ALCdevice *pDevice,ALCenum param)
rlm@0 1559 {
rlm@0 1560 const ALCchar *value = NULL;
rlm@0 1561
rlm@0 1562 switch(param)
rlm@0 1563 {
rlm@0 1564 case ALC_NO_ERROR:
rlm@0 1565 value = alcNoError;
rlm@0 1566 break;
rlm@0 1567
rlm@0 1568 case ALC_INVALID_ENUM:
rlm@0 1569 value = alcErrInvalidEnum;
rlm@0 1570 break;
rlm@0 1571
rlm@0 1572 case ALC_INVALID_VALUE:
rlm@0 1573 value = alcErrInvalidValue;
rlm@0 1574 break;
rlm@0 1575
rlm@0 1576 case ALC_INVALID_DEVICE:
rlm@0 1577 value = alcErrInvalidDevice;
rlm@0 1578 break;
rlm@0 1579
rlm@0 1580 case ALC_INVALID_CONTEXT:
rlm@0 1581 value = alcErrInvalidContext;
rlm@0 1582 break;
rlm@0 1583
rlm@0 1584 case ALC_OUT_OF_MEMORY:
rlm@0 1585 value = alcErrOutOfMemory;
rlm@0 1586 break;
rlm@0 1587
rlm@0 1588 case ALC_DEVICE_SPECIFIER:
rlm@0 1589 LockLists();
rlm@0 1590 if(IsDevice(pDevice))
rlm@0 1591 value = pDevice->szDeviceName;
rlm@0 1592 else
rlm@0 1593 {
rlm@0 1594 ProbeDeviceList();
rlm@0 1595 value = alcDeviceList;
rlm@0 1596 }
rlm@0 1597 UnlockLists();
rlm@0 1598 break;
rlm@0 1599
rlm@0 1600 case ALC_ALL_DEVICES_SPECIFIER:
rlm@0 1601 ProbeAllDeviceList();
rlm@0 1602 value = alcAllDeviceList;
rlm@0 1603 break;
rlm@0 1604
rlm@0 1605 case ALC_CAPTURE_DEVICE_SPECIFIER:
rlm@0 1606 LockLists();
rlm@0 1607 if(IsDevice(pDevice))
rlm@0 1608 value = pDevice->szDeviceName;
rlm@0 1609 else
rlm@0 1610 {
rlm@0 1611 ProbeCaptureDeviceList();
rlm@0 1612 value = alcCaptureDeviceList;
rlm@0 1613 }
rlm@0 1614 UnlockLists();
rlm@0 1615 break;
rlm@0 1616
rlm@0 1617 /* Default devices are always first in the list */
rlm@0 1618 case ALC_DEFAULT_DEVICE_SPECIFIER:
rlm@0 1619 if(!alcDeviceList)
rlm@0 1620 ProbeDeviceList();
rlm@0 1621
rlm@0 1622 free(alcDefaultDeviceSpecifier);
rlm@0 1623 alcDefaultDeviceSpecifier = strdup(alcDeviceList ? alcDeviceList : "");
rlm@0 1624 if(!alcDefaultDeviceSpecifier)
rlm@0 1625 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
rlm@0 1626 value = alcDefaultDeviceSpecifier;
rlm@0 1627 break;
rlm@0 1628
rlm@0 1629 case ALC_DEFAULT_ALL_DEVICES_SPECIFIER:
rlm@0 1630 if(!alcAllDeviceList)
rlm@0 1631 ProbeAllDeviceList();
rlm@0 1632
rlm@0 1633 free(alcDefaultAllDeviceSpecifier);
rlm@0 1634 alcDefaultAllDeviceSpecifier = strdup(alcAllDeviceList ?
rlm@0 1635 alcAllDeviceList : "");
rlm@0 1636 if(!alcDefaultAllDeviceSpecifier)
rlm@0 1637 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
rlm@0 1638 value = alcDefaultAllDeviceSpecifier;
rlm@0 1639 break;
rlm@0 1640
rlm@0 1641 case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER:
rlm@0 1642 if(!alcCaptureDeviceList)
rlm@0 1643 ProbeCaptureDeviceList();
rlm@0 1644
rlm@0 1645 free(alcCaptureDefaultDeviceSpecifier);
rlm@0 1646 alcCaptureDefaultDeviceSpecifier = strdup(alcCaptureDeviceList ?
rlm@0 1647 alcCaptureDeviceList : "");
rlm@0 1648 if(!alcCaptureDefaultDeviceSpecifier)
rlm@0 1649 alcSetError(pDevice, ALC_OUT_OF_MEMORY);
rlm@0 1650 value = alcCaptureDefaultDeviceSpecifier;
rlm@0 1651 break;
rlm@0 1652
rlm@0 1653 case ALC_EXTENSIONS:
rlm@0 1654 LockLists();
rlm@0 1655 if(IsDevice(pDevice))
rlm@0 1656 value = alcExtensionList;
rlm@0 1657 else
rlm@0 1658 value = alcNoDeviceExtList;
rlm@0 1659 UnlockLists();
rlm@0 1660 break;
rlm@0 1661
rlm@0 1662 default:
rlm@0 1663 alcSetError(pDevice, ALC_INVALID_ENUM);
rlm@0 1664 break;
rlm@0 1665 }
rlm@0 1666
rlm@0 1667 return value;
rlm@0 1668 }
rlm@0 1669
rlm@0 1670
rlm@0 1671 /*
rlm@0 1672 alcGetIntegerv
rlm@0 1673
rlm@0 1674 Returns information about the Device and the version of Open AL
rlm@0 1675 */
rlm@0 1676 ALC_API ALCvoid ALC_APIENTRY alcGetIntegerv(ALCdevice *device,ALCenum param,ALsizei size,ALCint *data)
rlm@0 1677 {
rlm@0 1678 if(size == 0 || data == NULL)
rlm@0 1679 {
rlm@0 1680 alcSetError(device, ALC_INVALID_VALUE);
rlm@0 1681 return;
rlm@0 1682 }
rlm@0 1683
rlm@0 1684 LockLists();
rlm@0 1685 if(!IsDevice(device))
rlm@0 1686 {
rlm@0 1687 switch(param)
rlm@0 1688 {
rlm@0 1689 case ALC_MAJOR_VERSION:
rlm@0 1690 *data = alcMajorVersion;
rlm@0 1691 break;
rlm@0 1692 case ALC_MINOR_VERSION:
rlm@0 1693 *data = alcMinorVersion;
rlm@0 1694 break;
rlm@0 1695
rlm@0 1696 case ALC_ATTRIBUTES_SIZE:
rlm@0 1697 case ALC_ALL_ATTRIBUTES:
rlm@0 1698 case ALC_FREQUENCY:
rlm@0 1699 case ALC_REFRESH:
rlm@0 1700 case ALC_SYNC:
rlm@0 1701 case ALC_MONO_SOURCES:
rlm@0 1702 case ALC_STEREO_SOURCES:
rlm@0 1703 case ALC_CAPTURE_SAMPLES:
rlm@0 1704 case ALC_FORMAT_CHANNELS_SOFT:
rlm@0 1705 case ALC_FORMAT_TYPE_SOFT:
rlm@0 1706 alcSetError(NULL, ALC_INVALID_DEVICE);
rlm@0 1707 break;
rlm@0 1708
rlm@0 1709 default:
rlm@0 1710 alcSetError(NULL, ALC_INVALID_ENUM);
rlm@0 1711 break;
rlm@0 1712 }
rlm@0 1713 }
rlm@0 1714 else if(device->IsCaptureDevice)
rlm@0 1715 {
rlm@0 1716 switch(param)
rlm@0 1717 {
rlm@0 1718 case ALC_CAPTURE_SAMPLES:
rlm@0 1719 LockDevice(device);
rlm@0 1720 *data = ALCdevice_AvailableSamples(device);
rlm@0 1721 UnlockDevice(device);
rlm@0 1722 break;
rlm@0 1723
rlm@0 1724 case ALC_CONNECTED:
rlm@0 1725 *data = device->Connected;
rlm@0 1726 break;
rlm@0 1727
rlm@0 1728 default:
rlm@0 1729 alcSetError(device, ALC_INVALID_ENUM);
rlm@0 1730 break;
rlm@0 1731 }
rlm@0 1732 }
rlm@0 1733 else /* render device */
rlm@0 1734 {
rlm@0 1735 switch(param)
rlm@0 1736 {
rlm@0 1737 case ALC_MAJOR_VERSION:
rlm@0 1738 *data = alcMajorVersion;
rlm@0 1739 break;
rlm@0 1740
rlm@0 1741 case ALC_MINOR_VERSION:
rlm@0 1742 *data = alcMinorVersion;
rlm@0 1743 break;
rlm@0 1744
rlm@0 1745 case ALC_EFX_MAJOR_VERSION:
rlm@0 1746 *data = alcEFXMajorVersion;
rlm@0 1747 break;
rlm@0 1748
rlm@0 1749 case ALC_EFX_MINOR_VERSION:
rlm@0 1750 *data = alcEFXMinorVersion;
rlm@0 1751 break;
rlm@0 1752
rlm@0 1753 case ALC_ATTRIBUTES_SIZE:
rlm@0 1754 *data = 13;
rlm@0 1755 break;
rlm@0 1756
rlm@0 1757 case ALC_ALL_ATTRIBUTES:
rlm@0 1758 if(size < 13)
rlm@0 1759 alcSetError(device, ALC_INVALID_VALUE);
rlm@0 1760 else
rlm@0 1761 {
rlm@0 1762 int i = 0;
rlm@0 1763
rlm@0 1764 data[i++] = ALC_FREQUENCY;
rlm@0 1765 data[i++] = device->Frequency;
rlm@0 1766
rlm@0 1767 if(!device->IsLoopbackDevice)
rlm@0 1768 {
rlm@0 1769 data[i++] = ALC_REFRESH;
rlm@0 1770 data[i++] = device->Frequency / device->UpdateSize;
rlm@0 1771
rlm@0 1772 data[i++] = ALC_SYNC;
rlm@0 1773 data[i++] = ALC_FALSE;
rlm@0 1774 }
rlm@0 1775 else
rlm@0 1776 {
rlm@0 1777 data[i++] = ALC_FORMAT_CHANNELS_SOFT;
rlm@0 1778 data[i++] = device->FmtChans;
rlm@0 1779
rlm@0 1780 data[i++] = ALC_FORMAT_TYPE_SOFT;
rlm@0 1781 data[i++] = device->FmtType;
rlm@0 1782 }
rlm@0 1783
rlm@0 1784 data[i++] = ALC_MONO_SOURCES;
rlm@0 1785 data[i++] = device->NumMonoSources;
rlm@0 1786
rlm@0 1787 data[i++] = ALC_STEREO_SOURCES;
rlm@0 1788 data[i++] = device->NumStereoSources;
rlm@0 1789
rlm@0 1790 data[i++] = ALC_MAX_AUXILIARY_SENDS;
rlm@0 1791 data[i++] = device->NumAuxSends;
rlm@0 1792
rlm@0 1793 data[i++] = 0;
rlm@0 1794 }
rlm@0 1795 break;
rlm@0 1796
rlm@0 1797 case ALC_FREQUENCY:
rlm@0 1798 *data = device->Frequency;
rlm@0 1799 break;
rlm@0 1800
rlm@0 1801 case ALC_REFRESH:
rlm@0 1802 if(device->IsLoopbackDevice)
rlm@0 1803 alcSetError(device, ALC_INVALID_DEVICE);
rlm@0 1804 else
rlm@0 1805 *data = device->Frequency / device->UpdateSize;
rlm@0 1806 break;
rlm@0 1807
rlm@0 1808 case ALC_SYNC:
rlm@0 1809 if(device->IsLoopbackDevice)
rlm@0 1810 alcSetError(device, ALC_INVALID_DEVICE);
rlm@0 1811 else
rlm@0 1812 *data = ALC_FALSE;
rlm@0 1813 break;
rlm@0 1814
rlm@0 1815 case ALC_FORMAT_CHANNELS_SOFT:
rlm@0 1816 if(!device->IsLoopbackDevice)
rlm@0 1817 alcSetError(device, ALC_INVALID_DEVICE);
rlm@0 1818 else
rlm@0 1819 *data = device->FmtChans;
rlm@0 1820 break;
rlm@0 1821
rlm@0 1822 case ALC_FORMAT_TYPE_SOFT:
rlm@0 1823 if(!device->IsLoopbackDevice)
rlm@0 1824 alcSetError(device, ALC_INVALID_DEVICE);
rlm@0 1825 else
rlm@0 1826 *data = device->FmtType;
rlm@0 1827 break;
rlm@0 1828
rlm@0 1829 case ALC_MONO_SOURCES:
rlm@0 1830 *data = device->NumMonoSources;
rlm@0 1831 break;
rlm@0 1832
rlm@0 1833 case ALC_STEREO_SOURCES:
rlm@0 1834 *data = device->NumStereoSources;
rlm@0 1835 break;
rlm@0 1836
rlm@0 1837 case ALC_MAX_AUXILIARY_SENDS:
rlm@0 1838 *data = device->NumAuxSends;
rlm@0 1839 break;
rlm@0 1840
rlm@0 1841 case ALC_CONNECTED:
rlm@0 1842 *data = device->Connected;
rlm@0 1843 break;
rlm@0 1844
rlm@0 1845 default:
rlm@0 1846 alcSetError(device, ALC_INVALID_ENUM);
rlm@0 1847 break;
rlm@0 1848 }
rlm@0 1849 }
rlm@0 1850 UnlockLists();
rlm@0 1851 }
rlm@0 1852
rlm@0 1853
rlm@0 1854 /*
rlm@0 1855 alcIsExtensionPresent
rlm@0 1856
rlm@0 1857 Determines if there is support for a particular extension
rlm@0 1858 */
rlm@0 1859 ALC_API ALCboolean ALC_APIENTRY alcIsExtensionPresent(ALCdevice *device, const ALCchar *extName)
rlm@0 1860 {
rlm@0 1861 ALCboolean bResult = ALC_FALSE;
rlm@0 1862 const char *ptr;
rlm@0 1863 size_t len;
rlm@0 1864
rlm@0 1865 if(!extName)
rlm@0 1866 {
rlm@0 1867 alcSetError(device, ALC_INVALID_VALUE);
rlm@0 1868 return ALC_FALSE;
rlm@0 1869 }
rlm@0 1870
rlm@0 1871 len = strlen(extName);
rlm@0 1872 LockLists();
rlm@0 1873 ptr = (IsDevice(device) ? alcExtensionList : alcNoDeviceExtList);
rlm@0 1874 UnlockLists();
rlm@0 1875 while(ptr && *ptr)
rlm@0 1876 {
rlm@0 1877 if(strncasecmp(ptr, extName, len) == 0 &&
rlm@0 1878 (ptr[len] == '\0' || isspace(ptr[len])))
rlm@0 1879 {
rlm@0 1880 bResult = ALC_TRUE;
rlm@0 1881 break;
rlm@0 1882 }
rlm@0 1883 if((ptr=strchr(ptr, ' ')) != NULL)
rlm@0 1884 {
rlm@0 1885 do {
rlm@0 1886 ++ptr;
rlm@0 1887 } while(isspace(*ptr));
rlm@0 1888 }
rlm@0 1889 }
rlm@0 1890
rlm@0 1891 return bResult;
rlm@0 1892 }
rlm@0 1893
rlm@0 1894
rlm@0 1895 /*
rlm@0 1896 alcGetProcAddress
rlm@0 1897
rlm@0 1898 Retrieves the function address for a particular extension function
rlm@0 1899 */
rlm@0 1900 ALC_API ALCvoid* ALC_APIENTRY alcGetProcAddress(ALCdevice *device, const ALCchar *funcName)
rlm@0 1901 {
rlm@0 1902 ALsizei i = 0;
rlm@0 1903
rlm@0 1904 if(!funcName)
rlm@0 1905 {
rlm@0 1906 alcSetError(device, ALC_INVALID_VALUE);
rlm@0 1907 return NULL;
rlm@0 1908 }
rlm@0 1909
rlm@0 1910 while(alcFunctions[i].funcName && strcmp(alcFunctions[i].funcName,funcName) != 0)
rlm@0 1911 i++;
rlm@0 1912 return alcFunctions[i].address;
rlm@0 1913 }
rlm@0 1914
rlm@0 1915
rlm@0 1916 /*
rlm@0 1917 alcGetEnumValue
rlm@0 1918
rlm@0 1919 Get the value for a particular ALC Enumerated Value
rlm@0 1920 */
rlm@0 1921 ALC_API ALCenum ALC_APIENTRY alcGetEnumValue(ALCdevice *device, const ALCchar *enumName)
rlm@0 1922 {
rlm@0 1923 ALsizei i = 0;
rlm@0 1924
rlm@0 1925 if(!enumName)
rlm@0 1926 {
rlm@0 1927 alcSetError(device, ALC_INVALID_VALUE);
rlm@0 1928 return (ALCenum)0;
rlm@0 1929 }
rlm@0 1930
rlm@0 1931 while(enumeration[i].enumName && strcmp(enumeration[i].enumName,enumName) != 0)
rlm@0 1932 i++;
rlm@0 1933 return enumeration[i].value;
rlm@0 1934 }
rlm@0 1935
rlm@0 1936
rlm@0 1937 /*
rlm@0 1938 alcCreateContext
rlm@0 1939
rlm@0 1940 Create and attach a Context to a particular Device.
rlm@0 1941 */
rlm@0 1942 ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCint *attrList)
rlm@0 1943 {
rlm@0 1944 ALCcontext *ALContext;
rlm@0 1945 void *temp;
rlm@0 1946
rlm@0 1947 LockLists();
rlm@0 1948 if(!IsDevice(device) || device->IsCaptureDevice || !device->Connected)
rlm@0 1949 {
rlm@0 1950 alcSetError(device, ALC_INVALID_DEVICE);
rlm@0 1951 UnlockLists();
rlm@0 1952 return NULL;
rlm@0 1953 }
rlm@0 1954
rlm@0 1955 // Reset Context Last Error code
rlm@0 1956 device->LastError = ALC_NO_ERROR;
rlm@0 1957
rlm@0 1958 if(UpdateDeviceParams(device, attrList) == ALC_FALSE)
rlm@0 1959 {
rlm@0 1960 alcSetError(device, ALC_INVALID_DEVICE);
rlm@0 1961 aluHandleDisconnect(device);
rlm@0 1962 UnlockLists();
rlm@0 1963 return NULL;
rlm@0 1964 }
rlm@0 1965
rlm@0 1966 LockDevice(device);
rlm@0 1967 ALContext = NULL;
rlm@0 1968 temp = realloc(device->Contexts, (device->NumContexts+1) * sizeof(*device->Contexts));
rlm@0 1969 if(temp)
rlm@0 1970 {
rlm@0 1971 device->Contexts = temp;
rlm@0 1972
rlm@0 1973 ALContext = calloc(1, sizeof(ALCcontext));
rlm@0 1974 if(ALContext)
rlm@0 1975 {
rlm@0 1976 ALContext->MaxActiveSources = 256;
rlm@0 1977 ALContext->ActiveSources = malloc(sizeof(ALContext->ActiveSources[0]) *
rlm@0 1978 ALContext->MaxActiveSources);
rlm@0 1979 }
rlm@0 1980 }
rlm@0 1981 if(!ALContext || !ALContext->ActiveSources)
rlm@0 1982 {
rlm@0 1983 free(ALContext);
rlm@0 1984 alcSetError(device, ALC_OUT_OF_MEMORY);
rlm@0 1985 UnlockDevice(device);
rlm@0 1986 if(device->NumContexts == 0)
rlm@0 1987 {
rlm@0 1988 ALCdevice_StopPlayback(device);
rlm@0 1989 device->Flags &= ~DEVICE_RUNNING;
rlm@0 1990 }
rlm@0 1991 UnlockLists();
rlm@0 1992 return NULL;
rlm@0 1993 }
rlm@0 1994
rlm@0 1995 device->Contexts[device->NumContexts++] = ALContext;
rlm@0 1996 ALContext->Device = device;
rlm@0 1997
rlm@0 1998 InitContext(ALContext);
rlm@0 1999 UnlockDevice(device);
rlm@0 2000
rlm@0 2001 ALContext->next = g_pContextList;
rlm@0 2002 g_pContextList = ALContext;
rlm@0 2003 g_ulContextCount++;
rlm@0 2004
rlm@0 2005 UnlockLists();
rlm@0 2006
rlm@0 2007 return ALContext;
rlm@0 2008 }
rlm@0 2009
rlm@0 2010
rlm@0 2011 /*
rlm@0 2012 alcDestroyContext
rlm@0 2013
rlm@0 2014 Remove a Context
rlm@0 2015 */
rlm@0 2016 ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context)
rlm@0 2017 {
rlm@0 2018 ALCdevice *Device;
rlm@0 2019 ALCcontext **list;
rlm@0 2020 ALuint i;
rlm@0 2021
rlm@0 2022 LockLists();
rlm@0 2023 list = &g_pContextList;
rlm@0 2024 while(*list && *list != context)
rlm@0 2025 list = &(*list)->next;
rlm@0 2026
rlm@0 2027 if(!*list)
rlm@0 2028 {
rlm@0 2029 alcSetError(NULL, ALC_INVALID_CONTEXT);
rlm@0 2030 UnlockLists();
rlm@0 2031 return;
rlm@0 2032 }
rlm@0 2033
rlm@0 2034 *list = (*list)->next;
rlm@0 2035 g_ulContextCount--;
rlm@0 2036
rlm@0 2037 if(context == tls_get(LocalContext))
rlm@0 2038 tls_set(LocalContext, NULL);
rlm@0 2039 if(context == GlobalContext)
rlm@0 2040 GlobalContext = NULL;
rlm@0 2041
rlm@0 2042 Device = context->Device;
rlm@0 2043 LockDevice(Device);
rlm@0 2044 for(i = 0;i < Device->NumContexts;i++)
rlm@0 2045 {
rlm@0 2046 if(Device->Contexts[i] == context)
rlm@0 2047 {
rlm@0 2048 Device->Contexts[i] = Device->Contexts[Device->NumContexts-1];
rlm@0 2049 Device->NumContexts--;
rlm@0 2050 break;
rlm@0 2051 }
rlm@0 2052 }
rlm@0 2053 UnlockDevice(Device);
rlm@0 2054
rlm@0 2055 if(Device->NumContexts == 0)
rlm@0 2056 {
rlm@0 2057 ALCdevice_StopPlayback(Device);
rlm@0 2058 Device->Flags &= ~DEVICE_RUNNING;
rlm@0 2059 }
rlm@0 2060 UnlockLists();
rlm@0 2061
rlm@0 2062 if(context->SourceMap.size > 0)
rlm@0 2063 {
rlm@0 2064 ERR("alcDestroyContext(): deleting %d Source(s)\n", context->SourceMap.size);
rlm@0 2065 ReleaseALSources(context);
rlm@0 2066 }
rlm@0 2067 ResetUIntMap(&context->SourceMap);
rlm@0 2068
rlm@0 2069 if(context->EffectSlotMap.size > 0)
rlm@0 2070 {
rlm@0 2071 ERR("alcDestroyContext(): deleting %d AuxiliaryEffectSlot(s)\n", context->EffectSlotMap.size);
rlm@0 2072 ReleaseALAuxiliaryEffectSlots(context);
rlm@0 2073 }
rlm@0 2074 ResetUIntMap(&context->EffectSlotMap);
rlm@0 2075
rlm@0 2076 free(context->ActiveSources);
rlm@0 2077 context->ActiveSources = NULL;
rlm@0 2078 context->MaxActiveSources = 0;
rlm@0 2079 context->ActiveSourceCount = 0;
rlm@0 2080
rlm@0 2081 FreeContext(context);
rlm@0 2082 }
rlm@0 2083
rlm@0 2084
rlm@0 2085 /*
rlm@0 2086 alcGetCurrentContext
rlm@0 2087
rlm@0 2088 Returns the currently active Context
rlm@0 2089 */
rlm@0 2090 ALC_API ALCcontext* ALC_APIENTRY alcGetCurrentContext(ALCvoid)
rlm@0 2091 {
rlm@0 2092 ALCcontext *Context;
rlm@0 2093
rlm@0 2094 LockLists();
rlm@0 2095 Context = tls_get(LocalContext);
rlm@0 2096 if(Context && !IsContext(Context))
rlm@0 2097 {
rlm@0 2098 tls_set(LocalContext, NULL);
rlm@0 2099 Context = NULL;
rlm@0 2100 }
rlm@0 2101 if(!Context)
rlm@0 2102 Context = GlobalContext;
rlm@0 2103 UnlockLists();
rlm@0 2104
rlm@0 2105 return Context;
rlm@0 2106 }
rlm@0 2107
rlm@0 2108 /*
rlm@0 2109 alcGetThreadContext
rlm@0 2110
rlm@0 2111 Returns the currently active thread-local Context
rlm@0 2112 */
rlm@0 2113 ALC_API ALCcontext* ALC_APIENTRY alcGetThreadContext(void)
rlm@0 2114 {
rlm@0 2115 ALCcontext *pContext = NULL;
rlm@0 2116
rlm@0 2117 LockLists();
rlm@0 2118
rlm@0 2119 pContext = tls_get(LocalContext);
rlm@0 2120 if(pContext && !IsContext(pContext))
rlm@0 2121 {
rlm@0 2122 tls_set(LocalContext, NULL);
rlm@0 2123 pContext = NULL;
rlm@0 2124 }
rlm@0 2125
rlm@0 2126 UnlockLists();
rlm@0 2127
rlm@0 2128 return pContext;
rlm@0 2129 }
rlm@0 2130
rlm@0 2131
rlm@0 2132 /*
rlm@0 2133 alcGetContextsDevice
rlm@0 2134
rlm@0 2135 Returns the Device that a particular Context is attached to
rlm@0 2136 */
rlm@0 2137 ALC_API ALCdevice* ALC_APIENTRY alcGetContextsDevice(ALCcontext *pContext)
rlm@0 2138 {
rlm@0 2139 ALCdevice *pDevice = NULL;
rlm@0 2140
rlm@0 2141 LockLists();
rlm@0 2142 if(IsContext(pContext))
rlm@0 2143 pDevice = pContext->Device;
rlm@0 2144 else
rlm@0 2145 alcSetError(NULL, ALC_INVALID_CONTEXT);
rlm@0 2146 UnlockLists();
rlm@0 2147
rlm@0 2148 return pDevice;
rlm@0 2149 }
rlm@0 2150
rlm@0 2151
rlm@0 2152 /*
rlm@0 2153 alcMakeContextCurrent
rlm@0 2154
rlm@0 2155 Makes the given Context the active Context
rlm@0 2156 */
rlm@0 2157 ALC_API ALCboolean ALC_APIENTRY alcMakeContextCurrent(ALCcontext *context)
rlm@0 2158 {
rlm@0 2159 ALboolean bReturn = AL_TRUE;
rlm@0 2160
rlm@0 2161 LockLists();
rlm@0 2162
rlm@0 2163 // context must be a valid Context or NULL
rlm@0 2164 if(context == NULL || IsContext(context))
rlm@0 2165 {
rlm@0 2166 GlobalContext = context;
rlm@0 2167 tls_set(LocalContext, NULL);
rlm@0 2168 }
rlm@0 2169 else
rlm@0 2170 {
rlm@0 2171 alcSetError(NULL, ALC_INVALID_CONTEXT);
rlm@0 2172 bReturn = AL_FALSE;
rlm@0 2173 }
rlm@0 2174
rlm@0 2175 UnlockLists();
rlm@0 2176
rlm@0 2177 return bReturn;
rlm@0 2178 }
rlm@0 2179
rlm@0 2180 /*
rlm@0 2181 alcSetThreadContext
rlm@0 2182
rlm@0 2183 Makes the given Context the active Context for the current thread
rlm@0 2184 */
rlm@0 2185 ALC_API ALCboolean ALC_APIENTRY alcSetThreadContext(ALCcontext *context)
rlm@0 2186 {
rlm@0 2187 ALboolean bReturn = AL_TRUE;
rlm@0 2188
rlm@0 2189 LockLists();
rlm@0 2190
rlm@0 2191 // context must be a valid Context or NULL
rlm@0 2192 if(context == NULL || IsContext(context))
rlm@0 2193 tls_set(LocalContext, context);
rlm@0 2194 else
rlm@0 2195 {
rlm@0 2196 alcSetError(NULL, ALC_INVALID_CONTEXT);
rlm@0 2197 bReturn = AL_FALSE;
rlm@0 2198 }
rlm@0 2199
rlm@0 2200 UnlockLists();
rlm@0 2201
rlm@0 2202 return bReturn;
rlm@0 2203 }
rlm@0 2204
rlm@0 2205
rlm@0 2206 static void GetFormatFromString(const char *str, enum DevFmtChannels *chans, enum DevFmtType *type)
rlm@0 2207 {
rlm@0 2208 if(strcasecmp(str, "AL_FORMAT_MONO32") == 0)
rlm@0 2209 {
rlm@0 2210 *chans = DevFmtMono;
rlm@0 2211 *type = DevFmtFloat;
rlm@0 2212 return;
rlm@0 2213 }
rlm@0 2214 if(strcasecmp(str, "AL_FORMAT_STEREO32") == 0)
rlm@0 2215 {
rlm@0 2216 *chans = DevFmtStereo;
rlm@0 2217 *type = DevFmtFloat;
rlm@0 2218 return;
rlm@0 2219 }
rlm@0 2220 if(strcasecmp(str, "AL_FORMAT_QUAD32") == 0)
rlm@0 2221 {
rlm@0 2222 *chans = DevFmtQuad;
rlm@0 2223 *type = DevFmtFloat;
rlm@0 2224 return;
rlm@0 2225 }
rlm@0 2226 if(strcasecmp(str, "AL_FORMAT_51CHN32") == 0)
rlm@0 2227 {
rlm@0 2228 *chans = DevFmtX51;
rlm@0 2229 *type = DevFmtFloat;
rlm@0 2230 return;
rlm@0 2231 }
rlm@0 2232 if(strcasecmp(str, "AL_FORMAT_61CHN32") == 0)
rlm@0 2233 {
rlm@0 2234 *chans = DevFmtX61;
rlm@0 2235 *type = DevFmtFloat;
rlm@0 2236 return;
rlm@0 2237 }
rlm@0 2238 if(strcasecmp(str, "AL_FORMAT_71CHN32") == 0)
rlm@0 2239 {
rlm@0 2240 *chans = DevFmtX71;
rlm@0 2241 *type = DevFmtFloat;
rlm@0 2242 return;
rlm@0 2243 }
rlm@0 2244
rlm@0 2245 if(strcasecmp(str, "AL_FORMAT_MONO16") == 0)
rlm@0 2246 {
rlm@0 2247 *chans = DevFmtMono;
rlm@0 2248 *type = DevFmtShort;
rlm@0 2249 return;
rlm@0 2250 }
rlm@0 2251 if(strcasecmp(str, "AL_FORMAT_STEREO16") == 0)
rlm@0 2252 {
rlm@0 2253 *chans = DevFmtStereo;
rlm@0 2254 *type = DevFmtShort;
rlm@0 2255 return;
rlm@0 2256 }
rlm@0 2257 if(strcasecmp(str, "AL_FORMAT_QUAD16") == 0)
rlm@0 2258 {
rlm@0 2259 *chans = DevFmtQuad;
rlm@0 2260 *type = DevFmtShort;
rlm@0 2261 return;
rlm@0 2262 }
rlm@0 2263 if(strcasecmp(str, "AL_FORMAT_51CHN16") == 0)
rlm@0 2264 {
rlm@0 2265 *chans = DevFmtX51;
rlm@0 2266 *type = DevFmtShort;
rlm@0 2267 return;
rlm@0 2268 }
rlm@0 2269 if(strcasecmp(str, "AL_FORMAT_61CHN16") == 0)
rlm@0 2270 {
rlm@0 2271 *chans = DevFmtX61;
rlm@0 2272 *type = DevFmtShort;
rlm@0 2273 return;
rlm@0 2274 }
rlm@0 2275 if(strcasecmp(str, "AL_FORMAT_71CHN16") == 0)
rlm@0 2276 {
rlm@0 2277 *chans = DevFmtX71;
rlm@0 2278 *type = DevFmtShort;
rlm@0 2279 return;
rlm@0 2280 }
rlm@0 2281
rlm@0 2282 if(strcasecmp(str, "AL_FORMAT_MONO8") == 0)
rlm@0 2283 {
rlm@0 2284 *chans = DevFmtMono;
rlm@0 2285 *type = DevFmtByte;
rlm@0 2286 return;
rlm@0 2287 }
rlm@0 2288 if(strcasecmp(str, "AL_FORMAT_STEREO8") == 0)
rlm@0 2289 {
rlm@0 2290 *chans = DevFmtStereo;
rlm@0 2291 *type = DevFmtByte;
rlm@0 2292 return;
rlm@0 2293 }
rlm@0 2294 if(strcasecmp(str, "AL_FORMAT_QUAD8") == 0)
rlm@0 2295 {
rlm@0 2296 *chans = DevFmtQuad;
rlm@0 2297 *type = DevFmtByte;
rlm@0 2298 return;
rlm@0 2299 }
rlm@0 2300 if(strcasecmp(str, "AL_FORMAT_51CHN8") == 0)
rlm@0 2301 {
rlm@0 2302 *chans = DevFmtX51;
rlm@0 2303 *type = DevFmtByte;
rlm@0 2304 return;
rlm@0 2305 }
rlm@0 2306 if(strcasecmp(str, "AL_FORMAT_61CHN8") == 0)
rlm@0 2307 {
rlm@0 2308 *chans = DevFmtX61;
rlm@0 2309 *type = DevFmtByte;
rlm@0 2310 return;
rlm@0 2311 }
rlm@0 2312 if(strcasecmp(str, "AL_FORMAT_71CHN8") == 0)
rlm@0 2313 {
rlm@0 2314 *chans = DevFmtX71;
rlm@0 2315 *type = DevFmtByte;
rlm@0 2316 return;
rlm@0 2317 }
rlm@0 2318
rlm@0 2319 ERR("Unknown format: \"%s\"\n", str);
rlm@0 2320 *chans = DevFmtStereo;
rlm@0 2321 *type = DevFmtShort;
rlm@0 2322 }
rlm@0 2323
rlm@0 2324 /*
rlm@0 2325 alcOpenDevice
rlm@0 2326
rlm@0 2327 Open the Device specified.
rlm@0 2328 */
rlm@0 2329 ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
rlm@0 2330 {
rlm@0 2331 const ALCchar *fmt;
rlm@0 2332 ALCdevice *device;
rlm@0 2333
rlm@0 2334 DO_INITCONFIG();
rlm@0 2335
rlm@0 2336 if(!PlaybackBackend.name)
rlm@0 2337 {
rlm@0 2338 alcSetError(NULL, ALC_INVALID_VALUE);
rlm@0 2339 return NULL;
rlm@0 2340 }
rlm@0 2341
rlm@0 2342 if(deviceName && (!deviceName[0] || strcasecmp(deviceName, "openal soft") == 0 || strcasecmp(deviceName, "openal-soft") == 0))
rlm@0 2343 deviceName = NULL;
rlm@0 2344
rlm@0 2345 device = calloc(1, sizeof(ALCdevice));
rlm@0 2346 if(!device)
rlm@0 2347 {
rlm@0 2348 alcSetError(NULL, ALC_OUT_OF_MEMORY);
rlm@0 2349 return NULL;
rlm@0 2350 }
rlm@0 2351
rlm@0 2352 //Validate device
rlm@0 2353 device->Funcs = &PlaybackBackend.Funcs;
rlm@0 2354 device->Connected = ALC_TRUE;
rlm@0 2355 device->IsCaptureDevice = AL_FALSE;
rlm@0 2356 device->IsLoopbackDevice = AL_FALSE;
rlm@0 2357 InitializeCriticalSection(&device->Mutex);
rlm@0 2358 device->LastError = ALC_NO_ERROR;
rlm@0 2359
rlm@0 2360 device->Flags = 0;
rlm@0 2361 device->Bs2b = NULL;
rlm@0 2362 device->szDeviceName = NULL;
rlm@0 2363
rlm@0 2364 device->Contexts = NULL;
rlm@0 2365 device->NumContexts = 0;
rlm@0 2366
rlm@0 2367 InitUIntMap(&device->BufferMap);
rlm@0 2368 InitUIntMap(&device->EffectMap);
rlm@0 2369 InitUIntMap(&device->FilterMap);
rlm@0 2370
rlm@0 2371 //Set output format
rlm@0 2372 if(ConfigValueExists(NULL, "frequency"))
rlm@0 2373 device->Flags |= DEVICE_FREQUENCY_REQUEST;
rlm@0 2374 device->Frequency = GetConfigValueInt(NULL, "frequency", DEFAULT_OUTPUT_RATE);
rlm@0 2375 if(device->Frequency < 8000)
rlm@0 2376 device->Frequency = 8000;
rlm@0 2377
rlm@0 2378 if(ConfigValueExists(NULL, "format"))
rlm@0 2379 device->Flags |= DEVICE_CHANNELS_REQUEST;
rlm@0 2380 fmt = GetConfigValue(NULL, "format", "AL_FORMAT_STEREO16");
rlm@0 2381 GetFormatFromString(fmt, &device->FmtChans, &device->FmtType);
rlm@0 2382
rlm@0 2383 device->NumUpdates = GetConfigValueInt(NULL, "periods", 4);
rlm@0 2384 if(device->NumUpdates < 2)
rlm@0 2385 device->NumUpdates = 4;
rlm@0 2386
rlm@0 2387 device->UpdateSize = GetConfigValueInt(NULL, "period_size", 1024);
rlm@0 2388 if(device->UpdateSize <= 0)
rlm@0 2389 device->UpdateSize = 1024;
rlm@0 2390
rlm@0 2391 device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
rlm@0 2392 if(device->MaxNoOfSources <= 0)
rlm@0 2393 device->MaxNoOfSources = 256;
rlm@0 2394
rlm@0 2395 device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4);
rlm@0 2396 if(device->AuxiliaryEffectSlotMax <= 0)
rlm@0 2397 device->AuxiliaryEffectSlotMax = 4;
rlm@0 2398
rlm@0 2399 device->NumStereoSources = 1;
rlm@0 2400 device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
rlm@0 2401
rlm@0 2402 device->NumAuxSends = GetConfigValueInt(NULL, "sends", MAX_SENDS);
rlm@0 2403 if(device->NumAuxSends > MAX_SENDS)
rlm@0 2404 device->NumAuxSends = MAX_SENDS;
rlm@0 2405
rlm@0 2406 device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
rlm@0 2407
rlm@0 2408 // Find a playback device to open
rlm@0 2409 LockLists();
rlm@0 2410 if(ALCdevice_OpenPlayback(device, deviceName))
rlm@0 2411 {
rlm@0 2412 device->next = g_pDeviceList;
rlm@0 2413 g_pDeviceList = device;
rlm@0 2414 g_ulDeviceCount++;
rlm@0 2415 }
rlm@0 2416 else
rlm@0 2417 {
rlm@0 2418 // No suitable output device found
rlm@0 2419 DeleteCriticalSection(&device->Mutex);
rlm@0 2420 free(device);
rlm@0 2421 device = NULL;
rlm@0 2422 alcSetError(NULL, ALC_INVALID_VALUE);
rlm@0 2423 }
rlm@0 2424 UnlockLists();
rlm@0 2425
rlm@0 2426 return device;
rlm@0 2427 }
rlm@0 2428
rlm@0 2429
rlm@0 2430 /*
rlm@0 2431 alcCloseDevice
rlm@0 2432
rlm@0 2433 Close the specified Device
rlm@0 2434 */
rlm@0 2435 ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice)
rlm@0 2436 {
rlm@0 2437 ALCdevice **list;
rlm@0 2438
rlm@0 2439 LockLists();
rlm@0 2440 list = &g_pDeviceList;
rlm@0 2441 while(*list && *list != pDevice)
rlm@0 2442 list = &(*list)->next;
rlm@0 2443
rlm@0 2444 if(!*list || (*list)->IsCaptureDevice)
rlm@0 2445 {
rlm@0 2446 alcSetError(*list, ALC_INVALID_DEVICE);
rlm@0 2447 UnlockLists();
rlm@0 2448 return ALC_FALSE;
rlm@0 2449 }
rlm@0 2450
rlm@0 2451 *list = (*list)->next;
rlm@0 2452 g_ulDeviceCount--;
rlm@0 2453
rlm@0 2454 UnlockLists();
rlm@0 2455
rlm@0 2456 if(pDevice->NumContexts > 0)
rlm@0 2457 {
rlm@0 2458 WARN("alcCloseDevice(): destroying %u Context(s)\n", pDevice->NumContexts);
rlm@0 2459 while(pDevice->NumContexts > 0)
rlm@0 2460 alcDestroyContext(pDevice->Contexts[0]);
rlm@0 2461 }
rlm@0 2462 ALCdevice_ClosePlayback(pDevice);
rlm@0 2463
rlm@0 2464 if(pDevice->BufferMap.size > 0)
rlm@0 2465 {
rlm@0 2466 WARN("alcCloseDevice(): deleting %d Buffer(s)\n", pDevice->BufferMap.size);
rlm@0 2467 ReleaseALBuffers(pDevice);
rlm@0 2468 }
rlm@0 2469 ResetUIntMap(&pDevice->BufferMap);
rlm@0 2470
rlm@0 2471 if(pDevice->EffectMap.size > 0)
rlm@0 2472 {
rlm@0 2473 WARN("alcCloseDevice(): deleting %d Effect(s)\n", pDevice->EffectMap.size);
rlm@0 2474 ReleaseALEffects(pDevice);
rlm@0 2475 }
rlm@0 2476 ResetUIntMap(&pDevice->EffectMap);
rlm@0 2477
rlm@0 2478 if(pDevice->FilterMap.size > 0)
rlm@0 2479 {
rlm@0 2480 WARN("alcCloseDevice(): deleting %d Filter(s)\n", pDevice->FilterMap.size);
rlm@0 2481 ReleaseALFilters(pDevice);
rlm@0 2482 }
rlm@0 2483 ResetUIntMap(&pDevice->FilterMap);
rlm@0 2484
rlm@0 2485 free(pDevice->Bs2b);
rlm@0 2486 pDevice->Bs2b = NULL;
rlm@0 2487
rlm@0 2488 free(pDevice->szDeviceName);
rlm@0 2489 pDevice->szDeviceName = NULL;
rlm@0 2490
rlm@0 2491 free(pDevice->Contexts);
rlm@0 2492 pDevice->Contexts = NULL;
rlm@0 2493
rlm@0 2494 DeleteCriticalSection(&pDevice->Mutex);
rlm@0 2495
rlm@0 2496 //Release device structure
rlm@0 2497 memset(pDevice, 0, sizeof(ALCdevice));
rlm@0 2498 free(pDevice);
rlm@0 2499
rlm@0 2500 return ALC_TRUE;
rlm@0 2501 }
rlm@0 2502
rlm@0 2503
rlm@0 2504 ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(void)
rlm@0 2505 {
rlm@0 2506 ALCdevice *device;
rlm@0 2507
rlm@0 2508 DO_INITCONFIG();
rlm@0 2509
rlm@0 2510 device = calloc(1, sizeof(ALCdevice));
rlm@0 2511 if(!device)
rlm@0 2512 {
rlm@0 2513 alcSetError(NULL, ALC_OUT_OF_MEMORY);
rlm@0 2514 return NULL;
rlm@0 2515 }
rlm@0 2516
rlm@0 2517 //Validate device
rlm@0 2518 device->Funcs = &BackendLoopback.Funcs;
rlm@0 2519 device->Connected = ALC_TRUE;
rlm@0 2520 device->IsCaptureDevice = AL_FALSE;
rlm@0 2521 device->IsLoopbackDevice = AL_TRUE;
rlm@0 2522 InitializeCriticalSection(&device->Mutex);
rlm@0 2523 device->LastError = ALC_NO_ERROR;
rlm@0 2524
rlm@0 2525 device->Flags = 0;
rlm@0 2526 device->Bs2b = NULL;
rlm@0 2527 device->szDeviceName = NULL;
rlm@0 2528
rlm@0 2529 device->Contexts = NULL;
rlm@0 2530 device->NumContexts = 0;
rlm@0 2531
rlm@0 2532 InitUIntMap(&device->BufferMap);
rlm@0 2533 InitUIntMap(&device->EffectMap);
rlm@0 2534 InitUIntMap(&device->FilterMap);
rlm@0 2535
rlm@0 2536 //Set output format
rlm@0 2537 device->Frequency = 44100;
rlm@0 2538 device->FmtChans = DevFmtStereo;
rlm@0 2539 device->FmtType = DevFmtShort;
rlm@0 2540
rlm@0 2541 device->NumUpdates = 0;
rlm@0 2542 device->UpdateSize = 0;
rlm@0 2543
rlm@0 2544 device->MaxNoOfSources = GetConfigValueInt(NULL, "sources", 256);
rlm@0 2545 if(device->MaxNoOfSources <= 0)
rlm@0 2546 device->MaxNoOfSources = 256;
rlm@0 2547
rlm@0 2548 device->AuxiliaryEffectSlotMax = GetConfigValueInt(NULL, "slots", 4);
rlm@0 2549 if(device->AuxiliaryEffectSlotMax <= 0)
rlm@0 2550 device->AuxiliaryEffectSlotMax = 4;
rlm@0 2551
rlm@0 2552 device->NumStereoSources = 1;
rlm@0 2553 device->NumMonoSources = device->MaxNoOfSources - device->NumStereoSources;
rlm@0 2554
rlm@0 2555 device->NumAuxSends = GetConfigValueInt(NULL, "sends", MAX_SENDS);
rlm@0 2556 if(device->NumAuxSends > MAX_SENDS)
rlm@0 2557 device->NumAuxSends = MAX_SENDS;
rlm@0 2558
rlm@0 2559 device->Bs2bLevel = GetConfigValueInt(NULL, "cf_level", 0);
rlm@0 2560
rlm@0 2561 // Open the "backend"
rlm@0 2562 LockLists();
rlm@0 2563 ALCdevice_OpenPlayback(device, "Loopback");
rlm@0 2564
rlm@0 2565 device->next = g_pDeviceList;
rlm@0 2566 g_pDeviceList = device;
rlm@0 2567 g_ulDeviceCount++;
rlm@0 2568 UnlockLists();
rlm@0 2569
rlm@0 2570 return device;
rlm@0 2571 }
rlm@0 2572
rlm@0 2573 ALC_API ALCboolean ALC_APIENTRY alcIsRenderFormatSupportedSOFT(ALCdevice *device, ALCsizei freq, ALCenum channels, ALCenum type)
rlm@0 2574 {
rlm@0 2575 ALCboolean ret = ALC_FALSE;
rlm@0 2576
rlm@0 2577 LockLists();
rlm@0 2578 if(!IsDevice(device) || !device->IsLoopbackDevice)
rlm@0 2579 alcSetError(device, ALC_INVALID_DEVICE);
rlm@0 2580 else if(freq <= 0)
rlm@0 2581 alcSetError(device, ALC_INVALID_VALUE);
rlm@0 2582 else if(!IsValidALCType(type) || !IsValidALCChannels(channels))
rlm@0 2583 alcSetError(device, ALC_INVALID_ENUM);
rlm@0 2584 else
rlm@0 2585 {
rlm@0 2586 if(BytesFromDevFmt(type) > 0 && ChannelsFromDevFmt(channels) > 0 &&
rlm@0 2587 freq >= 8000)
rlm@0 2588 ret = ALC_TRUE;
rlm@0 2589 }
rlm@0 2590 UnlockLists();
rlm@0 2591
rlm@0 2592 return ret;
rlm@0 2593 }
rlm@0 2594
rlm@0 2595 ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, ALCvoid *buffer, ALCsizei samples)
rlm@0 2596 {
rlm@0 2597 LockLists();
rlm@0 2598 if(!IsDevice(device) || !device->IsLoopbackDevice)
rlm@0 2599 alcSetError(device, ALC_INVALID_DEVICE);
rlm@0 2600 else if(samples < 0 || (samples > 0 && buffer == NULL))
rlm@0 2601 alcSetError(device, ALC_INVALID_VALUE);
rlm@0 2602 else
rlm@0 2603 aluMixData(device, buffer, samples);
rlm@0 2604 UnlockLists();
rlm@0 2605 }
rlm@0 2606
rlm@0 2607
rlm@0 2608 static void ReleaseALC(ALCboolean doclose)
rlm@0 2609 {
rlm@0 2610 free(alcDeviceList); alcDeviceList = NULL;
rlm@0 2611 alcDeviceListSize = 0;
rlm@0 2612 free(alcAllDeviceList); alcAllDeviceList = NULL;
rlm@0 2613 alcAllDeviceListSize = 0;
rlm@0 2614 free(alcCaptureDeviceList); alcCaptureDeviceList = NULL;
rlm@0 2615 alcCaptureDeviceListSize = 0;
rlm@0 2616
rlm@0 2617 free(alcDefaultDeviceSpecifier);
rlm@0 2618 alcDefaultDeviceSpecifier = NULL;
rlm@0 2619 free(alcDefaultAllDeviceSpecifier);
rlm@0 2620 alcDefaultAllDeviceSpecifier = NULL;
rlm@0 2621 free(alcCaptureDefaultDeviceSpecifier);
rlm@0 2622 alcCaptureDefaultDeviceSpecifier = NULL;
rlm@0 2623
rlm@0 2624 if(doclose)
rlm@0 2625 {
rlm@0 2626 if(g_ulDeviceCount > 0)
rlm@0 2627 WARN("ReleaseALC(): closing %u Device%s\n", g_ulDeviceCount, (g_ulDeviceCount>1)?"s":"");
rlm@0 2628
rlm@0 2629 while(g_pDeviceList)
rlm@0 2630 {
rlm@0 2631 if(g_pDeviceList->IsCaptureDevice)
rlm@0 2632 alcCaptureCloseDevice(g_pDeviceList);
rlm@0 2633 else
rlm@0 2634 alcCloseDevice(g_pDeviceList);
rlm@0 2635 }
rlm@0 2636 }
rlm@0 2637 else
rlm@0 2638 {
rlm@0 2639 if(g_ulDeviceCount > 0)
rlm@0 2640 WARN("ReleaseALC(): %u Device%s not closed\n", g_ulDeviceCount, (g_ulDeviceCount>1)?"s":"");
rlm@0 2641 }
rlm@0 2642 }
rlm@0 2643
rlm@0 2644 ///////////////////////////////////////////////////////