332
|
1 /*
|
|
2 * downmix.c
|
|
3 * Copyright (C) 2000-2002 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
|
|
22 */
|
|
23
|
|
24 #include "a52.h"
|
|
25 #include "a52_internal.h"
|
|
26
|
|
27 #define CONVERT(acmod,output) (((output) << 3) + (acmod))
|
|
28
|
|
29 int a52_downmix_init (int input, int flags, sample_t * level,
|
|
30 sample_t clev, sample_t slev)
|
|
31 {
|
|
32 static uint8_t table[11][8] = {
|
|
33 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
|
|
34 A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
|
|
35 {A52_MONO, A52_MONO, A52_MONO, A52_MONO,
|
|
36 A52_MONO, A52_MONO, A52_MONO, A52_MONO},
|
|
37 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
|
|
38 A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
|
|
39 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
|
|
40 A52_STEREO, A52_3F, A52_STEREO, A52_3F},
|
|
41 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
|
|
42 A52_2F1R, A52_2F1R, A52_2F1R, A52_2F1R},
|
|
43 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
|
|
44 A52_2F1R, A52_3F1R, A52_2F1R, A52_3F1R},
|
|
45 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
|
|
46 A52_2F2R, A52_2F2R, A52_2F2R, A52_2F2R},
|
|
47 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
|
|
48 A52_2F2R, A52_3F2R, A52_2F2R, A52_3F2R},
|
|
49 {A52_CHANNEL1, A52_MONO, A52_MONO, A52_MONO,
|
|
50 A52_MONO, A52_MONO, A52_MONO, A52_MONO},
|
|
51 {A52_CHANNEL2, A52_MONO, A52_MONO, A52_MONO,
|
|
52 A52_MONO, A52_MONO, A52_MONO, A52_MONO},
|
|
53 {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_DOLBY,
|
|
54 A52_DOLBY, A52_DOLBY, A52_DOLBY, A52_DOLBY}
|
|
55 };
|
|
56 int output;
|
|
57
|
|
58 output = flags & A52_CHANNEL_MASK;
|
|
59 if (output > A52_DOLBY)
|
|
60 return -1;
|
|
61
|
|
62 output = table[output][input & 7];
|
|
63
|
|
64 if ((output == A52_STEREO) &&
|
|
65 ((input == A52_DOLBY) || ((input == A52_3F) && (clev == LEVEL_3DB))))
|
|
66 output = A52_DOLBY;
|
|
67
|
|
68 if (flags & A52_ADJUST_LEVEL)
|
|
69 switch (CONVERT (input & 7, output)) {
|
|
70
|
|
71 case CONVERT (A52_3F, A52_MONO):
|
|
72 *level *= LEVEL_3DB / (1 + clev);
|
|
73 break;
|
|
74
|
|
75 case CONVERT (A52_STEREO, A52_MONO):
|
|
76 case CONVERT (A52_2F2R, A52_2F1R):
|
|
77 case CONVERT (A52_3F2R, A52_3F1R):
|
|
78 level_3db:
|
|
79 *level *= LEVEL_3DB;
|
|
80 break;
|
|
81
|
|
82 case CONVERT (A52_3F2R, A52_2F1R):
|
|
83 if (clev < LEVEL_PLUS3DB - 1)
|
|
84 goto level_3db;
|
|
85 /* break thru */
|
|
86 case CONVERT (A52_3F, A52_STEREO):
|
|
87 case CONVERT (A52_3F1R, A52_2F1R):
|
|
88 case CONVERT (A52_3F1R, A52_2F2R):
|
|
89 case CONVERT (A52_3F2R, A52_2F2R):
|
|
90 *level /= 1 + clev;
|
|
91 break;
|
|
92
|
|
93 case CONVERT (A52_2F1R, A52_MONO):
|
|
94 *level *= LEVEL_PLUS3DB / (2 + slev);
|
|
95 break;
|
|
96
|
|
97 case CONVERT (A52_2F1R, A52_STEREO):
|
|
98 case CONVERT (A52_3F1R, A52_3F):
|
|
99 *level /= 1 + slev * LEVEL_3DB;
|
|
100 break;
|
|
101
|
|
102 case CONVERT (A52_3F1R, A52_MONO):
|
|
103 *level *= LEVEL_3DB / (1 + clev + 0.5 * slev);
|
|
104 break;
|
|
105
|
|
106 case CONVERT (A52_3F1R, A52_STEREO):
|
|
107 *level /= 1 + clev + slev * LEVEL_3DB;
|
|
108 break;
|
|
109
|
|
110 case CONVERT (A52_2F2R, A52_MONO):
|
|
111 *level *= LEVEL_3DB / (1 + slev);
|
|
112 break;
|
|
113
|
|
114 case CONVERT (A52_2F2R, A52_STEREO):
|
|
115 case CONVERT (A52_3F2R, A52_3F):
|
|
116 *level /= 1 + slev;
|
|
117 break;
|
|
118
|
|
119 case CONVERT (A52_3F2R, A52_MONO):
|
|
120 *level *= LEVEL_3DB / (1 + clev + slev);
|
|
121 break;
|
|
122
|
|
123 case CONVERT (A52_3F2R, A52_STEREO):
|
|
124 *level /= 1 + clev + slev;
|
|
125 break;
|
|
126
|
|
127 case CONVERT (A52_MONO, A52_DOLBY):
|
|
128 *level *= LEVEL_PLUS3DB;
|
|
129 break;
|
|
130
|
|
131 case CONVERT (A52_3F, A52_DOLBY):
|
|
132 case CONVERT (A52_2F1R, A52_DOLBY):
|
|
133 *level *= 1 / (1 + LEVEL_3DB);
|
|
134 break;
|
|
135
|
|
136 case CONVERT (A52_3F1R, A52_DOLBY):
|
|
137 case CONVERT (A52_2F2R, A52_DOLBY):
|
|
138 *level *= 1 / (1 + 2 * LEVEL_3DB);
|
|
139 break;
|
|
140
|
|
141 case CONVERT (A52_3F2R, A52_DOLBY):
|
|
142 *level *= 1 / (1 + 3 * LEVEL_3DB);
|
|
143 break;
|
|
144 }
|
|
145
|
|
146 return output;
|
|
147 }
|
|
148
|
|
149 int a52_downmix_coeff (sample_t * coeff, int acmod, int output, sample_t level,
|
|
150 sample_t clev, sample_t slev)
|
|
151 {
|
|
152 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
|
|
153
|
|
154 case CONVERT (A52_CHANNEL, A52_CHANNEL):
|
|
155 case CONVERT (A52_MONO, A52_MONO):
|
|
156 case CONVERT (A52_STEREO, A52_STEREO):
|
|
157 case CONVERT (A52_3F, A52_3F):
|
|
158 case CONVERT (A52_2F1R, A52_2F1R):
|
|
159 case CONVERT (A52_3F1R, A52_3F1R):
|
|
160 case CONVERT (A52_2F2R, A52_2F2R):
|
|
161 case CONVERT (A52_3F2R, A52_3F2R):
|
|
162 case CONVERT (A52_STEREO, A52_DOLBY):
|
|
163 coeff[0] = coeff[1] = coeff[2] = coeff[3] = coeff[4] = level;
|
|
164 return 0;
|
|
165
|
|
166 case CONVERT (A52_CHANNEL, A52_MONO):
|
|
167 coeff[0] = coeff[1] = level * LEVEL_6DB;
|
|
168 return 3;
|
|
169
|
|
170 case CONVERT (A52_STEREO, A52_MONO):
|
|
171 coeff[0] = coeff[1] = level * LEVEL_3DB;
|
|
172 return 3;
|
|
173
|
|
174 case CONVERT (A52_3F, A52_MONO):
|
|
175 coeff[0] = coeff[2] = level * LEVEL_3DB;
|
|
176 coeff[1] = level * clev * LEVEL_PLUS3DB;
|
|
177 return 7;
|
|
178
|
|
179 case CONVERT (A52_2F1R, A52_MONO):
|
|
180 coeff[0] = coeff[1] = level * LEVEL_3DB;
|
|
181 coeff[2] = level * slev * LEVEL_3DB;
|
|
182 return 7;
|
|
183
|
|
184 case CONVERT (A52_2F2R, A52_MONO):
|
|
185 coeff[0] = coeff[1] = level * LEVEL_3DB;
|
|
186 coeff[2] = coeff[3] = level * slev * LEVEL_3DB;
|
|
187 return 15;
|
|
188
|
|
189 case CONVERT (A52_3F1R, A52_MONO):
|
|
190 coeff[0] = coeff[2] = level * LEVEL_3DB;
|
|
191 coeff[1] = level * clev * LEVEL_PLUS3DB;
|
|
192 coeff[3] = level * slev * LEVEL_3DB;
|
|
193 return 15;
|
|
194
|
|
195 case CONVERT (A52_3F2R, A52_MONO):
|
|
196 coeff[0] = coeff[2] = level * LEVEL_3DB;
|
|
197 coeff[1] = level * clev * LEVEL_PLUS3DB;
|
|
198 coeff[3] = coeff[4] = level * slev * LEVEL_3DB;
|
|
199 return 31;
|
|
200
|
|
201 case CONVERT (A52_MONO, A52_DOLBY):
|
|
202 coeff[0] = level * LEVEL_3DB;
|
|
203 return 0;
|
|
204
|
|
205 case CONVERT (A52_3F, A52_DOLBY):
|
|
206 clev = LEVEL_3DB;
|
|
207 case CONVERT (A52_3F, A52_STEREO):
|
|
208 case CONVERT (A52_3F1R, A52_2F1R):
|
|
209 case CONVERT (A52_3F2R, A52_2F2R):
|
|
210 coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
|
|
211 coeff[1] = level * clev;
|
|
212 return 7;
|
|
213
|
|
214 case CONVERT (A52_2F1R, A52_DOLBY):
|
|
215 slev = 1;
|
|
216 case CONVERT (A52_2F1R, A52_STEREO):
|
|
217 coeff[0] = coeff[1] = level;
|
|
218 coeff[2] = level * slev * LEVEL_3DB;
|
|
219 return 7;
|
|
220
|
|
221 case CONVERT (A52_3F1R, A52_DOLBY):
|
|
222 clev = LEVEL_3DB;
|
|
223 slev = 1;
|
|
224 case CONVERT (A52_3F1R, A52_STEREO):
|
|
225 coeff[0] = coeff[2] = level;
|
|
226 coeff[1] = level * clev;
|
|
227 coeff[3] = level * slev * LEVEL_3DB;
|
|
228 return 15;
|
|
229
|
|
230 case CONVERT (A52_2F2R, A52_DOLBY):
|
|
231 slev = LEVEL_3DB;
|
|
232 case CONVERT (A52_2F2R, A52_STEREO):
|
|
233 coeff[0] = coeff[1] = level;
|
|
234 coeff[2] = coeff[3] = level * slev;
|
|
235 return 15;
|
|
236
|
|
237 case CONVERT (A52_3F2R, A52_DOLBY):
|
|
238 clev = LEVEL_3DB;
|
|
239 case CONVERT (A52_3F2R, A52_2F1R):
|
|
240 slev = LEVEL_3DB;
|
|
241 case CONVERT (A52_3F2R, A52_STEREO):
|
|
242 coeff[0] = coeff[2] = level;
|
|
243 coeff[1] = level * clev;
|
|
244 coeff[3] = coeff[4] = level * slev;
|
|
245 return 31;
|
|
246
|
|
247 case CONVERT (A52_3F1R, A52_3F):
|
|
248 coeff[0] = coeff[1] = coeff[2] = level;
|
|
249 coeff[3] = level * slev * LEVEL_3DB;
|
|
250 return 13;
|
|
251
|
|
252 case CONVERT (A52_3F2R, A52_3F):
|
|
253 coeff[0] = coeff[1] = coeff[2] = level;
|
|
254 coeff[3] = coeff[4] = level * slev;
|
|
255 return 29;
|
|
256
|
|
257 case CONVERT (A52_2F2R, A52_2F1R):
|
|
258 coeff[0] = coeff[1] = level;
|
|
259 coeff[2] = coeff[3] = level * LEVEL_3DB;
|
|
260 return 12;
|
|
261
|
|
262 case CONVERT (A52_3F2R, A52_3F1R):
|
|
263 coeff[0] = coeff[1] = coeff[2] = level;
|
|
264 coeff[3] = coeff[4] = level * LEVEL_3DB;
|
|
265 return 24;
|
|
266
|
|
267 case CONVERT (A52_2F1R, A52_2F2R):
|
|
268 coeff[0] = coeff[1] = level;
|
|
269 coeff[2] = level * LEVEL_3DB;
|
|
270 return 0;
|
|
271
|
|
272 case CONVERT (A52_3F1R, A52_2F2R):
|
|
273 coeff[0] = coeff[2] = level;
|
|
274 coeff[1] = level * clev;
|
|
275 coeff[3] = level * LEVEL_3DB;
|
|
276 return 7;
|
|
277
|
|
278 case CONVERT (A52_3F1R, A52_3F2R):
|
|
279 coeff[0] = coeff[1] = coeff[2] = level;
|
|
280 coeff[3] = level * LEVEL_3DB;
|
|
281 return 0;
|
|
282
|
|
283 case CONVERT (A52_CHANNEL, A52_CHANNEL1):
|
|
284 coeff[0] = level;
|
|
285 coeff[1] = 0;
|
|
286 return 0;
|
|
287
|
|
288 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
|
|
289 coeff[0] = 0;
|
|
290 coeff[1] = level;
|
|
291 return 0;
|
|
292 }
|
|
293
|
|
294 return -1; /* NOTREACHED */
|
|
295 }
|
|
296
|
|
297 static void mix2to1 (sample_t * dest, sample_t * src, sample_t bias)
|
|
298 {
|
|
299 int i;
|
|
300
|
|
301 for (i = 0; i < 256; i++)
|
|
302 dest[i] += src[i] + bias;
|
|
303 }
|
|
304
|
|
305 static void mix3to1 (sample_t * samples, sample_t bias)
|
|
306 {
|
|
307 int i;
|
|
308
|
|
309 for (i = 0; i < 256; i++)
|
|
310 samples[i] += samples[i + 256] + samples[i + 512] + bias;
|
|
311 }
|
|
312
|
|
313 static void mix4to1 (sample_t * samples, sample_t bias)
|
|
314 {
|
|
315 int i;
|
|
316
|
|
317 for (i = 0; i < 256; i++)
|
|
318 samples[i] += (samples[i + 256] + samples[i + 512] +
|
|
319 samples[i + 768] + bias);
|
|
320 }
|
|
321
|
|
322 static void mix5to1 (sample_t * samples, sample_t bias)
|
|
323 {
|
|
324 int i;
|
|
325
|
|
326 for (i = 0; i < 256; i++)
|
|
327 samples[i] += (samples[i + 256] + samples[i + 512] +
|
|
328 samples[i + 768] + samples[i + 1024] + bias);
|
|
329 }
|
|
330
|
|
331 static void mix3to2 (sample_t * samples, sample_t bias)
|
|
332 {
|
|
333 int i;
|
|
334 sample_t common;
|
|
335
|
|
336 for (i = 0; i < 256; i++) {
|
|
337 common = samples[i + 256] + bias;
|
|
338 samples[i] += common;
|
|
339 samples[i + 256] = samples[i + 512] + common;
|
|
340 }
|
|
341 }
|
|
342
|
|
343 static void mix21to2 (sample_t * left, sample_t * right, sample_t bias)
|
|
344 {
|
|
345 int i;
|
|
346 sample_t common;
|
|
347
|
|
348 for (i = 0; i < 256; i++) {
|
|
349 common = right[i + 256] + bias;
|
|
350 left[i] += common;
|
|
351 right[i] += common;
|
|
352 }
|
|
353 }
|
|
354
|
|
355 static void mix21toS (sample_t * samples, sample_t bias)
|
|
356 {
|
|
357 int i;
|
|
358 sample_t surround;
|
|
359
|
|
360 for (i = 0; i < 256; i++) {
|
|
361 surround = samples[i + 512];
|
|
362 samples[i] += bias - surround;
|
|
363 samples[i + 256] += bias + surround;
|
|
364 }
|
|
365 }
|
|
366
|
|
367 static void mix31to2 (sample_t * samples, sample_t bias)
|
|
368 {
|
|
369 int i;
|
|
370 sample_t common;
|
|
371
|
|
372 for (i = 0; i < 256; i++) {
|
|
373 common = samples[i + 256] + samples[i + 768] + bias;
|
|
374 samples[i] += common;
|
|
375 samples[i + 256] = samples[i + 512] + common;
|
|
376 }
|
|
377 }
|
|
378
|
|
379 static void mix31toS (sample_t * samples, sample_t bias)
|
|
380 {
|
|
381 int i;
|
|
382 sample_t common, surround;
|
|
383
|
|
384 for (i = 0; i < 256; i++) {
|
|
385 common = samples[i + 256] + bias;
|
|
386 surround = samples[i + 768];
|
|
387 samples[i] += common - surround;
|
|
388 samples[i + 256] = samples[i + 512] + common + surround;
|
|
389 }
|
|
390 }
|
|
391
|
|
392 static void mix22toS (sample_t * samples, sample_t bias)
|
|
393 {
|
|
394 int i;
|
|
395 sample_t surround;
|
|
396
|
|
397 for (i = 0; i < 256; i++) {
|
|
398 surround = samples[i + 512] + samples[i + 768];
|
|
399 samples[i] += bias - surround;
|
|
400 samples[i + 256] += bias + surround;
|
|
401 }
|
|
402 }
|
|
403
|
|
404 static void mix32to2 (sample_t * samples, sample_t bias)
|
|
405 {
|
|
406 int i;
|
|
407 sample_t common;
|
|
408
|
|
409 for (i = 0; i < 256; i++) {
|
|
410 common = samples[i + 256] + bias;
|
|
411 samples[i] += common + samples[i + 768];
|
|
412 samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
|
|
413 }
|
|
414 }
|
|
415
|
|
416 static void mix32toS (sample_t * samples, sample_t bias)
|
|
417 {
|
|
418 int i;
|
|
419 sample_t common, surround;
|
|
420
|
|
421 for (i = 0; i < 256; i++) {
|
|
422 common = samples[i + 256] + bias;
|
|
423 surround = samples[i + 768] + samples[i + 1024];
|
|
424 samples[i] += common - surround;
|
|
425 samples[i + 256] = samples[i + 512] + common + surround;
|
|
426 }
|
|
427 }
|
|
428
|
|
429 static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
|
|
430 {
|
|
431 int i;
|
|
432
|
|
433 for (i = 0; i < 256; i++)
|
|
434 dest[i] = src[i] + src[i + 256] + bias;
|
|
435 }
|
|
436
|
|
437 static void zero (sample_t * samples)
|
|
438 {
|
|
439 int i;
|
|
440
|
|
441 for (i = 0; i < 256; i++)
|
|
442 samples[i] = 0;
|
|
443 }
|
|
444
|
|
445 void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
|
|
446 sample_t clev, sample_t slev)
|
|
447 {
|
|
448 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
|
|
449
|
|
450 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
|
|
451 memcpy (samples, samples + 256, 256 * sizeof (sample_t));
|
|
452 break;
|
|
453
|
|
454 case CONVERT (A52_CHANNEL, A52_MONO):
|
|
455 case CONVERT (A52_STEREO, A52_MONO):
|
|
456 mix_2to1:
|
|
457 mix2to1 (samples, samples + 256, bias);
|
|
458 break;
|
|
459
|
|
460 case CONVERT (A52_2F1R, A52_MONO):
|
|
461 if (slev == 0)
|
|
462 goto mix_2to1;
|
|
463 case CONVERT (A52_3F, A52_MONO):
|
|
464 mix_3to1:
|
|
465 mix3to1 (samples, bias);
|
|
466 break;
|
|
467
|
|
468 case CONVERT (A52_3F1R, A52_MONO):
|
|
469 if (slev == 0)
|
|
470 goto mix_3to1;
|
|
471 case CONVERT (A52_2F2R, A52_MONO):
|
|
472 if (slev == 0)
|
|
473 goto mix_2to1;
|
|
474 mix4to1 (samples, bias);
|
|
475 break;
|
|
476
|
|
477 case CONVERT (A52_3F2R, A52_MONO):
|
|
478 if (slev == 0)
|
|
479 goto mix_3to1;
|
|
480 mix5to1 (samples, bias);
|
|
481 break;
|
|
482
|
|
483 case CONVERT (A52_MONO, A52_DOLBY):
|
|
484 memcpy (samples + 256, samples, 256 * sizeof (sample_t));
|
|
485 break;
|
|
486
|
|
487 case CONVERT (A52_3F, A52_STEREO):
|
|
488 case CONVERT (A52_3F, A52_DOLBY):
|
|
489 mix_3to2:
|
|
490 mix3to2 (samples, bias);
|
|
491 break;
|
|
492
|
|
493 case CONVERT (A52_2F1R, A52_STEREO):
|
|
494 if (slev == 0)
|
|
495 break;
|
|
496 mix21to2 (samples, samples + 256, bias);
|
|
497 break;
|
|
498
|
|
499 case CONVERT (A52_2F1R, A52_DOLBY):
|
|
500 mix21toS (samples, bias);
|
|
501 break;
|
|
502
|
|
503 case CONVERT (A52_3F1R, A52_STEREO):
|
|
504 if (slev == 0)
|
|
505 goto mix_3to2;
|
|
506 mix31to2 (samples, bias);
|
|
507 break;
|
|
508
|
|
509 case CONVERT (A52_3F1R, A52_DOLBY):
|
|
510 mix31toS (samples, bias);
|
|
511 break;
|
|
512
|
|
513 case CONVERT (A52_2F2R, A52_STEREO):
|
|
514 if (slev == 0)
|
|
515 break;
|
|
516 mix2to1 (samples, samples + 512, bias);
|
|
517 mix2to1 (samples + 256, samples + 768, bias);
|
|
518 break;
|
|
519
|
|
520 case CONVERT (A52_2F2R, A52_DOLBY):
|
|
521 mix22toS (samples, bias);
|
|
522 break;
|
|
523
|
|
524 case CONVERT (A52_3F2R, A52_STEREO):
|
|
525 if (slev == 0)
|
|
526 goto mix_3to2;
|
|
527 mix32to2 (samples, bias);
|
|
528 break;
|
|
529
|
|
530 case CONVERT (A52_3F2R, A52_DOLBY):
|
|
531 mix32toS (samples, bias);
|
|
532 break;
|
|
533
|
|
534 case CONVERT (A52_3F1R, A52_3F):
|
|
535 if (slev == 0)
|
|
536 break;
|
|
537 mix21to2 (samples, samples + 512, bias);
|
|
538 break;
|
|
539
|
|
540 case CONVERT (A52_3F2R, A52_3F):
|
|
541 if (slev == 0)
|
|
542 break;
|
|
543 mix2to1 (samples, samples + 768, bias);
|
|
544 mix2to1 (samples + 512, samples + 1024, bias);
|
|
545 break;
|
|
546
|
|
547 case CONVERT (A52_3F1R, A52_2F1R):
|
|
548 mix3to2 (samples, bias);
|
|
549 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
|
|
550 break;
|
|
551
|
|
552 case CONVERT (A52_2F2R, A52_2F1R):
|
|
553 mix2to1 (samples + 512, samples + 768, bias);
|
|
554 break;
|
|
555
|
|
556 case CONVERT (A52_3F2R, A52_2F1R):
|
|
557 mix3to2 (samples, bias);
|
|
558 move2to1 (samples + 768, samples + 512, bias);
|
|
559 break;
|
|
560
|
|
561 case CONVERT (A52_3F2R, A52_3F1R):
|
|
562 mix2to1 (samples + 768, samples + 1024, bias);
|
|
563 break;
|
|
564
|
|
565 case CONVERT (A52_2F1R, A52_2F2R):
|
|
566 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
|
|
567 break;
|
|
568
|
|
569 case CONVERT (A52_3F1R, A52_2F2R):
|
|
570 mix3to2 (samples, bias);
|
|
571 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
|
|
572 break;
|
|
573
|
|
574 case CONVERT (A52_3F2R, A52_2F2R):
|
|
575 mix3to2 (samples, bias);
|
|
576 memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
|
|
577 memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
|
|
578 break;
|
|
579
|
|
580 case CONVERT (A52_3F1R, A52_3F2R):
|
|
581 memcpy (samples + 1027, samples + 768, 256 * sizeof (sample_t));
|
|
582 break;
|
|
583 }
|
|
584 }
|
|
585
|
|
586 void a52_upmix (sample_t * samples, int acmod, int output)
|
|
587 {
|
|
588 switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
|
|
589
|
|
590 case CONVERT (A52_CHANNEL, A52_CHANNEL2):
|
|
591 memcpy (samples + 256, samples, 256 * sizeof (sample_t));
|
|
592 break;
|
|
593
|
|
594 case CONVERT (A52_3F2R, A52_MONO):
|
|
595 zero (samples + 1024);
|
|
596 case CONVERT (A52_3F1R, A52_MONO):
|
|
597 case CONVERT (A52_2F2R, A52_MONO):
|
|
598 zero (samples + 768);
|
|
599 case CONVERT (A52_3F, A52_MONO):
|
|
600 case CONVERT (A52_2F1R, A52_MONO):
|
|
601 zero (samples + 512);
|
|
602 case CONVERT (A52_CHANNEL, A52_MONO):
|
|
603 case CONVERT (A52_STEREO, A52_MONO):
|
|
604 zero (samples + 256);
|
|
605 break;
|
|
606
|
|
607 case CONVERT (A52_3F2R, A52_STEREO):
|
|
608 case CONVERT (A52_3F2R, A52_DOLBY):
|
|
609 zero (samples + 1024);
|
|
610 case CONVERT (A52_3F1R, A52_STEREO):
|
|
611 case CONVERT (A52_3F1R, A52_DOLBY):
|
|
612 zero (samples + 768);
|
|
613 case CONVERT (A52_3F, A52_STEREO):
|
|
614 case CONVERT (A52_3F, A52_DOLBY):
|
|
615 mix_3to2:
|
|
616 memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
|
|
617 zero (samples + 256);
|
|
618 break;
|
|
619
|
|
620 case CONVERT (A52_2F2R, A52_STEREO):
|
|
621 case CONVERT (A52_2F2R, A52_DOLBY):
|
|
622 zero (samples + 768);
|
|
623 case CONVERT (A52_2F1R, A52_STEREO):
|
|
624 case CONVERT (A52_2F1R, A52_DOLBY):
|
|
625 zero (samples + 512);
|
|
626 break;
|
|
627
|
|
628 case CONVERT (A52_3F2R, A52_3F):
|
|
629 zero (samples + 1024);
|
|
630 case CONVERT (A52_3F1R, A52_3F):
|
|
631 case CONVERT (A52_2F2R, A52_2F1R):
|
|
632 zero (samples + 768);
|
|
633 break;
|
|
634
|
|
635 case CONVERT (A52_3F2R, A52_3F1R):
|
|
636 zero (samples + 1024);
|
|
637 break;
|
|
638
|
|
639 case CONVERT (A52_3F2R, A52_2F1R):
|
|
640 zero (samples + 1024);
|
|
641 case CONVERT (A52_3F1R, A52_2F1R):
|
|
642 mix_31to21:
|
|
643 memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
|
|
644 goto mix_3to2;
|
|
645
|
|
646 case CONVERT (A52_3F2R, A52_2F2R):
|
|
647 memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
|
|
648 goto mix_31to21;
|
|
649 }
|
|
650 }
|