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
26 #include "alListener.h"
29 AL_API ALvoid AL_APIENTRY
alListenerf(ALenum param
, ALfloat value
)
33 Context
= GetContextRef();
41 CHECK_VALUE(Context
, value
>= 0.0f
&& isfinite(value
));
43 Context
->Listener
.Gain
= value
;
44 Context
->UpdateSources
= AL_TRUE
;
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
;
55 al_throwerr(Context
, AL_INVALID_ENUM
);
60 ALCcontext_DecRef(Context
);
64 AL_API ALvoid AL_APIENTRY
alListener3f(ALenum param
, ALfloat value1
, ALfloat value2
, ALfloat value3
)
68 Context
= GetContextRef();
76 CHECK_VALUE(Context
, isfinite(value1
) && isfinite(value2
) && isfinite(value3
));
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
);
87 CHECK_VALUE(Context
, isfinite(value1
) && isfinite(value2
) && isfinite(value3
));
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
);
98 al_throwerr(Context
, AL_INVALID_ENUM
);
103 ALCcontext_DecRef(Context
);
107 AL_API ALvoid AL_APIENTRY
alListenerfv(ALenum param
, const ALfloat
*values
)
116 case AL_METERS_PER_UNIT
:
117 alListenerf(param
, values
[0]);
122 alListener3f(param
, values
[0], values
[1], values
[2]);
127 Context
= GetContextRef();
132 ALfloat U
[3], V
[3], N
[3];
133 CHECK_VALUE(Context
, values
);
137 CHECK_VALUE(Context
, isfinite(values
[0]) && isfinite(values
[1]) &&
138 isfinite(values
[2]) && isfinite(values
[3]) &&
139 isfinite(values
[4]) && isfinite(values
[5]));
150 /* Build and normalize right-vector */
151 aluCrossproduct(N
, V
, U
);
154 LockContext(Context
);
155 Context
->Listener
.Forward
[0] = values
[0];
156 Context
->Listener
.Forward
[1] = values
[1];
157 Context
->Listener
.Forward
[2] = values
[2];
158 Context
->Listener
.Up
[0] = values
[3];
159 Context
->Listener
.Up
[1] = values
[4];
160 Context
->Listener
.Up
[2] = values
[5];
161 Context
->Listener
.Matrix
[0][0] = U
[0];
162 Context
->Listener
.Matrix
[0][1] = V
[0];
163 Context
->Listener
.Matrix
[0][2] = -N
[0];
164 Context
->Listener
.Matrix
[0][3] = 0.0f
;
165 Context
->Listener
.Matrix
[1][0] = U
[1];
166 Context
->Listener
.Matrix
[1][1] = V
[1];
167 Context
->Listener
.Matrix
[1][2] = -N
[1];
168 Context
->Listener
.Matrix
[1][3] = 0.0f
;
169 Context
->Listener
.Matrix
[2][0] = U
[2];
170 Context
->Listener
.Matrix
[2][1] = V
[2];
171 Context
->Listener
.Matrix
[2][2] = -N
[2];
172 Context
->Listener
.Matrix
[2][3] = 0.0f
;
173 Context
->Listener
.Matrix
[3][0] = 0.0f
;
174 Context
->Listener
.Matrix
[3][1] = 0.0f
;
175 Context
->Listener
.Matrix
[3][2] = 0.0f
;
176 Context
->Listener
.Matrix
[3][3] = 1.0f
;
177 Context
->UpdateSources
= AL_TRUE
;
178 UnlockContext(Context
);
182 al_throwerr(Context
, AL_INVALID_ENUM
);
187 ALCcontext_DecRef(Context
);
191 AL_API ALvoid AL_APIENTRY
alListeneri(ALenum param
, ALint value
)
197 Context
= GetContextRef();
205 al_throwerr(Context
, AL_INVALID_ENUM
);
210 ALCcontext_DecRef(Context
);
214 AL_API
void AL_APIENTRY
alListener3i(ALenum param
, ALint value1
, ALint value2
, ALint value3
)
222 alListener3f(param
, (ALfloat
)value1
, (ALfloat
)value2
, (ALfloat
)value3
);
226 Context
= GetContextRef();
234 al_throwerr(Context
, AL_INVALID_ENUM
);
239 ALCcontext_DecRef(Context
);
243 AL_API
void AL_APIENTRY
alListeneriv(ALenum param
, const ALint
*values
)
254 alListener3f(param
, (ALfloat
)values
[0], (ALfloat
)values
[1], (ALfloat
)values
[2]);
258 fvals
[0] = (ALfloat
)values
[0];
259 fvals
[1] = (ALfloat
)values
[1];
260 fvals
[2] = (ALfloat
)values
[2];
261 fvals
[3] = (ALfloat
)values
[3];
262 fvals
[4] = (ALfloat
)values
[4];
263 fvals
[5] = (ALfloat
)values
[5];
264 alListenerfv(param
, fvals
);
269 Context
= GetContextRef();
274 CHECK_VALUE(Context
, values
);
278 al_throwerr(Context
, AL_INVALID_ENUM
);
283 ALCcontext_DecRef(Context
);
287 AL_API ALvoid AL_APIENTRY
alGetListenerf(ALenum param
, ALfloat
*value
)
291 Context
= GetContextRef();
296 CHECK_VALUE(Context
, value
);
300 *value
= Context
->Listener
.Gain
;
303 case AL_METERS_PER_UNIT
:
304 *value
= Context
->Listener
.MetersPerUnit
;
308 al_throwerr(Context
, AL_INVALID_ENUM
);
313 ALCcontext_DecRef(Context
);
317 AL_API ALvoid AL_APIENTRY
alGetListener3f(ALenum param
, ALfloat
*value1
, ALfloat
*value2
, ALfloat
*value3
)
321 Context
= GetContextRef();
326 CHECK_VALUE(Context
, value1
&& value2
&& value3
);
330 LockContext(Context
);
331 *value1
= Context
->Listener
.Position
[0];
332 *value2
= Context
->Listener
.Position
[1];
333 *value3
= Context
->Listener
.Position
[2];
334 UnlockContext(Context
);
338 LockContext(Context
);
339 *value1
= Context
->Listener
.Velocity
[0];
340 *value2
= Context
->Listener
.Velocity
[1];
341 *value3
= Context
->Listener
.Velocity
[2];
342 UnlockContext(Context
);
346 al_throwerr(Context
, AL_INVALID_ENUM
);
351 ALCcontext_DecRef(Context
);
355 AL_API ALvoid AL_APIENTRY
alGetListenerfv(ALenum param
, ALfloat
*values
)
362 case AL_METERS_PER_UNIT
:
363 alGetListenerf(param
, values
);
368 alGetListener3f(param
, values
+0, values
+1, values
+2);
372 Context
= GetContextRef();
377 CHECK_VALUE(Context
, values
);
381 LockContext(Context
);
383 values
[0] = Context
->Listener
.Forward
[0];
384 values
[1] = Context
->Listener
.Forward
[1];
385 values
[2] = Context
->Listener
.Forward
[2];
386 values
[3] = Context
->Listener
.Up
[0];
387 values
[4] = Context
->Listener
.Up
[1];
388 values
[5] = Context
->Listener
.Up
[2];
389 UnlockContext(Context
);
393 al_throwerr(Context
, AL_INVALID_ENUM
);
398 ALCcontext_DecRef(Context
);
402 AL_API ALvoid AL_APIENTRY
alGetListeneri(ALenum param
, ALint
*value
)
406 Context
= GetContextRef();
411 CHECK_VALUE(Context
, value
);
415 al_throwerr(Context
, AL_INVALID_ENUM
);
420 ALCcontext_DecRef(Context
);
424 AL_API
void AL_APIENTRY
alGetListener3i(ALenum param
, ALint
*value1
, ALint
*value2
, ALint
*value3
)
428 Context
= GetContextRef();
433 CHECK_VALUE(Context
, value1
&& value2
&& value3
);
437 LockContext(Context
);
438 *value1
= (ALint
)Context
->Listener
.Position
[0];
439 *value2
= (ALint
)Context
->Listener
.Position
[1];
440 *value3
= (ALint
)Context
->Listener
.Position
[2];
441 UnlockContext(Context
);
445 LockContext(Context
);
446 *value1
= (ALint
)Context
->Listener
.Velocity
[0];
447 *value2
= (ALint
)Context
->Listener
.Velocity
[1];
448 *value3
= (ALint
)Context
->Listener
.Velocity
[2];
449 UnlockContext(Context
);
453 al_throwerr(Context
, AL_INVALID_ENUM
);
458 ALCcontext_DecRef(Context
);
462 AL_API
void AL_APIENTRY
alGetListeneriv(ALenum param
, ALint
* values
)
470 alGetListener3i(param
, values
+0, values
+1, values
+2);
474 Context
= GetContextRef();
479 CHECK_VALUE(Context
, values
);
483 LockContext(Context
);
485 values
[0] = (ALint
)Context
->Listener
.Forward
[0];
486 values
[1] = (ALint
)Context
->Listener
.Forward
[1];
487 values
[2] = (ALint
)Context
->Listener
.Forward
[2];
488 values
[3] = (ALint
)Context
->Listener
.Up
[0];
489 values
[4] = (ALint
)Context
->Listener
.Up
[1];
490 values
[5] = (ALint
)Context
->Listener
.Up
[2];
491 UnlockContext(Context
);
495 al_throwerr(Context
, AL_INVALID_ENUM
);
500 ALCcontext_DecRef(Context
);