]> git.sesse.net Git - vlc/blob - src/ac3_decoder/ac3_downmix.c
* Header cleaning: filled all empty authors fields, added CVS $Id stuff.
[vlc] / src / ac3_decoder / ac3_downmix.c
1 /*****************************************************************************
2  * ac3_downmix.c: ac3 downmix functions
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: ac3_downmix.c,v 1.18 2001/03/21 13:42:34 sam Exp $
6  *
7  * Authors: Michel Kaempf <maxx@via.ecp.fr>
8  *          Aaron Holtzman <aholtzma@engr.uvic.ca>
9  *          Renaud Dartus <reno@videolan.org>
10  *
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.
15  * 
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.
20  *
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  *****************************************************************************/
25 #include "defs.h"
26
27 #include "int_types.h"
28 #include "ac3_decoder.h"
29 #include "ac3_internal.h"
30
31 #include "ac3_downmix.h"
32
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 };
36
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 */
40
41 int __inline__ downmix (ac3dec_t * p_ac3dec, float * channel, s16 * out_buf)
42 {
43
44     dm_par_t    dm_par;
45     
46     dm_par.clev = 0.0;
47     dm_par.slev = 0.0;
48     dm_par.unit = 1.0;
49
50     if (p_ac3dec->bsi.acmod & 0x1) /* have center */
51         dm_par.clev = cmixlev_lut[p_ac3dec->bsi.cmixlev];
52
53     if (p_ac3dec->bsi.acmod & 0x4) /* have surround channels */
54         dm_par.slev = smixlev_lut[p_ac3dec->bsi.surmixlev];
55
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;
59
60
61     /*
62     if (p_ac3dec->bsi.acmod > 7)
63         intf_ErrMsg( "ac3dec: (downmix) invalid acmod number" );
64     */
65     
66     switch(p_ac3dec->bsi.acmod)
67     {
68         case 7:         // 3/2
69                     downmix_3f_2r_to_2ch_c (channel, &dm_par);
70                         break;
71                 case 6:         // 2/2
72                         downmix_2f_2r_to_2ch_c (channel, &dm_par);
73                         break;
74                 case 5:         // 3/1
75                         downmix_3f_1r_to_2ch_c (channel, &dm_par);
76                         break;
77                 case 4:         // 2/1
78                         downmix_2f_1r_to_2ch_c (channel, &dm_par);
79                         break;
80                 case 3:         // 3/0
81                         downmix_3f_0r_to_2ch_c (channel, &dm_par);
82                         break;
83                 case 2:
84                         break;
85                 default:        // 1/0
86             /* FIXME
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]; */
91             return 1;
92         }
93     return 0;
94 }
95