diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libmad/layer12.c | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libmad/layer12.c')
-rw-r--r-- | lib/rbcodec/codecs/libmad/layer12.c | 537 |
1 files changed, 537 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libmad/layer12.c b/lib/rbcodec/codecs/libmad/layer12.c new file mode 100644 index 0000000000..e00bb64530 --- /dev/null +++ b/lib/rbcodec/codecs/libmad/layer12.c | |||
@@ -0,0 +1,537 @@ | |||
1 | /* | ||
2 | * libmad - MPEG audio decoder library | ||
3 | * Copyright (C) 2000-2004 Underbit Technologies, Inc. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | * $Id$ | ||
20 | */ | ||
21 | |||
22 | # ifdef HAVE_CONFIG_H | ||
23 | # include "config.h" | ||
24 | # endif | ||
25 | |||
26 | # include "global.h" | ||
27 | |||
28 | # ifdef HAVE_LIMITS_H | ||
29 | # include <limits.h> | ||
30 | # else | ||
31 | # undef CHAR_BIT | ||
32 | # define CHAR_BIT 8 | ||
33 | # endif | ||
34 | |||
35 | # include "fixed.h" | ||
36 | # include "bit.h" | ||
37 | # include "stream.h" | ||
38 | # include "frame.h" | ||
39 | # include "layer12.h" | ||
40 | |||
41 | /* | ||
42 | * scalefactor table | ||
43 | * used in both Layer I and Layer II decoding | ||
44 | */ | ||
45 | static | ||
46 | mad_fixed_t const sf_table[64] ICONST_ATTR = { | ||
47 | # include "sf_table.dat" | ||
48 | }; | ||
49 | |||
50 | /* --- Layer I ------------------------------------------------------------- */ | ||
51 | |||
52 | /* linear scaling table */ | ||
53 | static | ||
54 | mad_fixed_t const linear_table[14] ICONST_ATTR = { | ||
55 | MAD_F(0x15555555), /* 2^2 / (2^2 - 1) == 1.33333333333333 */ | ||
56 | MAD_F(0x12492492), /* 2^3 / (2^3 - 1) == 1.14285714285714 */ | ||
57 | MAD_F(0x11111111), /* 2^4 / (2^4 - 1) == 1.06666666666667 */ | ||
58 | MAD_F(0x10842108), /* 2^5 / (2^5 - 1) == 1.03225806451613 */ | ||
59 | MAD_F(0x10410410), /* 2^6 / (2^6 - 1) == 1.01587301587302 */ | ||
60 | MAD_F(0x10204081), /* 2^7 / (2^7 - 1) == 1.00787401574803 */ | ||
61 | MAD_F(0x10101010), /* 2^8 / (2^8 - 1) == 1.00392156862745 */ | ||
62 | MAD_F(0x10080402), /* 2^9 / (2^9 - 1) == 1.00195694716243 */ | ||
63 | MAD_F(0x10040100), /* 2^10 / (2^10 - 1) == 1.00097751710655 */ | ||
64 | MAD_F(0x10020040), /* 2^11 / (2^11 - 1) == 1.00048851978505 */ | ||
65 | MAD_F(0x10010010), /* 2^12 / (2^12 - 1) == 1.00024420024420 */ | ||
66 | MAD_F(0x10008004), /* 2^13 / (2^13 - 1) == 1.00012208521548 */ | ||
67 | MAD_F(0x10004001), /* 2^14 / (2^14 - 1) == 1.00006103888177 */ | ||
68 | MAD_F(0x10002000) /* 2^15 / (2^15 - 1) == 1.00003051850948 */ | ||
69 | }; | ||
70 | |||
71 | /* | ||
72 | * NAME: I_sample() | ||
73 | * DESCRIPTION: decode one requantized Layer I sample from a bitstream | ||
74 | */ | ||
75 | static inline | ||
76 | mad_fixed_t I_sample(struct mad_bitptr *ptr, unsigned int nb) | ||
77 | { | ||
78 | mad_fixed_t sample; | ||
79 | |||
80 | sample = mad_bit_read(ptr, nb); | ||
81 | |||
82 | /* invert most significant bit, extend sign, then scale to fixed format */ | ||
83 | |||
84 | sample ^= 1 << (nb - 1); | ||
85 | sample |= -(sample & (1 << (nb - 1))); | ||
86 | |||
87 | sample <<= MAD_F_FRACBITS - (nb - 1); | ||
88 | |||
89 | /* requantize the sample */ | ||
90 | |||
91 | /* s'' = (2^nb / (2^nb - 1)) * (s''' + 2^(-nb + 1)) */ | ||
92 | |||
93 | sample += MAD_F_ONE >> (nb - 1); | ||
94 | |||
95 | return mad_f_mul(sample, linear_table[nb - 2]); | ||
96 | |||
97 | /* s' = factor * s'' */ | ||
98 | /* (to be performed by caller) */ | ||
99 | } | ||
100 | |||
101 | /* | ||
102 | * NAME: layer->I() | ||
103 | * DESCRIPTION: decode a single Layer I frame | ||
104 | */ | ||
105 | int mad_layer_I(struct mad_stream *stream, struct mad_frame *frame) | ||
106 | { | ||
107 | struct mad_header *header = &frame->header; | ||
108 | unsigned int nch, bound, ch, s, sb, nb; | ||
109 | unsigned char allocation[2][32], scalefactor[2][32]; | ||
110 | |||
111 | nch = MAD_NCHANNELS(header); | ||
112 | |||
113 | bound = 32; | ||
114 | if (header->mode == MAD_MODE_JOINT_STEREO) { | ||
115 | header->flags |= MAD_FLAG_I_STEREO; | ||
116 | bound = 4 + header->mode_extension * 4; | ||
117 | } | ||
118 | |||
119 | /* check CRC word */ | ||
120 | |||
121 | if (header->flags & MAD_FLAG_PROTECTION) { | ||
122 | header->crc_check = | ||
123 | mad_bit_crc(stream->ptr, 4 * (bound * nch + (32 - bound)), | ||
124 | header->crc_check); | ||
125 | |||
126 | if (header->crc_check != header->crc_target && | ||
127 | !(frame->options & MAD_OPTION_IGNORECRC)) { | ||
128 | stream->error = MAD_ERROR_BADCRC; | ||
129 | return -1; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | /* decode bit allocations */ | ||
134 | |||
135 | for (sb = 0; sb < bound; ++sb) { | ||
136 | for (ch = 0; ch < nch; ++ch) { | ||
137 | nb = mad_bit_read(&stream->ptr, 4); | ||
138 | |||
139 | if (nb == 15) { | ||
140 | stream->error = MAD_ERROR_BADBITALLOC; | ||
141 | return -1; | ||
142 | } | ||
143 | |||
144 | allocation[ch][sb] = nb ? nb + 1 : 0; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | for (sb = bound; sb < 32; ++sb) { | ||
149 | nb = mad_bit_read(&stream->ptr, 4); | ||
150 | |||
151 | if (nb == 15) { | ||
152 | stream->error = MAD_ERROR_BADBITALLOC; | ||
153 | return -1; | ||
154 | } | ||
155 | |||
156 | allocation[0][sb] = | ||
157 | allocation[1][sb] = nb ? nb + 1 : 0; | ||
158 | } | ||
159 | |||
160 | /* decode scalefactors */ | ||
161 | |||
162 | for (sb = 0; sb < 32; ++sb) { | ||
163 | for (ch = 0; ch < nch; ++ch) { | ||
164 | if (allocation[ch][sb]) { | ||
165 | scalefactor[ch][sb] = mad_bit_read(&stream->ptr, 6); | ||
166 | |||
167 | # if defined(OPT_STRICT) | ||
168 | /* | ||
169 | * Scalefactor index 63 does not appear in Table B.1 of | ||
170 | * ISO/IEC 11172-3. Nonetheless, other implementations accept it, | ||
171 | * so we only reject it if OPT_STRICT is defined. | ||
172 | */ | ||
173 | if (scalefactor[ch][sb] == 63) { | ||
174 | stream->error = MAD_ERROR_BADSCALEFACTOR; | ||
175 | return -1; | ||
176 | } | ||
177 | # endif | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | |||
182 | /* decode samples */ | ||
183 | |||
184 | for (s = 0; s < 12; ++s) { | ||
185 | for (sb = 0; sb < bound; ++sb) { | ||
186 | for (ch = 0; ch < nch; ++ch) { | ||
187 | nb = allocation[ch][sb]; | ||
188 | (*frame->sbsample)[ch][s][sb] = nb ? | ||
189 | mad_f_mul(I_sample(&stream->ptr, nb), | ||
190 | sf_table[scalefactor[ch][sb]]) : 0; | ||
191 | } | ||
192 | } | ||
193 | |||
194 | for (sb = bound; sb < 32; ++sb) { | ||
195 | if ((nb = allocation[0][sb])) { | ||
196 | mad_fixed_t sample; | ||
197 | |||
198 | sample = I_sample(&stream->ptr, nb); | ||
199 | |||
200 | for (ch = 0; ch < nch; ++ch) { | ||
201 | (*frame->sbsample)[ch][s][sb] = | ||
202 | mad_f_mul(sample, sf_table[scalefactor[ch][sb]]); | ||
203 | } | ||
204 | } | ||
205 | else { | ||
206 | for (ch = 0; ch < nch; ++ch) | ||
207 | (*frame->sbsample)[ch][s][sb] = 0; | ||
208 | } | ||
209 | } | ||
210 | } | ||
211 | |||
212 | return 0; | ||
213 | } | ||
214 | |||
215 | /* --- Layer II ------------------------------------------------------------ */ | ||
216 | |||
217 | /* possible quantization per subband table */ | ||
218 | static | ||
219 | struct { | ||
220 | unsigned int sblimit; | ||
221 | unsigned char const offsets[30]; | ||
222 | } const sbquant_table[5] = { | ||
223 | /* ISO/IEC 11172-3 Table B.2a */ | ||
224 | { 27, { 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, /* 0 */ | ||
225 | 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0 } }, | ||
226 | /* ISO/IEC 11172-3 Table B.2b */ | ||
227 | { 30, { 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 3, 3, 3, 3, 3, /* 1 */ | ||
228 | 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0 } }, | ||
229 | /* ISO/IEC 11172-3 Table B.2c */ | ||
230 | { 8, { 5, 5, 2, 2, 2, 2, 2, 2 } }, /* 2 */ | ||
231 | /* ISO/IEC 11172-3 Table B.2d */ | ||
232 | { 12, { 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 } }, /* 3 */ | ||
233 | /* ISO/IEC 13818-3 Table B.1 */ | ||
234 | { 30, { 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, /* 4 */ | ||
235 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } } | ||
236 | }; | ||
237 | |||
238 | /* bit allocation table */ | ||
239 | static | ||
240 | struct { | ||
241 | unsigned short nbal; | ||
242 | unsigned short offset; | ||
243 | } const bitalloc_table[8] = { | ||
244 | { 2, 0 }, /* 0 */ | ||
245 | { 2, 3 }, /* 1 */ | ||
246 | { 3, 3 }, /* 2 */ | ||
247 | { 3, 1 }, /* 3 */ | ||
248 | { 4, 2 }, /* 4 */ | ||
249 | { 4, 3 }, /* 5 */ | ||
250 | { 4, 4 }, /* 6 */ | ||
251 | { 4, 5 } /* 7 */ | ||
252 | }; | ||
253 | |||
254 | /* offsets into quantization class table */ | ||
255 | static | ||
256 | unsigned char const offset_table[6][15] = { | ||
257 | { 0, 1, 16 }, /* 0 */ | ||
258 | { 0, 1, 2, 3, 4, 5, 16 }, /* 1 */ | ||
259 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, /* 2 */ | ||
260 | { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, /* 3 */ | ||
261 | { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16 }, /* 4 */ | ||
262 | { 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 } /* 5 */ | ||
263 | }; | ||
264 | |||
265 | /* quantization class table */ | ||
266 | static | ||
267 | struct quantclass { | ||
268 | unsigned short nlevels; | ||
269 | unsigned char group; | ||
270 | unsigned char bits; | ||
271 | mad_fixed_t C; | ||
272 | mad_fixed_t D; | ||
273 | } const qc_table[17] ICONST_ATTR = { | ||
274 | # include "qc_table.dat" | ||
275 | }; | ||
276 | |||
277 | /* | ||
278 | * NAME: II_samples() | ||
279 | * DESCRIPTION: decode three requantized Layer II samples from a bitstream | ||
280 | */ | ||
281 | static | ||
282 | void II_samples(struct mad_bitptr *ptr, | ||
283 | struct quantclass const *quantclass, | ||
284 | mad_fixed_t output[3]) | ||
285 | { | ||
286 | unsigned int nb, s, sample[3]; | ||
287 | |||
288 | if ((nb = quantclass->group)) { | ||
289 | unsigned int c, nlevels; | ||
290 | |||
291 | /* degrouping */ | ||
292 | c = mad_bit_read(ptr, quantclass->bits); | ||
293 | nlevels = quantclass->nlevels; | ||
294 | |||
295 | for (s = 0; s < 3; ++s) { | ||
296 | sample[s] = c % nlevels; | ||
297 | c /= nlevels; | ||
298 | } | ||
299 | } | ||
300 | else { | ||
301 | nb = quantclass->bits; | ||
302 | |||
303 | for (s = 0; s < 3; ++s) | ||
304 | sample[s] = mad_bit_read(ptr, nb); | ||
305 | } | ||
306 | |||
307 | for (s = 0; s < 3; ++s) { | ||
308 | mad_fixed_t requantized; | ||
309 | |||
310 | /* invert most significant bit, extend sign, then scale to fixed format */ | ||
311 | |||
312 | requantized = sample[s] ^ (1 << (nb - 1)); | ||
313 | requantized |= -(requantized & (1 << (nb - 1))); | ||
314 | |||
315 | requantized <<= MAD_F_FRACBITS - (nb - 1); | ||
316 | |||
317 | /* requantize the sample */ | ||
318 | |||
319 | /* s'' = C * (s''' + D) */ | ||
320 | |||
321 | output[s] = mad_f_mul(requantized + quantclass->D, quantclass->C); | ||
322 | |||
323 | /* s' = factor * s'' */ | ||
324 | /* (to be performed by caller) */ | ||
325 | } | ||
326 | } | ||
327 | |||
328 | /* | ||
329 | * NAME: layer->II() | ||
330 | * DESCRIPTION: decode a single Layer II frame | ||
331 | */ | ||
332 | int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame) | ||
333 | { | ||
334 | struct mad_header *header = &frame->header; | ||
335 | struct mad_bitptr start; | ||
336 | unsigned int index, sblimit, nbal, nch, bound, gr, ch, s, sb; | ||
337 | unsigned char const *offsets; | ||
338 | unsigned char allocation[2][32], scfsi[2][32], scalefactor[2][32][3]; | ||
339 | mad_fixed_t samples[3]; | ||
340 | |||
341 | nch = MAD_NCHANNELS(header); | ||
342 | |||
343 | if (header->flags & MAD_FLAG_LSF_EXT) | ||
344 | index = 4; | ||
345 | else if (header->flags & MAD_FLAG_FREEFORMAT) | ||
346 | goto freeformat; | ||
347 | else { | ||
348 | unsigned long bitrate_per_channel; | ||
349 | |||
350 | bitrate_per_channel = header->bitrate; | ||
351 | if (nch == 2) { | ||
352 | bitrate_per_channel /= 2; | ||
353 | |||
354 | # if defined(OPT_STRICT) | ||
355 | /* | ||
356 | * ISO/IEC 11172-3 allows only single channel mode for 32, 48, 56, and | ||
357 | * 80 kbps bitrates in Layer II, but some encoders ignore this | ||
358 | * restriction. We enforce it if OPT_STRICT is defined. | ||
359 | */ | ||
360 | if (bitrate_per_channel <= 28000 || bitrate_per_channel == 40000) { | ||
361 | stream->error = MAD_ERROR_BADMODE; | ||
362 | return -1; | ||
363 | } | ||
364 | # endif | ||
365 | } | ||
366 | else { /* nch == 1 */ | ||
367 | if (bitrate_per_channel > 192000) { | ||
368 | /* | ||
369 | * ISO/IEC 11172-3 does not allow single channel mode for 224, 256, | ||
370 | * 320, or 384 kbps bitrates in Layer II. | ||
371 | */ | ||
372 | stream->error = MAD_ERROR_BADMODE; | ||
373 | return -1; | ||
374 | } | ||
375 | } | ||
376 | |||
377 | if (bitrate_per_channel <= 48000) | ||
378 | index = (header->samplerate == 32000) ? 3 : 2; | ||
379 | else if (bitrate_per_channel <= 80000) | ||
380 | index = 0; | ||
381 | else { | ||
382 | freeformat: | ||
383 | index = (header->samplerate == 48000) ? 0 : 1; | ||
384 | } | ||
385 | } | ||
386 | |||
387 | sblimit = sbquant_table[index].sblimit; | ||
388 | offsets = sbquant_table[index].offsets; | ||
389 | |||
390 | bound = 32; | ||
391 | if (header->mode == MAD_MODE_JOINT_STEREO) { | ||
392 | header->flags |= MAD_FLAG_I_STEREO; | ||
393 | bound = 4 + header->mode_extension * 4; | ||
394 | } | ||
395 | |||
396 | if (bound > sblimit) | ||
397 | bound = sblimit; | ||
398 | |||
399 | start = stream->ptr; | ||
400 | |||
401 | /* decode bit allocations */ | ||
402 | |||
403 | for (sb = 0; sb < bound; ++sb) { | ||
404 | nbal = bitalloc_table[offsets[sb]].nbal; | ||
405 | |||
406 | for (ch = 0; ch < nch; ++ch) | ||
407 | allocation[ch][sb] = mad_bit_read(&stream->ptr, nbal); | ||
408 | } | ||
409 | |||
410 | for (sb = bound; sb < sblimit; ++sb) { | ||
411 | nbal = bitalloc_table[offsets[sb]].nbal; | ||
412 | |||
413 | allocation[0][sb] = | ||
414 | allocation[1][sb] = mad_bit_read(&stream->ptr, nbal); | ||
415 | } | ||
416 | |||
417 | /* decode scalefactor selection info */ | ||
418 | |||
419 | for (sb = 0; sb < sblimit; ++sb) { | ||
420 | for (ch = 0; ch < nch; ++ch) { | ||
421 | if (allocation[ch][sb]) | ||
422 | scfsi[ch][sb] = mad_bit_read(&stream->ptr, 2); | ||
423 | } | ||
424 | } | ||
425 | |||
426 | /* check CRC word */ | ||
427 | |||
428 | if (header->flags & MAD_FLAG_PROTECTION) { | ||
429 | header->crc_check = | ||
430 | mad_bit_crc(start, mad_bit_length(&start, &stream->ptr), | ||
431 | header->crc_check); | ||
432 | |||
433 | if (header->crc_check != header->crc_target && | ||
434 | !(frame->options & MAD_OPTION_IGNORECRC)) { | ||
435 | stream->error = MAD_ERROR_BADCRC; | ||
436 | return -1; | ||
437 | } | ||
438 | } | ||
439 | |||
440 | /* decode scalefactors */ | ||
441 | |||
442 | for (sb = 0; sb < sblimit; ++sb) { | ||
443 | for (ch = 0; ch < nch; ++ch) { | ||
444 | if (allocation[ch][sb]) { | ||
445 | scalefactor[ch][sb][0] = mad_bit_read(&stream->ptr, 6); | ||
446 | |||
447 | switch (scfsi[ch][sb]) { | ||
448 | case 2: | ||
449 | scalefactor[ch][sb][2] = | ||
450 | scalefactor[ch][sb][1] = | ||
451 | scalefactor[ch][sb][0]; | ||
452 | break; | ||
453 | |||
454 | case 0: | ||
455 | scalefactor[ch][sb][1] = mad_bit_read(&stream->ptr, 6); | ||
456 | /* fall through */ | ||
457 | |||
458 | case 1: | ||
459 | case 3: | ||
460 | scalefactor[ch][sb][2] = mad_bit_read(&stream->ptr, 6); | ||
461 | } | ||
462 | |||
463 | if (scfsi[ch][sb] & 1) | ||
464 | scalefactor[ch][sb][1] = scalefactor[ch][sb][scfsi[ch][sb] - 1]; | ||
465 | |||
466 | # if defined(OPT_STRICT) | ||
467 | /* | ||
468 | * Scalefactor index 63 does not appear in Table B.1 of | ||
469 | * ISO/IEC 11172-3. Nonetheless, other implementations accept it, | ||
470 | * so we only reject it if OPT_STRICT is defined. | ||
471 | */ | ||
472 | if (scalefactor[ch][sb][0] == 63 || | ||
473 | scalefactor[ch][sb][1] == 63 || | ||
474 | scalefactor[ch][sb][2] == 63) { | ||
475 | stream->error = MAD_ERROR_BADSCALEFACTOR; | ||
476 | return -1; | ||
477 | } | ||
478 | # endif | ||
479 | } | ||
480 | } | ||
481 | } | ||
482 | |||
483 | /* decode samples */ | ||
484 | |||
485 | for (gr = 0; gr < 12; ++gr) { | ||
486 | for (sb = 0; sb < bound; ++sb) { | ||
487 | for (ch = 0; ch < nch; ++ch) { | ||
488 | if ((index = allocation[ch][sb])) { | ||
489 | int off = bitalloc_table[offsets[sb]].offset; | ||
490 | index = offset_table[off][index - 1]; | ||
491 | |||
492 | II_samples(&stream->ptr, &qc_table[index], samples); | ||
493 | |||
494 | for (s = 0; s < 3; ++s) { | ||
495 | (*frame->sbsample)[ch][3 * gr + s][sb] = | ||
496 | mad_f_mul(samples[s], sf_table[scalefactor[ch][sb][gr / 4]]); | ||
497 | } | ||
498 | } | ||
499 | else { | ||
500 | for (s = 0; s < 3; ++s) | ||
501 | (*frame->sbsample)[ch][3 * gr + s][sb] = 0; | ||
502 | } | ||
503 | } | ||
504 | } | ||
505 | |||
506 | for (sb = bound; sb < sblimit; ++sb) { | ||
507 | if ((index = allocation[0][sb])) { | ||
508 | int off = bitalloc_table[offsets[sb]].offset; | ||
509 | index = offset_table[off][index - 1]; | ||
510 | |||
511 | II_samples(&stream->ptr, &qc_table[index], samples); | ||
512 | |||
513 | for (ch = 0; ch < nch; ++ch) { | ||
514 | for (s = 0; s < 3; ++s) { | ||
515 | (*frame->sbsample)[ch][3 * gr + s][sb] = | ||
516 | mad_f_mul(samples[s], sf_table[scalefactor[ch][sb][gr / 4]]); | ||
517 | } | ||
518 | } | ||
519 | } | ||
520 | else { | ||
521 | for (ch = 0; ch < nch; ++ch) { | ||
522 | for (s = 0; s < 3; ++s) | ||
523 | (*frame->sbsample)[ch][3 * gr + s][sb] = 0; | ||
524 | } | ||
525 | } | ||
526 | } | ||
527 | |||
528 | for (ch = 0; ch < nch; ++ch) { | ||
529 | for (s = 0; s < 3; ++s) { | ||
530 | for (sb = sblimit; sb < 32; ++sb) | ||
531 | (*frame->sbsample)[ch][3 * gr + s][sb] = 0; | ||
532 | } | ||
533 | } | ||
534 | } | ||
535 | |||
536 | return 0; | ||
537 | } | ||