Rework HRTF decision logic
[openal-soft.git] / OpenAL32 / alListener.c
blobc30d6f8471cadef028eec527f810f1e8dc2e708b
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.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 switch(param)
38 case AL_GAIN:
39 if(!(value >= 0.0f && isfinite(value)))
40 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
42 context->Listener->Gain = value;
43 ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
44 break;
46 case AL_METERS_PER_UNIT:
47 if(!(value >= 0.0f && isfinite(value)))
48 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
50 context->Listener->MetersPerUnit = value;
51 ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
52 break;
54 default:
55 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
58 done:
59 ALCcontext_DecRef(context);
63 AL_API ALvoid AL_APIENTRY alListener3f(ALenum param, ALfloat value1, ALfloat value2, ALfloat value3)
65 ALCcontext *context;
67 context = GetContextRef();
68 if(!context) return;
70 switch(param)
72 case AL_POSITION:
73 if(!(isfinite(value1) && isfinite(value2) && isfinite(value3)))
74 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
76 LockContext(context);
77 context->Listener->Position[0] = value1;
78 context->Listener->Position[1] = value2;
79 context->Listener->Position[2] = value3;
80 ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
81 UnlockContext(context);
82 break;
84 case AL_VELOCITY:
85 if(!(isfinite(value1) && isfinite(value2) && isfinite(value3)))
86 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
88 LockContext(context);
89 context->Listener->Velocity[0] = value1;
90 context->Listener->Velocity[1] = value2;
91 context->Listener->Velocity[2] = value3;
92 ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
93 UnlockContext(context);
94 break;
96 default:
97 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
100 done:
101 ALCcontext_DecRef(context);
105 AL_API ALvoid AL_APIENTRY alListenerfv(ALenum param, const ALfloat *values)
107 ALCcontext *context;
109 if(values)
111 switch(param)
113 case AL_GAIN:
114 case AL_METERS_PER_UNIT:
115 alListenerf(param, values[0]);
116 return;
118 case AL_POSITION:
119 case AL_VELOCITY:
120 alListener3f(param, values[0], values[1], values[2]);
121 return;
125 context = GetContextRef();
126 if(!context) return;
128 if(!(values))
129 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
130 switch(param)
132 case AL_ORIENTATION:
133 if(!(isfinite(values[0]) && isfinite(values[1]) && isfinite(values[2]) &&
134 isfinite(values[3]) && isfinite(values[4]) && isfinite(values[5])))
135 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
137 LockContext(context);
138 /* AT then UP */
139 context->Listener->Forward[0] = values[0];
140 context->Listener->Forward[1] = values[1];
141 context->Listener->Forward[2] = values[2];
142 context->Listener->Up[0] = values[3];
143 context->Listener->Up[1] = values[4];
144 context->Listener->Up[2] = values[5];
145 ATOMIC_STORE(&context->UpdateSources, AL_TRUE);
146 UnlockContext(context);
147 break;
149 default:
150 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
153 done:
154 ALCcontext_DecRef(context);
158 AL_API ALvoid AL_APIENTRY alListeneri(ALenum param, ALint UNUSED(value))
160 ALCcontext *context;
162 context = GetContextRef();
163 if(!context) return;
165 switch(param)
167 default:
168 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
171 done:
172 ALCcontext_DecRef(context);
176 AL_API void AL_APIENTRY alListener3i(ALenum param, ALint value1, ALint value2, ALint value3)
178 ALCcontext *context;
180 switch(param)
182 case AL_POSITION:
183 case AL_VELOCITY:
184 alListener3f(param, (ALfloat)value1, (ALfloat)value2, (ALfloat)value3);
185 return;
188 context = GetContextRef();
189 if(!context) return;
191 switch(param)
193 default:
194 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
197 done:
198 ALCcontext_DecRef(context);
202 AL_API void AL_APIENTRY alListeneriv(ALenum param, const ALint *values)
204 ALCcontext *context;
206 if(values)
208 ALfloat fvals[6];
209 switch(param)
211 case AL_POSITION:
212 case AL_VELOCITY:
213 alListener3f(param, (ALfloat)values[0], (ALfloat)values[1], (ALfloat)values[2]);
214 return;
216 case AL_ORIENTATION:
217 fvals[0] = (ALfloat)values[0];
218 fvals[1] = (ALfloat)values[1];
219 fvals[2] = (ALfloat)values[2];
220 fvals[3] = (ALfloat)values[3];
221 fvals[4] = (ALfloat)values[4];
222 fvals[5] = (ALfloat)values[5];
223 alListenerfv(param, fvals);
224 return;
228 context = GetContextRef();
229 if(!context) return;
231 if(!(values))
232 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
233 switch(param)
235 default:
236 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
239 done:
240 ALCcontext_DecRef(context);
244 AL_API ALvoid AL_APIENTRY alGetListenerf(ALenum param, ALfloat *value)
246 ALCcontext *context;
248 context = GetContextRef();
249 if(!context) return;
251 if(!(value))
252 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
253 switch(param)
255 case AL_GAIN:
256 *value = context->Listener->Gain;
257 break;
259 case AL_METERS_PER_UNIT:
260 *value = context->Listener->MetersPerUnit;
261 break;
263 default:
264 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
267 done:
268 ALCcontext_DecRef(context);
272 AL_API ALvoid AL_APIENTRY alGetListener3f(ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3)
274 ALCcontext *context;
276 context = GetContextRef();
277 if(!context) return;
279 if(!(value1 && value2 && value3))
280 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
281 switch(param)
283 case AL_POSITION:
284 LockContext(context);
285 *value1 = context->Listener->Position[0];
286 *value2 = context->Listener->Position[1];
287 *value3 = context->Listener->Position[2];
288 UnlockContext(context);
289 break;
291 case AL_VELOCITY:
292 LockContext(context);
293 *value1 = context->Listener->Velocity[0];
294 *value2 = context->Listener->Velocity[1];
295 *value3 = context->Listener->Velocity[2];
296 UnlockContext(context);
297 break;
299 default:
300 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
303 done:
304 ALCcontext_DecRef(context);
308 AL_API ALvoid AL_APIENTRY alGetListenerfv(ALenum param, ALfloat *values)
310 ALCcontext *context;
312 switch(param)
314 case AL_GAIN:
315 case AL_METERS_PER_UNIT:
316 alGetListenerf(param, values);
317 return;
319 case AL_POSITION:
320 case AL_VELOCITY:
321 alGetListener3f(param, values+0, values+1, values+2);
322 return;
325 context = GetContextRef();
326 if(!context) return;
328 if(!(values))
329 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
330 switch(param)
332 case AL_ORIENTATION:
333 LockContext(context);
334 // AT then UP
335 values[0] = context->Listener->Forward[0];
336 values[1] = context->Listener->Forward[1];
337 values[2] = context->Listener->Forward[2];
338 values[3] = context->Listener->Up[0];
339 values[4] = context->Listener->Up[1];
340 values[5] = context->Listener->Up[2];
341 UnlockContext(context);
342 break;
344 default:
345 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
348 done:
349 ALCcontext_DecRef(context);
353 AL_API ALvoid AL_APIENTRY alGetListeneri(ALenum param, ALint *value)
355 ALCcontext *context;
357 context = GetContextRef();
358 if(!context) return;
360 if(!(value))
361 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
362 switch(param)
364 default:
365 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
368 done:
369 ALCcontext_DecRef(context);
373 AL_API void AL_APIENTRY alGetListener3i(ALenum param, ALint *value1, ALint *value2, ALint *value3)
375 ALCcontext *context;
377 context = GetContextRef();
378 if(!context) return;
380 if(!(value1 && value2 && value3))
381 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
382 switch (param)
384 case AL_POSITION:
385 LockContext(context);
386 *value1 = (ALint)context->Listener->Position[0];
387 *value2 = (ALint)context->Listener->Position[1];
388 *value3 = (ALint)context->Listener->Position[2];
389 UnlockContext(context);
390 break;
392 case AL_VELOCITY:
393 LockContext(context);
394 *value1 = (ALint)context->Listener->Velocity[0];
395 *value2 = (ALint)context->Listener->Velocity[1];
396 *value3 = (ALint)context->Listener->Velocity[2];
397 UnlockContext(context);
398 break;
400 default:
401 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
404 done:
405 ALCcontext_DecRef(context);
409 AL_API void AL_APIENTRY alGetListeneriv(ALenum param, ALint* values)
411 ALCcontext *context;
413 switch(param)
415 case AL_POSITION:
416 case AL_VELOCITY:
417 alGetListener3i(param, values+0, values+1, values+2);
418 return;
421 context = GetContextRef();
422 if(!context) return;
424 if(!(values))
425 SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
426 switch(param)
428 case AL_ORIENTATION:
429 LockContext(context);
430 // AT then UP
431 values[0] = (ALint)context->Listener->Forward[0];
432 values[1] = (ALint)context->Listener->Forward[1];
433 values[2] = (ALint)context->Listener->Forward[2];
434 values[3] = (ALint)context->Listener->Up[0];
435 values[4] = (ALint)context->Listener->Up[1];
436 values[5] = (ALint)context->Listener->Up[2];
437 UnlockContext(context);
438 break;
440 default:
441 SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
444 done:
445 ALCcontext_DecRef(context);