Statistics
| Branch: | Revision:

ffmpeg / libavcodec / liba52 / downmix.c @ 976f969b

History | View | Annotate | Download (16 KB)

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 "config.h"
25

    
26
#include <string.h>
27
#include <inttypes.h>
28

    
29
#include "a52.h"
30
#include "a52_internal.h"
31

    
32
#define CONVERT(acmod,output) (((output) << 3) + (acmod))
33

    
34
int a52_downmix_init (int input, int flags, sample_t * level,
35
                      sample_t clev, sample_t slev)
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

    
69
    if ((output == A52_STEREO) &&
70
        ((input == A52_DOLBY) || ((input == A52_3F) && (clev == LEVEL_3DB))))
71
        output = A52_DOLBY;
72

    
73
    if (flags & A52_ADJUST_LEVEL)
74
        switch (CONVERT (input & 7, output)) {
75

    
76
        case CONVERT (A52_3F, A52_MONO):
77
            *level *= LEVEL_3DB / (1 + clev);
78
            break;
79

    
80
        case CONVERT (A52_STEREO, A52_MONO):
81
        case CONVERT (A52_2F2R, A52_2F1R):
82
        case CONVERT (A52_3F2R, A52_3F1R):
83
        level_3db:
84
            *level *= LEVEL_3DB;
85
            break;
86

    
87
        case CONVERT (A52_3F2R, A52_2F1R):
88
            if (clev < LEVEL_PLUS3DB - 1)
89
                goto level_3db;
90
            /* break thru */
91
        case CONVERT (A52_3F, A52_STEREO):
92
        case CONVERT (A52_3F1R, A52_2F1R):
93
        case CONVERT (A52_3F1R, A52_2F2R):
94
        case CONVERT (A52_3F2R, A52_2F2R):
95
            *level /= 1 + clev;
96
            break;
97

    
98
        case CONVERT (A52_2F1R, A52_MONO):
99
            *level *= LEVEL_PLUS3DB / (2 + slev);
100
            break;
101

    
102
        case CONVERT (A52_2F1R, A52_STEREO):
103
        case CONVERT (A52_3F1R, A52_3F):
104
            *level /= 1 + slev * LEVEL_3DB;
105
            break;
106

    
107
        case CONVERT (A52_3F1R, A52_MONO):
108
            *level *= LEVEL_3DB / (1 + clev + 0.5 * slev);
109
            break;
110

    
111
        case CONVERT (A52_3F1R, A52_STEREO):
112
            *level /= 1 + clev + slev * LEVEL_3DB;
113
            break;
114

    
115
        case CONVERT (A52_2F2R, A52_MONO):
116
            *level *= LEVEL_3DB / (1 + slev);
117
            break;
118

    
119
        case CONVERT (A52_2F2R, A52_STEREO):
120
        case CONVERT (A52_3F2R, A52_3F):
121
            *level /= 1 + slev;
122
            break;
123

    
124
        case CONVERT (A52_3F2R, A52_MONO):
125
            *level *= LEVEL_3DB / (1 + clev + slev);
126
            break;
127

    
128
        case CONVERT (A52_3F2R, A52_STEREO):
129
            *level /= 1 + clev + slev;
130
            break;
131

    
132
        case CONVERT (A52_MONO, A52_DOLBY):
133
            *level *= LEVEL_PLUS3DB;
134
            break;
135

    
136
        case CONVERT (A52_3F, A52_DOLBY):
137
        case CONVERT (A52_2F1R, A52_DOLBY):
138
            *level *= 1 / (1 + LEVEL_3DB);
139
            break;
140

    
141
        case CONVERT (A52_3F1R, A52_DOLBY):
142
        case CONVERT (A52_2F2R, A52_DOLBY):
143
            *level *= 1 / (1 + 2 * LEVEL_3DB);
144
            break;
145

    
146
        case CONVERT (A52_3F2R, A52_DOLBY):
147
            *level *= 1 / (1 + 3 * LEVEL_3DB);
148
            break;
149
        }
150

    
151
    return output;
152
}
153

    
154
int a52_downmix_coeff (sample_t * coeff, int acmod, int output, sample_t level,
155
                       sample_t clev, sample_t slev)
