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