summaryrefslogtreecommitdiff
authorharlekin <harlekin>2002-04-19 16:08:55 (UTC)
committer harlekin <harlekin>2002-04-19 16:08:55 (UTC)
commit7ea4abeb652e6787e57a938e1ca028d25fd249ce (patch) (unidiff)
treeee08f2d9d6aaa8adb1c5f07f4124da8a61eb8cd5
parentcaa7ced77b9014526607f9f65c58aabe7e0ba631 (diff)
downloadopie-7ea4abeb652e6787e57a938e1ca028d25fd249ce.zip
opie-7ea4abeb652e6787e57a938e1ca028d25fd249ce.tar.gz
opie-7ea4abeb652e6787e57a938e1ca028d25fd249ce.tar.bz2
new libmad version, less cpu usage
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/COPYRIGHT21
-rw-r--r--core/multimedia/opieplayer/libmad/D.dat2
-rw-r--r--core/multimedia/opieplayer/libmad/bit.c39
-rw-r--r--core/multimedia/opieplayer/libmad/bit.h2
-rw-r--r--core/multimedia/opieplayer/libmad/decoder.c60
-rw-r--r--core/multimedia/opieplayer/libmad/decoder.h20
-rw-r--r--core/multimedia/opieplayer/libmad/fixed.c2
-rw-r--r--core/multimedia/opieplayer/libmad/fixed.h97
-rw-r--r--core/multimedia/opieplayer/libmad/frame.c4
-rw-r--r--core/multimedia/opieplayer/libmad/frame.h60
-rw-r--r--core/multimedia/opieplayer/libmad/huffman.c21
-rw-r--r--core/multimedia/opieplayer/libmad/huffman.h20
-rw-r--r--core/multimedia/opieplayer/libmad/imdct_s.dat2
-rw-r--r--core/multimedia/opieplayer/libmad/layer12.c2
-rw-r--r--core/multimedia/opieplayer/libmad/layer12.h2
-rw-r--r--core/multimedia/opieplayer/libmad/layer3.c150
-rw-r--r--core/multimedia/opieplayer/libmad/layer3.h2
-rw-r--r--core/multimedia/opieplayer/libmad/libmad_global.h15
-rw-r--r--core/multimedia/opieplayer/libmad/libmad_version.h6
-rw-r--r--core/multimedia/opieplayer/libmad/opie-libmadplugin.control2
-rw-r--r--core/multimedia/opieplayer/libmad/qc_table.dat2
-rw-r--r--core/multimedia/opieplayer/libmad/rq_table.dat2
-rw-r--r--core/multimedia/opieplayer/libmad/sf_table.dat2
-rw-r--r--core/multimedia/opieplayer/libmad/stream.c41
-rw-r--r--core/multimedia/opieplayer/libmad/stream.h13
-rw-r--r--core/multimedia/opieplayer/libmad/synth.c328
-rw-r--r--core/multimedia/opieplayer/libmad/synth.h33
-rw-r--r--core/multimedia/opieplayer/libmad/timer.c66
-rw-r--r--core/multimedia/opieplayer/libmad/timer.h4
-rw-r--r--core/multimedia/opieplayer/libmad/version.c6
30 files changed, 625 insertions, 401 deletions
diff --git a/core/multimedia/opieplayer/libmad/COPYRIGHT b/core/multimedia/opieplayer/libmad/COPYRIGHT
new file mode 100644
index 0000000..f30a707
--- a/dev/null
+++ b/core/multimedia/opieplayer/libmad/COPYRIGHT
@@ -0,0 +1,21 @@
1
2 libmad - MPEG audio decoder library
3 Copyright (C) 2000-2001 Robert Leslie
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 If you would like to negotiate alternate licensing terms, you may do
20 so by contacting the author: Robert Leslie <rob@mars.org>
21
diff --git a/core/multimedia/opieplayer/libmad/D.dat b/core/multimedia/opieplayer/libmad/D.dat
index f33d30c..c3ee74c 100644
--- a/core/multimedia/opieplayer/libmad/D.dat
+++ b/core/multimedia/opieplayer/libmad/D.dat
@@ -1,194 +1,194 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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/* 22/*
23 * These are the coefficients for the subband synthesis window. This is a 23 * These are the coefficients for the subband synthesis window. This is a
24 * reordered version of Table B.3 from ISO/IEC 11172-3. 24 * reordered version of Table B.3 from ISO/IEC 11172-3.
25 * 25 *
26 * Every value is parameterized so that shift optimizations can be made at 26 * Every value is parameterized so that shift optimizations can be made at
27 * compile-time. For example, every value can be right-shifted 12 bits to 27 * compile-time. For example, every value can be right-shifted 12 bits to
28 * minimize multiply instruction times without any loss of accuracy. 28 * minimize multiply instruction times without any loss of accuracy.
29 */ 29 */
30 30
31 { PRESHIFT(0x00000000) /* 0.000000000 */,/* 0 */ 31 { PRESHIFT(0x00000000) /* 0.000000000 */,/* 0 */
32 -PRESHIFT(0x0001d000) /* -0.000442505 */, 32 -PRESHIFT(0x0001d000) /* -0.000442505 */,
33 PRESHIFT(0x000d5000) /* 0.003250122 */, 33 PRESHIFT(0x000d5000) /* 0.003250122 */,
34 -PRESHIFT(0x001cb000) /* -0.007003784 */, 34 -PRESHIFT(0x001cb000) /* -0.007003784 */,
35 PRESHIFT(0x007f5000) /* 0.031082153 */, 35 PRESHIFT(0x007f5000) /* 0.031082153 */,
36 -PRESHIFT(0x01421000) /* -0.078628540 */, 36 -PRESHIFT(0x01421000) /* -0.078628540 */,
37 PRESHIFT(0x019ae000) /* 0.100311279 */, 37 PRESHIFT(0x019ae000) /* 0.100311279 */,
38 -PRESHIFT(0x09271000) /* -0.572036743 */, 38 -PRESHIFT(0x09271000) /* -0.572036743 */,
39 PRESHIFT(0x1251e000) /* 1.144989014 */, 39 PRESHIFT(0x1251e000) /* 1.144989014 */,
40 PRESHIFT(0x09271000) /* 0.572036743 */, 40 PRESHIFT(0x09271000) /* 0.572036743 */,
41 PRESHIFT(0x019ae000) /* 0.100311279 */, 41 PRESHIFT(0x019ae000) /* 0.100311279 */,
42 PRESHIFT(0x01421000) /* 0.078628540 */, 42 PRESHIFT(0x01421000) /* 0.078628540 */,
43 PRESHIFT(0x007f5000) /* 0.031082153 */, 43 PRESHIFT(0x007f5000) /* 0.031082153 */,
44 PRESHIFT(0x001cb000) /* 0.007003784 */, 44 PRESHIFT(0x001cb000) /* 0.007003784 */,
45 PRESHIFT(0x000d5000) /* 0.003250122 */, 45 PRESHIFT(0x000d5000) /* 0.003250122 */,
46 PRESHIFT(0x0001d000) /* 0.000442505 */, 46 PRESHIFT(0x0001d000) /* 0.000442505 */,
47 47
48 PRESHIFT(0x00000000) /* 0.000000000 */, 48 PRESHIFT(0x00000000) /* 0.000000000 */,
49 -PRESHIFT(0x0001d000) /* -0.000442505 */, 49 -PRESHIFT(0x0001d000) /* -0.000442505 */,
50 PRESHIFT(0x000d5000) /* 0.003250122 */, 50 PRESHIFT(0x000d5000) /* 0.003250122 */,
51 -PRESHIFT(0x001cb000) /* -0.007003784 */, 51 -PRESHIFT(0x001cb000) /* -0.007003784 */,
52 PRESHIFT(0x007f5000) /* 0.031082153 */, 52 PRESHIFT(0x007f5000) /* 0.031082153 */,
53 -PRESHIFT(0x01421000) /* -0.078628540 */, 53 -PRESHIFT(0x01421000) /* -0.078628540 */,
54 PRESHIFT(0x019ae000) /* 0.100311279 */, 54 PRESHIFT(0x019ae000) /* 0.100311279 */,
55 -PRESHIFT(0x09271000) /* -0.572036743 */, 55 -PRESHIFT(0x09271000) /* -0.572036743 */,
56 PRESHIFT(0x1251e000) /* 1.144989014 */, 56 PRESHIFT(0x1251e000) /* 1.144989014 */,
57 PRESHIFT(0x09271000) /* 0.572036743 */, 57 PRESHIFT(0x09271000) /* 0.572036743 */,
58 PRESHIFT(0x019ae000) /* 0.100311279 */, 58 PRESHIFT(0x019ae000) /* 0.100311279 */,
59 PRESHIFT(0x01421000) /* 0.078628540 */, 59 PRESHIFT(0x01421000) /* 0.078628540 */,
60 PRESHIFT(0x007f5000) /* 0.031082153 */, 60 PRESHIFT(0x007f5000) /* 0.031082153 */,
61 PRESHIFT(0x001cb000) /* 0.007003784 */, 61 PRESHIFT(0x001cb000) /* 0.007003784 */,
62 PRESHIFT(0x000d5000) /* 0.003250122 */, 62 PRESHIFT(0x000d5000) /* 0.003250122 */,
63 PRESHIFT(0x0001d000) /* 0.000442505 */ }, 63 PRESHIFT(0x0001d000) /* 0.000442505 */ },
64 64
65 { -PRESHIFT(0x00001000) /* -0.000015259 */,/* 1 */ 65 { -PRESHIFT(0x00001000) /* -0.000015259 */,/* 1 */
66 -PRESHIFT(0x0001f000) /* -0.000473022 */, 66 -PRESHIFT(0x0001f000) /* -0.000473022 */,
67 PRESHIFT(0x000da000) /* 0.003326416 */, 67 PRESHIFT(0x000da000) /* 0.003326416 */,
68 -PRESHIFT(0x00207000) /* -0.007919312 */, 68 -PRESHIFT(0x00207000) /* -0.007919312 */,
69 PRESHIFT(0x007d0000) /* 0.030517578 */, 69 PRESHIFT(0x007d0000) /* 0.030517578 */,
70 -PRESHIFT(0x0158d000) /* -0.084182739 */, 70 -PRESHIFT(0x0158d000) /* -0.084182739 */,
71 PRESHIFT(0x01747000) /* 0.090927124 */, 71 PRESHIFT(0x01747000) /* 0.090927124 */,
72 -PRESHIFT(0x099a8000) /* -0.600219727 */, 72 -PRESHIFT(0x099a8000) /* -0.600219727 */,
73 PRESHIFT(0x124f0000) /* 1.144287109 */, 73 PRESHIFT(0x124f0000) /* 1.144287109 */,
74 PRESHIFT(0x08b38000) /* 0.543823242 */, 74 PRESHIFT(0x08b38000) /* 0.543823242 */,
75 PRESHIFT(0x01bde000) /* 0.108856201 */, 75 PRESHIFT(0x01bde000) /* 0.108856201 */,
76 PRESHIFT(0x012b4000) /* 0.073059082 */, 76 PRESHIFT(0x012b4000) /* 0.073059082 */,
77 PRESHIFT(0x0080f000) /* 0.031478882 */, 77 PRESHIFT(0x0080f000) /* 0.031478882 */,
78 PRESHIFT(0x00191000) /* 0.006118774 */, 78 PRESHIFT(0x00191000) /* 0.006118774 */,
79 PRESHIFT(0x000d0000) /* 0.003173828 */, 79 PRESHIFT(0x000d0000) /* 0.003173828 */,
80 PRESHIFT(0x0001a000) /* 0.000396729 */, 80 PRESHIFT(0x0001a000) /* 0.000396729 */,
81 81
82 -PRESHIFT(0x00001000) /* -0.000015259 */, 82 -PRESHIFT(0x00001000) /* -0.000015259 */,
83 -PRESHIFT(0x0001f000) /* -0.000473022 */, 83 -PRESHIFT(0x0001f000) /* -0.000473022 */,
84 PRESHIFT(0x000da000) /* 0.003326416 */, 84 PRESHIFT(0x000da000) /* 0.003326416 */,
85 -PRESHIFT(0x00207000) /* -0.007919312 */, 85 -PRESHIFT(0x00207000) /* -0.007919312 */,
86 PRESHIFT(0x007d0000) /* 0.030517578 */, 86 PRESHIFT(0x007d0000) /* 0.030517578 */,
87 -PRESHIFT(0x0158d000) /* -0.084182739 */, 87 -PRESHIFT(0x0158d000) /* -0.084182739 */,
88 PRESHIFT(0x01747000) /* 0.090927124 */, 88 PRESHIFT(0x01747000) /* 0.090927124 */,
89 -PRESHIFT(0x099a8000) /* -0.600219727 */, 89 -PRESHIFT(0x099a8000) /* -0.600219727 */,
90 PRESHIFT(0x124f0000) /* 1.144287109 */, 90 PRESHIFT(0x124f0000) /* 1.144287109 */,
91 PRESHIFT(0x08b38000) /* 0.543823242 */, 91 PRESHIFT(0x08b38000) /* 0.543823242 */,
92 PRESHIFT(0x01bde000) /* 0.108856201 */, 92 PRESHIFT(0x01bde000) /* 0.108856201 */,
93 PRESHIFT(0x012b4000) /* 0.073059082 */, 93 PRESHIFT(0x012b4000) /* 0.073059082 */,
94 PRESHIFT(0x0080f000) /* 0.031478882 */, 94 PRESHIFT(0x0080f000) /* 0.031478882 */,
95 PRESHIFT(0x00191000) /* 0.006118774 */, 95 PRESHIFT(0x00191000) /* 0.006118774 */,
96 PRESHIFT(0x000d0000) /* 0.003173828 */, 96 PRESHIFT(0x000d0000) /* 0.003173828 */,
97 PRESHIFT(0x0001a000) /* 0.000396729 */ }, 97 PRESHIFT(0x0001a000) /* 0.000396729 */ },
98 98
99 { -PRESHIFT(0x00001000) /* -0.000015259 */,/* 2 */ 99 { -PRESHIFT(0x00001000) /* -0.000015259 */,/* 2 */
100 -PRESHIFT(0x00023000) /* -0.000534058 */, 100 -PRESHIFT(0x00023000) /* -0.000534058 */,
101 PRESHIFT(0x000de000) /* 0.003387451 */, 101 PRESHIFT(0x000de000) /* 0.003387451 */,
102 -PRESHIFT(0x00245000) /* -0.008865356 */, 102 -PRESHIFT(0x00245000) /* -0.008865356 */,
103 PRESHIFT(0x007a0000) /* 0.029785156 */, 103 PRESHIFT(0x007a0000) /* 0.029785156 */,
104 -PRESHIFT(0x016f7000) /* -0.089706421 */, 104 -PRESHIFT(0x016f7000) /* -0.089706421 */,
105 PRESHIFT(0x014a8000) /* 0.080688477 */, 105 PRESHIFT(0x014a8000) /* 0.080688477 */,
106 -PRESHIFT(0x0a0d8000) /* -0.628295898 */, 106 -PRESHIFT(0x0a0d8000) /* -0.628295898 */,
107 PRESHIFT(0x12468000) /* 1.142211914 */, 107 PRESHIFT(0x12468000) /* 1.142211914 */,
108 PRESHIFT(0x083ff000) /* 0.515609741 */, 108 PRESHIFT(0x083ff000) /* 0.515609741 */,
109 PRESHIFT(0x01dd8000) /* 0.116577148 */, 109 PRESHIFT(0x01dd8000) /* 0.116577148 */,
110 PRESHIFT(0x01149000) /* 0.067520142 */, 110 PRESHIFT(0x01149000) /* 0.067520142 */,
111 PRESHIFT(0x00820000) /* 0.031738281 */, 111 PRESHIFT(0x00820000) /* 0.031738281 */,
112 PRESHIFT(0x0015b000) /* 0.005294800 */, 112 PRESHIFT(0x0015b000) /* 0.005294800 */,
113 PRESHIFT(0x000ca000) /* 0.003082275 */, 113 PRESHIFT(0x000ca000) /* 0.003082275 */,
114 PRESHIFT(0x00018000) /* 0.000366211 */, 114 PRESHIFT(0x00018000) /* 0.000366211 */,
115 115
116 -PRESHIFT(0x00001000) /* -0.000015259 */, 116 -PRESHIFT(0x00001000) /* -0.000015259 */,
117 -PRESHIFT(0x00023000) /* -0.000534058 */, 117 -PRESHIFT(0x00023000) /* -0.000534058 */,
118 PRESHIFT(0x000de000) /* 0.003387451 */, 118 PRESHIFT(0x000de000) /* 0.003387451 */,
119 -PRESHIFT(0x00245000) /* -0.008865356 */, 119 -PRESHIFT(0x00245000) /* -0.008865356 */,
120 PRESHIFT(0x007a0000) /* 0.029785156 */, 120 PRESHIFT(0x007a0000) /* 0.029785156 */,
121 -PRESHIFT(0x016f7000) /* -0.089706421 */, 121 -PRESHIFT(0x016f7000) /* -0.089706421 */,
122 PRESHIFT(0x014a8000) /* 0.080688477 */, 122 PRESHIFT(0x014a8000) /* 0.080688477 */,
123 -PRESHIFT(0x0a0d8000) /* -0.628295898 */, 123 -PRESHIFT(0x0a0d8000) /* -0.628295898 */,
124 PRESHIFT(0x12468000) /* 1.142211914 */, 124 PRESHIFT(0x12468000) /* 1.142211914 */,
125 PRESHIFT(0x083ff000) /* 0.515609741 */, 125 PRESHIFT(0x083ff000) /* 0.515609741 */,
126 PRESHIFT(0x01dd8000) /* 0.116577148 */, 126 PRESHIFT(0x01dd8000) /* 0.116577148 */,
127 PRESHIFT(0x01149000) /* 0.067520142 */, 127 PRESHIFT(0x01149000) /* 0.067520142 */,
128 PRESHIFT(0x00820000) /* 0.031738281 */, 128 PRESHIFT(0x00820000) /* 0.031738281 */,
129 PRESHIFT(0x0015b000) /* 0.005294800 */, 129 PRESHIFT(0x0015b000) /* 0.005294800 */,
130 PRESHIFT(0x000ca000) /* 0.003082275 */, 130 PRESHIFT(0x000ca000) /* 0.003082275 */,
131 PRESHIFT(0x00018000) /* 0.000366211 */ }, 131 PRESHIFT(0x00018000) /* 0.000366211 */ },
132 132
133 { -PRESHIFT(0x00001000) /* -0.000015259 */,/* 3 */ 133 { -PRESHIFT(0x00001000) /* -0.000015259 */,/* 3 */
134 -PRESHIFT(0x00026000) /* -0.000579834 */, 134 -PRESHIFT(0x00026000) /* -0.000579834 */,
135 PRESHIFT(0x000e1000) /* 0.003433228 */, 135 PRESHIFT(0x000e1000) /* 0.003433228 */,
136 -PRESHIFT(0x00285000) /* -0.009841919 */, 136 -PRESHIFT(0x00285000) /* -0.009841919 */,
137 PRESHIFT(0x00765000) /* 0.028884888 */, 137 PRESHIFT(0x00765000) /* 0.028884888 */,
138 -PRESHIFT(0x0185d000) /* -0.095169067 */, 138 -PRESHIFT(0x0185d000) /* -0.095169067 */,
139 PRESHIFT(0x011d1000) /* 0.069595337 */, 139 PRESHIFT(0x011d1000) /* 0.069595337 */,
140 -PRESHIFT(0x0a7fe000) /* -0.656219482 */, 140 -PRESHIFT(0x0a7fe000) /* -0.656219482 */,
141 PRESHIFT(0x12386000) /* 1.138763428 */, 141 PRESHIFT(0x12386000) /* 1.138763428 */,
142 PRESHIFT(0x07ccb000) /* 0.487472534 */, 142 PRESHIFT(0x07ccb000) /* 0.487472534 */,
143 PRESHIFT(0x01f9c000) /* 0.123474121 */, 143 PRESHIFT(0x01f9c000) /* 0.123474121 */,
144 PRESHIFT(0x00fdf000) /* 0.061996460 */, 144 PRESHIFT(0x00fdf000) /* 0.061996460 */,
145 PRESHIFT(0x00827000) /* 0.031845093 */, 145 PRESHIFT(0x00827000) /* 0.031845093 */,
146 PRESHIFT(0x00126000) /* 0.004486084 */, 146 PRESHIFT(0x00126000) /* 0.004486084 */,
147 PRESHIFT(0x000c4000) /* 0.002990723 */, 147 PRESHIFT(0x000c4000) /* 0.002990723 */,
148 PRESHIFT(0x00015000) /* 0.000320435 */, 148 PRESHIFT(0x00015000) /* 0.000320435 */,
149 149
150 -PRESHIFT(0x00001000) /* -0.000015259 */, 150 -PRESHIFT(0x00001000) /* -0.000015259 */,
151 -PRESHIFT(0x00026000) /* -0.000579834 */, 151 -PRESHIFT(0x00026000) /* -0.000579834 */,
152 PRESHIFT(0x000e1000) /* 0.003433228 */, 152 PRESHIFT(0x000e1000) /* 0.003433228 */,
153 -PRESHIFT(0x00285000) /* -0.009841919 */, 153 -PRESHIFT(0x00285000) /* -0.009841919 */,
154 PRESHIFT(0x00765000) /* 0.028884888 */, 154 PRESHIFT(0x00765000) /* 0.028884888 */,
155 -PRESHIFT(0x0185d000) /* -0.095169067 */, 155 -PRESHIFT(0x0185d000) /* -0.095169067 */,
156 PRESHIFT(0x011d1000) /* 0.069595337 */, 156 PRESHIFT(0x011d1000) /* 0.069595337 */,
157 -PRESHIFT(0x0a7fe000) /* -0.656219482 */, 157 -PRESHIFT(0x0a7fe000) /* -0.656219482 */,
158 PRESHIFT(0x12386000) /* 1.138763428 */, 158 PRESHIFT(0x12386000) /* 1.138763428 */,
159 PRESHIFT(0x07ccb000) /* 0.487472534 */, 159 PRESHIFT(0x07ccb000) /* 0.487472534 */,
160 PRESHIFT(0x01f9c000) /* 0.123474121 */, 160 PRESHIFT(0x01f9c000) /* 0.123474121 */,
161 PRESHIFT(0x00fdf000) /* 0.061996460 */, 161 PRESHIFT(0x00fdf000) /* 0.061996460 */,
162 PRESHIFT(0x00827000) /* 0.031845093 */, 162 PRESHIFT(0x00827000) /* 0.031845093 */,
163 PRESHIFT(0x00126000) /* 0.004486084 */, 163 PRESHIFT(0x00126000) /* 0.004486084 */,
164 PRESHIFT(0x000c4000) /* 0.002990723 */, 164 PRESHIFT(0x000c4000) /* 0.002990723 */,
165 PRESHIFT(0x00015000) /* 0.000320435 */ }, 165 PRESHIFT(0x00015000) /* 0.000320435 */ },
166 166
167 { -PRESHIFT(0x00001000) /* -0.000015259 */,/* 4 */ 167 { -PRESHIFT(0x00001000) /* -0.000015259 */,/* 4 */
168 -PRESHIFT(0x00029000) /* -0.000625610 */, 168 -PRESHIFT(0x00029000) /* -0.000625610 */,
169 PRESHIFT(0x000e3000) /* 0.003463745 */, 169 PRESHIFT(0x000e3000) /* 0.003463745 */,
170 -PRESHIFT(0x002c7000) /* -0.010848999 */, 170 -PRESHIFT(0x002c7000) /* -0.010848999 */,
171 PRESHIFT(0x0071e000) /* 0.027801514 */, 171 PRESHIFT(0x0071e000) /* 0.027801514 */,
172 -PRESHIFT(0x019bd000) /* -0.100540161 */, 172 -PRESHIFT(0x019bd000) /* -0.100540161 */,
173 PRESHIFT(0x00ec0000) /* 0.057617187 */, 173 PRESHIFT(0x00ec0000) /* 0.057617187 */,
174 -PRESHIFT(0x0af15000) /* -0.683914185 */, 174 -PRESHIFT(0x0af15000) /* -0.683914185 */,
175 PRESHIFT(0x12249000) /* 1.133926392 */, 175 PRESHIFT(0x12249000) /* 1.133926392 */,
176 PRESHIFT(0x075a0000) /* 0.459472656 */, 176 PRESHIFT(0x075a0000) /* 0.459472656 */,
177 PRESHIFT(0x0212c000) /* 0.129577637 */, 177 PRESHIFT(0x0212c000) /* 0.129577637 */,
178 PRESHIFT(0x00e79000) /* 0.056533813 */, 178 PRESHIFT(0x00e79000) /* 0.056533813 */,
179 PRESHIFT(0x00825000) /* 0.031814575 */, 179 PRESHIFT(0x00825000) /* 0.031814575 */,
180 PRESHIFT(0x000f4000) /* 0.003723145 */, 180 PRESHIFT(0x000f4000) /* 0.003723145 */,
181 PRESHIFT(0x000be000) /* 0.002899170 */, 181 PRESHIFT(0x000be000) /* 0.002899170 */,
182 PRESHIFT(0x00013000) /* 0.000289917 */, 182 PRESHIFT(0x00013000) /* 0.000289917 */,
183 183
184 -PRESHIFT(0x00001000) /* -0.000015259 */, 184 -PRESHIFT(0x00001000) /* -0.000015259 */,
185 -PRESHIFT(0x00029000) /* -0.000625610 */, 185 -PRESHIFT(0x00029000) /* -0.000625610 */,
186 PRESHIFT(0x000e3000) /* 0.003463745 */, 186 PRESHIFT(0x000e3000) /* 0.003463745 */,
187 -PRESHIFT(0x002c7000) /* -0.010848999 */, 187 -PRESHIFT(0x002c7000) /* -0.010848999 */,
188 PRESHIFT(0x0071e000) /* 0.027801514 */, 188 PRESHIFT(0x0071e000) /* 0.027801514 */,
189 -PRESHIFT(0x019bd000) /* -0.100540161 */, 189 -PRESHIFT(0x019bd000) /* -0.100540161 */,
190 PRESHIFT(0x00ec0000) /* 0.057617187 */, 190 PRESHIFT(0x00ec0000) /* 0.057617187 */,
191 -PRESHIFT(0x0af15000) /* -0.683914185 */, 191 -PRESHIFT(0x0af15000) /* -0.683914185 */,
192 PRESHIFT(0x12249000) /* 1.133926392 */, 192 PRESHIFT(0x12249000) /* 1.133926392 */,
193 PRESHIFT(0x075a0000) /* 0.459472656 */, 193 PRESHIFT(0x075a0000) /* 0.459472656 */,
194 PRESHIFT(0x0212c000) /* 0.129577637 */, 194 PRESHIFT(0x0212c000) /* 0.129577637 */,
diff --git a/core/multimedia/opieplayer/libmad/bit.c b/core/multimedia/opieplayer/libmad/bit.c
index 2466c5f..4a4661b 100644
--- a/core/multimedia/opieplayer/libmad/bit.c
+++ b/core/multimedia/opieplayer/libmad/bit.c
@@ -1,220 +1,237 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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
28# ifdef HAVE_LIMITS_H 28# ifdef HAVE_LIMITS_H
29# include <limits.h> 29# include <limits.h>
30# else 30# else
31# define CHAR_BIT 8 31# define CHAR_BIT 8
32# endif 32# endif
33 33
34# include "bit.h" 34# include "bit.h"
35 35
36/* 36/*
37 * This is the lookup table for computing the CRC-check word. 37 * This is the lookup table for computing the CRC-check word.
38 * As described in section 2.4.3.1 and depicted in Figure A.9 38 * As described in section 2.4.3.1 and depicted in Figure A.9
39 * of ISO/IEC 11172-3, the generator polynomial is: 39 * of ISO/IEC 11172-3, the generator polynomial is:
40 * 40 *
41 * G(X) = X^16 + X^15 + X^2 + 1 41 * G(X) = X^16 + X^15 + X^2 + 1
42 */ 42 */
43static 43static
44unsigned short const crc_table[256] = { 44unsigned short const crc_table[256] = {
45 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011, 45 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
46 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022, 46 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
47 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072, 47 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
48 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041, 48 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
49 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2, 49 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
50 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1, 50 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
51 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1, 51 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
52 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082, 52 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
53 53
54 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192, 54 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
55 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1, 55 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
56 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1, 56 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
57 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2, 57 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
58 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151, 58 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
59 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162, 59 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
60 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132, 60 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
61 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101, 61 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
62 62
63 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312, 63 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
64 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321, 64 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
65 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371, 65 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
66 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342, 66 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
67 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1, 67 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
68 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2, 68 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
69 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2, 69 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
70 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381, 70 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
71 71
72 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291, 72 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
73 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2, 73 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
74 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2, 74 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
75 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1, 75 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
76 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252, 76 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
77 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261, 77 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
78 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231, 78 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
79 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202 79 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
80}; 80};
81 81
82# define CRC_POLY 0x8005 82# define CRC_POLY 0x8005
83 83
84/* 84/*
85 * NAME:bit->init() 85 * NAME:bit->init()
86 * DESCRIPTION:initialize bit pointer struct 86 * DESCRIPTION:initialize bit pointer struct
87 */ 87 */
88void mad_bit_init(struct mad_bitptr *bitptr, unsigned char const *byte) 88void mad_bit_init(struct mad_bitptr *bitptr, unsigned char const *byte)
89{ 89{
90 bitptr->byte = byte; 90 bitptr->byte = byte;
91 bitptr->cache = 0; 91 bitptr->cache = 0;
92 bitptr->left = CHAR_BIT; 92 bitptr->left = CHAR_BIT;
93} 93}
94 94
95/* 95/*
96 * NAME:bit->length() 96 * NAME:bit->length()
97 * DESCRIPTION:return number of bits between start and end points 97 * DESCRIPTION:return number of bits between start and end points
98 */ 98 */
99unsigned int mad_bit_length(struct mad_bitptr const *begin, 99unsigned int mad_bit_length(struct mad_bitptr const *begin,
100 struct mad_bitptr const *end) 100 struct mad_bitptr const *end)
101{ 101{
102 return begin->left + 102 return begin->left +
103 CHAR_BIT * (end->byte - (begin->byte + 1)) + (CHAR_BIT - end->left); 103 CHAR_BIT * (end->byte - (begin->byte + 1)) + (CHAR_BIT - end->left);
104} 104}
105 105
106/* 106/*
107 * NAME:bit->nextbyte() 107 * NAME:bit->nextbyte()
108 * DESCRIPTION:return pointer to next unprocessed byte 108 * DESCRIPTION:return pointer to next unprocessed byte
109 */ 109 */
110unsigned char const *mad_bit_nextbyte(struct mad_bitptr const *bitptr) 110unsigned char const *mad_bit_nextbyte(struct mad_bitptr const *bitptr)
111{ 111{
112 return bitptr->left == CHAR_BIT ? bitptr->byte : bitptr->byte + 1; 112 return bitptr->left == CHAR_BIT ? bitptr->byte : bitptr->byte + 1;
113} 113}
114 114
115/* 115/*
116 * NAME:bit->skip() 116 * NAME:bit->skip()
117 * DESCRIPTION:advance bit pointer 117 * DESCRIPTION:advance bit pointer
118 */ 118 */
119void mad_bit_skip(struct mad_bitptr *bitptr, unsigned int len) 119void mad_bit_skip(struct mad_bitptr *bitptr, unsigned int len)
120{ 120{
121 bitptr->byte += len / CHAR_BIT; 121 bitptr->byte += len / CHAR_BIT;
122 bitptr->left -= len % CHAR_BIT; 122 bitptr->left -= len % CHAR_BIT;
123 123
124 if (bitptr->left > CHAR_BIT) { 124 if (bitptr->left > CHAR_BIT) {
125 bitptr->byte++; 125 bitptr->byte++;
126 bitptr->left += CHAR_BIT; 126 bitptr->left += CHAR_BIT;
127 } 127 }
128 128
129 if (bitptr->left < CHAR_BIT) 129 if (bitptr->left < CHAR_BIT)
130 bitptr->cache = *bitptr->byte; 130 bitptr->cache = *bitptr->byte;
131} 131}
132 132
133/* 133/*
134 * NAME:bit->read() 134 * NAME:bit->read()
135 * DESCRIPTION:read an arbitrary number of bits and return their UIMSBF value 135 * DESCRIPTION:read an arbitrary number of bits and return their UIMSBF value
136 */ 136 */
137unsigned long mad_bit_read(struct mad_bitptr *bitptr, unsigned int len) 137unsigned long mad_bit_read(struct mad_bitptr *bitptr, unsigned int len)
138{ 138{
139 register unsigned long value; 139 register unsigned long value;
140 140
141 if (bitptr->left == CHAR_BIT) 141 if (bitptr->left == CHAR_BIT)
142 bitptr->cache = *bitptr->byte; 142 bitptr->cache = *bitptr->byte;
143 143
144 if (len < bitptr->left) { 144 if (len < bitptr->left) {
145 value = (bitptr->cache & ((1 << bitptr->left) - 1)) >> 145 value = (bitptr->cache & ((1 << bitptr->left) - 1)) >>
146 (bitptr->left - len); 146 (bitptr->left - len);
147 bitptr->left -= len; 147 bitptr->left -= len;
148 148
149 return value; 149 return value;
150 } 150 }
151 151
152 /* remaining bits in current byte */ 152 /* remaining bits in current byte */
153 153
154 value = bitptr->cache & ((1 << bitptr->left) - 1); 154 value = bitptr->cache & ((1 << bitptr->left) - 1);
155 len -= bitptr->left; 155 len -= bitptr->left;
156 156
157 bitptr->byte++; 157 bitptr->byte++;
158 bitptr->left = CHAR_BIT; 158 bitptr->left = CHAR_BIT;
159 159
160 /* more bytes */ 160 /* more bytes */
161 161
162 while (len >= CHAR_BIT) { 162 while (len >= CHAR_BIT) {
163 value = (value << CHAR_BIT) | *bitptr->byte++; 163 value = (value << CHAR_BIT) | *bitptr->byte++;
164 len -= CHAR_BIT; 164 len -= CHAR_BIT;
165 } 165 }
166 166
167 if (len > 0) { 167 if (len > 0) {
168 bitptr->cache = *bitptr->byte; 168 bitptr->cache = *bitptr->byte;
169 169
170 value = (value << len) | (bitptr->cache >> (CHAR_BIT - len)); 170 value = (value << len) | (bitptr->cache >> (CHAR_BIT - len));
171 bitptr->left -= len; 171 bitptr->left -= len;
172 } 172 }
173 173
174 return value; 174 return value;
175} 175}
176 176
177# if 0 177# if 0
178/* 178/*
179 * NAME:bit->write() 179 * NAME:bit->write()
180 * DESCRIPTION:write an arbitrary number of bits 180 * DESCRIPTION:write an arbitrary number of bits
181 */ 181 */
182void mad_bit_write(struct mad_bitptr *bitptr, unsigned int len, 182void mad_bit_write(struct mad_bitptr *bitptr, unsigned int len,
183 unsigned long value) 183 unsigned long value)
184{ 184{
185 unsigned char *ptr; 185 unsigned char *ptr;
186 186
187 ptr = (unsigned char *) bitptr->byte; 187 ptr = (unsigned char *) bitptr->byte;
188 188
189 /* ... */ 189 /* ... */
190} 190}
191# endif 191# endif
192 192
193/* 193/*
194 * NAME:bit->crc() 194 * NAME:bit->crc()
195 * DESCRIPTION:compute CRC-check word 195 * DESCRIPTION:compute CRC-check word
196 */ 196 */
197unsigned short mad_bit_crc(struct mad_bitptr bitptr, unsigned int len, 197unsigned short mad_bit_crc(struct mad_bitptr bitptr, unsigned int len,
198 unsigned short init) 198 unsigned short init)
199{ 199{
200 register unsigned int crc, data; 200 register unsigned int crc;
201 201
202# if CHAR_BIT == 8 202 for (crc = init; len >= 32; len -= 32) {
203 for (crc = init; len >= 8; len -= 8) { 203 register unsigned long data;
204 crc = (crc << 8) ^ 204
205 crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff]; 205 data = mad_bit_read(&bitptr, 32);
206
207 crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 24)) & 0xff];
208 crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 16)) & 0xff];
209 crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 8)) & 0xff];
210 crc = (crc << 8) ^ crc_table[((crc >> 8) ^ (data >> 0)) & 0xff];
211 }
212
213 switch (len / 8) {
214 case 3: crc = (crc << 8) ^
215 crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
216 case 2: crc = (crc << 8) ^
217 crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
218 case 1: crc = (crc << 8) ^
219 crc_table[((crc >> 8) ^ mad_bit_read(&bitptr, 8)) & 0xff];
220
221 len %= 8;
222
223 case 0: break;
206 } 224 }
207# else
208 crc = init;
209# endif
210 225
211 while (len--) { 226 while (len--) {
212 data = mad_bit_read(&bitptr, 1) ^ (crc >> 15); 227 register unsigned int msb;
228
229 msb = mad_bit_read(&bitptr, 1) ^ (crc >> 15);
213 230
214 crc <<= 1; 231 crc <<= 1;
215 if (data & 1) 232 if (msb & 1)
216 crc ^= CRC_POLY; 233 crc ^= CRC_POLY;
217 } 234 }
218 235
219 return crc & 0xffff; 236 return crc & 0xffff;
220} 237}
diff --git a/core/multimedia/opieplayer/libmad/bit.h b/core/multimedia/opieplayer/libmad/bit.h
index f315bc9..3448d40 100644
--- a/core/multimedia/opieplayer/libmad/bit.h
+++ b/core/multimedia/opieplayer/libmad/bit.h
@@ -1,47 +1,47 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# ifndef LIBMAD_BIT_H 22# ifndef LIBMAD_BIT_H
23# define LIBMAD_BIT_H 23# define LIBMAD_BIT_H
24 24
25struct mad_bitptr { 25struct mad_bitptr {
26 unsigned char const *byte; 26 unsigned char const *byte;
27 unsigned short cache; 27 unsigned short cache;
28 unsigned short left; 28 unsigned short left;
29}; 29};
30 30
31void mad_bit_init(struct mad_bitptr *, unsigned char const *); 31void mad_bit_init(struct mad_bitptr *, unsigned char const *);
32 32
33 # define mad_bit_finish(bitptr) /* nothing */ 33 # define mad_bit_finish(bitptr) /* nothing */
34 34
35unsigned int mad_bit_length(struct mad_bitptr const *, 35unsigned int mad_bit_length(struct mad_bitptr const *,
36 struct mad_bitptr const *); 36 struct mad_bitptr const *);
37 37
38# define mad_bit_bitsleft(bitptr) ((bitptr)->left) 38# define mad_bit_bitsleft(bitptr) ((bitptr)->left)
39unsigned char const *mad_bit_nextbyte(struct mad_bitptr const *); 39unsigned char const *mad_bit_nextbyte(struct mad_bitptr const *);
40 40
41void mad_bit_skip(struct mad_bitptr *, unsigned int); 41void mad_bit_skip(struct mad_bitptr *, unsigned int);
42unsigned long mad_bit_read(struct mad_bitptr *, unsigned int); 42unsigned long mad_bit_read(struct mad_bitptr *, unsigned int);
43void mad_bit_write(struct mad_bitptr *, unsigned int, unsigned long); 43void mad_bit_write(struct mad_bitptr *, unsigned int, unsigned long);
44 44
45unsigned short mad_bit_crc(struct mad_bitptr, unsigned int, unsigned short); 45unsigned short mad_bit_crc(struct mad_bitptr, unsigned int, unsigned short);
46 46
47# endif 47# endif
diff --git a/core/multimedia/opieplayer/libmad/decoder.c b/core/multimedia/opieplayer/libmad/decoder.c
index dcf7cf3..b2b6cbb 100644
--- a/core/multimedia/opieplayer/libmad/decoder.c
+++ b/core/multimedia/opieplayer/libmad/decoder.c
@@ -1,554 +1,570 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# else
25# ifndef WEXITSTATUS
26# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
27# endif
28# ifndef WIFEXITED
29# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
30# endif
31# endif 24# endif
32 25
33# include "libmad_global.h" 26# include "libmad_global.h"
34 27
35# include <sys/types.h> 28# ifdef HAVE_SYS_TYPES_H
29# include <sys/types.h>
30# endif
36 31
37# ifdef HAVE_SYS_WAIT_H 32# ifdef HAVE_SYS_WAIT_H
38# include <sys/wait.h> 33# include <sys/wait.h>
39# endif 34# endif
40 35
41# ifdef HAVE_UNISTD_H 36# ifdef HAVE_UNISTD_H
42# include <unistd.h> 37# include <unistd.h>
43# endif 38# endif
44 39
45# include <fcntl.h> 40# ifdef HAVE_FCNTL_H
41# include <fcntl.h>
42# endif
43
46# include <stdlib.h> 44# include <stdlib.h>
47# include <errno.h> 45
46# ifdef HAVE_ERRNO_H
47# include <errno.h>
48# endif
48 49
49# include "stream.h" 50# include "stream.h"
50# include "frame.h" 51# include "frame.h"
51# include "synth.h" 52# include "synth.h"
52# include "decoder.h" 53# include "decoder.h"
53 54
54void mad_decoder_init(struct mad_decoder *decoder, void *data, 55void mad_decoder_init(struct mad_decoder *decoder, void *data,
55 enum mad_flow (*input_func)(void *, struct mad_stream *), 56 enum mad_flow (*input_func)(void *,
57 struct mad_stream *),
56 enum mad_flow (*header_func)(void *, 58 enum mad_flow (*header_func)(void *,
57 struct mad_header const *), 59 struct mad_header const *),
58 enum mad_flow (*filter_func)(void *, struct mad_frame *), 60 enum mad_flow (*filter_func)(void *,
61 struct mad_stream const *,
62 struct mad_frame *),
59 enum mad_flow (*output_func)(void *, 63 enum mad_flow (*output_func)(void *,
60 struct mad_header const *, 64 struct mad_header const *,
61 struct mad_pcm *), 65 struct mad_pcm *),
62 enum mad_flow (*error_func)(void *, struct mad_stream *, 66 enum mad_flow (*error_func)(void *,
67 struct mad_stream *,
63 struct mad_frame *), 68 struct mad_frame *),
64 enum mad_flow (*message_func)(void *, 69 enum mad_flow (*message_func)(void *,
65 void *, unsigned int *)) 70 void *, unsigned int *))
66{ 71{
67 decoder->mode = -1; 72 decoder->mode = -1;
68 73
69 decoder->options = 0; 74 decoder->options = 0;
70 75
71 decoder->async.pid = 0; 76 decoder->async.pid = 0;
72 decoder->async.in = -1; 77 decoder->async.in = -1;
73 decoder->async.out = -1; 78 decoder->async.out = -1;
74 79
75 decoder->sync = 0; 80 decoder->sync = 0;
76 81
77 decoder->cb_data = data; 82 decoder->cb_data = data;
78 83
79 decoder->input_func = input_func; 84 decoder->input_func = input_func;
80 decoder->header_func = header_func; 85 decoder->header_func = header_func;
81 decoder->filter_func = filter_func; 86 decoder->filter_func = filter_func;
82 decoder->output_func = output_func; 87 decoder->output_func = output_func;
83 decoder->error_func = error_func; 88 decoder->error_func = error_func;
84 decoder->message_func = message_func; 89 decoder->message_func = message_func;
85} 90}
86 91
87int mad_decoder_finish(struct mad_decoder *decoder) 92int mad_decoder_finish(struct mad_decoder *decoder)
88{ 93{
94# if defined(USE_ASYNC)
89 if (decoder->mode == MAD_DECODER_MODE_ASYNC && decoder->async.pid) { 95 if (decoder->mode == MAD_DECODER_MODE_ASYNC && decoder->async.pid) {
90 pid_t pid; 96 pid_t pid;
91 int status; 97 int status;
92 98
93 close(decoder->async.in); 99 close(decoder->async.in);
94 100
95 do { 101 do
96 pid = waitpid(decoder->async.pid, &status, 0); 102 pid = waitpid(decoder->async.pid, &status, 0);
97 }
98 while (pid == -1 && errno == EINTR); 103 while (pid == -1 && errno == EINTR);
99 104
100 decoder->mode = -1; 105 decoder->mode = -1;
101 106
102 close(decoder->async.out); 107 close(decoder->async.out);
103 108
104 decoder->async.pid = 0; 109 decoder->async.pid = 0;
105 decoder->async.in = -1; 110 decoder->async.in = -1;
106 decoder->async.out = -1; 111 decoder->async.out = -1;
107 112
108 if (pid == -1) 113 if (pid == -1)
109 return -1; 114 return -1;
110 115
111 return (!WIFEXITED(status) || WEXITSTATUS(status)) ? -1 : 0; 116 return (!WIFEXITED(status) || WEXITSTATUS(status)) ? -1 : 0;
112 } 117 }
118# endif
113 119
114 return 0; 120 return 0;
115} 121}
116 122
123# if defined(USE_ASYNC)
117static 124static
118enum mad_flow send_io(int fd, void const *data, size_t len) 125enum mad_flow send_io(int fd, void const *data, size_t len)
119{ 126{
120 char const *ptr = data; 127 char const *ptr = data;
121 ssize_t count; 128 ssize_t count;
122 129
123 while (len) { 130 while (len) {
124 do { 131 do
125 count = write(fd, ptr, len); 132 count = write(fd, ptr, len);
126 }
127 while (count == -1 && errno == EINTR); 133 while (count == -1 && errno == EINTR);
128 134
129 if (count == -1) 135 if (count == -1)
130 return MAD_FLOW_BREAK; 136 return MAD_FLOW_BREAK;
131 137
132 len -= count; 138 len -= count;
133 ptr += count; 139 ptr += count;
134 } 140 }
135 141
136 return MAD_FLOW_CONTINUE; 142 return MAD_FLOW_CONTINUE;
137} 143}
138 144
139static 145static
140enum mad_flow receive_io(int fd, void *buffer, size_t len) 146enum mad_flow receive_io(int fd, void *buffer, size_t len)
141{ 147{
142 char *ptr = buffer; 148 char *ptr = buffer;
143 ssize_t count; 149 ssize_t count;
144 150
145 while (len) { 151 while (len) {
146 do { 152 do
147 count = read(fd, ptr, len); 153 count = read(fd, ptr, len);
148 }
149 while (count == -1 && errno == EINTR); 154 while (count == -1 && errno == EINTR);
150 155
151 if (count == -1) 156 if (count == -1)
152 return (errno == EAGAIN) ? MAD_FLOW_IGNORE : MAD_FLOW_BREAK; 157 return (errno == EAGAIN) ? MAD_FLOW_IGNORE : MAD_FLOW_BREAK;
153 else if (count == 0) 158 else if (count == 0)
154 return MAD_FLOW_STOP; 159 return MAD_FLOW_STOP;
155 160
156 len -= count; 161 len -= count;
157 ptr += count; 162 ptr += count;
158 } 163 }
159 164
160 return MAD_FLOW_CONTINUE; 165 return MAD_FLOW_CONTINUE;
161} 166}
162 167
163static 168static
164enum mad_flow receive_io_blocking(int fd, void *buffer, size_t len) 169enum mad_flow receive_io_blocking(int fd, void *buffer, size_t len)
165{ 170{
166 int flags, blocking; 171 int flags, blocking;
167 enum mad_flow result; 172 enum mad_flow result;
168 173
169 flags = fcntl(fd, F_GETFL); 174 flags = fcntl(fd, F_GETFL);
170 if (flags == -1) 175 if (flags == -1)
171 return MAD_FLOW_BREAK; 176 return MAD_FLOW_BREAK;
172 177
173 blocking = flags & ~O_NONBLOCK; 178 blocking = flags & ~O_NONBLOCK;
174 179
175 if (blocking != flags && 180 if (blocking != flags &&
176 fcntl(fd, F_SETFL, blocking) == -1) 181 fcntl(fd, F_SETFL, blocking) == -1)
177 return MAD_FLOW_BREAK; 182 return MAD_FLOW_BREAK;
178 183
179 result = receive_io(fd, buffer, len); 184 result = receive_io(fd, buffer, len);
180 185
181 if (flags != blocking && 186 if (flags != blocking &&
182 fcntl(fd, F_SETFL, flags) == -1) 187 fcntl(fd, F_SETFL, flags) == -1)
183 return MAD_FLOW_BREAK; 188 return MAD_FLOW_BREAK;
184 189
185 return result; 190 return result;
186} 191}
187 192
188static 193static
189enum mad_flow send(int fd, void const *message, unsigned int size) 194enum mad_flow send(int fd, void const *message, unsigned int size)
190{ 195{
191 enum mad_flow result; 196 enum mad_flow result;
192 197
193 /* send size */ 198 /* send size */
194 199
195 result = send_io(fd, &size, sizeof(size)); 200 result = send_io(fd, &size, sizeof(size));
196 201
197 /* send message */ 202 /* send message */
198 203
199 if (result == MAD_FLOW_CONTINUE) 204 if (result == MAD_FLOW_CONTINUE)
200 result = send_io(fd, message, size); 205 result = send_io(fd, message, size);
201 206
202 return result; 207 return result;
203} 208}
204 209
205static 210static
206enum mad_flow receive(int fd, void **message, unsigned int *size) 211enum mad_flow receive(int fd, void **message, unsigned int *size)
207{ 212{
208 enum mad_flow result; 213 enum mad_flow result;
209 unsigned int actual; 214 unsigned int actual;
210 215
211 if (*message == 0) 216 if (*message == 0)
212 *size = 0; 217 *size = 0;
213 218
214 /* receive size */ 219 /* receive size */
215 220
216 result = receive_io(fd, &actual, sizeof(actual)); 221 result = receive_io(fd, &actual, sizeof(actual));
217 222
218 /* receive message */ 223 /* receive message */
219 224
220 if (result == MAD_FLOW_CONTINUE) { 225 if (result == MAD_FLOW_CONTINUE) {
221 if (actual > *size) 226 if (actual > *size)
222 actual -= *size; 227 actual -= *size;
223 else { 228 else {
224 *size = actual; 229 *size = actual;
225 actual = 0; 230 actual = 0;
226 } 231 }
227 232
228 if (*size > 0) { 233 if (*size > 0) {
229 if (*message == 0) { 234 if (*message == 0) {
230 *message = malloc(*size); 235 *message = malloc(*size);
231 if (*message == 0) 236 if (*message == 0)
232 return MAD_FLOW_BREAK; 237 return MAD_FLOW_BREAK;
233 } 238 }
234 239
235 result = receive_io_blocking(fd, *message, *size); 240 result = receive_io_blocking(fd, *message, *size);
236 } 241 }
237 242
238 /* throw away remainder of message */ 243 /* throw away remainder of message */
239 244
240 while (actual && result == MAD_FLOW_CONTINUE) { 245 while (actual && result == MAD_FLOW_CONTINUE) {
241 char sink[256]; 246 char sink[256];
242 unsigned int len; 247 unsigned int len;
243 248
244 len = actual > sizeof(sink) ? sizeof(sink) : actual; 249 len = actual > sizeof(sink) ? sizeof(sink) : actual;
245 250
246 result = receive_io_blocking(fd, sink, len); 251 result = receive_io_blocking(fd, sink, len);
247 252
248 actual -= len; 253 actual -= len;
249 } 254 }
250 } 255 }
251 256
252 return result; 257 return result;
253} 258}
254 259
255static 260static
256enum mad_flow check_message(struct mad_decoder *decoder) 261enum mad_flow check_message(struct mad_decoder *decoder)
257{ 262{
258 enum mad_flow result; 263 enum mad_flow result;
259 void *message = 0; 264 void *message = 0;
260 unsigned int size; 265 unsigned int size;
261 266
262 result = receive(decoder->async.in, &message, &size); 267 result = receive(decoder->async.in, &message, &size);
263 268
264 if (result == MAD_FLOW_CONTINUE) { 269 if (result == MAD_FLOW_CONTINUE) {
265 if (decoder->message_func == 0) 270 if (decoder->message_func == 0)
266 size = 0; 271 size = 0;
267 else { 272 else {
268 result = decoder->message_func(decoder->cb_data, message, &size); 273 result = decoder->message_func(decoder->cb_data, message, &size);
269 274
270 if (result == MAD_FLOW_IGNORE || 275 if (result == MAD_FLOW_IGNORE ||
271 result == MAD_FLOW_BREAK) 276 result == MAD_FLOW_BREAK)
272 size = 0; 277 size = 0;
273 } 278 }
274 279
275 if (send(decoder->async.out, message, size) != MAD_FLOW_CONTINUE) 280 if (send(decoder->async.out, message, size) != MAD_FLOW_CONTINUE)
276 result = MAD_FLOW_BREAK; 281 result = MAD_FLOW_BREAK;
277 } 282 }
278 283
279 if (message) 284 if (message)
280 free(message); 285 free(message);
281 286
282 return result; 287 return result;
283} 288}
289# endif
284 290
285static 291static
286enum mad_flow error_default(void *data, struct mad_stream *stream, 292enum mad_flow error_default(void *data, struct mad_stream *stream,
287 struct mad_frame *frame) 293 struct mad_frame *frame)
288{ 294{
289 int *bad_last_frame = data; 295 int *bad_last_frame = data;
290 296
291 switch (stream->error) { 297 switch (stream->error) {
292 case MAD_ERROR_BADCRC: 298 case MAD_ERROR_BADCRC:
293 if (*bad_last_frame) 299 if (*bad_last_frame)
294 mad_frame_mute(frame); 300 mad_frame_mute(frame);
295 else 301 else
296 *bad_last_frame = 1; 302 *bad_last_frame = 1;
297 303
298 return MAD_FLOW_IGNORE; 304 return MAD_FLOW_IGNORE;
299 305
300 default: 306 default:
301 return MAD_FLOW_CONTINUE; 307 return MAD_FLOW_CONTINUE;
302 } 308 }
303} 309}
304 310
305static 311static
306int run_sync(struct mad_decoder *decoder) 312int run_sync(struct mad_decoder *decoder)
307{ 313{
308 enum mad_flow (*error_func)(void *, struct mad_stream *, struct mad_frame *); 314 enum mad_flow (*error_func)(void *, struct mad_stream *, struct mad_frame *);
309 void *error_data; 315 void *error_data;
310 int bad_last_frame = 0; 316 int bad_last_frame = 0;
311 struct mad_stream *stream; 317 struct mad_stream *stream;
312 struct mad_frame *frame; 318 struct mad_frame *frame;
313 struct mad_synth *synth; 319 struct mad_synth *synth;
314 int result = 0; 320 int result = 0;
315 321
316 if (decoder->input_func == 0) 322 if (decoder->input_func == 0)
317 return 0; 323 return 0;
318 324
319 if (decoder->error_func) { 325 if (decoder->error_func) {
320 error_func = decoder->error_func; 326 error_func = decoder->error_func;
321 error_data = decoder->cb_data; 327 error_data = decoder->cb_data;
322 } 328 }
323 else { 329 else {
324 error_func = error_default; 330 error_func = error_default;
325 error_data = &bad_last_frame; 331 error_data = &bad_last_frame;
326 } 332 }
327 333
328 stream = &decoder->sync->stream; 334 stream = &decoder->sync->stream;
329 frame = &decoder->sync->frame; 335 frame = &decoder->sync->frame;
330 synth = &decoder->sync->synth; 336 synth = &decoder->sync->synth;
331 337
332 mad_stream_init(stream); 338 mad_stream_init(stream);
333 mad_frame_init(frame); 339 mad_frame_init(frame);
334 mad_synth_init(synth); 340 mad_synth_init(synth);
335 341
336 mad_stream_options(stream, decoder->options); 342 mad_stream_options(stream, decoder->options);
337 343
338 do { 344 do {
339 switch (decoder->input_func(decoder->cb_data, stream)) { 345 switch (decoder->input_func(decoder->cb_data, stream)) {
340 case MAD_FLOW_STOP: 346 case MAD_FLOW_STOP:
341 goto done; 347 goto done;
342 case MAD_FLOW_BREAK: 348 case MAD_FLOW_BREAK:
343 goto fail; 349 goto fail;
344 case MAD_FLOW_IGNORE: 350 case MAD_FLOW_IGNORE:
345 continue; 351 continue;
346 case MAD_FLOW_CONTINUE: 352 case MAD_FLOW_CONTINUE:
347 break; 353 break;
348 } 354 }
349 355
350 while (1) { 356 while (1) {
357# if defined(USE_ASYNC)
351 if (decoder->mode == MAD_DECODER_MODE_ASYNC) { 358 if (decoder->mode == MAD_DECODER_MODE_ASYNC) {
352 switch (check_message(decoder)) { 359 switch (check_message(decoder)) {
353 case MAD_FLOW_IGNORE: 360 case MAD_FLOW_IGNORE:
354 case MAD_FLOW_CONTINUE: 361 case MAD_FLOW_CONTINUE:
355 break; 362 break;
356 case MAD_FLOW_BREAK: 363 case MAD_FLOW_BREAK:
357 goto fail; 364 goto fail;
358 case MAD_FLOW_STOP: 365 case MAD_FLOW_STOP:
359 goto done; 366 goto done;
360 } 367 }
361 } 368 }
369# endif
362 370
363 if (decoder->header_func) { 371 if (decoder->header_func) {
364 if (mad_header_decode(&frame->header, stream) == -1) { 372 if (mad_header_decode(&frame->header, stream) == -1) {
365 if (!MAD_RECOVERABLE(stream->error)) 373 if (!MAD_RECOVERABLE(stream->error))
366 break; 374 break;
367 375
368 switch (error_func(error_data, stream, frame)) { 376 switch (error_func(error_data, stream, frame)) {
369 case MAD_FLOW_STOP: 377 case MAD_FLOW_STOP:
370 goto done; 378 goto done;
371 case MAD_FLOW_BREAK: 379 case MAD_FLOW_BREAK:
372 goto fail; 380 goto fail;
373 case MAD_FLOW_IGNORE: 381 case MAD_FLOW_IGNORE:
374 case MAD_FLOW_CONTINUE: 382 case MAD_FLOW_CONTINUE:
375 default: 383 default:
376 continue; 384 continue;
377 } 385 }
378 } 386 }
379 387
380 switch (decoder->header_func(decoder->cb_data, &frame->header)) { 388 switch (decoder->header_func(decoder->cb_data, &frame->header)) {
381 case MAD_FLOW_STOP: 389 case MAD_FLOW_STOP:
382 goto done; 390 goto done;
383 case MAD_FLOW_BREAK: 391 case MAD_FLOW_BREAK:
384 goto fail; 392 goto fail;
385 case MAD_FLOW_IGNORE: 393 case MAD_FLOW_IGNORE:
386 continue; 394 continue;
387 case MAD_FLOW_CONTINUE: 395 case MAD_FLOW_CONTINUE:
388 break; 396 break;
389 } 397 }
390 } 398 }
391 399
392 if (mad_frame_decode(frame, stream) == -1) { 400 if (mad_frame_decode(frame, stream) == -1) {
393 if (!MAD_RECOVERABLE(stream->error)) 401 if (!MAD_RECOVERABLE(stream->error))
394 break; 402 break;
395 403
396 switch (error_func(error_data, stream, frame)) { 404 switch (error_func(error_data, stream, frame)) {
397 case MAD_FLOW_STOP: 405 case MAD_FLOW_STOP:
398 goto done; 406 goto done;
399 case MAD_FLOW_BREAK: 407 case MAD_FLOW_BREAK:
400 goto fail; 408 goto fail;
401 case MAD_FLOW_IGNORE: 409 case MAD_FLOW_IGNORE:
402 break; 410 break;
403 case MAD_FLOW_CONTINUE: 411 case MAD_FLOW_CONTINUE:
404 default: 412 default:
405 continue; 413 continue;
406 } 414 }
407 } 415 }
408 else 416 else
409 bad_last_frame = 0; 417 bad_last_frame = 0;
410 418
411 if (decoder->filter_func) { 419 if (decoder->filter_func) {
412 switch (decoder->filter_func(decoder->cb_data, frame)) { 420 switch (decoder->filter_func(decoder->cb_data, stream, frame)) {
413 case MAD_FLOW_STOP: 421 case MAD_FLOW_STOP:
414 goto done; 422 goto done;
415 case MAD_FLOW_BREAK: 423 case MAD_FLOW_BREAK:
416 goto fail; 424 goto fail;
417 case MAD_FLOW_IGNORE: 425 case MAD_FLOW_IGNORE:
418 continue; 426 continue;
419 case MAD_FLOW_CONTINUE: 427 case MAD_FLOW_CONTINUE:
420 break; 428 break;
421 } 429 }
422 } 430 }
423 431
424 mad_synth_frame(synth, frame); 432 mad_synth_frame(synth, frame);
425 433
426 if (decoder->output_func) { 434 if (decoder->output_func) {
427 switch (decoder->output_func(decoder->cb_data, 435 switch (decoder->output_func(decoder->cb_data,
428 &frame->header, &synth->pcm)) { 436 &frame->header, &synth->pcm)) {
429 case MAD_FLOW_STOP: 437 case MAD_FLOW_STOP:
430 goto done; 438 goto done;
431 case MAD_FLOW_BREAK: 439 case MAD_FLOW_BREAK:
432 goto fail; 440 goto fail;
433 case MAD_FLOW_IGNORE: 441 case MAD_FLOW_IGNORE:
434 case MAD_FLOW_CONTINUE: 442 case MAD_FLOW_CONTINUE:
435 break; 443 break;
436 } 444 }
437 } 445 }
438 } 446 }
439 } 447 }
440 while (stream->error == MAD_ERROR_BUFLEN); 448 while (stream->error == MAD_ERROR_BUFLEN);
441 449
442 fail: 450 fail:
443 result = -1; 451 result = -1;
444 452
445 done: 453 done:
446 mad_synth_finish(synth); 454 mad_synth_finish(synth);
447 mad_frame_finish(frame); 455 mad_frame_finish(frame);
448 mad_stream_finish(stream); 456 mad_stream_finish(stream);
449 457
450 return result; 458 return result;
451} 459}
452 460
461# if defined(USE_ASYNC)
453static 462static
454int run_async(struct mad_decoder *decoder) 463int run_async(struct mad_decoder *decoder)
455{ 464{
456 pid_t pid; 465 pid_t pid;
457 int ptoc[2], ctop[2], flags; 466 int ptoc[2], ctop[2], flags;
458 467
459 if (pipe(ptoc) == -1) 468 if (pipe(ptoc) == -1)
460 return -1; 469 return -1;
461 470
462 if (pipe(ctop) == -1) { 471 if (pipe(ctop) == -1) {
463 close(ptoc[0]); 472 close(ptoc[0]);
464 close(ptoc[1]); 473 close(ptoc[1]);
465 return -1; 474 return -1;
466 } 475 }
467 476
468 flags = fcntl(ptoc[0], F_GETFL); 477 flags = fcntl(ptoc[0], F_GETFL);
469 if (flags == -1 || 478 if (flags == -1 ||
470 fcntl(ptoc[0], F_SETFL, flags | O_NONBLOCK) == -1) { 479 fcntl(ptoc[0], F_SETFL, flags | O_NONBLOCK) == -1) {
471 close(ctop[0]); 480 close(ctop[0]);
472 close(ctop[1]); 481 close(ctop[1]);
473 close(ptoc[0]); 482 close(ptoc[0]);
474 close(ptoc[1]); 483 close(ptoc[1]);
475 return -1; 484 return -1;
476 } 485 }
477 486
478 pid = fork(); 487 pid = fork();
479 if (pid == -1) { 488 if (pid == -1) {
480 close(ctop[0]); 489 close(ctop[0]);
481 close(ctop[1]); 490 close(ctop[1]);
482 close(ptoc[0]); 491 close(ptoc[0]);
483 close(ptoc[1]); 492 close(ptoc[1]);
484 return -1; 493 return -1;
485 } 494 }
486 495
487 decoder->async.pid = pid; 496 decoder->async.pid = pid;
488 497
489 if (pid) { 498 if (pid) {
490 /* parent */ 499 /* parent */
491 500
492 close(ptoc[0]); 501 close(ptoc[0]);
493 close(ctop[1]); 502 close(ctop[1]);
494 503
495 decoder->async.in = ctop[0]; 504 decoder->async.in = ctop[0];
496 decoder->async.out = ptoc[1]; 505 decoder->async.out = ptoc[1];
497 506
498 return 0; 507 return 0;
499 } 508 }
500 509
501 /* child */ 510 /* child */
502 511
503 close(ptoc[1]); 512 close(ptoc[1]);
504 close(ctop[0]); 513 close(ctop[0]);
505 514
506 decoder->async.in = ptoc[0]; 515 decoder->async.in = ptoc[0];
507 decoder->async.out = ctop[1]; 516 decoder->async.out = ctop[1];
508 517
509 _exit(run_sync(decoder)); 518 _exit(run_sync(decoder));
510 519
511 /* not reached */ 520 /* not reached */
512 return -1; 521 return -1;
513} 522}
523# endif
514 524
515int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode) 525int mad_decoder_run(struct mad_decoder *decoder, enum mad_decoder_mode mode)
516{ 526{
517 int result; 527 int result;
518 int (*run)(struct mad_decoder *) = 0; 528 int (*run)(struct mad_decoder *) = 0;
519 529
520 switch (decoder->mode = mode) { 530 switch (decoder->mode = mode) {
521 case MAD_DECODER_MODE_SYNC: 531 case MAD_DECODER_MODE_SYNC:
522 run = run_sync; 532 run = run_sync;
523 break; 533 break;
524 534
525 case MAD_DECODER_MODE_ASYNC: 535 case MAD_DECODER_MODE_ASYNC:
536# if defined(USE_ASYNC)
526 run = run_async; 537 run = run_async;
538# endif
527 break; 539 break;
528 } 540 }
529 541
530 if (run == 0) 542 if (run == 0)
531 return -1; 543 return -1;
532 544
533 decoder->sync = malloc(sizeof(*decoder->sync)); 545 decoder->sync = malloc(sizeof(*decoder->sync));
534 if (decoder->sync == 0) 546 if (decoder->sync == 0)
535 return -1; 547 return -1;
536 548
537 result = run(decoder); 549 result = run(decoder);
538 550
539 free(decoder->sync); 551 free(decoder->sync);
540 decoder->sync = 0; 552 decoder->sync = 0;
541 553
542 return result; 554 return result;
543} 555}
544 556
545int mad_decoder_message(struct mad_decoder *decoder, 557int mad_decoder_message(struct mad_decoder *decoder,
546 void *message, unsigned int *len) 558 void *message, unsigned int *len)
547{ 559{
560# if defined(USE_ASYNC)
548 if (decoder->mode != MAD_DECODER_MODE_ASYNC || 561 if (decoder->mode != MAD_DECODER_MODE_ASYNC ||
549 send(decoder->async.out, message, *len) != MAD_FLOW_CONTINUE || 562 send(decoder->async.out, message, *len) != MAD_FLOW_CONTINUE ||
550 receive(decoder->async.in, &message, len) != MAD_FLOW_CONTINUE) 563 receive(decoder->async.in, &message, len) != MAD_FLOW_CONTINUE)
551 return -1; 564 return -1;
552 565
553 return 0; 566 return 0;
567# else
568 return -1;
569# endif
554} 570}
diff --git a/core/multimedia/opieplayer/libmad/decoder.h b/core/multimedia/opieplayer/libmad/decoder.h
index dbacc1a..f34150d 100644
--- a/core/multimedia/opieplayer/libmad/decoder.h
+++ b/core/multimedia/opieplayer/libmad/decoder.h
@@ -1,87 +1,91 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# ifndef LIBMAD_DECODER_H 22# ifndef LIBMAD_DECODER_H
23# define LIBMAD_DECODER_H 23# define LIBMAD_DECODER_H
24 24
25# include "stream.h" 25# include "stream.h"
26# include "frame.h" 26# include "frame.h"
27# include "synth.h" 27# include "synth.h"
28 28
29enum mad_decoder_mode { 29enum mad_decoder_mode {
30 MAD_DECODER_MODE_SYNC = 0, 30 MAD_DECODER_MODE_SYNC = 0,
31 MAD_DECODER_MODE_ASYNC 31 MAD_DECODER_MODE_ASYNC
32}; 32};
33 33
34enum mad_flow { 34enum mad_flow {
35 MAD_FLOW_CONTINUE = 0x0000, 35 MAD_FLOW_CONTINUE = 0x0000,/* continue normally */
36 MAD_FLOW_STOP = 0x0010, 36 MAD_FLOW_STOP = 0x0010,/* stop decoding normally */
37 MAD_FLOW_BREAK = 0x0011, 37 MAD_FLOW_BREAK = 0x0011,/* stop decoding and signal an error */
38 MAD_FLOW_IGNORE = 0x0020 38 MAD_FLOW_IGNORE = 0x0020/* ignore the current frame */
39}; 39};
40 40
41struct mad_decoder { 41struct mad_decoder {
42 enum mad_decoder_mode mode; 42 enum mad_decoder_mode mode;
43 43
44 int options; 44 int options;
45 45
46 struct { 46 struct {
47 long pid; 47 long pid;
48 int in; 48 int in;
49 int out; 49 int out;
50 } async; 50 } async;
51 51
52 struct { 52 struct {
53 struct mad_stream stream; 53 struct mad_stream stream;
54 struct mad_frame frame; 54 struct mad_frame frame;
55 struct mad_synth synth; 55 struct mad_synth synth;
56 } *sync; 56 } *sync;
57 57
58 void *cb_data; 58 void *cb_data;
59 59
60 enum mad_flow (*input_func)(void *, struct mad_stream *); 60 enum mad_flow (*input_func)(void *, struct mad_stream *);
61 enum mad_flow (*header_func)(void *, struct mad_header const *); 61 enum mad_flow (*header_func)(void *, struct mad_header const *);
62 enum mad_flow (*filter_func)(void *, struct mad_frame *); 62 enum mad_flow (*filter_func)(void *,
63 struct mad_stream const *, struct mad_frame *);
63 enum mad_flow (*output_func)(void *, 64 enum mad_flow (*output_func)(void *,
64 struct mad_header const *, struct mad_pcm *); 65 struct mad_header const *, struct mad_pcm *);
65 enum mad_flow (*error_func)(void *, struct mad_stream *, struct mad_frame *); 66 enum mad_flow (*error_func)(void *, struct mad_stream *, struct mad_frame *);
66 enum mad_flow (*message_func)(void *, void *, unsigned int *); 67 enum mad_flow (*message_func)(void *, void *, unsigned int *);
67}; 68};
68 69
69void mad_decoder_init(struct mad_decoder *, void *, 70void mad_decoder_init(struct mad_decoder *, void *,
70 enum mad_flow (*)(void *, struct mad_stream *), 71 enum mad_flow (*)(void *, struct mad_stream *),
71 enum mad_flow (*)(void *, struct mad_header const *), 72 enum mad_flow (*)(void *, struct mad_header const *),
72 enum mad_flow (*)(void *, struct mad_frame *), 73 enum mad_flow (*)(void *,
74 struct mad_stream const *,
75 struct mad_frame *),
73 enum mad_flow (*)(void *, 76 enum mad_flow (*)(void *,
74 struct mad_header const *, 77 struct mad_header const *,
75 struct mad_pcm *), 78 struct mad_pcm *),
76 enum mad_flow (*)(void *, 79 enum mad_flow (*)(void *,
77 struct mad_stream *, 80 struct mad_stream *,
78 struct mad_frame *), 81 struct mad_frame *),
79 enum mad_flow (*)(void *, void *, unsigned int *)); 82 enum mad_flow (*)(void *, void *, unsigned int *));
80int mad_decoder_finish(struct mad_decoder *); 83int mad_decoder_finish(struct mad_decoder *);
81 84
82# define mad_decoder_options(decoder, opts) ((decoder)->options = (opts)) 85# define mad_decoder_options(decoder, opts) \
86 ((void) ((decoder)->options = (opts)))
83 87
84int mad_decoder_run(struct mad_decoder *, enum mad_decoder_mode); 88int mad_decoder_run(struct mad_decoder *, enum mad_decoder_mode);
85int mad_decoder_message(struct mad_decoder *, void *, unsigned int *); 89int mad_decoder_message(struct mad_decoder *, void *, unsigned int *);
86 90
87# endif 91# endif
diff --git a/core/multimedia/opieplayer/libmad/fixed.c b/core/multimedia/opieplayer/libmad/fixed.c
index be5c94e..af1e87e 100644
--- a/core/multimedia/opieplayer/libmad/fixed.c
+++ b/core/multimedia/opieplayer/libmad/fixed.c
@@ -1,37 +1,37 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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
28# include "fixed.h" 28# include "fixed.h"
29 29
30/* 30/*
31 * NAME:fixed->abs() 31 * NAME:fixed->abs()
32 * DESCRIPTION:return absolute value of a fixed-point number 32 * DESCRIPTION:return absolute value of a fixed-point number
33 */ 33 */
34mad_fixed_t mad_f_abs(mad_fixed_t x) 34mad_fixed_t mad_f_abs(mad_fixed_t x)
35{ 35{
36 return x < 0 ? -x : x; 36 return x < 0 ? -x : x;
37} 37}
diff --git a/core/multimedia/opieplayer/libmad/fixed.h b/core/multimedia/opieplayer/libmad/fixed.h
index 00ade62..c9b98ca 100644
--- a/core/multimedia/opieplayer/libmad/fixed.h
+++ b/core/multimedia/opieplayer/libmad/fixed.h
@@ -1,413 +1,476 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# ifndef LIBMAD_FIXED_H 22# ifndef LIBMAD_FIXED_H
23# define LIBMAD_FIXED_H 23# define LIBMAD_FIXED_H
24 24
25# if SIZEOF_INT >= 4 25# if SIZEOF_INT >= 4
26typedef signed int mad_fixed_t; 26typedef signed int mad_fixed_t;
27 27
28typedef signed int mad_fixed64hi_t; 28typedef signed int mad_fixed64hi_t;
29typedef unsigned int mad_fixed64lo_t; 29typedef unsigned int mad_fixed64lo_t;
30# else 30# else
31typedef signed long mad_fixed_t; 31typedef signed long mad_fixed_t;
32 32
33typedef signed long mad_fixed64hi_t; 33typedef signed long mad_fixed64hi_t;
34typedef unsigned long mad_fixed64lo_t; 34typedef unsigned long mad_fixed64lo_t;
35# endif 35# endif
36 36
37# if defined(_MSC_VER)
38# define mad_fixed64_t signed __int64
39# elif 1 || defined(__GNUC__)
40# define mad_fixed64_t signed long long
41# endif
42
43# if defined(FPM_FLOAT)
44typedef double mad_sample_t;
45# else
46typedef mad_fixed_t mad_sample_t;
47# endif
48
37/* 49/*
38 * Fixed-point format: 0xABBBBBBB 50 * Fixed-point format: 0xABBBBBBB
39 * A == whole part (sign + 3 bits) 51 * A == whole part (sign + 3 bits)
40 * B == fractional part (28 bits) 52 * B == fractional part (28 bits)
41 * 53 *
42 * Values are signed two's complement, so the effective range is: 54 * Values are signed two's complement, so the effective range is:
43 * 0x80000000 to 0x7fffffff 55 * 0x80000000 to 0x7fffffff
44 * -8.0 to +7.9999999962747097015380859375 56 * -8.0 to +7.9999999962747097015380859375
45 * 57 *
46 * The smallest representable value is: 58 * The smallest representable value is:
47 * 0x00000001 == 0.0000000037252902984619140625 (i.e. about 3.725e-9) 59 * 0x00000001 == 0.0000000037252902984619140625 (i.e. about 3.725e-9)
48 * 60 *
49 * 28 bits of fractional accuracy represent about 61 * 28 bits of fractional accuracy represent about
50 * 8.6 digits of decimal accuracy. 62 * 8.6 digits of decimal accuracy.
51 * 63 *
52 * Fixed-point numbers can be added or subtracted as normal 64 * Fixed-point numbers can be added or subtracted as normal
53 * integers, but multiplication requires shifting the 64-bit result 65 * integers, but multiplication requires shifting the 64-bit result
54 * from 56 fractional bits back to 28 (and rounding.) 66 * from 56 fractional bits back to 28 (and rounding.)
55 * 67 *
56 * Changing the definition of MAD_F_FRACBITS is only partially 68 * Changing the definition of MAD_F_FRACBITS is only partially
57 * supported, and must be done with care. 69 * supported, and must be done with care.
58 */ 70 */
59 71
60 # define MAD_F_FRACBITS 28 72 # define MAD_F_FRACBITS 28
61 73
62# if MAD_F_FRACBITS == 28 74# if MAD_F_FRACBITS == 28
63 # define MAD_F(x) ((mad_fixed_t) (x##L)) 75 # define MAD_F(x) ((mad_fixed_t) (x##L))
64# else 76# else
65# if MAD_F_FRACBITS < 28 77# if MAD_F_FRACBITS < 28
66# warning "MAD_F_FRACBITS < 28" 78# warning "MAD_F_FRACBITS < 28"
67 # define MAD_F(x) ((mad_fixed_t) \ 79 # define MAD_F(x) ((mad_fixed_t) \
68 (((x##L) + \ 80 (((x##L) + \
69 (1L << (28 - MAD_F_FRACBITS - 1))) >> \ 81 (1L << (28 - MAD_F_FRACBITS - 1))) >> \
70 (28 - MAD_F_FRACBITS))) 82 (28 - MAD_F_FRACBITS)))
71# elif MAD_F_FRACBITS > 28 83# elif MAD_F_FRACBITS > 28
72# error "MAD_F_FRACBITS > 28 not currently supported" 84# error "MAD_F_FRACBITS > 28 not currently supported"
73 # define MAD_F(x) ((mad_fixed_t) \ 85 # define MAD_F(x) ((mad_fixed_t) \
74 ((x##L) << (MAD_F_FRACBITS - 28))) 86 ((x##L) << (MAD_F_FRACBITS - 28)))
75# endif 87# endif
76# endif 88# endif
77 89
78 # define MAD_F_MIN ((mad_fixed_t) -0x80000000L) 90 # define MAD_F_MIN ((mad_fixed_t) -0x80000000L)
79 # define MAD_F_MAX ((mad_fixed_t) +0x7fffffffL) 91 # define MAD_F_MAX ((mad_fixed_t) +0x7fffffffL)
80 92
81 # define MAD_F_ONE MAD_F(0x10000000) 93 # define MAD_F_ONE MAD_F(0x10000000)
82 94
83 # define mad_f_tofixed(x)((mad_fixed_t) \ 95 # define mad_f_tofixed(x)((mad_fixed_t) \
84 ((x) * (double) (1L << MAD_F_FRACBITS) + 0.5)) 96 ((x) * (double) (1L << MAD_F_FRACBITS) + 0.5))
85 # define mad_f_todouble(x)((double) \ 97 # define mad_f_todouble(x)((double) \
86 ((x) / (double) (1L << MAD_F_FRACBITS))) 98 ((x) / (double) (1L << MAD_F_FRACBITS)))
87 99
88 # define mad_f_intpart(x)((x) >> MAD_F_FRACBITS) 100 # define mad_f_intpart(x)((x) >> MAD_F_FRACBITS)
89 # define mad_f_fracpart(x)((x) & ((1L << MAD_F_FRACBITS) - 1)) 101 # define mad_f_fracpart(x)((x) & ((1L << MAD_F_FRACBITS) - 1))
90 /* (x should be positive) */ 102 /* (x should be positive) */
91 103
92 # define mad_f_fromint(x)((x) << MAD_F_FRACBITS) 104 # define mad_f_fromint(x)((x) << MAD_F_FRACBITS)
93 105
94 # define mad_f_add(x, y)((x) + (y)) 106 # define mad_f_add(x, y)((x) + (y))
95 # define mad_f_sub(x, y)((x) - (y)) 107 # define mad_f_sub(x, y)((x) - (y))
96 108
97# if defined(FPM_64BIT) 109# if defined(FPM_FLOAT)
110# error "FPM_FLOAT not yet supported"
111
112# undef MAD_F
113 # define MAD_F(x) mad_f_todouble(x)
114
115 # define mad_f_mul(x, y)((x) * (y))
116# define mad_f_scale64
117
118# undef ASO_ZEROCHECK
119
120# elif defined(FPM_64BIT)
98 121
99/* 122/*
100 * This version should be the most accurate if 64-bit (long long) types are 123 * This version should be the most accurate if 64-bit types are supported by
101 * supported by the compiler, although it may not be the most efficient. 124 * the compiler, although it may not be the most efficient.
102 */ 125 */
103# if defined(OPT_ACCURACY) 126# if defined(OPT_ACCURACY)
104# define mad_f_mul(x, y) \ 127# define mad_f_mul(x, y) \
105 ((mad_fixed_t) \ 128 ((mad_fixed_t) \
106 ((((signed long long) (x) * (y)) + \ 129 ((((mad_fixed64_t) (x) * (y)) + \
107 (1L << (MAD_F_SCALEBITS - 1))) >> MAD_F_SCALEBITS)) 130 (1L << (MAD_F_SCALEBITS - 1))) >> MAD_F_SCALEBITS))
108# else 131# else
109# define mad_f_mul(x, y) \ 132# define mad_f_mul(x, y) \
110 ((mad_fixed_t) (((signed long long) (x) * (y)) >> MAD_F_SCALEBITS)) 133 ((mad_fixed_t) (((mad_fixed64_t) (x) * (y)) >> MAD_F_SCALEBITS))
111# endif 134# endif
112 135
113# define MAD_F_SCALEBITS MAD_F_FRACBITS 136# define MAD_F_SCALEBITS MAD_F_FRACBITS
114 137
115/* --- Intel --------------------------------------------------------------- */ 138/* --- Intel --------------------------------------------------------------- */
116 139
117# elif defined(FPM_INTEL) 140# elif defined(FPM_INTEL)
118 141
142# if defined(_MSC_VER)
143# pragma warning(push)
144# pragma warning(disable: 4035) /* no return value */
145static __forceinline
146mad_fixed_t mad_f_mul_inline(mad_fixed_t x, mad_fixed_t y)
147{
148 enum {
149 fracbits = MAD_F_FRACBITS
150 };
151
152 __asm {
153 mov eax, x
154 imul y
155 shrd eax, edx, fracbits
156 }
157
158 /* implicit return of eax */
159}
160# pragma warning(pop)
161
162 # define mad_f_mul mad_f_mul_inline
163# define mad_f_scale64
164# else
119/* 165/*
120 * This Intel version is fast and accurate; the disposition of the least 166 * This Intel version is fast and accurate; the disposition of the least
121 * significant bit depends on OPT_ACCURACY via mad_f_scale64(). 167 * significant bit depends on OPT_ACCURACY via mad_f_scale64().
122 */ 168 */
123# define MAD_F_MLX(hi, lo, x, y) \ 169# define MAD_F_MLX(hi, lo, x, y) \
124 asm ("imull %3" \ 170 asm ("imull %3" \
125 : "=a" (lo), "=d" (hi) \ 171 : "=a" (lo), "=d" (hi) \
126 : "%a" (x), "rm" (y) \ 172 : "%a" (x), "rm" (y) \
127 : "cc") 173 : "cc")
128 174
129# if defined(OPT_ACCURACY) 175# if defined(OPT_ACCURACY)
130/* 176/*
131 * This gives best accuracy but is not very fast. 177 * This gives best accuracy but is not very fast.
132 */ 178 */
133# define MAD_F_MLA(hi, lo, x, y) \ 179# define MAD_F_MLA(hi, lo, x, y) \
134 ({ mad_fixed64hi_t __hi; \ 180 ({ mad_fixed64hi_t __hi; \
135 mad_fixed64lo_t __lo; \ 181 mad_fixed64lo_t __lo; \
136 MAD_F_MLX(__hi, __lo, (x), (y)); \ 182 MAD_F_MLX(__hi, __lo, (x), (y)); \
137 asm ("addl %2,%0\n\t" \ 183 asm ("addl %2,%0\n\t" \
138 "adcl %3,%1" \ 184 "adcl %3,%1" \
139 : "=rm" (lo), "=rm" (hi) \ 185 : "=rm" (lo), "=rm" (hi) \
140 : "r" (__lo), "r" (__hi), "0" (lo), "1" (hi) \ 186 : "r" (__lo), "r" (__hi), "0" (lo), "1" (hi) \
141 : "cc"); \ 187 : "cc"); \
142 }) 188 })
143# endif /* OPT_ACCURACY */ 189# endif /* OPT_ACCURACY */
144 190
145# if defined(OPT_ACCURACY) 191# if defined(OPT_ACCURACY)
146/* 192/*
147 * Surprisingly, this is faster than SHRD followed by ADC. 193 * Surprisingly, this is faster than SHRD followed by ADC.
148 */ 194 */
149# define mad_f_scale64(hi, lo) \ 195# define mad_f_scale64(hi, lo) \
150 ({ mad_fixed64hi_t __hi_; \ 196 ({ mad_fixed64hi_t __hi_; \
151 mad_fixed64lo_t __lo_; \ 197 mad_fixed64lo_t __lo_; \
152 mad_fixed_t __result; \ 198 mad_fixed_t __result; \
153 asm ("addl %4,%2\n\t" \ 199 asm ("addl %4,%2\n\t" \
154 "adcl %5,%3" \ 200 "adcl %5,%3" \
155 : "=rm" (__lo_), "=rm" (__hi_) \ 201 : "=rm" (__lo_), "=rm" (__hi_) \
156 : "0" (lo), "1" (hi), \ 202 : "0" (lo), "1" (hi), \
157 "ir" (1L << (MAD_F_SCALEBITS - 1)), "ir" (0) \ 203 "ir" (1L << (MAD_F_SCALEBITS - 1)), "ir" (0) \
158 : "cc"); \ 204 : "cc"); \
159 asm ("shrdl %3,%2,%1" \ 205 asm ("shrdl %3,%2,%1" \
160 : "=rm" (__result) \ 206 : "=rm" (__result) \
161 : "0" (__lo_), "r" (__hi_), "I" (MAD_F_SCALEBITS) \ 207 : "0" (__lo_), "r" (__hi_), "I" (MAD_F_SCALEBITS) \
162 : "cc"); \ 208 : "cc"); \
163 __result; \ 209 __result; \
164 }) 210 })
165# else 211# else
166# define mad_f_scale64(hi, lo) \ 212# define mad_f_scale64(hi, lo) \
167 ({ mad_fixed_t __result; \ 213 ({ mad_fixed_t __result; \
168 asm ("shrdl %3,%2,%1" \ 214 asm ("shrdl %3,%2,%1" \
169 : "=rm" (__result) \ 215 : "=rm" (__result) \
170 : "0" (lo), "r" (hi), "I" (MAD_F_SCALEBITS) \ 216 : "0" (lo), "r" (hi), "I" (MAD_F_SCALEBITS) \
171 : "cc"); \ 217 : "cc"); \
172 __result; \ 218 __result; \
173 }) 219 })
174# endif /* OPT_ACCURACY */ 220# endif /* OPT_ACCURACY */
175 221
176# define MAD_F_SCALEBITS MAD_F_FRACBITS 222# define MAD_F_SCALEBITS MAD_F_FRACBITS
223# endif
177 224
178/* --- ARM ----------------------------------------------------------------- */ 225/* --- ARM ----------------------------------------------------------------- */
179 226
180# elif defined(FPM_ARM) 227# elif defined(FPM_ARM)
181 228
182/* 229/*
183 * This ARM V4 version is as accurate as FPM_64BIT but much faster. The 230 * This ARM V4 version is as accurate as FPM_64BIT but much faster. The
184 * least significant bit is properly rounded at no CPU cycle cost! 231 * least significant bit is properly rounded at no CPU cycle cost!
185 */ 232 */
186# if 1 233# if 1
187/* 234/*
188 * There's a bug somewhere, possibly in the compiler, that sometimes makes 235 * There's a bug somewhere, possibly in the compiler, that sometimes makes
189 * this necessary instead of the default implementation via MAD_F_MLX and 236 * this necessary instead of the default implementation via MAD_F_MLX and
190 * mad_f_scale64. It may be related to the use (or lack) of 237 * mad_f_scale64. It may be related to the use (or lack) of
191 * -finline-functions and/or -fstrength-reduce. 238 * -finline-functions and/or -fstrength-reduce.
192 * 239 *
193 * This is also apparently faster than MAD_F_MLX/mad_f_scale64. 240 * This is also apparently faster than MAD_F_MLX/mad_f_scale64.
194 */ 241 */
195# define mad_f_mul(x, y) \ 242# define mad_f_mul(x, y) \
196 ({ mad_fixed64hi_t __hi; \ 243 ({ mad_fixed64hi_t __hi; \
197 mad_fixed64lo_t __lo; \ 244 mad_fixed64lo_t __lo; \
198 mad_fixed_t __result; \ 245 mad_fixed_t __result; \
199 asm ("smull%0, %1, %3, %4\n\t" \ 246 asm ("smull%0, %1, %3, %4\n\t" \
200 "movs%0, %0, lsr %5\n\t" \ 247 "movs%0, %0, lsr %5\n\t" \
201 "adc%2, %0, %1, lsl %6" \ 248 "adc%2, %0, %1, lsl %6" \
202 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \ 249 : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
203 : "%r" (x), "r" (y), \ 250 : "%r" (x), "r" (y), \
204 "M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \ 251 "M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \
205 : "cc"); \ 252 : "cc"); \
206 __result; \ 253 __result; \
207 }) 254 })
208# endif 255# endif
209 256
210# define MAD_F_MLX(hi, lo, x, y) \ 257# define MAD_F_MLX(hi, lo, x, y) \
211 asm ("smull%0, %1, %2, %3" \ 258 asm ("smull%0, %1, %2, %3" \
212 : "=&r" (lo), "=&r" (hi) \ 259 : "=&r" (lo), "=&r" (hi) \
213 : "%r" (x), "r" (y)) 260 : "%r" (x), "r" (y))
214 261
215# define MAD_F_MLA(hi, lo, x, y) \ 262# define MAD_F_MLA(hi, lo, x, y) \
216 asm ("smlal%0, %1, %2, %3" \ 263 asm ("smlal%0, %1, %2, %3" \
217 : "+r" (lo), "+r" (hi) \ 264 : "+r" (lo), "+r" (hi) \
218 : "%r" (x), "r" (y)) 265 : "%r" (x), "r" (y))
219 266
267# define MAD_F_MLN(hi, lo) \
268 asm ("rsbs%0, %2, #0\n\t" \
269 "rsc%1, %3, #0" \
270 : "=r" (lo), "=r" (hi) \
271 : "0" (lo), "1" (hi) \
272 : "cc")
273
220# define mad_f_scale64(hi, lo) \ 274# define mad_f_scale64(hi, lo) \
221 ({ mad_fixed_t __result; \ 275 ({ mad_fixed_t __result; \
222 asm ("movs%0, %1, lsr %3\n\t" \ 276 asm ("movs%0, %1, lsr %3\n\t" \
223 "adc%0, %0, %2, lsl %4" \ 277 "adc%0, %0, %2, lsl %4" \
224 : "=r" (__result) \ 278 : "=r" (__result) \
225 : "r" (lo), "r" (hi), \ 279 : "r" (lo), "r" (hi), \
226 "M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \ 280 "M" (MAD_F_SCALEBITS), "M" (32 - MAD_F_SCALEBITS) \
227 : "cc"); \ 281 : "cc"); \
228 __result; \ 282 __result; \
229 }) 283 })
230 284
231# define MAD_F_SCALEBITS MAD_F_FRACBITS 285# define MAD_F_SCALEBITS MAD_F_FRACBITS
232 286
233/* --- MIPS ---------------------------------------------------------------- */ 287/* --- MIPS ---------------------------------------------------------------- */
234 288
235# elif defined(FPM_MIPS) 289# elif defined(FPM_MIPS)
236 290
237/* 291/*
238 * This MIPS version is fast and accurate; the disposition of the least 292 * This MIPS version is fast and accurate; the disposition of the least
239 * significant bit depends on OPT_ACCURACY via mad_f_scale64(). 293 * significant bit depends on OPT_ACCURACY via mad_f_scale64().
240 */ 294 */
241# define MAD_F_MLX(hi, lo, x, y) \ 295# define MAD_F_MLX(hi, lo, x, y) \
242 asm ("mult%2,%3" \ 296 asm ("mult%2,%3" \
243 : "=l" (lo), "=h" (hi) \ 297 : "=l" (lo), "=h" (hi) \
244 : "%r" (x), "r" (y)) 298 : "%r" (x), "r" (y))
245 299
246# if defined(HAVE_MADD_ASM) 300# if defined(HAVE_MADD_ASM)
247# define MAD_F_MLA(hi, lo, x, y) \ 301# define MAD_F_MLA(hi, lo, x, y) \
248 asm ("madd%2,%3" \ 302 asm ("madd%2,%3" \
249 : "+l" (lo), "+h" (hi) \ 303 : "+l" (lo), "+h" (hi) \
250 : "%r" (x), "r" (y)) 304 : "%r" (x), "r" (y))
251# elif defined(HAVE_MADD16_ASM) 305# elif defined(HAVE_MADD16_ASM)
252/* 306/*
253 * This loses significant accuracy due to the 16-bit integer limit in the 307 * This loses significant accuracy due to the 16-bit integer limit in the
254 * multiply/accumulate instruction. 308 * multiply/accumulate instruction.
255 */ 309 */
256# define MAD_F_ML0(hi, lo, x, y) \ 310# define MAD_F_ML0(hi, lo, x, y) \
257 asm ("mult%2,%3" \ 311 asm ("mult%2,%3" \
258 : "=l" (lo), "=h" (hi) \ 312 : "=l" (lo), "=h" (hi) \
259 : "%r" ((x) >> 12), "r" ((y) >> 16)) 313 : "%r" ((x) >> 12), "r" ((y) >> 16))
260# define MAD_F_MLA(hi, lo, x, y) \ 314# define MAD_F_MLA(hi, lo, x, y) \
261 asm ("madd16%2,%3" \ 315 asm ("madd16%2,%3" \
262 : "+l" (lo), "+h" (hi) \ 316 : "+l" (lo), "+h" (hi) \
263 : "%r" ((x) >> 12), "r" ((y) >> 16)) 317 : "%r" ((x) >> 12), "r" ((y) >> 16))
264# define MAD_F_MLZ(hi, lo) ((mad_fixed_t) (lo)) 318# define MAD_F_MLZ(hi, lo) ((mad_fixed_t) (lo))
265# endif 319# endif
266 320
267# if defined(OPT_SPEED) 321# if defined(OPT_SPEED)
268# define mad_f_scale64(hi, lo) \ 322# define mad_f_scale64(hi, lo) \
269 ((mad_fixed_t) ((hi) << (32 - MAD_F_SCALEBITS))) 323 ((mad_fixed_t) ((hi) << (32 - MAD_F_SCALEBITS)))
270# define MAD_F_SCALEBITS MAD_F_FRACBITS 324# define MAD_F_SCALEBITS MAD_F_FRACBITS
271# endif 325# endif
272 326
273/* --- SPARC --------------------------------------------------------------- */ 327/* --- SPARC --------------------------------------------------------------- */
274 328
275# elif defined(FPM_SPARC) 329# elif defined(FPM_SPARC)
276 330
277/* 331/*
278 * This SPARC V8 version is fast and accurate; the disposition of the least 332 * This SPARC V8 version is fast and accurate; the disposition of the least
279 * significant bit depends on OPT_ACCURACY via mad_f_scale64(). 333 * significant bit depends on OPT_ACCURACY via mad_f_scale64().
280 */ 334 */
281# define MAD_F_MLX(hi, lo, x, y) \ 335# define MAD_F_MLX(hi, lo, x, y) \
282 asm ("smul %2, %3, %0\n\t" \ 336 asm ("smul %2, %3, %0\n\t" \
283 "rd %%y, %1" \ 337 "rd %%y, %1" \
284 : "=r" (lo), "=r" (hi) \ 338 : "=r" (lo), "=r" (hi) \
285 : "%r" (x), "rI" (y)) 339 : "%r" (x), "rI" (y))
286 340
287/* --- PowerPC ------------------------------------------------------------- */ 341/* --- PowerPC ------------------------------------------------------------- */
288 342
289# elif defined(FPM_PPC) 343# elif defined(FPM_PPC)
290 344
291/* 345/*
292 * This PowerPC version is tuned for the 4xx embedded processors. It is 346 * This PowerPC version is tuned for the 4xx embedded processors. It is
293 * effectively a tuned version of FPM_64BIT. It is a little faster and just 347 * effectively a tuned version of FPM_64BIT. It is a little faster and just
294 * as accurate. The disposition of the least significant bit depends on 348 * as accurate. The disposition of the least significant bit depends on
295 * OPT_ACCURACY via mad_f_scale64(). 349 * OPT_ACCURACY via mad_f_scale64().
296 */ 350 */
297# define MAD_F_MLX(hi, lo, x, y) \ 351# define MAD_F_MLX(hi, lo, x, y) \
298 asm ("mulhw %1, %2, %3\n\t" \ 352 asm ("mulhw %1, %2, %3\n\t" \
299 "mullw %0, %2, %3" \ 353 "mullw %0, %2, %3" \
300 : "=&r" (lo), "=&r" (hi) \ 354 : "=&r" (lo), "=&r" (hi) \
301 : "%r" (x), "r" (y)) 355 : "%r" (x), "r" (y))
302 356
303# define MAD_F_MLA(hi, lo, x, y) \ 357# define MAD_F_MLA(hi, lo, x, y) \
304 ({ mad_fixed64hi_t __hi; \ 358 ({ mad_fixed64hi_t __hi; \
305 mad_fixed64lo_t __lo; \ 359 mad_fixed64lo_t __lo; \
306 MAD_F_MLX(__hi, __lo, (x), (y)); \ 360 MAD_F_MLX(__hi, __lo, (x), (y)); \
307 asm ("addc %0, %2, %3\n\t" \ 361 asm ("addc %0, %2, %3\n\t" \
308 "adde %1, %4, %5" \ 362 "adde %1, %4, %5" \
309 : "=r" (lo), "=r" (hi) \ 363 : "=r" (lo), "=r" (hi) \
310 : "%r" (__lo), "0" (lo), "%r" (__hi), "1" (hi)); \ 364 : "%r" (__lo), "0" (lo), "%r" (__hi), "1" (hi)); \
311 }) 365 })
312 366
313# if defined(OPT_ACCURACY) 367# if defined(OPT_ACCURACY)
314/* 368/*
315 * This is accurate and ~2 - 2.5 times slower than the unrounded version. 369 * This is accurate and ~2 - 2.5 times slower than the unrounded version.
316 * 370 *
317 * The __volatile__ improves the generated code by another 5% (fewer spills 371 * The __volatile__ improves the generated code by another 5% (fewer spills
318 * to memory); eventually they should be removed. 372 * to memory); eventually they should be removed.
319 */ 373 */
320# define mad_f_scale64(hi, lo) \ 374# define mad_f_scale64(hi, lo) \
321 ({ mad_fixed_t __result; \ 375 ({ mad_fixed_t __result; \
322 mad_fixed64hi_t __hi_; \ 376 mad_fixed64hi_t __hi_; \
323 mad_fixed64lo_t __lo_; \ 377 mad_fixed64lo_t __lo_; \
324 asm __volatile__ ("addc %0, %2, %4\n\t" \ 378 asm __volatile__ ("addc %0, %2, %4\n\t" \
325 "addze %1, %3" \ 379 "addze %1, %3" \
326 : "=r" (__lo_), "=r" (__hi_) \ 380 : "=r" (__lo_), "=r" (__hi_) \
327 : "r" (lo), "r" (hi), "r" (1 << (MAD_F_SCALEBITS - 1))); \ 381 : "r" (lo), "r" (hi), "r" (1 << (MAD_F_SCALEBITS - 1))); \
328 asm __volatile__ ("rlwinm %0, %2,32-%3,0,%3-1\n\t" \ 382 asm __volatile__ ("rlwinm %0, %2,32-%3,0,%3-1\n\t" \
329 "rlwimi %0, %1,32-%3,%3,31" \ 383 "rlwimi %0, %1,32-%3,%3,31" \
330 : "=&r" (__result) \ 384 : "=&r" (__result) \
331 : "r" (__lo_), "r" (__hi_), "I" (MAD_F_SCALEBITS)); \ 385 : "r" (__lo_), "r" (__hi_), "I" (MAD_F_SCALEBITS)); \
332 __result; \ 386 __result; \
333 }) 387 })
334# else 388# else
335# define mad_f_scale64(hi, lo) \ 389# define mad_f_scale64(hi, lo) \
336 ({ mad_fixed_t __result; \ 390 ({ mad_fixed_t __result; \
337 asm ("rlwinm %0, %2,32-%3,0,%3-1\n\t" \ 391 asm ("rlwinm %0, %2,32-%3,0,%3-1\n\t" \
338 "rlwimi %0, %1,32-%3,%3,31" \ 392 "rlwimi %0, %1,32-%3,%3,31" \
339 : "=r" (__result) \ 393 : "=r" (__result) \
340 : "r" (lo), "r" (hi), "I" (MAD_F_SCALEBITS)); \ 394 : "r" (lo), "r" (hi), "I" (MAD_F_SCALEBITS)); \
341 __result; \ 395 __result; \
342 }) 396 })
343# endif /* OPT_ACCURACY */ 397# endif /* OPT_ACCURACY */
344 398
345# define MAD_F_SCALEBITS MAD_F_FRACBITS 399# define MAD_F_SCALEBITS MAD_F_FRACBITS
346 400
347/* --- Default ------------------------------------------------------------- */ 401/* --- Default ------------------------------------------------------------- */
348 402
349# elif defined(FPM_DEFAULT) 403# elif defined(FPM_DEFAULT)
350 404
351/* 405/*
352 * This version is the most portable but it loses significant accuracy. 406 * This version is the most portable but it loses significant accuracy.
353 * Furthermore, accuracy is biased against the second argument, so care 407 * Furthermore, accuracy is biased against the second argument, so care
354 * should be taken when ordering operands. 408 * should be taken when ordering operands.
355 * 409 *
356 * The scale factors are constant as this is not used with SSO. 410 * The scale factors are constant as this is not used with SSO.
357 * 411 *
358 * Pre-rounding is required to stay within the limits of compliance. 412 * Pre-rounding is required to stay within the limits of compliance.
359 */ 413 */
360 # define mad_f_mul(x, y)((((x) + (1L << 11)) >> 12) * \ 414# if defined(OPT_SPEED)
415 # define mad_f_mul(x, y)(((x) >> 12) * ((y) >> 16))
416# else
417 # define mad_f_mul(x, y)((((x) + (1L << 11)) >> 12) * \
361 (((y) + (1L << 15)) >> 16)) 418 (((y) + (1L << 15)) >> 16))
419# endif
362 420
363/* ------------------------------------------------------------------------- */ 421/* ------------------------------------------------------------------------- */
364 422
365# else 423# else
366# error "no FPM selected" 424# error "no FPM selected"
367# endif 425# endif
368 426
369/* default implementations */ 427/* default implementations */
370 428
371# if !defined(mad_f_mul) 429# if !defined(mad_f_mul)
372# define mad_f_mul(x, y) \ 430# define mad_f_mul(x, y) \
373 ({ mad_fixed64hi_t __hi; \ 431 ({ mad_fixed64hi_t __hi; \
374 mad_fixed64lo_t __lo; \ 432 mad_fixed64lo_t __lo; \
375 MAD_F_MLX(__hi, __lo, (x), (y)); \ 433 MAD_F_MLX(__hi, __lo, (x), (y)); \
376 mad_f_scale64(__hi, __lo); \ 434 mad_f_scale64(__hi, __lo); \
377 }) 435 })
378# endif 436# endif
379 437
380# if !defined(MAD_F_MLA) 438# if !defined(MAD_F_MLA)
381 # define MAD_F_ML0(hi, lo, x, y)((lo) = mad_f_mul((x), (y))) 439 # define MAD_F_ML0(hi, lo, x, y)((lo) = mad_f_mul((x), (y)))
382 # define MAD_F_MLA(hi, lo, x, y)((lo) += mad_f_mul((x), (y))) 440 # define MAD_F_MLA(hi, lo, x, y)((lo) += mad_f_mul((x), (y)))
441 # define MAD_F_MLN(hi, lo) ((lo) = -(lo))
383 # define MAD_F_MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo)) 442 # define MAD_F_MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo))
384# endif 443# endif
385 444
386# if !defined(MAD_F_ML0) 445# if !defined(MAD_F_ML0)
387 # define MAD_F_ML0(hi, lo, x, y)MAD_F_MLX((hi), (lo), (x), (y)) 446 # define MAD_F_ML0(hi, lo, x, y)MAD_F_MLX((hi), (lo), (x), (y))
388# endif 447# endif
389 448
449# if !defined(MAD_F_MLN)
450 # define MAD_F_MLN(hi, lo) ((hi) = ((lo) = -(lo)) ? ~(hi) : -(hi))
451# endif
452
390# if !defined(MAD_F_MLZ) 453# if !defined(MAD_F_MLZ)
391 # define MAD_F_MLZ(hi, lo) mad_f_scale64((hi), (lo)) 454 # define MAD_F_MLZ(hi, lo) mad_f_scale64((hi), (lo))
392# endif 455# endif
393 456
394# if !defined(mad_f_scale64) 457# if !defined(mad_f_scale64)
395# if defined(OPT_ACCURACY) 458# if defined(OPT_ACCURACY)
396# define mad_f_scale64(hi, lo) \ 459# define mad_f_scale64(hi, lo) \
397 ((((mad_fixed_t) \ 460 ((((mad_fixed_t) \
398 (((hi) << (32 - (MAD_F_SCALEBITS - 1))) | \ 461 (((hi) << (32 - (MAD_F_SCALEBITS - 1))) | \
399 ((lo) >> (MAD_F_SCALEBITS - 1)))) + 1) >> 1) 462 ((lo) >> (MAD_F_SCALEBITS - 1)))) + 1) >> 1)
400# else 463# else
401# define mad_f_scale64(hi, lo) \ 464# define mad_f_scale64(hi, lo) \
402 ((mad_fixed_t) \ 465 ((mad_fixed_t) \
403 (((hi) << (32 - MAD_F_SCALEBITS)) | \ 466 (((hi) << (32 - MAD_F_SCALEBITS)) | \
404 ((lo) >> MAD_F_SCALEBITS))) 467 ((lo) >> MAD_F_SCALEBITS)))
405# endif 468# endif
406# define MAD_F_SCALEBITS MAD_F_FRACBITS 469# define MAD_F_SCALEBITS MAD_F_FRACBITS
407# endif 470# endif
408 471
409/* miscellaneous C routines */ 472/* miscellaneous C routines */
410 473
411mad_fixed_t mad_f_abs(mad_fixed_t); 474mad_fixed_t mad_f_abs(mad_fixed_t);
412 475
413# endif 476# endif
diff --git a/core/multimedia/opieplayer/libmad/frame.c b/core/multimedia/opieplayer/libmad/frame.c
index 4ebb80c..bf15e7f 100644
--- a/core/multimedia/opieplayer/libmad/frame.c
+++ b/core/multimedia/opieplayer/libmad/frame.c
@@ -1,499 +1,499 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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
28# include <stdlib.h> 28# include <stdlib.h>
29 29
30# include "bit.h" 30# include "bit.h"
31# include "stream.h" 31# include "stream.h"
32# include "frame.h" 32# include "frame.h"
33# include "timer.h" 33# include "timer.h"
34# include "layer12.h" 34# include "layer12.h"
35# include "layer3.h" 35# include "layer3.h"
36 36
37static 37static
38unsigned long const bitrate_table[5][15] = { 38unsigned long const bitrate_table[5][15] = {
39 /* MPEG-1 */ 39 /* MPEG-1 */
40 { 0, 32000, 64000, 96000, 128000, 160000, 192000, 224000, /* Layer I */ 40 { 0, 32000, 64000, 96000, 128000, 160000, 192000, 224000, /* Layer I */
41 256000, 288000, 320000, 352000, 384000, 416000, 448000 }, 41 256000, 288000, 320000, 352000, 384000, 416000, 448000 },
42 { 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, /* Layer II */ 42 { 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, /* Layer II */
43 128000, 160000, 192000, 224000, 256000, 320000, 384000 }, 43 128000, 160000, 192000, 224000, 256000, 320000, 384000 },
44 { 0, 32000, 40000, 48000, 56000, 64000, 80000, 96000, /* Layer III */ 44 { 0, 32000, 40000, 48000, 56000, 64000, 80000, 96000, /* Layer III */
45 112000, 128000, 160000, 192000, 224000, 256000, 320000 }, 45 112000, 128000, 160000, 192000, 224000, 256000, 320000 },
46 46
47 /* MPEG-2 LSF */ 47 /* MPEG-2 LSF */
48 { 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, /* Layer I */ 48 { 0, 32000, 48000, 56000, 64000, 80000, 96000, 112000, /* Layer I */
49 128000, 144000, 160000, 176000, 192000, 224000, 256000 }, 49 128000, 144000, 160000, 176000, 192000, 224000, 256000 },
50 { 0, 8000, 16000, 24000, 32000, 40000, 48000, 56000, /* Layers */ 50 { 0, 8000, 16000, 24000, 32000, 40000, 48000, 56000, /* Layers */
51 64000, 80000, 96000, 112000, 128000, 144000, 160000 } /* II & III */ 51 64000, 80000, 96000, 112000, 128000, 144000, 160000 } /* II & III */
52}; 52};
53 53
54static 54static
55unsigned int const samplerate_table[3] = { 44100, 48000, 32000 }; 55unsigned int const samplerate_table[3] = { 44100, 48000, 32000 };
56 56
57static 57static
58int (*const decoder_table[3])(struct mad_stream *, struct mad_frame *) = { 58int (*const decoder_table[3])(struct mad_stream *, struct mad_frame *) = {
59 mad_layer_I, 59 mad_layer_I,
60 mad_layer_II, 60 mad_layer_II,
61 mad_layer_III 61 mad_layer_III
62}; 62};
63 63
64/* 64/*
65 * NAME:header->init() 65 * NAME:header->init()
66 * DESCRIPTION:initialize header struct 66 * DESCRIPTION:initialize header struct
67 */ 67 */
68void mad_header_init(struct mad_header *header) 68void mad_header_init(struct mad_header *header)
69{ 69{
70 header->layer = 0; 70 header->layer = 0;
71 header->mode = 0; 71 header->mode = 0;
72 header->mode_extension = 0; 72 header->mode_extension = 0;
73 header->emphasis = 0; 73 header->emphasis = 0;
74 74
75 header->bitrate = 0; 75 header->bitrate = 0;
76 header->samplerate = 0; 76 header->samplerate = 0;
77 77
78 header->crc_check = 0; 78 header->crc_check = 0;
79 header->crc_target = 0; 79 header->crc_target = 0;
80 80
81 header->flags = 0; 81 header->flags = 0;
82 header->private_bits = 0; 82 header->private_bits = 0;
83 83
84 header->duration = mad_timer_zero; 84 header->duration = mad_timer_zero;
85} 85}
86 86
87/* 87/*
88 * NAME:frame->init() 88 * NAME:frame->init()
89 * DESCRIPTION:initialize frame struct 89 * DESCRIPTION:initialize frame struct
90 */ 90 */
91void mad_frame_init(struct mad_frame *frame) 91void mad_frame_init(struct mad_frame *frame)
92{ 92{
93 mad_header_init(&frame->header); 93 mad_header_init(&frame->header);
94 94
95 frame->options = 0; 95 frame->options = 0;
96 96
97 frame->overlap = 0; 97 frame->overlap = 0;
98 mad_frame_mute(frame); 98 mad_frame_mute(frame);
99} 99}
100 100
101/* 101/*
102 * NAME:frame->finish() 102 * NAME:frame->finish()
103 * DESCRIPTION:deallocate any dynamic memory associated with frame 103 * DESCRIPTION:deallocate any dynamic memory associated with frame
104 */ 104 */
105void mad_frame_finish(struct mad_frame *frame) 105void mad_frame_finish(struct mad_frame *frame)
106{ 106{
107 mad_header_finish(&frame->header); 107 mad_header_finish(&frame->header);
108 108
109 if (frame->overlap) { 109 if (frame->overlap) {
110 free(frame->overlap); 110 free(frame->overlap);
111 frame->overlap = 0; 111 frame->overlap = 0;
112 } 112 }
113} 113}
114 114
115/* 115/*
116 * NAME:decode_header() 116 * NAME:decode_header()
117 * DESCRIPTION:read header data and following CRC word 117 * DESCRIPTION:read header data and following CRC word
118 */ 118 */
119static 119static
120int decode_header(struct mad_header *header, struct mad_stream *stream) 120int decode_header(struct mad_header *header, struct mad_stream *stream)
121{ 121{
122 unsigned int index; 122 unsigned int index;
123 123
124 header->flags = 0; 124 header->flags = 0;
125 header->private_bits = 0; 125 header->private_bits = 0;
126 126
127 /* header() */ 127 /* header() */
128 128
129 /* syncword */ 129 /* syncword */
130 mad_bit_skip(&stream->ptr, 11); 130 mad_bit_skip(&stream->ptr, 11);
131 131
132 /* MPEG 2.5 indicator (really part of syncword) */ 132 /* MPEG 2.5 indicator (really part of syncword) */
133 if (mad_bit_read(&stream->ptr, 1) == 0) 133 if (mad_bit_read(&stream->ptr, 1) == 0)
134 header->flags |= MAD_FLAG_MPEG_2_5_EXT; 134 header->flags |= MAD_FLAG_MPEG_2_5_EXT;
135 135
136 /* ID */ 136 /* ID */
137 if (mad_bit_read(&stream->ptr, 1) == 0) 137 if (mad_bit_read(&stream->ptr, 1) == 0)
138 header->flags |= MAD_FLAG_LSF_EXT; 138 header->flags |= MAD_FLAG_LSF_EXT;
139 else if (header->flags & MAD_FLAG_MPEG_2_5_EXT) { 139 else if (header->flags & MAD_FLAG_MPEG_2_5_EXT) {
140 stream->error = MAD_ERROR_LOSTSYNC; 140 stream->error = MAD_ERROR_LOSTSYNC;
141 return -1; 141 return -1;
142 } 142 }
143 143
144 /* layer */ 144 /* layer */
145 header->layer = 4 - mad_bit_read(&stream->ptr, 2); 145 header->layer = 4 - mad_bit_read(&stream->ptr, 2);
146 146
147 if (header->layer == 4) { 147 if (header->layer == 4) {
148 stream->error = MAD_ERROR_BADLAYER; 148 stream->error = MAD_ERROR_BADLAYER;
149 return -1; 149 return -1;
150 } 150 }
151 151
152 /* protection_bit */ 152 /* protection_bit */
153 if (mad_bit_read(&stream->ptr, 1) == 0) { 153 if (mad_bit_read(&stream->ptr, 1) == 0) {
154 header->flags |= MAD_FLAG_PROTECTION; 154 header->flags |= MAD_FLAG_PROTECTION;
155 header->crc_check = mad_bit_crc(stream->ptr, 16, 0xffff); 155 header->crc_check = mad_bit_crc(stream->ptr, 16, 0xffff);
156 } 156 }
157 157
158 /* bitrate_index */ 158 /* bitrate_index */
159 index = mad_bit_read(&stream->ptr, 4); 159 index = mad_bit_read(&stream->ptr, 4);
160 160
161 if (index == 15) { 161 if (index == 15) {
162 stream->error = MAD_ERROR_BADBITRATE; 162 stream->error = MAD_ERROR_BADBITRATE;
163 return -1; 163 return -1;
164 } 164 }
165 165
166 if (header->flags & MAD_FLAG_LSF_EXT) 166 if (header->flags & MAD_FLAG_LSF_EXT)
167 header->bitrate = bitrate_table[3 + (header->layer >> 1)][index]; 167 header->bitrate = bitrate_table[3 + (header->layer >> 1)][index];
168 else 168 else
169 header->bitrate = bitrate_table[header->layer - 1][index]; 169 header->bitrate = bitrate_table[header->layer - 1][index];
170 170
171 /* sampling_frequency */ 171 /* sampling_frequency */
172 index = mad_bit_read(&stream->ptr, 2); 172 index = mad_bit_read(&stream->ptr, 2);
173 173
174 if (index == 3) { 174 if (index == 3) {
175 stream->error = MAD_ERROR_BADSAMPLERATE; 175 stream->error = MAD_ERROR_BADSAMPLERATE;
176 return -1; 176 return -1;
177 } 177 }
178 178
179 header->samplerate = samplerate_table[index]; 179 header->samplerate = samplerate_table[index];
180 180
181 if (header->flags & MAD_FLAG_LSF_EXT) { 181 if (header->flags & MAD_FLAG_LSF_EXT) {
182 header->samplerate /= 2; 182 header->samplerate /= 2;
183 183
184 if (header->flags & MAD_FLAG_MPEG_2_5_EXT) 184 if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
185 header->samplerate /= 2; 185 header->samplerate /= 2;
186 } 186 }
187 187
188 /* padding_bit */ 188 /* padding_bit */
189 if (mad_bit_read(&stream->ptr, 1)) 189 if (mad_bit_read(&stream->ptr, 1))
190 header->flags |= MAD_FLAG_PADDING; 190 header->flags |= MAD_FLAG_PADDING;
191 191
192 /* private_bit */ 192 /* private_bit */
193 if (mad_bit_read(&stream->ptr, 1)) 193 if (mad_bit_read(&stream->ptr, 1))
194 header->private_bits |= MAD_PRIVATE_HEADER; 194 header->private_bits |= MAD_PRIVATE_HEADER;
195 195
196 /* mode */ 196 /* mode */
197 header->mode = 3 - mad_bit_read(&stream->ptr, 2); 197 header->mode = 3 - mad_bit_read(&stream->ptr, 2);
198 198
199 /* mode_extension */ 199 /* mode_extension */
200 header->mode_extension = mad_bit_read(&stream->ptr, 2); 200 header->mode_extension = mad_bit_read(&stream->ptr, 2);
201 201
202 /* copyright */ 202 /* copyright */
203 if (mad_bit_read(&stream->ptr, 1)) 203 if (mad_bit_read(&stream->ptr, 1))
204 header->flags |= MAD_FLAG_COPYRIGHT; 204 header->flags |= MAD_FLAG_COPYRIGHT;
205 205
206 /* original/copy */ 206 /* original/copy */
207 if (mad_bit_read(&stream->ptr, 1)) 207 if (mad_bit_read(&stream->ptr, 1))
208 header->flags |= MAD_FLAG_ORIGINAL; 208 header->flags |= MAD_FLAG_ORIGINAL;
209 209
210 /* emphasis */ 210 /* emphasis */
211 header->emphasis = mad_bit_read(&stream->ptr, 2); 211 header->emphasis = mad_bit_read(&stream->ptr, 2);
212 212
213 if (header->emphasis == 2) { 213 if (header->emphasis == 2) {
214 stream->error = MAD_ERROR_BADEMPHASIS; 214 stream->error = MAD_ERROR_BADEMPHASIS;
215 return -1; 215 return -1;
216 } 216 }
217 217
218 /* error_check() */ 218 /* error_check() */
219 219
220 /* crc_check */ 220 /* crc_check */
221 if (header->flags & MAD_FLAG_PROTECTION) 221 if (header->flags & MAD_FLAG_PROTECTION)
222 header->crc_target = mad_bit_read(&stream->ptr, 16); 222 header->crc_target = mad_bit_read(&stream->ptr, 16);
223 223
224 return 0; 224 return 0;
225} 225}
226 226
227/* 227/*
228 * NAME:free_bitrate() 228 * NAME:free_bitrate()
229 * DESCRIPTION:attempt to discover the bitstream's free bitrate 229 * DESCRIPTION:attempt to discover the bitstream's free bitrate
230 */ 230 */
231static 231static
232int free_bitrate(struct mad_stream *stream, struct mad_header const *header) 232int free_bitrate(struct mad_stream *stream, struct mad_header const *header)
233{ 233{
234 struct mad_bitptr keep_ptr; 234 struct mad_bitptr keep_ptr;
235 unsigned long rate = 0; 235 unsigned long rate = 0;
236 unsigned int pad_slot, slots_per_frame; 236 unsigned int pad_slot, slots_per_frame;
237 unsigned char const *ptr = 0; 237 unsigned char const *ptr = 0;
238 238
239 keep_ptr = stream->ptr; 239 keep_ptr = stream->ptr;
240 240
241 pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0; 241 pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0;
242 slots_per_frame = (header->layer == MAD_LAYER_III && 242 slots_per_frame = (header->layer == MAD_LAYER_III &&
243 (header->flags & MAD_FLAG_LSF_EXT)) ? 72 : 144; 243 (header->flags & MAD_FLAG_LSF_EXT)) ? 72 : 144;
244 244
245 while (mad_stream_sync(stream) == 0) { 245 while (mad_stream_sync(stream) == 0) {
246 struct mad_stream peek_stream; 246 struct mad_stream peek_stream;
247 struct mad_header peek_header; 247 struct mad_header peek_header;
248 248
249 peek_stream = *stream; 249 peek_stream = *stream;
250 peek_header = *header; 250 peek_header = *header;
251 251
252 if (decode_header(&peek_header, &peek_stream) == 0 && 252 if (decode_header(&peek_header, &peek_stream) == 0 &&
253 peek_header.layer == header->layer && 253 peek_header.layer == header->layer &&
254 peek_header.samplerate == header->samplerate) { 254 peek_header.samplerate == header->samplerate) {
255 unsigned int N; 255 unsigned int N;
256 256
257 ptr = mad_bit_nextbyte(&stream->ptr); 257 ptr = mad_bit_nextbyte(&stream->ptr);
258 258
259 N = ptr - stream->this_frame; 259 N = ptr - stream->this_frame;
260 260
261 if (header->layer == MAD_LAYER_I) { 261 if (header->layer == MAD_LAYER_I) {
262 rate = (unsigned long) header->samplerate * 262 rate = (unsigned long) header->samplerate *
263 (N - 4 * pad_slot + 4) / 48 / 1000; 263 (N - 4 * pad_slot + 4) / 48 / 1000;
264 } 264 }
265 else { 265 else {
266 rate = (unsigned long) header->samplerate * 266 rate = (unsigned long) header->samplerate *
267 (N - pad_slot + 1) / slots_per_frame / 1000; 267 (N - pad_slot + 1) / slots_per_frame / 1000;
268 } 268 }
269 269
270 if (rate >= 8) 270 if (rate >= 8)
271 break; 271 break;
272 } 272 }
273 273
274 mad_bit_skip(&stream->ptr, 8); 274 mad_bit_skip(&stream->ptr, 8);
275 } 275 }
276 276
277 stream->ptr = keep_ptr; 277 stream->ptr = keep_ptr;
278 278
279 if (rate < 8 || (header->layer == MAD_LAYER_III && rate > 640)) { 279 if (rate < 8 || (header->layer == MAD_LAYER_III && rate > 640)) {
280 stream->error = MAD_ERROR_LOSTSYNC; 280 stream->error = MAD_ERROR_LOSTSYNC;
281 return -1; 281 return -1;
282 } 282 }
283 283
284 stream->freerate = rate * 1000; 284 stream->freerate = rate * 1000;
285 285
286# if 0 && defined(DEBUG) 286# if 0 && defined(DEBUG)
287 fprintf(stderr, "free bitrate == %lu\n", stream->freerate); 287 fprintf(stderr, "free bitrate == %lu\n", stream->freerate);
288# endif 288# endif
289 289
290 return 0; 290 return 0;
291} 291}
292 292
293/* 293/*
294 * NAME:header->decode() 294 * NAME:header->decode()
295 * DESCRIPTION:read the next frame header from the stream 295 * DESCRIPTION:read the next frame header from the stream
296 */ 296 */
297int mad_header_decode(struct mad_header *header, struct mad_stream *stream) 297int mad_header_decode(struct mad_header *header, struct mad_stream *stream)
298{ 298{
299 register unsigned char const *ptr, *end; 299 register unsigned char const *ptr, *end;
300 unsigned int pad_slot, N; 300 unsigned int pad_slot, N;
301 301
302 ptr = stream->next_frame; 302 ptr = stream->next_frame;
303 end = stream->bufend; 303 end = stream->bufend;
304 304
305 if (ptr == 0) { 305 if (ptr == 0) {
306 stream->error = MAD_ERROR_BUFPTR; 306 stream->error = MAD_ERROR_BUFPTR;
307 goto fail; 307 goto fail;
308 } 308 }
309 309
310 /* stream skip */ 310 /* stream skip */
311 if (stream->skiplen) { 311 if (stream->skiplen) {
312 if (!stream->sync) 312 if (!stream->sync)
313 ptr = stream->this_frame; 313 ptr = stream->this_frame;
314 314
315 if (end - ptr < stream->skiplen) { 315 if (end - ptr < stream->skiplen) {
316 stream->skiplen -= end - ptr; 316 stream->skiplen -= end - ptr;
317 stream->next_frame = end; 317 stream->next_frame = end;
318 318
319 stream->error = MAD_ERROR_BUFLEN; 319 stream->error = MAD_ERROR_BUFLEN;
320 goto fail; 320 goto fail;
321 } 321 }
322 322
323 ptr += stream->skiplen; 323 ptr += stream->skiplen;
324 stream->skiplen = 0; 324 stream->skiplen = 0;
325 325
326 stream->sync = 1; 326 stream->sync = 1;
327 } 327 }
328 328
329 sync: 329 sync:
330 /* synchronize */ 330 /* synchronize */
331 if (stream->sync) { 331 if (stream->sync) {
332 if (end - ptr < MAD_BUFFER_GUARD) { 332 if (end - ptr < MAD_BUFFER_GUARD) {
333 stream->next_frame = ptr; 333 stream->next_frame = ptr;
334 334
335 stream->error = MAD_ERROR_BUFLEN; 335 stream->error = MAD_ERROR_BUFLEN;
336 goto fail; 336 goto fail;
337 } 337 }
338 else if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) { 338 else if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
339 /* mark point where frame sync word was expected */ 339 /* mark point where frame sync word was expected */
340 stream->this_frame = ptr; 340 stream->this_frame = ptr;
341 stream->next_frame = ptr + 1; 341 stream->next_frame = ptr + 1;
342 342
343 stream->error = MAD_ERROR_LOSTSYNC; 343 stream->error = MAD_ERROR_LOSTSYNC;
344 goto fail; 344 goto fail;
345 } 345 }
346 } 346 }
347 else { 347 else {
348 mad_bit_init(&stream->ptr, ptr); 348 mad_bit_init(&stream->ptr, ptr);
349 349
350 if (mad_stream_sync(stream) == -1) { 350 if (mad_stream_sync(stream) == -1) {
351 if (end - stream->next_frame >= MAD_BUFFER_GUARD) 351 if (end - stream->next_frame >= MAD_BUFFER_GUARD)
352 stream->next_frame = end - MAD_BUFFER_GUARD; 352 stream->next_frame = end - MAD_BUFFER_GUARD;
353 353
354 stream->error = MAD_ERROR_BUFLEN; 354 stream->error = MAD_ERROR_BUFLEN;
355 goto fail; 355 goto fail;
356 } 356 }
357 357
358 ptr = mad_bit_nextbyte(&stream->ptr); 358 ptr = mad_bit_nextbyte(&stream->ptr);
359 } 359 }
360 360
361 /* begin processing */ 361 /* begin processing */
362 stream->this_frame = ptr; 362 stream->this_frame = ptr;
363 stream->next_frame = ptr + 1; /* possibly bogus sync word */ 363 stream->next_frame = ptr + 1; /* possibly bogus sync word */
364 364
365 mad_bit_init(&stream->ptr, stream->this_frame); 365 mad_bit_init(&stream->ptr, stream->this_frame);
366 366
367 if (decode_header(header, stream) == -1) 367 if (decode_header(header, stream) == -1)
368 goto fail; 368 goto fail;
369 369
370 /* calculate frame duration */ 370 /* calculate frame duration */
371 mad_timer_set(&header->duration, 0, 371 mad_timer_set(&header->duration, 0,
372 32 * MAD_NSBSAMPLES(header), header->samplerate); 372 32 * MAD_NSBSAMPLES(header), header->samplerate);
373 373
374 /* calculate free bit rate */ 374 /* calculate free bit rate */
375 if (header->bitrate == 0) { 375 if (header->bitrate == 0) {
376 if ((!stream->sync || !stream->freerate) && 376 if ((stream->freerate == 0 || !stream->sync) &&
377 free_bitrate(stream, header) == -1) 377 free_bitrate(stream, header) == -1)
378 goto fail; 378 goto fail;
379 379
380 header->bitrate = stream->freerate; 380 header->bitrate = stream->freerate;
381 header->flags |= MAD_FLAG_FREEFORMAT; 381 header->flags |= MAD_FLAG_FREEFORMAT;
382 } 382 }
383 383
384 /* calculate beginning of next frame */ 384 /* calculate beginning of next frame */
385 pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0; 385 pad_slot = (header->flags & MAD_FLAG_PADDING) ? 1 : 0;
386 386
387 if (header->layer == MAD_LAYER_I) 387 if (header->layer == MAD_LAYER_I)
388 N = ((12 * header->bitrate / header->samplerate) + pad_slot) * 4; 388 N = ((12 * header->bitrate / header->samplerate) + pad_slot) * 4;
389 else { 389 else {
390 unsigned int slots_per_frame; 390 unsigned int slots_per_frame;
391 391
392 slots_per_frame = (header->layer == MAD_LAYER_III && 392 slots_per_frame = (header->layer == MAD_LAYER_III &&
393 (header->flags & MAD_FLAG_LSF_EXT)) ? 72 : 144; 393 (header->flags & MAD_FLAG_LSF_EXT)) ? 72 : 144;
394 394
395 N = (slots_per_frame * header->bitrate / header->samplerate) + pad_slot; 395 N = (slots_per_frame * header->bitrate / header->samplerate) + pad_slot;
396 } 396 }
397 397
398 /* verify there is enough data left in buffer to decode this frame */ 398 /* verify there is enough data left in buffer to decode this frame */
399 if (N + MAD_BUFFER_GUARD > end - stream->this_frame) { 399 if (N + MAD_BUFFER_GUARD > end - stream->this_frame) {
400 stream->next_frame = stream->this_frame; 400 stream->next_frame = stream->this_frame;
401 401
402 stream->error = MAD_ERROR_BUFLEN; 402 stream->error = MAD_ERROR_BUFLEN;
403 goto fail; 403 goto fail;
404 } 404 }
405 405
406 stream->next_frame = stream->this_frame + N; 406 stream->next_frame = stream->this_frame + N;
407 407
408 if (!stream->sync) { 408 if (!stream->sync) {
409 /* check that a valid frame header follows this frame */ 409 /* check that a valid frame header follows this frame */
410 410
411 ptr = stream->next_frame; 411 ptr = stream->next_frame;
412 if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) { 412 if (!(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) {
413 ptr = stream->next_frame = stream->this_frame + 1; 413 ptr = stream->next_frame = stream->this_frame + 1;
414 goto sync; 414 goto sync;
415 } 415 }
416 416
417 stream->sync = 1; 417 stream->sync = 1;
418 } 418 }
419 419
420 header->flags |= MAD_FLAG_INCOMPLETE; 420 header->flags |= MAD_FLAG_INCOMPLETE;
421 421
422 return 0; 422 return 0;
423 423
424 fail: 424 fail:
425 stream->sync = 0; 425 stream->sync = 0;
426 426
427 return -1; 427 return -1;
428} 428}
429 429
430/* 430/*
431 * NAME:frame->decode() 431 * NAME:frame->decode()
432 * DESCRIPTION:decode a single frame from a bitstream 432 * DESCRIPTION:decode a single frame from a bitstream
433 */ 433 */
434int mad_frame_decode(struct mad_frame *frame, struct mad_stream *stream) 434int mad_frame_decode(struct mad_frame *frame, struct mad_stream *stream)
435{ 435{
436 frame->options = stream->options; 436 frame->options = stream->options;
437 437
438 /* header() */ 438 /* header() */
439 /* error_check() */ 439 /* error_check() */
440 440
441 if (!(frame->header.flags & MAD_FLAG_INCOMPLETE) && 441 if (!(frame->header.flags & MAD_FLAG_INCOMPLETE) &&
442 mad_header_decode(&frame->header, stream) == -1) 442 mad_header_decode(&frame->header, stream) == -1)
443 goto fail; 443 goto fail;
444 444
445 /* audio_data() */ 445 /* audio_data() */
446 446
447 frame->header.flags &= ~MAD_FLAG_INCOMPLETE; 447 frame->header.flags &= ~MAD_FLAG_INCOMPLETE;
448 448
449 if (decoder_table[frame->header.layer - 1](stream, frame) == -1) { 449 if (decoder_table[frame->header.layer - 1](stream, frame) == -1) {
450 if (!MAD_RECOVERABLE(stream->error)) 450 if (!MAD_RECOVERABLE(stream->error))
451 stream->next_frame = stream->this_frame; 451 stream->next_frame = stream->this_frame;
452 452
453 goto fail; 453 goto fail;
454 } 454 }
455 455
456 /* ancillary_data() */ 456 /* ancillary_data() */
457 457
458 if (frame->header.layer != MAD_LAYER_III) { 458 if (frame->header.layer != MAD_LAYER_III) {
459 struct mad_bitptr next_frame; 459 struct mad_bitptr next_frame;
460 460
461 mad_bit_init(&next_frame, stream->next_frame); 461 mad_bit_init(&next_frame, stream->next_frame);
462 462
463 stream->anc_ptr = stream->ptr; 463 stream->anc_ptr = stream->ptr;
464 stream->anc_bitlen = mad_bit_length(&stream->ptr, &next_frame); 464 stream->anc_bitlen = mad_bit_length(&stream->ptr, &next_frame);
465 465
466 mad_bit_finish(&next_frame); 466 mad_bit_finish(&next_frame);
467 } 467 }
468 468
469 return 0; 469 return 0;
470 470
471 fail: 471 fail:
472 stream->anc_bitlen = 0; 472 stream->anc_bitlen = 0;
473 return -1; 473 return -1;
474} 474}
475 475
476/* 476/*
477 * NAME:frame->mute() 477 * NAME:frame->mute()
478 * DESCRIPTION:zero all subband values so the frame becomes silent 478 * DESCRIPTION:zero all subband values so the frame becomes silent
479 */ 479 */
480void mad_frame_mute(struct mad_frame *frame) 480void mad_frame_mute(struct mad_frame *frame)
481{ 481{
482 unsigned int s, sb; 482 unsigned int s, sb;
483 483
484 for (s = 0; s < 36; ++s) { 484 for (s = 0; s < 36; ++s) {
485 for (sb = 0; sb < 32; ++sb) { 485 for (sb = 0; sb < 32; ++sb) {
486 frame->sbsample[0][s][sb] = 486 frame->sbsample[0][s][sb] =
487 frame->sbsample[1][s][sb] = 0; 487 frame->sbsample[1][s][sb] = 0;
488 } 488 }
489 } 489 }
490 490
491 if (frame->overlap) { 491 if (frame->overlap) {
492 for (s = 0; s < 18; ++s) { 492 for (s = 0; s < 18; ++s) {
493 for (sb = 0; sb < 32; ++sb) { 493 for (sb = 0; sb < 32; ++sb) {
494 (*frame->overlap)[0][sb][s] = 494 (*frame->overlap)[0][sb][s] =
495 (*frame->overlap)[1][sb][s] = 0; 495 (*frame->overlap)[1][sb][s] = 0;
496 } 496 }
497 } 497 }
498 } 498 }
499} 499}
diff --git a/core/multimedia/opieplayer/libmad/frame.h b/core/multimedia/opieplayer/libmad/frame.h
index e88d0c8..3b8e454 100644
--- a/core/multimedia/opieplayer/libmad/frame.h
+++ b/core/multimedia/opieplayer/libmad/frame.h
@@ -1,115 +1,117 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# ifndef LIBMAD_FRAME_H 22# ifndef LIBMAD_FRAME_H
23# define LIBMAD_FRAME_H 23# define LIBMAD_FRAME_H
24 24
25# include "fixed.h" 25# include "fixed.h"
26# include "timer.h" 26# include "timer.h"
27# include "stream.h" 27# include "stream.h"
28 28
29enum mad_layer { 29enum mad_layer {
30 MAD_LAYER_I = 1, /* Layer I */ 30 MAD_LAYER_I = 1, /* Layer I */
31 MAD_LAYER_II = 2, /* Layer II */ 31 MAD_LAYER_II = 2, /* Layer II */
32 MAD_LAYER_III = 3 /* Layer III */ 32 MAD_LAYER_III = 3 /* Layer III */
33}; 33};
34 34
35enum mad_mode { 35enum mad_mode {
36 MAD_MODE_SINGLE_CHANNEL = 0, /* single channel */ 36 MAD_MODE_SINGLE_CHANNEL = 0, /* single channel */
37 MAD_MODE_DUAL_CHANNEL = 1, /* dual channel */ 37 MAD_MODE_DUAL_CHANNEL = 1, /* dual channel */
38 MAD_MODE_JOINT_STEREO = 2, /* joint (MS/intensity) stereo */ 38 MAD_MODE_JOINT_STEREO = 2, /* joint (MS/intensity) stereo */
39 MAD_MODE_STEREO = 3 /* normal LR stereo */ 39 MAD_MODE_STEREO = 3 /* normal LR stereo */
40}; 40};
41 41
42enum mad_emphasis { 42enum mad_emphasis {
43 MAD_EMPHASIS_NONE = 0, /* no emphasis */ 43 MAD_EMPHASIS_NONE = 0, /* no emphasis */
44 MAD_EMPHASIS_50_15_US = 1, /* 50/15 microseconds emphasis */ 44 MAD_EMPHASIS_50_15_US = 1, /* 50/15 microseconds emphasis */
45 MAD_EMPHASIS_CCITT_J_17 = 3 /* CCITT J.17 emphasis */ 45 MAD_EMPHASIS_CCITT_J_17 = 3 /* CCITT J.17 emphasis */
46}; 46};
47 47
48struct mad_frame { 48struct mad_header {
49 struct mad_header { 49 enum mad_layer layer; /* audio layer (1, 2, or 3) */
50 enum mad_layer layer; /* audio layer (1, 2, or 3) */ 50 enum mad_mode mode; /* channel mode (see above) */
51 enum mad_mode mode; /* channel mode (see above) */ 51 int mode_extension; /* additional mode info */
52 int mode_extension; /* additional mode info */ 52 enum mad_emphasis emphasis; /* de-emphasis to use (see above) */
53 enum mad_emphasis emphasis; /* de-emphasis to use (see above) */ 53
54 unsigned long bitrate; /* stream bitrate (bps) */
55 unsigned int samplerate; /* sampling frequency (Hz) */
54 56
55 unsigned long bitrate; /* stream bitrate (bps) */ 57 unsigned short crc_check; /* frame CRC accumulator */
56 unsigned int samplerate; /* sampling frequency (Hz) */ 58 unsigned short crc_target; /* final target CRC checksum */
57 59
58 unsigned short crc_check; /* frame CRC accumulator */ 60 int flags; /* flags (see below) */
59 unsigned short crc_target; /* final target CRC checksum */ 61 int private_bits; /* private bits (see below) */
60 62
61 int flags; /* flags (see below) */ 63 mad_timer_t duration; /* audio playing time of frame */
62 int private_bits; /* private bits (see below) */ 64};
63 65
64 mad_timer_t duration; /* audio playing time of frame */ 66struct mad_frame {
65 } header; 67 struct mad_header header; /* MPEG audio header */
66 68
67 int options; /* decoding options (from stream) */ 69 int options; /* decoding options (from stream) */
68 70
69 mad_fixed_t sbsample[2][36][32];/* synthesis subband filter samples */ 71 mad_fixed_t sbsample[2][36][32];/* synthesis subband filter samples */
70 mad_fixed_t (*overlap)[2][32][18];/* Layer III block overlap data */ 72 mad_fixed_t (*overlap)[2][32][18];/* Layer III block overlap data */
71}; 73};
72 74
73 # define MAD_NCHANNELS(header) ((header)->mode ? 2 : 1) 75 # define MAD_NCHANNELS(header) ((header)->mode ? 2 : 1)
74# define MAD_NSBSAMPLES(header) \ 76# define MAD_NSBSAMPLES(header) \
75 ((header)->layer == MAD_LAYER_I ? 12 : \ 77 ((header)->layer == MAD_LAYER_I ? 12 : \
76 (((header)->layer == MAD_LAYER_III && \ 78 (((header)->layer == MAD_LAYER_III && \
77 ((header)->flags & MAD_FLAG_LSF_EXT)) ? 18 : 36)) 79 ((header)->flags & MAD_FLAG_LSF_EXT)) ? 18 : 36))
78 80
79enum { 81enum {
80 MAD_FLAG_NPRIVATE_III = 0x0007,/* number of Layer III private bits */ 82 MAD_FLAG_NPRIVATE_III = 0x0007,/* number of Layer III private bits */
81 MAD_FLAG_INCOMPLETE = 0x0008,/* header but not data is decoded */ 83 MAD_FLAG_INCOMPLETE = 0x0008,/* header but not data is decoded */
82 84
83 MAD_FLAG_PROTECTION = 0x0010,/* frame has CRC protection */ 85 MAD_FLAG_PROTECTION = 0x0010,/* frame has CRC protection */
84 MAD_FLAG_COPYRIGHT = 0x0020,/* frame is copyright */ 86 MAD_FLAG_COPYRIGHT = 0x0020,/* frame is copyright */
85 MAD_FLAG_ORIGINAL = 0x0040,/* frame is original (else copy) */ 87 MAD_FLAG_ORIGINAL = 0x0040,/* frame is original (else copy) */
86 MAD_FLAG_PADDING = 0x0080,/* frame has additional slot */ 88 MAD_FLAG_PADDING = 0x0080,/* frame has additional slot */
87 89
88 MAD_FLAG_I_STEREO = 0x0100,/* uses intensity joint stereo */ 90 MAD_FLAG_I_STEREO = 0x0100,/* uses intensity joint stereo */
89 MAD_FLAG_MS_STEREO = 0x0200,/* uses middle/side joint stereo */ 91 MAD_FLAG_MS_STEREO = 0x0200,/* uses middle/side joint stereo */
90 MAD_FLAG_FREEFORMAT = 0x0400,/* uses free format bitrate */ 92 MAD_FLAG_FREEFORMAT = 0x0400,/* uses free format bitrate */
91 93
92 MAD_FLAG_LSF_EXT = 0x1000,/* lower sampling freq. extension */ 94 MAD_FLAG_LSF_EXT = 0x1000,/* lower sampling freq. extension */
93 MAD_FLAG_MC_EXT = 0x2000,/* multichannel audio extension */ 95 MAD_FLAG_MC_EXT = 0x2000,/* multichannel audio extension */
94 MAD_FLAG_MPEG_2_5_EXT = 0x4000/* MPEG 2.5 (unofficial) extension */ 96 MAD_FLAG_MPEG_2_5_EXT = 0x4000/* MPEG 2.5 (unofficial) extension */
95}; 97};
96 98
97enum { 99enum {
98 MAD_PRIVATE_HEADER = 0x0100,/* header private bit */ 100 MAD_PRIVATE_HEADER = 0x0100,/* header private bit */
99 MAD_PRIVATE_III = 0x001f/* Layer III private bits (up to 5) */ 101 MAD_PRIVATE_III = 0x001f/* Layer III private bits (up to 5) */
100}; 102};
101 103
102void mad_header_init(struct mad_header *); 104void mad_header_init(struct mad_header *);
103 105
104# define mad_header_finish(header) /* nothing */ 106# define mad_header_finish(header) /* nothing */
105 107
106int mad_header_decode(struct mad_header *, struct mad_stream *); 108int mad_header_decode(struct mad_header *, struct mad_stream *);
107 109
108void mad_frame_init(struct mad_frame *); 110void mad_frame_init(struct mad_frame *);
109void mad_frame_finish(struct mad_frame *); 111void mad_frame_finish(struct mad_frame *);
110 112
111int mad_frame_decode(struct mad_frame *, struct mad_stream *); 113int mad_frame_decode(struct mad_frame *, struct mad_stream *);
112 114
113void mad_frame_mute(struct mad_frame *); 115void mad_frame_mute(struct mad_frame *);
114 116
115# endif 117# endif
diff --git a/core/multimedia/opieplayer/libmad/huffman.c b/core/multimedia/opieplayer/libmad/huffman.c
index 8ec9499..5ea6547 100644
--- a/core/multimedia/opieplayer/libmad/huffman.c
+++ b/core/multimedia/opieplayer/libmad/huffman.c
@@ -1,296 +1,307 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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
28# include "huffman.h" 28# include "huffman.h"
29 29
30/* 30/*
31 * These are the Huffman code words for Layer III. 31 * These are the Huffman code words for Layer III.
32 * The data for these tables are derived from Table B.7 of ISO/IEC 11172-3. 32 * The data for these tables are derived from Table B.7 of ISO/IEC 11172-3.
33 * 33 *
34 * These tables support decoding up to 4 Huffman code bits at a time. 34 * These tables support decoding up to 4 Huffman code bits at a time.
35 */ 35 */
36 36
37 # define V(v, w, x, y, hlen){ { 1, hlen, v, w, x, y } } 37# if defined(__GNUC__)
38 # define PTR(offs, bits){ ptr: { 0, bits, offs } } 38 # define PTR(offs, bits){ ptr: { 0, bits, offs } }
39 # define V(v, w, x, y, hlen){ value: { 1, hlen, v, w, x, y } }
40# else
41 # define PTR(offs, bits){ { 0, bits, offs } }
42 # define V(v, w, x, y, hlen){ { 1, hlen, (v << 0) | (w << 1) | \
43 (x << 2) | (y << 3) } }
44# endif
39 45
40static 46static
41union huffquad const hufftabA[] = { 47union huffquad const hufftabA[] = {
42 /* 0000 */ PTR(16, 2), 48 /* 0000 */ PTR(16, 2),
43 /* 0001 */ PTR(20, 2), 49 /* 0001 */ PTR(20, 2),
44 /* 0010 */ PTR(24, 1), 50 /* 0010 */ PTR(24, 1),
45 /* 0011 */ PTR(26, 1), 51 /* 0011 */ PTR(26, 1),
46 /* 0100 */ V(0, 0, 1, 0, 4), 52 /* 0100 */ V(0, 0, 1, 0, 4),
47 /* 0101 */ V(0, 0, 0, 1, 4), 53 /* 0101 */ V(0, 0, 0, 1, 4),
48 /* 0110 */ V(0, 1, 0, 0, 4), 54 /* 0110 */ V(0, 1, 0, 0, 4),
49 /* 0111 */ V(1, 0, 0, 0, 4), 55 /* 0111 */ V(1, 0, 0, 0, 4),
50 /* 1000 */ V(0, 0, 0, 0, 1), 56 /* 1000 */ V(0, 0, 0, 0, 1),
51 /* 1001 */ V(0, 0, 0, 0, 1), 57 /* 1001 */ V(0, 0, 0, 0, 1),
52 /* 1010 */ V(0, 0, 0, 0, 1), 58 /* 1010 */ V(0, 0, 0, 0, 1),
53 /* 1011 */ V(0, 0, 0, 0, 1), 59 /* 1011 */ V(0, 0, 0, 0, 1),
54 /* 1100 */ V(0, 0, 0, 0, 1), 60 /* 1100 */ V(0, 0, 0, 0, 1),
55 /* 1101 */ V(0, 0, 0, 0, 1), 61 /* 1101 */ V(0, 0, 0, 0, 1),
56 /* 1110 */ V(0, 0, 0, 0, 1), 62 /* 1110 */ V(0, 0, 0, 0, 1),
57 /* 1111 */ V(0, 0, 0, 0, 1), 63 /* 1111 */ V(0, 0, 0, 0, 1),
58 64
59 /* 0000 ... */ 65 /* 0000 ... */
60 /* 00 */ V(1, 0, 1, 1, 2),/* 16 */ 66 /* 00 */ V(1, 0, 1, 1, 2),/* 16 */
61 /* 01 */ V(1, 1, 1, 1, 2), 67 /* 01 */ V(1, 1, 1, 1, 2),
62 /* 10 */ V(1, 1, 0, 1, 2), 68 /* 10 */ V(1, 1, 0, 1, 2),
63 /* 11 */ V(1, 1, 1, 0, 2), 69 /* 11 */ V(1, 1, 1, 0, 2),
64 70
65 /* 0001 ... */ 71 /* 0001 ... */
66 /* 00 */ V(0, 1, 1, 1, 2),/* 20 */ 72 /* 00 */ V(0, 1, 1, 1, 2),/* 20 */
67 /* 01 */ V(0, 1, 0, 1, 2), 73 /* 01 */ V(0, 1, 0, 1, 2),
68 /* 10 */ V(1, 0, 0, 1, 1), 74 /* 10 */ V(1, 0, 0, 1, 1),
69 /* 11 */ V(1, 0, 0, 1, 1), 75 /* 11 */ V(1, 0, 0, 1, 1),
70 76
71 /* 0010 ... */ 77 /* 0010 ... */
72 /* 0 */ V(0, 1, 1, 0, 1),/* 24 */ 78 /* 0 */ V(0, 1, 1, 0, 1),/* 24 */
73 /* 1 */ V(0, 0, 1, 1, 1), 79 /* 1 */ V(0, 0, 1, 1, 1),
74 80
75 /* 0011 ... */ 81 /* 0011 ... */
76 /* 0 */ V(1, 0, 1, 0, 1),/* 26 */ 82 /* 0 */ V(1, 0, 1, 0, 1),/* 26 */
77 /* 1 */ V(1, 1, 0, 0, 1) 83 /* 1 */ V(1, 1, 0, 0, 1)
78}; 84};
79 85
80static 86static
81union huffquad const hufftabB[] = { 87union huffquad const hufftabB[] = {
82 /* 0000 */ V(1, 1, 1, 1, 4), 88 /* 0000 */ V(1, 1, 1, 1, 4),
83 /* 0001 */ V(1, 1, 1, 0, 4), 89 /* 0001 */ V(1, 1, 1, 0, 4),
84 /* 0010 */ V(1, 1, 0, 1, 4), 90 /* 0010 */ V(1, 1, 0, 1, 4),
85 /* 0011 */ V(1, 1, 0, 0, 4), 91 /* 0011 */ V(1, 1, 0, 0, 4),
86 /* 0100 */ V(1, 0, 1, 1, 4), 92 /* 0100 */ V(1, 0, 1, 1, 4),
87 /* 0101 */ V(1, 0, 1, 0, 4), 93 /* 0101 */ V(1, 0, 1, 0, 4),
88 /* 0110 */ V(1, 0, 0, 1, 4), 94 /* 0110 */ V(1, 0, 0, 1, 4),
89 /* 0111 */ V(1, 0, 0, 0, 4), 95 /* 0111 */ V(1, 0, 0, 0, 4),
90 /* 1000 */ V(0, 1, 1, 1, 4), 96 /* 1000 */ V(0, 1, 1, 1, 4),
91 /* 1001 */ V(0, 1, 1, 0, 4), 97 /* 1001 */ V(0, 1, 1, 0, 4),
92 /* 1010 */ V(0, 1, 0, 1, 4), 98 /* 1010 */ V(0, 1, 0, 1, 4),
93 /* 1011 */ V(0, 1, 0, 0, 4), 99 /* 1011 */ V(0, 1, 0, 0, 4),
94 /* 1100 */ V(0, 0, 1, 1, 4), 100 /* 1100 */ V(0, 0, 1, 1, 4),
95 /* 1101 */ V(0, 0, 1, 0, 4), 101 /* 1101 */ V(0, 0, 1, 0, 4),
96 /* 1110 */ V(0, 0, 0, 1, 4), 102 /* 1110 */ V(0, 0, 0, 1, 4),
97 /* 1111 */ V(0, 0, 0, 0, 4) 103 /* 1111 */ V(0, 0, 0, 0, 4)
98}; 104};
99 105
100# undef V 106# undef V
101# undef PTR 107# undef PTR
102 108
103 # define V(x, y, hlen) { { 1, hlen, x, y } } 109# if defined(__GNUC__)
104 # define PTR(offs, bits){ ptr: { 0, bits, offs } } 110 # define PTR(offs, bits){ ptr: { 0, bits, offs } }
111 # define V(x, y, hlen) { value: { 1, hlen, x, y } }
112# else
113 # define PTR(offs, bits){ { 0, bits, offs } }
114 # define V(x, y, hlen) { { 1, hlen, (x << 0) | (y << 4) } }
115# endif
105 116
106static 117static
107union huffpair const hufftab0[] = { 118union huffpair const hufftab0[] = {
108 /* */ V(0, 0, 0) 119 /* */ V(0, 0, 0)
109}; 120};
110 121
111static 122static
112union huffpair const hufftab1[] = { 123union huffpair const hufftab1[] = {
113 /* 000 */ V(1, 1, 3), 124 /* 000 */ V(1, 1, 3),
114 /* 001 */ V(0, 1, 3), 125 /* 001 */ V(0, 1, 3),
115 /* 010 */ V(1, 0, 2), 126 /* 010 */ V(1, 0, 2),
116 /* 011 */ V(1, 0, 2), 127 /* 011 */ V(1, 0, 2),
117 /* 100 */ V(0, 0, 1), 128 /* 100 */ V(0, 0, 1),
118 /* 101 */ V(0, 0, 1), 129 /* 101 */ V(0, 0, 1),
119 /* 110 */ V(0, 0, 1), 130 /* 110 */ V(0, 0, 1),
120 /* 111 */ V(0, 0, 1) 131 /* 111 */ V(0, 0, 1)
121}; 132};
122 133
123static 134static
124union huffpair const hufftab2[] = { 135union huffpair const hufftab2[] = {
125 /* 000 */ PTR(8, 3), 136 /* 000 */ PTR(8, 3),
126 /* 001 */ V(1, 1, 3), 137 /* 001 */ V(1, 1, 3),
127 /* 010 */ V(0, 1, 3), 138 /* 010 */ V(0, 1, 3),
128 /* 011 */ V(1, 0, 3), 139 /* 011 */ V(1, 0, 3),
129 /* 100 */ V(0, 0, 1), 140 /* 100 */ V(0, 0, 1),
130 /* 101 */ V(0, 0, 1), 141 /* 101 */ V(0, 0, 1),
131 /* 110 */ V(0, 0, 1), 142 /* 110 */ V(0, 0, 1),
132 /* 111 */ V(0, 0, 1), 143 /* 111 */ V(0, 0, 1),
133 144
134 /* 000 ... */ 145 /* 000 ... */
135 /* 000 */ V(2, 2, 3),/* 8 */ 146 /* 000 */ V(2, 2, 3),/* 8 */
136 /* 001 */ V(0, 2, 3), 147 /* 001 */ V(0, 2, 3),
137 /* 010 */ V(1, 2, 2), 148 /* 010 */ V(1, 2, 2),
138 /* 011 */ V(1, 2, 2), 149 /* 011 */ V(1, 2, 2),
139 /* 100 */ V(2, 1, 2), 150 /* 100 */ V(2, 1, 2),
140 /* 101 */ V(2, 1, 2), 151 /* 101 */ V(2, 1, 2),
141 /* 110 */ V(2, 0, 2), 152 /* 110 */ V(2, 0, 2),
142 /* 111 */ V(2, 0, 2) 153 /* 111 */ V(2, 0, 2)
143}; 154};
144 155
145static 156static
146union huffpair const hufftab3[] = { 157union huffpair const hufftab3[] = {
147 /* 000 */ PTR(8, 3), 158 /* 000 */ PTR(8, 3),
148 /* 001 */ V(1, 0, 3), 159 /* 001 */ V(1, 0, 3),
149 /* 010 */ V(1, 1, 2), 160 /* 010 */ V(1, 1, 2),
150 /* 011 */ V(1, 1, 2), 161 /* 011 */ V(1, 1, 2),
151 /* 100 */ V(0, 1, 2), 162 /* 100 */ V(0, 1, 2),
152 /* 101 */ V(0, 1, 2), 163 /* 101 */ V(0, 1, 2),
153 /* 110 */ V(0, 0, 2), 164 /* 110 */ V(0, 0, 2),
154 /* 111 */ V(0, 0, 2), 165 /* 111 */ V(0, 0, 2),
155 166
156 /* 000 ... */ 167 /* 000 ... */
157 /* 000 */ V(2, 2, 3),/* 8 */ 168 /* 000 */ V(2, 2, 3),/* 8 */
158 /* 001 */ V(0, 2, 3), 169 /* 001 */ V(0, 2, 3),
159 /* 010 */ V(1, 2, 2), 170 /* 010 */ V(1, 2, 2),
160 /* 011 */ V(1, 2, 2), 171 /* 011 */ V(1, 2, 2),
161 /* 100 */ V(2, 1, 2), 172 /* 100 */ V(2, 1, 2),
162 /* 101 */ V(2, 1, 2), 173 /* 101 */ V(2, 1, 2),
163 /* 110 */ V(2, 0, 2), 174 /* 110 */ V(2, 0, 2),
164 /* 111 */ V(2, 0, 2) 175 /* 111 */ V(2, 0, 2)
165}; 176};
166 177
167static 178static
168union huffpair const hufftab5[] = { 179union huffpair const hufftab5[] = {
169 /* 000 */ PTR(8, 4), 180 /* 000 */ PTR(8, 4),
170 /* 001 */ V(1, 1, 3), 181 /* 001 */ V(1, 1, 3),
171 /* 010 */ V(0, 1, 3), 182 /* 010 */ V(0, 1, 3),
172 /* 011 */ V(1, 0, 3), 183 /* 011 */ V(1, 0, 3),
173 /* 100 */ V(0, 0, 1), 184 /* 100 */ V(0, 0, 1),
174 /* 101 */ V(0, 0, 1), 185 /* 101 */ V(0, 0, 1),
175 /* 110 */ V(0, 0, 1), 186 /* 110 */ V(0, 0, 1),
176 /* 111 */ V(0, 0, 1), 187 /* 111 */ V(0, 0, 1),
177 188
178 /* 000 ... */ 189 /* 000 ... */
179 /* 0000 */ PTR(24, 1),/* 8 */ 190 /* 0000 */ PTR(24, 1),/* 8 */
180 /* 0001 */ V(3, 2, 4), 191 /* 0001 */ V(3, 2, 4),
181 /* 0010 */ V(3, 1, 3), 192 /* 0010 */ V(3, 1, 3),
182 /* 0011 */ V(3, 1, 3), 193 /* 0011 */ V(3, 1, 3),
183 /* 0100 */ V(1, 3, 4), 194 /* 0100 */ V(1, 3, 4),
184 /* 0101 */ V(0, 3, 4), 195 /* 0101 */ V(0, 3, 4),
185 /* 0110 */ V(3, 0, 4), 196 /* 0110 */ V(3, 0, 4),
186 /* 0111 */ V(2, 2, 4), 197 /* 0111 */ V(2, 2, 4),
187 /* 1000 */ V(1, 2, 3), 198 /* 1000 */ V(1, 2, 3),
188 /* 1001 */ V(1, 2, 3), 199 /* 1001 */ V(1, 2, 3),
189 /* 1010 */ V(2, 1, 3), 200 /* 1010 */ V(2, 1, 3),
190 /* 1011 */ V(2, 1, 3), 201 /* 1011 */ V(2, 1, 3),
191 /* 1100 */ V(0, 2, 3), 202 /* 1100 */ V(0, 2, 3),
192 /* 1101 */ V(0, 2, 3), 203 /* 1101 */ V(0, 2, 3),
193 /* 1110 */ V(2, 0, 3), 204 /* 1110 */ V(2, 0, 3),
194 /* 1111 */ V(2, 0, 3), 205 /* 1111 */ V(2, 0, 3),
195 206
196 /* 000 0000 ... */ 207 /* 000 0000 ... */
197 /* 0 */ V(3, 3, 1),/* 24 */ 208 /* 0 */ V(3, 3, 1),/* 24 */
198 /* 1 */ V(2, 3, 1) 209 /* 1 */ V(2, 3, 1)
199}; 210};
200 211
201static 212static
202union huffpair const hufftab6[] = { 213union huffpair const hufftab6[] = {
203 /* 0000 */ PTR(16, 3), 214 /* 0000 */ PTR(16, 3),
204 /* 0001 */ PTR(24, 1), 215 /* 0001 */ PTR(24, 1),
205 /* 0010 */ PTR(26, 1), 216 /* 0010 */ PTR(26, 1),
206 /* 0011 */ V(1, 2, 4), 217 /* 0011 */ V(1, 2, 4),
207 /* 0100 */ V(2, 1, 4), 218 /* 0100 */ V(2, 1, 4),
208 /* 0101 */ V(2, 0, 4), 219 /* 0101 */ V(2, 0, 4),
209 /* 0110 */ V(0, 1, 3), 220 /* 0110 */ V(0, 1, 3),
210 /* 0111 */ V(0, 1, 3), 221 /* 0111 */ V(0, 1, 3),
211 /* 1000 */ V(1, 1, 2), 222 /* 1000 */ V(1, 1, 2),
212 /* 1001 */ V(1, 1, 2), 223 /* 1001 */ V(1, 1, 2),
213 /* 1010 */ V(1, 1, 2), 224 /* 1010 */ V(1, 1, 2),
214 /* 1011 */ V(1, 1, 2), 225 /* 1011 */ V(1, 1, 2),
215 /* 1100 */ V(1, 0, 3), 226 /* 1100 */ V(1, 0, 3),
216 /* 1101 */ V(1, 0, 3), 227 /* 1101 */ V(1, 0, 3),
217 /* 1110 */ V(0, 0, 3), 228 /* 1110 */ V(0, 0, 3),
218 /* 1111 */ V(0, 0, 3), 229 /* 1111 */ V(0, 0, 3),
219 230
220 /* 0000 ... */ 231 /* 0000 ... */
221 /* 000 */ V(3, 3, 3),/* 16 */ 232 /* 000 */ V(3, 3, 3),/* 16 */
222 /* 001 */ V(0, 3, 3), 233 /* 001 */ V(0, 3, 3),
223 /* 010 */ V(2, 3, 2), 234 /* 010 */ V(2, 3, 2),
224 /* 011 */ V(2, 3, 2), 235 /* 011 */ V(2, 3, 2),
225 /* 100 */ V(3, 2, 2), 236 /* 100 */ V(3, 2, 2),
226 /* 101 */ V(3, 2, 2), 237 /* 101 */ V(3, 2, 2),
227 /* 110 */ V(3, 0, 2), 238 /* 110 */ V(3, 0, 2),
228 /* 111 */ V(3, 0, 2), 239 /* 111 */ V(3, 0, 2),
229 240
230 /* 0001 ... */ 241 /* 0001 ... */
231 /* 0 */ V(1, 3, 1),/* 24 */ 242 /* 0 */ V(1, 3, 1),/* 24 */
232 /* 1 */ V(3, 1, 1), 243 /* 1 */ V(3, 1, 1),
233 244
234 /* 0010 ... */ 245 /* 0010 ... */
235 /* 0 */ V(2, 2, 1),/* 26 */ 246 /* 0 */ V(2, 2, 1),/* 26 */
236 /* 1 */ V(0, 2, 1) 247 /* 1 */ V(0, 2, 1)
237}; 248};
238 249
239static 250static
240union huffpair const hufftab7[] = { 251union huffpair const hufftab7[] = {
241 /* 0000 */ PTR(16, 4), 252 /* 0000 */ PTR(16, 4),
242 /* 0001 */ PTR(32, 4), 253 /* 0001 */ PTR(32, 4),
243 /* 0010 */ PTR(48, 2), 254 /* 0010 */ PTR(48, 2),
244 /* 0011 */ V(1, 1, 4), 255 /* 0011 */ V(1, 1, 4),
245 /* 0100 */ V(0, 1, 3), 256 /* 0100 */ V(0, 1, 3),
246 /* 0101 */ V(0, 1, 3), 257 /* 0101 */ V(0, 1, 3),
247 /* 0110 */ V(1, 0, 3), 258 /* 0110 */ V(1, 0, 3),
248 /* 0111 */ V(1, 0, 3), 259 /* 0111 */ V(1, 0, 3),
249 /* 1000 */ V(0, 0, 1), 260 /* 1000 */ V(0, 0, 1),
250 /* 1001 */ V(0, 0, 1), 261 /* 1001 */ V(0, 0, 1),
251 /* 1010 */ V(0, 0, 1), 262 /* 1010 */ V(0, 0, 1),
252 /* 1011 */ V(0, 0, 1), 263 /* 1011 */ V(0, 0, 1),
253 /* 1100 */ V(0, 0, 1), 264 /* 1100 */ V(0, 0, 1),
254 /* 1101 */ V(0, 0, 1), 265 /* 1101 */ V(0, 0, 1),
255 /* 1110 */ V(0, 0, 1), 266 /* 1110 */ V(0, 0, 1),
256 /* 1111 */ V(0, 0, 1), 267 /* 1111 */ V(0, 0, 1),
257 268
258 /* 0000 ... */ 269 /* 0000 ... */
259 /* 0000 */ PTR(52, 2),/* 16 */ 270 /* 0000 */ PTR(52, 2),/* 16 */
260 /* 0001 */ PTR(56, 1), 271 /* 0001 */ PTR(56, 1),
261 /* 0010 */ PTR(58, 1), 272 /* 0010 */ PTR(58, 1),
262 /* 0011 */ V(1, 5, 4), 273 /* 0011 */ V(1, 5, 4),
263 /* 0100 */ V(5, 1, 4), 274 /* 0100 */ V(5, 1, 4),
264 /* 0101 */ PTR(60, 1), 275 /* 0101 */ PTR(60, 1),
265 /* 0110 */ V(5, 0, 4), 276 /* 0110 */ V(5, 0, 4),
266 /* 0111 */ PTR(62, 1), 277 /* 0111 */ PTR(62, 1),
267 /* 1000 */ V(2, 4, 4), 278 /* 1000 */ V(2, 4, 4),
268 /* 1001 */ V(4, 2, 4), 279 /* 1001 */ V(4, 2, 4),
269 /* 1010 */ V(1, 4, 3), 280 /* 1010 */ V(1, 4, 3),
270 /* 1011 */ V(1, 4, 3), 281 /* 1011 */ V(1, 4, 3),
271 /* 1100 */ V(4, 1, 3), 282 /* 1100 */ V(4, 1, 3),
272 /* 1101 */ V(4, 1, 3), 283 /* 1101 */ V(4, 1, 3),
273 /* 1110 */ V(4, 0, 3), 284 /* 1110 */ V(4, 0, 3),
274 /* 1111 */ V(4, 0, 3), 285 /* 1111 */ V(4, 0, 3),
275 286
276 /* 0001 ... */ 287 /* 0001 ... */
277 /* 0000 */ V(0, 4, 4),/* 32 */ 288 /* 0000 */ V(0, 4, 4),/* 32 */
278 /* 0001 */ V(2, 3, 4), 289 /* 0001 */ V(2, 3, 4),
279 /* 0010 */ V(3, 2, 4), 290 /* 0010 */ V(3, 2, 4),
280 /* 0011 */ V(0, 3, 4), 291 /* 0011 */ V(0, 3, 4),
281 /* 0100 */ V(1, 3, 3), 292 /* 0100 */ V(1, 3, 3),
282 /* 0101 */ V(1, 3, 3), 293 /* 0101 */ V(1, 3, 3),
283 /* 0110 */ V(3, 1, 3), 294 /* 0110 */ V(3, 1, 3),
284 /* 0111 */ V(3, 1, 3), 295 /* 0111 */ V(3, 1, 3),
285 /* 1000 */ V(3, 0, 3), 296 /* 1000 */ V(3, 0, 3),
286 /* 1001 */ V(3, 0, 3), 297 /* 1001 */ V(3, 0, 3),
287 /* 1010 */ V(2, 2, 3), 298 /* 1010 */ V(2, 2, 3),
288 /* 1011 */ V(2, 2, 3), 299 /* 1011 */ V(2, 2, 3),
289 /* 1100 */ V(1, 2, 2), 300 /* 1100 */ V(1, 2, 2),
290 /* 1101 */ V(1, 2, 2), 301 /* 1101 */ V(1, 2, 2),
291 /* 1110 */ V(1, 2, 2), 302 /* 1110 */ V(1, 2, 2),
292 /* 1111 */ V(1, 2, 2), 303 /* 1111 */ V(1, 2, 2),
293 304
294 /* 0010 ... */ 305 /* 0010 ... */
295 /* 00 */ V(2, 1, 1),/* 48 */ 306 /* 00 */ V(2, 1, 1),/* 48 */
296 /* 01 */ V(2, 1, 1), 307 /* 01 */ V(2, 1, 1),
diff --git a/core/multimedia/opieplayer/libmad/huffman.h b/core/multimedia/opieplayer/libmad/huffman.h
index 1801210..d051949 100644
--- a/core/multimedia/opieplayer/libmad/huffman.h
+++ b/core/multimedia/opieplayer/libmad/huffman.h
@@ -1,66 +1,66 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# ifndef LIBMAD_HUFFMAN_H 22# ifndef LIBMAD_HUFFMAN_H
23# define LIBMAD_HUFFMAN_H 23# define LIBMAD_HUFFMAN_H
24 24
25union huffquad { 25union huffquad {
26 struct { 26 struct {
27 unsigned short final : 1; 27 unsigned short final : 1;
28 unsigned short bits : 3;
29 unsigned short offset : 12;
30 } ptr;
31 struct {
32 unsigned short final : 1;
28 unsigned short hlen : 3; 33 unsigned short hlen : 3;
29 unsigned short v : 1; 34 unsigned short v : 1;
30 unsigned short w : 1; 35 unsigned short w : 1;
31 unsigned short x : 1; 36 unsigned short x : 1;
32 unsigned short y : 1; 37 unsigned short y : 1;
33 } value; 38 } value;
39 unsigned short final : 1;
40};
41
42union huffpair {
34 struct { 43 struct {
35 unsigned short final : 1; 44 unsigned short final : 1;
36 unsigned short bits : 3; 45 unsigned short bits : 3;
37 unsigned short offset : 12; 46 unsigned short offset : 12;
38 } ptr; 47 } ptr;
39 unsigned short final : 1;
40};
41
42union huffpair {
43 struct { 48 struct {
44 unsigned short final : 1; 49 unsigned short final : 1;
45 unsigned short hlen : 3; 50 unsigned short hlen : 3;
46 unsigned short x : 4; 51 unsigned short x : 4;
47 unsigned short y : 4; 52 unsigned short y : 4;
48 } value; 53 } value;
49 struct {
50 unsigned short final : 1;
51 unsigned short bits : 3;
52 unsigned short offset : 12;
53 } ptr;
54 unsigned short final : 1; 54 unsigned short final : 1;
55}; 55};
56 56
57struct hufftable { 57struct hufftable {
58 union huffpair const *table; 58 union huffpair const *table;
59 unsigned short linbits; 59 unsigned short linbits;
60 unsigned short startbits; 60 unsigned short startbits;
61}; 61};
62 62
63extern union huffquad const *const mad_huff_quad_table[2]; 63extern union huffquad const *const mad_huff_quad_table[2];
64extern struct hufftable const mad_huff_pair_table[32]; 64extern struct hufftable const mad_huff_pair_table[32];
65 65
66# endif 66# endif
diff --git a/core/multimedia/opieplayer/libmad/imdct_s.dat b/core/multimedia/opieplayer/libmad/imdct_s.dat
index 00d62eb..ed70446 100644
--- a/core/multimedia/opieplayer/libmad/imdct_s.dat
+++ b/core/multimedia/opieplayer/libmad/imdct_s.dat
@@ -1,62 +1,62 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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 /* 0 */ { MAD_F(0x09bd7ca0) /* 0.608761429 */, 22 /* 0 */ { MAD_F(0x09bd7ca0) /* 0.608761429 */,
23 -MAD_F(0x0ec835e8) /* -0.923879533 */, 23 -MAD_F(0x0ec835e8) /* -0.923879533 */,
24 -MAD_F(0x0216a2a2) /* -0.130526192 */, 24 -MAD_F(0x0216a2a2) /* -0.130526192 */,
25 MAD_F(0x0fdcf549) /* 0.991444861 */, 25 MAD_F(0x0fdcf549) /* 0.991444861 */,
26 -MAD_F(0x061f78aa) /* -0.382683432 */, 26 -MAD_F(0x061f78aa) /* -0.382683432 */,
27 -MAD_F(0x0cb19346) /* -0.793353340 */ }, 27 -MAD_F(0x0cb19346) /* -0.793353340 */ },
28 28
29 /* 6 */ { -MAD_F(0x0cb19346) /* -0.793353340 */, 29 /* 6 */ { -MAD_F(0x0cb19346) /* -0.793353340 */,
30 MAD_F(0x061f78aa) /* 0.382683432 */, 30 MAD_F(0x061f78aa) /* 0.382683432 */,
31 MAD_F(0x0fdcf549) /* 0.991444861 */, 31 MAD_F(0x0fdcf549) /* 0.991444861 */,
32 MAD_F(0x0216a2a2) /* 0.130526192 */, 32 MAD_F(0x0216a2a2) /* 0.130526192 */,
33 -MAD_F(0x0ec835e8) /* -0.923879533 */, 33 -MAD_F(0x0ec835e8) /* -0.923879533 */,
34 -MAD_F(0x09bd7ca0) /* -0.608761429 */ }, 34 -MAD_F(0x09bd7ca0) /* -0.608761429 */ },
35 35
36 /* 1 */ { MAD_F(0x061f78aa) /* 0.382683432 */, 36 /* 1 */ { MAD_F(0x061f78aa) /* 0.382683432 */,
37 -MAD_F(0x0ec835e8) /* -0.923879533 */, 37 -MAD_F(0x0ec835e8) /* -0.923879533 */,
38 MAD_F(0x0ec835e8) /* 0.923879533 */, 38 MAD_F(0x0ec835e8) /* 0.923879533 */,
39 -MAD_F(0x061f78aa) /* -0.382683432 */, 39 -MAD_F(0x061f78aa) /* -0.382683432 */,
40 -MAD_F(0x061f78aa) /* -0.382683432 */, 40 -MAD_F(0x061f78aa) /* -0.382683432 */,
41 MAD_F(0x0ec835e8) /* 0.923879533 */ }, 41 MAD_F(0x0ec835e8) /* 0.923879533 */ },
42 42
43 /* 7 */ { -MAD_F(0x0ec835e8) /* -0.923879533 */, 43 /* 7 */ { -MAD_F(0x0ec835e8) /* -0.923879533 */,
44 -MAD_F(0x061f78aa) /* -0.382683432 */, 44 -MAD_F(0x061f78aa) /* -0.382683432 */,
45 MAD_F(0x061f78aa) /* 0.382683432 */, 45 MAD_F(0x061f78aa) /* 0.382683432 */,
46 MAD_F(0x0ec835e8) /* 0.923879533 */, 46 MAD_F(0x0ec835e8) /* 0.923879533 */,
47 MAD_F(0x0ec835e8) /* 0.923879533 */, 47 MAD_F(0x0ec835e8) /* 0.923879533 */,
48 MAD_F(0x061f78aa) /* 0.382683432 */ }, 48 MAD_F(0x061f78aa) /* 0.382683432 */ },
49 49
50 /* 2 */ { MAD_F(0x0216a2a2) /* 0.130526192 */, 50 /* 2 */ { MAD_F(0x0216a2a2) /* 0.130526192 */,
51 -MAD_F(0x061f78aa) /* -0.382683432 */, 51 -MAD_F(0x061f78aa) /* -0.382683432 */,
52 MAD_F(0x09bd7ca0) /* 0.608761429 */, 52 MAD_F(0x09bd7ca0) /* 0.608761429 */,
53 -MAD_F(0x0cb19346) /* -0.793353340 */, 53 -MAD_F(0x0cb19346) /* -0.793353340 */,
54 MAD_F(0x0ec835e8) /* 0.923879533 */, 54 MAD_F(0x0ec835e8) /* 0.923879533 */,
55 -MAD_F(0x0fdcf549) /* -0.991444861 */ }, 55 -MAD_F(0x0fdcf549) /* -0.991444861 */ },
56 56
57 /* 8 */ { -MAD_F(0x0fdcf549) /* -0.991444861 */, 57 /* 8 */ { -MAD_F(0x0fdcf549) /* -0.991444861 */,
58 -MAD_F(0x0ec835e8) /* -0.923879533 */, 58 -MAD_F(0x0ec835e8) /* -0.923879533 */,
59 -MAD_F(0x0cb19346) /* -0.793353340 */, 59 -MAD_F(0x0cb19346) /* -0.793353340 */,
60 -MAD_F(0x09bd7ca0) /* -0.608761429 */, 60 -MAD_F(0x09bd7ca0) /* -0.608761429 */,
61 -MAD_F(0x061f78aa) /* -0.382683432 */, 61 -MAD_F(0x061f78aa) /* -0.382683432 */,
62 -MAD_F(0x0216a2a2) /* -0.130526192 */ } 62 -MAD_F(0x0216a2a2) /* -0.130526192 */ }
diff --git a/core/multimedia/opieplayer/libmad/layer12.c b/core/multimedia/opieplayer/libmad/layer12.c
index 41b17ca..d291174 100644
--- a/core/multimedia/opieplayer/libmad/layer12.c
+++ b/core/multimedia/opieplayer/libmad/layer12.c
@@ -1,194 +1,194 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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
28# ifdef HAVE_LIMITS_H 28# ifdef HAVE_LIMITS_H
29# include <limits.h> 29# include <limits.h>
30# else 30# else
31# define CHAR_BIT 8 31# define CHAR_BIT 8
32# endif 32# endif
33 33
34# include "fixed.h" 34# include "fixed.h"
35# include "bit.h" 35# include "bit.h"
36# include "stream.h" 36# include "stream.h"
37# include "frame.h" 37# include "frame.h"
38# include "layer12.h" 38# include "layer12.h"
39 39
40/* 40/*
41 * scalefactor table 41 * scalefactor table
42 * used in both Layer I and Layer II decoding 42 * used in both Layer I and Layer II decoding
43 */ 43 */
44static 44static
45mad_fixed_t const sf_table[63] = { 45mad_fixed_t const sf_table[63] = {
46# include "sf_table.dat" 46# include "sf_table.dat"
47}; 47};
48 48
49/* --- Layer I ------------------------------------------------------------- */ 49/* --- Layer I ------------------------------------------------------------- */
50 50
51/* linear scaling table */ 51/* linear scaling table */
52static 52static
53mad_fixed_t const linear_table[14] = { 53mad_fixed_t const linear_table[14] = {
54 MAD_F(0x15555555), /* 2^2 / (2^2 - 1) == 1.33333333333333 */ 54 MAD_F(0x15555555), /* 2^2 / (2^2 - 1) == 1.33333333333333 */
55 MAD_F(0x12492492), /* 2^3 / (2^3 - 1) == 1.14285714285714 */ 55 MAD_F(0x12492492), /* 2^3 / (2^3 - 1) == 1.14285714285714 */
56 MAD_F(0x11111111), /* 2^4 / (2^4 - 1) == 1.06666666666667 */ 56 MAD_F(0x11111111), /* 2^4 / (2^4 - 1) == 1.06666666666667 */
57 MAD_F(0x10842108), /* 2^5 / (2^5 - 1) == 1.03225806451613 */ 57 MAD_F(0x10842108), /* 2^5 / (2^5 - 1) == 1.03225806451613 */
58 MAD_F(0x10410410), /* 2^6 / (2^6 - 1) == 1.01587301587302 */ 58 MAD_F(0x10410410), /* 2^6 / (2^6 - 1) == 1.01587301587302 */
59 MAD_F(0x10204081), /* 2^7 / (2^7 - 1) == 1.00787401574803 */ 59 MAD_F(0x10204081), /* 2^7 / (2^7 - 1) == 1.00787401574803 */
60 MAD_F(0x10101010), /* 2^8 / (2^8 - 1) == 1.00392156862745 */ 60 MAD_F(0x10101010), /* 2^8 / (2^8 - 1) == 1.00392156862745 */
61 MAD_F(0x10080402), /* 2^9 / (2^9 - 1) == 1.00195694716243 */ 61 MAD_F(0x10080402), /* 2^9 / (2^9 - 1) == 1.00195694716243 */
62 MAD_F(0x10040100), /* 2^10 / (2^10 - 1) == 1.00097751710655 */ 62 MAD_F(0x10040100), /* 2^10 / (2^10 - 1) == 1.00097751710655 */
63 MAD_F(0x10020040), /* 2^11 / (2^11 - 1) == 1.00048851978505 */ 63 MAD_F(0x10020040), /* 2^11 / (2^11 - 1) == 1.00048851978505 */
64 MAD_F(0x10010010), /* 2^12 / (2^12 - 1) == 1.00024420024420 */ 64 MAD_F(0x10010010), /* 2^12 / (2^12 - 1) == 1.00024420024420 */
65 MAD_F(0x10008004), /* 2^13 / (2^13 - 1) == 1.00012208521548 */ 65 MAD_F(0x10008004), /* 2^13 / (2^13 - 1) == 1.00012208521548 */
66 MAD_F(0x10004001), /* 2^14 / (2^14 - 1) == 1.00006103888177 */ 66 MAD_F(0x10004001), /* 2^14 / (2^14 - 1) == 1.00006103888177 */
67 MAD_F(0x10002000) /* 2^15 / (2^15 - 1) == 1.00003051850948 */ 67 MAD_F(0x10002000) /* 2^15 / (2^15 - 1) == 1.00003051850948 */
68}; 68};
69 69
70/* 70/*
71 * NAME:I_sample() 71 * NAME:I_sample()
72 * DESCRIPTION:decode one requantized Layer I sample from a bitstream 72 * DESCRIPTION:decode one requantized Layer I sample from a bitstream
73 */ 73 */
74static 74static
75mad_fixed_t I_sample(struct mad_bitptr *ptr, unsigned int nb) 75mad_fixed_t I_sample(struct mad_bitptr *ptr, unsigned int nb)
76{ 76{
77 mad_fixed_t sample; 77 mad_fixed_t sample;
78 78
79 sample = mad_bit_read(ptr, nb); 79 sample = mad_bit_read(ptr, nb);
80 80
81 /* invert most significant bit, extend sign, then scale to fixed format */ 81 /* invert most significant bit, extend sign, then scale to fixed format */
82 82
83 sample ^= 1 << (nb - 1); 83 sample ^= 1 << (nb - 1);
84 sample |= -(sample & (1 << (nb - 1))); 84 sample |= -(sample & (1 << (nb - 1)));
85 85
86 sample <<= MAD_F_FRACBITS - (nb - 1); 86 sample <<= MAD_F_FRACBITS - (nb - 1);
87 87
88 /* requantize the sample */ 88 /* requantize the sample */
89 89
90 /* s'' = (2^nb / (2^nb - 1)) * (s''' + 2^(-nb + 1)) */ 90 /* s'' = (2^nb / (2^nb - 1)) * (s''' + 2^(-nb + 1)) */
91 91
92 sample += MAD_F_ONE >> (nb - 1); 92 sample += MAD_F_ONE >> (nb - 1);
93 93
94 return mad_f_mul(sample, linear_table[nb - 2]); 94 return mad_f_mul(sample, linear_table[nb - 2]);
95 95
96 /* s' = factor * s'' */ 96 /* s' = factor * s'' */
97 /* (to be performed by caller) */ 97 /* (to be performed by caller) */
98} 98}
99 99
100/* 100/*
101 * NAME:layer->I() 101 * NAME:layer->I()
102 * DESCRIPTION:decode a single Layer I frame 102 * DESCRIPTION:decode a single Layer I frame
103 */ 103 */
104int mad_layer_I(struct mad_stream *stream, struct mad_frame *frame) 104int mad_layer_I(struct mad_stream *stream, struct mad_frame *frame)
105{ 105{
106 struct mad_header *header = &frame->header; 106 struct mad_header *header = &frame->header;
107 unsigned int nch, bound, ch, s, sb, nb; 107 unsigned int nch, bound, ch, s, sb, nb;
108 unsigned char allocation[2][32], scalefactor[2][32]; 108 unsigned char allocation[2][32], scalefactor[2][32];
109 109
110 nch = MAD_NCHANNELS(header); 110 nch = MAD_NCHANNELS(header);
111 111
112 bound = 32; 112 bound = 32;
113 if (header->mode == MAD_MODE_JOINT_STEREO) { 113 if (header->mode == MAD_MODE_JOINT_STEREO) {
114 header->flags |= MAD_FLAG_I_STEREO; 114 header->flags |= MAD_FLAG_I_STEREO;
115 bound = 4 + header->mode_extension * 4; 115 bound = 4 + header->mode_extension * 4;
116 } 116 }
117 117
118 /* check CRC word */ 118 /* check CRC word */
119 119
120 if (header->flags & MAD_FLAG_PROTECTION) { 120 if (header->flags & MAD_FLAG_PROTECTION) {
121 header->crc_check = 121 header->crc_check =
122 mad_bit_crc(stream->ptr, 4 * (bound * nch + (32 - bound)), 122 mad_bit_crc(stream->ptr, 4 * (bound * nch + (32 - bound)),
123 header->crc_check); 123 header->crc_check);
124 124
125 if (header->crc_check != header->crc_target && 125 if (header->crc_check != header->crc_target &&
126 !(frame->options & MAD_OPTION_IGNORECRC)) { 126 !(frame->options & MAD_OPTION_IGNORECRC)) {
127 stream->error = MAD_ERROR_BADCRC; 127 stream->error = MAD_ERROR_BADCRC;
128 return -1; 128 return -1;
129 } 129 }
130 } 130 }
131 131
132 /* decode bit allocations */ 132 /* decode bit allocations */
133 133
134 for (sb = 0; sb < bound; ++sb) { 134 for (sb = 0; sb < bound; ++sb) {
135 for (ch = 0; ch < nch; ++ch) { 135 for (ch = 0; ch < nch; ++ch) {
136 nb = mad_bit_read(&stream->ptr, 4); 136 nb = mad_bit_read(&stream->ptr, 4);
137 137
138 if (nb == 15) { 138 if (nb == 15) {
139 stream->error = MAD_ERROR_BADBITALLOC; 139 stream->error = MAD_ERROR_BADBITALLOC;
140 return -1; 140 return -1;
141 } 141 }
142 142
143 allocation[ch][sb] = nb ? nb + 1 : 0; 143 allocation[ch][sb] = nb ? nb + 1 : 0;
144 } 144 }
145 } 145 }
146 146
147 for (sb = bound; sb < 32; ++sb) { 147 for (sb = bound; sb < 32; ++sb) {
148 nb = mad_bit_read(&stream->ptr, 4); 148 nb = mad_bit_read(&stream->ptr, 4);
149 149
150 if (nb == 15) { 150 if (nb == 15) {
151 stream->error = MAD_ERROR_BADBITALLOC; 151 stream->error = MAD_ERROR_BADBITALLOC;
152 return -1; 152 return -1;
153 } 153 }
154 154
155 allocation[0][sb] = 155 allocation[0][sb] =
156 allocation[1][sb] = nb ? nb + 1 : 0; 156 allocation[1][sb] = nb ? nb + 1 : 0;
157 } 157 }
158 158
159 /* decode scalefactors */ 159 /* decode scalefactors */
160 160
161 for (sb = 0; sb < 32; ++sb) { 161 for (sb = 0; sb < 32; ++sb) {
162 for (ch = 0; ch < nch; ++ch) { 162 for (ch = 0; ch < nch; ++ch) {
163 if (allocation[ch][sb]) { 163 if (allocation[ch][sb]) {
164 scalefactor[ch][sb] = mad_bit_read(&stream->ptr, 6); 164 scalefactor[ch][sb] = mad_bit_read(&stream->ptr, 6);
165 165
166 if (scalefactor[ch][sb] == 63) { 166 if (scalefactor[ch][sb] == 63) {
167 stream->error = MAD_ERROR_BADSCALEFACTOR; 167 stream->error = MAD_ERROR_BADSCALEFACTOR;
168 return -1; 168 return -1;
169 } 169 }
170 } 170 }
171 } 171 }
172 } 172 }
173 173
174 /* decode samples */ 174 /* decode samples */
175 175
176 for (s = 0; s < 12; ++s) { 176 for (s = 0; s < 12; ++s) {
177 for (sb = 0; sb < bound; ++sb) { 177 for (sb = 0; sb < bound; ++sb) {
178 for (ch = 0; ch < nch; ++ch) { 178 for (ch = 0; ch < nch; ++ch) {
179 nb = allocation[ch][sb]; 179 nb = allocation[ch][sb];
180 frame->sbsample[ch][s][sb] = nb ? 180 frame->sbsample[ch][s][sb] = nb ?
181 mad_f_mul(I_sample(&stream->ptr, nb), 181 mad_f_mul(I_sample(&stream->ptr, nb),
182 sf_table[scalefactor[ch][sb]]) : 0; 182 sf_table[scalefactor[ch][sb]]) : 0;
183 } 183 }
184 } 184 }
185 185
186 for (sb = bound; sb < 32; ++sb) { 186 for (sb = bound; sb < 32; ++sb) {
187 if ((nb = allocation[0][sb])) { 187 if ((nb = allocation[0][sb])) {
188 mad_fixed_t sample; 188 mad_fixed_t sample;
189 189
190 sample = I_sample(&stream->ptr, nb); 190 sample = I_sample(&stream->ptr, nb);
191 191
192 for (ch = 0; ch < nch; ++ch) { 192 for (ch = 0; ch < nch; ++ch) {
193 frame->sbsample[ch][s][sb] = 193 frame->sbsample[ch][s][sb] =
194 mad_f_mul(sample, sf_table[scalefactor[ch][sb]]); 194 mad_f_mul(sample, sf_table[scalefactor[ch][sb]]);
diff --git a/core/multimedia/opieplayer/libmad/layer12.h b/core/multimedia/opieplayer/libmad/layer12.h
index d2c81ac..c673726 100644
--- a/core/multimedia/opieplayer/libmad/layer12.h
+++ b/core/multimedia/opieplayer/libmad/layer12.h
@@ -1,31 +1,31 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# ifndef LIBMAD_LAYER12_H 22# ifndef LIBMAD_LAYER12_H
23# define LIBMAD_LAYER12_H 23# define LIBMAD_LAYER12_H
24 24
25# include "stream.h" 25# include "stream.h"
26# include "frame.h" 26# include "frame.h"
27 27
28int mad_layer_I(struct mad_stream *, struct mad_frame *); 28int mad_layer_I(struct mad_stream *, struct mad_frame *);
29int mad_layer_II(struct mad_stream *, struct mad_frame *); 29int mad_layer_II(struct mad_stream *, struct mad_frame *);
30 30
31# endif 31# endif
diff --git a/core/multimedia/opieplayer/libmad/layer3.c b/core/multimedia/opieplayer/libmad/layer3.c
index 194fc7e..03f13fe 100644
--- a/core/multimedia/opieplayer/libmad/layer3.c
+++ b/core/multimedia/opieplayer/libmad/layer3.c
@@ -1,245 +1,253 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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
28# include <stdlib.h> 28# include <stdlib.h>
29# include <string.h> 29# include <string.h>
30# include <assert.h> 30
31# ifdef HAVE_ASSERT_H
32# include <assert.h>
33# endif
31 34
32# ifdef HAVE_LIMITS_H 35# ifdef HAVE_LIMITS_H
33# include <limits.h> 36# include <limits.h>
34# else 37# else
35# define CHAR_BIT 8 38# define CHAR_BIT 8
36# endif 39# endif
37 40
38# include "fixed.h" 41# include "fixed.h"
39# include "bit.h" 42# include "bit.h"
40# include "stream.h" 43# include "stream.h"
41# include "frame.h" 44# include "frame.h"
42# include "huffman.h" 45# include "huffman.h"
43# include "layer3.h" 46# include "layer3.h"
44 47
45/* --- Layer III ----------------------------------------------------------- */ 48/* --- Layer III ----------------------------------------------------------- */
46 49
47enum { 50enum {
48 count1table_select = 0x01, 51 count1table_select = 0x01,
49 scalefac_scale = 0x02, 52 scalefac_scale = 0x02,
50 preflag = 0x04, 53 preflag = 0x04,
51 mixed_block_flag = 0x08 54 mixed_block_flag = 0x08
52}; 55};
53 56
57enum {
58 I_STEREO = 0x1,
59 MS_STEREO = 0x2
60};
61
54struct sideinfo { 62struct sideinfo {
55 unsigned int main_data_begin; 63 unsigned int main_data_begin;
56 unsigned int private_bits; 64 unsigned int private_bits;
57 65
58 unsigned char scfsi[2]; 66 unsigned char scfsi[2];
59 67
60 struct granule { 68 struct granule {
61 struct channel { 69 struct channel {
62 /* from side info */ 70 /* from side info */
63 unsigned short part2_3_length; 71 unsigned short part2_3_length;
64 unsigned short big_values; 72 unsigned short big_values;
65 unsigned short global_gain; 73 unsigned short global_gain;
66 unsigned short scalefac_compress; 74 unsigned short scalefac_compress;
67 75
68 unsigned char flags; 76 unsigned char flags;
69 unsigned char block_type; 77 unsigned char block_type;
70 unsigned char table_select[3]; 78 unsigned char table_select[3];
71 unsigned char subblock_gain[3]; 79 unsigned char subblock_gain[3];
72 unsigned char region0_count; 80 unsigned char region0_count;
73 unsigned char region1_count; 81 unsigned char region1_count;
74 82
75 /* from main_data */ 83 /* from main_data */
76 unsigned char scalefac[39];/* scalefac_l and/or scalefac_s */ 84 unsigned char scalefac[39];/* scalefac_l and/or scalefac_s */
77 } ch[2]; 85 } ch[2];
78 } gr[2]; 86 } gr[2];
79}; 87};
80 88
81/* 89/*
82 * scalefactor bit lengths 90 * scalefactor bit lengths
83 * derived from section 2.4.2.7 of ISO/IEC 11172-3 91 * derived from section 2.4.2.7 of ISO/IEC 11172-3
84 */ 92 */
85static 93static
86struct { 94struct {
87 unsigned char slen1; 95 unsigned char slen1;
88 unsigned char slen2; 96 unsigned char slen2;
89} const sflen_table[16] = { 97} const sflen_table[16] = {
90 { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 }, 98 { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 },
91 { 3, 0 }, { 1, 1 }, { 1, 2 }, { 1, 3 }, 99 { 3, 0 }, { 1, 1 }, { 1, 2 }, { 1, 3 },
92 { 2, 1 }, { 2, 2 }, { 2, 3 }, { 3, 1 }, 100 { 2, 1 }, { 2, 2 }, { 2, 3 }, { 3, 1 },
93 { 3, 2 }, { 3, 3 }, { 4, 2 }, { 4, 3 } 101 { 3, 2 }, { 3, 3 }, { 4, 2 }, { 4, 3 }
94}; 102};
95 103
96/* 104/*
97 * number of LSF scalefactor band values 105 * number of LSF scalefactor band values
98 * derived from section 2.4.3.2 of ISO/IEC 13818-3 106 * derived from section 2.4.3.2 of ISO/IEC 13818-3
99 */ 107 */
100static 108static
101unsigned char const nsfb_table[6][3][4] = { 109unsigned char const nsfb_table[6][3][4] = {
102 { { 6, 5, 5, 5 }, 110 { { 6, 5, 5, 5 },
103 { 9, 9, 9, 9 }, 111 { 9, 9, 9, 9 },
104 { 6, 9, 9, 9 } }, 112 { 6, 9, 9, 9 } },
105 113
106 { { 6, 5, 7, 3 }, 114 { { 6, 5, 7, 3 },
107 { 9, 9, 12, 6 }, 115 { 9, 9, 12, 6 },
108 { 6, 9, 12, 6 } }, 116 { 6, 9, 12, 6 } },
109 117
110 { { 11, 10, 0, 0 }, 118 { { 11, 10, 0, 0 },
111 { 18, 18, 0, 0 }, 119 { 18, 18, 0, 0 },
112 { 15, 18, 0, 0 } }, 120 { 15, 18, 0, 0 } },
113 121
114 { { 7, 7, 7, 0 }, 122 { { 7, 7, 7, 0 },
115 { 12, 12, 12, 0 }, 123 { 12, 12, 12, 0 },
116 { 6, 15, 12, 0 } }, 124 { 6, 15, 12, 0 } },
117 125
118 { { 6, 6, 6, 3 }, 126 { { 6, 6, 6, 3 },
119 { 12, 9, 9, 6 }, 127 { 12, 9, 9, 6 },
120 { 6, 12, 9, 6 } }, 128 { 6, 12, 9, 6 } },
121 129
122 { { 8, 8, 5, 0 }, 130 { { 8, 8, 5, 0 },
123 { 15, 12, 9, 0 }, 131 { 15, 12, 9, 0 },
124 { 6, 18, 9, 0 } } 132 { 6, 18, 9, 0 } }
125}; 133};
126 134
127/* 135/*
128 * MPEG-1 scalefactor band widths 136 * MPEG-1 scalefactor band widths
129 * derived from Table B.8 of ISO/IEC 11172-3 137 * derived from Table B.8 of ISO/IEC 11172-3
130 */ 138 */
131static 139static
132unsigned char const sfb_48000_long[] = { 140unsigned char const sfb_48000_long[] = {
133 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10, 141 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10,
134 12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192 142 12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192
135}; 143};
136 144
137static 145static
138unsigned char const sfb_44100_long[] = { 146unsigned char const sfb_44100_long[] = {
139 4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10, 147 4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10,
140 12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158 148 12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158
141}; 149};
142 150
143static 151static
144unsigned char const sfb_32000_long[] = { 152unsigned char const sfb_32000_long[] = {
145 4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12, 153 4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12,
146 16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26 154 16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26
147}; 155};
148 156
149static 157static
150unsigned char const sfb_48000_short[] = { 158unsigned char const sfb_48000_short[] = {
151 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 159 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
152 6, 6, 6, 6, 6, 10, 10, 10, 12, 12, 12, 14, 14, 160 6, 6, 6, 6, 6, 10, 10, 10, 12, 12, 12, 14, 14,
153 14, 16, 16, 16, 20, 20, 20, 26, 26, 26, 66, 66, 66 161 14, 16, 16, 16, 20, 20, 20, 26, 26, 26, 66, 66, 66
154}; 162};
155 163
156static 164static
157unsigned char const sfb_44100_short[] = { 165unsigned char const sfb_44100_short[] = {
158 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 166 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
159 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 167 6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14,
160 14, 18, 18, 18, 22, 22, 22, 30, 30, 30, 56, 56, 56 168 14, 18, 18, 18, 22, 22, 22, 30, 30, 30, 56, 56, 56
161}; 169};
162 170
163static 171static
164unsigned char const sfb_32000_short[] = { 172unsigned char const sfb_32000_short[] = {
165 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 173 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
166 6, 6, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 20, 174 6, 6, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 20,
167 20, 26, 26, 26, 34, 34, 34, 42, 42, 42, 12, 12, 12 175 20, 26, 26, 26, 34, 34, 34, 42, 42, 42, 12, 12, 12
168}; 176};
169 177
170static 178static
171unsigned char const sfb_48000_mixed[] = { 179unsigned char const sfb_48000_mixed[] = {
172 /* long */ 4, 4, 4, 4, 4, 4, 6, 6, 180 /* long */ 4, 4, 4, 4, 4, 4, 6, 6,
173 /* short */ 4, 4, 4, 6, 6, 6, 6, 6, 6, 10, 181 /* short */ 4, 4, 4, 6, 6, 6, 6, 6, 6, 10,
174 10, 10, 12, 12, 12, 14, 14, 14, 16, 16, 182 10, 10, 12, 12, 12, 14, 14, 14, 16, 16,
175 16, 20, 20, 20, 26, 26, 26, 66, 66, 66 183 16, 20, 20, 20, 26, 26, 26, 66, 66, 66
176}; 184};
177 185
178static 186static
179unsigned char const sfb_44100_mixed[] = { 187unsigned char const sfb_44100_mixed[] = {
180 /* long */ 4, 4, 4, 4, 4, 4, 6, 6, 188 /* long */ 4, 4, 4, 4, 4, 4, 6, 6,
181 /* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 10, 189 /* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 10,
182 10, 10, 12, 12, 12, 14, 14, 14, 18, 18, 190 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
183 18, 22, 22, 22, 30, 30, 30, 56, 56, 56 191 18, 22, 22, 22, 30, 30, 30, 56, 56, 56
184}; 192};
185 193
186static 194static
187unsigned char const sfb_32000_mixed[] = { 195unsigned char const sfb_32000_mixed[] = {
188 /* long */ 4, 4, 4, 4, 4, 4, 6, 6, 196 /* long */ 4, 4, 4, 4, 4, 4, 6, 6,
189 /* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 12, 197 /* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 12,
190 12, 12, 16, 16, 16, 20, 20, 20, 26, 26, 198 12, 12, 16, 16, 16, 20, 20, 20, 26, 26,
191 26, 34, 34, 34, 42, 42, 42, 12, 12, 12 199 26, 34, 34, 34, 42, 42, 42, 12, 12, 12
192}; 200};
193 201
194/* 202/*
195 * MPEG-2 scalefactor band widths 203 * MPEG-2 scalefactor band widths
196 * derived from Table B.2 of ISO/IEC 13818-3 204 * derived from Table B.2 of ISO/IEC 13818-3
197 */ 205 */
198static 206static
199unsigned char const sfb_24000_long[] = { 207unsigned char const sfb_24000_long[] = {
200 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 208 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
201 18, 22, 26, 32, 38, 46, 54, 62, 70, 76, 36 209 18, 22, 26, 32, 38, 46, 54, 62, 70, 76, 36
202}; 210};
203 211
204static 212static
205unsigned char const sfb_22050_long[] = { 213unsigned char const sfb_22050_long[] = {
206 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 214 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
207 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54 215 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54
208}; 216};
209 217
210# define sfb_16000_long sfb_22050_long 218# define sfb_16000_long sfb_22050_long
211 219
212static 220static
213unsigned char const sfb_24000_short[] = { 221unsigned char const sfb_24000_short[] = {
214 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 222 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8,
215 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18, 223 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
216 18, 24, 24, 24, 32, 32, 32, 44, 44, 44, 12, 12, 12 224 18, 24, 24, 24, 32, 32, 32, 44, 44, 44, 12, 12, 12
217}; 225};
218 226
219static 227static
220unsigned char const sfb_22050_short[] = { 228unsigned char const sfb_22050_short[] = {
221 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 229 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6,
222 6, 6, 8, 8, 8, 10, 10, 10, 14, 14, 14, 18, 18, 230 6, 6, 8, 8, 8, 10, 10, 10, 14, 14, 14, 18, 18,
223 18, 26, 26, 26, 32, 32, 32, 42, 42, 42, 18, 18, 18 231 18, 26, 26, 26, 32, 32, 32, 42, 42, 42, 18, 18, 18
224}; 232};
225 233
226static 234static
227unsigned char const sfb_16000_short[] = { 235unsigned char const sfb_16000_short[] = {
228 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 236 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8,
229 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18, 237 8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
230 18, 24, 24, 24, 30, 30, 30, 40, 40, 40, 18, 18, 18 238 18, 24, 24, 24, 30, 30, 30, 40, 40, 40, 18, 18, 18
231}; 239};
232 240
233static 241static
234unsigned char const sfb_24000_mixed[] = { 242unsigned char const sfb_24000_mixed[] = {
235 /* long */ 6, 6, 6, 6, 6, 6, 243 /* long */ 6, 6, 6, 6, 6, 6,
236 /* short */ 6, 6, 6, 8, 8, 8, 10, 10, 10, 12, 244 /* short */ 6, 6, 6, 8, 8, 8, 10, 10, 10, 12,
237 12, 12, 14, 14, 14, 18, 18, 18, 24, 24, 245 12, 12, 14, 14, 14, 18, 18, 18, 24, 24,
238 24, 32, 32, 32, 44, 44, 44, 12, 12, 12 246 24, 32, 32, 32, 44, 44, 44, 12, 12, 12
239}; 247};
240 248
241static 249static
242unsigned char const sfb_22050_mixed[] = { 250unsigned char const sfb_22050_mixed[] = {
243 /* long */ 6, 6, 6, 6, 6, 6, 251 /* long */ 6, 6, 6, 6, 6, 6,
244 /* short */ 6, 6, 6, 6, 6, 6, 8, 8, 8, 10, 252 /* short */ 6, 6, 6, 6, 6, 6, 8, 8, 8, 10,
245 10, 10, 14, 14, 14, 18, 18, 18, 26, 26, 253 10, 10, 14, 14, 14, 18, 18, 18, 26, 26,
@@ -314,1436 +322,1438 @@ struct {
314static 322static
315unsigned char const pretab[22] = { 323unsigned char const pretab[22] = {
316 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 324 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0
317}; 325};
318 326
319/* 327/*
320 * table for requantization 328 * table for requantization
321 * 329 *
322 * rq_table[x].mantissa * 2^(rq_table[x].exponent) = x^(4/3) 330 * rq_table[x].mantissa * 2^(rq_table[x].exponent) = x^(4/3)
323 */ 331 */
324static 332static
325struct fixedfloat { 333struct fixedfloat {
326 unsigned long mantissa : 27; 334 unsigned long mantissa : 27;
327 unsigned short exponent : 5; 335 unsigned short exponent : 5;
328} const rq_table[8207] = { 336} const rq_table[8207] = {
329# include "rq_table.dat" 337# include "rq_table.dat"
330}; 338};
331 339
332/* 340/*
333 * fractional powers of two 341 * fractional powers of two
334 * used for requantization and joint stereo decoding 342 * used for requantization and joint stereo decoding
335 * 343 *
336 * root_table[3 + x] = 2^(x/4) 344 * root_table[3 + x] = 2^(x/4)
337 */ 345 */
338static 346static
339mad_fixed_t const root_table[7] = { 347mad_fixed_t const root_table[7] = {
340 MAD_F(0x09837f05) /* 2^(-3/4) == 0.59460355750136 */, 348 MAD_F(0x09837f05) /* 2^(-3/4) == 0.59460355750136 */,
341 MAD_F(0x0b504f33) /* 2^(-2/4) == 0.70710678118655 */, 349 MAD_F(0x0b504f33) /* 2^(-2/4) == 0.70710678118655 */,
342 MAD_F(0x0d744fcd) /* 2^(-1/4) == 0.84089641525371 */, 350 MAD_F(0x0d744fcd) /* 2^(-1/4) == 0.84089641525371 */,
343 MAD_F(0x10000000) /* 2^( 0/4) == 1.00000000000000 */, 351 MAD_F(0x10000000) /* 2^( 0/4) == 1.00000000000000 */,
344 MAD_F(0x1306fe0a) /* 2^(+1/4) == 1.18920711500272 */, 352 MAD_F(0x1306fe0a) /* 2^(+1/4) == 1.18920711500272 */,
345 MAD_F(0x16a09e66) /* 2^(+2/4) == 1.41421356237310 */, 353 MAD_F(0x16a09e66) /* 2^(+2/4) == 1.41421356237310 */,
346 MAD_F(0x1ae89f99) /* 2^(+3/4) == 1.68179283050743 */ 354 MAD_F(0x1ae89f99) /* 2^(+3/4) == 1.68179283050743 */
347}; 355};
348 356
349/* 357/*
350 * coefficients for aliasing reduction 358 * coefficients for aliasing reduction
351 * derived from Table B.9 of ISO/IEC 11172-3 359 * derived from Table B.9 of ISO/IEC 11172-3
352 * 360 *
353 * 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 }
354 * cs[i] = 1 / sqrt(1 + c[i]^2) 362 * cs[i] = 1 / sqrt(1 + c[i]^2)
355 * ca[i] = c[i] / sqrt(1 + c[i]^2) 363 * ca[i] = c[i] / sqrt(1 + c[i]^2)
356 */ 364 */
357static 365static
358mad_fixed_t const cs[8] = { 366mad_fixed_t const cs[8] = {
359 +MAD_F(0x0db84a81) /* +0.857492926 */, +MAD_F(0x0e1b9d7f) /* +0.881741997 */, 367 +MAD_F(0x0db84a81) /* +0.857492926 */, +MAD_F(0x0e1b9d7f) /* +0.881741997 */,
360 +MAD_F(0x0f31adcf) /* +0.949628649 */, +MAD_F(0x0fbba815) /* +0.983314592 */, 368 +MAD_F(0x0f31adcf) /* +0.949628649 */, +MAD_F(0x0fbba815) /* +0.983314592 */,
361 +MAD_F(0x0feda417) /* +0.995517816 */, +MAD_F(0x0ffc8fc8) /* +0.999160558 */, 369 +MAD_F(0x0feda417) /* +0.995517816 */, +MAD_F(0x0ffc8fc8) /* +0.999160558 */,
362 +MAD_F(0x0fff964c) /* +0.999899195 */, +MAD_F(0x0ffff8d3) /* +0.999993155 */ 370 +MAD_F(0x0fff964c) /* +0.999899195 */, +MAD_F(0x0ffff8d3) /* +0.999993155 */
363}; 371};
364 372
365static 373static
366mad_fixed_t const ca[8] = { 374mad_fixed_t const ca[8] = {
367 -MAD_F(0x083b5fe7) /* -0.514495755 */, -MAD_F(0x078c36d2) /* -0.471731969 */, 375 -MAD_F(0x083b5fe7) /* -0.514495755 */, -MAD_F(0x078c36d2) /* -0.471731969 */,
368 -MAD_F(0x05039814) /* -0.313377454 */, -MAD_F(0x02e91dd1) /* -0.181913200 */, 376 -MAD_F(0x05039814) /* -0.313377454 */, -MAD_F(0x02e91dd1) /* -0.181913200 */,
369 -MAD_F(0x0183603a) /* -0.094574193 */, -MAD_F(0x00a7cb87) /* -0.040965583 */, 377 -MAD_F(0x0183603a) /* -0.094574193 */, -MAD_F(0x00a7cb87) /* -0.040965583 */,
370 -MAD_F(0x003a2847) /* -0.014198569 */, -MAD_F(0x000f27b4) /* -0.003699975 */ 378 -MAD_F(0x003a2847) /* -0.014198569 */, -MAD_F(0x000f27b4) /* -0.003699975 */
371}; 379};
372 380
373/* 381/*
374 * IMDCT coefficients for short blocks 382 * IMDCT coefficients for short blocks
375 * 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
376 * 384 *
377 * 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))
378 * 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))
379 */ 387 */
380static 388static
381mad_fixed_t const imdct_s[6][6] = { 389mad_fixed_t const imdct_s[6][6] = {
382# include "imdct_s.dat" 390# include "imdct_s.dat"
383}; 391};
384 392
385# if !defined(ASO_IMDCT) 393# if !defined(ASO_IMDCT)
386/* 394/*
387 * windowing coefficients for long blocks 395 * windowing coefficients for long blocks
388 * 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
389 * 397 *
390 * window_l[i] = sin((PI / 36) * (i + 1/2)) 398 * window_l[i] = sin((PI / 36) * (i + 1/2))
391 */ 399 */
392static 400static
393mad_fixed_t const window_l[36] = { 401mad_fixed_t const window_l[36] = {
394 MAD_F(0x00b2aa3e) /* 0.043619387 */, MAD_F(0x0216a2a2) /* 0.130526192 */, 402 MAD_F(0x00b2aa3e) /* 0.043619387 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
395 MAD_F(0x03768962) /* 0.216439614 */, MAD_F(0x04cfb0e2) /* 0.300705800 */, 403 MAD_F(0x03768962) /* 0.216439614 */, MAD_F(0x04cfb0e2) /* 0.300705800 */,
396 MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x07635284) /* 0.461748613 */, 404 MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x07635284) /* 0.461748613 */,
397 MAD_F(0x0898c779) /* 0.537299608 */, MAD_F(0x09bd7ca0) /* 0.608761429 */, 405 MAD_F(0x0898c779) /* 0.537299608 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
398 MAD_F(0x0acf37ad) /* 0.675590208 */, MAD_F(0x0bcbe352) /* 0.737277337 */, 406 MAD_F(0x0acf37ad) /* 0.675590208 */, MAD_F(0x0bcbe352) /* 0.737277337 */,
399 MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x0d7e8807) /* 0.843391446 */, 407 MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x0d7e8807) /* 0.843391446 */,
400 408
401 MAD_F(0x0e313245) /* 0.887010833 */, MAD_F(0x0ec835e8) /* 0.923879533 */, 409 MAD_F(0x0e313245) /* 0.887010833 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
402 MAD_F(0x0f426cb5) /* 0.953716951 */, MAD_F(0x0f9ee890) /* 0.976296007 */, 410 MAD_F(0x0f426cb5) /* 0.953716951 */, MAD_F(0x0f9ee890) /* 0.976296007 */,
403 MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ffc19fd) /* 0.999048222 */, 411 MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ffc19fd) /* 0.999048222 */,
404 MAD_F(0x0ffc19fd) /* 0.999048222 */, MAD_F(0x0fdcf549) /* 0.991444861 */, 412 MAD_F(0x0ffc19fd) /* 0.999048222 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
405 MAD_F(0x0f9ee890) /* 0.976296007 */, MAD_F(0x0f426cb5) /* 0.953716951 */, 413 MAD_F(0x0f9ee890) /* 0.976296007 */, MAD_F(0x0f426cb5) /* 0.953716951 */,
406 MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0e313245) /* 0.887010833 */, 414 MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0e313245) /* 0.887010833 */,
407 415
408 MAD_F(0x0d7e8807) /* 0.843391446 */, MAD_F(0x0cb19346) /* 0.793353340 */, 416 MAD_F(0x0d7e8807) /* 0.843391446 */, MAD_F(0x0cb19346) /* 0.793353340 */,
409 MAD_F(0x0bcbe352) /* 0.737277337 */, MAD_F(0x0acf37ad) /* 0.675590208 */, 417 MAD_F(0x0bcbe352) /* 0.737277337 */, MAD_F(0x0acf37ad) /* 0.675590208 */,
410 MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0898c779) /* 0.537299608 */, 418 MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0898c779) /* 0.537299608 */,
411 MAD_F(0x07635284) /* 0.461748613 */, MAD_F(0x061f78aa) /* 0.382683432 */, 419 MAD_F(0x07635284) /* 0.461748613 */, MAD_F(0x061f78aa) /* 0.382683432 */,
412 MAD_F(0x04cfb0e2) /* 0.300705800 */, MAD_F(0x03768962) /* 0.216439614 */, 420 MAD_F(0x04cfb0e2) /* 0.300705800 */, MAD_F(0x03768962) /* 0.216439614 */,
413 MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x00b2aa3e) /* 0.043619387 */, 421 MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x00b2aa3e) /* 0.043619387 */,
414}; 422};
415# endif /* ASO_IMDCT */ 423# endif /* ASO_IMDCT */
416 424
417/* 425/*
418 * windowing coefficients for short blocks 426 * windowing coefficients for short blocks
419 * derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3 427 * derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3
420 * 428 *
421 * window_s[i] = sin((PI / 12) * (i + 1/2)) 429 * window_s[i] = sin((PI / 12) * (i + 1/2))
422 */ 430 */
423static 431static
424mad_fixed_t const window_s[12] = { 432mad_fixed_t const window_s[12] = {
425 MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x061f78aa) /* 0.382683432 */, 433 MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x061f78aa) /* 0.382683432 */,
426 MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0cb19346) /* 0.793353340 */, 434 MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0cb19346) /* 0.793353340 */,
427 MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0fdcf549) /* 0.991444861 */, 435 MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
428 MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ec835e8) /* 0.923879533 */, 436 MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
429 MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x09bd7ca0) /* 0.608761429 */, 437 MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
430 MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x0216a2a2) /* 0.130526192 */, 438 MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
431}; 439};
432 440
433/* 441/*
434 * coefficients for intensity stereo processing 442 * coefficients for intensity stereo processing
435 * 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
436 * 444 *
437 * is_ratio[i] = tan(i * (PI / 12)) 445 * is_ratio[i] = tan(i * (PI / 12))
438 * is_table[i] = is_ratio[i] / (1 + is_ratio[i]) 446 * is_table[i] = is_ratio[i] / (1 + is_ratio[i])
439 */ 447 */
440static 448static
441mad_fixed_t const is_table[7] = { 449mad_fixed_t const is_table[7] = {
442 MAD_F(0x00000000) /* 0.000000000 */, 450 MAD_F(0x00000000) /* 0.000000000 */,
443 MAD_F(0x0361962f) /* 0.211324865 */, 451 MAD_F(0x0361962f) /* 0.211324865 */,
444 MAD_F(0x05db3d74) /* 0.366025404 */, 452 MAD_F(0x05db3d74) /* 0.366025404 */,
445 MAD_F(0x08000000) /* 0.500000000 */, 453 MAD_F(0x08000000) /* 0.500000000 */,
446 MAD_F(0x0a24c28c) /* 0.633974596 */, 454 MAD_F(0x0a24c28c) /* 0.633974596 */,
447 MAD_F(0x0c9e69d1) /* 0.788675135 */, 455 MAD_F(0x0c9e69d1) /* 0.788675135 */,
448 MAD_F(0x10000000) /* 1.000000000 */ 456 MAD_F(0x10000000) /* 1.000000000 */
449}; 457};
450 458
451/* 459/*
452 * coefficients for LSF intensity stereo processing 460 * coefficients for LSF intensity stereo processing
453 * 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
454 * 462 *
455 * is_lsf_table[0][i] = (1 / sqrt(sqrt(2)))^(i + 1) 463 * is_lsf_table[0][i] = (1 / sqrt(sqrt(2)))^(i + 1)
456 * is_lsf_table[1][i] = (1 / sqrt(2))^(i + 1) 464 * is_lsf_table[1][i] = (1 / sqrt(2))^(i + 1)
457 */ 465 */
458static 466static
459mad_fixed_t const is_lsf_table[2][15] = { 467mad_fixed_t const is_lsf_table[2][15] = {
460 { 468 {
461 MAD_F(0x0d744fcd) /* 0.840896415 */, 469 MAD_F(0x0d744fcd) /* 0.840896415 */,
462 MAD_F(0x0b504f33) /* 0.707106781 */, 470 MAD_F(0x0b504f33) /* 0.707106781 */,
463 MAD_F(0x09837f05) /* 0.594603558 */, 471 MAD_F(0x09837f05) /* 0.594603558 */,
464 MAD_F(0x08000000) /* 0.500000000 */, 472 MAD_F(0x08000000) /* 0.500000000 */,
465 MAD_F(0x06ba27e6) /* 0.420448208 */, 473 MAD_F(0x06ba27e6) /* 0.420448208 */,
466 MAD_F(0x05a8279a) /* 0.353553391 */, 474 MAD_F(0x05a8279a) /* 0.353553391 */,
467 MAD_F(0x04c1bf83) /* 0.297301779 */, 475 MAD_F(0x04c1bf83) /* 0.297301779 */,
468 MAD_F(0x04000000) /* 0.250000000 */, 476 MAD_F(0x04000000) /* 0.250000000 */,
469 MAD_F(0x035d13f3) /* 0.210224104 */, 477 MAD_F(0x035d13f3) /* 0.210224104 */,
470 MAD_F(0x02d413cd) /* 0.176776695 */, 478 MAD_F(0x02d413cd) /* 0.176776695 */,
471 MAD_F(0x0260dfc1) /* 0.148650889 */, 479 MAD_F(0x0260dfc1) /* 0.148650889 */,
472 MAD_F(0x02000000) /* 0.125000000 */, 480 MAD_F(0x02000000) /* 0.125000000 */,
473 MAD_F(0x01ae89fa) /* 0.105112052 */, 481 MAD_F(0x01ae89fa) /* 0.105112052 */,
474 MAD_F(0x016a09e6) /* 0.088388348 */, 482 MAD_F(0x016a09e6) /* 0.088388348 */,
475 MAD_F(0x01306fe1) /* 0.074325445 */ 483 MAD_F(0x01306fe1) /* 0.074325445 */
476 }, { 484 }, {
477 MAD_F(0x0b504f33) /* 0.707106781 */, 485 MAD_F(0x0b504f33) /* 0.707106781 */,
478 MAD_F(0x08000000) /* 0.500000000 */, 486 MAD_F(0x08000000) /* 0.500000000 */,
479 MAD_F(0x05a8279a) /* 0.353553391 */, 487 MAD_F(0x05a8279a) /* 0.353553391 */,
480 MAD_F(0x04000000) /* 0.250000000 */, 488 MAD_F(0x04000000) /* 0.250000000 */,
481 MAD_F(0x02d413cd) /* 0.176776695 */, 489 MAD_F(0x02d413cd) /* 0.176776695 */,
482 MAD_F(0x02000000) /* 0.125000000 */, 490 MAD_F(0x02000000) /* 0.125000000 */,
483 MAD_F(0x016a09e6) /* 0.088388348 */, 491 MAD_F(0x016a09e6) /* 0.088388348 */,
484 MAD_F(0x01000000) /* 0.062500000 */, 492 MAD_F(0x01000000) /* 0.062500000 */,
485 MAD_F(0x00b504f3) /* 0.044194174 */, 493 MAD_F(0x00b504f3) /* 0.044194174 */,
486 MAD_F(0x00800000) /* 0.031250000 */, 494 MAD_F(0x00800000) /* 0.031250000 */,
487 MAD_F(0x005a827a) /* 0.022097087 */, 495 MAD_F(0x005a827a) /* 0.022097087 */,
488 MAD_F(0x00400000) /* 0.015625000 */, 496 MAD_F(0x00400000) /* 0.015625000 */,
489 MAD_F(0x002d413d) /* 0.011048543 */, 497 MAD_F(0x002d413d) /* 0.011048543 */,
490 MAD_F(0x00200000) /* 0.007812500 */, 498 MAD_F(0x00200000) /* 0.007812500 */,
491 MAD_F(0x0016a09e) /* 0.005524272 */ 499 MAD_F(0x0016a09e) /* 0.005524272 */
492 } 500 }
493}; 501};
494 502
495/* 503/*
496 * NAME:III_sideinfo() 504 * NAME:III_sideinfo()
497 * DESCRIPTION:decode frame side information from a bitstream 505 * DESCRIPTION:decode frame side information from a bitstream
498 */ 506 */
499static 507static
500enum mad_error III_sideinfo(struct mad_bitptr *ptr, unsigned int nch, 508enum mad_error III_sideinfo(struct mad_bitptr *ptr, unsigned int nch,
501 int lsf, struct sideinfo *si, 509 int lsf, struct sideinfo *si,
502 unsigned int *data_bitlen, 510 unsigned int *data_bitlen,
503 unsigned int *priv_bitlen) 511 unsigned int *priv_bitlen)
504{ 512{
505 unsigned int ngr, gr, ch, i; 513 unsigned int ngr, gr, ch, i;
506 enum mad_error result = 0; 514 enum mad_error result = MAD_ERROR_NONE;
507 515
508 *data_bitlen = 0; 516 *data_bitlen = 0;
509 *priv_bitlen = lsf ? ((nch == 1) ? 1 : 2) : ((nch == 1) ? 5 : 3); 517 *priv_bitlen = lsf ? ((nch == 1) ? 1 : 2) : ((nch == 1) ? 5 : 3);
510 518
511 si->main_data_begin = mad_bit_read(ptr, lsf ? 8 : 9); 519 si->main_data_begin = mad_bit_read(ptr, lsf ? 8 : 9);
512 si->private_bits = mad_bit_read(ptr, *priv_bitlen); 520 si->private_bits = mad_bit_read(ptr, *priv_bitlen);
513 521
514 ngr = 1; 522 ngr = 1;
515 if (!lsf) { 523 if (!lsf) {
516 ngr = 2; 524 ngr = 2;
517 525
518 for (ch = 0; ch < nch; ++ch) 526 for (ch = 0; ch < nch; ++ch)
519 si->scfsi[ch] = mad_bit_read(ptr, 4); 527 si->scfsi[ch] = mad_bit_read(ptr, 4);
520 } 528 }
521 529
522 for (gr = 0; gr < ngr; ++gr) { 530 for (gr = 0; gr < ngr; ++gr) {
523 struct granule *granule = &si->gr[gr]; 531 struct granule *granule = &si->gr[gr];
524 532
525 for (ch = 0; ch < nch; ++ch) { 533 for (ch = 0; ch < nch; ++ch) {
526 struct channel *channel = &granule->ch[ch]; 534 struct channel *channel = &granule->ch[ch];
527 535
528 channel->part2_3_length = mad_bit_read(ptr, 12); 536 channel->part2_3_length = mad_bit_read(ptr, 12);
529 channel->big_values = mad_bit_read(ptr, 9); 537 channel->big_values = mad_bit_read(ptr, 9);
530 channel->global_gain = mad_bit_read(ptr, 8); 538 channel->global_gain = mad_bit_read(ptr, 8);
531 channel->scalefac_compress = mad_bit_read(ptr, lsf ? 9 : 4); 539 channel->scalefac_compress = mad_bit_read(ptr, lsf ? 9 : 4);
532 540
533 *data_bitlen += channel->part2_3_length; 541 *data_bitlen += channel->part2_3_length;
534 542
535 if (channel->big_values > 288 && result == 0) 543 if (channel->big_values > 288 && result == 0)
536 result = MAD_ERROR_BADBIGVALUES; 544 result = MAD_ERROR_BADBIGVALUES;
537 545
538 channel->flags = 0; 546 channel->flags = 0;
539 547
540 /* window_switching_flag */ 548 /* window_switching_flag */
541 if (mad_bit_read(ptr, 1)) { 549 if (mad_bit_read(ptr, 1)) {
542 channel->block_type = mad_bit_read(ptr, 2); 550 channel->block_type = mad_bit_read(ptr, 2);
543 551
544 if (channel->block_type == 0 && result == 0) 552 if (channel->block_type == 0 && result == 0)
545 result = MAD_ERROR_BADBLOCKTYPE; 553 result = MAD_ERROR_BADBLOCKTYPE;
546 554
547 if (!lsf && channel->block_type == 2 && si->scfsi[ch] && result == 0) 555 if (!lsf && channel->block_type == 2 && si->scfsi[ch] && result == 0)
548 result = MAD_ERROR_BADSCFSI; 556 result = MAD_ERROR_BADSCFSI;
549 557
550 channel->region0_count = 7; 558 channel->region0_count = 7;
551 channel->region1_count = 36; 559 channel->region1_count = 36;
552 560
553 if (mad_bit_read(ptr, 1)) 561 if (mad_bit_read(ptr, 1))
554 channel->flags |= mixed_block_flag; 562 channel->flags |= mixed_block_flag;
555 else if (channel->block_type == 2) 563 else if (channel->block_type == 2)
556 channel->region0_count = 8; 564 channel->region0_count = 8;
557 565
558 for (i = 0; i < 2; ++i) 566 for (i = 0; i < 2; ++i)
559 channel->table_select[i] = mad_bit_read(ptr, 5); 567 channel->table_select[i] = mad_bit_read(ptr, 5);
560 568
561# if defined(DEBUG) 569# if defined(DEBUG)
562 channel->table_select[2] = 4; /* not used */ 570 channel->table_select[2] = 4; /* not used */
563# endif 571# endif
564 572
565 for (i = 0; i < 3; ++i) 573 for (i = 0; i < 3; ++i)
566 channel->subblock_gain[i] = mad_bit_read(ptr, 3); 574 channel->subblock_gain[i] = mad_bit_read(ptr, 3);
567 } 575 }
568 else { 576 else {
569 channel->block_type = 0; 577 channel->block_type = 0;
570 578
571 for (i = 0; i < 3; ++i) 579 for (i = 0; i < 3; ++i)
572 channel->table_select[i] = mad_bit_read(ptr, 5); 580 channel->table_select[i] = mad_bit_read(ptr, 5);
573 581
574 channel->region0_count = mad_bit_read(ptr, 4); 582 channel->region0_count = mad_bit_read(ptr, 4);
575 channel->region1_count = mad_bit_read(ptr, 3); 583 channel->region1_count = mad_bit_read(ptr, 3);
576 } 584 }
577 585
578 /* [preflag,] scalefac_scale, count1table_select */ 586 /* [preflag,] scalefac_scale, count1table_select */
579 channel->flags |= mad_bit_read(ptr, lsf ? 2 : 3); 587 channel->flags |= mad_bit_read(ptr, lsf ? 2 : 3);
580 } 588 }
581 } 589 }
582 590
583 return result; 591 return result;
584} 592}
585 593
586/* 594/*
587 * NAME:III_scalefactors_lsf() 595 * NAME:III_scalefactors_lsf()
588 * DESCRIPTION:decode channel scalefactors for LSF from a bitstream 596 * DESCRIPTION:decode channel scalefactors for LSF from a bitstream
589 */ 597 */
590static 598static
591unsigned int III_scalefactors_lsf(struct mad_bitptr *ptr, 599unsigned int III_scalefactors_lsf(struct mad_bitptr *ptr,
592 struct channel *channel, 600 struct channel *channel,
593 struct channel *gr1ch, int mode_extension) 601 struct channel *gr1ch, int mode_extension)
594{ 602{
595 struct mad_bitptr start; 603 struct mad_bitptr start;
596 unsigned int scalefac_compress, index, slen[4], part, n, i; 604 unsigned int scalefac_compress, index, slen[4], part, n, i;
597 unsigned char const *nsfb; 605 unsigned char const *nsfb;
598 606
599 start = *ptr; 607 start = *ptr;
600 608
601 scalefac_compress = channel->scalefac_compress; 609 scalefac_compress = channel->scalefac_compress;
602 index = (channel->block_type == 2) ? 610 index = (channel->block_type == 2) ?
603 ((channel->flags & mixed_block_flag) ? 2 : 1) : 0; 611 ((channel->flags & mixed_block_flag) ? 2 : 1) : 0;
604 612
605 if (!((mode_extension & 0x1) && gr1ch)) { 613 if (!((mode_extension & I_STEREO) && gr1ch)) {
606 if (scalefac_compress < 400) { 614 if (scalefac_compress < 400) {
607 slen[0] = (scalefac_compress >> 4) / 5; 615 slen[0] = (scalefac_compress >> 4) / 5;
608 slen[1] = (scalefac_compress >> 4) % 5; 616 slen[1] = (scalefac_compress >> 4) % 5;
609 slen[2] = (scalefac_compress % 16) >> 2; 617 slen[2] = (scalefac_compress % 16) >> 2;
610 slen[3] = scalefac_compress % 4; 618 slen[3] = scalefac_compress % 4;
611 619
612 nsfb = nsfb_table[0][index]; 620 nsfb = nsfb_table[0][index];
613 } 621 }
614 else if (scalefac_compress < 500) { 622 else if (scalefac_compress < 500) {
615 scalefac_compress -= 400; 623 scalefac_compress -= 400;
616 624
617 slen[0] = (scalefac_compress >> 2) / 5; 625 slen[0] = (scalefac_compress >> 2) / 5;
618 slen[1] = (scalefac_compress >> 2) % 5; 626 slen[1] = (scalefac_compress >> 2) % 5;
619 slen[2] = scalefac_compress % 4; 627 slen[2] = scalefac_compress % 4;
620 slen[3] = 0; 628 slen[3] = 0;
621 629
622 nsfb = nsfb_table[1][index]; 630 nsfb = nsfb_table[1][index];
623 } 631 }
624 else { 632 else {
625 scalefac_compress -= 500; 633 scalefac_compress -= 500;
626 634
627 slen[0] = scalefac_compress / 3; 635 slen[0] = scalefac_compress / 3;
628 slen[1] = scalefac_compress % 3; 636 slen[1] = scalefac_compress % 3;
629 slen[2] = 0; 637 slen[2] = 0;
630 slen[3] = 0; 638 slen[3] = 0;
631 639
632 channel->flags |= preflag; 640 channel->flags |= preflag;
633 641
634 nsfb = nsfb_table[2][index]; 642 nsfb = nsfb_table[2][index];
635 } 643 }
636 644
637 n = 0; 645 n = 0;
638 for (part = 0; part < 4; ++part) { 646 for (part = 0; part < 4; ++part) {
639 for (i = 0; i < nsfb[part]; ++i) 647 for (i = 0; i < nsfb[part]; ++i)
640 channel->scalefac[n++] = mad_bit_read(ptr, slen[part]); 648 channel->scalefac[n++] = mad_bit_read(ptr, slen[part]);
641 } 649 }
642 650
643 while (n < 39) 651 while (n < 39)
644 channel->scalefac[n++] = 0; 652 channel->scalefac[n++] = 0;
645 } 653 }
646 else { /* (mode_extension & 0x1) && gr1ch (i.e. ch == 1) */ 654 else { /* (mode_extension & I_STEREO) && gr1ch (i.e. ch == 1) */
647 scalefac_compress >>= 1; 655 scalefac_compress >>= 1;
648 656
649 if (scalefac_compress < 180) { 657 if (scalefac_compress < 180) {
650 slen[0] = scalefac_compress / 36; 658 slen[0] = scalefac_compress / 36;
651 slen[1] = (scalefac_compress % 36) / 6; 659 slen[1] = (scalefac_compress % 36) / 6;
652 slen[2] = (scalefac_compress % 36) % 6; 660 slen[2] = (scalefac_compress % 36) % 6;
653 slen[3] = 0; 661 slen[3] = 0;
654 662
655 nsfb = nsfb_table[3][index]; 663 nsfb = nsfb_table[3][index];
656 } 664 }
657 else if (scalefac_compress < 244) { 665 else if (scalefac_compress < 244) {
658 scalefac_compress -= 180; 666 scalefac_compress -= 180;
659 667
660 slen[0] = (scalefac_compress % 64) >> 4; 668 slen[0] = (scalefac_compress % 64) >> 4;
661 slen[1] = (scalefac_compress % 16) >> 2; 669 slen[1] = (scalefac_compress % 16) >> 2;
662 slen[2] = scalefac_compress % 4; 670 slen[2] = scalefac_compress % 4;
663 slen[3] = 0; 671 slen[3] = 0;
664 672
665 nsfb = nsfb_table[4][index]; 673 nsfb = nsfb_table[4][index];
666 } 674 }
667 else { 675 else {
668 scalefac_compress -= 244; 676 scalefac_compress -= 244;
669 677
670 slen[0] = scalefac_compress / 3; 678 slen[0] = scalefac_compress / 3;
671 slen[1] = scalefac_compress % 3; 679 slen[1] = scalefac_compress % 3;
672 slen[2] = 0; 680 slen[2] = 0;
673 slen[3] = 0; 681 slen[3] = 0;
674 682
675 nsfb = nsfb_table[5][index]; 683 nsfb = nsfb_table[5][index];
676 } 684 }
677 685
678 n = 0; 686 n = 0;
679 for (part = 0; part < 4; ++part) { 687 for (part = 0; part < 4; ++part) {
680 unsigned int max, is_pos; 688 unsigned int max, is_pos;
681 689
682 max = (1 << slen[part]) - 1; 690 max = (1 << slen[part]) - 1;
683 691
684 for (i = 0; i < nsfb[part]; ++i) { 692 for (i = 0; i < nsfb[part]; ++i) {
685 is_pos = mad_bit_read(ptr, slen[part]); 693 is_pos = mad_bit_read(ptr, slen[part]);
686 694
687 channel->scalefac[n] = is_pos; 695 channel->scalefac[n] = is_pos;
688 gr1ch->scalefac[n++] = (is_pos == max); 696 gr1ch->scalefac[n++] = (is_pos == max);
689 } 697 }
690 } 698 }
691 699
692 while (n < 39) { 700 while (n < 39) {
693 channel->scalefac[n] = 0; 701 channel->scalefac[n] = 0;
694 gr1ch->scalefac[n++] = 0; /* apparently not illegal */ 702 gr1ch->scalefac[n++] = 0; /* apparently not illegal */
695 } 703 }
696 } 704 }
697 705
698 return mad_bit_length(&start, ptr); 706 return mad_bit_length(&start, ptr);
699} 707}
700 708
701/* 709/*
702 * NAME:III_scalefactors() 710 * NAME:III_scalefactors()
703 * DESCRIPTION:decode channel scalefactors of one granule from a bitstream 711 * DESCRIPTION:decode channel scalefactors of one granule from a bitstream
704 */ 712 */
705static 713static
706unsigned int III_scalefactors(struct mad_bitptr *ptr, struct channel *channel, 714unsigned int III_scalefactors(struct mad_bitptr *ptr, struct channel *channel,
707 struct channel const *gr0ch, unsigned int scfsi) 715 struct channel const *gr0ch, unsigned int scfsi)
708{ 716{
709 struct mad_bitptr start; 717 struct mad_bitptr start;
710 unsigned int slen1, slen2, sfbi; 718 unsigned int slen1, slen2, sfbi;
711 719
712 start = *ptr; 720 start = *ptr;
713 721
714 slen1 = sflen_table[channel->scalefac_compress].slen1; 722 slen1 = sflen_table[channel->scalefac_compress].slen1;
715 slen2 = sflen_table[channel->scalefac_compress].slen2; 723 slen2 = sflen_table[channel->scalefac_compress].slen2;
716 724
717 if (channel->block_type == 2) { 725 if (channel->block_type == 2) {
718 unsigned int nsfb; 726 unsigned int nsfb;
719 727
720 sfbi = 0; 728 sfbi = 0;
721 729
722 nsfb = (channel->flags & mixed_block_flag) ? 8 + 3 * 3 : 6 * 3; 730 nsfb = (channel->flags & mixed_block_flag) ? 8 + 3 * 3 : 6 * 3;
723 while (nsfb--) 731 while (nsfb--)
724 channel->scalefac[sfbi++] = mad_bit_read(ptr, slen1); 732 channel->scalefac[sfbi++] = mad_bit_read(ptr, slen1);
725 733
726 nsfb = 6 * 3; 734 nsfb = 6 * 3;
727 while (nsfb--) 735 while (nsfb--)
728 channel->scalefac[sfbi++] = mad_bit_read(ptr, slen2); 736 channel->scalefac[sfbi++] = mad_bit_read(ptr, slen2);
729 737
730 nsfb = 1 * 3; 738 nsfb = 1 * 3;
731 while (nsfb--) 739 while (nsfb--)
732 channel->scalefac[sfbi++] = 0; 740 channel->scalefac[sfbi++] = 0;
733 } 741 }
734 else { /* channel->block_type != 2 */ 742 else { /* channel->block_type != 2 */
735 if (scfsi & 0x8) { 743 if (scfsi & 0x8) {
736 for (sfbi = 0; sfbi < 6; ++sfbi) 744 for (sfbi = 0; sfbi < 6; ++sfbi)
737 channel->scalefac[sfbi] = gr0ch->scalefac[sfbi]; 745 channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
738 } 746 }
739 else { 747 else {
740 for (sfbi = 0; sfbi < 6; ++sfbi) 748 for (sfbi = 0; sfbi < 6; ++sfbi)
741 channel->scalefac[sfbi] = mad_bit_read(ptr, slen1); 749 channel->scalefac[sfbi] = mad_bit_read(ptr, slen1);
742 } 750 }
743 751
744 if (scfsi & 0x4) { 752 if (scfsi & 0x4) {
745 for (sfbi = 6; sfbi < 11; ++sfbi) 753 for (sfbi = 6; sfbi < 11; ++sfbi)
746 channel->scalefac[sfbi] = gr0ch->scalefac[sfbi]; 754 channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
747 } 755 }
748 else { 756 else {
749 for (sfbi = 6; sfbi < 11; ++sfbi) 757 for (sfbi = 6; sfbi < 11; ++sfbi)
750 channel->scalefac[sfbi] = mad_bit_read(ptr, slen1); 758 channel->scalefac[sfbi] = mad_bit_read(ptr, slen1);
751 } 759 }
752 760
753 if (scfsi & 0x2) { 761 if (scfsi & 0x2) {
754 for (sfbi = 11; sfbi < 16; ++sfbi) 762 for (sfbi = 11; sfbi < 16; ++sfbi)
755 channel->scalefac[sfbi] = gr0ch->scalefac[sfbi]; 763 channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
756 } 764 }
757 else { 765 else {
758 for (sfbi = 11; sfbi < 16; ++sfbi) 766 for (sfbi = 11; sfbi < 16; ++sfbi)
759 channel->scalefac[sfbi] = mad_bit_read(ptr, slen2); 767 channel->scalefac[sfbi] = mad_bit_read(ptr, slen2);
760 } 768 }
761 769
762 if (scfsi & 0x1) { 770 if (scfsi & 0x1) {
763 for (sfbi = 16; sfbi < 21; ++sfbi) 771 for (sfbi = 16; sfbi < 21; ++sfbi)
764 channel->scalefac[sfbi] = gr0ch->scalefac[sfbi]; 772 channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
765 } 773 }
766 else { 774 else {
767 for (sfbi = 16; sfbi < 21; ++sfbi) 775 for (sfbi = 16; sfbi < 21; ++sfbi)
768 channel->scalefac[sfbi] = mad_bit_read(ptr, slen2); 776 channel->scalefac[sfbi] = mad_bit_read(ptr, slen2);
769 } 777 }
770 778
771 channel->scalefac[21] = 0; 779 channel->scalefac[21] = 0;
772 } 780 }
773 781
774 return mad_bit_length(&start, ptr); 782 return mad_bit_length(&start, ptr);
775} 783}
776 784
777/* 785/*
786 * The Layer III formula for requantization and scaling is defined by
787 * section 2.4.3.4.7.1 of ISO/IEC 11172-3, as follows:
788 *
789 * long blocks:
790 * xr[i] = sign(is[i]) * abs(is[i])^(4/3) *
791 * 2^((1/4) * (global_gain - 210)) *
792 * 2^-(scalefac_multiplier *
793 * (scalefac_l[sfb] + preflag * pretab[sfb]))
794 *
795 * short blocks:
796 * xr[i] = sign(is[i]) * abs(is[i])^(4/3) *
797 * 2^((1/4) * (global_gain - 210 - 8 * subblock_gain[w])) *
798 * 2^-(scalefac_multiplier * scalefac_s[sfb][w])
799 *
800 * where:
801 * scalefac_multiplier = (scalefac_scale + 1) / 2
802 *
803 * The routines III_exponents() and III_requantize() facilitate this
804 * calculation.
805 */
806
807/*
778 * NAME:III_exponents() 808 * NAME:III_exponents()
779 * DESCRIPTION:calculate scalefactor exponents 809 * DESCRIPTION:calculate scalefactor exponents
780 */ 810 */
781static 811static
782void III_exponents(struct channel const *channel, 812void III_exponents(struct channel const *channel,
783 unsigned char const *sfbwidth, signed int exponents[39]) 813 unsigned char const *sfbwidth, signed int exponents[39])
784{ 814{
785 signed int gain; 815 signed int gain;
786 unsigned int scalefac_multiplier, sfbi; 816 unsigned int scalefac_multiplier, sfbi;
787 817
788 gain = (signed int) channel->global_gain - 210; 818 gain = (signed int) channel->global_gain - 210;
789 scalefac_multiplier = (channel->flags & scalefac_scale) ? 2 : 1; 819 scalefac_multiplier = (channel->flags & scalefac_scale) ? 2 : 1;
790 820
791 if (channel->block_type == 2) { 821 if (channel->block_type == 2) {
792 unsigned int l; 822 unsigned int l;
793 signed int gain0, gain1, gain2; 823 signed int gain0, gain1, gain2;
794 824
795 sfbi = l = 0; 825 sfbi = l = 0;
796 826
797 if (channel->flags & mixed_block_flag) { 827 if (channel->flags & mixed_block_flag) {
798 unsigned int premask; 828 unsigned int premask;
799 829
800 premask = (channel->flags & preflag) ? ~0 : 0; 830 premask = (channel->flags & preflag) ? ~0 : 0;
801 831
802 /* long block subbands 0-1 */ 832 /* long block subbands 0-1 */
803 833
804 while (l < 36) { 834 while (l < 36) {
805 exponents[sfbi] = gain - 835 exponents[sfbi] = gain -
806 (signed int) ((channel->scalefac[sfbi] + (pretab[sfbi] & premask)) << 836 (signed int) ((channel->scalefac[sfbi] + (pretab[sfbi] & premask)) <<
807 scalefac_multiplier); 837 scalefac_multiplier);
808 838
809 l += sfbwidth[sfbi++]; 839 l += sfbwidth[sfbi++];
810 } 840 }
811 } 841 }
812 842
813 /* this is probably wrong for 8000 Hz short/mixed blocks */ 843 /* this is probably wrong for 8000 Hz short/mixed blocks */
814 844
815 gain0 = gain - 8 * (signed int) channel->subblock_gain[0]; 845 gain0 = gain - 8 * (signed int) channel->subblock_gain[0];
816 gain1 = gain - 8 * (signed int) channel->subblock_gain[1]; 846 gain1 = gain - 8 * (signed int) channel->subblock_gain[1];
817 gain2 = gain - 8 * (signed int) channel->subblock_gain[2]; 847 gain2 = gain - 8 * (signed int) channel->subblock_gain[2];
818 848
819 while (l < 576) { 849 while (l < 576) {
820 exponents[sfbi + 0] = gain0 - 850 exponents[sfbi + 0] = gain0 -
821 (signed int) (channel->scalefac[sfbi + 0] << scalefac_multiplier); 851 (signed int) (channel->scalefac[sfbi + 0] << scalefac_multiplier);
822 exponents[sfbi + 1] = gain1 - 852 exponents[sfbi + 1] = gain1 -
823 (signed int) (channel->scalefac[sfbi + 1] << scalefac_multiplier); 853 (signed int) (channel->scalefac[sfbi + 1] << scalefac_multiplier);
824 exponents[sfbi + 2] = gain2 - 854 exponents[sfbi + 2] = gain2 -
825 (signed int) (channel->scalefac[sfbi + 2] << scalefac_multiplier); 855 (signed int) (channel->scalefac[sfbi + 2] << scalefac_multiplier);
826 856
827 l += 3 * sfbwidth[sfbi]; 857 l += 3 * sfbwidth[sfbi];
828 sfbi += 3; 858 sfbi += 3;
829 } 859 }
830 } 860 }
831 else { /* channel->block_type != 2 */ 861 else { /* channel->block_type != 2 */
832 if (channel->flags & preflag) { 862 if (channel->flags & preflag) {
833 for (sfbi = 0; sfbi < 22; ++sfbi) { 863 for (sfbi = 0; sfbi < 22; ++sfbi) {
834 exponents[sfbi] = gain - 864 exponents[sfbi] = gain -
835 (signed int) ((channel->scalefac[sfbi] + pretab[sfbi]) << 865 (signed int) ((channel->scalefac[sfbi] + pretab[sfbi]) <<
836 scalefac_multiplier); 866 scalefac_multiplier);
837 } 867 }
838 } 868 }
839 else { 869 else {
840 for (sfbi = 0; sfbi < 22; ++sfbi) { 870 for (sfbi = 0; sfbi < 22; ++sfbi) {
841 exponents[sfbi] = gain - 871 exponents[sfbi] = gain -
842 (signed int) (channel->scalefac[sfbi] << scalefac_multiplier); 872 (signed int) (channel->scalefac[sfbi] << scalefac_multiplier);
843 } 873 }
844 } 874 }
845 } 875 }
846} 876}
847 877
848/* 878/*
849 * NAME:III_requantize() 879 * NAME:III_requantize()
850 * DESCRIPTION:requantize one (positive) value 880 * DESCRIPTION:requantize one (positive) value
851 */ 881 */
852static 882static
853mad_fixed_t III_requantize(unsigned int value, signed int exp) 883mad_fixed_t III_requantize(unsigned int value, signed int exp)
854{ 884{
855 mad_fixed_t requantized; 885 mad_fixed_t requantized;
856 signed int frac; 886 signed int frac;
857 struct fixedfloat const *power; 887 struct fixedfloat const *power;
858 888
859 /* 889 frac = exp % 4; /* assumes sign(frac) == sign(exp) */
860 * long blocks:
861 * xr[i] = sign(is[i]) * abs(is[i])^(4/3) *
862 * 2^((1/4) * (global_gain - 210)) *
863 * 2^-(scalefac_multiplier *
864 * (scalefac_l[sfb] + preflag * pretab[sfb]))
865 *
866 * short blocks:
867 * xr[i] = sign(is[i]) * abs(is[i])^(4/3) *
868 * 2^((1/4) * (global_gain - 210 - 8 * subblock_gain[w])) *
869 * 2^-(scalefac_multiplier * scalefac_s[sfb][w])
870 *
871 * where:
872 * scalefac_multiplier = (scalefac_scale + 1) / 2
873 */
874
875 frac = exp % 4;
876 exp /= 4; 890 exp /= 4;
877 891
878 power = &rq_table[value]; 892 power = &rq_table[value];
879 requantized = power->mantissa; 893 requantized = power->mantissa;
880 exp += power->exponent; 894 exp += power->exponent;
881 895
882 if (exp < 0) { 896 if (exp < 0) {
883 if (-exp >= sizeof(mad_fixed_t) * CHAR_BIT) { 897 if (-exp >= sizeof(mad_fixed_t) * CHAR_BIT) {
884 /* underflow */ 898 /* underflow */
885 requantized = 0; 899 requantized = 0;
886 } 900 }
887 else 901 else {
902 requantized += 1L << (-exp - 1);
888 requantized >>= -exp; 903 requantized >>= -exp;
904 }
889 } 905 }
890 else { 906 else {
891 if (exp >= 5) { 907 if (exp >= 5) {
892 /* overflow */ 908 /* overflow */
893# if defined(DEBUG) 909# if defined(DEBUG)
894 fprintf(stderr, "requantize overflow (%f * 2^%d)\n", 910 fprintf(stderr, "requantize overflow (%f * 2^%d)\n",
895 mad_f_todouble(requantized), exp); 911 mad_f_todouble(requantized), exp);
896# endif 912# endif
897 requantized = MAD_F_MAX; 913 requantized = MAD_F_MAX;
898 } 914 }
899 else 915 else
900 requantized <<= exp; 916 requantized <<= exp;
901 } 917 }
902 918
903 return frac ? mad_f_mul(requantized, root_table[3 + frac]) : requantized; 919 return frac ? mad_f_mul(requantized, root_table[3 + frac]) : requantized;
904} 920}
905 921
906/* we must take care that sz >= bits and sz < sizeof(long) lest bits == 0 */ 922/* we must take care that sz >= bits and sz < sizeof(long) lest bits == 0 */
907 # define MASK(cache, sz, bits)\ 923 # define MASK(cache, sz, bits)\
908 (((cache) >> ((sz) - (bits))) & ((1 << (bits)) - 1)) 924 (((cache) >> ((sz) - (bits))) & ((1 << (bits)) - 1))
909# define MASK1BIT(cache, sz) \ 925# define MASK1BIT(cache, sz) \
910 ((cache) & (1 << ((sz) - 1))) 926 ((cache) & (1 << ((sz) - 1)))
911 927
912/* 928/*
913 * NAME:III_huffdecode() 929 * NAME:III_huffdecode()
914 * DESCRIPTION:decode Huffman code words of one channel of one granule 930 * DESCRIPTION:decode Huffman code words of one channel of one granule
915 */ 931 */
916static 932static
917enum mad_error III_huffdecode(struct mad_bitptr *ptr, mad_fixed_t xr[576], 933enum mad_error III_huffdecode(struct mad_bitptr *ptr, mad_fixed_t xr[576],
918 struct channel *channel, 934 struct channel *channel,
919 unsigned char const *sfbwidth, 935 unsigned char const *sfbwidth,
920 unsigned int part2_length) 936 unsigned int part2_length)
921{ 937{
922 signed int exponents[39], exp; 938 signed int exponents[39], exp;
923 signed int const *expptr; 939 signed int const *expptr;
924 struct mad_bitptr peek; 940 struct mad_bitptr peek;
925 signed int bits_left, cachesz; 941 signed int bits_left, cachesz;
926 register mad_fixed_t *xrptr; 942 register mad_fixed_t *xrptr;
927 mad_fixed_t const *sfbound; 943 mad_fixed_t const *sfbound;
928 register unsigned long bitcache; 944 register unsigned long bitcache;
929 945
930 bits_left = (signed) channel->part2_3_length - (signed) part2_length; 946 bits_left = (signed) channel->part2_3_length - (signed) part2_length;
931 if (bits_left < 0) 947 if (bits_left < 0)
932 return MAD_ERROR_BADPART3LEN; 948 return MAD_ERROR_BADPART3LEN;
933 949
934 III_exponents(channel, sfbwidth, exponents); 950 III_exponents(channel, sfbwidth, exponents);
935 951
936 peek = *ptr; 952 peek = *ptr;
937 mad_bit_skip(ptr, bits_left); 953 mad_bit_skip(ptr, bits_left);
938 954
939 /* align bit reads to byte boundaries */ 955 /* align bit reads to byte boundaries */
940 cachesz = mad_bit_bitsleft(&peek); 956 cachesz = mad_bit_bitsleft(&peek);
941 cachesz += ((32 - 1 - 24) + (24 - cachesz)) & ~7; 957 cachesz += ((32 - 1 - 24) + (24 - cachesz)) & ~7;
942 958
943 bitcache = mad_bit_read(&peek, cachesz); 959 bitcache = mad_bit_read(&peek, cachesz);
944 bits_left -= cachesz; 960 bits_left -= cachesz;
945 961
946 xrptr = &xr[0]; 962 xrptr = &xr[0];
947 963
948 /* big_values */ 964 /* big_values */
949 { 965 {
950 unsigned int region, rcount; 966 unsigned int region, rcount;
951 struct hufftable const *entry; 967 struct hufftable const *entry;
952 union huffpair const *table; 968 union huffpair const *table;
953 unsigned int linbits, startbits, big_values, reqhits; 969 unsigned int linbits, startbits, big_values, reqhits;
954 mad_fixed_t reqcache[16]; 970 mad_fixed_t reqcache[16];
955 971
956 sfbound = xrptr + *sfbwidth++; 972 sfbound = xrptr + *sfbwidth++;
957 rcount = channel->region0_count + 1; 973 rcount = channel->region0_count + 1;
958 974
959 entry = &mad_huff_pair_table[channel->table_select[region = 0]]; 975 entry = &mad_huff_pair_table[channel->table_select[region = 0]];
960 table = entry->table; 976 table = entry->table;
961 linbits = entry->linbits; 977 linbits = entry->linbits;
962 startbits = entry->startbits; 978 startbits = entry->startbits;
963 979
964 if (table == 0) 980 if (table == 0)
965 return MAD_ERROR_BADHUFFTABLE; 981 return MAD_ERROR_BADHUFFTABLE;
966 982
967 expptr = &exponents[0]; 983 expptr = &exponents[0];
968 exp = *expptr++; 984 exp = *expptr++;
969 reqhits = 0; 985 reqhits = 0;
970 986
971 big_values = channel->big_values; 987 big_values = channel->big_values;
972 988
973 while (big_values-- && cachesz + bits_left > 0) { 989 while (big_values-- && cachesz + bits_left > 0) {
974 union huffpair const *pair; 990 union huffpair const *pair;
975 unsigned int clumpsz, value; 991 unsigned int clumpsz, value;
976 register mad_fixed_t requantized; 992 register mad_fixed_t requantized;
977 993
978 if (xrptr == sfbound) { 994 if (xrptr == sfbound) {
979 sfbound += *sfbwidth++; 995 sfbound += *sfbwidth++;
980 996
981 /* change table if region boundary */ 997 /* change table if region boundary */
982 998
983 if (--rcount == 0) { 999 if (--rcount == 0) {
984 if (region == 0) 1000 if (region == 0)
985 rcount = channel->region1_count + 1; 1001 rcount = channel->region1_count + 1;
986 else 1002 else
987 rcount = 0; /* all remaining */ 1003 rcount = 0; /* all remaining */
988 1004
989 entry = &mad_huff_pair_table[channel->table_select[++region]]; 1005 entry = &mad_huff_pair_table[channel->table_select[++region]];
990 table = entry->table; 1006 table = entry->table;
991 linbits = entry->linbits; 1007 linbits = entry->linbits;
992 startbits = entry->startbits; 1008 startbits = entry->startbits;
993 1009
994 if (table == 0) 1010 if (table == 0)
995 return MAD_ERROR_BADHUFFTABLE; 1011 return MAD_ERROR_BADHUFFTABLE;
996 } 1012 }
997 1013
998 if (exp != *expptr) { 1014 if (exp != *expptr) {
999 exp = *expptr; 1015 exp = *expptr;
1000 reqhits = 0; 1016 reqhits = 0;
1001 } 1017 }
1002 1018
1003 ++expptr; 1019 ++expptr;
1004 } 1020 }
1005 1021
1006 if (cachesz < 21) { 1022 if (cachesz < 21) {
1007 unsigned int bits; 1023 unsigned int bits;
1008 1024
1009 bits = ((32 - 1 - 21) + (21 - cachesz)) & ~7; 1025 bits = ((32 - 1 - 21) + (21 - cachesz)) & ~7;
1010 bitcache = (bitcache << bits) | mad_bit_read(&peek, bits); 1026 bitcache = (bitcache << bits) | mad_bit_read(&peek, bits);
1011 cachesz += bits; 1027 cachesz += bits;
1012 bits_left -= bits; 1028 bits_left -= bits;
1013 } 1029 }
1014 1030
1015 /* hcod (0..19) */ 1031 /* hcod (0..19) */
1016 1032
1017 clumpsz = startbits; 1033 clumpsz = startbits;
1018 pair = &table[MASK(bitcache, cachesz, clumpsz)]; 1034 pair = &table[MASK(bitcache, cachesz, clumpsz)];
1019 1035
1020 while (!pair->final) { 1036 while (!pair->final) {
1021 cachesz -= clumpsz; 1037 cachesz -= clumpsz;
1022 1038
1023 clumpsz = pair->ptr.bits; 1039 clumpsz = pair->ptr.bits;
1024 pair = &table[pair->ptr.offset + MASK(bitcache, cachesz, clumpsz)]; 1040 pair = &table[pair->ptr.offset + MASK(bitcache, cachesz, clumpsz)];
1025 } 1041 }
1026 1042
1027 cachesz -= pair->value.hlen; 1043 cachesz -= pair->value.hlen;
1028 1044
1029 if (linbits) { 1045 if (linbits) {
1030 /* x (0..14) */ 1046 /* x (0..14) */
1031 1047
1032 value = pair->value.x; 1048 value = pair->value.x;
1033 1049
1034 switch (value) { 1050 switch (value) {
1035 case 0: 1051 case 0:
1036 xrptr[0] = 0; 1052 xrptr[0] = 0;
1037 break; 1053 break;
1038 1054
1039 case 15: 1055 case 15:
1040 if (cachesz < linbits + 2) { 1056 if (cachesz < linbits + 2) {
1041 bitcache = (bitcache << 16) | mad_bit_read(&peek, 16); 1057 bitcache = (bitcache << 16) | mad_bit_read(&peek, 16);
1042 cachesz += 16; 1058 cachesz += 16;
1043 bits_left -= 16; 1059 bits_left -= 16;
1044 } 1060 }
1045 1061
1046 value += MASK(bitcache, cachesz, linbits); 1062 value += MASK(bitcache, cachesz, linbits);
1047 cachesz -= linbits; 1063 cachesz -= linbits;
1048 1064
1049 requantized = III_requantize(value, exp); 1065 requantized = III_requantize(value, exp);
1050 goto x_final; 1066 goto x_final;
1051 1067
1052 default: 1068 default:
1053 if (reqhits & (1 << value)) 1069 if (reqhits & (1 << value))
1054 requantized = reqcache[value]; 1070 requantized = reqcache[value];
1055 else { 1071 else {
1056 reqhits |= (1 << value); 1072 reqhits |= (1 << value);
1057 requantized = reqcache[value] = III_requantize(value, exp); 1073 requantized = reqcache[value] = III_requantize(value, exp);
1058 } 1074 }
1059 1075
1060 x_final: 1076 x_final:
1061 xrptr[0] = MASK1BIT(bitcache, cachesz--) ? 1077 xrptr[0] = MASK1BIT(bitcache, cachesz--) ?
1062 -requantized : requantized; 1078 -requantized : requantized;
1063 } 1079 }
1064 1080
1065 /* y (0..14) */ 1081 /* y (0..14) */
1066 1082
1067 value = pair->value.y; 1083 value = pair->value.y;
1068 1084
1069 switch (value) { 1085 switch (value) {
1070 case 0: 1086 case 0:
1071 xrptr[1] = 0; 1087 xrptr[1] = 0;
1072 break; 1088 break;
1073 1089
1074 case 15: 1090 case 15:
1075 if (cachesz < linbits + 1) { 1091 if (cachesz < linbits + 1) {
1076 bitcache = (bitcache << 16) | mad_bit_read(&peek, 16); 1092 bitcache = (bitcache << 16) | mad_bit_read(&peek, 16);
1077 cachesz += 16; 1093 cachesz += 16;
1078 bits_left -= 16; 1094 bits_left -= 16;
1079 } 1095 }
1080 1096
1081 value += MASK(bitcache, cachesz, linbits); 1097 value += MASK(bitcache, cachesz, linbits);
1082 cachesz -= linbits; 1098 cachesz -= linbits;
1083 1099
1084 requantized = III_requantize(value, exp); 1100 requantized = III_requantize(value, exp);
1085 goto y_final; 1101 goto y_final;
1086 1102
1087 default: 1103 default:
1088 if (reqhits & (1 << value)) 1104 if (reqhits & (1 << value))
1089 requantized = reqcache[value]; 1105 requantized = reqcache[value];
1090 else { 1106 else {
1091 reqhits |= (1 << value); 1107 reqhits |= (1 << value);
1092 requantized = reqcache[value] = III_requantize(value, exp); 1108 requantized = reqcache[value] = III_requantize(value, exp);
1093 } 1109 }
1094 1110
1095 y_final: 1111 y_final:
1096 xrptr[1] = MASK1BIT(bitcache, cachesz--) ? 1112 xrptr[1] = MASK1BIT(bitcache, cachesz--) ?
1097 -requantized : requantized; 1113 -requantized : requantized;
1098 } 1114 }
1099 } 1115 }
1100 else { 1116 else {
1101 /* x (0..1) */ 1117 /* x (0..1) */
1102 1118
1103 value = pair->value.x; 1119 value = pair->value.x;
1104 1120
1105 if (value == 0) 1121 if (value == 0)
1106 xrptr[0] = 0; 1122 xrptr[0] = 0;
1107 else { 1123 else {
1108 if (reqhits & (1 << value)) 1124 if (reqhits & (1 << value))
1109 requantized = reqcache[value]; 1125 requantized = reqcache[value];
1110 else { 1126 else {
1111 reqhits |= (1 << value); 1127 reqhits |= (1 << value);
1112 requantized = reqcache[value] = III_requantize(value, exp); 1128 requantized = reqcache[value] = III_requantize(value, exp);
1113 } 1129 }
1114 1130
1115 xrptr[0] = MASK1BIT(bitcache, cachesz--) ? 1131 xrptr[0] = MASK1BIT(bitcache, cachesz--) ?
1116 -requantized : requantized; 1132 -requantized : requantized;
1117 } 1133 }
1118 1134
1119 /* y (0..1) */ 1135 /* y (0..1) */
1120 1136
1121 value = pair->value.y; 1137 value = pair->value.y;
1122 1138
1123 if (value == 0) 1139 if (value == 0)
1124 xrptr[1] = 0; 1140 xrptr[1] = 0;
1125 else { 1141 else {
1126 if (reqhits & (1 << value)) 1142 if (reqhits & (1 << value))
1127 requantized = reqcache[value]; 1143 requantized = reqcache[value];
1128 else { 1144 else {
1129 reqhits |= (1 << value); 1145 reqhits |= (1 << value);
1130 requantized = reqcache[value] = III_requantize(value, exp); 1146 requantized = reqcache[value] = III_requantize(value, exp);
1131 } 1147 }
1132 1148
1133 xrptr[1] = MASK1BIT(bitcache, cachesz--) ? 1149 xrptr[1] = MASK1BIT(bitcache, cachesz--) ?
1134 -requantized : requantized; 1150 -requantized : requantized;
1135 } 1151 }
1136 } 1152 }
1137 1153
1138 xrptr += 2; 1154 xrptr += 2;
1139 } 1155 }
1140 } 1156 }
1141 1157
1142 if (cachesz + bits_left < 0) 1158 if (cachesz + bits_left < 0)
1143 return MAD_ERROR_BADHUFFDATA; /* big_values overrun */ 1159 return MAD_ERROR_BADHUFFDATA; /* big_values overrun */
1144 1160
1145 /* count1 */ 1161 /* count1 */
1146 { 1162 {
1147 union huffquad const *table; 1163 union huffquad const *table;
1148 register mad_fixed_t requantized; 1164 register mad_fixed_t requantized;
1149 1165
1150 table = mad_huff_quad_table[channel->flags & count1table_select]; 1166 table = mad_huff_quad_table[channel->flags & count1table_select];
1151 1167
1152 requantized = III_requantize(1, exp); 1168 requantized = III_requantize(1, exp);
1153 1169
1154 while (cachesz + bits_left > 0 && xrptr <= &xr[572]) { 1170 while (cachesz + bits_left > 0 && xrptr <= &xr[572]) {
1155 union huffquad const *quad; 1171 union huffquad const *quad;
1156 1172
1157 /* hcod (1..6) */ 1173 /* hcod (1..6) */
1158 1174
1159 if (cachesz < 10) { 1175 if (cachesz < 10) {
1160 bitcache = (bitcache << 16) | mad_bit_read(&peek, 16); 1176 bitcache = (bitcache << 16) | mad_bit_read(&peek, 16);
1161 cachesz += 16; 1177 cachesz += 16;
1162 bits_left -= 16; 1178 bits_left -= 16;
1163 } 1179 }
1164 1180
1165 quad = &table[MASK(bitcache, cachesz, 4)]; 1181 quad = &table[MASK(bitcache, cachesz, 4)];
1166 1182
1167 /* quad tables guaranteed to have at most one extra lookup */ 1183 /* quad tables guaranteed to have at most one extra lookup */
1168 if (!quad->final) { 1184 if (!quad->final) {
1169 cachesz -= 4; 1185 cachesz -= 4;
1170 1186
1171 quad = &table[quad->ptr.offset + 1187 quad = &table[quad->ptr.offset +
1172 MASK(bitcache, cachesz, quad->ptr.bits)]; 1188 MASK(bitcache, cachesz, quad->ptr.bits)];
1173 } 1189 }
1174 1190
1175 cachesz -= quad->value.hlen; 1191 cachesz -= quad->value.hlen;
1176 1192
1177 if (xrptr == sfbound) { 1193 if (xrptr == sfbound) {
1178 sfbound += *sfbwidth++; 1194 sfbound += *sfbwidth++;
1179 1195
1180 if (exp != *expptr) { 1196 if (exp != *expptr) {
1181 exp = *expptr; 1197 exp = *expptr;
1182 requantized = III_requantize(1, exp); 1198 requantized = III_requantize(1, exp);
1183 } 1199 }
1184 1200
1185 ++expptr; 1201 ++expptr;
1186 } 1202 }
1187 1203
1188 /* v (0..1) */ 1204 /* v (0..1) */
1189 1205
1190 xrptr[0] = quad->value.v ? 1206 xrptr[0] = quad->value.v ?
1191 (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0; 1207 (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
1192 1208
1193 /* w (0..1) */ 1209 /* w (0..1) */
1194 1210
1195 xrptr[1] = quad->value.w ? 1211 xrptr[1] = quad->value.w ?
1196 (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0; 1212 (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
1197 1213
1198 xrptr += 2; 1214 xrptr += 2;
1199 1215
1200 if (xrptr == sfbound) { 1216 if (xrptr == sfbound) {
1201 sfbound += *sfbwidth++; 1217 sfbound += *sfbwidth++;
1202 1218
1203 if (exp != *expptr) { 1219 if (exp != *expptr) {
1204 exp = *expptr; 1220 exp = *expptr;
1205 requantized = III_requantize(1, exp); 1221 requantized = III_requantize(1, exp);
1206 } 1222 }
1207 1223
1208 ++expptr; 1224 ++expptr;
1209 } 1225 }
1210 1226
1211 /* x (0..1) */ 1227 /* x (0..1) */
1212 1228
1213 xrptr[0] = quad->value.x ? 1229 xrptr[0] = quad->value.x ?
1214 (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0; 1230 (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
1215 1231
1216 /* y (0..1) */ 1232 /* y (0..1) */
1217 1233
1218 xrptr[1] = quad->value.y ? 1234 xrptr[1] = quad->value.y ?
1219 (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0; 1235 (MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
1220 1236
1221 xrptr += 2; 1237 xrptr += 2;
1222 } 1238 }
1223 1239
1224 if (cachesz + bits_left < 0) { 1240 if (cachesz + bits_left < 0) {
1225# if 0 && defined(DEBUG) 1241# if 0 && defined(DEBUG)
1226 fprintf(stderr, "huffman count1 overrun (%d bits)\n", 1242 fprintf(stderr, "huffman count1 overrun (%d bits)\n",
1227 -(cachesz + bits_left)); 1243 -(cachesz + bits_left));
1228# endif 1244# endif
1229 1245
1230 /* technically the bitstream is misformatted, but apparently 1246 /* technically the bitstream is misformatted, but apparently
1231 some encoders are just a bit sloppy with stuffing bits */ 1247 some encoders are just a bit sloppy with stuffing bits */
1232 1248
1233 xrptr -= 4; 1249 xrptr -= 4;
1234 } 1250 }
1235 } 1251 }
1236 1252
1237 assert(-bits_left <= MAD_BUFFER_GUARD * CHAR_BIT); 1253 assert(-bits_left <= MAD_BUFFER_GUARD * CHAR_BIT);
1238 1254
1239# if 0 && defined(DEBUG) 1255# if 0 && defined(DEBUG)
1240 if (bits_left < 0) 1256 if (bits_left < 0)
1241 fprintf(stderr, "read %d bits too many\n", -bits_left); 1257 fprintf(stderr, "read %d bits too many\n", -bits_left);
1242 else if (cachesz + bits_left > 0) 1258 else if (cachesz + bits_left > 0)
1243 fprintf(stderr, "%d stuffing bits\n", cachesz + bits_left); 1259 fprintf(stderr, "%d stuffing bits\n", cachesz + bits_left);
1244# endif 1260# endif
1245 1261
1246 /* rzero */ 1262 /* rzero */
1247 while (xrptr < &xr[576]) { 1263 while (xrptr < &xr[576]) {
1248 xrptr[0] = 0; 1264 xrptr[0] = 0;
1249 xrptr[1] = 0; 1265 xrptr[1] = 0;
1250 1266
1251 xrptr += 2; 1267 xrptr += 2;
1252 } 1268 }
1253 1269
1254 return 0; 1270 return MAD_ERROR_NONE;
1255} 1271}
1256 1272
1257# undef MASK 1273# undef MASK
1258# undef MASK1BIT 1274# undef MASK1BIT
1259 1275
1260/* 1276/*
1261 * NAME:III_reorder() 1277 * NAME:III_reorder()
1262 * DESCRIPTION:reorder frequency lines of a short block into subband order 1278 * DESCRIPTION:reorder frequency lines of a short block into subband order
1263 */ 1279 */
1264static 1280static
1265void III_reorder(mad_fixed_t xr[576], struct channel const *channel, 1281void III_reorder(mad_fixed_t xr[576], struct channel const *channel,
1266 unsigned char const sfbwidth[39]) 1282 unsigned char const sfbwidth[39])
1267{ 1283{
1268 mad_fixed_t tmp[32][3][6]; 1284 mad_fixed_t tmp[32][3][6];
1269 unsigned int sb, l, sfbi, f, w, sbw[3], sw[3]; 1285 unsigned int sb, l, f, w, sbw[3], sw[3];
1270 1286
1271 /* this is probably wrong for 8000 Hz mixed blocks */ 1287 /* this is probably wrong for 8000 Hz mixed blocks */
1272 1288
1273 if (channel->flags & mixed_block_flag) 1289 sb = 0;
1274 sb = 2, sfbi = 3 * 3; 1290 if (channel->flags & mixed_block_flag) {
1275 else 1291 sb = 2;
1276 sb = 0, sfbi = 0; 1292
1293 l = 0;
1294 while (l < 36)
1295 l += *sfbwidth++;
1296 }
1277 1297
1278 for (w = 0; w < 3; ++w) { 1298 for (w = 0; w < 3; ++w) {
1279 sbw[w] = sb; 1299 sbw[w] = sb;
1280 sw[w] = 0; 1300 sw[w] = 0;
1281 } 1301 }
1282 1302
1283 f = sfbwidth[sfbi]; 1303 f = *sfbwidth++;
1284 w = 0; 1304 w = 0;
1285 1305
1286 for (l = 18 * sb; l < 576; ++l) { 1306 for (l = 18 * sb; l < 576; ++l) {
1307 if (f-- == 0) {
1308 f = *sfbwidth++ - 1;
1309 w = (w + 1) % 3;
1310 }
1311
1287 tmp[sbw[w]][w][sw[w]++] = xr[l]; 1312 tmp[sbw[w]][w][sw[w]++] = xr[l];
1288 1313
1289 if (sw[w] == 6) { 1314 if (sw[w] == 6) {
1290 sw[w] = 0; 1315 sw[w] = 0;
1291 ++sbw[w]; 1316 ++sbw[w];
1292 } 1317 }
1293
1294 if (--f == 0) {
1295 if (++w == 3)
1296 w = 0;
1297
1298 f = sfbwidth[++sfbi];
1299 }
1300 } 1318 }
1301 1319
1302 memcpy(&xr[18 * sb], &tmp[sb], (576 - 18 * sb) * sizeof(mad_fixed_t)); 1320 memcpy(&xr[18 * sb], &tmp[sb], (576 - 18 * sb) * sizeof(mad_fixed_t));
1303} 1321}
1304 1322
1305/* 1323/*
1306 * NAME:III_stereo() 1324 * NAME:III_stereo()
1307 * DESCRIPTION:perform joint stereo processing on a granule 1325 * DESCRIPTION:perform joint stereo processing on a granule
1308 */ 1326 */
1309static 1327static
1310enum mad_error III_stereo(mad_fixed_t xr[2][576], 1328enum mad_error III_stereo(mad_fixed_t xr[2][576],
1311 struct granule const *granule, 1329 struct granule const *granule,
1312 struct mad_header *header, 1330 struct mad_header *header,
1313 unsigned char const *sfbwidth) 1331 unsigned char const *sfbwidth)
1314{ 1332{
1315 short modes[39]; 1333 short modes[39];
1316 unsigned int sfbi, l, n, i; 1334 unsigned int sfbi, l, n, i;
1317 1335
1318 enum {
1319 i_stereo = 0x1,
1320 ms_stereo = 0x2
1321 };
1322
1323 if (granule->ch[0].block_type != 1336 if (granule->ch[0].block_type !=
1324 granule->ch[1].block_type || 1337 granule->ch[1].block_type ||
1325 (granule->ch[0].flags & mixed_block_flag) != 1338 (granule->ch[0].flags & mixed_block_flag) !=
1326 (granule->ch[1].flags & mixed_block_flag)) 1339 (granule->ch[1].flags & mixed_block_flag))
1327 return MAD_ERROR_BADSTEREO; 1340 return MAD_ERROR_BADSTEREO;
1328 1341
1329 for (i = 0; i < 39; ++i) 1342 for (i = 0; i < 39; ++i)
1330 modes[i] = header->mode_extension; 1343 modes[i] = header->mode_extension;
1331 1344
1332 /* intensity stereo */ 1345 /* intensity stereo */
1333 1346
1334 if (header->mode_extension & i_stereo) { 1347 if (header->mode_extension & I_STEREO) {
1335 struct channel const *right_ch = &granule->ch[1]; 1348 struct channel const *right_ch = &granule->ch[1];
1336 mad_fixed_t const *right_xr = xr[1]; 1349 mad_fixed_t const *right_xr = xr[1];
1337 unsigned int is_pos; 1350 unsigned int is_pos;
1338 1351
1339 header->flags |= MAD_FLAG_I_STEREO; 1352 header->flags |= MAD_FLAG_I_STEREO;
1340 1353
1341 /* first determine which scalefactor bands are to be processed */ 1354 /* first determine which scalefactor bands are to be processed */
1342 1355
1343 if (right_ch->block_type == 2) { 1356 if (right_ch->block_type == 2) {
1344 unsigned int lower, start, max, bound[3], w; 1357 unsigned int lower, start, max, bound[3], w;
1345 1358
1346 lower = start = max = bound[0] = bound[1] = bound[2] = 0; 1359 lower = start = max = bound[0] = bound[1] = bound[2] = 0;
1347 1360
1348 sfbi = l = 0; 1361 sfbi = l = 0;
1349 1362
1350 if (right_ch->flags & mixed_block_flag) { 1363 if (right_ch->flags & mixed_block_flag) {
1351 while (l < 36) { 1364 while (l < 36) {
1352 n = sfbwidth[sfbi++]; 1365 n = sfbwidth[sfbi++];
1353 1366
1354 for (i = 0; i < n; ++i) { 1367 for (i = 0; i < n; ++i) {
1355 if (right_xr[i]) { 1368 if (right_xr[i]) {
1356 lower = sfbi; 1369 lower = sfbi;
1357 break; 1370 break;
1358 } 1371 }
1359 } 1372 }
1360 1373
1361 right_xr += n; 1374 right_xr += n;
1362 l += n; 1375 l += n;
1363 } 1376 }
1364 1377
1365 start = sfbi; 1378 start = sfbi;
1366 } 1379 }
1367 1380
1368 w = 0; 1381 w = 0;
1369 while (l < 576) { 1382 while (l < 576) {
1370 n = sfbwidth[sfbi++]; 1383 n = sfbwidth[sfbi++];
1371 1384
1372 for (i = 0; i < n; ++i) { 1385 for (i = 0; i < n; ++i) {
1373 if (right_xr[i]) { 1386 if (right_xr[i]) {
1374 max = bound[w] = sfbi; 1387 max = bound[w] = sfbi;
1375 break; 1388 break;
1376 } 1389 }
1377 } 1390 }
1378 1391
1379 right_xr += n; 1392 right_xr += n;
1380 l += n; 1393 l += n;
1381 w = (w + 1) % 3; 1394 w = (w + 1) % 3;
1382 } 1395 }
1383 1396
1384 if (max) 1397 if (max)
1385 lower = start; 1398 lower = start;
1386 1399
1387 /* long blocks */ 1400 /* long blocks */
1388 1401
1389 for (i = 0; i < lower; ++i) 1402 for (i = 0; i < lower; ++i)
1390 modes[i] = header->mode_extension & ~i_stereo; 1403 modes[i] = header->mode_extension & ~I_STEREO;
1391 1404
1392 /* short blocks */ 1405 /* short blocks */
1393 1406
1394 w = 0; 1407 w = 0;
1395 for (i = start; i < max; ++i) { 1408 for (i = start; i < max; ++i) {
1396 if (i < bound[w]) 1409 if (i < bound[w])
1397 modes[i] = header->mode_extension & ~i_stereo; 1410 modes[i] = header->mode_extension & ~I_STEREO;
1398 1411
1399 w = (w + 1) % 3; 1412 w = (w + 1) % 3;
1400 } 1413 }
1401 } 1414 }
1402 else { /* right_ch->block_type != 2 */ 1415 else { /* right_ch->block_type != 2 */
1403 unsigned int bound; 1416 unsigned int bound;
1404 1417
1405 bound = 0; 1418 bound = 0;
1406 for (sfbi = l = 0; l < 576; l += n) { 1419 for (sfbi = l = 0; l < 576; l += n) {
1407 n = sfbwidth[sfbi++]; 1420 n = sfbwidth[sfbi++];
1408 1421
1409 for (i = 0; i < n; ++i) { 1422 for (i = 0; i < n; ++i) {
1410 if (right_xr[i]) { 1423 if (right_xr[i]) {
1411 bound = sfbi; 1424 bound = sfbi;
1412 break; 1425 break;
1413 } 1426 }
1414 } 1427 }
1415 1428
1416 right_xr += n; 1429 right_xr += n;
1417 } 1430 }
1418 1431
1419 for (i = 0; i < bound; ++i) 1432 for (i = 0; i < bound; ++i)
1420 modes[i] = header->mode_extension & ~i_stereo; 1433 modes[i] = header->mode_extension & ~I_STEREO;
1421 } 1434 }
1422 1435
1423 /* now do the actual processing */ 1436 /* now do the actual processing */
1424 1437
1425 if (header->flags & MAD_FLAG_LSF_EXT) { 1438 if (header->flags & MAD_FLAG_LSF_EXT) {
1426 unsigned char const *illegal_pos = granule[1].ch[1].scalefac; 1439 unsigned char const *illegal_pos = granule[1].ch[1].scalefac;
1427 mad_fixed_t const *lsf_scale; 1440 mad_fixed_t const *lsf_scale;
1428 1441
1429 /* intensity_scale */ 1442 /* intensity_scale */
1430 lsf_scale = is_lsf_table[right_ch->scalefac_compress & 0x1]; 1443 lsf_scale = is_lsf_table[right_ch->scalefac_compress & 0x1];
1431 1444
1432 for (sfbi = l = 0; l < 576; ++sfbi, l += n) { 1445 for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
1433 n = sfbwidth[sfbi]; 1446 n = sfbwidth[sfbi];
1434 1447
1435 if (!(modes[sfbi] & i_stereo)) 1448 if (!(modes[sfbi] & I_STEREO))
1436 continue; 1449 continue;
1437 1450
1438 if (illegal_pos[sfbi]) { 1451 if (illegal_pos[sfbi]) {
1439 modes[sfbi] &= ~i_stereo; 1452 modes[sfbi] &= ~I_STEREO;
1440 continue; 1453 continue;
1441 } 1454 }
1442 1455
1443 is_pos = right_ch->scalefac[sfbi]; 1456 is_pos = right_ch->scalefac[sfbi];
1444 1457
1445 for (i = 0; i < n; ++i) { 1458 for (i = 0; i < n; ++i) {
1446 register mad_fixed_t left; 1459 register mad_fixed_t left;
1447 1460
1448 left = xr[0][l + i]; 1461 left = xr[0][l + i];
1449 1462
1450 if (is_pos == 0) 1463 if (is_pos == 0)
1451 xr[1][l + i] = left; 1464 xr[1][l + i] = left;
1452 else { 1465 else {
1453 register mad_fixed_t opposite; 1466 register mad_fixed_t opposite;
1454 1467
1455 opposite = mad_f_mul(left, lsf_scale[(is_pos - 1) / 2]); 1468 opposite = mad_f_mul(left, lsf_scale[(is_pos - 1) / 2]);
1456 1469
1457 if (is_pos & 1) { 1470 if (is_pos & 1) {
1458 xr[0][l + i] = opposite; 1471 xr[0][l + i] = opposite;
1459 xr[1][l + i] = left; 1472 xr[1][l + i] = left;
1460 } 1473 }
1461 else 1474 else
1462 xr[1][l + i] = opposite; 1475 xr[1][l + i] = opposite;
1463 } 1476 }
1464 } 1477 }
1465 } 1478 }
1466 } 1479 }
1467 else { /* !(header->flags & MAD_FLAG_LSF_EXT) */ 1480 else { /* !(header->flags & MAD_FLAG_LSF_EXT) */
1468 for (sfbi = l = 0; l < 576; ++sfbi, l += n) { 1481 for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
1469 n = sfbwidth[sfbi]; 1482 n = sfbwidth[sfbi];
1470 1483
1471 if (!(modes[sfbi] & i_stereo)) 1484 if (!(modes[sfbi] & I_STEREO))
1472 continue; 1485 continue;
1473 1486
1474 is_pos = right_ch->scalefac[sfbi]; 1487 is_pos = right_ch->scalefac[sfbi];
1475 1488
1476 if (is_pos >= 7) { /* illegal intensity position */ 1489 if (is_pos >= 7) { /* illegal intensity position */
1477 modes[sfbi] &= ~i_stereo; 1490 modes[sfbi] &= ~I_STEREO;
1478 continue; 1491 continue;
1479 } 1492 }
1480 1493
1481 for (i = 0; i < n; ++i) { 1494 for (i = 0; i < n; ++i) {
1482 register mad_fixed_t left; 1495 register mad_fixed_t left;
1483 1496
1484 left = xr[0][l + i]; 1497 left = xr[0][l + i];
1485 1498
1486 xr[0][l + i] = mad_f_mul(left, is_table[ is_pos]); 1499 xr[0][l + i] = mad_f_mul(left, is_table[ is_pos]);
1487 xr[1][l + i] = mad_f_mul(left, is_table[6 - is_pos]); 1500 xr[1][l + i] = mad_f_mul(left, is_table[6 - is_pos]);
1488 } 1501 }
1489 } 1502 }
1490 } 1503 }
1491 } 1504 }
1492 1505
1493 /* middle/side stereo */ 1506 /* middle/side stereo */
1494 1507
1495 if (header->mode_extension & ms_stereo) { 1508 if (header->mode_extension & MS_STEREO) {
1496 register mad_fixed_t invsqrt2; 1509 register mad_fixed_t invsqrt2;
1497 1510
1498 header->flags |= MAD_FLAG_MS_STEREO; 1511 header->flags |= MAD_FLAG_MS_STEREO;
1499 1512
1500 invsqrt2 = root_table[3 + -2]; 1513 invsqrt2 = root_table[3 + -2];
1501 1514
1502 for (sfbi = l = 0; l < 576; ++sfbi, l += n) { 1515 for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
1503 n = sfbwidth[sfbi]; 1516 n = sfbwidth[sfbi];
1504 1517
1505 if (modes[sfbi] != ms_stereo) 1518 if (modes[sfbi] != MS_STEREO)
1506 continue; 1519 continue;
1507 1520
1508 for (i = 0; i < n; ++i) { 1521 for (i = 0; i < n; ++i) {
1509 register mad_fixed_t m, s; 1522 register mad_fixed_t m, s;
1510 1523
1511 m = xr[0][l + i]; 1524 m = xr[0][l + i];
1512 s = xr[1][l + i]; 1525 s = xr[1][l + i];
1513 1526
1514 xr[0][l + i] = mad_f_mul(m + s, invsqrt2); /* l = (m + s) / sqrt(2) */ 1527 xr[0][l + i] = mad_f_mul(m + s, invsqrt2); /* l = (m + s) / sqrt(2) */
1515 xr[1][l + i] = mad_f_mul(m - s, invsqrt2); /* r = (m - s) / sqrt(2) */ 1528 xr[1][l + i] = mad_f_mul(m - s, invsqrt2); /* r = (m - s) / sqrt(2) */
1516 } 1529 }
1517 } 1530 }
1518 } 1531 }
1519 1532
1520 return 0; 1533 return MAD_ERROR_NONE;
1521} 1534}
1522 1535
1523/* 1536/*
1524 * NAME:III_aliasreduce() 1537 * NAME:III_aliasreduce()
1525 * DESCRIPTION:perform frequency line alias reduction 1538 * DESCRIPTION:perform frequency line alias reduction
1526 */ 1539 */
1527static 1540static
1528void III_aliasreduce(mad_fixed_t xr[576], int lines) 1541void III_aliasreduce(mad_fixed_t xr[576], int lines)
1529{ 1542{
1530 mad_fixed_t const *bound; 1543 mad_fixed_t const *bound;
1531 int i; 1544 int i;
1532 1545
1533 bound = &xr[lines]; 1546 bound = &xr[lines];
1534 for (xr += 18; xr < bound; xr += 18) { 1547 for (xr += 18; xr < bound; xr += 18) {
1535 for (i = 0; i < 8; ++i) { 1548 for (i = 0; i < 8; ++i) {
1536 register mad_fixed_t *aptr, *bptr, a, b; 1549 register mad_fixed_t a, b;
1537 register mad_fixed64hi_t hi; 1550 register mad_fixed64hi_t hi;
1538 register mad_fixed64lo_t lo; 1551 register mad_fixed64lo_t lo;
1539 1552
1540 aptr = &xr[-1 - i]; 1553 a = xr[-1 - i];
1541 bptr = &xr[ i]; 1554 b = xr[ i];
1542
1543 a = *aptr;
1544 b = *bptr;
1545 1555
1546# if defined(ASO_ZEROCHECK) 1556# if defined(ASO_ZEROCHECK)
1547 if (a | b) { 1557 if (a | b) {
1548# endif 1558# endif
1549 MAD_F_ML0(hi, lo, a, cs[i]); 1559 MAD_F_ML0(hi, lo, a, cs[i]);
1550 MAD_F_MLA(hi, lo, -b, ca[i]); 1560 MAD_F_MLA(hi, lo, -b, ca[i]);
1551 1561
1552 *aptr = MAD_F_MLZ(hi, lo); 1562 xr[-1 - i] = MAD_F_MLZ(hi, lo);
1553 1563
1554 MAD_F_ML0(hi, lo, b, cs[i]); 1564 MAD_F_ML0(hi, lo, b, cs[i]);
1555 MAD_F_MLA(hi, lo, a, ca[i]); 1565 MAD_F_MLA(hi, lo, a, ca[i]);
1556 1566
1557 *bptr = MAD_F_MLZ(hi, lo); 1567 xr[ i] = MAD_F_MLZ(hi, lo);
1558# if defined(ASO_ZEROCHECK) 1568# if defined(ASO_ZEROCHECK)
1559 } 1569 }
1560# endif 1570# endif
1561 } 1571 }
1562 } 1572 }
1563} 1573}
1564 1574
1565# if defined(ASO_IMDCT) 1575# if defined(ASO_IMDCT)
1566void 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);
1567# else 1577# else
1568/* 1578/*
1569 * NAME:imdct36 1579 * NAME:imdct36
1570 * DESCRIPTION:perform X[18]->x[36] IMDCT 1580 * DESCRIPTION:perform X[18]->x[36] IMDCT
1571 */ 1581 */
1572static inline 1582static inline
1573void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36]) 1583void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36])
1574{ 1584{
1575 mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7; 1585 mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7;
1576 mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15; 1586 mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15;
1577 register mad_fixed64hi_t hi; 1587 register mad_fixed64hi_t hi;
1578 register mad_fixed64lo_t lo; 1588 register mad_fixed64lo_t lo;
1579 1589
1580 MAD_F_ML0(hi, lo, X[4], MAD_F(0x0ec835e8)); 1590 MAD_F_ML0(hi, lo, X[4], MAD_F(0x0ec835e8));
1581 MAD_F_MLA(hi, lo, X[13], MAD_F(0x061f78aa)); 1591 MAD_F_MLA(hi, lo, X[13], MAD_F(0x061f78aa));
1582 1592
1583 t6 = MAD_F_MLZ(hi, lo); 1593 t6 = MAD_F_MLZ(hi, lo);
1584 1594
1585 MAD_F_MLA(hi, lo, (t14 = X[1] - X[10]), -MAD_F(0x061f78aa)); 1595 MAD_F_MLA(hi, lo, (t14 = X[1] - X[10]), -MAD_F(0x061f78aa));
1586 MAD_F_MLA(hi, lo, (t15 = X[7] + X[16]), -MAD_F(0x0ec835e8)); 1596 MAD_F_MLA(hi, lo, (t15 = X[7] + X[16]), -MAD_F(0x0ec835e8));
1587 1597
1588 t0 = MAD_F_MLZ(hi, lo); 1598 t0 = MAD_F_MLZ(hi, lo);
1589 1599
1590 MAD_F_MLA(hi, lo, (t8 = X[0] - X[11] - X[12]), MAD_F(0x0216a2a2)); 1600 MAD_F_MLA(hi, lo, (t8 = X[0] - X[11] - X[12]), MAD_F(0x0216a2a2));
1591 MAD_F_MLA(hi, lo, (t9 = X[2] - X[9] - X[14]), MAD_F(0x09bd7ca0)); 1601 MAD_F_MLA(hi, lo, (t9 = X[2] - X[9] - X[14]), MAD_F(0x09bd7ca0));
1592 MAD_F_MLA(hi, lo, (t10 = X[3] - X[8] - X[15]), -MAD_F(0x0cb19346)); 1602 MAD_F_MLA(hi, lo, (t10 = X[3] - X[8] - X[15]), -MAD_F(0x0cb19346));
1593 MAD_F_MLA(hi, lo, (t11 = X[5] - X[6] - X[17]), -MAD_F(0x0fdcf549)); 1603 MAD_F_MLA(hi, lo, (t11 = X[5] - X[6] - X[17]), -MAD_F(0x0fdcf549));
1594 1604
1595 x[7] = MAD_F_MLZ(hi, lo); 1605 x[7] = MAD_F_MLZ(hi, lo);
1596 x[10] = -x[7]; 1606 x[10] = -x[7];
1597 1607
1598 MAD_F_ML0(hi, lo, t8, -MAD_F(0x0cb19346)); 1608 MAD_F_ML0(hi, lo, t8, -MAD_F(0x0cb19346));
1599 MAD_F_MLA(hi, lo, t9, MAD_F(0x0fdcf549)); 1609 MAD_F_MLA(hi, lo, t9, MAD_F(0x0fdcf549));
1600 MAD_F_MLA(hi, lo, t10, MAD_F(0x0216a2a2)); 1610 MAD_F_MLA(hi, lo, t10, MAD_F(0x0216a2a2));
1601 MAD_F_MLA(hi, lo, t11, -MAD_F(0x09bd7ca0)); 1611 MAD_F_MLA(hi, lo, t11, -MAD_F(0x09bd7ca0));
1602 1612
1603 x[19] = x[34] = MAD_F_MLZ(hi, lo) - t0; 1613 x[19] = x[34] = MAD_F_MLZ(hi, lo) - t0;
1604 1614
1605 t12 = X[0] - X[3] + X[8] - X[11] - X[12] + X[15]; 1615 t12 = X[0] - X[3] + X[8] - X[11] - X[12] + X[15];
1606 t13 = X[2] + X[5] - X[6] - X[9] - X[14] - X[17]; 1616 t13 = X[2] + X[5] - X[6] - X[9] - X[14] - X[17];
1607 1617
1608 MAD_F_ML0(hi, lo, t12, -MAD_F(0x0ec835e8)); 1618 MAD_F_ML0(hi, lo, t12, -MAD_F(0x0ec835e8));
1609 MAD_F_MLA(hi, lo, t13, MAD_F(0x061f78aa)); 1619 MAD_F_MLA(hi, lo, t13, MAD_F(0x061f78aa));
1610 1620
1611 x[22] = x[31] = MAD_F_MLZ(hi, lo) + t0; 1621 x[22] = x[31] = MAD_F_MLZ(hi, lo) + t0;
1612 1622
1613 MAD_F_ML0(hi, lo, X[1], -MAD_F(0x09bd7ca0)); 1623 MAD_F_ML0(hi, lo, X[1], -MAD_F(0x09bd7ca0));
1614 MAD_F_MLA(hi, lo, X[7], MAD_F(0x0216a2a2)); 1624 MAD_F_MLA(hi, lo, X[7], MAD_F(0x0216a2a2));
1615 MAD_F_MLA(hi, lo, X[10], -MAD_F(0x0fdcf549)); 1625 MAD_F_MLA(hi, lo, X[10], -MAD_F(0x0fdcf549));
1616 MAD_F_MLA(hi, lo, X[16], MAD_F(0x0cb19346)); 1626 MAD_F_MLA(hi, lo, X[16], MAD_F(0x0cb19346));
1617 1627
1618 t1 = MAD_F_MLZ(hi, lo) + t6; 1628 t1 = MAD_F_MLZ(hi, lo) + t6;
1619 1629
1620 MAD_F_ML0(hi, lo, X[0], MAD_F(0x03768962)); 1630 MAD_F_ML0(hi, lo, X[0], MAD_F(0x03768962));
1621 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0e313245)); 1631 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0e313245));
1622 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0ffc19fd)); 1632 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0ffc19fd));
1623 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0acf37ad)); 1633 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0acf37ad));
1624 MAD_F_MLA(hi, lo, X[6], MAD_F(0x04cfb0e2)); 1634 MAD_F_MLA(hi, lo, X[6], MAD_F(0x04cfb0e2));
1625 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0898c779)); 1635 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0898c779));
1626 MAD_F_MLA(hi, lo, X[9], MAD_F(0x0d7e8807)); 1636 MAD_F_MLA(hi, lo, X[9], MAD_F(0x0d7e8807));
1627 MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f426cb5)); 1637 MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f426cb5));
1628 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0bcbe352)); 1638 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0bcbe352));
1629 MAD_F_MLA(hi, lo, X[14], MAD_F(0x00b2aa3e)); 1639 MAD_F_MLA(hi, lo, X[14], MAD_F(0x00b2aa3e));
1630 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x07635284)); 1640 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x07635284));
1631 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0f9ee890)); 1641 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0f9ee890));
1632 1642
1633 x[6] = MAD_F_MLZ(hi, lo) + t1; 1643 x[6] = MAD_F_MLZ(hi, lo) + t1;
1634 x[11] = -x[6]; 1644 x[11] = -x[6];
1635 1645
1636 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f426cb5)); 1646 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f426cb5));
1637 MAD_F_MLA(hi, lo, X[2], -MAD_F(0x00b2aa3e)); 1647 MAD_F_MLA(hi, lo, X[2], -MAD_F(0x00b2aa3e));
1638 MAD_F_MLA(hi, lo, X[3], MAD_F(0x0898c779)); 1648 MAD_F_MLA(hi, lo, X[3], MAD_F(0x0898c779));
1639 MAD_F_MLA(hi, lo, X[5], MAD_F(0x0f9ee890)); 1649 MAD_F_MLA(hi, lo, X[5], MAD_F(0x0f9ee890));
1640 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0acf37ad)); 1650 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0acf37ad));
1641 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x07635284)); 1651 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x07635284));
1642 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0e313245)); 1652 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0e313245));
1643 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0bcbe352)); 1653 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0bcbe352));
1644 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x03768962)); 1654 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x03768962));
1645 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0d7e8807)); 1655 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0d7e8807));
1646 MAD_F_MLA(hi, lo, X[15], MAD_F(0x0ffc19fd)); 1656 MAD_F_MLA(hi, lo, X[15], MAD_F(0x0ffc19fd));
1647 MAD_F_MLA(hi, lo, X[17], MAD_F(0x04cfb0e2)); 1657 MAD_F_MLA(hi, lo, X[17], MAD_F(0x04cfb0e2));
1648 1658
1649 x[23] = x[30] = MAD_F_MLZ(hi, lo) + t1; 1659 x[23] = x[30] = MAD_F_MLZ(hi, lo) + t1;
1650 1660
1651 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0bcbe352)); 1661 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0bcbe352));
1652 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0d7e8807)); 1662 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0d7e8807));
1653 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x07635284)); 1663 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x07635284));
1654 MAD_F_MLA(hi, lo, X[5], MAD_F(0x04cfb0e2)); 1664 MAD_F_MLA(hi, lo, X[5], MAD_F(0x04cfb0e2));
1655 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f9ee890)); 1665 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f9ee890));
1656 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0ffc19fd)); 1666 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0ffc19fd));
1657 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x00b2aa3e)); 1667 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x00b2aa3e));
1658 MAD_F_MLA(hi, lo, X[11], MAD_F(0x03768962)); 1668 MAD_F_MLA(hi, lo, X[11], MAD_F(0x03768962));
1659 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0f426cb5)); 1669 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0f426cb5));
1660 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0e313245)); 1670 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0e313245));
1661 MAD_F_MLA(hi, lo, X[15], MAD_F(0x0898c779)); 1671 MAD_F_MLA(hi, lo, X[15], MAD_F(0x0898c779));
1662 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0acf37ad)); 1672 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0acf37ad));
1663 1673
1664 x[18] = x[35] = MAD_F_MLZ(hi, lo) - t1; 1674 x[18] = x[35] = MAD_F_MLZ(hi, lo) - t1;
1665 1675
1666 MAD_F_ML0(hi, lo, X[4], MAD_F(0x061f78aa)); 1676 MAD_F_ML0(hi, lo, X[4], MAD_F(0x061f78aa));
1667 MAD_F_MLA(hi, lo, X[13], -MAD_F(0x0ec835e8)); 1677 MAD_F_MLA(hi, lo, X[13], -MAD_F(0x0ec835e8));
1668 1678
1669 t7 = MAD_F_MLZ(hi, lo); 1679 t7 = MAD_F_MLZ(hi, lo);
1670 1680
1671 MAD_F_MLA(hi, lo, X[1], -MAD_F(0x0cb19346)); 1681 MAD_F_MLA(hi, lo, X[1], -MAD_F(0x0cb19346));
1672 MAD_F_MLA(hi, lo, X[7], MAD_F(0x0fdcf549)); 1682 MAD_F_MLA(hi, lo, X[7], MAD_F(0x0fdcf549));
1673 MAD_F_MLA(hi, lo, X[10], MAD_F(0x0216a2a2)); 1683 MAD_F_MLA(hi, lo, X[10], MAD_F(0x0216a2a2));
1674 MAD_F_MLA(hi, lo, X[16], -MAD_F(0x09bd7ca0)); 1684 MAD_F_MLA(hi, lo, X[16], -MAD_F(0x09bd7ca0));
1675 1685
1676 t2 = MAD_F_MLZ(hi, lo); 1686 t2 = MAD_F_MLZ(hi, lo);
1677 1687
1678 MAD_F_MLA(hi, lo, X[0], MAD_F(0x04cfb0e2)); 1688 MAD_F_MLA(hi, lo, X[0], MAD_F(0x04cfb0e2));
1679 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0ffc19fd)); 1689 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0ffc19fd));
1680 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0d7e8807)); 1690 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0d7e8807));
1681 MAD_F_MLA(hi, lo, X[5], MAD_F(0x03768962)); 1691 MAD_F_MLA(hi, lo, X[5], MAD_F(0x03768962));
1682 MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0bcbe352)); 1692 MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0bcbe352));
1683 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0e313245)); 1693 MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0e313245));
1684 MAD_F_MLA(hi, lo, X[9], MAD_F(0x07635284)); 1694 MAD_F_MLA(hi, lo, X[9], MAD_F(0x07635284));
1685 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0acf37ad)); 1695 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0acf37ad));
1686 MAD_F_MLA(hi, lo, X[12], MAD_F(0x0f9ee890)); 1696 MAD_F_MLA(hi, lo, X[12], MAD_F(0x0f9ee890));
1687 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0898c779)); 1697 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0898c779));
1688 MAD_F_MLA(hi, lo, X[15], MAD_F(0x00b2aa3e)); 1698 MAD_F_MLA(hi, lo, X[15], MAD_F(0x00b2aa3e));
1689 MAD_F_MLA(hi, lo, X[17], MAD_F(0x0f426cb5)); 1699 MAD_F_MLA(hi, lo, X[17], MAD_F(0x0f426cb5));
1690 1700
1691 x[5] = MAD_F_MLZ(hi, lo); 1701 x[5] = MAD_F_MLZ(hi, lo);
1692 x[12] = -x[5]; 1702 x[12] = -x[5];
1693 1703
1694 MAD_F_ML0(hi, lo, X[0], MAD_F(0x0acf37ad)); 1704 MAD_F_ML0(hi, lo, X[0], MAD_F(0x0acf37ad));
1695 MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0898c779)); 1705 MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0898c779));
1696 MAD_F_MLA(hi, lo, X[3], MAD_F(0x0e313245)); 1706 MAD_F_MLA(hi, lo, X[3], MAD_F(0x0e313245));
1697 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0f426cb5)); 1707 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0f426cb5));
1698 MAD_F_MLA(hi, lo, X[6], -MAD_F(0x03768962)); 1708 MAD_F_MLA(hi, lo, X[6], -MAD_F(0x03768962));
1699 MAD_F_MLA(hi, lo, X[8], MAD_F(0x00b2aa3e)); 1709 MAD_F_MLA(hi, lo, X[8], MAD_F(0x00b2aa3e));
1700 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0ffc19fd)); 1710 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0ffc19fd));
1701 MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f9ee890)); 1711 MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f9ee890));
1702 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x04cfb0e2)); 1712 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x04cfb0e2));
1703 MAD_F_MLA(hi, lo, X[14], MAD_F(0x07635284)); 1713 MAD_F_MLA(hi, lo, X[14], MAD_F(0x07635284));
1704 MAD_F_MLA(hi, lo, X[15], MAD_F(0x0d7e8807)); 1714 MAD_F_MLA(hi, lo, X[15], MAD_F(0x0d7e8807));
1705 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0bcbe352)); 1715 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0bcbe352));
1706 1716
1707 x[0] = MAD_F_MLZ(hi, lo) + t2; 1717 x[0] = MAD_F_MLZ(hi, lo) + t2;
1708 x[17] = -x[0]; 1718 x[17] = -x[0];
1709 1719
1710 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f9ee890)); 1720 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f9ee890));
1711 MAD_F_MLA(hi, lo, X[2], -MAD_F(0x07635284)); 1721 MAD_F_MLA(hi, lo, X[2], -MAD_F(0x07635284));
1712 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x00b2aa3e)); 1722 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x00b2aa3e));
1713 MAD_F_MLA(hi, lo, X[5], MAD_F(0x0bcbe352)); 1723 MAD_F_MLA(hi, lo, X[5], MAD_F(0x0bcbe352));
1714 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f426cb5)); 1724 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f426cb5));
1715 MAD_F_MLA(hi, lo, X[8], MAD_F(0x0d7e8807)); 1725 MAD_F_MLA(hi, lo, X[8], MAD_F(0x0d7e8807));
1716 MAD_F_MLA(hi, lo, X[9], MAD_F(0x0898c779)); 1726 MAD_F_MLA(hi, lo, X[9], MAD_F(0x0898c779));
1717 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x04cfb0e2)); 1727 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x04cfb0e2));
1718 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0acf37ad)); 1728 MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0acf37ad));
1719 MAD_F_MLA(hi, lo, X[14], -MAD_F(0x0ffc19fd)); 1729 MAD_F_MLA(hi, lo, X[14], -MAD_F(0x0ffc19fd));
1720 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0e313245)); 1730 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0e313245));
1721 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x03768962)); 1731 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x03768962));
1722 1732
1723 x[24] = x[29] = MAD_F_MLZ(hi, lo) + t2; 1733 x[24] = x[29] = MAD_F_MLZ(hi, lo) + t2;
1724 1734
1725 MAD_F_ML0(hi, lo, X[1], -MAD_F(0x0216a2a2)); 1735 MAD_F_ML0(hi, lo, X[1], -MAD_F(0x0216a2a2));
1726 MAD_F_MLA(hi, lo, X[7], -MAD_F(0x09bd7ca0)); 1736 MAD_F_MLA(hi, lo, X[7], -MAD_F(0x09bd7ca0));
1727 MAD_F_MLA(hi, lo, X[10], MAD_F(0x0cb19346)); 1737 MAD_F_MLA(hi, lo, X[10], MAD_F(0x0cb19346));
1728 MAD_F_MLA(hi, lo, X[16], MAD_F(0x0fdcf549)); 1738 MAD_F_MLA(hi, lo, X[16], MAD_F(0x0fdcf549));
1729 1739
1730 t3 = MAD_F_MLZ(hi, lo) + t7; 1740 t3 = MAD_F_MLZ(hi, lo) + t7;
1731 1741
1732 MAD_F_ML0(hi, lo, X[0], MAD_F(0x00b2aa3e)); 1742 MAD_F_ML0(hi, lo, X[0], MAD_F(0x00b2aa3e));
1733 MAD_F_MLA(hi, lo, X[2], MAD_F(0x03768962)); 1743 MAD_F_MLA(hi, lo, X[2], MAD_F(0x03768962));
1734 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x04cfb0e2)); 1744 MAD_F_MLA(hi, lo, X[3], -MAD_F(0x04cfb0e2));
1735 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x07635284)); 1745 MAD_F_MLA(hi, lo, X[5], -MAD_F(0x07635284));
1736 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0898c779)); 1746 MAD_F_MLA(hi, lo, X[6], MAD_F(0x0898c779));
1737 MAD_F_MLA(hi, lo, X[8], MAD_F(0x0acf37ad)); 1747 MAD_F_MLA(hi, lo, X[8], MAD_F(0x0acf37ad));
1738 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0bcbe352)); 1748 MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0bcbe352));
1739 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0d7e8807)); 1749 MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0d7e8807));
1740 MAD_F_MLA(hi, lo, X[12], MAD_F(0x0e313245)); 1750 MAD_F_MLA(hi, lo, X[12], MAD_F(0x0e313245));
1741 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f426cb5)); 1751 MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f426cb5));
1742 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0f9ee890)); 1752 MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0f9ee890));
1743 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0ffc19fd)); 1753 MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0ffc19fd));
1744 1754
1745 x[8] = MAD_F_MLZ(hi, lo) + t3; 1755 x[8] = MAD_F_MLZ(hi, lo) + t3;
1746 x[9] = -x[8]; 1756 x[9] = -x[8];
1747 1757
1748 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0e313245)); 1758 MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0e313245));
1749 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0bcbe352)); 1759 MAD_F_MLA(hi, lo, X[2], MAD_F(0x0bcbe352));
@@ -1952,541 +1962,541 @@ void III_imdct_s(mad_fixed_t const X[18], mad_fixed_t z[36])
1952 1962
1953 yptr = &y[0]; 1963 yptr = &y[0];
1954 1964
1955 for (w = 0; w < 3; ++w) { 1965 for (w = 0; w < 3; ++w) {
1956 register mad_fixed_t const (*s)[6]; 1966 register mad_fixed_t const (*s)[6];
1957 1967
1958 s = imdct_s; 1968 s = imdct_s;
1959 1969
1960 for (i = 0; i < 3; ++i) { 1970 for (i = 0; i < 3; ++i) {
1961 MAD_F_ML0(hi, lo, X[0], (*s)[0]); 1971 MAD_F_ML0(hi, lo, X[0], (*s)[0]);
1962 MAD_F_MLA(hi, lo, X[1], (*s)[1]); 1972 MAD_F_MLA(hi, lo, X[1], (*s)[1]);
1963 MAD_F_MLA(hi, lo, X[2], (*s)[2]); 1973 MAD_F_MLA(hi, lo, X[2], (*s)[2]);
1964 MAD_F_MLA(hi, lo, X[3], (*s)[3]); 1974 MAD_F_MLA(hi, lo, X[3], (*s)[3]);
1965 MAD_F_MLA(hi, lo, X[4], (*s)[4]); 1975 MAD_F_MLA(hi, lo, X[4], (*s)[4]);
1966 MAD_F_MLA(hi, lo, X[5], (*s)[5]); 1976 MAD_F_MLA(hi, lo, X[5], (*s)[5]);
1967 1977
1968 yptr[i + 0] = MAD_F_MLZ(hi, lo); 1978 yptr[i + 0] = MAD_F_MLZ(hi, lo);
1969 yptr[5 - i] = -yptr[i + 0]; 1979 yptr[5 - i] = -yptr[i + 0];
1970 1980
1971 ++s; 1981 ++s;
1972 1982
1973 MAD_F_ML0(hi, lo, X[0], (*s)[0]); 1983 MAD_F_ML0(hi, lo, X[0], (*s)[0]);
1974 MAD_F_MLA(hi, lo, X[1], (*s)[1]); 1984 MAD_F_MLA(hi, lo, X[1], (*s)[1]);
1975 MAD_F_MLA(hi, lo, X[2], (*s)[2]); 1985 MAD_F_MLA(hi, lo, X[2], (*s)[2]);
1976 MAD_F_MLA(hi, lo, X[3], (*s)[3]); 1986 MAD_F_MLA(hi, lo, X[3], (*s)[3]);
1977 MAD_F_MLA(hi, lo, X[4], (*s)[4]); 1987 MAD_F_MLA(hi, lo, X[4], (*s)[4]);
1978 MAD_F_MLA(hi, lo, X[5], (*s)[5]); 1988 MAD_F_MLA(hi, lo, X[5], (*s)[5]);
1979 1989
1980 yptr[ i + 6] = MAD_F_MLZ(hi, lo); 1990 yptr[ i + 6] = MAD_F_MLZ(hi, lo);
1981 yptr[11 - i] = yptr[i + 6]; 1991 yptr[11 - i] = yptr[i + 6];
1982 1992
1983 ++s; 1993 ++s;
1984 } 1994 }
1985 1995
1986 yptr += 12; 1996 yptr += 12;
1987 X += 6; 1997 X += 6;
1988 } 1998 }
1989 1999
1990 /* windowing, overlapping and concatenation */ 2000 /* windowing, overlapping and concatenation */
1991 2001
1992 yptr = &y[0]; 2002 yptr = &y[0];
1993 wptr = &window_s[0]; 2003 wptr = &window_s[0];
1994 2004
1995 for (i = 0; i < 6; ++i) { 2005 for (i = 0; i < 6; ++i) {
1996 z[i + 0] = 0; 2006 z[i + 0] = 0;
1997 z[i + 6] = mad_f_mul(yptr[ 0 + 0], wptr[0]); 2007 z[i + 6] = mad_f_mul(yptr[ 0 + 0], wptr[0]);
1998 2008
1999 MAD_F_ML0(hi, lo, yptr[ 0 + 6], wptr[6]); 2009 MAD_F_ML0(hi, lo, yptr[ 0 + 6], wptr[6]);
2000 MAD_F_MLA(hi, lo, yptr[12 + 0], wptr[0]); 2010 MAD_F_MLA(hi, lo, yptr[12 + 0], wptr[0]);
2001 2011
2002 z[i + 12] = MAD_F_MLZ(hi, lo); 2012 z[i + 12] = MAD_F_MLZ(hi, lo);
2003 2013
2004 MAD_F_ML0(hi, lo, yptr[12 + 6], wptr[6]); 2014 MAD_F_ML0(hi, lo, yptr[12 + 6], wptr[6]);
2005 MAD_F_MLA(hi, lo, yptr[24 + 0], wptr[0]); 2015 MAD_F_MLA(hi, lo, yptr[24 + 0], wptr[0]);
2006 2016
2007 z[i + 18] = MAD_F_MLZ(hi, lo); 2017 z[i + 18] = MAD_F_MLZ(hi, lo);
2008 2018
2009 z[i + 24] = mad_f_mul(yptr[24 + 6], wptr[6]); 2019 z[i + 24] = mad_f_mul(yptr[24 + 6], wptr[6]);
2010 z[i + 30] = 0; 2020 z[i + 30] = 0;
2011 2021
2012 ++yptr; 2022 ++yptr;
2013 ++wptr; 2023 ++wptr;
2014 } 2024 }
2015} 2025}
2016 2026
2017/* 2027/*
2018 * NAME:III_overlap() 2028 * NAME:III_overlap()
2019 * DESCRIPTION:perform overlap-add of windowed IMDCT outputs 2029 * DESCRIPTION:perform overlap-add of windowed IMDCT outputs
2020 */ 2030 */
2021static 2031static
2022void III_overlap(mad_fixed_t const output[36], mad_fixed_t overlap[18], 2032void III_overlap(mad_fixed_t const output[36], mad_fixed_t overlap[18],
2023 mad_fixed_t sample[18][32], unsigned int sb) 2033 mad_fixed_t sample[18][32], unsigned int sb)
2024{ 2034{
2025 unsigned int i; 2035 unsigned int i;
2026 2036
2027# if defined(ASO_INTERLEAVE2) 2037# if defined(ASO_INTERLEAVE2)
2028 { 2038 {
2029 register mad_fixed_t tmp1, tmp2; 2039 register mad_fixed_t tmp1, tmp2;
2030 2040
2031 tmp1 = overlap[0]; 2041 tmp1 = overlap[0];
2032 tmp2 = overlap[1]; 2042 tmp2 = overlap[1];
2033 2043
2034 for (i = 0; i < 16; i += 2) { 2044 for (i = 0; i < 16; i += 2) {
2035 sample[i + 0][sb] = output[i + 0] + tmp1; 2045 sample[i + 0][sb] = output[i + 0] + tmp1;
2036 overlap[i + 0] = output[i + 0 + 18]; 2046 overlap[i + 0] = output[i + 0 + 18];
2037 tmp1 = overlap[i + 2]; 2047 tmp1 = overlap[i + 2];
2038 2048
2039 sample[i + 1][sb] = output[i + 1] + tmp2; 2049 sample[i + 1][sb] = output[i + 1] + tmp2;
2040 overlap[i + 1] = output[i + 1 + 18]; 2050 overlap[i + 1] = output[i + 1 + 18];
2041 tmp2 = overlap[i + 3]; 2051 tmp2 = overlap[i + 3];
2042 } 2052 }
2043 2053
2044 sample[16][sb] = output[16] + tmp1; 2054 sample[16][sb] = output[16] + tmp1;
2045 overlap[16] = output[16 + 18]; 2055 overlap[16] = output[16 + 18];
2046 sample[17][sb] = output[17] + tmp2; 2056 sample[17][sb] = output[17] + tmp2;
2047 overlap[17] = output[17 + 18]; 2057 overlap[17] = output[17 + 18];
2048 } 2058 }
2049# elif 0 2059# elif 0
2050 for (i = 0; i < 18; i += 2) { 2060 for (i = 0; i < 18; i += 2) {
2051 sample[i + 0][sb] = output[i + 0] + overlap[i + 0]; 2061 sample[i + 0][sb] = output[i + 0] + overlap[i + 0];
2052 overlap[i + 0] = output[i + 0 + 18]; 2062 overlap[i + 0] = output[i + 0 + 18];
2053 2063
2054 sample[i + 1][sb] = output[i + 1] + overlap[i + 1]; 2064 sample[i + 1][sb] = output[i + 1] + overlap[i + 1];
2055 overlap[i + 1] = output[i + 1 + 18]; 2065 overlap[i + 1] = output[i + 1 + 18];
2056 } 2066 }
2057# else 2067# else
2058 for (i = 0; i < 18; ++i) { 2068 for (i = 0; i < 18; ++i) {
2059 sample[i][sb] = output[i] + overlap[i]; 2069 sample[i][sb] = output[i] + overlap[i];
2060 overlap[i] = output[i + 18]; 2070 overlap[i] = output[i + 18];
2061 } 2071 }
2062# endif 2072# endif
2063} 2073}
2064 2074
2065/* 2075/*
2066 * NAME:III_overlap_z() 2076 * NAME:III_overlap_z()
2067 * DESCRIPTION:perform "overlap-add" of zero IMDCT outputs 2077 * DESCRIPTION:perform "overlap-add" of zero IMDCT outputs
2068 */ 2078 */
2069static inline 2079static inline
2070void III_overlap_z(mad_fixed_t overlap[18], 2080void III_overlap_z(mad_fixed_t overlap[18],
2071 mad_fixed_t sample[18][32], unsigned int sb) 2081 mad_fixed_t sample[18][32], unsigned int sb)
2072{ 2082{
2073 unsigned int i; 2083 unsigned int i;
2074 2084
2075# if defined(ASO_INTERLEAVE2) 2085# if defined(ASO_INTERLEAVE2)
2076 { 2086 {
2077 register mad_fixed_t tmp1, tmp2; 2087 register mad_fixed_t tmp1, tmp2;
2078 2088
2079 tmp1 = overlap[0]; 2089 tmp1 = overlap[0];
2080 tmp2 = overlap[1]; 2090 tmp2 = overlap[1];
2081 2091
2082 for (i = 0; i < 16; i += 2) { 2092 for (i = 0; i < 16; i += 2) {
2083 sample[i + 0][sb] = tmp1; 2093 sample[i + 0][sb] = tmp1;
2084 overlap[i + 0] = 0; 2094 overlap[i + 0] = 0;
2085 tmp1 = overlap[i + 2]; 2095 tmp1 = overlap[i + 2];
2086 2096
2087 sample[i + 1][sb] = tmp2; 2097 sample[i + 1][sb] = tmp2;
2088 overlap[i + 1] = 0; 2098 overlap[i + 1] = 0;
2089 tmp2 = overlap[i + 3]; 2099 tmp2 = overlap[i + 3];
2090 } 2100 }
2091 2101
2092 sample[16][sb] = tmp1; 2102 sample[16][sb] = tmp1;
2093 overlap[16] = 0; 2103 overlap[16] = 0;
2094 sample[17][sb] = tmp2; 2104 sample[17][sb] = tmp2;
2095 overlap[17] = 0; 2105 overlap[17] = 0;
2096 } 2106 }
2097# else 2107# else
2098 for (i = 0; i < 18; ++i) { 2108 for (i = 0; i < 18; ++i) {
2099 sample[i][sb] = overlap[i]; 2109 sample[i][sb] = overlap[i];
2100 overlap[i] = 0; 2110 overlap[i] = 0;
2101 } 2111 }
2102# endif 2112# endif
2103} 2113}
2104 2114
2105/* 2115/*
2106 * NAME:III_freqinver() 2116 * NAME:III_freqinver()
2107 * DESCRIPTION:perform subband frequency inversion for odd sample lines 2117 * DESCRIPTION:perform subband frequency inversion for odd sample lines
2108 */ 2118 */
2109static 2119static
2110void III_freqinver(mad_fixed_t sample[18][32], unsigned int sb) 2120void III_freqinver(mad_fixed_t sample[18][32], unsigned int sb)
2111{ 2121{
2112 unsigned int i; 2122 unsigned int i;
2113 2123
2114# if 1 || defined(ASO_INTERLEAVE1) || defined(ASO_INTERLEAVE2) 2124# if 1 || defined(ASO_INTERLEAVE1) || defined(ASO_INTERLEAVE2)
2115 { 2125 {
2116 register mad_fixed_t tmp1, tmp2; 2126 register mad_fixed_t tmp1, tmp2;
2117 2127
2118 tmp1 = sample[1][sb]; 2128 tmp1 = sample[1][sb];
2119 tmp2 = sample[3][sb]; 2129 tmp2 = sample[3][sb];
2120 2130
2121 for (i = 1; i < 13; i += 4) { 2131 for (i = 1; i < 13; i += 4) {
2122 sample[i + 0][sb] = -tmp1; 2132 sample[i + 0][sb] = -tmp1;
2123 tmp1 = sample[i + 4][sb]; 2133 tmp1 = sample[i + 4][sb];
2124 sample[i + 2][sb] = -tmp2; 2134 sample[i + 2][sb] = -tmp2;
2125 tmp2 = sample[i + 6][sb]; 2135 tmp2 = sample[i + 6][sb];
2126 } 2136 }
2127 2137
2128 sample[13][sb] = -tmp1; 2138 sample[13][sb] = -tmp1;
2129 tmp1 = sample[17][sb]; 2139 tmp1 = sample[17][sb];
2130 sample[15][sb] = -tmp2; 2140 sample[15][sb] = -tmp2;
2131 sample[17][sb] = -tmp1; 2141 sample[17][sb] = -tmp1;
2132 } 2142 }
2133# else 2143# else
2134 for (i = 1; i < 18; i += 2) 2144 for (i = 1; i < 18; i += 2)
2135 sample[i][sb] = -sample[i][sb]; 2145 sample[i][sb] = -sample[i][sb];
2136# endif 2146# endif
2137} 2147}
2138 2148
2139/* 2149/*
2140 * NAME:III_decode() 2150 * NAME:III_decode()
2141 * DESCRIPTION:decode frame main_data 2151 * DESCRIPTION:decode frame main_data
2142 */ 2152 */
2143static 2153static
2144int III_decode(struct mad_bitptr *ptr, struct mad_frame *frame, 2154enum mad_error III_decode(struct mad_bitptr *ptr, struct mad_frame *frame,
2145 struct sideinfo *si, unsigned int nch) 2155 struct sideinfo *si, unsigned int nch)
2146{ 2156{
2147 struct mad_header *header = &frame->header; 2157 struct mad_header *header = &frame->header;
2148 unsigned int sfreqi, ngr, gr; 2158 unsigned int sfreqi, ngr, gr;
2149 2159
2150 { 2160 {
2151 unsigned int sfreq; 2161 unsigned int sfreq;
2152 2162
2153 sfreq = header->samplerate; 2163 sfreq = header->samplerate;
2154 if (header->flags & MAD_FLAG_MPEG_2_5_EXT) 2164 if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
2155 sfreq *= 2; 2165 sfreq *= 2;
2156 2166
2157 /* 48000 => 0, 44100 => 1, 32000 => 2, 2167 /* 48000 => 0, 44100 => 1, 32000 => 2,
2158 24000 => 3, 22050 => 4, 16000 => 5 */ 2168 24000 => 3, 22050 => 4, 16000 => 5 */
2159 sfreqi = ((sfreq >> 7) & 0x000f) + 2169 sfreqi = ((sfreq >> 7) & 0x000f) +
2160 ((sfreq >> 15) & 0x0001) - 8; 2170 ((sfreq >> 15) & 0x0001) - 8;
2161 2171
2162 if (header->flags & MAD_FLAG_MPEG_2_5_EXT) 2172 if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
2163 sfreqi += 3; 2173 sfreqi += 3;
2164 } 2174 }
2165 2175
2166 /* scalefactors, Huffman decoding, requantization */ 2176 /* scalefactors, Huffman decoding, requantization */
2167 2177
2168 ngr = (header->flags & MAD_FLAG_LSF_EXT) ? 1 : 2; 2178 ngr = (header->flags & MAD_FLAG_LSF_EXT) ? 1 : 2;
2169 2179
2170 for (gr = 0; gr < ngr; ++gr) { 2180 for (gr = 0; gr < ngr; ++gr) {
2171 struct granule *granule = &si->gr[gr]; 2181 struct granule *granule = &si->gr[gr];
2172 unsigned char const *sfbwidth = 0; 2182 unsigned char const *sfbwidth[2];
2173 mad_fixed_t xr[2][576]; 2183 mad_fixed_t xr[2][576];
2174 unsigned int ch; 2184 unsigned int ch;
2175 enum mad_error error; 2185 enum mad_error error;
2176 2186
2177 for (ch = 0; ch < nch; ++ch) { 2187 for (ch = 0; ch < nch; ++ch) {
2178 struct channel *channel = &granule->ch[ch]; 2188 struct channel *channel = &granule->ch[ch];
2179 unsigned int part2_length; 2189 unsigned int part2_length;
2180 2190
2181 sfbwidth = sfbwidth_table[sfreqi].l; 2191 sfbwidth[ch] = sfbwidth_table[sfreqi].l;
2182 if (channel->block_type == 2) { 2192 if (channel->block_type == 2) {
2183 sfbwidth = (channel->flags & mixed_block_flag) ? 2193 sfbwidth[ch] = (channel->flags & mixed_block_flag) ?
2184 sfbwidth_table[sfreqi].m : sfbwidth_table[sfreqi].s; 2194 sfbwidth_table[sfreqi].m : sfbwidth_table[sfreqi].s;
2185 } 2195 }
2186 2196
2187 if (header->flags & MAD_FLAG_LSF_EXT) { 2197 if (header->flags & MAD_FLAG_LSF_EXT) {
2188 part2_length = III_scalefactors_lsf(ptr, channel, 2198 part2_length = III_scalefactors_lsf(ptr, channel,
2189 ch == 0 ? 0 : &si->gr[1].ch[1], 2199 ch == 0 ? 0 : &si->gr[1].ch[1],
2190 header->mode_extension); 2200 header->mode_extension);
2191 } 2201 }
2192 else { 2202 else {
2193 part2_length = III_scalefactors(ptr, channel, &si->gr[0].ch[ch], 2203 part2_length = III_scalefactors(ptr, channel, &si->gr[0].ch[ch],
2194 gr == 0 ? 0 : si->scfsi[ch]); 2204 gr == 0 ? 0 : si->scfsi[ch]);
2195 } 2205 }
2196 2206
2197 error = III_huffdecode(ptr, xr[ch], channel, sfbwidth, part2_length); 2207 error = III_huffdecode(ptr, xr[ch], channel, sfbwidth[ch], part2_length);
2198 if (error) 2208 if (error)
2199 return error; 2209 return error;
2200 } 2210 }
2201 2211
2202 /* joint stereo processing */ 2212 /* joint stereo processing */
2203 2213
2204 if (header->mode == MAD_MODE_JOINT_STEREO && header->mode_extension) { 2214 if (header->mode == MAD_MODE_JOINT_STEREO && header->mode_extension) {
2205 error = III_stereo(xr, granule, header, sfbwidth); 2215 error = III_stereo(xr, granule, header, sfbwidth[0]);
2206 if (error) 2216 if (error)
2207 return error; 2217 return error;
2208 } 2218 }
2209 2219
2210 /* reordering, alias reduction, IMDCT, overlap-add, frequency inversion */ 2220 /* reordering, alias reduction, IMDCT, overlap-add, frequency inversion */
2211 2221
2212 for (ch = 0; ch < nch; ++ch) { 2222 for (ch = 0; ch < nch; ++ch) {
2213 struct channel const *channel = &granule->ch[ch]; 2223 struct channel const *channel = &granule->ch[ch];
2214 mad_fixed_t (*sample)[32] = &frame->sbsample[ch][18 * gr]; 2224 mad_fixed_t (*sample)[32] = &frame->sbsample[ch][18 * gr];
2215 unsigned int sb, l, i, sblimit; 2225 unsigned int sb, l, i, sblimit;
2216 mad_fixed_t output[36]; 2226 mad_fixed_t output[36];
2217 2227
2218 if (channel->block_type == 2) { 2228 if (channel->block_type == 2) {
2219 III_reorder(xr[ch], channel, sfbwidth_table[sfreqi].s); 2229 III_reorder(xr[ch], channel, sfbwidth[ch]);
2220 2230
2221# if !defined(OPT_STRICT) 2231# if !defined(OPT_STRICT)
2222 /* 2232 /*
2223 * According to ISO/IEC 11172-3, "Alias reduction is not applied for 2233 * According to ISO/IEC 11172-3, "Alias reduction is not applied for
2224 * granules with block_type == 2 (short block)." However, other 2234 * granules with block_type == 2 (short block)." However, other
2225 * sources suggest alias reduction should indeed be performed on the 2235 * sources suggest alias reduction should indeed be performed on the
2226 * lower two subbands of mixed blocks. Most other implementations do 2236 * lower two subbands of mixed blocks. Most other implementations do
2227 * this, so by default we will too. 2237 * this, so by default we will too.
2228 */ 2238 */
2229 if (channel->flags & mixed_block_flag) 2239 if (channel->flags & mixed_block_flag)
2230 III_aliasreduce(xr[ch], 36); 2240 III_aliasreduce(xr[ch], 36);
2231# endif 2241# endif
2232 } 2242 }
2233 else 2243 else
2234 III_aliasreduce(xr[ch], 576); 2244 III_aliasreduce(xr[ch], 576);
2235 2245
2236 l = 0; 2246 l = 0;
2237 2247
2238 /* subbands 0-1 */ 2248 /* subbands 0-1 */
2239 2249
2240 if (channel->block_type != 2 || (channel->flags & mixed_block_flag)) { 2250 if (channel->block_type != 2 || (channel->flags & mixed_block_flag)) {
2241 unsigned int block_type; 2251 unsigned int block_type;
2242 2252
2243 block_type = channel->block_type; 2253 block_type = channel->block_type;
2244 if (channel->flags & mixed_block_flag) 2254 if (channel->flags & mixed_block_flag)
2245 block_type = 0; 2255 block_type = 0;
2246 2256
2247 /* long blocks */ 2257 /* long blocks */
2248 for (sb = 0; sb < 2; ++sb, l += 18) { 2258 for (sb = 0; sb < 2; ++sb, l += 18) {
2249 III_imdct_l(&xr[ch][l], output, block_type); 2259 III_imdct_l(&xr[ch][l], output, block_type);
2250 III_overlap(output, (*frame->overlap)[ch][sb], sample, sb); 2260 III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
2251 } 2261 }
2252 } 2262 }
2253 else { 2263 else {
2254 /* short blocks */ 2264 /* short blocks */
2255 for (sb = 0; sb < 2; ++sb, l += 18) { 2265 for (sb = 0; sb < 2; ++sb, l += 18) {
2256 III_imdct_s(&xr[ch][l], output); 2266 III_imdct_s(&xr[ch][l], output);
2257 III_overlap(output, (*frame->overlap)[ch][sb], sample, sb); 2267 III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
2258 } 2268 }
2259 } 2269 }
2260 2270
2261 III_freqinver(sample, 1); 2271 III_freqinver(sample, 1);
2262 2272
2263 /* (nonzero) subbands 2-31 */ 2273 /* (nonzero) subbands 2-31 */
2264 2274
2265 i = 576; 2275 i = 576;
2266 while (i > 36 && xr[ch][i - 1] == 0) 2276 while (i > 36 && xr[ch][i - 1] == 0)
2267 --i; 2277 --i;
2268 2278
2269 sblimit = 32 - (576 - i) / 18; 2279 sblimit = 32 - (576 - i) / 18;
2270 2280
2271 if (channel->block_type != 2) { 2281 if (channel->block_type != 2) {
2272 /* long blocks */ 2282 /* long blocks */
2273 for (sb = 2; sb < sblimit; ++sb, l += 18) { 2283 for (sb = 2; sb < sblimit; ++sb, l += 18) {
2274 III_imdct_l(&xr[ch][l], output, channel->block_type); 2284 III_imdct_l(&xr[ch][l], output, channel->block_type);
2275 III_overlap(output, (*frame->overlap)[ch][sb], sample, sb); 2285 III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
2276 2286
2277 if (sb & 1) 2287 if (sb & 1)
2278 III_freqinver(sample, sb); 2288 III_freqinver(sample, sb);
2279 } 2289 }
2280 } 2290 }
2281 else { 2291 else {
2282 /* short blocks */ 2292 /* short blocks */
2283 for (sb = 2; sb < sblimit; ++sb, l += 18) { 2293 for (sb = 2; sb < sblimit; ++sb, l += 18) {
2284 III_imdct_s(&xr[ch][l], output); 2294 III_imdct_s(&xr[ch][l], output);
2285 III_overlap(output, (*frame->overlap)[ch][sb], sample, sb); 2295 III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
2286 2296
2287 if (sb & 1) 2297 if (sb & 1)
2288 III_freqinver(sample, sb); 2298 III_freqinver(sample, sb);
2289 } 2299 }
2290 } 2300 }
2291 2301
2292 /* remaining (zero) subbands */ 2302 /* remaining (zero) subbands */
2293 2303
2294 for (sb = sblimit; sb < 32; ++sb) { 2304 for (sb = sblimit; sb < 32; ++sb) {
2295 III_overlap_z((*frame->overlap)[ch][sb], sample, sb); 2305 III_overlap_z((*frame->overlap)[ch][sb], sample, sb);
2296 2306
2297 if (sb & 1) 2307 if (sb & 1)
2298 III_freqinver(sample, sb); 2308 III_freqinver(sample, sb);
2299 } 2309 }
2300 } 2310 }
2301 } 2311 }
2302 2312
2303 return 0; 2313 return MAD_ERROR_NONE;
2304} 2314}
2305 2315
2306/* 2316/*
2307 * NAME:layer->III() 2317 * NAME:layer->III()
2308 * DESCRIPTION:decode a single Layer III frame 2318 * DESCRIPTION:decode a single Layer III frame
2309 */ 2319 */
2310int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame) 2320int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame)
2311{ 2321{
2312 struct mad_header *header = &frame->header; 2322 struct mad_header *header = &frame->header;
2313 unsigned int nch, priv_bitlen, next_md_begin = 0; 2323 unsigned int nch, priv_bitlen, next_md_begin = 0;
2314 unsigned int si_len, data_bitlen, md_len; 2324 unsigned int si_len, data_bitlen, md_len;
2315 unsigned int frame_space, frame_used, frame_free; 2325 unsigned int frame_space, frame_used, frame_free;
2316 struct mad_bitptr ptr; 2326 struct mad_bitptr ptr;
2317 struct sideinfo si; 2327 struct sideinfo si;
2318 enum mad_error error; 2328 enum mad_error error;
2319 int result = 0; 2329 int result = 0;
2320 2330
2321 /* allocate Layer III dynamic structures */ 2331 /* allocate Layer III dynamic structures */
2322 2332
2323 if (stream->main_data == 0) { 2333 if (stream->main_data == 0) {
2324 stream->main_data = malloc(MAD_BUFFER_MDLEN); 2334 stream->main_data = malloc(MAD_BUFFER_MDLEN);
2325 if (stream->main_data == 0) { 2335 if (stream->main_data == 0) {
2326 stream->error = MAD_ERROR_NOMEM; 2336 stream->error = MAD_ERROR_NOMEM;
2327 return -1; 2337 return -1;
2328 } 2338 }
2329 } 2339 }
2330 2340
2331 if (frame->overlap == 0) { 2341 if (frame->overlap == 0) {
2332 frame->overlap = calloc(2 * 32 * 18, sizeof(mad_fixed_t)); 2342 frame->overlap = calloc(2 * 32 * 18, sizeof(mad_fixed_t));
2333 if (frame->overlap == 0) { 2343 if (frame->overlap == 0) {
2334 stream->error = MAD_ERROR_NOMEM; 2344 stream->error = MAD_ERROR_NOMEM;
2335 return -1; 2345 return -1;
2336 } 2346 }
2337 } 2347 }
2338 2348
2339 nch = MAD_NCHANNELS(header); 2349 nch = MAD_NCHANNELS(header);
2340 si_len = (header->flags & MAD_FLAG_LSF_EXT) ? 2350 si_len = (header->flags & MAD_FLAG_LSF_EXT) ?
2341 (nch == 1 ? 9 : 17) : (nch == 1 ? 17 : 32); 2351 (nch == 1 ? 9 : 17) : (nch == 1 ? 17 : 32);
2342 2352
2343 /* check frame sanity */ 2353 /* check frame sanity */
2344 2354
2345 if (stream->next_frame - mad_bit_nextbyte(&stream->ptr) < 2355 if (stream->next_frame - mad_bit_nextbyte(&stream->ptr) <
2346 (signed int) si_len) { 2356 (signed int) si_len) {
2347 stream->error = MAD_ERROR_BADFRAMELEN; 2357 stream->error = MAD_ERROR_BADFRAMELEN;
2348 stream->md_len = 0; 2358 stream->md_len = 0;
2349 return -1; 2359 return -1;
2350 } 2360 }
2351 2361
2352 /* check CRC word */ 2362 /* check CRC word */
2353 2363
2354 if (header->flags & MAD_FLAG_PROTECTION) { 2364 if (header->flags & MAD_FLAG_PROTECTION) {
2355 header->crc_check = 2365 header->crc_check =
2356 mad_bit_crc(stream->ptr, si_len * CHAR_BIT, header->crc_check); 2366 mad_bit_crc(stream->ptr, si_len * CHAR_BIT, header->crc_check);
2357 2367
2358 if (header->crc_check != header->crc_target && 2368 if (header->crc_check != header->crc_target &&
2359 !(frame->options & MAD_OPTION_IGNORECRC)) { 2369 !(frame->options & MAD_OPTION_IGNORECRC)) {
2360 stream->error = MAD_ERROR_BADCRC; 2370 stream->error = MAD_ERROR_BADCRC;
2361 result = -1; 2371 result = -1;
2362 } 2372 }
2363 } 2373 }
2364 2374
2365 /* decode frame side information */ 2375 /* decode frame side information */
2366 2376
2367 error = III_sideinfo(&stream->ptr, nch, header->flags & MAD_FLAG_LSF_EXT, 2377 error = III_sideinfo(&stream->ptr, nch, header->flags & MAD_FLAG_LSF_EXT,
2368 &si, &data_bitlen, &priv_bitlen); 2378 &si, &data_bitlen, &priv_bitlen);
2369 if (error && result == 0) { 2379 if (error && result == 0) {
2370 stream->error = error; 2380 stream->error = error;
2371 result = -1; 2381 result = -1;
2372 } 2382 }
2373 2383
2374 header->flags |= priv_bitlen; 2384 header->flags |= priv_bitlen;
2375 header->private_bits |= si.private_bits; 2385 header->private_bits |= si.private_bits;
2376 2386
2377 /* find main_data of next frame */ 2387 /* find main_data of next frame */
2378 2388
2379 { 2389 {
2380 struct mad_bitptr peek; 2390 struct mad_bitptr peek;
2381 unsigned long header; 2391 unsigned long header;
2382 2392
2383 mad_bit_init(&peek, stream->next_frame); 2393 mad_bit_init(&peek, stream->next_frame);
2384 2394
2385 header = mad_bit_read(&peek, 32); 2395 header = mad_bit_read(&peek, 32);
2386 if ((header & 0xffe60000L) /* syncword | layer */ == 0xffe20000L) { 2396 if ((header & 0xffe60000L) /* syncword | layer */ == 0xffe20000L) {
2387 if (!(header & 0x00010000L)) /* protection_bit */ 2397 if (!(header & 0x00010000L)) /* protection_bit */
2388 mad_bit_skip(&peek, 16); /* crc_check */ 2398 mad_bit_skip(&peek, 16); /* crc_check */
2389 2399
2390 next_md_begin = 2400 next_md_begin =
2391 mad_bit_read(&peek, (header & 0x00080000L) /* ID */ ? 9 : 8); 2401 mad_bit_read(&peek, (header & 0x00080000L) /* ID */ ? 9 : 8);
2392 } 2402 }
2393 2403
2394 mad_bit_finish(&peek); 2404 mad_bit_finish(&peek);
2395 } 2405 }
2396 2406
2397 /* find main_data of this frame */ 2407 /* find main_data of this frame */
2398 2408
2399 frame_space = stream->next_frame - mad_bit_nextbyte(&stream->ptr); 2409 frame_space = stream->next_frame - mad_bit_nextbyte(&stream->ptr);
2400 2410
2401 if (next_md_begin > si.main_data_begin + frame_space) 2411 if (next_md_begin > si.main_data_begin + frame_space)
2402 next_md_begin = 0; 2412 next_md_begin = 0;
2403 2413
2404 md_len = si.main_data_begin + frame_space - next_md_begin; 2414 md_len = si.main_data_begin + frame_space - next_md_begin;
2405 2415
2406 frame_used = 0; 2416 frame_used = 0;
2407 2417
2408 if (si.main_data_begin == 0) { 2418 if (si.main_data_begin == 0) {
2409 ptr = stream->ptr; 2419 ptr = stream->ptr;
2410 stream->md_len = 0; 2420 stream->md_len = 0;
2411 2421
2412 frame_used = md_len; 2422 frame_used = md_len;
2413 } 2423 }
2414 else { 2424 else {
2415 if (si.main_data_begin > stream->md_len) { 2425 if (si.main_data_begin > stream->md_len) {
2416 if (result == 0) { 2426 if (result == 0) {
2417 stream->error = MAD_ERROR_BADDATAPTR; 2427 stream->error = MAD_ERROR_BADDATAPTR;
2418 result = -1; 2428 result = -1;
2419 } 2429 }
2420 } 2430 }
2421 else { 2431 else {
2422 mad_bit_init(&ptr, 2432 mad_bit_init(&ptr,
2423 *stream->main_data + stream->md_len - si.main_data_begin); 2433 *stream->main_data + stream->md_len - si.main_data_begin);
2424 2434
2425 if (md_len > si.main_data_begin) { 2435 if (md_len > si.main_data_begin) {
2426 assert(stream->md_len + md_len - 2436 assert(stream->md_len + md_len -
2427 si.main_data_begin <= MAD_BUFFER_MDLEN); 2437 si.main_data_begin <= MAD_BUFFER_MDLEN);
2428 2438
2429 memcpy(*stream->main_data + stream->md_len, 2439 memcpy(*stream->main_data + stream->md_len,
2430 mad_bit_nextbyte(&stream->ptr), 2440 mad_bit_nextbyte(&stream->ptr),
2431 frame_used = md_len - si.main_data_begin); 2441 frame_used = md_len - si.main_data_begin);
2432 stream->md_len += frame_used; 2442 stream->md_len += frame_used;
2433 } 2443 }
2434 } 2444 }
2435 } 2445 }
2436 2446
2437 frame_free = frame_space - frame_used; 2447 frame_free = frame_space - frame_used;
2438 2448
2439 /* decode main_data */ 2449 /* decode main_data */
2440 2450
2441 if (result == 0) { 2451 if (result == 0) {
2442 error = III_decode(&ptr, frame, &si, nch); 2452 error = III_decode(&ptr, frame, &si, nch);
2443 if (error) { 2453 if (error) {
2444 stream->error = error; 2454 stream->error = error;
2445 result = -1; 2455 result = -1;
2446 } 2456 }
2447 } 2457 }
2448 2458
2449 /* designate ancillary bits */ 2459 /* designate ancillary bits */
2450 2460
2451 stream->anc_ptr = ptr; 2461 stream->anc_ptr = ptr;
2452 stream->anc_bitlen = md_len * CHAR_BIT - data_bitlen; 2462 stream->anc_bitlen = md_len * CHAR_BIT - data_bitlen;
2453 2463
2454# if 0 && defined(DEBUG) 2464# if 0 && defined(DEBUG)
2455 fprintf(stderr, 2465 fprintf(stderr,
2456 "main_data_begin:%u, md_len:%u, frame_free:%u, " 2466 "main_data_begin:%u, md_len:%u, frame_free:%u, "
2457 "data_bitlen:%u, anc_bitlen: %u\n", 2467 "data_bitlen:%u, anc_bitlen: %u\n",
2458 si.main_data_begin, md_len, frame_free, 2468 si.main_data_begin, md_len, frame_free,
2459 data_bitlen, stream->anc_bitlen); 2469 data_bitlen, stream->anc_bitlen);
2460# endif 2470# endif
2461 2471
2462 /* preload main_data buffer with up to 511 bytes for next frame(s) */ 2472 /* preload main_data buffer with up to 511 bytes for next frame(s) */
2463 2473
2464 if (frame_free >= next_md_begin) { 2474 if (frame_free >= next_md_begin) {
2465 memcpy(*stream->main_data, 2475 memcpy(*stream->main_data,
2466 stream->next_frame - next_md_begin, next_md_begin); 2476 stream->next_frame - next_md_begin, next_md_begin);
2467 stream->md_len = next_md_begin; 2477 stream->md_len = next_md_begin;
2468 } 2478 }
2469 else { 2479 else {
2470 if (md_len < si.main_data_begin) { 2480 if (md_len < si.main_data_begin) {
2471 unsigned int extra; 2481 unsigned int extra;
2472 2482
2473 extra = si.main_data_begin - md_len; 2483 extra = si.main_data_begin - md_len;
2474 if (extra + frame_free > next_md_begin) 2484 if (extra + frame_free > next_md_begin)
2475 extra = next_md_begin - frame_free; 2485 extra = next_md_begin - frame_free;
2476 2486
2477 if (extra < stream->md_len) { 2487 if (extra < stream->md_len) {
2478 memmove(*stream->main_data, 2488 memmove(*stream->main_data,
2479 *stream->main_data + stream->md_len - extra, extra); 2489 *stream->main_data + stream->md_len - extra, extra);
2480 stream->md_len = extra; 2490 stream->md_len = extra;
2481 } 2491 }
2482 } 2492 }
2483 else 2493 else
2484 stream->md_len = 0; 2494 stream->md_len = 0;
2485 2495
2486 memcpy(*stream->main_data + stream->md_len, 2496 memcpy(*stream->main_data + stream->md_len,
2487 stream->next_frame - frame_free, frame_free); 2497 stream->next_frame - frame_free, frame_free);
2488 stream->md_len += frame_free; 2498 stream->md_len += frame_free;
2489 } 2499 }
2490 2500
2491 return result; 2501 return result;
2492} 2502}
diff --git a/core/multimedia/opieplayer/libmad/layer3.h b/core/multimedia/opieplayer/libmad/layer3.h
index 1fd83e2..c1a5c69 100644
--- a/core/multimedia/opieplayer/libmad/layer3.h
+++ b/core/multimedia/opieplayer/libmad/layer3.h
@@ -1,30 +1,30 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# ifndef LIBMAD_LAYER3_H 22# ifndef LIBMAD_LAYER3_H
23# define LIBMAD_LAYER3_H 23# define LIBMAD_LAYER3_H
24 24
25# include "stream.h" 25# include "stream.h"
26# include "frame.h" 26# include "frame.h"
27 27
28int mad_layer_III(struct mad_stream *, struct mad_frame *); 28int mad_layer_III(struct mad_stream *, struct mad_frame *);
29 29
30# endif 30# endif
diff --git a/core/multimedia/opieplayer/libmad/libmad_global.h b/core/multimedia/opieplayer/libmad/libmad_global.h
index f2a2a71..2c9c713 100644
--- a/core/multimedia/opieplayer/libmad/libmad_global.h
+++ b/core/multimedia/opieplayer/libmad/libmad_global.h
@@ -1,45 +1,58 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# ifndef LIBMAD_GLOBAL_H 22# ifndef LIBMAD_GLOBAL_H
23# define LIBMAD_GLOBAL_H 23# define LIBMAD_GLOBAL_H
24 24
25/* conditional debugging */ 25/* conditional debugging */
26 26
27# if defined(DEBUG) && defined(NDEBUG) 27# if defined(DEBUG) && defined(NDEBUG)
28# error "cannot define both DEBUG and NDEBUG" 28# error "cannot define both DEBUG and NDEBUG"
29# endif 29# endif
30 30
31# if defined(DEBUG) 31# if defined(DEBUG)
32# include <stdio.h> 32# include <stdio.h>
33# endif 33# endif
34 34
35/* conditional features */ 35/* conditional features */
36 36
37# if defined(OPT_SPEED) && defined(OPT_ACCURACY) 37# if defined(OPT_SPEED) && defined(OPT_ACCURACY)
38# error "cannot optimize for both speed and accuracy" 38# error "cannot optimize for both speed and accuracy"
39# endif 39# endif
40 40
41# if defined(OPT_SPEED) && !defined(OPT_SSO) 41# if defined(OPT_SPEED) && !defined(OPT_SSO)
42# define OPT_SSO 1 42# define OPT_SSO 1
43# endif 43# endif
44 44
45# if defined(HAVE_UNISTD_H) && defined(HAVE_WAITPID) && \
46 defined(HAVE_FCNTL) && defined(HAVE_PIPE) && defined(HAVE_FORK)
47# define USE_ASYNC
48# endif
49
50# if !defined(HAVE_ASSERT_H)
51# if defined(NDEBUG)
52 # define assert(x)/* nothing */
53# else
54 # define assert(x)do { if (!(x)) abort(); } while (0)
55# endif
56# endif
57
45# endif 58# endif
diff --git a/core/multimedia/opieplayer/libmad/libmad_version.h b/core/multimedia/opieplayer/libmad/libmad_version.h
index f8ee1fa..9e684a7 100644
--- a/core/multimedia/opieplayer/libmad/libmad_version.h
+++ b/core/multimedia/opieplayer/libmad/libmad_version.h
@@ -1,47 +1,47 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# ifndef LIBMAD_VERSION_H 22# ifndef LIBMAD_VERSION_H
23# define LIBMAD_VERSION_H 23# define LIBMAD_VERSION_H
24 24
25 # define MAD_VERSION_MAJOR0 25 # define MAD_VERSION_MAJOR0
26 # define MAD_VERSION_MINOR13 26 # define MAD_VERSION_MINOR14
27 # define MAD_VERSION_PATCH0 27 # define MAD_VERSION_PATCH2
28 # define MAD_VERSION_EXTRA" (beta)" 28 # define MAD_VERSION_EXTRA" (beta)"
29 29
30 # define MAD_VERSION_STRINGIZE(str)#str 30 # define MAD_VERSION_STRINGIZE(str)#str
31 # define MAD_VERSION_STRING(num)MAD_VERSION_STRINGIZE(num) 31 # define MAD_VERSION_STRING(num)MAD_VERSION_STRINGIZE(num)
32 32
33 # define MAD_VERSION MAD_VERSION_STRING(MAD_VERSION_MAJOR) "." \ 33 # define MAD_VERSION MAD_VERSION_STRING(MAD_VERSION_MAJOR) "." \
34 MAD_VERSION_STRING(MAD_VERSION_MINOR) "." \ 34 MAD_VERSION_STRING(MAD_VERSION_MINOR) "." \
35 MAD_VERSION_STRING(MAD_VERSION_PATCH) \ 35 MAD_VERSION_STRING(MAD_VERSION_PATCH) \
36 MAD_VERSION_EXTRA 36 MAD_VERSION_EXTRA
37 37
38 # define MAD_PUBLISHYEAR"2000-2001" 38 # define MAD_PUBLISHYEAR"2000-2001"
39 # define MAD_AUTHOR "Robert Leslie" 39 # define MAD_AUTHOR "Robert Leslie"
40 # define MAD_EMAIL "rob@mars.org" 40 # define MAD_EMAIL "rob@mars.org"
41 41
42extern char const mad_version[]; 42extern char const mad_version[];
43extern char const mad_copyright[]; 43extern char const mad_copyright[];
44extern char const mad_author[]; 44extern char const mad_author[];
45extern char const mad_build[]; 45extern char const mad_build[];
46 46
47# endif 47# endif
diff --git a/core/multimedia/opieplayer/libmad/opie-libmadplugin.control b/core/multimedia/opieplayer/libmad/opie-libmadplugin.control
index 941047f..42ea6c7 100644
--- a/core/multimedia/opieplayer/libmad/opie-libmadplugin.control
+++ b/core/multimedia/opieplayer/libmad/opie-libmadplugin.control
@@ -1,9 +1,9 @@
1Files: plugins/codecs/libmadplugin.so.1.0.0 plugins/codecs/libmadplugin.so.1.0 plugins/codecs/libmadplugin.so.1 plugins/codecs/libmadplugin.so 1Files: plugins/codecs/libmadplugin.so.1.0.0 plugins/codecs/libmadplugin.so.1.0 plugins/codecs/libmadplugin.so.1 plugins/codecs/libmadplugin.so
2Priority: optional 2Priority: optional
3Section: opie/plugins 3Section: opie/plugins
4Maintainer: John Ryland <jryland@trolltech.com> 4Maintainer: Maximilian Reiss <max.reiss@gmx.de>
5Architecture: arm 5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION 6Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base ($QPE_VERSION) 7Depends: opie-base ($QPE_VERSION)
8Description: MP3 file plugin using libmad 8Description: MP3 file plugin using libmad
9 Plugin to play MP3 files with the mediaplayer in the Opie environment. 9 Plugin to play MP3 files with the mediaplayer in the Opie environment.
diff --git a/core/multimedia/opieplayer/libmad/qc_table.dat b/core/multimedia/opieplayer/libmad/qc_table.dat
index 92b7f38..5d9ca96 100644
--- a/core/multimedia/opieplayer/libmad/qc_table.dat
+++ b/core/multimedia/opieplayer/libmad/qc_table.dat
@@ -1,77 +1,77 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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/* 22/*
23 * These are the Layer II classes of quantization. 23 * These are the Layer II classes of quantization.
24 * The table is derived from Table B.4 of ISO/IEC 11172-3. 24 * The table is derived from Table B.4 of ISO/IEC 11172-3.
25 */ 25 */
26 26
27 { 3, 2, 5, 27 { 3, 2, 5,
28 MAD_F(0x15555555) /* 1.33333333333 => 1.33333333209, e 0.00000000124 */, 28 MAD_F(0x15555555) /* 1.33333333333 => 1.33333333209, e 0.00000000124 */,
29 MAD_F(0x08000000) /* 0.50000000000 => 0.50000000000, e 0.00000000000 */ }, 29 MAD_F(0x08000000) /* 0.50000000000 => 0.50000000000, e 0.00000000000 */ },
30 { 5, 3, 7, 30 { 5, 3, 7,
31 MAD_F(0x1999999a) /* 1.60000000000 => 1.60000000149, e -0.00000000149 */, 31 MAD_F(0x1999999a) /* 1.60000000000 => 1.60000000149, e -0.00000000149 */,
32 MAD_F(0x08000000) /* 0.50000000000 => 0.50000000000, e 0.00000000000 */ }, 32 MAD_F(0x08000000) /* 0.50000000000 => 0.50000000000, e 0.00000000000 */ },
33 { 7, 0, 3, 33 { 7, 0, 3,
34 MAD_F(0x12492492) /* 1.14285714286 => 1.14285714179, e 0.00000000107 */, 34 MAD_F(0x12492492) /* 1.14285714286 => 1.14285714179, e 0.00000000107 */,
35 MAD_F(0x04000000) /* 0.25000000000 => 0.25000000000, e 0.00000000000 */ }, 35 MAD_F(0x04000000) /* 0.25000000000 => 0.25000000000, e 0.00000000000 */ },
36 { 9, 4, 10, 36 { 9, 4, 10,
37 MAD_F(0x1c71c71c) /* 1.77777777777 => 1.77777777612, e 0.00000000165 */, 37 MAD_F(0x1c71c71c) /* 1.77777777777 => 1.77777777612, e 0.00000000165 */,
38 MAD_F(0x08000000) /* 0.50000000000 => 0.50000000000, e 0.00000000000 */ }, 38 MAD_F(0x08000000) /* 0.50000000000 => 0.50000000000, e 0.00000000000 */ },
39 { 15, 0, 4, 39 { 15, 0, 4,
40 MAD_F(0x11111111) /* 1.06666666666 => 1.06666666642, e 0.00000000024 */, 40 MAD_F(0x11111111) /* 1.06666666666 => 1.06666666642, e 0.00000000024 */,
41 MAD_F(0x02000000) /* 0.12500000000 => 0.12500000000, e 0.00000000000 */ }, 41 MAD_F(0x02000000) /* 0.12500000000 => 0.12500000000, e 0.00000000000 */ },
42 { 31, 0, 5, 42 { 31, 0, 5,
43 MAD_F(0x10842108) /* 1.03225806452 => 1.03225806355, e 0.00000000097 */, 43 MAD_F(0x10842108) /* 1.03225806452 => 1.03225806355, e 0.00000000097 */,
44 MAD_F(0x01000000) /* 0.06250000000 => 0.06250000000, e 0.00000000000 */ }, 44 MAD_F(0x01000000) /* 0.06250000000 => 0.06250000000, e 0.00000000000 */ },
45 { 63, 0, 6, 45 { 63, 0, 6,
46 MAD_F(0x10410410) /* 1.01587301587 => 1.01587301493, e 0.00000000094 */, 46 MAD_F(0x10410410) /* 1.01587301587 => 1.01587301493, e 0.00000000094 */,
47 MAD_F(0x00800000) /* 0.03125000000 => 0.03125000000, e 0.00000000000 */ }, 47 MAD_F(0x00800000) /* 0.03125000000 => 0.03125000000, e 0.00000000000 */ },
48 { 127, 0, 7, 48 { 127, 0, 7,
49 MAD_F(0x10204081) /* 1.00787401575 => 1.00787401572, e 0.00000000003 */, 49 MAD_F(0x10204081) /* 1.00787401575 => 1.00787401572, e 0.00000000003 */,
50 MAD_F(0x00400000) /* 0.01562500000 => 0.01562500000, e 0.00000000000 */ }, 50 MAD_F(0x00400000) /* 0.01562500000 => 0.01562500000, e 0.00000000000 */ },
51 { 255, 0, 8, 51 { 255, 0, 8,
52 MAD_F(0x10101010) /* 1.00392156863 => 1.00392156839, e 0.00000000024 */, 52 MAD_F(0x10101010) /* 1.00392156863 => 1.00392156839, e 0.00000000024 */,
53 MAD_F(0x00200000) /* 0.00781250000 => 0.00781250000, e 0.00000000000 */ }, 53 MAD_F(0x00200000) /* 0.00781250000 => 0.00781250000, e 0.00000000000 */ },
54 { 511, 0, 9, 54 { 511, 0, 9,
55 MAD_F(0x10080402) /* 1.00195694716 => 1.00195694715, e 0.00000000001 */, 55 MAD_F(0x10080402) /* 1.00195694716 => 1.00195694715, e 0.00000000001 */,
56 MAD_F(0x00100000) /* 0.00390625000 => 0.00390625000, e 0.00000000000 */ }, 56 MAD_F(0x00100000) /* 0.00390625000 => 0.00390625000, e 0.00000000000 */ },
57 { 1023, 0, 10, 57 { 1023, 0, 10,
58 MAD_F(0x10040100) /* 1.00097751711 => 1.00097751617, e 0.00000000094 */, 58 MAD_F(0x10040100) /* 1.00097751711 => 1.00097751617, e 0.00000000094 */,
59 MAD_F(0x00080000) /* 0.00195312500 => 0.00195312500, e 0.00000000000 */ }, 59 MAD_F(0x00080000) /* 0.00195312500 => 0.00195312500, e 0.00000000000 */ },
60 { 2047, 0, 11, 60 { 2047, 0, 11,
61 MAD_F(0x10020040) /* 1.00048851979 => 1.00048851967, e 0.00000000012 */, 61 MAD_F(0x10020040) /* 1.00048851979 => 1.00048851967, e 0.00000000012 */,
62 MAD_F(0x00040000) /* 0.00097656250 => 0.00097656250, e 0.00000000000 */ }, 62 MAD_F(0x00040000) /* 0.00097656250 => 0.00097656250, e 0.00000000000 */ },
63 { 4095, 0, 12, 63 { 4095, 0, 12,
64 MAD_F(0x10010010) /* 1.00024420024 => 1.00024420023, e 0.00000000001 */, 64 MAD_F(0x10010010) /* 1.00024420024 => 1.00024420023, e 0.00000000001 */,
65 MAD_F(0x00020000) /* 0.00048828125 => 0.00048828125, e 0.00000000000 */ }, 65 MAD_F(0x00020000) /* 0.00048828125 => 0.00048828125, e 0.00000000000 */ },
66 { 8191, 0, 13, 66 { 8191, 0, 13,
67 MAD_F(0x10008004) /* 1.00012208522 => 1.00012208521, e 0.00000000001 */, 67 MAD_F(0x10008004) /* 1.00012208522 => 1.00012208521, e 0.00000000001 */,
68 MAD_F(0x00010000) /* 0.00024414063 => 0.00024414062, e 0.00000000000 */ }, 68 MAD_F(0x00010000) /* 0.00024414063 => 0.00024414062, e 0.00000000000 */ },
69 { 16383, 0, 14, 69 { 16383, 0, 14,
70 MAD_F(0x10004001) /* 1.00006103888 => 1.00006103888, e -0.00000000000 */, 70 MAD_F(0x10004001) /* 1.00006103888 => 1.00006103888, e -0.00000000000 */,
71 MAD_F(0x00008000) /* 0.00012207031 => 0.00012207031, e -0.00000000000 */ }, 71 MAD_F(0x00008000) /* 0.00012207031 => 0.00012207031, e -0.00000000000 */ },
72 { 32767, 0, 15, 72 { 32767, 0, 15,
73 MAD_F(0x10002000) /* 1.00003051851 => 1.00003051758, e 0.00000000093 */, 73 MAD_F(0x10002000) /* 1.00003051851 => 1.00003051758, e 0.00000000093 */,
74 MAD_F(0x00004000) /* 0.00006103516 => 0.00006103516, e 0.00000000000 */ }, 74 MAD_F(0x00004000) /* 0.00006103516 => 0.00006103516, e 0.00000000000 */ },
75 { 65535, 0, 16, 75 { 65535, 0, 16,
76 MAD_F(0x10001000) /* 1.00001525902 => 1.00001525879, e 0.00000000023 */, 76 MAD_F(0x10001000) /* 1.00001525902 => 1.00001525879, e 0.00000000023 */,
77 MAD_F(0x00002000) /* 0.00003051758 => 0.00003051758, e 0.00000000000 */ } 77 MAD_F(0x00002000) /* 0.00003051758 => 0.00003051758, e 0.00000000000 */ }
diff --git a/core/multimedia/opieplayer/libmad/rq_table.dat b/core/multimedia/opieplayer/libmad/rq_table.dat
index b6d1634..803cf04 100644
--- a/core/multimedia/opieplayer/libmad/rq_table.dat
+++ b/core/multimedia/opieplayer/libmad/rq_table.dat
@@ -1,194 +1,194 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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/* 22/*
23 * This is the lookup table used to compute x^(4/3) for Layer III 23 * This is the lookup table used to compute x^(4/3) for Layer III
24 * requantization. To maintain the best possible accuracy, the value is 24 * requantization. To maintain the best possible accuracy, the value is
25 * stored as a normalized mantissa with exponent. The requantization 25 * stored as a normalized mantissa with exponent. The requantization
26 * algorithm recombines these parts with appropriate scaling. 26 * algorithm recombines these parts with appropriate scaling.
27 */ 27 */
28 28
29 /* 0 */ { MAD_F(0x00000000) /* 0.000000000 */, 0 }, 29 /* 0 */ { MAD_F(0x00000000) /* 0.000000000 */, 0 },
30 /* 1 */ { MAD_F(0x04000000) /* 0.250000000 */, 2 }, 30 /* 1 */ { MAD_F(0x04000000) /* 0.250000000 */, 2 },
31 /* 2 */ { MAD_F(0x050a28be) /* 0.314980262 */, 3 }, 31 /* 2 */ { MAD_F(0x050a28be) /* 0.314980262 */, 3 },
32 /* 3 */ { MAD_F(0x0453a5cd) /* 0.270421794 */, 4 }, 32 /* 3 */ { MAD_F(0x0453a5cd) /* 0.270421794 */, 4 },
33 /* 4 */ { MAD_F(0x06597fa9) /* 0.396850263 */, 4 }, 33 /* 4 */ { MAD_F(0x06597fa9) /* 0.396850263 */, 4 },
34 /* 5 */ { MAD_F(0x04466275) /* 0.267183742 */, 5 }, 34 /* 5 */ { MAD_F(0x04466275) /* 0.267183742 */, 5 },
35 /* 6 */ { MAD_F(0x05738c72) /* 0.340710111 */, 5 }, 35 /* 6 */ { MAD_F(0x05738c72) /* 0.340710111 */, 5 },
36 /* 7 */ { MAD_F(0x06b1fc81) /* 0.418453696 */, 5 }, 36 /* 7 */ { MAD_F(0x06b1fc81) /* 0.418453696 */, 5 },
37 /* 8 */ { MAD_F(0x04000000) /* 0.250000000 */, 6 }, 37 /* 8 */ { MAD_F(0x04000000) /* 0.250000000 */, 6 },
38 /* 9 */ { MAD_F(0x04ae20d7) /* 0.292511788 */, 6 }, 38 /* 9 */ { MAD_F(0x04ae20d7) /* 0.292511788 */, 6 },
39 /* 10 */ { MAD_F(0x0562d694) /* 0.336630420 */, 6 }, 39 /* 10 */ { MAD_F(0x0562d694) /* 0.336630420 */, 6 },
40 /* 11 */ { MAD_F(0x061dae96) /* 0.382246578 */, 6 }, 40 /* 11 */ { MAD_F(0x061dae96) /* 0.382246578 */, 6 },
41 /* 12 */ { MAD_F(0x06de47f4) /* 0.429267841 */, 6 }, 41 /* 12 */ { MAD_F(0x06de47f4) /* 0.429267841 */, 6 },
42 /* 13 */ { MAD_F(0x07a44f7a) /* 0.477614858 */, 6 }, 42 /* 13 */ { MAD_F(0x07a44f7a) /* 0.477614858 */, 6 },
43 /* 14 */ { MAD_F(0x0437be65) /* 0.263609310 */, 7 }, 43 /* 14 */ { MAD_F(0x0437be65) /* 0.263609310 */, 7 },
44 /* 15 */ { MAD_F(0x049fc824) /* 0.289009227 */, 7 }, 44 /* 15 */ { MAD_F(0x049fc824) /* 0.289009227 */, 7 },
45 45
46 /* 16 */ { MAD_F(0x050a28be) /* 0.314980262 */, 7 }, 46 /* 16 */ { MAD_F(0x050a28be) /* 0.314980262 */, 7 },
47 /* 17 */ { MAD_F(0x0576c6f5) /* 0.341498336 */, 7 }, 47 /* 17 */ { MAD_F(0x0576c6f5) /* 0.341498336 */, 7 },
48 /* 18 */ { MAD_F(0x05e58c0b) /* 0.368541759 */, 7 }, 48 /* 18 */ { MAD_F(0x05e58c0b) /* 0.368541759 */, 7 },
49 /* 19 */ { MAD_F(0x06566361) /* 0.396090870 */, 7 }, 49 /* 19 */ { MAD_F(0x06566361) /* 0.396090870 */, 7 },
50 /* 20 */ { MAD_F(0x06c93a2e) /* 0.424127753 */, 7 }, 50 /* 20 */ { MAD_F(0x06c93a2e) /* 0.424127753 */, 7 },
51 /* 21 */ { MAD_F(0x073dff3e) /* 0.452635998 */, 7 }, 51 /* 21 */ { MAD_F(0x073dff3e) /* 0.452635998 */, 7 },
52 /* 22 */ { MAD_F(0x07b4a2bc) /* 0.481600510 */, 7 }, 52 /* 22 */ { MAD_F(0x07b4a2bc) /* 0.481600510 */, 7 },
53 /* 23 */ { MAD_F(0x04168b05) /* 0.255503674 */, 8 }, 53 /* 23 */ { MAD_F(0x04168b05) /* 0.255503674 */, 8 },
54 /* 24 */ { MAD_F(0x0453a5cd) /* 0.270421794 */, 8 }, 54 /* 24 */ { MAD_F(0x0453a5cd) /* 0.270421794 */, 8 },
55 /* 25 */ { MAD_F(0x04919b6a) /* 0.285548607 */, 8 }, 55 /* 25 */ { MAD_F(0x04919b6a) /* 0.285548607 */, 8 },
56 /* 26 */ { MAD_F(0x04d065fb) /* 0.300878507 */, 8 }, 56 /* 26 */ { MAD_F(0x04d065fb) /* 0.300878507 */, 8 },
57 /* 27 */ { MAD_F(0x05100000) /* 0.316406250 */, 8 }, 57 /* 27 */ { MAD_F(0x05100000) /* 0.316406250 */, 8 },
58 /* 28 */ { MAD_F(0x05506451) /* 0.332126919 */, 8 }, 58 /* 28 */ { MAD_F(0x05506451) /* 0.332126919 */, 8 },
59 /* 29 */ { MAD_F(0x05918e15) /* 0.348035890 */, 8 }, 59 /* 29 */ { MAD_F(0x05918e15) /* 0.348035890 */, 8 },
60 /* 30 */ { MAD_F(0x05d378bb) /* 0.364128809 */, 8 }, 60 /* 30 */ { MAD_F(0x05d378bb) /* 0.364128809 */, 8 },
61 /* 31 */ { MAD_F(0x06161ff3) /* 0.380401563 */, 8 }, 61 /* 31 */ { MAD_F(0x06161ff3) /* 0.380401563 */, 8 },
62 62
63 /* 32 */ { MAD_F(0x06597fa9) /* 0.396850263 */, 8 }, 63 /* 32 */ { MAD_F(0x06597fa9) /* 0.396850263 */, 8 },
64 /* 33 */ { MAD_F(0x069d9400) /* 0.413471222 */, 8 }, 64 /* 33 */ { MAD_F(0x069d9400) /* 0.413471222 */, 8 },
65 /* 34 */ { MAD_F(0x06e2594c) /* 0.430260942 */, 8 }, 65 /* 34 */ { MAD_F(0x06e2594c) /* 0.430260942 */, 8 },
66 /* 35 */ { MAD_F(0x0727cc11) /* 0.447216097 */, 8 }, 66 /* 35 */ { MAD_F(0x0727cc11) /* 0.447216097 */, 8 },
67 /* 36 */ { MAD_F(0x076de8fc) /* 0.464333519 */, 8 }, 67 /* 36 */ { MAD_F(0x076de8fc) /* 0.464333519 */, 8 },
68 /* 37 */ { MAD_F(0x07b4ace3) /* 0.481610189 */, 8 }, 68 /* 37 */ { MAD_F(0x07b4ace3) /* 0.481610189 */, 8 },
69 /* 38 */ { MAD_F(0x07fc14bf) /* 0.499043224 */, 8 }, 69 /* 38 */ { MAD_F(0x07fc14bf) /* 0.499043224 */, 8 },
70 /* 39 */ { MAD_F(0x04220ed7) /* 0.258314934 */, 9 }, 70 /* 39 */ { MAD_F(0x04220ed7) /* 0.258314934 */, 9 },
71 /* 40 */ { MAD_F(0x04466275) /* 0.267183742 */, 9 }, 71 /* 40 */ { MAD_F(0x04466275) /* 0.267183742 */, 9 },
72 /* 41 */ { MAD_F(0x046b03e7) /* 0.276126771 */, 9 }, 72 /* 41 */ { MAD_F(0x046b03e7) /* 0.276126771 */, 9 },
73 /* 42 */ { MAD_F(0x048ff1e8) /* 0.285142811 */, 9 }, 73 /* 42 */ { MAD_F(0x048ff1e8) /* 0.285142811 */, 9 },
74 /* 43 */ { MAD_F(0x04b52b3f) /* 0.294230696 */, 9 }, 74 /* 43 */ { MAD_F(0x04b52b3f) /* 0.294230696 */, 9 },
75 /* 44 */ { MAD_F(0x04daaec0) /* 0.303389310 */, 9 }, 75 /* 44 */ { MAD_F(0x04daaec0) /* 0.303389310 */, 9 },
76 /* 45 */ { MAD_F(0x05007b49) /* 0.312617576 */, 9 }, 76 /* 45 */ { MAD_F(0x05007b49) /* 0.312617576 */, 9 },
77 /* 46 */ { MAD_F(0x05268fc6) /* 0.321914457 */, 9 }, 77 /* 46 */ { MAD_F(0x05268fc6) /* 0.321914457 */, 9 },
78 /* 47 */ { MAD_F(0x054ceb2a) /* 0.331278957 */, 9 }, 78 /* 47 */ { MAD_F(0x054ceb2a) /* 0.331278957 */, 9 },
79 79
80 /* 48 */ { MAD_F(0x05738c72) /* 0.340710111 */, 9 }, 80 /* 48 */ { MAD_F(0x05738c72) /* 0.340710111 */, 9 },
81 /* 49 */ { MAD_F(0x059a72a5) /* 0.350206992 */, 9 }, 81 /* 49 */ { MAD_F(0x059a72a5) /* 0.350206992 */, 9 },
82 /* 50 */ { MAD_F(0x05c19cd3) /* 0.359768701 */, 9 }, 82 /* 50 */ { MAD_F(0x05c19cd3) /* 0.359768701 */, 9 },
83 /* 51 */ { MAD_F(0x05e90a12) /* 0.369394372 */, 9 }, 83 /* 51 */ { MAD_F(0x05e90a12) /* 0.369394372 */, 9 },
84 /* 52 */ { MAD_F(0x0610b982) /* 0.379083164 */, 9 }, 84 /* 52 */ { MAD_F(0x0610b982) /* 0.379083164 */, 9 },
85 /* 53 */ { MAD_F(0x0638aa48) /* 0.388834268 */, 9 }, 85 /* 53 */ { MAD_F(0x0638aa48) /* 0.388834268 */, 9 },
86 /* 54 */ { MAD_F(0x0660db91) /* 0.398646895 */, 9 }, 86 /* 54 */ { MAD_F(0x0660db91) /* 0.398646895 */, 9 },
87 /* 55 */ { MAD_F(0x06894c90) /* 0.408520284 */, 9 }, 87 /* 55 */ { MAD_F(0x06894c90) /* 0.408520284 */, 9 },
88 /* 56 */ { MAD_F(0x06b1fc81) /* 0.418453696 */, 9 }, 88 /* 56 */ { MAD_F(0x06b1fc81) /* 0.418453696 */, 9 },
89 /* 57 */ { MAD_F(0x06daeaa1) /* 0.428446415 */, 9 }, 89 /* 57 */ { MAD_F(0x06daeaa1) /* 0.428446415 */, 9 },
90 /* 58 */ { MAD_F(0x07041636) /* 0.438497744 */, 9 }, 90 /* 58 */ { MAD_F(0x07041636) /* 0.438497744 */, 9 },
91 /* 59 */ { MAD_F(0x072d7e8b) /* 0.448607009 */, 9 }, 91 /* 59 */ { MAD_F(0x072d7e8b) /* 0.448607009 */, 9 },
92 /* 60 */ { MAD_F(0x075722ef) /* 0.458773552 */, 9 }, 92 /* 60 */ { MAD_F(0x075722ef) /* 0.458773552 */, 9 },
93 /* 61 */ { MAD_F(0x078102b8) /* 0.468996735 */, 9 }, 93 /* 61 */ { MAD_F(0x078102b8) /* 0.468996735 */, 9 },
94 /* 62 */ { MAD_F(0x07ab1d3e) /* 0.479275937 */, 9 }, 94 /* 62 */ { MAD_F(0x07ab1d3e) /* 0.479275937 */, 9 },
95 /* 63 */ { MAD_F(0x07d571e0) /* 0.489610555 */, 9 }, 95 /* 63 */ { MAD_F(0x07d571e0) /* 0.489610555 */, 9 },
96 96
97 /* 64 */ { MAD_F(0x04000000) /* 0.250000000 */, 10 }, 97 /* 64 */ { MAD_F(0x04000000) /* 0.250000000 */, 10 },
98 /* 65 */ { MAD_F(0x04156381) /* 0.255221850 */, 10 }, 98 /* 65 */ { MAD_F(0x04156381) /* 0.255221850 */, 10 },
99 /* 66 */ { MAD_F(0x042ae32a) /* 0.260470548 */, 10 }, 99 /* 66 */ { MAD_F(0x042ae32a) /* 0.260470548 */, 10 },
100 /* 67 */ { MAD_F(0x04407eb1) /* 0.265745823 */, 10 }, 100 /* 67 */ { MAD_F(0x04407eb1) /* 0.265745823 */, 10 },
101 /* 68 */ { MAD_F(0x045635cf) /* 0.271047409 */, 10 }, 101 /* 68 */ { MAD_F(0x045635cf) /* 0.271047409 */, 10 },
102 /* 69 */ { MAD_F(0x046c083e) /* 0.276375048 */, 10 }, 102 /* 69 */ { MAD_F(0x046c083e) /* 0.276375048 */, 10 },
103 /* 70 */ { MAD_F(0x0481f5bb) /* 0.281728487 */, 10 }, 103 /* 70 */ { MAD_F(0x0481f5bb) /* 0.281728487 */, 10 },
104 /* 71 */ { MAD_F(0x0497fe03) /* 0.287107481 */, 10 }, 104 /* 71 */ { MAD_F(0x0497fe03) /* 0.287107481 */, 10 },
105 /* 72 */ { MAD_F(0x04ae20d7) /* 0.292511788 */, 10 }, 105 /* 72 */ { MAD_F(0x04ae20d7) /* 0.292511788 */, 10 },
106 /* 73 */ { MAD_F(0x04c45df6) /* 0.297941173 */, 10 }, 106 /* 73 */ { MAD_F(0x04c45df6) /* 0.297941173 */, 10 },
107 /* 74 */ { MAD_F(0x04dab524) /* 0.303395408 */, 10 }, 107 /* 74 */ { MAD_F(0x04dab524) /* 0.303395408 */, 10 },
108 /* 75 */ { MAD_F(0x04f12624) /* 0.308874267 */, 10 }, 108 /* 75 */ { MAD_F(0x04f12624) /* 0.308874267 */, 10 },
109 /* 76 */ { MAD_F(0x0507b0bc) /* 0.314377532 */, 10 }, 109 /* 76 */ { MAD_F(0x0507b0bc) /* 0.314377532 */, 10 },
110 /* 77 */ { MAD_F(0x051e54b1) /* 0.319904987 */, 10 }, 110 /* 77 */ { MAD_F(0x051e54b1) /* 0.319904987 */, 10 },
111 /* 78 */ { MAD_F(0x053511cb) /* 0.325456423 */, 10 }, 111 /* 78 */ { MAD_F(0x053511cb) /* 0.325456423 */, 10 },
112 /* 79 */ { MAD_F(0x054be7d4) /* 0.331031635 */, 10 }, 112 /* 79 */ { MAD_F(0x054be7d4) /* 0.331031635 */, 10 },
113 113
114 /* 80 */ { MAD_F(0x0562d694) /* 0.336630420 */, 10 }, 114 /* 80 */ { MAD_F(0x0562d694) /* 0.336630420 */, 10 },
115 /* 81 */ { MAD_F(0x0579ddd8) /* 0.342252584 */, 10 }, 115 /* 81 */ { MAD_F(0x0579ddd8) /* 0.342252584 */, 10 },
116 /* 82 */ { MAD_F(0x0590fd6c) /* 0.347897931 */, 10 }, 116 /* 82 */ { MAD_F(0x0590fd6c) /* 0.347897931 */, 10 },
117 /* 83 */ { MAD_F(0x05a8351c) /* 0.353566275 */, 10 }, 117 /* 83 */ { MAD_F(0x05a8351c) /* 0.353566275 */, 10 },
118 /* 84 */ { MAD_F(0x05bf84b8) /* 0.359257429 */, 10 }, 118 /* 84 */ { MAD_F(0x05bf84b8) /* 0.359257429 */, 10 },
119 /* 85 */ { MAD_F(0x05d6ec0e) /* 0.364971213 */, 10 }, 119 /* 85 */ { MAD_F(0x05d6ec0e) /* 0.364971213 */, 10 },
120 /* 86 */ { MAD_F(0x05ee6aef) /* 0.370707448 */, 10 }, 120 /* 86 */ { MAD_F(0x05ee6aef) /* 0.370707448 */, 10 },
121 /* 87 */ { MAD_F(0x0606012b) /* 0.376465960 */, 10 }, 121 /* 87 */ { MAD_F(0x0606012b) /* 0.376465960 */, 10 },
122 /* 88 */ { MAD_F(0x061dae96) /* 0.382246578 */, 10 }, 122 /* 88 */ { MAD_F(0x061dae96) /* 0.382246578 */, 10 },
123 /* 89 */ { MAD_F(0x06357302) /* 0.388049134 */, 10 }, 123 /* 89 */ { MAD_F(0x06357302) /* 0.388049134 */, 10 },
124 /* 90 */ { MAD_F(0x064d4e43) /* 0.393873464 */, 10 }, 124 /* 90 */ { MAD_F(0x064d4e43) /* 0.393873464 */, 10 },
125 /* 91 */ { MAD_F(0x0665402d) /* 0.399719406 */, 10 }, 125 /* 91 */ { MAD_F(0x0665402d) /* 0.399719406 */, 10 },
126 /* 92 */ { MAD_F(0x067d4896) /* 0.405586801 */, 10 }, 126 /* 92 */ { MAD_F(0x067d4896) /* 0.405586801 */, 10 },
127 /* 93 */ { MAD_F(0x06956753) /* 0.411475493 */, 10 }, 127 /* 93 */ { MAD_F(0x06956753) /* 0.411475493 */, 10 },
128 /* 94 */ { MAD_F(0x06ad9c3d) /* 0.417385331 */, 10 }, 128 /* 94 */ { MAD_F(0x06ad9c3d) /* 0.417385331 */, 10 },
129 /* 95 */ { MAD_F(0x06c5e72b) /* 0.423316162 */, 10 }, 129 /* 95 */ { MAD_F(0x06c5e72b) /* 0.423316162 */, 10 },
130 130
131 /* 96 */ { MAD_F(0x06de47f4) /* 0.429267841 */, 10 }, 131 /* 96 */ { MAD_F(0x06de47f4) /* 0.429267841 */, 10 },
132 /* 97 */ { MAD_F(0x06f6be73) /* 0.435240221 */, 10 }, 132 /* 97 */ { MAD_F(0x06f6be73) /* 0.435240221 */, 10 },
133 /* 98 */ { MAD_F(0x070f4a80) /* 0.441233161 */, 10 }, 133 /* 98 */ { MAD_F(0x070f4a80) /* 0.441233161 */, 10 },
134 /* 99 */ { MAD_F(0x0727ebf7) /* 0.447246519 */, 10 }, 134 /* 99 */ { MAD_F(0x0727ebf7) /* 0.447246519 */, 10 },
135 /* 100 */ { MAD_F(0x0740a2b2) /* 0.453280160 */, 10 }, 135 /* 100 */ { MAD_F(0x0740a2b2) /* 0.453280160 */, 10 },
136 /* 101 */ { MAD_F(0x07596e8d) /* 0.459333946 */, 10 }, 136 /* 101 */ { MAD_F(0x07596e8d) /* 0.459333946 */, 10 },
137 /* 102 */ { MAD_F(0x07724f64) /* 0.465407744 */, 10 }, 137 /* 102 */ { MAD_F(0x07724f64) /* 0.465407744 */, 10 },
138 /* 103 */ { MAD_F(0x078b4514) /* 0.471501425 */, 10 }, 138 /* 103 */ { MAD_F(0x078b4514) /* 0.471501425 */, 10 },
139 /* 104 */ { MAD_F(0x07a44f7a) /* 0.477614858 */, 10 }, 139 /* 104 */ { MAD_F(0x07a44f7a) /* 0.477614858 */, 10 },
140 /* 105 */ { MAD_F(0x07bd6e75) /* 0.483747918 */, 10 }, 140 /* 105 */ { MAD_F(0x07bd6e75) /* 0.483747918 */, 10 },
141 /* 106 */ { MAD_F(0x07d6a1e2) /* 0.489900479 */, 10 }, 141 /* 106 */ { MAD_F(0x07d6a1e2) /* 0.489900479 */, 10 },
142 /* 107 */ { MAD_F(0x07efe9a1) /* 0.496072418 */, 10 }, 142 /* 107 */ { MAD_F(0x07efe9a1) /* 0.496072418 */, 10 },
143 /* 108 */ { MAD_F(0x0404a2c9) /* 0.251131807 */, 11 }, 143 /* 108 */ { MAD_F(0x0404a2c9) /* 0.251131807 */, 11 },
144 /* 109 */ { MAD_F(0x04115aca) /* 0.254236974 */, 11 }, 144 /* 109 */ { MAD_F(0x04115aca) /* 0.254236974 */, 11 },
145 /* 110 */ { MAD_F(0x041e1cc4) /* 0.257351652 */, 11 }, 145 /* 110 */ { MAD_F(0x041e1cc4) /* 0.257351652 */, 11 },
146 /* 111 */ { MAD_F(0x042ae8a7) /* 0.260475783 */, 11 }, 146 /* 111 */ { MAD_F(0x042ae8a7) /* 0.260475783 */, 11 },
147 147
148 /* 112 */ { MAD_F(0x0437be65) /* 0.263609310 */, 11 }, 148 /* 112 */ { MAD_F(0x0437be65) /* 0.263609310 */, 11 },
149 /* 113 */ { MAD_F(0x04449dee) /* 0.266752177 */, 11 }, 149 /* 113 */ { MAD_F(0x04449dee) /* 0.266752177 */, 11 },
150 /* 114 */ { MAD_F(0x04518733) /* 0.269904329 */, 11 }, 150 /* 114 */ { MAD_F(0x04518733) /* 0.269904329 */, 11 },
151 /* 115 */ { MAD_F(0x045e7a26) /* 0.273065710 */, 11 }, 151 /* 115 */ { MAD_F(0x045e7a26) /* 0.273065710 */, 11 },
152 /* 116 */ { MAD_F(0x046b76b9) /* 0.276236269 */, 11 }, 152 /* 116 */ { MAD_F(0x046b76b9) /* 0.276236269 */, 11 },
153 /* 117 */ { MAD_F(0x04787cdc) /* 0.279415952 */, 11 }, 153 /* 117 */ { MAD_F(0x04787cdc) /* 0.279415952 */, 11 },
154 /* 118 */ { MAD_F(0x04858c83) /* 0.282604707 */, 11 }, 154 /* 118 */ { MAD_F(0x04858c83) /* 0.282604707 */, 11 },
155 /* 119 */ { MAD_F(0x0492a59f) /* 0.285802482 */, 11 }, 155 /* 119 */ { MAD_F(0x0492a59f) /* 0.285802482 */, 11 },
156 /* 120 */ { MAD_F(0x049fc824) /* 0.289009227 */, 11 }, 156 /* 120 */ { MAD_F(0x049fc824) /* 0.289009227 */, 11 },
157 /* 121 */ { MAD_F(0x04acf402) /* 0.292224893 */, 11 }, 157 /* 121 */ { MAD_F(0x04acf402) /* 0.292224893 */, 11 },
158 /* 122 */ { MAD_F(0x04ba292e) /* 0.295449429 */, 11 }, 158 /* 122 */ { MAD_F(0x04ba292e) /* 0.295449429 */, 11 },
159 /* 123 */ { MAD_F(0x04c7679a) /* 0.298682788 */, 11 }, 159 /* 123 */ { MAD_F(0x04c7679a) /* 0.298682788 */, 11 },
160 /* 124 */ { MAD_F(0x04d4af3a) /* 0.301924921 */, 11 }, 160 /* 124 */ { MAD_F(0x04d4af3a) /* 0.301924921 */, 11 },
161 /* 125 */ { MAD_F(0x04e20000) /* 0.305175781 */, 11 }, 161 /* 125 */ { MAD_F(0x04e20000) /* 0.305175781 */, 11 },
162 /* 126 */ { MAD_F(0x04ef59e0) /* 0.308435322 */, 11 }, 162 /* 126 */ { MAD_F(0x04ef59e0) /* 0.308435322 */, 11 },
163 /* 127 */ { MAD_F(0x04fcbcce) /* 0.311703498 */, 11 }, 163 /* 127 */ { MAD_F(0x04fcbcce) /* 0.311703498 */, 11 },
164 164
165 /* 128 */ { MAD_F(0x050a28be) /* 0.314980262 */, 11 }, 165 /* 128 */ { MAD_F(0x050a28be) /* 0.314980262 */, 11 },
166 /* 129 */ { MAD_F(0x05179da4) /* 0.318265572 */, 11 }, 166 /* 129 */ { MAD_F(0x05179da4) /* 0.318265572 */, 11 },
167 /* 130 */ { MAD_F(0x05251b73) /* 0.321559381 */, 11 }, 167 /* 130 */ { MAD_F(0x05251b73) /* 0.321559381 */, 11 },
168 /* 131 */ { MAD_F(0x0532a220) /* 0.324861647 */, 11 }, 168 /* 131 */ { MAD_F(0x0532a220) /* 0.324861647 */, 11 },
169 /* 132 */ { MAD_F(0x054031a0) /* 0.328172327 */, 11 }, 169 /* 132 */ { MAD_F(0x054031a0) /* 0.328172327 */, 11 },
170 /* 133 */ { MAD_F(0x054dc9e7) /* 0.331491377 */, 11 }, 170 /* 133 */ { MAD_F(0x054dc9e7) /* 0.331491377 */, 11 },
171 /* 134 */ { MAD_F(0x055b6ae9) /* 0.334818756 */, 11 }, 171 /* 134 */ { MAD_F(0x055b6ae9) /* 0.334818756 */, 11 },
172 /* 135 */ { MAD_F(0x0569149c) /* 0.338154423 */, 11 }, 172 /* 135 */ { MAD_F(0x0569149c) /* 0.338154423 */, 11 },
173 /* 136 */ { MAD_F(0x0576c6f5) /* 0.341498336 */, 11 }, 173 /* 136 */ { MAD_F(0x0576c6f5) /* 0.341498336 */, 11 },
174 /* 137 */ { MAD_F(0x058481e9) /* 0.344850455 */, 11 }, 174 /* 137 */ { MAD_F(0x058481e9) /* 0.344850455 */, 11 },
175 /* 138 */ { MAD_F(0x0592456d) /* 0.348210741 */, 11 }, 175 /* 138 */ { MAD_F(0x0592456d) /* 0.348210741 */, 11 },
176 /* 139 */ { MAD_F(0x05a01176) /* 0.351579152 */, 11 }, 176 /* 139 */ { MAD_F(0x05a01176) /* 0.351579152 */, 11 },
177 /* 140 */ { MAD_F(0x05ade5fa) /* 0.354955651 */, 11 }, 177 /* 140 */ { MAD_F(0x05ade5fa) /* 0.354955651 */, 11 },
178 /* 141 */ { MAD_F(0x05bbc2ef) /* 0.358340200 */, 11 }, 178 /* 141 */ { MAD_F(0x05bbc2ef) /* 0.358340200 */, 11 },
179 /* 142 */ { MAD_F(0x05c9a84a) /* 0.361732758 */, 11 }, 179 /* 142 */ { MAD_F(0x05c9a84a) /* 0.361732758 */, 11 },
180 /* 143 */ { MAD_F(0x05d79601) /* 0.365133291 */, 11 }, 180 /* 143 */ { MAD_F(0x05d79601) /* 0.365133291 */, 11 },
181 181
182 /* 144 */ { MAD_F(0x05e58c0b) /* 0.368541759 */, 11 }, 182 /* 144 */ { MAD_F(0x05e58c0b) /* 0.368541759 */, 11 },
183 /* 145 */ { MAD_F(0x05f38a5d) /* 0.371958126 */, 11 }, 183 /* 145 */ { MAD_F(0x05f38a5d) /* 0.371958126 */, 11 },
184 /* 146 */ { MAD_F(0x060190ee) /* 0.375382356 */, 11 }, 184 /* 146 */ { MAD_F(0x060190ee) /* 0.375382356 */, 11 },
185 /* 147 */ { MAD_F(0x060f9fb3) /* 0.378814413 */, 11 }, 185 /* 147 */ { MAD_F(0x060f9fb3) /* 0.378814413 */, 11 },
186 /* 148 */ { MAD_F(0x061db6a5) /* 0.382254261 */, 11 }, 186 /* 148 */ { MAD_F(0x061db6a5) /* 0.382254261 */, 11 },
187 /* 149 */ { MAD_F(0x062bd5b8) /* 0.385701865 */, 11 }, 187 /* 149 */ { MAD_F(0x062bd5b8) /* 0.385701865 */, 11 },
188 /* 150 */ { MAD_F(0x0639fce4) /* 0.389157191 */, 11 }, 188 /* 150 */ { MAD_F(0x0639fce4) /* 0.389157191 */, 11 },
189 /* 151 */ { MAD_F(0x06482c1f) /* 0.392620204 */, 11 }, 189 /* 151 */ { MAD_F(0x06482c1f) /* 0.392620204 */, 11 },
190 /* 152 */ { MAD_F(0x06566361) /* 0.396090870 */, 11 }, 190 /* 152 */ { MAD_F(0x06566361) /* 0.396090870 */, 11 },
191 /* 153 */ { MAD_F(0x0664a2a0) /* 0.399569155 */, 11 }, 191 /* 153 */ { MAD_F(0x0664a2a0) /* 0.399569155 */, 11 },
192 /* 154 */ { MAD_F(0x0672e9d4) /* 0.403055027 */, 11 }, 192 /* 154 */ { MAD_F(0x0672e9d4) /* 0.403055027 */, 11 },
193 /* 155 */ { MAD_F(0x068138f3) /* 0.406548452 */, 11 }, 193 /* 155 */ { MAD_F(0x068138f3) /* 0.406548452 */, 11 },
194 /* 156 */ { MAD_F(0x068f8ff5) /* 0.410049398 */, 11 }, 194 /* 156 */ { MAD_F(0x068f8ff5) /* 0.410049398 */, 11 },
diff --git a/core/multimedia/opieplayer/libmad/sf_table.dat b/core/multimedia/opieplayer/libmad/sf_table.dat
index 18e6202..bc368af 100644
--- a/core/multimedia/opieplayer/libmad/sf_table.dat
+++ b/core/multimedia/opieplayer/libmad/sf_table.dat
@@ -1,100 +1,100 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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/* 22/*
23 * These are the scalefactor values for Layer I and Layer II. 23 * These are the scalefactor values for Layer I and Layer II.
24 * The values are from Table B.1 of ISO/IEC 11172-3. 24 * The values are from Table B.1 of ISO/IEC 11172-3.
25 * 25 *
26 * There is some error introduced by the 32-bit fixed-point representation; 26 * There is some error introduced by the 32-bit fixed-point representation;
27 * the amount of error is shown. For 16-bit PCM output, this shouldn't be 27 * the amount of error is shown. For 16-bit PCM output, this shouldn't be
28 * too much of a problem. 28 * too much of a problem.
29 */ 29 */
30 30
31 MAD_F(0x20000000), /* 2.000000000000 => 2.000000000000, e 0.000000000000 */ 31 MAD_F(0x20000000), /* 2.000000000000 => 2.000000000000, e 0.000000000000 */
32 MAD_F(0x1965fea5), /* 1.587401051968 => 1.587401051074, e 0.000000000894 */ 32 MAD_F(0x1965fea5), /* 1.587401051968 => 1.587401051074, e 0.000000000894 */
33 MAD_F(0x1428a2fa), /* 1.259921049895 => 1.259921051562, e -0.000000001667 */ 33 MAD_F(0x1428a2fa), /* 1.259921049895 => 1.259921051562, e -0.000000001667 */
34 MAD_F(0x10000000), /* 1.000000000000 => 1.000000000000, e 0.000000000000 */ 34 MAD_F(0x10000000), /* 1.000000000000 => 1.000000000000, e 0.000000000000 */
35 MAD_F(0x0cb2ff53), /* 0.793700525984 => 0.793700527400, e -0.000000001416 */ 35 MAD_F(0x0cb2ff53), /* 0.793700525984 => 0.793700527400, e -0.000000001416 */
36 MAD_F(0x0a14517d), /* 0.629960524947 => 0.629960525781, e -0.000000000833 */ 36 MAD_F(0x0a14517d), /* 0.629960524947 => 0.629960525781, e -0.000000000833 */
37 MAD_F(0x08000000), /* 0.500000000000 => 0.500000000000, e 0.000000000000 */ 37 MAD_F(0x08000000), /* 0.500000000000 => 0.500000000000, e 0.000000000000 */
38 MAD_F(0x06597fa9), /* 0.396850262992 => 0.396850261837, e 0.000000001155 */ 38 MAD_F(0x06597fa9), /* 0.396850262992 => 0.396850261837, e 0.000000001155 */
39 39
40 MAD_F(0x050a28be), /* 0.314980262474 => 0.314980261028, e 0.000000001446 */ 40 MAD_F(0x050a28be), /* 0.314980262474 => 0.314980261028, e 0.000000001446 */
41 MAD_F(0x04000000), /* 0.250000000000 => 0.250000000000, e 0.000000000000 */ 41 MAD_F(0x04000000), /* 0.250000000000 => 0.250000000000, e 0.000000000000 */
42 MAD_F(0x032cbfd5), /* 0.198425131496 => 0.198425132781, e -0.000000001285 */ 42 MAD_F(0x032cbfd5), /* 0.198425131496 => 0.198425132781, e -0.000000001285 */
43 MAD_F(0x0285145f), /* 0.157490131237 => 0.157490130514, e 0.000000000723 */ 43 MAD_F(0x0285145f), /* 0.157490131237 => 0.157490130514, e 0.000000000723 */
44 MAD_F(0x02000000), /* 0.125000000000 => 0.125000000000, e 0.000000000000 */ 44 MAD_F(0x02000000), /* 0.125000000000 => 0.125000000000, e 0.000000000000 */
45 MAD_F(0x01965fea), /* 0.099212565748 => 0.099212564528, e 0.000000001220 */ 45 MAD_F(0x01965fea), /* 0.099212565748 => 0.099212564528, e 0.000000001220 */
46 MAD_F(0x01428a30), /* 0.078745065618 => 0.078745067120, e -0.000000001501 */ 46 MAD_F(0x01428a30), /* 0.078745065618 => 0.078745067120, e -0.000000001501 */
47 MAD_F(0x01000000), /* 0.062500000000 => 0.062500000000, e 0.000000000000 */ 47 MAD_F(0x01000000), /* 0.062500000000 => 0.062500000000, e 0.000000000000 */
48 48
49 MAD_F(0x00cb2ff5), /* 0.049606282874 => 0.049606282264, e 0.000000000610 */ 49 MAD_F(0x00cb2ff5), /* 0.049606282874 => 0.049606282264, e 0.000000000610 */
50 MAD_F(0x00a14518), /* 0.039372532809 => 0.039372533560, e -0.000000000751 */ 50 MAD_F(0x00a14518), /* 0.039372532809 => 0.039372533560, e -0.000000000751 */
51 MAD_F(0x00800000), /* 0.031250000000 => 0.031250000000, e 0.000000000000 */ 51 MAD_F(0x00800000), /* 0.031250000000 => 0.031250000000, e 0.000000000000 */
52 MAD_F(0x006597fb), /* 0.024803141437 => 0.024803142995, e -0.000000001558 */ 52 MAD_F(0x006597fb), /* 0.024803141437 => 0.024803142995, e -0.000000001558 */
53 MAD_F(0x0050a28c), /* 0.019686266405 => 0.019686266780, e -0.000000000375 */ 53 MAD_F(0x0050a28c), /* 0.019686266405 => 0.019686266780, e -0.000000000375 */
54 MAD_F(0x00400000), /* 0.015625000000 => 0.015625000000, e 0.000000000000 */ 54 MAD_F(0x00400000), /* 0.015625000000 => 0.015625000000, e 0.000000000000 */
55 MAD_F(0x0032cbfd), /* 0.012401570719 => 0.012401569635, e 0.000000001084 */ 55 MAD_F(0x0032cbfd), /* 0.012401570719 => 0.012401569635, e 0.000000001084 */
56 MAD_F(0x00285146), /* 0.009843133202 => 0.009843133390, e -0.000000000188 */ 56 MAD_F(0x00285146), /* 0.009843133202 => 0.009843133390, e -0.000000000188 */
57 57
58 MAD_F(0x00200000), /* 0.007812500000 => 0.007812500000, e 0.000000000000 */ 58 MAD_F(0x00200000), /* 0.007812500000 => 0.007812500000, e 0.000000000000 */
59 MAD_F(0x001965ff), /* 0.006200785359 => 0.006200786680, e -0.000000001321 */ 59 MAD_F(0x001965ff), /* 0.006200785359 => 0.006200786680, e -0.000000001321 */
60 MAD_F(0x001428a3), /* 0.004921566601 => 0.004921566695, e -0.000000000094 */ 60 MAD_F(0x001428a3), /* 0.004921566601 => 0.004921566695, e -0.000000000094 */
61 MAD_F(0x00100000), /* 0.003906250000 => 0.003906250000, e 0.000000000000 */ 61 MAD_F(0x00100000), /* 0.003906250000 => 0.003906250000, e 0.000000000000 */
62 MAD_F(0x000cb2ff), /* 0.003100392680 => 0.003100391477, e 0.000000001202 */ 62 MAD_F(0x000cb2ff), /* 0.003100392680 => 0.003100391477, e 0.000000001202 */
63 MAD_F(0x000a1451), /* 0.002460783301 => 0.002460781485, e 0.000000001816 */ 63 MAD_F(0x000a1451), /* 0.002460783301 => 0.002460781485, e 0.000000001816 */
64 MAD_F(0x00080000), /* 0.001953125000 => 0.001953125000, e 0.000000000000 */ 64 MAD_F(0x00080000), /* 0.001953125000 => 0.001953125000, e 0.000000000000 */
65 MAD_F(0x00065980), /* 0.001550196340 => 0.001550197601, e -0.000000001262 */ 65 MAD_F(0x00065980), /* 0.001550196340 => 0.001550197601, e -0.000000001262 */
66 66
67 MAD_F(0x00050a29), /* 0.001230391650 => 0.001230392605, e -0.000000000955 */ 67 MAD_F(0x00050a29), /* 0.001230391650 => 0.001230392605, e -0.000000000955 */
68 MAD_F(0x00040000), /* 0.000976562500 => 0.000976562500, e 0.000000000000 */ 68 MAD_F(0x00040000), /* 0.000976562500 => 0.000976562500, e 0.000000000000 */
69 MAD_F(0x00032cc0), /* 0.000775098170 => 0.000775098801, e -0.000000000631 */ 69 MAD_F(0x00032cc0), /* 0.000775098170 => 0.000775098801, e -0.000000000631 */
70 MAD_F(0x00028514), /* 0.000615195825 => 0.000615194440, e 0.000000001385 */ 70 MAD_F(0x00028514), /* 0.000615195825 => 0.000615194440, e 0.000000001385 */
71 MAD_F(0x00020000), /* 0.000488281250 => 0.000488281250, e 0.000000000000 */ 71 MAD_F(0x00020000), /* 0.000488281250 => 0.000488281250, e 0.000000000000 */
72 MAD_F(0x00019660), /* 0.000387549085 => 0.000387549400, e -0.000000000315 */ 72 MAD_F(0x00019660), /* 0.000387549085 => 0.000387549400, e -0.000000000315 */
73 MAD_F(0x0001428a), /* 0.000307597913 => 0.000307597220, e 0.000000000693 */ 73 MAD_F(0x0001428a), /* 0.000307597913 => 0.000307597220, e 0.000000000693 */
74 MAD_F(0x00010000), /* 0.000244140625 => 0.000244140625, e 0.000000000000 */ 74 MAD_F(0x00010000), /* 0.000244140625 => 0.000244140625, e 0.000000000000 */
75 75
76 MAD_F(0x0000cb30), /* 0.000193774542 => 0.000193774700, e -0.000000000158 */ 76 MAD_F(0x0000cb30), /* 0.000193774542 => 0.000193774700, e -0.000000000158 */
77 MAD_F(0x0000a145), /* 0.000153798956 => 0.000153798610, e 0.000000000346 */ 77 MAD_F(0x0000a145), /* 0.000153798956 => 0.000153798610, e 0.000000000346 */
78 MAD_F(0x00008000), /* 0.000122070313 => 0.000122070313, e 0.000000000000 */ 78 MAD_F(0x00008000), /* 0.000122070313 => 0.000122070313, e 0.000000000000 */
79 MAD_F(0x00006598), /* 0.000096887271 => 0.000096887350, e -0.000000000079 */ 79 MAD_F(0x00006598), /* 0.000096887271 => 0.000096887350, e -0.000000000079 */
80 MAD_F(0x000050a3), /* 0.000076899478 => 0.000076901168, e -0.000000001689 */ 80 MAD_F(0x000050a3), /* 0.000076899478 => 0.000076901168, e -0.000000001689 */
81 MAD_F(0x00004000), /* 0.000061035156 => 0.000061035156, e 0.000000000000 */ 81 MAD_F(0x00004000), /* 0.000061035156 => 0.000061035156, e 0.000000000000 */
82 MAD_F(0x000032cc), /* 0.000048443636 => 0.000048443675, e -0.000000000039 */ 82 MAD_F(0x000032cc), /* 0.000048443636 => 0.000048443675, e -0.000000000039 */
83 MAD_F(0x00002851), /* 0.000038449739 => 0.000038448721, e 0.000000001018 */ 83 MAD_F(0x00002851), /* 0.000038449739 => 0.000038448721, e 0.000000001018 */
84 84
85 MAD_F(0x00002000), /* 0.000030517578 => 0.000030517578, e 0.000000000000 */ 85 MAD_F(0x00002000), /* 0.000030517578 => 0.000030517578, e 0.000000000000 */
86 MAD_F(0x00001966), /* 0.000024221818 => 0.000024221838, e -0.000000000020 */ 86 MAD_F(0x00001966), /* 0.000024221818 => 0.000024221838, e -0.000000000020 */
87 MAD_F(0x00001429), /* 0.000019224870 => 0.000019226223, e -0.000000001354 */ 87 MAD_F(0x00001429), /* 0.000019224870 => 0.000019226223, e -0.000000001354 */
88 MAD_F(0x00001000), /* 0.000015258789 => 0.000015258789, e -0.000000000000 */ 88 MAD_F(0x00001000), /* 0.000015258789 => 0.000015258789, e -0.000000000000 */
89 MAD_F(0x00000cb3), /* 0.000012110909 => 0.000012110919, e -0.000000000010 */ 89 MAD_F(0x00000cb3), /* 0.000012110909 => 0.000012110919, e -0.000000000010 */
90 MAD_F(0x00000a14), /* 0.000009612435 => 0.000009611249, e 0.000000001186 */ 90 MAD_F(0x00000a14), /* 0.000009612435 => 0.000009611249, e 0.000000001186 */
91 MAD_F(0x00000800), /* 0.000007629395 => 0.000007629395, e -0.000000000000 */ 91 MAD_F(0x00000800), /* 0.000007629395 => 0.000007629395, e -0.000000000000 */
92 MAD_F(0x00000659), /* 0.000006055454 => 0.000006053597, e 0.000000001858 */ 92 MAD_F(0x00000659), /* 0.000006055454 => 0.000006053597, e 0.000000001858 */
93 93
94 MAD_F(0x0000050a), /* 0.000004806217 => 0.000004805624, e 0.000000000593 */ 94 MAD_F(0x0000050a), /* 0.000004806217 => 0.000004805624, e 0.000000000593 */
95 MAD_F(0x00000400), /* 0.000003814697 => 0.000003814697, e 0.000000000000 */ 95 MAD_F(0x00000400), /* 0.000003814697 => 0.000003814697, e 0.000000000000 */
96 MAD_F(0x0000032d), /* 0.000003027727 => 0.000003028661, e -0.000000000934 */ 96 MAD_F(0x0000032d), /* 0.000003027727 => 0.000003028661, e -0.000000000934 */
97 MAD_F(0x00000285), /* 0.000002403109 => 0.000002402812, e 0.000000000296 */ 97 MAD_F(0x00000285), /* 0.000002403109 => 0.000002402812, e 0.000000000296 */
98 MAD_F(0x00000200), /* 0.000001907349 => 0.000001907349, e -0.000000000000 */ 98 MAD_F(0x00000200), /* 0.000001907349 => 0.000001907349, e -0.000000000000 */
99 MAD_F(0x00000196), /* 0.000001513864 => 0.000001512468, e 0.000000001396 */ 99 MAD_F(0x00000196), /* 0.000001513864 => 0.000001512468, e 0.000000001396 */
100 MAD_F(0x00000143) /* 0.000001201554 => 0.000001203269, e -0.000000001714 */ 100 MAD_F(0x00000143) /* 0.000001201554 => 0.000001203269, e -0.000000001714 */
diff --git a/core/multimedia/opieplayer/libmad/stream.c b/core/multimedia/opieplayer/libmad/stream.c
index dea7b8e..4374de7 100644
--- a/core/multimedia/opieplayer/libmad/stream.c
+++ b/core/multimedia/opieplayer/libmad/stream.c
@@ -1,123 +1,160 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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
28# include <stdlib.h> 28# include <stdlib.h>
29 29
30# include "bit.h" 30# include "bit.h"
31# include "stream.h" 31# include "stream.h"
32 32
33/* 33/*
34 * NAME:stream->init() 34 * NAME:stream->init()
35 * DESCRIPTION:initialize stream struct 35 * DESCRIPTION:initialize stream struct
36 */ 36 */
37void mad_stream_init(struct mad_stream *stream) 37void mad_stream_init(struct mad_stream *stream)
38{ 38{
39 stream->buffer = 0; 39 stream->buffer = 0;
40 stream->bufend = 0; 40 stream->bufend = 0;
41 stream->skiplen = 0; 41 stream->skiplen = 0;
42 42
43 stream->sync = 0; 43 stream->sync = 0;
44 stream->freerate = 0; 44 stream->freerate = 0;
45 45
46 stream->this_frame = 0; 46 stream->this_frame = 0;
47 stream->next_frame = 0; 47 stream->next_frame = 0;
48 mad_bit_init(&stream->ptr, 0); 48 mad_bit_init(&stream->ptr, 0);
49 49
50 mad_bit_init(&stream->anc_ptr, 0); 50 mad_bit_init(&stream->anc_ptr, 0);
51 stream->anc_bitlen = 0; 51 stream->anc_bitlen = 0;
52 52
53 stream->main_data = 0; 53 stream->main_data = 0;
54 stream->md_len = 0; 54 stream->md_len = 0;
55 55
56 stream->options = 0; 56 stream->options = 0;
57 stream->error = 0; 57 stream->error = MAD_ERROR_NONE;
58} 58}
59 59
60/* 60/*
61 * NAME:stream->finish() 61 * NAME:stream->finish()
62 * DESCRIPTION:deallocate any dynamic memory associated with stream 62 * DESCRIPTION:deallocate any dynamic memory associated with stream
63 */ 63 */
64void mad_stream_finish(struct mad_stream *stream) 64void mad_stream_finish(struct mad_stream *stream)
65{ 65{
66 if (stream->main_data) { 66 if (stream->main_data) {
67 free(stream->main_data); 67 free(stream->main_data);
68 stream->main_data = 0; 68 stream->main_data = 0;
69 } 69 }
70 70
71 mad_bit_finish(&stream->anc_ptr); 71 mad_bit_finish(&stream->anc_ptr);
72 mad_bit_finish(&stream->ptr); 72 mad_bit_finish(&stream->ptr);
73} 73}
74 74
75/* 75/*
76 * NAME:stream->buffer() 76 * NAME:stream->buffer()
77 * DESCRIPTION:set stream buffer pointers 77 * DESCRIPTION:set stream buffer pointers
78 */ 78 */
79void mad_stream_buffer(struct mad_stream *stream, 79void mad_stream_buffer(struct mad_stream *stream,
80 unsigned char const *buffer, unsigned long length) 80 unsigned char const *buffer, unsigned long length)
81{ 81{
82 stream->buffer = buffer; 82 stream->buffer = buffer;
83 stream->bufend = buffer + length; 83 stream->bufend = buffer + length;
84 84
85 stream->this_frame = buffer; 85 stream->this_frame = buffer;
86 stream->next_frame = buffer; 86 stream->next_frame = buffer;
87 87
88 stream->sync = 1; 88 stream->sync = 1;
89 89
90 mad_bit_init(&stream->ptr, buffer); 90 mad_bit_init(&stream->ptr, buffer);
91} 91}
92 92
93/* 93/*
94 * NAME:stream->skip() 94 * NAME:stream->skip()
95 * DESCRIPTION:arrange to skip bytes before the next frame 95 * DESCRIPTION:arrange to skip bytes before the next frame
96 */ 96 */
97void mad_stream_skip(struct mad_stream *stream, unsigned long length) 97void mad_stream_skip(struct mad_stream *stream, unsigned long length)
98{ 98{
99 stream->skiplen += length; 99 stream->skiplen += length;
100} 100}
101 101
102/* 102/*
103 * NAME:stream->sync() 103 * NAME:stream->sync()
104 * DESCRIPTION:locate the next stream sync word 104 * DESCRIPTION:locate the next stream sync word
105 */ 105 */
106int mad_stream_sync(struct mad_stream *stream) 106int mad_stream_sync(struct mad_stream *stream)
107{ 107{
108 register unsigned char const *ptr, *end; 108 register unsigned char const *ptr, *end;
109 109
110 ptr = mad_bit_nextbyte(&stream->ptr); 110 ptr = mad_bit_nextbyte(&stream->ptr);
111 end = stream->bufend; 111 end = stream->bufend;
112 112
113 while (ptr < end - 1 && 113 while (ptr < end - 1 &&
114 !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0)) 114 !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0))
115 ++ptr; 115 ++ptr;
116 116
117 if (end - ptr < MAD_BUFFER_GUARD) 117 if (end - ptr < MAD_BUFFER_GUARD)
118 return -1; 118 return -1;
119 119
120 mad_bit_init(&stream->ptr, ptr); 120 mad_bit_init(&stream->ptr, ptr);
121 121
122 return 0; 122 return 0;
123} 123}
124
125/*
126 * NAME:stream->errorstr()
127 * DESCRIPTION:return a string description of the current error condition
128 */
129char const *mad_stream_errorstr(struct mad_stream const *stream)
130{
131 switch (stream->error) {
132 case MAD_ERROR_NONE: return "no error";
133
134 case MAD_ERROR_BUFLEN: return "input buffer too small (or EOF)";
135 case MAD_ERROR_BUFPTR: return "invalid (null) buffer pointer";
136
137 case MAD_ERROR_NOMEM: return "not enough memory";
138
139 case MAD_ERROR_LOSTSYNC: return "lost synchronization";
140 case MAD_ERROR_BADLAYER: return "reserved header layer value";
141 case MAD_ERROR_BADBITRATE: return "forbidden bitrate value";
142 case MAD_ERROR_BADSAMPLERATE: return "reserved sample frequency value";
143 case MAD_ERROR_BADEMPHASIS: return "reserved emphasis value";
144
145 case MAD_ERROR_BADCRC: return "CRC check failed";
146 case MAD_ERROR_BADBITALLOC: return "forbidden bit allocation value";
147 case MAD_ERROR_BADSCALEFACTOR: return "bad scalefactor index";
148 case MAD_ERROR_BADFRAMELEN: return "bad frame length";
149 case MAD_ERROR_BADBIGVALUES: return "bad big_values count";
150 case MAD_ERROR_BADBLOCKTYPE: return "reserved block_type";
151 case MAD_ERROR_BADSCFSI: return "bad scalefactor selection info";
152 case MAD_ERROR_BADDATAPTR: return "bad main_data_begin pointer";
153 case MAD_ERROR_BADPART3LEN: return "bad audio data length";
154 case MAD_ERROR_BADHUFFTABLE: return "bad Huffman table select";
155 case MAD_ERROR_BADHUFFDATA: return "Huffman data overrun";
156 case MAD_ERROR_BADSTEREO: return "incompatible block_type for JS";
157 }
158
159 return 0;
160}
diff --git a/core/multimedia/opieplayer/libmad/stream.h b/core/multimedia/opieplayer/libmad/stream.h
index cf3280e..08e6dc5 100644
--- a/core/multimedia/opieplayer/libmad/stream.h
+++ b/core/multimedia/opieplayer/libmad/stream.h
@@ -1,102 +1,107 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# ifndef LIBMAD_STREAM_H 22# ifndef LIBMAD_STREAM_H
23# define LIBMAD_STREAM_H 23# define LIBMAD_STREAM_H
24 24
25# include "bit.h" 25# include "bit.h"
26 26
27 # define MAD_BUFFER_GUARD8 27 # define MAD_BUFFER_GUARD8
28 # define MAD_BUFFER_MDLEN(511 + 2048 + MAD_BUFFER_GUARD) 28 # define MAD_BUFFER_MDLEN(511 + 2048 + MAD_BUFFER_GUARD)
29 29
30enum mad_error { 30enum mad_error {
31 MAD_ERROR_NONE = 0x0000,/* no error */
32
31 MAD_ERROR_BUFLEN = 0x0001,/* input buffer too small (or EOF) */ 33 MAD_ERROR_BUFLEN = 0x0001,/* input buffer too small (or EOF) */
32 MAD_ERROR_BUFPTR = 0x0002,/* invalid (null) buffer pointer */ 34 MAD_ERROR_BUFPTR = 0x0002,/* invalid (null) buffer pointer */
33 35
34 MAD_ERROR_NOMEM = 0x0031,/* not enough memory */ 36 MAD_ERROR_NOMEM = 0x0031,/* not enough memory */
35 37
36 MAD_ERROR_LOSTSYNC = 0x0101,/* lost synchronization */ 38 MAD_ERROR_LOSTSYNC = 0x0101,/* lost synchronization */
37 MAD_ERROR_BADLAYER = 0x0102,/* reserved header layer value */ 39 MAD_ERROR_BADLAYER = 0x0102,/* reserved header layer value */
38 MAD_ERROR_BADBITRATE = 0x0103,/* forbidden bitrate value */ 40 MAD_ERROR_BADBITRATE = 0x0103,/* forbidden bitrate value */
39 MAD_ERROR_BADSAMPLERATE = 0x0104,/* reserved sample frequency value */ 41 MAD_ERROR_BADSAMPLERATE = 0x0104,/* reserved sample frequency value */
40 MAD_ERROR_BADEMPHASIS = 0x0105,/* reserved emphasis value */ 42 MAD_ERROR_BADEMPHASIS = 0x0105,/* reserved emphasis value */
41 43
42 MAD_ERROR_BADCRC = 0x0201,/* CRC check failed */ 44 MAD_ERROR_BADCRC = 0x0201,/* CRC check failed */
43 MAD_ERROR_BADBITALLOC = 0x0211,/* forbidden bit allocation value */ 45 MAD_ERROR_BADBITALLOC = 0x0211,/* forbidden bit allocation value */
44 MAD_ERROR_BADSCALEFACTOR = 0x0221,/* bad scalefactor index */ 46 MAD_ERROR_BADSCALEFACTOR = 0x0221,/* bad scalefactor index */
45 MAD_ERROR_BADFRAMELEN = 0x0231,/* bad frame length */ 47 MAD_ERROR_BADFRAMELEN = 0x0231,/* bad frame length */
46 MAD_ERROR_BADBIGVALUES = 0x0232,/* bad big_values count */ 48 MAD_ERROR_BADBIGVALUES = 0x0232,/* bad big_values count */
47 MAD_ERROR_BADBLOCKTYPE = 0x0233,/* reserved block_type */ 49 MAD_ERROR_BADBLOCKTYPE = 0x0233,/* reserved block_type */
48 MAD_ERROR_BADSCFSI = 0x0234,/* bad scalefactor selection info */ 50 MAD_ERROR_BADSCFSI = 0x0234,/* bad scalefactor selection info */
49 MAD_ERROR_BADDATAPTR = 0x0235,/* bad main_data_begin pointer */ 51 MAD_ERROR_BADDATAPTR = 0x0235,/* bad main_data_begin pointer */
50 MAD_ERROR_BADPART3LEN = 0x0236,/* bad audio data length */ 52 MAD_ERROR_BADPART3LEN = 0x0236,/* bad audio data length */
51 MAD_ERROR_BADHUFFTABLE = 0x0237,/* bad Huffman table select */ 53 MAD_ERROR_BADHUFFTABLE = 0x0237,/* bad Huffman table select */
52 MAD_ERROR_BADHUFFDATA = 0x0238,/* Huffman data overrun */ 54 MAD_ERROR_BADHUFFDATA = 0x0238,/* Huffman data overrun */
53 MAD_ERROR_BADSTEREO = 0x0239/* incompatible block_type for JS */ 55 MAD_ERROR_BADSTEREO = 0x0239/* incompatible block_type for JS */
54}; 56};
55 57
56 # define MAD_RECOVERABLE(error)((error) & 0xff00) 58 # define MAD_RECOVERABLE(error)((error) & 0xff00)
57 59
58struct mad_stream { 60struct mad_stream {
59 unsigned char const *buffer; /* input bitstream buffer */ 61 unsigned char const *buffer; /* input bitstream buffer */
60 unsigned char const *bufend; /* end of buffer */ 62 unsigned char const *bufend; /* end of buffer */
61 unsigned long skiplen; /* bytes to skip before next frame */ 63 unsigned long skiplen; /* bytes to skip before next frame */
62 64
63 int sync; /* stream sync found */ 65 int sync; /* stream sync found */
64 unsigned long freerate; /* free bitrate (fixed) */ 66 unsigned long freerate; /* free bitrate (fixed) */
65 67
66 unsigned char const *this_frame;/* start of current frame */ 68 unsigned char const *this_frame;/* start of current frame */
67 unsigned char const *next_frame;/* start of next frame */ 69 unsigned char const *next_frame;/* start of next frame */
68 struct mad_bitptr ptr; /* current processing bit pointer */ 70 struct mad_bitptr ptr; /* current processing bit pointer */
69 71
70 struct mad_bitptr anc_ptr; /* ancillary bits pointer */ 72 struct mad_bitptr anc_ptr; /* ancillary bits pointer */
71 unsigned int anc_bitlen; /* number of ancillary bits */ 73 unsigned int anc_bitlen; /* number of ancillary bits */
72 74
73 unsigned char (*main_data)[MAD_BUFFER_MDLEN]; 75 unsigned char (*main_data)[MAD_BUFFER_MDLEN];
74 /* Layer III main_data() */ 76 /* Layer III main_data() */
75 unsigned int md_len; /* bytes in main_data */ 77 unsigned int md_len; /* bytes in main_data */
76 78
77 int options; /* decoding options (see below) */ 79 int options; /* decoding options (see below) */
78 enum mad_error error; /* error code (see above) */ 80 enum mad_error error; /* error code (see above) */
79}; 81};
80 82
81enum { 83enum {
82 MAD_OPTION_IGNORECRC = 0x0001,/* ignore CRC errors */ 84 MAD_OPTION_IGNORECRC = 0x0001,/* ignore CRC errors */
83 MAD_OPTION_HALFSAMPLERATE = 0x0002,/* generate PCM at 1/2 sample rate */ 85 MAD_OPTION_HALFSAMPLERATE = 0x0002/* generate PCM at 1/2 sample rate */
84# if 0 /* not yet implemented */ 86# if 0 /* not yet implemented */
85 MAD_OPTION_LEFTCHANNEL = 0x0010,/* decode left channel only */ 87 MAD_OPTION_LEFTCHANNEL = 0x0010,/* decode left channel only */
86 MAD_OPTION_RIGHTCHANNEL = 0x0020,/* decode right channel only */ 88 MAD_OPTION_RIGHTCHANNEL = 0x0020,/* decode right channel only */
87 MAD_OPTION_SINGLECHANNEL = 0x0030,/* combine channels */ 89 MAD_OPTION_SINGLECHANNEL = 0x0030/* combine channels */
88# endif 90# endif
89}; 91};
90 92
91void mad_stream_init(struct mad_stream *); 93void mad_stream_init(struct mad_stream *);
92void mad_stream_finish(struct mad_stream *); 94void mad_stream_finish(struct mad_stream *);
93 95
94# define mad_stream_options(stream, opts) ((stream)->options = (opts)) 96# define mad_stream_options(stream, opts) \
97 ((void) ((stream)->options = (opts)))
95 98
96void mad_stream_buffer(struct mad_stream *, 99void mad_stream_buffer(struct mad_stream *,
97 unsigned char const *, unsigned long); 100 unsigned char const *, unsigned long);
98void mad_stream_skip(struct mad_stream *, unsigned long); 101void mad_stream_skip(struct mad_stream *, unsigned long);
99 102
100int mad_stream_sync(struct mad_stream *); 103int mad_stream_sync(struct mad_stream *);
101 104
105char const *mad_stream_errorstr(struct mad_stream const *);
106
102# endif 107# endif
diff --git a/core/multimedia/opieplayer/libmad/synth.c b/core/multimedia/opieplayer/libmad/synth.c
index e1914c9..cf3c1d5 100644
--- a/core/multimedia/opieplayer/libmad/synth.c
+++ b/core/multimedia/opieplayer/libmad/synth.c
@@ -1,855 +1,857 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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
28# include "fixed.h" 28# include "fixed.h"
29# include "frame.h" 29# include "frame.h"
30# include "synth.h" 30# include "synth.h"
31 31
32/* 32/*
33 * NAME:synth->init() 33 * NAME:synth->init()
34 * DESCRIPTION:initialize synth struct 34 * DESCRIPTION:initialize synth struct
35 */ 35 */
36void mad_synth_init(struct mad_synth *synth) 36void mad_synth_init(struct mad_synth *synth)
37{ 37{
38 mad_synth_mute(synth); 38 mad_synth_mute(synth);
39 39
40 synth->phase = 0; 40 synth->phase = 0;
41 41
42 synth->pcm.samplerate = 0; 42 synth->pcm.samplerate = 0;
43 synth->pcm.channels = 0; 43 synth->pcm.channels = 0;
44 synth->pcm.length = 0; 44 synth->pcm.length = 0;
45} 45}
46 46
47/* 47/*
48 * NAME:synth->mute() 48 * NAME:synth->mute()
49 * DESCRIPTION:zero all polyphase filterbank values, resetting synthesis 49 * DESCRIPTION:zero all polyphase filterbank values, resetting synthesis
50 */ 50 */
51void mad_synth_mute(struct mad_synth *synth) 51void mad_synth_mute(struct mad_synth *synth)
52{ 52{
53 unsigned int ch, s, v; 53 unsigned int ch, s, v;
54 54
55 for (ch = 0; ch < 2; ++ch) { 55 for (ch = 0; ch < 2; ++ch) {
56 for (s = 0; s < 16; ++s) { 56 for (s = 0; s < 16; ++s) {
57 for (v = 0; v < 8; ++v) { 57 for (v = 0; v < 8; ++v) {
58 synth->filter[ch][0][0][s][v] = synth->filter[ch][0][1][s][v] = 58 synth->filter[ch][0][0][s][v] = synth->filter[ch][0][1][s][v] =
59 synth->filter[ch][1][0][s][v] = synth->filter[ch][1][1][s][v] = 0; 59 synth->filter[ch][1][0][s][v] = synth->filter[ch][1][1][s][v] = 0;
60 } 60 }
61 } 61 }
62 } 62 }
63} 63}
64 64
65/* 65/*
66 * An optional optimization called here the Subband Synthesis Optimization 66 * An optional optimization called here the Subband Synthesis Optimization
67 * (SSO) improves the performance of subband synthesis at the expense of 67 * (SSO) improves the performance of subband synthesis at the expense of
68 * accuracy. 68 * accuracy.
69 * 69 *
70 * The idea is to simplify 32x32->64-bit multiplication to 32x32->32 such 70 * The idea is to simplify 32x32->64-bit multiplication to 32x32->32 such
71 * that extra scaling and rounding are not necessary. This often allows the 71 * that extra scaling and rounding are not necessary. This often allows the
72 * compiler to use faster 32-bit multiply-accumulate instructions instead of 72 * compiler to use faster 32-bit multiply-accumulate instructions instead of
73 * explicit 64-bit multiply, shift, and add instructions. 73 * explicit 64-bit multiply, shift, and add instructions.
74 * 74 *
75 * SSO works like this: a full 32x32->64-bit multiply of two mad_fixed_t 75 * SSO works like this: a full 32x32->64-bit multiply of two mad_fixed_t
76 * values requires the result to be right-shifted 28 bits to be properly 76 * values requires the result to be right-shifted 28 bits to be properly
77 * scaled to the same fixed-point format. Right shifts can be applied at any 77 * scaled to the same fixed-point format. Right shifts can be applied at any
78 * time to either operand or to the result, so the optimization involves 78 * time to either operand or to the result, so the optimization involves
79 * careful placement of these shifts to minimize the loss of accuracy. 79 * careful placement of these shifts to minimize the loss of accuracy.
80 * 80 *
81 * First, a 14-bit shift is applied with rounding at compile-time to the D[] 81 * First, a 14-bit shift is applied with rounding at compile-time to the D[]
82 * table of coefficients for the subband synthesis window. This only loses 2 82 * table of coefficients for the subband synthesis window. This only loses 2
83 * bits of accuracy because the lower 12 bits are always zero. A second 83 * bits of accuracy because the lower 12 bits are always zero. A second
84 * 12-bit shift occurs after the DCT calculation. This loses 12 bits of 84 * 12-bit shift occurs after the DCT calculation. This loses 12 bits of
85 * accuracy. Finally, a third 2-bit shift occurs just before the sample is 85 * accuracy. Finally, a third 2-bit shift occurs just before the sample is
86 * saved in the PCM buffer. 14 + 12 + 2 == 28 bits. 86 * saved in the PCM buffer. 14 + 12 + 2 == 28 bits.
87 */ 87 */
88 88
89/* FPM_DEFAULT without OPT_SSO will actually lose accuracy and performance */ 89/* FPM_DEFAULT without OPT_SSO will actually lose accuracy and performance */
90 90
91# if defined(FPM_DEFAULT) && !defined(OPT_SSO) 91# if defined(FPM_DEFAULT) && !defined(OPT_SSO)
92# define OPT_SSO 92# define OPT_SSO
93# endif 93# endif
94 94
95/* second SSO shift, with rounding */ 95/* second SSO shift, with rounding */
96 96
97# if defined(OPT_SSO) 97# if defined(OPT_SSO)
98# define SHIFT(x) (((x) + (1L << 11)) >> 12) 98# define SHIFT(x) (((x) + (1L << 11)) >> 12)
99# else 99# else
100# define SHIFT(x) (x) 100# define SHIFT(x) (x)
101# endif 101# endif
102 102
103/* possible DCT speed optimization */ 103/* possible DCT speed optimization */
104 104
105# if defined(OPT_SPEED) && defined(MAD_F_MLX) 105# if defined(OPT_SPEED) && defined(MAD_F_MLX)
106# define OPT_DCTO 106# define OPT_DCTO
107# define MUL(x, y) \ 107# define MUL(x, y) \
108 ({ mad_fixed64hi_t hi; \ 108 ({ mad_fixed64hi_t hi; \
109 mad_fixed64lo_t lo; \ 109 mad_fixed64lo_t lo; \
110 MAD_F_MLX(hi, lo, (x), (y)); \ 110 MAD_F_MLX(hi, lo, (x), (y)); \
111 hi << (32 - MAD_F_SCALEBITS - 3); \ 111 hi << (32 - MAD_F_SCALEBITS - 3); \
112 }) 112 })
113# else 113# else
114# undef OPT_DCTO 114# undef OPT_DCTO
115# define MUL(x, y) mad_f_mul((x), (y)) 115# define MUL(x, y) mad_f_mul((x), (y))
116# endif 116# endif
117 117
118/* 118/*
119 * NAME:dct32() 119 * NAME:dct32()
120 * DESCRIPTION:perform fast in[32]->out[32] DCT 120 * DESCRIPTION:perform fast in[32]->out[32] DCT
121 */ 121 */
122static 122static
123void dct32(mad_fixed_t const in[32], unsigned int slot, 123void dct32(mad_fixed_t const in[32], unsigned int slot,
124 mad_fixed_t lo[16][8], mad_fixed_t hi[16][8]) 124 mad_fixed_t lo[16][8], mad_fixed_t hi[16][8])
125{ 125{
126 mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7; 126 mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7;
127 mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15; 127 mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15;
128 mad_fixed_t t16, t17, t18, t19, t20, t21, t22, t23; 128 mad_fixed_t t16, t17, t18, t19, t20, t21, t22, t23;
129 mad_fixed_t t24, t25, t26, t27, t28, t29, t30, t31; 129 mad_fixed_t t24, t25, t26, t27, t28, t29, t30, t31;
130 mad_fixed_t t32, t33, t34, t35, t36, t37, t38, t39; 130 mad_fixed_t t32, t33, t34, t35, t36, t37, t38, t39;
131 mad_fixed_t t40, t41, t42, t43, t44, t45, t46, t47; 131 mad_fixed_t t40, t41, t42, t43, t44, t45, t46, t47;
132 mad_fixed_t t48, t49, t50, t51, t52, t53, t54, t55; 132 mad_fixed_t t48, t49, t50, t51, t52, t53, t54, t55;
133 mad_fixed_t t56, t57, t58, t59, t60, t61, t62, t63; 133 mad_fixed_t t56, t57, t58, t59, t60, t61, t62, t63;
134 mad_fixed_t t64, t65, t66, t67, t68, t69, t70, t71; 134 mad_fixed_t t64, t65, t66, t67, t68, t69, t70, t71;
135 mad_fixed_t t72, t73, t74, t75, t76, t77, t78, t79; 135 mad_fixed_t t72, t73, t74, t75, t76, t77, t78, t79;
136 mad_fixed_t t80, t81, t82, t83, t84, t85, t86, t87; 136 mad_fixed_t t80, t81, t82, t83, t84, t85, t86, t87;
137 mad_fixed_t t88, t89, t90, t91, t92, t93, t94, t95; 137 mad_fixed_t t88, t89, t90, t91, t92, t93, t94, t95;
138 mad_fixed_t t96, t97, t98, t99, t100, t101, t102, t103; 138 mad_fixed_t t96, t97, t98, t99, t100, t101, t102, t103;
139 mad_fixed_t t104, t105, t106, t107, t108, t109, t110, t111; 139 mad_fixed_t t104, t105, t106, t107, t108, t109, t110, t111;
140 mad_fixed_t t112, t113, t114, t115, t116, t117, t118, t119; 140 mad_fixed_t t112, t113, t114, t115, t116, t117, t118, t119;
141 mad_fixed_t t120, t121, t122, t123, t124, t125, t126, t127; 141 mad_fixed_t t120, t121, t122, t123, t124, t125, t126, t127;
142 mad_fixed_t t128, t129, t130, t131, t132, t133, t134, t135; 142 mad_fixed_t t128, t129, t130, t131, t132, t133, t134, t135;
143 mad_fixed_t t136, t137, t138, t139, t140, t141, t142, t143; 143 mad_fixed_t t136, t137, t138, t139, t140, t141, t142, t143;
144 mad_fixed_t t144, t145, t146, t147, t148, t149, t150, t151; 144 mad_fixed_t t144, t145, t146, t147, t148, t149, t150, t151;
145 mad_fixed_t t152, t153, t154, t155, t156, t157, t158, t159; 145 mad_fixed_t t152, t153, t154, t155, t156, t157, t158, t159;
146 mad_fixed_t t160, t161, t162, t163, t164, t165, t166, t167; 146 mad_fixed_t t160, t161, t162, t163, t164, t165, t166, t167;
147 mad_fixed_t t168, t169, t170, t171, t172, t173, t174, t175; 147 mad_fixed_t t168, t169, t170, t171, t172, t173, t174, t175;
148 mad_fixed_t t176; 148 mad_fixed_t t176;
149 149
150 /* costab[i] = cos(PI / (2 * 32) * i) */ 150 /* costab[i] = cos(PI / (2 * 32) * i) */
151 151
152# if defined(OPT_DCTO) 152# if defined(OPT_DCTO)
153 enum { 153 # define costab1MAD_F(0x7fd8878e)
154 costab1 = MAD_F(0x7fd8878e), 154 # define costab2MAD_F(0x7f62368f)
155 costab2 = MAD_F(0x7f62368f), 155 # define costab3MAD_F(0x7e9d55fc)
156 costab3 = MAD_F(0x7e9d55fc), 156 # define costab4MAD_F(0x7d8a5f40)
157 costab4 = MAD_F(0x7d8a5f40), 157 # define costab5MAD_F(0x7c29fbee)
158 costab5 = MAD_F(0x7c29fbee), 158 # define costab6MAD_F(0x7a7d055b)
159 costab6 = MAD_F(0x7a7d055b), 159 # define costab7MAD_F(0x78848414)
160 costab7 = MAD_F(0x78848414), 160 # define costab8MAD_F(0x7641af3d)
161 costab8 = MAD_F(0x7641af3d), 161 # define costab9MAD_F(0x73b5ebd1)
162 costab9 = MAD_F(0x73b5ebd1), 162 # define costab10MAD_F(0x70e2cbc6)
163 costab10 = MAD_F(0x70e2cbc6), 163 # define costab11MAD_F(0x6dca0d14)
164 costab11 = MAD_F(0x6dca0d14), 164 # define costab12MAD_F(0x6a6d98a4)
165 costab12 = MAD_F(0x6a6d98a4), 165 # define costab13MAD_F(0x66cf8120)
166 costab13 = MAD_F(0x66cf8120), 166 # define costab14MAD_F(0x62f201ac)
167 costab14 = MAD_F(0x62f201ac), 167 # define costab15MAD_F(0x5ed77c8a)
168 costab15 = MAD_F(0x5ed77c8a), 168 # define costab16MAD_F(0x5a82799a)
169 costab16 = MAD_F(0x5a82799a), 169 # define costab17MAD_F(0x55f5a4d2)
170 costab17 = MAD_F(0x55f5a4d2), 170 # define costab18MAD_F(0x5133cc94)
171 costab18 = MAD_F(0x5133cc94), 171 # define costab19MAD_F(0x4c3fdff4)
172 costab19 = MAD_F(0x4c3fdff4), 172 # define costab20MAD_F(0x471cece7)
173 costab20 = MAD_F(0x471cece7), 173 # define costab21MAD_F(0x41ce1e65)
174 costab21 = MAD_F(0x41ce1e65), 174 # define costab22MAD_F(0x3c56ba70)
175 costab22 = MAD_F(0x3c56ba70), 175 # define costab23MAD_F(0x36ba2014)
176 costab23 = MAD_F(0x36ba2014), 176 # define costab24MAD_F(0x30fbc54d)
177 costab24 = MAD_F(0x30fbc54d), 177 # define costab25MAD_F(0x2b1f34eb)
178 costab25 = MAD_F(0x2b1f34eb), 178 # define costab26MAD_F(0x25280c5e)
179 costab26 = MAD_F(0x25280c5e), 179 # define costab27MAD_F(0x1f19f97b)
180 costab27 = MAD_F(0x1f19f97b), 180 # define costab28MAD_F(0x18f8b83c)
181 costab28 = MAD_F(0x18f8b83c), 181 # define costab29MAD_F(0x12c8106f)
182 costab29 = MAD_F(0x12c8106f), 182 # define costab30MAD_F(0x0c8bd35e)
183 costab30 = MAD_F(0x0c8bd35e), 183 # define costab31MAD_F(0x0647d97c)
184 costab31 = MAD_F(0x0647d97c)
185 };
186# else 184# else
187 enum { 185 # define costab1MAD_F(0x0ffb10f2) /* 0.998795456 */
188 costab1 = MAD_F(0x0ffb10f2), /* 0.998795456 */ 186 # define costab2MAD_F(0x0fec46d2) /* 0.995184727 */
189 costab2 = MAD_F(0x0fec46d2), /* 0.995184727 */ 187 # define costab3MAD_F(0x0fd3aac0) /* 0.989176510 */
190 costab3 = MAD_F(0x0fd3aac0), /* 0.989176510 */ 188 # define costab4MAD_F(0x0fb14be8) /* 0.980785280 */
191 costab4 = MAD_F(0x0fb14be8), /* 0.980785280 */ 189 # define costab5MAD_F(0x0f853f7e) /* 0.970031253 */
192 costab5 = MAD_F(0x0f853f7e), /* 0.970031253 */ 190 # define costab6MAD_F(0x0f4fa0ab) /* 0.956940336 */
193 costab6 = MAD_F(0x0f4fa0ab), /* 0.956940336 */ 191 # define costab7MAD_F(0x0f109082) /* 0.941544065 */
194 costab7 = MAD_F(0x0f109082), /* 0.941544065 */ 192 # define costab8MAD_F(0x0ec835e8) /* 0.923879533 */
195 costab8 = MAD_F(0x0ec835e8), /* 0.923879533 */ 193 # define costab9MAD_F(0x0e76bd7a) /* 0.903989293 */
196 costab9 = MAD_F(0x0e76bd7a), /* 0.903989293 */ 194 # define costab10MAD_F(0x0e1c5979) /* 0.881921264 */
197 costab10 = MAD_F(0x0e1c5979), /* 0.881921264 */ 195 # define costab11MAD_F(0x0db941a3) /* 0.857728610 */
198 costab11 = MAD_F(0x0db941a3), /* 0.857728610 */ 196 # define costab12MAD_F(0x0d4db315) /* 0.831469612 */
199 costab12 = MAD_F(0x0d4db315), /* 0.831469612 */ 197 # define costab13MAD_F(0x0cd9f024) /* 0.803207531 */
200 costab13 = MAD_F(0x0cd9f024), /* 0.803207531 */ 198 # define costab14MAD_F(0x0c5e4036) /* 0.773010453 */
201 costab14 = MAD_F(0x0c5e4036), /* 0.773010453 */ 199 # define costab15MAD_F(0x0bdaef91) /* 0.740951125 */
202 costab15 = MAD_F(0x0bdaef91), /* 0.740951125 */ 200 # define costab16MAD_F(0x0b504f33) /* 0.707106781 */
203 costab16 = MAD_F(0x0b504f33), /* 0.707106781 */ 201 # define costab17MAD_F(0x0abeb49a) /* 0.671558955 */
204 costab17 = MAD_F(0x0abeb49a), /* 0.671558955 */ 202 # define costab18MAD_F(0x0a267993) /* 0.634393284 */
205 costab18 = MAD_F(0x0a267993), /* 0.634393284 */ 203 # define costab19MAD_F(0x0987fbfe) /* 0.595699304 */
206 costab19 = MAD_F(0x0987fbfe), /* 0.595699304 */ 204 # define costab20MAD_F(0x08e39d9d) /* 0.555570233 */
207 costab20 = MAD_F(0x08e39d9d), /* 0.555570233 */ 205 # define costab21MAD_F(0x0839c3cd) /* 0.514102744 */
208 costab21 = MAD_F(0x0839c3cd), /* 0.514102744 */ 206 # define costab22MAD_F(0x078ad74e) /* 0.471396737 */
209 costab22 = MAD_F(0x078ad74e), /* 0.471396737 */ 207 # define costab23MAD_F(0x06d74402) /* 0.427555093 */
210 costab23 = MAD_F(0x06d74402), /* 0.427555093 */ 208 # define costab24MAD_F(0x061f78aa) /* 0.382683432 */
211 costab24 = MAD_F(0x061f78aa), /* 0.382683432 */ 209 # define costab25MAD_F(0x0563e69d) /* 0.336889853 */
212 costab25 = MAD_F(0x0563e69d), /* 0.336889853 */ 210 # define costab26MAD_F(0x04a5018c) /* 0.290284677 */
213 costab26 = MAD_F(0x04a5018c), /* 0.290284677 */ 211 # define costab27MAD_F(0x03e33f2f) /* 0.242980180 */
214 costab27 = MAD_F(0x03e33f2f), /* 0.242980180 */ 212 # define costab28MAD_F(0x031f1708) /* 0.195090322 */
215 costab28 = MAD_F(0x031f1708), /* 0.195090322 */ 213 # define costab29MAD_F(0x0259020e) /* 0.146730474 */
216 costab29 = MAD_F(0x0259020e), /* 0.146730474 */ 214 # define costab30MAD_F(0x01917a6c) /* 0.098017140 */
217 costab30 = MAD_F(0x01917a6c), /* 0.098017140 */ 215 # define costab31MAD_F(0x00c8fb30) /* 0.049067674 */
218 costab31 = MAD_F(0x00c8fb30) /* 0.049067674 */
219 };
220# endif 216# endif
221 217
222 t0 = in[0] + in[31]; t16 = MUL(in[0] - in[31], costab1); 218 t0 = in[0] + in[31]; t16 = MUL(in[0] - in[31], costab1);
223 t1 = in[15] + in[16]; t17 = MUL(in[15] - in[16], costab31); 219 t1 = in[15] + in[16]; t17 = MUL(in[15] - in[16], costab31);
224 220
225 t41 = t16 + t17; 221 t41 = t16 + t17;
226 t59 = MUL(t16 - t17, costab2); 222 t59 = MUL(t16 - t17, costab2);
227 t33 = t0 + t1; 223 t33 = t0 + t1;
228 t50 = MUL(t0 - t1, costab2); 224 t50 = MUL(t0 - t1, costab2);
229 225
230 t2 = in[7] + in[24]; t18 = MUL(in[7] - in[24], costab15); 226 t2 = in[7] + in[24]; t18 = MUL(in[7] - in[24], costab15);
231 t3 = in[8] + in[23]; t19 = MUL(in[8] - in[23], costab17); 227 t3 = in[8] + in[23]; t19 = MUL(in[8] - in[23], costab17);
232 228
233 t42 = t18 + t19; 229 t42 = t18 + t19;
234 t60 = MUL(t18 - t19, costab30); 230 t60 = MUL(t18 - t19, costab30);
235 t34 = t2 + t3; 231 t34 = t2 + t3;
236 t51 = MUL(t2 - t3, costab30); 232 t51 = MUL(t2 - t3, costab30);
237 233
238 t4 = in[3] + in[28]; t20 = MUL(in[3] - in[28], costab7); 234 t4 = in[3] + in[28]; t20 = MUL(in[3] - in[28], costab7);
239 t5 = in[12] + in[19]; t21 = MUL(in[12] - in[19], costab25); 235 t5 = in[12] + in[19]; t21 = MUL(in[12] - in[19], costab25);
240 236
241 t43 = t20 + t21; 237 t43 = t20 + t21;
242 t61 = MUL(t20 - t21, costab14); 238 t61 = MUL(t20 - t21, costab14);
243 t35 = t4 + t5; 239 t35 = t4 + t5;
244 t52 = MUL(t4 - t5, costab14); 240 t52 = MUL(t4 - t5, costab14);
245 241
246 t6 = in[4] + in[27]; t22 = MUL(in[4] - in[27], costab9); 242 t6 = in[4] + in[27]; t22 = MUL(in[4] - in[27], costab9);
247 t7 = in[11] + in[20]; t23 = MUL(in[11] - in[20], costab23); 243 t7 = in[11] + in[20]; t23 = MUL(in[11] - in[20], costab23);
248 244
249 t44 = t22 + t23; 245 t44 = t22 + t23;
250 t62 = MUL(t22 - t23, costab18); 246 t62 = MUL(t22 - t23, costab18);
251 t36 = t6 + t7; 247 t36 = t6 + t7;
252 t53 = MUL(t6 - t7, costab18); 248 t53 = MUL(t6 - t7, costab18);
253 249
254 t8 = in[1] + in[30]; t24 = MUL(in[1] - in[30], costab3); 250 t8 = in[1] + in[30]; t24 = MUL(in[1] - in[30], costab3);
255 t9 = in[14] + in[17]; t25 = MUL(in[14] - in[17], costab29); 251 t9 = in[14] + in[17]; t25 = MUL(in[14] - in[17], costab29);
256 252
257 t45 = t24 + t25; 253 t45 = t24 + t25;
258 t63 = MUL(t24 - t25, costab6); 254 t63 = MUL(t24 - t25, costab6);
259 t37 = t8 + t9; 255 t37 = t8 + t9;
260 t54 = MUL(t8 - t9, costab6); 256 t54 = MUL(t8 - t9, costab6);
261 257
262 t10 = in[6] + in[25]; t26 = MUL(in[6] - in[25], costab13); 258 t10 = in[6] + in[25]; t26 = MUL(in[6] - in[25], costab13);
263 t11 = in[9] + in[22]; t27 = MUL(in[9] - in[22], costab19); 259 t11 = in[9] + in[22]; t27 = MUL(in[9] - in[22], costab19);
264 260
265 t46 = t26 + t27; 261 t46 = t26 + t27;
266 t64 = MUL(t26 - t27, costab26); 262 t64 = MUL(t26 - t27, costab26);
267 t38 = t10 + t11; 263 t38 = t10 + t11;
268 t55 = MUL(t10 - t11, costab26); 264 t55 = MUL(t10 - t11, costab26);
269 265
270 t12 = in[2] + in[29]; t28 = MUL(in[2] - in[29], costab5); 266 t12 = in[2] + in[29]; t28 = MUL(in[2] - in[29], costab5);
271 t13 = in[13] + in[18]; t29 = MUL(in[13] - in[18], costab27); 267 t13 = in[13] + in[18]; t29 = MUL(in[13] - in[18], costab27);
272 268
273 t47 = t28 + t29; 269 t47 = t28 + t29;
274 t65 = MUL(t28 - t29, costab10); 270 t65 = MUL(t28 - t29, costab10);
275 t39 = t12 + t13; 271 t39 = t12 + t13;
276 t56 = MUL(t12 - t13, costab10); 272 t56 = MUL(t12 - t13, costab10);
277 273
278 t14 = in[5] + in[26]; t30 = MUL(in[5] - in[26], costab11); 274 t14 = in[5] + in[26]; t30 = MUL(in[5] - in[26], costab11);
279 t15 = in[10] + in[21]; t31 = MUL(in[10] - in[21], costab21); 275 t15 = in[10] + in[21]; t31 = MUL(in[10] - in[21], costab21);
280 276
281 t48 = t30 + t31; 277 t48 = t30 + t31;
282 t66 = MUL(t30 - t31, costab22); 278 t66 = MUL(t30 - t31, costab22);
283 t40 = t14 + t15; 279 t40 = t14 + t15;
284 t57 = MUL(t14 - t15, costab22); 280 t57 = MUL(t14 - t15, costab22);
285 281
286 t69 = t33 + t34; t89 = MUL(t33 - t34, costab4); 282 t69 = t33 + t34; t89 = MUL(t33 - t34, costab4);
287 t70 = t35 + t36; t90 = MUL(t35 - t36, costab28); 283 t70 = t35 + t36; t90 = MUL(t35 - t36, costab28);
288 t71 = t37 + t38; t91 = MUL(t37 - t38, costab12); 284 t71 = t37 + t38; t91 = MUL(t37 - t38, costab12);
289 t72 = t39 + t40; t92 = MUL(t39 - t40, costab20); 285 t72 = t39 + t40; t92 = MUL(t39 - t40, costab20);
290 t73 = t41 + t42; t94 = MUL(t41 - t42, costab4); 286 t73 = t41 + t42; t94 = MUL(t41 - t42, costab4);
291 t74 = t43 + t44; t95 = MUL(t43 - t44, costab28); 287 t74 = t43 + t44; t95 = MUL(t43 - t44, costab28);
292 t75 = t45 + t46; t96 = MUL(t45 - t46, costab12); 288 t75 = t45 + t46; t96 = MUL(t45 - t46, costab12);
293 t76 = t47 + t48; t97 = MUL(t47 - t48, costab20); 289 t76 = t47 + t48; t97 = MUL(t47 - t48, costab20);
294 290
295 t78 = t50 + t51; t100 = MUL(t50 - t51, costab4); 291 t78 = t50 + t51; t100 = MUL(t50 - t51, costab4);
296 t79 = t52 + t53; t101 = MUL(t52 - t53, costab28); 292 t79 = t52 + t53; t101 = MUL(t52 - t53, costab28);
297 t80 = t54 + t55; t102 = MUL(t54 - t55, costab12); 293 t80 = t54 + t55; t102 = MUL(t54 - t55, costab12);
298 t81 = t56 + t57; t103 = MUL(t56 - t57, costab20); 294 t81 = t56 + t57; t103 = MUL(t56 - t57, costab20);
299 295
300 t83 = t59 + t60; t106 = MUL(t59 - t60, costab4); 296 t83 = t59 + t60; t106 = MUL(t59 - t60, costab4);
301 t84 = t61 + t62; t107 = MUL(t61 - t62, costab28); 297 t84 = t61 + t62; t107 = MUL(t61 - t62, costab28);
302 t85 = t63 + t64; t108 = MUL(t63 - t64, costab12); 298 t85 = t63 + t64; t108 = MUL(t63 - t64, costab12);
303 t86 = t65 + t66; t109 = MUL(t65 - t66, costab20); 299 t86 = t65 + t66; t109 = MUL(t65 - t66, costab20);
304 300
305 t113 = t69 + t70; 301 t113 = t69 + t70;
306 t114 = t71 + t72; 302 t114 = t71 + t72;
307 303
308 /* 0 */ hi[15][slot] = SHIFT(t113 + t114); 304 /* 0 */ hi[15][slot] = SHIFT(t113 + t114);
309 /* 16 */ lo[ 0][slot] = SHIFT(MUL(t113 - t114, costab16)); 305 /* 16 */ lo[ 0][slot] = SHIFT(MUL(t113 - t114, costab16));
310 306
311 t115 = t73 + t74; 307 t115 = t73 + t74;
312 t116 = t75 + t76; 308 t116 = t75 + t76;
313 309
314 t32 = t115 + t116; 310 t32 = t115 + t116;
315 311
316 /* 1 */ hi[14][slot] = SHIFT(t32); 312 /* 1 */ hi[14][slot] = SHIFT(t32);
317 313
318 t118 = t78 + t79; 314 t118 = t78 + t79;
319 t119 = t80 + t81; 315 t119 = t80 + t81;
320 316
321 t58 = t118 + t119; 317 t58 = t118 + t119;
322 318
323 /* 2 */ hi[13][slot] = SHIFT(t58); 319 /* 2 */ hi[13][slot] = SHIFT(t58);
324 320
325 t121 = t83 + t84; 321 t121 = t83 + t84;
326 t122 = t85 + t86; 322 t122 = t85 + t86;
327 323
328 t67 = t121 + t122; 324 t67 = t121 + t122;
329 325
330 t49 = (t67 << 1) - t32; 326 t49 = (t67 * 2) - t32;
331 327
332 /* 3 */ hi[12][slot] = SHIFT(t49); 328 /* 3 */ hi[12][slot] = SHIFT(t49);
333 329
334 t125 = t89 + t90; 330 t125 = t89 + t90;
335 t126 = t91 + t92; 331 t126 = t91 + t92;
336 332
337 t93 = t125 + t126; 333 t93 = t125 + t126;
338 334
339 /* 4 */ hi[11][slot] = SHIFT(t93); 335 /* 4 */ hi[11][slot] = SHIFT(t93);
340 336
341 t128 = t94 + t95; 337 t128 = t94 + t95;
342 t129 = t96 + t97; 338 t129 = t96 + t97;
343 339
344 t98 = t128 + t129; 340 t98 = t128 + t129;
345 341
346 t68 = (t98 << 1) - t49; 342 t68 = (t98 * 2) - t49;
347 343
348 /* 5 */ hi[10][slot] = SHIFT(t68); 344 /* 5 */ hi[10][slot] = SHIFT(t68);
349 345
350 t132 = t100 + t101; 346 t132 = t100 + t101;
351 t133 = t102 + t103; 347 t133 = t102 + t103;
352 348
353 t104 = t132 + t133; 349 t104 = t132 + t133;
354 350
355 t82 = (t104 << 1) - t58; 351 t82 = (t104 * 2) - t58;
356 352
357 /* 6 */ hi[ 9][slot] = SHIFT(t82); 353 /* 6 */ hi[ 9][slot] = SHIFT(t82);
358 354
359 t136 = t106 + t107; 355 t136 = t106 + t107;
360 t137 = t108 + t109; 356 t137 = t108 + t109;
361 357
362 t110 = t136 + t137; 358 t110 = t136 + t137;
363 359
364 t87 = (t110 << 1) - t67; 360 t87 = (t110 * 2) - t67;
365 361
366 t77 = (t87 << 1) - t68; 362 t77 = (t87 * 2) - t68;
367 363
368 /* 7 */ hi[ 8][slot] = SHIFT(t77); 364 /* 7 */ hi[ 8][slot] = SHIFT(t77);
369 365
370 t141 = MUL(t69 - t70, costab8); 366 t141 = MUL(t69 - t70, costab8);
371 t142 = MUL(t71 - t72, costab24); 367 t142 = MUL(t71 - t72, costab24);
372 t143 = t141 + t142; 368 t143 = t141 + t142;
373 369
374 /* 8 */ hi[ 7][slot] = SHIFT(t143); 370 /* 8 */ hi[ 7][slot] = SHIFT(t143);
375 /* 24 */ lo[ 8][slot] = 371 /* 24 */ lo[ 8][slot] =
376 SHIFT((MUL(t141 - t142, costab16) << 1) - t143); 372 SHIFT((MUL(t141 - t142, costab16) * 2) - t143);
377 373
378 t144 = MUL(t73 - t74, costab8); 374 t144 = MUL(t73 - t74, costab8);
379 t145 = MUL(t75 - t76, costab24); 375 t145 = MUL(t75 - t76, costab24);
380 t146 = t144 + t145; 376 t146 = t144 + t145;
381 377
382 t88 = (t146 << 1) - t77; 378 t88 = (t146 * 2) - t77;
383 379
384 /* 9 */ hi[ 6][slot] = SHIFT(t88); 380 /* 9 */ hi[ 6][slot] = SHIFT(t88);
385 381
386 t148 = MUL(t78 - t79, costab8); 382 t148 = MUL(t78 - t79, costab8);
387 t149 = MUL(t80 - t81, costab24); 383 t149 = MUL(t80 - t81, costab24);
388 t150 = t148 + t149; 384 t150 = t148 + t149;
389 385
390 t105 = (t150 << 1) - t82; 386 t105 = (t150 * 2) - t82;
391 387
392 /* 10 */ hi[ 5][slot] = SHIFT(t105); 388 /* 10 */ hi[ 5][slot] = SHIFT(t105);
393 389
394 t152 = MUL(t83 - t84, costab8); 390 t152 = MUL(t83 - t84, costab8);
395 t153 = MUL(t85 - t86, costab24); 391 t153 = MUL(t85 - t86, costab24);
396 t154 = t152 + t153; 392 t154 = t152 + t153;
397 393
398 t111 = (t154 << 1) - t87; 394 t111 = (t154 * 2) - t87;
399 395
400 t99 = (t111 << 1) - t88; 396 t99 = (t111 * 2) - t88;
401 397
402 /* 11 */ hi[ 4][slot] = SHIFT(t99); 398 /* 11 */ hi[ 4][slot] = SHIFT(t99);
403 399
404 t157 = MUL(t89 - t90, costab8); 400 t157 = MUL(t89 - t90, costab8);
405 t158 = MUL(t91 - t92, costab24); 401 t158 = MUL(t91 - t92, costab24);
406 t159 = t157 + t158; 402 t159 = t157 + t158;
407 403
408 t127 = (t159 << 1) - t93; 404 t127 = (t159 * 2) - t93;
409 405
410 /* 12 */ hi[ 3][slot] = SHIFT(t127); 406 /* 12 */ hi[ 3][slot] = SHIFT(t127);
411 407
412 t160 = (MUL(t125 - t126, costab16) << 1) - t127; 408 t160 = (MUL(t125 - t126, costab16) * 2) - t127;
413 409
414 /* 20 */ lo[ 4][slot] = SHIFT(t160); 410 /* 20 */ lo[ 4][slot] = SHIFT(t160);
415 /* 28 */ lo[12][slot] = 411 /* 28 */ lo[12][slot] =
416 SHIFT((((MUL(t157 - t158, costab16) << 1) - t159) << 1) - t160); 412 SHIFT((((MUL(t157 - t158, costab16) * 2) - t159) * 2) - t160);
417 413
418 t161 = MUL(t94 - t95, costab8); 414 t161 = MUL(t94 - t95, costab8);
419 t162 = MUL(t96 - t97, costab24); 415 t162 = MUL(t96 - t97, costab24);
420 t163 = t161 + t162; 416 t163 = t161 + t162;
421 417
422 t130 = (t163 << 1) - t98; 418 t130 = (t163 * 2) - t98;
423 419
424 t112 = (t130 << 1) - t99; 420 t112 = (t130 * 2) - t99;
425 421
426 /* 13 */ hi[ 2][slot] = SHIFT(t112); 422 /* 13 */ hi[ 2][slot] = SHIFT(t112);
427 423
428 t164 = (MUL(t128 - t129, costab16) << 1) - t130; 424 t164 = (MUL(t128 - t129, costab16) * 2) - t130;
429 425
430 t166 = MUL(t100 - t101, costab8); 426 t166 = MUL(t100 - t101, costab8);
431 t167 = MUL(t102 - t103, costab24); 427 t167 = MUL(t102 - t103, costab24);
432 t168 = t166 + t167; 428 t168 = t166 + t167;
433 429
434 t134 = (t168 << 1) - t104; 430 t134 = (t168 * 2) - t104;
435 431
436 t120 = (t134 << 1) - t105; 432 t120 = (t134 * 2) - t105;
437 433
438 /* 14 */ hi[ 1][slot] = SHIFT(t120); 434 /* 14 */ hi[ 1][slot] = SHIFT(t120);
439 435
440 t135 = (MUL(t118 - t119, costab16) << 1) - t120; 436 t135 = (MUL(t118 - t119, costab16) * 2) - t120;
441 437
442 /* 18 */ lo[ 2][slot] = SHIFT(t135); 438 /* 18 */ lo[ 2][slot] = SHIFT(t135);
443 439
444 t169 = (MUL(t132 - t133, costab16) << 1) - t134; 440 t169 = (MUL(t132 - t133, costab16) * 2) - t134;
445 441
446 t151 = (t169 << 1) - t135; 442 t151 = (t169 * 2) - t135;
447 443
448 /* 22 */ lo[ 6][slot] = SHIFT(t151); 444 /* 22 */ lo[ 6][slot] = SHIFT(t151);
449 445
450 t170 = (((MUL(t148 - t149, costab16) << 1) - t150) << 1) - t151; 446 t170 = (((MUL(t148 - t149, costab16) * 2) - t150) * 2) - t151;
451 447
452 /* 26 */ lo[10][slot] = SHIFT(t170); 448 /* 26 */ lo[10][slot] = SHIFT(t170);
453 /* 30 */ lo[14][slot] = 449 /* 30 */ lo[14][slot] =
454 SHIFT((((((MUL(t166 - t167, costab16) << 1) - 450 SHIFT((((((MUL(t166 - t167, costab16) * 2) -
455 t168) << 1) - t169) << 1) - t170); 451 t168) * 2) - t169) * 2) - t170);
456 452
457 t171 = MUL(t106 - t107, costab8); 453 t171 = MUL(t106 - t107, costab8);
458 t172 = MUL(t108 - t109, costab24); 454 t172 = MUL(t108 - t109, costab24);
459 t173 = t171 + t172; 455 t173 = t171 + t172;
460 456
461 t138 = (t173 << 1) - t110; 457 t138 = (t173 * 2) - t110;
462 458
463 t123 = (t138 << 1) - t111; 459 t123 = (t138 * 2) - t111;
464 460
465 t139 = (MUL(t121 - t122, costab16) << 1) - t123; 461 t139 = (MUL(t121 - t122, costab16) * 2) - t123;
466 462
467 t117 = (t123 << 1) - t112; 463 t117 = (t123 * 2) - t112;
468 464
469 /* 15 */ hi[ 0][slot] = SHIFT(t117); 465 /* 15 */ hi[ 0][slot] = SHIFT(t117);
470 466
471 t124 = (MUL(t115 - t116, costab16) << 1) - t117; 467 t124 = (MUL(t115 - t116, costab16) * 2) - t117;
472 468
473 /* 17 */ lo[ 1][slot] = SHIFT(t124); 469 /* 17 */ lo[ 1][slot] = SHIFT(t124);
474 470
475 t131 = (t139 << 1) - t124; 471 t131 = (t139 * 2) - t124;
476 472
477 /* 19 */ lo[ 3][slot] = SHIFT(t131); 473 /* 19 */ lo[ 3][slot] = SHIFT(t131);
478 474
479 t140 = (t164 << 1) - t131; 475 t140 = (t164 * 2) - t131;
480 476
481 /* 21 */ lo[ 5][slot] = SHIFT(t140); 477 /* 21 */ lo[ 5][slot] = SHIFT(t140);
482 478
483 t174 = (MUL(t136 - t137, costab16) << 1) - t138; 479 t174 = (MUL(t136 - t137, costab16) * 2) - t138;
484 480
485 t155 = (t174 << 1) - t139; 481 t155 = (t174 * 2) - t139;
486 482
487 t147 = (t155 << 1) - t140; 483 t147 = (t155 * 2) - t140;
488 484
489 /* 23 */ lo[ 7][slot] = SHIFT(t147); 485 /* 23 */ lo[ 7][slot] = SHIFT(t147);
490 486
491 t156 = (((MUL(t144 - t145, costab16) << 1) - t146) << 1) - t147; 487 t156 = (((MUL(t144 - t145, costab16) * 2) - t146) * 2) - t147;
492 488
493 /* 25 */ lo[ 9][slot] = SHIFT(t156); 489 /* 25 */ lo[ 9][slot] = SHIFT(t156);
494 490
495 t175 = (((MUL(t152 - t153, costab16) << 1) - t154) << 1) - t155; 491 t175 = (((MUL(t152 - t153, costab16) * 2) - t154) * 2) - t155;
496 492
497 t165 = (t175 << 1) - t156; 493 t165 = (t175 * 2) - t156;
498 494
499 /* 27 */ lo[11][slot] = SHIFT(t165); 495 /* 27 */ lo[11][slot] = SHIFT(t165);
500 496
501 t176 = (((((MUL(t161 - t162, costab16) << 1) - 497 t176 = (((((MUL(t161 - t162, costab16) * 2) -
502 t163) << 1) - t164) << 1) - t165; 498 t163) * 2) - t164) * 2) - t165;
503 499
504 /* 29 */ lo[13][slot] = SHIFT(t176); 500 /* 29 */ lo[13][slot] = SHIFT(t176);
505 /* 31 */ lo[15][slot] = 501 /* 31 */ lo[15][slot] =
506 SHIFT((((((((MUL(t171 - t172, costab16) << 1) - 502 SHIFT((((((((MUL(t171 - t172, costab16) * 2) -
507 t173) << 1) - t174) << 1) - t175) << 1) - t176); 503 t173) * 2) - t174) * 2) - t175) * 2) - t176);
508 504
509 /* 505 /*
510 * Totals: 506 * Totals:
511 * 80 multiplies 507 * 80 multiplies
512 * 80 additions 508 * 80 additions
513 * 119 subtractions 509 * 119 subtractions
514 * 49 shifts (not counting SSO) 510 * 49 shifts (not counting SSO)
515 */ 511 */
516} 512}
517 513
518# undef MUL 514# undef MUL
519# undef SHIFT 515# undef SHIFT
520 516
521/* third SSO shift and/or D[] optimization preshift */ 517/* third SSO shift and/or D[] optimization preshift */
522 518
523# if defined(OPT_SSO) 519# if defined(OPT_SSO)
524# if MAD_F_FRACBITS != 28 520# if MAD_F_FRACBITS != 28
525# error "MAD_F_FRACBITS must be 28 to use OPT_SSO" 521# error "MAD_F_FRACBITS must be 28 to use OPT_SSO"
526# endif 522# endif
527 # define ML0(hi, lo, x, y)((lo) = (x) * (y)) 523 # define ML0(hi, lo, x, y)((lo) = (x) * (y))
528 # define MLA(hi, lo, x, y)((lo) += (x) * (y)) 524 # define MLA(hi, lo, x, y)((lo) += (x) * (y))
525 # define MLN(hi, lo) ((lo) = -(lo))
529 # define MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo)) 526 # define MLZ(hi, lo) ((void) (hi), (mad_fixed_t) (lo))
530 # define SHIFT(x) ((x) >> 2) 527 # define SHIFT(x) ((x) >> 2)
531 # define PRESHIFT(x) ((MAD_F(x) + (1L << 13)) >> 14) 528 # define PRESHIFT(x) ((MAD_F(x) + (1L << 13)) >> 14)
532# else 529# else
533 # define ML0(hi, lo, x, y)MAD_F_ML0((hi), (lo), (x), (y)) 530 # define ML0(hi, lo, x, y)MAD_F_ML0((hi), (lo), (x), (y))
534 # define MLA(hi, lo, x, y)MAD_F_MLA((hi), (lo), (x), (y)) 531 # define MLA(hi, lo, x, y)MAD_F_MLA((hi), (lo), (x), (y))
532 # define MLN(hi, lo) MAD_F_MLN((hi), (lo))
535 # define MLZ(hi, lo) MAD_F_MLZ((hi), (lo)) 533 # define MLZ(hi, lo) MAD_F_MLZ((hi), (lo))
536 # define SHIFT(x) (x) 534 # define SHIFT(x) (x)
537# if defined(MAD_F_SCALEBITS) 535# if defined(MAD_F_SCALEBITS)
538# undef MAD_F_SCALEBITS 536# undef MAD_F_SCALEBITS
539 # define MAD_F_SCALEBITS(MAD_F_FRACBITS - 12) 537 # define MAD_F_SCALEBITS(MAD_F_FRACBITS - 12)
540 # define PRESHIFT(x) (MAD_F(x) >> 12) 538 # define PRESHIFT(x) (MAD_F(x) >> 12)
541# else 539# else
542 # define PRESHIFT(x) MAD_F(x) 540 # define PRESHIFT(x) MAD_F(x)
543# endif 541# endif
544# endif 542# endif
545 543
546static 544static
547mad_fixed_t const D[17][32] = { 545mad_fixed_t const D[17][32] = {
548# include "D.dat" 546# include "D.dat"
549}; 547};
550 548
551# if defined(ASO_SYNTH) 549# if defined(ASO_SYNTH)
552void synth_full(struct mad_synth *, struct mad_frame const *, 550void synth_full(struct mad_synth *, struct mad_frame const *,
553 unsigned int, unsigned int); 551 unsigned int, unsigned int);
554# else 552# else
555/* 553/*
556 * NAME:synth->full() 554 * NAME:synth->full()
557 * DESCRIPTION:perform full frequency PCM synthesis 555 * DESCRIPTION:perform full frequency PCM synthesis
558 */ 556 */
559static 557static
560void synth_full(struct mad_synth *synth, struct mad_frame const *frame, 558void synth_full(struct mad_synth *synth, struct mad_frame const *frame,
561 unsigned int nch, unsigned int ns) 559 unsigned int nch, unsigned int ns)
562{ 560{
563 unsigned int phase, ch, s, sb, pe, po; 561 unsigned int phase, ch, s, sb, pe, po;
564 mad_fixed_t *pcm1, *pcm2, (*filter)[2][2][16][8]; 562 mad_fixed_t *pcm1, *pcm2, (*filter)[2][2][16][8];
565 mad_fixed_t const (*sbsample)[36][32]; 563 mad_fixed_t const (*sbsample)[36][32];
566 register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8]; 564 register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
567 register mad_fixed_t const (*Dptr)[32], *ptr; 565 register mad_fixed_t const (*Dptr)[32], *ptr;
568 register mad_fixed64hi_t hi; 566 register mad_fixed64hi_t hi;
569 register mad_fixed64lo_t lo; 567 register mad_fixed64lo_t lo;
570 568
571 for (ch = 0; ch < nch; ++ch) { 569 for (ch = 0; ch < nch; ++ch) {
572 sbsample = &frame->sbsample[ch]; 570 sbsample = &frame->sbsample[ch];
573 filter = &synth->filter[ch]; 571 filter = &synth->filter[ch];
574 phase = synth->phase; 572 phase = synth->phase;
575 pcm1 = synth->pcm.samples[ch]; 573 pcm1 = synth->pcm.samples[ch];
576 574
577 for (s = 0; s < ns; ++s) { 575 for (s = 0; s < ns; ++s) {
578 dct32((*sbsample)[s], phase >> 1, 576 dct32((*sbsample)[s], phase >> 1,
579 (*filter)[0][phase & 1], (*filter)[1][phase & 1]); 577 (*filter)[0][phase & 1], (*filter)[1][phase & 1]);
580 578
581 pe = phase & ~1; 579 pe = phase & ~1;
582 po = ((phase - 1) & 0xf) | 1; 580 po = ((phase - 1) & 0xf) | 1;
583 581
584 /* calculate 32 samples */ 582 /* calculate 32 samples */
585 583
586 fe = &(*filter)[0][ phase & 1][0]; 584 fe = &(*filter)[0][ phase & 1][0];
587 fx = &(*filter)[0][~phase & 1][0]; 585 fx = &(*filter)[0][~phase & 1][0];
588 fo = &(*filter)[1][~phase & 1][0]; 586 fo = &(*filter)[1][~phase & 1][0];
589 587
590 Dptr = &D[0]; 588 Dptr = &D[0];
591 589
590 ptr = *Dptr + po;
591 ML0(hi, lo, (*fx)[0], ptr[ 0]);
592 MLA(hi, lo, (*fx)[1], ptr[14]);
593 MLA(hi, lo, (*fx)[2], ptr[12]);
594 MLA(hi, lo, (*fx)[3], ptr[10]);
595 MLA(hi, lo, (*fx)[4], ptr[ 8]);
596 MLA(hi, lo, (*fx)[5], ptr[ 6]);
597 MLA(hi, lo, (*fx)[6], ptr[ 4]);
598 MLA(hi, lo, (*fx)[7], ptr[ 2]);
599 MLN(hi, lo);
600
592 ptr = *Dptr + pe; 601 ptr = *Dptr + pe;
593 ML0(hi, lo, (*fe)[0], ptr[ 0]); 602 MLA(hi, lo, (*fe)[0], ptr[ 0]);
594 MLA(hi, lo, (*fe)[1], ptr[14]); 603 MLA(hi, lo, (*fe)[1], ptr[14]);
595 MLA(hi, lo, (*fe)[2], ptr[12]); 604 MLA(hi, lo, (*fe)[2], ptr[12]);
596 MLA(hi, lo, (*fe)[3], ptr[10]); 605 MLA(hi, lo, (*fe)[3], ptr[10]);
597 MLA(hi, lo, (*fe)[4], ptr[ 8]); 606 MLA(hi, lo, (*fe)[4], ptr[ 8]);
598 MLA(hi, lo, (*fe)[5], ptr[ 6]); 607 MLA(hi, lo, (*fe)[5], ptr[ 6]);
599 MLA(hi, lo, (*fe)[6], ptr[ 4]); 608 MLA(hi, lo, (*fe)[6], ptr[ 4]);
600 MLA(hi, lo, (*fe)[7], ptr[ 2]); 609 MLA(hi, lo, (*fe)[7], ptr[ 2]);
601 610
602 ptr = *Dptr + po;
603 MLA(hi, lo, (*fx)[0], -ptr[ 0]);
604 MLA(hi, lo, (*fx)[1], -ptr[14]);
605 MLA(hi, lo, (*fx)[2], -ptr[12]);
606 MLA(hi, lo, (*fx)[3], -ptr[10]);
607 MLA(hi, lo, (*fx)[4], -ptr[ 8]);
608 MLA(hi, lo, (*fx)[5], -ptr[ 6]);
609 MLA(hi, lo, (*fx)[6], -ptr[ 4]);
610 MLA(hi, lo, (*fx)[7], -ptr[ 2]);
611
612 *pcm1++ = SHIFT(MLZ(hi, lo)); 611 *pcm1++ = SHIFT(MLZ(hi, lo));
613 612
614 pcm2 = pcm1 + 30; 613 pcm2 = pcm1 + 30;
615 614
616 for (sb = 1; sb < 16; ++sb) { 615 for (sb = 1; sb < 16; ++sb) {
617 ++fe; 616 ++fe;
618 ++Dptr; 617 ++Dptr;
619 618
620 /* D[32 - sb][i] == -D[sb][31 - i] */ 619 /* D[32 - sb][i] == -D[sb][31 - i] */
621 620
621 ptr = *Dptr + po;
622 ML0(hi, lo, (*fo)[0], ptr[ 0]);
623 MLA(hi, lo, (*fo)[1], ptr[14]);
624 MLA(hi, lo, (*fo)[2], ptr[12]);
625 MLA(hi, lo, (*fo)[3], ptr[10]);
626 MLA(hi, lo, (*fo)[4], ptr[ 8]);
627 MLA(hi, lo, (*fo)[5], ptr[ 6]);
628 MLA(hi, lo, (*fo)[6], ptr[ 4]);
629 MLA(hi, lo, (*fo)[7], ptr[ 2]);
630 MLN(hi, lo);
631
622 ptr = *Dptr + pe; 632 ptr = *Dptr + pe;
623 ML0(hi, lo, (*fe)[7], ptr[ 2]); 633 MLA(hi, lo, (*fe)[7], ptr[ 2]);
624 MLA(hi, lo, (*fe)[6], ptr[ 4]); 634 MLA(hi, lo, (*fe)[6], ptr[ 4]);
625 MLA(hi, lo, (*fe)[5], ptr[ 6]); 635 MLA(hi, lo, (*fe)[5], ptr[ 6]);
626 MLA(hi, lo, (*fe)[4], ptr[ 8]); 636 MLA(hi, lo, (*fe)[4], ptr[ 8]);
627 MLA(hi, lo, (*fe)[3], ptr[10]); 637 MLA(hi, lo, (*fe)[3], ptr[10]);
628 MLA(hi, lo, (*fe)[2], ptr[12]); 638 MLA(hi, lo, (*fe)[2], ptr[12]);
629 MLA(hi, lo, (*fe)[1], ptr[14]); 639 MLA(hi, lo, (*fe)[1], ptr[14]);
630 MLA(hi, lo, (*fe)[0], ptr[ 0]); 640 MLA(hi, lo, (*fe)[0], ptr[ 0]);
631 641
632 ptr = *Dptr + po;
633 MLA(hi, lo, (*fo)[0], -ptr[ 0]);
634 MLA(hi, lo, (*fo)[1], -ptr[14]);
635 MLA(hi, lo, (*fo)[2], -ptr[12]);
636 MLA(hi, lo, (*fo)[3], -ptr[10]);
637 MLA(hi, lo, (*fo)[4], -ptr[ 8]);
638 MLA(hi, lo, (*fo)[5], -ptr[ 6]);
639 MLA(hi, lo, (*fo)[6], -ptr[ 4]);
640 MLA(hi, lo, (*fo)[7], -ptr[ 2]);
641
642 *pcm1++ = SHIFT(MLZ(hi, lo)); 642 *pcm1++ = SHIFT(MLZ(hi, lo));
643 643
644 ptr = *Dptr - po;
645 ML0(hi, lo, (*fo)[7], ptr[31 - 2]);
646 MLA(hi, lo, (*fo)[6], ptr[31 - 4]);
647 MLA(hi, lo, (*fo)[5], ptr[31 - 6]);
648 MLA(hi, lo, (*fo)[4], ptr[31 - 8]);
649 MLA(hi, lo, (*fo)[3], ptr[31 - 10]);
650 MLA(hi, lo, (*fo)[2], ptr[31 - 12]);
651 MLA(hi, lo, (*fo)[1], ptr[31 - 14]);
652 MLA(hi, lo, (*fo)[0], ptr[31 - 16]);
653
654 ptr = *Dptr - pe; 644 ptr = *Dptr - pe;
655 MLA(hi, lo, (*fe)[0], ptr[31 - 16]); 645 ML0(hi, lo, (*fe)[0], ptr[31 - 16]);
656 MLA(hi, lo, (*fe)[1], ptr[31 - 14]); 646 MLA(hi, lo, (*fe)[1], ptr[31 - 14]);
657 MLA(hi, lo, (*fe)[2], ptr[31 - 12]); 647 MLA(hi, lo, (*fe)[2], ptr[31 - 12]);
658 MLA(hi, lo, (*fe)[3], ptr[31 - 10]); 648 MLA(hi, lo, (*fe)[3], ptr[31 - 10]);
659 MLA(hi, lo, (*fe)[4], ptr[31 - 8]); 649 MLA(hi, lo, (*fe)[4], ptr[31 - 8]);
660 MLA(hi, lo, (*fe)[5], ptr[31 - 6]); 650 MLA(hi, lo, (*fe)[5], ptr[31 - 6]);
661 MLA(hi, lo, (*fe)[6], ptr[31 - 4]); 651 MLA(hi, lo, (*fe)[6], ptr[31 - 4]);
662 MLA(hi, lo, (*fe)[7], ptr[31 - 2]); 652 MLA(hi, lo, (*fe)[7], ptr[31 - 2]);
663 653
654 ptr = *Dptr - po;
655 MLA(hi, lo, (*fo)[7], ptr[31 - 2]);
656 MLA(hi, lo, (*fo)[6], ptr[31 - 4]);
657 MLA(hi, lo, (*fo)[5], ptr[31 - 6]);
658 MLA(hi, lo, (*fo)[4], ptr[31 - 8]);
659 MLA(hi, lo, (*fo)[3], ptr[31 - 10]);
660 MLA(hi, lo, (*fo)[2], ptr[31 - 12]);
661 MLA(hi, lo, (*fo)[1], ptr[31 - 14]);
662 MLA(hi, lo, (*fo)[0], ptr[31 - 16]);
663
664 *pcm2-- = SHIFT(MLZ(hi, lo)); 664 *pcm2-- = SHIFT(MLZ(hi, lo));
665 665
666 ++fo; 666 ++fo;
667 } 667 }
668 668
669 ++Dptr; 669 ++Dptr;
670 670
671 ptr = *Dptr + po; 671 ptr = *Dptr + po;
672 ML0(hi, lo, (*fo)[0], ptr[ 0]); 672 ML0(hi, lo, (*fo)[0], ptr[ 0]);
673 MLA(hi, lo, (*fo)[1], ptr[14]); 673 MLA(hi, lo, (*fo)[1], ptr[14]);
674 MLA(hi, lo, (*fo)[2], ptr[12]); 674 MLA(hi, lo, (*fo)[2], ptr[12]);
675 MLA(hi, lo, (*fo)[3], ptr[10]); 675 MLA(hi, lo, (*fo)[3], ptr[10]);
676 MLA(hi, lo, (*fo)[4], ptr[ 8]); 676 MLA(hi, lo, (*fo)[4], ptr[ 8]);
677 MLA(hi, lo, (*fo)[5], ptr[ 6]); 677 MLA(hi, lo, (*fo)[5], ptr[ 6]);
678 MLA(hi, lo, (*fo)[6], ptr[ 4]); 678 MLA(hi, lo, (*fo)[6], ptr[ 4]);
679 MLA(hi, lo, (*fo)[7], ptr[ 2]); 679 MLA(hi, lo, (*fo)[7], ptr[ 2]);
680 680
681 *pcm1 = SHIFT(-MLZ(hi, lo)); 681 *pcm1 = SHIFT(-MLZ(hi, lo));
682 pcm1 += 16; 682 pcm1 += 16;
683 683
684 phase = (phase + 1) % 16; 684 phase = (phase + 1) % 16;
685 } 685 }
686 } 686 }
687} 687}
688# endif 688# endif
689 689
690/* 690/*
691 * NAME:synth->half() 691 * NAME:synth->half()
692 * DESCRIPTION:perform half frequency PCM synthesis 692 * DESCRIPTION:perform half frequency PCM synthesis
693 */ 693 */
694static 694static
695void synth_half(struct mad_synth *synth, struct mad_frame const *frame, 695void synth_half(struct mad_synth *synth, struct mad_frame const *frame,
696 unsigned int nch, unsigned int ns) 696 unsigned int nch, unsigned int ns)
697{ 697{
698 unsigned int phase, ch, s, sb, pe, po; 698 unsigned int phase, ch, s, sb, pe, po;
699 mad_fixed_t *pcm1, *pcm2, (*filter)[2][2][16][8]; 699 mad_fixed_t *pcm1, *pcm2, (*filter)[2][2][16][8];
700 mad_fixed_t const (*sbsample)[36][32]; 700 mad_fixed_t const (*sbsample)[36][32];
701 register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8]; 701 register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
702 register mad_fixed_t const (*Dptr)[32], *ptr; 702 register mad_fixed_t const (*Dptr)[32], *ptr;
703 register mad_fixed64hi_t hi; 703 register mad_fixed64hi_t hi;
704 register mad_fixed64lo_t lo; 704 register mad_fixed64lo_t lo;
705 705
706 for (ch = 0; ch < nch; ++ch) { 706 for (ch = 0; ch < nch; ++ch) {
707 sbsample = &frame->sbsample[ch]; 707 sbsample = &frame->sbsample[ch];
708 filter = &synth->filter[ch]; 708 filter = &synth->filter[ch];
709 phase = synth->phase; 709 phase = synth->phase;
710 pcm1 = synth->pcm.samples[ch]; 710 pcm1 = synth->pcm.samples[ch];
711 711
712 for (s = 0; s < ns; ++s) { 712 for (s = 0; s < ns; ++s) {
713 dct32((*sbsample)[s], phase >> 1, 713 dct32((*sbsample)[s], phase >> 1,
714 (*filter)[0][phase & 1], (*filter)[1][phase & 1]); 714 (*filter)[0][phase & 1], (*filter)[1][phase & 1]);
715 715
716 pe = phase & ~1; 716 pe = phase & ~1;
717 po = ((phase - 1) & 0xf) | 1; 717 po = ((phase - 1) & 0xf) | 1;
718 718
719 /* calculate 16 samples */ 719 /* calculate 16 samples */
720 720
721 fe = &(*filter)[0][ phase & 1][0]; 721 fe = &(*filter)[0][ phase & 1][0];
722 fx = &(*filter)[0][~phase & 1][0]; 722 fx = &(*filter)[0][~phase & 1][0];
723 fo = &(*filter)[1][~phase & 1][0]; 723 fo = &(*filter)[1][~phase & 1][0];
724 724
725 Dptr = &D[0]; 725 Dptr = &D[0];
726 726
727 ptr = *Dptr + po;
728 ML0(hi, lo, (*fx)[0], ptr[ 0]);
729 MLA(hi, lo, (*fx)[1], ptr[14]);
730 MLA(hi, lo, (*fx)[2], ptr[12]);
731 MLA(hi, lo, (*fx)[3], ptr[10]);
732 MLA(hi, lo, (*fx)[4], ptr[ 8]);
733 MLA(hi, lo, (*fx)[5], ptr[ 6]);
734 MLA(hi, lo, (*fx)[6], ptr[ 4]);
735 MLA(hi, lo, (*fx)[7], ptr[ 2]);
736 MLN(hi, lo);
737
727 ptr = *Dptr + pe; 738 ptr = *Dptr + pe;
728 ML0(hi, lo, (*fe)[0], ptr[ 0]); 739 MLA(hi, lo, (*fe)[0], ptr[ 0]);
729 MLA(hi, lo, (*fe)[1], ptr[14]); 740 MLA(hi, lo, (*fe)[1], ptr[14]);
730 MLA(hi, lo, (*fe)[2], ptr[12]); 741 MLA(hi, lo, (*fe)[2], ptr[12]);
731 MLA(hi, lo, (*fe)[3], ptr[10]); 742 MLA(hi, lo, (*fe)[3], ptr[10]);
732 MLA(hi, lo, (*fe)[4], ptr[ 8]); 743 MLA(hi, lo, (*fe)[4], ptr[ 8]);
733 MLA(hi, lo, (*fe)[5], ptr[ 6]); 744 MLA(hi, lo, (*fe)[5], ptr[ 6]);
734 MLA(hi, lo, (*fe)[6], ptr[ 4]); 745 MLA(hi, lo, (*fe)[6], ptr[ 4]);
735 MLA(hi, lo, (*fe)[7], ptr[ 2]); 746 MLA(hi, lo, (*fe)[7], ptr[ 2]);
736 747
737 ptr = *Dptr + po;
738 MLA(hi, lo, (*fx)[0], -ptr[ 0]);
739 MLA(hi, lo, (*fx)[1], -ptr[14]);
740 MLA(hi, lo, (*fx)[2], -ptr[12]);
741 MLA(hi, lo, (*fx)[3], -ptr[10]);
742 MLA(hi, lo, (*fx)[4], -ptr[ 8]);
743 MLA(hi, lo, (*fx)[5], -ptr[ 6]);
744 MLA(hi, lo, (*fx)[6], -ptr[ 4]);
745 MLA(hi, lo, (*fx)[7], -ptr[ 2]);
746
747 *pcm1++ = SHIFT(MLZ(hi, lo)); 748 *pcm1++ = SHIFT(MLZ(hi, lo));
748 749
749 pcm2 = pcm1 + 14; 750 pcm2 = pcm1 + 14;
750 751
751 for (sb = 1; sb < 16; ++sb) { 752 for (sb = 1; sb < 16; ++sb) {
752 ++fe; 753 ++fe;
753 ++Dptr; 754 ++Dptr;
754 755
755 /* D[32 - sb][i] == -D[sb][31 - i] */ 756 /* D[32 - sb][i] == -D[sb][31 - i] */
756 757
757 if (!(sb & 1)) { 758 if (!(sb & 1)) {
759 ptr = *Dptr + po;
760 ML0(hi, lo, (*fo)[0], ptr[ 0]);
761 MLA(hi, lo, (*fo)[1], ptr[14]);
762 MLA(hi, lo, (*fo)[2], ptr[12]);
763 MLA(hi, lo, (*fo)[3], ptr[10]);
764 MLA(hi, lo, (*fo)[4], ptr[ 8]);
765 MLA(hi, lo, (*fo)[5], ptr[ 6]);
766 MLA(hi, lo, (*fo)[6], ptr[ 4]);
767 MLA(hi, lo, (*fo)[7], ptr[ 2]);
768 MLN(hi, lo);
769
758 ptr = *Dptr + pe; 770 ptr = *Dptr + pe;
759 ML0(hi, lo, (*fe)[7], ptr[ 2]); 771 MLA(hi, lo, (*fe)[7], ptr[ 2]);
760 MLA(hi, lo, (*fe)[6], ptr[ 4]); 772 MLA(hi, lo, (*fe)[6], ptr[ 4]);
761 MLA(hi, lo, (*fe)[5], ptr[ 6]); 773 MLA(hi, lo, (*fe)[5], ptr[ 6]);
762 MLA(hi, lo, (*fe)[4], ptr[ 8]); 774 MLA(hi, lo, (*fe)[4], ptr[ 8]);
763 MLA(hi, lo, (*fe)[3], ptr[10]); 775 MLA(hi, lo, (*fe)[3], ptr[10]);
764 MLA(hi, lo, (*fe)[2], ptr[12]); 776 MLA(hi, lo, (*fe)[2], ptr[12]);
765 MLA(hi, lo, (*fe)[1], ptr[14]); 777 MLA(hi, lo, (*fe)[1], ptr[14]);
766 MLA(hi, lo, (*fe)[0], ptr[ 0]); 778 MLA(hi, lo, (*fe)[0], ptr[ 0]);
767 779
768 ptr = *Dptr + po;
769 MLA(hi, lo, (*fo)[0], -ptr[ 0]);
770 MLA(hi, lo, (*fo)[1], -ptr[14]);
771 MLA(hi, lo, (*fo)[2], -ptr[12]);
772 MLA(hi, lo, (*fo)[3], -ptr[10]);
773 MLA(hi, lo, (*fo)[4], -ptr[ 8]);
774 MLA(hi, lo, (*fo)[5], -ptr[ 6]);
775 MLA(hi, lo, (*fo)[6], -ptr[ 4]);
776 MLA(hi, lo, (*fo)[7], -ptr[ 2]);
777
778 *pcm1++ = SHIFT(MLZ(hi, lo)); 780 *pcm1++ = SHIFT(MLZ(hi, lo));
779 781
780 ptr = *Dptr - po; 782 ptr = *Dptr - po;
781 ML0(hi, lo, (*fo)[7], ptr[31 - 2]); 783 ML0(hi, lo, (*fo)[7], ptr[31 - 2]);
782 MLA(hi, lo, (*fo)[6], ptr[31 - 4]); 784 MLA(hi, lo, (*fo)[6], ptr[31 - 4]);
783 MLA(hi, lo, (*fo)[5], ptr[31 - 6]); 785 MLA(hi, lo, (*fo)[5], ptr[31 - 6]);
784 MLA(hi, lo, (*fo)[4], ptr[31 - 8]); 786 MLA(hi, lo, (*fo)[4], ptr[31 - 8]);
785 MLA(hi, lo, (*fo)[3], ptr[31 - 10]); 787 MLA(hi, lo, (*fo)[3], ptr[31 - 10]);
786 MLA(hi, lo, (*fo)[2], ptr[31 - 12]); 788 MLA(hi, lo, (*fo)[2], ptr[31 - 12]);
787 MLA(hi, lo, (*fo)[1], ptr[31 - 14]); 789 MLA(hi, lo, (*fo)[1], ptr[31 - 14]);
788 MLA(hi, lo, (*fo)[0], ptr[31 - 16]); 790 MLA(hi, lo, (*fo)[0], ptr[31 - 16]);
789 791
790 ptr = *Dptr - pe; 792 ptr = *Dptr - pe;
791 MLA(hi, lo, (*fe)[0], ptr[31 - 16]); 793 MLA(hi, lo, (*fe)[0], ptr[31 - 16]);
792 MLA(hi, lo, (*fe)[1], ptr[31 - 14]); 794 MLA(hi, lo, (*fe)[1], ptr[31 - 14]);
793 MLA(hi, lo, (*fe)[2], ptr[31 - 12]); 795 MLA(hi, lo, (*fe)[2], ptr[31 - 12]);
794 MLA(hi, lo, (*fe)[3], ptr[31 - 10]); 796 MLA(hi, lo, (*fe)[3], ptr[31 - 10]);
795 MLA(hi, lo, (*fe)[4], ptr[31 - 8]); 797 MLA(hi, lo, (*fe)[4], ptr[31 - 8]);
796 MLA(hi, lo, (*fe)[5], ptr[31 - 6]); 798 MLA(hi, lo, (*fe)[5], ptr[31 - 6]);
797 MLA(hi, lo, (*fe)[6], ptr[31 - 4]); 799 MLA(hi, lo, (*fe)[6], ptr[31 - 4]);
798 MLA(hi, lo, (*fe)[7], ptr[31 - 2]); 800 MLA(hi, lo, (*fe)[7], ptr[31 - 2]);
799 801
800 *pcm2-- = SHIFT(MLZ(hi, lo)); 802 *pcm2-- = SHIFT(MLZ(hi, lo));
801 } 803 }
802 804
803 ++fo; 805 ++fo;
804 } 806 }
805 807
806 ++Dptr; 808 ++Dptr;
807 809
808 ptr = *Dptr + po; 810 ptr = *Dptr + po;
809 ML0(hi, lo, (*fo)[0], ptr[ 0]); 811 ML0(hi, lo, (*fo)[0], ptr[ 0]);
810 MLA(hi, lo, (*fo)[1], ptr[14]); 812 MLA(hi, lo, (*fo)[1], ptr[14]);
811 MLA(hi, lo, (*fo)[2], ptr[12]); 813 MLA(hi, lo, (*fo)[2], ptr[12]);
812 MLA(hi, lo, (*fo)[3], ptr[10]); 814 MLA(hi, lo, (*fo)[3], ptr[10]);
813 MLA(hi, lo, (*fo)[4], ptr[ 8]); 815 MLA(hi, lo, (*fo)[4], ptr[ 8]);
814 MLA(hi, lo, (*fo)[5], ptr[ 6]); 816 MLA(hi, lo, (*fo)[5], ptr[ 6]);
815 MLA(hi, lo, (*fo)[6], ptr[ 4]); 817 MLA(hi, lo, (*fo)[6], ptr[ 4]);
816 MLA(hi, lo, (*fo)[7], ptr[ 2]); 818 MLA(hi, lo, (*fo)[7], ptr[ 2]);
817 819
818 *pcm1 = SHIFT(-MLZ(hi, lo)); 820 *pcm1 = SHIFT(-MLZ(hi, lo));
819 pcm1 += 8; 821 pcm1 += 8;
820 822
821 phase = (phase + 1) % 16; 823 phase = (phase + 1) % 16;
822 } 824 }
823 } 825 }
824} 826}
825 827
826/* 828/*
827 * NAME:synth->frame() 829 * NAME:synth->frame()
828 * DESCRIPTION:perform PCM synthesis of frame subband samples 830 * DESCRIPTION:perform PCM synthesis of frame subband samples
829 */ 831 */
830void mad_synth_frame(struct mad_synth *synth, struct mad_frame const *frame) 832void mad_synth_frame(struct mad_synth *synth, struct mad_frame const *frame)
831{ 833{
832 unsigned int nch, ns; 834 unsigned int nch, ns;
833 void (*synth_frame)(struct mad_synth *, struct mad_frame const *, 835 void (*synth_frame)(struct mad_synth *, struct mad_frame const *,
834 unsigned int, unsigned int); 836 unsigned int, unsigned int);
835 837
836 nch = MAD_NCHANNELS(&frame->header); 838 nch = MAD_NCHANNELS(&frame->header);
837 ns = MAD_NSBSAMPLES(&frame->header); 839 ns = MAD_NSBSAMPLES(&frame->header);
838 840
839 synth->pcm.samplerate = frame->header.samplerate; 841 synth->pcm.samplerate = frame->header.samplerate;
840 synth->pcm.channels = nch; 842 synth->pcm.channels = nch;
841 synth->pcm.length = 32 * ns; 843 synth->pcm.length = 32 * ns;
842 844
843 synth_frame = synth_full; 845 synth_frame = synth_full;
844 846
845 if (frame->options & MAD_OPTION_HALFSAMPLERATE) { 847 if (frame->options & MAD_OPTION_HALFSAMPLERATE) {
846 synth->pcm.samplerate /= 2; 848 synth->pcm.samplerate /= 2;
847 synth->pcm.length /= 2; 849 synth->pcm.length /= 2;
848 850
849 synth_frame = synth_half; 851 synth_frame = synth_half;
850 } 852 }
851 853
852 synth_frame(synth, frame, nch, ns); 854 synth_frame(synth, frame, nch, ns);
853 855
854 synth->phase = (synth->phase + ns) % 16; 856 synth->phase = (synth->phase + ns) % 16;
855} 857}
diff --git a/core/multimedia/opieplayer/libmad/synth.h b/core/multimedia/opieplayer/libmad/synth.h
index 64f6a86..2c9d5c8 100644
--- a/core/multimedia/opieplayer/libmad/synth.h
+++ b/core/multimedia/opieplayer/libmad/synth.h
@@ -1,50 +1,69 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# ifndef LIBMAD_SYNTH_H 22# ifndef LIBMAD_SYNTH_H
23# define LIBMAD_SYNTH_H 23# define LIBMAD_SYNTH_H
24 24
25# include "fixed.h" 25# include "fixed.h"
26# include "frame.h" 26# include "frame.h"
27 27
28struct mad_pcm {
29 unsigned int samplerate; /* sampling frequency (Hz) */
30 unsigned short channels; /* number of channels */
31 unsigned short length; /* number of samples per channel */
32 mad_fixed_t samples[2][1152]; /* PCM output samples [ch][sample] */
33};
34
28struct mad_synth { 35struct mad_synth {
29 mad_fixed_t filter[2][2][2][16][8];/* polyphase filterbank outputs */ 36 mad_fixed_t filter[2][2][2][16][8];/* polyphase filterbank outputs */
30 /* [ch][eo][peo][s][v] */ 37 /* [ch][eo][peo][s][v] */
31 38
32 unsigned int phase; /* current processing phase */ 39 unsigned int phase; /* current processing phase */
33 40
34 struct mad_pcm { 41 struct mad_pcm pcm; /* PCM output */
35 unsigned int samplerate; /* sampling frequency (Hz) */ 42};
36 unsigned short channels; /* number of channels */ 43
37 unsigned short length; /* number of samples per channel */ 44/* single channel PCM selector */
38 mad_fixed_t samples[2][1152];/* PCM output samples */ 45enum {
39 } pcm; 46 MAD_PCM_CHANNEL_SINGLE = 0
47};
48
49/* dual channel PCM selector */
50enum {
51 MAD_PCM_CHANNEL_DUAL_1 = 0,
52 MAD_PCM_CHANNEL_DUAL_2 = 1
53};
54
55/* stereo PCM selector */
56enum {
57 MAD_PCM_CHANNEL_STEREO_LEFT = 0,
58 MAD_PCM_CHANNEL_STEREO_RIGHT = 1
40}; 59};
41 60
42void mad_synth_init(struct mad_synth *); 61void mad_synth_init(struct mad_synth *);
43 62
44# define mad_synth_finish(synth) /* nothing */ 63# define mad_synth_finish(synth) /* nothing */
45 64
46void mad_synth_mute(struct mad_synth *); 65void mad_synth_mute(struct mad_synth *);
47 66
48void mad_synth_frame(struct mad_synth *, struct mad_frame const *); 67void mad_synth_frame(struct mad_synth *, struct mad_frame const *);
49 68
50# endif 69# endif
diff --git a/core/multimedia/opieplayer/libmad/timer.c b/core/multimedia/opieplayer/libmad/timer.c
index b30680c..299fe0b 100644
--- a/core/multimedia/opieplayer/libmad/timer.c
+++ b/core/multimedia/opieplayer/libmad/timer.c
@@ -1,480 +1,484 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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
28# include <stdio.h> 28# include <stdio.h>
29# include <assert.h> 29
30# ifdef HAVE_ASSERT_H
31# include <assert.h>
32# endif
30 33
31# include "timer.h" 34# include "timer.h"
32 35
33mad_timer_t const mad_timer_zero = { 0, 0 }; 36mad_timer_t const mad_timer_zero = { 0, 0 };
34 37
35/* 38/*
36 * NAME:timer->compare() 39 * NAME:timer->compare()
37 * DESCRIPTION:indicate relative order of two timers 40 * DESCRIPTION:indicate relative order of two timers
38 */ 41 */
39int mad_timer_compare(mad_timer_t timer1, mad_timer_t timer2) 42int mad_timer_compare(mad_timer_t timer1, mad_timer_t timer2)
40{ 43{
41 signed long diff; 44 signed long diff;
42 45
43 diff = timer1.seconds - timer2.seconds; 46 diff = timer1.seconds - timer2.seconds;
44 if (diff < 0) 47 if (diff < 0)
45 return -1; 48 return -1;
46 else if (diff > 0) 49 else if (diff > 0)
47 return +1; 50 return +1;
48 51
49 diff = timer1.fraction - timer2.fraction; 52 diff = timer1.fraction - timer2.fraction;
50 if (diff < 0) 53 if (diff < 0)
51 return -1; 54 return -1;
52 else if (diff > 0) 55 else if (diff > 0)
53 return +1; 56 return +1;
54 57
55 return 0; 58 return 0;
56} 59}
57 60
58/* 61/*
59 * NAME:timer->negate() 62 * NAME:timer->negate()
60 * DESCRIPTION:invert the sign of a timer 63 * DESCRIPTION:invert the sign of a timer
61 */ 64 */
62void mad_timer_negate(mad_timer_t *timer) 65void mad_timer_negate(mad_timer_t *timer)
63{ 66{
64 timer->seconds = -timer->seconds; 67 timer->seconds = -timer->seconds;
65 68
66 if (timer->fraction) { 69 if (timer->fraction) {
67 timer->seconds -= 1; 70 timer->seconds -= 1;
68 timer->fraction = MAD_TIMER_RESOLUTION - timer->fraction; 71 timer->fraction = MAD_TIMER_RESOLUTION - timer->fraction;
69 } 72 }
70} 73}
71 74
72/* 75/*
73 * NAME:timer->abs() 76 * NAME:timer->abs()
74 * DESCRIPTION:return the absolute value of a timer 77 * DESCRIPTION:return the absolute value of a timer
75 */ 78 */
76mad_timer_t mad_timer_abs(mad_timer_t timer) 79mad_timer_t mad_timer_abs(mad_timer_t timer)
77{ 80{
78 if (mad_timer_sign(timer) < 0) 81 if (mad_timer_sign(timer) < 0)
79 mad_timer_negate(&timer); 82 mad_timer_negate(&timer);
80 83
81 return timer; 84 return timer;
82} 85}
83 86
84/* 87/*
85 * NAME:reduce_timer() 88 * NAME:reduce_timer()
86 * DESCRIPTION:carry timer fraction into seconds 89 * DESCRIPTION:carry timer fraction into seconds
87 */ 90 */
88static 91static
89void reduce_timer(mad_timer_t *timer) 92void reduce_timer(mad_timer_t *timer)
90{ 93{
91 timer->seconds += timer->fraction / MAD_TIMER_RESOLUTION; 94 timer->seconds += timer->fraction / MAD_TIMER_RESOLUTION;
92 timer->fraction %= MAD_TIMER_RESOLUTION; 95 timer->fraction %= MAD_TIMER_RESOLUTION;
93} 96}
94 97
95/* 98/*
96 * NAME:gcd() 99 * NAME:gcd()
97 * DESCRIPTION:compute greatest common denominator 100 * DESCRIPTION:compute greatest common denominator
98 */ 101 */
99static 102static
100unsigned long gcd(unsigned long num1, unsigned long num2) 103unsigned long gcd(unsigned long num1, unsigned long num2)
101{ 104{
102 unsigned long tmp; 105 unsigned long tmp;
103 106
104 while (num2) { 107 while (num2) {
105 tmp = num2; 108 tmp = num2;
106 num2 = num1 % num2; 109 num2 = num1 % num2;
107 num1 = tmp; 110 num1 = tmp;
108 } 111 }
109 112
110 return num1; 113 return num1;
111} 114}
112 115
113/* 116/*
114 * NAME:reduce_rational() 117 * NAME:reduce_rational()
115 * DESCRIPTION:convert rational expression to lowest terms 118 * DESCRIPTION:convert rational expression to lowest terms
116 */ 119 */
117static 120static
118void reduce_rational(unsigned long *numer, unsigned long *denom) 121void reduce_rational(unsigned long *numer, unsigned long *denom)
119{ 122{
120 unsigned long factor; 123 unsigned long factor;
121 124
122 factor = gcd(*numer, *denom); 125 factor = gcd(*numer, *denom);
123 126
124 assert(factor != 0); 127 assert(factor != 0);
125 128
126 *numer /= factor; 129 *numer /= factor;
127 *denom /= factor; 130 *denom /= factor;
128} 131}
129 132
130/* 133/*
131 * NAME:scale_rational() 134 * NAME:scale_rational()
132 * DESCRIPTION:solve numer/denom == ?/scale avoiding overflowing 135 * DESCRIPTION:solve numer/denom == ?/scale avoiding overflowing
133 */ 136 */
134static 137static
135unsigned long scale_rational(unsigned long numer, unsigned long denom, 138unsigned long scale_rational(unsigned long numer, unsigned long denom,
136 unsigned long scale) 139 unsigned long scale)
137{ 140{
138 reduce_rational(&numer, &denom); 141 reduce_rational(&numer, &denom);
139 reduce_rational(&scale, &denom); 142 reduce_rational(&scale, &denom);
140 143
141 assert(denom != 0); 144 assert(denom != 0);
142 145
143 if (denom < scale) 146 if (denom < scale)
144 return numer * (scale / denom) + numer * (scale % denom) / denom; 147 return numer * (scale / denom) + numer * (scale % denom) / denom;
145 if (denom < numer) 148 if (denom < numer)
146 return scale * (numer / denom) + scale * (numer % denom) / denom; 149 return scale * (numer / denom) + scale * (numer % denom) / denom;
147 150
148 return numer * scale / denom; 151 return numer * scale / denom;
149} 152}
150 153
151/* 154/*
152 * NAME:timer->set() 155 * NAME:timer->set()
153 * DESCRIPTION:set timer to specific value 156 * DESCRIPTION:set timer to specific (positive) value
154 */ 157 */
155void mad_timer_set(mad_timer_t *timer, unsigned long seconds, 158void mad_timer_set(mad_timer_t *timer, unsigned long seconds,
156 unsigned long fraction, unsigned long fracparts) 159 unsigned long numer, unsigned long denom)
157{ 160{
158 timer->seconds = seconds; 161 timer->seconds = seconds;
159 162 if (numer >= denom && denom > 0) {
160 if (fraction == 0) 163 timer->seconds += numer / denom;
161 fracparts = 0; 164 numer %= denom;
162 else if (fracparts == 0) {
163 fracparts = fraction;
164 fraction = 1;
165 } 165 }
166 166
167 switch (fracparts) { 167 switch (denom) {
168 case 0: 168 case 0:
169 case 1:
169 timer->fraction = 0; 170 timer->fraction = 0;
170 break; 171 break;
171 172
172 case MAD_TIMER_RESOLUTION: 173 case MAD_TIMER_RESOLUTION:
173 timer->fraction = fraction; 174 timer->fraction = numer;
175 break;
176
177 case 1000:
178 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 1000);
174 break; 179 break;
175 180
176 case 8000: 181 case 8000:
177 timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 8000); 182 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 8000);
178 break; 183 break;
179 184
180 case 11025: 185 case 11025:
181 timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 11025); 186 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 11025);
182 break; 187 break;
183 188
184 case 12000: 189 case 12000:
185 timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 12000); 190 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 12000);
186 break; 191 break;
187 192
188 case 16000: 193 case 16000:
189 timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 16000); 194 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 16000);
190 break; 195 break;
191 196
192 case 22050: 197 case 22050:
193 timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 22050); 198 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 22050);
194 break; 199 break;
195 200
196 case 24000: 201 case 24000:
197 timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 24000); 202 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 24000);
198 break; 203 break;
199 204
200 case 32000: 205 case 32000:
201 timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 32000); 206 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 32000);
202 break; 207 break;
203 208
204 case 44100: 209 case 44100:
205 timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 44100); 210 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 44100);
206 break; 211 break;
207 212
208 case 48000: 213 case 48000:
209 timer->fraction = fraction * (MAD_TIMER_RESOLUTION / 48000); 214 timer->fraction = numer * (MAD_TIMER_RESOLUTION / 48000);
210 break; 215 break;
211 216
212 default: 217 default:
213 timer->fraction = 218 timer->fraction = scale_rational(numer, denom, MAD_TIMER_RESOLUTION);
214 scale_rational(fraction, fracparts, MAD_TIMER_RESOLUTION);
215 break; 219 break;
216 } 220 }
217 221
218 if (timer->fraction >= MAD_TIMER_RESOLUTION) 222 if (timer->fraction >= MAD_TIMER_RESOLUTION)
219 reduce_timer(timer); 223 reduce_timer(timer);
220} 224}
221 225
222/* 226/*
223 * NAME:timer->add() 227 * NAME:timer->add()
224 * DESCRIPTION:add one timer to another 228 * DESCRIPTION:add one timer to another
225 */ 229 */
226void mad_timer_add(mad_timer_t *timer, mad_timer_t incr) 230void mad_timer_add(mad_timer_t *timer, mad_timer_t incr)
227{ 231{
228 timer->seconds += incr.seconds; 232 timer->seconds += incr.seconds;
229 timer->fraction += incr.fraction; 233 timer->fraction += incr.fraction;
230 234
231 if (timer->fraction >= MAD_TIMER_RESOLUTION) 235 if (timer->fraction >= MAD_TIMER_RESOLUTION)
232 reduce_timer(timer); 236 reduce_timer(timer);
233} 237}
234 238
235/* 239/*
236 * NAME:timer->multiply() 240 * NAME:timer->multiply()
237 * DESCRIPTION:multiply a timer by a scalar value 241 * DESCRIPTION:multiply a timer by a scalar value
238 */ 242 */
239void mad_timer_multiply(mad_timer_t *timer, signed long scalar) 243void mad_timer_multiply(mad_timer_t *timer, signed long scalar)
240{ 244{
241 mad_timer_t addend; 245 mad_timer_t addend;
242 unsigned long factor; 246 unsigned long factor;
243 247
244 factor = scalar; 248 factor = scalar;
245 if (scalar < 0) { 249 if (scalar < 0) {
246 mad_timer_negate(timer);
247 factor = -scalar; 250 factor = -scalar;
251 mad_timer_negate(timer);
248 } 252 }
249 253
250 addend = *timer; 254 addend = *timer;
251 *timer = mad_timer_zero; 255 *timer = mad_timer_zero;
252 256
253 while (factor) { 257 while (factor) {
254 if (factor & 1) 258 if (factor & 1)
255 mad_timer_add(timer, addend); 259 mad_timer_add(timer, addend);
256 260
257 mad_timer_add(&addend, addend); 261 mad_timer_add(&addend, addend);
258 factor >>= 1; 262 factor >>= 1;
259 } 263 }
260} 264}
261 265
262/* 266/*
263 * NAME:timer->count() 267 * NAME:timer->count()
264 * DESCRIPTION:return timer value in selected units 268 * DESCRIPTION:return timer value in selected units
265 */ 269 */
266signed long mad_timer_count(mad_timer_t timer, enum mad_units units) 270signed long mad_timer_count(mad_timer_t timer, enum mad_units units)
267{ 271{
268 switch (units) { 272 switch (units) {
269 case MAD_UNITS_HOURS: 273 case MAD_UNITS_HOURS:
270 return timer.seconds / 60 / 60; 274 return timer.seconds / 60 / 60;
271 275
272 case MAD_UNITS_MINUTES: 276 case MAD_UNITS_MINUTES:
273 return timer.seconds / 60; 277 return timer.seconds / 60;
274 278
275 case MAD_UNITS_SECONDS: 279 case MAD_UNITS_SECONDS:
276 return timer.seconds; 280 return timer.seconds;
277 281
278 case MAD_UNITS_DECISECONDS: 282 case MAD_UNITS_DECISECONDS:
279 case MAD_UNITS_CENTISECONDS: 283 case MAD_UNITS_CENTISECONDS:
280 case MAD_UNITS_MILLISECONDS: 284 case MAD_UNITS_MILLISECONDS:
281 285
282 case MAD_UNITS_8000_HZ: 286 case MAD_UNITS_8000_HZ:
283 case MAD_UNITS_11025_HZ: 287 case MAD_UNITS_11025_HZ:
284 case MAD_UNITS_12000_HZ: 288 case MAD_UNITS_12000_HZ:
285 case MAD_UNITS_16000_HZ: 289 case MAD_UNITS_16000_HZ:
286 case MAD_UNITS_22050_HZ: 290 case MAD_UNITS_22050_HZ:
287 case MAD_UNITS_24000_HZ: 291 case MAD_UNITS_24000_HZ:
288 case MAD_UNITS_32000_HZ: 292 case MAD_UNITS_32000_HZ:
289 case MAD_UNITS_44100_HZ: 293 case MAD_UNITS_44100_HZ:
290 case MAD_UNITS_48000_HZ: 294 case MAD_UNITS_48000_HZ:
291 295
292 case MAD_UNITS_24_FPS: 296 case MAD_UNITS_24_FPS:
293 case MAD_UNITS_25_FPS: 297 case MAD_UNITS_25_FPS:
294 case MAD_UNITS_30_FPS: 298 case MAD_UNITS_30_FPS:
295 case MAD_UNITS_48_FPS: 299 case MAD_UNITS_48_FPS:
296 case MAD_UNITS_50_FPS: 300 case MAD_UNITS_50_FPS:
297 case MAD_UNITS_60_FPS: 301 case MAD_UNITS_60_FPS:
298 case MAD_UNITS_75_FPS: 302 case MAD_UNITS_75_FPS:
299 return timer.seconds * (signed long) units + 303 return timer.seconds * (signed long) units +
300 (signed long) scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, 304 (signed long) scale_rational(timer.fraction, MAD_TIMER_RESOLUTION,
301 units); 305 units);
302 306
303 case MAD_UNITS_23_976_FPS: 307 case MAD_UNITS_23_976_FPS:
304 case MAD_UNITS_24_975_FPS: 308 case MAD_UNITS_24_975_FPS:
305 case MAD_UNITS_29_97_FPS: 309 case MAD_UNITS_29_97_FPS:
306 case MAD_UNITS_47_952_FPS: 310 case MAD_UNITS_47_952_FPS:
307 case MAD_UNITS_49_95_FPS: 311 case MAD_UNITS_49_95_FPS:
308 case MAD_UNITS_59_94_FPS: 312 case MAD_UNITS_59_94_FPS:
309 return (mad_timer_count(timer, -units) + 1) * 1000 / 1001; 313 return (mad_timer_count(timer, -units) + 1) * 1000 / 1001;
310 } 314 }
311 315
312 /* unsupported units */ 316 /* unsupported units */
313 return 0; 317 return 0;
314} 318}
315 319
316/* 320/*
317 * NAME:timer->fraction() 321 * NAME:timer->fraction()
318 * DESCRIPTION:return fractional part of timer in arbitrary terms 322 * DESCRIPTION:return fractional part of timer in arbitrary terms
319 */ 323 */
320unsigned long mad_timer_fraction(mad_timer_t timer, unsigned long fracparts) 324unsigned long mad_timer_fraction(mad_timer_t timer, unsigned long denom)
321{ 325{
322 timer = mad_timer_abs(timer); 326 timer = mad_timer_abs(timer);
323 327
324 switch (fracparts) { 328 switch (denom) {
325 case 0: 329 case 0:
326 return MAD_TIMER_RESOLUTION / timer.fraction; 330 return MAD_TIMER_RESOLUTION / timer.fraction;
327 331
328 case MAD_TIMER_RESOLUTION: 332 case MAD_TIMER_RESOLUTION:
329 return timer.fraction; 333 return timer.fraction;
330 334
331 default: 335 default:
332 return scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, fracparts); 336 return scale_rational(timer.fraction, MAD_TIMER_RESOLUTION, denom);
333 } 337 }
334} 338}
335 339
336/* 340/*
337 * NAME:timer->string() 341 * NAME:timer->string()
338 * DESCRIPTION:write a string representation of a timer using a template 342 * DESCRIPTION:write a string representation of a timer using a template
339 */ 343 */
340void mad_timer_string(mad_timer_t timer, 344void mad_timer_string(mad_timer_t timer,
341 char *dest, char const *format, enum mad_units units, 345 char *dest, char const *format, enum mad_units units,
342 enum mad_units fracunits, unsigned long subparts) 346 enum mad_units fracunits, unsigned long subparts)
343{ 347{
344 unsigned long hours, minutes, seconds, sub; 348 unsigned long hours, minutes, seconds, sub;
345 unsigned int frac; 349 unsigned int frac;
346 350
347 timer = mad_timer_abs(timer); 351 timer = mad_timer_abs(timer);
348 352
349 seconds = timer.seconds; 353 seconds = timer.seconds;
350 frac = sub = 0; 354 frac = sub = 0;
351 355
352 switch (fracunits) { 356 switch (fracunits) {
353 case MAD_UNITS_HOURS: 357 case MAD_UNITS_HOURS:
354 case MAD_UNITS_MINUTES: 358 case MAD_UNITS_MINUTES:
355 case MAD_UNITS_SECONDS: 359 case MAD_UNITS_SECONDS:
356 break; 360 break;
357 361
358 case MAD_UNITS_DECISECONDS: 362 case MAD_UNITS_DECISECONDS:
359 case MAD_UNITS_CENTISECONDS: 363 case MAD_UNITS_CENTISECONDS:
360 case MAD_UNITS_MILLISECONDS: 364 case MAD_UNITS_MILLISECONDS:
361 365
362 case MAD_UNITS_8000_HZ: 366 case MAD_UNITS_8000_HZ:
363 case MAD_UNITS_11025_HZ: 367 case MAD_UNITS_11025_HZ:
364 case MAD_UNITS_12000_HZ: 368 case MAD_UNITS_12000_HZ:
365 case MAD_UNITS_16000_HZ: 369 case MAD_UNITS_16000_HZ:
366 case MAD_UNITS_22050_HZ: 370 case MAD_UNITS_22050_HZ:
367 case MAD_UNITS_24000_HZ: 371 case MAD_UNITS_24000_HZ:
368 case MAD_UNITS_32000_HZ: 372 case MAD_UNITS_32000_HZ:
369 case MAD_UNITS_44100_HZ: 373 case MAD_UNITS_44100_HZ:
370 case MAD_UNITS_48000_HZ: 374 case MAD_UNITS_48000_HZ:
371 375
372 case MAD_UNITS_24_FPS: 376 case MAD_UNITS_24_FPS:
373 case MAD_UNITS_25_FPS: 377 case MAD_UNITS_25_FPS:
374 case MAD_UNITS_30_FPS: 378 case MAD_UNITS_30_FPS:
375 case MAD_UNITS_48_FPS: 379 case MAD_UNITS_48_FPS:
376 case MAD_UNITS_50_FPS: 380 case MAD_UNITS_50_FPS:
377 case MAD_UNITS_60_FPS: 381 case MAD_UNITS_60_FPS:
378 case MAD_UNITS_75_FPS: 382 case MAD_UNITS_75_FPS:
379 { 383 {
380 unsigned long fracparts; 384 unsigned long denom;
381 385
382 fracparts = MAD_TIMER_RESOLUTION / fracunits; 386 denom = MAD_TIMER_RESOLUTION / fracunits;
383 387
384 frac = timer.fraction / fracparts; 388 frac = timer.fraction / denom;
385 sub = scale_rational(timer.fraction % fracparts, fracparts, subparts); 389 sub = scale_rational(timer.fraction % denom, denom, subparts);
386 } 390 }
387 break; 391 break;
388 392
389 case MAD_UNITS_23_976_FPS: 393 case MAD_UNITS_23_976_FPS:
390 case MAD_UNITS_24_975_FPS: 394 case MAD_UNITS_24_975_FPS:
391 case MAD_UNITS_29_97_FPS: 395 case MAD_UNITS_29_97_FPS:
392 case MAD_UNITS_47_952_FPS: 396 case MAD_UNITS_47_952_FPS:
393 case MAD_UNITS_49_95_FPS: 397 case MAD_UNITS_49_95_FPS:
394 case MAD_UNITS_59_94_FPS: 398 case MAD_UNITS_59_94_FPS:
395 /* drop-frame encoding */ 399 /* drop-frame encoding */
396 /* N.B. this is only well-defined for MAD_UNITS_29_97_FPS */ 400 /* N.B. this is only well-defined for MAD_UNITS_29_97_FPS */
397 { 401 {
398 unsigned long frame, cycle, d, m; 402 unsigned long frame, cycle, d, m;
399 403
400 frame = mad_timer_count(timer, fracunits); 404 frame = mad_timer_count(timer, fracunits);
401 405
402 cycle = -fracunits * 60 * 10 - (10 - 1) * 2; 406 cycle = -fracunits * 60 * 10 - (10 - 1) * 2;
403 407
404 d = frame / cycle; 408 d = frame / cycle;
405 m = frame % cycle; 409 m = frame % cycle;
406 frame += (10 - 1) * 2 * d; 410 frame += (10 - 1) * 2 * d;
407 if (m > 2) 411 if (m > 2)
408 frame += 2 * ((m - 2) / (cycle / 10)); 412 frame += 2 * ((m - 2) / (cycle / 10));
409 413
410 frac = frame % -fracunits; 414 frac = frame % -fracunits;
411 seconds = frame / -fracunits; 415 seconds = frame / -fracunits;
412 } 416 }
413 break; 417 break;
414 } 418 }
415 419
416 switch (units) { 420 switch (units) {
417 case MAD_UNITS_HOURS: 421 case MAD_UNITS_HOURS:
418 minutes = seconds / 60; 422 minutes = seconds / 60;
419 hours = minutes / 60; 423 hours = minutes / 60;
420 424
421 sprintf(dest, format, 425 sprintf(dest, format,
422 hours, 426 hours,
423 (unsigned int) (minutes % 60), 427 (unsigned int) (minutes % 60),
424 (unsigned int) (seconds % 60), 428 (unsigned int) (seconds % 60),
425 frac, sub); 429 frac, sub);
426 break; 430 break;
427 431
428 case MAD_UNITS_MINUTES: 432 case MAD_UNITS_MINUTES:
429 minutes = seconds / 60; 433 minutes = seconds / 60;
430 434
431 sprintf(dest, format, 435 sprintf(dest, format,
432 minutes, 436 minutes,
433 (unsigned int) (seconds % 60), 437 (unsigned int) (seconds % 60),
434 frac, sub); 438 frac, sub);
435 break; 439 break;
436 440
437 case MAD_UNITS_SECONDS: 441 case MAD_UNITS_SECONDS:
438 sprintf(dest, format, 442 sprintf(dest, format,
439 seconds, 443 seconds,
440 frac, sub); 444 frac, sub);
441 break; 445 break;
442 446
443 case MAD_UNITS_23_976_FPS: 447 case MAD_UNITS_23_976_FPS:
444 case MAD_UNITS_24_975_FPS: 448 case MAD_UNITS_24_975_FPS:
445 case MAD_UNITS_29_97_FPS: 449 case MAD_UNITS_29_97_FPS:
446 case MAD_UNITS_47_952_FPS: 450 case MAD_UNITS_47_952_FPS:
447 case MAD_UNITS_49_95_FPS: 451 case MAD_UNITS_49_95_FPS:
448 case MAD_UNITS_59_94_FPS: 452 case MAD_UNITS_59_94_FPS:
449 if (fracunits < 0) { 453 if (fracunits < 0) {
450 /* not yet implemented */ 454 /* not yet implemented */
451 sub = 0; 455 sub = 0;
452 } 456 }
453 457
454 /* fall through */ 458 /* fall through */
455 459
456 case MAD_UNITS_DECISECONDS: 460 case MAD_UNITS_DECISECONDS:
457 case MAD_UNITS_CENTISECONDS: 461 case MAD_UNITS_CENTISECONDS:
458 case MAD_UNITS_MILLISECONDS: 462 case MAD_UNITS_MILLISECONDS:
459 463
460 case MAD_UNITS_8000_HZ: 464 case MAD_UNITS_8000_HZ:
461 case MAD_UNITS_11025_HZ: 465 case MAD_UNITS_11025_HZ:
462 case MAD_UNITS_12000_HZ: 466 case MAD_UNITS_12000_HZ:
463 case MAD_UNITS_16000_HZ: 467 case MAD_UNITS_16000_HZ:
464 case MAD_UNITS_22050_HZ: 468 case MAD_UNITS_22050_HZ:
465 case MAD_UNITS_24000_HZ: 469 case MAD_UNITS_24000_HZ:
466 case MAD_UNITS_32000_HZ: 470 case MAD_UNITS_32000_HZ:
467 case MAD_UNITS_44100_HZ: 471 case MAD_UNITS_44100_HZ:
468 case MAD_UNITS_48000_HZ: 472 case MAD_UNITS_48000_HZ:
469 473
470 case MAD_UNITS_24_FPS: 474 case MAD_UNITS_24_FPS:
471 case MAD_UNITS_25_FPS: 475 case MAD_UNITS_25_FPS:
472 case MAD_UNITS_30_FPS: 476 case MAD_UNITS_30_FPS:
473 case MAD_UNITS_48_FPS: 477 case MAD_UNITS_48_FPS:
474 case MAD_UNITS_50_FPS: 478 case MAD_UNITS_50_FPS:
475 case MAD_UNITS_60_FPS: 479 case MAD_UNITS_60_FPS:
476 case MAD_UNITS_75_FPS: 480 case MAD_UNITS_75_FPS:
477 sprintf(dest, format, mad_timer_count(timer, units), sub); 481 sprintf(dest, format, mad_timer_count(timer, units), sub);
478 break; 482 break;
479 } 483 }
480} 484}
diff --git a/core/multimedia/opieplayer/libmad/timer.h b/core/multimedia/opieplayer/libmad/timer.h
index 67fe16a..f8afb8e 100644
--- a/core/multimedia/opieplayer/libmad/timer.h
+++ b/core/multimedia/opieplayer/libmad/timer.h
@@ -1,100 +1,100 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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# ifndef LIBMAD_TIMER_H 22# ifndef LIBMAD_TIMER_H
23# define LIBMAD_TIMER_H 23# define LIBMAD_TIMER_H
24 24
25typedef struct { 25typedef struct {
26 signed long seconds; /* whole seconds */ 26 signed long seconds; /* whole seconds */
27 unsigned long fraction;/* 1/MAD_TIMER_RESOLUTION seconds */ 27 unsigned long fraction;/* 1/MAD_TIMER_RESOLUTION seconds */
28} mad_timer_t; 28} mad_timer_t;
29 29
30extern mad_timer_t const mad_timer_zero; 30extern mad_timer_t const mad_timer_zero;
31 31
32 # define MAD_TIMER_RESOLUTION352800000UL 32 # define MAD_TIMER_RESOLUTION352800000UL
33 33
34enum mad_units { 34enum mad_units {
35 MAD_UNITS_HOURS = -2, 35 MAD_UNITS_HOURS = -2,
36 MAD_UNITS_MINUTES = -1, 36 MAD_UNITS_MINUTES = -1,
37 MAD_UNITS_SECONDS = 0, 37 MAD_UNITS_SECONDS = 0,
38 38
39 /* metric units */ 39 /* metric units */
40 40
41 MAD_UNITS_DECISECONDS = 10, 41 MAD_UNITS_DECISECONDS = 10,
42 MAD_UNITS_CENTISECONDS = 100, 42 MAD_UNITS_CENTISECONDS = 100,
43 MAD_UNITS_MILLISECONDS = 1000, 43 MAD_UNITS_MILLISECONDS = 1000,
44 44
45 /* audio sample units */ 45 /* audio sample units */
46 46
47 MAD_UNITS_8000_HZ = 8000, 47 MAD_UNITS_8000_HZ = 8000,
48 MAD_UNITS_11025_HZ = 11025, 48 MAD_UNITS_11025_HZ = 11025,
49 MAD_UNITS_12000_HZ = 12000, 49 MAD_UNITS_12000_HZ = 12000,
50 50
51 MAD_UNITS_16000_HZ = 16000, 51 MAD_UNITS_16000_HZ = 16000,
52 MAD_UNITS_22050_HZ = 22050, 52 MAD_UNITS_22050_HZ = 22050,
53 MAD_UNITS_24000_HZ = 24000, 53 MAD_UNITS_24000_HZ = 24000,
54 54
55 MAD_UNITS_32000_HZ = 32000, 55 MAD_UNITS_32000_HZ = 32000,
56 MAD_UNITS_44100_HZ = 44100, 56 MAD_UNITS_44100_HZ = 44100,
57 MAD_UNITS_48000_HZ = 48000, 57 MAD_UNITS_48000_HZ = 48000,
58 58
59 /* video frame/field units */ 59 /* video frame/field units */
60 60
61 MAD_UNITS_24_FPS = 24, 61 MAD_UNITS_24_FPS = 24,
62 MAD_UNITS_25_FPS = 25, 62 MAD_UNITS_25_FPS = 25,
63 MAD_UNITS_30_FPS = 30, 63 MAD_UNITS_30_FPS = 30,
64 MAD_UNITS_48_FPS = 48, 64 MAD_UNITS_48_FPS = 48,
65 MAD_UNITS_50_FPS = 50, 65 MAD_UNITS_50_FPS = 50,
66 MAD_UNITS_60_FPS = 60, 66 MAD_UNITS_60_FPS = 60,
67 67
68 /* CD audio frames */ 68 /* CD audio frames */
69 69
70 MAD_UNITS_75_FPS = 75, 70 MAD_UNITS_75_FPS = 75,
71 71
72 /* video drop-frame units */ 72 /* video drop-frame units */
73 73
74 MAD_UNITS_23_976_FPS = -24, 74 MAD_UNITS_23_976_FPS = -24,
75 MAD_UNITS_24_975_FPS = -25, 75 MAD_UNITS_24_975_FPS = -25,
76 MAD_UNITS_29_97_FPS = -30, 76 MAD_UNITS_29_97_FPS = -30,
77 MAD_UNITS_47_952_FPS = -48, 77 MAD_UNITS_47_952_FPS = -48,
78 MAD_UNITS_49_95_FPS = -50, 78 MAD_UNITS_49_95_FPS = -50,
79 MAD_UNITS_59_94_FPS = -60 79 MAD_UNITS_59_94_FPS = -60
80}; 80};
81 81
82 # define mad_timer_reset(timer)(*(timer) = mad_timer_zero) 82 # define mad_timer_reset(timer)((void) (*(timer) = mad_timer_zero))
83 83
84int mad_timer_compare(mad_timer_t, mad_timer_t); 84int mad_timer_compare(mad_timer_t, mad_timer_t);
85 85
86 # define mad_timer_sign(timer)mad_timer_compare((timer), mad_timer_zero) 86 # define mad_timer_sign(timer)mad_timer_compare((timer), mad_timer_zero)
87 87
88void mad_timer_negate(mad_timer_t *); 88void mad_timer_negate(mad_timer_t *);
89mad_timer_t mad_timer_abs(mad_timer_t); 89mad_timer_t mad_timer_abs(mad_timer_t);
90 90
91void mad_timer_set(mad_timer_t *, unsigned long, unsigned long, unsigned long); 91void mad_timer_set(mad_timer_t *, unsigned long, unsigned long, unsigned long);
92void mad_timer_add(mad_timer_t *, mad_timer_t); 92void mad_timer_add(mad_timer_t *, mad_timer_t);
93void mad_timer_multiply(mad_timer_t *, signed long); 93void mad_timer_multiply(mad_timer_t *, signed long);
94 94
95signed long mad_timer_count(mad_timer_t, enum mad_units); 95signed long mad_timer_count(mad_timer_t, enum mad_units);
96unsigned long mad_timer_fraction(mad_timer_t, unsigned long); 96unsigned long mad_timer_fraction(mad_timer_t, unsigned long);
97void mad_timer_string(mad_timer_t, char *, char const *, 97void mad_timer_string(mad_timer_t, char *, char const *,
98 enum mad_units, enum mad_units, unsigned long); 98 enum mad_units, enum mad_units, unsigned long);
99 99
100# endif 100# endif
diff --git a/core/multimedia/opieplayer/libmad/version.c b/core/multimedia/opieplayer/libmad/version.c
index 413d54b..fb126f4 100644
--- a/core/multimedia/opieplayer/libmad/version.c
+++ b/core/multimedia/opieplayer/libmad/version.c
@@ -1,91 +1,91 @@
1/* 1/*
2 * mad - MPEG audio decoder 2 * libmad - MPEG audio decoder library
3 * Copyright (C) 2000-2001 Robert Leslie 3 * Copyright (C) 2000-2001 Robert Leslie
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
28# include "libmad_version.h" 28# include "libmad_version.h"
29 29
30char const mad_version[] = "MPEG Audio Decoder version " MAD_VERSION; 30char const mad_version[] = "MPEG Audio Decoder " MAD_VERSION;
31char const mad_copyright[] = "Copyright (C) " MAD_PUBLISHYEAR " " MAD_AUTHOR; 31char const mad_copyright[] = "Copyright (C) " MAD_PUBLISHYEAR " " MAD_AUTHOR;
32char const mad_author[] = MAD_AUTHOR " <" MAD_EMAIL ">"; 32char const mad_author[] = MAD_AUTHOR " <" MAD_EMAIL ">";
33 33
34char const mad_build[] = 34char const mad_build[] = ""
35# if defined(FPM_64BIT) 35# if defined(FPM_64BIT)
36 "FPM_64BIT " 36 "FPM_64BIT "
37# elif defined(FPM_INTEL) 37# elif defined(FPM_INTEL)
38 "FPM_INTEL " 38 "FPM_INTEL "
39# elif defined(FPM_ARM) 39# elif defined(FPM_ARM)
40 "FPM_ARM " 40 "FPM_ARM "
41# elif defined(FPM_MIPS) 41# elif defined(FPM_MIPS)
42 "FPM_MIPS " 42 "FPM_MIPS "
43# elif defined(FPM_SPARC) 43# elif defined(FPM_SPARC)
44 "FPM_SPARC " 44 "FPM_SPARC "
45# elif defined(FPM_PPC) 45# elif defined(FPM_PPC)
46 "FPM_PPC " 46 "FPM_PPC "
47# elif defined(FPM_DEFAULT) 47# elif defined(FPM_DEFAULT)
48 "FPM_DEFAULT " 48 "FPM_DEFAULT "
49# endif 49# endif
50 50
51# if defined(ASO_IMDCT) 51# if defined(ASO_IMDCT)
52 "ASO_IMDCT " 52 "ASO_IMDCT "
53# endif 53# endif
54# if defined(ASO_INTERLEAVE1) 54# if defined(ASO_INTERLEAVE1)
55 "ASO_INTERLEAVE1 " 55 "ASO_INTERLEAVE1 "
56# endif 56# endif
57# if defined(ASO_INTERLEAVE2) 57# if defined(ASO_INTERLEAVE2)
58 "ASO_INTERLEAVE2 " 58 "ASO_INTERLEAVE2 "
59# endif 59# endif
60# if defined(ASO_ZEROCHECK) 60# if defined(ASO_ZEROCHECK)
61 "ASO_ZEROCHECK " 61 "ASO_ZEROCHECK "
62# endif 62# endif
63 63
64# if defined(OPT_SPEED) 64# if defined(OPT_SPEED)
65 "OPT_SPEED " 65 "OPT_SPEED "
66# elif defined(OPT_ACCURACY) 66# elif defined(OPT_ACCURACY)
67 "OPT_ACCURACY " 67 "OPT_ACCURACY "
68# endif 68# endif
69 69
70# if defined(OPT_SSO) 70# if defined(OPT_SSO)
71 "OPT_SSO " 71 "OPT_SSO "
72# endif 72# endif
73 73
74# if defined(OPT_DCTO) /* never defined here */ 74# if defined(OPT_DCTO) /* never defined here */
75 "OPT_DCTO " 75 "OPT_DCTO "
76# endif 76# endif
77 77
78# if defined(OPT_STRICT) 78# if defined(OPT_STRICT)
79 "OPT_STRICT " 79 "OPT_STRICT "
80# endif 80# endif
81 81
82# if defined(EXPERIMENTAL) 82# if defined(EXPERIMENTAL)
83 "EXPERIMENTAL " 83 "EXPERIMENTAL "
84# endif 84# endif
85 85
86# if defined(DEBUG) 86# if defined(DEBUG)
87 "DEBUG " 87 "DEBUG "
88# elif defined(NDEBUG) 88# elif defined(NDEBUG)
89 "NDEBUG " 89 "NDEBUG "
90# endif 90# endif
91; 91;