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