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;
|
|
68
|
|
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
|
|
457 for (i = 0; i < 256; i++) {
|
|
458 common = right[i + 256] + bias;
|
|
459 left[i] += common;
|
|
460 right[i] += common;
|
|
461 }
|
|
462 }
|
|
463
|
|
464 static void mix21toS (sample_t * samples, sample_t bias)
|
|
465 {
|
|
466 int i;
|
|
467 sample_t surround;
|
|
468
|
|
469 for (i = 0; i < 256; i++) {
|
|
470 surround = samples[i + 512];
|
|
471 samples[i] += bias - surround;
|
|
472 samples[i + 256] += bias + surround;
|
|
473 }
|
|
474 }
|
|
475
|
|
476 static void mix31to2 (sample_t * samples, sample_t bias)
|
|
477 {
|
|
478 int i;
|
|
479 sample_t common;
|
|
480
|
|
481 for (i = 0; i < 256; i++) {
|
|
482 common = samples[i + 256] + samples[i + 768] + bias;
|
|
483 samples[i] += common;
|
|
484 samples[i + 256] = samples[i + 512] + common;
|
|
485 }
|
|
486 }
|
|
487
|
|
488 static void mix31toS (sample_t * samples, sample_t bias)
|
|
489 {
|
|
490 int i;
|
|
491 sample_t common, surround;
|
|
492
|
|
493 for (i = 0; i < 256; i++) {
|
|
494 common = samples[i + 256] + bias;
|
|
495 surround = samples[i + 768];
|
|
496 samples[i] += common - surround;
|
|
497 samples[i + 256] = samples[i + 512] + common + surround;
|
|
498 }
|
|
499 }
|
|
500
|
|
501 static void mix22toS (sample_t * samples, sample_t bias)
|
|
502 {
|
|
503 int i;
|
|
504 sample_t surround;
|
|
505
|
|
506 for (i = 0; i < 256; i++) {
|
|
507 surround = samples[i + 512] + samples[i + 768];
|
|
508 samples[i] += bias - surround;
|
|
509 samples[i + 256] += bias + surround;
|
|
510 }
|
|
511 }
|
|
512
|
|
513 static void mix32to2 (sample_t * samples, sample_t bias)
|
|
514 {
|
|
515 int i;
|
|
516 sample_t common;
|
|
517
|
3624
|
518 #ifdef HAVE_SSE
|
|
519 asm volatile(
|
|
520 "movlps %1, %%xmm7 \n\t"
|
|
521 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
522 "movl $-1024, %%esi \n\t"
|
|
523 "1: \n\t"
|
|
524 "movaps 1024(%0, %%esi), %%xmm0 \n\t"
|
|
525 "addps %%xmm7, %%xmm0 \n\t" // common
|
|
526 "movaps %%xmm0, %%xmm1 \n\t" // common
|
|
527 "addps (%0, %%esi), %%xmm0 \n\t"
|
|
528 "addps 2048(%0, %%esi), %%xmm1 \n\t"
|
|
529 "addps 3072(%0, %%esi), %%xmm0 \n\t"
|
|
530 "addps 4096(%0, %%esi), %%xmm1 \n\t"
|
|
531 "movaps %%xmm0, (%0, %%esi) \n\t"
|
|
532 "movaps %%xmm1, 1024(%0, %%esi) \n\t"
|
|
533 "addl $16, %%esi \n\t"
|
|
534 " jnz 1b \n\t"
|
|
535 :: "r" (samples+256), "m" (bias)
|
|
536 : "%esi"
|
|
537 );
|
|
538 #else
|
3394
|
539 for (i = 0; i < 256; i++) {
|
|
540 common = samples[i + 256] + bias;
|
|
541 samples[i] += common + samples[i + 768];
|
|
542 samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
|
|
543 }
|
3624
|
544 #endif
|
3394
|
545 }
|
|
546
|
|
547 static void mix32toS (sample_t * samples, sample_t bias)
|
|
548 {
|
|
549 int i;
|
|
550 sample_t common, surround;
|
|
551
|
3625
|
552 #ifdef HAVE_SSE
|
|
553 asm volatile(
|
|
554 "movlps %1, %%xmm7 \n\t"
|
|
555 "shufps $0x00, %%xmm7, %%xmm7 \n\t"
|
|
556 "movl $-1024, %%esi \n\t"
|
|
557 "1: \n\t"
|
|
558 "movaps 1024(%0, %%esi), %%xmm0 \n\t"
|
|
559 "movaps 3072(%0, %%esi), %%xmm2 \n\t"
|
|
560 "addps %%xmm7, %%xmm0 \n\t" // common
|
|
561 "addps 4096(%0, %%esi), %%xmm2 \n\t" // surround
|
|
562 "movaps (%0, %%esi), %%xmm1 \n\t"
|
|
563 "movaps 2048(%0, %%esi), %%xmm3 \n\t"
|
|
564 "subps %%xmm2, %%xmm1 \n\t"
|
|
565 "addps %%xmm2, %%xmm3 \n\t"
|
|
566 "addps %%xmm0, %%xmm1 \n\t"
|
|
567 "addps %%xmm0, %%xmm3 \n\t"
|
|
568 "movaps %%xmm1, (%0, %%esi) \n\t"
|
|
569 "movaps %%xmm3, 1024(%0, %%esi) \n\t"
|
|
570 "addl $16, %%esi \n\t"
|
|
571 " jnz 1b \n\t"
|
|
572 :: "r" (samples+256), "m" (bias)
|
|
573 : "%esi"
|
|
574 );
|
|
575 #else
|
3394
|
576 for (i = 0; i < 256; i++) {
|
|
577 common = samples[i + 256] + bias;
|
|
578 surround = samples[i + 768] + samples[i + 1024];
|
|
579 samples[i] += common - surround;
|
|
580 samples[i + 256] = samples[i + 512] + common + surround;
|
|
581 }
|
3625
|
582 #endif
|
3394
|
583 }
|
|
584
|
|
585 static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
|
|
586 {
|
|
587 int i;
|
|
588
|
|
589 for (i = 0; i < 256; i++)
|
|
590 dest[i] = src[i] + src[i + 256] + bias;
|
|
591 }
|
|
592
|
|
593 static void zero (sample_t * samples)
|
|
594 {
|
|
595 int i;
|
|
596
|
|
597 for (i = 0; i < 256; i++)
|
|
598 samples[i] = 0;
|
|
599 }
|
|
600
|
|
601 void downmix (sample_t * samples, int acmod, int output, sample_t bias,
|
|
602 sample_t clev, sample_t slev)
|
|
603 {
|
|
604 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
|
|
605
|
|
606 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
|
|
607 memcpy (samples, samples + 256, 256 * sizeof (sample_t));
|
|
608 break;
|
|
609
|
|
610 case CONVERT (A52_CHANNEL, A52_MONO):
|
|
611 case CONVERT (A52_STEREO, A52_MONO):
|
|
612 mix_2to1:
|
|
613 mix2to1 (samples, samples + 256, bias);
|
|
614 break;
|
|
615
|
|
616 case CONVERT (A52_2F1R, A52_MONO):
|
|
617 if (slev == 0)
|
|
618 goto mix_2to1;
|
|
619 case CONVERT (A52_3F, A52_MONO):
|
|
620 mix_3to1:
|
|
621 mix3to1 (samples, bias);
|
|
622 break;
|
|
623
|
|
624 case CONVERT (A52_3F1R, A52_MONO):
|
|
625 if (slev == 0)
|
|
626 goto mix_3to1;
|
|
627 case CONVERT (A52_2F2R, A52_MONO):
|
|
628 if (slev == 0)
|
|
629 goto mix_2to1;
|
|
630 mix4to1 (samples, bias);
|
|
631 break;
|
|
632
|
|
633 case CONVERT (A52_3F2R, A52_MONO):
|
|
634 if (slev == 0)
|
|
635 goto mix_3to1;
|
|
636 mix5to1 (samples, bias);
|
|
637 break;
|
|
638
|
|
639 case CONVERT (A52_MONO, A52_DOLBY):
|
|
640 memcpy (samples + 256, samples, 256 * sizeof (sample_t));
|
|
641 break;
|
|
642
|
|
643 case CONVERT (A52_3F, A52_STEREO):
|
|
644 case CONVERT (A52_3F, A52_DOLBY):
|
|
645 mix_3to2:
|
|
646 mix3to2 (samples, bias);
|
|
647 break;
|
|
648
|
|
649 case CONVERT (A52_2F1R, A52_STEREO):
|
|
650 if (slev == 0)
|
|
651 break;
|
|
652 mix21to2 (samples, samples + 256, bias);
|
|
653 break;
|
|
654
|
|
655 case CONVERT (A52_2F1R, A52_DOLBY):
|
|
656 mix21toS (samples, bias);
|
|
657 break;
|
|
658
|
|
659 case CONVERT (A52_3F1R, A52_STEREO):
|
|
660 if (slev == 0)
|
|
661 goto mix_3to2;
|
|
662 mix31to2 (samples, bias);
|
|
663 break;
|
|
664
|
|
665 case CONVERT (A52_3F1R, A52_DOLBY):
|
|
666 mix31toS (samples, bias);
|
|
667 break;
|
|
668
|
|
669 case CONVERT (A52_2F2R, A52_STEREO):
|
|
670 if (slev == 0)
|
|
671 break;
|
|
672 mix2to1 (samples, samples + 512, bias);
|
|
673 mix2to1 (samples + 256, samples + 768, bias);
|
|
674 break;
|
|
675
|
|
676 case CONVERT (A52_2F2R, A52_DOLBY):
|
|
677 mix22toS (samples, bias);
|
|
678 break;
|
|
679
|
|
680 case CONVERT (A52_3F2R, A52_STEREO):
|
|
681 if (slev == 0)
|
|
682 goto mix_3to2;
|
|
683 mix32to2 (samples, bias);
|
|
684 break;
|
|
685
|
|
686 case CONVERT (A52_3F2R, A52_DOLBY):
|
|
687 mix32toS (samples, bias);
|
|
688 break;
|
|
689
|
|
690 case CONVERT (A52_3F1R, A52_3F):
|
|
691 if (slev == 0)
|
|
692 break;
|
|
693 mix21to2 (samples, samples + 512, bias);
|
|
694 break;
|
|
695
|
|
696 case CONVERT (A52_3F2R, A52_3F):
|
|
697 if (slev == 0)
|
|
698 break;
|
|
699 mix2to1 (samples, samples + 768, bias);
|
|
700 mix2to1 (samples + 512, samples + 1024, bias);
|
|
701 break;
|
|
702
|
|
703 case CONVERT (A52_3F1R, A52_2F1R):
|
|
704 mix3to2 (samples, bias);
|
|
705 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
|
|
706 break;
|
|
707
|
|
708 case CONVERT (A52_2F2R, A52_2F1R):
|
|
709 mix2to1 (samples + 512, samples + 768, bias);
|
|
710 break;
|
|
711
|
|
712 case CONVERT (A52_3F2R, A52_2F1R):
|
3678
|
713 mix3to2 (samples, bias); //FIXME possible bug? (output doesnt seem to be used)
|
3394
|
714 move2to1 (samples + 768, samples + 512, bias);
|
|
715 break;
|
|
716
|
|
717 case CONVERT (A52_3F2R, A52_3F1R):
|
|
718 mix2to1 (samples + 768, samples + 1024, bias);
|
|
719 break;
|
|
720
|
|
721 case CONVERT (A52_2F1R, A52_2F2R):
|
|
722 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
|
|
723 break;
|
|
724
|
|
725 case CONVERT (A52_3F1R, A52_2F2R):
|
|
726 mix3to2 (samples, bias);
|
|
727 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
|
|
728 break;
|
|
729
|
|
730 case CONVERT (A52_3F2R, A52_2F2R):
|
|
731 mix3to2 (samples, bias);
|
|
732 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
|
|
733 memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
|
|
734 break;
|
|
735
|
|
736 case CONVERT (A52_3F1R, A52_3F2R):
|
|
737 memcpy (samples + 1027, samples + 768, 256 * sizeof (sample_t));
|
|
738 break;
|
|
739 }
|
|
740 }
|
|
741
|
|
742 void upmix (sample_t * samples, int acmod, int output)
|
|
743 {
|
|
744 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
|
|
745
|
|
746 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
|
|
747 memcpy (samples + 256, samples, 256 * sizeof (sample_t));
|
|
748 break;
|
|
749
|
|
750 case CONVERT (A52_3F2R, A52_MONO):
|
|
751 zero (samples + 1024);
|
|
752 case CONVERT (A52_3F1R, A52_MONO):
|
|
753 case CONVERT (A52_2F2R, A52_MONO):
|
|
754 zero (samples + 768);
|
|
755 case CONVERT (A52_3F, A52_MONO):
|
|
756 case CONVERT (A52_2F1R, A52_MONO):
|
|
757 zero (samples + 512);
|
|
758 case CONVERT (A52_CHANNEL, A52_MONO):
|
|
759 case CONVERT (A52_STEREO, A52_MONO):
|
|
760 zero (samples + 256);
|
|
761 break;
|
|
762
|
|
763 case CONVERT (A52_3F2R, A52_STEREO):
|
|
764 case CONVERT (A52_3F2R, A52_DOLBY):
|
|
765 zero (samples + 1024);
|
|
766 case CONVERT (A52_3F1R, A52_STEREO):
|
|
767 case CONVERT (A52_3F1R, A52_DOLBY):
|
|
768 zero (samples + 768);
|
|
769 case CONVERT (A52_3F, A52_STEREO):
|
|
770 case CONVERT (A52_3F, A52_DOLBY):
|
|
771 mix_3to2:
|
|
772 memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
|
|
773 zero (samples + 256);
|
|
774 break;
|
|
775
|
|
776 case CONVERT (A52_2F2R, A52_STEREO):
|
|
777 case CONVERT (A52_2F2R, A52_DOLBY):
|
|
778 zero (samples + 768);
|
|
779 case CONVERT (A52_2F1R, A52_STEREO):
|
|
780 case CONVERT (A52_2F1R, A52_DOLBY):
|
|
781 zero (samples + 512);
|
|
782 break;
|
|
783
|
|
784 case CONVERT (A52_3F2R, A52_3F):
|
|
785 zero (samples + 1024);
|
|
786 case CONVERT (A52_3F1R, A52_3F):
|
|
787 case CONVERT (A52_2F2R, A52_2F1R):
|
|
788 zero (samples + 768);
|
|
789 break;
|
|
790
|
|
791 case CONVERT (A52_3F2R, A52_3F1R):
|
|
792 zero (samples + 1024);
|
|
793 break;
|
|
794
|
|
795 case CONVERT (A52_3F2R, A52_2F1R):
|
|
796 zero (samples + 1024);
|
|
797 case CONVERT (A52_3F1R, A52_2F1R):
|
|
798 mix_31to21:
|
|
799 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
|
|
800 goto mix_3to2;
|
|
801
|
|
802 case CONVERT (A52_3F2R, A52_2F2R):
|
|
803 memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
|
|
804 goto mix_31to21;
|
|
805 }
|
|
806 }
|