Fixed initialisation of tf in file_open(). Without setting the memory to 0,
[cinelerra_cv/mob.git] / libmpeg3 / audio / exponents.c
blob1b4cb27ec34b213a41accfb23a43ea2808d1abab
1 /*
3 * exponents.c Copyright (C) Aaron Holtzman - May 1999
5 * This file is part of libmpeg3
6 *
7 * libmpeg3 is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * libmpeg3 is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Make; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define MIN(x, y) ((x) > (y) ? (y) : (x))
26 #include "mpeg3audio.h"
27 #include <stdio.h>
29 /* Exponent defines */
30 #define UNPACK_FBW 1
31 #define UNPACK_CPL 2
32 #define UNPACK_LFE 4
34 static inline int mpeg3audio_ac3_exp_unpack_ch(unsigned int type,
35 unsigned int expstr,
36 unsigned int ngrps,
37 unsigned int initial_exp,
38 unsigned short exps[],
39 unsigned short *dest)
41 int i, j;
42 int exp_acc;
43 int exp_1, exp_2, exp_3;
45 if(expstr == MPEG3_EXP_REUSE)
46 return 0;
48 /* Handle the initial absolute exponent */
49 exp_acc = initial_exp;
50 j = 0;
52 /* In the case of a fbw channel then the initial absolute value is
53 * also an exponent */
54 if(type != UNPACK_CPL)
55 dest[j++] = exp_acc;
57 /* Loop through the groups and fill the dest array appropriately */
58 for(i = 0; i < ngrps; i++)
60 if(exps[i] > 124)
62 // fprintf(stderr, "mpeg3audio_ac3_exp_unpack_ch: Invalid exponent %d\n", exps[i]);
63 return 1;
66 exp_1 = exps[i] / 25;
67 exp_2 = (exps[i] % 25) / 5;
68 exp_3 = (exps[i] % 25) % 5;
70 exp_acc += (exp_1 - 2);
72 switch(expstr)
74 case MPEG3_EXP_D45:
75 j = MIN(255, j);
76 dest[j++] = exp_acc;
77 j = MIN(255, j);
78 dest[j++] = exp_acc;
79 case MPEG3_EXP_D25:
80 j = MIN(255, j);
81 dest[j++] = exp_acc;
82 case MPEG3_EXP_D15:
83 j = MIN(255, j);
84 dest[j++] = exp_acc;
87 exp_acc += (exp_2 - 2);
89 switch(expstr)
91 case MPEG3_EXP_D45:
92 j = MIN(255, j);
93 dest[j++] = exp_acc;
94 j = MIN(255, j);
95 dest[j++] = exp_acc;
96 case MPEG3_EXP_D25:
97 j = MIN(255, j);
98 dest[j++] = exp_acc;
99 case MPEG3_EXP_D15:
100 j = MIN(255, j);
101 dest[j++] = exp_acc;
104 exp_acc += (exp_3 - 2);
106 switch(expstr)
108 case MPEG3_EXP_D45:
109 j = MIN(255, j);
110 dest[j++] = exp_acc;
111 j = MIN(255, j);
112 dest[j++] = exp_acc;
113 case MPEG3_EXP_D25:
114 j = MIN(255, j);
115 dest[j++] = exp_acc;
116 case MPEG3_EXP_D15:
117 j = MIN(255, j);
118 dest[j++] = exp_acc;
121 return 0;
124 int mpeg3audio_ac3_exponent_unpack(mpeg3audio_t *audio,
125 mpeg3_ac3bsi_t *bsi,
126 mpeg3_ac3audblk_t *audblk)
128 int i, result = 0;
130 for(i = 0; i < bsi->nfchans; i++)
131 result |= mpeg3audio_ac3_exp_unpack_ch(UNPACK_FBW,
132 audblk->chexpstr[i],
133 audblk->nchgrps[i],
134 audblk->exps[i][0],
135 &audblk->exps[i][1],
136 audblk->fbw_exp[i]);
138 if(audblk->cplinu && !result)
139 result |= mpeg3audio_ac3_exp_unpack_ch(UNPACK_CPL,
140 audblk->cplexpstr,
141 audblk->ncplgrps,
142 audblk->cplabsexp << 1,
143 audblk->cplexps,
144 &audblk->cpl_exp[audblk->cplstrtmant]);
146 if(bsi->lfeon && !result)
147 result |= mpeg3audio_ac3_exp_unpack_ch(UNPACK_LFE,
148 audblk->lfeexpstr,
150 audblk->lfeexps[0],
151 &audblk->lfeexps[1],
152 audblk->lfe_exp);
153 return result;