Diffstat (limited to 'core/multimedia/opieplayer/libmpeg3/audio/layer2.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmpeg3/audio/layer2.c | 418 |
1 files changed, 418 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmpeg3/audio/layer2.c b/core/multimedia/opieplayer/libmpeg3/audio/layer2.c new file mode 100644 index 0000000..01582fe --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/layer2.c | |||
@@ -0,0 +1,418 @@ | |||
1 | /* | ||
2 | * most other tables are calculated on program start (which is (of course) | ||
3 | * not ISO-conform) .. | ||
4 | * Layer-3 huffman table is in huffman.h | ||
5 | */ | ||
6 | |||
7 | #include "mpeg3audio.h" | ||
8 | #include "../libmpeg3.h" | ||
9 | #include "../mpeg3protos.h" | ||
10 | #include "tables.h" | ||
11 | |||
12 | struct al_table alloc_0[] = { | ||
13 | {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, | ||
14 | {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, | ||
15 | {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, | ||
16 | {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, | ||
17 | {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, | ||
18 | {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, | ||
19 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
20 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
21 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
22 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
23 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
24 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
25 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
26 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
27 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
28 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
29 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
30 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
31 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
32 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
33 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
34 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
35 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
36 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
37 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
38 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
39 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
40 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
41 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
42 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
43 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
44 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
45 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
46 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
47 | {2,0},{5,3},{7,5},{16,-32767}, | ||
48 | {2,0},{5,3},{7,5},{16,-32767}, | ||
49 | {2,0},{5,3},{7,5},{16,-32767}, | ||
50 | {2,0},{5,3},{7,5},{16,-32767} }; | ||
51 | |||
52 | struct al_table alloc_1[] = { | ||
53 | {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, | ||
54 | {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, | ||
55 | {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, | ||
56 | {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, | ||
57 | {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, | ||
58 | {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, | ||
59 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
60 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
61 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
62 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
63 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
64 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
65 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
66 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
67 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
68 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
69 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
70 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
71 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
72 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
73 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
74 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, | ||
75 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
76 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
77 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
78 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
79 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
80 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
81 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
82 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
83 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
84 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
85 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
86 | {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, | ||
87 | {2,0},{5,3},{7,5},{16,-32767}, | ||
88 | {2,0},{5,3},{7,5},{16,-32767}, | ||
89 | {2,0},{5,3},{7,5},{16,-32767}, | ||
90 | {2,0},{5,3},{7,5},{16,-32767}, | ||
91 | {2,0},{5,3},{7,5},{16,-32767}, | ||
92 | {2,0},{5,3},{7,5},{16,-32767}, | ||
93 | {2,0},{5,3},{7,5},{16,-32767} }; | ||
94 | |||
95 | struct al_table alloc_2[] = { | ||
96 | {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255}, | ||
97 | {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383}, | ||
98 | {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255}, | ||
99 | {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383}, | ||
100 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
101 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
102 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
103 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
104 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
105 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} }; | ||
106 | |||
107 | struct al_table alloc_3[] = { | ||
108 | {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255}, | ||
109 | {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383}, | ||
110 | {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255}, | ||
111 | {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383}, | ||
112 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
113 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
114 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
115 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
116 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
117 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
118 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
119 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
120 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
121 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} }; | ||
122 | |||
123 | struct al_table alloc_4[] = { | ||
124 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
125 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191}, | ||
126 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
127 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191}, | ||
128 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
129 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191}, | ||
130 | {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, | ||
131 | {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191}, | ||
132 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
133 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
134 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
135 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
136 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
137 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
138 | {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, | ||
139 | {2,0},{5,3},{7,5},{10,9}, | ||
140 | {2,0},{5,3},{7,5},{10,9}, | ||
141 | {2,0},{5,3},{7,5},{10,9}, | ||
142 | {2,0},{5,3},{7,5},{10,9}, | ||
143 | {2,0},{5,3},{7,5},{10,9}, | ||
144 | {2,0},{5,3},{7,5},{10,9}, | ||
145 | {2,0},{5,3},{7,5},{10,9}, | ||
146 | {2,0},{5,3},{7,5},{10,9}, | ||
147 | {2,0},{5,3},{7,5},{10,9}, | ||
148 | {2,0},{5,3},{7,5},{10,9}, | ||
149 | {2,0},{5,3},{7,5},{10,9}, | ||
150 | {2,0},{5,3},{7,5},{10,9}, | ||
151 | {2,0},{5,3},{7,5},{10,9}, | ||
152 | {2,0},{5,3},{7,5},{10,9}, | ||
153 | {2,0},{5,3},{7,5},{10,9}, | ||
154 | {2,0},{5,3},{7,5},{10,9}, | ||
155 | {2,0},{5,3},{7,5},{10,9}, | ||
156 | {2,0},{5,3},{7,5},{10,9}, | ||
157 | {2,0},{5,3},{7,5},{10,9} }; | ||
158 | |||
159 | |||
160 | int mpeg3audio_II_select_table(mpeg3audio_t *audio) | ||
161 | { | ||
162 | static int translate[3][2][16] = | ||
163 | {{{ 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0}, | ||
164 | { 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0}}, | ||
165 | {{ 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0}, | ||
166 | { 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0}}, | ||
167 | {{ 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0}, | ||
168 | { 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0}}}; | ||
169 | int table, sblim; | ||
170 | static struct al_table *tables[5] = | ||
171 | {alloc_0, alloc_1, alloc_2, alloc_3, alloc_4}; | ||
172 | static int sblims[5] = {27, 30, 8, 12, 30}; | ||
173 | |||
174 | if(audio->lsf) | ||
175 | table = 4; | ||
176 | else | ||
177 | table = translate[audio->sampling_frequency_code][2 - audio->channels][audio->bitrate_index]; | ||
178 | sblim = sblims[table]; | ||
179 | |||
180 | audio->alloc = tables[table]; | ||
181 | audio->II_sblimit = sblim; | ||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | int mpeg3audio_II_step_one(mpeg3audio_t *audio, unsigned int *bit_alloc, int *scale) | ||
186 | { | ||
187 | int stereo = audio->channels - 1; | ||
188 | int sblimit = audio->II_sblimit; | ||
189 | int jsbound = audio->jsbound; | ||
190 | int sblimit2 = audio->II_sblimit << stereo; | ||
191 | struct al_table *alloc1 = audio->alloc; | ||
192 | int i, result = 0; | ||
193 | unsigned int *scfsi_buf = audio->layer2_scfsi_buf; | ||
194 | unsigned int *scfsi, *bita; | ||
195 | int sc, step; | ||
196 | |||
197 | bita = bit_alloc; | ||
198 | if(stereo) | ||
199 | { | ||
200 | /* Stereo */ | ||
201 | for(i = jsbound;i ; i--, alloc1 += (1 << step)) | ||
202 | { | ||
203 | *bita++ = (char)mpeg3bits_getbits(audio->astream, step = alloc1->bits); | ||
204 | *bita++ = (char)mpeg3bits_getbits(audio->astream, step); | ||
205 | } | ||
206 | for(i = sblimit-jsbound; i; i--, alloc1 += (1 << step)) | ||
207 | { | ||
208 | bita[0] = (char)mpeg3bits_getbits(audio->astream, step = alloc1->bits); | ||
209 | bita[1] = bita[0]; | ||
210 | bita += 2; | ||
211 | } | ||
212 | bita = bit_alloc; | ||
213 | scfsi = scfsi_buf; | ||
214 | for(i = sblimit2; i; i--) | ||
215 | if(*bita++) *scfsi++ = (char)mpeg3bits_getbits(audio->astream, 2); | ||
216 | } | ||
217 | else | ||
218 | { | ||
219 | /* mono */ | ||
220 | for(i = sblimit; i; i--, alloc1 += (1 << step)) | ||
221 | *bita++ = (char)mpeg3bits_getbits(audio->astream, step = alloc1->bits); | ||
222 | bita = bit_alloc; | ||
223 | scfsi = scfsi_buf; | ||
224 | for(i = sblimit; i; i--) if (*bita++) *scfsi++ = (char)mpeg3bits_getbits(audio->astream, 2); | ||
225 | } | ||
226 | |||
227 | bita = bit_alloc; | ||
228 | scfsi = scfsi_buf; | ||
229 | for(i = sblimit2; i; i--) | ||
230 | { | ||
231 | if(*bita++) | ||
232 | switch(*scfsi++) | ||
233 | { | ||
234 | case 0: | ||
235 | *scale++ = mpeg3bits_getbits(audio->astream, 6); | ||
236 | *scale++ = mpeg3bits_getbits(audio->astream, 6); | ||
237 | *scale++ = mpeg3bits_getbits(audio->astream, 6); | ||
238 | break; | ||
239 | case 1 : | ||
240 | *scale++ = sc = mpeg3bits_getbits(audio->astream, 6); | ||
241 | *scale++ = sc; | ||
242 | *scale++ = mpeg3bits_getbits(audio->astream, 6); | ||
243 | break; | ||
244 | case 2: | ||
245 | *scale++ = sc = mpeg3bits_getbits(audio->astream, 6); | ||
246 | *scale++ = sc; | ||
247 | *scale++ = sc; | ||
248 | break; | ||
249 | default: /* case 3 */ | ||
250 | *scale++ = mpeg3bits_getbits(audio->astream, 6); | ||
251 | *scale++ = sc = mpeg3bits_getbits(audio->astream, 6); | ||
252 | *scale++ = sc; | ||
253 | break; | ||
254 | } | ||
255 | } | ||
256 | return result | mpeg3bits_error(audio->astream); | ||
257 | } | ||
258 | |||
259 | int mpeg3audio_II_step_two(mpeg3audio_t *audio, unsigned int *bit_alloc, mpeg3_real_t fraction[2][4][SBLIMIT], int *scale, int x1) | ||
260 | { | ||
261 | int i, j, k, ba, result = 0; | ||
262 | int channels = audio->channels; | ||
263 | int sblimit = audio->II_sblimit; | ||
264 | int jsbound = audio->jsbound; | ||
265 | struct al_table *alloc2, *alloc1 = audio->alloc; | ||
266 | unsigned int *bita = bit_alloc; | ||
267 | int d1, step, test; | ||
268 | |||
269 | for(i = 0; i < jsbound; i++, alloc1 += (1 << step)) | ||
270 | { | ||
271 | step = alloc1->bits; | ||
272 | for(j = 0; j < channels; j++) | ||
273 | { | ||
274 | if(ba = *bita++) | ||
275 | { | ||
276 | k = (alloc2 = alloc1 + ba)->bits; | ||
277 | if((d1 = alloc2->d) < 0) | ||
278 | { | ||
279 | mpeg3_real_t cm = mpeg3_muls[k][scale[x1]]; | ||
280 | |||
281 | fraction[j][0][i] = ((mpeg3_real_t)((int)mpeg3bits_getbits(audio->astream, k) + d1)) * cm; | ||
282 | fraction[j][1][i] = ((mpeg3_real_t)((int)mpeg3bits_getbits(audio->astream, k) + d1)) * cm; | ||
283 | fraction[j][2][i] = ((mpeg3_real_t)((int)mpeg3bits_getbits(audio->astream, k) + d1)) * cm; | ||
284 | } | ||
285 | else | ||
286 | { | ||
287 | static int *table[] = | ||
288 | {0, 0, 0, mpeg3_grp_3tab, 0, mpeg3_grp_5tab, 0, 0, 0, mpeg3_grp_9tab}; | ||
289 | unsigned int idx, *tab, m = scale[x1]; | ||
290 | |||
291 | idx = (unsigned int)mpeg3bits_getbits(audio->astream, k); | ||
292 | tab = (unsigned int*)(table[d1] + idx + idx + idx); | ||
293 | fraction[j][0][i] = mpeg3_muls[*tab++][m]; | ||
294 | fraction[j][1][i] = mpeg3_muls[*tab++][m]; | ||
295 | fraction[j][2][i] = mpeg3_muls[*tab][m]; | ||
296 | } | ||
297 | scale += 3; | ||
298 | } | ||
299 | else | ||
300 | fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0; | ||
301 | } | ||
302 | } | ||
303 | |||
304 | for(i = jsbound; i < sblimit; i++, alloc1 += (1 << step)) | ||
305 | { | ||
306 | step = alloc1->bits; | ||
307 | /* channel 1 and channel 2 bitalloc are the same */ | ||
308 | bita++; | ||
309 | if((ba = *bita++)) | ||
310 | { | ||
311 | k=(alloc2 = alloc1+ba)->bits; | ||
312 | if((d1 = alloc2->d) < 0) | ||
313 | { | ||
314 | mpeg3_real_t cm; | ||
315 | |||
316 | cm = mpeg3_muls[k][scale[x1 + 3]]; | ||
317 | fraction[1][0][i] = (fraction[0][0][i] = (mpeg3_real_t)((int)mpeg3bits_getbits(audio->astream, k) + d1)) * cm; | ||
318 | fraction[1][1][i] = (fraction[0][1][i] = (mpeg3_real_t)((int)mpeg3bits_getbits(audio->astream, k) + d1)) * cm; | ||
319 | fraction[1][2][i] = (fraction[0][2][i] = (mpeg3_real_t)((int)mpeg3bits_getbits(audio->astream, k) + d1)) * cm; | ||
320 | cm = mpeg3_muls[k][scale[x1]]; | ||
321 | fraction[0][0][i] *= cm; | ||
322 | fraction[0][1][i] *= cm; | ||
323 | fraction[0][2][i] *= cm; | ||
324 | } | ||
325 | else | ||
326 | { | ||
327 | static int *table[] = {0, 0, 0, mpeg3_grp_3tab, 0, mpeg3_grp_5tab, 0, 0, 0, mpeg3_grp_9tab}; | ||
328 | unsigned int idx, *tab, m1, m2; | ||
329 | |||
330 | m1 = scale[x1]; | ||
331 | m2 = scale[x1+3]; | ||
332 | idx = (unsigned int)mpeg3bits_getbits(audio->astream, k); | ||
333 | tab = (unsigned int*)(table[d1] + idx + idx + idx); | ||
334 | fraction[0][0][i] = mpeg3_muls[*tab][m1]; | ||
335 | fraction[1][0][i] = mpeg3_muls[*tab++][m2]; | ||
336 | fraction[0][1][i] = mpeg3_muls[*tab][m1]; | ||
337 | fraction[1][1][i] = mpeg3_muls[*tab++][m2]; | ||
338 | fraction[0][2][i] = mpeg3_muls[*tab][m1]; | ||
339 | fraction[1][2][i] = mpeg3_muls[*tab][m2]; | ||
340 | } | ||
341 | scale += 6; | ||
342 | } | ||
343 | else | ||
344 | { | ||
345 | fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] = | ||
346 | fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0; | ||
347 | } | ||
348 | /* | ||
349 | should we use individual scalefac for channel 2 or | ||
350 | is the current way the right one , where we just copy channel 1 to | ||
351 | channel 2 ?? | ||
352 | The current 'strange' thing is, that we throw away the scalefac | ||
353 | values for the second channel ...!! | ||
354 | -> changed .. now we use the scalefac values of channel one !! | ||
355 | */ | ||
356 | } | ||
357 | |||
358 | if(sblimit > SBLIMIT) sblimit = SBLIMIT; | ||
359 | |||
360 | for(i = sblimit; i < SBLIMIT; i++) | ||
361 | for(j = 0; j < channels; j++) | ||
362 | fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0; | ||
363 | |||
364 | return result | mpeg3bits_error(audio->astream); | ||
365 | } | ||
366 | |||
367 | int mpeg3audio_dolayer2(mpeg3audio_t *audio) | ||
368 | { | ||
369 | int i, j, result = 0; | ||
370 | int channels = audio->channels; | ||
371 | mpeg3_real_t fraction[2][4][SBLIMIT]; /* pick_table clears unused subbands */ | ||
372 | unsigned int bit_alloc[64]; | ||
373 | int scale[192]; | ||
374 | int single = audio->single; | ||
375 | |||
376 | if(audio->error_protection) | ||
377 | mpeg3bits_getbits(audio->astream, 16); | ||
378 | |||
379 | mpeg3audio_II_select_table(audio); | ||
380 | |||
381 | audio->jsbound = (audio->mode == MPG_MD_JOINT_STEREO) ? | ||
382 | (audio->mode_ext << 2) + 4 : audio->II_sblimit; | ||
383 | |||
384 | if(channels == 1 || single == 3) | ||
385 | single = 0; | ||
386 | |||
387 | result |= mpeg3audio_II_step_one(audio, bit_alloc, scale); | ||
388 | |||
389 | for(i = 0; i < SCALE_BLOCK && !result; i++) | ||
390 | { | ||
391 | result |= mpeg3audio_II_step_two(audio, bit_alloc, fraction, scale, i >> 2); | ||
392 | |||
393 | for(j = 0; j < 3; j++) | ||
394 | { | ||
395 | if(single >= 0) | ||
396 | { | ||
397 | /* Monaural */ | ||
398 | mpeg3audio_synth_mono(audio, fraction[single][j], audio->pcm_sample, &(audio->pcm_point)); | ||
399 | } | ||
400 | else | ||
401 | { | ||
402 | /* Stereo */ | ||
403 | int p1 = audio->pcm_point; | ||
404 | mpeg3audio_synth_stereo(audio, fraction[0][j], 0, audio->pcm_sample, &p1); | ||
405 | mpeg3audio_synth_stereo(audio, fraction[1][j], 1, audio->pcm_sample, &(audio->pcm_point)); | ||
406 | } | ||
407 | |||
408 | if(audio->pcm_point / audio->channels >= audio->pcm_allocated - MPEG3AUDIO_PADDING * audio->channels) | ||
409 | { | ||
410 | /* Need more room */ | ||
411 | mpeg3audio_replace_buffer(audio, audio->pcm_allocated + MPEG3AUDIO_PADDING * audio->channels); | ||
412 | } | ||
413 | } | ||
414 | } | ||
415 | |||
416 | |||
417 | return result; | ||
418 | } | ||