Make sure the ALSA device list is reset if no cards are found
[openal-soft/openal-hmr.git] / OpenAL32 / alListener.c
blobcef7ae4b0b14031fa179a49f4f467f22f4b77b7d
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"
28 ALAPI ALvoid ALAPIENTRY alListenerf(ALenum eParam, ALfloat flValue)
30 ALCcontext *pContext;
32 pContext = GetContextSuspended();
33 if(!pContext) return;
35 switch(eParam)
37 case AL_GAIN:
38 if(flValue >= 0.0f)
39 pContext->Listener.Gain = flValue;
40 else
41 alSetError(AL_INVALID_VALUE);
42 break;
44 case AL_METERS_PER_UNIT:
45 if(flValue > 0.0f)
46 pContext->Listener.MetersPerUnit = flValue;
47 else
48 alSetError(AL_INVALID_VALUE);
49 break;
51 default:
52 alSetError(AL_INVALID_ENUM);
53 break;
56 ProcessContext(pContext);
60 ALAPI ALvoid ALAPIENTRY alListener3f(ALenum eParam, ALfloat flValue1, ALfloat flValue2, ALfloat flValue3)
62 ALCcontext *pContext;
64 pContext = GetContextSuspended();
65 if(!pContext) return;
67 switch(eParam)
69 case AL_POSITION:
70 pContext->Listener.Position[0] = flValue1;
71 pContext->Listener.Position[1] = flValue2;
72 pContext->Listener.Position[2] = flValue3;
73 break;
75 case AL_VELOCITY:
76 pContext->Listener.Velocity[0] = flValue1;
77 pContext->Listener.Velocity[1] = flValue2;
78 pContext->Listener.Velocity[2] = flValue3;
79 break;
81 default:
82 alSetError(AL_INVALID_ENUM);
83 break;
86 ProcessContext(pContext);
90 ALAPI ALvoid ALAPIENTRY alListenerfv(ALenum eParam, const ALfloat *pflValues)
92 ALCcontext *pContext;
94 pContext = GetContextSuspended();
95 if(!pContext) return;
97 if(pflValues)
99 switch(eParam)
101 case AL_GAIN:
102 if(pflValues[0] >= 0.0f)
103 pContext->Listener.Gain = pflValues[0];
104 else
105 alSetError(AL_INVALID_VALUE);
106 break;
108 case AL_METERS_PER_UNIT:
109 if(pflValues[0] > 0.0f)
110 pContext->Listener.MetersPerUnit = pflValues[0];
111 else
112 alSetError(AL_INVALID_VALUE);
113 break;
115 case AL_POSITION:
116 pContext->Listener.Position[0] = pflValues[0];
117 pContext->Listener.Position[1] = pflValues[1];
118 pContext->Listener.Position[2] = pflValues[2];
119 break;
121 case AL_VELOCITY:
122 pContext->Listener.Velocity[0] = pflValues[0];
123 pContext->Listener.Velocity[1] = pflValues[1];
124 pContext->Listener.Velocity[2] = pflValues[2];
125 break;
127 case AL_ORIENTATION:
128 // AT then UP
129 pContext->Listener.Forward[0] = pflValues[0];
130 pContext->Listener.Forward[1] = pflValues[1];
131 pContext->Listener.Forward[2] = pflValues[2];
132 pContext->Listener.Up[0] = pflValues[3];
133 pContext->Listener.Up[1] = pflValues[4];
134 pContext->Listener.Up[2] = pflValues[5];
135 break;
137 default:
138 alSetError(AL_INVALID_ENUM);
139 break;
142 else
143 alSetError(AL_INVALID_VALUE);
145 ProcessContext(pContext);
149 ALAPI ALvoid ALAPIENTRY alListeneri(ALenum eParam, ALint lValue)
151 ALCcontext *pContext;
153 (void)lValue;
155 pContext = GetContextSuspended();
156 if(!pContext) return;
158 switch(eParam)
160 default:
161 alSetError(AL_INVALID_ENUM);
162 break;
165 ProcessContext(pContext);
169 ALAPI void ALAPIENTRY alListener3i(ALenum eParam, ALint lValue1, ALint lValue2, ALint lValue3)
171 ALCcontext *pContext;
173 pContext = GetContextSuspended();
174 if(!pContext) return;
176 switch(eParam)
178 case AL_POSITION:
179 case AL_VELOCITY:
180 alListener3f(eParam, (ALfloat)lValue1, (ALfloat)lValue2, (ALfloat)lValue3);
181 break;
183 default:
184 alSetError(AL_INVALID_ENUM);
185 break;
188 ProcessContext(pContext);
192 ALAPI void ALAPIENTRY alListeneriv( ALenum eParam, const ALint* plValues )
194 ALCcontext *pContext;
195 ALfloat flValues[6];
197 pContext = GetContextSuspended();
198 if(!pContext) return;
200 if(plValues)
202 switch(eParam)
204 case AL_POSITION:
205 case AL_VELOCITY:
206 flValues[0] = (ALfloat)plValues[0];
207 flValues[1] = (ALfloat)plValues[1];
208 flValues[2] = (ALfloat)plValues[2];
209 alListenerfv(eParam, flValues);
210 break;
212 case AL_ORIENTATION:
213 flValues[0] = (ALfloat)plValues[0];
214 flValues[1] = (ALfloat)plValues[1];
215 flValues[2] = (ALfloat)plValues[2];
216 flValues[3] = (ALfloat)plValues[3];
217 flValues[4] = (ALfloat)plValues[4];
218 flValues[5] = (ALfloat)plValues[5];
219 alListenerfv(eParam, flValues);
220 break;
222 default:
223 alSetError(AL_INVALID_ENUM);
224 break;
227 else
228 alSetError(AL_INVALID_VALUE);
230 ProcessContext(pContext);
234 ALAPI ALvoid ALAPIENTRY alGetListenerf(ALenum eParam, ALfloat *pflValue)
236 ALCcontext *pContext;
238 pContext = GetContextSuspended();
239 if(!pContext) return;
241 if(pflValue)
243 switch(eParam)
245 case AL_GAIN:
246 *pflValue = pContext->Listener.Gain;
247 break;
249 case AL_METERS_PER_UNIT:
250 *pflValue = pContext->Listener.MetersPerUnit;
251 break;
253 default:
254 alSetError(AL_INVALID_ENUM);
255 break;
258 else
259 alSetError(AL_INVALID_VALUE);
261 ProcessContext(pContext);
265 ALAPI ALvoid ALAPIENTRY alGetListener3f(ALenum eParam, ALfloat *pflValue1, ALfloat *pflValue2, ALfloat *pflValue3)
267 ALCcontext *pContext;
269 pContext = GetContextSuspended();
270 if(!pContext) return;
272 if(pflValue1 && pflValue2 && pflValue3)
274 switch(eParam)
276 case AL_POSITION:
277 *pflValue1 = pContext->Listener.Position[0];
278 *pflValue2 = pContext->Listener.Position[1];
279 *pflValue3 = pContext->Listener.Position[2];
280 break;
282 case AL_VELOCITY:
283 *pflValue1 = pContext->Listener.Velocity[0];
284 *pflValue2 = pContext->Listener.Velocity[1];
285 *pflValue3 = pContext->Listener.Velocity[2];
286 break;
288 default:
289 alSetError(AL_INVALID_ENUM);
290 break;
293 else
294 alSetError(AL_INVALID_VALUE);
296 ProcessContext(pContext);
300 ALAPI ALvoid ALAPIENTRY alGetListenerfv(ALenum eParam, ALfloat *pflValues)
302 ALCcontext *pContext;
304 pContext = GetContextSuspended();
305 if(!pContext) return;
307 if(pflValues)
309 switch(eParam)
311 case AL_GAIN:
312 pflValues[0] = pContext->Listener.Gain;
313 break;
315 case AL_METERS_PER_UNIT:
316 pflValues[0] = pContext->Listener.MetersPerUnit;
317 break;
319 case AL_POSITION:
320 pflValues[0] = pContext->Listener.Position[0];
321 pflValues[1] = pContext->Listener.Position[1];
322 pflValues[2] = pContext->Listener.Position[2];
323 break;
325 case AL_VELOCITY:
326 pflValues[0] = pContext->Listener.Velocity[0];
327 pflValues[1] = pContext->Listener.Velocity[1];
328 pflValues[2] = pContext->Listener.Velocity[2];
329 break;
331 case AL_ORIENTATION:
332 // AT then UP
333 pflValues[0] = pContext->Listener.Forward[0];
334 pflValues[1] = pContext->Listener.Forward[1];
335 pflValues[2] = pContext->Listener.Forward[2];
336 pflValues[3] = pContext->Listener.Up[0];
337 pflValues[4] = pContext->Listener.Up[1];
338 pflValues[5] = pContext->Listener.Up[2];
339 break;
341 default:
342 alSetError(AL_INVALID_ENUM);
343 break;
346 else
347 alSetError(AL_INVALID_VALUE);
349 ProcessContext(pContext);
353 ALAPI ALvoid ALAPIENTRY alGetListeneri(ALenum eParam, ALint *plValue)
355 ALCcontext *pContext;
357 pContext = GetContextSuspended();
358 if(!pContext) return;
360 if(plValue)
362 switch(eParam)
364 default:
365 alSetError(AL_INVALID_ENUM);
366 break;
369 else
370 alSetError(AL_INVALID_VALUE);
372 ProcessContext(pContext);
376 ALAPI void ALAPIENTRY alGetListener3i(ALenum eParam, ALint *plValue1, ALint *plValue2, ALint *plValue3)
378 ALCcontext *pContext;
380 pContext = GetContextSuspended();
381 if(!pContext) return;
383 if(plValue1 && plValue2 && plValue3)
385 switch (eParam)
387 case AL_POSITION:
388 *plValue1 = (ALint)pContext->Listener.Position[0];
389 *plValue2 = (ALint)pContext->Listener.Position[1];
390 *plValue3 = (ALint)pContext->Listener.Position[2];
391 break;
393 case AL_VELOCITY:
394 *plValue1 = (ALint)pContext->Listener.Velocity[0];
395 *plValue2 = (ALint)pContext->Listener.Velocity[1];
396 *plValue3 = (ALint)pContext->Listener.Velocity[2];
397 break;
399 default:
400 alSetError(AL_INVALID_ENUM);
401 break;
404 else
405 alSetError(AL_INVALID_VALUE);
407 ProcessContext(pContext);
411 ALAPI void ALAPIENTRY alGetListeneriv(ALenum eParam, ALint* plValues)
413 ALCcontext *pContext;
415 pContext = GetContextSuspended();
416 if(!pContext) return;
418 if(plValues)
420 switch(eParam)
422 case AL_POSITION:
423 plValues[0] = (ALint)pContext->Listener.Position[0];
424 plValues[1] = (ALint)pContext->Listener.Position[1];
425 plValues[2] = (ALint)pContext->Listener.Position[2];
426 break;
428 case AL_VELOCITY:
429 plValues[0] = (ALint)pContext->Listener.Velocity[0];
430 plValues[1] = (ALint)pContext->Listener.Velocity[1];
431 plValues[2] = (ALint)pContext->Listener.Velocity[2];
432 break;
434 case AL_ORIENTATION:
435 // AT then UP
436 plValues[0] = (ALint)pContext->Listener.Forward[0];
437 plValues[1] = (ALint)pContext->Listener.Forward[1];
438 plValues[2] = (ALint)pContext->Listener.Forward[2];
439 plValues[3] = (ALint)pContext->Listener.Up[0];
440 plValues[4] = (ALint)pContext->Listener.Up[1];
441 plValues[5] = (ALint)pContext->Listener.Up[2];
442 break;
444 default:
445 alSetError(AL_INVALID_ENUM);
446 break;
449 else
450 alSetError(AL_INVALID_VALUE);
452 ProcessContext(pContext);