Don't try to use the non-standard alloca.h
[openal-soft.git] / Alc / mixer_neon.c
blob6a0421a5ebadcf5c4f5ba60a978cc40b4880a442
1 #include "config.h"
3 #include <arm_neon.h>
5 #include "AL/al.h"
6 #include "AL/alc.h"
7 #include "alMain.h"
8 #include "alu.h"
9 #include "hrtf.h"
12 static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
13 const ALuint IrSize,
14 ALfloat (*restrict Coeffs)[2],
15 const ALfloat (*restrict CoeffStep)[2],
16 ALfloat left, ALfloat right)
18 ALuint c;
19 float32x4_t leftright4;
21 float32x2_t leftright2 = vdup_n_f32(0.0);
22 leftright2 = vset_lane_f32(left, leftright2, 0);
23 leftright2 = vset_lane_f32(right, leftright2, 1);
24 leftright4 = vcombine_f32(leftright2, leftright2);
26 for(c = 0;c < IrSize;c += 2)
28 const ALuint o0 = (Offset+c)&HRIR_MASK;
29 const ALuint o1 = (o0+1)&HRIR_MASK;
30 float32x4_t vals = vcombine_f32(vld1_f32((float32_t*)&Values[o0][0]),
31 vld1_f32((float32_t*)&Values[o1][0]));
32 float32x4_t coefs = vld1q_f32((float32_t*)&Coeffs[c][0]);
33 float32x4_t deltas = vld1q_f32(&CoeffStep[c][0]);
35 vals = vmlaq_f32(vals, coefs, leftright4);
36 coefs = vaddq_f32(coefs, deltas);
38 vst1_f32((float32_t*)&Values[o0][0], vget_low_f32(vals));
39 vst1_f32((float32_t*)&Values[o1][0], vget_high_f32(vals));
40 vst1q_f32(&Coeffs[c][0], coefs);
44 static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
45 const ALuint IrSize,
46 ALfloat (*restrict Coeffs)[2],
47 ALfloat left, ALfloat right)
49 ALuint c;
50 float32x4_t leftright4;
52 float32x2_t leftright2 = vdup_n_f32(0.0);
53 leftright2 = vset_lane_f32(left, leftright2, 0);
54 leftright2 = vset_lane_f32(right, leftright2, 1);
55 leftright4 = vcombine_f32(leftright2, leftright2);
57 for(c = 0;c < IrSize;c += 2)
59 const ALuint o0 = (Offset+c)&HRIR_MASK;
60 const ALuint o1 = (o0+1)&HRIR_MASK;
61 float32x4_t vals = vcombine_f32(vld1_f32((float32_t*)&Values[o0][0]),
62 vld1_f32((float32_t*)&Values[o1][0]));
63 float32x4_t coefs = vld1q_f32((float32_t*)&Coeffs[c][0]);
65 vals = vmlaq_f32(vals, coefs, leftright4);
67 vst1_f32((float32_t*)&Values[o0][0], vget_low_f32(vals));
68 vst1_f32((float32_t*)&Values[o1][0], vget_high_f32(vals));
73 #define SUFFIX Neon
74 #include "mixer_inc.c"
75 #undef SUFFIX
78 void MixDirect_Neon(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat *data,
79 MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize)
81 ALfloat DrySend, Step;
82 float32x4_t gain;
83 ALuint c;
85 for(c = 0;c < MaxChannels;c++)
87 ALuint pos = 0;
88 DrySend = Gains->Current[c];
89 Step = Gains->Step[c];
90 if(Step != 1.0f && Counter > 0)
92 for(;pos < BufferSize && pos < Counter;pos++)
94 OutBuffer[c][OutPos+pos] += data[pos]*DrySend;
95 DrySend *= Step;
97 if(pos == Counter)
98 DrySend = Gains->Target[c];
99 Gains->Current[c] = DrySend;
100 /* Mix until pos is aligned with 4 or the mix is done. */
101 for(;pos < BufferSize && (pos&3) != 0;pos++)
102 OutBuffer[c][OutPos+pos] += data[pos]*DrySend;
105 if(!(DrySend > GAIN_SILENCE_THRESHOLD))
106 continue;
107 gain = vdupq_n_f32(DrySend);
108 for(;BufferSize-pos > 3;pos += 4)
110 const float32x4_t val4 = vld1q_f32(&data[pos]);
111 float32x4_t dry4 = vld1q_f32(&OutBuffer[c][OutPos+pos]);
112 dry4 = vaddq_f32(dry4, vmulq_f32(val4, gain));
113 vst1q_f32(&OutBuffer[c][OutPos+pos], dry4);
115 for(;pos < BufferSize;pos++)
116 OutBuffer[c][OutPos+pos] += data[pos]*DrySend;
121 void MixSend_Neon(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat *data,
122 MixGainMono *Gain, ALuint Counter, ALuint OutPos, ALuint BufferSize)
124 ALfloat WetGain, Step;
125 float32x4_t gain;
128 ALuint pos = 0;
129 WetGain = Gain->Current;
130 Step = Gain->Step;
131 if(Step != 1.0f && Counter > 0)
133 for(;pos < BufferSize && pos < Counter;pos++)
135 OutBuffer[0][OutPos+pos] += data[pos]*WetGain;
136 WetGain *= Step;
138 if(pos == Counter)
139 WetGain = Gain->Target;
140 Gain->Current = WetGain;
141 for(;pos < BufferSize && (pos&3) != 0;pos++)
142 OutBuffer[0][OutPos+pos] += data[pos]*WetGain;
145 if(!(WetGain > GAIN_SILENCE_THRESHOLD))
146 return;
147 gain = vdupq_n_f32(WetGain);
148 for(;BufferSize-pos > 3;pos += 4)
150 const float32x4_t val4 = vld1q_f32(&data[pos]);
151 float32x4_t wet4 = vld1q_f32(&OutBuffer[0][OutPos+pos]);
152 wet4 = vaddq_f32(wet4, vmulq_f32(val4, gain));
153 vst1q_f32(&OutBuffer[0][OutPos+pos], wet4);
155 for(;pos < BufferSize;pos++)
156 OutBuffer[0][OutPos+pos] += data[pos] * WetGain;