alListener.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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.
  8. *
  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.
  13. *
  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
  19. */
  20. #include "config.h"
  21. #include "alMain.h"
  22. #include "AL/alc.h"
  23. #include "alError.h"
  24. #include "alListener.h"
  25. #include "alSource.h"
  26. AL_API ALvoid AL_APIENTRY alListenerf(ALenum eParam, ALfloat flValue)
  27. {
  28. ALCcontext *pContext;
  29. ALboolean updateAll = AL_FALSE;
  30. pContext = GetContextSuspended();
  31. if(!pContext) return;
  32. switch(eParam)
  33. {
  34. case AL_GAIN:
  35. if(flValue >= 0.0f)
  36. {
  37. pContext->Listener.Gain = flValue;
  38. updateAll = AL_TRUE;
  39. }
  40. else
  41. alSetError(pContext, AL_INVALID_VALUE);
  42. break;
  43. case AL_METERS_PER_UNIT:
  44. if(flValue > 0.0f)
  45. {
  46. pContext->Listener.MetersPerUnit = flValue;
  47. updateAll = AL_TRUE;
  48. }
  49. else
  50. alSetError(pContext, AL_INVALID_VALUE);
  51. break;
  52. default:
  53. alSetError(pContext, AL_INVALID_ENUM);
  54. break;
  55. }
  56. // Force updating the sources for these parameters, since even head-
  57. // relative sources are affected
  58. if(updateAll)
  59. {
  60. ALsizei pos;
  61. for(pos = 0;pos < pContext->SourceMap.size;pos++)
  62. {
  63. ALsource *source = pContext->SourceMap.array[pos].value;
  64. source->NeedsUpdate = AL_TRUE;
  65. }
  66. }
  67. ProcessContext(pContext);
  68. }
  69. AL_API ALvoid AL_APIENTRY alListener3f(ALenum eParam, ALfloat flValue1, ALfloat flValue2, ALfloat flValue3)
  70. {
  71. ALCcontext *pContext;
  72. ALboolean updateWorld = AL_FALSE;
  73. pContext = GetContextSuspended();
  74. if(!pContext) return;
  75. switch(eParam)
  76. {
  77. case AL_POSITION:
  78. pContext->Listener.Position[0] = flValue1;
  79. pContext->Listener.Position[1] = flValue2;
  80. pContext->Listener.Position[2] = flValue3;
  81. updateWorld = AL_TRUE;
  82. break;
  83. case AL_VELOCITY:
  84. pContext->Listener.Velocity[0] = flValue1;
  85. pContext->Listener.Velocity[1] = flValue2;
  86. pContext->Listener.Velocity[2] = flValue3;
  87. updateWorld = AL_TRUE;
  88. break;
  89. default:
  90. alSetError(pContext, AL_INVALID_ENUM);
  91. break;
  92. }
  93. if(updateWorld)
  94. {
  95. ALsizei pos;
  96. for(pos = 0;pos < pContext->SourceMap.size;pos++)
  97. {
  98. ALsource *source = pContext->SourceMap.array[pos].value;
  99. if(!source->bHeadRelative)
  100. source->NeedsUpdate = AL_TRUE;
  101. }
  102. }
  103. ProcessContext(pContext);
  104. }
  105. AL_API ALvoid AL_APIENTRY alListenerfv(ALenum eParam, const ALfloat *pflValues)
  106. {
  107. ALCcontext *pContext;
  108. ALboolean updateWorld = AL_FALSE;
  109. pContext = GetContextSuspended();
  110. if(!pContext) return;
  111. if(pflValues)
  112. {
  113. switch(eParam)
  114. {
  115. case AL_GAIN:
  116. case AL_METERS_PER_UNIT:
  117. alListenerf(eParam, pflValues[0]);
  118. break;
  119. case AL_POSITION:
  120. case AL_VELOCITY:
  121. alListener3f(eParam, pflValues[0], pflValues[1], pflValues[2]);
  122. break;
  123. case AL_ORIENTATION:
  124. // AT then UP
  125. pContext->Listener.Forward[0] = pflValues[0];
  126. pContext->Listener.Forward[1] = pflValues[1];
  127. pContext->Listener.Forward[2] = pflValues[2];
  128. pContext->Listener.Up[0] = pflValues[3];
  129. pContext->Listener.Up[1] = pflValues[4];
  130. pContext->Listener.Up[2] = pflValues[5];
  131. updateWorld = AL_TRUE;
  132. break;
  133. default:
  134. alSetError(pContext, AL_INVALID_ENUM);
  135. break;
  136. }
  137. }
  138. else
  139. alSetError(pContext, AL_INVALID_VALUE);
  140. if(updateWorld)
  141. {
  142. ALsizei pos;
  143. for(pos = 0;pos < pContext->SourceMap.size;pos++)
  144. {
  145. ALsource *source = pContext->SourceMap.array[pos].value;
  146. if(!source->bHeadRelative)
  147. source->NeedsUpdate = AL_TRUE;
  148. }
  149. }
  150. ProcessContext(pContext);
  151. }
  152. AL_API ALvoid AL_APIENTRY alListeneri(ALenum eParam, ALint lValue)
  153. {
  154. ALCcontext *pContext;
  155. (void)lValue;
  156. pContext = GetContextSuspended();
  157. if(!pContext) return;
  158. switch(eParam)
  159. {
  160. default:
  161. alSetError(pContext, AL_INVALID_ENUM);
  162. break;
  163. }
  164. ProcessContext(pContext);
  165. }
  166. AL_API void AL_APIENTRY alListener3i(ALenum eParam, ALint lValue1, ALint lValue2, ALint lValue3)
  167. {
  168. ALCcontext *pContext;
  169. pContext = GetContextSuspended();
  170. if(!pContext) return;
  171. switch(eParam)
  172. {
  173. case AL_POSITION:
  174. case AL_VELOCITY:
  175. alListener3f(eParam, (ALfloat)lValue1, (ALfloat)lValue2, (ALfloat)lValue3);
  176. break;
  177. default:
  178. alSetError(pContext, AL_INVALID_ENUM);
  179. break;
  180. }
  181. ProcessContext(pContext);
  182. }
  183. AL_API void AL_APIENTRY alListeneriv( ALenum eParam, const ALint* plValues )
  184. {
  185. ALCcontext *pContext;
  186. ALfloat flValues[6];
  187. pContext = GetContextSuspended();
  188. if(!pContext) return;
  189. if(plValues)
  190. {
  191. switch(eParam)
  192. {
  193. case AL_POSITION:
  194. case AL_VELOCITY:
  195. flValues[0] = (ALfloat)plValues[0];
  196. flValues[1] = (ALfloat)plValues[1];
  197. flValues[2] = (ALfloat)plValues[2];
  198. alListenerfv(eParam, flValues);
  199. break;
  200. case AL_ORIENTATION:
  201. flValues[0] = (ALfloat)plValues[0];
  202. flValues[1] = (ALfloat)plValues[1];
  203. flValues[2] = (ALfloat)plValues[2];
  204. flValues[3] = (ALfloat)plValues[3];
  205. flValues[4] = (ALfloat)plValues[4];
  206. flValues[5] = (ALfloat)plValues[5];
  207. alListenerfv(eParam, flValues);
  208. break;
  209. default:
  210. alSetError(pContext, AL_INVALID_ENUM);
  211. break;
  212. }
  213. }
  214. else
  215. alSetError(pContext, AL_INVALID_VALUE);
  216. ProcessContext(pContext);
  217. }
  218. AL_API ALvoid AL_APIENTRY alGetListenerf(ALenum eParam, ALfloat *pflValue)
  219. {
  220. ALCcontext *pContext;
  221. pContext = GetContextSuspended();
  222. if(!pContext) return;
  223. if(pflValue)
  224. {
  225. switch(eParam)
  226. {
  227. case AL_GAIN:
  228. *pflValue = pContext->Listener.Gain;
  229. break;
  230. case AL_METERS_PER_UNIT:
  231. *pflValue = pContext->Listener.MetersPerUnit;
  232. break;
  233. default:
  234. alSetError(pContext, AL_INVALID_ENUM);
  235. break;
  236. }
  237. }
  238. else
  239. alSetError(pContext, AL_INVALID_VALUE);
  240. ProcessContext(pContext);
  241. }
  242. AL_API ALvoid AL_APIENTRY alGetListener3f(ALenum eParam, ALfloat *pflValue1, ALfloat *pflValue2, ALfloat *pflValue3)
  243. {
  244. ALCcontext *pContext;
  245. pContext = GetContextSuspended();
  246. if(!pContext) return;
  247. if(pflValue1 && pflValue2 && pflValue3)
  248. {
  249. switch(eParam)
  250. {
  251. case AL_POSITION:
  252. *pflValue1 = pContext->Listener.Position[0];
  253. *pflValue2 = pContext->Listener.Position[1];
  254. *pflValue3 = pContext->Listener.Position[2];
  255. break;
  256. case AL_VELOCITY:
  257. *pflValue1 = pContext->Listener.Velocity[0];
  258. *pflValue2 = pContext->Listener.Velocity[1];
  259. *pflValue3 = pContext->Listener.Velocity[2];
  260. break;
  261. default:
  262. alSetError(pContext, AL_INVALID_ENUM);
  263. break;
  264. }
  265. }
  266. else
  267. alSetError(pContext, AL_INVALID_VALUE);
  268. ProcessContext(pContext);
  269. }
  270. AL_API ALvoid AL_APIENTRY alGetListenerfv(ALenum eParam, ALfloat *pflValues)
  271. {
  272. ALCcontext *pContext;
  273. pContext = GetContextSuspended();
  274. if(!pContext) return;
  275. if(pflValues)
  276. {
  277. switch(eParam)
  278. {
  279. case AL_GAIN:
  280. pflValues[0] = pContext->Listener.Gain;
  281. break;
  282. case AL_METERS_PER_UNIT:
  283. pflValues[0] = pContext->Listener.MetersPerUnit;
  284. break;
  285. case AL_POSITION:
  286. pflValues[0] = pContext->Listener.Position[0];
  287. pflValues[1] = pContext->Listener.Position[1];
  288. pflValues[2] = pContext->Listener.Position[2];
  289. break;
  290. case AL_VELOCITY:
  291. pflValues[0] = pContext->Listener.Velocity[0];
  292. pflValues[1] = pContext->Listener.Velocity[1];
  293. pflValues[2] = pContext->Listener.Velocity[2];
  294. break;
  295. case AL_ORIENTATION:
  296. // AT then UP
  297. pflValues[0] = pContext->Listener.Forward[0];
  298. pflValues[1] = pContext->Listener.Forward[1];
  299. pflValues[2] = pContext->Listener.Forward[2];
  300. pflValues[3] = pContext->Listener.Up[0];
  301. pflValues[4] = pContext->Listener.Up[1];
  302. pflValues[5] = pContext->Listener.Up[2];
  303. break;
  304. default:
  305. alSetError(pContext, AL_INVALID_ENUM);
  306. break;
  307. }
  308. }
  309. else
  310. alSetError(pContext, AL_INVALID_VALUE);
  311. ProcessContext(pContext);
  312. }
  313. AL_API ALvoid AL_APIENTRY alGetListeneri(ALenum eParam, ALint *plValue)
  314. {
  315. ALCcontext *pContext;
  316. pContext = GetContextSuspended();
  317. if(!pContext) return;
  318. if(plValue)
  319. {
  320. switch(eParam)
  321. {
  322. default:
  323. alSetError(pContext, AL_INVALID_ENUM);
  324. break;
  325. }
  326. }
  327. else
  328. alSetError(pContext, AL_INVALID_VALUE);
  329. ProcessContext(pContext);
  330. }
  331. AL_API void AL_APIENTRY alGetListener3i(ALenum eParam, ALint *plValue1, ALint *plValue2, ALint *plValue3)
  332. {
  333. ALCcontext *pContext;
  334. pContext = GetContextSuspended();
  335. if(!pContext) return;
  336. if(plValue1 && plValue2 && plValue3)
  337. {
  338. switch (eParam)
  339. {
  340. case AL_POSITION:
  341. *plValue1 = (ALint)pContext->Listener.Position[0];
  342. *plValue2 = (ALint)pContext->Listener.Position[1];
  343. *plValue3 = (ALint)pContext->Listener.Position[2];
  344. break;
  345. case AL_VELOCITY:
  346. *plValue1 = (ALint)pContext->Listener.Velocity[0];
  347. *plValue2 = (ALint)pContext->Listener.Velocity[1];
  348. *plValue3 = (ALint)pContext->Listener.Velocity[2];
  349. break;
  350. default:
  351. alSetError(pContext, AL_INVALID_ENUM);
  352. break;
  353. }
  354. }
  355. else
  356. alSetError(pContext, AL_INVALID_VALUE);
  357. ProcessContext(pContext);
  358. }
  359. AL_API void AL_APIENTRY alGetListeneriv(ALenum eParam, ALint* plValues)
  360. {
  361. ALCcontext *pContext;
  362. pContext = GetContextSuspended();
  363. if(!pContext) return;
  364. if(plValues)
  365. {
  366. switch(eParam)
  367. {
  368. case AL_POSITION:
  369. plValues[0] = (ALint)pContext->Listener.Position[0];
  370. plValues[1] = (ALint)pContext->Listener.Position[1];
  371. plValues[2] = (ALint)pContext->Listener.Position[2];
  372. break;
  373. case AL_VELOCITY:
  374. plValues[0] = (ALint)pContext->Listener.Velocity[0];
  375. plValues[1] = (ALint)pContext->Listener.Velocity[1];
  376. plValues[2] = (ALint)pContext->Listener.Velocity[2];
  377. break;
  378. case AL_ORIENTATION:
  379. // AT then UP
  380. plValues[0] = (ALint)pContext->Listener.Forward[0];
  381. plValues[1] = (ALint)pContext->Listener.Forward[1];
  382. plValues[2] = (ALint)pContext->Listener.Forward[2];
  383. plValues[3] = (ALint)pContext->Listener.Up[0];
  384. plValues[4] = (ALint)pContext->Listener.Up[1];
  385. plValues[5] = (ALint)pContext->Listener.Up[2];
  386. break;
  387. default:
  388. alSetError(pContext, AL_INVALID_ENUM);
  389. break;
  390. }
  391. }
  392. else
  393. alSetError(pContext, AL_INVALID_VALUE);
  394. ProcessContext(pContext);
  395. }