Mercurial > audio-send
view OpenAL32/alState.c @ 27:f79bef1687c5
separated some tasks in build.xml
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 19 Nov 2011 19:25:21 -0700 |
parents | f9476ff7637e |
children |
line wrap: on
line source
1 /**2 * OpenAL cross platform audio library3 * Copyright (C) 1999-2000 by authors.4 * This library is free software; you can redistribute it and/or5 * modify it under the terms of the GNU Library General Public6 * License as published by the Free Software Foundation; either7 * version 2 of the License, or (at your option) any later version.8 *9 * This library is distributed in the hope that it will be useful,10 * but WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12 * Library General Public License for more details.13 *14 * You should have received a copy of the GNU Library General Public15 * License along with this library; if not, write to the16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,17 * Boston, MA 02111-1307, USA.18 * Or go to http://www.gnu.org/copyleft/lgpl.html19 */21 #include "config.h"23 #include <stdlib.h>24 #include "alMain.h"25 #include "AL/alc.h"26 #include "AL/alext.h"27 #include "alError.h"28 #include "alSource.h"29 #include "alAuxEffectSlot.h"30 #include "alState.h"32 static const ALchar alVendor[] = "OpenAL Community";33 static const ALchar alVersion[] = "1.1 ALSOFT "ALSOFT_VERSION;34 static const ALchar alRenderer[] = "OpenAL Soft";36 // Error Messages37 static const ALchar alNoError[] = "No Error";38 static const ALchar alErrInvalidName[] = "Invalid Name";39 static const ALchar alErrInvalidEnum[] = "Invalid Enum";40 static const ALchar alErrInvalidValue[] = "Invalid Value";41 static const ALchar alErrInvalidOp[] = "Invalid Operation";42 static const ALchar alErrOutOfMemory[] = "Out of Memory";44 AL_API ALvoid AL_APIENTRY alEnable(ALenum capability)45 {46 ALCcontext *Context;48 Context = GetLockedContext();49 if(!Context) return;51 switch(capability)52 {53 case AL_SOURCE_DISTANCE_MODEL:54 Context->SourceDistanceModel = AL_TRUE;55 Context->UpdateSources = AL_TRUE;56 break;58 default:59 alSetError(Context, AL_INVALID_ENUM);60 break;61 }63 UnlockContext(Context);64 }66 AL_API ALvoid AL_APIENTRY alDisable(ALenum capability)67 {68 ALCcontext *Context;70 Context = GetLockedContext();71 if(!Context) return;73 switch(capability)74 {75 case AL_SOURCE_DISTANCE_MODEL:76 Context->SourceDistanceModel = AL_FALSE;77 Context->UpdateSources = AL_TRUE;78 break;80 default:81 alSetError(Context, AL_INVALID_ENUM);82 break;83 }85 UnlockContext(Context);86 }88 AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability)89 {90 ALCcontext *Context;91 ALboolean value=AL_FALSE;93 Context = GetLockedContext();94 if(!Context) return AL_FALSE;96 switch(capability)97 {98 case AL_SOURCE_DISTANCE_MODEL:99 value = Context->SourceDistanceModel;100 break;102 default:103 alSetError(Context, AL_INVALID_ENUM);104 break;105 }107 UnlockContext(Context);109 return value;110 }112 AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname)113 {114 ALCcontext *Context;115 ALboolean value=AL_FALSE;117 Context = GetLockedContext();118 if(!Context) return AL_FALSE;120 switch(pname)121 {122 case AL_DOPPLER_FACTOR:123 if(Context->DopplerFactor != 0.0f)124 value = AL_TRUE;125 break;127 case AL_DOPPLER_VELOCITY:128 if(Context->DopplerVelocity != 0.0f)129 value = AL_TRUE;130 break;132 case AL_DISTANCE_MODEL:133 if(Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED)134 value = AL_TRUE;135 break;137 case AL_SPEED_OF_SOUND:138 if(Context->flSpeedOfSound != 0.0f)139 value = AL_TRUE;140 break;142 case AL_DEFERRED_UPDATES_SOFT:143 value = Context->DeferUpdates;144 break;146 default:147 alSetError(Context, AL_INVALID_ENUM);148 break;149 }151 UnlockContext(Context);153 return value;154 }156 AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname)157 {158 ALCcontext *Context;159 ALdouble value = 0.0;161 Context = GetLockedContext();162 if(!Context) return 0.0;164 switch(pname)165 {166 case AL_DOPPLER_FACTOR:167 value = (double)Context->DopplerFactor;168 break;170 case AL_DOPPLER_VELOCITY:171 value = (double)Context->DopplerVelocity;172 break;174 case AL_DISTANCE_MODEL:175 value = (double)Context->DistanceModel;176 break;178 case AL_SPEED_OF_SOUND:179 value = (double)Context->flSpeedOfSound;180 break;182 case AL_DEFERRED_UPDATES_SOFT:183 value = (ALdouble)Context->DeferUpdates;184 break;186 default:187 alSetError(Context, AL_INVALID_ENUM);188 break;189 }191 UnlockContext(Context);193 return value;194 }196 AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname)197 {198 ALCcontext *Context;199 ALfloat value = 0.0f;201 Context = GetLockedContext();202 if(!Context) return 0.0f;204 switch(pname)205 {206 case AL_DOPPLER_FACTOR:207 value = Context->DopplerFactor;208 break;210 case AL_DOPPLER_VELOCITY:211 value = Context->DopplerVelocity;212 break;214 case AL_DISTANCE_MODEL:215 value = (float)Context->DistanceModel;216 break;218 case AL_SPEED_OF_SOUND:219 value = Context->flSpeedOfSound;220 break;222 case AL_DEFERRED_UPDATES_SOFT:223 value = (ALfloat)Context->DeferUpdates;224 break;226 default:227 alSetError(Context, AL_INVALID_ENUM);228 break;229 }231 UnlockContext(Context);233 return value;234 }236 AL_API ALint AL_APIENTRY alGetInteger(ALenum pname)237 {238 ALCcontext *Context;239 ALint value = 0;241 Context = GetLockedContext();242 if(!Context) return 0;244 switch(pname)245 {246 case AL_DOPPLER_FACTOR:247 value = (ALint)Context->DopplerFactor;248 break;250 case AL_DOPPLER_VELOCITY:251 value = (ALint)Context->DopplerVelocity;252 break;254 case AL_DISTANCE_MODEL:255 value = (ALint)Context->DistanceModel;256 break;258 case AL_SPEED_OF_SOUND:259 value = (ALint)Context->flSpeedOfSound;260 break;262 case AL_DEFERRED_UPDATES_SOFT:263 value = (ALint)Context->DeferUpdates;264 break;266 default:267 alSetError(Context, AL_INVALID_ENUM);268 break;269 }271 UnlockContext(Context);273 return value;274 }276 AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname,ALboolean *data)277 {278 ALCcontext *Context;280 if(data)281 {282 switch(pname)283 {284 case AL_DOPPLER_FACTOR:285 case AL_DOPPLER_VELOCITY:286 case AL_DISTANCE_MODEL:287 case AL_SPEED_OF_SOUND:288 case AL_DEFERRED_UPDATES_SOFT:289 *data = alGetBoolean(pname);290 return;291 }292 }294 Context = GetLockedContext();295 if(!Context) return;297 if(data)298 {299 switch(pname)300 {301 default:302 alSetError(Context, AL_INVALID_ENUM);303 break;304 }305 }306 else307 {308 // data is a NULL pointer309 alSetError(Context, AL_INVALID_VALUE);310 }312 UnlockContext(Context);313 }315 AL_API ALvoid AL_APIENTRY alGetDoublev(ALenum pname,ALdouble *data)316 {317 ALCcontext *Context;319 if(data)320 {321 switch(pname)322 {323 case AL_DOPPLER_FACTOR:324 case AL_DOPPLER_VELOCITY:325 case AL_DISTANCE_MODEL:326 case AL_SPEED_OF_SOUND:327 case AL_DEFERRED_UPDATES_SOFT:328 *data = alGetDouble(pname);329 return;330 }331 }333 Context = GetLockedContext();334 if(!Context) return;336 if(data)337 {338 switch(pname)339 {340 default:341 alSetError(Context, AL_INVALID_ENUM);342 break;343 }344 }345 else346 {347 // data is a NULL pointer348 alSetError(Context, AL_INVALID_VALUE);349 }351 UnlockContext(Context);352 }354 AL_API ALvoid AL_APIENTRY alGetFloatv(ALenum pname,ALfloat *data)355 {356 ALCcontext *Context;358 if(data)359 {360 switch(pname)361 {362 case AL_DOPPLER_FACTOR:363 case AL_DOPPLER_VELOCITY:364 case AL_DISTANCE_MODEL:365 case AL_SPEED_OF_SOUND:366 case AL_DEFERRED_UPDATES_SOFT:367 *data = alGetFloat(pname);368 return;369 }370 }372 Context = GetLockedContext();373 if(!Context) return;375 if(data)376 {377 switch(pname)378 {379 default:380 alSetError(Context, AL_INVALID_ENUM);381 break;382 }383 }384 else385 {386 // data is a NULL pointer387 alSetError(Context, AL_INVALID_VALUE);388 }390 UnlockContext(Context);391 }393 AL_API ALvoid AL_APIENTRY alGetIntegerv(ALenum pname,ALint *data)394 {395 ALCcontext *Context;397 if(data)398 {399 switch(pname)400 {401 case AL_DOPPLER_FACTOR:402 case AL_DOPPLER_VELOCITY:403 case AL_DISTANCE_MODEL:404 case AL_SPEED_OF_SOUND:405 case AL_DEFERRED_UPDATES_SOFT:406 *data = alGetInteger(pname);407 return;408 }409 }411 Context = GetLockedContext();412 if(!Context) return;414 if(data)415 {416 switch(pname)417 {418 default:419 alSetError(Context, AL_INVALID_ENUM);420 break;421 }422 }423 else424 {425 // data is a NULL pointer426 alSetError(Context, AL_INVALID_VALUE);427 }429 UnlockContext(Context);430 }432 AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname)433 {434 const ALchar *value;435 ALCcontext *pContext;437 pContext = GetLockedContext();438 if(!pContext) return NULL;440 switch(pname)441 {442 case AL_VENDOR:443 value=alVendor;444 break;446 case AL_VERSION:447 value=alVersion;448 break;450 case AL_RENDERER:451 value=alRenderer;452 break;454 case AL_EXTENSIONS:455 value=pContext->ExtensionList;//alExtensions;456 break;458 case AL_NO_ERROR:459 value=alNoError;460 break;462 case AL_INVALID_NAME:463 value=alErrInvalidName;464 break;466 case AL_INVALID_ENUM:467 value=alErrInvalidEnum;468 break;470 case AL_INVALID_VALUE:471 value=alErrInvalidValue;472 break;474 case AL_INVALID_OPERATION:475 value=alErrInvalidOp;476 break;478 case AL_OUT_OF_MEMORY:479 value=alErrOutOfMemory;480 break;482 default:483 value=NULL;484 alSetError(pContext, AL_INVALID_ENUM);485 break;486 }488 UnlockContext(pContext);490 return value;491 }493 AL_API ALvoid AL_APIENTRY alDopplerFactor(ALfloat value)494 {495 ALCcontext *Context;497 Context = GetLockedContext();498 if(!Context) return;500 if(value >= 0.0f && isfinite(value))501 {502 Context->DopplerFactor = value;503 Context->UpdateSources = AL_TRUE;504 }505 else506 alSetError(Context, AL_INVALID_VALUE);508 UnlockContext(Context);509 }511 AL_API ALvoid AL_APIENTRY alDopplerVelocity(ALfloat value)512 {513 ALCcontext *Context;515 Context = GetLockedContext();516 if(!Context) return;518 if(value > 0.0f && isfinite(value))519 {520 Context->DopplerVelocity=value;521 Context->UpdateSources = AL_TRUE;522 }523 else524 alSetError(Context, AL_INVALID_VALUE);526 UnlockContext(Context);527 }529 AL_API ALvoid AL_APIENTRY alSpeedOfSound(ALfloat flSpeedOfSound)530 {531 ALCcontext *pContext;533 pContext = GetLockedContext();534 if(!pContext) return;536 if(flSpeedOfSound > 0.0f && isfinite(flSpeedOfSound))537 {538 pContext->flSpeedOfSound = flSpeedOfSound;539 pContext->UpdateSources = AL_TRUE;540 }541 else542 alSetError(pContext, AL_INVALID_VALUE);544 UnlockContext(pContext);545 }547 AL_API ALvoid AL_APIENTRY alDistanceModel(ALenum value)548 {549 ALCcontext *Context;551 Context = GetLockedContext();552 if(!Context) return;554 switch(value)555 {556 case AL_NONE:557 case AL_INVERSE_DISTANCE:558 case AL_INVERSE_DISTANCE_CLAMPED:559 case AL_LINEAR_DISTANCE:560 case AL_LINEAR_DISTANCE_CLAMPED:561 case AL_EXPONENT_DISTANCE:562 case AL_EXPONENT_DISTANCE_CLAMPED:563 Context->DistanceModel = value;564 Context->UpdateSources = AL_TRUE;565 break;567 default:568 alSetError(Context, AL_INVALID_VALUE);569 break;570 }572 UnlockContext(Context);573 }576 AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void)577 {578 ALCcontext *Context;580 Context = GetLockedContext();581 if(!Context) return;583 if(!Context->DeferUpdates)584 {585 ALboolean UpdateSources;586 ALsource **src, **src_end;587 ALeffectslot *ALEffectSlot;588 ALsizei e;590 Context->DeferUpdates = AL_TRUE;592 /* Make sure all pending updates are performed */593 UpdateSources = Context->UpdateSources;594 Context->UpdateSources = AL_FALSE;596 src = Context->ActiveSources;597 src_end = src + Context->ActiveSourceCount;598 while(src != src_end)599 {600 if((*src)->state != AL_PLAYING)601 {602 Context->ActiveSourceCount--;603 *src = *(--src_end);604 continue;605 }607 if((*src)->NeedsUpdate || UpdateSources)608 {609 (*src)->NeedsUpdate = AL_FALSE;610 ALsource_Update(*src, Context);611 }612 src++;613 }615 for(e = 0;e < Context->EffectSlotMap.size;e++)616 {617 ALEffectSlot = Context->EffectSlotMap.array[e].value;618 if(ALEffectSlot->NeedsUpdate)619 {620 ALEffectSlot->NeedsUpdate = AL_FALSE;621 ALEffect_Update(ALEffectSlot->EffectState, Context, ALEffectSlot);622 }623 }624 }626 UnlockContext(Context);627 }629 AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void)630 {631 ALCcontext *Context;633 Context = GetLockedContext();634 if(!Context) return;636 if(Context->DeferUpdates)637 {638 ALsizei pos;640 Context->DeferUpdates = AL_FALSE;642 for(pos = 0;pos < Context->SourceMap.size;pos++)643 {644 ALsource *Source = Context->SourceMap.array[pos].value;645 ALenum new_state;647 if(Source->lOffset != -1)648 ApplyOffset(Source);650 new_state = Source->new_state;651 Source->new_state = AL_NONE;652 if(new_state)653 SetSourceState(Source, Context, new_state);654 }655 }657 UnlockContext(Context);658 }