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