156
{
157
    switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
158

    
159
    case CONVERT (A52_CHANNEL, A52_CHANNEL):
160
    case CONVERT (A52_MONO, A52_MONO):
161
    case CONVERT (A52_STEREO, A52_STEREO):
162
    case CONVERT (A52_3F, A52_3F):
163
    case CONVERT (A52_2F1R, A52_2F1R):
164
    case CONVERT (A52_3F1R, A52_3F1R):
165
    case CONVERT (A52_2F2R, A52_2F2R):
166
    case CONVERT (A52_3F2R, A52_3F2R):
167
    case CONVERT (A52_STEREO, A52_DOLBY):
168
        coeff[0] = coeff[1] = coeff[2] = coeff[3] = coeff[4] = level;
169
        return 0;
170

    
171
    case CONVERT (A52_CHANNEL, A52_MONO):
172
        coeff[0] = coeff[1] = level * LEVEL_6DB;
173
        return 3;
174

    
175
    case CONVERT (A52_STEREO, A52_MONO):
176
        coeff[0] = coeff[1] = level * LEVEL_3DB;
177
        return 3;
178

    
179
    case CONVERT (A52_3F, A52_MONO):
180
        coeff[0] = coeff[2] = level * LEVEL_3DB;
181
        coeff[1] = level * clev * LEVEL_PLUS3DB;
182
        return 7;
183

    
184
    case CONVERT (A52_2F1R, A52_MONO):
185
        coeff[0] = coeff[1] = level * LEVEL_3DB;
186
        coeff[2] = level * slev * LEVEL_3DB;
187
        return 7;
188

    
189
    case CONVERT (A52_2F2R, A52_MONO):
190
        coeff[0] = coeff[1] = level * LEVEL_3DB;
191
        coeff[2] = coeff[3] = level * slev * LEVEL_3DB;
192
        return 15;
193

    
194
    case CONVERT (A52_3F1R, A52_MONO):
195
        coeff[0] = coeff[2] = level * LEVEL_3DB;
196
        coeff[1] = level * clev * LEVEL_PLUS3DB;
197
        coeff[3] = level * slev * LEVEL_3DB;
198
        return 15;
199

    
200
    case CONVERT (A52_3F2R, A52_MONO):
201
        coeff[0] = coeff[2] = level * LEVEL_3DB;
202
        coeff[1] = level * clev * LEVEL_PLUS3DB;
203
        coeff[3] = coeff[4] = level * slev * LEVEL_3DB;
204
        return 31;
205

    
206
    case CONVERT (A52_MONO, A52_DOLBY):
207
        coeff[0] = level * LEVEL_3DB;
208
        return 0;
209

    
210
    case CONVERT (A52_3F, A52_DOLBY):
211
        clev = LEVEL_3DB;
212
    case CONVERT (A52_3F, A52_STEREO):
213
    case CONVERT (A52_3F1R, A52_2F1R):
214
    case CONVERT (A52_3F2R, A52_2F2R):
215
        coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
216
        coeff[1] = level * clev;
217
        return 7;
218

    
219
    case CONVERT (A52_2F1R, A52_DOLBY):
220
        slev = 1;
221
    case CONVERT (A52_2F1R, A52_STEREO):
222
        coeff[0] = coeff[1] = level;
223
        coeff[2] = level * slev * LEVEL_3DB;
224
        return 7;
225

    
226
    case CONVERT (A52_3F1R, A52_DOLBY):
227
        clev = LEVEL_3DB;
228
        slev = 1;
229
    case CONVERT (A52_3F1R, A52_STEREO):
230
        coeff[0] = coeff[2] = level;
231
        coeff[1] = level * clev;
232
        coeff[3] = level * slev * LEVEL_3DB;
233
        return 15;
234

    
235
    case CONVERT (A52_2F2R, A52_DOLBY):
236
        slev = LEVEL_3DB;
237
    case CONVERT (A52_2F2R, A52_STEREO):
238
        coeff[0] = coeff[1] = level;
239
        coeff[2] = coeff[3] = level * slev;
240
        return 15;
241

    
242
    case CONVERT (A52_3F2R, A52_DOLBY):
243
        clev = LEVEL_3DB;
244
    case CONVERT (A52_3F2R, A52_2F1R):
245
        slev = LEVEL_3DB;
246
    case CONVERT (A52_3F2R, A52_STEREO):
247
        coeff[0] = coeff[2] = level;
248
        coeff[1] = level * clev;
249
        coeff[3] = coeff[4] = level * slev;
250
        return 31;
251

    
252
    case CONVERT (A52_3F1R, A52_3F):
253
        coeff[0] = coeff[1] = coeff[2] = level;
254
        coeff[3] = level * slev * LEVEL_3DB;
255
        return 13;
256

    
257
    case CONVERT (A52_3F2R, A52_3F):
258
        coeff[0] = coeff[1] = coeff[2] = level;
259
        coeff[3] = coeff[4] = level * slev;
260
        return 29;
261

    
262
    case CONVERT (A52_2F2R, A52_2F1R):
263
        coeff[0] = coeff[1] = level;
264
        coeff[2] = coeff[3] = level * LEVEL_3DB;
265
        return 12;
266

    
267
    case CONVERT (A52_3F2R, A52_3F1R):
268
        coeff[0] = coeff[1] = coeff[2] = level;
269
        coeff[3] = coeff[4] = level * LEVEL_3DB;
270
        return 24;
271

    
272
    case CONVERT (A52_2F1R, A52_2F2R):
273
        coeff[0] = coeff[1] = level;
274
        coeff[2] = level * LEVEL_3DB;
275
        return 0;
276

    
277
    case CONVERT (A52_3F1R, A52_2F2R):
278
        coeff[0] = coeff[2] = level;
279
        coeff[1] = level * clev;
280
        coeff[3] = level * LEVEL_3DB;
281
        return 7;
282

    
283
    case CONVERT (A52_3F1R, A52_3F2R):
284
        coeff[0] = coeff[1] = coeff[2] = level;
285
        coeff[3] = level * LEVEL_3DB;
286
        return 0;
287

    
288
    case CONVERT (A52_CHANNEL, A52_CHANNEL1):
289
        coeff[0] = level;
290
        coeff[1] = 0;
291
        return 0;
292

    
293
    case CONVERT (A52_CHANNEL, A52_CHANNEL2):
294
        coeff[0] = 0;
295
        coeff[1] = level;
296
        return 0;
297
    }
