| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661 |
- /**
- * OpenAL cross platform audio library
- * Copyright (C) 1999-2000 by authors.
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- * Or go to http://www.gnu.org/copyleft/lgpl.html
- */
- #include "config.h"
- #include <stdlib.h>
- #include "alMain.h"
- #include "AL/alc.h"
- #include "AL/alext.h"
- #include "alError.h"
- #include "alSource.h"
- #include "alState.h"
- #include "alDatabuffer.h"
- static const ALchar alVendor[] = "OpenAL Community";
- static const ALchar alVersion[] = "1.1 ALSOFT "ALSOFT_VERSION;
- static const ALchar alRenderer[] = "OpenAL Soft";
- // Error Messages
- static const ALchar alNoError[] = "No Error";
- static const ALchar alErrInvalidName[] = "Invalid Name";
- static const ALchar alErrInvalidEnum[] = "Invalid Enum";
- static const ALchar alErrInvalidValue[] = "Invalid Value";
- static const ALchar alErrInvalidOp[] = "Invalid Operation";
- static const ALchar alErrOutOfMemory[] = "Out of Memory";
- AL_API ALvoid AL_APIENTRY alEnable(ALenum capability)
- {
- ALCcontext *Context;
- ALboolean updateSources = AL_FALSE;
- Context = GetContextSuspended();
- if(!Context) return;
- switch(capability)
- {
- case AL_SOURCE_DISTANCE_MODEL:
- Context->SourceDistanceModel = AL_TRUE;
- updateSources = AL_TRUE;
- break;
- default:
- alSetError(Context, AL_INVALID_ENUM);
- break;
- }
- if(updateSources)
- {
- ALsizei pos;
- for(pos = 0;pos < Context->SourceMap.size;pos++)
- {
- ALsource *source = Context->SourceMap.array[pos].value;
- source->NeedsUpdate = AL_TRUE;
- }
- }
- ProcessContext(Context);
- }
- AL_API ALvoid AL_APIENTRY alDisable(ALenum capability)
- {
- ALCcontext *Context;
- ALboolean updateSources = AL_FALSE;
- Context = GetContextSuspended();
- if(!Context) return;
- switch(capability)
- {
- case AL_SOURCE_DISTANCE_MODEL:
- Context->SourceDistanceModel = AL_FALSE;
- updateSources = AL_TRUE;
- break;
- default:
- alSetError(Context, AL_INVALID_ENUM);
- break;
- }
- if(updateSources)
- {
- ALsizei pos;
- for(pos = 0;pos < Context->SourceMap.size;pos++)
- {
- ALsource *source = Context->SourceMap.array[pos].value;
- source->NeedsUpdate = AL_TRUE;
- }
- }
- ProcessContext(Context);
- }
- AL_API ALboolean AL_APIENTRY alIsEnabled(ALenum capability)
- {
- ALCcontext *Context;
- ALboolean value=AL_FALSE;
- Context = GetContextSuspended();
- if(!Context) return AL_FALSE;
- switch(capability)
- {
- case AL_SOURCE_DISTANCE_MODEL:
- value = Context->SourceDistanceModel;
- break;
- default:
- alSetError(Context, AL_INVALID_ENUM);
- break;
- }
- ProcessContext(Context);
- return value;
- }
- AL_API ALboolean AL_APIENTRY alGetBoolean(ALenum pname)
- {
- ALCcontext *Context;
- ALboolean value=AL_FALSE;
- Context = GetContextSuspended();
- if(!Context) return AL_FALSE;
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- if(Context->DopplerFactor != int2ALfp(0))
- value = AL_TRUE;
- break;
- case AL_DOPPLER_VELOCITY:
- if(Context->DopplerVelocity != int2ALfp(0))
- value = AL_TRUE;
- break;
- case AL_DISTANCE_MODEL:
- if(Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED)
- value = AL_TRUE;
- break;
- case AL_SPEED_OF_SOUND:
- if(Context->flSpeedOfSound != int2ALfp(0))
- value = AL_TRUE;
- break;
- default:
- alSetError(Context, AL_INVALID_ENUM);
- break;
- }
- ProcessContext(Context);
- return value;
- }
- AL_API ALdouble AL_APIENTRY alGetDouble(ALenum pname)
- {
- ALCcontext *Context;
- ALdouble value = 0.0;
- Context = GetContextSuspended();
- if(!Context) return 0.0;
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- value = (double)ALfp2float(Context->DopplerFactor);
- break;
- case AL_DOPPLER_VELOCITY:
- value = (double)ALfp2float(Context->DopplerVelocity);
- break;
- case AL_DISTANCE_MODEL:
- value = (double)Context->DistanceModel;
- break;
- case AL_SPEED_OF_SOUND:
- value = (double)ALfp2float(Context->flSpeedOfSound);
- break;
- default:
- alSetError(Context, AL_INVALID_ENUM);
- break;
- }
- ProcessContext(Context);
- return value;
- }
- AL_API ALfloat AL_APIENTRY alGetFloat(ALenum pname)
- {
- ALCcontext *Context;
- ALfloat value = 0.0f;
- Context = GetContextSuspended();
- if(!Context) return 0.0f;
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- value = ALfp2float(Context->DopplerFactor);
- break;
- case AL_DOPPLER_VELOCITY:
- value = ALfp2float(Context->DopplerVelocity);
- break;
- case AL_DISTANCE_MODEL:
- value = (float)Context->DistanceModel;
- break;
- case AL_SPEED_OF_SOUND:
- value = ALfp2float(Context->flSpeedOfSound);
- break;
- default:
- alSetError(Context, AL_INVALID_ENUM);
- break;
- }
- ProcessContext(Context);
- return value;
- }
- AL_API ALint AL_APIENTRY alGetInteger(ALenum pname)
- {
- ALCcontext *Context;
- ALint value = 0;
- Context = GetContextSuspended();
- if(!Context) return 0;
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- value = (ALint)ALfp2int(Context->DopplerFactor);
- break;
- case AL_DOPPLER_VELOCITY:
- value = (ALint)ALfp2int(Context->DopplerVelocity);
- break;
- case AL_DISTANCE_MODEL:
- value = (ALint)Context->DistanceModel;
- break;
- case AL_SPEED_OF_SOUND:
- value = (ALint)ALfp2int(Context->flSpeedOfSound);
- break;
- case AL_SAMPLE_SOURCE_EXT:
- if(Context->SampleSource)
- value = (ALint)Context->SampleSource->databuffer;
- else
- value = 0;
- break;
- case AL_SAMPLE_SINK_EXT:
- if(Context->SampleSink)
- value = (ALint)Context->SampleSink->databuffer;
- else
- value = 0;
- break;
- default:
- alSetError(Context, AL_INVALID_ENUM);
- break;
- }
- ProcessContext(Context);
- return value;
- }
- AL_API ALvoid AL_APIENTRY alGetBooleanv(ALenum pname,ALboolean *data)
- {
- ALCcontext *Context;
- Context = GetContextSuspended();
- if(!Context) return;
- if(data)
- {
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- *data = (ALboolean)((Context->DopplerFactor != int2ALfp(0)) ? AL_TRUE : AL_FALSE);
- break;
- case AL_DOPPLER_VELOCITY:
- *data = (ALboolean)((Context->DopplerVelocity != int2ALfp(0)) ? AL_TRUE : AL_FALSE);
- break;
- case AL_DISTANCE_MODEL:
- *data = (ALboolean)((Context->DistanceModel == AL_INVERSE_DISTANCE_CLAMPED) ? AL_TRUE : AL_FALSE);
- break;
- case AL_SPEED_OF_SOUND:
- *data = (ALboolean)((Context->flSpeedOfSound != int2ALfp(0)) ? AL_TRUE : AL_FALSE);
- break;
- default:
- alSetError(Context, AL_INVALID_ENUM);
- break;
- }
- }
- else
- {
- // data is a NULL pointer
- alSetError(Context, AL_INVALID_VALUE);
- }
- ProcessContext(Context);
- }
- AL_API ALvoid AL_APIENTRY alGetDoublev(ALenum pname,ALdouble *data)
- {
- ALCcontext *Context;
- Context = GetContextSuspended();
- if(!Context) return;
- if(data)
- {
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- *data = (double)ALfp2float(Context->DopplerFactor);
- break;
- case AL_DOPPLER_VELOCITY:
- *data = (double)ALfp2float(Context->DopplerVelocity);
- break;
- case AL_DISTANCE_MODEL:
- *data = (double)Context->DistanceModel;
- break;
- case AL_SPEED_OF_SOUND:
- *data = (double)ALfp2float(Context->flSpeedOfSound);
- break;
- default:
- alSetError(Context, AL_INVALID_ENUM);
- break;
- }
- }
- else
- {
- // data is a NULL pointer
- alSetError(Context, AL_INVALID_VALUE);
- }
- ProcessContext(Context);
- }
- AL_API ALvoid AL_APIENTRY alGetFloatv(ALenum pname,ALfloat *data)
- {
- ALCcontext *Context;
- Context = GetContextSuspended();
- if(!Context) return;
- if(data)
- {
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- *data = ALfp2float(Context->DopplerFactor);
- break;
- case AL_DOPPLER_VELOCITY:
- *data = ALfp2float(Context->DopplerVelocity);
- break;
- case AL_DISTANCE_MODEL:
- *data = (float)Context->DistanceModel;
- break;
- case AL_SPEED_OF_SOUND:
- *data = ALfp2float(Context->flSpeedOfSound);
- break;
- default:
- alSetError(Context, AL_INVALID_ENUM);
- break;
- }
- }
- else
- {
- // data is a NULL pointer
- alSetError(Context, AL_INVALID_VALUE);
- }
- ProcessContext(Context);
- }
- AL_API ALvoid AL_APIENTRY alGetIntegerv(ALenum pname,ALint *data)
- {
- ALCcontext *Context;
- Context = GetContextSuspended();
- if(!Context) return;
- if(data)
- {
- switch(pname)
- {
- case AL_DOPPLER_FACTOR:
- *data = (ALint)ALfp2int(Context->DopplerFactor);
- break;
- case AL_DOPPLER_VELOCITY:
- *data = (ALint)ALfp2int(Context->DopplerVelocity);
- break;
- case AL_DISTANCE_MODEL:
- *data = (ALint)Context->DistanceModel;
- break;
- case AL_SPEED_OF_SOUND:
- *data = (ALint)ALfp2int(Context->flSpeedOfSound);
- break;
- case AL_SAMPLE_SOURCE_EXT:
- if(Context->SampleSource)
- *data = (ALint)Context->SampleSource->databuffer;
- else
- *data = 0;
- break;
- case AL_SAMPLE_SINK_EXT:
- if(Context->SampleSink)
- *data = (ALint)Context->SampleSink->databuffer;
- else
- *data = 0;
- break;
- default:
- alSetError(Context, AL_INVALID_ENUM);
- break;
- }
- }
- else
- {
- // data is a NULL pointer
- alSetError(Context, AL_INVALID_VALUE);
- }
- ProcessContext(Context);
- }
- AL_API const ALchar* AL_APIENTRY alGetString(ALenum pname)
- {
- const ALchar *value;
- ALCcontext *pContext;
- pContext = GetContextSuspended();
- if(!pContext) return NULL;
- switch(pname)
- {
- case AL_VENDOR:
- value=alVendor;
- break;
- case AL_VERSION:
- value=alVersion;
- break;
- case AL_RENDERER:
- value=alRenderer;
- break;
- case AL_EXTENSIONS:
- value=pContext->ExtensionList;//alExtensions;
- break;
- case AL_NO_ERROR:
- value=alNoError;
- break;
- case AL_INVALID_NAME:
- value=alErrInvalidName;
- break;
- case AL_INVALID_ENUM:
- value=alErrInvalidEnum;
- break;
- case AL_INVALID_VALUE:
- value=alErrInvalidValue;
- break;
- case AL_INVALID_OPERATION:
- value=alErrInvalidOp;
- break;
- case AL_OUT_OF_MEMORY:
- value=alErrOutOfMemory;
- break;
- default:
- value=NULL;
- alSetError(pContext, AL_INVALID_ENUM);
- break;
- }
- ProcessContext(pContext);
- return value;
- }
- AL_API ALvoid AL_APIENTRY alDopplerFactor(ALfloat value)
- {
- ALCcontext *Context;
- ALboolean updateSources = AL_FALSE;
- Context = GetContextSuspended();
- if(!Context) return;
- if(value >= 0.0f)
- {
- Context->DopplerFactor = float2ALfp(value);
- updateSources = AL_TRUE;
- }
- else
- alSetError(Context, AL_INVALID_VALUE);
- // Force updating the sources for these parameters, since even head-
- // relative sources are affected
- if(updateSources)
- {
- ALsizei pos;
- for(pos = 0;pos < Context->SourceMap.size;pos++)
- {
- ALsource *source = Context->SourceMap.array[pos].value;
- source->NeedsUpdate = AL_TRUE;
- }
- }
- ProcessContext(Context);
- }
- AL_API ALvoid AL_APIENTRY alDopplerVelocity(ALfloat value)
- {
- ALCcontext *Context;
- ALboolean updateSources = AL_FALSE;
- Context = GetContextSuspended();
- if(!Context) return;
- if(value > 0.0f)
- {
- Context->DopplerVelocity=float2ALfp(value);
- updateSources = AL_TRUE;
- }
- else
- alSetError(Context, AL_INVALID_VALUE);
- if(updateSources)
- {
- ALsizei pos;
- for(pos = 0;pos < Context->SourceMap.size;pos++)
- {
- ALsource *source = Context->SourceMap.array[pos].value;
- source->NeedsUpdate = AL_TRUE;
- }
- }
- ProcessContext(Context);
- }
- AL_API ALvoid AL_APIENTRY alSpeedOfSound(ALfloat flSpeedOfSound)
- {
- ALCcontext *pContext;
- ALboolean updateSources = AL_FALSE;
- pContext = GetContextSuspended();
- if(!pContext) return;
- if(flSpeedOfSound > 0.0f)
- {
- pContext->flSpeedOfSound = float2ALfp(flSpeedOfSound);
- updateSources = AL_TRUE;
- }
- else
- alSetError(pContext, AL_INVALID_VALUE);
- if(updateSources)
- {
- ALsizei pos;
- for(pos = 0;pos < pContext->SourceMap.size;pos++)
- {
- ALsource *source = pContext->SourceMap.array[pos].value;
- source->NeedsUpdate = AL_TRUE;
- }
- }
- ProcessContext(pContext);
- }
- AL_API ALvoid AL_APIENTRY alDistanceModel(ALenum value)
- {
- ALCcontext *Context;
- ALboolean updateSources = AL_FALSE;
- Context = GetContextSuspended();
- if(!Context) return;
- switch(value)
- {
- case AL_NONE:
- case AL_INVERSE_DISTANCE:
- case AL_INVERSE_DISTANCE_CLAMPED:
- case AL_LINEAR_DISTANCE:
- case AL_LINEAR_DISTANCE_CLAMPED:
- case AL_EXPONENT_DISTANCE:
- case AL_EXPONENT_DISTANCE_CLAMPED:
- Context->DistanceModel = value;
- updateSources = !Context->SourceDistanceModel;
- break;
- default:
- alSetError(Context, AL_INVALID_VALUE);
- break;
- }
- if(updateSources)
- {
- ALsizei pos;
- for(pos = 0;pos < Context->SourceMap.size;pos++)
- {
- ALsource *source = Context->SourceMap.array[pos].value;
- source->NeedsUpdate = AL_TRUE;
- }
- }
- ProcessContext(Context);
- }
|