zenilib: zenilib/jni/external/openal-soft/Alc/mixer_sse.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mixer_sse.c
Go to the documentation of this file.
1 #include "config.h"
2
3 #ifdef HAVE_XMMINTRIN_H
4 #include <xmmintrin.h>
5 #endif
6
7 #include "AL/al.h"
8 #include "AL/alc.h"
9 #include "alMain.h"
10 #include "alu.h"
11
12 #include "alSource.h"
13 #include "alAuxEffectSlot.h"
14 #include "mixer_defs.h"
15
16
17 static __inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*RESTRICT Values)[2],
18 const ALuint IrSize,
19 ALfloat (*RESTRICT Coeffs)[2],
20 const ALfloat (*RESTRICT CoeffStep)[2],
21 ALfloat left, ALfloat right)
22 {
23 const __m128 lrlr = { left, right, left, right };
24 __m128 coeffs, deltas, imp0, imp1;
25 __m128 vals = _mm_setzero_ps();
26 ALuint i;
27
28 if((Offset&1))
29 {
30 const ALuint o0 = Offset&HRIR_MASK;
31 const ALuint o1 = (Offset+IrSize-1)&HRIR_MASK;
32
33 coeffs = _mm_load_ps(&Coeffs[0][0]);
34 deltas = _mm_load_ps(&CoeffStep[0][0]);
35 vals = _mm_loadl_pi(vals, (__m64*)&Values[o0][0]);
36 imp0 = _mm_mul_ps(lrlr, coeffs);
37 coeffs = _mm_add_ps(coeffs, deltas);
38 vals = _mm_add_ps(imp0, vals);
39 _mm_store_ps(&Coeffs[0][0], coeffs);
40 _mm_storel_pi((__m64*)&Values[o0][0], vals);
41 for(i = 1;i < IrSize-1;i += 2)
42 {
43 const ALuint o2 = (Offset+i)&HRIR_MASK;
44
45 coeffs = _mm_load_ps(&Coeffs[i+1][0]);
46 deltas = _mm_load_ps(&CoeffStep[i+1][0]);
47 vals = _mm_load_ps(&Values[o2][0]);
48 imp1 = _mm_mul_ps(lrlr, coeffs);
49 coeffs = _mm_add_ps(coeffs, deltas);
50 imp0 = _mm_shuffle_ps(imp0, imp1, _MM_SHUFFLE(1, 0, 3, 2));
51 vals = _mm_add_ps(imp0, vals);
52 _mm_store_ps(&Coeffs[i+1][0], coeffs);
53 _mm_store_ps(&Values[o2][0], vals);
54 imp0 = imp1;
55 }
56 vals = _mm_loadl_pi(vals, (__m64*)&Values[o1][0]);
57 imp0 = _mm_movehl_ps(imp0, imp0);
58 vals = _mm_add_ps(imp0, vals);
59 _mm_storel_pi((__m64*)&Values[o1][0], vals);
60 }
61 else
62 {
63 for(i = 0;i < IrSize;i += 2)
64 {
65 const ALuint o = (Offset + i)&HRIR_MASK;
66
67 coeffs = _mm_load_ps(&Coeffs[i][0]);
68 deltas = _mm_load_ps(&CoeffStep[i][0]);
69 vals = _mm_load_ps(&Values[o][0]);
70 imp0 = _mm_mul_ps(lrlr, coeffs);
71 coeffs = _mm_add_ps(coeffs, deltas);
72 vals = _mm_add_ps(imp0, vals);
73 _mm_store_ps(&Coeffs[i][0], coeffs);
74 _mm_store_ps(&Values[o][0], vals);
75 }
76 }
77 }
78
79 static __inline void ApplyCoeffs(ALuint Offset, ALfloat (*RESTRICT Values)[2],
80 const ALuint IrSize,
81 ALfloat (*RESTRICT Coeffs)[2],
82 ALfloat left, ALfloat right)
83 {
84 const __m128 lrlr = { left, right, left, right };
85 __m128 vals = _mm_setzero_ps();
86 __m128 coeffs;
87 ALuint i;
88
89 if((Offset&1))
90 {
91 const ALuint o0 = Offset&HRIR_MASK;
92 const ALuint o1 = (Offset+IrSize-1)&HRIR_MASK;
93 __m128 imp0, imp1;
94
95 coeffs = _mm_load_ps(&Coeffs[0][0]);
96 vals = _mm_loadl_pi(vals, (__m64*)&Values[o0][0]);
97 imp0 = _mm_mul_ps(lrlr, coeffs);
98 vals = _mm_add_ps(imp0, vals);
99 _mm_storel_pi((__m64*)&Values[o0][0], vals);
100 for(i = 1;i < IrSize-1;i += 2)
101 {
102 const ALuint o2 = (Offset+i)&HRIR_MASK;
103
104 coeffs = _mm_load_ps(&Coeffs[i+1][0]);
105 vals = _mm_load_ps(&Values[o2][0]);
106 imp1 = _mm_mul_ps(lrlr, coeffs);
107 imp0 = _mm_shuffle_ps(imp0, imp1, _MM_SHUFFLE(1, 0, 3, 2));
108 vals = _mm_add_ps(imp0, vals);
109 _mm_store_ps(&Values[o2][0], vals);
110 imp0 = imp1;
111 }
112 vals = _mm_loadl_pi(vals, (__m64*)&Values[o1][0]);
113 imp0 = _mm_movehl_ps(imp0, imp0);
114 vals = _mm_add_ps(imp0, vals);
115 _mm_storel_pi((__m64*)&Values[o1][0], vals);
116 }
117 else
118 {
119 for(i = 0;i < IrSize;i += 2)
120 {
121 const ALuint o = (Offset + i)&HRIR_MASK;
122
123 coeffs = _mm_load_ps(&Coeffs[i][0]);
124 vals = _mm_load_ps(&Values[o][0]);
125 vals = _mm_add_ps(vals, _mm_mul_ps(lrlr, coeffs));
126 _mm_store_ps(&Values[o][0], vals);
127 }
128 }
129 }
130
131 #define SUFFIX SSE
132 #include "mixer_inc.c"
133 #undef SUFFIX
134
135
136 void MixDirect_SSE(const DirectParams *params, const ALfloat *RESTRICT data, ALuint srcchan,
137 ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
138 {
139 ALfloat (*RESTRICT DryBuffer)[BUFFERSIZE] = params->OutBuffer;
140 ALfloat *RESTRICT ClickRemoval = params->ClickRemoval;
141 ALfloat *RESTRICT PendingClicks = params->PendingClicks;
142 ALfloat DrySend;
143 ALuint pos;
144 ALuint c;
145
146 for(c = 0;c < MaxChannels;c++)
147 {
148 __m128 gain;
149
150 DrySend = params->Gains[srcchan][c];
151 if(DrySend < 0.00001f)
152 continue;
153
154 if(OutPos == 0)
155 ClickRemoval[c] -= data[0]*DrySend;
156
157 gain = _mm_set1_ps(DrySend);
158 for(pos = 0;pos < BufferSize-3;pos += 4)
159 {
160 const __m128 val4 = _mm_load_ps(&data[pos]);
161 __m128 dry4 = _mm_load_ps(&DryBuffer[c][OutPos+pos]);
162 dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain));
163 _mm_store_ps(&DryBuffer[c][OutPos+pos], dry4);
164 }
165 for(;pos < BufferSize;pos++)
166 DryBuffer[c][OutPos+pos] += data[pos]*DrySend;
167
168 if(OutPos+pos == SamplesToDo)
169 PendingClicks[c] += data[pos]*DrySend;
170 }
171 }
172
173
174 void MixSend_SSE(const SendParams *params, const ALfloat *RESTRICT data,
175 ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
176 {
177 ALeffectslot *Slot = params->Slot;
178 ALfloat (*RESTRICT WetBuffer)[BUFFERSIZE] = Slot->WetBuffer;
179 ALfloat *RESTRICT WetClickRemoval = Slot->ClickRemoval;
180 ALfloat *RESTRICT WetPendingClicks = Slot->PendingClicks;
181 const ALfloat WetGain = params->Gain;
182 __m128 gain;
183 ALuint pos;
184
185 if(WetGain < 0.00001f)
186 return;
187
188 if(OutPos == 0)
189 WetClickRemoval[0] -= data[0] * WetGain;
190
191 gain = _mm_set1_ps(WetGain);
192 for(pos = 0;pos < BufferSize-3;pos+=4)
193 {
194 const __m128 val4 = _mm_load_ps(&data[pos]);
195 __m128 wet4 = _mm_load_ps(&WetBuffer[0][OutPos+pos]);
196 wet4 = _mm_add_ps(wet4, _mm_mul_ps(val4, gain));
197 _mm_store_ps(&WetBuffer[0][OutPos+pos], wet4);
198 }
199 for(;pos < BufferSize;pos++)
200 WetBuffer[0][OutPos+pos] += data[pos] * WetGain;
201
202 if(OutPos+pos == SamplesToDo)
203 WetPendingClicks[0] += data[pos] * WetGain;
204 }
ApplyCoeffsStep
static __inline void ApplyCoeffsStep(ALuint Offset, ALfloat(*RESTRICT Values)[2], const ALuint IrSize, ALfloat(*RESTRICT Coeffs)[2], const ALfloat(*RESTRICT CoeffStep)[2], ALfloat left, ALfloat right)
Definition: mixer_sse.c:17
DirectParams::OutBuffer
ALfloat(* OutBuffer)[BUFFERSIZE]
Definition: alSource.h:50
DirectParams
Definition: alSource.h:49
MixDirect_SSE
void MixDirect_SSE(const struct DirectParams *, const ALfloat *RESTRICT, ALuint, ALuint, ALuint, ALuint)
left
GLint left
Definition: glew.h:7291
f
GLclampf f
Definition: glew.h:3390
alu.h
MixSend_SSE
void MixSend_SSE(const struct SendParams *, const ALfloat *RESTRICT, ALuint, ALuint, ALuint)
alSource.h
ApplyCoeffs
static __inline void ApplyCoeffs(ALuint Offset, ALfloat(*RESTRICT Values)[2], const ALuint IrSize, ALfloat(*RESTRICT Coeffs)[2], ALfloat left, ALfloat right)
Definition: mixer_sse.c:79
ALfloat
float ALfloat
Definition: al.h:68
mixer_inc.c
params
GLenum GLvoid ** params
Definition: gl2ext.h:806
alAuxEffectSlot.h
ALeffectslot::PendingClicks
ALfloat PendingClicks[1]
Definition: alAuxEffectSlot.h:32
ALeffectslot
Definition: alAuxEffectSlot.h:19
alMain.h
SendParams::Slot
struct ALeffectslot * Slot
Definition: alSource.h:70
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
c
const GLfloat * c
Definition: glew.h:14913
mixer_defs.h
SendParams::Gain
ALfloat Gain
Definition: alSource.h:74
DirectParams::Gains
ALfloat Gains[MaxChannels][MaxChannels]
Definition: alSource.h:62
ALuint
unsigned int ALuint
Definition: al.h:59
ALeffectslot::ClickRemoval
ALfloat ClickRemoval[1]
Definition: alAuxEffectSlot.h:31
DirectParams::PendingClicks
ALfloat * PendingClicks
Definition: alSource.h:52
HRIR_MASK
#define HRIR_MASK
Definition: alMain.h:777
i
int i
Definition: pngrutil.c:1377
right
GLfloat right
Definition: glew.h:13816
BUFFERSIZE
#define BUFFERSIZE
Definition: alMain.h:556
SendParams
Definition: alSource.h:69
DirectParams::ClickRemoval
ALfloat * ClickRemoval
Definition: alSource.h:51
coeffs
GLenum GLenum const GLfloat * coeffs
Definition: glew.h:12405
MaxChannels
Definition: alMain.h:491