diff OpenAL32/alListener.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/alListener.c	Tue Oct 25 13:02:31 2011 -0700
     1.3 @@ -0,0 +1,465 @@
     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 "alMain.h"
    1.27 +#include "AL/alc.h"
    1.28 +#include "alError.h"
    1.29 +#include "alListener.h"
    1.30 +#include "alSource.h"
    1.31 +
    1.32 +AL_API ALvoid AL_APIENTRY alListenerf(ALenum eParam, ALfloat flValue)
    1.33 +{
    1.34 +    ALCcontext *pContext;
    1.35 +
    1.36 +    pContext = GetLockedContext();
    1.37 +    if(!pContext) return;
    1.38 +
    1.39 +    switch(eParam)
    1.40 +    {
    1.41 +        case AL_GAIN:
    1.42 +            if(flValue >= 0.0f && isfinite(flValue))
    1.43 +            {
    1.44 +                pContext->Listener.Gain = flValue;
    1.45 +                pContext->UpdateSources = AL_TRUE;
    1.46 +            }
    1.47 +            else
    1.48 +                alSetError(pContext, AL_INVALID_VALUE);
    1.49 +            break;
    1.50 +
    1.51 +        case AL_METERS_PER_UNIT:
    1.52 +            if(flValue > 0.0f && isfinite(flValue))
    1.53 +            {
    1.54 +                pContext->Listener.MetersPerUnit = flValue;
    1.55 +                pContext->UpdateSources = AL_TRUE;
    1.56 +            }
    1.57 +            else
    1.58 +                alSetError(pContext, AL_INVALID_VALUE);
    1.59 +            break;
    1.60 +
    1.61 +        default:
    1.62 +            alSetError(pContext, AL_INVALID_ENUM);
    1.63 +            break;
    1.64 +    }
    1.65 +
    1.66 +    UnlockContext(pContext);
    1.67 +}
    1.68 +
    1.69 +
    1.70 +AL_API ALvoid AL_APIENTRY alListener3f(ALenum eParam, ALfloat flValue1, ALfloat flValue2, ALfloat flValue3)
    1.71 +{
    1.72 +    ALCcontext *pContext;
    1.73 +
    1.74 +    pContext = GetLockedContext();
    1.75 +    if(!pContext) return;
    1.76 +
    1.77 +    switch(eParam)
    1.78 +    {
    1.79 +        case AL_POSITION:
    1.80 +            if(isfinite(flValue1) && isfinite(flValue2) && isfinite(flValue3))
    1.81 +            {
    1.82 +                pContext->Listener.Position[0] = flValue1;
    1.83 +                pContext->Listener.Position[1] = flValue2;
    1.84 +                pContext->Listener.Position[2] = flValue3;
    1.85 +                pContext->UpdateSources = AL_TRUE;
    1.86 +            }
    1.87 +            else
    1.88 +                alSetError(pContext, AL_INVALID_VALUE);
    1.89 +            break;
    1.90 +
    1.91 +        case AL_VELOCITY:
    1.92 +            if(isfinite(flValue1) && isfinite(flValue2) && isfinite(flValue3))
    1.93 +            {
    1.94 +                pContext->Listener.Velocity[0] = flValue1;
    1.95 +                pContext->Listener.Velocity[1] = flValue2;
    1.96 +                pContext->Listener.Velocity[2] = flValue3;
    1.97 +                pContext->UpdateSources = AL_TRUE;
    1.98 +            }
    1.99 +            else
   1.100 +                alSetError(pContext, AL_INVALID_VALUE);
   1.101 +            break;
   1.102 +
   1.103 +        default:
   1.104 +            alSetError(pContext, AL_INVALID_ENUM);
   1.105 +            break;
   1.106 +    }
   1.107 +
   1.108 +    UnlockContext(pContext);
   1.109 +}
   1.110 +
   1.111 +
   1.112 +AL_API ALvoid AL_APIENTRY alListenerfv(ALenum eParam, const ALfloat *pflValues)
   1.113 +{
   1.114 +    ALCcontext *pContext;
   1.115 +
   1.116 +    if(pflValues)
   1.117 +    {
   1.118 +        switch(eParam)
   1.119 +        {
   1.120 +            case AL_GAIN:
   1.121 +            case AL_METERS_PER_UNIT:
   1.122 +                alListenerf(eParam, pflValues[0]);
   1.123 +                return;
   1.124 +
   1.125 +            case AL_POSITION:
   1.126 +            case AL_VELOCITY:
   1.127 +                alListener3f(eParam, pflValues[0], pflValues[1], pflValues[2]);
   1.128 +                return;
   1.129 +        }
   1.130 +    }
   1.131 +
   1.132 +    pContext = GetLockedContext();
   1.133 +    if(!pContext) return;
   1.134 +
   1.135 +    if(pflValues)
   1.136 +    {
   1.137 +        switch(eParam)
   1.138 +        {
   1.139 +            case AL_ORIENTATION:
   1.140 +                if(isfinite(pflValues[0]) && isfinite(pflValues[1]) &&
   1.141 +                   isfinite(pflValues[2]) && isfinite(pflValues[3]) &&
   1.142 +                   isfinite(pflValues[4]) && isfinite(pflValues[5]))
   1.143 +                {
   1.144 +                    // AT then UP
   1.145 +                    pContext->Listener.Forward[0] = pflValues[0];
   1.146 +                    pContext->Listener.Forward[1] = pflValues[1];
   1.147 +                    pContext->Listener.Forward[2] = pflValues[2];
   1.148 +                    pContext->Listener.Up[0] = pflValues[3];
   1.149 +                    pContext->Listener.Up[1] = pflValues[4];
   1.150 +                    pContext->Listener.Up[2] = pflValues[5];
   1.151 +                    pContext->UpdateSources = AL_TRUE;
   1.152 +                }
   1.153 +                else
   1.154 +                    alSetError(pContext, AL_INVALID_VALUE);
   1.155 +                break;
   1.156 +
   1.157 +            default:
   1.158 +                alSetError(pContext, AL_INVALID_ENUM);
   1.159 +                break;
   1.160 +        }
   1.161 +    }
   1.162 +    else
   1.163 +        alSetError(pContext, AL_INVALID_VALUE);
   1.164 +
   1.165 +    UnlockContext(pContext);
   1.166 +}
   1.167 +
   1.168 +
   1.169 +AL_API ALvoid AL_APIENTRY alListeneri(ALenum eParam, ALint lValue)
   1.170 +{
   1.171 +    ALCcontext *pContext;
   1.172 +
   1.173 +    (void)lValue;
   1.174 +
   1.175 +    pContext = GetLockedContext();
   1.176 +    if(!pContext) return;
   1.177 +
   1.178 +    switch(eParam)
   1.179 +    {
   1.180 +        default:
   1.181 +            alSetError(pContext, AL_INVALID_ENUM);
   1.182 +            break;
   1.183 +    }
   1.184 +
   1.185 +    UnlockContext(pContext);
   1.186 +}
   1.187 +
   1.188 +
   1.189 +AL_API void AL_APIENTRY alListener3i(ALenum eParam, ALint lValue1, ALint lValue2, ALint lValue3)
   1.190 +{
   1.191 +    ALCcontext *pContext;
   1.192 +
   1.193 +    switch(eParam)
   1.194 +    {
   1.195 +        case AL_POSITION:
   1.196 +        case AL_VELOCITY:
   1.197 +            alListener3f(eParam, (ALfloat)lValue1, (ALfloat)lValue2, (ALfloat)lValue3);
   1.198 +            return;
   1.199 +    }
   1.200 +
   1.201 +    pContext = GetLockedContext();
   1.202 +    if(!pContext) return;
   1.203 +
   1.204 +    switch(eParam)
   1.205 +    {
   1.206 +        default:
   1.207 +            alSetError(pContext, AL_INVALID_ENUM);
   1.208 +            break;
   1.209 +    }
   1.210 +
   1.211 +    UnlockContext(pContext);
   1.212 +}
   1.213 +
   1.214 +
   1.215 +AL_API void AL_APIENTRY alListeneriv( ALenum eParam, const ALint* plValues )
   1.216 +{
   1.217 +    ALCcontext *pContext;
   1.218 +    ALfloat flValues[6];
   1.219 +
   1.220 +    if(plValues)
   1.221 +    {
   1.222 +        switch(eParam)
   1.223 +        {
   1.224 +            case AL_POSITION:
   1.225 +            case AL_VELOCITY:
   1.226 +                alListener3f(eParam, plValues[0], plValues[1], plValues[2]);
   1.227 +                return;
   1.228 +
   1.229 +            case AL_ORIENTATION:
   1.230 +                flValues[0] = (ALfloat)plValues[0];
   1.231 +                flValues[1] = (ALfloat)plValues[1];
   1.232 +                flValues[2] = (ALfloat)plValues[2];
   1.233 +                flValues[3] = (ALfloat)plValues[3];
   1.234 +                flValues[4] = (ALfloat)plValues[4];
   1.235 +                flValues[5] = (ALfloat)plValues[5];
   1.236 +                alListenerfv(eParam, flValues);
   1.237 +                return;
   1.238 +        }
   1.239 +    }
   1.240 +
   1.241 +    pContext = GetLockedContext();
   1.242 +    if(!pContext) return;
   1.243 +
   1.244 +    if(plValues)
   1.245 +    {
   1.246 +        switch(eParam)
   1.247 +        {
   1.248 +            default:
   1.249 +                alSetError(pContext, AL_INVALID_ENUM);
   1.250 +                break;
   1.251 +        }
   1.252 +    }
   1.253 +    else
   1.254 +        alSetError(pContext, AL_INVALID_VALUE);
   1.255 +
   1.256 +    UnlockContext(pContext);
   1.257 +}
   1.258 +
   1.259 +
   1.260 +AL_API ALvoid AL_APIENTRY alGetListenerf(ALenum eParam, ALfloat *pflValue)
   1.261 +{
   1.262 +    ALCcontext *pContext;
   1.263 +
   1.264 +    pContext = GetLockedContext();
   1.265 +    if(!pContext) return;
   1.266 +
   1.267 +    if(pflValue)
   1.268 +    {
   1.269 +        switch(eParam)
   1.270 +        {
   1.271 +            case AL_GAIN:
   1.272 +                *pflValue = pContext->Listener.Gain;
   1.273 +                break;
   1.274 +
   1.275 +            case AL_METERS_PER_UNIT:
   1.276 +                *pflValue = pContext->Listener.MetersPerUnit;
   1.277 +                break;
   1.278 +
   1.279 +            default:
   1.280 +                alSetError(pContext, AL_INVALID_ENUM);
   1.281 +                break;
   1.282 +        }
   1.283 +    }
   1.284 +    else
   1.285 +        alSetError(pContext, AL_INVALID_VALUE);
   1.286 +
   1.287 +    UnlockContext(pContext);
   1.288 +}
   1.289 +
   1.290 +
   1.291 +AL_API ALvoid AL_APIENTRY alGetListener3f(ALenum eParam, ALfloat *pflValue1, ALfloat *pflValue2, ALfloat *pflValue3)
   1.292 +{
   1.293 +    ALCcontext *pContext;
   1.294 +
   1.295 +    pContext = GetLockedContext();
   1.296 +    if(!pContext) return;
   1.297 +
   1.298 +    if(pflValue1 && pflValue2 && pflValue3)
   1.299 +    {
   1.300 +        switch(eParam)
   1.301 +        {
   1.302 +            case AL_POSITION:
   1.303 +                *pflValue1 = pContext->Listener.Position[0];
   1.304 +                *pflValue2 = pContext->Listener.Position[1];
   1.305 +                *pflValue3 = pContext->Listener.Position[2];
   1.306 +                break;
   1.307 +
   1.308 +            case AL_VELOCITY:
   1.309 +                *pflValue1 = pContext->Listener.Velocity[0];
   1.310 +                *pflValue2 = pContext->Listener.Velocity[1];
   1.311 +                *pflValue3 = pContext->Listener.Velocity[2];
   1.312 +                break;
   1.313 +
   1.314 +            default:
   1.315 +                alSetError(pContext, AL_INVALID_ENUM);
   1.316 +                break;
   1.317 +        }
   1.318 +    }
   1.319 +    else
   1.320 +        alSetError(pContext, AL_INVALID_VALUE);
   1.321 +
   1.322 +    UnlockContext(pContext);
   1.323 +}
   1.324 +
   1.325 +
   1.326 +AL_API ALvoid AL_APIENTRY alGetListenerfv(ALenum eParam, ALfloat *pflValues)
   1.327 +{
   1.328 +    ALCcontext *pContext;
   1.329 +
   1.330 +    switch(eParam)
   1.331 +    {
   1.332 +        case AL_GAIN:
   1.333 +        case AL_METERS_PER_UNIT:
   1.334 +            alGetListenerf(eParam, pflValues);
   1.335 +            return;
   1.336 +
   1.337 +        case AL_POSITION:
   1.338 +        case AL_VELOCITY:
   1.339 +            alGetListener3f(eParam, pflValues+0, pflValues+1, pflValues+2);
   1.340 +            return;
   1.341 +    }
   1.342 +
   1.343 +    pContext = GetLockedContext();
   1.344 +    if(!pContext) return;
   1.345 +
   1.346 +    if(pflValues)
   1.347 +    {
   1.348 +        switch(eParam)
   1.349 +        {
   1.350 +            case AL_ORIENTATION:
   1.351 +                // AT then UP
   1.352 +                pflValues[0] = pContext->Listener.Forward[0];
   1.353 +                pflValues[1] = pContext->Listener.Forward[1];
   1.354 +                pflValues[2] = pContext->Listener.Forward[2];
   1.355 +                pflValues[3] = pContext->Listener.Up[0];
   1.356 +                pflValues[4] = pContext->Listener.Up[1];
   1.357 +                pflValues[5] = pContext->Listener.Up[2];
   1.358 +                break;
   1.359 +
   1.360 +            default:
   1.361 +                alSetError(pContext, AL_INVALID_ENUM);
   1.362 +                break;
   1.363 +        }
   1.364 +    }
   1.365 +    else
   1.366 +        alSetError(pContext, AL_INVALID_VALUE);
   1.367 +
   1.368 +    UnlockContext(pContext);
   1.369 +}
   1.370 +
   1.371 +
   1.372 +AL_API ALvoid AL_APIENTRY alGetListeneri(ALenum eParam, ALint *plValue)
   1.373 +{
   1.374 +    ALCcontext *pContext;
   1.375 +
   1.376 +    pContext = GetLockedContext();
   1.377 +    if(!pContext) return;
   1.378 +
   1.379 +    if(plValue)
   1.380 +    {
   1.381 +        switch(eParam)
   1.382 +        {
   1.383 +            default:
   1.384 +                alSetError(pContext, AL_INVALID_ENUM);
   1.385 +                break;
   1.386 +        }
   1.387 +    }
   1.388 +    else
   1.389 +        alSetError(pContext, AL_INVALID_VALUE);
   1.390 +
   1.391 +    UnlockContext(pContext);
   1.392 +}
   1.393 +
   1.394 +
   1.395 +AL_API void AL_APIENTRY alGetListener3i(ALenum eParam, ALint *plValue1, ALint *plValue2, ALint *plValue3)
   1.396 +{
   1.397 +    ALCcontext *pContext;
   1.398 +
   1.399 +    pContext = GetLockedContext();
   1.400 +    if(!pContext) return;
   1.401 +
   1.402 +    if(plValue1 && plValue2 && plValue3)
   1.403 +    {
   1.404 +        switch (eParam)
   1.405 +        {
   1.406 +            case AL_POSITION:
   1.407 +                *plValue1 = (ALint)pContext->Listener.Position[0];
   1.408 +                *plValue2 = (ALint)pContext->Listener.Position[1];
   1.409 +                *plValue3 = (ALint)pContext->Listener.Position[2];
   1.410 +                break;
   1.411 +
   1.412 +            case AL_VELOCITY:
   1.413 +                *plValue1 = (ALint)pContext->Listener.Velocity[0];
   1.414 +                *plValue2 = (ALint)pContext->Listener.Velocity[1];
   1.415 +                *plValue3 = (ALint)pContext->Listener.Velocity[2];
   1.416 +                break;
   1.417 +
   1.418 +            default:
   1.419 +                alSetError(pContext, AL_INVALID_ENUM);
   1.420 +                break;
   1.421 +        }
   1.422 +    }
   1.423 +    else
   1.424 +        alSetError(pContext, AL_INVALID_VALUE);
   1.425 +
   1.426 +    UnlockContext(pContext);
   1.427 +}
   1.428 +
   1.429 +
   1.430 +AL_API void AL_APIENTRY alGetListeneriv(ALenum eParam, ALint* plValues)
   1.431 +{
   1.432 +    ALCcontext *pContext;
   1.433 +
   1.434 +    switch(eParam)
   1.435 +    {
   1.436 +        case AL_POSITION:
   1.437 +        case AL_VELOCITY:
   1.438 +            alGetListener3i(eParam, plValues+0, plValues+1, plValues+2);
   1.439 +            return;
   1.440 +    }
   1.441 +
   1.442 +    pContext = GetLockedContext();
   1.443 +    if(!pContext) return;
   1.444 +
   1.445 +    if(plValues)
   1.446 +    {
   1.447 +        switch(eParam)
   1.448 +        {
   1.449 +            case AL_ORIENTATION:
   1.450 +                // AT then UP
   1.451 +                plValues[0] = (ALint)pContext->Listener.Forward[0];
   1.452 +                plValues[1] = (ALint)pContext->Listener.Forward[1];
   1.453 +                plValues[2] = (ALint)pContext->Listener.Forward[2];
   1.454 +                plValues[3] = (ALint)pContext->Listener.Up[0];
   1.455 +                plValues[4] = (ALint)pContext->Listener.Up[1];
   1.456 +                plValues[5] = (ALint)pContext->Listener.Up[2];
   1.457 +                break;
   1.458 +
   1.459 +            default:
   1.460 +                alSetError(pContext, AL_INVALID_ENUM);
   1.461 +                break;
   1.462 +        }
   1.463 +    }
   1.464 +    else
   1.465 +        alSetError(pContext, AL_INVALID_VALUE);
   1.466 +
   1.467 +    UnlockContext(pContext);
   1.468 +}