summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmad/layer3.c
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/libmad/layer3.c') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/layer3.c232
1 files changed, 214 insertions, 18 deletions
diff --git a/core/multimedia/opieplayer/libmad/layer3.c b/core/multimedia/opieplayer/libmad/layer3.c
index 03f13fe..3c5dd9e 100644
--- a/core/multimedia/opieplayer/libmad/layer3.c
+++ b/core/multimedia/opieplayer/libmad/layer3.c
@@ -1,27 +1,27 @@
1/* 1/*
2 * libmad - MPEG audio decoder library 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 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 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 7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version. 8 * (at your option) any later version.
9 * 9 *
10 * This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License 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 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 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * 18 *
19 * $Id$ 19 * $Id$
20 */ 20 */
21 21
22# ifdef HAVE_CONFIG_H 22# ifdef HAVE_CONFIG_H
23# include "libmad_config.h" 23# include "libmad_config.h"
24# endif 24# endif
25 25
26# include "libmad_global.h" 26# include "libmad_global.h"
27 27
@@ -267,50 +267,50 @@ unsigned char const sfb_16000_mixed[] = {
267 * derived from public sources 267 * derived from public sources
268 */ 268 */
269# define sfb_12000_long sfb_16000_long 269# define sfb_12000_long sfb_16000_long
270# define sfb_11025_long sfb_12000_long 270# define sfb_11025_long sfb_12000_long
271 271
272static 272static
273unsigned char const sfb_8000_long[] = { 273unsigned char const sfb_8000_long[] = {
274 12, 12, 12, 12, 12, 12, 16, 20, 24, 28, 32, 274 12, 12, 12, 12, 12, 12, 16, 20, 24, 28, 32,
275 40, 48, 56, 64, 76, 90, 2, 2, 2, 2, 2 275 40, 48, 56, 64, 76, 90, 2, 2, 2, 2, 2
276}; 276};
277 277
278# define sfb_12000_short sfb_16000_short 278# define sfb_12000_short sfb_16000_short
279# define sfb_11025_short sfb_12000_short 279# define sfb_11025_short sfb_12000_short
280 280
281static 281static
282unsigned char const sfb_8000_short[] = { 282unsigned char const sfb_8000_short[] = {
283 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 16, 283 8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 16,
284 16, 16, 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36, 284 16, 16, 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36,
285 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26 285 36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26
286}; 286};
287 287
288# define sfb_12000_mixed sfb_16000_mixed 288# define sfb_12000_mixed sfb_16000_mixed
289# define sfb_11025_mixed sfb_12000_mixed 289# define sfb_11025_mixed sfb_12000_mixed
290 290
291/* the 8000 Hz short block scalefactor bands do not break after the first 36 291/* the 8000 Hz short block scalefactor bands do not break after
292 frequency lines, so this is probably wrong */ 292 the first 36 frequency lines, so this is probably wrong */
293static 293static
294unsigned char const sfb_8000_mixed[] = { 294unsigned char const sfb_8000_mixed[] = {
295 /* long */ 12, 12, 12, 295 /* long */ 12, 12, 12,
296 /* short */ 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16, 296 /* short */ 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16,
297 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36, 36, 297 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36, 36,
298 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26 298 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26
299}; 299};
300 300
301static 301static
302struct { 302struct {
303 unsigned char const *l; 303 unsigned char const *l;
304 unsigned char const *s; 304 unsigned char const *s;
305 unsigned char const *m; 305 unsigned char const *m;
306} const sfbwidth_table[9] = { 306} const sfbwidth_table[9] = {
307 { sfb_48000_long, sfb_48000_short, sfb_48000_mixed }, 307 { sfb_48000_long, sfb_48000_short, sfb_48000_mixed },
308 { sfb_44100_long, sfb_44100_short, sfb_44100_mixed }, 308 { sfb_44100_long, sfb_44100_short, sfb_44100_mixed },
309 { sfb_32000_long, sfb_32000_short, sfb_32000_mixed }, 309 { sfb_32000_long, sfb_32000_short, sfb_32000_mixed },
310 { sfb_24000_long, sfb_24000_short, sfb_24000_mixed }, 310 { sfb_24000_long, sfb_24000_short, sfb_24000_mixed },
311 { sfb_22050_long, sfb_22050_short, sfb_22050_mixed }, 311 { sfb_22050_long, sfb_22050_short, sfb_22050_mixed },
312 { sfb_16000_long, sfb_16000_short, sfb_16000_mixed }, 312 { sfb_16000_long, sfb_16000_short, sfb_16000_mixed },
313 { sfb_12000_long, sfb_12000_short, sfb_12000_mixed }, 313 { sfb_12000_long, sfb_12000_short, sfb_12000_mixed },
314 { sfb_11025_long, sfb_11025_short, sfb_11025_mixed }, 314 { sfb_11025_long, sfb_11025_short, sfb_11025_mixed },
315 { sfb_8000_long, sfb_8000_short, sfb_8000_mixed } 315 { sfb_8000_long, sfb_8000_short, sfb_8000_mixed }
316}; 316};
@@ -361,49 +361,49 @@ mad_fixed_t const root_table[7] = {
361 * c[] = { -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037 } 361 * c[] = { -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037 }
362 * cs[i] = 1 / sqrt(1 + c[i]^2) 362 * cs[i] = 1 / sqrt(1 + c[i]^2)
363 * ca[i] = c[i] / sqrt(1 + c[i]^2) 363 * ca[i] = c[i] / sqrt(1 + c[i]^2)
364 */ 364 */
365static 365static
366mad_fixed_t const cs[8] = { 366mad_fixed_t const cs[8] = {
367 +MAD_F(0x0db84a81) /* +0.857492926 */, +MAD_F(0x0e1b9d7f) /* +0.881741997 */, 367 +MAD_F(0x0db84a81) /* +0.857492926 */, +MAD_F(0x0e1b9d7f) /* +0.881741997 */,
368 +MAD_F(0x0f31adcf) /* +0.949628649 */, +MAD_F(0x0fbba815) /* +0.983314592 */, 368 +MAD_F(0x0f31adcf) /* +0.949628649 */, +MAD_F(0x0fbba815) /* +0.983314592 */,
369 +MAD_F(0x0feda417) /* +0.995517816 */, +MAD_F(0x0ffc8fc8) /* +0.999160558 */, 369 +MAD_F(0x0feda417) /* +0.995517816 */, +MAD_F(0x0ffc8fc8) /* +0.999160558 */,
370 +MAD_F(0x0fff964c) /* +0.999899195 */, +MAD_F(0x0ffff8d3) /* +0.999993155 */ 370 +MAD_F(0x0fff964c) /* +0.999899195 */, +MAD_F(0x0ffff8d3) /* +0.999993155 */
371}; 371};
372 372
373static 373static
374mad_fixed_t const ca[8] = { 374mad_fixed_t const ca[8] = {
375 -MAD_F(0x083b5fe7) /* -0.514495755 */, -MAD_F(0x078c36d2) /* -0.471731969 */, 375 -MAD_F(0x083b5fe7) /* -0.514495755 */, -MAD_F(0x078c36d2) /* -0.471731969 */,
376 -MAD_F(0x05039814) /* -0.313377454 */, -MAD_F(0x02e91dd1) /* -0.181913200 */, 376 -MAD_F(0x05039814) /* -0.313377454 */, -MAD_F(0x02e91dd1) /* -0.181913200 */,
377 -MAD_F(0x0183603a) /* -0.094574193 */, -MAD_F(0x00a7cb87) /* -0.040965583 */, 377 -MAD_F(0x0183603a) /* -0.094574193 */, -MAD_F(0x00a7cb87) /* -0.040965583 */,
378 -MAD_F(0x003a2847) /* -0.014198569 */, -MAD_F(0x000f27b4) /* -0.003699975 */ 378 -MAD_F(0x003a2847) /* -0.014198569 */, -MAD_F(0x000f27b4) /* -0.003699975 */
379}; 379};
380 380
381/* 381/*
382 * IMDCT coefficients for short blocks 382 * IMDCT coefficients for short blocks
383 * derived from section 2.4.3.4.10.2 of ISO/IEC 11172-3 383 * derived from section 2.4.3.4.10.2 of ISO/IEC 11172-3
384 * 384 *
385 * imdct_s[i/even][k] = cos((PI / 24) * (2 * (i / 2) + 7) * (2 * k + 1)) 385 * imdct_s[i/even][k] = cos((PI / 24) * (2 * (i / 2) + 7) * (2 * k + 1))
386 * imdct_s[i /odd][k] = cos((PI / 24) * (2 * (6 + (i-1)/2) + 7) * (2 * k + 1)) 386 * imdct_s[i /odd][k] = cos((PI / 24) * (2 * (6 + (i-1)/2) + 7) * (2 * k + 1))
387 */ 387 */
388static 388static
389mad_fixed_t const imdct_s[6][6] = { 389mad_fixed_t const imdct_s[6][6] = {
390# include "imdct_s.dat" 390# include "imdct_s.dat"
391}; 391};
392 392
393# if !defined(ASO_IMDCT) 393# if !defined(ASO_IMDCT)
394/* 394/*
395 * windowing coefficients for long blocks 395 * windowing coefficients for long blocks
396 * derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3 396 * derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3
397 * 397 *
398 * window_l[i] = sin((PI / 36) * (i + 1/2)) 398 * window_l[i] = sin((PI / 36) * (i + 1/2))
399 */ 399 */
400static 400static
401mad_fixed_t const window_l[36] = { 401mad_fixed_t const window_l[36] = {
402 MAD_F(0x00b2aa3e) /* 0.043619387 */, MAD_F(0x0216a2a2) /* 0.130526192 */, 402 MAD_F(0x00b2aa3e) /* 0.043619387 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
403 MAD_F(0x03768962) /* 0.216439614 */, MAD_F(0x04cfb0e2) /* 0.300705800 */, 403 MAD_F(0x03768962) /* 0.216439614 */, MAD_F(0x04cfb0e2) /* 0.300705800 */,
404 MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x07635284) /* 0.461748613 */, 404 MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x07635284) /* 0.461748613 */,
405 MAD_F(0x0898c779) /* 0.537299608 */, MAD_F(0x09bd7ca0) /* 0.608761429 */, 405 MAD_F(0x0898c779) /* 0.537299608 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
406 MAD_F(0x0acf37ad) /* 0.675590208 */, MAD_F(0x0bcbe352) /* 0.737277337 */, 406 MAD_F(0x0acf37ad) /* 0.675590208 */, MAD_F(0x0bcbe352) /* 0.737277337 */,
407 MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x0d7e8807) /* 0.843391446 */, 407 MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x0d7e8807) /* 0.843391446 */,
408 408
409 MAD_F(0x0e313245) /* 0.887010833 */, MAD_F(0x0ec835e8) /* 0.923879533 */, 409 MAD_F(0x0e313245) /* 0.887010833 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
@@ -440,49 +440,49 @@ mad_fixed_t const window_s[12] = {
440 440
441/* 441/*
442 * coefficients for intensity stereo processing 442 * coefficients for intensity stereo processing
443 * derived from section 2.4.3.4.9.3 of ISO/IEC 11172-3 443 * derived from section 2.4.3.4.9.3 of ISO/IEC 11172-3
444 * 444 *
445 * is_ratio[i] = tan(i * (PI / 12)) 445 * is_ratio[i] = tan(i * (PI / 12))
446 * is_table[i] = is_ratio[i] / (1 + is_ratio[i]) 446 * is_table[i] = is_ratio[i] / (1 + is_ratio[i])
447 */ 447 */
448static 448static
449mad_fixed_t const is_table[7] = { 449mad_fixed_t const is_table[7] = {
450 MAD_F(0x00000000) /* 0.000000000 */, 450 MAD_F(0x00000000) /* 0.000000000 */,
451 MAD_F(0x0361962f) /* 0.211324865 */, 451 MAD_F(0x0361962f) /* 0.211324865 */,
452 MAD_F(0x05db3d74) /* 0.366025404 */, 452 MAD_F(0x05db3d74) /* 0.366025404 */,
453 MAD_F(0x08000000) /* 0.500000000 */, 453 MAD_F(0x08000000) /* 0.500000000 */,
454 MAD_F(0x0a24c28c) /* 0.633974596 */, 454 MAD_F(0x0a24c28c) /* 0.633974596 */,
455 MAD_F(0x0c9e69d1) /* 0.788675135 */, 455 MAD_F(0x0c9e69d1) /* 0.788675135 */,
456 MAD_F(0x10000000) /* 1.000000000 */ 456 MAD_F(0x10000000) /* 1.000000000 */
457}; 457};
458 458
459/* 459/*
460 * coefficients for LSF intensity stereo processing 460 * coefficients for LSF intensity stereo processing
461 * derived from section 2.4.3.2 of ISO/IEC 13818-3 461 * derived from section 2.4.3.2 of ISO/IEC 13818-3
462 * 462 *
463 * is_lsf_table[0][i] = (1 / sqrt(sqrt(2)))^(i + 1) 463 * is_lsf_table[0][i] = (1 / sqrt(sqrt(2)))^(i + 1)
464 * is_lsf_table[1][i] = (1 / sqrt(2))^(i + 1) 464 * is_lsf_table[1][i] = (1 / sqrt(2)) ^(i + 1)
465 */ 465 */
466static 466static
467mad_fixed_t const is_lsf_table[2][15] = { 467mad_fixed_t const is_lsf_table[2][15] = {
468 { 468 {
469 MAD_F(0x0d744fcd) /* 0.840896415 */, 469 MAD_F(0x0d744fcd) /* 0.840896415 */,
470 MAD_F(0x0b504f33) /* 0.707106781 */, 470 MAD_F(0x0b504f33) /* 0.707106781 */,
471 MAD_F(0x09837f05) /* 0.594603558 */, 471 MAD_F(0x09837f05) /* 0.594603558 */,
472 MAD_F(0x08000000) /* 0.500000000 */, 472 MAD_F(0x08000000) /* 0.500000000 */,
473 MAD_F(0x06ba27e6) /* 0.420448208 */, 473 MAD_F(0x06ba27e6) /* 0.420448208 */,
474 MAD_F(0x05a8279a) /* 0.353553391 */, 474 MAD_F(0x05a8279a) /* 0.353553391 */,
475 MAD_F(0x04c1bf83) /* 0.297301779 */, 475 MAD_F(0x04c1bf83) /* 0.297301779 */,
476 MAD_F(0x04000000) /* 0.250000000 */, 476 MAD_F(0x04000000) /* 0.250000000 */,
477 MAD_F(0x035d13f3) /* 0.210224104 */, 477 MAD_F(0x035d13f3) /* 0.210224104 */,
478 MAD_F(0x02d413cd) /* 0.176776695 */, 478 MAD_F(0x02d413cd) /* 0.176776695 */,
479 MAD_F(0x0260dfc1) /* 0.148650889 */, 479 MAD_F(0x0260dfc1) /* 0.148650889 */,
480 MAD_F(0x02000000) /* 0.125000000 */, 480 MAD_F(0x02000000) /* 0.125000000 */,
481 MAD_F(0x01ae89fa) /* 0.105112052 */, 481 MAD_F(0x01ae89fa) /* 0.105112052 */,
482 MAD_F(0x016a09e6) /* 0.088388348 */, 482 MAD_F(0x016a09e6) /* 0.088388348 */,
483 MAD_F(0x01306fe1) /* 0.074325445 */ 483 MAD_F(0x01306fe1) /* 0.074325445 */
484 }, { 484 }, {
485 MAD_F(0x0b504f33) /* 0.707106781 */, 485 MAD_F(0x0b504f33) /* 0.707106781 */,
486 MAD_F(0x08000000) /* 0.500000000 */, 486 MAD_F(0x08000000) /* 0.500000000 */,
487 MAD_F(0x05a8279a) /* 0.353553391 */, 487 MAD_F(0x05a8279a) /* 0.353553391 */,
488 MAD_F(0x04000000) /* 0.250000000 */, 488 MAD_F(0x04000000) /* 0.250000000 */,
@@ -1554,48 +1554,235 @@ void III_aliasreduce(mad_fixed_t xr[576], int lines)
1554 b = xr[ i]; 1554 b = xr[ i];
1555 1555
1556# if defined(ASO_ZEROCHECK) 1556# if defined(ASO_ZEROCHECK)
1557 if (a | b) { 1557 if (a | b) {
1558# endif 1558# endif
1559 MAD_F_ML0(hi, lo, a, cs[i]); 1559 MAD_F_ML0(hi, lo, a, cs[i]);
1560 MAD_F_MLA(hi, lo, -b, ca[i]); 1560 MAD_F_MLA(hi, lo, -b, ca[i]);
1561 1561
1562 xr[-1 - i] = MAD_F_MLZ(hi, lo); 1562 xr[-1 - i] = MAD_F_MLZ(hi, lo);
1563 1563
1564 MAD_F_ML0(hi, lo, b, cs[i]); 1564 MAD_F_ML0(hi, lo, b, cs[i]);
1565 MAD_F_MLA(hi, lo, a, ca[i]); 1565 MAD_F_MLA(hi, lo, a, ca[i]);
1566 1566
1567 xr[ i] = MAD_F_MLZ(hi, lo); 1567 xr[ i] = MAD_F_MLZ(hi, lo);
1568# if defined(ASO_ZEROCHECK) 1568# if defined(ASO_ZEROCHECK)
1569 } 1569 }
1570# endif 1570# endif
1571 } 1571 }
1572 } 1572 }
1573} 1573}
1574 1574
1575# if defined(ASO_IMDCT) 1575# if defined(ASO_IMDCT)
1576void III_imdct_l(mad_fixed_t const [18], mad_fixed_t [36], unsigned int); 1576void III_imdct_l(mad_fixed_t const [18], mad_fixed_t [36], unsigned int);
1577# else 1577# else
1578# if 1
1579static
1580void fastsdct(mad_fixed_t const x[9], mad_fixed_t y[18])
1581{
1582 mad_fixed_t a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12;
1583 mad_fixed_t a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25;
1584 mad_fixed_t m0, m1, m2, m3, m4, m5, m6, m7;
1585
1586 enum {
1587 c0 = MAD_F(0x1f838b8d), /* 2 * cos( 1 * PI / 18) */
1588 c1 = MAD_F(0x1bb67ae8), /* 2 * cos( 3 * PI / 18) */
1589 c2 = MAD_F(0x18836fa3), /* 2 * cos( 4 * PI / 18) */
1590 c3 = MAD_F(0x1491b752), /* 2 * cos( 5 * PI / 18) */
1591 c4 = MAD_F(0x0af1d43a), /* 2 * cos( 7 * PI / 18) */
1592 c5 = MAD_F(0x058e86a0), /* 2 * cos( 8 * PI / 18) */
1593 c6 = -MAD_F(0x1e11f642) /* 2 * cos(16 * PI / 18) */
1594 };
1595
1596 a0 = x[3] + x[5];
1597 a1 = x[3] - x[5];
1598 a2 = x[6] + x[2];
1599 a3 = x[6] - x[2];
1600 a4 = x[1] + x[7];
1601 a5 = x[1] - x[7];
1602 a6 = x[8] + x[0];
1603 a7 = x[8] - x[0];
1604
1605 a8 = a0 + a2;
1606 a9 = a0 - a2;
1607 a10 = a0 - a6;
1608 a11 = a2 - a6;
1609 a12 = a8 + a6;
1610 a13 = a1 - a3;
1611 a14 = a13 + a7;
1612 a15 = a3 + a7;
1613 a16 = a1 - a7;
1614 a17 = a1 + a3;
1615
1616 m0 = mad_f_mul(a17, -c3);
1617 m1 = mad_f_mul(a16, -c0);
1618 m2 = mad_f_mul(a15, -c4);
1619 m3 = mad_f_mul(a14, -c1);
1620 m4 = mad_f_mul(a5, -c1);
1621 m5 = mad_f_mul(a11, -c6);
1622 m6 = mad_f_mul(a10, -c5);
1623 m7 = mad_f_mul(a9, -c2);
1624
1625 a18 = x[4] + a4;
1626 a19 = 2 * x[4] - a4;
1627 a20 = a19 + m5;
1628 a21 = a19 - m5;
1629 a22 = a19 + m6;
1630 a23 = m4 + m2;
1631 a24 = m4 - m2;
1632 a25 = m4 + m1;
1633
1634 /* output to every other slot for convenience */
1635
1636 y[ 0] = a18 + a12;
1637 y[ 2] = m0 - a25;
1638 y[ 4] = m7 - a20;
1639 y[ 6] = m3;
1640 y[ 8] = a21 - m6;
1641 y[10] = a24 - m1;
1642 y[12] = a12 - 2 * a18;
1643 y[14] = a23 + m0;
1644 y[16] = a22 + m7;
1645}
1646
1647static inline
1648void sdctII(mad_fixed_t const x[18], mad_fixed_t X[18])
1649{
1650 mad_fixed_t tmp[9];
1651 int i;
1652
1653 /* scale[i] = 2 * cos(PI * (2 * i + 1) / (2 * 18)) */
1654 static mad_fixed_t const scale[9] = {
1655 MAD_F(0x1fe0d3b4), MAD_F(0x1ee8dd47), MAD_F(0x1d007930),
1656 MAD_F(0x1a367e59), MAD_F(0x16a09e66), MAD_F(0x125abcf8),
1657 MAD_F(0x0d8616bc), MAD_F(0x08483ee1), MAD_F(0x02c9fad7)
1658 };
1659
1660 /* divide the 18-point SDCT-II into two 9-point SDCT-IIs */
1661
1662 /* even input butterfly */
1663
1664 for (i = 0; i < 9; i += 3) {
1665 tmp[i + 0] = x[i + 0] + x[18 - (i + 0) - 1];
1666 tmp[i + 1] = x[i + 1] + x[18 - (i + 1) - 1];
1667 tmp[i + 2] = x[i + 2] + x[18 - (i + 2) - 1];
1668 }
1669
1670 fastsdct(tmp, &X[0]);
1671
1672 /* odd input butterfly and scaling */
1673
1674 for (i = 0; i < 9; i += 3) {
1675 tmp[i + 0] = mad_f_mul(x[i + 0] - x[18 - (i + 0) - 1], scale[i + 0]);
1676 tmp[i + 1] = mad_f_mul(x[i + 1] - x[18 - (i + 1) - 1], scale[i + 1]);
1677 tmp[i + 2] = mad_f_mul(x[i + 2] - x[18 - (i + 2) - 1], scale[i + 2]);
1678 }
1679
1680 fastsdct(tmp, &X[1]);
1681
1682 /* output accumulation */
1683
1684 for (i = 3; i < 18; i += 8) {
1685 X[i + 0] -= X[(i + 0) - 2];
1686 X[i + 2] -= X[(i + 2) - 2];
1687 X[i + 4] -= X[(i + 4) - 2];
1688 X[i + 6] -= X[(i + 6) - 2];
1689 }
1690}
1691
1692static inline
1693void dctIV(mad_fixed_t const y[18], mad_fixed_t X[18])
1694{
1695 mad_fixed_t tmp[18];
1696 int i;
1697
1698 /* scale[i] = 2 * cos(PI * (2 * i + 1) / (4 * 18)) */
1699 static mad_fixed_t const scale[18] = {
1700 MAD_F(0x1ff833fa), MAD_F(0x1fb9ea93), MAD_F(0x1f3dd120),
1701 MAD_F(0x1e84d969), MAD_F(0x1d906bcf), MAD_F(0x1c62648b),
1702 MAD_F(0x1afd100f), MAD_F(0x1963268b), MAD_F(0x1797c6a4),
1703 MAD_F(0x159e6f5b), MAD_F(0x137af940), MAD_F(0x11318ef3),
1704 MAD_F(0x0ec6a507), MAD_F(0x0c3ef153), MAD_F(0x099f61c5),
1705 MAD_F(0x06ed12c5), MAD_F(0x042d4544), MAD_F(0x0165547c)
1706 };
1707
1708 /* scaling */
1709
1710 for (i = 0; i < 18; i += 3) {
1711 tmp[i + 0] = mad_f_mul(y[i + 0], scale[i + 0]);
1712 tmp[i + 1] = mad_f_mul(y[i + 1], scale[i + 1]);
1713 tmp[i + 2] = mad_f_mul(y[i + 2], scale[i + 2]);
1714 }
1715
1716 /* SDCT-II */
1717
1718 sdctII(tmp, X);
1719
1720 /* scale reduction and output accumulation */
1721
1722 X[0] /= 2;
1723 for (i = 1; i < 17; i += 4) {
1724 X[i + 0] = X[i + 0] / 2 - X[(i + 0) - 1];
1725 X[i + 1] = X[i + 1] / 2 - X[(i + 1) - 1];
1726 X[i + 2] = X[i + 2] / 2 - X[(i + 2) - 1];
1727 X[i + 3] = X[i + 3] / 2 - X[(i + 3) - 1];
1728 }
1729 X[17] = X[17] / 2 - X[16];
1730}
1731
1732/*
1733 * NAME:imdct36
1734 * DESCRIPTION:perform X[18]->x[36] IMDCT using Szu-Wei Lee's fast algorithm
1735 */
1736static inline
1737void imdct36(mad_fixed_t const x[18], mad_fixed_t y[36])
1738{
1739 mad_fixed_t tmp[18];
1740 int i;
1741
1742 /* DCT-IV */
1743
1744 dctIV(x, tmp);
1745
1746 /* convert 18-point DCT-IV to 36-point IMDCT */
1747
1748 for (i = 0; i < 9; i += 3) {
1749 y[i + 0] = tmp[9 + (i + 0)];
1750 y[i + 1] = tmp[9 + (i + 1)];
1751 y[i + 2] = tmp[9 + (i + 2)];
1752 }
1753 for (i = 9; i < 27; i += 3) {
1754 y[i + 0] = -tmp[36 - (9 + (i + 0)) - 1];
1755 y[i + 1] = -tmp[36 - (9 + (i + 1)) - 1];
1756 y[i + 2] = -tmp[36 - (9 + (i + 2)) - 1];
1757 }
1758 for (i = 27; i < 36; i += 3) {
1759 y[i + 0] = -tmp[(i + 0) - 27];
1760 y[i + 1] = -tmp[(i + 1) - 27];
1761 y[i + 2] = -tmp[(i + 2) - 27];
1762 }
1763}
1764# else
1578/* 1765/*
1579 * NAME:imdct36 1766 * NAME:imdct36
1580 * DESCRIPTION:perform X[18]->x[36] IMDCT 1767 * DESCRIPTION:perform X[18]->x[36] IMDCT
1581 */ 1768 */
1582static inline 1769static inline
1583void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36]) 1770void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36])
1584{ 1771{
1585 mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7; 1772 mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7;
1586 mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15; 1773 mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15;
1587 register mad_fixed64hi_t hi; 1774 register mad_fixed64hi_t hi;
1588 register mad_fixed64lo_t lo; 1775 register mad_fixed64lo_t lo;
1589 1776
1590 MAD_F_ML0(hi, lo, X[4], MAD_F(0x0ec835e8)); 1777 MAD_F_ML0(hi, lo, X[4], MAD_F(0x0ec835e8));
1591 MAD_F_MLA(hi, lo, X[13], MAD_F(0x061f78aa)); 1778 MAD_F_MLA(hi, lo, X[13], MAD_F(0x061f78aa));
1592 1779
1593 t6 = MAD_F_MLZ(hi, lo); 1780 t6 = MAD_F_MLZ(hi, lo);
1594 1781
1595 MAD_F_MLA(hi, lo, (t14 = X[1] - X[10]), -MAD_F(0x061f78aa)); 1782 MAD_F_MLA(hi, lo, (t14 = X[1] - X[10]), -MAD_F(0x061f78aa));
1596 MAD_F_MLA(hi, lo, (t15 = X[7] + X[16]), -MAD_F(0x0ec835e8)); 1783 MAD_F_MLA(hi, lo, (t15 = X[7] + X[16]), -MAD_F(0x0ec835e8));
1597 1784
1598 t0 = MAD_F_MLZ(hi, lo); 1785 t0 = MAD_F_MLZ(hi, lo);
1599 1786
1600 MAD_F_MLA(hi, lo, (t8 = X[0] - X[11] - X[12]), MAD_F(0x0216a2a2)); 1787 MAD_F_MLA(hi, lo, (t8 = X[0] - X[11] - X[12]), MAD_F(0x0216a2a2));
1601 MAD_F_MLA(hi, lo, (t9 = X[2] - X[9] - X[14]), MAD_F(0x09bd7ca0)); 1788 MAD_F_MLA(hi, lo, (t9 = X[2] - X[9] - X[14]), MAD_F(0x09bd7ca0));
@@ -1844,48 +2031,49 @@ void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36])
1844 MAD_F_MLA(hi, lo, X[11], MAD_F(0x0ffc19fd)); 2031 MAD_F_MLA(hi, lo, X[11], MAD_F(0x0ffc19fd));
1845 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0898c779)); 2032 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0898c779));
1846 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f9ee890)); 2033 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f9ee890));
1847 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0bcbe352)); 2034 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0bcbe352));
1848 MAD_F_MLA(hi, lo, X[17], MAD_F(0x0e313245)); 2035 MAD_F_MLA(hi, lo, X[17], MAD_F(0x0e313245));
1849 2036
1850 x[3] = MAD_F_MLZ(hi, lo) + t5; 2037 x[3] = MAD_F_MLZ(hi, lo) + t5;
1851 x[14] = -x[3]; 2038 x[14] = -x[3];
1852 2039
1853 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0ffc19fd)); 2040 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0ffc19fd));
1854 MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0f9ee890)); 2041 MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0f9ee890));
1855 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0f426cb5)); 2042 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0f426cb5));
1856 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0e313245)); 2043 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0e313245));
1857 MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0d7e8807)); 2044 MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0d7e8807));
1858 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0bcbe352)); 2045 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0bcbe352));
1859 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0acf37ad)); 2046 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0acf37ad));
1860 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0898c779)); 2047 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0898c779));
1861 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x07635284)); 2048 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x07635284));
1862 MAD_F_MLA(hi, lo, X[14], -MAD_F(0x04cfb0e2)); 2049 MAD_F_MLA(hi, lo, X[14], -MAD_F(0x04cfb0e2));
1863 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x03768962)); 2050 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x03768962));
1864 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x00b2aa3e)); 2051 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x00b2aa3e));
1865 2052
1866 x[26] = x[27] = MAD_F_MLZ(hi, lo) + t5; 2053 x[26] = x[27] = MAD_F_MLZ(hi, lo) + t5;
1867} 2054}
2055# endif
1868 2056
1869/* 2057/*
1870 * NAME:III_imdct_l() 2058 * NAME:III_imdct_l()
1871 * DESCRIPTION:perform IMDCT and windowing for long blocks 2059 * DESCRIPTION:perform IMDCT and windowing for long blocks
1872 */ 2060 */
1873static 2061static
1874void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36], 2062void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36],
1875 unsigned int block_type) 2063 unsigned int block_type)
1876{ 2064{
1877 unsigned int i; 2065 unsigned int i;
1878 2066
1879 /* IMDCT */ 2067 /* IMDCT */
1880 2068
1881 imdct36(X, z); 2069 imdct36(X, z);
1882 2070
1883 /* windowing */ 2071 /* windowing */
1884 2072
1885 switch (block_type) { 2073 switch (block_type) {
1886 case 0: /* normal window */ 2074 case 0: /* normal window */
1887# if defined(ASO_INTERLEAVE1) 2075# if defined(ASO_INTERLEAVE1)
1888 { 2076 {
1889 register mad_fixed_t tmp1, tmp2; 2077 register mad_fixed_t tmp1, tmp2;
1890 2078
1891 tmp1 = window_l[0]; 2079 tmp1 = window_l[0];
@@ -1908,59 +2096,67 @@ void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36],
1908 tmp1 = z[0]; 2096 tmp1 = z[0];
1909 tmp2 = window_l[0]; 2097 tmp2 = window_l[0];
1910 2098
1911 for (i = 0; i < 35; ++i) { 2099 for (i = 0; i < 35; ++i) {
1912 z[i] = mad_f_mul(tmp1, tmp2); 2100 z[i] = mad_f_mul(tmp1, tmp2);
1913 tmp1 = z[i + 1]; 2101 tmp1 = z[i + 1];
1914 tmp2 = window_l[i + 1]; 2102 tmp2 = window_l[i + 1];
1915 } 2103 }
1916 2104
1917 z[35] = mad_f_mul(tmp1, tmp2); 2105 z[35] = mad_f_mul(tmp1, tmp2);
1918 } 2106 }
1919# elif 1 2107# elif 1
1920 for (i = 0; i < 36; i += 4) { 2108 for (i = 0; i < 36; i += 4) {
1921 z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]); 2109 z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
1922 z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]); 2110 z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
1923 z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]); 2111 z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
1924 z[i + 3] = mad_f_mul(z[i + 3], window_l[i + 3]); 2112 z[i + 3] = mad_f_mul(z[i + 3], window_l[i + 3]);
1925 } 2113 }
1926# else 2114# else
1927 for (i = 0; i < 36; ++i) z[i] = mad_f_mul(z[i], window_l[i]); 2115 for (i = 0; i < 36; ++i) z[i] = mad_f_mul(z[i], window_l[i]);
1928# endif 2116# endif
1929 break; 2117 break;
1930 2118
1931 case 1: /* start block */ 2119 case 1: /* start block */
1932 for (i = 0; i < 18; ++i) z[i] = mad_f_mul(z[i], window_l[i]); 2120 for (i = 0; i < 18; i += 3) {
2121 z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
2122 z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
2123 z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
2124 }
1933 /* (i = 18; i < 24; ++i) z[i] unchanged */ 2125 /* (i = 18; i < 24; ++i) z[i] unchanged */
1934 for (i = 24; i < 30; ++i) z[i] = mad_f_mul(z[i], window_s[i - 18]); 2126 for (i = 24; i < 30; ++i) z[i] = mad_f_mul(z[i], window_s[i - 18]);
1935 for (i = 30; i < 36; ++i) z[i] = 0; 2127 for (i = 30; i < 36; ++i) z[i] = 0;
1936 break; 2128 break;
1937 2129
1938 case 3: /* stop block */ 2130 case 3: /* stop block */
1939 for (i = 0; i < 6; ++i) z[i] = 0; 2131 for (i = 0; i < 6; ++i) z[i] = 0;
1940 for (i = 6; i < 12; ++i) z[i] = mad_f_mul(z[i], window_s[i - 6]); 2132 for (i = 6; i < 12; ++i) z[i] = mad_f_mul(z[i], window_s[i - 6]);
1941 /* (i = 12; i < 18; ++i) z[i] unchanged */ 2133 /* (i = 12; i < 18; ++i) z[i] unchanged */
1942 for (i = 18; i < 36; ++i) z[i] = mad_f_mul(z[i], window_l[i]); 2134 for (i = 18; i < 36; i += 3) {
2135 z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
2136 z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
2137 z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
2138 }
1943 break; 2139 break;
1944 } 2140 }
1945} 2141}
1946# endif /* ASO_IMDCT */ 2142# endif /* ASO_IMDCT */
1947 2143
1948/* 2144/*
1949 * NAME:III_imdct_s() 2145 * NAME:III_imdct_s()
1950 * DESCRIPTION:perform IMDCT and windowing for short blocks 2146 * DESCRIPTION:perform IMDCT and windowing for short blocks
1951 */ 2147 */
1952static 2148static
1953void III_imdct_s(mad_fixed_t const X[18], mad_fixed_t z[36]) 2149void III_imdct_s(mad_fixed_t const X[18], mad_fixed_t z[36])
1954{ 2150{
1955 mad_fixed_t y[36], *yptr; 2151 mad_fixed_t y[36], *yptr;
1956 mad_fixed_t const *wptr; 2152 mad_fixed_t const *wptr;
1957 int w, i; 2153 int w, i;
1958 register mad_fixed64hi_t hi; 2154 register mad_fixed64hi_t hi;
1959 register mad_fixed64lo_t lo; 2155 register mad_fixed64lo_t lo;
1960 2156
1961 /* IMDCT */ 2157 /* IMDCT */
1962 2158
1963 yptr = &y[0]; 2159 yptr = &y[0];
1964 2160
1965 for (w = 0; w < 3; ++w) { 2161 for (w = 0; w < 3; ++w) {
1966 register mad_fixed_t const (*s)[6]; 2162 register mad_fixed_t const (*s)[6];
@@ -2021,73 +2217,73 @@ void III_imdct_s(mad_fixed_t const X[18], mad_fixed_t z[36])
2021 2217
2022 ++yptr; 2218 ++yptr;
2023 ++wptr; 2219 ++wptr;
2024 } 2220 }
2025} 2221}
2026 2222
2027/* 2223/*
2028 * NAME:III_overlap() 2224 * NAME:III_overlap()
2029 * DESCRIPTION:perform overlap-add of windowed IMDCT outputs 2225 * DESCRIPTION:perform overlap-add of windowed IMDCT outputs
2030 */ 2226 */
2031static 2227static
2032void III_overlap(mad_fixed_t const output[36], mad_fixed_t overlap[18], 2228void III_overlap(mad_fixed_t const output[36], mad_fixed_t overlap[18],
2033 mad_fixed_t sample[18][32], unsigned int sb) 2229 mad_fixed_t sample[18][32], unsigned int sb)
2034{ 2230{
2035 unsigned int i; 2231 unsigned int i;
2036 2232
2037# if defined(ASO_INTERLEAVE2) 2233# if defined(ASO_INTERLEAVE2)
2038 { 2234 {
2039 register mad_fixed_t tmp1, tmp2; 2235 register mad_fixed_t tmp1, tmp2;
2040 2236
2041 tmp1 = overlap[0]; 2237 tmp1 = overlap[0];
2042 tmp2 = overlap[1]; 2238 tmp2 = overlap[1];
2043 2239
2044 for (i = 0; i < 16; i += 2) { 2240 for (i = 0; i < 16; i += 2) {
2045 sample[i + 0][sb] = output[i + 0] + tmp1; 2241 sample[i + 0][sb] = output[i + 0 + 0] + tmp1;
2046 overlap[i + 0] = output[i + 0 + 18]; 2242 overlap[i + 0] = output[i + 0 + 18];
2047 tmp1 = overlap[i + 2]; 2243 tmp1 = overlap[i + 2];
2048 2244
2049 sample[i + 1][sb] = output[i + 1] + tmp2; 2245 sample[i + 1][sb] = output[i + 1 + 0] + tmp2;
2050 overlap[i + 1] = output[i + 1 + 18]; 2246 overlap[i + 1] = output[i + 1 + 18];
2051 tmp2 = overlap[i + 3]; 2247 tmp2 = overlap[i + 3];
2052 } 2248 }
2053 2249
2054 sample[16][sb] = output[16] + tmp1; 2250 sample[16][sb] = output[16 + 0] + tmp1;
2055 overlap[16] = output[16 + 18]; 2251 overlap[16] = output[16 + 18];
2056 sample[17][sb] = output[17] + tmp2; 2252 sample[17][sb] = output[17 + 0] + tmp2;
2057 overlap[17] = output[17 + 18]; 2253 overlap[17] = output[17 + 18];
2058 } 2254 }
2059# elif 0 2255# elif 0
2060 for (i = 0; i < 18; i += 2) { 2256 for (i = 0; i < 18; i += 2) {
2061 sample[i + 0][sb] = output[i + 0] + overlap[i + 0]; 2257 sample[i + 0][sb] = output[i + 0 + 0] + overlap[i + 0];
2062 overlap[i + 0] = output[i + 0 + 18]; 2258 overlap[i + 0] = output[i + 0 + 18];
2063 2259
2064 sample[i + 1][sb] = output[i + 1] + overlap[i + 1]; 2260 sample[i + 1][sb] = output[i + 1 + 0] + overlap[i + 1];
2065 overlap[i + 1] = output[i + 1 + 18]; 2261 overlap[i + 1] = output[i + 1 + 18];
2066 } 2262 }
2067# else 2263# else
2068 for (i = 0; i < 18; ++i) { 2264 for (i = 0; i < 18; ++i) {
2069 sample[i][sb] = output[i] + overlap[i]; 2265 sample[i][sb] = output[i + 0] + overlap[i];
2070 overlap[i] = output[i + 18]; 2266 overlap[i] = output[i + 18];
2071 } 2267 }
2072# endif 2268# endif
2073} 2269}
2074 2270
2075/* 2271/*
2076 * NAME:III_overlap_z() 2272 * NAME:III_overlap_z()
2077 * DESCRIPTION:perform "overlap-add" of zero IMDCT outputs 2273 * DESCRIPTION:perform "overlap-add" of zero IMDCT outputs
2078 */ 2274 */
2079static inline 2275static inline
2080void III_overlap_z(mad_fixed_t overlap[18], 2276void III_overlap_z(mad_fixed_t overlap[18],
2081 mad_fixed_t sample[18][32], unsigned int sb) 2277 mad_fixed_t sample[18][32], unsigned int sb)
2082{ 2278{
2083 unsigned int i; 2279 unsigned int i;
2084 2280
2085# if defined(ASO_INTERLEAVE2) 2281# if defined(ASO_INTERLEAVE2)
2086 { 2282 {
2087 register mad_fixed_t tmp1, tmp2; 2283 register mad_fixed_t tmp1, tmp2;
2088 2284
2089 tmp1 = overlap[0]; 2285 tmp1 = overlap[0];
2090 tmp2 = overlap[1]; 2286 tmp2 = overlap[1];
2091 2287
2092 for (i = 0; i < 16; i += 2) { 2288 for (i = 0; i < 16; i += 2) {
2093 sample[i + 0][sb] = tmp1; 2289 sample[i + 0][sb] = tmp1;
@@ -2433,54 +2629,54 @@ int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame)
2433 *stream->main_data + stream->md_len - si.main_data_begin); 2629 *stream->main_data + stream->md_len - si.main_data_begin);
2434 2630
2435 if (md_len > si.main_data_begin) { 2631 if (md_len > si.main_data_begin) {
2436 assert(stream->md_len + md_len - 2632 assert(stream->md_len + md_len -
2437 si.main_data_begin <= MAD_BUFFER_MDLEN); 2633 si.main_data_begin <= MAD_BUFFER_MDLEN);
2438 2634
2439 memcpy(*stream->main_data + stream->md_len, 2635 memcpy(*stream->main_data + stream->md_len,
2440 mad_bit_nextbyte(&stream->ptr), 2636 mad_bit_nextbyte(&stream->ptr),
2441 frame_used = md_len - si.main_data_begin); 2637 frame_used = md_len - si.main_data_begin);
2442 stream->md_len += frame_used; 2638 stream->md_len += frame_used;
2443 } 2639 }
2444 } 2640 }
2445 } 2641 }
2446 2642
2447 frame_free = frame_space - frame_used; 2643 frame_free = frame_space - frame_used;
2448 2644
2449 /* decode main_data */ 2645 /* decode main_data */
2450 2646
2451 if (result == 0) { 2647 if (result == 0) {
2452 error = III_decode(&ptr, frame, &si, nch); 2648 error = III_decode(&ptr, frame, &si, nch);
2453 if (error) { 2649 if (error) {
2454 stream->error = error; 2650 stream->error = error;
2455 result = -1; 2651 result = -1;
2456 } 2652 }
2457 }
2458 2653
2459 /* designate ancillary bits */ 2654 /* designate ancillary bits */
2460 2655
2461 stream->anc_ptr = ptr; 2656 stream->anc_ptr = ptr;
2462 stream->anc_bitlen = md_len * CHAR_BIT - data_bitlen; 2657 stream->anc_bitlen = md_len * CHAR_BIT - data_bitlen;
2658 }
2463 2659
2464# if 0 && defined(DEBUG) 2660# if 0 && defined(DEBUG)
2465 fprintf(stderr, 2661 fprintf(stderr,
2466 "main_data_begin:%u, md_len:%u, frame_free:%u, " 2662 "main_data_begin:%u, md_len:%u, frame_free:%u, "
2467 "data_bitlen:%u, anc_bitlen: %u\n", 2663 "data_bitlen:%u, anc_bitlen: %u\n",
2468 si.main_data_begin, md_len, frame_free, 2664 si.main_data_begin, md_len, frame_free,
2469 data_bitlen, stream->anc_bitlen); 2665 data_bitlen, stream->anc_bitlen);
2470# endif 2666# endif
2471 2667
2472 /* preload main_data buffer with up to 511 bytes for next frame(s) */ 2668 /* preload main_data buffer with up to 511 bytes for next frame(s) */
2473 2669
2474 if (frame_free >= next_md_begin) { 2670 if (frame_free >= next_md_begin) {
2475 memcpy(*stream->main_data, 2671 memcpy(*stream->main_data,
2476 stream->next_frame - next_md_begin, next_md_begin); 2672 stream->next_frame - next_md_begin, next_md_begin);
2477 stream->md_len = next_md_begin; 2673 stream->md_len = next_md_begin;
2478 } 2674 }
2479 else { 2675 else {
2480 if (md_len < si.main_data_begin) { 2676 if (md_len < si.main_data_begin) {
2481 unsigned int extra; 2677 unsigned int extra;
2482 2678
2483 extra = si.main_data_begin - md_len; 2679 extra = si.main_data_begin - md_len;
2484 if (extra + frame_free > next_md_begin) 2680 if (extra + frame_free > next_md_begin)
2485 extra = next_md_begin - frame_free; 2681 extra = next_md_begin - frame_free;
2486 2682