Mercurial > audio-send
diff OpenAL32/alState.c @ 0:f9476ff7637e
initial forking of open-al to create multiple listeners
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 25 Oct 2011 13:02:31 -0700 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/OpenAL32/alState.c Tue Oct 25 13:02:31 2011 -0700 1.3 @@ -0,0 +1,658 @@ 1.4 +/** 1.5 + * OpenAL cross platform audio library 1.6 + * Copyright (C) 1999-2000 by authors. 1.7 + * This library is free software; you can redistribute it and/or 1.8 + * modify it under the terms of the GNU Library General Public 1.9 + * License as published by the Free Software Foundation; either 1.10 + * version 2 of the License, or (at your option) any later version. 1.11 + * 1.12 + * This library is distributed in the hope that it will be useful, 1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.15 + * Library General Public License for more details. 1.16 + * 1.17 + * You should have received a copy of the GNU Library General Public 1.18 + * License along with this library; if not, write to the 1.19 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 1.20 + * Boston, MA 02111-1307, USA. 1.21 + * Or go to http://www.gnu.org/copyleft/lgpl.html 1.22 + */ 1.23 + 1.24 +#include "config.h" 1.25 + 1.26 +#include <stdlib.h> 1.27 +#include "alMain.h" 1.28 +#include "AL/alc.h" 1.29 +#include "AL/alext.h" 1.30 +#include "alError.h" 1.31 +#include "alSource.h" 1.32 +#include "alAuxEffectSlot.h" 1.33 +#include "alState.h" 1.34 + 1.35 +static const ALchar alVendor[] = "OpenAL Community"; 1.36 +static const ALchar alVersion[] = "1.1 ALSOFT "ALSOFT_VERSION; 1.37 +static const ALchar alRenderer[] = "OpenAL Soft"; 1.38 + 1.39 +// Error Messages 1.40 +static const ALchar alNoError[] = "No Error"; 1.41 +static const ALchar alErrInvalidName[] = "Invalid Name"; 1.42 +static const ALchar alErrInvalidEnum[] = "Invalid Enum"; 1.43 +static const ALchar alErrInvalidValue[] = "Invalid Value"; 1.44 +static const ALchar alErrInvalidOp[] = "Invalid Operation"; 1.45 +static const ALchar alErrOutOfMemory[] = "Out of Memory"; 1.46 + 1.47 +AL_API ALvoid AL_APIENTRY alEnable(ALenum capability) 1.48 +{ 1.49 + ALCcontext *Context; 1.50 + 1.51 + Context = GetLockedContext(); 1.52 + if(!Context) return; 1.53 + 1.54 + switch(capability) 1.55 + { 1.56 + case AL_SOURCE_DISTANCE_MODEL: 1.57 + Context->SourceDistanceModel = AL_TRUE; 1.58 + Context->UpdateSources = AL_TRUE; 1.59 + break; 1.60 + 1.61 + default: 1.62 + alSetError(Context, AL_INVALID_ENUM); 1.63 + break; 1.64 + } 1.65 + 1.66 + UnlockContext(Context); 1.67 +} 1.68 + 1.69 +AL_API ALvoid AL_APIENTRY alDisable(ALenum capability) 1.70 +{ 1.71 + ALCcontext *Context; 1.72 + 1.73 + Context = GetLockedContext(); 1.74 + if(!Context) return; 1.75 + 1.76 + switch(capability) 1.77 + { 1.78 + case AL_SOURCE_DISTANCE_MODEL: 1.79 + Context->SourceDistanceModel = AL_FALSE; 1.80 + Context->UpdateSources = AL_TRUE; 1.81 + break; 1.82 + 1.83 + default: 1.84 + alSetError(Context, AL_INVALID_ENUM); 1.85 + break; 1.86 + } 1.87 + 1.88 + UnlockContext(Context); 1.89 +} 1.90 + 1.91 +AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability) 1.92 +{ 1.93 + ALCcontext *Context; 1.94 + ALboolean value=AL_FALSE; 1.95 + 1.96 + Context = GetLockedContext(); 1.97 + if(!Context) return AL_FALSE; 1.98 + 1.99 + switch(capability) 1.100 + { 1.101 + case AL_SOURCE_DISTANCE_MODEL: 1.102 + value = Context->SourceDistanceModel; 1.103 + break; 1.104 + 1.105 + default: 1.106 + alSetError(Context, AL_INVALID_ENUM); 1.107 + break; 1.108 + } 1.109 + 1.110 + UnlockContext(Context); 1.111 + 1.112 + return value; 1.113 +} 1.114 + 1.115 +AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname) 1.116 +{ 1.117 + ALCcontext *Context; 1.118 + ALboolean value=AL_FALSE; 1.119 + 1.120 + Context = GetLockedContext(); 1.121 + if(!Context) return AL_FALSE; 1.122 + 1.123 + switch(pname) 1.124 + { 1.125 + case AL_DOPPLER_FACTOR: 1.126 + if(Context->DopplerFactor != 0.0f) 1.127 + value = AL_TRUE; 1.128 + break; 1.129 + 1.130 + case AL_DOPPLER_VELOCITY: 1.131 + if(Context->DopplerVelocity != 0.0f) 1.132 + value = AL_TRUE; 1.133 + break; 1.134 + 1.135 + case AL_DISTANCE_MODEL: 1.136 + if(Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED) 1.137 + value = AL_TRUE; 1.138 + break; 1.139 + 1.140 + case AL_SPEED_OF_SOUND: 1.141 + if(Context->flSpeedOfSound != 0.0f) 1.142 + value = AL_TRUE; 1.143 + break; 1.144 + 1.145 + case AL_DEFERRED_UPDATES_SOFT: 1.146 + value = Context->DeferUpdates; 1.147 + break; 1.148 + 1.149 + default: 1.150 + alSetError(Context, AL_INVALID_ENUM); 1.151 + break; 1.152 + } 1.153 + 1.154 + UnlockContext(Context); 1.155 + 1.156 + return value; 1.157 +} 1.158 + 1.159 +AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname) 1.160 +{ 1.161 + ALCcontext *Context; 1.162 + ALdouble value = 0.0; 1.163 + 1.164 + Context = GetLockedContext(); 1.165 + if(!Context) return 0.0; 1.166 + 1.167 + switch(pname) 1.168 + { 1.169 + case AL_DOPPLER_FACTOR: 1.170 + value = (double)Context->DopplerFactor; 1.171 + break; 1.172 + 1.173 + case AL_DOPPLER_VELOCITY: 1.174 + value = (double)Context->DopplerVelocity; 1.175 + break; 1.176 + 1.177 + case AL_DISTANCE_MODEL: 1.178 + value = (double)Context->DistanceModel; 1.179 + break; 1.180 + 1.181 + case AL_SPEED_OF_SOUND: 1.182 + value = (double)Context->flSpeedOfSound; 1.183 + break; 1.184 + 1.185 + case AL_DEFERRED_UPDATES_SOFT: 1.186 + value = (ALdouble)Context->DeferUpdates; 1.187 + break; 1.188 + 1.189 + default: 1.190 + alSetError(Context, AL_INVALID_ENUM); 1.191 + break; 1.192 + } 1.193 + 1.194 + UnlockContext(Context); 1.195 + 1.196 + return value; 1.197 +} 1.198 + 1.199 +AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname) 1.200 +{ 1.201 + ALCcontext *Context; 1.202 + ALfloat value = 0.0f; 1.203 + 1.204 + Context = GetLockedContext(); 1.205 + if(!Context) return 0.0f; 1.206 + 1.207 + switch(pname) 1.208 + { 1.209 + case AL_DOPPLER_FACTOR: 1.210 + value = Context->DopplerFactor; 1.211 + break; 1.212 + 1.213 + case AL_DOPPLER_VELOCITY: 1.214 + value = Context->DopplerVelocity; 1.215 + break; 1.216 + 1.217 + case AL_DISTANCE_MODEL: 1.218 + value = (float)Context->DistanceModel; 1.219 + break; 1.220 + 1.221 + case AL_SPEED_OF_SOUND: 1.222 + value = Context->flSpeedOfSound; 1.223 + break; 1.224 + 1.225 + case AL_DEFERRED_UPDATES_SOFT: 1.226 + value = (ALfloat)Context->DeferUpdates; 1.227 + break; 1.228 + 1.229 + default: 1.230 + alSetError(Context, AL_INVALID_ENUM); 1.231 + break; 1.232 + } 1.233 + 1.234 + UnlockContext(Context); 1.235 + 1.236 + return value; 1.237 +} 1.238 + 1.239 +AL_API ALint AL_APIENTRY alGetInteger(ALenum pname) 1.240 +{ 1.241 + ALCcontext *Context; 1.242 + ALint value = 0; 1.243 + 1.244 + Context = GetLockedContext(); 1.245 + if(!Context) return 0; 1.246 + 1.247 + switch(pname) 1.248 + { 1.249 + case AL_DOPPLER_FACTOR: 1.250 + value = (ALint)Context->DopplerFactor; 1.251 + break; 1.252 + 1.253 + case AL_DOPPLER_VELOCITY: 1.254 + value = (ALint)Context->DopplerVelocity; 1.255 + break; 1.256 + 1.257 + case AL_DISTANCE_MODEL: 1.258 + value = (ALint)Context->DistanceModel; 1.259 + break; 1.260 + 1.261 + case AL_SPEED_OF_SOUND: 1.262 + value = (ALint)Context->flSpeedOfSound; 1.263 + break; 1.264 + 1.265 + case AL_DEFERRED_UPDATES_SOFT: 1.266 + value = (ALint)Context->DeferUpdates; 1.267 + break; 1.268 + 1.269 + default: 1.270 + alSetError(Context, AL_INVALID_ENUM); 1.271 + break; 1.272 + } 1.273 + 1.274 + UnlockContext(Context); 1.275 + 1.276 + return value; 1.277 +} 1.278 + 1.279 +AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname,ALboolean *data) 1.280 +{ 1.281 + ALCcontext *Context; 1.282 + 1.283 + if(data) 1.284 + { 1.285 + switch(pname) 1.286 + { 1.287 + case AL_DOPPLER_FACTOR: 1.288 + case AL_DOPPLER_VELOCITY: 1.289 + case AL_DISTANCE_MODEL: 1.290 + case AL_SPEED_OF_SOUND: 1.291 + case AL_DEFERRED_UPDATES_SOFT: 1.292 + *data = alGetBoolean(pname); 1.293 + return; 1.294 + } 1.295 + } 1.296 + 1.297 + Context = GetLockedContext(); 1.298 + if(!Context) return; 1.299 + 1.300 + if(data) 1.301 + { 1.302 + switch(pname) 1.303 + { 1.304 + default: 1.305 + alSetError(Context, AL_INVALID_ENUM); 1.306 + break; 1.307 + } 1.308 + } 1.309 + else 1.310 + { 1.311 + // data is a NULL pointer 1.312 + alSetError(Context, AL_INVALID_VALUE); 1.313 + } 1.314 + 1.315 + UnlockContext(Context); 1.316 +} 1.317 + 1.318 +AL_API ALvoid AL_APIENTRY alGetDoublev(ALenum pname,ALdouble *data) 1.319 +{ 1.320 + ALCcontext *Context; 1.321 + 1.322 + if(data) 1.323 + { 1.324 + switch(pname) 1.325 + { 1.326 + case AL_DOPPLER_FACTOR: 1.327 + case AL_DOPPLER_VELOCITY: 1.328 + case AL_DISTANCE_MODEL: 1.329 + case AL_SPEED_OF_SOUND: 1.330 + case AL_DEFERRED_UPDATES_SOFT: 1.331 + *data = alGetDouble(pname); 1.332 + return; 1.333 + } 1.334 + } 1.335 + 1.336 + Context = GetLockedContext(); 1.337 + if(!Context) return; 1.338 + 1.339 + if(data) 1.340 + { 1.341 + switch(pname) 1.342 + { 1.343 + default: 1.344 + alSetError(Context, AL_INVALID_ENUM); 1.345 + break; 1.346 + } 1.347 + } 1.348 + else 1.349 + { 1.350 + // data is a NULL pointer 1.351 + alSetError(Context, AL_INVALID_VALUE); 1.352 + } 1.353 + 1.354 + UnlockContext(Context); 1.355 +} 1.356 + 1.357 +AL_API ALvoid AL_APIENTRY alGetFloatv(ALenum pname,ALfloat *data) 1.358 +{ 1.359 + ALCcontext *Context; 1.360 + 1.361 + if(data) 1.362 + { 1.363 + switch(pname) 1.364 + { 1.365 + case AL_DOPPLER_FACTOR: 1.366 + case AL_DOPPLER_VELOCITY: 1.367 + case AL_DISTANCE_MODEL: 1.368 + case AL_SPEED_OF_SOUND: 1.369 + case AL_DEFERRED_UPDATES_SOFT: 1.370 + *data = alGetFloat(pname); 1.371 + return; 1.372 + } 1.373 + } 1.374 + 1.375 + Context = GetLockedContext(); 1.376 + if(!Context) return; 1.377 + 1.378 + if(data) 1.379 + { 1.380 + switch(pname) 1.381 + { 1.382 + default: 1.383 + alSetError(Context, AL_INVALID_ENUM); 1.384 + break; 1.385 + } 1.386 + } 1.387 + else 1.388 + { 1.389 + // data is a NULL pointer 1.390 + alSetError(Context, AL_INVALID_VALUE); 1.391 + } 1.392 + 1.393 + UnlockContext(Context); 1.394 +} 1.395 + 1.396 +AL_API ALvoid AL_APIENTRY alGetIntegerv(ALenum pname,ALint *data) 1.397 +{ 1.398 + ALCcontext *Context; 1.399 + 1.400 + if(data) 1.401 + { 1.402 + switch(pname) 1.403 + { 1.404 + case AL_DOPPLER_FACTOR: 1.405 + case AL_DOPPLER_VELOCITY: 1.406 + case AL_DISTANCE_MODEL: 1.407 + case AL_SPEED_OF_SOUND: 1.408 + case AL_DEFERRED_UPDATES_SOFT: 1.409 + *data = alGetInteger(pname); 1.410 + return; 1.411 + } 1.412 + } 1.413 + 1.414 + Context = GetLockedContext(); 1.415 + if(!Context) return; 1.416 + 1.417 + if(data) 1.418 + { 1.419 + switch(pname) 1.420 + { 1.421 + default: 1.422 + alSetError(Context, AL_INVALID_ENUM); 1.423 + break; 1.424 + } 1.425 + } 1.426 + else 1.427 + { 1.428 + // data is a NULL pointer 1.429 + alSetError(Context, AL_INVALID_VALUE); 1.430 + } 1.431 + 1.432 + UnlockContext(Context); 1.433 +} 1.434 + 1.435 +AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname) 1.436 +{ 1.437 + const ALchar *value; 1.438 + ALCcontext *pContext; 1.439 + 1.440 + pContext = GetLockedContext(); 1.441 + if(!pContext) return NULL; 1.442 + 1.443 + switch(pname) 1.444 + { 1.445 + case AL_VENDOR: 1.446 + value=alVendor; 1.447 + break; 1.448 + 1.449 + case AL_VERSION: 1.450 + value=alVersion; 1.451 + break; 1.452 + 1.453 + case AL_RENDERER: 1.454 + value=alRenderer; 1.455 + break; 1.456 + 1.457 + case AL_EXTENSIONS: 1.458 + value=pContext->ExtensionList;//alExtensions; 1.459 + break; 1.460 + 1.461 + case AL_NO_ERROR: 1.462 + value=alNoError; 1.463 + break; 1.464 + 1.465 + case AL_INVALID_NAME: 1.466 + value=alErrInvalidName; 1.467 + break; 1.468 + 1.469 + case AL_INVALID_ENUM: 1.470 + value=alErrInvalidEnum; 1.471 + break; 1.472 + 1.473 + case AL_INVALID_VALUE: 1.474 + value=alErrInvalidValue; 1.475 + break; 1.476 + 1.477 + case AL_INVALID_OPERATION: 1.478 + value=alErrInvalidOp; 1.479 + break; 1.480 + 1.481 + case AL_OUT_OF_MEMORY: 1.482 + value=alErrOutOfMemory; 1.483 + break; 1.484 + 1.485 + default: 1.486 + value=NULL; 1.487 + alSetError(pContext, AL_INVALID_ENUM); 1.488 + break; 1.489 + } 1.490 + 1.491 + UnlockContext(pContext); 1.492 + 1.493 + return value; 1.494 +} 1.495 + 1.496 +AL_API ALvoid AL_APIENTRY alDopplerFactor(ALfloat value) 1.497 +{ 1.498 + ALCcontext *Context; 1.499 + 1.500 + Context = GetLockedContext(); 1.501 + if(!Context) return; 1.502 + 1.503 + if(value >= 0.0f && isfinite(value)) 1.504 + { 1.505 + Context->DopplerFactor = value; 1.506 + Context->UpdateSources = AL_TRUE; 1.507 + } 1.508 + else 1.509 + alSetError(Context, AL_INVALID_VALUE); 1.510 + 1.511 + UnlockContext(Context); 1.512 +} 1.513 + 1.514 +AL_API ALvoid AL_APIENTRY alDopplerVelocity(ALfloat value) 1.515 +{ 1.516 + ALCcontext *Context; 1.517 + 1.518 + Context = GetLockedContext(); 1.519 + if(!Context) return; 1.520 + 1.521 + if(value > 0.0f && isfinite(value)) 1.522 + { 1.523 + Context->DopplerVelocity=value; 1.524 + Context->UpdateSources = AL_TRUE; 1.525 + } 1.526 + else 1.527 + alSetError(Context, AL_INVALID_VALUE); 1.528 + 1.529 + UnlockContext(Context); 1.530 +} 1.531 + 1.532 +AL_API ALvoid AL_APIENTRY alSpeedOfSound(ALfloat flSpeedOfSound) 1.533 +{ 1.534 + ALCcontext *pContext; 1.535 + 1.536 + pContext = GetLockedContext(); 1.537 + if(!pContext) return; 1.538 + 1.539 + if(flSpeedOfSound > 0.0f && isfinite(flSpeedOfSound)) 1.540 + { 1.541 + pContext->flSpeedOfSound = flSpeedOfSound; 1.542 + pContext->UpdateSources = AL_TRUE; 1.543 + } 1.544 + else 1.545 + alSetError(pContext, AL_INVALID_VALUE); 1.546 + 1.547 + UnlockContext(pContext); 1.548 +} 1.549 + 1.550 +AL_API ALvoid AL_APIENTRY alDistanceModel(ALenum value) 1.551 +{ 1.552 + ALCcontext *Context; 1.553 + 1.554 + Context = GetLockedContext(); 1.555 + if(!Context) return; 1.556 + 1.557 + switch(value) 1.558 + { 1.559 + case AL_NONE: 1.560 + case AL_INVERSE_DISTANCE: 1.561 + case AL_INVERSE_DISTANCE_CLAMPED: 1.562 + case AL_LINEAR_DISTANCE: 1.563 + case AL_LINEAR_DISTANCE_CLAMPED: 1.564 + case AL_EXPONENT_DISTANCE: 1.565 + case AL_EXPONENT_DISTANCE_CLAMPED: 1.566 + Context->DistanceModel = value; 1.567 + Context->UpdateSources = AL_TRUE; 1.568 + break; 1.569 + 1.570 + default: 1.571 + alSetError(Context, AL_INVALID_VALUE); 1.572 + break; 1.573 + } 1.574 + 1.575 + UnlockContext(Context); 1.576 +} 1.577 + 1.578 + 1.579 +AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void) 1.580 +{ 1.581 + ALCcontext *Context; 1.582 + 1.583 + Context = GetLockedContext(); 1.584 + if(!Context) return; 1.585 + 1.586 + if(!Context->DeferUpdates) 1.587 + { 1.588 + ALboolean UpdateSources; 1.589 + ALsource **src, **src_end; 1.590 + ALeffectslot *ALEffectSlot; 1.591 + ALsizei e; 1.592 + 1.593 + Context->DeferUpdates = AL_TRUE; 1.594 + 1.595 + /* Make sure all pending updates are performed */ 1.596 + UpdateSources = Context->UpdateSources; 1.597 + Context->UpdateSources = AL_FALSE; 1.598 + 1.599 + src = Context->ActiveSources; 1.600 + src_end = src + Context->ActiveSourceCount; 1.601 + while(src != src_end) 1.602 + { 1.603 + if((*src)->state != AL_PLAYING) 1.604 + { 1.605 + Context->ActiveSourceCount--; 1.606 + *src = *(--src_end); 1.607 + continue; 1.608 + } 1.609 + 1.610 + if((*src)->NeedsUpdate || UpdateSources) 1.611 + { 1.612 + (*src)->NeedsUpdate = AL_FALSE; 1.613 + ALsource_Update(*src, Context); 1.614 + } 1.615 + src++; 1.616 + } 1.617 + 1.618 + for(e = 0;e < Context->EffectSlotMap.size;e++) 1.619 + { 1.620 + ALEffectSlot = Context->EffectSlotMap.array[e].value; 1.621 + if(ALEffectSlot->NeedsUpdate) 1.622 + { 1.623 + ALEffectSlot->NeedsUpdate = AL_FALSE; 1.624 + ALEffect_Update(ALEffectSlot->EffectState, Context, ALEffectSlot); 1.625 + } 1.626 + } 1.627 + } 1.628 + 1.629 + UnlockContext(Context); 1.630 +} 1.631 + 1.632 +AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void) 1.633 +{ 1.634 + ALCcontext *Context; 1.635 + 1.636 + Context = GetLockedContext(); 1.637 + if(!Context) return; 1.638 + 1.639 + if(Context->DeferUpdates) 1.640 + { 1.641 + ALsizei pos; 1.642 + 1.643 + Context->DeferUpdates = AL_FALSE; 1.644 + 1.645 + for(pos = 0;pos < Context->SourceMap.size;pos++) 1.646 + { 1.647 + ALsource *Source = Context->SourceMap.array[pos].value; 1.648 + ALenum new_state; 1.649 + 1.650 + if(Source->lOffset != -1) 1.651 + ApplyOffset(Source); 1.652 + 1.653 + new_state = Source->new_state; 1.654 + Source->new_state = AL_NONE; 1.655 + if(new_state) 1.656 + SetSourceState(Source, Context, new_state); 1.657 + } 1.658 + } 1.659 + 1.660 + UnlockContext(Context); 1.661 +}