1 /*****************************************************************************
2 * ac3_rematrix.c: ac3 audio rematrixing
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: ac3_rematrix.c,v 1.8 2002/06/01 12:31:58 sam Exp $
7 * Authors: Michel Kaempf <maxx@via.ecp.fr>
8 * Aaron Holtzman <aholtzma@engr.uvic.ca>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
29 #include <vlc/decoder.h>
31 #include "ac3_imdct.h"
32 #include "ac3_downmix.h"
35 struct rematrix_band_s {
40 static const struct rematrix_band_s rematrix_band[] = { {13,24}, {25,36}, {37 ,60}, {61,252}};
42 static inline u32 min_value (u32 a, u32 b)
44 return (a < b ? a : b);
47 /* This routine simply does stereo rematixing for the 2 channel
49 void rematrix (ac3dec_t * p_ac3dec)
57 if (p_ac3dec->audblk.cplinu || p_ac3dec->audblk.cplbegf > 2)
59 else if (p_ac3dec->audblk.cplbegf > 0)
64 for (i=0;i < num_bands; i++) {
65 if (!p_ac3dec->audblk.rematflg[i])
68 start = rematrix_band[i].start;
69 end = min_value(rematrix_band[i].end ,12 * p_ac3dec->audblk.cplbegf + 36);
71 for (j=start;j < end; j++) {
72 left = 0.5f * ( *(p_ac3dec->samples+j) + *(p_ac3dec->samples+256+j) );
73 right = 0.5f * ( *(p_ac3dec->samples+j) - *(p_ac3dec->samples+256+j) );
74 *(p_ac3dec->samples+j) = left;
75 *(p_ac3dec->samples+256+j) = right;