298

    
299
    return -1;        /* NOTREACHED */
300
}
301

    
302
static void mix2to1 (sample_t * dest, sample_t * src, sample_t bias)
303
{
304
    int i;
305

    
306
    for (i = 0; i < 256; i++)
307
        dest[i] += src[i] + bias;
308
}
309

    
310
static void mix3to1 (sample_t * samples, sample_t bias)
311
{
312
    int i;
313

    
314
    for (i = 0; i < 256; i++)
315
        samples[i] += samples[i + 256] + samples[i + 512] + bias;
316
}
317

    
318
static void mix4to1 (sample_t * samples, sample_t bias)
319
{
320
    int i;
321

    
322
    for (i = 0; i < 256; i++)
323
        samples[i] += (samples[i + 256] + samples[i + 512] +
324
                       samples[i + 768] + bias);
325
}
326

    
327
static void mix5to1 (sample_t * samples, sample_t bias)
328
{
329
    int i;
330

    
331
    for (i = 0; i < 256; i++)
332
        samples[i] += (samples[i + 256] + samples[i + 512] +
333
                       samples[i + 768] + samples[i + 1024] + bias);
334
}
335

    
336
static void mix3to2 (sample_t * samples, sample_t bias)
337
{
338
    int i;
339
    sample_t common;
340

    
341
    for (i = 0; i < 256; i++) {
342
        common = samples[i + 256] + bias;
343
        samples[i] += common;
344
        samples[i + 256] = samples[i + 512] + common;
345
    }
346
}
347

    
348
static void mix21to2 (sample_t * left, sample_t * right, sample_t bias)
349
{
350
    int i;
351
    sample_t common;
352

    
353
    for (i = 0; i < 256; i++) {
354
        common = right[i + 256] + bias;
355
        left[i] += common;
356
        right[i] += common;
357
    }
358
}
359

    
360
static void mix21toS (sample_t * samples, sample_t bias)
361
{
362
    int i;
363
    sample_t surround;
364

    
365
    for (i = 0; i < 256; i++) {
366
        surround = samples[i + 512];
367
        samples[i] += bias - surround;
368
        samples[i + 256] += bias + surround;
369
    }
370
}
371

    
372
static void mix31to2 (sample_t * samples, sample_t bias)
373
{
374
    int i;
375
    sample_t common;
376

    
377
    for (i = 0; i < 256; i++) {
378
        common = samples[i + 256] + samples[i + 768] + bias;
379
        samples[i] += common;
380
        samples[i + 256] = samples[i + 512] + common;
381
    }
382
}
383

    
384
static void mix31toS (sample_t * samples, sample_t bias)
385
{
386
    int i;
387
    sample_t common, surround;
388

    
389
    for (i = 0; i < 256; i++) {
390
        common = samples[i + 256] + bias;
391
        surround = samples[i + 768];
392
        samples[i] += common - surround;
393
        samples[i + 256] = samples[i + 512] + common + surround;
394
    }
395
}
396

    
397
static void mix22toS (sample_t * samples, sample_t bias)
398
{
399
    int i;
400
    sample_t surround;
401

    
402
    for (i = 0; i < 256; i++) {
403
        surround = samples[i + 512] + samples[i + 768];
404
        samples[i] += bias - surround;
405
        samples[i + 256] += bias + surround;
406
    }
407
}
408

    
409
static void mix32to2 (sample_t * samples, sample_t bias)
410
{
411
    int i;
412
    sample_t common;
413

    
414
    for (i = 0; i < 256; i++) {
415
        common = samples[i + 256] + bias;
416
        samples[i] += common + samples[i + 768];
417
        samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
418
    }
419
}
420

    
421
static void mix32toS (sample_t * samples, sample_t bias)
422
{
423
    int i;
424
    sample_t common, surround;
425

    
426
    for (i = 0; i < 256; i++) {
427
        common = samples[i + 256] + bias;
428
        surround = samples[i + 768] + samples[i + 1024];
429
        samples[i] += common - surround;
430
        samples[i + 256] = samples[i + 512] + common + surround;
431
    }
432
}
433

    
434
static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
435
{
436
    int i;
437

    
438
    for (i = 0; i < 256; i++)
439
        dest[i] = src[i] + src[i + 256] + bias;
440
}
441

    
442
static void zero (sample_t * samples)
443
{
444
    int i;
445

    
446
    for (i = 0; i < 256; i++)
447
        samples[i] = 0;
448
}
449

    
450
void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
451
                  sample_t clev, sample_t slev)
