1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | #include "matrixlib.h" |
31 | #include "ALACAudioTypes.h" |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | void mix16( int32_t * in, uint32_t stride, int32_t * u, int32_t * v, int32_t numSamples, int32_t mixbits, int32_t mixres ) |
51 | { |
52 | int32_t j; |
53 | |
54 | if ( mixres != 0 ) |
55 | { |
56 | int32_t mod = 1 << mixbits; |
57 | int32_t m2; |
58 | |
59 | |
60 | m2 = mod - mixres; |
61 | for ( j = 0; j < numSamples; j++ ) |
62 | { |
63 | int32_t l, r; |
64 | |
65 | l = in[0] >> 16; |
66 | r = in[1] >> 16; |
67 | in += stride; |
68 | u[j] = (mixres * l + m2 * r) >> mixbits; |
69 | v[j] = l - r; |
70 | } |
71 | } |
72 | else |
73 | { |
74 | |
75 | for ( j = 0; j < numSamples; j++ ) |
76 | { |
77 | u[j] = in[0] >> 16; |
78 | v[j] = in[1] >> 16; |
79 | in += stride; |
80 | } |
81 | } |
82 | } |
83 | |
84 | |
85 | |
86 | |
87 | void mix20( int32_t * in, uint32_t stride, int32_t * u, int32_t * v, int32_t numSamples, int32_t mixbits, int32_t mixres ) |
88 | { |
89 | int32_t l, r; |
90 | int32_t j; |
91 | |
92 | if ( mixres != 0 ) |
93 | { |
94 | |
95 | int32_t mod = 1 << mixbits; |
96 | int32_t m2 = mod - mixres; |
97 | |
98 | for ( j = 0; j < numSamples; j++ ) |
99 | { |
100 | l = in[0] >> 12; |
101 | r = in[1] >> 12; |
102 | in += stride; |
103 | |
104 | u[j] = (mixres * l + m2 * r) >> mixbits; |
105 | v[j] = l - r; |
106 | } |
107 | } |
108 | else |
109 | { |
110 | |
111 | for ( j = 0; j < numSamples; j++ ) |
112 | { |
113 | u[j] = in[0] >> 12; |
114 | v[j] = in[1] >> 12; |
115 | in += stride; |
116 | } |
117 | } |
118 | } |
119 | |
120 | |
121 | |
122 | |
123 | void mix24( int32_t * in, uint32_t stride, int32_t * u, int32_t * v, int32_t numSamples, |
124 | int32_t mixbits, int32_t mixres, uint16_t * shiftUV, int32_t bytesShifted ) |
125 | { |
126 | int32_t l, r; |
127 | int32_t shift = bytesShifted * 8; |
128 | uint32_t mask = (1ul << shift) - 1; |
129 | int32_t j, k; |
130 | |
131 | if ( mixres != 0 ) |
132 | { |
133 | |
134 | int32_t mod = 1 << mixbits; |
135 | int32_t m2 = mod - mixres; |
136 | |
137 | if ( bytesShifted != 0 ) |
138 | { |
139 | for ( j = 0, k = 0; j < numSamples; j++, k += 2 ) |
140 | { |
141 | l = in[0] >> 8; |
142 | r = in[1] >> 8; |
143 | in += stride; |
144 | |
145 | shiftUV[k + 0] = (uint16_t)(l & mask); |
146 | shiftUV[k + 1] = (uint16_t)(r & mask); |
147 | |
148 | l >>= shift; |
149 | r >>= shift; |
150 | |
151 | u[j] = (mixres * l + m2 * r) >> mixbits; |
152 | v[j] = l - r; |
153 | } |
154 | } |
155 | else |
156 | { |
157 | for ( j = 0; j < numSamples; j++ ) |
158 | { |
159 | l = in[0] >> 8; |
160 | r = in[1] >> 8; |
161 | in += stride; |
162 | |
163 | u[j] = (mixres * l + m2 * r) >> mixbits; |
164 | v[j] = l - r; |
165 | } |
166 | } |
167 | } |
168 | else |
169 | { |
170 | |
171 | if ( bytesShifted != 0 ) |
172 | { |
173 | for ( j = 0, k = 0; j < numSamples; j++, k += 2 ) |
174 | { |
175 | l = in[0] >> 8; |
176 | r = in[1] >> 8; |
177 | in += stride; |
178 | |
179 | shiftUV[k + 0] = (uint16_t)(l & mask); |
180 | shiftUV[k + 1] = (uint16_t)(r & mask); |
181 | |
182 | l >>= shift; |
183 | r >>= shift; |
184 | |
185 | u[j] = l; |
186 | v[j] = r; |
187 | } |
188 | } |
189 | else |
190 | { |
191 | for ( j = 0; j < numSamples; j++ ) |
192 | { |
193 | l = in[0] >> 8; |
| Value stored to 'l' is never read |
194 | r = in[1] >> 8; |
195 | in += stride; |
196 | } |
197 | } |
198 | } |
199 | } |
200 | |
201 | |
202 | |
203 | |
204 | |
205 | |
206 | void mix32( int32_t * in, uint32_t stride, int32_t * u, int32_t * v, int32_t numSamples, |
207 | int32_t mixbits, int32_t mixres, uint16_t * shiftUV, int32_t bytesShifted ) |
208 | { |
209 | int32_t shift = bytesShifted * 8; |
210 | uint32_t mask = (1ul << shift) - 1; |
211 | int32_t l, r; |
212 | int32_t j, k; |
213 | |
214 | if ( mixres != 0 ) |
215 | { |
216 | int32_t mod = 1 << mixbits; |
217 | int32_t m2; |
218 | |
219 | |
220 | |
221 | |
222 | m2 = mod - mixres; |
223 | for ( j = 0, k = 0; j < numSamples; j++, k += 2 ) |
224 | { |
225 | l = in[0]; |
226 | r = in[1]; |
227 | in += stride; |
228 | |
229 | shiftUV[k + 0] = (uint16_t)(l & mask); |
230 | shiftUV[k + 1] = (uint16_t)(r & mask); |
231 | |
232 | l >>= shift; |
233 | r >>= shift; |
234 | |
235 | u[j] = (mixres * l + m2 * r) >> mixbits; |
236 | v[j] = l - r; |
237 | } |
238 | } |
239 | else |
240 | { |
241 | if ( bytesShifted == 0 ) |
242 | { |
243 | |
244 | for ( j = 0; j < numSamples; j++ ) |
245 | { |
246 | u[j] = in[0]; |
247 | v[j] = in[1]; |
248 | in += stride; |
249 | } |
250 | } |
251 | else |
252 | { |
253 | |
254 | for ( j = 0, k = 0; j < numSamples; j++, k += 2 ) |
255 | { |
256 | l = in[0]; |
257 | r = in[1]; |
258 | in += stride; |
259 | |
260 | shiftUV[k + 0] = (uint16_t)(l & mask); |
261 | shiftUV[k + 1] = (uint16_t)(r & mask); |
262 | |
263 | l >>= shift; |
264 | r >>= shift; |
265 | |
266 | u[j] = l; |
267 | v[j] = r; |
268 | } |
269 | } |
270 | } |
271 | } |
272 | |