1 /*****************************************************************************
2 * ac3_exponent.c: ac3 exponent calculations
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: ac3_exponent.c,v 1.24 2001/05/14 15:58:04 reno Exp $
7 * Authors: Michel Kaempf <maxx@via.ecp.fr>
8 * Michel Lespinasse <walken@zoy.org>
9 * Aaron Holtzman <aholtzma@engr.uvic.ca>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
27 #include <string.h> /* memcpy(), memset() */
34 #include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
36 #include "stream_control.h"
37 #include "input_ext-dec.h"
39 #include "audio_output.h"
41 #include "ac3_decoder.h"
43 #include "ac3_internal.h"
45 static const s16 exps_1[128] =
47 -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
48 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
51 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
55 static const s16 exps_2[128] =
57 -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
58 -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
59 -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
60 -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
61 -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
65 static const s16 exps_3[128] =
67 -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
68 -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
69 -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
70 -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
71 -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
79 static __inline__ int exp_unpack_ch (ac3dec_t * p_ac3dec, u16 type,
80 u16 expstr, u16 ngrps, u16 initial_exp,
81 u16 exps[], u16 * dest)
86 if (expstr == EXP_REUSE)
91 /* Handle the initial absolute exponent */
92 exp_acc = initial_exp;
95 /* In the case of a fbw channel then the initial absolute values is
97 if (type != UNPACK_CPL)
102 /* Loop through the groups and fill the dest array appropriately */
105 case EXP_D15: /* 1 */
106 for (i = 0; i < ngrps; i++)
110 intf_ErrMsg ( "ac3dec error: invalid exponent" );
113 exp_acc += (exps_1[exps[i]] /*- 2*/);
115 exp_acc += (exps_2[exps[i]] /*- 2*/);
117 exp_acc += (exps_3[exps[i]] /*- 2*/);
122 case EXP_D25: /* 2 */
123 for (i = 0; i < ngrps; i++)
127 intf_ErrMsg ( "ac3dec error: invalid exponent" );
130 exp_acc += (exps_1[exps[i]] /*- 2*/);
133 exp_acc += (exps_2[exps[i]] /*- 2*/);
136 exp_acc += (exps_3[exps[i]] /*- 2*/);
142 case EXP_D45: /* 3 */
143 for (i = 0; i < ngrps; i++)
147 intf_ErrMsg ( "ac3dec error: invalid exponent" );
150 exp_acc += (exps_1[exps[i]] /*- 2*/);
155 exp_acc += (exps_2[exps[i]] /*- 2*/);
160 exp_acc += (exps_3[exps[i]] /*- 2*/);
172 int exponent_unpack (ac3dec_t * p_ac3dec)
176 for (i = 0; i < p_ac3dec->bsi.nfchans; i++)
178 if (exp_unpack_ch (p_ac3dec, UNPACK_FBW, p_ac3dec->audblk.chexpstr[i],
179 p_ac3dec->audblk.nchgrps[i],
180 p_ac3dec->audblk.exps[i][0],
181 &p_ac3dec->audblk.exps[i][1],
182 p_ac3dec->audblk.fbw_exp[i]))
188 if (p_ac3dec->audblk.cplinu)
190 if (exp_unpack_ch (p_ac3dec, UNPACK_CPL, p_ac3dec->audblk.cplexpstr,
191 p_ac3dec->audblk.ncplgrps,
192 p_ac3dec->audblk.cplabsexp << 1,
193 p_ac3dec->audblk.cplexps,
194 &p_ac3dec->audblk.cpl_exp[p_ac3dec->audblk.cplstrtmant]))
200 if (p_ac3dec->bsi.lfeon)
202 if (exp_unpack_ch (p_ac3dec, UNPACK_LFE, p_ac3dec->audblk.lfeexpstr,
203 2, p_ac3dec->audblk.lfeexps[0],
204 &p_ac3dec->audblk.lfeexps[1],
205 p_ac3dec->audblk.lfe_exp))