452
{
453
    switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
454

    
455
    case CONVERT (A52_CHANNEL, A52_CHANNEL2):
456
        memcpy (samples, samples + 256, 256 * sizeof (sample_t));
457
        break;
458

    
459
    case CONVERT (A52_CHANNEL, A52_MONO):
460
    case CONVERT (A52_STEREO, A52_MONO):
461
    mix_2to1:
462
        mix2to1 (samples, samples + 256, bias);
463
        break;
464

    
465
    case CONVERT (A52_2F1R, A52_MONO):
466
        if (slev == 0)
467
            goto mix_2to1;
468
    case CONVERT (A52_3F, A52_MONO):
469
    mix_3to1:
470
        mix3to1 (samples, bias);
471
        break;
472

    
473
    case CONVERT (A52_3F1R, A52_MONO):
474
        if (slev == 0)
475
            goto mix_3to1;
476
    case CONVERT (A52_2F2R, A52_MONO):
477
        if (slev == 0)
478
            goto mix_2to1;
479
        mix4to1 (samples, bias);
480
        break;
481

    
482
    case CONVERT (A52_3F2R, A52_MONO):
483
        if (slev == 0)
484
            goto mix_3to1;
485
        mix5to1 (samples, bias);
486
        break;
487

    
488
    case CONVERT (A52_MONO, A52_DOLBY):
489
        memcpy (samples + 256, samples, 256 * sizeof (sample_t));
490
        break;
491

    
492
    case CONVERT (A52_3F, A52_STEREO):
493
    case CONVERT (A52_3F, A52_DOLBY):
494
    mix_3to2:
495
        mix3to2 (samples, bias);
496
        break;
497

    
498
    case CONVERT (A52_2F1R, A52_STEREO):
499
        if (slev == 0)
500
            break;
501
        mix21to2 (samples, samples + 256, bias);
502
        break;
503

    
504
    case CONVERT (A52_2F1R, A52_DOLBY):
505
        mix21toS (samples, bias);
506
        break;
507

    
508
    case CONVERT (A52_3F1R, A52_STEREO):
509
        if (slev == 0)
510
            goto mix_3to2;
511
        mix31to2 (samples, bias);
512
        break;
513

    
514
    case CONVERT (A52_3F1R, A52_DOLBY):
515
        mix31toS (samples, bias);
516
        break;
517

    
518
    case CONVERT (A52_2F2R, A52_STEREO):
519
        if (slev == 0)
520
            break;
521
        mix2to1 (samples, samples + 512, bias);
522
        mix2to1 (samples + 256, samples + 768, bias);
523
        break;
524

    
525
    case CONVERT (A52_2F2R, A52_DOLBY):
526
        mix22toS (samples, bias);
527
        break;
528

    
529
    case CONVERT (A52_3F2R, A52_STEREO):
530
        if (slev == 0)
531
            goto mix_3to2;
532
        mix32to2 (samples, bias);
533
        break;
534

    
535
    case CONVERT (A52_3F2R, A52_DOLBY):
536
        mix32toS (samples, bias);
537
        break;
538

    
539
    case CONVERT (A52_3F1R, A52_3F):
540
        if (slev == 0)
541
            break;
542
        mix21to2 (samples, samples + 512, bias);
543
        break;
544

    
545
    case CONVERT (A52_3F2R, A52_3F):
546
        if (slev == 0)
547
            break;
548
        mix2to1 (samples, samples + 768, bias);
549
        mix2to1 (samples + 512, samples + 1024, bias);
550
        break;
551

    
552
    case CONVERT (A52_3F1R, A52_2F1R):
553
        mix3to2 (samples, bias);
554
        memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
555
        break;
556

    
557
    case CONVERT (A52_2F2R, A52_2F1R):
558
        mix2to1 (samples + 512, samples + 768, bias);
559
        break;
560

    
561
    case CONVERT (A52_3F2R, A52_2F1R):
562
        mix3to2 (samples, bias);
563
        move2to1 (samples + 768, samples + 512, bias);
564
        break;
565

    
566
    case CONVERT (A52_3F2R, A52_3F1R):
567
        mix2to1 (samples + 768, samples + 1024, bias);
568
        break;
569

    
570
    case CONVERT (A52_2F1R, A52_2F2R):
571
        memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
572
        break;
573

    
574
    case CONVERT (A52_3F1R, A52_2F2R):
575
        mix3to2 (samples, bias);
576
        memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
577
        break;
578

    
579
    case CONVERT (A52_3F2R, A52_2F2R):
580
        mix3to2 (samples, bias);
581
        memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
582
        memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
583
        break;
584

    
585
    case CONVERT (A52_3F1R, A52_3F2R):
586
        memcpy (samples + 1027, samples + 768, 256 * sizeof (sample_t));
587
        break;
588
    }
