Add 'restrict' to another parameter
[openal-soft.git] / Alc / mixer_c.c
blob5b3e7b74e03e94e470e53778224f67bf66204c90
1 #include "config.h"
3 #include <assert.h>
5 #include "alMain.h"
6 #include "alu.h"
7 #include "alSource.h"
8 #include "alAuxEffectSlot.h"
11 static inline ALfloat point32(const ALfloat *vals, ALuint UNUSED(frac))
12 { return vals[0]; }
13 static inline ALfloat lerp32(const ALfloat *vals, ALuint frac)
14 { return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); }
15 static inline ALfloat fir4_32(const ALfloat *vals, ALuint frac)
16 { return resample_fir4(vals[-1], vals[0], vals[1], vals[2], frac); }
17 static inline ALfloat fir8_32(const ALfloat *vals, ALuint frac)
18 { return resample_fir8(vals[-3], vals[-2], vals[-1], vals[0], vals[1], vals[2], vals[3], vals[4], frac); }
21 const ALfloat *Resample_copy32_C(const BsincState* UNUSED(state), const ALfloat *src, ALuint UNUSED(frac),
22 ALuint UNUSED(increment), ALfloat *restrict dst, ALuint numsamples)
24 #if defined(HAVE_SSE) || defined(HAVE_NEON)
25 /* Avoid copying the source data if it's aligned like the destination. */
26 if((((intptr_t)src)&15) == (((intptr_t)dst)&15))
27 return src;
28 #endif
29 memcpy(dst, src, numsamples*sizeof(ALfloat));
30 return dst;
33 #define DECL_TEMPLATE(Sampler) \
34 const ALfloat *Resample_##Sampler##_C(const BsincState* UNUSED(state), \
35 const ALfloat *src, ALuint frac, ALuint increment, \
36 ALfloat *restrict dst, ALuint numsamples) \
37 { \
38 ALuint i; \
39 for(i = 0;i < numsamples;i++) \
40 { \
41 dst[i] = Sampler(src, frac); \
43 frac += increment; \
44 src += frac>>FRACTIONBITS; \
45 frac &= FRACTIONMASK; \
46 } \
47 return dst; \
50 DECL_TEMPLATE(point32)
51 DECL_TEMPLATE(lerp32)
52 DECL_TEMPLATE(fir4_32)
53 DECL_TEMPLATE(fir8_32)
55 #undef DECL_TEMPLATE
57 const ALfloat *Resample_bsinc32_C(const BsincState *state, const ALfloat *src, ALuint frac,
58 ALuint increment, ALfloat *restrict dst, ALuint dstlen)
60 const ALfloat *fil, *scd, *phd, *spd;
61 const ALfloat sf = state->sf;
62 const ALuint m = state->m;
63 const ALint l = state->l;
64 ALuint j_f, pi, i;
65 ALfloat pf, r;
66 ALint j_s;
68 for(i = 0;i < dstlen;i++)
70 // Calculate the phase index and factor.
71 #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS)
72 pi = frac >> FRAC_PHASE_BITDIFF;
73 pf = (frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF));
74 #undef FRAC_PHASE_BITDIFF
76 fil = state->coeffs[pi].filter;
77 scd = state->coeffs[pi].scDelta;
78 phd = state->coeffs[pi].phDelta;
79 spd = state->coeffs[pi].spDelta;
81 // Apply the scale and phase interpolated filter.
82 r = 0.0f;
83 for(j_f = 0,j_s = l;j_f < m;j_f++,j_s++)
84 r += (fil[j_f] + sf*scd[j_f] + pf*(phd[j_f] + sf*spd[j_f])) *
85 src[j_s];
86 dst[i] = r;
88 frac += increment;
89 src += frac>>FRACTIONBITS;
90 frac &= FRACTIONMASK;
92 return dst;
96 void ALfilterState_processC(ALfilterState *filter, ALfloat *restrict dst, const ALfloat *restrict src, ALuint numsamples)
98 ALuint i;
99 if(numsamples > 1)
101 dst[0] = filter->b0 * src[0] +
102 filter->b1 * filter->x[0] +
103 filter->b2 * filter->x[1] -
104 filter->a1 * filter->y[0] -
105 filter->a2 * filter->y[1];
106 dst[1] = filter->b0 * src[1] +
107 filter->b1 * src[0] +
108 filter->b2 * filter->x[0] -
109 filter->a1 * dst[0] -
110 filter->a2 * filter->y[0];
111 for(i = 2;i < numsamples;i++)
112 dst[i] = filter->b0 * src[i] +
113 filter->b1 * src[i-1] +
114 filter->b2 * src[i-2] -
115 filter->a1 * dst[i-1] -
116 filter->a2 * dst[i-2];
117 filter->x[0] = src[i-1];
118 filter->x[1] = src[i-2];
119 filter->y[0] = dst[i-1];
120 filter->y[1] = dst[i-2];
122 else if(numsamples == 1)
124 dst[0] = filter->b0 * src[0] +
125 filter->b1 * filter->x[0] +
126 filter->b2 * filter->x[1] -
127 filter->a1 * filter->y[0] -
128 filter->a2 * filter->y[1];
129 filter->x[1] = filter->x[0];
130 filter->x[0] = src[0];
131 filter->y[1] = filter->y[0];
132 filter->y[0] = dst[0];
137 static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
138 const ALuint IrSize,
139 ALfloat (*restrict Coeffs)[2],
140 const ALfloat (*restrict CoeffStep)[2],
141 ALfloat left, ALfloat right)
143 ALuint c;
144 for(c = 0;c < IrSize;c++)
146 const ALuint off = (Offset+c)&HRIR_MASK;
147 Values[off][0] += Coeffs[c][0] * left;
148 Values[off][1] += Coeffs[c][1] * right;
149 Coeffs[c][0] += CoeffStep[c][0];
150 Coeffs[c][1] += CoeffStep[c][1];
154 static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
155 const ALuint IrSize,
156 ALfloat (*restrict Coeffs)[2],
157 ALfloat left, ALfloat right)
159 ALuint c;
160 for(c = 0;c < IrSize;c++)
162 const ALuint off = (Offset+c)&HRIR_MASK;
163 Values[off][0] += Coeffs[c][0] * left;
164 Values[off][1] += Coeffs[c][1] * right;
168 #define MixHrtf MixHrtf_C
169 #include "mixer_inc.c"
170 #undef MixHrtf
173 void Mix_C(const ALfloat *data, ALuint OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
174 MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize)
176 ALfloat gain, step;
177 ALuint c;
179 for(c = 0;c < OutChans;c++)
181 ALuint pos = 0;
182 gain = Gains[c].Current;
183 step = Gains[c].Step;
184 if(step != 0.0f && Counter > 0)
186 ALuint minsize = minu(BufferSize, Counter);
187 for(;pos < minsize;pos++)
189 OutBuffer[c][OutPos+pos] += data[pos]*gain;
190 gain += step;
192 if(pos == Counter)
193 gain = Gains[c].Target;
194 Gains[c].Current = gain;
197 if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
198 continue;
199 for(;pos < BufferSize;pos++)
200 OutBuffer[c][OutPos+pos] += data[pos]*gain;
204 /* Basically the inverse of the above. Rather than one input going to multiple
205 * outputs (each with its own gain), it's multiple inputs (each with its own
206 * gain) going to one output. This applies one row (vs one column) of a matrix
207 * transform. And as the matrices are more or less static once set up, no
208 * stepping is necessary.
210 void MixRow_C(ALfloat *OutBuffer, const ALfloat *Mtx, ALfloat (*restrict data)[BUFFERSIZE], ALuint InChans, ALuint BufferSize)
212 ALuint c, i;
214 for(c = 0;c < InChans;c++)
216 ALfloat gain = Mtx[c];
217 if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
218 continue;
220 for(i = 0;i < BufferSize;i++)
221 OutBuffer[i] += data[c][i] * gain;