1 /*****************************************************************************
2 * ac3_downmix.c: ac3 downmix functions
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: ac3_downmix.c,v 1.19 2001/04/06 09:15:47 sam Exp $
7 * Authors: Michel Kaempf <maxx@via.ecp.fr>
8 * Aaron Holtzman <aholtzma@engr.uvic.ca>
9 * Renaud Dartus <reno@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
27 #include "int_types.h"
28 #include "ac3_decoder.h"
29 #include "ac3_internal.h"
31 #include "ac3_downmix.h"
33 /* Pre-scaled downmix coefficients */
34 static const float cmixlev_lut[4] = { 0.2928, 0.2468, 0.2071, 0.2468 };
35 static const float smixlev_lut[4] = { 0.2928, 0.2071, 0.0 , 0.2071 };
37 /* Downmix into _two_ channels...other downmix modes aren't implemented
38 * to reduce complexity. Realistically, there aren't many machines around
39 * with > 2 channel output anyways */
41 int __inline__ downmix (ac3dec_t * p_ac3dec, float * channel, s16 * out_buf)
50 if (p_ac3dec->bsi.acmod & 0x1) /* have center */
51 dm_par.clev = cmixlev_lut[p_ac3dec->bsi.cmixlev];
53 if (p_ac3dec->bsi.acmod & 0x4) /* have surround channels */
54 dm_par.slev = smixlev_lut[p_ac3dec->bsi.surmixlev];
56 dm_par.unit /= 1.0 + dm_par.clev + dm_par.slev;
57 dm_par.clev *= dm_par.unit;
58 dm_par.slev *= dm_par.unit;
62 if (p_ac3dec->bsi.acmod > 7)
63 intf_ErrMsg( "ac3dec: (downmix) invalid acmod number" );
66 switch(p_ac3dec->bsi.acmod)
69 downmix_3f_2r_to_2ch_c (channel, &dm_par);
72 downmix_2f_2r_to_2ch_c (channel, &dm_par);
75 downmix_3f_1r_to_2ch_c (channel, &dm_par);
78 downmix_2f_1r_to_2ch_c (channel, &dm_par);
81 downmix_3f_0r_to_2ch_c (channel, &dm_par);
87 if (p_ac3dec->bsi.acmod == 1)
88 center = p_ac3dec->samples.channel[0];
89 else if (p_ac3dec->bsi.acmod == 0)
90 center = p_ac3dec->samples.channel[0]; */