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