dedicated.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /**
  2. * OpenAL cross platform audio library
  3. * Copyright (C) 2011 by Chris Robinson.
  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 <stdlib.h>
  22. #include "alMain.h"
  23. #include "alFilter.h"
  24. #include "alAuxEffectSlot.h"
  25. #include "alError.h"
  26. #include "alu.h"
  27. typedef struct ALdedicatedState {
  28. DERIVE_FROM_TYPE(ALeffectState);
  29. ALfloat gains[MaxChannels];
  30. } ALdedicatedState;
  31. static ALvoid ALdedicatedState_Destruct(ALdedicatedState *UNUSED(state))
  32. {
  33. }
  34. static ALboolean ALdedicatedState_deviceUpdate(ALdedicatedState *UNUSED(state), ALCdevice *UNUSED(device))
  35. {
  36. return AL_TRUE;
  37. }
  38. static ALvoid ALdedicatedState_update(ALdedicatedState *state, ALCdevice *device, const ALeffectslot *Slot)
  39. {
  40. ALfloat Gain;
  41. ALsizei s;
  42. Gain = Slot->Gain * Slot->EffectProps.Dedicated.Gain;
  43. if(Slot->EffectType == AL_EFFECT_DEDICATED_DIALOGUE)
  44. ComputeAngleGains(device, atan2f(0.0f, 1.0f), 0.0f, Gain, state->gains);
  45. else if(Slot->EffectType == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT)
  46. {
  47. for(s = 0;s < MaxChannels;s++)
  48. state->gains[s] = 0.0f;
  49. state->gains[LFE] = Gain;
  50. }
  51. }
  52. static ALvoid ALdedicatedState_process(ALdedicatedState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE])
  53. {
  54. const ALfloat *gains = state->gains;
  55. ALuint i, c;
  56. for(c = 0;c < MaxChannels;c++)
  57. {
  58. if(!(gains[c] > GAIN_SILENCE_THRESHOLD))
  59. continue;
  60. for(i = 0;i < SamplesToDo;i++)
  61. SamplesOut[c][i] = SamplesIn[i] * gains[c];
  62. }
  63. }
  64. static void ALdedicatedState_Delete(ALdedicatedState *state)
  65. {
  66. free(state);
  67. }
  68. DEFINE_ALEFFECTSTATE_VTABLE(ALdedicatedState);
  69. typedef struct ALdedicatedStateFactory {
  70. DERIVE_FROM_TYPE(ALeffectStateFactory);
  71. } ALdedicatedStateFactory;
  72. ALeffectState *ALdedicatedStateFactory_create(ALdedicatedStateFactory *UNUSED(factory))
  73. {
  74. ALdedicatedState *state;
  75. ALsizei s;
  76. state = malloc(sizeof(*state));
  77. if(!state) return NULL;
  78. SET_VTABLE2(ALdedicatedState, ALeffectState, state);
  79. for(s = 0;s < MaxChannels;s++)
  80. state->gains[s] = 0.0f;
  81. return STATIC_CAST(ALeffectState, state);
  82. }
  83. DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALdedicatedStateFactory);
  84. ALeffectStateFactory *ALdedicatedStateFactory_getFactory(void)
  85. {
  86. static ALdedicatedStateFactory DedicatedFactory = { { GET_VTABLE2(ALdedicatedStateFactory, ALeffectStateFactory) } };
  87. return STATIC_CAST(ALeffectStateFactory, &DedicatedFactory);
  88. }
  89. void ALdedicated_setParami(ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALint UNUSED(val))
  90. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  91. void ALdedicated_setParamiv(ALeffect *effect, ALCcontext *context, ALenum param, const ALint *vals)
  92. {
  93. ALdedicated_setParami(effect, context, param, vals[0]);
  94. }
  95. void ALdedicated_setParamf(ALeffect *effect, ALCcontext *context, ALenum param, ALfloat val)
  96. {
  97. ALeffectProps *props = &effect->Props;
  98. switch(param)
  99. {
  100. case AL_DEDICATED_GAIN:
  101. if(!(val >= 0.0f && isfinite(val)))
  102. SET_ERROR_AND_RETURN(context, AL_INVALID_VALUE);
  103. props->Dedicated.Gain = val;
  104. break;
  105. default:
  106. SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
  107. }
  108. }
  109. void ALdedicated_setParamfv(ALeffect *effect, ALCcontext *context, ALenum param, const ALfloat *vals)
  110. {
  111. ALdedicated_setParamf(effect, context, param, vals[0]);
  112. }
  113. void ALdedicated_getParami(const ALeffect *UNUSED(effect), ALCcontext *context, ALenum UNUSED(param), ALint *UNUSED(val))
  114. { SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM); }
  115. void ALdedicated_getParamiv(const ALeffect *effect, ALCcontext *context, ALenum param, ALint *vals)
  116. {
  117. ALdedicated_getParami(effect, context, param, vals);
  118. }
  119. void ALdedicated_getParamf(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *val)
  120. {
  121. const ALeffectProps *props = &effect->Props;
  122. switch(param)
  123. {
  124. case AL_DEDICATED_GAIN:
  125. *val = props->Dedicated.Gain;
  126. break;
  127. default:
  128. SET_ERROR_AND_RETURN(context, AL_INVALID_ENUM);
  129. }
  130. }
  131. void ALdedicated_getParamfv(const ALeffect *effect, ALCcontext *context, ALenum param, ALfloat *vals)
  132. {
  133. ALdedicated_getParamf(effect, context, param, vals);
  134. }
  135. DEFINE_ALEFFECT_VTABLE(ALdedicated);