]> git.sesse.net Git - vlc/blob - src/ac3_decoder/ac3_rematrix.c
1f9f7b6fad3baea0664987efc3e1e995a4b94b01
[vlc] / src / ac3_decoder / ac3_rematrix.c
1 /*****************************************************************************
2  * ac3_rematrix.c: ac3 audio rematrixing
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors: Michel Kaempf <maxx@via.ecp.fr>
7  *          Aaron Holtzman <aholtzma@engr.uvic.ca>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23 #include "defs.h"
24
25 #include "int_types.h"
26 #include "ac3_decoder.h"
27 #include "ac3_internal.h"
28
29 struct rematrix_band_s {
30     u32 start;
31     u32 end;
32 };
33
34 static const struct rematrix_band_s rematrix_band[] = { {13,24}, {25,36}, {37 ,60}, {61,252}};
35
36 static __inline__ u32 min (u32 a, u32 b)
37 {
38     return (a < b ? a : b);
39 }
40
41 /* This routine simply does stereo rematixing for the 2 channel
42  * stereo mode */
43 void rematrix (ac3dec_t * p_ac3dec)
44 {
45     u32 num_bands;
46     u32 start;
47     u32 end;
48     u32 i,j;
49     float left,right;
50
51     if (p_ac3dec->audblk.cplinu || p_ac3dec->audblk.cplbegf > 2)
52         num_bands = 4;
53     else if (p_ac3dec->audblk.cplbegf > 0)
54         num_bands = 3;
55     else
56         num_bands = 2;
57
58     for (i=0;i < num_bands; i++) {
59         if (!p_ac3dec->audblk.rematflg[i])
60             continue;
61
62         start = rematrix_band[i].start;
63         end = min(rematrix_band[i].end ,12 * p_ac3dec->audblk.cplbegf + 36);
64
65         for (j=start;j < end; j++) {
66             left  = 0.5f * (p_ac3dec->coeffs.fbw[0][j] + p_ac3dec->coeffs.fbw[1][j]);
67             right = 0.5f * (p_ac3dec->coeffs.fbw[0][j] - p_ac3dec->coeffs.fbw[1][j]);
68             p_ac3dec->coeffs.fbw[0][j] = left;
69             p_ac3dec->coeffs.fbw[1][j] = right;
70         }
71     }
72 }