diff options
Diffstat (limited to 'apps/plugins/mp3_encoder.c')
-rw-r--r-- | apps/plugins/mp3_encoder.c | 2008 |
1 files changed, 2008 insertions, 0 deletions
diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c new file mode 100644 index 0000000000..c84e158aa1 --- /dev/null +++ b/apps/plugins/mp3_encoder.c | |||
@@ -0,0 +1,2008 @@ | |||
1 | // Shine is an MP3 encoder | ||
2 | // Copyright (C) 1999-2000 Gabriel Bouvigne | ||
3 | // | ||
4 | // This library is free software; you can redistribute it and/or | ||
5 | // modify it under the terms of the GNU Library General Public | ||
6 | // License as published by the Free Software Foundation; either | ||
7 | // version 2 of the License, or (at your option) any later version. | ||
8 | // | ||
9 | // This library is distributed in the hope that it will be useful, | ||
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | // Library General Public License for more details. | ||
13 | |||
14 | #include <stdio.h> | ||
15 | |||
16 | #define samp_per_frame 1152 | ||
17 | #define samp_per_frame2 576 | ||
18 | #define HAN_SIZE 512 | ||
19 | #define SBLIMIT 32 | ||
20 | #define WAVE_RIFF_PCM 0 | ||
21 | #define MAX_CHANNELS 2 | ||
22 | #define MAX_GRANULES 2 | ||
23 | #define HTN 34 | ||
24 | #define true 1 | ||
25 | #define false 0 | ||
26 | #define uint32 unsigned int | ||
27 | #define uint16 unsigned short | ||
28 | #define uint8 unsigned char | ||
29 | #define enct8 unsigned char | ||
30 | #ifndef bool | ||
31 | #define bool int | ||
32 | #endif | ||
33 | |||
34 | enum e_byte_order { order_unknown, order_bigEndian, order_littleEndian }; | ||
35 | |||
36 | #include "plugin.h" | ||
37 | #ifdef SIMULATOR | ||
38 | #define LINE_ATTR | ||
39 | #define IDATA_ATTR | ||
40 | #else | ||
41 | #define LINE_ATTR __attribute__ ((aligned (16))) | ||
42 | #define IDATA_ATTR __attribute__ ((section(".idata"))) | ||
43 | #endif | ||
44 | #define PFILE int* | ||
45 | #define memcpy rb->memcpy | ||
46 | #define memset rb->memset | ||
47 | |||
48 | static struct plugin_api* rb; | ||
49 | extern char iramcopy[]; | ||
50 | extern char iramstart[]; | ||
51 | extern char iramend[]; | ||
52 | |||
53 | typedef struct { | ||
54 | PFILE file; | ||
55 | int channels; | ||
56 | int bits; | ||
57 | long samplerate; | ||
58 | long total_samples; | ||
59 | long length; | ||
60 | } wave_t; | ||
61 | |||
62 | typedef struct { | ||
63 | int type; | ||
64 | int layr; | ||
65 | int mode; | ||
66 | int bitr; | ||
67 | int emph; | ||
68 | int padding; | ||
69 | long bits_per_frame; | ||
70 | long bitrate_index; | ||
71 | int samplerate_index; | ||
72 | int crc; | ||
73 | int ext; | ||
74 | int mode_ext; | ||
75 | int copyright; | ||
76 | int original; | ||
77 | } mpeg_t; | ||
78 | |||
79 | typedef struct { | ||
80 | enum e_byte_order byte_order; | ||
81 | char* infile; | ||
82 | wave_t wave; | ||
83 | char* outfile; | ||
84 | mpeg_t mpeg; | ||
85 | } config_t; | ||
86 | |||
87 | typedef struct { | ||
88 | int bitpos; | ||
89 | uint32 bbuf[257]; | ||
90 | } BF_Data; | ||
91 | |||
92 | /* Side information */ | ||
93 | typedef struct { | ||
94 | unsigned part2_3_length; | ||
95 | unsigned big_values; | ||
96 | int count1; | ||
97 | unsigned global_gain; | ||
98 | unsigned table_select[4]; | ||
99 | unsigned region0_count; | ||
100 | unsigned region1_count; | ||
101 | unsigned address1; | ||
102 | unsigned address2; | ||
103 | unsigned address3; | ||
104 | long quantizerStepSize; | ||
105 | } side_info_t; | ||
106 | |||
107 | struct huffcodetab { | ||
108 | int xlen; /*max. x-index+ */ | ||
109 | int ylen; /*max. y-index+ */ | ||
110 | int linbits; /*number of linbits */ | ||
111 | int linmax; /*max number stored in linbits */ | ||
112 | const uint16 *table; /*pointer to array[xlen][ylen] */ | ||
113 | const uint8 *hlen; /*pointer to array[xlen][ylen] */ | ||
114 | }; | ||
115 | |||
116 | /* !!!!!!!! start of IRAM area: do not insert before x_int1 array !!!!!!!!!!!!! */ | ||
117 | short x_int0 [HAN_SIZE] IDATA_ATTR LINE_ATTR; // 1024 Bytes | ||
118 | int mdct_freq [2][2][samp_per_frame2] IDATA_ATTR LINE_ATTR; // 9216 Bytes | ||
119 | short x_int1 [HAN_SIZE] IDATA_ATTR LINE_ATTR; // 1024 Bytes | ||
120 | /* !!!!!!!!!!!!!!!!!!!!! here you may insert other data !!!!!!!!!!!!!!!!!!!!!!! */ | ||
121 | uint8 int2idx [4096] IDATA_ATTR LINE_ATTR; // 4096 Bytes | ||
122 | enct8 enc_data [2][2][samp_per_frame2] IDATA_ATTR LINE_ATTR; // 4608 Bytes | ||
123 | short y_int [64] IDATA_ATTR LINE_ATTR; // 256 Bytes | ||
124 | int off [2] IDATA_ATTR LINE_ATTR; // 16 Bytes | ||
125 | int scalefac_long[23] IDATA_ATTR LINE_ATTR; // 96 Bytes | ||
126 | int mdct_in [36] IDATA_ATTR LINE_ATTR; // 144 Bytes | ||
127 | int sb_sample [2][3][18][SBLIMIT] IDATA_ATTR LINE_ATTR; // 13824 Bytes | ||
128 | BF_Data CodedData IDATA_ATTR LINE_ATTR; // 1040 Bytes | ||
129 | int ca_int [8] IDATA_ATTR LINE_ATTR; // 32 Bytes | ||
130 | int cs_int [8] IDATA_ATTR LINE_ATTR; // 32 Bytes | ||
131 | int win_int [18][36] IDATA_ATTR LINE_ATTR; // 2592 Bytes | ||
132 | short filter_int [SBLIMIT][64] IDATA_ATTR LINE_ATTR; // 8192 Bytes | ||
133 | short enwindow_int[512] IDATA_ATTR LINE_ATTR; // 1024 Bytes | ||
134 | uint8 ht_count1 [2][2][16] IDATA_ATTR LINE_ATTR; // 64 Bytes | ||
135 | uint16 t1HB [ 4] IDATA_ATTR LINE_ATTR; // Bytes | ||
136 | uint16 t2HB [ 9] IDATA_ATTR LINE_ATTR; // Bytes | ||
137 | uint16 t3HB [ 9] IDATA_ATTR LINE_ATTR; // Bytes | ||
138 | uint16 t5HB [ 16] IDATA_ATTR LINE_ATTR; // Bytes | ||
139 | uint16 t6HB [ 16] IDATA_ATTR LINE_ATTR; // Bytes | ||
140 | uint16 t7HB [ 36] IDATA_ATTR LINE_ATTR; // Bytes | ||
141 | uint16 t8HB [ 36] IDATA_ATTR LINE_ATTR; // Bytes | ||
142 | uint16 t9HB [ 36] IDATA_ATTR LINE_ATTR; // Bytes | ||
143 | uint16 t10HB [ 64] IDATA_ATTR LINE_ATTR; // Bytes | ||
144 | uint16 t11HB [ 64] IDATA_ATTR LINE_ATTR; // Bytes | ||
145 | uint16 t12HB [ 64] IDATA_ATTR LINE_ATTR; // Bytes | ||
146 | uint16 t13HB [256] IDATA_ATTR LINE_ATTR; // Bytes | ||
147 | uint16 t15HB [256] IDATA_ATTR LINE_ATTR; // Bytes | ||
148 | uint16 t16HB [256] IDATA_ATTR LINE_ATTR; // Bytes | ||
149 | uint16 t24HB [256] IDATA_ATTR LINE_ATTR; // Bytes | ||
150 | uint8 t1l [ 4] IDATA_ATTR LINE_ATTR; // Bytes | ||
151 | uint8 t2l [ 9] IDATA_ATTR LINE_ATTR; // Bytes | ||
152 | uint8 t3l [ 9] IDATA_ATTR LINE_ATTR; // Bytes | ||
153 | uint8 t5l [ 16] IDATA_ATTR LINE_ATTR; // Bytes | ||
154 | uint8 t6l [ 16] IDATA_ATTR LINE_ATTR; // Bytes | ||
155 | uint8 t7l [ 36] IDATA_ATTR LINE_ATTR; // Bytes | ||
156 | uint8 t8l [ 36] IDATA_ATTR LINE_ATTR; // Bytes | ||
157 | uint8 t9l [ 36] IDATA_ATTR LINE_ATTR; // Bytes | ||
158 | uint8 t10l [ 64] IDATA_ATTR LINE_ATTR; // Bytes | ||
159 | uint8 t11l [ 64] IDATA_ATTR LINE_ATTR; // Bytes | ||
160 | uint8 t12l [ 64] IDATA_ATTR LINE_ATTR; // Bytes | ||
161 | uint8 t13l [256] IDATA_ATTR LINE_ATTR; // Bytes | ||
162 | uint8 t15l [256] IDATA_ATTR LINE_ATTR; // Bytes | ||
163 | uint8 t16l [256] IDATA_ATTR LINE_ATTR; // Bytes | ||
164 | uint8 t24l [256] IDATA_ATTR LINE_ATTR; // Bytes | ||
165 | struct huffcodetab ht [HTN] IDATA_ATTR LINE_ATTR; // Bytes | ||
166 | |||
167 | static const uint8 ht_count1_const[2][2][16] = | ||
168 | { { { 1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1 }, /* table0 */ | ||
169 | { 1, 5, 5, 7, 5, 8, 7, 9, 5, 7, 7, 9, 7, 9, 9,10 } }, /* hleng0 */ | ||
170 | { {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, /* table1 */ | ||
171 | { 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 } } }; /* hleng1 */ | ||
172 | |||
173 | static const uint16 t1HB_const[4] = {1, 1, 1, 0}; | ||
174 | static const uint16 t2HB_const[9] = {1, 2, 1, 3, 1, 1, 3, 2, 0}; | ||
175 | static const uint16 t3HB_const[9] = {3, 2, 1, 1, 1, 1, 3, 2, 0}; | ||
176 | static const uint16 t5HB_const[16] = {1, 2, 6, 5, 3, 1, 4, 4, 7, 5, 7, 1, 6, 1, 1, 0}; | ||
177 | static const uint16 t6HB_const[16] = {7, 3, 5, 1, 6, 2, 3, 2, 5, 4, 4, 1, 3, 3, 2, 0}; | ||
178 | static const uint16 t7HB_const[36] = {1, 2, 10, 19, 16, 10, 3, 3, 7, 10, 5, 3, 11, 4, 13, 17, 8, 4, 12, 11, 18, 15, 11, 2, 7, 6, 9, 14, 3, 1, 6, 4, 5, 3, 2, 0}; | ||
179 | static const uint16 t8HB_const[36] = {3, 4, 6, 18, 12, 5, 5, 1, 2, 16, 9, 3, 7, 3, 5, 14, 7, 3, 19, 17, 15, 13, 10, 4, 13, 5, 8, 11, 5, 1, 12, 4, 4, 1, 1, 0}; | ||
180 | static const uint16 t9HB_const[36] = {7, 5, 9, 14, 15, 7, 6, 4, 5, 5, 6, 7, 7, 6, 8, 8, 8, 5, 15, 6, 9, 10, 5, 1, 11, 7, 9, 6, 4, 1, 14, 4, 6, 2, 6, 0}; | ||
181 | static const uint16 t10HB_const[64] = {1, 2, 10, 23, 35, 30, 12, 17, 3, 3, 8, 12, 18, 21, 12, 7, 11, 9, 15, 21, 32, 40, 19, 6, 14, 13, 22, 34, 46, 23, 18, 7, 20, 19, 33, 47, 27, 22, 9, 3, 31, 22, 41, 26, 21, 20, 5, 3, 14, 13, 10, 11, 16, 6, 5, 1, 9, 8, 7, 8, 4 , 4, 2, 0}; | ||
182 | static const uint16 t11HB_const[64] = {3, 4, 10, 24, 34, 33, 21, 15, 5, 3, 4, 10, 32, 17, 11, 10, 11, 7, 13, 18, 30, 31, 20, 5, 25, 11, 19, 59, 27, 18, 12, 5, 35, 33, 31, 58, 30, 16, 7, 5, 28, 26, 32, 19, 17, 15, 8, 14, 14, 12, 9, 13, 14, 9, 4, 1, 11, 4, 6, 6, 6, 3, 2, 0}; | ||
183 | static const uint16 t12HB_const[64] = {9, 6, 16, 33, 41, 39, 38, 26, 7, 5, 6, 9, 23, 16, 26, 11, 17, 7, 11, 14, 21, 30, 10, 7, 17, 10, 15, 12, 18, 28, 14, 5, 32, 13, 22, 19, 18, 16, 9, 5, 40, 17, 31, 29, 17, 13, 4, 2, 27, 12, 11, 15, 10, 7, 4, 1, 27, 12, 8, 12 , 6, 3, 1, 0}; | ||
184 | static const uint16 t13HB_const[256] = {1, 5, 14, 21, 34, 51, 46, 71, 42, 52, 68, 52, 67, 44, 43, 19, 3, 4, 12, 19, 31, 26, 44, 33, 31, 24, 32, 24, 31, 35, 22, 14, 15, 13, 23, 36, 59, 49, 77, 65, 29, 40, 30, 40, 27, 33, 42, 16, 22, | ||
185 | 20, 37, 61, 56, 79, 73, 64, 43, 76, 56, 37, 26, 31, 25, 14, 35, 16, 60, 57, 97, 75, 114, 91, 54, 73, 55, 41, 48, 53, 23, 24, 58, 27, 50, 96, 76, 70, 93, 84, 77, 58, 79, 29, 74, 49, 41, 17, 47, | ||
186 | 45, 78, 74, 115, 94, 90, 79, 69, 83, 71, 50, 59, 38, 36, 15, 72, 34, 56, 95, 92, 85, 91, 90, 86, 73, 77, 65, 51, 44, 43, 42, 43, 20, 30, 44, 55, 78, 72, 87, 78, 61, 46, 54, 37, 30, 20, 16, 53, | ||
187 | 25, 41, 37, 44, 59, 54, 81, 66, 76, 57, 54, 37, 18, 39, 11, 35, 33, 31, 57, 42, 82, 72, 80, 47, 58, 55, 21, 22, 26, 38, 22, 53, 25, 23, 38, 70, 60, 51, 36, 55, 26, 34, 23, 27, 14, 9, 7, 34, 32, | ||
188 | 28, 39, 49, 75, 30, 52, 48, 40, 52, 28, 18, 17, 9, 5, 45, 21, 34, 64, 56, 50, 49, 45, 31, 19, 12, 15, 10, 7, 6, 3, 48, 23, 20, 39, 36, 35, 53, 21, 16, 23, 13, 10, 6, 1, 4, 2, 16, 15, 17, 27, 25, | ||
189 | 20, 29, 11, 17, 12, 16, 8, 1, 1, 0, 1}; | ||
190 | static const uint16 t15HB_const[256] = {7, 12, 18, 53, 47, 76, 124, 108, 89, 123, 108, 119, 107, 81, 122, 63, 13, 5, 16, 27, 46, 36, 61, 51, 42, 70, 52, 83, 65, 41, 59, 36, 19, 17, 15, 24, 41, 34, 59, 48, 40, 64, 50, 78, 62, 80, 56, | ||
191 | 33, 29, 28, 25, 43, 39, 63, 55, 93, 76, 59, 93, 72, 54, 75, 50, 29, 52, 22, 42, 40, 67, 57, 95, 79, 72, 57, 89, 69, 49, 66, 46, 27, 77, 37, 35, 66, 58, 52, 91, 74, 62, 48, 79, 63, 90, 62, 40, 38, | ||
192 | 125, 32, 60, 56, 50, 92, 78, 65, 55, 87, 71, 51, 73, 51, 70, 30, 109, 53, 49, 94, 88, 75, 66, 122, 91, 73, 56, 42, 64, 44, 21, 25, 90, 43, 41, 77, 73, 63, 56, 92, 77, 66, 47, 67, 48, 53, 36, 20, | ||
193 | 71, 34, 67, 60, 58, 49, 88, 76, 67, 106, 71, 54, 38, 39, 23, 15, 109, 53, 51, 47, 90, 82, 58, 57, 48, 72, 57, 41, 23, 27, 62, 9, 86, 42, 40, 37, 70, 64, 52, 43, 70, 55, 42, 25, 29, 18, 11, 11, | ||
194 | 118, 68, 30, 55, 50, 46, 74, 65, 49, 39, 24, 16, 22, 13, 14, 7, 91, 44, 39, 38, 34, 63, 52, 45, 31, 52, 28, 19, 14, 8, 9, 3, 123, 60, 58, 53, 47, 43, 32, 22, 37, 24, 17, 12, 15, 10, 2, 1, 71, | ||
195 | 37, 34, 30, 28, 20, 17, 26, 21, 16, 10, 6, 8, 6, 2, 0}; | ||
196 | static const uint16 t16HB_const[256] = {1, 5, 14, 44, 74, 63, 110, 93, 172, 149, 138, 242, 225, 195, 376, 17, 3, 4, 12, 20, 35, 62, 53, 47, 83, 75, 68, 119, 201, 107, 207, 9, 15, 13, 23, 38, 67, 58, 103, 90, 161, 72, 127, 117, | ||
197 | 110, 209, 206, 16, 45, 21, 39, 69, 64, 114, 99, 87, 158, 140, 252, 212, 199, 387, 365, 26, 75, 36, 68, 65, 115, 101, 179, 164, 155, 264, 246, 226, 395, 382, 362, 9, 66, 30, 59, 56, 102, | ||
198 | 185, 173, 265, 142, 253, 232, 400, 388, 378, 445, 16, 111, 54, 52, 100, 184, 178, 160, 133, 257, 244, 228, 217, 385, 366, 715, 10, 98, 48, 91, 88, 165, 157, 148, 261, 248, 407, 397, 372, | ||
199 | 380, 889, 884, 8, 85, 84, 81, 159, 156, 143, 260, 249, 427, 401, 392, 383, 727, 713, 708, 7, 154, 76, 73, 141, 131, 256, 245, 426, 406, 394, 384, 735, 359, 710, 352, 11, 139, 129, 67, 125, | ||
200 | 247, 233, 229, 219, 393, 743, 737, 720, 885, 882, 439, 4, 243, 120, 118, 115, 227, 223, 396, 746, 742, 736, 721, 712, 706, 223, 436, 6, 202, 224, 222, 218, 216, 389, 386, 381, 364, 888, | ||
201 | 443, 707, 440, 437, 1728, 4, 747, 211, 210, 208, 370, 379, 734, 723, 714, 1735, 883, 877, 876, 3459, 865, 2, 377, 369, 102, 187, 726, 722, 358, 711, 709, 866, 1734, 871, 3458, 870, 434, | ||
202 | 0, 12, 10, 7, 11, 10, 17, 11, 9, 13, 12, 10, 7, 5, 3, 1, 3}; | ||
203 | static const uint16 t24HB_const[256] = {15, 13, 46, 80, 146, 262, 248, 434, 426, 669, 653, 649, 621, 517, 1032, 88, 14, 12, 21, 38, 71, 130, 122, 216, 209, 198, 327, 345, 319, 297, 279, 42, 47, 22, 41, 74, 68, 128, 120, 221, | ||
204 | 207, 194, 182, 340, 315, 295, 541, 18, 81, 39, 75, 70, 134, 125, 116, 220, 204, 190, 178, 325, 311, 293, 271, 16, 147, 72, 69, 135, 127, 118, 112, 210, 200, 188, 352, 323, 306, 285, | ||
205 | 540, 14, 263, 66, 129, 126, 119, 114, 214, 202, 192, 180, 341, 317, 301, 281, 262, 12, 249, 123, 121, 117, 113, 215, 206, 195, 185, 347, 330, 308, 291, 272, 520, 10, 435, 115, 111, | ||
206 | 109, 211, 203, 196, 187, 353, 332, 313, 298, 283, 531, 381, 17, 427, 212, 208, 205, 201, 193, 186, 177, 169, 320, 303, 286, 268, 514, 377, 16, 335, 199, 197, 191, 189, 181, 174, 333, | ||
207 | 321, 305, 289, 275, 521, 379, 371, 11, 668, 184, 183, 179, 175, 344, 331, 314, 304, 290, 277, 530, 383, 373, 366, 10, 652, 346, 171, 168, 164, 318, 309, 299, 287, 276, 263, 513, 375, | ||
208 | 368, 362, 6, 648, 322, 316, 312, 307, 302, 292, 284, 269, 261, 512, 376, 370, 364, 359, 4, 620, 300, 296, 294, 288, 282, 273, 266, 515, 380, 374, 369, 365, 361, 357, 2, 1033, 280, 278, | ||
209 | 274, 267, 264, 259, 382, 378, 372, 367, 363, 360, 358, 356, 0, 43, 20, 19, 17, 15, 13, 11, 9, 7, 6, 4, 7, 5, 3, 1, 3}; | ||
210 | |||
211 | static const uint8 t1l_const[4] = {1, 3, 2, 3}; | ||
212 | static const uint8 t2l_const[9] = {1, 3, 6, 3, 3, 5, 5, 5, 6}; | ||
213 | static const uint8 t3l_const[9] = {2, 2, 6, 3, 2, 5, 5, 5, 6}; | ||
214 | static const uint8 t5l_const[16] = {1, 3, 6, 7, 3, 3, 6, 7, 6, 6, 7, 8, 7, 6, 7, 8}; | ||
215 | static const uint8 t6l_const[16] = {3, 3, 5, 7, 3, 2, 4, 5, 4, 4, 5, 6, 6, 5, 6, 7}; | ||
216 | static const uint8 t7l_const[36] = {1, 3, 6, 8, 8, 9, 3, 4, 6, 7, 7, 8, 6, 5, 7, 8, 8, 9, 7, 7, 8, 9, 9, 9, 7, 7, 8, 9, 9, 10, 8, 8, 9, 10, 10, 10}; | ||
217 | static const uint8 t8l_const[36] = {2, 3, 6, 8, 8, 9, 3, 2, 4, 8, 8, 8, 6, 4, 6, 8, 8, 9, 8, 8, 8, 9, 9, 10, 8, 7, 8, 9, 10, 10, 9, 8, 9, 9, 11, 11}; | ||
218 | static const uint8 t9l_const[36] = {3, 3, 5, 6, 8, 9, 3, 3, 4, 5, 6, 8, 4, 4, 5, 6, 7, 8, 6, 5, 6, 7, 7, 8, 7, 6, 7, 7, 8, 9, 8, 7, 8, 8, 9, 9}; | ||
219 | static const uint8 t10l_const[64] = {1, 3, 6, 8, 9, 9, 9, 10, 3, 4, 6, 7, 8, 9, 8, 8, 6, 6, 7, 8, 9, 10, 9, 9, 7, 7, 8, 9, 10, 10, 9, 10, 8, 8, 9, 10, 10, 10, 10, 10, 9, 9, 10, 10, 11, 11, 10, 11, 8, 8, 9, 10, 10, 10, 11, 11, 9, 8, 9, 10, 10, 11, 11, 11}; | ||
220 | static const uint8 t11l_const[64] = {2, 3, 5, 7, 8, 9, 8, 9, 3, 3, 4, 6, 8, 8, 7, 8, 5, 5, 6, 7, 8, 9, 8, 8, 7, 6, 7, 9, 8, 10, 8, 9, 8, 8, 8, 9, 9, 10, 9, 10, 8, 8, 9, 10, 10, 11, 10, 11, 8, 7, 7, 8, 9, 10, 10, 10, 8, 7, 8, 9, 10, 10, 10, 10}; | ||
221 | static const uint8 t12l_const[64] = {4, 3, 5, 7, 8, 9, 9, 9, 3, 3, 4, 5, 7, 7, 8, 8, 5, 4, 5, 6, 7, 8, 7, 8, 6, 5, 6, 6, 7, 8, 8, 8, 7, 6, 7, 7, 8, 8, 8, 9, 8, 7, 8, 8, 8, 9, 8, 9, 8, 7, 7, 8, 8, 9, 9, 10, 9, 8, 8, 9, 9, 9, 9, 10}; | ||
222 | static const uint8 t13l_const[256] = {1, 4, 6, 7, 8, 9, 9, 10, 9, 10, 11, 11, 12, 12, 13, 13, 3, 4, 6, 7, 8, 8, 9, 9, 9, 9, 10, 10, 11, 12, 12, 12, 6, 6, 7, 8, 9, 9, 10, 10, 9, 10, 10, 11, 11, 12, 13, 13, 7, 7, 8, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 13, 13, | ||
223 | 8, 7, 9, 9, 10, 10, 11, 11, 10, 11, 11, 12, 12, 13, 13, 14, 9, 8, 9, 10, 10, 10, 11, 11, 11, 11, 12, 11, 13, 13, 14, 14, 9, 9, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 13, 13, 14, 14, 10, 9, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 16, 16, 9, 8, 9, 10, | ||
224 | 10, 11, 11, 12, 12, 12, 12, 13, 13, 14, 15, 15, 10, 9, 10, 10, 11, 11, 11, 13, 12, 13, 13, 14, 14, 14, 16, 15, 10, 10, 10, 11, 11, 12, 12, 13, 12, 13, 14, 13, 14, 15, 16, 17, 11, 10, 10, 11, 12, 12, 12, 12, 13, 13, 13, 14, 15, 15, 15, 16, 11, 11, 11, 12, 12, | ||
225 | 13, 12, 13, 14, 14, 15, 15, 15, 16, 16, 16, 12, 11, 12, 13, 13, 13, 14, 14, 14, 14, 14, 15, 16, 15, 16, 16, 13, 12, 12, 13, 13, 13, 15, 14, 14, 17, 15, 15, 15, 17, 16, 16, 12, 12, 13, 14, 14, 14, 15, 14, 15, 15, 16, 16, 19, 18, 19, 16}; | ||
226 | static const uint8 t15l_const[256] = {3, 4, 5, 7, 7, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 13, 4, 3, 5, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 5, 5, 5, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 11, 11, 11, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 7, 6, 7, | ||
227 | 7, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 8, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 11, 12, 9, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 9, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 12, 9, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, | ||
228 | 12, 12, 12, 9, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 10, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 13, 12, 10, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 11, 10, 9, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 13, 13, | ||
229 | 11, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 12, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 12, 13, 12, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13}; | ||
230 | static const uint8 t16l_const[256] = {1, 4, 6, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 9, 3, 4, 6, 7, 8, 9, 9, 9, 10, 10, 10, 11, 12, 11, 12, 8, 6, 6, 7, 8, 9, 9, 10, 10, 11, 10, 11, 11, 11, 12, 12, 9, 8, 7, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, | ||
231 | 10, 9, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 9, 9, 8, 9, 9, 10, 11, 11, 12, 11, 12, 12, 13, 13, 13, 14, 10, 10, 9, 9, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 14, 10, 10, 9, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 13, 15, 15, 10, 10, 10, | ||
232 | 10, 11, 11, 11, 12, 12, 13, 13, 13, 13, 14, 14, 14, 10, 11, 10, 10, 11, 11, 12, 12, 13, 13, 13, 13, 14, 13, 14, 13, 11, 11, 11, 10, 11, 12, 12, 12, 12, 13, 14, 14, 14, 15, 15, 14, 10, 12, 11, 11, 11, 12, 12, 13, 14, 14, 14, 14, 14, 14, 13, 14, 11, 12, 12, | ||
233 | 12, 12, 12, 13, 13, 13, 13, 15, 14, 14, 14, 14, 16, 11, 14, 12, 12, 12, 13, 13, 14, 14, 14, 16, 15, 15, 15, 17, 15, 11, 13, 13, 11, 12, 14, 14, 13, 14, 14, 15, 16, 15, 17, 15, 14, 11, 9, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 8}; | ||
234 | static const uint8 t24l_const[256] = {4, 4, 6, 7, 8, 9, 9, 10, 10, 11, 11, 11, 11, 11, 12, 9, 4, 4, 5, 6, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10, 8, 6, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 7, 7, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 7, 8, 7, 7, 8, | ||
235 | 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 7, 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 7, 9, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 7, 10, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 8, 10, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, | ||
236 | 8, 10, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 8, 11, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 8, 11, 10, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 8, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 8, 11, 10, 10, | ||
237 | 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 8, 12, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 4}; | ||
238 | |||
239 | const struct huffcodetab ht_const[HTN] = | ||
240 | { | ||
241 | { 0, 0, 0, 0, NULL, NULL}, | ||
242 | { 2, 2, 0, 0, t1HB, t1l}, | ||
243 | { 3, 3, 0, 0, t2HB, t2l}, | ||
244 | { 3, 3, 0, 0, t3HB, t3l}, | ||
245 | { 0, 0, 0, 0, NULL, NULL},// Apparently not used | ||
246 | { 4, 4, 0, 0, t5HB, t5l}, | ||
247 | { 4, 4, 0, 0, t6HB, t6l}, | ||
248 | { 6, 6, 0, 0, t7HB, t7l}, | ||
249 | { 6, 6, 0, 0, t8HB, t8l}, | ||
250 | { 6, 6, 0, 0, t9HB, t9l}, | ||
251 | { 8, 8, 0, 0,t10HB, t10l}, | ||
252 | { 8, 8, 0, 0,t11HB, t11l}, | ||
253 | { 8, 8, 0, 0,t12HB, t12l}, | ||
254 | {16,16, 0, 0,t13HB, t13l}, | ||
255 | { 0, 0, 0, 0, NULL, NULL},// Apparently not used | ||
256 | {16,16, 0, 0,t15HB, t15l}, | ||
257 | {16,16, 1, 1,t16HB, t16l}, | ||
258 | {16,16, 2, 3,t16HB, t16l}, | ||
259 | {16,16, 3, 7,t16HB, t16l}, | ||
260 | {16,16, 4, 15,t16HB, t16l}, | ||
261 | {16,16, 6, 63,t16HB, t16l}, | ||
262 | {16,16, 8, 255,t16HB, t16l}, | ||
263 | {16,16,10,1023,t16HB, t16l}, | ||
264 | {16,16,13,8191,t16HB, t16l}, | ||
265 | {16,16, 4, 15,t24HB, t24l}, | ||
266 | {16,16, 5, 31,t24HB, t24l}, | ||
267 | {16,16, 6, 63,t24HB, t24l}, | ||
268 | {16,16, 7, 127,t24HB, t24l}, | ||
269 | {16,16, 8, 255,t24HB, t24l}, | ||
270 | {16,16, 9, 511,t24HB, t24l}, | ||
271 | {16,16,11,2047,t24HB, t24l}, | ||
272 | {16,16,13,8191,t24HB, t24l} }; | ||
273 | |||
274 | const struct | ||
275 | { | ||
276 | unsigned region0_count; | ||
277 | unsigned region1_count; | ||
278 | } subdv_table[23] = | ||
279 | { {0, 0}, /* 0 bands */ | ||
280 | {0, 0}, /* 1 bands */ | ||
281 | {0, 0}, /* 2 bands */ | ||
282 | {0, 0}, /* 3 bands */ | ||
283 | {0, 0}, /* 4 bands */ | ||
284 | {0, 1}, /* 5 bands */ | ||
285 | {1, 1}, /* 6 bands */ | ||
286 | {1, 1}, /* 7 bands */ | ||
287 | {1, 2}, /* 8 bands */ | ||
288 | {2, 2}, /* 9 bands */ | ||
289 | {2, 3}, /* 10 bands */ | ||
290 | {2, 3}, /* 11 bands */ | ||
291 | {3, 4}, /* 12 bands */ | ||
292 | {3, 4}, /* 13 bands */ | ||
293 | {3, 4}, /* 14 bands */ | ||
294 | {4, 5}, /* 15 bands */ | ||
295 | {4, 5}, /* 16 bands */ | ||
296 | {4, 6}, /* 17 bands */ | ||
297 | {5, 6}, /* 18 bands */ | ||
298 | {5, 6}, /* 19 bands */ | ||
299 | {5, 7}, /* 20 bands */ | ||
300 | {6, 7}, /* 21 bands */ | ||
301 | {6, 7}, /* 22 bands */ | ||
302 | }; | ||
303 | |||
304 | /* This is table B.9: coefficients for aliasing reduction */ | ||
305 | static const int ca_int_const[8] = {0xffffbe25,0xffffc39e,0xffffd7e3,0xffffe8b7,0xfffff3e5,0xfffffac2,0xfffffe2f,0xffffff87}; | ||
306 | static const int cs_int_const[8] = {0x00006dc2,0x000070dd,0x0000798d,0x00007ddd,0x00007f6d,0x00007fe4,0x00007ffd,0x00008000}; | ||
307 | static const int win_int_const[18][36] = { | ||
308 | { 0x0000006b,0x00000121,0x000001a7,0x000001f9,0x00000215,0x000001f9,0x000001a7,0x00000121,0x0000006b,0xffffff8b,0xfffffe87,0xfffffd68,0xfffffc35,0xfffffaf9,0xfffff9bd,0xfffff88b,0xfffff76b,0xfffff667,0xfffff587,0xfffff4d1,0xfffff44b,0xfffff3f8,0xfffff3dd,0xfffff3f8,0xfffff44b,0xfffff4d1,0xfffff587,0xfffff667,0xfffff76b,0xfffff88b,0xfffff9bd,0xfffffaf9,0xfffffc35,0xfffffd68,0xfffffe87,0xffffff8b,}, | ||
309 | { 0xffffff83,0xfffffe49,0xfffffcf3,0xfffffbc3,0xfffffaf9,0xfffffacb,0xfffffb5a,0xfffffcb0,0xfffffebf,0x0000015e,0x00000451,0x0000074d,0x00000a02,0x00000c23,0x00000d72,0x00000dc4,0x00000d06,0x00000b45,0x000008a6,0x00000565,0x000001cf,0xfffffe3b,0xfffffaf9,0xfffff853,0xfffff67c,0xfffff594,0xfffff59b,0xfffff67a,0xfffff801,0xfffff9f1,0xfffffc01,0xfffffdeb,0xffffff72,0x00000066,0x000000b5,0x00000060,}, | ||
310 | { 0xffffffab,0xffffffc2,0x000000ec,0x000002e3,0x00000507,0x0000068f,0x000006c7,0x00000545,0x00000214,0xfffffdbc,0xfffff922,0xfffff55d,0xfffff366,0xfffff3dd,0xfffff6d7,0xfffffbd4,0x000001d7,0x000007a2,0x00000bfb,0x00000dfa,0x00000d3e,0x00000a00,0x00000507,0xffffff74,0xfffffa77,0xfffff70d,0xfffff5c4,0xfffff69f,0xfffff922,0xfffffc79,0xffffffb7,0x00000215,0x00000327,0x000002ef,0x000001d7,0x00000085,}, | ||
311 | { 0x0000008c,0x000001d7,0x00000244,0x000000ec,0xfffffdeb,0xfffffa77,0xfffff85e,0xfffff922,0xfffffd1d,0x00000327,0x000008f3,0x00000bfb,0x00000aa3,0x00000507,0xfffffd11,0xfffff5c4,0xfffff206,0xfffff366,0xfffff971,0x000001d7,0x00000961,0x00000d3e,0x00000c23,0x000006c7,0xffffff7b,0xfffff922,0xfffff600,0xfffff6d7,0xfffffabb,0xffffffab,0x00000387,0x00000507,0x0000042c,0x00000214,0x0000003e,0xffffffb7,}, | ||
312 | { 0x0000003c,0xffffff4b,0xfffffd28,0xfffffc0d,0xfffffdeb,0x00000283,0x0000070f,0x000007ff,0x000003ad,0xfffffbfd,0xfffff594,0xfffff4ec,0xfffffb2d,0x00000507,0x00000c88,0x00000cd4,0x00000565,0xfffffa91,0xfffff2e0,0xfffff2fa,0xfffffab0,0x00000530,0x00000c23,0x00000ba7,0x00000497,0xfffffbaf,0xfffff650,0xfffff720,0xfffffcb0,0x000002ec,0x00000611,0x00000507,0x000001a2,0xfffffed3,0xfffffe49,0xffffff6e,}, | ||
313 | { 0xffffff69,0xfffffe87,0x00000022,0x0000039b,0x00000507,0x0000016b,0xfffffad7,0xfffff76b,0xfffffb91,0x000004d7,0x00000b2f,0x0000081a,0xfffffd46,0xfffff3dd,0xfffff490,0xffffff65,0x00000b2f,0x00000d8d,0x00000445,0xfffff76b,0xfffff221,0xfffff8b7,0x00000507,0x00000c50,0x000008d7,0xfffffe87,0xfffff6b3,0xfffff77b,0xfffffedf,0x000005a2,0x00000669,0x00000215,0xfffffdb4,0xfffffced,0xfffffedf,0x0000002f,}, | ||
314 | { 0xffffffde,0x00000179,0x000002ba,0xffffffd1,0xfffffaf9,0xfffffb29,0x0000024c,0x00000895,0x00000529,0xfffffa5e,0xfffff4d1,0xfffffc65,0x0000094d,0x00000c23,0x00000097,0xfffff3b0,0xfffff4d1,0x00000313,0x00000ddf,0x00000895,0xfffff997,0xfffff273,0xfffffaf9,0x00000885,0x00000b70,0x00000179,0xfffff729,0xfffff7e6,0x00000121,0x00000749,0x0000046f,0xfffffdeb,0xfffffbbb,0xfffffe95,0x00000121,0x0000009b,}, | ||
315 | { 0x0000009d,0x000000b5,0xfffffd8f,0xfffffc9c,0x00000215,0x00000682,0x000000ff,0xfffff801,0xfffffa27,0x00000662,0x00000a6c,0xfffffe70,0xfffff37f,0xfffffaf9,0x00000ac2,0x00000b04,0xfffffa9b,0xfffff1ea,0xfffffe26,0x00000d06,0x00000873,0xfffff7bf,0xfffff3dd,0x000001a5,0x00000be4,0x00000451,0xfffff7af,0xfffff861,0x00000350,0x00000793,0x000000db,0xfffffaf9,0xfffffd66,0x000001df,0x000001b7,0xffffffec,}, | ||
316 | { 0x00000006,0xfffffe29,0xffffff56,0x00000414,0x00000215,0xfffffa2d,0xfffffbe5,0x000006de,0x0000067d,0xfffff8eb,0xfffff70d,0x00000671,0x00000b30,0xfffffaf9,0xfffff311,0x00000301,0x00000dfa,0xffffff62,0xfffff1cf,0xfffffe29,0x00000d8e,0x00000414,0xfffff3dd,0xfffffa2d,0x00000a1d,0x000006de,0xfffff845,0xfffff8eb,0x00000545,0x00000671,0xfffffcf8,0xfffffaf9,0x00000149,0x00000301,0xffffffc2,0xffffff62,}, | ||
317 | { 0xffffff62,0x0000003e,0x00000301,0xfffffeb7,0xfffffaf9,0x00000308,0x00000671,0xfffffabb,0xfffff8eb,0x000007bb,0x000006de,0xfffff5e3,0xfffffa2d,0x00000c23,0x00000414,0xfffff272,0xfffffe29,0x00000e31,0xffffff62,0xfffff206,0x00000301,0x00000cef,0xfffffaf9,0xfffff4d0,0x00000671,0x000008f3,0xfffff8eb,0xfffff983,0x000006de,0x0000041b,0xfffffa2d,0xfffffdeb,0x00000414,0x000000aa,0xfffffe29,0xfffffffa,}, | ||
318 | { 0x00000014,0x000001b7,0xfffffe21,0xfffffd66,0x00000507,0x000000db,0xfffff86d,0x00000350,0x0000079f,0xfffff7af,0xfffffbaf,0x00000be4,0xfffffe5b,0xfffff3dd,0x00000841,0x00000873,0xfffff2fa,0xfffffe26,0x00000e16,0xfffffa9b,0xfffff4fc,0x00000ac2,0x00000507,0xfffff37f,0x00000190,0x00000a6c,0xfffff99e,0xfffffa27,0x000007ff,0x000000ff,0xfffff97e,0x00000215,0x00000364,0xfffffd8f,0xffffff4b,0x0000009d,}, | ||
319 | { 0x0000009b,0xfffffedf,0xfffffe95,0x00000445,0xfffffdeb,0xfffffb91,0x00000749,0xfffffedf,0xfffff7e6,0x000008d7,0x00000179,0xfffff490,0x00000885,0x00000507,0xfffff273,0x00000669,0x00000895,0xfffff221,0x00000313,0x00000b2f,0xfffff3b0,0xffffff69,0x00000c23,0xfffff6b3,0xfffffc65,0x00000b2f,0xfffffa5e,0xfffffad7,0x00000895,0xfffffdb4,0xfffffb29,0x00000507,0xffffffd1,0xfffffd46,0x00000179,0x00000022,}, | ||
320 | { 0xffffffd1,0xfffffedf,0x00000313,0xfffffdb4,0xfffffdeb,0x00000669,0xfffffa5e,0xfffffedf,0x00000885,0xfffff6b3,0x00000179,0x000008d7,0xfffff3b0,0x00000507,0x00000749,0xfffff221,0x00000895,0x00000445,0xfffff273,0x00000b2f,0x0000009b,0xfffff490,0x00000c23,0xfffffd46,0xfffff7e6,0x00000b2f,0xfffffb29,0xfffffb91,0x00000895,0xfffffad7,0xfffffe95,0x00000507,0xfffffc65,0x00000022,0x00000179,0xffffff69,}, | ||
321 | { 0xffffff6e,0x000001b7,0xfffffed3,0xfffffe5e,0x00000507,0xfffff9ef,0x000002ec,0x00000350,0xfffff720,0x000009b0,0xfffffbaf,0xfffffb69,0x00000ba7,0xfffff3dd,0x00000530,0x00000550,0xfffff2fa,0x00000d20,0xfffffa91,0xfffffa9b,0x00000cd4,0xfffff378,0x00000507,0x000004d3,0xfffff4ec,0x00000a6c,0xfffffbfd,0xfffffc53,0x000007ff,0xfffff8f1,0x00000283,0x00000215,0xfffffc0d,0x000002d8,0xffffff4b,0xffffffc4,}, | ||
322 | { 0x00000049,0x0000003e,0xfffffdec,0x0000042c,0xfffffaf9,0x00000387,0x00000055,0xfffffabb,0x00000929,0xfffff600,0x000006de,0xffffff7b,0xfffff939,0x00000c23,0xfffff2c2,0x00000961,0xfffffe29,0xfffff971,0x00000c9a,0xfffff206,0x00000a3c,0xfffffd11,0xfffffaf9,0x00000aa3,0xfffff405,0x000008f3,0xfffffcd9,0xfffffd1d,0x000006de,0xfffff85e,0x00000589,0xfffffdeb,0xffffff14,0x00000244,0xfffffe29,0x0000008c,}, | ||
323 | { 0x00000085,0xfffffe29,0x000002ef,0xfffffcd9,0x00000215,0x00000049,0xfffffc79,0x000006de,0xfffff69f,0x00000a3c,0xfffff70d,0x00000589,0xffffff74,0xfffffaf9,0x00000a00,0xfffff2c2,0x00000dfa,0xfffff405,0x000007a2,0xfffffe29,0xfffffbd4,0x00000929,0xfffff3dd,0x00000c9a,0xfffff55d,0x000006de,0xfffffdbc,0xfffffdec,0x00000545,0xfffff939,0x0000068f,0xfffffaf9,0x000002e3,0xffffff14,0xffffffc2,0x00000055,}, | ||
324 | { 0xffffffa0,0x000000b5,0xffffff9a,0xffffff72,0x00000215,0xfffffc01,0x0000060f,0xfffff801,0x00000986,0xfffff59b,0x00000a6c,0xfffff67c,0x000007ad,0xfffffaf9,0x000001c5,0x000001cf,0xfffffa9b,0x000008a6,0xfffff4bb,0x00000d06,0xfffff23c,0x00000d72,0xfffff3dd,0x00000a02,0xfffff8b3,0x00000451,0xfffffea2,0xfffffebf,0x00000350,0xfffffb5a,0x00000535,0xfffffaf9,0x0000043d,0xfffffcf3,0x000001b7,0xffffff83,}, | ||
325 | { 0xffffff8b,0x00000179,0xfffffd68,0x000003cb,0xfffffaf9,0x00000643,0xfffff88b,0x00000895,0xfffff667,0x00000a79,0xfffff4d1,0x00000bb5,0xfffff3f8,0x00000c23,0xfffff3f8,0x00000bb5,0xfffff4d1,0x00000a79,0xfffff667,0x00000895,0xfffff88b,0x00000643,0xfffffaf9,0x000003cb,0xfffffd68,0x00000179,0xffffff8b,0xffffff95,0x00000121,0xfffffe59,0x000001f9,0xfffffdeb,0x000001f9,0xfffffe59,0x00000121,0xffffff95,}}; | ||
326 | |||
327 | const short filter_int_const[SBLIMIT][64] = { | ||
328 | { 23170, 24279, 25330, 26320, 27246, 28106, 28899, 29622, 30274, 30853, 31357, 31786, 32138, 32413, 32610, 32729, 32767, 32729, 32610, 32413, 32138, 31786, 31357, 30853, 30274, 29622, 28899, 28106, 27246, 26320, 25330, 24279, 23170, 22006, 20788, 19520, 18205, 16846, 15447, 14010, 12540, 11039, 9512, 7962, 6393, 4808, 3212, 1608, 0, -1607, -3211, -4807, -6392, -7961, -9511,-11038,-12539,-14009,-15446,-16845,-18204,-19519,-20787,-22005, }, | ||
329 | { -23169,-19519,-15446,-11038, -6392, -1607, 3212, 7962, 12540, 16846, 20788, 24279, 27246, 29622, 31357, 32413, 32767, 32413, 31357, 29622, 27246, 24279, 20788, 16846, 12540, 7962, 3212, -1607, -6392,-11038,-15446,-19519,-23169,-26319,-28898,-30852,-32137,-32728,-32609,-31785,-30273,-28105,-25329,-22005,-18204,-14009, -9511, -4807, 0, 4808, 9512, 14010, 18205, 22006, 25330, 28106, 30274, 31786, 32610, 32729, 32138, 30853, 28899, 26320, }, | ||
330 | { -23169,-28105,-31356,-32728,-32137,-29621,-25329,-19519,-12539, -4807, 3212, 11039, 18205, 24279, 28899, 31786, 32767, 31786, 28899, 24279, 18205, 11039, 3212, -4807,-12539,-19519,-25329,-29621,-32137,-32728,-31356,-28105,-23169,-16845, -9511, -1607, 6393, 14010, 20788, 26320, 30274, 32413, 32610, 30853, 27246, 22006, 15447, 7962, 0, -7961,-15446,-22005,-27245,-30852,-32609,-32412,-30273,-26319,-20787,-14009, -6392, 1608, 9512, 16846, }, | ||
331 | { 23170, 14010, 3212, -7961,-18204,-26319,-31356,-32728,-30273,-24278,-15446, -4807, 6393, 16846, 25330, 30853, 32767, 30853, 25330, 16846, 6393, -4807,-15446,-24278,-30273,-32728,-31356,-26319,-18204, -7961, 3212, 14010, 23170, 29622, 32610, 31786, 27246, 19520, 9512, -1607,-12539,-22005,-28898,-32412,-32137,-28105,-20787,-11038, 0, 11039, 20788, 28106, 32138, 32413, 28899, 22006, 12540, 1608, -9511,-19519,-27245,-31785,-32609,-29621, }, | ||
332 | { 23170, 30853, 32610, 28106, 18205, 4808, -9511,-22005,-30273,-32728,-28898,-19519, -6392, 7962, 20788, 29622, 32767, 29622, 20788, 7962, -6392,-19519,-28898,-32728,-30273,-22005, -9511, 4808, 18205, 28106, 32610, 30853, 23170, 11039, -3211,-16845,-27245,-32412,-31356,-24278,-12539, 1608, 15447, 26320, 32138, 31786, 25330, 14010, 0,-14009,-25329,-31785,-32137,-26319,-15446, -1607, 12540, 24279, 31357, 32413, 27246, 16846, 3212,-11038, }, | ||
333 | { -23169, -7961, 9512, 24279, 32138, 30853, 20788, 4808,-12539,-26319,-32609,-29621,-18204, -1607, 15447, 28106, 32767, 28106, 15447, -1607,-18204,-29621,-32609,-26319,-12539, 4808, 20788, 30853, 32138, 24279, 9512, -7961,-23169,-31785,-31356,-22005, -6392, 11039, 25330, 32413, 30274, 19520, 3212,-14009,-27245,-32728,-28898,-16845, 0, 16846, 28899, 32729, 27246, 14010, -3211,-19519,-30273,-32412,-25329,-11038, 6393, 22006, 31357, 31786, }, | ||
334 | { -23169,-32412,-28898,-14009, 6393, 24279, 32610, 28106, 12540, -7961,-25329,-32728,-27245,-11038, 9512, 26320, 32767, 26320, 9512,-11038,-27245,-32728,-25329, -7961, 12540, 28106, 32610, 24279, 6393,-14009,-28898,-32412,-23169, -4807, 15447, 29622, 32138, 22006, 3212,-16845,-30273,-31785,-20787, -1607, 18205, 30853, 31357, 19520, 0,-19519,-31356,-30852,-18204, 1608, 20788, 31786, 30274, 16846, -3211,-22005,-32137,-29621,-15446, 4808, }, | ||
335 | { 23170, 1608,-20787,-32412,-27245, -7961, 15447, 30853, 30274, 14010, -9511,-28105,-32137,-19519, 3212, 24279, 32767, 24279, 3212,-19519,-32137,-28105, -9511, 14010, 30274, 30853, 15447, -7961,-27245,-32412,-20787, 1608, 23170, 32729, 25330, 4808,-18204,-31785,-28898,-11038, 12540, 29622, 31357, 16846, -6392,-26319,-32609,-22005, 0, 22006, 32610, 26320, 6393,-16845,-31356,-29621,-12539, 11039, 28899, 31786, 18205, -4807,-25329,-32728, }, | ||
336 | { 23170, 32729, 20788, -4807,-27245,-31785,-15446, 11039, 30274, 29622, 9512,-16845,-32137,-26319, -3211, 22006, 32767, 22006, -3211,-26319,-32137,-16845, 9512, 29622, 30274, 11039,-15446,-31785,-27245, -4807, 20788, 32729, 23170, -1607,-25329,-32412,-18204, 7962, 28899, 30853, 12540,-14009,-31356,-28105, -6392, 19520, 32610, 24279, 0,-24278,-32609,-19519, 6393, 28106, 31357, 14010,-12539,-30852,-28898, -7961, 18205, 32413, 25330, 1608, }, | ||
337 | { -23169, 4808, 28899, 29622, 6393,-22005,-32609,-16845, 12540, 31786, 25330, -1607,-27245,-30852, -9511, 19520, 32767, 19520, -9511,-30852,-27245, -1607, 25330, 31786, 12540,-16845,-32609,-22005, 6393, 29622, 28899, 4808,-23169,-32412,-15446, 14010, 32138, 24279, -3211,-28105,-30273, -7961, 20788, 32729, 18205,-11038,-31356,-26319, 0, 26320, 31357, 11039,-18204,-32728,-20787, 7962, 30274, 28106, 3212,-24278,-32137,-14009, 15447, 32413, }, | ||
338 | { -23169,-31785, -9511, 22006, 32138, 11039,-20787,-32412,-12539, 19520, 32610, 14010,-18204,-32728,-15446, 16846, 32767, 16846,-15446,-32728,-18204, 14010, 32610, 19520,-12539,-32412,-20787, 11039, 32138, 22006, -9511,-31785,-23169, 7962, 31357, 24279, -6392,-30852,-25329, 4808, 30274, 26320, -3211,-29621,-27245, 1608, 28899, 28106, 0,-28105,-28898, -1607, 27246, 29622, 3212,-26319,-30273, -4807, 25330, 30853, 6393,-24278,-31356, -7961, }, | ||
339 | { 23170,-11038,-32609,-16845, 18205, 32413, 9512,-24278,-30273, -1607, 28899, 26320, -6392,-31785,-20787, 14010, 32767, 14010,-20787,-31785, -6392, 26320, 28899, -1607,-30273,-24278, 9512, 32413, 18205,-16845,-32609,-11038, 23170, 30853, 3212,-28105,-27245, 4808, 31357, 22006,-12539,-32728,-15446, 19520, 32138, 7962,-25329,-29621, 0, 29622, 25330, -7961,-32137,-19519, 15447, 32729, 12540,-22005,-31356, -4807, 27246, 28106, -3211,-30852, }, | ||
340 | { 23170, 29622, -3211,-31785,-18204, 19520, 31357, 1608,-30273,-22005, 15447, 32413, 6393,-28105,-25329, 11039, 32767, 11039,-25329,-28105, 6393, 32413, 15447,-22005,-30273, 1608, 31357, 19520,-18204,-31785, -3211, 29622, 23170,-14009,-32609, -7961, 27246, 26320, -9511,-32728,-12539, 24279, 28899, -4807,-32137,-16845, 20788, 30853, 0,-30852,-20787, 16846, 32138, 4808,-28898,-24278, 12540, 32729, 9512,-26319,-27245, 7962, 32610, 14010, }, | ||
341 | { -23169, 16846, 31357, -1607,-32137,-14009, 25330, 26320,-12539,-32412, -3211, 30853, 18205,-22005,-28898, 7962, 32767, 7962,-28898,-22005, 18205, 30853, -3211,-32412,-12539, 26320, 25330,-14009,-32137, -1607, 31357, 16846,-23169,-28105, 9512, 32729, 6393,-29621,-20787, 19520, 30274, -4807,-32609,-11038, 27246, 24279,-15446,-31785, 0, 31786, 15447,-24278,-27245, 11039, 32610, 4808,-30273,-19519, 20788, 29622, -6392,-32728, -9511, 28106, }, | ||
342 | { -23169,-26319, 15447, 30853, -6392,-32728, -3211, 31786, 12540,-28105,-20787, 22006, 27246,-14009,-31356, 4808, 32767, 4808,-31356,-14009, 27246, 22006,-20787,-28105, 12540, 31786, -3211,-32728, -6392, 30853, 15447,-26319,-23169, 19520, 28899,-11038,-32137, 1608, 32610, 7962,-30273,-16845, 25330, 24279,-18204,-29621, 9512, 32413, 0,-32412, -9511, 29622, 18205,-24278,-25329, 16846, 30274, -7961,-32609, -1607, 32138, 11039,-28898,-19519, }, | ||
343 | { 23170,-22005,-25329, 19520, 27246,-16845,-28898, 14010, 30274,-11038,-31356, 7962, 32138, -4807,-32609, 1608, 32767, 1608,-32609, -4807, 32138, 7962,-31356,-11038, 30274, 14010,-28898,-16845, 27246, 19520,-25329,-22005, 23170, 24279,-20787,-26319, 18205, 28106,-15446,-29621, 12540, 30853, -9511,-31785, 6393, 32413, -3211,-32728, 0, 32729, 3212,-32412, -6392, 31786, 9512,-30852,-12539, 29622, 15447,-28105,-18204, 26320, 20788,-24278, }, | ||
344 | { 23170, 22006,-25329,-19519, 27246, 16846,-28898,-14009, 30274, 11039,-31356, -7961, 32138, 4808,-32609, -1607, 32767, -1607,-32609, 4808, 32138, -7961,-31356, 11039, 30274,-14009,-28898, 16846, 27246,-19519,-25329, 22006, 23170,-24278,-20787, 26320, 18205,-28105,-15446, 29622, 12540,-30852, -9511, 31786, 6393,-32412, -3211, 32729, 0,-32728, 3212, 32413, -6392,-31785, 9512, 30853,-12539,-29621, 15447, 28106,-18204,-26319, 20788, 24279, }, | ||
345 | { -23169, 26320, 15447,-30852, -6392, 32729, -3211,-31785, 12540, 28106,-20787,-22005, 27246, 14010,-31356, -4807, 32767, -4807,-31356, 14010, 27246,-22005,-20787, 28106, 12540,-31785, -3211, 32729, -6392,-30852, 15447, 26320,-23169,-19519, 28899, 11039,-32137, -1607, 32610, -7961,-30273, 16846, 25330,-24278,-18204, 29622, 9512,-32412, 0, 32413, -9511,-29621, 18205, 24279,-25329,-16845, 30274, 7962,-32609, 1608, 32138,-11038,-28898, 19520, }, | ||
346 | { -23169,-16845, 31357, 1608,-32137, 14010, 25330,-26319,-12539, 32413, -3211,-30852, 18205, 22006,-28898, -7961, 32767, -7961,-28898, 22006, 18205,-30852, -3211, 32413,-12539,-26319, 25330, 14010,-32137, 1608, 31357,-16845,-23169, 28106, 9512,-32728, 6393, 29622,-20787,-19519, 30274, 4808,-32609, 11039, 27246,-24278,-15446, 31786, 0,-31785, 15447, 24279,-27245,-11038, 32610, -4807,-30273, 19520, 20788,-29621, -6392, 32729, -9511,-28105, }, | ||
347 | { 23170,-29621, -3211, 31786,-18204,-19519, 31357, -1607,-30273, 22006, 15447,-32412, 6393, 28106,-25329,-11038, 32767,-11038,-25329, 28106, 6393,-32412, 15447, 22006,-30273, -1607, 31357,-19519,-18204, 31786, -3211,-29621, 23170, 14010,-32609, 7962, 27246,-26319, -9511, 32729,-12539,-24278, 28899, 4808,-32137, 16846, 20788,-30852, 0, 30853,-20787,-16845, 32138, -4807,-28898, 24279, 12540,-32728, 9512, 26320,-27245, -7961, 32610,-14009, }, | ||
348 | { 23170, 11039,-32609, 16846, 18205,-32412, 9512, 24279,-30273, 1608, 28899,-26319, -6392, 31786,-20787,-14009, 32767,-14009,-20787, 31786, -6392,-26319, 28899, 1608,-30273, 24279, 9512,-32412, 18205, 16846,-32609, 11039, 23170,-30852, 3212, 28106,-27245, -4807, 31357,-22005,-12539, 32729,-15446,-19519, 32138, -7961,-25329, 29622, 0,-29621, 25330, 7962,-32137, 19520, 15447,-32728, 12540, 22006,-31356, 4808, 27246,-28105, -3211, 30853, }, | ||
349 | { -23169, 31786, -9511,-22005, 32138,-11038,-20787, 32413,-12539,-19519, 32610,-14009,-18204, 32729,-15446,-16845, 32767,-16845,-15446, 32729,-18204,-14009, 32610,-19519,-12539, 32413,-20787,-11038, 32138,-22005, -9511, 31786,-23169, -7961, 31357,-24278, -6392, 30853,-25329, -4807, 30274,-26319, -3211, 29622,-27245, -1607, 28899,-28105, 0, 28106,-28898, 1608, 27246,-29621, 3212, 26320,-30273, 4808, 25330,-30852, 6393, 24279,-31356, 7962, }, | ||
350 | { -23169, -4807, 28899,-29621, 6393, 22006,-32609, 16846, 12540,-31785, 25330, 1608,-27245, 30853, -9511,-19519, 32767,-19519, -9511, 30853,-27245, 1608, 25330,-31785, 12540, 16846,-32609, 22006, 6393,-29621, 28899, -4807,-23169, 32413,-15446,-14009, 32138,-24278, -3211, 28106,-30273, 7962, 20788,-32728, 18205, 11039,-31356, 26320, 0,-26319, 31357,-11038,-18204, 32729,-20787, -7961, 30274,-28105, 3212, 24279,-32137, 14010, 15447,-32412, }, | ||
351 | { 23170,-32728, 20788, 4808,-27245, 31786,-15446,-11038, 30274,-29621, 9512, 16846,-32137, 26320, -3211,-22005, 32767,-22005, -3211, 26320,-32137, 16846, 9512,-29621, 30274,-11038,-15446, 31786,-27245, 4808, 20788,-32728, 23170, 1608,-25329, 32413,-18204, -7961, 28899,-30852, 12540, 14010,-31356, 28106, -6392,-19519, 32610,-24278, 0, 24279,-32609, 19520, 6393,-28105, 31357,-14009,-12539, 30853,-28898, 7962, 18205,-32412, 25330, -1607, }, | ||
352 | { 23170, -1607,-20787, 32413,-27245, 7962, 15447,-30852, 30274,-14009, -9511, 28106,-32137, 19520, 3212,-24278, 32767,-24278, 3212, 19520,-32137, 28106, -9511,-14009, 30274,-30852, 15447, 7962,-27245, 32413,-20787, -1607, 23170,-32728, 25330, -4807,-18204, 31786,-28898, 11039, 12540,-29621, 31357,-16845, -6392, 26320,-32609, 22006, 0,-22005, 32610,-26319, 6393, 16846,-31356, 29622,-12539,-11038, 28899,-31785, 18205, 4808,-25329, 32729, }, | ||
353 | { -23169, 32413,-28898, 14010, 6393,-24278, 32610,-28105, 12540, 7962,-25329, 32729,-27245, 11039, 9512,-26319, 32767,-26319, 9512, 11039,-27245, 32729,-25329, 7962, 12540,-28105, 32610,-24278, 6393, 14010,-28898, 32413,-23169, 4808, 15447,-29621, 32138,-22005, 3212, 16846,-30273, 31786,-20787, 1608, 18205,-30852, 31357,-19519, 0, 19520,-31356, 30853,-18204, -1607, 20788,-31785, 30274,-16845, -3211, 22006,-32137, 29622,-15446, -4807, }, | ||
354 | { -23169, 7962, 9512,-24278, 32138,-30852, 20788, -4807,-12539, 26320,-32609, 29622,-18204, 1608, 15447,-28105, 32767,-28105, 15447, 1608,-18204, 29622,-32609, 26320,-12539, -4807, 20788,-30852, 32138,-24278, 9512, 7962,-23169, 31786,-31356, 22006, -6392,-11038, 25330,-32412, 30274,-19519, 3212, 14010,-27245, 32729,-28898, 16846, 0,-16845, 28899,-32728, 27246,-14009, -3211, 19520,-30273, 32413,-25329, 11039, 6393,-22005, 31357,-31785, }, | ||
355 | { 23170,-30852, 32610,-28105, 18205, -4807, -9511, 22006,-30273, 32729,-28898, 19520, -6392, -7961, 20788,-29621, 32767,-29621, 20788, -7961, -6392, 19520,-28898, 32729,-30273, 22006, -9511, -4807, 18205,-28105, 32610,-30852, 23170,-11038, -3211, 16846,-27245, 32413,-31356, 24279,-12539, -1607, 15447,-26319, 32138,-31785, 25330,-14009, 0, 14010,-25329, 31786,-32137, 26320,-15446, 1608, 12540,-24278, 31357,-32412, 27246,-16845, 3212, 11039, }, | ||
356 | { 23170,-14009, 3212, 7962,-18204, 26320,-31356, 32729,-30273, 24279,-15446, 4808, 6393,-16845, 25330,-30852, 32767,-30852, 25330,-16845, 6393, 4808,-15446, 24279,-30273, 32729,-31356, 26320,-18204, 7962, 3212,-14009, 23170,-29621, 32610,-31785, 27246,-19519, 9512, 1608,-12539, 22006,-28898, 32413,-32137, 28106,-20787, 11039, 0,-11038, 20788,-28105, 32138,-32412, 28899,-22005, 12540, -1607, -9511, 19520,-27245, 31786,-32609, 29622, }, | ||
357 | { -23169, 28106,-31356, 32729,-32137, 29622,-25329, 19520,-12539, 4808, 3212,-11038, 18205,-24278, 28899,-31785, 32767,-31785, 28899,-24278, 18205,-11038, 3212, 4808,-12539, 19520,-25329, 29622,-32137, 32729,-31356, 28106,-23169, 16846, -9511, 1608, 6393,-14009, 20788,-26319, 30274,-32412, 32610,-30852, 27246,-22005, 15447, -7961, 0, 7962,-15446, 22006,-27245, 30853,-32609, 32413,-30273, 26320,-20787, 14010, -6392, -1607, 9512,-16845, }, | ||
358 | { -23169, 19520,-15446, 11039, -6392, 1608, 3212, -7961, 12540,-16845, 20788,-24278, 27246,-29621, 31357,-32412, 32767,-32412, 31357,-29621, 27246,-24278, 20788,-16845, 12540, -7961, 3212, 1608, -6392, 11039,-15446, 19520,-23169, 26320,-28898, 30853,-32137, 32729,-32609, 31786,-30273, 28106,-25329, 22006,-18204, 14010, -9511, 4808, 0, -4807, 9512,-14009, 18205,-22005, 25330,-28105, 30274,-31785, 32610,-32728, 32138,-30852, 28899,-26319, }, | ||
359 | { 23170,-24278, 25330,-26319, 27246,-28105, 28899,-29621, 30274,-30852, 31357,-31785, 32138,-32412, 32610,-32728, 32767,-32728, 32610,-32412, 32138,-31785, 31357,-30852, 30274,-29621, 28899,-28105, 27246,-26319, 25330,-24278, 23170,-22005, 20788,-19519, 18205,-16845, 15447,-14009, 12540,-11038, 9512, -7961, 6393, -4807, 3212, -1607, 0, 1608, -3211, 4808, -6392, 7962, -9511, 11039,-12539, 14010,-15446, 16846,-18204, 19520,-20787, 22006, } }; | ||
360 | |||
361 | const int sfBandIndex[6][23] = | ||
362 | { | ||
363 | /* Table B.2.b: 22.05 kHz */ | ||
364 | {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, | ||
365 | /* Table B.2.c: 24 kHz */ | ||
366 | {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576}, | ||
367 | /* Table B.2.a: 16 kHz */ | ||
368 | {0,6,12,18,24,30,36,44,45,66,80,96,116,140,168,200,238,248,336,396,464,522,576}, | ||
369 | /* Table B.8.b: 44.1 kHz */ | ||
370 | {0,4, 8,12,16,20,24,30,36,44,52,62, 74, 90,110,134,162,196,238,288,342,418,576}, | ||
371 | /* Table B.8.c: 48 kHz */ | ||
372 | {0,4, 8,12,16,20,24,30,36,42,50,60, 72, 88,106,128,156,190,230,276,330,384,576}, | ||
373 | /* Table B.8.a: 32 kHz */ | ||
374 | {0,4, 8,12,16,20,24,30,36,44,54,66, 82,102,126,156,194,240,296,364,448,550,576} }; | ||
375 | |||
376 | const unsigned short enwindow_int_const[512] = { | ||
377 | 0x0000,0x0035,0x01fd,0x066c,0x4948,0x066c,0x01fd,0x0035,0x0000,0x0037,0x01f4,0x05d2,0x493c,0x06f8,0x0204,0x0034, | ||
378 | 0x0000,0x0038,0x01e8,0x052a,0x491a,0x0776,0x0208,0x0032,0x0000,0x0038,0x01d9,0x0474,0x48e1,0x07e7,0x020a,0x0031, | ||
379 | 0x0000,0x0039,0x01c8,0x03b0,0x4892,0x084b,0x0209,0x0030,0x0000,0x0039,0x01b3,0x02de,0x482d,0x08a2,0x0207,0x002e, | ||
380 | 0x0000,0x0039,0x019b,0x01fd,0x47b2,0x08ed,0x0202,0x002c,0x0000,0x0039,0x0180,0x010f,0x4721,0x092b,0x01fc,0x002a, | ||
381 | 0x0000,0x0038,0x0161,0x0011,0x467a,0x095e,0x01f4,0x0028,0x0000,0x0037,0x0140,0xff07,0x45bf,0x0985,0x01eb,0x0026, | ||
382 | 0x0000,0x0036,0x011b,0xfdee,0x44f0,0x09a2,0x01e0,0x0025,0x0000,0x0034,0x00f3,0xfcc8,0x440c,0x09b4,0x01d4,0x0023, | ||
383 | 0x0000,0x0032,0x00c7,0xfb93,0x4315,0x09bb,0x01c6,0x0021,0x0000,0x002f,0x0097,0xfa53,0x420b,0x09ba,0x01b8,0x001f, | ||
384 | 0x0000,0x002c,0x0065,0xf905,0x40f0,0x09af,0x01a9,0x001d,0x0000,0x0029,0x002e,0xf7aa,0x3fc3,0x099b,0x0198,0x001c, | ||
385 | 0x0000,0x0025,0xfff6,0xf643,0x3e85,0x0980,0x0188,0x001a,0xffff,0x0020,0xffb9,0xf4d1,0x3d37,0x095c,0x0176,0x0018, | ||
386 | 0xffff,0x001b,0xff79,0xf354,0x3bda,0x0932,0x0165,0x0017,0xffff,0x0015,0xff36,0xf1cc,0x3a70,0x0901,0x0153,0x0015, | ||
387 | 0xffff,0x000e,0xfeef,0xf03a,0x38f7,0x08ca,0x0141,0x0014,0xffff,0x0007,0xfea6,0xee9f,0x3773,0x088d,0x012f,0x0012, | ||
388 | 0xfffe,0x0000,0xfe5a,0xecfb,0x35e3,0x084b,0x011c,0x0011,0xfffe,0xfff8,0xfe0b,0xeb50,0x3447,0x0804,0x010a,0x0010, | ||
389 | 0xfffe,0xffef,0xfdbb,0xe99d,0x32a3,0x07ba,0x00f8,0x000f,0xfffd,0xffe5,0xfd67,0xe7e4,0x30f6,0x076b,0x00e6,0x000d, | ||
390 | 0xfffd,0xffdb,0xfd12,0xe624,0x2f41,0x071a,0x00d4,0x000c,0xfffd,0xffd0,0xfcbb,0xe461,0x2d86,0x06c6,0x00c3,0x000b, | ||
391 | 0xfffc,0xffc4,0xfc63,0xe299,0x2bc5,0x066f,0x00b2,0x000a,0xfffc,0xffb8,0xfc09,0xe0ce,0x2a00,0x0617,0x00a1,0x0009, | ||
392 | 0xfffb,0xffaa,0xfbaf,0xdf01,0x2836,0x05be,0x0091,0x0009,0xfffb,0xff9d,0xfb54,0xdd33,0x266a,0x0563,0x0081,0x0008, | ||
393 | 0xfffa,0xff8e,0xfaf9,0xdb65,0x249c,0x0508,0x0073,0x0007,0xfff9,0xff80,0xfa9e,0xd997,0x22ce,0x04ad,0x0064,0x0006, | ||
394 | 0xfff8,0xff70,0xfa43,0xd7cb,0x2100,0x0452,0x0057,0x0006,0xfff8,0xff60,0xf9ea,0xd601,0x1f33,0x03f8,0x0049,0x0005, | ||
395 | 0xfff7,0xff4f,0xf992,0xd43c,0x1d68,0x039e,0x003d,0x0005,0xfff6,0xff3e,0xf93b,0xd27b,0x1ba0,0x0346,0x0031,0x0004, | ||
396 | 0xfff5,0xff2d,0xf8e7,0xd0c0,0x19dd,0x02ef,0x0026,0x0004,0xfff4,0xff1b,0xf896,0xcf0b,0x181d,0x029a,0x001c,0x0004, | ||
397 | 0xfff2,0xff09,0xf847,0xcd5e,0x1664,0x0246,0x0012,0x0003,0xfff1,0xfef7,0xf7fd,0xcbba,0x14b1,0x01f6,0x0009,0x0003, | ||
398 | 0xfff0,0xfee5,0xf7b6,0xca1e,0x1306,0x01a7,0x0001,0x0003,0xffef,0xfed2,0xf774,0xc88e,0x1162,0x015b,0xfffa,0x0002, | ||
399 | 0xffed,0xfec0,0xf737,0xc70a,0x0fc7,0x0112,0xfff3,0x0002,0xffec,0xfeae,0xf700,0xc591,0x0e35,0x00cb,0xffec,0x0002, | ||
400 | 0xffea,0xfe9c,0xf6cf,0xc427,0x0cad,0x0088,0xffe6,0x0002,0xffe9,0xfe8b,0xf6a5,0xc2ca,0x0b30,0x0048,0xffe1,0x0002, | ||
401 | 0xffe7,0xfe79,0xf681,0xc17c,0x09be,0x000b,0xffdc,0x0001,0xffe5,0xfe69,0xf666,0xc03e,0x0857,0xffd3,0xffd8,0x0001, | ||
402 | 0xffe4,0xfe58,0xf652,0xbf11,0x06fc,0xff9c,0xffd5,0x0001,0xffe2,0xfe49,0xf647,0xbdf6,0x05ae,0xff6a,0xffd2,0x0001, | ||
403 | 0xffe0,0xfe3b,0xf646,0xbcec,0x046e,0xff3a,0xffcf,0x0001,0xffde,0xfe2d,0xf64d,0xbbf5,0x0339,0xff0e,0xffcd,0x0001, | ||
404 | 0xffdc,0xfe21,0xf65f,0xbb11,0x0213,0xfee6,0xffcb,0x0001,0xffdb,0xfe16,0xf67c,0xba42,0x00fa,0xfec1,0xffca,0x0001, | ||
405 | 0xffd9,0xfe0d,0xf6a3,0xb987,0xfff0,0xfea0,0xffc9,0x0001,0xffd7,0xfe05,0xf6d6,0xb8e0,0xfef2,0xfe81,0xffc8,0x0001, | ||
406 | 0xffd5,0xfdff,0xf714,0xb84f,0xfe04,0xfe66,0xffc8,0x0000,0xffd3,0xfdfa,0xf75f,0xb7d4,0xfd23,0xfe4e,0xffc8,0x0000, | ||
407 | 0xffd1,0xfdf8,0xf7b6,0xb76f,0xfc51,0xfe39,0xffc8,0x0000,0xffd0,0xfdf7,0xf81a,0xb720,0xfb8d,0xfe28,0xffc9,0x0000, | ||
408 | 0xffcf,0xfdf9,0xf88b,0xb6e7,0xfad7,0xfe19,0xffc9,0x0000,0xffcd,0xfdfd,0xf909,0xb6c5,0xfa2f,0xfe0d,0xffca,0x0000, | ||
409 | }; | ||
410 | |||
411 | const uint8 int2idx_const[4096] = { | ||
412 | 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, | ||
413 | 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, | ||
414 | 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, | ||
415 | 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, | ||
416 | 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, | ||
417 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, | ||
418 | 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, | ||
419 | 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, | ||
420 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, | ||
421 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, | ||
422 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, | ||
423 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31, | ||
424 | 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, | ||
425 | 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, | ||
426 | 34, 34, 34, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, | ||
427 | 36, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38, | ||
428 | 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 40, 40, 40, 40, | ||
429 | 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, | ||
430 | 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
431 | 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 45, 45, | ||
432 | 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 47, 47, | ||
433 | 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, | ||
434 | 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 50, 50, | ||
435 | 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, | ||
436 | 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, | ||
437 | 53, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, | ||
438 | 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, | ||
439 | 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, 58, 58, | ||
440 | 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, | ||
441 | 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 61, 61, 61, 61, 61, 61, 61, 61, | ||
442 | 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, | ||
443 | 62, 62, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
444 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | ||
445 | 65, 65, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, 67, 67, 67, | ||
446 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, | ||
447 | 68, 68, 68, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 70, | ||
448 | 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, | ||
449 | 71, 71, 71, 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73, | ||
450 | 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, | ||
451 | 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 76, 76, | ||
452 | 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | ||
453 | 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, | ||
454 | 78, 78, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80, | ||
455 | 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, | ||
456 | 81, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 83, | ||
457 | 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, | ||
458 | 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, | ||
459 | 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 87, 87, 87, 87, | ||
460 | 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, | ||
461 | 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, | ||
462 | 89, 89, 89, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, | ||
463 | 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, | ||
464 | 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, | ||
465 | 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95, | ||
466 | 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, | ||
467 | 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, | ||
468 | 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 99, 99, | ||
469 | 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,100,100,100,100,100,100,100,100,100,100, | ||
470 | 100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101, | ||
471 | 101,101,101,101,101,101,101,101,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102, | ||
472 | 102,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,104,104,104,104,104,104, | ||
473 | 104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,105,105,105,105,105,105,105,105,105,105,105,105,105, | ||
474 | 105,105,105,105,105,105,105,105,105,105,105,105,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106, | ||
475 | 106,106,106,106,106,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,108, | ||
476 | 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,109,109,109,109,109,109,109,109, | ||
477 | 109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,110,110,110,110,110,110,110,110,110,110,110,110,110,110, | ||
478 | 110,110,110,110,110,110,110,110,110,110,110,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111, | ||
479 | 111,111,111,111,111,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,113, | ||
480 | 113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,114,114,114,114,114,114,114,114, | ||
481 | 114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,115,115,115,115,115,115,115,115,115,115,115,115,115,115, | ||
482 | 115,115,115,115,115,115,115,115,115,115,115,115,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116, | ||
483 | 116,116,116,116,116,116,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117, | ||
484 | 118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,119,119,119,119,119,119, | ||
485 | 119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,120,120,120,120,120,120,120,120,120,120,120, | ||
486 | 120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121, | ||
487 | 121,121,121,121,121,121,121,121,121,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122, | ||
488 | 122,122,122,122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,124, | ||
489 | 124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,125,125,125,125,125,125,125, | ||
490 | 125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,126,126,126,126,126,126,126,126,126,126,126,126, | ||
491 | 126,126,126,126,126,126,126,126,126,126,126,126,126,126,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127, | ||
492 | 127,127,127,127,127,127,127,127,127,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, | ||
493 | 128,128,128,128,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,130, | ||
494 | 130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,131,131,131,131,131,131, | ||
495 | 131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,132,132,132,132,132,132,132,132,132,132,132, | ||
496 | 132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133, | ||
497 | 133,133,133,133,133,133,133,133,133,133,133,133,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134, | ||
498 | 134,134,134,134,134,134,134,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135, | ||
499 | 135,135,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,137,137, | ||
500 | 137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,138,138,138,138,138,138,138, | ||
501 | 138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,139,139,139,139,139,139,139,139,139,139,139, | ||
502 | 139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140, | ||
503 | 140,140,140,140,140,140,140,140,140,140,140,140,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, | ||
504 | 141,141,141,141,141,141,141,141,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, | ||
505 | 142,142,142,142,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,144, | ||
506 | 144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,145,145,145,145,145, | ||
507 | 145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,146,146,146,146,146,146,146,146,146, | ||
508 | 146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,147,147,147,147,147,147,147,147,147,147,147,147, | ||
509 | 147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148, | ||
510 | 148,148,148,148,148,148,148,148,148,148,148,148,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149, | ||
511 | 149,149,149,149,149,149,149,149,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150, | ||
512 | 150,150,150,150,150,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151, | ||
513 | 151,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,153,153,153, | ||
514 | 153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,154,154,154,154,154,154, | ||
515 | 154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,155,155,155,155,155,155,155,155,155, | ||
516 | 155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,156,156,156,156,156,156,156,156,156,156,156,156,156, | ||
517 | 156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157, | ||
518 | 157,157,157,157,157,157,157,157,157,157,157,157,157,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158, | ||
519 | 158,158,158,158,158,158,158,158,158,158,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159, | ||
520 | 159,159,159,159,159,159,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160, | ||
521 | 160,160,160,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161, | ||
522 | 162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,163,163,163, | ||
523 | 163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,164,164,164,164,164, | ||
524 | 164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,165,165,165,165,165,165,165,165, | ||
525 | 165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,166,166,166,166,166,166,166,166,166,166,166, | ||
526 | 166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,167,167,167,167,167,167,167,167,167,167,167,167,167,167, | ||
527 | 167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168, | ||
528 | 168,168,168,168,168,168,168,168,168,168,168,168,168,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169, | ||
529 | 169,169,169,169,169,169,169,169,169,169,169,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170, | ||
530 | 170,170,170,170,170,170,170,170,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171, | ||
531 | 171,171,171,171,171,171,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172, | ||
532 | 172,172,172,172,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173, | ||
533 | 173,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,175, | ||
534 | 175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,176,176,176, | ||
535 | 176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,177,177,177,177,177, | ||
536 | 177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,178,178,178,178,178,178,178, | ||
537 | 178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,179,179,179,179,179,179,179,179,179, | ||
538 | 179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,180,180,180,180,180,180,180,180,180,180,180, | ||
539 | 180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,181,181,181,181,181,181,181,181,181,181,181,181,181}; | ||
540 | |||
541 | short *x_int[2]; | ||
542 | short buffer[2*samp_per_frame]; | ||
543 | config_t config; | ||
544 | PFILE mp3file; | ||
545 | int mp3_hdl, file_hdl; | ||
546 | int frames_processed; | ||
547 | long wav_size; | ||
548 | uint32 enc_buffer[16384]; /* storage for 64 CodedData buffers */ | ||
549 | int enc_chunk = 0; /* chunk (each 256Byte) counter */ | ||
550 | |||
551 | /* forward declarations */ | ||
552 | void encodeSideInfo( side_info_t si[2][2] ); | ||
553 | void Huffmancodebits( enct8 *ix, int *xr, side_info_t *gi ); | ||
554 | int HuffmanCode(int table_select, enct8 *ix, int *xr); | ||
555 | int HuffmanCount1(unsigned tbl, enct8 *ix, int *xr ); | ||
556 | int new_choose_table( enct8 ix[samp_per_frame2], unsigned int begin, unsigned int end ); | ||
557 | void putbits(uint32 val, uint32 nbit); | ||
558 | int count_bit(enct8 ix[samp_per_frame2], unsigned int start, unsigned int end, unsigned int table ); | ||
559 | int bigv_bitcount(enct8 ix[samp_per_frame2], side_info_t *gi); | ||
560 | void bigv_tab_select( enct8 ix[samp_per_frame2], side_info_t *cod_info ); | ||
561 | void subdivide(side_info_t *cod_info); | ||
562 | void mdct_sub_int(int sb_sample[2][3][18][SBLIMIT], int (*mdct_freq)[2][samp_per_frame2]); | ||
563 | void filter_subband(short *buffer, int s[SBLIMIT], int k); | ||
564 | int read_samples(short *sample_buffer, int frame_size); | ||
565 | |||
566 | |||
567 | bool checkString(int *file, char *string) | ||
568 | { | ||
569 | char temp[4]; | ||
570 | |||
571 | rb->read(*file, temp, 4); | ||
572 | |||
573 | return (*(long*)temp == *(long*)string) ? 1 : 0; | ||
574 | } | ||
575 | |||
576 | int Read16BitsLowHigh(PFILE fp) | ||
577 | { | ||
578 | char first, second; | ||
579 | |||
580 | rb->read(*fp, &first, 1); | ||
581 | rb->read(*fp, &second, 1); | ||
582 | |||
583 | return ((int)second << 8) | (first & 0xff); | ||
584 | } | ||
585 | |||
586 | |||
587 | int Read32BitsLowHigh(PFILE fp) | ||
588 | { | ||
589 | int first, second, result; | ||
590 | |||
591 | first = 0xffff & Read16BitsLowHigh(fp); | ||
592 | second = 0xffff & Read16BitsLowHigh(fp); | ||
593 | result = (second << 16) + first; | ||
594 | |||
595 | return result; | ||
596 | } | ||
597 | |||
598 | void wave_close(void) | ||
599 | { | ||
600 | rb->close(*config.wave.file); | ||
601 | } | ||
602 | |||
603 | PFILE fread_open(char *filename) | ||
604 | { | ||
605 | file_hdl = rb->open(filename, O_RDONLY); | ||
606 | return file_hdl < 0 ? NULL : &file_hdl; | ||
607 | } | ||
608 | |||
609 | int wave_open(void) | ||
610 | { | ||
611 | unsigned short wFormatTag; | ||
612 | unsigned long dAvgBytesPerSec; | ||
613 | unsigned short wBlockAlign; | ||
614 | long header_size; | ||
615 | |||
616 | if((config.wave.file = fread_open(config.infile)) == NULL) | ||
617 | return -1; | ||
618 | |||
619 | if(!checkString(config.wave.file,"RIFF")) return -2; | ||
620 | Read32BitsLowHigh(config.wave.file); /* complete wave chunk size */ | ||
621 | if(!checkString(config.wave.file,"WAVE")) return -3; | ||
622 | if(!checkString(config.wave.file,"fmt ")) return -4; | ||
623 | |||
624 | header_size = Read32BitsLowHigh(config.wave.file); /* chunk size */ | ||
625 | wFormatTag = Read16BitsLowHigh(config.wave.file); | ||
626 | |||
627 | config.wave.channels = Read16BitsLowHigh(config.wave.file); | ||
628 | config.wave.samplerate = Read32BitsLowHigh(config.wave.file); | ||
629 | dAvgBytesPerSec = Read32BitsLowHigh(config.wave.file); | ||
630 | wBlockAlign = Read16BitsLowHigh(config.wave.file); | ||
631 | config.wave.bits = Read16BitsLowHigh(config.wave.file); | ||
632 | |||
633 | if(wFormatTag != 0x0001) return -5; | ||
634 | if(config.wave.bits != 16) return -6; | ||
635 | if(config.wave.channels > 2) return -7; | ||
636 | if(!checkString(config.wave.file,"data")) return -8; | ||
637 | |||
638 | header_size = 0x28; | ||
639 | wav_size = rb->filesize(*config.wave.file); | ||
640 | rb->lseek(*config.wave.file, header_size, SEEK_SET); | ||
641 | |||
642 | config.wave.total_samples = (wav_size-header_size) / (2*config.wave.channels); | ||
643 | config.wave.length = config.wave.total_samples / config.wave.samplerate; | ||
644 | |||
645 | return 0; | ||
646 | } | ||
647 | |||
648 | int read_samples(short *sample_buffer, int frame_size) | ||
649 | { | ||
650 | int samples = rb->read(*config.wave.file, sample_buffer, sizeof(short) * frame_size) / sizeof(short); | ||
651 | /* Pad last sample with zeros */ | ||
652 | if((samples < frame_size) && (samples > 0)) | ||
653 | while(samples < frame_size) | ||
654 | sample_buffer[samples++] = 0; | ||
655 | |||
656 | return samples; | ||
657 | } | ||
658 | |||
659 | inline uint32 myswap32(uint32 val) | ||
660 | { | ||
661 | const uint8* src = (const uint8*)&val; | ||
662 | |||
663 | return (uint32)src[3] | ((uint32)src[2] << 8) | ((uint32)src[1] << 16) | ((uint32)src[0] << 24); | ||
664 | } | ||
665 | |||
666 | void putbits(uint32 val, uint32 nbit) | ||
667 | { | ||
668 | int new_bitpos = CodedData.bitpos + nbit; | ||
669 | int i, ptrpos = CodedData.bitpos >> 5; | ||
670 | |||
671 | val = val & (0xffffffff >> (32 - nbit)); | ||
672 | |||
673 | /* data fit in one uint32 */ | ||
674 | if(((new_bitpos - 1) >> 5) == ptrpos) | ||
675 | CodedData.bbuf[ptrpos] |= val << ((32 - new_bitpos) & 31); | ||
676 | else | ||
677 | { | ||
678 | CodedData.bbuf[ptrpos ] |= val >> ((new_bitpos - 32) & 31); | ||
679 | CodedData.bbuf[ptrpos+1] |= val << ((32 - new_bitpos) & 31); | ||
680 | } | ||
681 | |||
682 | CodedData.bitpos = new_bitpos; | ||
683 | |||
684 | /* copy iram mp3 buffer to sdram/file */ | ||
685 | if(new_bitpos >= 256 * 32) | ||
686 | { | ||
687 | if(config.byte_order != order_bigEndian) | ||
688 | for(i=0; i<256; i++) | ||
689 | CodedData.bbuf[i] = myswap32(CodedData.bbuf[i]); | ||
690 | |||
691 | if(enc_chunk >= 64) /* sdram encoder buffer full? */ | ||
692 | { | ||
693 | rb->write(*mp3file, enc_buffer, 16384*sizeof(uint32)); | ||
694 | enc_chunk = 0; | ||
695 | } | ||
696 | |||
697 | /* copy iram buffer to sdram */ | ||
698 | memcpy(enc_buffer + enc_chunk*256, CodedData.bbuf, 256*sizeof(uint32)); | ||
699 | enc_chunk++; | ||
700 | |||
701 | CodedData.bbuf[0] = CodedData.bbuf[256]; | ||
702 | memset(CodedData.bbuf+1, 0, 256*sizeof(uint32)); | ||
703 | CodedData.bitpos &=31; | ||
704 | } | ||
705 | } | ||
706 | |||
707 | /* open the device to write the bit stream into it */ | ||
708 | void open_bitstream(char *bs_filenam) /* name of the bit stream file */ | ||
709 | { | ||
710 | mp3file = (mp3_hdl=rb->open(bs_filenam, O_WRONLY|O_CREAT)) < 0 ? NULL : &mp3_hdl; | ||
711 | } | ||
712 | |||
713 | /* This is called after a frame of audio has been quantized and coded. | ||
714 | It will write the encoded audio to the bitstream. Note that from a | ||
715 | layer3 encoder's perspective the bit stream is primarily a series | ||
716 | of main_data() blocks, with header and side information inserted at | ||
717 | the proper locations to maintain framing. See Figure A.7 in the IS */ | ||
718 | void format_bitstream( enct8 enc[2][2][samp_per_frame2], side_info_t side[2][2], int (*xr)[2][samp_per_frame2] ) | ||
719 | { | ||
720 | int gr, ch; | ||
721 | |||
722 | encodeSideInfo( side ); | ||
723 | |||
724 | for(gr=0; gr<2; gr++) | ||
725 | for(ch=0; ch<config.wave.channels; ch++) | ||
726 | Huffmancodebits( &enc[gr][ch][0], &xr[gr][ch][0], &side[gr][ch] ); | ||
727 | } | ||
728 | |||
729 | void encodeSideInfo( side_info_t si[2][2] ) | ||
730 | { | ||
731 | int gr, ch, header; | ||
732 | |||
733 | header = 0xfff00000; | ||
734 | header |= config.mpeg.type << 19; | ||
735 | header |= 1 /*config.mpeg.layr*/ << 17; | ||
736 | header |= !config.mpeg.crc << 16; | ||
737 | header |= config.mpeg.bitrate_index << 12; | ||
738 | header |= config.mpeg.samplerate_index << 10; | ||
739 | header |= config.mpeg.padding << 9; | ||
740 | header |= config.mpeg.ext << 8; | ||
741 | header |= config.mpeg.mode << 6; | ||
742 | header |= config.mpeg.mode_ext << 4; | ||
743 | header |= config.mpeg.copyright << 3; | ||
744 | header |= config.mpeg.original << 2; | ||
745 | header |= config.mpeg.emph << 0; | ||
746 | |||
747 | putbits( header, 32 ); | ||
748 | putbits( 0, config.wave.channels == 2 ? 20 : 18 ); | ||
749 | |||
750 | for(gr=0; gr<2; gr++) | ||
751 | for(ch=0; ch<config.wave.channels; ch++) | ||
752 | { | ||
753 | side_info_t *gi = &si[gr][ch]; | ||
754 | |||
755 | putbits( gi->part2_3_length, 12 ); | ||
756 | putbits( gi->big_values, 9 ); | ||
757 | putbits( gi->global_gain, 8 ); | ||
758 | putbits( gi->table_select[0], 10 ); | ||
759 | putbits( gi->table_select[1], 5 ); | ||
760 | putbits( gi->table_select[2], 5 ); | ||
761 | putbits( gi->region0_count, 4 ); | ||
762 | putbits( gi->region1_count, 3 ); | ||
763 | putbits( gi->table_select[3], 3 ); | ||
764 | } | ||
765 | } | ||
766 | |||
767 | /* Note the discussion of huffmancodebits() on pages 28 and 29 of the IS, | ||
768 | as well as the definitions of the side information on pages 26 and 27. */ | ||
769 | void Huffmancodebits( enct8 *ix, int *xr, side_info_t *gi ) | ||
770 | { | ||
771 | int region1Start; | ||
772 | int region2Start; | ||
773 | int i, bigvalues, count1End; | ||
774 | int stuffingBits; | ||
775 | int bitsWritten = 0; | ||
776 | unsigned scalefac_index; | ||
777 | |||
778 | /* 1: Write the bigvalues */ | ||
779 | bigvalues = gi->big_values << 1; | ||
780 | scalefac_index = gi->region0_count + 1; | ||
781 | region1Start = scalefac_long[ scalefac_index ]; | ||
782 | scalefac_index += gi->region1_count + 1; | ||
783 | region2Start = scalefac_long[ scalefac_index ]; | ||
784 | |||
785 | for(i=0; i<region1Start; i+=2) | ||
786 | bitsWritten += HuffmanCode(gi->table_select[0], ix+i, xr+i); | ||
787 | |||
788 | for( ; i<region2Start; i+=2) | ||
789 | bitsWritten += HuffmanCode(gi->table_select[1], ix+i, xr+i); | ||
790 | |||
791 | for( ; i<bigvalues; i+=2) | ||
792 | bitsWritten += HuffmanCode(gi->table_select[2], ix+i, xr+i); | ||
793 | |||
794 | /* 2: Write count1 area */ | ||
795 | count1End = bigvalues + (gi->count1 << 2); | ||
796 | for(i=bigvalues; i<count1End; i+=4) | ||
797 | bitsWritten += HuffmanCount1(gi->table_select[3], ix+i, xr+i); | ||
798 | |||
799 | if((stuffingBits = gi->part2_3_length - bitsWritten) != 0) | ||
800 | { | ||
801 | int stuffingWords = stuffingBits / 32; | ||
802 | int remainingBits = stuffingBits % 32; | ||
803 | |||
804 | if( remainingBits ) | ||
805 | putbits( ~0, remainingBits ); | ||
806 | |||
807 | /* Due to the nature of the Huffman code tables, we will pad with ones */ | ||
808 | while( stuffingWords-- ) | ||
809 | putbits( ~0, 32 ); | ||
810 | |||
811 | bitsWritten += stuffingBits; | ||
812 | } | ||
813 | } | ||
814 | |||
815 | int HuffmanCount1(unsigned tbl, enct8 *ix, int *xr) | ||
816 | { | ||
817 | uint32 dat, p, s; | ||
818 | int len, v, w, x, y; | ||
819 | #define signv (xr[0] < 0 ? 1 : 0) | ||
820 | #define signw (xr[1] < 0 ? 1 : 0) | ||
821 | #define signx (xr[2] < 0 ? 1 : 0) | ||
822 | #define signy (xr[3] < 0 ? 1 : 0) | ||
823 | |||
824 | v = ix[0]; | ||
825 | w = ix[1]; | ||
826 | x = ix[2]; | ||
827 | y = ix[3]; | ||
828 | p = v + (w << 1) + (x << 2) + (y << 3); | ||
829 | |||
830 | switch(p) | ||
831 | { | ||
832 | default: len = 0; s = 0; break; | ||
833 | case 1: len = 1; s = signv; break; | ||
834 | case 2: len = 1; s = signw; break; | ||
835 | case 3: len = 2; s = (signv << 1) + signw; break; | ||
836 | case 4: len = 1; s = signx; break; | ||
837 | case 5: len = 2; s = (signv << 1) + signx; break; | ||
838 | case 6: len = 2; s = (signw << 1) + signx; break; | ||
839 | case 7: len = 3; s = (signv << 2) + (signw << 1) + signx; break; | ||
840 | case 8: len = 1; s = signy; break; | ||
841 | case 9: len = 2; s = (signv << 1) + signy; break; | ||
842 | case 10: len = 2; s = (signw << 1) + signy; break; | ||
843 | case 11: len = 3; s = (signv << 2) + (signw << 1) + signy; break; | ||
844 | case 12: len = 2; s = (signx << 1) + signy; break; | ||
845 | case 13: len = 3; s = (signv << 2) + (signx << 1) + signy; break; | ||
846 | case 14: len = 3; s = (signw << 2) + (signx << 1) + signy; break; | ||
847 | case 15: len = 4; s = (signv << 3) + (signw << 2) + (signx << 1) + signy; break; | ||
848 | } | ||
849 | |||
850 | dat = (ht_count1[tbl][0][p] << len) + s; | ||
851 | len = ht_count1[tbl][1][p]; | ||
852 | putbits( dat, len ); | ||
853 | |||
854 | return len; | ||
855 | } | ||
856 | |||
857 | /* Implements the pseudocode of page 98 of the IS */ | ||
858 | int HuffmanCode(int table_select, enct8 *ix, int *xr) | ||
859 | { | ||
860 | unsigned linbitsx, linbitsy, linbits, idx; | ||
861 | const struct huffcodetab *h; | ||
862 | int x, y, bit; | ||
863 | uint32 code; | ||
864 | #define sign_x (xr[0] < 0 ? 1 : 0) | ||
865 | #define sign_y (xr[1] < 0 ? 1 : 0) | ||
866 | |||
867 | if(table_select == 0) | ||
868 | return 0; | ||
869 | |||
870 | x = ix[0]; | ||
871 | y = ix[1]; | ||
872 | h = &ht[table_select]; | ||
873 | linbits = h->linbits; | ||
874 | linbitsx = linbitsy = 0; | ||
875 | |||
876 | if( table_select > 15 ) | ||
877 | { /* ESC-table is used */ | ||
878 | if(x > 14) { linbitsx = x - 15; x = 15; } | ||
879 | if(y > 14) { linbitsy = y - 15; y = 15; } | ||
880 | |||
881 | idx = (x * h->ylen) + y; | ||
882 | code = h->table[idx]; | ||
883 | bit = h->hlen [idx]; | ||
884 | |||
885 | if(x) | ||
886 | { | ||
887 | if(x > 14) | ||
888 | { | ||
889 | code = (code << linbits) | linbitsx; | ||
890 | bit += linbits; | ||
891 | } | ||
892 | |||
893 | code = (code << 1) | sign_x; | ||
894 | bit += 1; | ||
895 | } | ||
896 | |||
897 | if(y) | ||
898 | { | ||
899 | if(y > 14) | ||
900 | { | ||
901 | code = (code << linbits) | linbitsy; | ||
902 | bit += linbits; | ||
903 | } | ||
904 | |||
905 | code = (code << 1) | sign_y; | ||
906 | bit += 1; | ||
907 | } | ||
908 | } | ||
909 | else | ||
910 | { /* No ESC-words */ | ||
911 | idx = (x * h->ylen) + y; | ||
912 | code = h->table[idx]; | ||
913 | bit = h->hlen [idx]; | ||
914 | |||
915 | if(x) | ||
916 | { | ||
917 | code = (code << 1) | sign_x; | ||
918 | bit += 1; | ||
919 | } | ||
920 | |||
921 | if(y) | ||
922 | { | ||
923 | code = (code << 1) | sign_y; | ||
924 | bit += 1; | ||
925 | } | ||
926 | } | ||
927 | |||
928 | putbits( code, bit ); | ||
929 | |||
930 | return bit; | ||
931 | } | ||
932 | |||
933 | /*************************************************************************/ | ||
934 | /* Choose the Huffman table that will encode ix[begin..end] with */ | ||
935 | /* the fewest bits. */ | ||
936 | /* Note: This code contains knowledge about the sizes and characteristics */ | ||
937 | /* of the Huffman tables as defined in the IS (Table B.7), and will not work */ | ||
938 | /* with any arbitrary tables. */ | ||
939 | /*************************************************************************/ | ||
940 | int new_choose_table( enct8 ix[samp_per_frame2], uint32 begin, uint32 end ) | ||
941 | { | ||
942 | uint32 i; | ||
943 | int max, sum0, sum1, table0, table1; | ||
944 | |||
945 | for(i=begin,max=0; i<end; i++) | ||
946 | if(ix[i] > max) | ||
947 | max = ix[i]; | ||
948 | |||
949 | if(!max) | ||
950 | return 0; | ||
951 | |||
952 | table0 = 0; | ||
953 | table1 = 0; | ||
954 | |||
955 | if(max <= 15) | ||
956 | { | ||
957 | /* try tables with no linbits */ | ||
958 | /* indx: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ | ||
959 | /* xlen: 0, 2, 3, 3, 0, 4, 4, 6, 6, 6, 8, 8, 8, 16, 0, 16 */ | ||
960 | for(table0=0; table0<14; table0++) | ||
961 | if(ht[table0].xlen > max) | ||
962 | break; | ||
963 | |||
964 | sum0 = count_bit(ix, begin, end, table0); | ||
965 | |||
966 | switch( table0 ) | ||
967 | { | ||
968 | case 2: sum1 = count_bit( ix, begin, end, 3 ); | ||
969 | if(sum1 <= sum0) table0 = 3; break; | ||
970 | |||
971 | case 5: sum1 = count_bit( ix, begin, end, 6 ); | ||
972 | if(sum1 <= sum0) table0 = 6; break; | ||
973 | |||
974 | case 7: sum1 = count_bit( ix, begin, end, 8 ); | ||
975 | if(sum1 <= sum0) { table0 = 8; sum0 = sum1; } | ||
976 | sum1 = count_bit( ix, begin, end, 9 ); | ||
977 | if(sum1 <= sum0) table0 = 9; break; | ||
978 | |||
979 | case 10: sum1 = count_bit( ix, begin, end, 11 ); | ||
980 | if(sum1 <= sum0) { table0 =11; sum0 = sum1; } | ||
981 | sum1 = count_bit( ix, begin, end, 12); | ||
982 | if(sum1 <= sum0) table0 = 12; break; | ||
983 | |||
984 | case 13: sum1 = count_bit( ix, begin, end, 15 ); | ||
985 | if(sum1 <= sum0) table0 = 15; break; | ||
986 | } | ||
987 | } | ||
988 | else | ||
989 | { | ||
990 | /* try tables with linbits */ | ||
991 | max -= 15; | ||
992 | |||
993 | /* index : 15 16 17 18 19 20 21 22 23 */ | ||
994 | /* linmax: 0 1 3 7 15 63 255 1023 8191 */ | ||
995 | for(table0=15; table0<24; table0++) | ||
996 | if(ht[table0].linmax >= max) | ||
997 | break; | ||
998 | |||
999 | /* index : 24 25 26 27 28 29 30 31 */ | ||
1000 | /* linmax: 15 31 63 127 255 511 2047 8191 */ | ||
1001 | for(table1=24; table1<32; table1++) | ||
1002 | if(ht[table1].linmax >= max) | ||
1003 | break; | ||
1004 | |||
1005 | sum0 = count_bit(ix, begin, end, table0); | ||
1006 | sum1 = count_bit(ix, begin, end, table1); | ||
1007 | |||
1008 | if(sum1 < sum0) | ||
1009 | table0 = table1; | ||
1010 | } | ||
1011 | return table0; | ||
1012 | } | ||
1013 | |||
1014 | /*************************************************************************/ | ||
1015 | /* Function: Count the number of bits necessary to code the subregion. */ | ||
1016 | /*************************************************************************/ | ||
1017 | int count_bit(enct8 ix[samp_per_frame2], unsigned int start, unsigned int end, unsigned int table ) | ||
1018 | { | ||
1019 | uint32 i; | ||
1020 | int sum; | ||
1021 | int x, y; | ||
1022 | unsigned linbits, ylen; | ||
1023 | const struct huffcodetab *h; | ||
1024 | |||
1025 | h = &ht[table]; | ||
1026 | sum = 0; | ||
1027 | ylen = h->ylen; | ||
1028 | |||
1029 | if(table > 15) | ||
1030 | { // ESC-table is used | ||
1031 | linbits = h->linbits; | ||
1032 | for(i=start; i<end; i+=2) | ||
1033 | { | ||
1034 | x = ix[i]; | ||
1035 | y = ix[i+1]; | ||
1036 | |||
1037 | if(x) | ||
1038 | { | ||
1039 | if(x > 14) { x = 15; sum += linbits; } | ||
1040 | sum++; | ||
1041 | } | ||
1042 | |||
1043 | if(y) | ||
1044 | { | ||
1045 | if(y > 14) { y = 15; sum += linbits; } | ||
1046 | sum++; | ||
1047 | } | ||
1048 | |||
1049 | sum += h->hlen[(x * ylen) + y]; | ||
1050 | } | ||
1051 | } | ||
1052 | else | ||
1053 | { /* No ESC-words */ | ||
1054 | for(i=start; i<end; i+=2) | ||
1055 | { | ||
1056 | x = ix[i]; | ||
1057 | y = ix[i+1]; | ||
1058 | |||
1059 | sum += h->hlen[(x * ylen) + y]; | ||
1060 | |||
1061 | if(x) sum++; | ||
1062 | if(y) sum++; | ||
1063 | } | ||
1064 | } | ||
1065 | |||
1066 | return sum; | ||
1067 | } | ||
1068 | |||
1069 | /*************************************************************************/ | ||
1070 | /* Function: Quantization of the vector xr ( -> ix) */ | ||
1071 | /*************************************************************************/ | ||
1072 | int quantize_int(int xr[samp_per_frame2], enct8 ix[samp_per_frame2], side_info_t *cod_info) | ||
1073 | { | ||
1074 | int i; | ||
1075 | #if 0 | ||
1076 | long step; | ||
1077 | uint32 frac_pow[] = { 0, 12400, 27146, 44682 }; | ||
1078 | |||
1079 | step = 1 << cod_info->quantizerStepSize / 4; | ||
1080 | step += (step * frac_pow[cod_info->quantizerStepSize & 3] + 32768) >> 16; | ||
1081 | |||
1082 | for(i=samp_per_frame2; i--; ) | ||
1083 | ix[i] = int2idx[4 * abs(xr[i]) / step]; | ||
1084 | |||
1085 | return 1; | ||
1086 | #else | ||
1087 | uint32 max=0, val, step, frac_pow[] = { 0x40000, 0x35d14, 0x2d414,0x260e0 }; | ||
1088 | |||
1089 | step = frac_pow[cod_info->quantizerStepSize & 3] >> cod_info->quantizerStepSize / 4; | ||
1090 | |||
1091 | for(i=samp_per_frame2; i--; ) | ||
1092 | { | ||
1093 | val = (((unsigned long)abs(xr[i]) * step + 32768) >> 16); | ||
1094 | max |= val; | ||
1095 | ix[i] = int2idx[val]; | ||
1096 | } | ||
1097 | return max < 4096 ? 1 : 0; | ||
1098 | #endif | ||
1099 | } | ||
1100 | |||
1101 | /*************************************************************************/ | ||
1102 | /* Function: Calculation of rzero, count1, big_values */ | ||
1103 | /* (Partitions ix into big values, quadruples and zeros). */ | ||
1104 | /*************************************************************************/ | ||
1105 | int calc_runlen( enct8 ix[samp_per_frame2], side_info_t *cod_info ) | ||
1106 | { | ||
1107 | int p, i, sum0 = 0, sum1 = 0; | ||
1108 | |||
1109 | for(i=samp_per_frame2; i-=2; ) | ||
1110 | if(ix[i-1] | ix[i-2]) | ||
1111 | break; | ||
1112 | |||
1113 | cod_info->count1 = 0; | ||
1114 | |||
1115 | for( ; i>3; i-=4) | ||
1116 | { | ||
1117 | int v = ix[i-1]; | ||
1118 | int w = ix[i-2]; | ||
1119 | int x = ix[i-3]; | ||
1120 | int y = ix[i-4]; | ||
1121 | |||
1122 | if((v | w | x | y) <= 1) | ||
1123 | { | ||
1124 | p = (y) + (x<<1) + (w<<2) + (v<<3); | ||
1125 | |||
1126 | sum0 += ht_count1[0][1][p]; /* add table0 hlength */ | ||
1127 | sum1 += ht_count1[1][1][p]; /* add table1 hlength */ | ||
1128 | |||
1129 | cod_info->count1++; | ||
1130 | } | ||
1131 | else break; | ||
1132 | } | ||
1133 | |||
1134 | cod_info->big_values = i >> 1; | ||
1135 | |||
1136 | if(sum0 < sum1) | ||
1137 | { | ||
1138 | cod_info->table_select[3] = 0; | ||
1139 | return sum0; | ||
1140 | } | ||
1141 | else | ||
1142 | { | ||
1143 | cod_info->table_select[3] = 1; | ||
1144 | return sum1; | ||
1145 | } | ||
1146 | } | ||
1147 | |||
1148 | /*************************************************************************/ | ||
1149 | /* presumable subdivides the bigvalue region which will use separate Huffman tables */ | ||
1150 | /*************************************************************************/ | ||
1151 | void subdivide(side_info_t *cod_info) | ||
1152 | { | ||
1153 | int scfb_anz = 0; | ||
1154 | int bigvalues_region; | ||
1155 | int thiscount, index; | ||
1156 | |||
1157 | if( !cod_info->big_values ) | ||
1158 | { /* no big_values region */ | ||
1159 | cod_info->region0_count = 0; | ||
1160 | cod_info->region1_count = 0; | ||
1161 | } | ||
1162 | else | ||
1163 | { | ||
1164 | bigvalues_region = 2 * cod_info->big_values; | ||
1165 | |||
1166 | /* Calculate scfb_anz */ | ||
1167 | while( scalefac_long[scfb_anz] < bigvalues_region ) | ||
1168 | scfb_anz++; | ||
1169 | |||
1170 | cod_info->region0_count = subdv_table[scfb_anz].region0_count; | ||
1171 | thiscount = cod_info->region0_count; | ||
1172 | index = thiscount + 1; | ||
1173 | while(thiscount && (scalefac_long[index] > bigvalues_region)) | ||
1174 | { | ||
1175 | thiscount--; | ||
1176 | index--; | ||
1177 | } | ||
1178 | cod_info->region0_count = thiscount; | ||
1179 | cod_info->region1_count = subdv_table[scfb_anz].region1_count; | ||
1180 | index = cod_info->region0_count + cod_info->region1_count + 2; | ||
1181 | thiscount = cod_info->region1_count; | ||
1182 | while(thiscount && (scalefac_long[index] > bigvalues_region)) | ||
1183 | { | ||
1184 | thiscount--; | ||
1185 | index--; | ||
1186 | } | ||
1187 | cod_info->region1_count = thiscount; | ||
1188 | cod_info->address1 = scalefac_long[cod_info->region0_count+1]; | ||
1189 | cod_info->address2 = scalefac_long[cod_info->region0_count+cod_info->region1_count+2]; | ||
1190 | cod_info->address3 = bigvalues_region; | ||
1191 | } | ||
1192 | } | ||
1193 | |||
1194 | /*************************************************************************/ | ||
1195 | /* Function: Select huffman code tables for bigvalues regions */ | ||
1196 | /*************************************************************************/ | ||
1197 | void bigv_tab_select( enct8 ix[samp_per_frame2], side_info_t *cod_info ) | ||
1198 | { | ||
1199 | cod_info->table_select[0] = 0; | ||
1200 | cod_info->table_select[1] = 0; | ||
1201 | cod_info->table_select[2] = 0; | ||
1202 | |||
1203 | if( cod_info->address1 > 0 ) | ||
1204 | cod_info->table_select[0] = new_choose_table(ix, 0 , cod_info->address1); | ||
1205 | |||
1206 | if( cod_info->address2 > cod_info->address1 ) | ||
1207 | cod_info->table_select[1] = new_choose_table(ix, cod_info->address1, cod_info->address2); | ||
1208 | |||
1209 | if( cod_info->big_values<<1 > cod_info->address2 ) | ||
1210 | cod_info->table_select[2] = new_choose_table(ix, cod_info->address2, cod_info->big_values<<1); | ||
1211 | } | ||
1212 | |||
1213 | /*************************************************************************/ | ||
1214 | /* Function: Count the number of bits necessary to code the bigvalues region */ | ||
1215 | /*************************************************************************/ | ||
1216 | int bigv_bitcount(enct8 ix[samp_per_frame2], side_info_t *gi) | ||
1217 | { | ||
1218 | int bits = 0; | ||
1219 | uint32 table; | ||
1220 | |||
1221 | if((table=gi->table_select[0])) /* region0 */ | ||
1222 | bits += count_bit(ix, 0 , gi->address1, table); | ||
1223 | |||
1224 | if((table=gi->table_select[1])) /* region1 */ | ||
1225 | bits += count_bit(ix, gi->address1, gi->address2, table); | ||
1226 | |||
1227 | if((table=gi->table_select[2])) /* region2 */ | ||
1228 | bits += count_bit(ix, gi->address2, gi->address3, table); | ||
1229 | |||
1230 | return bits; | ||
1231 | } | ||
1232 | |||
1233 | int quantcnt; | ||
1234 | |||
1235 | /* Speed up the outer_loop code which is called by iteration_loop. | ||
1236 | The outer_loop function precedes the call to the function inner_loop | ||
1237 | with a call to bin_search gain defined below, | ||
1238 | which returns a good starting quantizerStepSize. */ | ||
1239 | int quantize_and_count_bits(int xr[samp_per_frame2], enct8 ix[samp_per_frame2], side_info_t *cod_info) | ||
1240 | { | ||
1241 | int bits = 10000; | ||
1242 | |||
1243 | quantcnt++; | ||
1244 | |||
1245 | if(quantize_int(xr, ix, cod_info)) | ||
1246 | { | ||
1247 | bits = calc_runlen(ix, cod_info); /* rzero,count1,big_values*/ | ||
1248 | subdivide(cod_info); /* bigvalues sfb division */ | ||
1249 | bigv_tab_select(ix,cod_info); /* codebook selection*/ | ||
1250 | bits += bigv_bitcount(ix,cod_info); /* bit count */ | ||
1251 | } | ||
1252 | |||
1253 | return bits; | ||
1254 | } | ||
1255 | |||
1256 | /******************************************************************************/ | ||
1257 | /* The code selects the best quantizerStepSize for a particular set of scalefacs */ | ||
1258 | /******************************************************************************/ | ||
1259 | int inner_loop_int(int xr[2][2][samp_per_frame2], int max_bits, side_info_t *cod_info, int gr, int ch ) | ||
1260 | { | ||
1261 | int *xrs; /* int[samp_per_frame2] *xr; */ | ||
1262 | enct8 *ix; /* int[samp_per_frame2] *ix; */ | ||
1263 | int bits; | ||
1264 | |||
1265 | xrs = &xr[gr][ch][0]; | ||
1266 | ix = enc_data[gr][ch]; | ||
1267 | |||
1268 | while((bits=quantize_and_count_bits(xrs, ix, cod_info)) < max_bits- 128) | ||
1269 | { | ||
1270 | if(cod_info->quantizerStepSize == 0) | ||
1271 | break; | ||
1272 | |||
1273 | if(cod_info->quantizerStepSize <= 2) | ||
1274 | cod_info->quantizerStepSize = 0; | ||
1275 | else | ||
1276 | cod_info->quantizerStepSize -= 2; | ||
1277 | } | ||
1278 | |||
1279 | while(bits > max_bits) | ||
1280 | { | ||
1281 | cod_info->quantizerStepSize++; | ||
1282 | bits = quantize_and_count_bits(xrs, ix, cod_info); | ||
1283 | } | ||
1284 | |||
1285 | return bits; | ||
1286 | } | ||
1287 | |||
1288 | /************************************************************************/ | ||
1289 | /* iteration_loop() */ | ||
1290 | /************************************************************************/ | ||
1291 | void iteration_loop(int mdct_freq_org[2][2][samp_per_frame2], side_info_t cod_info[2][2], int mean_bits) | ||
1292 | { | ||
1293 | int max_bits; | ||
1294 | int ch, gr; | ||
1295 | int ResvSize = 0; /* Layer3 bit reservoir: Described in C.1.5.4.2.2 of the IS */ | ||
1296 | |||
1297 | for(gr=2; gr--; ) | ||
1298 | { | ||
1299 | for(ch=config.wave.channels; ch--; ) | ||
1300 | { | ||
1301 | /* calculation of number of available bit( per granule ) */ | ||
1302 | max_bits = mean_bits / config.wave.channels; | ||
1303 | |||
1304 | cod_info[gr][ch].big_values = 0; | ||
1305 | cod_info[gr][ch].count1 = 0; | ||
1306 | cod_info[gr][ch].table_select[0] = 0; | ||
1307 | cod_info[gr][ch].table_select[1] = 0; | ||
1308 | cod_info[gr][ch].table_select[2] = 0; | ||
1309 | cod_info[gr][ch].region0_count = 0; | ||
1310 | cod_info[gr][ch].region1_count = 0; | ||
1311 | cod_info[gr][ch].table_select[3] = 0; | ||
1312 | cod_info[gr][ch].part2_3_length = inner_loop_int(mdct_freq_org, max_bits, &cod_info[gr][ch], gr, ch); | ||
1313 | cod_info[gr][ch].global_gain = cod_info[gr][ch].quantizerStepSize + 210 - 0x3c; | ||
1314 | |||
1315 | /* Readjusts the size of the reservoir to reflect the granule's usage */ | ||
1316 | ResvSize += max_bits - cod_info[gr][ch].part2_3_length; | ||
1317 | } | ||
1318 | } | ||
1319 | |||
1320 | /* Makes sure that the reservoir size is within limits, possibly by adding stuffing | ||
1321 | bits. Note that stuffing bits are added by increasing a granule's part2_3_length */ | ||
1322 | cod_info[0][0].part2_3_length += ResvSize; | ||
1323 | } | ||
1324 | |||
1325 | /*-------------------------------------------------------------------*/ | ||
1326 | /* Function: Calculation of the MDCT */ | ||
1327 | /* In the case of long blocks ( block_type 0,1,3 ) there are */ | ||
1328 | /* 36 coefficents in the time domain and 18 in the frequency */ | ||
1329 | /* domain. */ | ||
1330 | /*-------------------------------------------------------------------*/ | ||
1331 | void mdct_int( int *in, int *out ) | ||
1332 | { | ||
1333 | int m, tmp=0; | ||
1334 | |||
1335 | for(m=18; m--; ) | ||
1336 | { | ||
1337 | #ifdef SIMULATOR | ||
1338 | int k; | ||
1339 | for(k=36,tmp=0; k--; ) | ||
1340 | tmp += in[k] * win_int[m][k]; | ||
1341 | #else | ||
1342 | asm volatile ("move.l #0, %macsr"); /* integer mode */ | ||
1343 | |||
1344 | { int *wint = win_int[m]; | ||
1345 | int *indat = in; | ||
1346 | |||
1347 | asm volatile( | ||
1348 | "movem.l (%[indat]), %%d0-%%d7\n" | ||
1349 | "move.l (%[wint]), %%a5\n" | ||
1350 | "mac.l %%d0, %%a5, ( 4, %[wint]), %%a5, %%acc0\n" | ||
1351 | "mac.l %%d1, %%a5, ( 8, %[wint]), %%a5, %%acc0\n" | ||
1352 | "mac.l %%d2, %%a5, ( 12, %[wint]), %%a5, %%acc0\n" | ||
1353 | "mac.l %%d3, %%a5, ( 16, %[wint]), %%a5, %%acc0\n" | ||
1354 | "mac.l %%d4, %%a5, ( 20, %[wint]), %%a5, %%acc0\n" | ||
1355 | "mac.l %%d5, %%a5, ( 24, %[wint]), %%a5, %%acc0\n" | ||
1356 | "mac.l %%d6, %%a5, ( 28, %[wint]), %%a5, %%acc0\n" | ||
1357 | "mac.l %%d7, %%a5, ( 32, %[wint]), %%a5, %%acc0\n" | ||
1358 | "movem.l (32,%[indat]), %%d0-%%d7\n" | ||
1359 | "mac.l %%d0, %%a5, ( 36, %[wint]), %%a5, %%acc0\n" | ||
1360 | "mac.l %%d1, %%a5, ( 40, %[wint]), %%a5, %%acc0\n" | ||
1361 | "mac.l %%d2, %%a5, ( 44, %[wint]), %%a5, %%acc0\n" | ||
1362 | "mac.l %%d3, %%a5, ( 48, %[wint]), %%a5, %%acc0\n" | ||
1363 | "mac.l %%d4, %%a5, ( 52, %[wint]), %%a5, %%acc0\n" | ||
1364 | "mac.l %%d5, %%a5, ( 56, %[wint]), %%a5, %%acc0\n" | ||
1365 | "mac.l %%d6, %%a5, ( 60, %[wint]), %%a5, %%acc0\n" | ||
1366 | "mac.l %%d7, %%a5, ( 64, %[wint]), %%a5, %%acc0\n" | ||
1367 | "movem.l (64,%[indat]), %%d0-%%d7\n" | ||
1368 | "mac.l %%d0, %%a5, ( 68, %[wint]), %%a5, %%acc0\n" | ||
1369 | "mac.l %%d1, %%a5, ( 72, %[wint]), %%a5, %%acc0\n" | ||
1370 | "mac.l %%d2, %%a5, ( 76, %[wint]), %%a5, %%acc0\n" | ||
1371 | "mac.l %%d3, %%a5, ( 80, %[wint]), %%a5, %%acc0\n" | ||
1372 | "mac.l %%d4, %%a5, ( 84, %[wint]), %%a5, %%acc0\n" | ||
1373 | "mac.l %%d5, %%a5, ( 88, %[wint]), %%a5, %%acc0\n" | ||
1374 | "mac.l %%d6, %%a5, ( 92, %[wint]), %%a5, %%acc0\n" | ||
1375 | "mac.l %%d7, %%a5, ( 96, %[wint]), %%a5, %%acc0\n" | ||
1376 | "movem.l (96,%[indat]), %%d0-%%d7\n" | ||
1377 | "mac.l %%d0, %%a5, (100, %[wint]), %%a5, %%acc0\n" | ||
1378 | "mac.l %%d1, %%a5, (104, %[wint]), %%a5, %%acc0\n" | ||
1379 | "mac.l %%d2, %%a5, (108, %[wint]), %%a5, %%acc0\n" | ||
1380 | "mac.l %%d3, %%a5, (112, %[wint]), %%a5, %%acc0\n" | ||
1381 | "mac.l %%d4, %%a5, (116, %[wint]), %%a5, %%acc0\n" | ||
1382 | "mac.l %%d5, %%a5, (120, %[wint]), %%a5, %%acc0\n" | ||
1383 | "mac.l %%d6, %%a5, (124, %[wint]), %%a5, %%acc0\n" | ||
1384 | "mac.l %%d7, %%a5, (128, %[wint]), %%a5, %%acc0\n" | ||
1385 | "movem.l (128,%[indat]), %%d0-%%d3\n" | ||
1386 | "mac.l %%d0, %%a5, (132, %[wint]), %%a5, %%acc0\n" | ||
1387 | "mac.l %%d1, %%a5, (136, %[wint]), %%a5, %%acc0\n" | ||
1388 | "mac.l %%d2, %%a5, (140, %[wint]), %%a5, %%acc0\n" | ||
1389 | "mac.l %%d3, %%a5, %%acc0\n" | ||
1390 | : : [indat] "a" (indat), [wint] "a" (wint) | ||
1391 | : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5"); | ||
1392 | } | ||
1393 | asm volatile ("movclr.l %%acc0, %[tmp]\n" : [tmp]"+r"(tmp) ); | ||
1394 | #endif | ||
1395 | out[m] = (tmp + 16384) >> 15; | ||
1396 | } | ||
1397 | } | ||
1398 | |||
1399 | |||
1400 | void mdct_sub_int(int sb_sample[2][3][18][SBLIMIT], int (*mdct_freq)[2][samp_per_frame2]) | ||
1401 | { | ||
1402 | int (*mdct_enc)[2][32][18] = (int (*)[2][32][18]) mdct_freq; | ||
1403 | int ch, gr, band, k, bu, bd; | ||
1404 | |||
1405 | for(gr=0; gr<2; gr++) | ||
1406 | for(ch=config.wave.channels; ch--; ) | ||
1407 | { | ||
1408 | /* 576=4*16*9: Compensate for inversion in the analysis filter */ | ||
1409 | for(band=33; (band-=2)>0; ) | ||
1410 | for(k=19; (k-=2)>0; ) | ||
1411 | sb_sample[ch][gr+1][k][band] = -sb_sample[ch][gr+1][k][band]; | ||
1412 | |||
1413 | /* 82944=4*32*648: Perform imdct of 18 previous subband samples + 18 current subband samples */ | ||
1414 | for(band=32; band--; ) | ||
1415 | { | ||
1416 | for(k=18; k--; ) | ||
1417 | { | ||
1418 | mdct_in[k] = sb_sample[ch][ gr ][k][band]; | ||
1419 | mdct_in[k+18] = sb_sample[ch][gr+1][k][band]; | ||
1420 | } | ||
1421 | |||
1422 | mdct_int(mdct_in, &mdct_enc[gr][ch][band][0]); | ||
1423 | } | ||
1424 | |||
1425 | /* 1024=4*256: Perform aliasing reduction butterfly*/ | ||
1426 | for(band=31; band--; ) | ||
1427 | for(k=8; k--; ) | ||
1428 | { | ||
1429 | bu = mdct_enc[gr][ch][band][17-k] * cs_int[k] + mdct_enc[gr][ch][band+1][k] * ca_int[k]; | ||
1430 | bd = mdct_enc[gr][ch][band+1][k] * cs_int[k] - mdct_enc[gr][ch][band][17-k] * ca_int[k]; | ||
1431 | mdct_enc[gr][ch][band][17-k] = (bu + 16384) >> 15; | ||
1432 | mdct_enc[gr][ch][band+1][k] = (bd + 16384) >> 15; | ||
1433 | } | ||
1434 | } | ||
1435 | |||
1436 | /* Save latest granule's subband samples to be used in the next mdct call */ | ||
1437 | for(ch=config.wave.channels ;ch--; ) | ||
1438 | memcpy(sb_sample[ch][0], sb_sample[ch][2], 18 * 32 * sizeof(int)); | ||
1439 | } | ||
1440 | |||
1441 | void filter_subband(short *buffer, int s[SBLIMIT], int k) | ||
1442 | { | ||
1443 | short *enwindow = enwindow_int; | ||
1444 | int i, j, tmp = 0; | ||
1445 | #ifndef SIMULATOR | ||
1446 | int reg_buff[14]; /* register storage buffer */ | ||
1447 | #endif | ||
1448 | |||
1449 | /* replace 32 oldest samples with 32 new samples */ | ||
1450 | /* 2304=72*32: PCM Samples are little-endian, swap if necessary */ | ||
1451 | if(config.byte_order == order_bigEndian) | ||
1452 | { | ||
1453 | for(i=32; i--; ) | ||
1454 | { | ||
1455 | j = *(unsigned short*)(buffer+=2); | ||
1456 | x_int[k][i+off[k]] = (short)((j >> 8) | (j << 8)); | ||
1457 | } | ||
1458 | } | ||
1459 | else | ||
1460 | { | ||
1461 | for(i=32; i--; ) | ||
1462 | x_int[k][i+off[k]] = (short)*(buffer+=2); | ||
1463 | } | ||
1464 | |||
1465 | /* 36864=72*512: shift samples into proper window positions */ | ||
1466 | #ifdef SIMULATOR | ||
1467 | for(i=0; i<64; i++) | ||
1468 | { | ||
1469 | for(j=0, tmp=0; j<512; j+=64) | ||
1470 | tmp += (int)x_int[k][(i+0+j+off[k])&(HAN_SIZE-1)] * (int)*(enwindow++); | ||
1471 | y_int[i] = (short)((tmp + (1<<18)) >> 19); | ||
1472 | } | ||
1473 | #else | ||
1474 | { short *xint = &x_int[k][off[k]]; | ||
1475 | short *yint = y_int; | ||
1476 | |||
1477 | asm volatile ("movem.l %%d0/%%d2-%%d7/%%a2-%%a7,(%0)\n" : : "a" (reg_buff) : "d0"); | ||
1478 | asm volatile ("move.l #0, %macsr"); /* integer mode */ | ||
1479 | asm volatile ("move.l #32, %acc2"); /* set loop counter */ | ||
1480 | |||
1481 | asm volatile( | ||
1482 | "move.l #32, %%acc2\n" | ||
1483 | "move.l %[xint], %%d0\n" /* d0 = x_int[k] */ | ||
1484 | "or.l #0x3ff, %%d0\n" | ||
1485 | "move.l %%d0, %%mask\n" /* set address mask */ | ||
1486 | |||
1487 | "move.l (%[xint]), %%d4\n" /* d4 = x_int[k][off[k]] */ | ||
1488 | ".align 2\n" | ||
1489 | |||
1490 | "loop_start:\n" | ||
1491 | "movem.l (%[enwindow]), %%d0-%%d3\n" /* load 4 values */ | ||
1492 | "mac.w %%d0u, %%d4u, (0x080,%[xint])&, %%d5, %%acc0\n" | ||
1493 | "mac.w %%d0l, %%d5u, (0x100,%[xint])&, %%d6, %%acc0\n" | ||
1494 | "mac.w %%d1u, %%d6u, (0x180,%[xint])&, %%d7, %%acc0\n" | ||
1495 | "mac.w %%d1l, %%d7u, (0x200,%[xint])&, %%a2, %%acc0\n" | ||
1496 | "mac.w %%d2u, %%a2u, (0x280,%[xint])&, %%a3, %%acc0\n" | ||
1497 | "mac.w %%d2l, %%a3u, (0x300,%[xint])&, %%a4, %%acc0\n" | ||
1498 | "mac.w %%d3u, %%a4u, (0x380,%[xint])&, %%a5, %%acc0\n" | ||
1499 | "mac.w %%d3l, %%a5u, %%acc0\n" | ||
1500 | |||
1501 | "movem.l (16,%[enwindow]), %%d0-%%d3\n" /* load 8 values */ | ||
1502 | "mac.w %%d0u, %%d4l, %%acc1\n" | ||
1503 | "mac.w %%d0l, %%d5l, %%acc1\n" | ||
1504 | "mac.w %%d1u, %%d6l, %%acc1\n" | ||
1505 | "mac.w %%d1l, %%d7l, %%acc1\n" | ||
1506 | "mac.w %%d2u, %%a2l, %%acc1\n" | ||
1507 | "mac.w %%d2l, %%a3l, %%acc1\n" | ||
1508 | "mac.w %%d3u, %%a4l, %%acc1\n" | ||
1509 | "add.l #4, %[xint]\n" /* xint += 2 */ | ||
1510 | "mac.w %%d3l, %%a5l, (%[xint])&, %%d4, %%acc1\n" | ||
1511 | |||
1512 | "movclr.l %%acc0, %%d5\n" | ||
1513 | "movclr.l %%acc1, %%d6\n" | ||
1514 | "add.l #262144, %%d5\n" | ||
1515 | "add.l #262144, %%d6\n" | ||
1516 | "move.l #19, %%d7\n" | ||
1517 | "asr.l %%d7,%%d5\n" | ||
1518 | "asr.l %%d7,%%d6\n" | ||
1519 | "move.w %%d5, (%[yint])\n" | ||
1520 | "move.w %%d6, (2,%[yint])\n" | ||
1521 | |||
1522 | "add.l #4, %[yint]\n" /* yint += 2 */ | ||
1523 | "add.l #32, %[enwindow]\n" /* enwindow += 16 */ | ||
1524 | |||
1525 | "moveq.l #1, %%d0\n" | ||
1526 | "msac.l %%d0, %%d0, %%acc2\n" | ||
1527 | "move.l %%acc2, %%d0\n" | ||
1528 | "tst.b %%d0\n" | ||
1529 | "jbne loop_start\n" | ||
1530 | |||
1531 | : [xint] "+a" (xint), [yint] "+a" (yint) | ||
1532 | : [enwindow] "a" (enwindow) | ||
1533 | : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a2", "a3", "a4", "a5"); | ||
1534 | |||
1535 | asm volatile ("movem.l (%0),%%d0/%%d2-%%d7/%%a2-%%a7\n" : : "a" (reg_buff) : "d0"); | ||
1536 | } | ||
1537 | #endif | ||
1538 | |||
1539 | /* 147456=72*2048 */ | ||
1540 | for(i=SBLIMIT; i--; ) // SBLIMIT: 32 | ||
1541 | { | ||
1542 | short *filt = filter_int[i]; | ||
1543 | |||
1544 | #ifdef SIMULATOR | ||
1545 | for(j=64, tmp=0; j--; ) | ||
1546 | tmp += (long)filt[j] * (long)y_int[j]; | ||
1547 | #else | ||
1548 | asm volatile ("move.l #0, %macsr"); /* integer mode */ | ||
1549 | { | ||
1550 | asm volatile( | ||
1551 | "move.l (%[yint]), %%a5\n" | ||
1552 | "movem.l (%[filt]), %%d0-%%d7\n" | ||
1553 | "mac.w %%d0u, %%a5u, %%acc0\n" | ||
1554 | "mac.w %%d0l, %%a5l, ( 4, %[yint]), %%a5, %%acc0\n" | ||
1555 | "mac.w %%d1u, %%a5u, %%acc0\n" | ||
1556 | "mac.w %%d1l, %%a5l, ( 8, %[yint]), %%a5, %%acc0\n" | ||
1557 | "mac.w %%d2u, %%a5u, %%acc0\n" | ||
1558 | "mac.w %%d2l, %%a5l, ( 12, %[yint]), %%a5, %%acc0\n" | ||
1559 | "mac.w %%d3u, %%a5u, %%acc0\n" | ||
1560 | "mac.w %%d3l, %%a5l, ( 16, %[yint]), %%a5, %%acc0\n" | ||
1561 | "mac.w %%d4u, %%a5u, %%acc0\n" | ||
1562 | "mac.w %%d4l, %%a5l, ( 20, %[yint]), %%a5, %%acc0\n" | ||
1563 | "mac.w %%d5u, %%a5u, %%acc0\n" | ||
1564 | "mac.w %%d5l, %%a5l, ( 24, %[yint]), %%a5, %%acc0\n" | ||
1565 | "mac.w %%d6u, %%a5u, %%acc0\n" | ||
1566 | "mac.w %%d6l, %%a5l, ( 28, %[yint]), %%a5, %%acc0\n" | ||
1567 | "mac.w %%d7u, %%a5u, %%acc0\n" | ||
1568 | "mac.w %%d7l, %%a5l, ( 32, %[yint]), %%a5, %%acc0\n" | ||
1569 | "movem.l (32,%[filt]), %%d0-%%d7\n" | ||
1570 | "mac.w %%d0u, %%a5u, %%acc0\n" | ||
1571 | "mac.w %%d0l, %%a5l, ( 36, %[yint]), %%a5, %%acc0\n" | ||
1572 | "mac.w %%d1u, %%a5u, %%acc0\n" | ||
1573 | "mac.w %%d1l, %%a5l, ( 40, %[yint]), %%a5, %%acc0\n" | ||
1574 | "mac.w %%d2u, %%a5u, %%acc0\n" | ||
1575 | "mac.w %%d2l, %%a5l, ( 44, %[yint]), %%a5, %%acc0\n" | ||
1576 | "mac.w %%d3u, %%a5u, %%acc0\n" | ||
1577 | "mac.w %%d3l, %%a5l, ( 48, %[yint]), %%a5, %%acc0\n" | ||
1578 | "mac.w %%d4u, %%a5u, %%acc0\n" | ||
1579 | "mac.w %%d4l, %%a5l, ( 52, %[yint]), %%a5, %%acc0\n" | ||
1580 | "mac.w %%d5u, %%a5u, %%acc0\n" | ||
1581 | "mac.w %%d5l, %%a5l, ( 56, %[yint]), %%a5, %%acc0\n" | ||
1582 | "mac.w %%d6u, %%a5u, %%acc0\n" | ||
1583 | "mac.w %%d6l, %%a5l, ( 60, %[yint]), %%a5, %%acc0\n" | ||
1584 | "mac.w %%d7u, %%a5u, %%acc0\n" | ||
1585 | "mac.w %%d7l, %%a5l, ( 64, %[yint]), %%a5, %%acc0\n" | ||
1586 | "movem.l (64,%[filt]), %%d0-%%d7\n" | ||
1587 | "mac.w %%d0u, %%a5u, %%acc0\n" | ||
1588 | "mac.w %%d0l, %%a5l, ( 68, %[yint]), %%a5, %%acc0\n" | ||
1589 | "mac.w %%d1u, %%a5u, %%acc0\n" | ||
1590 | "mac.w %%d1l, %%a5l, ( 72, %[yint]), %%a5, %%acc0\n" | ||
1591 | "mac.w %%d2u, %%a5u, %%acc0\n" | ||
1592 | "mac.w %%d2l, %%a5l, ( 76, %[yint]), %%a5, %%acc0\n" | ||
1593 | "mac.w %%d3u, %%a5u, %%acc0\n" | ||
1594 | "mac.w %%d3l, %%a5l, ( 80, %[yint]), %%a5, %%acc0\n" | ||
1595 | "mac.w %%d4u, %%a5u, %%acc0\n" | ||
1596 | "mac.w %%d4l, %%a5l, ( 84, %[yint]), %%a5, %%acc0\n" | ||
1597 | "mac.w %%d5u, %%a5u, %%acc0\n" | ||
1598 | "mac.w %%d5l, %%a5l, ( 88, %[yint]), %%a5, %%acc0\n" | ||
1599 | "mac.w %%d6u, %%a5u, %%acc0\n" | ||
1600 | "mac.w %%d6l, %%a5l, ( 92, %[yint]), %%a5, %%acc0\n" | ||
1601 | "mac.w %%d7u, %%a5u, %%acc0\n" | ||
1602 | "mac.w %%d7l, %%a5l, ( 96, %[yint]), %%a5, %%acc0\n" | ||
1603 | "movem.l (96,%[filt]), %%d0-%%d7\n" | ||
1604 | "mac.w %%d0u, %%a5u, %%acc0\n" | ||
1605 | "mac.w %%d0l, %%a5l, (100, %[yint]), %%a5, %%acc0\n" | ||
1606 | "mac.w %%d1u, %%a5u, %%acc0\n" | ||
1607 | "mac.w %%d1l, %%a5l, (104, %[yint]), %%a5, %%acc0\n" | ||
1608 | "mac.w %%d2u, %%a5u, %%acc0\n" | ||
1609 | "mac.w %%d2l, %%a5l, (108, %[yint]), %%a5, %%acc0\n" | ||
1610 | "mac.w %%d3u, %%a5u, %%acc0\n" | ||
1611 | "mac.w %%d3l, %%a5l, (112, %[yint]), %%a5, %%acc0\n" | ||
1612 | "mac.w %%d4u, %%a5u, %%acc0\n" | ||
1613 | "mac.w %%d4l, %%a5l, (116, %[yint]), %%a5, %%acc0\n" | ||
1614 | "mac.w %%d5u, %%a5u, %%acc0\n" | ||
1615 | "mac.w %%d5l, %%a5l, (120, %[yint]), %%a5, %%acc0\n" | ||
1616 | "mac.w %%d6u, %%a5u, %%acc0\n" | ||
1617 | "mac.w %%d6l, %%a5l, (124, %[yint]), %%a5, %%acc0\n" | ||
1618 | "mac.w %%d7u, %%a5u, %%acc0\n" | ||
1619 | "mac.w %%d7l, %%a5l, %%acc0\n" | ||
1620 | |||
1621 | : : [filt] "a" (filt), [yint] "a" (y_int) | ||
1622 | : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5" ); | ||
1623 | |||
1624 | asm volatile ("movclr.l %%acc0, %[tmp]\n" : [tmp]"+r"(tmp) ); | ||
1625 | } | ||
1626 | #endif | ||
1627 | s[i] = (tmp + 16384) >> 15; | ||
1628 | } | ||
1629 | |||
1630 | off[k] = (off[k] + 480) & (HAN_SIZE-1); /* offset is modulo HAN_SIZE */ | ||
1631 | } | ||
1632 | |||
1633 | void compress(void) | ||
1634 | { | ||
1635 | int channel; | ||
1636 | int i; | ||
1637 | char stg[20]; | ||
1638 | int gr; | ||
1639 | side_info_t cod_info[2][2]; | ||
1640 | short *buffer_window[2]; | ||
1641 | unsigned long avg_slots_per_frame; | ||
1642 | long frac_slots_per_frame; | ||
1643 | long whole_slots_per_frame; | ||
1644 | long slot_lag; | ||
1645 | int mean_bits; | ||
1646 | int sideinfo_len; | ||
1647 | |||
1648 | open_bitstream(config.outfile); | ||
1649 | |||
1650 | memset(cod_info , 0 , sizeof(cod_info )); | ||
1651 | memset(x_int0 , 0 , sizeof(x_int0 )); | ||
1652 | memset(x_int1 , 0 , sizeof(x_int1 )); | ||
1653 | memset(y_int , 0 , sizeof(y_int )); | ||
1654 | memset(mdct_freq , 0 , sizeof(mdct_freq )); | ||
1655 | memset(enc_data , 0 , sizeof(enc_data )); | ||
1656 | memset(off , 0 , sizeof(off )); | ||
1657 | memset(mdct_in , 0 , sizeof(mdct_in )); | ||
1658 | memset(sb_sample , 0 , sizeof(sb_sample )); | ||
1659 | memset(&CodedData , 0 , sizeof(CodedData )); | ||
1660 | memcpy(scalefac_long, sfBandIndex[config.mpeg.samplerate_index + (config.mpeg.type * 3)], sizeof(scalefac_long)); | ||
1661 | memcpy(ca_int , ca_int_const , sizeof(ca_int )); | ||
1662 | memcpy(cs_int , cs_int_const , sizeof(cs_int )); | ||
1663 | memcpy(win_int , win_int_const , sizeof(win_int )); | ||
1664 | memcpy(filter_int , filter_int_const , sizeof(filter_int )); | ||
1665 | memcpy(enwindow_int, enwindow_int_const, sizeof(enwindow_int)); | ||
1666 | memcpy(int2idx , int2idx_const , sizeof(int2idx )); | ||
1667 | memcpy(ht_count1 , ht_count1_const , sizeof(ht_count1 )); | ||
1668 | memcpy( t1HB , t1HB_const , sizeof(t1HB )); | ||
1669 | memcpy( t2HB , t2HB_const , sizeof(t2HB )); | ||
1670 | memcpy( t3HB , t3HB_const , sizeof(t3HB )); | ||
1671 | memcpy( t5HB , t5HB_const , sizeof(t5HB )); | ||
1672 | memcpy( t6HB , t6HB_const , sizeof(t6HB )); | ||
1673 | memcpy( t7HB , t7HB_const , sizeof(t7HB )); | ||
1674 | memcpy( t8HB , t8HB_const , sizeof(t8HB )); | ||
1675 | memcpy( t9HB , t9HB_const , sizeof(t9HB )); | ||
1676 | memcpy(t10HB , t10HB_const , sizeof(t10HB )); | ||
1677 | memcpy(t11HB , t11HB_const , sizeof(t11HB )); | ||
1678 | memcpy(t12HB , t12HB_const , sizeof(t12HB )); | ||
1679 | memcpy(t13HB , t13HB_const , sizeof(t13HB )); | ||
1680 | memcpy(t15HB , t15HB_const , sizeof(t15HB )); | ||
1681 | memcpy(t16HB , t16HB_const , sizeof(t16HB )); | ||
1682 | memcpy(t24HB , t24HB_const , sizeof(t24HB )); | ||
1683 | memcpy( t1l , t1l_const , sizeof(t1l )); | ||
1684 | memcpy( t2l , t2l_const , sizeof(t2l )); | ||
1685 | memcpy( t3l , t3l_const , sizeof(t3l )); | ||
1686 | memcpy( t5l , t5l_const , sizeof(t5l )); | ||
1687 | memcpy( t6l , t6l_const , sizeof(t6l )); | ||
1688 | memcpy( t7l , t7l_const , sizeof(t7l )); | ||
1689 | memcpy( t8l , t8l_const , sizeof(t8l )); | ||
1690 | memcpy( t9l , t9l_const , sizeof(t9l )); | ||
1691 | memcpy(t10l , t10l_const , sizeof(t10l )); | ||
1692 | memcpy(t11l , t11l_const , sizeof(t11l )); | ||
1693 | memcpy(t12l , t12l_const , sizeof(t12l )); | ||
1694 | memcpy(t13l , t13l_const , sizeof(t13l )); | ||
1695 | memcpy(t15l , t15l_const , sizeof(t15l )); | ||
1696 | memcpy(t16l , t16l_const , sizeof(t16l )); | ||
1697 | memcpy(t24l , t24l_const , sizeof(t24l )); | ||
1698 | memcpy(ht , ht_const , sizeof(ht )); | ||
1699 | |||
1700 | /* I don't know, wether this is really necessary */ | ||
1701 | ht[ 0].table = NULL; ht[ 0].hlen = NULL;// Apparently not used | ||
1702 | ht[ 1].table = t1HB; ht[ 1].hlen = t1l; | ||
1703 | ht[ 2].table = t2HB; ht[ 2].hlen = t2l; | ||
1704 | ht[ 3].table = t3HB; ht[ 3].hlen = t3l; | ||
1705 | ht[ 4].table = NULL; ht[ 4].hlen = NULL;// Apparently not used | ||
1706 | ht[ 5].table = t5HB; ht[ 5].hlen = t5l; | ||
1707 | ht[ 6].table = t6HB; ht[ 6].hlen = t6l; | ||
1708 | ht[ 7].table = t7HB; ht[ 7].hlen = t7l; | ||
1709 | ht[ 8].table = t8HB; ht[ 8].hlen = t8l; | ||
1710 | ht[ 9].table = t9HB; ht[ 9].hlen = t9l; | ||
1711 | ht[10].table = t10HB; ht[10].hlen = t10l; | ||
1712 | ht[11].table = t11HB; ht[11].hlen = t11l; | ||
1713 | ht[12].table = t12HB; ht[12].hlen = t12l; | ||
1714 | ht[13].table = t13HB; ht[13].hlen = t13l; | ||
1715 | ht[14].table = NULL; ht[14].hlen = NULL;// Apparently not used | ||
1716 | ht[15].table = t15HB; ht[15].hlen = t15l; | ||
1717 | ht[16].table = t16HB; ht[16].hlen = t16l; | ||
1718 | ht[17].table = t16HB; ht[17].hlen = t16l; | ||
1719 | ht[18].table = t16HB; ht[18].hlen = t16l; | ||
1720 | ht[19].table = t16HB; ht[19].hlen = t16l; | ||
1721 | ht[20].table = t16HB; ht[20].hlen = t16l; | ||
1722 | ht[21].table = t16HB; ht[21].hlen = t16l; | ||
1723 | ht[22].table = t16HB; ht[22].hlen = t16l; | ||
1724 | ht[23].table = t16HB; ht[23].hlen = t16l; | ||
1725 | ht[24].table = t24HB; ht[24].hlen = t24l; | ||
1726 | ht[25].table = t24HB; ht[25].hlen = t24l; | ||
1727 | ht[26].table = t24HB; ht[26].hlen = t24l; | ||
1728 | ht[27].table = t24HB; ht[27].hlen = t24l; | ||
1729 | ht[28].table = t24HB; ht[28].hlen = t24l; | ||
1730 | ht[29].table = t24HB; ht[29].hlen = t24l; | ||
1731 | ht[30].table = t24HB; ht[30].hlen = t24l; | ||
1732 | ht[31].table = t24HB; ht[31].hlen = t24l; | ||
1733 | |||
1734 | x_int[0] = x_int0; | ||
1735 | x_int[1] = x_int1; | ||
1736 | |||
1737 | #ifndef SIMULATOR | ||
1738 | if(((long)x_int0 | (long)x_int1) & 0x7ff) | ||
1739 | return; /* both arrays must be aligned to 0x800 boundary */ | ||
1740 | #endif | ||
1741 | |||
1742 | if(config.wave.channels == 1) | ||
1743 | sideinfo_len = 32 + 136; | ||
1744 | else | ||
1745 | sideinfo_len = 32 + 256; | ||
1746 | |||
1747 | /* Set initial step size */ | ||
1748 | cod_info[0][0].quantizerStepSize = 0x10; | ||
1749 | cod_info[0][1].quantizerStepSize = 0x10; | ||
1750 | cod_info[1][0].quantizerStepSize = 0x10; | ||
1751 | cod_info[1][1].quantizerStepSize = 0x10; | ||
1752 | |||
1753 | /* Figure average number of 'slots' per frame. */ | ||
1754 | frames_processed = 0; | ||
1755 | avg_slots_per_frame = (uint32)(samp_per_frame * 8000 * config.mpeg.bitr) / config.wave.samplerate; | ||
1756 | whole_slots_per_frame = avg_slots_per_frame / 64; | ||
1757 | frac_slots_per_frame = avg_slots_per_frame - 64 * whole_slots_per_frame; | ||
1758 | slot_lag = -frac_slots_per_frame; | ||
1759 | if(frac_slots_per_frame == 0) | ||
1760 | config.mpeg.padding = 0; | ||
1761 | |||
1762 | while(1) | ||
1763 | { | ||
1764 | rb->lcd_clear_display(); | ||
1765 | rb->snprintf(stg, 20, "Frame %d / %d", frames_processed++, wav_size/samp_per_frame/4); | ||
1766 | rb->lcd_putsxy(4, 20, stg); | ||
1767 | rb->lcd_update(); | ||
1768 | |||
1769 | if(read_samples(buffer, samp_per_frame<<1) == 0) | ||
1770 | break; | ||
1771 | |||
1772 | buffer_window[0] = &buffer[-2]; | ||
1773 | buffer_window[1] = &buffer[-1]; | ||
1774 | |||
1775 | if(frac_slots_per_frame) | ||
1776 | { | ||
1777 | if(slot_lag > frac_slots_per_frame - 64) | ||
1778 | { /* No padding for this frame */ | ||
1779 | slot_lag -= frac_slots_per_frame; | ||
1780 | config.mpeg.padding = 0; | ||
1781 | } | ||
1782 | else | ||
1783 | { /* Padding for this frame */ | ||
1784 | slot_lag += (64 - frac_slots_per_frame); | ||
1785 | config.mpeg.padding = 1; | ||
1786 | } | ||
1787 | } | ||
1788 | |||
1789 | config.mpeg.bits_per_frame = 8 * (whole_slots_per_frame + config.mpeg.padding); | ||
1790 | mean_bits = (config.mpeg.bits_per_frame - sideinfo_len) >> 1; | ||
1791 | |||
1792 | /* polyphase filtering */ | ||
1793 | for(gr=0; gr<2; gr++) | ||
1794 | for(channel=config.wave.channels; channel--; ) | ||
1795 | for(i=0; i<18; i++) | ||
1796 | { | ||
1797 | filter_subband(buffer_window[channel], &sb_sample[channel][gr+1][i][0], channel); | ||
1798 | buffer_window[channel] += 64; | ||
1799 | } | ||
1800 | |||
1801 | mdct_sub_int(sb_sample, mdct_freq); | ||
1802 | /* bit and noise allocation */ | ||
1803 | iteration_loop(mdct_freq, cod_info, mean_bits); | ||
1804 | /* write the frame to the bitstream */ | ||
1805 | format_bitstream(enc_data, cod_info, mdct_freq); | ||
1806 | } | ||
1807 | /* write last chunks to disk */ | ||
1808 | rb->write(*mp3file, enc_buffer, enc_chunk*256*sizeof(uint32)); | ||
1809 | } | ||
1810 | |||
1811 | static int find_bitrate_index(int bitr) | ||
1812 | { | ||
1813 | static long mpeg1[15] = {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320}; | ||
1814 | int i; | ||
1815 | |||
1816 | for(i=0;i<15;i++) | ||
1817 | if(bitr==mpeg1[i]) return i; | ||
1818 | |||
1819 | return -1; | ||
1820 | } | ||
1821 | |||
1822 | static int find_samplerate_index(long freq) | ||
1823 | { | ||
1824 | static long mpeg1[3] = {44100, 48000, 32000}; | ||
1825 | int i; | ||
1826 | |||
1827 | for(i=0;i<3;i++) | ||
1828 | if(freq==mpeg1[i]) return i; | ||
1829 | |||
1830 | return -1; | ||
1831 | } | ||
1832 | |||
1833 | |||
1834 | int num_file; | ||
1835 | char filename[12][80]; | ||
1836 | char mp3_name[80]; | ||
1837 | |||
1838 | void read_wav_files(char *dirname) | ||
1839 | { | ||
1840 | DIR *dir = rb->opendir(dirname); | ||
1841 | |||
1842 | if(!dir) | ||
1843 | return; | ||
1844 | |||
1845 | while(true) | ||
1846 | { | ||
1847 | struct dirent *entry; | ||
1848 | |||
1849 | entry = rb->readdir(dir); | ||
1850 | if(!entry) | ||
1851 | break; | ||
1852 | |||
1853 | if( !(entry->attribute & ATTR_DIRECTORY) ) | ||
1854 | { | ||
1855 | int slen = rb->strlen(entry->d_name); | ||
1856 | |||
1857 | /* add all wav audio files */ | ||
1858 | if(!rb->strcasecmp(entry->d_name + slen - 4, ".wav")) | ||
1859 | { | ||
1860 | if(num_file >= 12) | ||
1861 | break; | ||
1862 | |||
1863 | rb->strncpy(filename[num_file], dirname, 79); | ||
1864 | slen = rb->strlen(filename[num_file]); | ||
1865 | rb->strncpy(filename[num_file++] + slen, entry->d_name, 79); | ||
1866 | } | ||
1867 | } | ||
1868 | } | ||
1869 | rb->closedir(dir); | ||
1870 | } | ||
1871 | |||
1872 | char *get_mp3_filename(char *wav_name) | ||
1873 | { | ||
1874 | int slen = rb->strlen(wav_name); | ||
1875 | rb->strncpy(mp3_name, wav_name, 79); | ||
1876 | rb->strncpy(mp3_name + slen - 4, ".mp3", 5); | ||
1877 | |||
1878 | return mp3_name; | ||
1879 | } | ||
1880 | |||
1881 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | ||
1882 | { | ||
1883 | int fil, sfil, nfil; /* for file selection */ | ||
1884 | int rat, srat, nrat; /* for rate selection */ | ||
1885 | int i, cont, butt; | ||
1886 | long tim = 0; | ||
1887 | char stg[40]; | ||
1888 | char *bitratename[] = { "64","80","96","112","128","160","192","224","256","320" }; | ||
1889 | int brate[] = { 64,80,96,112,128,160,192,224,256,320 }; | ||
1890 | |||
1891 | TEST_PLUGIN_API(api); | ||
1892 | |||
1893 | (void)parameter; | ||
1894 | rb = api; | ||
1895 | |||
1896 | rb->lcd_setfont(FONT_SYSFIXED); | ||
1897 | |||
1898 | #ifndef SIMULATOR | ||
1899 | rb->cpu_boost(true); | ||
1900 | #endif | ||
1901 | rb->button_clear_queue(); | ||
1902 | |||
1903 | read_wav_files("/"); | ||
1904 | read_wav_files(REC_BASE_DIR"/"); | ||
1905 | |||
1906 | nfil = num_file - 1; | ||
1907 | sfil = 0; /* set first file as default */ | ||
1908 | cont = 1; | ||
1909 | |||
1910 | while(cont && (butt = rb->button_get_w_tmo(HZ/10)) != BUTTON_RIGHT) | ||
1911 | { | ||
1912 | switch(butt) | ||
1913 | { | ||
1914 | case BUTTON_OFF: cont = 0; break; | ||
1915 | case BUTTON_UP: if(sfil > 0 ) sfil--; break; | ||
1916 | case BUTTON_DOWN: if(sfil < nfil) sfil++; break; | ||
1917 | } | ||
1918 | |||
1919 | rb->lcd_clear_display(); | ||
1920 | rb->lcd_putsxy(2, 2, "-- Select WAV-File --"); | ||
1921 | |||
1922 | for(fil=0; fil<=nfil; fil++) | ||
1923 | rb->lcd_putsxy(2, 12 + fil*8, filename[fil]); | ||
1924 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | ||
1925 | rb->lcd_fillrect(0, 12 + sfil*8, 127, 8); | ||
1926 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
1927 | rb->lcd_update(); | ||
1928 | } | ||
1929 | |||
1930 | nrat = 9; | ||
1931 | srat = 4; /* set 128kBit as default */ | ||
1932 | |||
1933 | while(cont && (butt = rb->button_get_w_tmo(HZ/10)) != BUTTON_RIGHT) | ||
1934 | { | ||
1935 | switch(butt) | ||
1936 | { | ||
1937 | case BUTTON_OFF: cont = 0; break; | ||
1938 | case BUTTON_UP: if(srat > 0 ) srat--; break; | ||
1939 | case BUTTON_DOWN: if(srat < nrat) srat++; break; | ||
1940 | } | ||
1941 | |||
1942 | rb->lcd_clear_display(); | ||
1943 | rb->lcd_putsxy(2, 2, "-- Select Bitrate --"); | ||
1944 | |||
1945 | for(rat=0; rat<=nrat; rat++) | ||
1946 | rb->lcd_putsxy(2, 12 + rat*8, bitratename[rat]); | ||
1947 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | ||
1948 | rb->lcd_fillrect(0, 12 + srat*8, 127, 8); | ||
1949 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
1950 | rb->lcd_update(); | ||
1951 | } | ||
1952 | |||
1953 | config.infile = filename[sfil]; | ||
1954 | config.outfile = get_mp3_filename(filename[sfil]); | ||
1955 | #ifdef SIMULATOR | ||
1956 | config.byte_order = order_littleEndian; | ||
1957 | #else | ||
1958 | config.byte_order = order_bigEndian; | ||
1959 | #endif | ||
1960 | config.mpeg.type = 1; | ||
1961 | config.mpeg.layr = 2; | ||
1962 | config.mpeg.mode = 2; | ||
1963 | config.mpeg.bitr = brate[srat]; | ||
1964 | config.mpeg.emph = 0; | ||
1965 | config.mpeg.crc = 0; | ||
1966 | config.mpeg.ext = 0; | ||
1967 | config.mpeg.mode_ext = 0; | ||
1968 | config.mpeg.copyright = 0; | ||
1969 | config.mpeg.original = 1; | ||
1970 | config.mpeg.bitrate_index = find_bitrate_index(config.mpeg.bitr); | ||
1971 | |||
1972 | if(cont) | ||
1973 | { | ||
1974 | if((i=wave_open()) == 0) | ||
1975 | { | ||
1976 | config.mpeg.samplerate_index = find_samplerate_index(config.wave.samplerate); | ||
1977 | |||
1978 | tim = *rb->current_tick; | ||
1979 | compress(); | ||
1980 | tim = *rb->current_tick - tim; | ||
1981 | |||
1982 | wave_close(); | ||
1983 | rb->close(*mp3file); | ||
1984 | } | ||
1985 | else | ||
1986 | { | ||
1987 | rb->snprintf(stg, 20, "WaveOpen failed: %d", i); | ||
1988 | rb->lcd_putsxy(0, 20, stg); | ||
1989 | rb->lcd_update(); | ||
1990 | rb->sleep(2*HZ); | ||
1991 | } | ||
1992 | |||
1993 | rb->lcd_clear_display(); | ||
1994 | rb->snprintf(stg, 30, " Conversion: %d.%02ds ", tim/100, tim%100); | ||
1995 | rb->lcd_putsxy(0, 30, stg); | ||
1996 | tim = frames_processed * samp_per_frame * 100 / 44100; /* unit=.01s */ | ||
1997 | rb->snprintf(stg, 30, " WAV-Length: %d.%02ds ", tim/100, tim%100); | ||
1998 | rb->lcd_putsxy(0, 20, stg); | ||
1999 | rb->lcd_update(); | ||
2000 | rb->sleep(5*HZ); | ||
2001 | } | ||
2002 | |||
2003 | rb->lcd_setfont(FONT_UI); | ||
2004 | #ifndef SIMULATOR | ||
2005 | rb->cpu_boost(false); | ||
2006 | #endif | ||
2007 | return PLUGIN_OK; | ||
2008 | } | ||