Build the listener matrix separately
[openal-soft.git] / OpenAL32 / alListener.c
blob682acbb53825149eba9ac02aab773b3abd728a12
1 /**
2 * OpenAL cross platform audio library
3 * Copyright (C) 1999-2000 by authors.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * 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.html
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 param, ALfloat value)
31 ALCcontext *Context;
33 Context = GetContextRef();
34 if(!Context) return;
36 al_try
38 switch(param)
40 case AL_GAIN:
41 CHECK_VALUE(Context, value >= 0.0f && isfinite(value));
43 Context->Listener->Gain = value;
44 Context->UpdateSources = AL_TRUE;
45 break;
47 case AL_METERS_PER_UNIT:
48 CHECK_VALUE(Context, value >= 0.0f && isfinite(value));
50 Context->Listener->MetersPerUnit = value;
51 Context->UpdateSources = AL_TRUE;
52 break;
54 default:
55 al_throwerr(Context, AL_INVALID_ENUM);
58 al_endtry;
60 ALCcontext_DecRef(Context);
64 AL_API ALvoid AL_APIENTRY alListener3f(ALenum param, ALfloat value1, ALfloat value2, ALfloat value3)
66 ALCcontext *Context;
68 Context = GetContextRef();
69 if(!Context) return;
71 al_try
73 switch(param)
75 case AL_POSITION:
76 CHECK_VALUE(Context, isfinite(value1) && isfinite(value2) && isfinite(value3));
78 LockContext(Context);
79 Context->Listener->Position[0] = value1;
80 Context->Listener->Position[1] = value2;
81 Context->Listener->Position[2] = value3;
82 Context->UpdateSources = AL_TRUE;
83 UnlockContext(Context);
84 break;
86 case AL_VELOCITY:
87 CHECK_VALUE(Context, isfinite(value1) && isfinite(value2) && isfinite(value3));
89 LockContext(Context);
90 Context->Listener->Velocity[0] = value1;
91 Context->Listener->Velocity[1] = value2;
92 Context->Listener->Velocity[2] = value3;
93 Context->UpdateSources = AL_TRUE;
94 UnlockContext(Context);
95 break;
97 default:
98 al_throwerr(Context, AL_INVALID_ENUM);
101 al_endtry;
103 ALCcontext_DecRef(Context);
107 AL_API ALvoid AL_APIENTRY alListenerfv(ALenum param, const ALfloat *values)
109 ALCcontext *Context;
111 if(values)
113 switch(param)
115 case AL_GAIN:
116 case AL_METERS_PER_UNIT:
117 alListenerf(param, values[0]);
118 return;
120 case AL_POSITION:
121 case AL_VELOCITY:
122 alListener3f(param, values[0], values[1], values[2]);
123 return;
127 Context = GetContextRef();
128 if(!Context) return;
130 al_try
132 CHECK_VALUE(Context, values);
133 switch(param)
135 case AL_ORIENTATION:
136 CHECK_VALUE(Context, isfinite(values[0]) && isfinite(values[1]) &&
137 isfinite(values[2]) && isfinite(values[3]) &&
138 isfinite(values[4]) && isfinite(values[5]));
140 LockContext(Context);
141 /* AT then UP */
142 Context->Listener->Forward[0] = values[0];
143 Context->Listener->Forward[1] = values[1];
144 Context->Listener->Forward[2] = values[2];
145 Context->Listener->Up[0] = values[3];
146 Context->Listener->Up[1] = values[4];
147 Context->Listener->Up[2] = values[5];
148 Context->UpdateSources = AL_TRUE;
149 UnlockContext(Context);
150 break;
152 default:
153 al_throwerr(Context, AL_INVALID_ENUM);
156 al_endtry;
158 ALCcontext_DecRef(Context);
162 AL_API ALvoid AL_APIENTRY alListeneri(ALenum param, ALint value)
164 ALCcontext *Context;
166 (void)value;
168 Context = GetContextRef();
169 if(!Context) return;
171 al_try
173 switch(param)
175 default:
176 al_throwerr(Context, AL_INVALID_ENUM);
179 al_endtry;
181 ALCcontext_DecRef(Context);
185 AL_API void AL_APIENTRY alListener3i(ALenum param, ALint value1, ALint value2, ALint value3)
187 ALCcontext *Context;
189 switch(param)
191 case AL_POSITION:
192 case AL_VELOCITY:
193 alListener3f(param, (ALfloat)value1, (ALfloat)value2, (ALfloat)value3);
194 return;
197 Context = GetContextRef();
198 if(!Context) return;
200 al_try
202 switch(param)
204 default:
205 al_throwerr(Context, AL_INVALID_ENUM);
208 al_endtry;
210 ALCcontext_DecRef(Context);
214 AL_API void AL_APIENTRY alListeneriv(ALenum param, const ALint *values)
216 ALCcontext *Context;
218 if(values)
220 ALfloat fvals[6];
221 switch(param)
223 case AL_POSITION:
224 case AL_VELOCITY:
225 alListener3f(param, (ALfloat)values[0], (ALfloat)values[1], (ALfloat)values[2]);
226 return;
228 case AL_ORIENTATION:
229 fvals[0] = (ALfloat)values[0];
230 fvals[1] = (ALfloat)values[1];
231 fvals[2] = (ALfloat)values[2];
232 fvals[3] = (ALfloat)values[3];
233 fvals[4] = (ALfloat)values[4];
234 fvals[5] = (ALfloat)values[5];
235 alListenerfv(param, fvals);
236 return;
240 Context = GetContextRef();
241 if(!Context) return;
243 al_try
245 CHECK_VALUE(Context, values);
246 switch(param)
248 default:
249 al_throwerr(Context, AL_INVALID_ENUM);
252 al_endtry;
254 ALCcontext_DecRef(Context);
258 AL_API ALvoid AL_APIENTRY alGetListenerf(ALenum param, ALfloat *value)
260 ALCcontext *Context;
262 Context = GetContextRef();
263 if(!Context) return;
265 al_try
267 CHECK_VALUE(Context, value);
268 switch(param)
270 case AL_GAIN:
271 *value = Context->Listener->Gain;
272 break;
274 case AL_METERS_PER_UNIT:
275 *value = Context->Listener->MetersPerUnit;
276 break;
278 default:
279 al_throwerr(Context, AL_INVALID_ENUM);
282 al_endtry;
284 ALCcontext_DecRef(Context);
288 AL_API ALvoid AL_APIENTRY alGetListener3f(ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3)
290 ALCcontext *Context;
292 Context = GetContextRef();
293 if(!Context) return;
295 al_try
297 CHECK_VALUE(Context, value1 && value2 && value3);
298 switch(param)
300 case AL_POSITION:
301 LockContext(Context);
302 *value1 = Context->Listener->Position[0];
303 *value2 = Context->Listener->Position[1];
304 *value3 = Context->Listener->Position[2];
305 UnlockContext(Context);
306 break;
308 case AL_VELOCITY:
309 LockContext(Context);
310 *value1 = Context->Listener->Velocity[0];
311 *value2 = Context->Listener->Velocity[1];
312 *value3 = Context->Listener->Velocity[2];
313 UnlockContext(Context);
314 break;
316 default:
317 al_throwerr(Context, AL_INVALID_ENUM);
320 al_endtry;
322 ALCcontext_DecRef(Context);
326 AL_API ALvoid AL_APIENTRY alGetListenerfv(ALenum param, ALfloat *values)
328 ALCcontext *Context;
330 switch(param)
332 case AL_GAIN:
333 case AL_METERS_PER_UNIT:
334 alGetListenerf(param, values);
335 return;
337 case AL_POSITION:
338 case AL_VELOCITY:
339 alGetListener3f(param, values+0, values+1, values+2);
340 return;
343 Context = GetContextRef();
344 if(!Context) return;
346 al_try
348 CHECK_VALUE(Context, values);
349 switch(param)
351 case AL_ORIENTATION:
352 LockContext(Context);
353 // AT then UP
354 values[0] = Context->Listener->Forward[0];
355 values[1] = Context->Listener->Forward[1];
356 values[2] = Context->Listener->Forward[2];
357 values[3] = Context->Listener->Up[0];
358 values[4] = Context->Listener->Up[1];
359 values[5] = Context->Listener->Up[2];
360 UnlockContext(Context);
361 break;
363 default:
364 al_throwerr(Context, AL_INVALID_ENUM);
367 al_endtry;
369 ALCcontext_DecRef(Context);
373 AL_API ALvoid AL_APIENTRY alGetListeneri(ALenum param, ALint *value)
375 ALCcontext *Context;
377 Context = GetContextRef();
378 if(!Context) return;
380 al_try
382 CHECK_VALUE(Context, value);
383 switch(param)
385 default:
386 al_throwerr(Context, AL_INVALID_ENUM);
389 al_endtry;
391 ALCcontext_DecRef(Context);
395 AL_API void AL_APIENTRY alGetListener3i(ALenum param, ALint *value1, ALint *value2, ALint *value3)
397 ALCcontext *Context;
399 Context = GetContextRef();
400 if(!Context) return;
402 al_try
404 CHECK_VALUE(Context, value1 && value2 && value3);
405 switch (param)
407 case AL_POSITION:
408 LockContext(Context);
409 *value1 = (ALint)Context->Listener->Position[0];
410 *value2 = (ALint)Context->Listener->Position[1];
411 *value3 = (ALint)Context->Listener->Position[2];
412 UnlockContext(Context);
413 break;
415 case AL_VELOCITY:
416 LockContext(Context);
417 *value1 = (ALint)Context->Listener->Velocity[0];
418 *value2 = (ALint)Context->Listener->Velocity[1];
419 *value3 = (ALint)Context->Listener->Velocity[2];
420 UnlockContext(Context);
421 break;
423 default:
424 al_throwerr(Context, AL_INVALID_ENUM);
427 al_endtry;
429 ALCcontext_DecRef(Context);
433 AL_API void AL_APIENTRY alGetListeneriv(ALenum param, ALint* values)
435 ALCcontext *Context;
437 switch(param)
439 case AL_POSITION:
440 case AL_VELOCITY:
441 alGetListener3i(param, values+0, values+1, values+2);
442 return;
445 Context = GetContextRef();
446 if(!Context) return;
448 al_try
450 CHECK_VALUE(Context, values);
451 switch(param)
453 case AL_ORIENTATION:
454 LockContext(Context);
455 // AT then UP
456 values[0] = (ALint)Context->Listener->Forward[0];
457 values[1] = (ALint)Context->Listener->Forward[1];
458 values[2] = (ALint)Context->Listener->Forward[2];
459 values[3] = (ALint)Context->Listener->Up[0];
460 values[4] = (ALint)Context->Listener->Up[1];
461 values[5] = (ALint)Context->Listener->Up[2];
462 UnlockContext(Context);
463 break;
465 default:
466 al_throwerr(Context, AL_INVALID_ENUM);
469 al_endtry;
471 ALCcontext_DecRef(Context);