Statistics
| Branch: | Revision:

ffmpeg / libavcodec / liba52 / downmix.c @ 5509bffa

History | View | Annotate | Download (16.7 KB)

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