effect.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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 "effect.h"
  22. #include <algorithm>
  23. #include <cstdint>
  24. #include <cstring>
  25. #include <iterator>
  26. #include <memory>
  27. #include <mutex>
  28. #include <new>
  29. #include <numeric>
  30. #include <utility>
  31. #include "AL/al.h"
  32. #include "AL/alc.h"
  33. #include "AL/alext.h"
  34. #include "AL/efx-presets.h"
  35. #include "AL/efx.h"
  36. #include "albit.h"
  37. #include "alcmain.h"
  38. #include "alcontext.h"
  39. #include "almalloc.h"
  40. #include "alnumeric.h"
  41. #include "alstring.h"
  42. #include "core/except.h"
  43. #include "core/logging.h"
  44. #include "effects/base.h"
  45. #include "opthelpers.h"
  46. #include "vector.h"
  47. const EffectList gEffectList[16]{
  48. { "eaxreverb", EAXREVERB_EFFECT, AL_EFFECT_EAXREVERB },
  49. { "reverb", REVERB_EFFECT, AL_EFFECT_REVERB },
  50. { "autowah", AUTOWAH_EFFECT, AL_EFFECT_AUTOWAH },
  51. { "chorus", CHORUS_EFFECT, AL_EFFECT_CHORUS },
  52. { "compressor", COMPRESSOR_EFFECT, AL_EFFECT_COMPRESSOR },
  53. { "distortion", DISTORTION_EFFECT, AL_EFFECT_DISTORTION },
  54. { "echo", ECHO_EFFECT, AL_EFFECT_ECHO },
  55. { "equalizer", EQUALIZER_EFFECT, AL_EFFECT_EQUALIZER },
  56. { "flanger", FLANGER_EFFECT, AL_EFFECT_FLANGER },
  57. { "fshifter", FSHIFTER_EFFECT, AL_EFFECT_FREQUENCY_SHIFTER },
  58. { "modulator", MODULATOR_EFFECT, AL_EFFECT_RING_MODULATOR },
  59. { "pshifter", PSHIFTER_EFFECT, AL_EFFECT_PITCH_SHIFTER },
  60. { "vmorpher", VMORPHER_EFFECT, AL_EFFECT_VOCAL_MORPHER },
  61. { "dedicated", DEDICATED_EFFECT, AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT },
  62. { "dedicated", DEDICATED_EFFECT, AL_EFFECT_DEDICATED_DIALOGUE },
  63. { "convolution", CONVOLUTION_EFFECT, AL_EFFECT_CONVOLUTION_REVERB_SOFT },
  64. };
  65. bool DisabledEffects[MAX_EFFECTS];
  66. effect_exception::effect_exception(ALenum code, const char *msg, ...) : mErrorCode{code}
  67. {
  68. std::va_list args;
  69. va_start(args, msg);
  70. setMessage(msg, args);
  71. va_end(args);
  72. }
  73. namespace {
  74. struct EffectPropsItem {
  75. ALenum Type;
  76. const EffectProps &DefaultProps;
  77. const EffectVtable &Vtable;
  78. };
  79. constexpr EffectPropsItem EffectPropsList[] = {
  80. { AL_EFFECT_NULL, NullEffectProps, NullEffectVtable },
  81. { AL_EFFECT_EAXREVERB, ReverbEffectProps, ReverbEffectVtable },
  82. { AL_EFFECT_REVERB, StdReverbEffectProps, StdReverbEffectVtable },
  83. { AL_EFFECT_AUTOWAH, AutowahEffectProps, AutowahEffectVtable },
  84. { AL_EFFECT_CHORUS, ChorusEffectProps, ChorusEffectVtable },
  85. { AL_EFFECT_COMPRESSOR, CompressorEffectProps, CompressorEffectVtable },
  86. { AL_EFFECT_DISTORTION, DistortionEffectProps, DistortionEffectVtable },
  87. { AL_EFFECT_ECHO, EchoEffectProps, EchoEffectVtable },
  88. { AL_EFFECT_EQUALIZER, EqualizerEffectProps, EqualizerEffectVtable },
  89. { AL_EFFECT_FLANGER, FlangerEffectProps, FlangerEffectVtable },
  90. { AL_EFFECT_FREQUENCY_SHIFTER, FshifterEffectProps, FshifterEffectVtable },
  91. { AL_EFFECT_RING_MODULATOR, ModulatorEffectProps, ModulatorEffectVtable },
  92. { AL_EFFECT_PITCH_SHIFTER, PshifterEffectProps, PshifterEffectVtable },
  93. { AL_EFFECT_VOCAL_MORPHER, VmorpherEffectProps, VmorpherEffectVtable },
  94. { AL_EFFECT_DEDICATED_DIALOGUE, DedicatedEffectProps, DedicatedEffectVtable },
  95. { AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT, DedicatedEffectProps, DedicatedEffectVtable },
  96. { AL_EFFECT_CONVOLUTION_REVERB_SOFT, ConvolutionEffectProps, ConvolutionEffectVtable },
  97. };
  98. void ALeffect_setParami(ALeffect *effect, ALenum param, int value)
  99. { effect->vtab->setParami(&effect->Props, param, value); }
  100. void ALeffect_setParamiv(ALeffect *effect, ALenum param, const int *values)
  101. { effect->vtab->setParamiv(&effect->Props, param, values); }
  102. void ALeffect_setParamf(ALeffect *effect, ALenum param, float value)
  103. { effect->vtab->setParamf(&effect->Props, param, value); }
  104. void ALeffect_setParamfv(ALeffect *effect, ALenum param, const float *values)
  105. { effect->vtab->setParamfv(&effect->Props, param, values); }
  106. void ALeffect_getParami(const ALeffect *effect, ALenum param, int *value)
  107. { effect->vtab->getParami(&effect->Props, param, value); }
  108. void ALeffect_getParamiv(const ALeffect *effect, ALenum param, int *values)
  109. { effect->vtab->getParamiv(&effect->Props, param, values); }
  110. void ALeffect_getParamf(const ALeffect *effect, ALenum param, float *value)
  111. { effect->vtab->getParamf(&effect->Props, param, value); }
  112. void ALeffect_getParamfv(const ALeffect *effect, ALenum param, float *values)
  113. { effect->vtab->getParamfv(&effect->Props, param, values); }
  114. const EffectPropsItem *getEffectPropsItemByType(ALenum type)
  115. {
  116. auto iter = std::find_if(std::begin(EffectPropsList), std::end(EffectPropsList),
  117. [type](const EffectPropsItem &item) noexcept -> bool
  118. { return item.Type == type; });
  119. return (iter != std::end(EffectPropsList)) ? std::addressof(*iter) : nullptr;
  120. }
  121. void InitEffectParams(ALeffect *effect, ALenum type)
  122. {
  123. const EffectPropsItem *item{getEffectPropsItemByType(type)};
  124. if(item)
  125. {
  126. effect->Props = item->DefaultProps;
  127. effect->vtab = &item->Vtable;
  128. }
  129. else
  130. {
  131. effect->Props = EffectProps{};
  132. effect->vtab = &NullEffectVtable;
  133. }
  134. effect->type = type;
  135. }
  136. bool EnsureEffects(ALCdevice *device, size_t needed)
  137. {
  138. size_t count{std::accumulate(device->EffectList.cbegin(), device->EffectList.cend(), size_t{0},
  139. [](size_t cur, const EffectSubList &sublist) noexcept -> size_t
  140. { return cur + static_cast<ALuint>(al::popcount(sublist.FreeMask)); })};
  141. while(needed > count)
  142. {
  143. if UNLIKELY(device->EffectList.size() >= 1<<25)
  144. return false;
  145. device->EffectList.emplace_back();
  146. auto sublist = device->EffectList.end() - 1;
  147. sublist->FreeMask = ~0_u64;
  148. sublist->Effects = static_cast<ALeffect*>(al_calloc(alignof(ALeffect), sizeof(ALeffect)*64));
  149. if UNLIKELY(!sublist->Effects)
  150. {
  151. device->EffectList.pop_back();
  152. return false;
  153. }
  154. count += 64;
  155. }
  156. return true;
  157. }
  158. ALeffect *AllocEffect(ALCdevice *device)
  159. {
  160. auto sublist = std::find_if(device->EffectList.begin(), device->EffectList.end(),
  161. [](const EffectSubList &entry) noexcept -> bool
  162. { return entry.FreeMask != 0; }
  163. );
  164. auto lidx = static_cast<ALuint>(std::distance(device->EffectList.begin(), sublist));
  165. auto slidx = static_cast<ALuint>(al::countr_zero(sublist->FreeMask));
  166. ALeffect *effect{::new (sublist->Effects + slidx) ALeffect{}};
  167. InitEffectParams(effect, AL_EFFECT_NULL);
  168. /* Add 1 to avoid effect ID 0. */
  169. effect->id = ((lidx<<6) | slidx) + 1;
  170. sublist->FreeMask &= ~(1_u64 << slidx);
  171. return effect;
  172. }
  173. void FreeEffect(ALCdevice *device, ALeffect *effect)
  174. {
  175. const ALuint id{effect->id - 1};
  176. const size_t lidx{id >> 6};
  177. const ALuint slidx{id & 0x3f};
  178. al::destroy_at(effect);
  179. device->EffectList[lidx].FreeMask |= 1_u64 << slidx;
  180. }
  181. inline ALeffect *LookupEffect(ALCdevice *device, ALuint id)
  182. {
  183. const size_t lidx{(id-1) >> 6};
  184. const ALuint slidx{(id-1) & 0x3f};
  185. if UNLIKELY(lidx >= device->EffectList.size())
  186. return nullptr;
  187. EffectSubList &sublist = device->EffectList[lidx];
  188. if UNLIKELY(sublist.FreeMask & (1_u64 << slidx))
  189. return nullptr;
  190. return sublist.Effects + slidx;
  191. }
  192. } // namespace
  193. AL_API void AL_APIENTRY alGenEffects(ALsizei n, ALuint *effects)
  194. START_API_FUNC
  195. {
  196. ContextRef context{GetContextRef()};
  197. if UNLIKELY(!context) return;
  198. if UNLIKELY(n < 0)
  199. context->setError(AL_INVALID_VALUE, "Generating %d effects", n);
  200. if UNLIKELY(n <= 0) return;
  201. ALCdevice *device{context->mDevice.get()};
  202. std::lock_guard<std::mutex> _{device->EffectLock};
  203. if(!EnsureEffects(device, static_cast<ALuint>(n)))
  204. {
  205. context->setError(AL_OUT_OF_MEMORY, "Failed to allocate %d effect%s", n, (n==1)?"":"s");
  206. return;
  207. }
  208. if LIKELY(n == 1)
  209. {
  210. /* Special handling for the easy and normal case. */
  211. ALeffect *effect{AllocEffect(device)};
  212. effects[0] = effect->id;
  213. }
  214. else
  215. {
  216. /* Store the allocated buffer IDs in a separate local list, to avoid
  217. * modifying the user storage in case of failure.
  218. */
  219. al::vector<ALuint> ids;
  220. ids.reserve(static_cast<ALuint>(n));
  221. do {
  222. ALeffect *effect{AllocEffect(device)};
  223. ids.emplace_back(effect->id);
  224. } while(--n);
  225. std::copy(ids.cbegin(), ids.cend(), effects);
  226. }
  227. }
  228. END_API_FUNC
  229. AL_API void AL_APIENTRY alDeleteEffects(ALsizei n, const ALuint *effects)
  230. START_API_FUNC
  231. {
  232. ContextRef context{GetContextRef()};
  233. if UNLIKELY(!context) return;
  234. if UNLIKELY(n < 0)
  235. context->setError(AL_INVALID_VALUE, "Deleting %d effects", n);
  236. if UNLIKELY(n <= 0) return;
  237. ALCdevice *device{context->mDevice.get()};
  238. std::lock_guard<std::mutex> _{device->EffectLock};
  239. /* First try to find any effects that are invalid. */
  240. auto validate_effect = [device](const ALuint eid) -> bool
  241. { return !eid || LookupEffect(device, eid) != nullptr; };
  242. const ALuint *effects_end = effects + n;
  243. auto inveffect = std::find_if_not(effects, effects_end, validate_effect);
  244. if UNLIKELY(inveffect != effects_end)
  245. {
  246. context->setError(AL_INVALID_NAME, "Invalid effect ID %u", *inveffect);
  247. return;
  248. }
  249. /* All good. Delete non-0 effect IDs. */
  250. auto delete_effect = [device](ALuint eid) -> void
  251. {
  252. ALeffect *effect{eid ? LookupEffect(device, eid) : nullptr};
  253. if(effect) FreeEffect(device, effect);
  254. };
  255. std::for_each(effects, effects_end, delete_effect);
  256. }
  257. END_API_FUNC
  258. AL_API ALboolean AL_APIENTRY alIsEffect(ALuint effect)
  259. START_API_FUNC
  260. {
  261. ContextRef context{GetContextRef()};
  262. if LIKELY(context)
  263. {
  264. ALCdevice *device{context->mDevice.get()};
  265. std::lock_guard<std::mutex> _{device->EffectLock};
  266. if(!effect || LookupEffect(device, effect))
  267. return AL_TRUE;
  268. }
  269. return AL_FALSE;
  270. }
  271. END_API_FUNC
  272. AL_API void AL_APIENTRY alEffecti(ALuint effect, ALenum param, ALint value)
  273. START_API_FUNC
  274. {
  275. ContextRef context{GetContextRef()};
  276. if UNLIKELY(!context) return;
  277. ALCdevice *device{context->mDevice.get()};
  278. std::lock_guard<std::mutex> _{device->EffectLock};
  279. ALeffect *aleffect{LookupEffect(device, effect)};
  280. if UNLIKELY(!aleffect)
  281. context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
  282. else if(param == AL_EFFECT_TYPE)
  283. {
  284. bool isOk{value == AL_EFFECT_NULL};
  285. if(!isOk)
  286. {
  287. for(const EffectList &effectitem : gEffectList)
  288. {
  289. if(value == effectitem.val && !DisabledEffects[effectitem.type])
  290. {
  291. isOk = true;
  292. break;
  293. }
  294. }
  295. }
  296. if(isOk)
  297. InitEffectParams(aleffect, value);
  298. else
  299. context->setError(AL_INVALID_VALUE, "Effect type 0x%04x not supported", value);
  300. }
  301. else try
  302. {
  303. /* Call the appropriate handler */
  304. ALeffect_setParami(aleffect, param, value);
  305. }
  306. catch(effect_exception &e) {
  307. context->setError(e.errorCode(), "%s", e.what());
  308. }
  309. }
  310. END_API_FUNC
  311. AL_API void AL_APIENTRY alEffectiv(ALuint effect, ALenum param, const ALint *values)
  312. START_API_FUNC
  313. {
  314. switch(param)
  315. {
  316. case AL_EFFECT_TYPE:
  317. alEffecti(effect, param, values[0]);
  318. return;
  319. }
  320. ContextRef context{GetContextRef()};
  321. if UNLIKELY(!context) return;
  322. ALCdevice *device{context->mDevice.get()};
  323. std::lock_guard<std::mutex> _{device->EffectLock};
  324. ALeffect *aleffect{LookupEffect(device, effect)};
  325. if UNLIKELY(!aleffect)
  326. context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
  327. else try
  328. {
  329. /* Call the appropriate handler */
  330. ALeffect_setParamiv(aleffect, param, values);
  331. }
  332. catch(effect_exception &e) {
  333. context->setError(e.errorCode(), "%s", e.what());
  334. }
  335. }
  336. END_API_FUNC
  337. AL_API void AL_APIENTRY alEffectf(ALuint effect, ALenum param, ALfloat value)
  338. START_API_FUNC
  339. {
  340. ContextRef context{GetContextRef()};
  341. if UNLIKELY(!context) return;
  342. ALCdevice *device{context->mDevice.get()};
  343. std::lock_guard<std::mutex> _{device->EffectLock};
  344. ALeffect *aleffect{LookupEffect(device, effect)};
  345. if UNLIKELY(!aleffect)
  346. context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
  347. else try
  348. {
  349. /* Call the appropriate handler */
  350. ALeffect_setParamf(aleffect, param, value);
  351. }
  352. catch(effect_exception &e) {
  353. context->setError(e.errorCode(), "%s", e.what());
  354. }
  355. }
  356. END_API_FUNC
  357. AL_API void AL_APIENTRY alEffectfv(ALuint effect, ALenum param, const ALfloat *values)
  358. START_API_FUNC
  359. {
  360. ContextRef context{GetContextRef()};
  361. if UNLIKELY(!context) return;
  362. ALCdevice *device{context->mDevice.get()};
  363. std::lock_guard<std::mutex> _{device->EffectLock};
  364. ALeffect *aleffect{LookupEffect(device, effect)};
  365. if UNLIKELY(!aleffect)
  366. context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
  367. else try
  368. {
  369. /* Call the appropriate handler */
  370. ALeffect_setParamfv(aleffect, param, values);
  371. }
  372. catch(effect_exception &e) {
  373. context->setError(e.errorCode(), "%s", e.what());
  374. }
  375. }
  376. END_API_FUNC
  377. AL_API void AL_APIENTRY alGetEffecti(ALuint effect, ALenum param, ALint *value)
  378. START_API_FUNC
  379. {
  380. ContextRef context{GetContextRef()};
  381. if UNLIKELY(!context) return;
  382. ALCdevice *device{context->mDevice.get()};
  383. std::lock_guard<std::mutex> _{device->EffectLock};
  384. const ALeffect *aleffect{LookupEffect(device, effect)};
  385. if UNLIKELY(!aleffect)
  386. context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
  387. else if(param == AL_EFFECT_TYPE)
  388. *value = aleffect->type;
  389. else try
  390. {
  391. /* Call the appropriate handler */
  392. ALeffect_getParami(aleffect, param, value);
  393. }
  394. catch(effect_exception &e) {
  395. context->setError(e.errorCode(), "%s", e.what());
  396. }
  397. }
  398. END_API_FUNC
  399. AL_API void AL_APIENTRY alGetEffectiv(ALuint effect, ALenum param, ALint *values)
  400. START_API_FUNC
  401. {
  402. switch(param)
  403. {
  404. case AL_EFFECT_TYPE:
  405. alGetEffecti(effect, param, values);
  406. return;
  407. }
  408. ContextRef context{GetContextRef()};
  409. if UNLIKELY(!context) return;
  410. ALCdevice *device{context->mDevice.get()};
  411. std::lock_guard<std::mutex> _{device->EffectLock};
  412. const ALeffect *aleffect{LookupEffect(device, effect)};
  413. if UNLIKELY(!aleffect)
  414. context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
  415. else try
  416. {
  417. /* Call the appropriate handler */
  418. ALeffect_getParamiv(aleffect, param, values);
  419. }
  420. catch(effect_exception &e) {
  421. context->setError(e.errorCode(), "%s", e.what());
  422. }
  423. }
  424. END_API_FUNC
  425. AL_API void AL_APIENTRY alGetEffectf(ALuint effect, ALenum param, ALfloat *value)
  426. START_API_FUNC
  427. {
  428. ContextRef context{GetContextRef()};
  429. if UNLIKELY(!context) return;
  430. ALCdevice *device{context->mDevice.get()};
  431. std::lock_guard<std::mutex> _{device->EffectLock};
  432. const ALeffect *aleffect{LookupEffect(device, effect)};
  433. if UNLIKELY(!aleffect)
  434. context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
  435. else try
  436. {
  437. /* Call the appropriate handler */
  438. ALeffect_getParamf(aleffect, param, value);
  439. }
  440. catch(effect_exception &e) {
  441. context->setError(e.errorCode(), "%s", e.what());
  442. }
  443. }
  444. END_API_FUNC
  445. AL_API void AL_APIENTRY alGetEffectfv(ALuint effect, ALenum param, ALfloat *values)
  446. START_API_FUNC
  447. {
  448. ContextRef context{GetContextRef()};
  449. if UNLIKELY(!context) return;
  450. ALCdevice *device{context->mDevice.get()};
  451. std::lock_guard<std::mutex> _{device->EffectLock};
  452. const ALeffect *aleffect{LookupEffect(device, effect)};
  453. if UNLIKELY(!aleffect)
  454. context->setError(AL_INVALID_NAME, "Invalid effect ID %u", effect);
  455. else try
  456. {
  457. /* Call the appropriate handler */
  458. ALeffect_getParamfv(aleffect, param, values);
  459. }
  460. catch(effect_exception &e) {
  461. context->setError(e.errorCode(), "%s", e.what());
  462. }
  463. }
  464. END_API_FUNC
  465. void InitEffect(ALeffect *effect)
  466. {
  467. InitEffectParams(effect, AL_EFFECT_NULL);
  468. }
  469. EffectSubList::~EffectSubList()
  470. {
  471. uint64_t usemask{~FreeMask};
  472. while(usemask)
  473. {
  474. const int idx{al::countr_zero(usemask)};
  475. al::destroy_at(Effects+idx);
  476. usemask &= ~(1_u64 << idx);
  477. }
  478. FreeMask = ~usemask;
  479. al_free(Effects);
  480. Effects = nullptr;
  481. }
  482. #define DECL(x) { #x, EFX_REVERB_PRESET_##x }
  483. static const struct {
  484. const char name[32];
  485. EFXEAXREVERBPROPERTIES props;
  486. } reverblist[] = {
  487. DECL(GENERIC),
  488. DECL(PADDEDCELL),
  489. DECL(ROOM),
  490. DECL(BATHROOM),
  491. DECL(LIVINGROOM),
  492. DECL(STONEROOM),
  493. DECL(AUDITORIUM),
  494. DECL(CONCERTHALL),
  495. DECL(CAVE),
  496. DECL(ARENA),
  497. DECL(HANGAR),
  498. DECL(CARPETEDHALLWAY),
  499. DECL(HALLWAY),
  500. DECL(STONECORRIDOR),
  501. DECL(ALLEY),
  502. DECL(FOREST),
  503. DECL(CITY),
  504. DECL(MOUNTAINS),
  505. DECL(QUARRY),
  506. DECL(PLAIN),
  507. DECL(PARKINGLOT),
  508. DECL(SEWERPIPE),
  509. DECL(UNDERWATER),
  510. DECL(DRUGGED),
  511. DECL(DIZZY),
  512. DECL(PSYCHOTIC),
  513. DECL(CASTLE_SMALLROOM),
  514. DECL(CASTLE_SHORTPASSAGE),
  515. DECL(CASTLE_MEDIUMROOM),
  516. DECL(CASTLE_LARGEROOM),
  517. DECL(CASTLE_LONGPASSAGE),
  518. DECL(CASTLE_HALL),
  519. DECL(CASTLE_CUPBOARD),
  520. DECL(CASTLE_COURTYARD),
  521. DECL(CASTLE_ALCOVE),
  522. DECL(FACTORY_SMALLROOM),
  523. DECL(FACTORY_SHORTPASSAGE),
  524. DECL(FACTORY_MEDIUMROOM),
  525. DECL(FACTORY_LARGEROOM),
  526. DECL(FACTORY_LONGPASSAGE),
  527. DECL(FACTORY_HALL),
  528. DECL(FACTORY_CUPBOARD),
  529. DECL(FACTORY_COURTYARD),
  530. DECL(FACTORY_ALCOVE),
  531. DECL(ICEPALACE_SMALLROOM),
  532. DECL(ICEPALACE_SHORTPASSAGE),
  533. DECL(ICEPALACE_MEDIUMROOM),
  534. DECL(ICEPALACE_LARGEROOM),
  535. DECL(ICEPALACE_LONGPASSAGE),
  536. DECL(ICEPALACE_HALL),
  537. DECL(ICEPALACE_CUPBOARD),
  538. DECL(ICEPALACE_COURTYARD),
  539. DECL(ICEPALACE_ALCOVE),
  540. DECL(SPACESTATION_SMALLROOM),
  541. DECL(SPACESTATION_SHORTPASSAGE),
  542. DECL(SPACESTATION_MEDIUMROOM),
  543. DECL(SPACESTATION_LARGEROOM),
  544. DECL(SPACESTATION_LONGPASSAGE),
  545. DECL(SPACESTATION_HALL),
  546. DECL(SPACESTATION_CUPBOARD),
  547. DECL(SPACESTATION_ALCOVE),
  548. DECL(WOODEN_SMALLROOM),
  549. DECL(WOODEN_SHORTPASSAGE),
  550. DECL(WOODEN_MEDIUMROOM),
  551. DECL(WOODEN_LARGEROOM),
  552. DECL(WOODEN_LONGPASSAGE),
  553. DECL(WOODEN_HALL),
  554. DECL(WOODEN_CUPBOARD),
  555. DECL(WOODEN_COURTYARD),
  556. DECL(WOODEN_ALCOVE),
  557. DECL(SPORT_EMPTYSTADIUM),
  558. DECL(SPORT_SQUASHCOURT),
  559. DECL(SPORT_SMALLSWIMMINGPOOL),
  560. DECL(SPORT_LARGESWIMMINGPOOL),
  561. DECL(SPORT_GYMNASIUM),
  562. DECL(SPORT_FULLSTADIUM),
  563. DECL(SPORT_STADIUMTANNOY),
  564. DECL(PREFAB_WORKSHOP),
  565. DECL(PREFAB_SCHOOLROOM),
  566. DECL(PREFAB_PRACTISEROOM),
  567. DECL(PREFAB_OUTHOUSE),
  568. DECL(PREFAB_CARAVAN),
  569. DECL(DOME_TOMB),
  570. DECL(PIPE_SMALL),
  571. DECL(DOME_SAINTPAULS),
  572. DECL(PIPE_LONGTHIN),
  573. DECL(PIPE_LARGE),
  574. DECL(PIPE_RESONANT),
  575. DECL(OUTDOORS_BACKYARD),
  576. DECL(OUTDOORS_ROLLINGPLAINS),
  577. DECL(OUTDOORS_DEEPCANYON),
  578. DECL(OUTDOORS_CREEK),
  579. DECL(OUTDOORS_VALLEY),
  580. DECL(MOOD_HEAVEN),
  581. DECL(MOOD_HELL),
  582. DECL(MOOD_MEMORY),
  583. DECL(DRIVING_COMMENTATOR),
  584. DECL(DRIVING_PITGARAGE),
  585. DECL(DRIVING_INCAR_RACER),
  586. DECL(DRIVING_INCAR_SPORTS),
  587. DECL(DRIVING_INCAR_LUXURY),
  588. DECL(DRIVING_FULLGRANDSTAND),
  589. DECL(DRIVING_EMPTYGRANDSTAND),
  590. DECL(DRIVING_TUNNEL),
  591. DECL(CITY_STREETS),
  592. DECL(CITY_SUBWAY),
  593. DECL(CITY_MUSEUM),
  594. DECL(CITY_LIBRARY),
  595. DECL(CITY_UNDERPASS),
  596. DECL(CITY_ABANDONED),
  597. DECL(DUSTYROOM),
  598. DECL(CHAPEL),
  599. DECL(SMALLWATERROOM),
  600. };
  601. #undef DECL
  602. void LoadReverbPreset(const char *name, ALeffect *effect)
  603. {
  604. if(al::strcasecmp(name, "NONE") == 0)
  605. {
  606. InitEffectParams(effect, AL_EFFECT_NULL);
  607. TRACE("Loading reverb '%s'\n", "NONE");
  608. return;
  609. }
  610. if(!DisabledEffects[EAXREVERB_EFFECT])
  611. InitEffectParams(effect, AL_EFFECT_EAXREVERB);
  612. else if(!DisabledEffects[REVERB_EFFECT])
  613. InitEffectParams(effect, AL_EFFECT_REVERB);
  614. else
  615. InitEffectParams(effect, AL_EFFECT_NULL);
  616. for(const auto &reverbitem : reverblist)
  617. {
  618. const EFXEAXREVERBPROPERTIES *props;
  619. if(al::strcasecmp(name, reverbitem.name) != 0)
  620. continue;
  621. TRACE("Loading reverb '%s'\n", reverbitem.name);
  622. props = &reverbitem.props;
  623. effect->Props.Reverb.Density = props->flDensity;
  624. effect->Props.Reverb.Diffusion = props->flDiffusion;
  625. effect->Props.Reverb.Gain = props->flGain;
  626. effect->Props.Reverb.GainHF = props->flGainHF;
  627. effect->Props.Reverb.GainLF = props->flGainLF;
  628. effect->Props.Reverb.DecayTime = props->flDecayTime;
  629. effect->Props.Reverb.DecayHFRatio = props->flDecayHFRatio;
  630. effect->Props.Reverb.DecayLFRatio = props->flDecayLFRatio;
  631. effect->Props.Reverb.ReflectionsGain = props->flReflectionsGain;
  632. effect->Props.Reverb.ReflectionsDelay = props->flReflectionsDelay;
  633. effect->Props.Reverb.ReflectionsPan[0] = props->flReflectionsPan[0];
  634. effect->Props.Reverb.ReflectionsPan[1] = props->flReflectionsPan[1];
  635. effect->Props.Reverb.ReflectionsPan[2] = props->flReflectionsPan[2];
  636. effect->Props.Reverb.LateReverbGain = props->flLateReverbGain;
  637. effect->Props.Reverb.LateReverbDelay = props->flLateReverbDelay;
  638. effect->Props.Reverb.LateReverbPan[0] = props->flLateReverbPan[0];
  639. effect->Props.Reverb.LateReverbPan[1] = props->flLateReverbPan[1];
  640. effect->Props.Reverb.LateReverbPan[2] = props->flLateReverbPan[2];
  641. effect->Props.Reverb.EchoTime = props->flEchoTime;
  642. effect->Props.Reverb.EchoDepth = props->flEchoDepth;
  643. effect->Props.Reverb.ModulationTime = props->flModulationTime;
  644. effect->Props.Reverb.ModulationDepth = props->flModulationDepth;
  645. effect->Props.Reverb.AirAbsorptionGainHF = props->flAirAbsorptionGainHF;
  646. effect->Props.Reverb.HFReference = props->flHFReference;
  647. effect->Props.Reverb.LFReference = props->flLFReference;
  648. effect->Props.Reverb.RoomRolloffFactor = props->flRoomRolloffFactor;
  649. effect->Props.Reverb.DecayHFLimit = props->iDecayHFLimit ? AL_TRUE : AL_FALSE;
  650. return;
  651. }
  652. WARN("Reverb preset '%s' not found\n", name);
  653. }