8 #include "alAuxEffectSlot.h"
12 static inline ALfloat
do_point(const ALfloat
*restrict vals
, ALsizei
UNUSED(frac
))
14 static inline ALfloat
do_lerp(const ALfloat
*restrict vals
, ALsizei frac
)
15 { return lerp(vals
[0], vals
[1], frac
* (1.0f
/FRACTIONONE
)); }
16 static inline ALfloat
do_cubic(const ALfloat
*restrict vals
, ALsizei frac
)
17 { return cubic(vals
[0], vals
[1], vals
[2], vals
[3], frac
* (1.0f
/FRACTIONONE
)); }
19 const ALfloat
*Resample_copy_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(Tag, Sampler, O) \
33 const ALfloat *Resample_##Tag##_C(const InterpState* UNUSED(state), \
34 const ALfloat *restrict src, ALsizei frac, ALint increment, \
35 ALfloat *restrict dst, ALsizei numsamples) \
40 for(i = 0;i < numsamples;i++) \
42 dst[i] = Sampler(src, frac); \
45 src += frac>>FRACTIONBITS; \
46 frac &= FRACTIONMASK; \
51 DECL_TEMPLATE(point
, do_point
, 0)
52 DECL_TEMPLATE(lerp
, do_lerp
, 0)
53 DECL_TEMPLATE(cubic
, do_cubic
, 1)
57 const ALfloat
*Resample_bsinc_C(const InterpState
*state
, const ALfloat
*restrict src
,
58 ALsizei frac
, ALint increment
, ALfloat
*restrict dst
,
61 const ALfloat
*fil
, *scd
, *phd
, *spd
;
62 const ALfloat
*const filter
= state
->bsinc
.filter
;
63 const ALfloat sf
= state
->bsinc
.sf
;
64 const ALsizei m
= state
->bsinc
.m
;
68 src
+= state
->bsinc
.l
;
69 for(i
= 0;i
< dstlen
;i
++)
71 // Calculate the phase index and factor.
72 #define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS)
73 pi
= frac
>> FRAC_PHASE_BITDIFF
;
74 pf
= (frac
& ((1<<FRAC_PHASE_BITDIFF
)-1)) * (1.0f
/(1<<FRAC_PHASE_BITDIFF
));
75 #undef FRAC_PHASE_BITDIFF
77 fil
= ASSUME_ALIGNED(filter
+ m
*pi
*4, 16);
78 scd
= ASSUME_ALIGNED(fil
+ m
, 16);
79 phd
= ASSUME_ALIGNED(scd
+ m
, 16);
80 spd
= ASSUME_ALIGNED(phd
+ m
, 16);
82 // Apply the scale and phase interpolated filter.
84 for(j_f
= 0;j_f
< m
;j_f
++)
85 r
+= (fil
[j_f
] + sf
*scd
[j_f
] + pf
*(phd
[j_f
] + sf
*spd
[j_f
])) * src
[j_f
];
89 src
+= frac
>>FRACTIONBITS
;
96 static inline void ApplyCoeffs(ALsizei Offset
, ALfloat (*restrict Values
)[2],
98 const ALfloat (*restrict Coeffs
)[2],
99 ALfloat left
, ALfloat right
)
102 for(c
= 0;c
< IrSize
;c
++)
104 const ALsizei off
= (Offset
+c
)&HRIR_MASK
;
105 Values
[off
][0] += Coeffs
[c
][0] * left
;
106 Values
[off
][1] += Coeffs
[c
][1] * right
;
110 #define MixHrtf MixHrtf_C
111 #define MixHrtfBlend MixHrtfBlend_C
112 #define MixDirectHrtf MixDirectHrtf_C
113 #include "hrtf_inc.c"
117 void Mix_C(const ALfloat
*data
, ALsizei OutChans
, ALfloat (*restrict OutBuffer
)[BUFFERSIZE
],
118 ALfloat
*CurrentGains
, const ALfloat
*TargetGains
, ALsizei Counter
, ALsizei OutPos
,
121 ALfloat gain
, delta
, step
;
124 delta
= (Counter
> 0) ? 1.0f
/(ALfloat
)Counter
: 0.0f
;
126 for(c
= 0;c
< OutChans
;c
++)
129 gain
= CurrentGains
[c
];
130 step
= (TargetGains
[c
] - gain
) * delta
;
131 if(fabsf(step
) > FLT_EPSILON
)
133 ALsizei minsize
= mini(BufferSize
, Counter
);
134 for(;pos
< minsize
;pos
++)
136 OutBuffer
[c
][OutPos
+pos
] += data
[pos
]*gain
;
140 gain
= TargetGains
[c
];
141 CurrentGains
[c
] = gain
;
144 if(!(fabsf(gain
) > GAIN_SILENCE_THRESHOLD
))
146 for(;pos
< BufferSize
;pos
++)
147 OutBuffer
[c
][OutPos
+pos
] += data
[pos
]*gain
;
151 /* Basically the inverse of the above. Rather than one input going to multiple
152 * outputs (each with its own gain), it's multiple inputs (each with its own
153 * gain) going to one output. This applies one row (vs one column) of a matrix
154 * transform. And as the matrices are more or less static once set up, no
155 * stepping is necessary.
157 void MixRow_C(ALfloat
*OutBuffer
, const ALfloat
*Gains
, const ALfloat (*restrict data
)[BUFFERSIZE
], ALsizei InChans
, ALsizei InPos
, ALsizei BufferSize
)
161 for(c
= 0;c
< InChans
;c
++)
163 ALfloat gain
= Gains
[c
];
164 if(!(fabsf(gain
) > GAIN_SILENCE_THRESHOLD
))
167 for(i
= 0;i
< BufferSize
;i
++)
168 OutBuffer
[i
] += data
[c
][InPos
+i
] * gain
;