1 /*
2 MPEG Maaate: An Australian MPEG audio analysis toolkit
3 Copyright (C) 2000 Commonwealth Scientific and Industrial Research Organisation
4 (CSIRO), Australia.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #if HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include "layer3.H"
26
27 // scalefactor bands for which a scfsi is transmitted (0-5,6-10...)
28 static const unsigned int
29 sfbtable[2][5] = {{0, 6, 11, 16, 21}, // long blocks
30 {0, 6, 12, 0, 0}}; // short blocks
31
32 // structure to store bitallocation for scale factors
33 static const unsigned int slen[2][16] =
34 {{0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
35 {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}};
36
37 // structure to take widths of each scalefactor band
38 struct SFBandIndex {
39 unsigned int l[23];
40 unsigned int s[14];
41 };
42
43 // width of each scale factor band (B.8 ISO/IEC 11172-3)
44 static const SFBandIndex sfBandIndex[6] = {
45 {{0,4,8,12,16,20,24,30,36,44,52,62,74,90,110,134,162,196,238,288,342,418,576},{0,4,8,12,16,22,30,40,52,66,84,106,136,192}},
46 {{0,4,8,12,16,20,24,30,36,42,50,60,72,88,106,128,156,190,230,276,330,384,576},{0,4,8,12,16,22,28,38,50,64,80,100,126,192}},
47 {{0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576},{0,4,8,12,16,22,30,42,58,78,104,138,180,192}},
48 {{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},{0,4,8,12,18,24,32,42,56,74,100,132,174,192}},
49 {{0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576},{0,4,8,12,18,26,36,48,62,80,104,136,180,192}},
50 {{0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},{0,4,8,12,18,26,36,48,62,80,104,134,174,192}}
51 };
52
53 // preemphasis table (B.6 ISO/IEC 11172-3)
54 static const unsigned int
55 pretab[22] = {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0};
56
57 // coefficients for aliasing reduction (B.9 ISO/IEC 11172-3)
58 static const double
59 Ci[8] = {-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037};
60
61 // mpeg2
62 static const unsigned int nr_of_sfb_block[6][3][4] = {
63 {{6, 5, 5, 5},{ 9, 9, 9, 9 },{6, 9, 9, 9}},
64 {{6, 5, 7, 3},{ 9, 9, 12, 6},{6, 9, 12, 6}},
65 {{11, 10, 0, 0},{ 18, 18, 0, 0},{15,18,0,0 }},
66 {{7, 7, 7, 0},{ 12, 12, 12, 0},{6, 15, 12, 0}},
67 {{6, 6, 6, 3},{12, 9, 9, 6},{6, 12, 9, 6}},
68 {{8, 8, 5, 0},{15,12,9,0},{6,18,9,0}}
69 };
70
71 #define HTN 34 // no of huffman tables
72 #define MXOFF 250 // for huffman decoding
73
74 // huffman code tables from B.7 ISO/IEC 11172-3
75 /* .table 0 0 0 0 0*/
76 /* table 0 has no tree data*/
77
78 /* .table 1 7 2 2 0*/
79 static const unsigned char treedata_1[] = {
80 0x2, 0x1, 0x0, 0x0, 0x2, 0x1, 0x0, 0x10, 0x2, 0x1, 0x0, 0x1, 0x0, 0x11
81 };
82
83 /* .table 2 17 3 3 0*/
84 static const unsigned char treedata_2[] = {
85 0x2, 0x1, 0x0, 0x0, 0x4, 0x1, 0x2, 0x1, 0x0, 0x10,
86 0x0, 0x1, 0x2, 0x1, 0x0, 0x11, 0x4, 0x1, 0x2, 0x1, 0x0, 0x20, 0x0, 0x21,
87 0x2, 0x1, 0x0, 0x12, 0x2, 0x1, 0x0, 0x2, 0x0, 0x22
88 };
89
90 /* .table 3 17 3 3 0*/
91 static const unsigned char treedata_3[] = {
92 0x4, 0x1, 0x2, 0x1, 0x0, 0x0, 0x0, 0x1, 0x2, 0x1,
93 0x0, 0x11, 0x2, 0x1, 0x0, 0x10, 0x4, 0x1, 0x2, 0x1, 0x0, 0x20, 0x0, 0x21,
94 0x2, 0x1, 0x0, 0x12, 0x2, 0x1, 0x0, 0x2, 0x0, 0x22
95 };
96
97 /* .table 4 0 0 0 0*/
98 /* table 4 has no tree data*/
99
100 /* .table 5 31 4 4 0*/
101 static const unsigned char treedata_5[] = {
102 0x2, 0x1, 0x0, 0x0, 0x4, 0x1, 0x2, 0x1, 0x0, 0x10,
103 0x0, 0x1, 0x2, 0x1, 0x0, 0x11, 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x20,
104 0x0, 0x2, 0x2, 0x1, 0x0, 0x21, 0x0, 0x12, 0x8, 0x1,
105 0x4, 0x1, 0x2, 0x1, 0x0, 0x22, 0x0, 0x30, 0x2, 0x1, 0x0, 0x3, 0x0, 0x13,
106 0x2, 0x1, 0x0, 0x31, 0x2, 0x1, 0x0, 0x32, 0x2, 0x1, 0x0, 0x23, 0x0, 0x33
107 };
108
109 /* .table 6 31 4 4 0*/
110 static const unsigned char treedata_6[] = {
111 0x6, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x0, 0x0, 0x10,
112 0x0, 0x11, 0x6, 0x1, 0x2, 0x1, 0x0, 0x1, 0x2, 0x1, 0x0, 0x20, 0x0, 0x21,
113 0x6, 0x1, 0x2, 0x1, 0x0, 0x12, 0x2, 0x1, 0x0, 0x2,
114 0x0, 0x22, 0x4, 0x1, 0x2, 0x1, 0x0, 0x31, 0x0, 0x13, 0x4, 0x1, 0x2, 0x1,
115 0x0, 0x30, 0x0, 0x32, 0x2, 0x1, 0x0, 0x23, 0x2, 0x1, 0x0, 0x3, 0x0, 0x33
116 };
117
118 /* .table 7 71 6 6 0*/
119 static const unsigned char treedata_7[] = {
120 0x2, 0x1, 0x0, 0x0, 0x4, 0x1, 0x2, 0x1, 0x0, 0x10, 0x0,
121 0x1, 0x8, 0x1, 0x2, 0x1, 0x0, 0x11, 0x4, 0x1, 0x2, 0x1, 0x0, 0x20,
122 0x0, 0x2, 0x0, 0x21, 0x12, 0x1, 0x6, 0x1, 0x2, 0x1, 0x0,
123 0x12, 0x2, 0x1, 0x0, 0x22, 0x0, 0x30, 0x4, 0x1, 0x2, 0x1, 0x0, 0x31,
124 0x0, 0x13, 0x4, 0x1, 0x2, 0x1, 0x0, 0x3, 0x0, 0x32, 0x2,
125 0x1, 0x0, 0x23, 0x0, 0x4, 0xa, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x40,
126 0x0, 0x41, 0x2, 0x1, 0x0, 0x14, 0x2, 0x1, 0x0, 0x42, 0x0,
127 0x24, 0xc, 0x1, 0x6, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x33, 0x0, 0x43,
128 0x0, 0x50, 0x4, 0x1, 0x2, 0x1, 0x0, 0x34, 0x0, 0x5, 0x0,
129 0x51, 0x6, 0x1, 0x2, 0x1, 0x0, 0x15, 0x2, 0x1, 0x0, 0x52, 0x0, 0x25,
130 0x4, 0x1, 0x2, 0x1, 0x0, 0x44, 0x0, 0x35, 0x4,
131 0x1, 0x2, 0x1, 0x0, 0x53, 0x0, 0x54, 0x2, 0x1, 0x0, 0x45, 0x0, 0x55
132 };
133
134 /* .table 8 71 6 6 0*/
135 static const unsigned char treedata_8[] = {
136 0x6, 0x1, 0x2, 0x1, 0x0, 0x0, 0x2, 0x1, 0x0, 0x10, 0x0,
137 0x1, 0x2, 0x1, 0x0, 0x11, 0x4, 0x1, 0x2, 0x1, 0x0, 0x21, 0x0, 0x12,
138 0xe, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x20, 0x0, 0x2,
139 0x2, 0x1, 0x0, 0x22, 0x4, 0x1, 0x2, 0x1, 0x0, 0x30, 0x0, 0x3, 0x2, 0x1,
140 0x0, 0x31, 0x0, 0x13, 0xe, 0x1, 0x8, 0x1, 0x4, 0x1, 0x2,
141 0x1, 0x0, 0x32, 0x0, 0x23, 0x2, 0x1, 0x0, 0x40, 0x0, 0x4, 0x2, 0x1,
142 0x0, 0x41, 0x2, 0x1, 0x0, 0x14, 0x0, 0x42, 0xc, 0x1,
143 0x6, 0x1, 0x2, 0x1, 0x0, 0x24, 0x2, 0x1, 0x0, 0x33, 0x0, 0x50, 0x4, 0x1,
144 0x2, 0x1, 0x0, 0x43, 0x0, 0x34, 0x0, 0x51, 0x6, 0x1,
145 0x2, 0x1, 0x0, 0x15, 0x2, 0x1, 0x0, 0x5, 0x0, 0x52, 0x6, 0x1, 0x2, 0x1,
146 0x0, 0x25, 0x2, 0x1, 0x0, 0x44, 0x0, 0x35, 0x2,
147 0x1, 0x0, 0x53, 0x2, 0x1, 0x0, 0x45, 0x2, 0x1, 0x0, 0x54, 0x0, 0x55
148 };
149
150 /* .table 9 71 6 6 0*/
151 static const unsigned char treedata_9[] = {
152 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x0, 0x0, 0x10, 0x2,
153 0x1, 0x0, 0x1, 0x0, 0x11, 0xa, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x20,
154 0x0, 0x21, 0x2, 0x1, 0x0, 0x12, 0x2, 0x1, 0x0, 0x2,
155 0x0, 0x22, 0xc, 0x1, 0x6, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x30, 0x0, 0x3,
156 0x0, 0x31, 0x2, 0x1, 0x0, 0x13, 0x2, 0x1, 0x0, 0x32,
157 0x0, 0x23, 0xc, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x41, 0x0, 0x14, 0x4, 0x1,
158 0x2, 0x1, 0x0, 0x40, 0x0, 0x33, 0x2, 0x1, 0x0, 0x42,
159 0x0, 0x24, 0xa, 0x1, 0x6, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x4, 0x0, 0x50,
160 0x0, 0x43, 0x2, 0x1, 0x0, 0x34, 0x0, 0x51, 0x8, 0x1,
161 0x4, 0x1, 0x2, 0x1, 0x0, 0x15, 0x0, 0x52, 0x2, 0x1, 0x0, 0x25, 0x0, 0x44,
162 0x6, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x5, 0x0,
163 0x54, 0x0, 0x53, 0x2, 0x1, 0x0, 0x35, 0x2, 0x1, 0x0, 0x45, 0x0, 0x55
164 };
165
166 /*.table 10 127 8 8 0*/
167 static const unsigned char treedata_10[] = {
168 0x2, 0x1, 0x0, 0x0, 0x4, 0x1, 0x2, 0x1, 0x0, 0x10,
169 0x0, 0x1, 0xa, 0x1, 0x2, 0x1, 0x0, 0x11, 0x4, 0x1, 0x2, 0x1, 0x0, 0x20,
170 0x0, 0x2, 0x2, 0x1, 0x0, 0x21, 0x0, 0x12, 0x1c, 0x1,
171 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x22, 0x0, 0x30, 0x2, 0x1, 0x0, 0x31,
172 0x0, 0x13, 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x3,
173 0x0, 0x32, 0x2, 0x1, 0x0, 0x23, 0x0, 0x40, 0x4, 0x1, 0x2, 0x1, 0x0, 0x41,
174 0x0, 0x14, 0x4, 0x1, 0x2, 0x1, 0x0, 0x4, 0x0, 0x33,
175 0x2, 0x1, 0x0, 0x42, 0x0, 0x24, 0x1c, 0x1, 0xa, 0x1, 0x6, 0x1, 0x4, 0x1,
176 0x2, 0x1, 0x0, 0x50, 0x0, 0x5, 0x0, 0x60, 0x2, 0x1,
177 0x0, 0x61, 0x0, 0x16, 0xc, 0x1, 0x6, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x43,
178 0x0, 0x34, 0x0, 0x51, 0x2, 0x1, 0x0, 0x15, 0x2, 0x1,
179 0x0, 0x52, 0x0, 0x25, 0x4, 0x1, 0x2, 0x1, 0x0, 0x26, 0x0, 0x36, 0x0, 0x71,
180 0x14, 0x1, 0x8, 0x1, 0x2, 0x1, 0x0, 0x17, 0x4, 0x1,
181 0x2, 0x1, 0x0, 0x44, 0x0, 0x53, 0x0, 0x6, 0x6, 0x1, 0x4, 0x1, 0x2, 0x1,
182 0x0, 0x35, 0x0, 0x45, 0x0, 0x62, 0x2, 0x1, 0x0, 0x70,
183 0x2, 0x1, 0x0, 0x7, 0x0, 0x64, 0xe, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x72,
184 0x0, 0x27, 0x6, 0x1, 0x2, 0x1, 0x0, 0x63, 0x2, 0x1,
185 0x0, 0x54, 0x0, 0x55, 0x2, 0x1, 0x0, 0x46, 0x0, 0x73, 0x8, 0x1, 0x4, 0x1,
186 0x2, 0x1, 0x0, 0x37, 0x0, 0x65, 0x2, 0x1, 0x0, 0x56,
187 0x0, 0x74, 0x6, 0x1, 0x2, 0x1, 0x0, 0x47, 0x2, 0x1, 0x0, 0x66, 0x0, 0x75,
188 0x4, 0x1, 0x2, 0x1, 0x0, 0x57, 0x0, 0x76, 0x2, 0x1, 0x0, 0x67, 0x0, 0x77
189 };
190
191 /* .table 11 127 8 8 0*/
192 static const unsigned char treedata_11[] = {
193 0x6, 0x1, 0x2, 0x1, 0x0, 0x0, 0x2, 0x1, 0x0, 0x10,
194 0x0, 0x1, 0x8, 0x1, 0x2, 0x1, 0x0, 0x11, 0x4, 0x1, 0x2, 0x1, 0x0, 0x20,
195 0x0, 0x2, 0x0, 0x12, 0x18, 0x1, 0x8, 0x1, 0x2, 0x1,
196 0x0, 0x21, 0x2, 0x1, 0x0, 0x22, 0x2, 0x1, 0x0, 0x30, 0x0, 0x3, 0x4, 0x1,
197 0x2, 0x1, 0x0, 0x31, 0x0, 0x13, 0x4, 0x1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214 };
215
216 /* .table 12 127 8 8 0*/
217 static const unsigned char treedata_12[] = {
218 0xc, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x10, 0x0, 0x1,
219 0x2, 0x1, 0x0, 0x11, 0x2, 0x1, 0x0, 0x0, 0x2, 0x1, 0x0, 0x20, 0x0, 0x2,
220 0x10, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x21, 0x0, 0x12,
221 0x4, 0x1, 0x2, 0x1, 0x0, 0x22, 0x0, 0x31, 0x2, 0x1, 0x0, 0x13, 0x2, 0x1,
222 0x0, 0x30, 0x2, 0x1, 0x0, 0x3, 0x0, 0x40, 0x1a, 0x1,
223 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x32, 0x0, 0x23, 0x2, 0x1, 0x0, 0x41,
224 0x0, 0x33, 0xa, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x14,
225 0x0, 0x42, 0x2, 0x1, 0x0, 0x24, 0x2, 0x1, 0x0, 0x4, 0x0, 0x50, 0x4, 0x1,
226 0x2, 0x1, 0x0, 0x43, 0x0, 0x34, 0x2, 0x1, 0x0, 0x51,
227 0x0, 0x15, 0x1c, 0x1, 0xe, 0x1, 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x52,
228 0x0, 0x25, 0x2, 0x1, 0x0, 0x53, 0x0, 0x35, 0x4, 0x1,
229 0x2, 0x1, 0x0, 0x60, 0x0, 0x16, 0x0, 0x61, 0x4, 0x1, 0x2, 0x1, 0x0, 0x62,
230 0x0, 0x26, 0x6, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x5,
231 0x0, 0x6, 0x0, 0x44, 0x2, 0x1, 0x0, 0x54, 0x0, 0x45, 0x12, 0x1, 0xa, 0x1,
232 0x4, 0x1, 0x2, 0x1, 0x0, 0x63, 0x0, 0x36, 0x4, 0x1,
233 0x2, 0x1, 0x0, 0x70, 0x0, 0x7, 0x0, 0x71, 0x4, 0x1, 0x2, 0x1, 0x0, 0x17,
234 0x0, 0x64, 0x2, 0x1, 0x0, 0x46, 0x0, 0x72, 0xa, 0x1,
235 0x6, 0x1, 0x2, 0x1, 0x0, 0x27, 0x2, 0x1, 0x0, 0x55, 0x0, 0x73, 0x2, 0x1,
236 0x0, 0x37, 0x0, 0x56, 0x8, 0x1, 0x4, 0x1, 0x2, 0x1,
237 0x0, 0x65, 0x0, 0x74, 0x2, 0x1, 0x0, 0x47, 0x0, 0x66, 0x4, 0x1, 0x2, 0x1,
238 0x0, 0x75, 0x0, 0x57, 0x2, 0x1, 0x0, 0x76, 0x2, 0x1, 0x0, 0x67, 0x0, 0x77
239 };
240
241 /* .table 13 511 16 16 0*/
242 static const unsigned char treedata_13[] = {
243 0x2, 0x1, 0x0, 0x0, 0x6, 0x1, 0x2, 0x1, 0x0, 0x10, 0x2, 0x1, 0x0, 0x1, 0x0,
244 0x11, 0x1c, 0x1, 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x20, 0x0, 0x2, 0x2, 0x1,
245 0x0, 0x21, 0x0, 0x12, 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x22, 0x0, 0x30,
246 0x2, 0x1, 0x0, 0x3, 0x0, 0x31, 0x6, 0x1, 0x2, 0x1, 0x0, 0x13, 0x2, 0x1,
247 0x0, 0x32, 0x0, 0x23, 0x4, 0x1, 0x2, 0x1, 0x0, 0x40, 0x0, 0x4, 0x0, 0x41,
248 0x46, 0x1, 0x1c, 0x1, 0xe, 0x1, 0x6, 0x1, 0x2, 0x1, 0x0, 0x14, 0x2, 0x1,
249 0x0, 0x33, 0x0, 0x42, 0x4, 0x1, 0x2, 0x1, 0x0, 0x24, 0x0, 0x50, 0x2, 0x1,
250 0x0, 0x43, 0x0, 0x34, 0x4, 0x1, 0x2, 0x1, 0x0, 0x51, 0x0, 0x15, 0x4, 0x1,
251 0x2, 0x1, 0x0, 0x5, 0x0, 0x52, 0x2, 0x1, 0x0, 0x25, 0x2, 0x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x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x9e, 0x0, 0xae, 0x0, 0xcc, 0x2, 0x1,
308 0x0, 0xf8, 0x0, 0x8f, 0x12, 0x1, 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0xdb,
309 0x0, 0xbd, 0x2, 0x1, 0x0, 0xea, 0x0, 0xf9, 0x4, 0x1, 0x2, 0x1, 0x0, 0x9f,
310 0x0, 0xeb, 0x2, 0x1, 0x0, 0xbe, 0x2, 0x1, 0x0, 0xcd, 0x0, 0xfa, 0xe, 0x1,
311 0x4, 0x1, 0x2, 0x1, 0x0, 0xdd, 0x0, 0xec, 0x6, 0x1, 0x4, 0x1, 0x2, 0x1,
312 0x0, 0xe9, 0x0, 0xaf, 0x0, 0xdc, 0x2, 0x1, 0x0, 0xce, 0x0, 0xfb, 0x8, 0x1,
313 0x4, 0x1, 0x2, 0x1, 0x0, 0xbf, 0x0, 0xde, 0x2, 0x1, 0x0, 0xcf, 0x0, 0xee,
314 0x4, 0x1, 0x2, 0x1, 0x0, 0xdf, 0x0, 0xef, 0x2, 0x1, 0x0, 0xff, 0x2, 0x1,
315 0x0, 0xed, 0x2, 0x1, 0x0, 0xfd, 0x2, 0x1, 0x0, 0xfc, 0x0, 0xfe
316 };
317
318 /* .table 14 0 0 0 0*/
319 /* table 14 has no tree data*/
320
321 /* .table 15 511 16 16 0*/
322 static const unsigned char treedata_15[] = {
323 0x10, 0x1, 0x6, 0x1, 0x2, 0x1, 0x0, 0x0, 0x2, 0x1, 0x0, 0x10, 0x0, 0x1, 0x2,
324 0x1, 0x0, 0x11, 0x4, 0x1, 0x2, 0x1, 0x0, 0x20, 0x0, 0x2, 0x2, 0x1, 0x0, 0x21,
325 0x0, 0x12, 0x32, 0x1, 0x10, 0x1, 0x6, 0x1, 0x2, 0x1, 0x0, 0x22, 0x2, 0x1,
326 0x0, 0x30, 0x0, 0x31, 0x6, 0x1, 0x2, 0x1, 0x0, 0x13, 0x2, 0x1, 0x0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 0x0, 0x7f,
469 0xc, 0x1, 0x6, 0x1, 0x2, 0x1, 0x0, 0x8f, 0x2, 0x1, 0x0, 0xf8, 0x0, 0xf9,
470 0x4, 0x1, 0x2, 0x1, 0x0, 0x9f, 0x0, 0xfa, 0x0, 0xaf, 0x8, 0x1, 0x4, 0x1,
471 0x2, 0x1, 0x0, 0xfb, 0x0, 0xbf, 0x2, 0x1, 0x0, 0xfc, 0x0, 0xcf, 0x4, 0x1,
472 0x2, 0x1, 0x0, 0xfd, 0x0, 0xdf, 0x2, 0x1, 0x0, 0xfe, 0x0, 0xef
473 };
474
475 /* .table 17 511 16 16 2*/
476 /* .reference 16*/
477
478 /* .table 18 511 16 16 3*/
479 /* .reference 16*/
480
481 /* .table 19 511 16 16 4*/
482 /* .reference 16*/
483
484 /* .table 20 511 16 16 6*/
485 /* .reference 16*/
486
487 /* .table 21 511 16 16 8*/
488 /* .reference 16*/
489
490 /* .table 22 511 16 16 10*/
491 /* .reference 16*/
492
493 /* .table 23 511 16 16 13*/
494 /* .reference 16*/
495
496 /* .table 24 512 16 16 4*/
497 static const unsigned char treedata_24[] = {
498 0x3c, 0x1, 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x0, 0x0, 0x10, 0x2, 0x1, 0x0,
499 0x1, 0x0, 0x11, 0xe, 0x1, 0x6, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x20, 0x0, 0x2,
500 0x0, 0x21, 0x2, 0x1, 0x0, 0x12, 0x2, 0x1, 0x0, 0x22, 0x2, 0x1, 0x0, 0x30,
501 0x0, 0x3, 0xe, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x31, 0x0, 0x13, 0x4, 0x1,
502 0x2, 0x1, 0x0, 0x32, 0x0, 0x23, 0x4, 0x1, 0x2, 0x1, 0x0, 0x40, 0x0, 0x4,
503 0x0, 0x41, 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x14, 0x0, 0x33, 0x2, 0x1,
504 0x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0, 0xbd, 0x10, 0x1, 0x8, 0x1, 0x4, 0x1,
560 0x2, 0x1, 0x0, 0xea, 0x0, 0xae, 0x2, 0x1, 0x0, 0xdc, 0x0, 0xcd, 0x4, 0x1,
561 0x2, 0x1, 0x0, 0xeb, 0x0, 0xbe, 0x2, 0x1, 0x0, 0xdd, 0x0, 0xec, 0x8, 0x1,
562 0x4, 0x1, 0x2, 0x1, 0x0, 0xce, 0x0, 0xed, 0x2, 0x1, 0x0, 0xde, 0x0, 0xee,
563 0x0, 0xf, 0x4, 0x1, 0x2, 0x1, 0x0, 0xf0, 0x0, 0x1f, 0x0, 0xf1, 0x4, 0x1,
564 0x2, 0x1, 0x0, 0xf2, 0x0, 0x2f, 0x2, 0x1, 0x0, 0xf3, 0x0, 0x3f, 0x12, 0x1,
565 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0xf4, 0x0, 0x4f, 0x2, 0x1, 0x0, 0xf5,
566 0x0, 0x5f, 0x4, 0x1, 0x2, 0x1, 0x0, 0xf6, 0x0, 0x6f, 0x2, 0x1, 0x0, 0xf7,
567 0x2, 0x1, 0x0, 0x7f, 0x0, 0x8f, 0xa, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0xf8,
568 0x0, 0xf9, 0x4, 0x1, 0x2, 0x1, 0x0, 0x9f, 0x0, 0xaf, 0x0, 0xfa, 0x8, 0x1,
569 0x4, 0x1, 0x2, 0x1, 0x0, 0xfb, 0x0, 0xbf, 0x2, 0x1, 0x0, 0xfc, 0x0, 0xcf,
570 0x4, 0x1, 0x2, 0x1, 0x0, 0xfd, 0x0, 0xdf, 0x2, 0x1, 0x0, 0xfe, 0x0, 0xef
571 };
572
573 /* .table 25 512 16 16 5*/
574 /* .reference 24*/
575
576 /* .table 26 512 16 16 6*/
577 /* .reference 24*/
578
579 /* .table 27 512 16 16 7*/
580 /* .reference 24*/
581
582 /* .table 28 512 16 16 8*/
583 /* .reference 24*/
584
585 /* .table 29 512 16 16 9*/
586 /* .reference 24*/
587
588 /* .table 30 512 16 16 11*/
589 /* .reference 24*/
590
591 /* .table 31 512 16 16 13*/
592 /* .reference 24*/
593
594 /* .table 32 31 1 16 0*/
595 static const unsigned char treedata_32[] = {
596 0x2, 0x1, 0x0, 0x0, 0x8, 0x1, 0x4, 0x1, 0x2, 0x1,
597 0x0, 0x8, 0x0, 0x4, 0x2, 0x1, 0x0, 0x1, 0x0, 0x2, 0x8, 0x1, 0x4, 0x1,
598 0x2, 0x1, 0x0, 0xc, 0x0, 0xa, 0x2, 0x1, 0x0, 0x3,
599 0x0, 0x6, 0x6, 0x1, 0x2, 0x1, 0x0, 0x9, 0x2, 0x1, 0x0, 0x5, 0x0, 0x7,
600 0x4, 0x1, 0x2, 0x1, 0x0, 0xe, 0x0, 0xd, 0x2, 0x1, 0x0, 0xf, 0x0, 0xb,
601 };
602
603 /* .table 33 31 1 16 0*/
604 static const unsigned char treedata_33[] = {
605 0x10, 0x1, 0x8, 0x1, 0x4, 0x1, 0x2, 0x1, 0x0, 0x0,
606 0x0, 0x1, 0x2, 0x1, 0x0, 0x2, 0x0, 0x3, 0x4, 0x1, 0x2, 0x1, 0x0, 0x4,
607 0x0, 0x5, 0x2, 0x1, 0x0, 0x6, 0x0, 0x7, 0x8, 0x1,
608 0x4, 0x1, 0x2, 0x1, 0x0, 0x8, 0x0, 0x9, 0x2, 0x1, 0x0, 0xa, 0x0, 0xb,
609 0x4, 0x1, 0x2, 0x1, 0x0, 0xc, 0x0, 0xd, 0x2, 0x1, 0x0, 0xe, 0x0, 0xf
610 };
611
612 // Information needed to recover .table lines
613 struct huffinfo {
614 int treelen; // 3rd col
615 int xlen; // 4th col
616 int ylen; // 5th col
617 int linbits; // 6th col
618 // Information for .treedata or .reference lines
619 int ref; // .reference table, or .treedata if -1
620 const unsigned char *data; // ptr to treedata array
621 };
622
623 static const huffinfo hufftab[HTN] = {
624 { 0, 0, 0, 0, -1, NULL}, /* 0*/
625 { 7, 2, 2, 0, -1, treedata_1}, /* 1*/
626 { 17, 3, 3, 0, -1, treedata_2}, /* 2*/
627 { 17, 3, 3, 0, -1, treedata_3}, /* 3*/
628 { 0, 0, 0, 0, -1, NULL}, /* 4*/
629 { 31, 4, 4, 0, -1, treedata_5}, /* 5*/
630 { 31, 4, 4, 0, -1, treedata_6}, /* 6*/
631 { 71, 6, 6, 0, -1, treedata_7}, /* 7*/
632 { 71, 6, 6, 0, -1, treedata_8}, /* 8*/
633 { 71, 6, 6, 0, -1, treedata_9}, /* 9*/
634 {127, 8, 8, 0, -1, treedata_10}, /* 10*/
635 {127, 8, 8, 0, -1, treedata_11}, /* 11*/
636 {127, 8, 8, 0, -1, treedata_12}, /* 12*/
637 {511, 16, 16, 0, -1, treedata_13}, /* 13*/
638 { 0, 0, 0, 0, -1, NULL}, /* 14*/
639 {511, 16, 16, 0, -1, treedata_15}, /* 15*/
640 {511, 16, 16, 1, -1, treedata_16}, /* 16*/
641 {511, 16, 16, 2, 16, NULL}, /* 17*/
642 {511, 16, 16, 3, 16, NULL}, /* 18*/
643 {511, 16, 16, 4, 16, NULL}, /* 19*/
644 {511, 16, 16, 6, 16, NULL}, /* 20*/
645 {511, 16, 16, 8, 16, NULL}, /* 21*/
646 {511, 16, 16, 10, 16, NULL}, /* 22*/
647 {511, 16, 16, 13, 16, NULL}, /* 23*/
648 {512, 16, 16, 4, -1, treedata_24}, /* 24*/
649 {512, 16, 16, 5, 24, NULL}, /* 25*/
650 {512, 16, 16, 6, 24, NULL}, /* 26*/
651 {512, 16, 16, 7, 24, NULL}, /* 27*/
652 {512, 16, 16, 8, 24, NULL}, /* 28*/
653 {512, 16, 16, 9, 24, NULL}, /* 29*/
654 {512, 16, 16, 11, 24, NULL}, /* 30*/
655 {512, 16, 16, 13, 24, NULL}, /* 31*/
656 { 31, 1, 16, 0, -1, treedata_32}, /* 32*/
657 { 31, 1, 16, 0, -1, treedata_33} /* 33*/
658 };
659
660 struct CSAPI_MPEG huffcodetab {
661 char tablename[3]; // string, containing table_description
662 unsigned int xlen; // max. x-index+
663 unsigned int ylen; // max. y-index+
664 unsigned int linbits; // number of linbits
665 unsigned int linmax; // max number to be stored in linbits
666 int ref; // a positive value indicates a reference
667 unsigned char(*val)[2]; // decoder tree
668 unsigned int treelen; // length of decoder tree
669 };
670
671 // huffman encode table
672 static huffcodetab ht[HTN];
673
674 //--------------------------------------------------------------------------
675
676 // constructor
677 CSAPI_MPEG
Layer3(MPEGfile * mp)678 Layer3::Layer3 (MPEGfile *mp)
679 {
680 // set reference to audio frame handler
681 frame = mp;
682
683 // initialize buffer indexes
684 bufstart=bufend=whichbit=0;
685
686 // initialize huffman decoding
687 if (!read_decoder_table()) {
688 cerr << "MaaateP: Error reading huffman decoder table" << endl;
689 exit(1);
690 }
691
692 #ifdef DEBUG
693 noReadBits=0;
694 #endif
695
696 return;
697 }
698
699 // initialize the huffman decoder table
700 CSAPI_MPEG bool
read_decoder_table()701 Layer3::read_decoder_table()
702 {
703 const unsigned char *p;
704 int nn, t;
705 unsigned int i;
706 int n;
707 for (n=0; n<HTN; n++) {
708 sprintf(ht[n].tablename, "%d", n);
709 ht[n].treelen = hufftab[n].treelen;
710 ht[n].xlen = hufftab[n].xlen;
711 ht[n].ylen = hufftab[n].ylen;
712 ht[n].linbits = hufftab[n].linbits;
713 ht[n].linmax = (1 << ht[n].linbits) - 1;
714
715 // Check table name
716 // nn;
717 sscanf(ht[n].tablename, "%u", &nn);
718 if (nn != n) {
719 cerr << "MaaateP: wrong table number " << n << endl;
720 return false;
721 }
722
723 t = hufftab[n].ref;
724 if (t >= 0) {
725 ht[n].ref = t;
726 ht[n].val = ht[t].val;
727 ht[n].treelen = ht[t].treelen;
728 if ((ht[n].xlen != ht[t].xlen) || (ht[n].ylen != ht[t].ylen)) {
729 cerr << "MaaateP: wrong table reference " << n << endl;
730 return false;
731 };
732 } else if (t == -1) {
733 ht[n].ref = -1;
734 ht[n].val = (unsigned char (*)[2])
735 calloc(2 * (ht[n].treelen)+1, sizeof(unsigned char));
736 if (ht[n].val == NULL) {
737 cerr << "MaaateP: heap error while loading table " << n << endl;
738 cerr << "attempting calloc "
739 << 2 * (ht[n].treelen) << "\t"
740 << sizeof(unsigned char) << endl;
741 return false;
742 }
743 p = hufftab[n].data;
744 for (i = 0; i < ht[n].treelen; i++) {
745 ht[n].val[i][0] = *p++;
746 ht[n].val[i][1] = *p++;
747 }
748 } else {
749 cerr << "MaaateP: huffman decodertable error at table " << n << endl;
750 return false;
751 }
752 }
753 return (n==HTN);
754 }
755
756 // parse audio data of layer 3 frame
757 CSAPI_MPEG bool
parse_data(DecodeLevel decode)758 Layer3::parse_data(DecodeLevel decode)
759 {
760 // parse side information
761 decode_sideinfo();
762
763 // initialize/reset counters
764 count1_vals[0][0] = count1_vals[0][1] = 0; // counts no count1 values
765 count1_vals[1][0] = count1_vals[1][1] = 0; // within frame
766 spectral_bitsread=0; // counts no huffman bits read in frame
767 main_data_bitsread=0; // counts no of main_data bits read in frame
768
769 // check crc checksum
770 if (frame->crcprotected()) {
771 if (frame->checksum != calc_CRC()) {
772 cerr << "MaaateP: WARNING: wrong checksum" << endl;
773 // return false;
774 }
775 }
776
777 // set start reading of buffer to main_data_begin
778 if (!setbufstart()) {
779 // if not enough main_data available, skip frame
780 savetointerbuffer();
781 return false;
782 }
783
784 const int s_gr = granules();
785 const int s_ch = frame->channels();
786 const int s_ver = frame->version();
787 int gr, ch;
788 for (gr=0; gr<s_gr; gr++) {
789 for (ch=0; ch<s_ch; ch++) {
790
791 // parse scalefactor information
792 if (s_ver == MPEG1) {
793 decode_scale_I(gr, ch);
794 } else { // MPEG2
795 decode_scale_II(gr,ch);
796 }
797
798 // parse huffman encoded sample data
799 decode_huffmanbits(gr, ch);
800
801 if (decode > dec_fields) {
802 // restore the subband samples
803 restore_samples(gr, ch);
804 }
805
806 }
807 if (decode > dec_fields) {
808 // joint stereo processing
809 decode_jstereo(gr);
810
811 if (decode > dec_subsubbands) {
812 for (ch=0; ch<s_ch; ch++) {
813 // reorder spectrum
814 reorder(gr, ch);
815
816 // alias reduction
817 antialias(gr, ch);
818
819 // hybrid filter synthesis
820 hybrid(gr, ch);
821
822 if (decode > dec_subbands) {
823 // polyphase filterband synthesis: creates pcm samples
824 polyphase(gr, ch);
825 }
826 }
827 }
828 }
829 }
830
831 #ifdef DEBUG
832 noReadBits += main_data_bitsread;
833 // cerr << "noReadBits=" << noReadBits << endl;
834 #endif
835
836 // save remaining bytes from frame->buffer into intermediate buffer
837 savetointerbuffer();
838 return true;
839 }
840
841 // parses layerIII-specific side information header
842 CSAPI_MPEG void
decode_sideinfo()843 Layer3::decode_sideinfo()
844 {
845 const int s_ch = frame->channels();
846 int ch, gr, i;
847 unsigned int scfc;
848 if (frame->version() == MPEG1) {
849 // start of main_data (offset before header and stored in inter_buffer)
850 // max value of main_data: MAX_INTER_BUFSIZE
851 si.main_data_begin = frame->readbitsfrombuffer(9);
852
853 // for private use
854 if (s_ch == 1) {
855 si.private_bits = frame->readbitsfrombuffer(5);
856 } else {
857 si.private_bits = frame->readbitsfrombuffer(3);
858 }
859
860 // scale factor selection information
861 for (ch = 0; ch < s_ch; ch++) {
862 for (scfc = 0; scfc < 4; scfc++) { // scfsi-classes
863 si.ch[ch].scfsi[scfc] = frame->readbitsfrombuffer(1);
864 }
865 }
866
867 for (gr = 0; gr < 2 ; gr++) {
868 for (ch = 0; ch < s_ch; ch++) {
869 // no. of main_data bits used for scalefactors and huffman data
870 si.ch[ch].gr[gr].part2_3_length
871 = frame->readbitsfrombuffer(12);
872
873 // no. of value pairs at low frequencies (<8191)
874 si.ch[ch].gr[gr].big_values = frame->readbitsfrombuffer(9);
875
876 // quantizer step size information
877 si.ch[ch].gr[gr].global_gain = frame->readbitsfrombuffer(8);
878
879 // no. of bits used for scalefactors
880 si.ch[ch].gr[gr].scalefac_compress
881 = frame->readbitsfrombuffer(4);
882
883 // window switching flag
884 si.ch[ch].gr[gr].window_switching_flag
885 = frame->readbitsfrombuffer(1);
886
887 if (si.ch[ch].gr[gr].window_switching_flag) {
888 // window type for granule
889 si.ch[ch].gr[gr].block_type
890 = frame->readbitsfrombuffer(2);
891
892 // different windows for low and high frequencies?
893 si.ch[ch].gr[gr].mixed_block_flag
894 = frame->readbitsfrombuffer(1);
895
896 // which huffman table to use in area i of big_values
897 for (i = 0; i < 2; i++) {
898 si.ch[ch].gr[gr].table_select[i]
899 = frame->readbitsfrombuffer(5);
900 }
901
902 // gain offset from global gain with short windows
903 for (i = 0; i < 3; i++) {
904 si.ch[ch].gr[gr].subblock_gain[i]
905 = frame->readbitsfrombuffer(3);
906 }
907
908 // Set region_count parameters (spectrum partitioning)
909 // since they are implicit in this case.
910 if (blocktype(ch,gr) == 0) {
911 cerr << "MaaateP: Bad side info: blocktype 0 in split block"
912 << endl;
913 exit(0);
914 } else if (blocktype(ch,gr) == 2 && mixedblock(ch,gr)) {
915 si.ch[ch].gr[gr].region0_count = 8; /* MI 9; */
916 } else {
917 si.ch[ch].gr[gr].region0_count = 7; /* MI 8; */
918 }
919 si.ch[ch].gr[gr].region1_count
920 =20 - si.ch[ch].gr[gr].region0_count;
921
922 } else { // no window switching
923 si.ch[ch].gr[gr].block_type = 0;
924 si.ch[ch].gr[gr].mixed_block_flag = 0;
925
926 // which huffman table to use in area i of big_values
927 for (int i = 0; i < 3; i++) {
928 si.ch[ch].gr[gr].table_select[i]
929 = frame->readbitsfrombuffer(5);
930 }
931
932 // spectrum partitioning
933 si.ch[ch].gr[gr].region0_count
934 = frame->readbitsfrombuffer(4);
935 si.ch[ch].gr[gr].region1_count
936 = frame->readbitsfrombuffer(3);
937 }
938
939 // additional high frequency amplification?
940 si.ch[ch].gr[gr].preflag = frame->readbitsfrombuffer(1);
941
942 // scale factor scaling
943 si.ch[ch].gr[gr].scalefac_scale
944 = frame->readbitsfrombuffer(1);
945
946 // which huffman table for quadruples in are count1
947 si.ch[ch].gr[gr].count1table_select
948 = frame->readbitsfrombuffer(1);
949
950 }
951 }
952
953 } else { // MPEG2
954
955 si.main_data_begin = frame->readbitsfrombuffer(8);
956 if (s_ch == 1) {
957 si.private_bits = frame->readbitsfrombuffer(1);
958 } else {
959 si.private_bits = frame->readbitsfrombuffer(2);
960 }
961
962 for (gr = 0; gr < 1 ; gr++) {
963 for (ch = 0; ch < s_ch; ch++) {
964 si.ch[ch].gr[gr].part2_3_length
965 = frame->readbitsfrombuffer(12);
966 si.ch[ch].gr[gr].big_values
967 = frame->readbitsfrombuffer(9);
968 si.ch[ch].gr[gr].global_gain
969 = frame->readbitsfrombuffer(8);
970 si.ch[ch].gr[gr].scalefac_compress
971 = frame->readbitsfrombuffer(9);
972 si.ch[ch].gr[gr].window_switching_flag
973 = frame->readbitsfrombuffer(1);
974 if (si.ch[ch].gr[gr].window_switching_flag) {
975 si.ch[ch].gr[gr].block_type
976 = frame->readbitsfrombuffer(2);
977 si.ch[ch].gr[gr].mixed_block_flag
978 = frame->readbitsfrombuffer(1);
979 for (i = 0; i < 2; i++) {
980 si.ch[ch].gr[gr].table_select[i]
981 = frame->readbitsfrombuffer(5);
982 }
983 for (i = 0; i < 3; i++) {
984 si.ch[ch].gr[gr].subblock_gain[i]
985 = frame->readbitsfrombuffer(3);
986 }
987
988 // Set region_count parameters since they are
989 // implicit in this case.
990 if (blocktype(ch,gr) == 0) {
991 cerr << "MaaateP: Bad side info: blocktype 0 in split block"
992 << endl;
993 exit(0);
994 } else if (blocktype(ch,gr) == 2 && mixedblock(ch,gr)) {
995 si.ch[ch].gr[gr].region0_count = 8; /* MI 9; */
996 } else {
997 si.ch[ch].gr[gr].region0_count = 7; /* MI 8; */
998 }
999 si.ch[ch].gr[gr].region1_count =
1000 20 - si.ch[ch].gr[gr].region0_count;
1001
1002 } else { // no window switching
1003 si.ch[ch].gr[gr].block_type = 0;
1004 si.ch[ch].gr[gr].mixed_block_flag = 0;
1005
1006 for (i = 0; i < 3; i++) {
1007 si.ch[ch].gr[gr].table_select[i]
1008 = frame->readbitsfrombuffer(5);
1009 }
1010 si.ch[ch].gr[gr].region0_count
1011 = frame->readbitsfrombuffer(4);
1012 si.ch[ch].gr[gr].region1_count
1013 = frame->readbitsfrombuffer(3);
1014 }
1015
1016 si.ch[ch].gr[gr].scalefac_scale
1017 = frame->readbitsfrombuffer(1);
1018 si.ch[ch].gr[gr].count1table_select
1019 = frame->readbitsfrombuffer(1);
1020 }
1021 }
1022 }
1023 }
1024
1025 CSAPI_MPEG void
printSideinfo()1026 Layer3::printSideinfo()
1027 {
1028 cout << "\tLayer 3 Side information:" << endl;
1029 cout << "\tMain_data_begin=" << main_data_begin() << endl;
1030 cout << "\tPrivate_bits=" << private_bits() << endl;
1031 const int s_ch = frame->channels();
1032 int ch, area;
1033 unsigned int scfc;
1034 #ifdef DEBUG
1035 int gr, sfb;
1036 #endif
1037 for (ch=0; ch<s_ch; ch++) {
1038 for (scfc=0; scfc<4; scfc++) {
1039 cout << "\tscfsi[" << ch << "][" << scfc << "]="
1040 << scfsi(ch,scfc) << endl;
1041 }
1042 for (unsigned gr=0; gr<granules(); gr++) {
1043 cout << "\tpart2_3_length[" << ch << "][" << gr << "]="
1044 << part2_3_length(ch,gr) << endl;
1045 cout << "\tbig_values[" << ch << "][" << gr << "]="
1046 << big_values(ch,gr) << endl;
1047 cout << "\tglobal_gain[" << ch << "][" << gr << "]="
1048 << global_gain(ch,gr) << endl;
1049 cout << "\tscalefac_compress[" << ch << "][" << gr << "]="
1050 << scalefac_compress(ch,gr) << endl;
1051 cout << "\twindow_switching[" << ch << "][" << gr << "]="
1052 << window_switching(ch,gr) << endl;
1053 cout << "\tblocktype[" << ch << "][" << gr << "]="
1054 << blocktype(ch,gr)
1055 << " (" << blocktype_str(ch,gr) << ")" << endl;
1056 cout << "\tmixedblock[" << ch << "][" << gr << "]="
1057 << mixedblock(ch,gr) << endl;
1058 for (area=0; area<3; area++) {
1059 cout << "\ttable_select[" << ch << "][" << gr << "]["
1060 << area << "]=" << table_select(ch,gr,area) << endl;
1061 cout << "\tsubblock_gain[" << ch << "][" << gr << "]["
1062 << area << "]=" << subblock_gain(ch,gr,area) << endl;
1063 }
1064 cout << "\tregion0_count[" << ch << "][" << gr << "]="
1065 << region0_count(ch,gr) << endl;
1066 cout << "\tregion1_count[" << ch << "][" << gr << "]="
1067 << region1_count(ch,gr) << endl;
1068 cout << "\tpreflag[" << ch << "][" << gr << "]="
1069 << preflag(ch,gr) << endl;
1070 cout << "\tscalefac_scale[" << ch << "][" << gr << "]="
1071 << scalefac_scale(ch,gr) << endl;
1072 cout << "\tcount1table_select[" << ch << "][" << gr << "]="
1073 << count1table_select(ch,gr) << endl;
1074 #ifdef DEBUG
1075 cout << "\tregion0_samps[" << ch << "][" << gr << "]="
1076 << region0_samps(ch,gr) << endl;
1077 cout << "\tregion1_samps[" << ch << "][" << gr << "]="
1078 << region1_samps(ch,gr) << endl;
1079 cout << "\tregion2_samps[" << ch << "][" << gr << "]="
1080 << region2_samps(ch,gr) << endl;
1081 cout << "\tcount1_values[" << ch << "][" << gr << "]="
1082 << count1_values(ch,gr) << endl;
1083 cout << "\tslen1[" << ch << "][" << gr << "]="
1084 << slen1(ch,gr) << endl;
1085 cout << "\tslen2[" << ch << "][" << gr << "]="
1086 << slen2(ch,gr) << endl;
1087 cout << "\tscalefacs[" << ch << "][" << gr << "]=";
1088 if (window_switching(ch,gr) && (blocktype(ch,gr)==2)) {
1089 if (mixedblock(ch,gr)) { // mixed
1090 for (sfb=0; sfb<8; sfb++) { // long
1091 cout << " " << scalefac[ch][gr].l[sfb];
1092 }
1093 for (sfb=3; sfb<13; sfb++) { // short
1094 cout << " " << scalefac[gr][ch].s[0][sfb];
1095 cout << " " << scalefac[gr][ch].s[1][sfb];
1096 cout << " " << scalefac[gr][ch].s[2][sfb];
1097 }
1098 } else {
1099 for (sfb=0; sfb<13; sfb++) { // short only
1100 cout << " " << scalefac[gr][ch].s[0][sfb];
1101 cout << " " << scalefac[gr][ch].s[1][sfb];
1102 cout << " " << scalefac[gr][ch].s[2][sfb];
1103 }
1104 }
1105 } else {
1106 for (sfb=0; sfb<21; sfb++) { // long
1107 cout << " " << scalefac[gr][ch].l[sfb];
1108 }
1109 }
1110 cout << endl;
1111 #endif
1112 }
1113 }
1114 return;
1115 }
1116
1117 // calculates checksum on required fields
1118 CSAPI_MPEG unsigned int
calc_CRC()1119 Layer3::calc_CRC()
1120 {
1121 unsigned int crc = 0xffff;
1122 // header
1123 frame->update_CRC(frame->header.bitrate, 4, &crc);
1124 frame->update_CRC(frame->header.samplingrate, 2, &crc);
1125 frame->update_CRC(frame->header.padding, 1, &crc);
1126 frame->update_CRC(frame->header.extension, 1, &crc);
1127 frame->update_CRC(frame->header.mode, 2, &crc);
1128 frame->update_CRC(frame->header.mode_ext, 2, &crc);
1129 frame->update_CRC(frame->header.copyright, 1, &crc);
1130 frame->update_CRC(frame->header.original, 1, &crc);
1131 frame->update_CRC(frame->header.emphasis, 2, &crc);
1132
1133 // side info
1134 const int s_ch = frame->channels();
1135 int ch, gr, i;
1136 unsigned int scfc;
1137 if (frame->version() == MPEG1) {
1138 frame->update_CRC(si.main_data_begin, 9, &crc);
1139 if (s_ch == 1) {
1140 frame->update_CRC(si.private_bits, 5, &crc);
1141 } else {
1142 frame->update_CRC(si.private_bits, 3, &crc);
1143 }
1144 for (ch=0; ch<s_ch; ch++) {
1145 for (scfc = 0; scfc < 4; scfc++) {
1146 frame->update_CRC(si.ch[ch].scfsi[scfc], 1, &crc);
1147 }
1148 }
1149 for (gr = 0; gr < 2 ; gr++) {
1150 for (ch = 0; ch < s_ch; ch++) {
1151 frame->update_CRC(si.ch[ch].gr[gr].part2_3_length,
1152 12, &crc);
1153 frame->update_CRC(si.ch[ch].gr[gr].big_values,
1154 9, &crc);
1155 frame->update_CRC(si.ch[ch].gr[gr].global_gain,
1156 8, &crc);
1157 frame->update_CRC(si.ch[ch].gr[gr].scalefac_compress,
1158 4, &crc);
1159 frame->update_CRC(si.ch[ch].gr[gr].window_switching_flag,
1160 1, &crc);
1161 if (si.ch[ch].gr[gr].window_switching_flag) {
1162 frame->update_CRC(si.ch[ch].gr[gr].block_type,
1163 2, &crc);
1164 frame->update_CRC(si.ch[ch].gr[gr].mixed_block_flag,
1165 1, &crc);
1166 for (i = 0; i < 2; i++) {
1167 frame->update_CRC(si.ch[ch].gr[gr].table_select[i],
1168 5, &crc);
1169 }
1170 for (i = 0; i < 3; i++) {
1171 frame->update_CRC(si.ch[ch].gr[gr].subblock_gain[i],
1172 3, &crc);
1173 }
1174 } else { // no window switching
1175 for (i = 0; i < 3; i++) {
1176 frame->update_CRC(si.ch[ch].gr[gr].table_select[i],
1177 5, &crc);
1178 }
1179 frame->update_CRC(si.ch[ch].gr[gr].region0_count,
1180 4, &crc);
1181 frame->update_CRC(si.ch[ch].gr[gr].region1_count,
1182 3, &crc);
1183 }
1184 frame->update_CRC(si.ch[ch].gr[gr].preflag,
1185 1, &crc);
1186 frame->update_CRC(si.ch[ch].gr[gr].scalefac_scale,
1187 1, &crc);
1188 frame->update_CRC(si.ch[ch].gr[gr].count1table_select,
1189 1, &crc);
1190 }
1191 }
1192 } else { // MPEG2
1193 frame->update_CRC(si.main_data_begin, 8, &crc);
1194 if (s_ch == 1) {
1195 frame->update_CRC(si.private_bits, 1, &crc);
1196 } else {
1197 frame->update_CRC(si.private_bits, 2, &crc);
1198 }
1199 for (gr = 0; gr < 1 ; gr++) {
1200 for (ch = 0; ch < s_ch; ch++) {
1201 frame->update_CRC(si.ch[ch].gr[gr].part2_3_length,
1202 12, &crc);
1203 frame->update_CRC(si.ch[ch].gr[gr].big_values,
1204 9, &crc);
1205 frame->update_CRC(si.ch[ch].gr[gr].global_gain,
1206 8, &crc);
1207 frame->update_CRC(si.ch[ch].gr[gr].scalefac_compress,
1208 9, &crc);
1209 frame->update_CRC(si.ch[ch].gr[gr].window_switching_flag,
1210 1, &crc);
1211 if (si.ch[ch].gr[gr].window_switching_flag) {
1212 frame->update_CRC(si.ch[ch].gr[gr].block_type,
1213 2, &crc);
1214 frame->update_CRC(si.ch[ch].gr[gr].mixed_block_flag,
1215 1, &crc);
1216 for (i = 0; i < 2; i++) {
1217 frame->update_CRC(si.ch[ch].gr[gr].table_select[i],
1218 5, &crc);
1219 }
1220 for (i = 0; i < 3; i++) {
1221 frame->update_CRC(si.ch[ch].gr[gr].subblock_gain[i],
1222 3, &crc);
1223 }
1224 } else { // no window switching
1225 for (i = 0; i < 3; i++) {
1226 frame->update_CRC(si.ch[ch].gr[gr].table_select[i],
1227 5, &crc);
1228 }
1229 frame->update_CRC(si.ch[ch].gr[gr].region0_count,
1230 4, &crc);
1231 frame->update_CRC(si.ch[ch].gr[gr].region1_count,
1232 3, &crc);
1233 }
1234 frame->update_CRC(si.ch[ch].gr[gr].scalefac_scale,
1235 1, &crc);
1236 frame->update_CRC(si.ch[ch].gr[gr].count1table_select,
1237 1, &crc);
1238 }
1239 }
1240 }
1241
1242 return crc;
1243 }
1244
1245
1246 // parse the scale factors (MPEG1)
1247 CSAPI_MPEG void
decode_scale_I(int gr,int ch)1248 Layer3::decode_scale_I(int gr, int ch)
1249 {
1250 int window;
1251 unsigned int sfb, scfc;
1252
1253 if (window_switching(ch,gr) && (blocktype(ch,gr) == 2)) {
1254
1255 if (mixedblock(ch,gr)) { /// MIXED
1256 for (sfb=0; sfb<8; sfb++) {
1257 scalefac[gr][ch].l[sfb] = readbits(slen1(ch,gr));
1258 }
1259 for (sfb=3; sfb<6; sfb++) {
1260 for (window=0; window<3; window++) {
1261 scalefac[gr][ch].s[window][sfb]
1262 = readbits(slen1(ch,gr));
1263 }
1264 }
1265 for (sfb = 6; sfb < 12; sfb++) {
1266 for (window=0; window<3; window++) {
1267 scalefac[gr][ch].s[window][sfb]
1268 = readbits(slen2(ch,gr));
1269 }
1270 }
1271 for (window=0; window<3; window++) {
1272 scalefac[gr][ch].s[window][12] = 0;
1273 }
1274
1275 } else { // not mixed; SHORT
1276
1277 for (sfb=0; sfb<6; sfb++) {
1278 for (window=0; window<3; window++) {
1279 scalefac[gr][ch].s[window][sfb]
1280 = readbits (slen1(ch,gr));
1281 }
1282 }
1283 for (sfb=6; sfb<12; sfb++) {
1284 for (window=0; window<3; window++) {
1285 scalefac[gr][ch].s[window][sfb]
1286 = readbits (slen2(ch,gr));
1287 }
1288 }
1289 for (window=0; window<3; window++) {
1290 scalefac[gr][ch].s[window][12] = 0;
1291 }
1292 }
1293
1294 } else { // blocktypes 0,1,3; LONG
1295
1296 for (scfc=0; scfc<2; scfc++) {
1297 if ((scfsi(ch,scfc) == 0) || (gr == 0)) {
1298 for (sfb=sfbtable[0][scfc];
1299 sfb<sfbtable[0][scfc+1];
1300 sfb++) {
1301 scalefac[gr][ch].l[sfb] = readbits(slen1(ch,gr));
1302 }
1303 }
1304 }
1305 for (scfc=2; scfc<4; scfc++) {
1306 if ((scfsi(ch,scfc) == 0) || (gr == 0)) {
1307 for (sfb=sfbtable[0][scfc];
1308 sfb<sfbtable[0][scfc+1];
1309 sfb++) {
1310 scalefac[gr][ch].l[sfb] = readbits(slen2(ch,gr));
1311 }
1312 }
1313 }
1314
1315 }
1316 scalefac[gr][ch].l[21] = 0;
1317
1318 return;
1319 }
1320
1321
1322 // parses the scale factors (MPEG2)
1323 CSAPI_MPEG void
decode_scale_II(int gr,int ch)1324 Layer3::decode_scale_II(int gr, int ch)
1325 {
1326 unsigned int scalefac_buffer[54];
1327 unsigned int new_slen[4];
1328 short blocktypenumber=0, blocknumber = 0;
1329
1330 if (blocktype(ch,gr) == 2 && mixedblock(ch,gr) == 0)
1331 blocktypenumber = 1;
1332
1333 if (blocktype(ch,gr) == 2 && mixedblock(ch,gr) == 1)
1334 blocktypenumber = 2;
1335
1336 if (!((frame->mode_ext() & 0x1) && ch == 1)) {
1337 // not (intensity stereo and second channel)
1338 if(scalefac_compress(ch,gr) < 400) {
1339 new_slen[0] = (scalefac_compress(ch,gr) >> 4) / 5 ;
1340 new_slen[1] = (scalefac_compress(ch,gr) >> 4) % 5 ;
1341 new_slen[2] = (scalefac_compress(ch,gr) % 16) >> 2 ;
1342 new_slen[3] = (scalefac_compress(ch,gr) % 4);
1343 si.ch[ch].gr[gr].preflag = 0;
1344 blocknumber = 0;
1345
1346 } else if(scalefac_compress(ch,gr) < 500) {
1347 new_slen[0] = ((scalefac_compress(ch,gr) - 400 ) >> 2) / 5 ;
1348 new_slen[1] = ((scalefac_compress(ch,gr) - 400) >> 2) % 5 ;
1349 new_slen[2] = (scalefac_compress(ch,gr) - 400 ) % 4 ;
1350 new_slen[3] = 0;
1351 si.ch[ch].gr[gr].preflag = 0;
1352 blocknumber = 1;
1353
1354 } else if(scalefac_compress(ch,gr) < 512) {
1355 new_slen[0] = (scalefac_compress(ch,gr) - 500 ) / 3 ;
1356 new_slen[1] = (scalefac_compress(ch,gr) - 500) % 3 ;
1357 new_slen[2] = 0 ;
1358 new_slen[3] = 0;
1359 si.ch[ch].gr[gr].preflag = 1;
1360 blocknumber = 2;
1361 }
1362 }
1363
1364 if ((frame->mode_ext() & 0x1) && ch == 1) {
1365 // intensity stereo and second channel
1366 /* intensity_scale = scalefac_comp %2; */
1367 unsigned int intensity_scalefac_comp = scalefac_compress(ch,gr) >> 1;
1368
1369 if (intensity_scalefac_comp < 180) {
1370 new_slen[0] = intensity_scalefac_comp / 36 ;
1371 new_slen[1] = (intensity_scalefac_comp % 36 ) / 6 ;
1372 new_slen[2] = (intensity_scalefac_comp % 36) % 6;
1373 new_slen[3] = 0;
1374 si.ch[ch].gr[gr].preflag = 0;
1375 blocknumber = 3;
1376
1377 } else if (intensity_scalefac_comp < 244) {
1378 new_slen[0] = ((intensity_scalefac_comp - 180 ) % 64 ) >> 4 ;
1379 new_slen[1] = ((intensity_scalefac_comp - 180) % 16) >> 2 ;
1380 new_slen[2] = (intensity_scalefac_comp - 180 ) % 4 ;
1381 new_slen[3] = 0;
1382 si.ch[ch].gr[gr].preflag = 0;
1383 blocknumber = 4;
1384
1385 } else if (intensity_scalefac_comp < 255) {
1386 new_slen[0] = (intensity_scalefac_comp - 244 ) / 3 ;
1387 new_slen[1] = (intensity_scalefac_comp - 244 ) % 3 ;
1388 new_slen[2] = 0 ;
1389 new_slen[3] = 0;
1390 si.ch[ch].gr[gr].preflag = 0;
1391 blocknumber = 5;
1392 }
1393 }
1394
1395 // read scale factors into buffer
1396 int k = 0;
1397 int i, window;
1398 unsigned int sfb, j;
1399 for (i=0; i<4; i++) {
1400 for(j=0; j<nr_of_sfb_block[blocknumber][blocktypenumber][i]; j++) {
1401 if(new_slen[i] == 0) {
1402 scalefac_buffer[k++] = 0;
1403 } else {
1404 scalefac_buffer[k++] = readbits(new_slen[i]);
1405 }
1406 }
1407 }
1408
1409 k = 0;
1410 if (window_switching(ch,gr) && (blocktype(ch,gr) == 2)) {
1411
1412 if (mixedblock(ch,gr)) { // MIXED
1413 for (sfb = 0; sfb < 8; sfb++) {
1414 scalefac[gr][ch].l[sfb] = scalefac_buffer[k++];
1415 }
1416 for (sfb = 3; sfb < 12; sfb++) {
1417 for (window=0; window<3; window++) {
1418 scalefac[gr][ch].s[window][sfb] = scalefac_buffer[k++];
1419 }
1420 }
1421
1422 for (window=0; window<3; window++) {
1423 scalefac[gr][ch].s[window][12] = 0;
1424 }
1425
1426 } else { // not mixed; SHORT
1427
1428 for (sfb=0; sfb<12; sfb++) {
1429 for (window=0; window<3; window++) {
1430 scalefac[gr][ch].s[window][sfb] = scalefac_buffer[k++];
1431 }
1432 }
1433 for (window=0; window<3; window++) {
1434 scalefac[gr][ch].s[window][12] = 0;
1435 }
1436 }
1437
1438 } else { // blocktypes 0,1,3; LONG
1439
1440 for (sfb = 0; sfb < 21; sfb++) {
1441 scalefac[gr][ch].l[sfb] = scalefac_buffer[k++];
1442 }
1443 scalefac[gr][ch].l[21] = 0;
1444 }
1445
1446 return;
1447 }
1448
1449
1450 // parse the huffman encoded sample data
1451 // result: "is" data array
1452 CSAPI_MPEG void
decode_huffmanbits(int gr,int ch)1453 Layer3::decode_huffmanbits(int gr, int ch)
1454 {
1455 unsigned int x, y, v, w; // quantized samples
1456 int region1Start, region2Start;
1457 int i;
1458
1459 // find region boundaries for short block case
1460 region1Start = region0_samps(ch,gr);
1461 region2Start = region1Start + region1_samps(ch,gr);
1462
1463 #ifdef DEBUG
1464 // cerr << "maindata bits read=" << main_data_bitsread+noReadBits << endl;
1465 #endif
1466
1467 // calculate end of this spectrum
1468 endSpectralBits = spectral_bitsread + part2_3_length(ch,gr);
1469
1470 // decode samples within big_values area
1471 struct huffcodetab *h;
1472 int endloop = big_values(ch,gr) * 2;
1473 for (i = 0; i < endloop; i += 2) {
1474 // Select the huffman decoding table
1475 if (i < region1Start) {
1476 h = &ht[table_select(ch,gr,0)];
1477 } else if (i<region2Start) {
1478 h = &ht[table_select(ch,gr,1)];
1479 } else {
1480 h = &ht[table_select(ch,gr,2)];
1481 }
1482 huffman_decoder(h, &x, &y, &v, &w);
1483 is[gr][ch][i / SSLIMIT][i % SSLIMIT] = x;
1484 is[gr][ch][(i+1) / SSLIMIT][(i+1) % SSLIMIT] = y;
1485 }
1486
1487 // decode samples within count1 area
1488 h = &ht[count1table_select(ch,gr) + 32];
1489 while (main_data_bitsread < endSpectralBits && i < SBSSLIMIT ) {
1490 if (huffman_decoder(h, &x, &y, &v, &w)) {
1491 is[gr][ch][i / SSLIMIT][i % SSLIMIT] = v;
1492 is[gr][ch][(i+1) / SSLIMIT][(i+1) % SSLIMIT] = w;
1493 is[gr][ch][(i+2) / SSLIMIT][(i+2) % SSLIMIT] = x;
1494 is[gr][ch][(i+3) / SSLIMIT][(i+3) % SSLIMIT] = y;
1495 i += 4;
1496 }
1497 // update no of count1 values
1498 count1_vals[gr][ch]++;
1499 }
1500
1501
1502 #ifdef DEBUG
1503 // cerr << "2:mdb=" << main_data_bitsread+noReadBits << endl;
1504 #endif
1505
1506 // Dismiss stuffing Bits (no more than 32 at a time)
1507 if (main_data_bitsread < endSpectralBits) {
1508 unsigned int stuffed = endSpectralBits - main_data_bitsread;
1509 while (stuffed > 0) {
1510 if (stuffed < 32) {
1511 readbits(stuffed);
1512 stuffed = 0;
1513 } else {
1514 readbits(32);
1515 stuffed -= 32;
1516 }
1517 }
1518 } else if (main_data_bitsread > endSpectralBits) {
1519 cerr << "MaaateP: Error: can't rewind stream by "
1520 << main_data_bitsread-endSpectralBits
1521 << " bits." << endl;
1522 }
1523
1524 // update spectral_bitsread; (main_data_bitsread gets updated in readbits)
1525 spectral_bitsread = main_data_bitsread;
1526
1527 // Zero out rest (SSLMIT*SBLIMIT=576=SBSSLIMIT)
1528 if (i < SBSSLIMIT)
1529 memset ((void*)&is[gr][ch][i/SSLIMIT][i%SSLIMIT], 0,
1530 (SBSSLIMIT-i)*sizeof(long int));
1531
1532 /* original code
1533 for (; i < SBSSLIMIT; i++) {
1534 is[gr][ch][i / SSLIMIT][i % SSLIMIT] = 0;
1535 }
1536 */
1537
1538
1539 return;
1540 }
1541
1542
1543 // Do the huffman-decoding of the sample data
1544 // Note! for counta,countb -the 4 bit value is returned in y, discard x
1545 CSAPI_MPEG bool
huffman_decoder(struct huffcodetab * h,unsigned int * x,unsigned int * y,unsigned int * v,unsigned int * w)1546 Layer3::huffman_decoder(struct huffcodetab *h, // huffman code record
1547 unsigned int *x, // decoded x value
1548 unsigned int *y, // decoded y value
1549 unsigned int *v, // decoded v value
1550 unsigned int *w) // decoded w value
1551 {
1552 unsigned int point = 0;
1553 int error = 1;
1554
1555 if (h->val == NULL)
1556 return true;
1557
1558 // 1000...0000
1559 unsigned int level = (unsigned int)1 << (sizeof(unsigned int)*8-1);
1560
1561 // Table 0 needs no bits
1562 if ( h->treelen == 0) {
1563 *x = *y = 0;
1564 return true;
1565 }
1566
1567 // Lookup in Huffman table reading data bits
1568 do {
1569 if (h->val[point][0]==0) { /* end of tree */
1570 *x = h->val[point][1] >> 4;
1571 *y = h->val[point][1] & 0xf;
1572 error = 0;
1573 break;
1574 }
1575 if ((main_data_bitsread + 1) > endSpectralBits) {
1576 return false;
1577 }
1578 if (readbits(1)) {
1579 while (h->val[point][1] >= MXOFF) point += h->val[point][1];
1580 point += h->val[point][1];
1581 } else {
1582 while (h->val[point][0] >= MXOFF) point += h->val[point][0];
1583 point += h->val[point][0];
1584 }
1585 level >>= 1;
1586 } while (level || (point < ht->treelen) );
1587
1588 // Check for error
1589 if (error) { // set x and y to a medium value as a simple concealment
1590 cerr << "MaaateP: Illegal Huffman code in data." << endl;
1591 *x = ((h->xlen-1) << 1);
1592 *y = ((h->ylen-1) << 1);
1593 }
1594
1595 // Process sign encodings for quadruples tables
1596 if (h->tablename[0] == '3' && (h->tablename[1] == '2' ||
1597 h->tablename[1] == '3')) {
1598 *v = (*y>>3) & 1;
1599 *w = (*y>>2) & 1;
1600 *x = (*y>>1) & 1;
1601 *y = *y & 1;
1602
1603 if (*v) {
1604 if ((main_data_bitsread + 1) > endSpectralBits) {
1605 return false;
1606 }
1607 if (readbits(1) == 1) *v = -*v;
1608 }
1609 if (*w) {
1610 if ((main_data_bitsread + 1) > endSpectralBits) {
1611 return false;
1612 }
1613 if (readbits(1) == 1) *w = -*w;
1614 }
1615 if (*x) {
1616 if ((main_data_bitsread + 1) > endSpectralBits) {
1617 return false;
1618 }
1619 if (readbits(1) == 1) *x = -*x;
1620 }
1621 if (*y) {
1622 if ((main_data_bitsread + 1) > endSpectralBits) {
1623 return false;
1624 }
1625 if (readbits(1) == 1) *y = -*y;
1626 }
1627 } else {
1628 // Process sign and escape encodings for dual tables
1629
1630 if (h->linbits)
1631 if ((h->xlen-1) == *x) {
1632 if ((main_data_bitsread + h->linbits) > endSpectralBits) {
1633 *x += readbits(endSpectralBits - main_data_bitsread);
1634 return false;
1635 }
1636 *x += readbits(h->linbits);
1637 }
1638 if (*x) {
1639 if ((main_data_bitsread + 1) > endSpectralBits) {
1640 return false;
1641 }
1642 if (readbits(1) == 1) *x = -*x;
1643 }
1644 if (h->linbits)
1645 if ((h->ylen-1) == *y) {
1646 if ((main_data_bitsread + h->linbits) > endSpectralBits) {
1647 *x += readbits(endSpectralBits - main_data_bitsread);
1648 return false;
1649 }
1650 *y += readbits(h->linbits);
1651 }
1652 if (*y) {
1653 if ((main_data_bitsread + 1) > endSpectralBits) {
1654 return false;
1655 }
1656 if (readbits(1) == 1) *y = -*y;
1657 }
1658 }
1659 return true;
1660 }
1661
1662
1663 // restore the quantized value from "is"
1664 // result: "xr" data array
1665 CSAPI_MPEG void
restore_samples(int gr,int ch)1666 Layer3::restore_samples(int gr, int ch)
1667 {
1668 int cb = 0;
1669 int cb_begin = 0, cb_width = 0;
1670 int sb, ss;
1671 unsigned int next_cb_boundary, boundary;
1672
1673 // compute overall scaling for this channel and granule
1674 const double globalgain = pow(2.0, (0.25 * (global_gain(ch,gr) - 210.0)));
1675
1676 // compute scalefactor scaling for this channel and granule
1677 const double scfscale = -0.5 * (1.0 + scalefac_scale(ch,gr));
1678
1679 // Choose correct scalefactor band per block type,
1680 // initalize boundary
1681 if (window_switching(ch,gr) && blocktype(ch,gr) == 2) {
1682 if (mixedblock(ch,gr)) {
1683 // mixed blocks
1684 next_cb_boundary=scf_band_bound_l(1);
1685 } else {
1686 // pure short block
1687 next_cb_boundary=scf_band_bound_s(1)*3;
1688 cb_width = scf_band_bound_s(1);
1689 cb_begin = 0;
1690 }
1691 } else {
1692 // long blocks: 0,1,3
1693 next_cb_boundary=scf_band_bound_l(1);
1694 }
1695
1696 // Apply formula per block type
1697 for (sb = 0 ; sb < SBLIMIT ; sb++) {
1698 for (ss = 0 ; ss < SSLIMIT ; ss++) {
1699 boundary=(sb*18)+ss;
1700 if (boundary == next_cb_boundary) {
1701 // Adjust critical band boundary
1702 if (window_switching(ch,gr) && blocktype(ch,gr) == 2) {
1703 if (mixedblock(ch,gr)) { // MIXED BLOCK
1704 if (boundary == scf_band_bound_l(8)) {
1705 next_cb_boundary=scf_band_bound_s(4)*3;
1706 cb = 3;
1707 cb_width = scf_band_bound_s(cb+1) -
1708 scf_band_bound_s(cb);
1709 cb_begin = scf_band_bound_s(cb)*3;
1710 } else if (boundary < scf_band_bound_l(8)){
1711 next_cb_boundary =
1712 scf_band_bound_l((++cb)+1);
1713 } else {
1714 next_cb_boundary
1715 = scf_band_bound_s((++cb)+1)*3;
1716 cb_width = scf_band_bound_s(cb+1) -
1717 scf_band_bound_s(cb);
1718 cb_begin = scf_band_bound_s(cb)*3;
1719 }
1720 } else { // PURE SHORT BLOCKS
1721 next_cb_boundary =
1722 scf_band_bound_s((++cb)+1)*3;
1723 cb_width = scf_band_bound_s(cb+1) -
1724 scf_band_bound_s(cb);
1725 cb_begin = scf_band_bound_s(cb)*3;
1726 }
1727
1728 } else { // LONG BLOCKS
1729 next_cb_boundary = scf_band_bound_l((++cb)+1);
1730 }
1731 }
1732
1733 // Use overall (global) scaling
1734 xr[gr][ch][sb][ss] = globalgain;
1735
1736 // Do long/short dependent scaling operations
1737 if (window_switching(ch,gr) &&
1738 (((blocktype(ch,gr) == 2) &&
1739 (!mixedblock(ch,gr))) ||
1740 ((blocktype(ch,gr) == 2) &&
1741 mixedblock(ch,gr) && (sb >= 2)) )) {
1742
1743 xr[gr][ch][sb][ss] *= pow(2.0, 0.25 * -8.0 *
1744 subblock_gain(ch, gr,
1745 (boundary - cb_begin)/
1746 cb_width));
1747
1748 xr[gr][ch][sb][ss] *= pow(2.0, scfscale *
1749 scalefac[gr][ch].s[(boundary - cb_begin)
1750 /cb_width][cb]);
1751
1752 } else { // LONG block types 0,1,3 &
1753 // 1st 2 subbands of switched blocks
1754
1755 xr[gr][ch][sb][ss] *= pow(2.0, scfscale *
1756 (scalefac[gr][ch].l[cb] +
1757 preflag(ch,gr) * pretab[cb]));
1758 }
1759
1760 // Scale quantized value
1761 xr[gr][ch][sb][ss] *= pow(abs((int)is[gr][ch][sb][ss]), 4.0/3.0);
1762 if (is[gr][ch][sb][ss]<0) {
1763 xr[gr][ch][sb][ss] = -xr[gr][ch][sb][ss];
1764 }
1765 // printf("xl[%d,%d]=%f\n", sb, ss, xr[gr][ch][sb][ss]);
1766 }
1767 }
1768
1769 return;
1770 }
1771
1772
1773 // restore the stereo values from "xr"
1774 // result: "lr" data array
1775 // note: only called for channel 0
1776 CSAPI_MPEG void
decode_jstereo(int gr)1777 Layer3::decode_jstereo(int gr)
1778 {
1779 // second bit in mode_ext() indicates ms_stereo
1780 const bool ms_stereo = (frame->mode() == jstereo) &&
1781 (frame->mode_ext() & 0x2);
1782 // first bit indicates intensity_stereo
1783 const bool i_stereo = (frame->mode() == jstereo) &&
1784 (frame->mode_ext() & 0x1);
1785
1786 char is_pos[SBSSLIMIT];
1787 double is_ratio[SBSSLIMIT];
1788 double k[2][SBSSLIMIT];
1789 const int ch = 0;
1790 int i, j, ss, sb;
1791 int lines;
1792 int sfb, sfbcnt, max_sfb;
1793 const static double pi12 = PI/12;
1794
1795 // Intialization
1796 memset ((void *)&is_pos[0], 7, SBSSLIMIT*sizeof(char));
1797 /* original code
1798 for (i = 0; i < SBSSLIMIT; i++) {
1799 is_pos[i] = 7;
1800 }
1801 */
1802
1803 // intensity stereo processing
1804 const int s_ch = frame->channels();
1805 const int s_ver = frame->version();
1806 if ((s_ch == 2) && i_stereo ) {
1807 if (window_switching(ch,gr) && blocktype(ch,gr) == 2) {
1808 if(mixedblock(ch,gr)) {
1809 max_sfb = 0;
1810
1811 for (j=0; j<3; j++ ) {
1812 sfbcnt = 2;
1813 for (sfb=12; sfb >=3; sfb--) {
1814 lines= scf_band_bound_s(sfb+1) -
1815 scf_band_bound_s(sfb);
1816 i = 3*scf_band_bound_s(sfb) + (j+1) * lines - 1;
1817 while (lines > 0) {
1818 if (xr[gr][ch+1][i/SSLIMIT][i%SSLIMIT] != 0.0) {
1819 sfbcnt = sfb;
1820 sfb = -10;
1821 lines = -10;
1822 }
1823 lines--;
1824 i--;
1825 }
1826 }
1827 sfb = sfbcnt + 1;
1828
1829 if (sfb > max_sfb) max_sfb = sfb;
1830
1831 while (sfb<12) {
1832 sb = scf_band_bound_s(sfb+1) -
1833 scf_band_bound_s(sfb);
1834 i = 3*scf_band_bound_s(sfb) + j * sb;
1835 for ( ; sb > 0; sb--) {
1836 is_pos[i] = scalefac[gr][ch+1].s[j][sfb];
1837 if (is_pos[i] != 7)
1838 if (s_ver==MPEG2) {
1839 i_stereo_k_values(ch,
1840 gr,
1841 is_pos[i],
1842 i,
1843 k);
1844 } else {
1845 is_ratio[i] = tan((float)is_pos[i] * pi12);
1846 }
1847 i++;
1848 }
1849 sfb++;
1850 }
1851
1852 sb = scf_band_bound_s(12)-scf_band_bound_s(11);
1853 sfb = 3*scf_band_bound_s(11) + j * sb;
1854 sb = scf_band_bound_s(13)-scf_band_bound_s(12);
1855
1856 i = 3*scf_band_bound_s(11) + j * sb;
1857 for ( ; sb > 0; sb--) {
1858 is_pos[i] = is_pos[sfb];
1859 is_ratio[i] = is_ratio[sfb];
1860 k[0][i] = k[0][sfb];
1861 k[1][i] = k[1][sfb];
1862 i++;
1863 }
1864 }
1865 if (max_sfb <= 3) {
1866 i = 2;
1867 ss = 17;
1868 sb = -1;
1869 while ( i >= 0 ) {
1870 if ( xr[gr][ch+1][i][ss] != 0.0 ) {
1871 sb = i*18+ss;
1872 i = -1;
1873 } else {
1874 ss--;
1875 if ( ss < 0 ) {
1876 i--;
1877 ss = 17;
1878 }
1879 }
1880 }
1881 i = 0;
1882 while (((int)scf_band_bound_l(i)) <= sb) i++;
1883 sfb = i;
1884 i = scf_band_bound_l(i);
1885 for ( ; sfb<8; sfb++) {
1886 sb = scf_band_bound_l(sfb+1)-scf_band_bound_l(sfb);
1887 for ( ; sb > 0; sb--) {
1888 is_pos[i] = scalefac[gr][ch+1].l[sfb];
1889 if (is_pos[i] != 7)
1890 if (s_ver == MPEG2) {
1891 i_stereo_k_values(ch,
1892 gr,
1893 is_pos[i],
1894 i,
1895 k);
1896 } else {
1897 is_ratio[i] = tan((float)is_pos[i] * pi12);
1898 }
1899 i++;
1900 }
1901 }
1902 }
1903
1904 } else { // SHORT BLOCKS
1905
1906 for (j=0; j<3; j++) {
1907 sfbcnt = -1;
1908 for(sfb=12; sfb >=0; sfb--) {
1909 lines = scf_band_bound_s(sfb+1) -
1910 scf_band_bound_s(sfb);
1911 i = 3*scf_band_bound_s(sfb) + (j+1) * lines - 1;
1912 while (lines > 0) {
1913 if (xr[gr][ch+1][i/SSLIMIT][i%SSLIMIT] != 0.0 ) {
1914 sfbcnt = sfb;
1915 sfb = -10;
1916 lines = -10;
1917 }
1918 lines--;
1919 i--;
1920 }
1921 }
1922 sfb = sfbcnt + 1;
1923 while (sfb<12) {
1924 sb = scf_band_bound_s(sfb+1)-scf_band_bound_s(sfb);
1925 i = 3*scf_band_bound_s(sfb) + j * sb;
1926 for ( ; sb > 0; sb--) {
1927 is_pos[i] = scalefac[gr][ch+1].s[j][sfb];
1928 if (is_pos[i] != 7)
1929 if(s_ver == MPEG2) {
1930 i_stereo_k_values(ch,
1931 gr,
1932 is_pos[i],
1933 i,
1934 k);
1935 } else {
1936 is_ratio[i] = tan((float)is_pos[i] * pi12);
1937 }
1938 i++;
1939 }
1940 sfb++;
1941 }
1942
1943 sb = scf_band_bound_s(12)-scf_band_bound_s(11);
1944 sfb = 3*scf_band_bound_s(11) + j * sb;
1945 sb = scf_band_bound_s(13)-scf_band_bound_s(12);
1946
1947 i = 3*scf_band_bound_s(11) + j * sb;
1948 for ( ; sb > 0; sb--) {
1949 is_pos[i] = is_pos[sfb];
1950 is_ratio[i] = is_ratio[sfb];
1951 k[0][i] = k[0][sfb];
1952 k[1][i] = k[1][sfb];
1953 i++;
1954 }
1955 }
1956 }
1957 } else { // LONG BLOCKS
1958 i = 31;
1959 ss = 17;
1960 sb = 0;
1961 while (i >= 0) {
1962 if ( xr[gr][ch+1][i][ss] != 0.0 ) {
1963 sb = i*18+ss;
1964 i = -1;
1965 } else {
1966 ss--;
1967 if ( ss < 0 ) {
1968 i--;
1969 ss = 17;
1970 }
1971 }
1972 }
1973 i = 0;
1974 while (((int)scf_band_bound_l(i)) <= sb) i++;
1975 sfb = i;
1976 i = scf_band_bound_l(i);
1977 for ( ; sfb<21; sfb++) {
1978 sb = scf_band_bound_l(sfb+1) - scf_band_bound_l(sfb);
1979 for ( ; sb > 0; sb--) {
1980 is_pos[i] = scalefac[gr][ch+1].l[sfb];
1981 if (is_pos[i] != 7)
1982 if(s_ver == MPEG2) {
1983 i_stereo_k_values(ch,
1984 gr,
1985 is_pos[i],
1986 i,
1987 k);
1988 } else {
1989 is_ratio[i] = tan((float)is_pos[i] * pi12);
1990 }
1991 i++;
1992 }
1993 }
1994 sfb = scf_band_bound_l(20);
1995 for (sb = 576 - scf_band_bound_l(21); sb > 0; sb--) {
1996 is_pos[i] = is_pos[sfb];
1997 is_ratio[i] = is_ratio[sfb];
1998 k[0][i] = k[0][sfb];
1999 k[1][i] = k[1][sfb];
2000 i++;
2001 }
2002 }
2003 }
2004
2005
2006 // now write stereo values to lr
2007 if (s_ch == 2) {
2008 for(sb = 0; sb < SBLIMIT; sb++)
2009 for(ss = 0; ss < SSLIMIT; ss++) {
2010 i = (sb*18)+ss;
2011 if (is_pos[i] == 7) {
2012 if (ms_stereo) {
2013 lr[gr][0][sb][ss] = (xr[gr][0][sb][ss] +
2014 xr[gr][1][sb][ss]) / 1.41421356;
2015 lr[gr][1][sb][ss] = (xr[gr][0][sb][ss] -
2016 xr[gr][1][sb][ss]) / 1.41421356;
2017 } else {
2018 lr[gr][0][sb][ss] = xr[gr][0][sb][ss];
2019 lr[gr][1][sb][ss] = xr[gr][1][sb][ss];
2020 }
2021 } else if (i_stereo) {
2022 if (s_ver == MPEG2) {
2023 lr[gr][0][sb][ss] = xr[gr][0][sb][ss] * k[0][i];
2024 lr[gr][1][sb][ss] = xr[gr][0][sb][ss] * k[1][i];
2025 } else {
2026 lr[gr][0][sb][ss] = xr[gr][0][sb][ss] *
2027 (is_ratio[i]/(1+is_ratio[i]));
2028 lr[gr][1][sb][ss] = xr[gr][0][sb][ss] *
2029 (1/(1+is_ratio[i]));
2030 }
2031 } else {
2032 cerr << "MaaateP: Error in layer III joint stereo processing" << endl;
2033 }
2034 }
2035
2036 } else { // MONO: bypass xr[0][][] to lr[0][][]
2037
2038 memcpy((void*)&lr[gr][0][0][0], (void*)&xr[gr][0][0][0],
2039 SBSSLIMIT*sizeof(double));
2040 /* original code
2041 for (sb = 0; sb < SBLIMIT; sb++)
2042 for(ss = 0; ss < SSLIMIT; ss++)
2043 lr[gr][0][sb][ss] = xr[gr][0][sb][ss];
2044 */
2045 }
2046
2047 /*
2048 for (ch=0; ch < frame->channels(); ch++) {
2049 for (sb = 0; sb < SBLIMIT; sb++)
2050 for(ss = 0; ss < SSLIMIT; ss++)
2051 printf("lr[%d,%d,%d]=%f\n", ch, sb, ss, lr[gr][ch][sb][ss]);
2052 }
2053 */
2054
2055 return;
2056 }
2057
2058
2059 // MPEG2: calculation of k-values for intensity stereo
2060 CSAPI_MPEG void
i_stereo_k_values(int ch,int gr,char is_pos,int i,double k[2][SBSSLIMIT])2061 Layer3::i_stereo_k_values(int ch,
2062 int gr,
2063 char is_pos,
2064 int i,
2065 double k[2][SBSSLIMIT])
2066 {
2067 double io;
2068
2069 if ((scalefac_compress(ch,gr) % 2) == 1) {
2070 io = 0.707106781188;
2071 } else {
2072 io = 0.840896415256;
2073 }
2074
2075 if (is_pos == 0) {
2076 k[0][i] = 1.0;
2077 k[1][i] = 1.0;
2078 } else if ((is_pos % 2) == 1) {
2079 k[0][i] = pow(io, (float)(is_pos + 1)/2.0);
2080 k[1][i] = 1.0;
2081 } else {
2082 k[0][i] = 1.0;
2083 k[1][i] = pow(io, (float)is_pos/2.0);
2084 }
2085 return;
2086 }
2087
2088
2089 // reorder the data in "lr"
2090 // result: "ro" data array
2091 CSAPI_MPEG void
reorder(int gr,int ch)2092 Layer3::reorder (int gr, int ch)
2093 {
2094 int sfb, sfb_start, sfb_lines;
2095 int window, freq, src_line, des_line;
2096
2097 if (window_switching(ch,gr) && blocktype(ch,gr) == 2) {
2098 if (mixedblock(ch,gr)) {
2099 // No reorder for low 2 subbands
2100 memcpy((void*)&ro[gr][ch][0][0], (void *)&lr[gr][ch][0][0],
2101 sizeof(double)*2*SSLIMIT);
2102
2103 /* original code
2104 for (sb=0 ; sb < 2 ; sb++) {
2105 for (ss=0 ; ss < SSLIMIT ; ss++) {
2106 ro[gr][ch][sb][ss] = lr[gr][ch][sb][ss];
2107 }
2108 }
2109 */
2110
2111 // Reordering for rest switched short
2112 sfb_start = scf_band_bound_s(3);
2113 sfb_lines=scf_band_bound_s(4) - sfb_start;
2114 sfb = 3;
2115
2116 } else { // pure short: start from sfb = 0
2117 sfb_start=0;
2118 sfb_lines=scf_band_bound_s(1);
2119 sfb = 0;
2120 }
2121
2122 for (; sfb < 13; sfb++) {
2123 for (window=0; window<3; window++)
2124 for(freq=0;freq<sfb_lines;freq++) {
2125 src_line = sfb_start*3 + window*sfb_lines + freq;
2126 des_line = (sfb_start*3) + window + (freq*3);
2127 ro[gr][ch][des_line/SSLIMIT][des_line%SSLIMIT]
2128 = lr[gr][ch][src_line/SSLIMIT][src_line%SSLIMIT];
2129 }
2130 sfb_start=scf_band_bound_s(sfb);
2131 sfb_lines=scf_band_bound_s(sfb+1) - sfb_start;
2132 }
2133
2134 } else { // long blocks
2135
2136 // copy array lr to ro
2137 memcpy((void*)&ro[gr][ch][0][0], (void *)&lr[gr][ch][0][0],
2138 sizeof(double)*SBSSLIMIT);
2139
2140 /* original code
2141 for (sb=0 ; sb < SBLIMIT ; sb++)
2142 for (ss=0 ; ss < SSLIMIT ; ss++)
2143 ro[gr][ch][sb][ss] = lr[gr][ch][sb][ss];
2144 */
2145
2146 }
2147
2148 /*
2149 for (sb=0 ; sb < SBLIMIT ; sb++)
2150 for (ss=0 ; ss < SSLIMIT ; ss++)
2151 printf("ro[%d,%d]=%f\n",sb, ss, ro[gr][ch][sb][ss]);
2152 */
2153
2154 return;
2155 }
2156
2157
2158 // perform antialiasing on sample data in "ro"
2159 // result: "hybridIn" data array
2160 CSAPI_MPEG void
antialias(int gr,int ch)2161 Layer3::antialias(int gr, int ch)
2162 {
2163 static int init = 1;
2164 static double ca[8], cs[8];
2165 double bu, bd; // upper and lower butterfly inputs
2166 int sblim, sb, ss;
2167
2168
2169 // initialize once
2170 if (init == 1) {
2171 int i;
2172 double sq;
2173 for (i = 0; i < 8; i++) {
2174 sq = sqrt(1.0 + Ci[i] * Ci[i]);
2175 cs[i] = 1.0 / sq;
2176 ca[i] = Ci[i] / sq;
2177 }
2178 init = 0;
2179 }
2180
2181 // copy all inputs
2182 memcpy((void*)&hybridIn[gr][ch][0][0], (void *)&ro[gr][ch][0][0],
2183 sizeof(double)*SBSSLIMIT);
2184
2185 /* original code
2186 for(int sb=0; sb<SBLIMIT; sb++) {
2187 for(int ss=0; ss<SSLIMIT; ss++) {
2188 hybridIn[gr][ch][sb][ss] = ro[gr][ch][sb][ss];
2189 }
2190 }
2191 */
2192
2193
2194 // return if no further work necessary
2195 if (window_switching(ch,gr) && blocktype(ch,gr) == 2 &&
2196 !mixedblock(ch,gr)) {
2197 return;
2198 }
2199
2200 if (window_switching(ch,gr) && blocktype(ch,gr) == 2 &&
2201 mixedblock(ch,gr)) {
2202 sblim = 1;
2203 } else {
2204 sblim = SBLIMIT-1;
2205 }
2206
2207 // perform 31 alias-reduction operations between each pair of sub-bands
2208 // with 8 butterflies between each pair
2209 for (sb=0; sb < sblim; sb++) {
2210 for (ss = 0; ss < 8; ss++) {
2211 bu = ro[gr][ch][sb][17-ss];
2212 bd = ro[gr][ch][sb+1][ss];
2213 hybridIn[gr][ch][sb][17-ss] = (bu * cs[ss]) - (bd * ca[ss]);
2214 hybridIn[gr][ch][sb+1][ss] = (bd * cs[ss]) + (bu * ca[ss]);
2215 }
2216 }
2217
2218 /*
2219 for(int sb=0; sb<SBLIMIT; sb++) {
2220 for(int ss=0; ss<SSLIMIT; ss++) {
2221 printf("hybridIn[%d,%d]=%f\n", sb, ss, hybridIn[gr][ch][sb][ss]);
2222 }
2223 }
2224 */
2225
2226 return;
2227 }
2228
2229
2230 // calculate hybrid synthesis filter on hybridIn samples
2231 // result: "hybridOut" data array
2232 CSAPI_MPEG void
hybrid(int gr,int ch)2233 Layer3::hybrid(int gr, int ch)
2234 {
2235 int ss, sb;
2236 int bt;
2237 double rawout[36];
2238 static double prevblck[2][SBLIMIT][SSLIMIT];
2239 static int init = 1;
2240
2241 // initialize once
2242 if (init == 1) {
2243 memset((void*)&prevblck[0][0][0], 0, 2*SBSSLIMIT*sizeof(double));
2244
2245 /* original code
2246 int i, j, k;
2247 for (i = 0; i < 2; i++)
2248 for (j = 0; j < SBLIMIT; j++)
2249 for (k = 0; k < SSLIMIT; k++)
2250 prevblck[i][j][k] = 0.0;
2251 */
2252 init = 0;
2253 }
2254
2255 // go over subbands
2256 for (sb=0; sb<SBLIMIT; sb++) {
2257
2258 bt = (window_switching(ch, gr) && mixedblock(ch,gr) &&
2259 (sb < 2)) ? 0 : blocktype(ch,gr);
2260
2261 inv_mdct(hybridIn[gr][ch][sb], rawout, bt);
2262
2263 // Overlap addition
2264 for (ss = 0; ss < SSLIMIT; ss++) {
2265 hybridOut[gr][ch][ss][sb] = rawout[ss] + prevblck[ch][sb][ss];
2266 prevblck[ch][sb][ss] = rawout[ss+18];
2267
2268 // printf("hybridOut[%d,%d]=%f\n", sb, ss, hybridOut[gr][ch][ss][sb]);
2269 // printf("prevblck[%d,%d,%d]=%f\n", ch,sb, ss, prevblck[ch][sb][ss]);
2270
2271 }
2272 }
2273
2274 return;
2275 }
2276
2277
2278 // Calculation of the inverse MDCT
2279 // In the case of short blocks the 3 output vectors are already
2280 // overlapped and added in this module
2281 CSAPI_MPEG void
inv_mdct(double in[18],double out[36],int block_type)2282 Layer3::inv_mdct(double in[18], double out[36], int block_type)
2283 {
2284 int i, m, p;
2285 static double win[4][36];
2286 static int init = 1;
2287 double sum;
2288 double tmp[12];
2289 static double COS[144]; // 4*36
2290 const static double pi12 = PI/12;
2291 const static double pi36 = PI/36;
2292 const static double pi24 = PI/24;
2293 const static double pi72 = PI/72;
2294
2295 // initialze once
2296 if (init == 1) {
2297 // Type 0
2298 for (i = 0; i < 36; i++)
2299 win[0][i] = sin(pi36 * (i + 0.5));
2300
2301 // Type 1
2302 for (i = 0; i < 18; i++)
2303 win[1][i] = sin(pi36 * (i + 0.5));
2304 for (i = 18; i < 24; i++)
2305 win[1][i] = 1.0;
2306 for (i = 24; i < 30; i++)
2307 win[1][i] = sin(pi12 * (i + 0.5 - 18));
2308 for (i = 30; i < 36; i++)
2309 win[1][i] = 0.0;
2310
2311 // Type 3
2312 for (i = 0; i < 6; i++)
2313 win[3][i] = 0.0;
2314 for (i = 6; i < 12; i++)
2315 win[3][i] = sin(pi12 * (i + 0.5 - 6));
2316 for (i = 12; i < 18; i++)
2317 win[3][i] = 1.0;
2318 for (i = 18; i < 36; i++)
2319 win[3][i] = sin(pi36 * (i + 0.5));
2320
2321 // Type 2
2322 for (i = 0; i < 12; i++)
2323 win[2][i] = sin(pi12 * (i + 0.5)) ;
2324 for (i = 12; i < 36; i++)
2325 win[2][i] = 0.0 ;
2326
2327 for (i = 0; i < 4*36; i++)
2328 COS[i] = cos(pi72 * i);
2329
2330 init = 0;
2331 }
2332
2333 // initialize output samples
2334 memset((void*)&out[0], 0, 36*sizeof(double));
2335 /* original code
2336 for (i = 0; i < 36; i++) out[i]=0;
2337 */
2338
2339 if (block_type == 2){
2340 for (i=0; i<3; i++){
2341 for (p = 0; p<12; p++){
2342 sum = 0.0;
2343 for(m=0; m<6; m++)
2344 sum += in[i+3*m] * cos( pi24*(2*p+7)*(2*m+1) );
2345 tmp[p] = sum * win[block_type][p] ;
2346 }
2347 for (p=0; p<12; p++)
2348 out[6*i+p+6] += tmp[p];
2349 }
2350 } else {
2351 for (p=0; p<36; p++){
2352 sum = 0.0;
2353 for (m=0; m < 18; m++)
2354 sum += in[m] * COS[((2*p+19)*(2*m+1))%(144)];
2355 out[p] = sum * win[block_type][p];
2356 }
2357 }
2358
2359 return;
2360 }
2361
2362
2363 // polyphase filterbank synthesis on hybridOut samples
2364 // result: pcm samples
2365 CSAPI_MPEG void
polyphase(int gr,int ch)2366 Layer3::polyphase(int gr, int ch)
2367 {
2368 int ss, sb;
2369
2370 for (ss = 0; ss < SSLIMIT; ss++) {
2371 for (sb = 0; sb < SBLIMIT; sb++) {
2372 // Frequency inversion for polyphase
2373 if ((ss%2) && (sb%2)) {
2374 hybridOut[gr][ch][ss][sb] *= -1;
2375 }
2376 }
2377
2378 // perform subband synthesis
2379 subband_syn(&(hybridOut[gr][ch][ss][0]),
2380 ch,
2381 &(pcm[gr][ch][ss][0]));
2382 }
2383
2384 return;
2385 }
2386
2387
2388 // returns scalefactors for a sub-subband
2389 CSAPI_MPEG float
scalefactor(unsigned int ch,unsigned int ss,unsigned int granule)2390 Layer3::scalefactor (unsigned int ch, unsigned int ss, unsigned int granule)
2391 {
2392 int scfg=0;
2393 int gr=granule;
2394 short which;
2395 float exponent;
2396
2397 // compute scalefactor scaling for this channel and granule
2398 const double scfscale = -0.5 * (1.0 + scalefac_scale(ch,gr));
2399
2400 if (ss >= 576) {
2401 cerr << "MaaateP: Error: sub-subbands go from 0-575" << endl;
2402 return 0.0;
2403 }
2404
2405 // compute scalefactor group & scalefactor from sub-subband (0-576)
2406 // Choose correct scalefactor group dependent on window type
2407 if (window_switching(ch,gr) && blocktype(ch,gr) == 2) {
2408 if (mixedblock(ch,gr)) {
2409 // mixed windows
2410 if (ss < 36) {
2411 // lower two subbands (= 2 x 18 subsubbands)
2412 while (ss >= scf_band_bound_l(scfg+1)) {
2413 scfg++;
2414 }
2415 exponent = scfscale * (scalefac[gr][ch].l[scfg] +
2416 preflag(ch,granule) * pretab[scfg]);
2417 } else {
2418 scfg=3;
2419 // upper 30 subbands (i.e. above subsubband 3x12)
2420 while (ss >= scf_band_bound_s(scfg+1)*3) {
2421 scfg++;
2422 }
2423 which = ss % 3;
2424 exponent = scfscale * scalefac[gr][ch].s[which][scfg];
2425 }
2426 } else {
2427 // pure short windows
2428 while (ss >= scf_band_bound_s(scfg+1)*3) {
2429 scfg++;
2430 }
2431 which = ss % 3;
2432 exponent = scfscale * scalefac[gr][ch].s[which][scfg];
2433 }
2434 } else {
2435 // long blocks: 0,1,3
2436 while (ss >= scf_band_bound_l(scfg+1)) {
2437 scfg++;
2438 }
2439 // check scfsi
2440 if (scfsi_group(ch,scfg)) {
2441 // scale factors for second granule same as for first granule
2442 gr=0;
2443 }
2444 // calculate scalefactor
2445 exponent = scfscale * (scalefac[gr][ch].l[scfg] +
2446 preflag(ch,granule) * pretab[scfg]);
2447 }
2448
2449 if (exponent == 0.0) {
2450 // it would really be 1.0, but gives unjustified weighting when summed
2451 // as scalefactor of Layer III us being used similar to Layers I+II
2452 // return 0.0;
2453 // return 1.0;
2454 return 0.0;
2455 } else {
2456 return pow (2.0f, exponent);
2457 }
2458 }
2459
2460 // returns boundary of scale factor band for long blocks
2461 CSAPI_MPEG unsigned int
scf_band_bound_l(unsigned int subbandindex)2462 Layer3::scf_band_bound_l (unsigned int subbandindex)
2463 {
2464 if (subbandindex < 23) {
2465 if (frame->version() == MPEG1) {
2466 return sfBandIndex[frame->samplingrate_index()].l[subbandindex];
2467 } else {
2468 return sfBandIndex[frame->samplingrate_index()+3].l[subbandindex];
2469 }
2470 } else {
2471 cerr << "MaaateP: ERROR: unknown subband index (l):" << subbandindex <<\
2472 endl;
2473 return 0;
2474 }
2475 }
2476
2477 // returns boundary of scale factor band for short blocks
2478 CSAPI_MPEG unsigned int
scf_band_bound_s(unsigned int subbandindex)2479 Layer3::scf_band_bound_s (unsigned int subbandindex)
2480 {
2481 if (subbandindex < 14) {
2482 if (frame->version() == MPEG1) {
2483 return sfBandIndex[frame->samplingrate_index()].s[subbandindex];
2484 } else {
2485 return sfBandIndex[frame->samplingrate_index()+3].s[subbandindex];
2486 }
2487 } else {
2488 cerr << "MaaateP: ERROR: unknown subband index (s):" << subbandindex <<\
2489 endl;
2490 return 0;
2491 }
2492 }
2493
2494 // returns bitallocation for scalefactors for lower frequency part
2495 CSAPI_MPEG unsigned int
slen1(unsigned int channel,unsigned int granule)2496 Layer3::slen1 (unsigned int channel, unsigned int granule)
2497 {
2498 return slen[0][si.ch[channel].gr[granule].scalefac_compress];
2499 }
2500
2501 // returns bitallocation for scalefactors for higher frequency part
2502 CSAPI_MPEG unsigned int
slen2(unsigned int channel,unsigned int granule)2503 Layer3::slen2 (unsigned int channel, unsigned int granule)
2504 {
2505 return slen[1][si.ch[channel].gr[granule].scalefac_compress];
2506 }
2507
2508 // returns scfsi for scalefactor goup (long windows only)
2509 // class 0: groups 0-5 for long windows
2510 // class 1: groups 6-10 for long windows
2511 // class 2: groups 11-15 for long windows
2512 // class 3: groups 16-20 for long windows
2513 CSAPI_MPEG unsigned int
scfsi_group(unsigned int channel,unsigned int scfg)2514 Layer3::scfsi_group (unsigned int channel, unsigned int scfg)
2515 {
2516 int scf_class=0;
2517 while (scfg >= sfbtable[0][scf_class+1]) scf_class++;
2518 return si.ch[channel].scfsi[scf_class];
2519 }
2520
2521 // return amount of scalefactor bands for the granule
2522 CSAPI_MPEG unsigned int
scf_bands(unsigned int channel,unsigned int granule)2523 Layer3::scf_bands(unsigned int channel, unsigned int granule)
2524 {
2525 if (blocktype(channel,granule)==2 && !mixedblock(channel,granule)) {
2526 return 36; //3*12
2527 } else if (blocktype(channel,granule)==2) {
2528 return 35; //8+9*3
2529 } else { // blocktype = 0/1/3
2530 return 21;
2531 }
2532 }
2533
2534 // sets the starting index of the buffer to the start of main_data
2535 // skipping any anxilliary data from the previous main_data
2536 CSAPI_MPEG bool
setbufstart()2537 Layer3::setbufstart()
2538 {
2539 unsigned int bytesinbuf=0; // no of byte in interim buffer
2540 if (bufend != bufstart) {
2541 // bytes available in interim buffer
2542 if (bufend < bufstart) {
2543 bytesinbuf = (bufend+MAX_INTER_BUFSIZE)-bufstart;
2544 } else {
2545 bytesinbuf = bufend-bufstart;
2546 }
2547 } else {
2548 if (si.main_data_begin > 0) {
2549 cerr << "MaaateP: no data available in interim buffer" << endl;
2550 cerr << " Cannot rewind " << si.main_data_begin << " bits." << endl;
2551 return false;
2552 } else {
2553 return true;
2554 }
2555 }
2556
2557 if (si.main_data_begin > bytesinbuf) {
2558 cerr << "MaaateP: not enough main data available in interim buffer" << endl;
2559 cerr << " Cannot rewind " << si.main_data_begin - bytesinbuf << " bits." << endl;
2560 return false;
2561 }
2562 bufstart += bytesinbuf-si.main_data_begin;
2563 bufstart %= MAX_INTER_BUFSIZE;
2564 whichbit = 0;
2565 return true;
2566 }
2567
2568 // saves the remaining data of the frame to the interim buffer
2569 // (should get implemented more efficiently!)
2570 CSAPI_MPEG bool
savetointerbuffer()2571 Layer3::savetointerbuffer()
2572 {
2573 // in case of buffer overflow: count how often
2574 unsigned int overflow=0;
2575
2576 // determine the byte from which to copy from frame's buffer
2577 unsigned int whichbyte = frame->bitsread / 8;
2578 // if (frame->bitsread%8 > 0) whichbyte++;
2579
2580 // copy until framesize is reached
2581 const unsigned int s_fsize = frame->framesize();
2582 while (whichbyte < s_fsize) {
2583
2584 #ifndef WORDS_BIGENDIAN
2585 inter_buffer[bufend] = ((unsigned char*) &(frame->buffer[whichbyte/4]))
2586 [3-(whichbyte%4)];
2587 #else
2588 inter_buffer[bufend] = ((unsigned char*)frame->buffer)[whichbyte];
2589 #endif
2590 whichbyte++;
2591 // next place to store
2592 bufend = (bufend+1)%MAX_INTER_BUFSIZE;
2593 if (bufend == bufstart) {
2594 // buffer overflow
2595 overflow++;
2596 bufstart++;
2597 }
2598 }
2599
2600 if (overflow > 0)
2601 cerr << "MaaateP: WARNING: buffer overflow in interim buffer "
2602 << "(Threw away " << overflow << " old bytes.)"
2603 << endl;
2604
2605 return true;
2606 }
2607
2608 // resets the interim buffer and its variables
2609 CSAPI_MPEG bool
clearinterbuffer()2610 Layer3::clearinterbuffer()
2611 {
2612 bufstart = bufend = whichbit = 0;
2613
2614 #ifdef DEBUG
2615 noReadBits = 0;
2616 #endif
2617
2618 return true;
2619 }
2620
2621 // reads bits from appropriate buffer
2622 CSAPI_MPEG unsigned int
readbits(unsigned int nobits)2623 Layer3::readbits(unsigned int nobits)
2624 {
2625 if (nobits == 0) {
2626 return 0;
2627 }
2628
2629 // read from interim buffer as long as there's data there
2630 static unsigned int bitmask[9] = {
2631 0, // dummy
2632 0x01, 0x03, 0x07, 0x0F,
2633 0x1F, 0x3F, 0x7F, 0xFF,
2634 };
2635
2636 unsigned int val = 0;
2637 unsigned int bitsread=0;
2638
2639 while (bitsread < nobits) {
2640 unsigned int toread = nobits-bitsread;
2641 if (bufstart == bufend) {
2642 // no more bits in interim buffer -> read from frame buffer
2643 val |= frame->readbitsfrombuffer(toread);
2644 } else {
2645 unsigned int bitavail=8-whichbit;
2646 if (toread < bitavail) {
2647 // all bits contained in inter_buffer[bufstart]
2648 val |= ((inter_buffer[bufstart] >> (bitavail-toread))
2649 & bitmask[toread]);
2650 whichbit += toread;
2651 } else {
2652 // read rest of inter_buffer[bufstart]
2653 val |= (inter_buffer[bufstart] & bitmask[bitavail])
2654 << (toread-bitavail);
2655 whichbit=0;
2656 bufstart = (bufstart+1) % MAX_INTER_BUFSIZE;
2657 }
2658 toread=min(bitavail,toread);
2659 }
2660 bitsread += toread;
2661 }
2662 main_data_bitsread += nobits;
2663
2664 return val;
2665 }
2666
2667
2668 // returns scfsi for channel and scalefactor class
2669 // this tells whether the scalefactors for granule 0 are also used for gr 1
2670 CSAPI_MPEG int
scfsi(unsigned int channel,unsigned int scfclass)2671 Layer3::scfsi (unsigned int channel, unsigned int scfclass)
2672 {
2673 return si.ch[channel].scfsi[scfclass];
2674 }
2675
2676 // returns the samples of the 576 frequency lines (decoded huffman data)
2677 CSAPI_MPEG int
sample(unsigned int ch,unsigned int sb,unsigned int ss,unsigned int gr)2678 Layer3::sample (unsigned int ch,
2679 unsigned int sb,
2680 unsigned int ss,
2681 unsigned int gr)
2682 {
2683 return is[gr][ch][sb][ss];
2684 }
2685
2686 // returns the decoded subband samples
2687 CSAPI_MPEG double
restored_sample(unsigned int channel,unsigned int subband,unsigned int subsubband,unsigned int granule)2688 Layer3::restored_sample (unsigned int channel, unsigned int subband,
2689 unsigned int subsubband, unsigned int granule)
2690 {
2691 // printf("restored_sample(ch=%d,sb=%d,ss=%d,gr=%d)\n", channel, subband, subsubband, granule);
2692 return hybridOut[granule][channel][subsubband][subband];
2693 }
2694
2695 // returns the decoded pcm samples
2696 CSAPI_MPEG short
pcm_sample(unsigned int channel,unsigned int granule,unsigned int subband,unsigned int subsubband)2697 Layer3::pcm_sample (unsigned int channel, unsigned int granule,
2698 unsigned int subband, unsigned int subsubband)
2699 {
2700 // printf("channel %d, granule=%d, subband=%d, subsubband=%d\n", channel,granule,subband,subsubband);
2701 return pcm[granule][channel][subsubband][subband];
2702 }
2703
2704 CSAPI_MPEG double
mdct_sample(unsigned int ch,unsigned int gr,unsigned int ssb)2705 Layer3::mdct_sample (unsigned int ch, unsigned int gr, unsigned int ssb) {
2706 // calculate sb and ss from ssb
2707 unsigned int sb, ss;
2708 sb = ssb / SSLIMIT;
2709 ss = ssb % SSLIMIT;
2710 return lr[gr][ch][sb][ss];
2711 }
2712
2713 // return main_data_begin offset
2714 CSAPI_MPEG unsigned int
main_data_begin()2715 Layer3::main_data_begin()
2716 {
2717 return si.main_data_begin;
2718 }
2719
2720 // return private bits
2721 CSAPI_MPEG unsigned int
private_bits()2722 Layer3::private_bits()
2723 {
2724 return si.private_bits;
2725 }
2726
2727 // return length of part2 & 3 (scalefactors+huffman data)
2728 CSAPI_MPEG unsigned int
part2_3_length(unsigned int channel,unsigned int granule)2729 Layer3::part2_3_length(unsigned int channel, unsigned int granule)
2730 {
2731 return si.ch[channel].gr[granule].part2_3_length;
2732 }
2733
2734 // big values region
2735 // contains no of sample pairs encoded from lower part of spectrum
2736 CSAPI_MPEG unsigned int
big_values(unsigned int channel,unsigned int granule)2737 Layer3::big_values(unsigned int channel, unsigned int granule)
2738 {
2739 return si.ch[channel].gr[granule].big_values;
2740 }
2741
2742 // count1 values region
2743 // contains no of sample quadruples encoded from middle part of spectrum
2744 CSAPI_MPEG unsigned int
count1_values(unsigned int channel,unsigned int granule)2745 Layer3::count1_values(unsigned int channel, unsigned int granule)
2746 {
2747 return count1_vals[granule][channel];
2748 }
2749
2750 // return global gain (= quantizer step size)
2751 CSAPI_MPEG unsigned int
global_gain(unsigned int channel,unsigned int granule)2752 Layer3::global_gain(unsigned int channel, unsigned int granule)
2753 {
2754 return si.ch[channel].gr[granule].global_gain;
2755 }
2756
2757 // return scalefac_compress which encodes biallocation for scalefactors
2758 CSAPI_MPEG unsigned int
scalefac_compress(unsigned int channel,unsigned int granule)2759 Layer3::scalefac_compress(unsigned int channel, unsigned int granule)
2760 {
2761 return si.ch[channel].gr[granule].scalefac_compress;
2762 }
2763
2764 // returns 0 for long windows and 1 for transition, short or mixed windows
2765 CSAPI_MPEG bool
window_switching(unsigned int channel,unsigned int granule)2766 Layer3::window_switching(unsigned int channel, unsigned int granule)
2767 {
2768 return (bool) (si.ch[channel].gr[granule].window_switching_flag);
2769 }
2770
2771 // returns 1 for start of short windows, 2 for short windows, 3 for end of
2772 // short windows; 0 otherwise
2773 CSAPI_MPEG unsigned int
blocktype(unsigned int channel,unsigned int granule)2774 Layer3::blocktype(unsigned int channel, unsigned int granule)
2775 {
2776 return si.ch[channel].gr[granule].block_type;
2777 }
2778
2779 // returns string for description of block type
2780 CSAPI_MPEG const char*
blocktype_str(unsigned int channel,unsigned int granule)2781 Layer3::blocktype_str(unsigned int channel, unsigned int granule)
2782 {
2783 if (si.ch[channel].gr[granule].window_switching_flag) {
2784 // window switching
2785 switch (si.ch[channel].gr[granule].block_type) {
2786 case 1:
2787 if (mixedblock(channel,granule)) {
2788 return "start block (long block), mixed";
2789 } else {
2790 return "start block (long block)";
2791 }
2792 case 2:
2793 if (mixedblock(channel,granule)) {
2794 return "short blocks, mixed";
2795 } else {
2796 return "short blocks";
2797 }
2798 case 3:
2799 if (mixedblock(channel,granule)) {
2800 return "stop block (long block), mixed";
2801 } else {
2802 return "stop block (long block)";
2803 }
2804 default:
2805 return "reserved";
2806 }
2807 } else {
2808 return "long block";
2809 }
2810 }
2811
2812 // returns true if encoded block is mixed (i.e. two lowest subbands are
2813 // transformed with long windows, upper 30 subbands with short windows);
2814 // false otherwise
2815 CSAPI_MPEG bool
mixedblock(unsigned int channel,unsigned int granule)2816 Layer3::mixedblock(unsigned int channel, unsigned int granule)
2817 {
2818 return (bool) si.ch[channel].gr[granule].mixed_block_flag;
2819 }
2820
2821 // returns which huffman table to select for big_values area
2822 CSAPI_MPEG unsigned int
table_select(unsigned int channel,unsigned int granule,unsigned int area)2823 Layer3::table_select(unsigned int channel, unsigned int granule, unsigned int area)
2824 {
2825 return si.ch[channel].gr[granule].table_select[area];
2826 }
2827
2828 // returns gain of area
2829 CSAPI_MPEG unsigned int
subblock_gain(unsigned int channel,unsigned int granule,unsigned int area)2830 Layer3::subblock_gain(unsigned int channel, unsigned int granule, unsigned int area)
2831 {
2832 return si.ch[channel].gr[granule].subblock_gain[area];
2833 }
2834
2835 // returns region 0 boundary
2836 CSAPI_MPEG unsigned int
region0_count(unsigned int channel,unsigned int granule)2837 Layer3::region0_count(unsigned int channel, unsigned int granule)
2838 {
2839 return si.ch[channel].gr[granule].region0_count;
2840 }
2841
2842 // returns region 1 boundary
2843 CSAPI_MPEG unsigned int
region1_count(unsigned int channel,unsigned int granule)2844 Layer3::region1_count(unsigned int channel, unsigned int granule)
2845 {
2846 return si.ch[channel].gr[granule].region1_count;
2847 }
2848
2849 // returns no of samples in region0
2850 CSAPI_MPEG unsigned int
region0_samps(unsigned int channel,unsigned int granule)2851 Layer3::region0_samps(unsigned int channel, unsigned int granule)
2852 {
2853 if (big_values(channel,granule) > 0) {
2854 if (window_switching(channel,granule) &&
2855 blocktype(channel,granule)==2) {
2856 // pure short windows
2857 return 36; // as scf_band_bound_s[9/3]=12 for all sampling rates
2858 } else {
2859 return min (scf_band_bound_l (region0_count(channel,granule)+1),
2860 big_values(channel,granule)*2);
2861 }
2862 } else {
2863 return 0;
2864 }
2865 }
2866
2867 // returns no of samples in region1
2868 CSAPI_MPEG unsigned int
region1_samps(unsigned int channel,unsigned int granule)2869 Layer3::region1_samps(unsigned int channel, unsigned int granule)
2870 {
2871 if (big_values(channel,granule) > 0) {
2872 if (window_switching(channel,granule) &&
2873 blocktype(channel,granule)==2) {
2874 // pure short windows, no region 2
2875 return (2*big_values(channel,granule) - 36);
2876 } else {
2877 return (min (scf_band_bound_l (region0_count(channel,granule) +
2878 region1_count(channel,granule) + 2),
2879 big_values(channel,granule)*2) -
2880 region0_samps(channel,granule));
2881 }
2882 } else {
2883 return 0;
2884 }
2885 }
2886
2887 // returns no of samples in region2
2888 CSAPI_MPEG unsigned int
region2_samps(unsigned int channel,unsigned int granule)2889 Layer3::region2_samps(unsigned int channel, unsigned int granule)
2890 {
2891 if (big_values(channel,granule) > 0) {
2892 if (window_switching(channel,granule) &&
2893 blocktype(channel,granule)==2) {
2894 // pure short windows, no region 2
2895 return 0;
2896 } else {
2897 unsigned int region0_1_samps = region1_samps(channel,granule) +
2898 region0_samps(channel,granule);
2899 if ((2*big_values(channel,granule)) > region0_1_samps) {
2900 return (2*big_values(channel,granule) -
2901 region1_samps(channel,granule) -
2902 region0_samps(channel,granule));
2903 } else {
2904 return 0;
2905 }
2906 }
2907 } else {
2908 return 0;
2909 }
2910 }
2911
2912 // returns preemphasis flag
2913 CSAPI_MPEG unsigned int
preflag(unsigned int channel,unsigned int granule)2914 Layer3::preflag(unsigned int channel, unsigned int granule)
2915 {
2916 return si.ch[channel].gr[granule].preflag;
2917 }
2918
2919 // returns scalefactor scaling (i.e. quantized with stepsize of 2 or sqrt(2))
2920 CSAPI_MPEG unsigned int
scalefac_scale(unsigned int channel,unsigned int granule)2921 Layer3::scalefac_scale(unsigned int channel, unsigned int granule)
2922 {
2923 return si.ch[channel].gr[granule].scalefac_scale;
2924 }
2925
2926 // returns which huffman table to select for count1 area
2927 CSAPI_MPEG unsigned int
count1table_select(unsigned int channel,unsigned int granule)2928 Layer3::count1table_select(unsigned int channel, unsigned int granule)
2929 {
2930 return si.ch[channel].gr[granule].count1table_select;
2931 }
2932
2933 // returns the length of the layer3-specific header in bytes
2934 CSAPI_MPEG unsigned int
sideinfo_length()2935 Layer3::sideinfo_length()
2936 {
2937 if (frame->version() == MPEG1) {
2938 if (frame->channels() == 1) {
2939 return 17; // byte
2940 } else {
2941 return 32; // byte
2942 }
2943 } else { // MPEG2
2944 if (frame->channels() == 1) {
2945 return 9; // byte
2946 } else {
2947 return 17; // byte
2948 }
2949 }
2950 }
2951
2952 // returns the no of granules
2953 CSAPI_MPEG unsigned int
granules()2954 Layer3::granules()
2955 {
2956 return ((frame->version() == MPEG2) ? 1 : 2);
2957 }
2958
2959 // returns the no of slots of main_data
2960 CSAPI_MPEG unsigned int
main_data_slots()2961 Layer3::main_data_slots()
2962 {
2963 int nSlots = (int) ((144 * frame->bitrate()) / frame->samplingrate());
2964
2965 if (frame->version() == MPEG2) {
2966 nSlots /= 2;
2967 }
2968 nSlots -= sideinfo_length();
2969 if (frame->padding()) {
2970 nSlots++;
2971 }
2972 nSlots -= 4; // deduct header
2973 if (frame->crcprotected()) {
2974 nSlots -= 2; // deduct checksum
2975 }
2976
2977 return nSlots;
2978 }
2979