alcDedicated.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. // Must be first in all effects!
  29. ALeffectState state;
  30. ALfloat gains[MAXCHANNELS];
  31. } ALdedicatedState;
  32. static ALvoid DedicatedDestroy(ALeffectState *effect)
  33. {
  34. ALdedicatedState *state = (ALdedicatedState*)effect;
  35. free(state);
  36. }
  37. static ALboolean DedicatedDeviceUpdate(ALeffectState *effect, ALCdevice *Device)
  38. {
  39. (void)effect;
  40. (void)Device;
  41. return AL_TRUE;
  42. }
  43. static ALvoid DedicatedUpdate(ALeffectState *effect, ALCdevice *device, const ALeffectslot *Slot)
  44. {
  45. ALdedicatedState *state = (ALdedicatedState*)effect;
  46. const ALfloat *ChannelGain;
  47. ALfloat Gain;
  48. ALint pos;
  49. ALsizei s;
  50. Gain = Slot->Gain * Slot->effect.Dedicated.Gain;
  51. for(s = 0;s < MAXCHANNELS;s++)
  52. state->gains[s] = 0.0f;
  53. if(Slot->effect.type == AL_EFFECT_DEDICATED_DIALOGUE)
  54. {
  55. pos = aluCart2LUTpos(1.0f, 0.0f);
  56. ChannelGain = device->PanningLUT[pos];
  57. for(s = 0;s < MAXCHANNELS;s++)
  58. state->gains[s] = ChannelGain[s] * Gain;
  59. }
  60. else if(Slot->effect.type == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT)
  61. state->gains[LFE] = Gain;
  62. }
  63. static ALvoid DedicatedProcess(ALeffectState *effect, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[MAXCHANNELS])
  64. {
  65. ALdedicatedState *state = (ALdedicatedState*)effect;
  66. const ALfloat *gains = state->gains;
  67. ALuint i, s;
  68. for(i = 0;i < SamplesToDo;i++)
  69. {
  70. ALfloat sample;
  71. sample = SamplesIn[i];
  72. for(s = 0;s < MAXCHANNELS;s++)
  73. SamplesOut[i][s] = sample * gains[s];
  74. }
  75. }
  76. ALeffectState *DedicatedCreate(void)
  77. {
  78. ALdedicatedState *state;
  79. ALsizei s;
  80. state = malloc(sizeof(*state));
  81. if(!state)
  82. return NULL;
  83. state->state.Destroy = DedicatedDestroy;
  84. state->state.DeviceUpdate = DedicatedDeviceUpdate;
  85. state->state.Update = DedicatedUpdate;
  86. state->state.Process = DedicatedProcess;
  87. for(s = 0;s < MAXCHANNELS;s++)
  88. state->gains[s] = 0.0f;
  89. return &state->state;
  90. }