mixer_neon.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #include "config.h"
  2. #include <arm_neon.h>
  3. #include "AL/al.h"
  4. #include "AL/alc.h"
  5. #include "alMain.h"
  6. #include "alu.h"
  7. #include "hrtf.h"
  8. static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
  9. const ALuint IrSize,
  10. ALfloat (*restrict Coeffs)[2],
  11. const ALfloat (*restrict CoeffStep)[2],
  12. ALfloat left, ALfloat right)
  13. {
  14. ALuint c;
  15. float32x4_t leftright4;
  16. {
  17. float32x2_t leftright2 = vdup_n_f32(0.0);
  18. leftright2 = vset_lane_f32(left, leftright2, 0);
  19. leftright2 = vset_lane_f32(right, leftright2, 1);
  20. leftright4 = vcombine_f32(leftright2, leftright2);
  21. }
  22. for(c = 0;c < IrSize;c += 2)
  23. {
  24. const ALuint o0 = (Offset+c)&HRIR_MASK;
  25. const ALuint o1 = (o0+1)&HRIR_MASK;
  26. float32x4_t vals = vcombine_f32(vld1_f32((float32_t*)&Values[o0][0]),
  27. vld1_f32((float32_t*)&Values[o1][0]));
  28. float32x4_t coefs = vld1q_f32((float32_t*)&Coeffs[c][0]);
  29. float32x4_t deltas = vld1q_f32(&CoeffStep[c][0]);
  30. vals = vmlaq_f32(vals, coefs, leftright4);
  31. coefs = vaddq_f32(coefs, deltas);
  32. vst1_f32((float32_t*)&Values[o0][0], vget_low_f32(vals));
  33. vst1_f32((float32_t*)&Values[o1][0], vget_high_f32(vals));
  34. vst1q_f32(&Coeffs[c][0], coefs);
  35. }
  36. }
  37. static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
  38. const ALuint IrSize,
  39. ALfloat (*restrict Coeffs)[2],
  40. ALfloat left, ALfloat right)
  41. {
  42. ALuint c;
  43. float32x4_t leftright4;
  44. {
  45. float32x2_t leftright2 = vdup_n_f32(0.0);
  46. leftright2 = vset_lane_f32(left, leftright2, 0);
  47. leftright2 = vset_lane_f32(right, leftright2, 1);
  48. leftright4 = vcombine_f32(leftright2, leftright2);
  49. }
  50. for(c = 0;c < IrSize;c += 2)
  51. {
  52. const ALuint o0 = (Offset+c)&HRIR_MASK;
  53. const ALuint o1 = (o0+1)&HRIR_MASK;
  54. float32x4_t vals = vcombine_f32(vld1_f32((float32_t*)&Values[o0][0]),
  55. vld1_f32((float32_t*)&Values[o1][0]));
  56. float32x4_t coefs = vld1q_f32((float32_t*)&Coeffs[c][0]);
  57. vals = vmlaq_f32(vals, coefs, leftright4);
  58. vst1_f32((float32_t*)&Values[o0][0], vget_low_f32(vals));
  59. vst1_f32((float32_t*)&Values[o1][0], vget_high_f32(vals));
  60. }
  61. }
  62. #define MixHrtf MixHrtf_Neon
  63. #define MixDirectHrtf MixDirectHrtf_Neon
  64. #include "mixer_inc.c"
  65. #undef MixHrtf
  66. void Mix_Neon(const ALfloat *data, ALuint OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
  67. ALfloat *CurrentGains, const ALfloat *TargetGains, ALuint Counter, ALuint OutPos,
  68. ALuint BufferSize)
  69. {
  70. ALfloat gain, delta, step;
  71. float32x4_t gain4;
  72. ALuint c;
  73. delta = (Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f;
  74. for(c = 0;c < OutChans;c++)
  75. {
  76. ALuint pos = 0;
  77. gain = CurrentGains[c];
  78. step = (TargetGains[c] - gain) * delta;
  79. if(fabsf(step) > FLT_EPSILON)
  80. {
  81. ALuint minsize = minu(BufferSize, Counter);
  82. /* Mix with applying gain steps in aligned multiples of 4. */
  83. if(minsize-pos > 3)
  84. {
  85. float32x4_t step4;
  86. gain4 = vsetq_lane_f32(gain, gain4, 0);
  87. gain4 = vsetq_lane_f32(gain + step, gain4, 1);
  88. gain4 = vsetq_lane_f32(gain + step + step, gain4, 2);
  89. gain4 = vsetq_lane_f32(gain + step + step + step, gain4, 3);
  90. step4 = vdupq_n_f32(step + step + step + step);
  91. do {
  92. const float32x4_t val4 = vld1q_f32(&data[pos]);
  93. float32x4_t dry4 = vld1q_f32(&OutBuffer[c][OutPos+pos]);
  94. dry4 = vmlaq_f32(dry4, val4, gain4);
  95. gain4 = vaddq_f32(gain4, step4);
  96. vst1q_f32(&OutBuffer[c][OutPos+pos], dry4);
  97. pos += 4;
  98. } while(minsize-pos > 3);
  99. /* NOTE: gain4 now represents the next four gains after the
  100. * last four mixed samples, so the lowest element represents
  101. * the next gain to apply.
  102. */
  103. gain = vgetq_lane_f32(gain4, 0);
  104. }
  105. /* Mix with applying left over gain steps that aren't aligned multiples of 4. */
  106. for(;pos < minsize;pos++)
  107. {
  108. OutBuffer[c][OutPos+pos] += data[pos]*gain;
  109. gain += step;
  110. }
  111. if(pos == Counter)
  112. gain = TargetGains[c];
  113. CurrentGains[c] = gain;
  114. /* Mix until pos is aligned with 4 or the mix is done. */
  115. minsize = minu(BufferSize, (pos+3)&~3);
  116. for(;pos < minsize;pos++)
  117. OutBuffer[c][OutPos+pos] += data[pos]*gain;
  118. }
  119. if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
  120. continue;
  121. gain4 = vdupq_n_f32(gain);
  122. for(;BufferSize-pos > 3;pos += 4)
  123. {
  124. const float32x4_t val4 = vld1q_f32(&data[pos]);
  125. float32x4_t dry4 = vld1q_f32(&OutBuffer[c][OutPos+pos]);
  126. dry4 = vmlaq_f32(dry4, val4, gain4);
  127. vst1q_f32(&OutBuffer[c][OutPos+pos], dry4);
  128. }
  129. for(;pos < BufferSize;pos++)
  130. OutBuffer[c][OutPos+pos] += data[pos]*gain;
  131. }
  132. }
  133. void MixRow_Neon(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*restrict data)[BUFFERSIZE], ALuint InChans, ALuint InPos, ALuint BufferSize)
  134. {
  135. float32x4_t gain4;
  136. ALuint c;
  137. for(c = 0;c < InChans;c++)
  138. {
  139. ALuint pos = 0;
  140. ALfloat gain = Gains[c];
  141. if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
  142. continue;
  143. gain4 = vdupq_n_f32(gain);
  144. for(;BufferSize-pos > 3;pos += 4)
  145. {
  146. const float32x4_t val4 = vld1q_f32(&data[c][InPos+pos]);
  147. float32x4_t dry4 = vld1q_f32(&OutBuffer[pos]);
  148. dry4 = vmlaq_f32(dry4, val4, gain4);
  149. vst1q_f32(&OutBuffer[pos], dry4);
  150. }
  151. for(;pos < BufferSize;pos++)
  152. OutBuffer[pos] += data[c][InPos+pos]*gain;
  153. }
  154. }