]> git.sesse.net Git - vlc/blob - plugins/ac3_adec/ac3_rematrix.c
b7a7a30f03c2a1e9556f444f537bc70ca7983a99
[vlc] / plugins / ac3_adec / ac3_rematrix.c
1 /*****************************************************************************
2  * ac3_rematrix.c: ac3 audio rematrixing
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
5  * $Id: ac3_rematrix.c,v 1.4 2001/12/09 17:01:36 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
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include "defs.h"
29
30 #include <string.h>                                              /* memcpy() */
31
32 #include "common.h"
33 #include "intf_msg.h"
34 #include "threads.h"
35 #include "mtime.h"
36
37 #include "modules.h"
38 #include "modules_export.h"
39
40 #include "stream_control.h"
41 #include "input_ext-dec.h"
42
43 #include "ac3_imdct.h"
44 #include "ac3_downmix.h"
45 #include "ac3_decoder.h"
46
47 struct rematrix_band_s {
48     u32 start;
49     u32 end;
50 };
51
52 static const struct rematrix_band_s rematrix_band[] = { {13,24}, {25,36}, {37 ,60}, {61,252}};
53
54 static __inline__ u32 min_value (u32 a, u32 b)
55 {
56     return (a < b ? a : b);
57 }
58
59 /* This routine simply does stereo rematixing for the 2 channel
60  * stereo mode */
61 void rematrix (ac3dec_t * p_ac3dec)
62 {
63     u32 num_bands;
64     u32 start;
65     u32 end;
66     u32 i,j;
67     float left,right;
68
69     if (p_ac3dec->audblk.cplinu || p_ac3dec->audblk.cplbegf > 2)
70         num_bands = 4;
71     else if (p_ac3dec->audblk.cplbegf > 0)
72         num_bands = 3;
73     else
74         num_bands = 2;
75
76     for (i=0;i < num_bands; i++) {
77         if (!p_ac3dec->audblk.rematflg[i])
78             continue;
79
80         start = rematrix_band[i].start;
81         end = min_value(rematrix_band[i].end ,12 * p_ac3dec->audblk.cplbegf + 36);
82
83         for (j=start;j < end; j++) {
84             left  = 0.5f * ( *(p_ac3dec->samples+j) + *(p_ac3dec->samples+256+j) );
85             right = 0.5f * ( *(p_ac3dec->samples+j) - *(p_ac3dec->samples+256+j) );
86             *(p_ac3dec->samples+j) = left;
87             *(p_ac3dec->samples+256+j) = right;
88         }
89     }
90 }
91