]> git.sesse.net Git - vlc/blob - src/ac3_decoder/ac3_rematrix.c
* Fixed a few warnings with gcc 3.0.
[vlc] / src / ac3_decoder / ac3_rematrix.c
1 /*****************************************************************************
2  * ac3_rematrix.c: ac3 audio rematrixing
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: ac3_rematrix.c,v 1.16 2001/05/06 04:32:02 sam Exp $
6  *
7  * Authors: Michel Kaempf <maxx@via.ecp.fr>
8  *          Aaron Holtzman <aholtzma@engr.uvic.ca>
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 <string.h>                                              /* memcpy() */
27
28 #include "config.h"
29 #include "common.h"
30 #include "threads.h"
31 #include "mtime.h"
32
33 #include "stream_control.h"
34 #include "input_ext-dec.h"
35
36 #include "ac3_decoder.h"
37 #include "ac3_internal.h"
38
39 struct rematrix_band_s {
40     u32 start;
41     u32 end;
42 };
43
44 static const struct rematrix_band_s rematrix_band[] = { {13,24}, {25,36}, {37 ,60}, {61,252}};
45
46 static __inline__ u32 min_value (u32 a, u32 b)
47 {
48     return (a < b ? a : b);
49 }
50
51 /* This routine simply does stereo rematixing for the 2 channel
52  * stereo mode */
53 void rematrix (ac3dec_t * p_ac3dec)
54 {
55     u32 num_bands;
56     u32 start;
57     u32 end;
58     u32 i,j;
59     float left,right;
60
61     if (p_ac3dec->audblk.cplinu || p_ac3dec->audblk.cplbegf > 2)
62         num_bands = 4;
63     else if (p_ac3dec->audblk.cplbegf > 0)
64         num_bands = 3;
65     else
66         num_bands = 2;
67
68     for (i=0;i < num_bands; i++) {
69         if (!p_ac3dec->audblk.rematflg[i])
70             continue;
71
72         start = rematrix_band[i].start;
73         end = min_value(rematrix_band[i].end ,12 * p_ac3dec->audblk.cplbegf + 36);
74
75         for (j=start;j < end; j++) {
76             left  = 0.5f * (p_ac3dec->samples[0][j] + p_ac3dec->samples[1][j]);
77             right = 0.5f * (p_ac3dec->samples[0][j] - p_ac3dec->samples[1][j]);
78             p_ac3dec->samples[0][j] = left;
79             p_ac3dec->samples[1][j] = right;
80         }
81     }
82 }