1 /*****************************************************************************
2 * ac3_exponent.c: ac3 exponent calculations
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
6 * Authors: Michel Kaempf <maxx@via.ecp.fr>
7 * Michel Lespinasse <walken@zoy.org>
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 *****************************************************************************/
31 #include "stream_control.h"
32 #include "input_ext-dec.h"
34 #include "audio_output.h"
36 #include "ac3_decoder.h"
37 #include "ac3_decoder_thread.h"
41 #include "ac3_bit_stream.h"
42 #include "ac3_internal.h"
44 static const s16 exps_1[128] =
46 -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,
47 -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,
48 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,
49 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,
50 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,
54 static const s16 exps_2[128] =
56 -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,
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,
64 static const s16 exps_3[128] =
66 -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,
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,
78 static __inline__ int exp_unpack_ch (ac3dec_t * p_ac3dec, u16 type,
79 u16 expstr, u16 ngrps, u16 initial_exp,
80 u16 exps[], u16 * dest)
85 if (expstr == EXP_REUSE)
90 /* Handle the initial absolute exponent */
91 exp_acc = initial_exp;
94 /* In the case of a fbw channel then the initial absolute values is
96 if (type != UNPACK_CPL)
101 /* Loop through the groups and fill the dest array appropriately */
104 case EXP_D15: /* 1 */
105 for (i = 0; i < ngrps; i++)
109 intf_ErrMsg ( "ac3dec error: invalid exponent" );
112 exp_acc += (exps_1[exps[i]] /*- 2*/);
114 exp_acc += (exps_2[exps[i]] /*- 2*/);
116 exp_acc += (exps_3[exps[i]] /*- 2*/);
121 case EXP_D25: /* 2 */
122 for (i = 0; i < ngrps; i++)
126 intf_ErrMsg ( "ac3dec error: invalid exponent" );
129 exp_acc += (exps_1[exps[i]] /*- 2*/);
132 exp_acc += (exps_2[exps[i]] /*- 2*/);
135 exp_acc += (exps_3[exps[i]] /*- 2*/);
141 case EXP_D45: /* 3 */
142 for (i = 0; i < ngrps; i++)
146 intf_ErrMsg ( "ac3dec error: invalid exponent" );
149 exp_acc += (exps_1[exps[i]] /*- 2*/);
154 exp_acc += (exps_2[exps[i]] /*- 2*/);
159 exp_acc += (exps_3[exps[i]] /*- 2*/);
171 int exponent_unpack (ac3dec_t * p_ac3dec)
175 for (i = 0; i < p_ac3dec->bsi.nfchans; i++)
177 if (exp_unpack_ch (p_ac3dec, UNPACK_FBW, p_ac3dec->audblk.chexpstr[i],
178 p_ac3dec->audblk.nchgrps[i],
179 p_ac3dec->audblk.exps[i][0],
180 &p_ac3dec->audblk.exps[i][1],
181 p_ac3dec->audblk.fbw_exp[i]))
187 if (p_ac3dec->audblk.cplinu)
189 if (exp_unpack_ch (p_ac3dec, UNPACK_CPL, p_ac3dec->audblk.cplexpstr,
190 p_ac3dec->audblk.ncplgrps,
191 p_ac3dec->audblk.cplabsexp << 1,
192 p_ac3dec->audblk.cplexps,
193 &p_ac3dec->audblk.cpl_exp[p_ac3dec->audblk.cplstrtmant]))
199 if (p_ac3dec->bsi.lfeon)
201 if (exp_unpack_ch (p_ac3dec, UNPACK_LFE, p_ac3dec->audblk.lfeexpstr,
202 2, p_ac3dec->audblk.lfeexps[0],
203 &p_ac3dec->audblk.lfeexps[1],
204 p_ac3dec->audblk.lfe_exp))