mixer_c.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "config.h"
  2. #include <assert.h>
  3. #include "alMain.h"
  4. #include "alu.h"
  5. #include "alSource.h"
  6. #include "alAuxEffectSlot.h"
  7. static inline ALfloat point32(const ALfloat *vals, ALuint UNUSED(frac))
  8. { return vals[0]; }
  9. static inline ALfloat lerp32(const ALfloat *vals, ALuint frac)
  10. { return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); }
  11. static inline ALfloat cubic32(const ALfloat *vals, ALuint frac)
  12. { return cubic(vals[-1], vals[0], vals[1], vals[2], frac * (1.0f/FRACTIONONE)); }
  13. void Resample_copy32_C(const ALfloat *data, ALuint UNUSED(frac),
  14. ALuint increment, ALfloat *restrict OutBuffer, ALuint BufferSize)
  15. {
  16. assert(increment==FRACTIONONE);
  17. memcpy(OutBuffer, data, (BufferSize+1)*sizeof(ALfloat));
  18. }
  19. #define DECL_TEMPLATE(Sampler) \
  20. void Resample_##Sampler##_C(const ALfloat *data, ALuint frac, \
  21. ALuint increment, ALfloat *restrict OutBuffer, ALuint BufferSize) \
  22. { \
  23. ALuint pos = 0; \
  24. ALuint i; \
  25. \
  26. for(i = 0;i < BufferSize+1;i++) \
  27. { \
  28. OutBuffer[i] = Sampler(data + pos, frac); \
  29. \
  30. frac += increment; \
  31. pos += frac>>FRACTIONBITS; \
  32. frac &= FRACTIONMASK; \
  33. } \
  34. }
  35. DECL_TEMPLATE(point32)
  36. DECL_TEMPLATE(lerp32)
  37. DECL_TEMPLATE(cubic32)
  38. #undef DECL_TEMPLATE
  39. static inline void ApplyCoeffsStep(const ALuint IrSize,
  40. ALfloat (*restrict Coeffs)[2],
  41. const ALfloat (*restrict CoeffStep)[2])
  42. {
  43. ALuint c;
  44. for(c = 0;c < IrSize;c++)
  45. {
  46. Coeffs[c][0] += CoeffStep[c][0];
  47. Coeffs[c][1] += CoeffStep[c][1];
  48. }
  49. }
  50. static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
  51. const ALuint IrSize,
  52. ALfloat (*restrict Coeffs)[2],
  53. ALfloat left, ALfloat right)
  54. {
  55. ALuint c;
  56. for(c = 0;c < IrSize;c++)
  57. {
  58. const ALuint off = (Offset+c)&HRIR_MASK;
  59. Values[off][0] += Coeffs[c][0] * left;
  60. Values[off][1] += Coeffs[c][1] * right;
  61. }
  62. }
  63. #define SUFFIX C
  64. #include "mixer_inc.c"
  65. #undef SUFFIX
  66. void MixDirect_C(const DirectParams *params, const ALfloat *restrict data, ALuint srcchan,
  67. ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
  68. {
  69. ALfloat (*restrict OutBuffer)[BUFFERSIZE] = params->OutBuffer;
  70. ALfloat *restrict ClickRemoval = params->ClickRemoval;
  71. ALfloat *restrict PendingClicks = params->PendingClicks;
  72. ALfloat DrySend;
  73. ALuint pos;
  74. ALuint c;
  75. for(c = 0;c < MaxChannels;c++)
  76. {
  77. DrySend = params->Gains[srcchan][c];
  78. if(!(DrySend > GAIN_SILENCE_THRESHOLD))
  79. continue;
  80. if(OutPos == 0)
  81. ClickRemoval[c] -= data[0]*DrySend;
  82. for(pos = 0;pos < BufferSize;pos++)
  83. OutBuffer[c][OutPos+pos] += data[pos]*DrySend;
  84. if(OutPos+pos == SamplesToDo)
  85. PendingClicks[c] += data[pos]*DrySend;
  86. }
  87. }
  88. void MixSend_C(const SendParams *params, const ALfloat *restrict data,
  89. ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
  90. {
  91. ALfloat (*restrict OutBuffer)[BUFFERSIZE] = params->OutBuffer;
  92. ALfloat *restrict ClickRemoval = params->ClickRemoval;
  93. ALfloat *restrict PendingClicks = params->PendingClicks;
  94. ALfloat WetSend;
  95. ALuint pos;
  96. WetSend = params->Gain;
  97. if(!(WetSend > GAIN_SILENCE_THRESHOLD))
  98. return;
  99. if(OutPos == 0)
  100. ClickRemoval[0] -= data[0] * WetSend;
  101. for(pos = 0;pos < BufferSize;pos++)
  102. OutBuffer[0][OutPos+pos] += data[pos] * WetSend;
  103. if(OutPos+pos == SamplesToDo)
  104. PendingClicks[0] += data[pos] * WetSend;
  105. }