Add some helper wrappers to mmap files
[openal-soft.git] / Alc / mixer_neon.c
blobfcd0387a397154add22d83adac5cf28a692e0cf1
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));
72 #define MixHrtf MixHrtf_Neon
73 #define MixDirectHrtf MixDirectHrtf_Neon
74 #include "mixer_inc.c"
75 #undef MixHrtf
78 void Mix_Neon(const ALfloat *data, ALuint OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
79 MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize)
81 ALfloat gain, step;
82 float32x4_t gain4;
83 ALuint c;
85 for(c = 0;c < OutChans;c++)
87 ALuint pos = 0;
88 gain = Gains[c].Current;
89 step = Gains[c].Step;
90 if(step != 0.0f && Counter > 0)
92 ALuint minsize = minu(BufferSize, Counter);
93 /* Mix with applying gain steps in aligned multiples of 4. */
94 if(minsize-pos > 3)
96 float32x4_t step4;
97 gain4 = vsetq_lane_f32(gain, gain4, 0);
98 gain4 = vsetq_lane_f32(gain + step, gain4, 1);
99 gain4 = vsetq_lane_f32(gain + step + step, gain4, 2);
100 gain4 = vsetq_lane_f32(gain + step + step + step, gain4, 3);
101 step4 = vdupq_n_f32(step + step + step + step);
102 do {
103 const float32x4_t val4 = vld1q_f32(&data[pos]);
104 float32x4_t dry4 = vld1q_f32(&OutBuffer[c][OutPos+pos]);
105 dry4 = vmlaq_f32(dry4, val4, gain4);
106 gain4 = vaddq_f32(gain4, step4);
107 vst1q_f32(&OutBuffer[c][OutPos+pos], dry4);
108 pos += 4;
109 } while(minsize-pos > 3);
110 /* NOTE: gain4 now represents the next four gains after the
111 * last four mixed samples, so the lowest element represents
112 * the next gain to apply.
114 gain = vgetq_lane_f32(gain4, 0);
116 /* Mix with applying left over gain steps that aren't aligned multiples of 4. */
117 for(;pos < minsize;pos++)
119 OutBuffer[c][OutPos+pos] += data[pos]*gain;
120 gain += step;
122 if(pos == Counter)
123 gain = Gains[c].Target;
124 Gains[c].Current = gain;
126 /* Mix until pos is aligned with 4 or the mix is done. */
127 minsize = minu(BufferSize, (pos+3)&~3);
128 for(;pos < minsize;pos++)
129 OutBuffer[c][OutPos+pos] += data[pos]*gain;
132 if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
133 continue;
134 gain4 = vdupq_n_f32(gain);
135 for(;BufferSize-pos > 3;pos += 4)
137 const float32x4_t val4 = vld1q_f32(&data[pos]);
138 float32x4_t dry4 = vld1q_f32(&OutBuffer[c][OutPos+pos]);
139 dry4 = vmlaq_f32(dry4, val4, gain4);
140 vst1q_f32(&OutBuffer[c][OutPos+pos], dry4);
142 for(;pos < BufferSize;pos++)
143 OutBuffer[c][OutPos+pos] += data[pos]*gain;
147 void MixRow_Neon(ALfloat *OutBuffer, const ALfloat *Mtx, ALfloat (*restrict data)[BUFFERSIZE], ALuint InChans, ALuint BufferSize)
149 float32x4_t gain4;
150 ALuint c;
152 for(c = 0;c < InChans;c++)
154 ALuint pos = 0;
155 ALfloat gain = Mtx[c];
156 if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
157 continue;
159 gain4 = vdupq_n_f32(gain);
160 for(;BufferSize-pos > 3;pos += 4)
162 const float32x4_t val4 = vld1q_f32(&data[c][pos]);
163 float32x4_t dry4 = vld1q_f32(&OutBuffer[pos]);
164 dry4 = vmlaq_f32(dry4, val4, gain4);
165 vst1q_f32(&OutBuffer[pos], dry4);
167 for(;pos < BufferSize;pos++)
168 OutBuffer[pos] += data[c][pos]*gain;