1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "common.h"
4 #include "alloc_tables.h"
5
6 int sblims[5] = { 27, 30, 8, 12, 30 };
7
8 static sb_alloc al_table_0[SBLIMIT][16] =
9 {
10 { // 0
11 {0,4,0,0},{3,5,1,0},{7,3,3,2},{15,4,3,4},
12 {31,5,3,5},{63,6,3,6},{127,7,3,7},{255,8,3,8},
13 {511,9,3,9},{1023,10,3,10},{2047,11,3,11},{4095,12,3,12},
14 {8191,13,3,13},{16383,14,3,14},{32767,15,3,15},{65535,16,3,16}
15 },
16 { // 1
17 {0,4,0,0},{3,5,1,0},{7,3,3,2},{15,4,3,4},
18 {31,5,3,5},{63,6,3,6},{127,7,3,7},{255,8,3,8},
19 {511,9,3,9},{1023,10,3,10},{2047,11,3,11},{4095,12,3,12},
20 {8191,13,3,13},{16383,14,3,14},{32767,15,3,15},{65535,16,3,16}
21 },
22 { // 2
23 {0,4,0,0},{3,5,1,0},{7,3,3,2},{15,4,3,4},
24 {31,5,3,5},{63,6,3,6},{127,7,3,7},{255,8,3,8},
25 {511,9,3,9},{1023,10,3,10},{2047,11,3,11},{4095,12,3,12},
26 {8191,13,3,13},{16383,14,3,14},{32767,15,3,15},{65535,16,3,16}
27 },
28 { // 3
29 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
30 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
31 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
32 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
33 },
34 { // 4
35 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
36 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
37 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
38 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
39 },
40 { // 5
41 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
42 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
43 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
44 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
45 },
46 { // 6
47 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
48 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
49 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
50 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
51 },
52 { // 7
53 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
54 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
55 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
56 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
57 },
58 { // 8
59 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
60 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
61 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
62 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
63 },
64 { // 9
65 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
66 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
67 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
68 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
69 },
70 { // 10
71 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
72 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
73 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
74 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
75 },
76 { // 11
77 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
78 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
79 },
80 { // 12
81 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
82 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
83 },
84 { // 13
85 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
86 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
87 },
88 { // 14
89 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
90 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
91 },
92 { // 15
93 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
94 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
95 },
96 { // 16
97 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
98 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
99 },
100 { // 17
101 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
102 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
103 },
104 { // 18
105 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
106 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
107 },
108 { // 19
109 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
110 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
111 },
112 { // 20
113 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
114 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
115 },
116 { // 21
117 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
118 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
119 },
120 { // 22
121 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
122 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16 }
123 },
124 { // 23
125 {0,2,0,0},{3,5,1,0},{5,7,1,1},{65535,16,3,16}
126 },
127 { // 24
128 {0,2,0,0},{3,5,1,0},{5,7,1,1},{65535,16,3,16}
129 },
130 { // 25
131 {0,2,0,0},{3,5,1,0},{5,7,1,1},{65535,16,3,16}
132 },
133 { // 26
134 {0,2,0,0},{3,5,1,0},{5,7,1,1},{65535,16,3,16}
135 }
136 };
137
138
139 static sb_alloc al_table_1[SBLIMIT][16] =
140 {
141 {
142 {0,4,0,0},{3,5,1,0},{7,3,3,2},{15,4,3,4},
143 {31,5,3,5},{63,6,3,6},{127,7,3,7},{255,8,3,8},
144 {511,9,3,9},{1023,10,3,10},{2047,11,3,11},{4095,12,3,12},
145 {8191,13,3,13},{16383,14,3,14},{32767,15,3,15},{65535,16,3,16},
146 },
147 {
148 {0,4,0,0},{3,5,1,0},{7,3,3,2},{15,4,3,4},
149 {31,5,3,5},{63,6,3,6},{127,7,3,7},{255,8,3,8},
150 {511,9,3,9},{1023,10,3,10},{2047,11,3,11},{4095,12,3,12},
151 {8191,13,3,13},{16383,14,3,14},{32767,15,3,15},{65535,16,3,16},
152 },
153 {
154 {0,4,0,0},{3,5,1,0},{7,3,3,2},{15,4,3,4},
155 {31,5,3,5},{63,6,3,6},{127,7,3,7},{255,8,3,8},
156 {511,9,3,9},{1023,10,3,10},{2047,11,3,11},{4095,12,3,12},
157 {8191,13,3,13},{16383,14,3,14},{32767,15,3,15},{65535,16,3,16}
158 },
159 {
160 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
161 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
162 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
163 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
164 },
165 {
166 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
167 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
168 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
169 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
170 },
171 {
172 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
173 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
174 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
175 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
176 },
177 {
178 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
179 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
180 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
181 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
182 },
183 {
184 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
185 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
186 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
187 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
188 },
189 {
190 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
191 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
192 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
193 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
194 },
195 {
196 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
197 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
198 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
199 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
200 },
201 {
202 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
203 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
204 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
205 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{65535,16,3,16}
206 },
207 {
208 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
209 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
210 },
211 {
212 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
213 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
214 },
215 {
216 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
217 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
218 },
219 {
220 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
221 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
222 },
223 {
224 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
225 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
226 },
227 {
228 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
229 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
230 },
231 {
232 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
233 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
234 },
235 {
236 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
237 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
238 },
239 {
240 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
241 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
242 },
243 {
244 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
245 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
246 },
247 {
248 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
249 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
250 },
251 {
252 {0,3,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
253 {9,10,1,3},{15,4,3,4},{31,5,3,5},{65535,16,3,16}
254 },
255 {
256 {0,2,0,0},{3,5,1,0},{5,7,1,1},{65535,16,3,16}
257 },
258 {
259 {0,2,0,0},{3,5,1,0},{5,7,1,1},{65535,16,3,16}
260 },
261 {
262 {0,2,0,0},{3,5,1,0},{5,7,1,1},{65535,16,3,16}
263 },
264 {
265 {0,2,0,0},{3,5,1,0},{5,7,1,1},{65535,16,3,16}
266 },
267 {
268 {0,2,0,0},{3,5,1,0},{5,7,1,1},{65535,16,3,16}
269 },
270 {
271 {0,2,0,0},{3,5,1,0},{5,7,1,1},{65535,16,3,16}
272 },
273 {
274 {0,2,0,0},{3,5,1,0},{5,7,1,1},{65535,16,3,16}
275 }
276 };
277
278 static sb_alloc al_table_2[SBLIMIT][16] =
279 {
280 {
281 {0,4,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
282 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7},
283 {255,8,3,8},{511,9,3,9},{1023,10,3,10},{2047,11,3,11},
284 {4095,12,3,12},{8191,13,3,13},{16383,14,3,14},{32767,15,3,15}
285 },
286 {
287 {0,4,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
288 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7},
289 {255,8,3,8},{511,9,3,9},{1023,10,3,10},{2047,11,3,11},
290 {4095,12,3,12},{8191,13,3,13},{16383,14,3,14},{32767,15,3,15}
291 },
292 {
293 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
294 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
295 },
296 {
297 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
298 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
299 },
300 {
301 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
302 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
303 },
304 {
305 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
306 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
307 },
308 {
309 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
310 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
311 },
312 {
313 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
314 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
315 }
316 };
317
318 static sb_alloc al_table_3[SBLIMIT][16] =
319 {
320 {
321 {0,4,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
322 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7},
323 {255,8,3,8},{511,9,3,9},{1023,10,3,10},{2047,11,3,11},
324 {4095,12,3,12},{8191,13,3,13},{16383,14,3,14},{32767,15,3,15}
325 },
326 {
327 {0,4,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
328 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7},
329 {255,8,3,8},{511,9,3,9},{1023,10,3,10},{2047,11,3,11},
330 {4095,12,3,12},{8191,13,3,13},{16383,14,3,14},{32767,15,3,15}
331 },
332 {
333 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
334 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
335 },
336 {
337 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
338 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
339 },
340 {
341 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
342 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
343 },
344 {
345 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
346 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
347 },
348 {
349 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
350 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
351 },
352 {
353 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
354 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
355 },
356 {
357 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
358 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
359 },
360 {
361 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
362 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
363 },
364 {
365 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
366 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
367 },
368 {
369 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
370 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
371 }
372 };
373
374 static sb_alloc al_table_4[SBLIMIT][16] =
375 {
376 {
377 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
378 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
379 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
380 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{16383,14,3,14}
381 },
382 {
383 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
384 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
385 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
386 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{16383,14,3,14}
387 },
388 {
389 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
390 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
391 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
392 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{16383,14,3,14}
393 },
394 {
395 {0,4,0,0},{3,5,1,0},{5,7,1,1},{7,3,3,2},
396 {9,10,1,3},{15,4,3,4},{31,5,3,5},{63,6,3,6},
397 {127,7,3,7},{255,8,3,8},{511,9,3,9},{1023,10,3,10},
398 {2047,11,3,11},{4095,12,3,12},{8191,13,3,13},{16383,14,3,14}
399 },
400 {
401 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
402 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
403 },
404 {
405 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
406 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
407 },
408 {
409 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
410 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
411 },
412 {
413 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
414 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
415 },
416 {
417 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
418 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
419 },
420 {
421 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
422 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
423 },
424 {
425 {0,3,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3},
426 {15,4,3,4},{31,5,3,5},{63,6,3,6},{127,7,3,7}
427 },
428 {
429 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
430 },
431 {
432 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
433 },
434 {
435 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
436 },
437 {
438 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
439 },
440 {
441 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
442 },
443 {
444 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
445 },
446 {
447 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
448 },
449 {
450 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
451 },
452 {
453 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
454 },
455 {
456 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
457 },
458 {
459 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
460 },
461 {
462 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
463 },
464 {
465 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
466 },
467 {
468 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
469 },
470 {
471 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
472 },
473 {
474 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
475 },
476 {
477 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
478 },
479 {
480 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
481 },
482 {
483 {0,2,0,0},{3,5,1,0},{5,7,1,1},{9,10,1,3}
484 }
485 };
486
487 //---------------------------------------------------------------------------
488 // choose table, return # sb's
489 //---------------------------------------------------------------------------
pick_table(frame_params * fr)490 int pick_table (frame_params *fr)
491 {
492 int table, br, sfrq;
493
494 br = bitrate[2-1][fr->header->bitrate_index] / fr->stereo;
495 sfrq = s_freq[fr->header->sampling_frequency];
496
497 if (fr->header->version == MPEG_AUDIO_ID)
498 { // MPEG-1
499 if ((sfrq == 48 && br >= 56) || (br >= 56 && br <= 80)) table = 0;
500 else if (sfrq != 48 && br >= 96) table = 1;
501 else if (sfrq != 32 && br <= 48) table = 2;
502 else table = 3;
503 }
504 else table = 4; // MPEG-2 LSF
505
506 if (fr->tab_num != table)
507 {
508 fr->tab_num = table;
509 fr->sblimit = sblims[table];
510 switch(table)
511 {
512 case 1: fr->alloc = &al_table_1; break;
513 case 2: fr->alloc = &al_table_2; break;
514 case 3: fr->alloc = &al_table_3; break;
515 case 4:
516 fr->alloc = &al_table_4;
517 fprintf(stderr,"Warning! Danger! I don't think you can use LSF here!\n");
518 break;
519 default: fr->alloc = &al_table_0; break;
520 }
521 }
522 return(sblims[table]);
523 }
524
525
mc_pick_table(frame_params * fr_ps)526 void mc_pick_table (frame_params * fr_ps)
527 {
528 int tablemc, tableml, ws, sfrq;
529
530 /* BUG corrected SWKim060695 */
531 ws = fr_ps->header->sampling_frequency;
532 sfrq = s_freq[ws];
533
534 /* decision rules refer to sampling frequency */
535 /* For ML/MC channels, only get to choose between table 0 and 1.
536 See ISO13818 Section 2.5.2.12 */
537 if (sfrq == 48)
538 tablemc = 0;
539 else
540 tablemc = 1;
541
542
543 switch(tablemc) {
544 case 0:
545 fr_ps->alloc_mc = &al_table_0;
546 fr_ps->sblimit_mc = sblims[tablemc];
547 break;
548 case 1:
549 fr_ps->alloc_mc = &al_table_1;
550 fr_ps->sblimit_mc = sblims[tablemc];
551 break;
552 }
553
554
555 if (fr_ps->header->multiling_ch > 0) {
556 if (fr_ps->header->multiling_fs == 0) {
557 /* ML channels at same freq as main channels */
558 fr_ps->tab_num_ml = fr_ps->tab_num_mc;
559 fr_ps->alloc_ml = fr_ps->alloc_mc;
560 fr_ps->sblimit_ml = fr_ps->sblimit_mc;
561 } else {
562 /* ML channels at half frequency. i.e. LSF */
563 tableml = 4;
564 fr_ps->alloc_ml = &al_table_4;
565 fr_ps->sblimit_ml = sblims[4];
566 }
567 } /* ml_fs==0 */
568 /* ml_ch>0 */
569 if (verbosity >= 2) {
570 printf ("Multchannel uses : sblim = %d, table = %d\n", fr_ps->sblimit_mc,
571 fr_ps->tab_num_mc);
572 if (fr_ps->header->multiling_ch > 0)
573 printf ("Multilingual uses : sblim = %d, table = %d\n", fr_ps->sblimit_ml,
574 fr_ps->tab_num_ml);
575 }
576 }
577