589
}
590

    
591
void a52_upmix (sample_t * samples, int acmod, int output)
592
{
593
    switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
594

    
595
    case CONVERT (A52_CHANNEL, A52_CHANNEL2):
596
        memcpy (samples + 256, samples, 256 * sizeof (sample_t));
597
        break;
598

    
599
    case CONVERT (A52_3F2R, A52_MONO):
600
        zero (samples + 1024);
601
    case CONVERT (A52_3F1R, A52_MONO):
602
    case CONVERT (A52_2F2R, A52_MONO):
603
        zero (samples + 768);
604
    case CONVERT (A52_3F, A52_MONO):
605
    case CONVERT (A52_2F1R, A52_MONO):
606
        zero (samples + 512);
607
    case CONVERT (A52_CHANNEL, A52_MONO):
608
    case CONVERT (A52_STEREO, A52_MONO):
609
        zero (samples + 256);
610
        break;
611

    
612
    case CONVERT (A52_3F2R, A52_STEREO):
613
    case CONVERT (A52_3F2R, A52_DOLBY):
614
        zero (samples + 1024);
615
    case CONVERT (A52_3F1R, A52_STEREO):
616
    case CONVERT (A52_3F1R, A52_DOLBY):
617
        zero (samples + 768);
618
    case CONVERT (A52_3F, A52_STEREO):
619
    case CONVERT (A52_3F, A52_DOLBY):
620
    mix_3to2:
621
        memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
622
        zero (samples + 256);
623
        break;
624

    
625
    case CONVERT (A52_2F2R, A52_STEREO):
626
    case CONVERT (A52_2F2R, A52_DOLBY):
627
        zero (samples + 768);
628
    case CONVERT (A52_2F1R, A52_STEREO):
629
    case CONVERT (A52_2F1R, A52_DOLBY):
630
        zero (samples + 512);
631
        break;
632

    
633
    case CONVERT (A52_3F2R, A52_3F):
634
        zero (samples + 1024);
635
    case CONVERT (A52_3F1R, A52_3F):
636
    case CONVERT (A52_2F2R, A52_2F1R):
637
        zero (samples + 768);
638
        break;
639

    
640
    case CONVERT (A52_3F2R, A52_3F1R):
641
        zero (samples + 1024);
642
        break;
643

    
644
    case CONVERT (A52_3F2R, A52_2F1R):
645
        zero (samples + 1024);
646
    case CONVERT (A52_3F1R, A52_2F1R):
647
    mix_31to21:
648
        memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
649
        goto mix_3to2;
650

    
651
    case CONVERT (A52_3F2R, A52_2F2R):
652
        memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
653
        goto mix_31to21;
654
    }
655
}