3394
|
1 /*
|
|
2 * downmix.c
|
|
3 * Copyright (C) 2000-2001 Michel Lespinasse <walken@zoy.org>
|
|
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
|
5 *
|
|
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
|
|
7 * See http://liba52.sourceforge.net/ for updates.
|
|
8 *
|
|
9 * a52dec is free software; you can redistribute it and/or modify
|
|
10 * it under the terms of the GNU General Public License as published by
|
|
11 * the Free Software Foundation; either version 2 of the License, or
|
|
12 * (at your option) any later version.
|
|
13 *
|
|
14 * a52dec is distributed in the hope that it will be useful,
|
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 * GNU General Public License for more details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU General Public License
|
|
20 * along with this program; if not, write to the Free Software
|
|
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
3625
|
22 *
|
|
23 * SSE optimizations from Michael Niedermayer (michaelni@gmx.at)
|
3394
|
24 */
|
|
25
|
|
26 #include "config.h"
|
|
27
|
|
28 #include <string.h>
|
|
29 #include <inttypes.h>
|
|
30
|
|
31 #include "a52.h"
|
|
32 #include "a52_internal.h"
|
|
33
|
|
34 #define CONVERT(acmod,output) (((output) << 3) + (acmod))
|
|
35
|
|
36 int downmix_init (int input, int flags, sample_t * level,
|
|
37 sample_t clev, sample_t slev)
|
|
38 {
|
|
39 static uint8_t table[11][8] = {
|
|
40 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
|
|
41 A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
|
|
42 {A52_MONO, A52_MONO, A52_MONO, A52_MONO,
|
|
43 A52_MONO, A52_MONO, A52_MONO, A52_MONO},
|
|
44 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
|
|
45 A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
|
|
46 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
|
|
47 A52_STEREO, A52_3F, A52_STEREO, A52_3F},
|
|
48 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
|
|
49 A52_2F1R, A52_2F1R, A52_2F1R, A52_2F1R},
|
|
50 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
|
|
51 A52_2F1R, A52_3F1R, A52_2F1R, A52_3F1R},
|
|
52 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
|
|
53 A52_2F2R, A52_2F2R, A52_2F2R, A52_2F2R},
|
|
54 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
|
|
55 A52_2F2R, A52_3F2R, A52_2F2R, A52_3F2R},
|
|
56 {A52_CHANNEL1, A52_MONO, A52_MONO, A52_MONO,
|
|
57 A52_MONO, A52_MONO, A52_MONO, A52_MONO},
|
|
58 {A52_CHANNEL2, A52_MONO, A52_MONO, A52_MONO,
|
|
59 A52_MONO, A52_MONO, A52_MONO, A52_MONO},
|
|
60 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_DOLBY,
|
|
61 A52_DOLBY, A52_DOLBY, A52_DOLBY, A52_DOLBY}
|
|
62 };
|
|
63 int output;
|
|
64
|
|
65 output = flags & A52_CHANNEL_MASK;
|
|
66 if (output > A52_DOLBY)
|
|
67 return -1;
|
3738
|
68
|
3394
|
69 output = table[output][input & 7];
|
|
70
|
|
71 if ((output == A52_STEREO) &&
|
|
72 ((input == A52_DOLBY) || ((input == A52_3F) && (clev == LEVEL_3DB))))
|
|
73 output = A52_DOLBY;
|
|
74
|
|
75 if (flags & A52_ADJUST_LEVEL)
|
|
76 switch (CONVERT (input & 7, output)) {
|
|
77
|
|
78 case CONVERT (A52_3F, A52_MONO):
|
|
79 *level *= LEVEL_3DB / (1 + clev);
|
|
80 break;
|
|
81
|
|
82 case CONVERT (A52_STEREO, A52_MONO):
|
|
83 case CONVERT (A52_2F2R, A52_2F1R):
|
|
84 case CONVERT (A52_3F2R, A52_3F1R):
|
|
85 level_3db:
|
|
86 *level *= LEVEL_3DB;
|
|
87 break;
|
|
88
|
|
89 case CONVERT (A52_3F2R, A52_2F1R):
|
|
90 if (clev < LEVEL_PLUS3DB - 1)
|
|
91 goto level_3db;
|
|
92 /* break thru */
|
|
93 case CONVERT (A52_3F, A52_STEREO):
|
|
94 case CONVERT (A52_3F1R, A52_2F1R):
|
|
95 case CONVERT (A52_3F1R, A52_2F2R):
|
|
96 case CONVERT (A52_3F2R, A52_2F2R):
|
|
97 *level /= 1 + clev;
|
|
98 break;
|
|
99
|
|
100 case CONVERT (A52_2F1R, A52_MONO):
|
|
101 *level *= LEVEL_PLUS3DB / (2 + slev);
|
|
102 break;
|
|
103
|
|
104 case CONVERT (A52_2F1R, A52_STEREO):
|
|
105 case CONVERT (A52_3F1R, A52_3F):
|
|
106 *level /= 1 + slev * LEVEL_3DB;
|
|
107 break;
|
|
108
|
|
109 case CONVERT (A52_3F1R, A52_MONO):
|
|
110 *level *= LEVEL_3DB / (1 + clev + 0.5 * slev);
|
|
111 break;
|
|
112
|
|
113 case CONVERT (A52_3F1R, A52_STEREO):
|
|
114 *level /= 1 + clev + slev * LEVEL_3DB;
|
|
115 break;
|
|
116
|
|
117 case CONVERT (A52_2F2R, A52_MONO):
|
|
118 *level *= LEVEL_3DB / (1 + slev);
|
|
119 break;
|
|
120
|
|
121 case CONVERT (A52_2F2R, A52_STEREO):
|
|
122 case CONVERT (A52_3F2R, A52_3F):
|
|
123 *level /= 1 + slev;
|
|
124 break;
|
|
125
|
|
126 case CONVERT (A52_3F2R, A52_MONO):
|
|
127 *level *= LEVEL_3DB / (1 + clev + slev);
|
|
128 break;
|
|
129
|
|
130 case CONVERT (A52_3F2R, A52_STEREO):
|
|
131 *level /= 1 + clev + slev;
|
|
132 break;
|
|
133
|
|
134 case CONVERT (A52_MONO, A52_DOLBY):
|
|
135 *level *= LEVEL_PLUS3DB;
|
|
136 break;
|
|
137
|
|
138 case CONVERT (A52_3F, A52_DOLBY):
|
|
139 case CONVERT (A52_2F1R, A52_DOLBY):
|
|
140 *level *= 1 / (1 + LEVEL_3DB);
|
|
141 break;
|
|
142
|
|
143 case CONVERT (A52_3F1R, A52_DOLBY):
|
|
144 case CONVERT (A52_2F2R, A52_DOLBY):
|
|
145 *level *= 1 / (1 + 2 * LEVEL_3DB);
|
|
146 break;
|
|
147
|
|
148 case CONVERT (A52_3F2R, A52_DOLBY):
|
|
149 *level *= 1 / (1 + 3 * LEVEL_3DB);
|
|
150 break;
|
|
151 }
|
|
152
|
|
153 return output;
|
|
154 }
|
|
155
|
|
156 int downmix_coeff (sample_t * coeff, int acmod, int output, sample_t level,
|
|
157 sample_t clev, sample_t slev)
|
|
158 {
|
|
159 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
|
|
160
|
|
161 case CONVERT (A52_CHANNEL, A52_CHANNEL):
|
|
162 case CONVERT (A52_MONO, A52_MONO):
|
|
163 case CONVERT (A52_STEREO, A52_STEREO):
|
|
164 case CONVERT (A52_3F, A52_3F):
|
|
165 case CONVERT (A52_2F1R, A52_2F1R):
|
|
166 case CONVERT (A52_3F1R, A52_3F1R):
|
|
167 case CONVERT (A52_2F2R, A52_2F2R):
|
|
168 case CONVERT (A52_3F2R, A52_3F2R):
|
|
169 case CONVERT (A52_STEREO, A52_DOLBY):
|
|
170 coeff[0] = coeff[1] = coeff[2] = coeff[3] = coeff[4] = level;
|
|
171 return 0;
|
|
172
|
|
173 case CONVERT (A52_CHANNEL, A52_MONO):
|
|
174 coeff[0] = coeff[1] = level * LEVEL_6DB;
|
|
175 return 3;
|
|
176
|
|
177 case CONVERT (A52_STEREO, A52_MONO):
|
|
178 coeff[0] = coeff[1] = level * LEVEL_3DB;
|
|
179 return 3;
|
|
180
|
|
181 case CONVERT (A52_3F, A52_MONO):
|
|
182 coeff[0] = coeff[2] = level * LEVEL_3DB;
|
|
183 coeff[1] = level * clev * LEVEL_PLUS3DB;
|
|
184 return 7;
|
|
185
|
|
186 case CONVERT (A52_2F1R, A52_MONO):
|
|
187 coeff[0] = coeff[1] = level * LEVEL_3DB;
|
|
188 coeff[2] = level * slev * LEVEL_3DB;
|
|
189 return 7;
|
|
190
|
|
191 case CONVERT (A52_2F2R, A52_MONO):
|
|
192 coeff[0] = coeff[1] = level * LEVEL_3DB;
|
|
193 coeff[2] = coeff[3] = level * slev * LEVEL_3DB;
|
|
194 return 15;
|
|
195
|
|
196 case CONVERT (A52_3F1R, A52_MONO):
|
|
197 coeff[0] = coeff[2] = level * LEVEL_3DB;
|
|
198 coeff[1] = level * clev * LEVEL_PLUS3DB;
|
|
199 coeff[3] = level * slev * LEVEL_3DB;
|
|
200 return 15;
|
|
201
|
|
202 case CONVERT (A52_3F2R, A52_MONO):
|
|
203 coeff[0] = coeff[2] = level * LEVEL_3DB;
|
|
204 coeff[1] = level * clev * LEVEL_PLUS3DB;
|
|
205 coeff[3] = coeff[4] = level * slev * LEVEL_3DB;
|
|
206 return 31;
|
|
207
|
|
208 case CONVERT (A52_MONO, A52_DOLBY):
|
|
209 coeff[0] = level * LEVEL_3DB;
|
|
210 return 0;
|
|
211
|
|
212 case CONVERT (A52_3F, A52_DOLBY):
|
|
213 clev = LEVEL_3DB;
|
|
214 case CONVERT (A52_3F, A52_STEREO):
|
|
215 case CONVERT (A52_3F1R, A52_2F1R):
|
|
216 case CONVERT (A52_3F2R, A52_2F2R):
|
|
217 coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
|
|
218 coeff[1] = level * clev;
|
|
219 return 7;
|
|
220
|
|
221 case CONVERT (A52_2F1R, A52_DOLBY):
|
|
222 slev = 1;
|
|
223 case CONVERT (A52_2F1R, A52_STEREO):
|
|
224 coeff[0] = coeff[1] = level;
|
|
225 coeff[2] = level * slev * LEVEL_3DB;
|
|
226 return 7;
|
|
227
|
|
228 case CONVERT (A52_3F1R, A52_DOLBY):
|
|
229 clev = LEVEL_3DB;
|
|
230 slev = 1;
|
|
231 case CONVERT (A52_3F1R, A52_STEREO):
|
|
232 coeff[0] = coeff[2] = level;
|
|
233 coeff[1] = level * clev;
|
|
234 coeff[3] = level * slev * LEVEL_3DB;
|
|
235 return 15;
|
|
236
|
|
237 case CONVERT (A52_2F2R, A52_DOLBY):
|
|
238 slev = LEVEL_3DB;
|
|
239 case CONVERT (A52_2F2R, A52_STEREO):
|
|
240 coeff[0] = coeff[1] = level;
|
|
241 coeff[2] = coeff[3] = level * slev;
|
|
242 return 15;
|
|
243
|
|
244 case CONVERT (A52_3F2R, A52_DOLBY):
|
|
245 clev = LEVEL_3DB;
|
|
246 case CONVERT (A52_3F2R, A52_2F1R):
|
|
247 slev = LEVEL_3DB;
|
|
248 case CONVERT (A52_3F2R, A52_STEREO):
|
|
249 coeff[0] = coeff[2] = level;
|
|
250 coeff[1] = level * clev;
|
|
251 coeff[3] = coeff[4] = level * slev;
|
|
252 return 31;
|
|
253
|
|
254 case CONVERT (A52_3F1R, A52_3F):
|
|
255 coeff[0] = coeff[1] = coeff[2] = level;
|
|
256 coeff[3] = level * slev * LEVEL_3DB;
|
|
257 return 13;
|
|
258
|
|
259 case CONVERT (A52_3F2R, A52_3F):
|
|
260 coeff[0] = coeff[1] = coeff[2] = level;
|
|
261 coeff[3] = coeff[4] = level * slev;
|
|
262 return 29;
|
|
263
|
|
264 case CONVERT (A52_2F2R, A52_2F1R):
|
|
265 coeff[0] = coeff[1] = level;
|
|
266 coeff[2] = coeff[3] = level * LEVEL_3DB;
|
|
267 return 12;
|
|
268
|
|
269 case CONVERT (A52_3F2R, A52_3F1R):
|
|
270 coeff[0] = coeff[1] = coeff[2] = level;
|
|
271 coeff[3] = coeff[4] = level * LEVEL_3DB;
|
|
272 return 24;
|
|
273
|
|
274 case CONVERT (A52_2F1R, A52_2F2R):
|
|
275 coeff[0] = coeff[1] = level;
|
|
276 coeff[2] = level * LEVEL_3DB;
|
|
277 return 0;
|
|
278
|
|
279 case CONVERT (A52_3F1R, A52_2F2R):
|
|
280 coeff[0] = coeff[2] = level;
|
|
281 coeff[1] = level * clev;
|
|
282 coeff[3] = level * LEVEL_3DB;
|
|
283 return 7;
|
|
284
|
|
285 case CONVERT (A52_3F1R, A52_3F2R):
|
|
286 coeff[0] = coeff[1] = coeff[2] = level;
|
|
287 coeff[3] = level * LEVEL_3DB;
|
|
288 return 0;
|
|
289
|
|
290 case CONVERT (A52_CHANNEL, A52_CHANNEL1):
|
|
291 coeff[0] = level;
|
|
292 coeff[1] = 0;
|
|
293 return 0;
|
|
294
|
|
295 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
|
|
296 coeff[0] = 0;
|
|
297 coeff[1] = level;
|
|
298 return 0;
|
|
299 }
|
|
300
|
|
301 return -1; /* NOTREACHED */
|
|
302 }
|
|
303
|
|
304 static void mix2to1 (sample_t * dest, sample_t * src, sample_t bias)
|
|
305 {
|
|
306 int i;
|
|
307
|
3675
|
308 #ifdef HAVE_SSE
|
|
309 asm volatile(
|
|
310 "movlps %2, %%xmm7 \n\t"
|
|
311 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
312 "movl $-1024, %%esi \n\t"
|
|
313 "1: \n\t"
|
|
314 "movaps (%0, %%esi), %%xmm0 \n\t"
|
|
315 "movaps 16(%0, %%esi), %%xmm1 \n\t"
|
|
316 "addps (%1, %%esi), %%xmm0 \n\t"
|
|
317 "addps 16(%1, %%esi), %%xmm1 \n\t"
|
|
318 "addps %%xmm7, %%xmm0 \n\t"
|
|
319 "addps %%xmm7, %%xmm1 \n\t"
|
|
320 "movaps %%xmm0, (%1, %%esi) \n\t"
|
|
321 "movaps %%xmm1, 16(%1, %%esi) \n\t"
|
|
322 "addl $32, %%esi \n\t"
|
|
323 " jnz 1b \n\t"
|
|
324 :: "r" (src+256), "r" (dest+256), "m" (bias)
|
|
325 : "%esi"
|
|
326 );
|
|
327 #else
|
3394
|
328 for (i = 0; i < 256; i++)
|
|
329 dest[i] += src[i] + bias;
|
3675
|
330 #endif
|
3394
|
331 }
|
|
332
|
|
333 static void mix3to1 (sample_t * samples, sample_t bias)
|
|
334 {
|
|
335 int i;
|
|
336
|
3679
|
337 #ifdef HAVE_SSE
|
|
338 asm volatile(
|
|
339 "movlps %1, %%xmm7 \n\t"
|
|
340 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
341 "movl $-1024, %%esi \n\t"
|
|
342 "1: \n\t"
|
|
343 "movaps (%0, %%esi), %%xmm0 \n\t"
|
|
344 "movaps 1024(%0, %%esi), %%xmm1 \n\t"
|
|
345 "addps 2048(%0, %%esi), %%xmm0 \n\t"
|
|
346 "addps %%xmm7, %%xmm1 \n\t"
|
|
347 "addps %%xmm1, %%xmm0 \n\t"
|
|
348 "movaps %%xmm0, (%0, %%esi) \n\t"
|
|
349 "addl $16, %%esi \n\t"
|
|
350 " jnz 1b \n\t"
|
|
351 :: "r" (samples+256), "m" (bias)
|
|
352 : "%esi"
|
|
353 );
|
|
354 #else
|
3394
|
355 for (i = 0; i < 256; i++)
|
|
356 samples[i] += samples[i + 256] + samples[i + 512] + bias;
|
3679
|
357 #endif
|
3394
|
358 }
|
|
359
|
|
360 static void mix4to1 (sample_t * samples, sample_t bias)
|
|
361 {
|
|
362 int i;
|
|
363
|
3679
|
364 #ifdef HAVE_SSE
|
3677
|
365 asm volatile(
|
|
366 "movlps %1, %%xmm7 \n\t"
|
|
367 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
368 "movl $-1024, %%esi \n\t"
|
|
369 "1: \n\t"
|
|
370 "movaps (%0, %%esi), %%xmm0 \n\t"
|
|
371 "movaps 1024(%0, %%esi), %%xmm1 \n\t"
|
|
372 "addps 2048(%0, %%esi), %%xmm0 \n\t"
|
|
373 "addps 3072(%0, %%esi), %%xmm1 \n\t"
|
|
374 "addps %%xmm7, %%xmm0 \n\t"
|
|
375 "addps %%xmm1, %%xmm0 \n\t"
|
|
376 "movaps %%xmm0, (%0, %%esi) \n\t"
|
|
377 "addl $16, %%esi \n\t"
|
|
378 " jnz 1b \n\t"
|
|
379 :: "r" (samples+256), "m" (bias)
|
|
380 : "%esi"
|
|
381 );
|
|
382 #else
|
3394
|
383 for (i = 0; i < 256; i++)
|
|
384 samples[i] += (samples[i + 256] + samples[i + 512] +
|
|
385 samples[i + 768] + bias);
|
3677
|
386 #endif
|
3394
|
387 }
|
|
388
|
|
389 static void mix5to1 (sample_t * samples, sample_t bias)
|
|
390 {
|
|
391 int i;
|
|
392
|
3677
|
393 #ifdef HAVE_SSE
|
|
394 asm volatile(
|
|
395 "movlps %1, %%xmm7 \n\t"
|
|
396 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
397 "movl $-1024, %%esi \n\t"
|
|
398 "1: \n\t"
|
|
399 "movaps (%0, %%esi), %%xmm0 \n\t"
|
|
400 "movaps 1024(%0, %%esi), %%xmm1 \n\t"
|
|
401 "addps 2048(%0, %%esi), %%xmm0 \n\t"
|
|
402 "addps 3072(%0, %%esi), %%xmm1 \n\t"
|
|
403 "addps %%xmm7, %%xmm0 \n\t"
|
|
404 "addps 4096(%0, %%esi), %%xmm1 \n\t"
|
|
405 "addps %%xmm1, %%xmm0 \n\t"
|
|
406 "movaps %%xmm0, (%0, %%esi) \n\t"
|
|
407 "addl $16, %%esi \n\t"
|
|
408 " jnz 1b \n\t"
|
|
409 :: "r" (samples+256), "m" (bias)
|
|
410 : "%esi"
|
|
411 );
|
|
412 #else
|
3394
|
413 for (i = 0; i < 256; i++)
|
|
414 samples[i] += (samples[i + 256] + samples[i + 512] +
|
|
415 samples[i + 768] + samples[i + 1024] + bias);
|
3677
|
416 #endif
|
3394
|
417 }
|
|
418
|
|
419 static void mix3to2 (sample_t * samples, sample_t bias)
|
|
420 {
|
|
421 int i;
|
|
422 sample_t common;
|
|
423
|
3678
|
424 #ifdef HAVE_SSE
|
|
425 asm volatile(
|
|
426 "movlps %1, %%xmm7 \n\t"
|
|
427 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
428 "movl $-1024, %%esi \n\t"
|
|
429 "1: \n\t"
|
|
430 "movaps 1024(%0, %%esi), %%xmm0 \n\t"
|
|
431 "addps %%xmm7, %%xmm0 \n\t" //common
|
|
432 "movaps (%0, %%esi), %%xmm1 \n\t"
|
|
433 "movaps 2048(%0, %%esi), %%xmm2 \n\t"
|
|
434 "addps %%xmm0, %%xmm1 \n\t"
|
|
435 "addps %%xmm0, %%xmm2 \n\t"
|
|
436 "movaps %%xmm1, (%0, %%esi) \n\t"
|
|
437 "movaps %%xmm2, 1024(%0, %%esi) \n\t"
|
|
438 "addl $16, %%esi \n\t"
|
|
439 " jnz 1b \n\t"
|
|
440 :: "r" (samples+256), "m" (bias)
|
|
441 : "%esi"
|
|
442 );
|
|
443 #else
|
3394
|
444 for (i = 0; i < 256; i++) {
|
|
445 common = samples[i + 256] + bias;
|
|
446 samples[i] += common;
|
|
447 samples[i + 256] = samples[i + 512] + common;
|
|
448 }
|
3678
|
449 #endif
|
3394
|
450 }
|
|
451
|
|
452 static void mix21to2 (sample_t * left, sample_t * right, sample_t bias)
|
|
453 {
|
|
454 int i;
|
|
455 sample_t common;
|
|
456
|
3739
|
457 #ifdef HAVE_SSE
|
|
458 asm volatile(
|
|
459 "movlps %2, %%xmm7 \n\t"
|
|
460 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
461 "movl $-1024, %%esi \n\t"
|
|
462 "1: \n\t"
|
|
463 "movaps 1024(%1, %%esi), %%xmm0 \n\t"
|
|
464 "addps %%xmm7, %%xmm0 \n\t" //common
|
|
465 "movaps (%0, %%esi), %%xmm1 \n\t"
|
|
466 "movaps (%1, %%esi), %%xmm2 \n\t"
|
|
467 "addps %%xmm0, %%xmm1 \n\t"
|
|
468 "addps %%xmm0, %%xmm2 \n\t"
|
|
469 "movaps %%xmm1, (%0, %%esi) \n\t"
|
|
470 "movaps %%xmm2, (%1, %%esi) \n\t"
|
|
471 "addl $16, %%esi \n\t"
|
|
472 " jnz 1b \n\t"
|
|
473 :: "r" (left+256), "r" (right+256), "m" (bias)
|
|
474 : "%esi"
|
|
475 );
|
|
476 #else
|
3394
|
477 for (i = 0; i < 256; i++) {
|
|
478 common = right[i + 256] + bias;
|
|
479 left[i] += common;
|
|
480 right[i] += common;
|
|
481 }
|
3739
|
482 #endif
|
3394
|
483 }
|
|
484
|
|
485 static void mix21toS (sample_t * samples, sample_t bias)
|
|
486 {
|
|
487 int i;
|
|
488 sample_t surround;
|
|
489
|
3739
|
490 #ifdef HAVE_SSE
|
|
491 asm volatile(
|
|
492 "movlps %1, %%xmm7 \n\t"
|
|
493 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
494 "movl $-1024, %%esi \n\t"
|
|
495 "1: \n\t"
|
|
496 "movaps 2048(%0, %%esi), %%xmm0 \n\t" // surround
|
|
497 "movaps (%0, %%esi), %%xmm1 \n\t"
|
|
498 "movaps 1024(%0, %%esi), %%xmm2 \n\t"
|
|
499 "addps %%xmm7, %%xmm1 \n\t"
|
|
500 "addps %%xmm7, %%xmm2 \n\t"
|
|
501 "subps %%xmm0, %%xmm1 \n\t"
|
|
502 "addps %%xmm0, %%xmm2 \n\t"
|
|
503 "movaps %%xmm1, (%0, %%esi) \n\t"
|
|
504 "movaps %%xmm2, 1024(%0, %%esi) \n\t"
|
|
505 "addl $16, %%esi \n\t"
|
|
506 " jnz 1b \n\t"
|
|
507 :: "r" (samples+256), "m" (bias)
|
|
508 : "%esi"
|
|
509 );
|
|
510 #else
|
3394
|
511 for (i = 0; i < 256; i++) {
|
|
512 surround = samples[i + 512];
|
|
513 samples[i] += bias - surround;
|
|
514 samples[i + 256] += bias + surround;
|
|
515 }
|
3739
|
516 #endif
|
3394
|
517 }
|
|
518
|
|
519 static void mix31to2 (sample_t * samples, sample_t bias)
|
|
520 {
|
|
521 int i;
|
|
522 sample_t common;
|
|
523
|
3740
|
524 #ifdef HAVE_SSE
|
|
525 asm volatile(
|
|
526 "movlps %1, %%xmm7 \n\t"
|
|
527 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
528 "movl $-1024, %%esi \n\t"
|
|
529 "1: \n\t"
|
|
530 "movaps 1024(%0, %%esi), %%xmm0 \n\t"
|
|
531 "addps 3072(%0, %%esi), %%xmm0 \n\t"
|
|
532 "addps %%xmm7, %%xmm0 \n\t" // common
|
|
533 "movaps (%0, %%esi), %%xmm1 \n\t"
|
|
534 "movaps 2048(%0, %%esi), %%xmm2 \n\t"
|
|
535 "addps %%xmm0, %%xmm1 \n\t"
|
|
536 "addps %%xmm0, %%xmm2 \n\t"
|
|
537 "movaps %%xmm1, (%0, %%esi) \n\t"
|
|
538 "movaps %%xmm2, 1024(%0, %%esi) \n\t"
|
|
539 "addl $16, %%esi \n\t"
|
|
540 " jnz 1b \n\t"
|
|
541 :: "r" (samples+256), "m" (bias)
|
|
542 : "%esi"
|
|
543 );
|
|
544 #else
|
3394
|
545 for (i = 0; i < 256; i++) {
|
|
546 common = samples[i + 256] + samples[i + 768] + bias;
|
|
547 samples[i] += common;
|
|
548 samples[i + 256] = samples[i + 512] + common;
|
|
549 }
|
3740
|
550 #endif
|
3394
|
551 }
|
|
552
|
|
553 static void mix31toS (sample_t * samples, sample_t bias)
|
|
554 {
|
|
555 int i;
|
|
556 sample_t common, surround;
|
|
557
|
3740
|
558 #ifdef HAVE_SSE
|
|
559 asm volatile(
|
|
560 "movlps %1, %%xmm7 \n\t"
|
|
561 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
562 "movl $-1024, %%esi \n\t"
|
|
563 "1: \n\t"
|
|
564 "movaps 1024(%0, %%esi), %%xmm0 \n\t"
|
|
565 "movaps 3072(%0, %%esi), %%xmm3 \n\t" // surround
|
|
566 "addps %%xmm7, %%xmm0 \n\t" // common
|
|
567 "movaps (%0, %%esi), %%xmm1 \n\t"
|
|
568 "movaps 2048(%0, %%esi), %%xmm2 \n\t"
|
|
569 "addps %%xmm0, %%xmm1 \n\t"
|
|
570 "addps %%xmm0, %%xmm2 \n\t"
|
|
571 "subps %%xmm3, %%xmm1 \n\t"
|
|
572 "addps %%xmm3, %%xmm2 \n\t"
|
|
573 "movaps %%xmm1, (%0, %%esi) \n\t"
|
|
574 "movaps %%xmm2, 1024(%0, %%esi) \n\t"
|
|
575 "addl $16, %%esi \n\t"
|
|
576 " jnz 1b \n\t"
|
|
577 :: "r" (samples+256), "m" (bias)
|
|
578 : "%esi"
|
|
579 );
|
|
580 #else
|
3394
|
581 for (i = 0; i < 256; i++) {
|
|
582 common = samples[i + 256] + bias;
|
|
583 surround = samples[i + 768];
|
|
584 samples[i] += common - surround;
|
|
585 samples[i + 256] = samples[i + 512] + common + surround;
|
|
586 }
|
3740
|
587 #endif
|
3394
|
588 }
|
|
589
|
|
590 static void mix22toS (sample_t * samples, sample_t bias)
|
|
591 {
|
|
592 int i;
|
|
593 sample_t surround;
|
|
594
|
3741
|
595 #ifdef HAVE_SSE
|
|
596 asm volatile(
|
|
597 "movlps %1, %%xmm7 \n\t"
|
|
598 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
599 "movl $-1024, %%esi \n\t"
|
|
600 "1: \n\t"
|
|
601 "movaps 2048(%0, %%esi), %%xmm0 \n\t"
|
|
602 "addps 3072(%0, %%esi), %%xmm0 \n\t" // surround
|
|
603 "movaps (%0, %%esi), %%xmm1 \n\t"
|
|
604 "movaps 1024(%0, %%esi), %%xmm2 \n\t"
|
|
605 "addps %%xmm7, %%xmm1 \n\t"
|
|
606 "addps %%xmm7, %%xmm2 \n\t"
|
|
607 "subps %%xmm0, %%xmm1 \n\t"
|
|
608 "addps %%xmm0, %%xmm2 \n\t"
|
|
609 "movaps %%xmm1, (%0, %%esi) \n\t"
|
|
610 "movaps %%xmm2, 1024(%0, %%esi) \n\t"
|
|
611 "addl $16, %%esi \n\t"
|
|
612 " jnz 1b \n\t"
|
|
613 :: "r" (samples+256), "m" (bias)
|
|
614 : "%esi"
|
|
615 );
|
|
616 #else
|
3394
|
617 for (i = 0; i < 256; i++) {
|
|
618 surround = samples[i + 512] + samples[i + 768];
|
|
619 samples[i] += bias - surround;
|
|
620 samples[i + 256] += bias + surround;
|
|
621 }
|
3741
|
622 #endif
|
3394
|
623 }
|
|
624
|
|
625 static void mix32to2 (sample_t * samples, sample_t bias)
|
|
626 {
|
|
627 int i;
|
|
628 sample_t common;
|
|
629
|
3624
|
630 #ifdef HAVE_SSE
|
|
631 asm volatile(
|
|
632 "movlps %1, %%xmm7 \n\t"
|
|
633 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
634 "movl $-1024, %%esi \n\t"
|
|
635 "1: \n\t"
|
|
636 "movaps 1024(%0, %%esi), %%xmm0 \n\t"
|
|
637 "addps %%xmm7, %%xmm0 \n\t" // common
|
|
638 "movaps %%xmm0, %%xmm1 \n\t" // common
|
|
639 "addps (%0, %%esi), %%xmm0 \n\t"
|
|
640 "addps 2048(%0, %%esi), %%xmm1 \n\t"
|
|
641 "addps 3072(%0, %%esi), %%xmm0 \n\t"
|
|
642 "addps 4096(%0, %%esi), %%xmm1 \n\t"
|
|
643 "movaps %%xmm0, (%0, %%esi) \n\t"
|
|
644 "movaps %%xmm1, 1024(%0, %%esi) \n\t"
|
|
645 "addl $16, %%esi \n\t"
|
|
646 " jnz 1b \n\t"
|
|
647 :: "r" (samples+256), "m" (bias)
|
|
648 : "%esi"
|
|
649 );
|
|
650 #else
|
3394
|
651 for (i = 0; i < 256; i++) {
|
|
652 common = samples[i + 256] + bias;
|
|
653 samples[i] += common + samples[i + 768];
|
|
654 samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
|
|
655 }
|
3624
|
656 #endif
|
3394
|
657 }
|
|
658
|
|
659 static void mix32toS (sample_t * samples, sample_t bias)
|
|
660 {
|
|
661 int i;
|
|
662 sample_t common, surround;
|
|
663
|
3625
|
664 #ifdef HAVE_SSE
|
|
665 asm volatile(
|
|
666 "movlps %1, %%xmm7 \n\t"
|
|
667 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
668 "movl $-1024, %%esi \n\t"
|
|
669 "1: \n\t"
|
|
670 "movaps 1024(%0, %%esi), %%xmm0 \n\t"
|
|
671 "movaps 3072(%0, %%esi), %%xmm2 \n\t"
|
|
672 "addps %%xmm7, %%xmm0 \n\t" // common
|
|
673 "addps 4096(%0, %%esi), %%xmm2 \n\t" // surround
|
|
674 "movaps (%0, %%esi), %%xmm1 \n\t"
|
|
675 "movaps 2048(%0, %%esi), %%xmm3 \n\t"
|
|
676 "subps %%xmm2, %%xmm1 \n\t"
|
|
677 "addps %%xmm2, %%xmm3 \n\t"
|
|
678 "addps %%xmm0, %%xmm1 \n\t"
|
|
679 "addps %%xmm0, %%xmm3 \n\t"
|
|
680 "movaps %%xmm1, (%0, %%esi) \n\t"
|
|
681 "movaps %%xmm3, 1024(%0, %%esi) \n\t"
|
|
682 "addl $16, %%esi \n\t"
|
|
683 " jnz 1b \n\t"
|
|
684 :: "r" (samples+256), "m" (bias)
|
|
685 : "%esi"
|
|
686 );
|
|
687 #else
|
3394
|
688 for (i = 0; i < 256; i++) {
|
|
689 common = samples[i + 256] + bias;
|
|
690 surround = samples[i + 768] + samples[i + 1024];
|
|
691 samples[i] += common - surround;
|
|
692 samples[i + 256] = samples[i + 512] + common + surround;
|
|
693 }
|
3625
|
694 #endif
|
3394
|
695 }
|
|
696
|
|
697 static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
|
|
698 {
|
|
699 int i;
|
|
700
|
3741
|
701 #ifdef HAVE_SSE
|
|
702 asm volatile(
|
|
703 "movlps %2, %%xmm7 \n\t"
|
|
704 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
705 "movl $-1024, %%esi \n\t"
|
|
706 "1: \n\t"
|
|
707 "movaps (%0, %%esi), %%xmm0 \n\t"
|
|
708 "movaps 16(%0, %%esi), %%xmm1 \n\t"
|
|
709 "addps 1024(%0, %%esi), %%xmm0 \n\t"
|
|
710 "addps 1040(%0, %%esi), %%xmm1 \n\t"
|
|
711 "addps %%xmm7, %%xmm0 \n\t"
|
|
712 "addps %%xmm7, %%xmm1 \n\t"
|
|
713 "movaps %%xmm0, (%1, %%esi) \n\t"
|
|
714 "movaps %%xmm1, 16(%1, %%esi) \n\t"
|
|
715 "addl $32, %%esi \n\t"
|
|
716 " jnz 1b \n\t"
|
|
717 :: "r" (src+256), "r" (dest+256), "m" (bias)
|
|
718 : "%esi"
|
|
719 );
|
|
720 #else
|
3394
|
721 for (i = 0; i < 256; i++)
|
|
722 dest[i] = src[i] + src[i + 256] + bias;
|
3741
|
723 #endif
|
3394
|
724 }
|
|
725
|
|
726 static void zero (sample_t * samples)
|
|
727 {
|
|
728 int i;
|
3738
|
729 #ifdef HAVE_MMX
|
|
730 asm volatile(
|
|
731 "movl $-1024, %%esi \n\t"
|
|
732 "pxor %%mm0, %%mm0 \n\t"
|
|
733 "1: \n\t"
|
|
734 "movq %%mm0, (%0, %%esi) \n\t"
|
|
735 "movq %%mm0, 8(%0, %%esi) \n\t"
|
|
736 "movq %%mm0, 16(%0, %%esi) \n\t"
|
|
737 "movq %%mm0, 24(%0, %%esi) \n\t"
|
|
738 "addl $32, %%esi \n\t"
|
|
739 " jnz 1b \n\t"
|
|
740 "emms"
|
|
741 :: "r" (samples+256)
|
|
742 : "%esi"
|
|
743 );
|
|
744 #else
|
3394
|
745 for (i = 0; i < 256; i++)
|
|
746 samples[i] = 0;
|
3738
|
747 #endif
|
3394
|
748 }
|
|
749
|
|
750 void downmix (sample_t * samples, int acmod, int output, sample_t bias,
|
|
751 sample_t clev, sample_t slev)
|
|
752 {
|
|
753 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
|
|
754
|
|
755 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
|
|
756 memcpy (samples, samples + 256, 256 * sizeof (sample_t));
|
|
757 break;
|
|
758
|
|
759 case CONVERT (A52_CHANNEL, A52_MONO):
|
|
760 case CONVERT (A52_STEREO, A52_MONO):
|
|
761 mix_2to1:
|
|
762 mix2to1 (samples, samples + 256, bias);
|
|
763 break;
|
|
764
|
|
765 case CONVERT (A52_2F1R, A52_MONO):
|
|
766 if (slev == 0)
|
|
767 goto mix_2to1;
|
|
768 case CONVERT (A52_3F, A52_MONO):
|
|
769 mix_3to1:
|
|
770 mix3to1 (samples, bias);
|
|
771 break;
|
|
772
|
|
773 case CONVERT (A52_3F1R, A52_MONO):
|
|
774 if (slev == 0)
|
|
775 goto mix_3to1;
|
|
776 case CONVERT (A52_2F2R, A52_MONO):
|
|
777 if (slev == 0)
|
|
778 goto mix_2to1;
|
|
779 mix4to1 (samples, bias);
|
|
780 break;
|
|
781
|
|
782 case CONVERT (A52_3F2R, A52_MONO):
|
|
783 if (slev == 0)
|
|
784 goto mix_3to1;
|
|
785 mix5to1 (samples, bias);
|
|
786 break;
|
|
787
|
|
788 case CONVERT (A52_MONO, A52_DOLBY):
|
|
789 memcpy (samples + 256, samples, 256 * sizeof (sample_t));
|
|
790 break;
|
|
791
|
|
792 case CONVERT (A52_3F, A52_STEREO):
|
|
793 case CONVERT (A52_3F, A52_DOLBY):
|
|
794 mix_3to2:
|
|
795 mix3to2 (samples, bias);
|
|
796 break;
|
|
797
|
|
798 case CONVERT (A52_2F1R, A52_STEREO):
|
|
799 if (slev == 0)
|
|
800 break;
|
|
801 mix21to2 (samples, samples + 256, bias);
|
|
802 break;
|
|
803
|
|
804 case CONVERT (A52_2F1R, A52_DOLBY):
|
|
805 mix21toS (samples, bias);
|
|
806 break;
|
|
807
|
|
808 case CONVERT (A52_3F1R, A52_STEREO):
|
|
809 if (slev == 0)
|
|
810 goto mix_3to2;
|
|
811 mix31to2 (samples, bias);
|
|
812 break;
|
|
813
|
|
814 case CONVERT (A52_3F1R, A52_DOLBY):
|
|
815 mix31toS (samples, bias);
|
|
816 break;
|
|
817
|
|
818 case CONVERT (A52_2F2R, A52_STEREO):
|
|
819 if (slev == 0)
|
|
820 break;
|
|
821 mix2to1 (samples, samples + 512, bias);
|
|
822 mix2to1 (samples + 256, samples + 768, bias);
|
|
823 break;
|
|
824
|
|
825 case CONVERT (A52_2F2R, A52_DOLBY):
|
|
826 mix22toS (samples, bias);
|
|
827 break;
|
|
828
|
|
829 case CONVERT (A52_3F2R, A52_STEREO):
|
|
830 if (slev == 0)
|
|
831 goto mix_3to2;
|
|
832 mix32to2 (samples, bias);
|
|
833 break;
|
|
834
|
|
835 case CONVERT (A52_3F2R, A52_DOLBY):
|
|
836 mix32toS (samples, bias);
|
|
837 break;
|
|
838
|
|
839 case CONVERT (A52_3F1R, A52_3F):
|
|
840 if (slev == 0)
|
|
841 break;
|
|
842 mix21to2 (samples, samples + 512, bias);
|
|
843 break;
|
|
844
|
|
845 case CONVERT (A52_3F2R, A52_3F):
|
|
846 if (slev == 0)
|
|
847 break;
|
|
848 mix2to1 (samples, samples + 768, bias);
|
|
849 mix2to1 (samples + 512, samples + 1024, bias);
|
|
850 break;
|
|
851
|
|
852 case CONVERT (A52_3F1R, A52_2F1R):
|
|
853 mix3to2 (samples, bias);
|
|
854 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
|
|
855 break;
|
|
856
|
|
857 case CONVERT (A52_2F2R, A52_2F1R):
|
|
858 mix2to1 (samples + 512, samples + 768, bias);
|
|
859 break;
|
|
860
|
|
861 case CONVERT (A52_3F2R, A52_2F1R):
|
3678
|
862 mix3to2 (samples, bias); //FIXME possible bug? (output doesnt seem to be used)
|
3394
|
863 move2to1 (samples + 768, samples + 512, bias);
|
|
864 break;
|
|
865
|
|
866 case CONVERT (A52_3F2R, A52_3F1R):
|
|
867 mix2to1 (samples + 768, samples + 1024, bias);
|
|
868 break;
|
|
869
|
|
870 case CONVERT (A52_2F1R, A52_2F2R):
|
|
871 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
|
|
872 break;
|
|
873
|
|
874 case CONVERT (A52_3F1R, A52_2F2R):
|
|
875 mix3to2 (samples, bias);
|
|
876 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
|
|
877 break;
|
|
878
|
|
879 case CONVERT (A52_3F2R, A52_2F2R):
|
|
880 mix3to2 (samples, bias);
|
|
881 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
|
|
882 memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
|
|
883 break;
|
|
884
|
|
885 case CONVERT (A52_3F1R, A52_3F2R):
|
|
886 memcpy (samples + 1027, samples + 768, 256 * sizeof (sample_t));
|
|
887 break;
|
|
888 }
|
|
889 }
|
|
890
|
|
891 void upmix (sample_t * samples, int acmod, int output)
|
|
892 {
|
|
893 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
|
|
894
|
|
895 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
|
|
896 memcpy (samples + 256, samples, 256 * sizeof (sample_t));
|
|
897 break;
|
|
898
|
|
899 case CONVERT (A52_3F2R, A52_MONO):
|
|
900 zero (samples + 1024);
|
|
901 case CONVERT (A52_3F1R, A52_MONO):
|
|
902 case CONVERT (A52_2F2R, A52_MONO):
|
|
903 zero (samples + 768);
|
|
904 case CONVERT (A52_3F, A52_MONO):
|
|
905 case CONVERT (A52_2F1R, A52_MONO):
|
|
906 zero (samples + 512);
|
|
907 case CONVERT (A52_CHANNEL, A52_MONO):
|
|
908 case CONVERT (A52_STEREO, A52_MONO):
|
|
909 zero (samples + 256);
|
|
910 break;
|
|
911
|
|
912 case CONVERT (A52_3F2R, A52_STEREO):
|
|
913 case CONVERT (A52_3F2R, A52_DOLBY):
|
|
914 zero (samples + 1024);
|
|
915 case CONVERT (A52_3F1R, A52_STEREO):
|
|
916 case CONVERT (A52_3F1R, A52_DOLBY):
|
|
917 zero (samples + 768);
|
|
918 case CONVERT (A52_3F, A52_STEREO):
|
|
919 case CONVERT (A52_3F, A52_DOLBY):
|
|
920 mix_3to2:
|
|
921 memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
|
|
922 zero (samples + 256);
|
|
923 break;
|
|
924
|
|
925 case CONVERT (A52_2F2R, A52_STEREO):
|
|
926 case CONVERT (A52_2F2R, A52_DOLBY):
|
|
927 zero (samples + 768);
|
|
928 case CONVERT (A52_2F1R, A52_STEREO):
|
|
929 case CONVERT (A52_2F1R, A52_DOLBY):
|
|
930 zero (samples + 512);
|
|
931 break;
|
|
932
|
|
933 case CONVERT (A52_3F2R, A52_3F):
|
|
934 zero (samples + 1024);
|
|
935 case CONVERT (A52_3F1R, A52_3F):
|
|
936 case CONVERT (A52_2F2R, A52_2F1R):
|
|
937 zero (samples + 768);
|
|
938 break;
|
|
939
|
|
940 case CONVERT (A52_3F2R, A52_3F1R):
|
|
941 zero (samples + 1024);
|
|
942 break;
|
|
943
|
|
944 case CONVERT (A52_3F2R, A52_2F1R):
|
|
945 zero (samples + 1024);
|
|
946 case CONVERT (A52_3F1R, A52_2F1R):
|
|
947 mix_31to21:
|
|
948 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
|
|
949 goto mix_3to2;
|
|
950
|
|
951 case CONVERT (A52_3F2R, A52_2F2R):
|
|
952 memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
|
|
953 goto mix_31to21;
|
|
954 }
|
|
955 }
|