dts_downmix.c

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

Generated on Tue Dec 13 14:47:27 2005 for guliverkli by  doxygen 1.4.5