alFilter.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /**
  2. * OpenAL cross platform audio library
  3. * Copyright (C) 1999-2007 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.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. * Or go to http://www.gnu.org/copyleft/lgpl.html
  19. */
  20. #include "config.h"
  21. #include <stdlib.h>
  22. #include "alMain.h"
  23. #include "alu.h"
  24. #include "alFilter.h"
  25. #include "alThunk.h"
  26. #include "alError.h"
  27. extern inline struct ALfilter *LookupFilter(ALCdevice *device, ALuint id);
  28. extern inline struct ALfilter *RemoveFilter(ALCdevice *device, ALuint id);
  29. extern inline void ALfilterState_clear(ALfilterState *filter);
  30. extern inline void ALfilterState_processPassthru(ALfilterState *filter, const ALfloat *src, ALuint numsamples);
  31. extern inline ALfloat ALfilterState_processSingle(ALfilterState *filter, ALfloat sample);
  32. extern inline ALfloat calc_rcpQ_from_slope(ALfloat gain, ALfloat slope);
  33. extern inline ALfloat calc_rcpQ_from_bandwidth(ALfloat freq_mult, ALfloat bandwidth);
  34. static void InitFilterParams(ALfilter *filter, ALenum type);
  35. AL_API ALvoid AL_APIENTRY alGenFilters(ALsizei n, ALuint *filters)
  36. {
  37. ALCdevice *device;
  38. ALCcontext *context;
  39. ALsizei cur = 0;
  40. ALenum err;
  41. context = GetContextRef();
  42. if(!context) return;
  43. if(!(n >= 0))
  44. SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
  45. device = context->Device;
  46. for(cur = 0;cur < n;cur++)
  47. {
  48. ALfilter *filter = calloc(1, sizeof(ALfilter));
  49. if(!filter)
  50. {
  51. alDeleteFilters(cur, filters);
  52. SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
  53. }
  54. InitFilterParams(filter, AL_FILTER_NULL);
  55. err = NewThunkEntry(&filter->id);
  56. if(err == AL_NO_ERROR)
  57. err = InsertUIntMapEntry(&device->FilterMap, filter->id, filter);
  58. if(err != AL_NO_ERROR)
  59. {
  60. FreeThunkEntry(filter->id);
  61. memset(filter, 0, sizeof(ALfilter));
  62. free(filter);
  63. alDeleteFilters(cur, filters);
  64. SET_ERROR_AND_GOTO(context, err, done);
  65. }
  66. filters[cur] = filter->id;
  67. }
  68. done:
  69. ALCcontext_DecRef(context);
  70. }
  71. AL_API ALvoid AL_APIENTRY alDeleteFilters(ALsizei n, const ALuint *filters)
  72. {
  73. ALCdevice *device;
  74. ALCcontext *context;
  75. ALfilter *filter;
  76. ALsizei i;
  77. context = GetContextRef();
  78. if(!context) return;
  79. if(!(n >= 0))
  80. SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
  81. device = context->Device;
  82. for(i = 0;i < n;i++)
  83. {
  84. if(filters[i] && LookupFilter(device, filters[i]) == NULL)
  85. SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
  86. }
  87. for(i = 0;i < n;i++)
  88. {
  89. if((filter=RemoveFilter(device, filters[i])) == NULL)
  90. continue;
  91. FreeThunkEntry(filter->id);
  92. memset(filter, 0, sizeof(*filter));
  93. free(filter);
  94. }
  95. done:
  96. ALCcontext_DecRef(context);
  97. }
  98. AL_API ALboolean AL_APIENTRY alIsFilter(ALuint filter)
  99. {
  100. ALCcontext *Context;
  101. ALboolean result;
  102. Context = GetContextRef();
  103. if(!Context) return AL_FALSE;
  104. result = ((!filter || LookupFilter(Context->Device, filter)) ?
  105. AL_TRUE : AL_FALSE);
  106. ALCcontext_DecRef(Context);
  107. return result;
  108. }
  109. AL_API ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint value)
  110. {
  111. ALCcontext *Context;
  112. ALCdevice *Device;
  113. ALfilter *ALFilter;
  114. Context = GetContextRef();
  115. if(!Context) return;
  116. Device = Context->Device;
  117. if((ALFilter=LookupFilter(Device, filter)) == NULL)
  118. alSetError(Context, AL_INVALID_NAME);
  119. else
  120. {
  121. if(param == AL_FILTER_TYPE)
  122. {
  123. if(value == AL_FILTER_NULL || value == AL_FILTER_LOWPASS ||
  124. value == AL_FILTER_HIGHPASS || value == AL_FILTER_BANDPASS)
  125. InitFilterParams(ALFilter, value);
  126. else
  127. alSetError(Context, AL_INVALID_VALUE);
  128. }
  129. else
  130. {
  131. /* Call the appropriate handler */
  132. ALfilter_SetParami(ALFilter, Context, param, value);
  133. }
  134. }
  135. ALCcontext_DecRef(Context);
  136. }
  137. AL_API ALvoid AL_APIENTRY alFilteriv(ALuint filter, ALenum param, const ALint *values)
  138. {
  139. ALCcontext *Context;
  140. ALCdevice *Device;
  141. ALfilter *ALFilter;
  142. switch(param)
  143. {
  144. case AL_FILTER_TYPE:
  145. alFilteri(filter, param, values[0]);
  146. return;
  147. }
  148. Context = GetContextRef();
  149. if(!Context) return;
  150. Device = Context->Device;
  151. if((ALFilter=LookupFilter(Device, filter)) == NULL)
  152. alSetError(Context, AL_INVALID_NAME);
  153. else
  154. {
  155. /* Call the appropriate handler */
  156. ALfilter_SetParamiv(ALFilter, Context, param, values);
  157. }
  158. ALCcontext_DecRef(Context);
  159. }
  160. AL_API ALvoid AL_APIENTRY alFilterf(ALuint filter, ALenum param, ALfloat value)
  161. {
  162. ALCcontext *Context;
  163. ALCdevice *Device;
  164. ALfilter *ALFilter;
  165. Context = GetContextRef();
  166. if(!Context) return;
  167. Device = Context->Device;
  168. if((ALFilter=LookupFilter(Device, filter)) == NULL)
  169. alSetError(Context, AL_INVALID_NAME);
  170. else
  171. {
  172. /* Call the appropriate handler */
  173. ALfilter_SetParamf(ALFilter, Context, param, value);
  174. }
  175. ALCcontext_DecRef(Context);
  176. }
  177. AL_API ALvoid AL_APIENTRY alFilterfv(ALuint filter, ALenum param, const ALfloat *values)
  178. {
  179. ALCcontext *Context;
  180. ALCdevice *Device;
  181. ALfilter *ALFilter;
  182. Context = GetContextRef();
  183. if(!Context) return;
  184. Device = Context->Device;
  185. if((ALFilter=LookupFilter(Device, filter)) == NULL)
  186. alSetError(Context, AL_INVALID_NAME);
  187. else
  188. {
  189. /* Call the appropriate handler */
  190. ALfilter_SetParamfv(ALFilter, Context, param, values);
  191. }
  192. ALCcontext_DecRef(Context);
  193. }
  194. AL_API ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *value)
  195. {
  196. ALCcontext *Context;
  197. ALCdevice *Device;
  198. ALfilter *ALFilter;
  199. Context = GetContextRef();
  200. if(!Context) return;
  201. Device = Context->Device;
  202. if((ALFilter=LookupFilter(Device, filter)) == NULL)
  203. alSetError(Context, AL_INVALID_NAME);
  204. else
  205. {
  206. if(param == AL_FILTER_TYPE)
  207. *value = ALFilter->type;
  208. else
  209. {
  210. /* Call the appropriate handler */
  211. ALfilter_GetParami(ALFilter, Context, param, value);
  212. }
  213. }
  214. ALCcontext_DecRef(Context);
  215. }
  216. AL_API ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *values)
  217. {
  218. ALCcontext *Context;
  219. ALCdevice *Device;
  220. ALfilter *ALFilter;
  221. switch(param)
  222. {
  223. case AL_FILTER_TYPE:
  224. alGetFilteri(filter, param, values);
  225. return;
  226. }
  227. Context = GetContextRef();
  228. if(!Context) return;
  229. Device = Context->Device;
  230. if((ALFilter=LookupFilter(Device, filter)) == NULL)
  231. alSetError(Context, AL_INVALID_NAME);
  232. else
  233. {
  234. /* Call the appropriate handler */
  235. ALfilter_GetParamiv(ALFilter, Context, param, values);
  236. }
  237. ALCcontext_DecRef(Context);
  238. }
  239. AL_API ALvoid AL_APIENTRY alGetFilterf(ALuint filter, ALenum param, ALfloat *value)
  240. {
  241. ALCcontext *Context;
  242. ALCdevice *Device;
  243. ALfilter *ALFilter;
  244. Context = GetContextRef();
  245. if(!Context) return;
  246. Device = Context->Device;
  247. if((ALFilter=LookupFilter(Device, filter)) == NULL)
  248. alSetError(Context, AL_INVALID_NAME);
  249. else
  250. {
  251. /* Call the appropriate handler */
  252. ALfilter_GetParamf(ALFilter, Context, param, value);
  253. }
  254. ALCcontext_DecRef(Context);
  255. }
  256. AL_API ALvoid AL_APIENTRY alGetFilterfv(ALuint filter, ALenum param, ALfloat *values)
  257. {
  258. ALCcontext *Context;
  259. ALCdevice *Device;
  260. ALfilter *ALFilter;
  261. Context = GetContextRef();
  262. if(!Context) return;
  263. Device = Context->Device;
  264. if((ALFilter=LookupFilter(Device, filter)) == NULL)
  265. alSetError(Context, AL_INVALID_NAME);
  266. else
  267. {
  268. /* Call the appropriate handler */
  269. ALfilter_GetParamfv(ALFilter, Context, param, values);
  270. }
  271. ALCcontext_DecRef(Context);
  272. }
  273. void ALfilterState_setParams(ALfilterState *filter, ALfilterType type, ALfloat gain, ALfloat freq_mult, ALfloat rcpQ)
  274. {
  275. ALfloat alpha, sqrtgain_alpha_2;
  276. ALfloat w0, sin_w0, cos_w0;
  277. ALfloat a[3] = { 1.0f, 0.0f, 0.0f };
  278. ALfloat b[3] = { 1.0f, 0.0f, 0.0f };
  279. // Limit gain to -100dB
  280. gain = maxf(gain, 0.00001f);
  281. w0 = F_TAU * freq_mult;
  282. sin_w0 = sinf(w0);
  283. cos_w0 = cosf(w0);
  284. alpha = sin_w0/2.0f * rcpQ;
  285. /* Calculate filter coefficients depending on filter type */
  286. switch(type)
  287. {
  288. case ALfilterType_HighShelf:
  289. sqrtgain_alpha_2 = 2.0f * sqrtf(gain) * alpha;
  290. b[0] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2);
  291. b[1] = -2.0f*gain*((gain-1.0f) + (gain+1.0f)*cos_w0 );
  292. b[2] = gain*((gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2);
  293. a[0] = (gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2;
  294. a[1] = 2.0f* ((gain-1.0f) - (gain+1.0f)*cos_w0 );
  295. a[2] = (gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2;
  296. break;
  297. case ALfilterType_LowShelf:
  298. sqrtgain_alpha_2 = 2.0f * sqrtf(gain) * alpha;
  299. b[0] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 + sqrtgain_alpha_2);
  300. b[1] = 2.0f*gain*((gain-1.0f) - (gain+1.0f)*cos_w0 );
  301. b[2] = gain*((gain+1.0f) - (gain-1.0f)*cos_w0 - sqrtgain_alpha_2);
  302. a[0] = (gain+1.0f) + (gain-1.0f)*cos_w0 + sqrtgain_alpha_2;
  303. a[1] = -2.0f* ((gain-1.0f) + (gain+1.0f)*cos_w0 );
  304. a[2] = (gain+1.0f) + (gain-1.0f)*cos_w0 - sqrtgain_alpha_2;
  305. break;
  306. case ALfilterType_Peaking:
  307. gain = sqrtf(gain);
  308. b[0] = 1.0f + alpha * gain;
  309. b[1] = -2.0f * cos_w0;
  310. b[2] = 1.0f - alpha * gain;
  311. a[0] = 1.0f + alpha / gain;
  312. a[1] = -2.0f * cos_w0;
  313. a[2] = 1.0f - alpha / gain;
  314. break;
  315. case ALfilterType_LowPass:
  316. b[0] = (1.0f - cos_w0) / 2.0f;
  317. b[1] = 1.0f - cos_w0;
  318. b[2] = (1.0f - cos_w0) / 2.0f;
  319. a[0] = 1.0f + alpha;
  320. a[1] = -2.0f * cos_w0;
  321. a[2] = 1.0f - alpha;
  322. break;
  323. case ALfilterType_HighPass:
  324. b[0] = (1.0f + cos_w0) / 2.0f;
  325. b[1] = -(1.0f + cos_w0);
  326. b[2] = (1.0f + cos_w0) / 2.0f;
  327. a[0] = 1.0f + alpha;
  328. a[1] = -2.0f * cos_w0;
  329. a[2] = 1.0f - alpha;
  330. break;
  331. case ALfilterType_BandPass:
  332. b[0] = alpha;
  333. b[1] = 0;
  334. b[2] = -alpha;
  335. a[0] = 1.0f + alpha;
  336. a[1] = -2.0f * cos_w0;
  337. a[2] = 1.0f - alpha;
  338. break;
  339. }
  340. filter->a1 = a[1] / a[0];
  341. filter->a2 = a[2] / a[0];
  342. filter->b1 = b[1] / a[0];
  343. filter->b2 = b[2] / a[0];
  344. filter->input_gain = b[0] / a[0];
  345. filter->process = ALfilterState_processC;
  346. }
  347. static void lp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
  348. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  349. static void lp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
  350. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  351. static void lp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
  352. {
  353. switch(param)
  354. {
  355. case AL_LOWPASS_GAIN:
  356. if(!(val >= AL_LOWPASS_MIN_GAIN && val <= AL_LOWPASS_MAX_GAIN))
  357. SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
  358. filter->Gain = val;
  359. break;
  360. case AL_LOWPASS_GAINHF:
  361. if(!(val >= AL_LOWPASS_MIN_GAINHF && val <= AL_LOWPASS_MAX_GAINHF))
  362. SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
  363. filter->GainHF = val;
  364. break;
  365. default:
  366. SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
  367. }
  368. }
  369. static void lp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
  370. {
  371. lp_SetParamf(filter, context, param, vals[0]);
  372. }
  373. static void lp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
  374. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  375. static void lp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
  376. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  377. static void lp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
  378. {
  379. switch(param)
  380. {
  381. case AL_LOWPASS_GAIN:
  382. *val = filter->Gain;
  383. break;
  384. case AL_LOWPASS_GAINHF:
  385. *val = filter->GainHF;
  386. break;
  387. default:
  388. SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
  389. }
  390. }
  391. static void lp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
  392. {
  393. lp_GetParamf(filter, context, param, vals);
  394. }
  395. static void hp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
  396. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  397. static void hp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
  398. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  399. static void hp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
  400. {
  401. switch(param)
  402. {
  403. case AL_HIGHPASS_GAIN:
  404. if(!(val >= AL_HIGHPASS_MIN_GAIN && val <= AL_HIGHPASS_MAX_GAIN))
  405. SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
  406. filter->Gain = val;
  407. break;
  408. case AL_HIGHPASS_GAINLF:
  409. if(!(val >= AL_HIGHPASS_MIN_GAINLF && val <= AL_HIGHPASS_MAX_GAINLF))
  410. SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
  411. filter->GainLF = val;
  412. break;
  413. default:
  414. SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
  415. }
  416. }
  417. static void hp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
  418. {
  419. hp_SetParamf(filter, context, param, vals[0]);
  420. }
  421. static void hp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
  422. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  423. static void hp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
  424. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  425. static void hp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
  426. {
  427. switch(param)
  428. {
  429. case AL_HIGHPASS_GAIN:
  430. *val = filter->Gain;
  431. break;
  432. case AL_HIGHPASS_GAINLF:
  433. *val = filter->GainLF;
  434. break;
  435. default:
  436. SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
  437. }
  438. }
  439. static void hp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
  440. {
  441. hp_GetParamf(filter, context, param, vals);
  442. }
  443. static void bp_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
  444. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  445. static void bp_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
  446. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  447. static void bp_SetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat val)
  448. {
  449. switch(param)
  450. {
  451. case AL_BANDPASS_GAIN:
  452. if(!(val >= AL_BANDPASS_MIN_GAIN && val <= AL_BANDPASS_MAX_GAIN))
  453. SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
  454. filter->Gain = val;
  455. break;
  456. case AL_BANDPASS_GAINHF:
  457. if(!(val >= AL_BANDPASS_MIN_GAINHF && val <= AL_BANDPASS_MAX_GAINHF))
  458. SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
  459. filter->GainHF = val;
  460. break;
  461. case AL_BANDPASS_GAINLF:
  462. if(!(val >= AL_BANDPASS_MIN_GAINLF && val <= AL_BANDPASS_MAX_GAINLF))
  463. SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
  464. filter->GainLF = val;
  465. break;
  466. default:
  467. SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
  468. }
  469. }
  470. static void bp_SetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, const ALfloat *vals)
  471. {
  472. bp_SetParamf(filter, context, param, vals[0]);
  473. }
  474. static void bp_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
  475. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  476. static void bp_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
  477. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  478. static void bp_GetParamf(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *val)
  479. {
  480. switch(param)
  481. {
  482. case AL_BANDPASS_GAIN:
  483. *val = filter->Gain;
  484. break;
  485. case AL_BANDPASS_GAINHF:
  486. *val = filter->GainHF;
  487. break;
  488. case AL_BANDPASS_GAINLF:
  489. *val = filter->GainLF;
  490. break;
  491. default:
  492. SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
  493. }
  494. }
  495. static void bp_GetParamfv(ALfilter *filter, ALCcontext *context, ALenum param, ALfloat *vals)
  496. {
  497. bp_GetParamf(filter, context, param, vals);
  498. }
  499. static void null_SetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
  500. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  501. static void null_SetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALint *UNUSED(vals))
  502. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  503. static void null_SetParamf(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat UNUSED(val))
  504. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  505. static void null_SetParamfv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), const ALfloat *UNUSED(vals))
  506. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  507. static void null_GetParami(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
  508. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  509. static void null_GetParamiv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(vals))
  510. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  511. static void null_GetParamf(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat *UNUSED(val))
  512. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  513. static void null_GetParamfv(ALfilter *UNUSED(filter), ALCcontext *context, ALenum UNUSED(param), ALfloat *UNUSED(vals))
  514. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  515. ALvoid ReleaseALFilters(ALCdevice *device)
  516. {
  517. ALsizei i;
  518. for(i = 0;i < device->FilterMap.size;i++)
  519. {
  520. ALfilter *temp = device->FilterMap.array[i].value;
  521. device->FilterMap.array[i].value = NULL;
  522. // Release filter structure
  523. FreeThunkEntry(temp->id);
  524. memset(temp, 0, sizeof(ALfilter));
  525. free(temp);
  526. }
  527. }
  528. static void InitFilterParams(ALfilter *filter, ALenum type)
  529. {
  530. if(type == AL_FILTER_LOWPASS)
  531. {
  532. filter->Gain = AL_LOWPASS_DEFAULT_GAIN;
  533. filter->GainHF = AL_LOWPASS_DEFAULT_GAINHF;
  534. filter->HFReference = LOWPASSFREQREF;
  535. filter->GainLF = 1.0f;
  536. filter->LFReference = HIGHPASSFREQREF;
  537. filter->SetParami = lp_SetParami;
  538. filter->SetParamiv = lp_SetParamiv;
  539. filter->SetParamf = lp_SetParamf;
  540. filter->SetParamfv = lp_SetParamfv;
  541. filter->GetParami = lp_GetParami;
  542. filter->GetParamiv = lp_GetParamiv;
  543. filter->GetParamf = lp_GetParamf;
  544. filter->GetParamfv = lp_GetParamfv;
  545. }
  546. else if(type == AL_FILTER_HIGHPASS)
  547. {
  548. filter->Gain = AL_HIGHPASS_DEFAULT_GAIN;
  549. filter->GainHF = 1.0f;
  550. filter->HFReference = LOWPASSFREQREF;
  551. filter->GainLF = AL_HIGHPASS_DEFAULT_GAINLF;
  552. filter->LFReference = HIGHPASSFREQREF;
  553. filter->SetParami = hp_SetParami;
  554. filter->SetParamiv = hp_SetParamiv;
  555. filter->SetParamf = hp_SetParamf;
  556. filter->SetParamfv = hp_SetParamfv;
  557. filter->GetParami = hp_GetParami;
  558. filter->GetParamiv = hp_GetParamiv;
  559. filter->GetParamf = hp_GetParamf;
  560. filter->GetParamfv = hp_GetParamfv;
  561. }
  562. else if(type == AL_FILTER_BANDPASS)
  563. {
  564. filter->Gain = AL_BANDPASS_DEFAULT_GAIN;
  565. filter->GainHF = AL_BANDPASS_DEFAULT_GAINHF;
  566. filter->HFReference = LOWPASSFREQREF;
  567. filter->GainLF = AL_BANDPASS_DEFAULT_GAINLF;
  568. filter->LFReference = HIGHPASSFREQREF;
  569. filter->SetParami = bp_SetParami;
  570. filter->SetParamiv = bp_SetParamiv;
  571. filter->SetParamf = bp_SetParamf;
  572. filter->SetParamfv = bp_SetParamfv;
  573. filter->GetParami = bp_GetParami;
  574. filter->GetParamiv = bp_GetParamiv;
  575. filter->GetParamf = bp_GetParamf;
  576. filter->GetParamfv = bp_GetParamfv;
  577. }
  578. else
  579. {
  580. filter->Gain = 1.0f;
  581. filter->GainHF = 1.0f;
  582. filter->HFReference = LOWPASSFREQREF;
  583. filter->GainLF = 1.0f;
  584. filter->LFReference = HIGHPASSFREQREF;
  585. filter->SetParami = null_SetParami;
  586. filter->SetParamiv = null_SetParamiv;
  587. filter->SetParamf = null_SetParamf;
  588. filter->SetParamfv = null_SetParamfv;
  589. filter->GetParami = null_GetParami;
  590. filter->GetParamiv = null_GetParamiv;
  591. filter->GetParamf = null_GetParamf;
  592. filter->GetParamfv = null_GetParamfv;
  593. }
  594. filter->type = type;
  595. }