Move the resampler stuff to mixer.c where it's used
[openal-soft.git] / Alc / mixer_c.c
blob0d3e99a6c334926b6767887bf4c1665e8420d621
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 fir6_32(const ALfloat *vals, ALuint frac)
18 { return resample_fir6(vals[-2], vals[-1], vals[0], vals[1], vals[2], vals[3], frac); }
20 const ALfloat *Resample_copy32_C(const ALfloat *src, ALuint UNUSED(frac),
21 ALuint UNUSED(increment), ALfloat *restrict dst, ALuint numsamples)
23 #if defined(HAVE_SSE) || defined(HAVE_NEON)
24 /* Avoid copying the source data if it's aligned like the destination. */
25 if((((intptr_t)src)&15) == (((intptr_t)dst)&15))
26 return src;
27 #endif
28 memcpy(dst, src, numsamples*sizeof(ALfloat));
29 return dst;
32 #define DECL_TEMPLATE(Sampler) \
33 const ALfloat *Resample_##Sampler##_C(const ALfloat *src, ALuint frac, \
34 ALuint increment, ALfloat *restrict dst, ALuint numsamples) \
35 { \
36 ALuint i; \
37 for(i = 0;i < numsamples;i++) \
38 { \
39 dst[i] = Sampler(src, frac); \
41 frac += increment; \
42 src += frac>>FRACTIONBITS; \
43 frac &= FRACTIONMASK; \
44 } \
45 return dst; \
48 DECL_TEMPLATE(point32)
49 DECL_TEMPLATE(lerp32)
50 DECL_TEMPLATE(fir4_32)
51 DECL_TEMPLATE(fir6_32)
53 #undef DECL_TEMPLATE
56 void ALfilterState_processC(ALfilterState *filter, ALfloat *restrict dst, const ALfloat *src, ALuint numsamples)
58 ALuint i;
59 for(i = 0;i < numsamples;i++)
60 *(dst++) = ALfilterState_processSingle(filter, *(src++));
64 static inline void SetupCoeffs(ALfloat (*restrict OutCoeffs)[2],
65 const HrtfParams *hrtfparams,
66 ALuint IrSize, ALuint Counter)
68 ALuint c;
69 for(c = 0;c < IrSize;c++)
71 OutCoeffs[c][0] = hrtfparams->Coeffs[c][0] - (hrtfparams->CoeffStep[c][0]*Counter);
72 OutCoeffs[c][1] = hrtfparams->Coeffs[c][1] - (hrtfparams->CoeffStep[c][1]*Counter);
76 static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
77 const ALuint IrSize,
78 ALfloat (*restrict Coeffs)[2],
79 const ALfloat (*restrict CoeffStep)[2],
80 ALfloat left, ALfloat right)
82 ALuint c;
83 for(c = 0;c < IrSize;c++)
85 const ALuint off = (Offset+c)&HRIR_MASK;
86 Values[off][0] += Coeffs[c][0] * left;
87 Values[off][1] += Coeffs[c][1] * right;
88 Coeffs[c][0] += CoeffStep[c][0];
89 Coeffs[c][1] += CoeffStep[c][1];
93 static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
94 const ALuint IrSize,
95 ALfloat (*restrict Coeffs)[2],
96 ALfloat left, ALfloat right)
98 ALuint c;
99 for(c = 0;c < IrSize;c++)
101 const ALuint off = (Offset+c)&HRIR_MASK;
102 Values[off][0] += Coeffs[c][0] * left;
103 Values[off][1] += Coeffs[c][1] * right;
107 #define MixHrtf MixHrtf_C
108 #include "mixer_inc.c"
109 #undef MixHrtf
112 void Mix_C(const ALfloat *data, ALuint OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
113 MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize)
115 ALfloat gain, step;
116 ALuint c;
118 for(c = 0;c < OutChans;c++)
120 ALuint pos = 0;
121 gain = Gains[c].Current;
122 step = Gains[c].Step;
123 if(step != 0.0f && Counter > 0)
125 ALuint minsize = minu(BufferSize, Counter);
126 for(;pos < minsize;pos++)
128 OutBuffer[c][OutPos+pos] += data[pos]*gain;
129 gain += step;
131 if(pos == Counter)
132 gain = Gains[c].Target;
133 Gains[c].Current = gain;
136 if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
137 continue;
138 for(;pos < BufferSize;pos++)
139 OutBuffer[c][OutPos+pos] += data[pos]*gain;