8 #include "alAuxEffectSlot.h"
11 static inline ALfloat
point32(const ALfloat
*restrict vals
, ALsizei
UNUSED(frac
))
13 static inline ALfloat
lerp32(const ALfloat
*restrict vals
, ALsizei frac
)
14 { return lerp(vals
[0], vals
[1], frac
* (1.0f
/FRACTIONONE
)); }
15 static inline ALfloat
fir4_32(const ALfloat
*restrict vals
, ALsizei frac
)
16 { return resample_fir4(vals
[-1], vals
[0], vals
[1], vals
[2], frac
); }
19 const ALfloat
*Resample_copy32_C(const InterpState
* UNUSED(state
),
20 const ALfloat
*restrict src
, ALsizei
UNUSED(frac
), ALint
UNUSED(increment
),
21 ALfloat
*restrict dst
, ALsizei 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))
28 memcpy(dst
, src
, numsamples
*sizeof(ALfloat
));
32 #define DECL_TEMPLATE(Sampler) \
33 const ALfloat *Resample_##Sampler##_C(const InterpState* UNUSED(state), \
34 const ALfloat *restrict src, ALsizei frac, ALint increment, \
35 ALfloat *restrict dst, ALsizei numsamples) \
38 for(i = 0;i < numsamples;i++) \
40 dst[i] = Sampler(src, frac); \
43 src += frac>>FRACTIONBITS; \
44 frac &= FRACTIONMASK; \
49 DECL_TEMPLATE(point32
)
51 DECL_TEMPLATE(fir4_32
)
55 const ALfloat
*Resample_bsinc32_C(const InterpState
*state
, const ALfloat
*restrict src
,
56 ALsizei frac
, ALint increment
, ALfloat
*restrict dst
,
59 const ALfloat
*fil
, *scd
, *phd
, *spd
;
60 const ALfloat sf
= state
->bsinc
.sf
;
61 const ALsizei m
= state
->bsinc
.m
;
65 src
+= state
->bsinc
.l
;
66 for(i
= 0;i
< dstlen
;i
++)
68 // Calculate the phase index and factor.
69 #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS)
70 pi
= frac
>> FRAC_PHASE_BITDIFF
;
71 pf
= (frac
& ((1<<FRAC_PHASE_BITDIFF
)-1)) * (1.0f
/(1<<FRAC_PHASE_BITDIFF
));
72 #undef FRAC_PHASE_BITDIFF
74 fil
= ASSUME_ALIGNED(state
->bsinc
.coeffs
[pi
].filter
, 16);
75 scd
= ASSUME_ALIGNED(state
->bsinc
.coeffs
[pi
].scDelta
, 16);
76 phd
= ASSUME_ALIGNED(state
->bsinc
.coeffs
[pi
].phDelta
, 16);
77 spd
= ASSUME_ALIGNED(state
->bsinc
.coeffs
[pi
].spDelta
, 16);
79 // Apply the scale and phase interpolated filter.
81 for(j_f
= 0;j_f
< m
;j_f
++)
82 r
+= (fil
[j_f
] + sf
*scd
[j_f
] + pf
*(phd
[j_f
] + sf
*spd
[j_f
])) * src
[j_f
];
86 src
+= frac
>>FRACTIONBITS
;
93 void ALfilterState_processC(ALfilterState
*filter
, ALfloat
*restrict dst
, const ALfloat
*restrict src
, ALsizei numsamples
)
98 dst
[0] = filter
->b0
* src
[0] +
99 filter
->b1
* filter
->x
[0] +
100 filter
->b2
* filter
->x
[1] -
101 filter
->a1
* filter
->y
[0] -
102 filter
->a2
* filter
->y
[1];
103 dst
[1] = filter
->b0
* src
[1] +
104 filter
->b1
* src
[0] +
105 filter
->b2
* filter
->x
[0] -
106 filter
->a1
* dst
[0] -
107 filter
->a2
* filter
->y
[0];
108 for(i
= 2;i
< numsamples
;i
++)
109 dst
[i
] = filter
->b0
* src
[i
] +
110 filter
->b1
* src
[i
-1] +
111 filter
->b2
* src
[i
-2] -
112 filter
->a1
* dst
[i
-1] -
113 filter
->a2
* dst
[i
-2];
114 filter
->x
[0] = src
[i
-1];
115 filter
->x
[1] = src
[i
-2];
116 filter
->y
[0] = dst
[i
-1];
117 filter
->y
[1] = dst
[i
-2];
119 else if(numsamples
== 1)
121 dst
[0] = filter
->b0
* src
[0] +
122 filter
->b1
* filter
->x
[0] +
123 filter
->b2
* filter
->x
[1] -
124 filter
->a1
* filter
->y
[0] -
125 filter
->a2
* filter
->y
[1];
126 filter
->x
[1] = filter
->x
[0];
127 filter
->x
[0] = src
[0];
128 filter
->y
[1] = filter
->y
[0];
129 filter
->y
[0] = dst
[0];
134 static inline void ApplyCoeffs(ALsizei Offset
, ALfloat (*restrict Values
)[2],
135 const ALsizei IrSize
,
136 const ALfloat (*restrict Coeffs
)[2],
137 ALfloat left
, ALfloat right
)
140 for(c
= 0;c
< IrSize
;c
++)
142 const ALsizei off
= (Offset
+c
)&HRIR_MASK
;
143 Values
[off
][0] += Coeffs
[c
][0] * left
;
144 Values
[off
][1] += Coeffs
[c
][1] * right
;
148 #define MixHrtf MixHrtf_C
149 #define MixDirectHrtf MixDirectHrtf_C
150 #include "mixer_inc.c"
154 void Mix_C(const ALfloat
*data
, ALsizei OutChans
, ALfloat (*restrict OutBuffer
)[BUFFERSIZE
],
155 ALfloat
*CurrentGains
, const ALfloat
*TargetGains
, ALsizei Counter
, ALsizei OutPos
,
158 ALfloat gain
, delta
, step
;
161 delta
= (Counter
> 0) ? 1.0f
/(ALfloat
)Counter
: 0.0f
;
163 for(c
= 0;c
< OutChans
;c
++)
166 gain
= CurrentGains
[c
];
167 step
= (TargetGains
[c
] - gain
) * delta
;
168 if(fabsf(step
) > FLT_EPSILON
)
170 ALsizei minsize
= mini(BufferSize
, Counter
);
171 for(;pos
< minsize
;pos
++)
173 OutBuffer
[c
][OutPos
+pos
] += data
[pos
]*gain
;
177 gain
= TargetGains
[c
];
178 CurrentGains
[c
] = gain
;
181 if(!(fabsf(gain
) > GAIN_SILENCE_THRESHOLD
))
183 for(;pos
< BufferSize
;pos
++)
184 OutBuffer
[c
][OutPos
+pos
] += data
[pos
]*gain
;
188 /* Basically the inverse of the above. Rather than one input going to multiple
189 * outputs (each with its own gain), it's multiple inputs (each with its own
190 * gain) going to one output. This applies one row (vs one column) of a matrix
191 * transform. And as the matrices are more or less static once set up, no
192 * stepping is necessary.
194 void MixRow_C(ALfloat
*OutBuffer
, const ALfloat
*Gains
, const ALfloat (*restrict data
)[BUFFERSIZE
], ALsizei InChans
, ALsizei InPos
, ALsizei BufferSize
)
198 for(c
= 0;c
< InChans
;c
++)
200 ALfloat gain
= Gains
[c
];
201 if(!(fabsf(gain
) > GAIN_SILENCE_THRESHOLD
))
204 for(i
= 0;i
< BufferSize
;i
++)
205 OutBuffer
[i
] += data
[c
][InPos
+i
] * gain
;