rlm@0: /** rlm@0: * OpenAL cross platform audio library rlm@0: * Copyright (C) 1999-2000 by authors. rlm@0: * This library is free software; you can redistribute it and/or rlm@0: * modify it under the terms of the GNU Library General Public rlm@0: * License as published by the Free Software Foundation; either rlm@0: * version 2 of the License, or (at your option) any later version. rlm@0: * rlm@0: * This library is distributed in the hope that it will be useful, rlm@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of rlm@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU rlm@0: * Library General Public License for more details. rlm@0: * rlm@0: * You should have received a copy of the GNU Library General Public rlm@0: * License along with this library; if not, write to the rlm@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, rlm@0: * Boston, MA 02111-1307, USA. rlm@0: * Or go to http://www.gnu.org/copyleft/lgpl.html rlm@0: */ rlm@0: rlm@0: #include "config.h" rlm@0: rlm@0: #include rlm@0: #include "alMain.h" rlm@0: #include "AL/alc.h" rlm@0: #include "AL/alext.h" rlm@0: #include "alError.h" rlm@0: #include "alSource.h" rlm@0: #include "alAuxEffectSlot.h" rlm@0: #include "alState.h" rlm@0: rlm@0: static const ALchar alVendor[] = "OpenAL Community"; rlm@0: static const ALchar alVersion[] = "1.1 ALSOFT "ALSOFT_VERSION; rlm@0: static const ALchar alRenderer[] = "OpenAL Soft"; rlm@0: rlm@0: // Error Messages rlm@0: static const ALchar alNoError[] = "No Error"; rlm@0: static const ALchar alErrInvalidName[] = "Invalid Name"; rlm@0: static const ALchar alErrInvalidEnum[] = "Invalid Enum"; rlm@0: static const ALchar alErrInvalidValue[] = "Invalid Value"; rlm@0: static const ALchar alErrInvalidOp[] = "Invalid Operation"; rlm@0: static const ALchar alErrOutOfMemory[] = "Out of Memory"; rlm@0: rlm@0: AL_API ALvoid AL_APIENTRY alEnable(ALenum capability) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return; rlm@0: rlm@0: switch(capability) rlm@0: { rlm@0: case AL_SOURCE_DISTANCE_MODEL: rlm@0: Context->SourceDistanceModel = AL_TRUE; rlm@0: Context->UpdateSources = AL_TRUE; rlm@0: break; rlm@0: rlm@0: default: rlm@0: alSetError(Context, AL_INVALID_ENUM); rlm@0: break; rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: } rlm@0: rlm@0: AL_API ALvoid AL_APIENTRY alDisable(ALenum capability) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return; rlm@0: rlm@0: switch(capability) rlm@0: { rlm@0: case AL_SOURCE_DISTANCE_MODEL: rlm@0: Context->SourceDistanceModel = AL_FALSE; rlm@0: Context->UpdateSources = AL_TRUE; rlm@0: break; rlm@0: rlm@0: default: rlm@0: alSetError(Context, AL_INVALID_ENUM); rlm@0: break; rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: } rlm@0: rlm@0: AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: ALboolean value=AL_FALSE; rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return AL_FALSE; rlm@0: rlm@0: switch(capability) rlm@0: { rlm@0: case AL_SOURCE_DISTANCE_MODEL: rlm@0: value = Context->SourceDistanceModel; rlm@0: break; rlm@0: rlm@0: default: rlm@0: alSetError(Context, AL_INVALID_ENUM); rlm@0: break; rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: rlm@0: return value; rlm@0: } rlm@0: rlm@0: AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: ALboolean value=AL_FALSE; rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return AL_FALSE; rlm@0: rlm@0: switch(pname) rlm@0: { rlm@0: case AL_DOPPLER_FACTOR: rlm@0: if(Context->DopplerFactor != 0.0f) rlm@0: value = AL_TRUE; rlm@0: break; rlm@0: rlm@0: case AL_DOPPLER_VELOCITY: rlm@0: if(Context->DopplerVelocity != 0.0f) rlm@0: value = AL_TRUE; rlm@0: break; rlm@0: rlm@0: case AL_DISTANCE_MODEL: rlm@0: if(Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED) rlm@0: value = AL_TRUE; rlm@0: break; rlm@0: rlm@0: case AL_SPEED_OF_SOUND: rlm@0: if(Context->flSpeedOfSound != 0.0f) rlm@0: value = AL_TRUE; rlm@0: break; rlm@0: rlm@0: case AL_DEFERRED_UPDATES_SOFT: rlm@0: value = Context->DeferUpdates; rlm@0: break; rlm@0: rlm@0: default: rlm@0: alSetError(Context, AL_INVALID_ENUM); rlm@0: break; rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: rlm@0: return value; rlm@0: } rlm@0: rlm@0: AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: ALdouble value = 0.0; rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return 0.0; rlm@0: rlm@0: switch(pname) rlm@0: { rlm@0: case AL_DOPPLER_FACTOR: rlm@0: value = (double)Context->DopplerFactor; rlm@0: break; rlm@0: rlm@0: case AL_DOPPLER_VELOCITY: rlm@0: value = (double)Context->DopplerVelocity; rlm@0: break; rlm@0: rlm@0: case AL_DISTANCE_MODEL: rlm@0: value = (double)Context->DistanceModel; rlm@0: break; rlm@0: rlm@0: case AL_SPEED_OF_SOUND: rlm@0: value = (double)Context->flSpeedOfSound; rlm@0: break; rlm@0: rlm@0: case AL_DEFERRED_UPDATES_SOFT: rlm@0: value = (ALdouble)Context->DeferUpdates; rlm@0: break; rlm@0: rlm@0: default: rlm@0: alSetError(Context, AL_INVALID_ENUM); rlm@0: break; rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: rlm@0: return value; rlm@0: } rlm@0: rlm@0: AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: ALfloat value = 0.0f; rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return 0.0f; rlm@0: rlm@0: switch(pname) rlm@0: { rlm@0: case AL_DOPPLER_FACTOR: rlm@0: value = Context->DopplerFactor; rlm@0: break; rlm@0: rlm@0: case AL_DOPPLER_VELOCITY: rlm@0: value = Context->DopplerVelocity; rlm@0: break; rlm@0: rlm@0: case AL_DISTANCE_MODEL: rlm@0: value = (float)Context->DistanceModel; rlm@0: break; rlm@0: rlm@0: case AL_SPEED_OF_SOUND: rlm@0: value = Context->flSpeedOfSound; rlm@0: break; rlm@0: rlm@0: case AL_DEFERRED_UPDATES_SOFT: rlm@0: value = (ALfloat)Context->DeferUpdates; rlm@0: break; rlm@0: rlm@0: default: rlm@0: alSetError(Context, AL_INVALID_ENUM); rlm@0: break; rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: rlm@0: return value; rlm@0: } rlm@0: rlm@0: AL_API ALint AL_APIENTRY alGetInteger(ALenum pname) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: ALint value = 0; rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return 0; rlm@0: rlm@0: switch(pname) rlm@0: { rlm@0: case AL_DOPPLER_FACTOR: rlm@0: value = (ALint)Context->DopplerFactor; rlm@0: break; rlm@0: rlm@0: case AL_DOPPLER_VELOCITY: rlm@0: value = (ALint)Context->DopplerVelocity; rlm@0: break; rlm@0: rlm@0: case AL_DISTANCE_MODEL: rlm@0: value = (ALint)Context->DistanceModel; rlm@0: break; rlm@0: rlm@0: case AL_SPEED_OF_SOUND: rlm@0: value = (ALint)Context->flSpeedOfSound; rlm@0: break; rlm@0: rlm@0: case AL_DEFERRED_UPDATES_SOFT: rlm@0: value = (ALint)Context->DeferUpdates; rlm@0: break; rlm@0: rlm@0: default: rlm@0: alSetError(Context, AL_INVALID_ENUM); rlm@0: break; rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: rlm@0: return value; rlm@0: } rlm@0: rlm@0: AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname,ALboolean *data) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: rlm@0: if(data) rlm@0: { rlm@0: switch(pname) rlm@0: { rlm@0: case AL_DOPPLER_FACTOR: rlm@0: case AL_DOPPLER_VELOCITY: rlm@0: case AL_DISTANCE_MODEL: rlm@0: case AL_SPEED_OF_SOUND: rlm@0: case AL_DEFERRED_UPDATES_SOFT: rlm@0: *data = alGetBoolean(pname); rlm@0: return; rlm@0: } rlm@0: } rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return; rlm@0: rlm@0: if(data) rlm@0: { rlm@0: switch(pname) rlm@0: { rlm@0: default: rlm@0: alSetError(Context, AL_INVALID_ENUM); rlm@0: break; rlm@0: } rlm@0: } rlm@0: else rlm@0: { rlm@0: // data is a NULL pointer rlm@0: alSetError(Context, AL_INVALID_VALUE); rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: } rlm@0: rlm@0: AL_API ALvoid AL_APIENTRY alGetDoublev(ALenum pname,ALdouble *data) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: rlm@0: if(data) rlm@0: { rlm@0: switch(pname) rlm@0: { rlm@0: case AL_DOPPLER_FACTOR: rlm@0: case AL_DOPPLER_VELOCITY: rlm@0: case AL_DISTANCE_MODEL: rlm@0: case AL_SPEED_OF_SOUND: rlm@0: case AL_DEFERRED_UPDATES_SOFT: rlm@0: *data = alGetDouble(pname); rlm@0: return; rlm@0: } rlm@0: } rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return; rlm@0: rlm@0: if(data) rlm@0: { rlm@0: switch(pname) rlm@0: { rlm@0: default: rlm@0: alSetError(Context, AL_INVALID_ENUM); rlm@0: break; rlm@0: } rlm@0: } rlm@0: else rlm@0: { rlm@0: // data is a NULL pointer rlm@0: alSetError(Context, AL_INVALID_VALUE); rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: } rlm@0: rlm@0: AL_API ALvoid AL_APIENTRY alGetFloatv(ALenum pname,ALfloat *data) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: rlm@0: if(data) rlm@0: { rlm@0: switch(pname) rlm@0: { rlm@0: case AL_DOPPLER_FACTOR: rlm@0: case AL_DOPPLER_VELOCITY: rlm@0: case AL_DISTANCE_MODEL: rlm@0: case AL_SPEED_OF_SOUND: rlm@0: case AL_DEFERRED_UPDATES_SOFT: rlm@0: *data = alGetFloat(pname); rlm@0: return; rlm@0: } rlm@0: } rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return; rlm@0: rlm@0: if(data) rlm@0: { rlm@0: switch(pname) rlm@0: { rlm@0: default: rlm@0: alSetError(Context, AL_INVALID_ENUM); rlm@0: break; rlm@0: } rlm@0: } rlm@0: else rlm@0: { rlm@0: // data is a NULL pointer rlm@0: alSetError(Context, AL_INVALID_VALUE); rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: } rlm@0: rlm@0: AL_API ALvoid AL_APIENTRY alGetIntegerv(ALenum pname,ALint *data) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: rlm@0: if(data) rlm@0: { rlm@0: switch(pname) rlm@0: { rlm@0: case AL_DOPPLER_FACTOR: rlm@0: case AL_DOPPLER_VELOCITY: rlm@0: case AL_DISTANCE_MODEL: rlm@0: case AL_SPEED_OF_SOUND: rlm@0: case AL_DEFERRED_UPDATES_SOFT: rlm@0: *data = alGetInteger(pname); rlm@0: return; rlm@0: } rlm@0: } rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return; rlm@0: rlm@0: if(data) rlm@0: { rlm@0: switch(pname) rlm@0: { rlm@0: default: rlm@0: alSetError(Context, AL_INVALID_ENUM); rlm@0: break; rlm@0: } rlm@0: } rlm@0: else rlm@0: { rlm@0: // data is a NULL pointer rlm@0: alSetError(Context, AL_INVALID_VALUE); rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: } rlm@0: rlm@0: AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname) rlm@0: { rlm@0: const ALchar *value; rlm@0: ALCcontext *pContext; rlm@0: rlm@0: pContext = GetLockedContext(); rlm@0: if(!pContext) return NULL; rlm@0: rlm@0: switch(pname) rlm@0: { rlm@0: case AL_VENDOR: rlm@0: value=alVendor; rlm@0: break; rlm@0: rlm@0: case AL_VERSION: rlm@0: value=alVersion; rlm@0: break; rlm@0: rlm@0: case AL_RENDERER: rlm@0: value=alRenderer; rlm@0: break; rlm@0: rlm@0: case AL_EXTENSIONS: rlm@0: value=pContext->ExtensionList;//alExtensions; rlm@0: break; rlm@0: rlm@0: case AL_NO_ERROR: rlm@0: value=alNoError; rlm@0: break; rlm@0: rlm@0: case AL_INVALID_NAME: rlm@0: value=alErrInvalidName; rlm@0: break; rlm@0: rlm@0: case AL_INVALID_ENUM: rlm@0: value=alErrInvalidEnum; rlm@0: break; rlm@0: rlm@0: case AL_INVALID_VALUE: rlm@0: value=alErrInvalidValue; rlm@0: break; rlm@0: rlm@0: case AL_INVALID_OPERATION: rlm@0: value=alErrInvalidOp; rlm@0: break; rlm@0: rlm@0: case AL_OUT_OF_MEMORY: rlm@0: value=alErrOutOfMemory; rlm@0: break; rlm@0: rlm@0: default: rlm@0: value=NULL; rlm@0: alSetError(pContext, AL_INVALID_ENUM); rlm@0: break; rlm@0: } rlm@0: rlm@0: UnlockContext(pContext); rlm@0: rlm@0: return value; rlm@0: } rlm@0: rlm@0: AL_API ALvoid AL_APIENTRY alDopplerFactor(ALfloat value) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return; rlm@0: rlm@0: if(value >= 0.0f && isfinite(value)) rlm@0: { rlm@0: Context->DopplerFactor = value; rlm@0: Context->UpdateSources = AL_TRUE; rlm@0: } rlm@0: else rlm@0: alSetError(Context, AL_INVALID_VALUE); rlm@0: rlm@0: UnlockContext(Context); rlm@0: } rlm@0: rlm@0: AL_API ALvoid AL_APIENTRY alDopplerVelocity(ALfloat value) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return; rlm@0: rlm@0: if(value > 0.0f && isfinite(value)) rlm@0: { rlm@0: Context->DopplerVelocity=value; rlm@0: Context->UpdateSources = AL_TRUE; rlm@0: } rlm@0: else rlm@0: alSetError(Context, AL_INVALID_VALUE); rlm@0: rlm@0: UnlockContext(Context); rlm@0: } rlm@0: rlm@0: AL_API ALvoid AL_APIENTRY alSpeedOfSound(ALfloat flSpeedOfSound) rlm@0: { rlm@0: ALCcontext *pContext; rlm@0: rlm@0: pContext = GetLockedContext(); rlm@0: if(!pContext) return; rlm@0: rlm@0: if(flSpeedOfSound > 0.0f && isfinite(flSpeedOfSound)) rlm@0: { rlm@0: pContext->flSpeedOfSound = flSpeedOfSound; rlm@0: pContext->UpdateSources = AL_TRUE; rlm@0: } rlm@0: else rlm@0: alSetError(pContext, AL_INVALID_VALUE); rlm@0: rlm@0: UnlockContext(pContext); rlm@0: } rlm@0: rlm@0: AL_API ALvoid AL_APIENTRY alDistanceModel(ALenum value) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return; rlm@0: rlm@0: switch(value) rlm@0: { rlm@0: case AL_NONE: rlm@0: case AL_INVERSE_DISTANCE: rlm@0: case AL_INVERSE_DISTANCE_CLAMPED: rlm@0: case AL_LINEAR_DISTANCE: rlm@0: case AL_LINEAR_DISTANCE_CLAMPED: rlm@0: case AL_EXPONENT_DISTANCE: rlm@0: case AL_EXPONENT_DISTANCE_CLAMPED: rlm@0: Context->DistanceModel = value; rlm@0: Context->UpdateSources = AL_TRUE; rlm@0: break; rlm@0: rlm@0: default: rlm@0: alSetError(Context, AL_INVALID_VALUE); rlm@0: break; rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: } rlm@0: rlm@0: rlm@0: AL_API ALvoid AL_APIENTRY alDeferUpdatesSOFT(void) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return; rlm@0: rlm@0: if(!Context->DeferUpdates) rlm@0: { rlm@0: ALboolean UpdateSources; rlm@0: ALsource **src, **src_end; rlm@0: ALeffectslot *ALEffectSlot; rlm@0: ALsizei e; rlm@0: rlm@0: Context->DeferUpdates = AL_TRUE; rlm@0: rlm@0: /* Make sure all pending updates are performed */ rlm@0: UpdateSources = Context->UpdateSources; rlm@0: Context->UpdateSources = AL_FALSE; rlm@0: rlm@0: src = Context->ActiveSources; rlm@0: src_end = src + Context->ActiveSourceCount; rlm@0: while(src != src_end) rlm@0: { rlm@0: if((*src)->state != AL_PLAYING) rlm@0: { rlm@0: Context->ActiveSourceCount--; rlm@0: *src = *(--src_end); rlm@0: continue; rlm@0: } rlm@0: rlm@0: if((*src)->NeedsUpdate || UpdateSources) rlm@0: { rlm@0: (*src)->NeedsUpdate = AL_FALSE; rlm@0: ALsource_Update(*src, Context); rlm@0: } rlm@0: src++; rlm@0: } rlm@0: rlm@0: for(e = 0;e < Context->EffectSlotMap.size;e++) rlm@0: { rlm@0: ALEffectSlot = Context->EffectSlotMap.array[e].value; rlm@0: if(ALEffectSlot->NeedsUpdate) rlm@0: { rlm@0: ALEffectSlot->NeedsUpdate = AL_FALSE; rlm@0: ALEffect_Update(ALEffectSlot->EffectState, Context, ALEffectSlot); rlm@0: } rlm@0: } rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: } rlm@0: rlm@0: AL_API ALvoid AL_APIENTRY alProcessUpdatesSOFT(void) rlm@0: { rlm@0: ALCcontext *Context; rlm@0: rlm@0: Context = GetLockedContext(); rlm@0: if(!Context) return; rlm@0: rlm@0: if(Context->DeferUpdates) rlm@0: { rlm@0: ALsizei pos; rlm@0: rlm@0: Context->DeferUpdates = AL_FALSE; rlm@0: rlm@0: for(pos = 0;pos < Context->SourceMap.size;pos++) rlm@0: { rlm@0: ALsource *Source = Context->SourceMap.array[pos].value; rlm@0: ALenum new_state; rlm@0: rlm@0: if(Source->lOffset != -1) rlm@0: ApplyOffset(Source); rlm@0: rlm@0: new_state = Source->new_state; rlm@0: Source->new_state = AL_NONE; rlm@0: if(new_state) rlm@0: SetSourceState(Source, Context, new_state); rlm@0: } rlm@0: } rlm@0: rlm@0: UnlockContext(Context); rlm@0: }