Mercurial > audio-send
view OpenAL32/alListener.c @ 29:cdf320cb5949
updated test suite
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 10 Dec 2011 21:42:50 -0600 |
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 "alMain.h"24 #include "AL/alc.h"25 #include "alError.h"26 #include "alListener.h"27 #include "alSource.h"29 AL_API ALvoid AL_APIENTRY alListenerf(ALenum eParam, ALfloat flValue)30 {31 ALCcontext *pContext;33 pContext = GetLockedContext();34 if(!pContext) return;36 switch(eParam)37 {38 case AL_GAIN:39 if(flValue >= 0.0f && isfinite(flValue))40 {41 pContext->Listener.Gain = flValue;42 pContext->UpdateSources = AL_TRUE;43 }44 else45 alSetError(pContext, AL_INVALID_VALUE);46 break;48 case AL_METERS_PER_UNIT:49 if(flValue > 0.0f && isfinite(flValue))50 {51 pContext->Listener.MetersPerUnit = flValue;52 pContext->UpdateSources = AL_TRUE;53 }54 else55 alSetError(pContext, AL_INVALID_VALUE);56 break;58 default:59 alSetError(pContext, AL_INVALID_ENUM);60 break;61 }63 UnlockContext(pContext);64 }67 AL_API ALvoid AL_APIENTRY alListener3f(ALenum eParam, ALfloat flValue1, ALfloat flValue2, ALfloat flValue3)68 {69 ALCcontext *pContext;71 pContext = GetLockedContext();72 if(!pContext) return;74 switch(eParam)75 {76 case AL_POSITION:77 if(isfinite(flValue1) && isfinite(flValue2) && isfinite(flValue3))78 {79 pContext->Listener.Position[0] = flValue1;80 pContext->Listener.Position[1] = flValue2;81 pContext->Listener.Position[2] = flValue3;82 pContext->UpdateSources = AL_TRUE;83 }84 else85 alSetError(pContext, AL_INVALID_VALUE);86 break;88 case AL_VELOCITY:89 if(isfinite(flValue1) && isfinite(flValue2) && isfinite(flValue3))90 {91 pContext->Listener.Velocity[0] = flValue1;92 pContext->Listener.Velocity[1] = flValue2;93 pContext->Listener.Velocity[2] = flValue3;94 pContext->UpdateSources = AL_TRUE;95 }96 else97 alSetError(pContext, AL_INVALID_VALUE);98 break;100 default:101 alSetError(pContext, AL_INVALID_ENUM);102 break;103 }105 UnlockContext(pContext);106 }109 AL_API ALvoid AL_APIENTRY alListenerfv(ALenum eParam, const ALfloat *pflValues)110 {111 ALCcontext *pContext;113 if(pflValues)114 {115 switch(eParam)116 {117 case AL_GAIN:118 case AL_METERS_PER_UNIT:119 alListenerf(eParam, pflValues[0]);120 return;122 case AL_POSITION:123 case AL_VELOCITY:124 alListener3f(eParam, pflValues[0], pflValues[1], pflValues[2]);125 return;126 }127 }129 pContext = GetLockedContext();130 if(!pContext) return;132 if(pflValues)133 {134 switch(eParam)135 {136 case AL_ORIENTATION:137 if(isfinite(pflValues[0]) && isfinite(pflValues[1]) &&138 isfinite(pflValues[2]) && isfinite(pflValues[3]) &&139 isfinite(pflValues[4]) && isfinite(pflValues[5]))140 {141 // AT then UP142 pContext->Listener.Forward[0] = pflValues[0];143 pContext->Listener.Forward[1] = pflValues[1];144 pContext->Listener.Forward[2] = pflValues[2];145 pContext->Listener.Up[0] = pflValues[3];146 pContext->Listener.Up[1] = pflValues[4];147 pContext->Listener.Up[2] = pflValues[5];148 pContext->UpdateSources = AL_TRUE;149 }150 else151 alSetError(pContext, AL_INVALID_VALUE);152 break;154 default:155 alSetError(pContext, AL_INVALID_ENUM);156 break;157 }158 }159 else160 alSetError(pContext, AL_INVALID_VALUE);162 UnlockContext(pContext);163 }166 AL_API ALvoid AL_APIENTRY alListeneri(ALenum eParam, ALint lValue)167 {168 ALCcontext *pContext;170 (void)lValue;172 pContext = GetLockedContext();173 if(!pContext) return;175 switch(eParam)176 {177 default:178 alSetError(pContext, AL_INVALID_ENUM);179 break;180 }182 UnlockContext(pContext);183 }186 AL_API void AL_APIENTRY alListener3i(ALenum eParam, ALint lValue1, ALint lValue2, ALint lValue3)187 {188 ALCcontext *pContext;190 switch(eParam)191 {192 case AL_POSITION:193 case AL_VELOCITY:194 alListener3f(eParam, (ALfloat)lValue1, (ALfloat)lValue2, (ALfloat)lValue3);195 return;196 }198 pContext = GetLockedContext();199 if(!pContext) return;201 switch(eParam)202 {203 default:204 alSetError(pContext, AL_INVALID_ENUM);205 break;206 }208 UnlockContext(pContext);209 }212 AL_API void AL_APIENTRY alListeneriv( ALenum eParam, const ALint* plValues )213 {214 ALCcontext *pContext;215 ALfloat flValues[6];217 if(plValues)218 {219 switch(eParam)220 {221 case AL_POSITION:222 case AL_VELOCITY:223 alListener3f(eParam, plValues[0], plValues[1], plValues[2]);224 return;226 case AL_ORIENTATION:227 flValues[0] = (ALfloat)plValues[0];228 flValues[1] = (ALfloat)plValues[1];229 flValues[2] = (ALfloat)plValues[2];230 flValues[3] = (ALfloat)plValues[3];231 flValues[4] = (ALfloat)plValues[4];232 flValues[5] = (ALfloat)plValues[5];233 alListenerfv(eParam, flValues);234 return;235 }236 }238 pContext = GetLockedContext();239 if(!pContext) return;241 if(plValues)242 {243 switch(eParam)244 {245 default:246 alSetError(pContext, AL_INVALID_ENUM);247 break;248 }249 }250 else251 alSetError(pContext, AL_INVALID_VALUE);253 UnlockContext(pContext);254 }257 AL_API ALvoid AL_APIENTRY alGetListenerf(ALenum eParam, ALfloat *pflValue)258 {259 ALCcontext *pContext;261 pContext = GetLockedContext();262 if(!pContext) return;264 if(pflValue)265 {266 switch(eParam)267 {268 case AL_GAIN:269 *pflValue = pContext->Listener.Gain;270 break;272 case AL_METERS_PER_UNIT:273 *pflValue = pContext->Listener.MetersPerUnit;274 break;276 default:277 alSetError(pContext, AL_INVALID_ENUM);278 break;279 }280 }281 else282 alSetError(pContext, AL_INVALID_VALUE);284 UnlockContext(pContext);285 }288 AL_API ALvoid AL_APIENTRY alGetListener3f(ALenum eParam, ALfloat *pflValue1, ALfloat *pflValue2, ALfloat *pflValue3)289 {290 ALCcontext *pContext;292 pContext = GetLockedContext();293 if(!pContext) return;295 if(pflValue1 && pflValue2 && pflValue3)296 {297 switch(eParam)298 {299 case AL_POSITION:300 *pflValue1 = pContext->Listener.Position[0];301 *pflValue2 = pContext->Listener.Position[1];302 *pflValue3 = pContext->Listener.Position[2];303 break;305 case AL_VELOCITY:306 *pflValue1 = pContext->Listener.Velocity[0];307 *pflValue2 = pContext->Listener.Velocity[1];308 *pflValue3 = pContext->Listener.Velocity[2];309 break;311 default:312 alSetError(pContext, AL_INVALID_ENUM);313 break;314 }315 }316 else317 alSetError(pContext, AL_INVALID_VALUE);319 UnlockContext(pContext);320 }323 AL_API ALvoid AL_APIENTRY alGetListenerfv(ALenum eParam, ALfloat *pflValues)324 {325 ALCcontext *pContext;327 switch(eParam)328 {329 case AL_GAIN:330 case AL_METERS_PER_UNIT:331 alGetListenerf(eParam, pflValues);332 return;334 case AL_POSITION:335 case AL_VELOCITY:336 alGetListener3f(eParam, pflValues+0, pflValues+1, pflValues+2);337 return;338 }340 pContext = GetLockedContext();341 if(!pContext) return;343 if(pflValues)344 {345 switch(eParam)346 {347 case AL_ORIENTATION:348 // AT then UP349 pflValues[0] = pContext->Listener.Forward[0];350 pflValues[1] = pContext->Listener.Forward[1];351 pflValues[2] = pContext->Listener.Forward[2];352 pflValues[3] = pContext->Listener.Up[0];353 pflValues[4] = pContext->Listener.Up[1];354 pflValues[5] = pContext->Listener.Up[2];355 break;357 default:358 alSetError(pContext, AL_INVALID_ENUM);359 break;360 }361 }362 else363 alSetError(pContext, AL_INVALID_VALUE);365 UnlockContext(pContext);366 }369 AL_API ALvoid AL_APIENTRY alGetListeneri(ALenum eParam, ALint *plValue)370 {371 ALCcontext *pContext;373 pContext = GetLockedContext();374 if(!pContext) return;376 if(plValue)377 {378 switch(eParam)379 {380 default:381 alSetError(pContext, AL_INVALID_ENUM);382 break;383 }384 }385 else386 alSetError(pContext, AL_INVALID_VALUE);388 UnlockContext(pContext);389 }392 AL_API void AL_APIENTRY alGetListener3i(ALenum eParam, ALint *plValue1, ALint *plValue2, ALint *plValue3)393 {394 ALCcontext *pContext;396 pContext = GetLockedContext();397 if(!pContext) return;399 if(plValue1 && plValue2 && plValue3)400 {401 switch (eParam)402 {403 case AL_POSITION:404 *plValue1 = (ALint)pContext->Listener.Position[0];405 *plValue2 = (ALint)pContext->Listener.Position[1];406 *plValue3 = (ALint)pContext->Listener.Position[2];407 break;409 case AL_VELOCITY:410 *plValue1 = (ALint)pContext->Listener.Velocity[0];411 *plValue2 = (ALint)pContext->Listener.Velocity[1];412 *plValue3 = (ALint)pContext->Listener.Velocity[2];413 break;415 default:416 alSetError(pContext, AL_INVALID_ENUM);417 break;418 }419 }420 else421 alSetError(pContext, AL_INVALID_VALUE);423 UnlockContext(pContext);424 }427 AL_API void AL_APIENTRY alGetListeneriv(ALenum eParam, ALint* plValues)428 {429 ALCcontext *pContext;431 switch(eParam)432 {433 case AL_POSITION:434 case AL_VELOCITY:435 alGetListener3i(eParam, plValues+0, plValues+1, plValues+2);436 return;437 }439 pContext = GetLockedContext();440 if(!pContext) return;442 if(plValues)443 {444 switch(eParam)445 {446 case AL_ORIENTATION:447 // AT then UP448 plValues[0] = (ALint)pContext->Listener.Forward[0];449 plValues[1] = (ALint)pContext->Listener.Forward[1];450 plValues[2] = (ALint)pContext->Listener.Forward[2];451 plValues[3] = (ALint)pContext->Listener.Up[0];452 plValues[4] = (ALint)pContext->Listener.Up[1];453 plValues[5] = (ALint)pContext->Listener.Up[2];454 break;456 default:457 alSetError(pContext, AL_INVALID_ENUM);458 break;459 }460 }461 else462 alSetError(pContext, AL_INVALID_VALUE);464 UnlockContext(pContext);465 }