openal-soft/OpenAL32/alListener.c

485 lines
13 KiB
C
Raw Normal View History

2007-11-13 18:02:18 -08:00
/**
* 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
*/
2008-01-16 14:09:04 -08:00
#include "config.h"
2007-11-13 18:02:18 -08:00
#include "alMain.h"
#include "AL/alc.h"
#include "alError.h"
#include "alListener.h"
#include "alSource.h"
2007-11-13 18:02:18 -08:00
2010-03-19 14:34:18 -07:00
AL_API ALvoid AL_APIENTRY alListenerf(ALenum eParam, ALfloat flValue)
2007-11-13 18:02:18 -08:00
{
ALCcontext *pContext;
ALboolean updateAll = AL_FALSE;
2007-11-13 18:02:18 -08:00
pContext = GetContextSuspended();
if(!pContext) return;
switch(eParam)
2007-11-13 18:02:18 -08:00
{
case AL_GAIN:
if(flValue >= 0.0f)
{
2007-11-13 18:02:18 -08:00
pContext->Listener.Gain = flValue;
updateAll = AL_TRUE;
}
2007-11-13 18:02:18 -08:00
else
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_VALUE);
2007-11-13 18:02:18 -08:00
break;
case AL_METERS_PER_UNIT:
if(flValue > 0.0f)
{
pContext->Listener.MetersPerUnit = flValue;
updateAll = AL_TRUE;
}
else
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_VALUE);
break;
2007-11-13 18:02:18 -08:00
default:
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_ENUM);
2007-11-13 18:02:18 -08:00
break;
}
// Force updating the sources for these parameters, since even head-
// relative sources are affected
if(updateAll)
{
ALsizei pos;
for(pos = 0;pos < pContext->SourceMap.size;pos++)
{
ALsource *source = pContext->SourceMap.array[pos].value;
source->NeedsUpdate = AL_TRUE;
}
}
ProcessContext(pContext);
2007-11-13 18:02:18 -08:00
}
2010-03-19 14:34:18 -07:00
AL_API ALvoid AL_APIENTRY alListener3f(ALenum eParam, ALfloat flValue1, ALfloat flValue2, ALfloat flValue3)
2007-11-13 18:02:18 -08:00
{
ALCcontext *pContext;
ALboolean updateWorld = AL_FALSE;
2007-11-13 18:02:18 -08:00
pContext = GetContextSuspended();
if(!pContext) return;
switch(eParam)
2007-11-13 18:02:18 -08:00
{
case AL_POSITION:
pContext->Listener.Position[0] = flValue1;
pContext->Listener.Position[1] = flValue2;
pContext->Listener.Position[2] = flValue3;
updateWorld = AL_TRUE;
2007-11-13 18:02:18 -08:00
break;
case AL_VELOCITY:
pContext->Listener.Velocity[0] = flValue1;
pContext->Listener.Velocity[1] = flValue2;
pContext->Listener.Velocity[2] = flValue3;
updateWorld = AL_TRUE;
2007-11-13 18:02:18 -08:00
break;
default:
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_ENUM);
2007-11-13 18:02:18 -08:00
break;
}
if(updateWorld)
{
ALsizei pos;
for(pos = 0;pos < pContext->SourceMap.size;pos++)
{
ALsource *source = pContext->SourceMap.array[pos].value;
if(!source->bHeadRelative)
source->NeedsUpdate = AL_TRUE;
}
}
ProcessContext(pContext);
2007-11-13 18:02:18 -08:00
}
2010-03-19 14:34:18 -07:00
AL_API ALvoid AL_APIENTRY alListenerfv(ALenum eParam, const ALfloat *pflValues)
2007-11-13 18:02:18 -08:00
{
ALCcontext *pContext;
ALboolean updateWorld = AL_FALSE;
2007-11-13 18:02:18 -08:00
pContext = GetContextSuspended();
if(!pContext) return;
if(pflValues)
2007-11-13 18:02:18 -08:00
{
switch(eParam)
2007-11-13 18:02:18 -08:00
{
case AL_GAIN:
case AL_METERS_PER_UNIT:
alListenerf(eParam, pflValues[0]);
break;
2007-11-13 18:02:18 -08:00
case AL_POSITION:
case AL_VELOCITY:
alListener3f(eParam, pflValues[0], pflValues[1], pflValues[2]);
2007-11-13 18:02:18 -08:00
break;
case AL_ORIENTATION:
// AT then UP
pContext->Listener.Forward[0] = pflValues[0];
pContext->Listener.Forward[1] = pflValues[1];
pContext->Listener.Forward[2] = pflValues[2];
pContext->Listener.Up[0] = pflValues[3];
pContext->Listener.Up[1] = pflValues[4];
pContext->Listener.Up[2] = pflValues[5];
updateWorld = AL_TRUE;
2007-11-13 18:02:18 -08:00
break;
default:
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_ENUM);
2007-11-13 18:02:18 -08:00
break;
}
}
else
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_VALUE);
2007-11-13 18:02:18 -08:00
if(updateWorld)
{
ALsizei pos;
for(pos = 0;pos < pContext->SourceMap.size;pos++)
{
ALsource *source = pContext->SourceMap.array[pos].value;
if(!source->bHeadRelative)
source->NeedsUpdate = AL_TRUE;
}
}
ProcessContext(pContext);
2007-11-13 18:02:18 -08:00
}
2010-03-19 14:34:18 -07:00
AL_API ALvoid AL_APIENTRY alListeneri(ALenum eParam, ALint lValue)
2007-11-13 18:02:18 -08:00
{
ALCcontext *pContext;
(void)lValue;
pContext = GetContextSuspended();
if(!pContext) return;
switch(eParam)
2007-11-13 18:02:18 -08:00
{
default:
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_ENUM);
2007-11-13 18:02:18 -08:00
break;
}
ProcessContext(pContext);
2007-11-13 18:02:18 -08:00
}
2010-03-19 14:34:18 -07:00
AL_API void AL_APIENTRY alListener3i(ALenum eParam, ALint lValue1, ALint lValue2, ALint lValue3)
2007-11-13 18:02:18 -08:00
{
ALCcontext *pContext;
pContext = GetContextSuspended();
if(!pContext) return;
switch(eParam)
2007-11-13 18:02:18 -08:00
{
case AL_POSITION:
case AL_VELOCITY:
alListener3f(eParam, (ALfloat)lValue1, (ALfloat)lValue2, (ALfloat)lValue3);
break;
default:
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_ENUM);
2007-11-13 18:02:18 -08:00
break;
}
ProcessContext(pContext);
2007-11-13 18:02:18 -08:00
}
2010-03-19 14:34:18 -07:00
AL_API void AL_APIENTRY alListeneriv( ALenum eParam, const ALint* plValues )
2007-11-13 18:02:18 -08:00
{
ALCcontext *pContext;
ALfloat flValues[6];
pContext = GetContextSuspended();
if(!pContext) return;
if(plValues)
2007-11-13 18:02:18 -08:00
{
switch(eParam)
2007-11-13 18:02:18 -08:00
{
case AL_POSITION:
case AL_VELOCITY:
flValues[0] = (ALfloat)plValues[0];
flValues[1] = (ALfloat)plValues[1];
flValues[2] = (ALfloat)plValues[2];
alListenerfv(eParam, flValues);
break;
case AL_ORIENTATION:
flValues[0] = (ALfloat)plValues[0];
flValues[1] = (ALfloat)plValues[1];
flValues[2] = (ALfloat)plValues[2];
flValues[3] = (ALfloat)plValues[3];
flValues[4] = (ALfloat)plValues[4];
flValues[5] = (ALfloat)plValues[5];
alListenerfv(eParam, flValues);
break;
default:
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_ENUM);
2007-11-13 18:02:18 -08:00
break;
}
}
else
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_VALUE);
2007-11-13 18:02:18 -08:00
ProcessContext(pContext);
2007-11-13 18:02:18 -08:00
}
2010-03-19 14:34:18 -07:00
AL_API ALvoid AL_APIENTRY alGetListenerf(ALenum eParam, ALfloat *pflValue)
2007-11-13 18:02:18 -08:00
{
ALCcontext *pContext;
pContext = GetContextSuspended();
if(!pContext) return;
if(pflValue)
2007-11-13 18:02:18 -08:00
{
switch(eParam)
2007-11-13 18:02:18 -08:00
{
case AL_GAIN:
*pflValue = pContext->Listener.Gain;
break;
case AL_METERS_PER_UNIT:
*pflValue = pContext->Listener.MetersPerUnit;
break;
2007-11-13 18:02:18 -08:00
default:
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_ENUM);
2007-11-13 18:02:18 -08:00
break;
}
}
else
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_VALUE);
2007-11-13 18:02:18 -08:00
ProcessContext(pContext);
2007-11-13 18:02:18 -08:00
}
2010-03-19 14:34:18 -07:00
AL_API ALvoid AL_APIENTRY alGetListener3f(ALenum eParam, ALfloat *pflValue1, ALfloat *pflValue2, ALfloat *pflValue3)
2007-11-13 18:02:18 -08:00
{
ALCcontext *pContext;
pContext = GetContextSuspended();
if(!pContext) return;
if(pflValue1 && pflValue2 && pflValue3)
2007-11-13 18:02:18 -08:00
{
switch(eParam)
2007-11-13 18:02:18 -08:00
{
case AL_POSITION:
*pflValue1 = pContext->Listener.Position[0];
*pflValue2 = pContext->Listener.Position[1];
*pflValue3 = pContext->Listener.Position[2];
break;
case AL_VELOCITY:
*pflValue1 = pContext->Listener.Velocity[0];
*pflValue2 = pContext->Listener.Velocity[1];
*pflValue3 = pContext->Listener.Velocity[2];
break;
default:
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_ENUM);
2007-11-13 18:02:18 -08:00
break;
}
}
else
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_VALUE);
2007-11-13 18:02:18 -08:00
ProcessContext(pContext);
2007-11-13 18:02:18 -08:00
}
2010-03-19 14:34:18 -07:00
AL_API ALvoid AL_APIENTRY alGetListenerfv(ALenum eParam, ALfloat *pflValues)
2007-11-13 18:02:18 -08:00
{
ALCcontext *pContext;
pContext = GetContextSuspended();
if(!pContext) return;
if(pflValues)
2007-11-13 18:02:18 -08:00
{
switch(eParam)
2007-11-13 18:02:18 -08:00
{
case AL_GAIN:
pflValues[0] = pContext->Listener.Gain;
break;
case AL_METERS_PER_UNIT:
pflValues[0] = pContext->Listener.MetersPerUnit;
break;
2007-11-13 18:02:18 -08:00
case AL_POSITION:
pflValues[0] = pContext->Listener.Position[0];
pflValues[1] = pContext->Listener.Position[1];
pflValues[2] = pContext->Listener.Position[2];
break;
case AL_VELOCITY:
pflValues[0] = pContext->Listener.Velocity[0];
pflValues[1] = pContext->Listener.Velocity[1];
pflValues[2] = pContext->Listener.Velocity[2];
break;
case AL_ORIENTATION:
// AT then UP
pflValues[0] = pContext->Listener.Forward[0];
pflValues[1] = pContext->Listener.Forward[1];
pflValues[2] = pContext->Listener.Forward[2];
pflValues[3] = pContext->Listener.Up[0];
pflValues[4] = pContext->Listener.Up[1];
pflValues[5] = pContext->Listener.Up[2];
break;
default:
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_ENUM);
2007-11-13 18:02:18 -08:00
break;
}
}
else
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_VALUE);
2007-11-13 18:02:18 -08:00
ProcessContext(pContext);
2007-11-13 18:02:18 -08:00
}
2010-03-19 14:34:18 -07:00
AL_API ALvoid AL_APIENTRY alGetListeneri(ALenum eParam, ALint *plValue)
2007-11-13 18:02:18 -08:00
{
ALCcontext *pContext;
pContext = GetContextSuspended();
if(!pContext) return;
if(plValue)
2007-11-13 18:02:18 -08:00
{
switch(eParam)
2007-11-13 18:02:18 -08:00
{
default:
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_ENUM);
2007-11-13 18:02:18 -08:00
break;
}
}
else
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_VALUE);
2007-11-13 18:02:18 -08:00
ProcessContext(pContext);
2007-11-13 18:02:18 -08:00
}
2010-03-19 14:34:18 -07:00
AL_API void AL_APIENTRY alGetListener3i(ALenum eParam, ALint *plValue1, ALint *plValue2, ALint *plValue3)
2007-11-13 18:02:18 -08:00
{
ALCcontext *pContext;
pContext = GetContextSuspended();
if(!pContext) return;
if(plValue1 && plValue2 && plValue3)
2007-11-13 18:02:18 -08:00
{
switch (eParam)
2007-11-13 18:02:18 -08:00
{
case AL_POSITION:
*plValue1 = (ALint)pContext->Listener.Position[0];
*plValue2 = (ALint)pContext->Listener.Position[1];
*plValue3 = (ALint)pContext->Listener.Position[2];
break;
case AL_VELOCITY:
*plValue1 = (ALint)pContext->Listener.Velocity[0];
*plValue2 = (ALint)pContext->Listener.Velocity[1];
*plValue3 = (ALint)pContext->Listener.Velocity[2];
break;
default:
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_ENUM);
2007-11-13 18:02:18 -08:00
break;
}
}
else
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_VALUE);
2007-11-13 18:02:18 -08:00
ProcessContext(pContext);
2007-11-13 18:02:18 -08:00
}
2010-03-19 14:34:18 -07:00
AL_API void AL_APIENTRY alGetListeneriv(ALenum eParam, ALint* plValues)
2007-11-13 18:02:18 -08:00
{
ALCcontext *pContext;
pContext = GetContextSuspended();
if(!pContext) return;
if(plValues)
2007-11-13 18:02:18 -08:00
{
switch(eParam)
2007-11-13 18:02:18 -08:00
{
case AL_POSITION:
plValues[0] = (ALint)pContext->Listener.Position[0];
plValues[1] = (ALint)pContext->Listener.Position[1];
plValues[2] = (ALint)pContext->Listener.Position[2];
break;
case AL_VELOCITY:
plValues[0] = (ALint)pContext->Listener.Velocity[0];
plValues[1] = (ALint)pContext->Listener.Velocity[1];
plValues[2] = (ALint)pContext->Listener.Velocity[2];
break;
case AL_ORIENTATION:
// AT then UP
plValues[0] = (ALint)pContext->Listener.Forward[0];
plValues[1] = (ALint)pContext->Listener.Forward[1];
plValues[2] = (ALint)pContext->Listener.Forward[2];
plValues[3] = (ALint)pContext->Listener.Up[0];
plValues[4] = (ALint)pContext->Listener.Up[1];
plValues[5] = (ALint)pContext->Listener.Up[2];
break;
default:
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_ENUM);
2007-11-13 18:02:18 -08:00
break;
}
}
else
2010-03-16 17:35:51 -07:00
alSetError(pContext, AL_INVALID_VALUE);
2007-11-13 18:02:18 -08:00
ProcessContext(pContext);
2007-11-13 18:02:18 -08:00
}