- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# downmix.c

    00001 /*
    00002  * downmix.c
    00003  * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
    00004  * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
    00005  *
    00006  * This file is part of a52dec, a free ATSC A-52 stream decoder.
    00007  * See http://liba52.sourceforge.net/ for updates.
    00008  *
    00009  * a52dec is free software; you can redistribute it and/or modify
    00010  * it under the terms of the GNU General Public License as published by
    00011  * the Free Software Foundation; either version 2 of the License, or
    00012  * (at your option) any later version.
    00013  *
    00014  * a52dec is distributed in the hope that it will be useful,
    00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00017  * GNU General Public License for more details.
    00018  *
    00019  * You should have received a copy of the GNU General Public License
    00020  * along with this program; if not, write to the Free Software
    00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00022  */
    00023
    00024 #include "config.h"
    00025
    00026 #include <string.h>
    00027 #include <inttypes.h>
    00028
    00029 #include "a52.h"
    00030 #include "a52_internal.h"
    00031
    00032 #define CONVERT(acmod,output) (((output) << 3) + (acmod))
    00033
    00034 int a52_downmix_init (int input, int flags, sample_t * level,
    00035                       sample_t clev, sample_t slev)
    00036 {
    00037     static uint8_t table[11][8] = {
    00038         {A52_CHANNEL,   A52_DOLBY,      A52_STEREO,     A52_STEREO,
    00039          A52_STEREO,    A52_STEREO,     A52_STEREO,     A52_STEREO},
    00040         {A52_MONO,      A52_MONO,       A52_MONO,       A52_MONO,
    00041          A52_MONO,      A52_MONO,       A52_MONO,       A52_MONO},
    00042         {A52_CHANNEL,   A52_DOLBY,      A52_STEREO,     A52_STEREO,
    00043          A52_STEREO,    A52_STEREO,     A52_STEREO,     A52_STEREO},
    00044         {A52_CHANNEL,   A52_DOLBY,      A52_STEREO,     A52_3F,
    00045          A52_STEREO,    A52_3F,         A52_STEREO,     A52_3F},
    00046         {A52_CHANNEL,   A52_DOLBY,      A52_STEREO,     A52_STEREO,
    00047          A52_2F1R,      A52_2F1R,       A52_2F1R,       A52_2F1R},
    00048         {A52_CHANNEL,   A52_DOLBY,      A52_STEREO,     A52_STEREO,
    00049          A52_2F1R,      A52_3F1R,       A52_2F1R,       A52_3F1R},
    00050         {A52_CHANNEL,   A52_DOLBY,      A52_STEREO,     A52_3F,
    00051          A52_2F2R,      A52_2F2R,       A52_2F2R,       A52_2F2R},
    00052         {A52_CHANNEL,   A52_DOLBY,      A52_STEREO,     A52_3F,
    00053          A52_2F2R,      A52_3F2R,       A52_2F2R,       A52_3F2R},
    00054         {A52_CHANNEL1,  A52_MONO,       A52_MONO,       A52_MONO,
    00055          A52_MONO,      A52_MONO,       A52_MONO,       A52_MONO},
    00056         {A52_CHANNEL2,  A52_MONO,       A52_MONO,       A52_MONO,
    00057          A52_MONO,      A52_MONO,       A52_MONO,       A52_MONO},
    00058         {A52_CHANNEL,   A52_DOLBY,      A52_STEREO,     A52_DOLBY,
    00059          A52_DOLBY,     A52_DOLBY,      A52_DOLBY,      A52_DOLBY}
    00060     };
    00061     int output;
    00062
    00063     output = flags & A52_CHANNEL_MASK;
    00064     if (output > A52_DOLBY)
    00065         return -1;
    00066
    00067     output = table[output][input & 7];
    00068
    00069     if ((output == A52_STEREO) &&
    00070         ((input == A52_DOLBY) || ((input == A52_3F) && (clev == LEVEL_3DB))))
    00071         output = A52_DOLBY;
    00072
    00073     if (flags & A52_ADJUST_LEVEL)
    00074         switch (CONVERT (input & 7, output)) {
    00075
    00076         case CONVERT (A52_3F, A52_MONO):
    00077             *level *= LEVEL_3DB / (1 + clev);
    00078             break;
    00079
    00080         case CONVERT (A52_STEREO, A52_MONO):
    00081         case CONVERT (A52_2F2R, A52_2F1R):
    00082         case CONVERT (A52_3F2R, A52_3F1R):
    00083         level_3db:
    00084             *level *= LEVEL_3DB;
    00085             break;
    00086
    00087         case CONVERT (A52_3F2R, A52_2F1R):
    00088             if (clev < LEVEL_PLUS3DB - 1)
    00089                 goto level_3db;
    00090             /* break thru */
    00091         case CONVERT (A52_3F, A52_STEREO):
    00092         case CONVERT (A52_3F1R, A52_2F1R):
    00093         case CONVERT (A52_3F1R, A52_2F2R):
    00094         case CONVERT (A52_3F2R, A52_2F2R):
    00095             *level /= 1 + clev;
    00096             break;
    00097
    00098         case CONVERT (A52_2F1R, A52_MONO):
    00099             *level *= LEVEL_PLUS3DB / (2 + slev);
    00100             break;
    00101
    00102         case CONVERT (A52_2F1R, A52_STEREO):
    00103         case CONVERT (A52_3F1R, A52_3F):
    00104             *level /= 1 + slev * LEVEL_3DB;
    00105             break;
    00106
    00107         case CONVERT (A52_3F1R, A52_MONO):
    00108             *level *= LEVEL_3DB / (1 + clev + 0.5 * slev);
    00109             break;
    00110
    00111         case CONVERT (A52_3F1R, A52_STEREO):
    00112             *level /= 1 + clev + slev * LEVEL_3DB;
    00113             break;
    00114
    00115         case CONVERT (A52_2F2R, A52_MONO):
    00116             *level *= LEVEL_3DB / (1 + slev);
    00117             break;
    00118
    00119         case CONVERT (A52_2F2R, A52_STEREO):
    00120         case CONVERT (A52_3F2R, A52_3F):
    00121             *level /= 1 + slev;
    00122             break;
    00123
    00124         case CONVERT (A52_3F2R, A52_MONO):
    00125             *level *= LEVEL_3DB / (1 + clev + slev);
    00126             break;
    00127
    00128         case CONVERT (A52_3F2R, A52_STEREO):
    00129             *level /= 1 + clev + slev;
    00130             break;
    00131
    00132         case CONVERT (A52_MONO, A52_DOLBY):
    00133             *level *= LEVEL_PLUS3DB;
    00134             break;
    00135
    00136         case CONVERT (A52_3F, A52_DOLBY):
    00137         case CONVERT (A52_2F1R, A52_DOLBY):
    00138             *level *= 1 / (1 + LEVEL_3DB);
    00139             break;
    00140
    00141         case CONVERT (A52_3F1R, A52_DOLBY):
    00142         case CONVERT (A52_2F2R, A52_DOLBY):
    00143             *level *= 1 / (1 + 2 * LEVEL_3DB);
    00144             break;
    00145
    00146         case CONVERT (A52_3F2R, A52_DOLBY):
    00147             *level *= 1 / (1 + 3 * LEVEL_3DB);
    00148             break;
    00149         }
    00150
    00151     return output;
    00152 }
    00153
    00154 int a52_downmix_coeff (sample_t * coeff, int acmod, int output, sample_t level,
    00155                        sample_t clev, sample_t slev)
    00156 {
    00157     switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
    00158
    00159     case CONVERT (A52_CHANNEL, A52_CHANNEL):
    00160     case CONVERT (A52_MONO, A52_MONO):
    00161     case CONVERT (A52_STEREO, A52_STEREO):
    00162     case CONVERT (A52_3F, A52_3F):
    00163     case CONVERT (A52_2F1R, A52_2F1R):
    00164     case CONVERT (A52_3F1R, A52_3F1R):
    00165     case CONVERT (A52_2F2R, A52_2F2R):
    00166     case CONVERT (A52_3F2R, A52_3F2R):
    00167     case CONVERT (A52_STEREO, A52_DOLBY):
    00168         coeff[0] = coeff[1] = coeff[2] = coeff[3] = coeff[4] = level;
    00169         return 0;
    00170
    00171     case CONVERT (A52_CHANNEL, A52_MONO):
    00172         coeff[0] = coeff[1] = level * LEVEL_6DB;
    00173         return 3;
    00174
    00175     case CONVERT (A52_STEREO, A52_MONO):
    00176         coeff[0] = coeff[1] = level * LEVEL_3DB;
    00177         return 3;
    00178
    00179     case CONVERT (A52_3F, A52_MONO):
    00180         coeff[0] = coeff[2] = level * LEVEL_3DB;
    00181         coeff[1] = level * clev * LEVEL_PLUS3DB;
    00182         return 7;
    00183
    00184     case CONVERT (A52_2F1R, A52_MONO):
    00185         coeff[0] = coeff[1] = level * LEVEL_3DB;
    00186         coeff[2] = level * slev * LEVEL_3DB;
    00187         return 7;
    00188
    00189     case CONVERT (A52_2F2R, A52_MONO):
    00190         coeff[0] = coeff[1] = level * LEVEL_3DB;
    00191         coeff[2] = coeff[3] = level * slev * LEVEL_3DB;
    00192         return 15;
    00193
    00194     case CONVERT (A52_3F1R, A52_MONO):
    00195         coeff[0] = coeff[2] = level * LEVEL_3DB;
    00196         coeff[1] = level * clev * LEVEL_PLUS3DB;
    00197         coeff[3] = level * slev * LEVEL_3DB;
    00198         return 15;
    00199
    00200     case CONVERT (A52_3F2R, A52_MONO):
    00201         coeff[0] = coeff[2] = level * LEVEL_3DB;
    00202         coeff[1] = level * clev * LEVEL_PLUS3DB;
    00203         coeff[3] = coeff[4] = level * slev * LEVEL_3DB;
    00204         return 31;
    00205
    00206     case CONVERT (A52_MONO, A52_DOLBY):
    00207         coeff[0] = level * LEVEL_3DB;
    00208         return 0;
    00209
    00210     case CONVERT (A52_3F, A52_DOLBY):
    00211         clev = LEVEL_3DB;
    00212     case CONVERT (A52_3F, A52_STEREO):
    00213     case CONVERT (A52_3F1R, A52_2F1R):
    00214     case CONVERT (A52_3F2R, A52_2F2R):
    00215         coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
    00216         coeff[1] = level * clev;
    00217         return 7;
    00218
    00219     case CONVERT (A52_2F1R, A52_DOLBY):
    00220         slev = 1;
    00221     case CONVERT (A52_2F1R, A52_STEREO):
    00222         coeff[0] = coeff[1] = level;
    00223         coeff[2] = level * slev * LEVEL_3DB;
    00224         return 7;
    00225
    00226     case CONVERT (A52_3F1R, A52_DOLBY):
    00227         clev = LEVEL_3DB;
    00228         slev = 1;
    00229     case CONVERT (A52_3F1R, A52_STEREO):
    00230         coeff[0] = coeff[2] = level;
    00231         coeff[1] = level * clev;
    00232         coeff[3] = level * slev * LEVEL_3DB;
    00233         return 15;
    00234
    00235     case CONVERT (A52_2F2R, A52_DOLBY):
    00236         slev = LEVEL_3DB;
    00237     case CONVERT (A52_2F2R, A52_STEREO):
    00238         coeff[0] = coeff[1] = level;
    00239         coeff[2] = coeff[3] = level * slev;
    00240         return 15;
    00241
    00242     case CONVERT (A52_3F2R, A52_DOLBY):
    00243         clev = LEVEL_3DB;
    00244     case CONVERT (A52_3F2R, A52_2F1R):
    00245         slev = LEVEL_3DB;
    00246     case CONVERT (A52_3F2R, A52_STEREO):
    00247         coeff[0] = coeff[2] = level;
    00248         coeff[1] = level * clev;
    00249         coeff[3] = coeff[4] = level * slev;
    00250         return 31;
    00251
    00252     case CONVERT (A52_3F1R, A52_3F):
    00253         coeff[0] = coeff[1] = coeff[2] = level;
    00254         coeff[3] = level * slev * LEVEL_3DB;
    00255         return 13;
    00256
    00257     case CONVERT (A52_3F2R, A52_3F):
    00258         coeff[0] = coeff[1] = coeff[2] = level;
    00259         coeff[3] = coeff[4] = level * slev;
    00260         return 29;
    00261
    00262     case CONVERT (A52_2F2R, A52_2F1R):
    00263         coeff[0] = coeff[1] = level;
    00264         coeff[2] = coeff[3] = level * LEVEL_3DB;
    00265         return 12;
    00266
    00267     case CONVERT (A52_3F2R, A52_3F1R):
    00268         coeff[0] = coeff[1] = coeff[2] = level;
    00269         coeff[3] = coeff[4] = level * LEVEL_3DB;
    00270         return 24;
    00271
    00272     case CONVERT (A52_2F1R, A52_2F2R):
    00273         coeff[0] = coeff[1] = level;
    00274         coeff[2] = level * LEVEL_3DB;
    00275         return 0;
    00276
    00277     case CONVERT (A52_3F1R, A52_2F2R):
    00278         coeff[0] = coeff[2] = level;
    00279         coeff[1] = level * clev;
    00280         coeff[3] = level * LEVEL_3DB;
    00281         return 7;
    00282
    00283     case CONVERT (A52_3F1R, A52_3F2R):
    00284         coeff[0] = coeff[1] = coeff[2] = level;
    00285         coeff[3] = level * LEVEL_3DB;
    00286         return 0;
    00287
    00288     case CONVERT (A52_CHANNEL, A52_CHANNEL1):
    00289         coeff[0] = level;
    00290         coeff[1] = 0;
    00291         return 0;
    00292
    00293     case CONVERT (A52_CHANNEL, A52_CHANNEL2):
    00294         coeff[0] = 0;
    00295         coeff[1] = level;
    00296         return 0;
    00297     }
    00298
    00299     return -1;  /* NOTREACHED */
    00300 }
    00301
    00302 static void mix2to1 (sample_t * dest, sample_t * src, sample_t bias)
    00303 {
    00304     int i;
    00305
    00306     for (i = 0; i < 256; i++)
    00307         dest[i] += src[i] + bias;
    00308 }
    00309
    00310 static void mix3to1 (sample_t * samples, sample_t bias)
    00311 {
    00312     int i;
    00313
    00314     for (i = 0; i < 256; i++)
    00315         samples[i] += samples[i + 256] + samples[i + 512] + bias;
    00316 }
    00317
    00318 static void mix4to1 (sample_t * samples, sample_t bias)
    00319 {
    00320     int i;
    00321
    00322     for (i = 0; i < 256; i++)
    00323         samples[i] += (samples[i + 256] + samples[i + 512] +
    00324                        samples[i + 768] + bias);
    00325 }
    00326
    00327 static void mix5to1 (sample_t * samples, sample_t bias)
    00328 {
    00329     int i;
    00330
    00331     for (i = 0; i < 256; i++)
    00332         samples[i] += (samples[i + 256] + samples[i + 512] +
    00333                        samples[i + 768] + samples[i + 1024] + bias);
    00334 }
    00335
    00336 static void mix3to2 (sample_t * samples, sample_t bias)
    00337 {
    00338     int i;
    00339     sample_t common;
    00340
    00341     for (i = 0; i < 256; i++) {
    00342         common = samples[i + 256] + bias;
    00343         samples[i] += common;
    00344         samples[i + 256] = samples[i + 512] + common;
    00345     }
    00346 }
    00347
    00348 static void mix21to2 (sample_t * left, sample_t * right, sample_t bias)
    00349 {
    00350     int i;
    00351     sample_t common;
    00352
    00353     for (i = 0; i < 256; i++) {
    00354         common = right[i + 256] + bias;
    00355         left[i] += common;
    00356         right[i] += common;
    00357     }
    00358 }
    00359
    00360 static void mix21toS (sample_t * samples, sample_t bias)
    00361 {
    00362     int i;
    00363     sample_t surround;
    00364
    00365     for (i = 0; i < 256; i++) {
    00366         surround = samples[i + 512];
    00367         samples[i] += bias - surround;
    00368         samples[i + 256] += bias + surround;
    00369     }
    00370 }
    00371
    00372 static void mix31to2 (sample_t * samples, sample_t bias)
    00373 {
    00374     int i;
    00375     sample_t common;
    00376
    00377     for (i = 0; i < 256; i++) {
    00378         common = samples[i + 256] + samples[i + 768] + bias;
    00379         samples[i] += common;
    00380         samples[i + 256] = samples[i + 512] + common;
    00381     }
    00382 }
    00383
    00384 static void mix31toS (sample_t * samples, sample_t bias)
    00385 {
    00386     int i;
    00387     sample_t common, surround;
    00388
    00389     for (i = 0; i < 256; i++) {
    00390         common = samples[i + 256] + bias;
    00391         surround = samples[i + 768];
    00392         samples[i] += common - surround;
    00393         samples[i + 256] = samples[i + 512] + common + surround;
    00394     }
    00395 }
    00396
    00397 static void mix22toS (sample_t * samples, sample_t bias)
    00398 {
    00399     int i;
    00400     sample_t surround;
    00401
    00402     for (i = 0; i < 256; i++) {
    00403         surround = samples[i + 512] + samples[i + 768];
    00404         samples[i] += bias - surround;
    00405         samples[i + 256] += bias + surround;
    00406     }
    00407 }
    00408
    00409 static void mix32to2 (sample_t * samples, sample_t bias)
    00410 {
    00411     int i;
    00412     sample_t common;
    00413
    00414     for (i = 0; i < 256; i++) {
    00415         common = samples[i + 256] + bias;
    00416         samples[i] += common + samples[i + 768];
    00417         samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
    00418     }
    00419 }
    00420
    00421 static void mix32toS (sample_t * samples, sample_t bias)
    00422 {
    00423     int i;
    00424     sample_t common, surround;
    00425
    00426     for (i = 0; i < 256; i++) {
    00427         common = samples[i + 256] + bias;
    00428         surround = samples[i + 768] + samples[i + 1024];
    00429         samples[i] += common - surround;
    00430         samples[i + 256] = samples[i + 512] + common + surround;
    00431     }
    00432 }
    00433
    00434 static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
    00435 {
    00436     int i;
    00437
    00438     for (i = 0; i < 256; i++)
    00439         dest[i] = src[i] + src[i + 256] + bias;
    00440 }
    00441
    00442 static void zero (sample_t * samples)
    00443 {
    00444     int i;
    00445
    00446     for (i = 0; i < 256; i++)
    00447         samples[i] = 0;
    00448 }
    00449
    00450 void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
    00451                   sample_t clev, sample_t slev)
    00452 {
    00453     switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
    00454
    00455     case CONVERT (A52_CHANNEL, A52_CHANNEL2):
    00456         memcpy (samples, samples + 256, 256 * sizeof (sample_t));
    00457         break;
    00458
    00459     case CONVERT (A52_CHANNEL, A52_MONO):
    00460     case CONVERT (A52_STEREO, A52_MONO):
    00461     mix_2to1:
    00462         mix2to1 (samples, samples + 256, bias);
    00463         break;
    00464
    00465     case CONVERT (A52_2F1R, A52_MONO):
    00466         if (slev == 0)
    00467             goto mix_2to1;
    00468     case CONVERT (A52_3F, A52_MONO):
    00469     mix_3to1:
    00470         mix3to1 (samples, bias);
    00471         break;
    00472
    00473     case CONVERT (A52_3F1R, A52_MONO):
    00474         if (slev == 0)
    00475             goto mix_3to1;
    00476     case CONVERT (A52_2F2R, A52_MONO):
    00477         if (slev == 0)
    00478             goto mix_2to1;
    00479         mix4to1 (samples, bias);
    00480         break;
    00481
    00482     case CONVERT (A52_3F2R, A52_MONO):
    00483         if (slev == 0)
    00484             goto mix_3to1;
    00485         mix5to1 (samples, bias);
    00486         break;
    00487
    00488     case CONVERT (A52_MONO, A52_DOLBY):
    00489         memcpy (samples + 256, samples, 256 * sizeof (sample_t));
    00490         break;
    00491
    00492     case CONVERT (A52_3F, A52_STEREO):
    00493     case CONVERT (A52_3F, A52_DOLBY):
    00494     mix_3to2:
    00495         mix3to2 (samples, bias);
    00496         break;
    00497
    00498     case CONVERT (A52_2F1R, A52_STEREO):
    00499         if (slev == 0)
    00500             break;
    00501         mix21to2 (samples, samples + 256, bias);
    00502         break;
    00503
    00504     case CONVERT (A52_2F1R, A52_DOLBY):
    00505         mix21toS (samples, bias);
    00506         break;
    00507
    00508     case CONVERT (A52_3F1R, A52_STEREO):
    00509         if (slev == 0)
    00510             goto mix_3to2;
    00511         mix31to2 (samples, bias);
    00512         break;
    00513
    00514     case CONVERT (A52_3F1R, A52_DOLBY):
    00515         mix31toS (samples, bias);
    00516         break;
    00517
    00518     case CONVERT (A52_2F2R, A52_STEREO):
    00519         if (slev == 0)
    00520             break;
    00521         mix2to1 (samples, samples + 512, bias);
    00522         mix2to1 (samples + 256, samples + 768, bias);
    00523         break;
    00524
    00525     case CONVERT (A52_2F2R, A52_DOLBY):
    00526         mix22toS (samples, bias);
    00527         break;
    00528
    00529     case CONVERT (A52_3F2R, A52_STEREO):
    00530         if (slev == 0)
    00531             goto mix_3to2;
    00532         mix32to2 (samples, bias);
    00533         break;
    00534
    00535     case CONVERT (A52_3F2R, A52_DOLBY):
    00536         mix32toS (samples, bias);
    00537         break;
    00538
    00539     case CONVERT (A52_3F1R, A52_3F):
    00540         if (slev == 0)
    00541             break;
    00542         mix21to2 (samples, samples + 512, bias);
    00543         break;
    00544
    00545     case CONVERT (A52_3F2R, A52_3F):
    00546         if (slev == 0)
    00547             break;
    00548         mix2to1 (samples, samples + 768, bias);
    00549         mix2to1 (samples + 512, samples + 1024, bias);
    00550         break;
    00551
    00552     case CONVERT (A52_3F1R, A52_2F1R):
    00553         mix3to2 (samples, bias);
    00554         memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
    00555         break;
    00556
    00557     case CONVERT (A52_2F2R, A52_2F1R):
    00558         mix2to1 (samples + 512, samples + 768, bias);
    00559         break;
    00560
    00561     case CONVERT (A52_3F2R, A52_2F1R):
    00562         mix3to2 (samples, bias);
    00563         move2to1 (samples + 768, samples + 512, bias);
    00564         break;
    00565
    00566     case CONVERT (A52_3F2R, A52_3F1R):
    00567         mix2to1 (samples + 768, samples + 1024, bias);
    00568         break;
    00569
    00570     case CONVERT (A52_2F1R, A52_2F2R):
    00571         memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
    00572         break;
    00573
    00574     case CONVERT (A52_3F1R, A52_2F2R):
    00575         mix3to2 (samples, bias);
    00576         memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
    00577         break;
    00578
    00579     case CONVERT (A52_3F2R, A52_2F2R):
    00580         mix3to2 (samples, bias);
    00581         memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
    00582         memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
    00583         break;
    00584
    00585     case CONVERT (A52_3F1R, A52_3F2R):
    00586         memcpy (samples + 1027, samples + 768, 256 * sizeof (sample_t));
    00587         break;
    00588     }
    00589 }
    00590
    00591 void a52_upmix (sample_t * samples, int acmod, int output)
    00592 {
    00593     switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
    00594
    00595     case CONVERT (A52_CHANNEL, A52_CHANNEL2):
    00596         memcpy (samples + 256, samples, 256 * sizeof (sample_t));
    00597         break;
    00598
    00599     case CONVERT (A52_3F2R, A52_MONO):
    00600         zero (samples + 1024);
    00601     case CONVERT (A52_3F1R, A52_MONO):
    00602     case CONVERT (A52_2F2R, A52_MONO):
    00603         zero (samples + 768);
    00604     case CONVERT (A52_3F, A52_MONO):
    00605     case CONVERT (A52_2F1R, A52_MONO):
    00606         zero (samples + 512);
    00607     case CONVERT (A52_CHANNEL, A52_MONO):
    00608     case CONVERT (A52_STEREO, A52_MONO):
    00609         zero (samples + 256);
    00610         break;
    00611
    00612     case CONVERT (A52_3F2R, A52_STEREO):
    00613     case CONVERT (A52_3F2R, A52_DOLBY):
    00614         zero (samples + 1024);
    00615     case CONVERT (A52_3F1R, A52_STEREO):
    00616     case CONVERT (A52_3F1R, A52_DOLBY):
    00617         zero (samples + 768);
    00618     case CONVERT (A52_3F, A52_STEREO):
    00619     case CONVERT (A52_3F, A52_DOLBY):
    00620     mix_3to2:
    00621         memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
    00622         zero (samples + 256);
    00623         break;
    00624
    00625     case CONVERT (A52_2F2R, A52_STEREO):
    00626     case CONVERT (A52_2F2R, A52_DOLBY):
    00627         zero (samples + 768);
    00628     case CONVERT (A52_2F1R, A52_STEREO):
    00629     case CONVERT (A52_2F1R, A52_DOLBY):
    00630         zero (samples + 512);
    00631         break;
    00632
    00633     case CONVERT (A52_3F2R, A52_3F):
    00634         zero (samples + 1024);
    00635     case CONVERT (A52_3F1R, A52_3F):
    00636     case CONVERT (A52_2F2R, A52_2F1R):
    00637         zero (samples + 768);
    00638         break;
    00639
    00640     case CONVERT (A52_3F2R, A52_3F1R):
    00641         zero (samples + 1024);
    00642         break;
    00643
    00644     case CONVERT (A52_3F2R, A52_2F1R):
    00645         zero (samples + 1024);
    00646     case CONVERT (A52_3F1R, A52_2F1R):
    00647     mix_31to21:
    00648         memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
    00649         goto mix_3to2;
    00650
    00651     case CONVERT (A52_3F2R, A52_2F2R):
    00652         memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
    00653         goto mix_31to21;
    00654     }
    00655 }