diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rbcodec/codecs/mp3_enc.c | 3983 | ||||
-rw-r--r-- | lib/rbcodec/codecs/wavpack_enc.c | 125 |
2 files changed, 2302 insertions, 1806 deletions
diff --git a/lib/rbcodec/codecs/mp3_enc.c b/lib/rbcodec/codecs/mp3_enc.c index a349f99f25..8765d120e2 100644 --- a/lib/rbcodec/codecs/mp3_enc.c +++ b/lib/rbcodec/codecs/mp3_enc.c | |||
@@ -38,15 +38,12 @@ | |||
38 | 38 | ||
39 | CODEC_ENC_HEADER | 39 | CODEC_ENC_HEADER |
40 | 40 | ||
41 | #define SAMPL2 576 | 41 | #if NUM_CORES > 1 |
42 | #define SBLIMIT 32 | 42 | #define MP3_ENC_COP |
43 | #define HTN 16 | 43 | #endif |
44 | #define memcpy ci->memcpy | 44 | |
45 | #define memset ci->memset | 45 | typedef struct |
46 | #define putlong(c, s) if(s+sz <= 32) { cc = (cc << s) | c; sz+= s; } \ | 46 | { |
47 | else { putbits(cc, sz); cc = c; sz = s; } | ||
48 | |||
49 | typedef struct { | ||
50 | int type; /* 0=(MPEG2 - 22.05,24,16kHz) 1=(MPEG1 - 44.1,48,32kHz) */ | 47 | int type; /* 0=(MPEG2 - 22.05,24,16kHz) 1=(MPEG1 - 44.1,48,32kHz) */ |
51 | int mode; /* 0=stereo, 1=jstereo, 2=dual, 3=mono */ | 48 | int mode; /* 0=stereo, 1=jstereo, 2=dual, 3=mono */ |
52 | int bitrate; | 49 | int bitrate; |
@@ -57,9 +54,10 @@ typedef struct { | |||
57 | } mpeg_t; | 54 | } mpeg_t; |
58 | 55 | ||
59 | /* Side information */ | 56 | /* Side information */ |
60 | typedef struct { | 57 | typedef struct |
58 | { | ||
61 | uint32_t part2_3_length; | 59 | uint32_t part2_3_length; |
62 | int count1; /* number of 0-1-quadruples */ | 60 | int count1; /* number of 0-1-quadruples */ |
63 | uint32_t global_gain; | 61 | uint32_t global_gain; |
64 | uint32_t table_select[4]; | 62 | uint32_t table_select[4]; |
65 | uint32_t region_0_1; | 63 | uint32_t region_0_1; |
@@ -71,7 +69,8 @@ typedef struct { | |||
71 | uint32_t max_val; | 69 | uint32_t max_val; |
72 | } side_info_t; | 70 | } side_info_t; |
73 | 71 | ||
74 | typedef struct { | 72 | typedef struct |
73 | { | ||
75 | side_info_t cod_info[2][2]; | 74 | side_info_t cod_info[2][2]; |
76 | mpeg_t mpg; | 75 | mpeg_t mpg; |
77 | long frac_per_frame; | 76 | long frac_per_frame; |
@@ -80,194 +79,190 @@ typedef struct { | |||
80 | long slot_lag; | 79 | long slot_lag; |
81 | int sideinfo_len; | 80 | int sideinfo_len; |
82 | int mean_bits; | 81 | int mean_bits; |
83 | int ResvSize; | 82 | int resv_size; |
84 | int channels; | 83 | int channels; |
85 | int granules; | 84 | int granules; |
86 | long src_samplerate; | 85 | long src_samplerate; |
87 | long samplerate; | 86 | long samplerate; |
88 | short *samp_buffer; | 87 | short *samp_buffer; |
89 | unsigned samp_per_frame; | 88 | unsigned samp_per_frame; |
90 | int flush_frames; | 89 | int flush_frames; |
91 | int delay; | 90 | int delay; |
92 | int padding; | 91 | int padding; |
93 | } config_t; | 92 | } config_t; |
94 | 93 | ||
95 | typedef struct { | 94 | typedef struct |
96 | int bitpos; /* current bitpos for writing */ | 95 | { |
97 | uint32_t bbuf[263]; | 96 | int bitpos; /* current bitpos for writing */ |
98 | } BF_Data; | 97 | uint32_t bbuf[263]; |
98 | } bf_data; | ||
99 | 99 | ||
100 | struct huffcodetab { | 100 | struct huffcodetab |
101 | int len; /* max. index */ | 101 | { |
102 | const uint8_t *table; /* pointer to array[len][len] */ | 102 | int len; /* max. index */ |
103 | const uint8_t *hlen; /* pointer to array[len][len] */ | 103 | const uint8_t *table; /* pointer to array[len][len] */ |
104 | const uint8_t *hlen; /* pointer to array[len][len] */ | ||
104 | }; | 105 | }; |
105 | 106 | ||
106 | struct huffcodebig { | 107 | struct huffcodebig |
107 | int len; /* max. index */ | 108 | { |
108 | int linbits; /* number of linbits */ | 109 | int len; /* max. index */ |
109 | int linmax; /* max number stored in linbits */ | 110 | int linbits; /* number of linbits */ |
111 | int linmax; /* max number stored in linbits */ | ||
110 | }; | 112 | }; |
111 | 113 | ||
112 | #define shft4(x) ((x + 8) >> 4) | 114 | #define shft4(x) (((x) + 8) >> 4) |
113 | #define shft9(x) ((x + 256) >> 9) | 115 | #define shft9(x) (((x) + 256) >> 9) |
114 | #define shft13(x) ((x + 4096) >> 13) | 116 | #define shft13(x) (((x) + 4096) >> 13) |
115 | #define shft15(x) ((x + 16384) >> 15) | 117 | #define shft15(x) (((x) + 16384) >> 15) |
116 | #define shft16(x) ((x + 32768) >> 16) | 118 | #define shft16(x) (((x) + 32768) >> 16) |
117 | #define shft_n(x,n) ((x) >> n) | 119 | #define shft_n(x, n) ( (x) >> (n)) |
118 | #define SQRT 724 /* sqrt(2) * 512 */ | 120 | #define SQRT 724 /* sqrt(2) * 512 */ |
119 | 121 | ||
120 | static short mfbuf [2*(1152+512)] IBSS_ATTR | 122 | static config_t cfg IBSS_ATTR; |
121 | /* for memcpy and 32-bit access */ MEM_ALIGN_ATTR; /* 3328 Bytes */ | 123 | static short mfbuf [2*(1152+512)] IBSS_ATTR |
122 | static int sb_data [2][2][18][SBLIMIT] IBSS_ATTR; /* 13824 Bytes */ | 124 | /* for memcpy and 32-bit access */ MEM_ALIGN_ATTR; /* 6656 Bytes */ |
123 | static int mdct_freq [SAMPL2] IBSS_ATTR; /* 2304 Bytes */ | 125 | static int sb_data [2][2][18][32] IBSS_ATTR; /* 9216 Bytes */ |
124 | static char mdct_sign [SAMPL2] IBSS_ATTR; /* 576 Bytes */ | 126 | static int mdct_freq [576] IBSS_ATTR; /* 2304 Bytes */ |
125 | static short enc_data [SAMPL2] IBSS_ATTR; /* 1152 Bytes */ | 127 | static char mdct_sign [576] IBSS_ATTR; /* 576 Bytes */ |
126 | static uint32_t scalefac [23] IBSS_ATTR; /* 92 Bytes */ | 128 | static short enc_data [576] IBSS_ATTR; /* 1152 Bytes */ |
127 | static BF_Data CodedData IBSS_ATTR; /* 1056 Bytes */ | 129 | static uint32_t scalefac [22] IBSS_ATTR; /* 88 Bytes */ |
128 | static int ca [8] IBSS_ATTR; /* 32 Bytes */ | 130 | static bf_data coded_data IBSS_ATTR; /* 1056 Bytes */ |
129 | static int cs [8] IBSS_ATTR; /* 32 Bytes */ | 131 | static uint8_t band_scale_f[22] IBSS_ATTR; /* 22 Bytes */ |
130 | static int cx [9] IBSS_ATTR; /* 36 Bytes */ | 132 | |
131 | static int win [18][4] IBSS_ATTR; /* 288 Bytes */ | 133 | #ifdef MP3_ENC_COP |
132 | static short enwindow [15*27+24] IBSS_ATTR; /* 862 Bytes */ | 134 | /* 2-entry circular buffer to pass subband data between threads */ |
133 | static short int2idx [4096] IBSS_ATTR; /* 8192 Bytes */ | 135 | /* 18432 bytes is way too much for IRAM and it must be in coherent RAM */ |
134 | static uint8_t ht_count [2][2][16] IBSS_ATTR; /* 64 Bytes */ | 136 | static int sb_data_buf[2][2][2][18][32] SHAREDBSS_ATTR |
135 | static uint32_t tab01 [ 16] IBSS_ATTR; /* 64 Bytes */ | 137 | MEM_ALIGN_ATTR; |
136 | static uint32_t tab23 [ 9] IBSS_ATTR; /* 36 Bytes */ | 138 | static int (*sb_data_cod)[2][2][18][32] IBSS_ATTR; /* 4 Bytes */ |
137 | static uint32_t tab56 [ 16] IBSS_ATTR; /* 64 Bytes */ | 139 | static int (*sb_data_enc)[2][2][18][32] IBSS_ATTR; /* 4 Bytes */ |
138 | static uint32_t tab1315 [256] IBSS_ATTR; /* 1024 Bytes */ | 140 | #endif /* MP3_ENC_COP */ |
139 | static uint32_t tab1624 [256] IBSS_ATTR; /* 1024 Bytes */ | 141 | |
140 | static uint32_t tab789 [ 36] IBSS_ATTR; /* 144 Bytes */ | 142 | static const uint8_t ht_count[2][2][16] ICONST_ATTR = |
141 | static uint32_t tabABC [ 64] IBSS_ATTR; /* 256 Bytes */ | 143 | { { { 1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1 }, /* table0 */ |
142 | static uint8_t t1HB [ 4] IBSS_ATTR; | 144 | { 1, 5, 5, 7, 5, 8, 7, 9, 5, 7, 7, 9, 7, 9, 9,10 } }, /* hleng0 */ |
143 | static uint8_t t2HB [ 9] IBSS_ATTR; | 145 | { { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, /* table1 */ |
144 | static uint8_t t3HB [ 9] IBSS_ATTR; | 146 | { 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 } } }; /* hleng1 */ |
145 | static uint8_t t5HB [ 16] IBSS_ATTR; | 147 | |
146 | static uint8_t t6HB [ 16] IBSS_ATTR; | 148 | static const uint8_t t1HB[4] ICONST_ATTR = |
147 | static uint8_t t7HB [ 36] IBSS_ATTR; | 149 | { 1, 1, 1, 0 }; |
148 | static uint8_t t8HB [ 36] IBSS_ATTR; | 150 | |
149 | static uint8_t t9HB [ 36] IBSS_ATTR; | 151 | static const uint8_t t2HB[9] ICONST_ATTR = |
150 | static uint8_t t10HB [ 64] IBSS_ATTR; | 152 | { 1, 2, 1, 3, 1, 1, 3, 2, 0 }; |
151 | static uint8_t t11HB [ 64] IBSS_ATTR; | 153 | |
152 | static uint8_t t12HB [ 64] IBSS_ATTR; | 154 | static const uint8_t t3HB[9] ICONST_ATTR = |
153 | static uint8_t t13HB [256] IBSS_ATTR; | 155 | { 3, 2, 1, 1, 1, 1, 3, 2, 0 }; |
154 | static uint8_t t15HB [256] IBSS_ATTR; | 156 | |
155 | static uint16_t t16HB [256] IBSS_ATTR; | 157 | static const uint8_t t5HB[16] ICONST_ATTR = |
156 | static uint16_t t24HB [256] IBSS_ATTR; | 158 | { 1, 2, 6, 5, 3, 1, 4, 4, 7, 5, 7, 1, 6, 1, 1, 0 }; |
157 | static uint8_t t1l [ 8] IBSS_ATTR; | 159 | |
158 | static uint8_t t2l [ 9] IBSS_ATTR; | 160 | static const uint8_t t6HB[16] ICONST_ATTR = |
159 | static uint8_t t3l [ 9] IBSS_ATTR; | 161 | { 7, 3, 5, 1, 6, 2, 3, 2, 5, 4, 4, 1, 3, 3, 2 ,0 }; |
160 | static uint8_t t5l [ 16] IBSS_ATTR; | 162 | |
161 | static uint8_t t6l [ 16] IBSS_ATTR; | 163 | static const uint8_t t7HB[36] ICONST_ATTR = |
162 | static uint8_t t7l [ 36] IBSS_ATTR; | ||
163 | static uint8_t t8l [ 36] IBSS_ATTR; | ||
164 | static uint8_t t9l [ 36] IBSS_ATTR; | ||
165 | static uint8_t t10l [ 64] IBSS_ATTR; | ||
166 | static uint8_t t11l [ 64] IBSS_ATTR; | ||
167 | static uint8_t t12l [ 64] IBSS_ATTR; | ||
168 | static uint8_t t13l [256] IBSS_ATTR; | ||
169 | static uint8_t t15l [256] IBSS_ATTR; | ||
170 | static uint8_t t16l [256] IBSS_ATTR; | ||
171 | static uint8_t t24l [256] IBSS_ATTR; | ||
172 | static struct huffcodetab ht [HTN] IBSS_ATTR; | ||
173 | |||
174 | static config_t cfg IBSS_ATTR; | ||
175 | static uint8_t band_scale_f[22]; | ||
176 | |||
177 | static const uint8_t ht_count_const[2][2][16] = | ||
178 | { { { 1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1 }, /* table0 */ | ||
179 | { 1, 5, 5, 7, 5, 8, 7, 9, 5, 7, 7, 9, 7, 9, 9,10 } }, /* hleng0 */ | ||
180 | { {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, /* table1 */ | ||
181 | { 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 } } }; /* hleng1 */ | ||
182 | |||
183 | static const uint8_t t1HB_const[4] = {1,1,1,0}; | ||
184 | static const uint8_t t2HB_const[9] = {1,2,1,3,1,1,3,2,0}; | ||
185 | static const uint8_t t3HB_const[9] = {3,2,1,1,1,1,3,2,0}; | ||
186 | static const uint8_t t5HB_const[16] = {1,2,6,5,3,1,4,4,7,5,7,1,6,1,1,0}; | ||
187 | static const uint8_t t6HB_const[16] = {7,3,5,1,6,2,3,2,5,4,4,1,3,3,2,0}; | ||
188 | |||
189 | static const uint8_t t7HB_const[36] = | ||
190 | { 1, 2,10,19,16,10, 3, 3, 7,10, 5, 3,11, 4,13,17, 8, 4, | 164 | { 1, 2,10,19,16,10, 3, 3, 7,10, 5, 3,11, 4,13,17, 8, 4, |
191 | 12,11,18,15,11, 2, 7, 6, 9,14, 3, 1, 6, 4, 5, 3, 2, 0 }; | 165 | 12,11,18,15,11, 2, 7, 6, 9,14, 3, 1, 6, 4, 5, 3, 2, 0 }; |
192 | 166 | ||
193 | static const uint8_t t8HB_const[36] = | 167 | static const uint8_t t8HB[36] ICONST_ATTR = |
194 | { 3, 4, 6,18,12, 5, 5, 1, 2,16, 9, 3, 7, 3, 5,14, 7, 3, | 168 | { 3, 4, 6,18,12, 5, 5, 1, 2,16, 9, 3, 7, 3, 5,14, 7, 3, |
195 | 19,17,15,13,10, 4,13, 5, 8,11, 5, 1,12, 4, 4, 1, 1, 0 }; | 169 | 19,17,15,13,10, 4,13, 5, 8,11, 5, 1,12, 4, 4, 1, 1, 0 }; |
196 | 170 | ||
197 | static const uint8_t t9HB_const[36] = | 171 | static const uint8_t t9HB[36] ICONST_ATTR = |
198 | { 7, 5, 9,14,15, 7, 6, 4, 5, 5, 6, 7, 7, 6, 8, 8, 8, 5, | 172 | { 7, 5, 9,14,15, 7, 6, 4, 5, 5, 6, 7, 7, 6, 8, 8, 8, 5, |
199 | 15, 6, 9,10, 5, 1,11, 7, 9, 6, 4, 1,14, 4, 6, 2, 6, 0 }; | 173 | 15, 6, 9,10, 5, 1,11, 7, 9, 6, 4, 1,14, 4, 6, 2, 6, 0 }; |
200 | 174 | ||
201 | static const uint8_t t10HB_const[64] = | 175 | static const uint8_t t10HB[64] ICONST_ATTR = |
202 | {1,2,10,23,35,30,12,17,3,3,8,12,18,21,12,7,11,9,15,21,32, | 176 | { 1, 2,10,23,35,30,12,17, 3, 3, 8,12,18,21,12, 7, |
203 | 40,19,6,14,13,22,34,46,23,18,7,20,19,33,47,27,22,9,3,31,22, | 177 | 11, 9,15,21,32,40,19, 6,14,13,22,34,46,23,18, 7, |
204 | 41,26,21,20,5,3,14,13,10,11,16,6,5,1,9,8,7,8,4,4,2,0 }; | 178 | 20,19,33,47,27,22, 9, 3,31,22,41,26,21,20, 5, 3, |
205 | 179 | 14,13,10,11,16, 6, 5, 1, 9, 8, 7, 8, 4, 4, 2, 0 }; | |
206 | static const uint8_t t11HB_const[64] = | 180 | |
207 | {3,4,10,24,34,33,21,15,5,3,4,10,32,17,11,10,11,7,13,18,30, | 181 | static const uint8_t t11HB[64] ICONST_ATTR = |
208 | 31,20,5,25,11,19,59,27,18,12,5,35,33,31,58,30,16,7,5,28,26, | 182 | { 3, 4,10,24,34,33,21,15, 5, 3, 4,10,32,17,11,10, |
209 | 32,19,17,15,8,14,14,12,9,13,14,9,4,1,11,4,6,6,6,3,2,0 }; | 183 | 11, 7,13,18,30,31,20, 5,25,11,19,59,27,18,12, 5, |
210 | 184 | 35,33,31,58,30,16, 7, 5,28,26,32,19,17,15, 8,14, | |
211 | static const uint8_t t12HB_const[64] = | 185 | 14,12, 9,13,14, 9, 4, 1,11, 4, 6, 6, 6, 3, 2, 0 }; |
212 | {9,6,16,33,41,39,38,26,7,5,6,9,23,16,26,11,17,7,11,14,21, | 186 | |
213 | 30,10,7,17,10,15,12,18,28,14,5,32,13,22,19,18,16,9,5,40,17, | 187 | static const uint8_t t12HB[64] ICONST_ATTR = |
214 | 31,29,17,13,4,2,27,12,11,15,10,7,4,1,27,12,8,12,6,3,1,0 }; | 188 | { 9, 6,16,33,41,39,38,26, 7, 5, 6, 9,23,16,26,11, |
215 | 189 | 17, 7,11,14,21,30,10, 7,17,10,15,12,18,28,14, 5, | |
216 | static const uint8_t t13HB_const[256] = | 190 | 32,13,22,19,18,16, 9, 5,40,17,31,29,17,13, 4, 2, |
217 | {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, | 191 | 27,12,11,15,10, 7, 4, 1,27,12, 8,12, 6, 3, 1, 0 }; |
218 | 24,31,35,22,14,15,13,23,36,59,49,77,65,29,40,30,40,27,33,42,16,22,20,37,61,56, | 192 | |
219 | 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, | 193 | static const uint8_t t13HB[256] ICONST_ATTR = |
220 | 23,24,58,27,50,96,76,70,93,84,77,58,79,29,74,49,41,17,47,45,78,74,115,94,90, | 194 | { 1, 5, 14, 21, 34, 51, 46, 71, 42, 52, 68, 52, 67, 44, 43, 19, |
221 | 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, | 195 | 3, 4, 12, 19, 31, 26, 44, 33, 31, 24, 32, 24, 31, 35, 22, 14, |
222 | 20,30,44,55,78,72,87,78,61,46,54,37,30,20,16,53,25,41,37,44,59,54,81,66,76,57, | 196 | 15, 13, 23, 36, 59, 49, 77, 65, 29, 40, 30, 40, 27, 33, 42, 16, |
223 | 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, | 197 | 22, 20, 37, 61, 56, 79, 73, 64, 43, 76, 56, 37, 26, 31, 25, 14, |
224 | 60,51,36,55,26,34,23,27,14,9,7,34,32,28,39,49,75,30,52,48,40,52,28,18,17,9,5, | 198 | 35, 16, 60, 57, 97, 75,114, 91, 54, 73, 55, 41, 48, 53, 23, 24, |
225 | 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, | 199 | 58, 27, 50, 96, 76, 70, 93, 84, 77, 58, 79, 29, 74, 49, 41, 17, |
226 | 10,6,1,4,2,16,15,17,27,25,20,29,11,17,12,16,8,1,1,0,1 }; | 200 | 47, 45, 78, 74,115, 94, 90, 79, 69, 83, 71, 50, 59, 38, 36, 15, |
227 | 201 | 72, 34, 56, 95, 92, 85, 91, 90, 86, 73, 77, 65, 51, 44, 43, 42, | |
228 | static const uint8_t t15HB_const[256] = | 202 | 43, 20, 30, 44, 55, 78, 72, 87, 78, 61, 46, 54, 37, 30, 20, 16, |
229 | {7,12,18,53,47,76,124,108,89,123,108,119,107,81,122,63,13,5,16,27,46,36,61,51, | 203 | 53, 25, 41, 37, 44, 59, 54, 81, 66, 76, 57, 54, 37, 18, 39, 11, |
230 | 42,70,52,83,65,41,59,36,19,17,15,24,41,34,59,48,40,64,50,78,62,80,56,33,29,28, | 204 | 35, 33, 31, 57, 42, 82, 72, 80, 47, 58, 55, 21, 22, 26, 38, 22, |
231 | 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, | 205 | 53, 25, 23, 38, 70, 60, 51, 36, 55, 26, 34, 23, 27, 14, 9, 7, |
232 | 49,66,46,27,77,37,35,66,58,52,91,74,62,48,79,63,90,62,40,38,125,32,60,56,50, | 206 | 34, 32, 28, 39, 49, 75, 30, 52, 48, 40, 52, 28, 18, 17, 9, 5, |
233 | 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, | 207 | 45, 21, 34, 64, 56, 50, 49, 45, 31, 19, 12, 15, 10, 7, 6, 3, |
234 | 21,25,90,43,41,77,73,63,56,92,77,66,47,67,48,53,36,20,71,34,67,60,58,49,88,76, | 208 | 48, 23, 20, 39, 36, 35, 53, 21, 16, 23, 13, 10, 6, 1, 4, 2, |
235 | 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, | 209 | 16, 15, 17, 27, 25, 20, 29, 11, 17, 12, 16, 8, 1, 1, 0, 1 }; |
236 | 42,40,37,70,64,52,43,70,55,42,25,29,18,11,11,118,68,30,55,50,46,74,65,49,39, | 210 | |
237 | 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, | 211 | static const uint8_t t15HB[256] ICONST_ATTR = |
238 | 43,32,22,37,24,17,12,15,10,2,1,71,37,34,30,28,20,17,26,21,16,10,6,8,6,2,0}; | 212 | { 7, 12, 18, 53, 47, 76,124,108, 89,123,108,119,107, 81,122, 63, |
239 | 213 | 13, 5, 16, 27, 46, 36, 61, 51, 42, 70, 52, 83, 65, 41, 59, 36, | |
240 | static const uint16_t t16HB_const[256] = | 214 | 19, 17, 15, 24, 41, 34, 59, 48, 40, 64, 50, 78, 62, 80, 56, 33, |
241 | {1,5,14,44,74,63,110,93,172,149,138,242,225,195,376,17,3,4,12,20,35,62,53,47, | 215 | 29, 28, 25, 43, 39, 63, 55, 93, 76, 59, 93, 72, 54, 75, 50, 29, |
242 | 83,75,68,119,201,107,207,9,15,13,23,38,67,58,103,90,161,72,127,117,110,209, | 216 | 52, 22, 42, 40, 67, 57, 95, 79, 72, 57, 89, 69, 49, 66, 46, 27, |
243 | 206,16,45,21,39,69,64,114,99,87,158,140,252,212,199,387,365,26,75,36,68,65, | 217 | 77, 37, 35, 66, 58, 52, 91, 74, 62, 48, 79, 63, 90, 62, 40, 38, |
244 | 115,101,179,164,155,264,246,226,395,382,362,9,66,30,59,56,102,185,173,265,142, | 218 | 125, 32, 60, 56, 50, 92, 78, 65, 55, 87, 71, 51, 73, 51, 70, 30, |
245 | 253,232,400,388,378,445,16,111,54,52,100,184,178,160,133,257,244,228,217,385, | 219 | 109, 53, 49, 94, 88, 75, 66,122, 91, 73, 56, 42, 64, 44, 21, 25, |
246 | 366,715,10,98,48,91,88,165,157,148,261,248,407,397,372,380,889,884,8,85,84,81, | 220 | 90, 43, 41, 77, 73, 63, 56, 92, 77, 66, 47, 67, 48, 53, 36, 20, |
247 | 159,156,143,260,249,427,401,392,383,727,713,708,7,154,76,73,141,131,256,245, | 221 | 71, 34, 67, 60, 58, 49, 88, 76, 67,106, 71, 54, 38, 39, 23, 15, |
248 | 426,406,394,384,735,359,710,352,11,139,129,67,125,247,233,229,219,393,743,737, | 222 | 109, 53, 51, 47, 90, 82, 58, 57, 48, 72, 57, 41, 23, 27, 62, 9, |
249 | 720,885,882,439,4,243,120,118,115,227,223,396,746,742,736,721,712,706,223,436, | 223 | 86, 42, 40, 37, 70, 64, 52, 43, 70, 55, 42, 25, 29, 18, 11, 11, |
250 | 6,202,224,222,218,216,389,386,381,364,888,443,707,440,437,1728,4,747,211,210, | 224 | 118, 68, 30, 55, 50, 46, 74, 65, 49, 39, 24, 16, 22, 13, 14, 7, |
251 | 208,370,379,734,723,714,1735,883,877,876,3459,865,2,377,369,102,187,726,722, | 225 | 91, 44, 39, 38, 34, 63, 52, 45, 31, 52, 28, 19, 14, 8, 9, 3, |
252 | 358,711,709,866,1734,871,3458,870,434,0,12,10,7,11,10,17,11,9,13,12,10,7,5,3, | 226 | 123, 60, 58, 53, 47, 43, 32, 22, 37, 24, 17, 12, 15, 10, 2, 1, |
253 | 1,3}; | 227 | 71, 37, 34, 30, 28, 20, 17, 26, 21, 16, 10, 6, 8, 6, 2, 0 }; |
254 | 228 | ||
255 | static const uint16_t t24HB_const[256] = | 229 | static const uint16_t t16HB[256] ICONST_ATTR = |
256 | {15,13,46,80,146,262,248,434,426,669,653,649,621,517,1032,88,14,12,21,38,71, | 230 | { 1, 5, 14, 44, 74, 63,110, 93,172, 149, 138,242, 225, 195, 376, 17, |
257 | 130,122,216,209,198,327,345,319,297,279,42,47,22,41,74,68,128,120,221,207,194, | 231 | 3, 4, 12, 20, 35, 62, 53, 47, 83, 75, 68,119, 201, 107, 207, 9, |
258 | 182,340,315,295,541,18,81,39,75,70,134,125,116,220,204,190,178,325,311,293, | 232 | 15, 13, 23, 38, 67, 58,103, 90,161, 72, 127,117, 110, 209, 206, 16, |
259 | 271,16,147,72,69,135,127,118,112,210,200,188,352,323,306,285,540,14,263,66, | 233 | 45, 21, 39, 69, 64,114, 99, 87,158, 140, 252,212, 199, 387, 365, 26, |
260 | 129,126,119,114,214,202,192,180,341,317,301,281,262,12,249,123,121,117,113, | 234 | 75, 36, 68, 65,115,101,179,164,155, 264, 246,226, 395, 382, 362, 9, |
261 | 215,206,195,185,347,330,308,291,272,520,10,435,115,111,109,211,203,196,187, | 235 | 66, 30, 59, 56,102,185,173,265,142, 253, 232,400, 388, 378, 445, 16, |
262 | 353,332,313,298,283,531,381,17,427,212,208,205,201,193,186,177,169,320,303, | 236 | 111, 54, 52,100,184,178,160,133,257, 244, 228,217, 385, 366, 715, 10, |
263 | 286,268,514,377,16,335,199,197,191,189,181,174,333,321,305,289,275,521,379, | 237 | 98, 48, 91, 88,165,157,148,261,248, 407, 397,372, 380, 889, 884, 8, |
264 | 371,11,668,184,183,179,175,344,331,314,304,290,277,530,383,373,366,10,652,346, | 238 | 85, 84, 81,159,156,143,260,249,427, 401, 392,383, 727, 713, 708, 7, |
265 | 171,168,164,318,309,299,287,276,263,513,375,368,362,6,648,322,316,312,307,302, | 239 | 154, 76, 73,141,131,256,245,426,406, 394, 384,735, 359, 710, 352, 11, |
266 | 292,284,269,261,512,376,370,364,359,4,620,300,296,294,288,282,273,266,515,380, | 240 | 139,129, 67,125,247,233,229,219,393, 743, 737,720, 885, 882, 439, 4, |
267 | 374,369,365,361,357,2,1033,280,278,274,267,264,259,382,378,372,367,363,360, | 241 | 243,120,118,115,227,223,396,746,742, 736, 721,712, 706, 223, 436, 6, |
268 | 358,356,0,43,20,19,17,15,13,11,9,7,6,4,7,5,3,1,3}; | 242 | 202,224,222,218,216,389,386,381,364, 888, 443,707, 440, 437,1728, 4, |
269 | 243 | 747,211,210,208,370,379,734,723,714,1735, 883,877, 876,3459, 865, 2, | |
270 | static const uint32_t tab1315_const[256] = | 244 | 377,369,102,187,726,722,358,711,709, 866,1734,871,3458, 870, 434, 0, |
245 | 12, 10, 7, 11, 10, 17, 11, 9, 13, 12, 10, 7, 5, 3, 1, 3 }; | ||
246 | |||
247 | static const uint16_t t24HB[256] ICONST_ATTR = | ||
248 | { 15, 13, 46, 80,146,262,248,434,426,669,653,649,621,517,1032, 88, | ||
249 | 14, 12, 21, 38, 71,130,122,216,209,198,327,345,319,297, 279, 42, | ||
250 | 47, 22, 41, 74, 68,128,120,221,207,194,182,340,315,295, 541, 18, | ||
251 | 81, 39, 75, 70,134,125,116,220,204,190,178,325,311,293, 271, 16, | ||
252 | 147, 72, 69,135,127,118,112,210,200,188,352,323,306,285, 540, 14, | ||
253 | 263, 66,129,126,119,114,214,202,192,180,341,317,301,281, 262, 12, | ||
254 | 249,123,121,117,113,215,206,195,185,347,330,308,291,272, 520, 10, | ||
255 | 435,115,111,109,211,203,196,187,353,332,313,298,283,531, 381, 17, | ||
256 | 427,212,208,205,201,193,186,177,169,320,303,286,268,514, 377, 16, | ||
257 | 335,199,197,191,189,181,174,333,321,305,289,275,521,379, 371, 11, | ||
258 | 668,184,183,179,175,344,331,314,304,290,277,530,383,373, 366, 10, | ||
259 | 652,346,171,168,164,318,309,299,287,276,263,513,375,368, 362, 6, | ||
260 | 648,322,316,312,307,302,292,284,269,261,512,376,370,364, 359, 4, | ||
261 | 620,300,296,294,288,282,273,266,515,380,374,369,365,361, 357, 2, | ||
262 | 1033,280,278,274,267,264,259,382,378,372,367,363,360,358, 356, 0, | ||
263 | 43, 20, 19, 17, 15, 13, 11, 9, 7, 6, 4, 7, 5, 3, 1, 3 }; | ||
264 | |||
265 | static const uint32_t tab1315[256] ICONST_ATTR = | ||
271 | { 0x010003,0x050005,0x070006,0x080008,0x090008,0x0a0009,0x0a000a,0x0b000a, | 266 | { 0x010003,0x050005,0x070006,0x080008,0x090008,0x0a0009,0x0a000a,0x0b000a, |
272 | 0x0a000a,0x0b000b,0x0c000b,0x0c000c,0x0d000c,0x0d000c,0x0e000d,0x0e000e, | 267 | 0x0a000a,0x0b000b,0x0c000b,0x0c000c,0x0d000c,0x0d000c,0x0e000d,0x0e000e, |
273 | 0x040005,0x060005,0x080007,0x090008,0x0a0009,0x0a0009,0x0b000a,0x0b000a, | 268 | 0x040005,0x060005,0x080007,0x090008,0x0a0009,0x0a0009,0x0b000a,0x0b000a, |
@@ -301,168 +296,204 @@ static const uint32_t tab1315_const[256] = | |||
301 | 0x0d000d,0x0e000d,0x0f000d,0x10000d,0x10000d,0x10000d,0x11000d,0x10000e, | 296 | 0x0d000d,0x0e000d,0x0f000d,0x10000d,0x10000d,0x10000d,0x11000d,0x10000e, |
302 | 0x11000e,0x11000e,0x12000e,0x12000e,0x15000f,0x14000f,0x15000f,0x12000f }; | 297 | 0x11000e,0x11000e,0x12000e,0x12000e,0x15000f,0x14000f,0x15000f,0x12000f }; |
303 | 298 | ||
304 | static const uint32_t tab01_const[16] = | 299 | static const uint32_t tab01[16] ICONST_ATTR = |
305 | { 0x10004,0x50005,0x50005,0x70006,0x50005,0x80006,0x70006,0x90007, | 300 | { 0x10004,0x50005,0x50005,0x70006,0x50005,0x80006,0x70006,0x90007, |
306 | 0x50005,0x70006,0x70006,0x90007,0x70006,0x90007,0x90007,0xa0008 }; | 301 | 0x50005,0x70006,0x70006,0x90007,0x70006,0x90007,0x90007,0xa0008 }; |
307 | 302 | ||
308 | static const uint32_t tab23_const[ 9] = | 303 | static const uint32_t tab23[ 9] ICONST_ATTR = |
309 | { 0x10002,0x40003,0x70007,0x40004,0x50004,0x70007,0x60006,0x70007,0x80008 }; | 304 | { 0x10002,0x40003,0x70007,0x40004,0x50004,0x70007,0x60006,0x70007,0x80008 }; |
310 | 305 | ||
311 | static const uint32_t tab56_const[16] = | 306 | static const uint32_t tab56[16] ICONST_ATTR = |
312 | { 0x10003,0x40004,0x70006,0x80008,0x40004,0x50004,0x80006,0x90007, | 307 | { 0x10003,0x40004,0x70006,0x80008,0x40004,0x50004,0x80006,0x90007, |
313 | 0x70005,0x80006,0x90007,0xa0008,0x80007,0x80007,0x90008,0xa0009 }; | 308 | 0x70005,0x80006,0x90007,0xa0008,0x80007,0x80007,0x90008,0xa0009 }; |
314 | 309 | ||
315 | static const uint32_t tab789_const[36] = | 310 | static const uint32_t tab789[36] ICONST_ATTR = |
316 | {0x00100803,0x00401004,0x00701c06,0x00902407,0x00902409,0x00a0280a,0x00401004, | 311 | { 0x100803,0x401004,0x701c06,0x902407,0x902409,0xa0280a,0x401004,0x601005, |
317 | 0x00601005,0x00801806,0x00902807,0x00902808,0x00a0280a,0x00701c05,0x00701806, | 312 | 0x801806,0x902807,0x902808,0xa0280a,0x701c05,0x701806,0x902007,0xa02808, |
318 | 0x00902007,0x00a02808,0x00a02809,0x00b02c0a,0x00802407,0x00902807,0x00a02808, | 313 | 0xa02809,0xb02c0a,0x802407,0x902807,0xa02808,0xb02c09,0xb02c09,0xb0300a, |
319 | 0x00b02c09,0x00b02c09,0x00b0300a,0x00802408,0x00902408,0x00a02809,0x00b02c09, | 314 | 0x802408,0x902408,0xa02809,0xb02c09,0xb0300a,0xc0300b,0x902809,0xa02809, |
320 | 0x00b0300a,0x00c0300b,0x00902809,0x00a02809,0x00b02c0a,0x00c02c0a,0x00c0340b, | 315 | 0xb02c0a,0xc02c0a,0xc0340b,0xc0340b }; |
321 | 0x00c0340b}; | 316 | |
322 | 317 | static const uint32_t tabABC[64] ICONST_ATTR = | |
323 | static const uint32_t tabABC_const[64] = | 318 | { 0x100804,0x401004,0x701806,0x902008,0xa02409,0xa0280a,0xa0240a,0xb0280a, |
324 | {0x00100804,0x00401004,0x00701806,0x00902008,0x00a02409,0x00a0280a,0x00a0240a, | 319 | 0x401004,0x601405,0x801806,0x902007,0xa02809,0xb02809,0xa0240a,0xa0280a, |
325 | 0x00b0280a,0x00401004,0x00601405,0x00801806,0x00902007,0x00a02809,0x00b02809, | 320 | 0x701806,0x801c06,0x902007,0xa02408,0xb02809,0xc02c0a,0xb02809,0xb0280a, |
326 | 0x00a0240a,0x00a0280a,0x00701806,0x00801c06,0x00902007,0x00a02408,0x00b02809, | 321 | 0x802007,0x902007,0xa02408,0xb02c08,0xc02809,0xc0300a,0xb0280a,0xc02c0a, |
327 | 0x00c02c0a,0x00b02809,0x00b0280a,0x00802007,0x00902007,0x00a02408,0x00b02c08, | 322 | 0x902408,0xa02808,0xb02809,0xc02c09,0xc02c0a,0xc0300a,0xc02c0a,0xc0300b, |
328 | 0x00c02809,0x00c0300a,0x00b0280a,0x00c02c0a,0x00902408,0x00a02808,0x00b02809, | 323 | 0xa02409,0xb02809,0xc02c0a,0xc0300a,0xd0300a,0xd0340b,0xc0300a,0xd0340b, |
329 | 0x00c02c09,0x00c02c0a,0x00c0300a,0x00c02c0a,0x00c0300b,0x00a02409,0x00b02809, | 324 | 0x902409,0xa02409,0xb02409,0xc0280a,0xc02c0a,0xc0300b,0xd0300b,0xd0300c, |
330 | 0x00c02c0a,0x00c0300a,0x00d0300a,0x00d0340b,0x00c0300a,0x00d0340b,0x00902409, | 325 | 0xa0240a,0xa0240a,0xb0280a,0xc02c0b,0xc0300b,0xd0300b,0xd0300b,0xd0300c }; |
331 | 0x00a02409,0x00b02409,0x00c0280a,0x00c02c0a,0x00c0300b,0x00d0300b,0x00d0300c, | 326 | |
332 | 0x00a0240a,0x00a0240a,0x00b0280a,0x00c02c0b,0x00c0300b,0x00d0300b,0x00d0300b, | 327 | static const uint32_t tab1624[256] ICONST_ATTR = |
333 | 0x00d0300c}; | 328 | { 0x010004,0x050005,0x070007,0x090008,0x0a0009,0x0a000a,0x0b000a,0x0b000b, |
334 | 329 | 0x0c000b,0x0c000c,0x0c000c,0x0d000c,0x0d000c,0x0d000c,0x0e000d,0x0a000a, | |
335 | static const uint32_t tab1624_const[256] = | 330 | 0x040005,0x060006,0x080007,0x090008,0x0a0009,0x0b000a,0x0b000a,0x0b000b, |
336 | {0x00010004,0x00050005,0x00070007,0x00090008,0x000a0009,0x000a000a,0x000b000a, | 331 | 0x0c000b,0x0c000b,0x0c000c,0x0d000c,0x0e000c,0x0d000c,0x0e000c,0x0a000a, |
337 | 0x000b000b,0x000c000b,0x000c000c,0x000c000c,0x000d000c,0x000d000c,0x000d000c, | 332 | 0x070007,0x080007,0x090008,0x0a0009,0x0b0009,0x0b000a,0x0c000a,0x0c000b, |
338 | 0x000e000d,0x000a000a,0x00040005,0x00060006,0x00080007,0x00090008,0x000a0009, | 333 | 0x0d000b,0x0c000b,0x0d000b,0x0d000c,0x0d000c,0x0e000c,0x0e000d,0x0b0009, |
339 | 0x000b000a,0x000b000a,0x000b000b,0x000c000b,0x000c000b,0x000c000c,0x000d000c, | 334 | 0x090008,0x090008,0x0a0009,0x0b0009,0x0b000a,0x0c000a,0x0c000a,0x0c000b, |
340 | 0x000e000c,0x000d000c,0x000e000c,0x000a000a,0x00070007,0x00080007,0x00090008, | 335 | 0x0d000b,0x0d000b,0x0e000b,0x0e000c,0x0e000c,0x0f000c,0x0f000c,0x0c0009, |
341 | 0x000a0009,0x000b0009,0x000b000a,0x000c000a,0x000c000b,0x000d000b,0x000c000b, | 336 | 0x0a0009,0x0a0009,0x0b0009,0x0b000a,0x0c000a,0x0c000a,0x0d000a,0x0d000b, |
342 | 0x000d000b,0x000d000c,0x000d000c,0x000e000c,0x000e000d,0x000b0009,0x00090008, | 337 | 0x0d000b,0x0e000b,0x0e000c,0x0e000c,0x0f000c,0x0f000c,0x0f000d,0x0b0009, |
343 | 0x00090008,0x000a0009,0x000b0009,0x000b000a,0x000c000a,0x000c000a,0x000c000b, | 338 | 0x0a000a,0x0a0009,0x0b000a,0x0b000a,0x0c000a,0x0d000a,0x0d000b,0x0e000b, |
344 | 0x000d000b,0x000d000b,0x000e000b,0x000e000c,0x000e000c,0x000f000c,0x000f000c, | 339 | 0x0d000b,0x0e000b,0x0e000c,0x0f000c,0x0f000c,0x0f000c,0x10000c,0x0c0009, |
345 | 0x000c0009,0x000a0009,0x000a0009,0x000b0009,0x000b000a,0x000c000a,0x000c000a, | 340 | 0x0b000a,0x0b000a,0x0b000a,0x0c000a,0x0d000a,0x0d000b,0x0d000b,0x0d000b, |
346 | 0x000d000a,0x000d000b,0x000d000b,0x000e000b,0x000e000c,0x000e000c,0x000f000c, | 341 | 0x0e000b,0x0e000c,0x0e000c,0x0e000c,0x0f000c,0x0f000c,0x10000d,0x0c0009, |
347 | 0x000f000c,0x000f000d,0x000b0009,0x000a000a,0x000a0009,0x000b000a,0x000b000a, | 342 | 0x0b000b,0x0b000a,0x0c000a,0x0c000a,0x0d000b,0x0d000b,0x0d000b,0x0e000b, |
348 | 0x000c000a,0x000d000a,0x000d000b,0x000e000b,0x000d000b,0x000e000b,0x000e000c, | 343 | 0x0e000c,0x0f000c,0x0f000c,0x0f000c,0x0f000c,0x11000d,0x11000d,0x0c000a, |
349 | 0x000f000c,0x000f000c,0x000f000c,0x0010000c,0x000c0009,0x000b000a,0x000b000a, | 344 | 0x0b000b,0x0c000b,0x0c000b,0x0d000b,0x0d000b,0x0d000b,0x0e000b,0x0e000b, |
350 | 0x000b000a,0x000c000a,0x000d000a,0x000d000b,0x000d000b,0x000d000b,0x000e000b, | 345 | 0x0f000b,0x0f000c,0x0f000c,0x0f000c,0x10000c,0x10000d,0x10000d,0x0c000a, |
351 | 0x000e000c,0x000e000c,0x000e000c,0x000f000c,0x000f000c,0x0010000d,0x000c0009, | 346 | 0x0c000b,0x0c000b,0x0c000b,0x0d000b,0x0d000b,0x0e000b,0x0e000b,0x0f000c, |
352 | 0x000b000b,0x000b000a,0x000c000a,0x000c000a,0x000d000b,0x000d000b,0x000d000b, | 347 | 0x0f000c,0x0f000c,0x0f000c,0x10000c,0x0f000d,0x10000d,0x0f000d,0x0d000a, |
353 | 0x000e000b,0x000e000c,0x000f000c,0x000f000c,0x000f000c,0x000f000c,0x0011000d, | 348 | 0x0c000c,0x0d000b,0x0c000b,0x0d000b,0x0e000b,0x0e000c,0x0e000c,0x0e000c, |
354 | 0x0011000d,0x000c000a,0x000b000b,0x000c000b,0x000c000b,0x000d000b,0x000d000b, | 349 | 0x0f000c,0x10000c,0x10000c,0x10000d,0x11000d,0x11000d,0x10000d,0x0c000a, |
355 | 0x000d000b,0x000e000b,0x000e000b,0x000f000b,0x000f000c,0x000f000c,0x000f000c, | 350 | 0x0d000c,0x0d000c,0x0d000b,0x0d000b,0x0e000b,0x0e000c,0x0f000c,0x10000c, |
356 | 0x0010000c,0x0010000d,0x0010000d,0x000c000a,0x000c000b,0x000c000b,0x000c000b, | 351 | 0x10000c,0x10000c,0x10000c,0x10000d,0x10000d,0x0f000d,0x10000d,0x0d000a, |
357 | 0x000d000b,0x000d000b,0x000e000b,0x000e000b,0x000f000c,0x000f000c,0x000f000c, | 352 | 0x0d000c,0x0e000c,0x0e000c,0x0e000c,0x0e000c,0x0f000c,0x0f000c,0x0f000c, |
358 | 0x000f000c,0x0010000c,0x000f000d,0x0010000d,0x000f000d,0x000d000a,0x000c000c, | 353 | 0x0f000c,0x11000c,0x10000d,0x10000d,0x10000d,0x10000d,0x12000d,0x0d000a, |
359 | 0x000d000b,0x000c000b,0x000d000b,0x000e000b,0x000e000c,0x000e000c,0x000e000c, | 354 | 0x0f000c,0x0e000c,0x0e000c,0x0e000c,0x0f000c,0x0f000c,0x10000c,0x10000c, |
360 | 0x000f000c,0x0010000c,0x0010000c,0x0010000d,0x0011000d,0x0011000d,0x0010000d, | 355 | 0x10000d,0x12000d,0x11000d,0x11000d,0x11000d,0x13000d,0x11000d,0x0d000a, |
361 | 0x000c000a,0x000d000c,0x000d000c,0x000d000b,0x000d000b,0x000e000b,0x000e000c, | 356 | 0x0e000d,0x0f000c,0x0d000c,0x0e000c,0x10000c,0x10000c,0x0f000c,0x10000d, |
362 | 0x000f000c,0x0010000c,0x0010000c,0x0010000c,0x0010000c,0x0010000d,0x0010000d, | 357 | 0x10000d,0x11000d,0x12000d,0x11000d,0x13000d,0x11000d,0x10000d,0x0d000a, |
363 | 0x000f000d,0x0010000d,0x000d000a,0x000d000c,0x000e000c,0x000e000c,0x000e000c, | 358 | 0x0a0009,0x0a0009,0x0a0009,0x0b0009,0x0b0009,0x0c0009,0x0c0009,0x0c0009, |
364 | 0x000e000c,0x000f000c,0x000f000c,0x000f000c,0x000f000c,0x0011000c,0x0010000d, | 359 | 0x0d0009,0x0d0009,0x0d0009,0x0d000a,0x0d000a,0x0d000a,0x0d000a,0x0a0006 }; |
365 | 0x0010000d,0x0010000d,0x0010000d,0x0012000d,0x000d000a,0x000f000c,0x000e000c, | 360 | |
366 | 0x000e000c,0x000e000c,0x000f000c,0x000f000c,0x0010000c,0x0010000c,0x0010000d, | 361 | static const uint8_t t1l[8] ICONST_ATTR = |
367 | 0x0012000d,0x0011000d,0x0011000d,0x0011000d,0x0013000d,0x0011000d,0x000d000a, | 362 | { 1,3,2,3,1,4,3,5 }; |
368 | 0x000e000d,0x000f000c,0x000d000c,0x000e000c,0x0010000c,0x0010000c,0x000f000c, | 363 | |
369 | 0x0010000d,0x0010000d,0x0011000d,0x0012000d,0x0011000d,0x0013000d,0x0011000d, | 364 | static const uint8_t t2l[9] ICONST_ATTR = |
370 | 0x0010000d,0x000d000a,0x000a0009,0x000a0009,0x000a0009,0x000b0009,0x000b0009, | 365 | { 1,3,6,3,3,5,5,5,6 }; |
371 | 0x000c0009,0x000c0009,0x000c0009,0x000d0009,0x000d0009,0x000d0009,0x000d000a, | 366 | |
372 | 0x000d000a,0x000d000a,0x000d000a,0x000a0006}; | 367 | static const uint8_t t3l[9] ICONST_ATTR = |
373 | 368 | { 2,2,6,3,2,5,5,5,6 }; | |
374 | static const uint8_t t1l_const[8] = {1,3,2,3,1,4,3,5}; | 369 | |
375 | static const uint8_t t2l_const[9] = {1,3,6,3,3,5,5,5,6}; | 370 | static const uint8_t t5l[16] ICONST_ATTR = |
376 | static const uint8_t t3l_const[9] = {2,2,6,3,2,5,5,5,6}; | 371 | { 1,3,6,7,3,3,6,7,6,6,7,8,7,6,7,8 }; |
377 | static const uint8_t t5l_const[16] = {1,3,6,7,3,3,6,7,6,6,7,8,7,6,7,8}; | 372 | |
378 | static const uint8_t t6l_const[16] = {3,3,5,7,3,2,4,5,4,4,5,6,6,5,6,7}; | 373 | static const uint8_t t6l[16] ICONST_ATTR = |
379 | 374 | { 3,3,5,7,3,2,4,5,4,4,5,6,6,5,6,7 }; | |
380 | static const uint8_t t7l_const[36] = | 375 | |
381 | {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}; | 376 | static const uint8_t t7l[36] ICONST_ATTR = |
382 | 377 | { 1, 3, 6, 8, 8, 9, 3, 4, 6, 7, 7, 8, 6, 5, 7, 8, 8, 9, | |
383 | static const uint8_t t8l_const[36] = | 378 | 7, 7, 8, 9, 9, 9, 7, 7, 8, 9, 9,10, 8, 8, 9,10,10,10 }; |
384 | {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}; | 379 | |
385 | 380 | static const uint8_t t8l[36] ICONST_ATTR = | |
386 | static const uint8_t t9l_const[36] = | 381 | { 2, 3, 6, 8, 8, 9, 3, 2, 4, 8, 8, 8, 6, 4, 6, 8, 8, 9, |
387 | {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}; | 382 | 8, 8, 8, 9, 9,10, 8, 7, 8, 9,10,10, 9, 8, 9, 9,11,11 }; |
388 | 383 | ||
389 | static const uint8_t t10l_const[64] = | 384 | static const uint8_t t9l[36] ICONST_ATTR = |
390 | {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, | 385 | { 3, 3, 5, 6, 8, 9, 3, 3, 4, 5, 6, 8, 4, 4, 5, 6, 7, 8, |
391 | 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}; | 386 | 6, 5, 6, 7, 7, 8, 7, 6, 7, 7, 8, 9, 8, 7, 8, 8, 9, 9 }; |
392 | 387 | ||
393 | static const uint8_t t11l_const[64] = | 388 | static const uint8_t t10l[64] ICONST_ATTR = |
394 | {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, | 389 | { 1, 3, 6, 8, 9, 9, 9,10, 3, 4, 6, 7, 8, 9, 8, 8, |
395 | 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}; | 390 | 6, 6, 7, 8, 9,10, 9, 9, 7, 7, 8, 9,10,10, 9,10, |
396 | 391 | 8, 8, 9,10,10,10,10,10, 9, 9,10,10,11,11,10,11, | |
397 | static const uint8_t t12l_const[64] = | 392 | 8, 8, 9,10,10,10,11,11, 9, 8, 9,10,10,11,11,11 }; |
398 | {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, | 393 | |
399 | 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}; | 394 | static const uint8_t t11l[64] ICONST_ATTR = |
400 | 395 | { 2, 3, 5, 7, 8, 9, 8, 9, 3, 3, 4, 6, 8, 8, 7, 8, | |
401 | static const uint8_t t13l_const[256] = | 396 | 5, 5, 6, 7, 8, 9, 8, 8, 7, 6, 7, 9, 8,10, 8, 9, |
402 | {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, | 397 | 8, 8, 8, 9, 9,10, 9,10, 8, 8, 9,10,10,11,10,11, |
403 | 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, | 398 | 8, 7, 7, 8, 9,10,10,10, 8, 7, 8, 9,10,10,10,10 }; |
404 | 13,13,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, | 399 | |
405 | 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, | 400 | static const uint8_t t12l[64] ICONST_ATTR = |
406 | 11,12,12,12,12,13,13,13,14,16,16,9,8,9,10,10,11,11,12,12,12,12,13,13,14,15,15, | 401 | { 4, 3, 5, 7, 8, 9, 9, 9, 3, 3, 4, 5, 7, 7, 8, 8, |
407 | 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, | 402 | 5, 4, 5, 6, 7, 8, 7, 8, 6, 5, 6, 6, 7, 8, 8, 8, |
408 | 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, | 403 | 7, 6, 7, 7, 8, 8, 8, 9, 8, 7, 8, 8, 8, 9, 8, 9, |
409 | 12,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, | 404 | 8, 7, 7, 8, 8, 9, 9,10, 9, 8, 8, 9, 9, 9, 9,10 }; |
410 | 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, | 405 | |
411 | 15,15,16,16,19,18,19,16}; | 406 | static const uint8_t t13l[256] ICONST_ATTR = |
412 | 407 | { 1, 4, 6, 7, 8, 9, 9,10, 9,10,11,11,12,12,13,13, | |
413 | static const uint8_t t15l_const[256] = | 408 | 3, 4, 6, 7, 8, 8, 9, 9, 9, 9,10,10,11,12,12,12, |
414 | {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, | 409 | 6, 6, 7, 8, 9, 9,10,10, 9,10,10,11,11,12,13,13, |
415 | 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, | 410 | 7, 7, 8, 9, 9,10,10,10,10,11,11,11,11,12,13,13, |
416 | 7,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, | 411 | 8, 7, 9, 9,10,10,11,11,10,11,11,12,12,13,13,14, |
417 | 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, | 412 | 9, 8, 9,10,10,10,11,11,11,11,12,11,13,13,14,14, |
418 | 8,9,9,9,9,10,10,10,10,11,11,12,12,12,9,8,9,9,9,9,10,10,10,11,11,11,11,12,12, | 413 | 9, 9,10,10,11,11,11,11,11,12,12,12,13,13,14,14, |
419 | 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, | 414 | 10, 9,10,11,11,11,12,12,12,12,13,13,13,14,16,16, |
420 | 11,12,12,12,13,11,10,9,10,10,10,11,11,11,11,11,11,12,12,13,13,11,10,10,10,10, | 415 | 9, 8, 9,10,10,11,11,12,12,12,12,13,13,14,15,15, |
421 | 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, | 416 | 10, 9,10,10,11,11,11,13,12,13,13,14,14,14,16,15, |
422 | 13,12,11,11,11,11,11,11,12,12,12,12,12,13,13,13,13}; | 417 | 10,10,10,11,11,12,12,13,12,13,14,13,14,15,16,17, |
423 | 418 | 11,10,10,11,12,12,12,12,13,13,13,14,15,15,15,16, | |
424 | static const uint8_t t16l_const[256] = | 419 | 11,11,11,12,12,13,12,13,14,14,15,15,15,16,16,16, |
425 | {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, | 420 | 12,11,12,13,13,13,14,14,14,14,14,15,16,15,16,16, |
426 | 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, | 421 | 13,12,12,13,13,13,15,14,14,17,15,15,15,17,16,16, |
427 | 13,13,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, | 422 | 12,12,13,14,14,14,15,14,15,15,16,16,19,18,19,16 }; |
428 | 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, | 423 | |
429 | 11,11,12,12,13,13,13,13,15,15,10,10,10,10,11,11,11,12,12,13,13,13,13,14,14,14, | 424 | static const uint8_t t15l[256] ICONST_ATTR = |
430 | 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, | 425 | { 3, 4, 5, 7, 7, 8, 9, 9, 9,10,10,11,11,11,12,13, |
431 | 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,12, | 426 | 4, 3, 5, 6, 7, 7, 8, 8, 8, 9, 9,10,10,10,11,11, |
432 | 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, | 427 | 5, 5, 5, 6, 7, 7, 8, 8, 8, 9, 9,10,10,11,11,11, |
433 | 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, | 428 | 6, 6, 6, 7, 7, 8, 8, 9, 9, 9,10,10,10,11,11,11, |
434 | 11,11,11,11,11,11,11,8}; | 429 | 7, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,11,11, |
435 | 430 | 8, 7, 7, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,11,12, | |
436 | static const uint8_t t24l_const[256] = | 431 | 9, 7, 8, 8, 8, 9, 9, 9, 9,10,10,10,11,11,12,12, |
437 | {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, | 432 | 9, 8, 8, 9, 9, 9, 9,10,10,10,10,10,11,11,11,12, |
438 | 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, | 433 | 9, 8, 8, 9, 9, 9, 9,10,10,10,10,11,11,12,12,12, |
439 | 8,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, | 434 | 9, 8, 9, 9, 9, 9,10,10,10,11,11,11,11,12,12,12, |
440 | 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, | 435 | 10, 9, 9, 9,10,10,10,10,10,11,11,11,11,12,13,12, |
441 | 9,9,9,9,9,10,10,10,10,11,11,8,10,9,9,9,9,9,9,10,10,10,10,10,11,11,11,8,11,9,9, | 436 | 10, 9, 9, 9,10,10,10,10,11,11,11,11,12,12,12,13, |
442 | 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, | 437 | 11,10, 9,10,10,10,11,11,11,11,11,11,12,12,13,13, |
443 | 8,11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,8,11,10,10,10,10,10,10,10,11, | 438 | 11,10,10,10,10,11,11,11,11,12,12,12,12,12,13,13, |
444 | 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, | 439 | 12,11,11,11,11,11,11,11,12,12,12,12,13,13,12,13, |
445 | 7,7,7,7,7,7,8,8,8,8,4}; | 440 | 12,11,11,11,11,11,11,12,12,12,12,12,13,13,13,13 }; |
446 | 441 | ||
447 | static const struct huffcodetab ht_const[HTN] = | 442 | static const uint8_t t16l[256] ICONST_ATTR = |
448 | { { 0, NULL, NULL}, /* Apparently not used */ | 443 | { 1, 4, 6, 8, 9, 9,10,10,11,11,11,12,12,12,13, 9, |
449 | { 2, t1HB, t1l}, | 444 | 3, 4, 6, 7, 8, 9, 9, 9,10,10,10,11,12,11,12, 8, |
450 | { 3, t2HB, t2l}, | 445 | 6, 6, 7, 8, 9, 9,10,10,11,10,11,11,11,12,12, 9, |
451 | { 3, t3HB, t3l}, | 446 | 8, 7, 8, 9, 9,10,10,10,11,11,12,12,12,13,13,10, |
452 | { 0, NULL, NULL}, /* Apparently not used */ | 447 | 9, 8, 9, 9,10,10,11,11,11,12,12,12,13,13,13, 9, |
453 | { 4, t5HB, t5l}, | 448 | 9, 8, 9, 9,10,11,11,12,11,12,12,13,13,13,14,10, |
454 | { 4, t6HB, t6l}, | 449 | 10, 9, 9,10,11,11,11,11,12,12,12,12,13,13,14,10, |
455 | { 6, t7HB, t7l}, | 450 | 10, 9,10,10,11,11,11,12,12,13,13,13,13,15,15,10, |
456 | { 6, t8HB, t8l}, | 451 | 10,10,10,11,11,11,12,12,13,13,13,13,14,14,14,10, |
457 | { 6, t9HB, t9l}, | 452 | 11,10,10,11,11,12,12,13,13,13,13,14,13,14,13,11, |
458 | { 8, t10HB, t10l}, | 453 | 11,11,10,11,12,12,12,12,13,14,14,14,15,15,14,10, |
459 | { 8, t11HB, t11l}, | 454 | 12,11,11,11,12,12,13,14,14,14,14,14,14,13,14,11, |
460 | { 8, t12HB, t12l}, | 455 | 12,12,12,12,12,13,13,13,13,15,14,14,14,14,16,11, |
461 | {16, t13HB, t13l}, | 456 | 14,12,12,12,13,13,14,14,14,16,15,15,15,17,15,11, |
462 | { 0, NULL, NULL}, /* Apparently not used */ | 457 | 13,13,11,12,14,14,13,14,14,15,16,15,17,15,14,11, |
463 | {16, t15HB, t15l} }; | 458 | 9, 8, 8, 9, 9,10,10,10,11,11,11,11,11,11,11, 8 }; |
464 | 459 | ||
465 | static const struct huffcodebig ht_big[HTN] = | 460 | static const uint8_t t24l[256] ICONST_ATTR = |
461 | { 4, 4, 6, 7, 8, 9, 9,10,10,11,11,11,11,11,12, 9, | ||
462 | 4, 4, 5, 6, 7, 8, 8, 9, 9, 9,10,10,10,10,10, 8, | ||
463 | 6, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11, 7, | ||
464 | 7, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9,10,10,10,10, 7, | ||
465 | 8, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,10,10,11, 7, | ||
466 | 9, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10, 7, | ||
467 | 9, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,11, 7, | ||
468 | 10, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, | ||
469 | 10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11, 8, | ||
470 | 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11,11, 8, | ||
471 | 11, 9, 9, 9, 9,10,10,10,10,10,10,11,11,11,11, 8, | ||
472 | 11,10, 9, 9, 9,10,10,10,10,10,10,11,11,11,11, 8, | ||
473 | 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11, 8, | ||
474 | 11,10,10,10,10,10,10,10,11,11,11,11,11,11,11, 8, | ||
475 | 12,10,10,10,10,10,10,11,11,11,11,11,11,11,11, 8, | ||
476 | 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 4 }; | ||
477 | |||
478 | static const struct huffcodetab ht[16] ICONST_ATTR = | ||
479 | { { 0, NULL, NULL }, /* Apparently not used */ | ||
480 | { 2, t1HB, t1l }, | ||
481 | { 3, t2HB, t2l }, | ||
482 | { 3, t3HB, t3l }, | ||
483 | { 0, NULL, NULL }, /* Apparently not used */ | ||
484 | { 4, t5HB, t5l }, | ||
485 | { 4, t6HB, t6l }, | ||
486 | { 6, t7HB, t7l }, | ||
487 | { 6, t8HB, t8l }, | ||
488 | { 6, t9HB, t9l }, | ||
489 | { 8, t10HB, t10l }, | ||
490 | { 8, t11HB, t11l }, | ||
491 | { 8, t12HB, t12l }, | ||
492 | { 16, t13HB, t13l }, | ||
493 | { 0, NULL, NULL }, /* Apparently not used */ | ||
494 | { 16, t15HB, t15l } }; | ||
495 | |||
496 | static const struct huffcodebig ht_big[16] ICONST_ATTR = | ||
466 | { { 16, 1, 1 }, | 497 | { { 16, 1, 1 }, |
467 | { 16, 2, 3 }, | 498 | { 16, 2, 3 }, |
468 | { 16, 3, 7 }, | 499 | { 16, 3, 7 }, |
@@ -484,335 +515,365 @@ static const struct | |||
484 | { | 515 | { |
485 | uint32_t region0_cnt; | 516 | uint32_t region0_cnt; |
486 | uint32_t region1_cnt; | 517 | uint32_t region1_cnt; |
487 | } subdv_table[23] = | 518 | } subdv_table[23] ICONST_ATTR = |
488 | { {0, 0}, /* 0 bands */ | 519 | { { 0, 0 }, /* 0 bands */ |
489 | {0, 0}, /* 1 bands */ | 520 | { 0, 0 }, /* 1 bands */ |
490 | {0, 0}, /* 2 bands */ | 521 | { 0, 0 }, /* 2 bands */ |
491 | {0, 0}, /* 3 bands */ | 522 | { 0, 0 }, /* 3 bands */ |
492 | {0, 0}, /* 4 bands */ | 523 | { 0, 0 }, /* 4 bands */ |
493 | {0, 1}, /* 5 bands */ | 524 | { 0, 1 }, /* 5 bands */ |
494 | {1, 1}, /* 6 bands */ | 525 | { 1, 1 }, /* 6 bands */ |
495 | {1, 1}, /* 7 bands */ | 526 | { 1, 1 }, /* 7 bands */ |
496 | {1, 2}, /* 8 bands */ | 527 | { 1, 2 }, /* 8 bands */ |
497 | {2, 2}, /* 9 bands */ | 528 | { 2, 2 }, /* 9 bands */ |
498 | {2, 3}, /* 10 bands */ | 529 | { 2, 3 }, /* 10 bands */ |
499 | {2, 3}, /* 11 bands */ | 530 | { 2, 3 }, /* 11 bands */ |
500 | {3, 4}, /* 12 bands */ | 531 | { 3, 4 }, /* 12 bands */ |
501 | {3, 4}, /* 13 bands */ | 532 | { 3, 4 }, /* 13 bands */ |
502 | {3, 4}, /* 14 bands */ | 533 | { 3, 4 }, /* 14 bands */ |
503 | {4, 5}, /* 15 bands */ | 534 | { 4, 5 }, /* 15 bands */ |
504 | {4, 5}, /* 16 bands */ | 535 | { 4, 5 }, /* 16 bands */ |
505 | {4, 6}, /* 17 bands */ | 536 | { 4, 6 }, /* 17 bands */ |
506 | {5, 6}, /* 18 bands */ | 537 | { 5, 6 }, /* 18 bands */ |
507 | {5, 6}, /* 19 bands */ | 538 | { 5, 6 }, /* 19 bands */ |
508 | {5, 7}, /* 20 bands */ | 539 | { 5, 7 }, /* 20 bands */ |
509 | {6, 7}, /* 21 bands */ | 540 | { 6, 7 }, /* 21 bands */ |
510 | {6, 7}, /* 22 bands */ | 541 | { 6, 7 }, /* 22 bands */ |
511 | }; | 542 | }; |
512 | 543 | ||
513 | static const uint32_t sfBand[6][23] = | 544 | /* Not ICONST: Appropriate table copied to scalefac */ |
545 | static const uint32_t sf_band[6][22] = | ||
514 | { | 546 | { |
515 | /* Table B.2.b: 22.05 kHz */ | 547 | /* Table B.2.b: 22.05 kHz */ |
516 | {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, | 548 | { 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, |
549 | 116,140,168,200,238,284,336,396,464,522,576 }, | ||
517 | /* Table B.2.c: 24 kHz */ | 550 | /* Table B.2.c: 24 kHz */ |
518 | {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576}, | 551 | { 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, |
552 | 114,136,162,194,232,278,330,394,464,540,576 }, | ||
519 | /* Table B.2.a: 16 kHz */ | 553 | /* Table B.2.a: 16 kHz */ |
520 | {0,6,12,18,24,30,36,44,45,66,80,96,116,140,168,200,238,248,336,396,464,522,576}, | 554 | { 6, 12, 18, 24, 30, 36, 44, 45, 66, 80, 96, |
555 | 116,140,168,200,238,248,336,396,464,522,576 }, | ||
521 | /* Table B.8.b: 44.1 kHz */ | 556 | /* Table B.8.b: 44.1 kHz */ |
522 | {0,4, 8,12,16,20,24,30,36,44,52,62, 74, 90,110,134,162,196,238,288,342,418,576}, | 557 | { 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, |
558 | 74, 90,110,134,162,196,238,288,342,418,576 }, | ||
523 | /* Table B.8.c: 48 kHz */ | 559 | /* Table B.8.c: 48 kHz */ |
524 | {0,4, 8,12,16,20,24,30,36,42,50,60, 72, 88,106,128,156,190,230,276,330,384,576}, | 560 | { 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, |
561 | 72, 88,106,128,156,190,230,276,330,384,576 }, | ||
525 | /* Table B.8.a: 32 kHz */ | 562 | /* Table B.8.a: 32 kHz */ |
526 | {0,4, 8,12,16,20,24,30,36,44,54,66, 82,102,126,156,194,240,296,364,448,550,576} }; | 563 | { 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, |
527 | 564 | 82,102,126,156,194,240,296,364,448,550,576 } }; | |
528 | 565 | ||
529 | static const short int2idx_const[4096] = /* int2idx[i] = sqrt(i*sqrt(i)); */ | 566 | /* int2idx[i] = sqrt(i*sqrt(i)); */ |
530 | { | 567 | static const short int2idx[4096] ICONST_ATTR = |
531 | 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, | 568 | { 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, |
532 | 9, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, | 569 | 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, |
533 | 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, | 570 | 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, |
534 | 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26, | 571 | 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 22, 22, 22, 22, |
535 | 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, | 572 | 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26, |
536 | 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 34, 35, 35, 35, 35, 36, 36, 36, | 573 | 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, |
537 | 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 38, 39, 39, 39, 39, 40, 40, 40, 40, 40, | 574 | 31, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, |
538 | 41, 41, 41, 41, 42, 42, 42, 42, 42, 43, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45, | 575 | 34, 35, 35, 35, 35, 36, 36, 36, 36, 36, 37, 37, 37, 37, 38, 38, |
539 | 45, 45, 45, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 48, 48, 48, 48, 49, 49, 49, | 576 | 38, 38, 38, 39, 39, 39, 39, 40, 40, 40, 40, 40, 41, 41, 41, 41, |
540 | 49, 49, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53, | 577 | 42, 42, 42, 42, 42, 43, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45, |
541 | 53, 53, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 56, 56, 56, 56, 56, 57, 57, 57, | 578 | 45, 45, 45, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 48, 48, 48, |
542 | 57, 57, 58, 58, 58, 58, 58, 58, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 61, 61, | 579 | 48, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, |
543 | 61, 61, 61, 62, 62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 65, | 580 | 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 55, |
544 | 65, 65, 65, 65, 65, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68, | 581 | 55, 55, 55, 55, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 58, 58, |
545 | 68, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 72, 72, 72, | 582 | 58, 58, 58, 58, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 61, 61, |
546 | 72, 72, 72, 73, 73, 73, 73, 73, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, | 583 | 61, 61, 61, 62, 62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 64, 64, |
547 | 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 79, 79, 79, | 584 | 64, 64, 64, 65, 65, 65, 65, 65, 65, 66, 66, 66, 66, 66, 67, 67, |
548 | 79, 79, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, | 585 | 67, 67, 67, 68, 68, 68, 68, 68, 68, 69, 69, 69, 69, 69, 70, 70, |
549 | 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 86, 86, 86, | 586 | 70, 70, 70, 70, 71, 71, 71, 71, 71, 72, 72, 72, 72, 72, 72, 73, |
550 | 86, 86, 86, 87, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 89, 89, 89, 89, 89, | 587 | 73, 73, 73, 73, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, |
551 | 89, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 93, | 588 | 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, |
552 | 93, 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95, 95, 95, 96, 96, 96, | 589 | 78, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, |
553 | 96, 96, 96, 97, 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 98, 99, 99, 99, 99, 99, | 590 | 81, 81, 82, 82, 82, 82, 82, 82, 83, 83, 83, 83, 83, 84, 84, 84, |
554 | 99, 99,100,100,100,100,100,100,101,101,101,101,101,101,102,102,102,102,102,102, | 591 | 84, 84, 84, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, 87, |
555 | 103,103,103,103,103,103,104,104,104,104,104,104,104,105,105,105,105,105,105,106, | 592 | 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 89, 89, 89, 89, 89, |
556 | 106,106,106,106,106,107,107,107,107,107,107,107,108,108,108,108,108,108,109,109, | 593 | 89, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, 91, 92, 92, 92, |
557 | 109,109,109,109,110,110,110,110,110,110,110,111,111,111,111,111,111,112,112,112, | 594 | 92, 92, 92, 93, 93, 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 95, |
558 | 112,112,112,112,113,113,113,113,113,113,114,114,114,114,114,114,115,115,115,115, | 595 | 95, 95, 95, 95, 95, 96, 96, 96, 96, 96, 96, 97, 97, 97, 97, 97, |
559 | 115,115,115,116,116,116,116,116,116,117,117,117,117,117,117,117,118,118,118,118, | 596 | 97, 98, 98, 98, 98, 98, 98, 99, 99, 99, 99, 99, 99, 99,100,100, |
560 | 118,118,118,119,119,119,119,119,119,120,120,120,120,120,120,120,121,121,121,121, | 597 | 100,100,100,100,101,101,101,101,101,101,102,102,102,102,102,102, |
561 | 121,121,122,122,122,122,122,122,122,123,123,123,123,123,123,123,124,124,124,124, | 598 | 103,103,103,103,103,103,104,104,104,104,104,104,104,105,105,105, |
562 | 124,124,125,125,125,125,125,125,125,126,126,126,126,126,126,126,127,127,127,127, | 599 | 105,105,105,106,106,106,106,106,106,107,107,107,107,107,107,107, |
563 | 127,127,128,128,128,128,128,128,128,129,129,129,129,129,129,129,130,130,130,130, | 600 | 108,108,108,108,108,108,109,109,109,109,109,109,110,110,110,110, |
564 | 130,130,131,131,131,131,131,131,131,132,132,132,132,132,132,132,133,133,133,133, | 601 | 110,110,110,111,111,111,111,111,111,112,112,112,112,112,112,112, |
565 | 133,133,133,134,134,134,134,134,134,134,135,135,135,135,135,135,136,136,136,136, | 602 | 113,113,113,113,113,113,114,114,114,114,114,114,115,115,115,115, |
566 | 136,136,136,137,137,137,137,137,137,137,138,138,138,138,138,138,138,139,139,139, | 603 | 115,115,115,116,116,116,116,116,116,117,117,117,117,117,117,117, |
567 | 139,139,139,139,140,140,140,140,140,140,140,141,141,141,141,141,141,141,142,142, | 604 | 118,118,118,118,118,118,118,119,119,119,119,119,119,120,120,120, |
568 | 142,142,142,142,142,143,143,143,143,143,143,143,144,144,144,144,144,144,144,145, | 605 | 120,120,120,120,121,121,121,121,121,121,122,122,122,122,122,122, |
569 | 145,145,145,145,145,145,146,146,146,146,146,146,146,147,147,147,147,147,147,147, | 606 | 122,123,123,123,123,123,123,123,124,124,124,124,124,124,125,125, |
570 | 148,148,148,148,148,148,148,149,149,149,149,149,149,149,150,150,150,150,150,150, | 607 | 125,125,125,125,125,126,126,126,126,126,126,126,127,127,127,127, |
571 | 150,151,151,151,151,151,151,151,152,152,152,152,152,152,152,153,153,153,153,153, | 608 | 127,127,128,128,128,128,128,128,128,129,129,129,129,129,129,129, |
572 | 153,153,154,154,154,154,154,154,154,154,155,155,155,155,155,155,155,156,156,156, | 609 | 130,130,130,130,130,130,131,131,131,131,131,131,131,132,132,132, |
573 | 156,156,156,156,157,157,157,157,157,157,157,158,158,158,158,158,158,158,159,159, | 610 | 132,132,132,132,133,133,133,133,133,133,133,134,134,134,134,134, |
574 | 159,159,159,159,159,160,160,160,160,160,160,160,160,161,161,161,161,161,161,161, | 611 | 134,134,135,135,135,135,135,135,136,136,136,136,136,136,136,137, |
575 | 162,162,162,162,162,162,162,163,163,163,163,163,163,163,163,164,164,164,164,164, | 612 | 137,137,137,137,137,137,138,138,138,138,138,138,138,139,139,139, |
576 | 164,164,165,165,165,165,165,165,165,166,166,166,166,166,166,166,167,167,167,167, | 613 | 139,139,139,139,140,140,140,140,140,140,140,141,141,141,141,141, |
577 | 167,167,167,167,168,168,168,168,168,168,168,169,169,169,169,169,169,169,169,170, | 614 | 141,141,142,142,142,142,142,142,142,143,143,143,143,143,143,143, |
578 | 170,170,170,170,170,170,171,171,171,171,171,171,171,172,172,172,172,172,172,172, | 615 | 144,144,144,144,144,144,144,145,145,145,145,145,145,145,146,146, |
579 | 172,173,173,173,173,173,173,173,174,174,174,174,174,174,174,174,175,175,175,175, | 616 | 146,146,146,146,146,147,147,147,147,147,147,147,148,148,148,148, |
580 | 175,175,175,176,176,176,176,176,176,176,176,177,177,177,177,177,177,177,178,178, | 617 | 148,148,148,149,149,149,149,149,149,149,150,150,150,150,150,150, |
581 | 178,178,178,178,178,178,179,179,179,179,179,179,179,180,180,180,180,180,180,180, | 618 | 150,151,151,151,151,151,151,151,152,152,152,152,152,152,152,153, |
582 | 180,181,181,181,181,181,181,181,182,182,182,182,182,182,182,182,183,183,183,183, | 619 | 153,153,153,153,153,153,154,154,154,154,154,154,154,154,155,155, |
583 | 183,183,183,184,184,184,184,184,184,184,184,185,185,185,185,185,185,185,186,186, | 620 | 155,155,155,155,155,156,156,156,156,156,156,156,157,157,157,157, |
584 | 186,186,186,186,186,186,187,187,187,187,187,187,187,187,188,188,188,188,188,188, | 621 | 157,157,157,158,158,158,158,158,158,158,159,159,159,159,159,159, |
585 | 188,189,189,189,189,189,189,189,189,190,190,190,190,190,190,190,190,191,191,191, | 622 | 159,160,160,160,160,160,160,160,160,161,161,161,161,161,161,161, |
586 | 191,191,191,191,192,192,192,192,192,192,192,192,193,193,193,193,193,193,193,193, | 623 | 162,162,162,162,162,162,162,163,163,163,163,163,163,163,163,164, |
587 | 194,194,194,194,194,194,194,195,195,195,195,195,195,195,195,196,196,196,196,196, | 624 | 164,164,164,164,164,164,165,165,165,165,165,165,165,166,166,166, |
588 | 196,196,196,197,197,197,197,197,197,197,197,198,198,198,198,198,198,198,199,199, | 625 | 166,166,166,166,167,167,167,167,167,167,167,167,168,168,168,168, |
589 | 199,199,199,199,199,199,200,200,200,200,200,200,200,200,201,201,201,201,201,201, | 626 | 168,168,168,169,169,169,169,169,169,169,169,170,170,170,170,170, |
590 | 201,201,202,202,202,202,202,202,202,202,203,203,203,203,203,203,203,204,204,204, | 627 | 170,170,171,171,171,171,171,171,171,172,172,172,172,172,172,172, |
591 | 204,204,204,204,204,205,205,205,205,205,205,205,205,206,206,206,206,206,206,206, | 628 | 172,173,173,173,173,173,173,173,174,174,174,174,174,174,174,174, |
592 | 206,207,207,207,207,207,207,207,207,208,208,208,208,208,208,208,208,209,209,209, | 629 | 175,175,175,175,175,175,175,176,176,176,176,176,176,176,176,177, |
593 | 209,209,209,209,209,210,210,210,210,210,210,210,210,211,211,211,211,211,211,211, | 630 | 177,177,177,177,177,177,178,178,178,178,178,178,178,178,179,179, |
594 | 211,212,212,212,212,212,212,212,212,213,213,213,213,213,213,213,213,214,214,214, | 631 | 179,179,179,179,179,180,180,180,180,180,180,180,180,181,181,181, |
595 | 214,214,214,214,214,215,215,215,215,215,215,215,215,216,216,216,216,216,216,216, | 632 | 181,181,181,181,182,182,182,182,182,182,182,182,183,183,183,183, |
596 | 216,217,217,217,217,217,217,217,217,218,218,218,218,218,218,218,218,219,219,219, | 633 | 183,183,183,184,184,184,184,184,184,184,184,185,185,185,185,185, |
597 | 219,219,219,219,219,220,220,220,220,220,220,220,220,221,221,221,221,221,221,221, | 634 | 185,185,186,186,186,186,186,186,186,186,187,187,187,187,187,187, |
598 | 221,222,222,222,222,222,222,222,222,223,223,223,223,223,223,223,223,224,224,224, | 635 | 187,187,188,188,188,188,188,188,188,189,189,189,189,189,189,189, |
599 | 224,224,224,224,224,225,225,225,225,225,225,225,225,226,226,226,226,226,226,226, | 636 | 189,190,190,190,190,190,190,190,190,191,191,191,191,191,191,191, |
600 | 226,227,227,227,227,227,227,227,227,228,228,228,228,228,228,228,228,229,229,229, | 637 | 192,192,192,192,192,192,192,192,193,193,193,193,193,193,193,193, |
601 | 229,229,229,229,229,229,230,230,230,230,230,230,230,230,231,231,231,231,231,231, | 638 | 194,194,194,194,194,194,194,195,195,195,195,195,195,195,195,196, |
602 | 231,231,232,232,232,232,232,232,232,232,233,233,233,233,233,233,233,233,234,234, | 639 | 196,196,196,196,196,196,196,197,197,197,197,197,197,197,197,198, |
603 | 234,234,234,234,234,234,234,235,235,235,235,235,235,235,235,236,236,236,236,236, | 640 | 198,198,198,198,198,198,199,199,199,199,199,199,199,199,200,200, |
604 | 236,236,236,237,237,237,237,237,237,237,237,238,238,238,238,238,238,238,238,238, | 641 | 200,200,200,200,200,200,201,201,201,201,201,201,201,201,202,202, |
605 | 239,239,239,239,239,239,239,239,240,240,240,240,240,240,240,240,241,241,241,241, | 642 | 202,202,202,202,202,202,203,203,203,203,203,203,203,204,204,204, |
606 | 241,241,241,241,242,242,242,242,242,242,242,242,242,243,243,243,243,243,243,243, | 643 | 204,204,204,204,204,205,205,205,205,205,205,205,205,206,206,206, |
607 | 243,244,244,244,244,244,244,244,244,245,245,245,245,245,245,245,245,245,246,246, | 644 | 206,206,206,206,206,207,207,207,207,207,207,207,207,208,208,208, |
608 | 246,246,246,246,246,246,247,247,247,247,247,247,247,247,248,248,248,248,248,248, | 645 | 208,208,208,208,208,209,209,209,209,209,209,209,209,210,210,210, |
609 | 248,248,248,249,249,249,249,249,249,249,249,250,250,250,250,250,250,250,250,250, | 646 | 210,210,210,210,210,211,211,211,211,211,211,211,211,212,212,212, |
610 | 251,251,251,251,251,251,251,251,252,252,252,252,252,252,252,252,253,253,253,253, | 647 | 212,212,212,212,212,213,213,213,213,213,213,213,213,214,214,214, |
611 | 253,253,253,253,253,254,254,254,254,254,254,254,254,255,255,255,255,255,255,255, | 648 | 214,214,214,214,214,215,215,215,215,215,215,215,215,216,216,216, |
612 | 255,255,256,256,256,256,256,256,256,256,257,257,257,257,257,257,257,257,257,258, | 649 | 216,216,216,216,216,217,217,217,217,217,217,217,217,218,218,218, |
613 | 258,258,258,258,258,258,258,259,259,259,259,259,259,259,259,259,260,260,260,260, | 650 | 218,218,218,218,218,219,219,219,219,219,219,219,219,220,220,220, |
614 | 260,260,260,260,261,261,261,261,261,261,261,261,261,262,262,262,262,262,262,262, | 651 | 220,220,220,220,220,221,221,221,221,221,221,221,221,222,222,222, |
615 | 262,263,263,263,263,263,263,263,263,263,264,264,264,264,264,264,264,264,265,265, | 652 | 222,222,222,222,222,223,223,223,223,223,223,223,223,224,224,224, |
616 | 265,265,265,265,265,265,265,266,266,266,266,266,266,266,266,267,267,267,267,267, | 653 | 224,224,224,224,224,225,225,225,225,225,225,225,225,226,226,226, |
617 | 267,267,267,267,268,268,268,268,268,268,268,268,268,269,269,269,269,269,269,269, | 654 | 226,226,226,226,226,227,227,227,227,227,227,227,227,228,228,228, |
618 | 269,270,270,270,270,270,270,270,270,270,271,271,271,271,271,271,271,271,271,272, | 655 | 228,228,228,228,228,229,229,229,229,229,229,229,229,229,230,230, |
619 | 272,272,272,272,272,272,272,273,273,273,273,273,273,273,273,273,274,274,274,274, | 656 | 230,230,230,230,230,230,231,231,231,231,231,231,231,231,232,232, |
620 | 274,274,274,274,275,275,275,275,275,275,275,275,275,276,276,276,276,276,276,276, | 657 | 232,232,232,232,232,232,233,233,233,233,233,233,233,233,234,234, |
621 | 276,276,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,279, | 658 | 234,234,234,234,234,234,234,235,235,235,235,235,235,235,235,236, |
622 | 279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,281,281,281, | 659 | 236,236,236,236,236,236,236,237,237,237,237,237,237,237,237,238, |
623 | 281,281,281,281,281,282,282,282,282,282,282,282,282,282,283,283,283,283,283,283, | 660 | 238,238,238,238,238,238,238,238,239,239,239,239,239,239,239,239, |
624 | 283,283,283,284,284,284,284,284,284,284,284,284,285,285,285,285,285,285,285,285, | 661 | 240,240,240,240,240,240,240,240,241,241,241,241,241,241,241,241, |
625 | 286,286,286,286,286,286,286,286,286,287,287,287,287,287,287,287,287,287,288,288, | 662 | 242,242,242,242,242,242,242,242,242,243,243,243,243,243,243,243, |
626 | 288,288,288,288,288,288,288,289,289,289,289,289,289,289,289,289,290,290,290,290, | 663 | 243,244,244,244,244,244,244,244,244,245,245,245,245,245,245,245, |
627 | 290,290,290,290,291,291,291,291,291,291,291,291,291,292,292,292,292,292,292,292, | 664 | 245,245,246,246,246,246,246,246,246,246,247,247,247,247,247,247, |
628 | 292,292,293,293,293,293,293,293,293,293,293,294,294,294,294,294,294,294,294,294, | 665 | 247,247,248,248,248,248,248,248,248,248,248,249,249,249,249,249, |
629 | 295,295,295,295,295,295,295,295,295,296,296,296,296,296,296,296,296,296,297,297, | 666 | 249,249,249,250,250,250,250,250,250,250,250,250,251,251,251,251, |
630 | 297,297,297,297,297,297,297,298,298,298,298,298,298,298,298,299,299,299,299,299, | 667 | 251,251,251,251,252,252,252,252,252,252,252,252,253,253,253,253, |
631 | 299,299,299,299,300,300,300,300,300,300,300,300,300,301,301,301,301,301,301,301, | 668 | 253,253,253,253,253,254,254,254,254,254,254,254,254,255,255,255, |
632 | 301,301,302,302,302,302,302,302,302,302,302,303,303,303,303,303,303,303,303,303, | 669 | 255,255,255,255,255,255,256,256,256,256,256,256,256,256,257,257, |
633 | 304,304,304,304,304,304,304,304,304,305,305,305,305,305,305,305,305,305,306,306, | 670 | 257,257,257,257,257,257,257,258,258,258,258,258,258,258,258,259, |
634 | 306,306,306,306,306,306,306,307,307,307,307,307,307,307,307,307,308,308,308,308, | 671 | 259,259,259,259,259,259,259,259,260,260,260,260,260,260,260,260, |
635 | 308,308,308,308,308,309,309,309,309,309,309,309,309,309,310,310,310,310,310,310, | 672 | 261,261,261,261,261,261,261,261,261,262,262,262,262,262,262,262, |
636 | 310,310,310,311,311,311,311,311,311,311,311,311,312,312,312,312,312,312,312,312, | 673 | 262,263,263,263,263,263,263,263,263,263,264,264,264,264,264,264, |
637 | 312,313,313,313,313,313,313,313,313,313,314,314,314,314,314,314,314,314,314,315, | 674 | 264,264,265,265,265,265,265,265,265,265,265,266,266,266,266,266, |
638 | 315,315,315,315,315,315,315,315,316,316,316,316,316,316,316,316,316,317,317,317, | 675 | 266,266,266,267,267,267,267,267,267,267,267,267,268,268,268,268, |
639 | 317,317,317,317,317,317,318,318,318,318,318,318,318,318,318,318,319,319,319,319, | 676 | 268,268,268,268,268,269,269,269,269,269,269,269,269,270,270,270, |
640 | 319,319,319,319,319,320,320,320,320,320,320,320,320,320,321,321,321,321,321,321, | 677 | 270,270,270,270,270,270,271,271,271,271,271,271,271,271,271,272, |
641 | 321,321,321,322,322,322,322,322,322,322,322,322,323,323,323,323,323,323,323,323, | 678 | 272,272,272,272,272,272,272,273,273,273,273,273,273,273,273,273, |
642 | 323,324,324,324,324,324,324,324,324,324,325,325,325,325,325,325,325,325,325,325, | 679 | 274,274,274,274,274,274,274,274,275,275,275,275,275,275,275,275, |
643 | 326,326,326,326,326,326,326,326,326,327,327,327,327,327,327,327,327,327,328,328, | 680 | 275,276,276,276,276,276,276,276,276,276,277,277,277,277,277,277, |
644 | 328,328,328,328,328,328,328,329,329,329,329,329,329,329,329,329,330,330,330,330, | 681 | 277,277,277,278,278,278,278,278,278,278,278,279,279,279,279,279, |
645 | 330,330,330,330,330,330,331,331,331,331,331,331,331,331,331,332,332,332,332,332, | 682 | 279,279,279,279,280,280,280,280,280,280,280,280,280,281,281,281, |
646 | 332,332,332,332,333,333,333,333,333,333,333,333,333,334,334,334,334,334,334,334, | 683 | 281,281,281,281,281,282,282,282,282,282,282,282,282,282,283,283, |
647 | 334,334,335,335,335,335,335,335,335,335,335,335,336,336,336,336,336,336,336,336, | 684 | 283,283,283,283,283,283,283,284,284,284,284,284,284,284,284,284, |
648 | 336,337,337,337,337,337,337,337,337,337,338,338,338,338,338,338,338,338,338,338, | 685 | 285,285,285,285,285,285,285,285,286,286,286,286,286,286,286,286, |
649 | 339,339,339,339,339,339,339,339,339,340,340,340,340,340,340,340,340,340,341,341, | 686 | 286,287,287,287,287,287,287,287,287,287,288,288,288,288,288,288, |
650 | 341,341,341,341,341,341,341,341,342,342,342,342,342,342,342,342,342,343,343,343, | 687 | 288,288,288,289,289,289,289,289,289,289,289,289,290,290,290,290, |
651 | 343,343,343,343,343,343,344,344,344,344,344,344,344,344,344,344,345,345,345,345, | 688 | 290,290,290,290,291,291,291,291,291,291,291,291,291,292,292,292, |
652 | 345,345,345,345,345,346,346,346,346,346,346,346,346,346,347,347,347,347,347,347, | 689 | 292,292,292,292,292,292,293,293,293,293,293,293,293,293,293,294, |
653 | 347,347,347,347,348,348,348,348,348,348,348,348,348,349,349,349,349,349,349,349, | 690 | 294,294,294,294,294,294,294,294,295,295,295,295,295,295,295,295, |
654 | 349,349,350,350,350,350,350,350,350,350,350,350,351,351,351,351,351,351,351,351, | 691 | 295,296,296,296,296,296,296,296,296,296,297,297,297,297,297,297, |
655 | 351,352,352,352,352,352,352,352,352,352,352,353,353,353,353,353,353,353,353,353, | 692 | 297,297,297,298,298,298,298,298,298,298,298,299,299,299,299,299, |
656 | 354,354,354,354,354,354,354,354,354,355,355,355,355,355,355,355,355,355,355,356, | 693 | 299,299,299,299,300,300,300,300,300,300,300,300,300,301,301,301, |
657 | 356,356,356,356,356,356,356,356,357,357,357,357,357,357,357,357,357,357,358,358, | 694 | 301,301,301,301,301,301,302,302,302,302,302,302,302,302,302,303, |
658 | 358,358,358,358,358,358,358,359,359,359,359,359,359,359,359,359,359,360,360,360, | 695 | 303,303,303,303,303,303,303,303,304,304,304,304,304,304,304,304, |
659 | 360,360,360,360,360,360,361,361,361,361,361,361,361,361,361,361,362,362,362,362, | 696 | 304,305,305,305,305,305,305,305,305,305,306,306,306,306,306,306, |
660 | 362,362,362,362,362,363,363,363,363,363,363,363,363,363,363,364,364,364,364,364, | 697 | 306,306,306,307,307,307,307,307,307,307,307,307,308,308,308,308, |
661 | 364,364,364,364,365,365,365,365,365,365,365,365,365,365,366,366,366,366,366,366, | 698 | 308,308,308,308,308,309,309,309,309,309,309,309,309,309,310,310, |
662 | 366,366,366,367,367,367,367,367,367,367,367,367,367,368,368,368,368,368,368,368, | 699 | 310,310,310,310,310,310,310,311,311,311,311,311,311,311,311,311, |
663 | 368,368,369,369,369,369,369,369,369,369,369,369,370,370,370,370,370,370,370,370, | 700 | 312,312,312,312,312,312,312,312,312,313,313,313,313,313,313,313, |
664 | 370,370,371,371,371,371,371,371,371,371,371,372,372,372,372,372,372,372,372,372, | 701 | 313,313,314,314,314,314,314,314,314,314,314,315,315,315,315,315, |
665 | 372,373,373,373,373,373,373,373,373,373,374,374,374,374,374,374,374,374,374,374, | 702 | 315,315,315,315,316,316,316,316,316,316,316,316,316,317,317,317, |
666 | 375,375,375,375,375,375,375,375,375,375,376,376,376,376,376,376,376,376,376,377, | 703 | 317,317,317,317,317,317,318,318,318,318,318,318,318,318,318,318, |
667 | 377,377,377,377,377,377,377,377,377,378,378,378,378,378,378,378,378,378,379,379, | 704 | 319,319,319,319,319,319,319,319,319,320,320,320,320,320,320,320, |
668 | 379,379,379,379,379,379,379,379,380,380,380,380,380,380,380,380,380,380,381,381, | 705 | 320,320,321,321,321,321,321,321,321,321,321,322,322,322,322,322, |
669 | 381,381,381,381,381,381,381,382,382,382,382,382,382,382,382,382,382,383,383,383, | 706 | 322,322,322,322,323,323,323,323,323,323,323,323,323,324,324,324, |
670 | 383,383,383,383,383,383,383,384,384,384,384,384,384,384,384,384,385,385,385,385, | 707 | 324,324,324,324,324,324,325,325,325,325,325,325,325,325,325,325, |
671 | 385,385,385,385,385,385,386,386,386,386,386,386,386,386,386,386,387,387,387,387, | 708 | 326,326,326,326,326,326,326,326,326,327,327,327,327,327,327,327, |
672 | 387,387,387,387,387,387,388,388,388,388,388,388,388,388,388,389,389,389,389,389, | 709 | 327,327,328,328,328,328,328,328,328,328,328,329,329,329,329,329, |
673 | 389,389,389,389,389,390,390,390,390,390,390,390,390,390,390,391,391,391,391,391, | 710 | 329,329,329,329,330,330,330,330,330,330,330,330,330,330,331,331, |
674 | 391,391,391,391,391,392,392,392,392,392,392,392,392,392,393,393,393,393,393,393, | 711 | 331,331,331,331,331,331,331,332,332,332,332,332,332,332,332,332, |
675 | 393,393,393,393,394,394,394,394,394,394,394,394,394,394,395,395,395,395,395,395, | 712 | 333,333,333,333,333,333,333,333,333,334,334,334,334,334,334,334, |
676 | 395,395,395,395,396,396,396,396,396,396,396,396,396,397,397,397,397,397,397,397, | 713 | 334,334,335,335,335,335,335,335,335,335,335,335,336,336,336,336, |
677 | 397,397,397,398,398,398,398,398,398,398,398,398,398,399,399,399,399,399,399,399, | 714 | 336,336,336,336,336,337,337,337,337,337,337,337,337,337,338,338, |
678 | 399,399,399,400,400,400,400,400,400,400,400,400,400,401,401,401,401,401,401,401, | 715 | 338,338,338,338,338,338,338,338,339,339,339,339,339,339,339,339, |
679 | 401,401,402,402,402,402,402,402,402,402,402,402,403,403,403,403,403,403,403,403, | 716 | 339,340,340,340,340,340,340,340,340,340,341,341,341,341,341,341, |
680 | 403,403,404,404,404,404,404,404,404,404,404,404,405,405,405,405,405,405,405,405, | 717 | 341,341,341,341,342,342,342,342,342,342,342,342,342,343,343,343, |
681 | 405,405,406,406,406,406,406,406,406,406,406,406,407,407,407,407,407,407,407,407, | 718 | 343,343,343,343,343,343,344,344,344,344,344,344,344,344,344,344, |
682 | 407,407,408,408,408,408,408,408,408,408,408,408,409,409,409,409,409,409,409,409, | 719 | 345,345,345,345,345,345,345,345,345,346,346,346,346,346,346,346, |
683 | 409,410,410,410,410,410,410,410,410,410,410,411,411,411,411,411,411,411,411,411, | 720 | 346,346,347,347,347,347,347,347,347,347,347,347,348,348,348,348, |
684 | 411,412,412,412,412,412,412,412,412,412,412,413,413,413,413,413,413,413,413,413, | 721 | 348,348,348,348,348,349,349,349,349,349,349,349,349,349,350,350, |
685 | 413,414,414,414,414,414,414,414,414,414,414,415,415,415,415,415,415,415,415,415, | 722 | 350,350,350,350,350,350,350,350,351,351,351,351,351,351,351,351, |
686 | 415,416,416,416,416,416,416,416,416,416,416,417,417,417,417,417,417,417,417,417, | 723 | 351,352,352,352,352,352,352,352,352,352,352,353,353,353,353,353, |
687 | 417,418,418,418,418,418,418,418,418,418,418,419,419,419,419,419,419,419,419,419, | 724 | 353,353,353,353,354,354,354,354,354,354,354,354,354,355,355,355, |
688 | 419,420,420,420,420,420,420,420,420,420,420,421,421,421,421,421,421,421,421,421, | 725 | 355,355,355,355,355,355,355,356,356,356,356,356,356,356,356,356, |
689 | 421,422,422,422,422,422,422,422,422,422,422,423,423,423,423,423,423,423,423,423, | 726 | 357,357,357,357,357,357,357,357,357,357,358,358,358,358,358,358, |
690 | 423,424,424,424,424,424,424,424,424,424,424,425,425,425,425,425,425,425,425,425, | 727 | 358,358,358,359,359,359,359,359,359,359,359,359,359,360,360,360, |
691 | 425,426,426,426,426,426,426,426,426,426,426,427,427,427,427,427,427,427,427,427, | 728 | 360,360,360,360,360,360,361,361,361,361,361,361,361,361,361,361, |
692 | 427,428,428,428,428,428,428,428,428,428,428,429,429,429,429,429,429,429,429,429, | 729 | 362,362,362,362,362,362,362,362,362,363,363,363,363,363,363,363, |
693 | 429,430,430,430,430,430,430,430,430,430,430,431,431,431,431,431,431,431,431,431, | 730 | 363,363,363,364,364,364,364,364,364,364,364,364,365,365,365,365, |
694 | 431,432,432,432,432,432,432,432,432,432,432,433,433,433,433,433,433,433,433,433, | 731 | 365,365,365,365,365,365,366,366,366,366,366,366,366,366,366,367, |
695 | 433,434,434,434,434,434,434,434,434,434,434,435,435,435,435,435,435,435,435,435, | 732 | 367,367,367,367,367,367,367,367,367,368,368,368,368,368,368,368, |
696 | 435,435,436,436,436,436,436,436,436,436,436,436,437,437,437,437,437,437,437,437, | 733 | 368,368,369,369,369,369,369,369,369,369,369,369,370,370,370,370, |
697 | 437,437,438,438,438,438,438,438,438,438,438,438,439,439,439,439,439,439,439,439, | 734 | 370,370,370,370,370,370,371,371,371,371,371,371,371,371,371,372, |
698 | 439,439,440,440,440,440,440,440,440,440,440,440,441,441,441,441,441,441,441,441, | 735 | 372,372,372,372,372,372,372,372,372,373,373,373,373,373,373,373, |
699 | 441,441,442,442,442,442,442,442,442,442,442,442,443,443,443,443,443,443,443,443, | 736 | 373,373,374,374,374,374,374,374,374,374,374,374,375,375,375,375, |
700 | 443,443,443,444,444,444,444,444,444,444,444,444,444,445,445,445,445,445,445,445, | 737 | 375,375,375,375,375,375,376,376,376,376,376,376,376,376,376,377, |
701 | 445,445,445,446,446,446,446,446,446,446,446,446,446,447,447,447,447,447,447,447, | 738 | 377,377,377,377,377,377,377,377,377,378,378,378,378,378,378,378, |
702 | 447,447,447,448,448,448,448,448,448,448,448,448,448,448,449,449,449,449,449,449, | 739 | 378,378,379,379,379,379,379,379,379,379,379,379,380,380,380,380, |
703 | 449,449,449,449,450,450,450,450,450,450,450,450,450,450,451,451,451,451,451,451, | 740 | 380,380,380,380,380,380,381,381,381,381,381,381,381,381,381,382, |
704 | 451,451,451,451,452,452,452,452,452,452,452,452,452,452,453,453,453,453,453,453, | 741 | 382,382,382,382,382,382,382,382,382,383,383,383,383,383,383,383, |
705 | 453,453,453,453,453,454,454,454,454,454,454,454,454,454,454,455,455,455,455,455, | 742 | 383,383,383,384,384,384,384,384,384,384,384,384,385,385,385,385, |
706 | 455,455,455,455,455,456,456,456,456,456,456,456,456,456,456,457,457,457,457,457, | 743 | 385,385,385,385,385,385,386,386,386,386,386,386,386,386,386,386, |
707 | 457,457,457,457,457,457,458,458,458,458,458,458,458,458,458,458,459,459,459,459, | 744 | 387,387,387,387,387,387,387,387,387,387,388,388,388,388,388,388, |
708 | 459,459,459,459,459,459,460,460,460,460,460,460,460,460,460,460,460,461,461,461, | 745 | 388,388,388,389,389,389,389,389,389,389,389,389,389,390,390,390, |
709 | 461,461,461,461,461,461,461,462,462,462,462,462,462,462,462,462,462,463,463,463, | 746 | 390,390,390,390,390,390,390,391,391,391,391,391,391,391,391,391, |
710 | 463,463,463,463,463,463,463,463,464,464,464,464,464,464,464,464,464,464,465,465, | 747 | 391,392,392,392,392,392,392,392,392,392,393,393,393,393,393,393, |
711 | 465,465,465,465,465,465,465,465,466,466,466,466,466,466,466,466,466,466,466,467, | 748 | 393,393,393,393,394,394,394,394,394,394,394,394,394,394,395,395, |
712 | 467,467,467,467,467,467,467,467,467,468,468,468,468,468,468,468,468,468,468,469, | 749 | 395,395,395,395,395,395,395,395,396,396,396,396,396,396,396,396, |
713 | 469,469,469,469,469,469,469,469,469,469,470,470,470,470,470,470,470,470,470,470, | 750 | 396,397,397,397,397,397,397,397,397,397,397,398,398,398,398,398, |
714 | 471,471,471,471,471,471,471,471,471,471,472,472,472,472,472,472,472,472,472,472, | 751 | 398,398,398,398,398,399,399,399,399,399,399,399,399,399,399,400, |
715 | 472,473,473,473,473,473,473,473,473,473,473,474,474,474,474,474,474,474,474,474, | 752 | 400,400,400,400,400,400,400,400,400,401,401,401,401,401,401,401, |
716 | 474,475,475,475,475,475,475,475,475,475,475,475,476,476,476,476,476,476,476,476, | 753 | 401,401,402,402,402,402,402,402,402,402,402,402,403,403,403,403, |
717 | 476,476,477,477,477,477,477,477,477,477,477,477,477,478,478,478,478,478,478,478, | 754 | 403,403,403,403,403,403,404,404,404,404,404,404,404,404,404,404, |
718 | 478,478,478,479,479,479,479,479,479,479,479,479,479,479,480,480,480,480,480,480, | 755 | 405,405,405,405,405,405,405,405,405,405,406,406,406,406,406,406, |
719 | 480,480,480,480,481,481,481,481,481,481,481,481,481,481,482,482,482,482,482,482, | 756 | 406,406,406,406,407,407,407,407,407,407,407,407,407,407,408,408, |
720 | 482,482,482,482,482,483,483,483,483,483,483,483,483,483,483,484,484,484,484,484, | 757 | 408,408,408,408,408,408,408,408,409,409,409,409,409,409,409,409, |
721 | 484,484,484,484,484,484,485,485,485,485,485,485,485,485,485,485,486,486,486,486, | 758 | 409,410,410,410,410,410,410,410,410,410,410,411,411,411,411,411, |
722 | 486,486,486,486,486,486,486,487,487,487,487,487,487,487,487,487,487,488,488,488, | 759 | 411,411,411,411,411,412,412,412,412,412,412,412,412,412,412,413, |
723 | 488,488,488,488,488,488,488,488,489,489,489,489,489,489,489,489,489,489,490,490, | 760 | 413,413,413,413,413,413,413,413,413,414,414,414,414,414,414,414, |
724 | 490,490,490,490,490,490,490,490,490,491,491,491,491,491,491,491,491,491,491,492, | 761 | 414,414,414,415,415,415,415,415,415,415,415,415,415,416,416,416, |
725 | 492,492,492,492,492,492,492,492,492,492,493,493,493,493,493,493,493,493,493,493, | 762 | 416,416,416,416,416,416,416,417,417,417,417,417,417,417,417,417, |
726 | 494,494,494,494,494,494,494,494,494,494,494,495,495,495,495,495,495,495,495,495, | 763 | 417,418,418,418,418,418,418,418,418,418,418,419,419,419,419,419, |
727 | 495,496,496,496,496,496,496,496,496,496,496,496,497,497,497,497,497,497,497,497, | 764 | 419,419,419,419,419,420,420,420,420,420,420,420,420,420,420,421, |
728 | 497,497,497,498,498,498,498,498,498,498,498,498,498,499,499,499,499,499,499,499, | 765 | 421,421,421,421,421,421,421,421,421,422,422,422,422,422,422,422, |
729 | 499,499,499,499,500,500,500,500,500,500,500,500,500,500,501,501,501,501,501,501, | 766 | 422,422,422,423,423,423,423,423,423,423,423,423,423,424,424,424, |
730 | 501,501,501,501,501,502,502,502,502,502,502,502,502,502,502,503,503,503,503,503, | 767 | 424,424,424,424,424,424,424,425,425,425,425,425,425,425,425,425, |
731 | 503,503,503,503,503,503,504,504,504,504,504,504,504,504,504,504,504,505,505,505, | 768 | 425,426,426,426,426,426,426,426,426,426,426,427,427,427,427,427, |
732 | 505,505,505,505,505,505,505,506,506,506,506,506,506,506,506,506,506,506,507,507, | 769 | 427,427,427,427,427,428,428,428,428,428,428,428,428,428,428,429, |
733 | 507,507,507,507,507,507,507,507,507,508,508,508,508,508,508,508,508,508,508,509, | 770 | 429,429,429,429,429,429,429,429,429,430,430,430,430,430,430,430, |
734 | 509,509,509,509,509,509,509,509,509,509,510,510,510,510,510,510,510,510,510,510, | 771 | 430,430,430,431,431,431,431,431,431,431,431,431,431,432,432,432, |
735 | 510,511,511,511,511,511,511,511,511,511,511,512,512,512,512,512 }; | 772 | 432,432,432,432,432,432,432,433,433,433,433,433,433,433,433,433, |
736 | 773 | 433,434,434,434,434,434,434,434,434,434,434,435,435,435,435,435, | |
737 | static const int order[32] = | 774 | 435,435,435,435,435,435,436,436,436,436,436,436,436,436,436,436, |
775 | 437,437,437,437,437,437,437,437,437,437,438,438,438,438,438,438, | ||
776 | 438,438,438,438,439,439,439,439,439,439,439,439,439,439,440,440, | ||
777 | 440,440,440,440,440,440,440,440,441,441,441,441,441,441,441,441, | ||
778 | 441,441,442,442,442,442,442,442,442,442,442,442,443,443,443,443, | ||
779 | 443,443,443,443,443,443,443,444,444,444,444,444,444,444,444,444, | ||
780 | 444,445,445,445,445,445,445,445,445,445,445,446,446,446,446,446, | ||
781 | 446,446,446,446,446,447,447,447,447,447,447,447,447,447,447,448, | ||
782 | 448,448,448,448,448,448,448,448,448,448,449,449,449,449,449,449, | ||
783 | 449,449,449,449,450,450,450,450,450,450,450,450,450,450,451,451, | ||
784 | 451,451,451,451,451,451,451,451,452,452,452,452,452,452,452,452, | ||
785 | 452,452,453,453,453,453,453,453,453,453,453,453,453,454,454,454, | ||
786 | 454,454,454,454,454,454,454,455,455,455,455,455,455,455,455,455, | ||
787 | 455,456,456,456,456,456,456,456,456,456,456,457,457,457,457,457, | ||
788 | 457,457,457,457,457,457,458,458,458,458,458,458,458,458,458,458, | ||
789 | 459,459,459,459,459,459,459,459,459,459,460,460,460,460,460,460, | ||
790 | 460,460,460,460,460,461,461,461,461,461,461,461,461,461,461,462, | ||
791 | 462,462,462,462,462,462,462,462,462,463,463,463,463,463,463,463, | ||
792 | 463,463,463,463,464,464,464,464,464,464,464,464,464,464,465,465, | ||
793 | 465,465,465,465,465,465,465,465,466,466,466,466,466,466,466,466, | ||
794 | 466,466,466,467,467,467,467,467,467,467,467,467,467,468,468,468, | ||
795 | 468,468,468,468,468,468,468,469,469,469,469,469,469,469,469,469, | ||
796 | 469,469,470,470,470,470,470,470,470,470,470,470,471,471,471,471, | ||
797 | 471,471,471,471,471,471,472,472,472,472,472,472,472,472,472,472, | ||
798 | 472,473,473,473,473,473,473,473,473,473,473,474,474,474,474,474, | ||
799 | 474,474,474,474,474,475,475,475,475,475,475,475,475,475,475,475, | ||
800 | 476,476,476,476,476,476,476,476,476,476,477,477,477,477,477,477, | ||
801 | 477,477,477,477,477,478,478,478,478,478,478,478,478,478,478,479, | ||
802 | 479,479,479,479,479,479,479,479,479,479,480,480,480,480,480,480, | ||
803 | 480,480,480,480,481,481,481,481,481,481,481,481,481,481,482,482, | ||
804 | 482,482,482,482,482,482,482,482,482,483,483,483,483,483,483,483, | ||
805 | 483,483,483,484,484,484,484,484,484,484,484,484,484,484,485,485, | ||
806 | 485,485,485,485,485,485,485,485,486,486,486,486,486,486,486,486, | ||
807 | 486,486,486,487,487,487,487,487,487,487,487,487,487,488,488,488, | ||
808 | 488,488,488,488,488,488,488,488,489,489,489,489,489,489,489,489, | ||
809 | 489,489,490,490,490,490,490,490,490,490,490,490,490,491,491,491, | ||
810 | 491,491,491,491,491,491,491,492,492,492,492,492,492,492,492,492, | ||
811 | 492,492,493,493,493,493,493,493,493,493,493,493,494,494,494,494, | ||
812 | 494,494,494,494,494,494,494,495,495,495,495,495,495,495,495,495, | ||
813 | 495,496,496,496,496,496,496,496,496,496,496,496,497,497,497,497, | ||
814 | 497,497,497,497,497,497,497,498,498,498,498,498,498,498,498,498, | ||
815 | 498,499,499,499,499,499,499,499,499,499,499,499,500,500,500,500, | ||
816 | 500,500,500,500,500,500,501,501,501,501,501,501,501,501,501,501, | ||
817 | 501,502,502,502,502,502,502,502,502,502,502,503,503,503,503,503, | ||
818 | 503,503,503,503,503,503,504,504,504,504,504,504,504,504,504,504, | ||
819 | 504,505,505,505,505,505,505,505,505,505,505,506,506,506,506,506, | ||
820 | 506,506,506,506,506,506,507,507,507,507,507,507,507,507,507,507, | ||
821 | 507,508,508,508,508,508,508,508,508,508,508,509,509,509,509,509, | ||
822 | 509,509,509,509,509,509,510,510,510,510,510,510,510,510,510,510, | ||
823 | 510,511,511,511,511,511,511,511,511,511,511,512,512,512,512,512 }; | ||
824 | |||
825 | static const int order[32] ICONST_ATTR = | ||
738 | { 0, 1, 16, 17, 8, 9, 24, 25, 4, 5, 20, 21, 12, 13, 28, 29, | 826 | { 0, 1, 16, 17, 8, 9, 24, 25, 4, 5, 20, 21, 12, 13, 28, 29, |
739 | 2, 3, 18, 19,10,11, 26, 27, 6, 7, 22, 23, 14, 15, 30, 31 }; | 827 | 2, 3, 18, 19,10,11, 26, 27, 6, 7, 22, 23, 14, 15, 30, 31 }; |
740 | 828 | ||
741 | static const long sampr_index[2][3] = | 829 | static const int cx[9] ICONST_ATTR = |
742 | { { 22050, 24000, 16000 }, /* MPEG 2 */ | ||
743 | { 44100, 48000, 32000 } }; /* MPEG 1 */ | ||
744 | |||
745 | static const long bitr_index[2][15] = | ||
746 | { {0, 8,16,24,32,40,48,56, 64, 80, 96,112,128,144,160}, /* MPEG 2 */ | ||
747 | {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320} }; /* MPEG 1 */ | ||
748 | |||
749 | static const int num_bands[3][15] = | ||
750 | { {0,10,10,10,10,12,14,16, 20, 22, 24, 26, 28, 30, 32}, | ||
751 | {0,10,10,10,10,10,12,14, 18, 24, 26, 28, 30, 32, 32}, | ||
752 | {0,10,12,14,18,24,26,28, 30, 32, 32, 32, 32, 32, 32} }; | ||
753 | |||
754 | static const int cx_const[9] = | ||
755 | { 16135, 10531, 5604, 15396, -2845,-12551, 14189, 8192, 16384 }; | 830 | { 16135, 10531, 5604, 15396, -2845,-12551, 14189, 8192, 16384 }; |
756 | 831 | ||
757 | static const int ca_const[8] = | 832 | static const int ca[8] ICONST_ATTR = |
758 | {-16859,-15458,-10269, -5961, -3099, -1342, -465, -121 }; | 833 | {-16859,-15458,-10269, -5961, -3099, -1342, -465, -121 }; |
759 | 834 | ||
760 | static const int cs_const[8] = | 835 | static const int cs[8] ICONST_ATTR = |
761 | { 28098, 28893, 31117, 32221, 32621, 32740, 32765, 32768 }; | 836 | { 28098, 28893, 31117, 32221, 32621, 32740, 32765, 32768 }; |
762 | 837 | ||
763 | static const short enwindow_const[15*27+24] = | 838 | static const short enwindow[15*20+16] ICONST_ATTR |
764 | { 0, 65, 593, 1766, 22228, 2115, 611, 62, | 839 | __attribute__((aligned(4))) = |
765 | 8, 119, 1419, 10564,-11659,-1635,-154, -9, | 840 | { 0, 65, 593, 1766, 22228, 2115, 611, 62, |
766 | -8, -119,-1419,-10564, 11659, 1635, 154, 9, 464, 100, 91, | 841 | 8, 119, 1419, 10564,-11659,-1635,-154, -9, 464, 100, 91, 0, |
767 | 0, 69, 604, 1635, 23148, 2363, 643, 62, | 842 | 0, 69, 604, 1635, 23148, 2363, 643, 62, |
768 | 7, 107, 1368, 10449,-12733,-1818,-180,-11, | 843 | 7, 107, 1368, 10449,-12733,-1818,-180,-11, 420, 200, 164, 0, |
769 | -7, -107,-1368,-10449, 12733, 1818, 180, 11, 420, 200, 164, | 844 | 0, 72, 608, 1465, 23979, 2600, 671, 63, |
770 | 0, 72, 608, 1465, 23979, 2600, 671, 63, | 845 | 7, 94, 1305, 10265,-13818,-2004,-207,-12, 380, 297, 220, 0, |
771 | 7, 94, 1305, 10265,-13818,-2004,-207,-12, | 846 | 0, 76, 606, 1256, 24718, 2825, 693, 63, |
772 | -7, -94,-1305,-10265, 13818, 2004, 207, 12, 380, 297, 220, | 847 | 6, 81, 1232, 10016,-14908,-2192,-236,-14, 342, 392, 262, 0, |
773 | 0, 76, 606, 1256, 24718, 2825, 693, 63, | 848 | 0, 78, 597, 1007, 25359, 3033, 712, 63, |
774 | 6, 81, 1232, 10016,-14908,-2192,-236,-14, | 849 | 6, 68, 1150, 9706,-15995,-2380,-267,-15, 307, 483, 289, 0, |
775 | -6, -81,-1232,-10016, 14908, 2192, 236, 14, 342, 392, 262, | 850 | 0, 80, 580, 719, 25901, 3224, 726, 62, |
776 | 0, 78, 597, 1007, 25359, 3033, 712, 63, | 851 | 6, 54, 1060, 9343,-17072,-2565,-299,-17, 274, 569, 304, 0, |
777 | 6, 68, 1150, 9706,-15995,-2380,-267,-15, | 852 | -1, 82, 555, 391, 26339, 3395, 735, 61, |
778 | -6, -68,-1150, -9706, 15995, 2380, 267, 15, 307, 483, 289, | 853 | 5, 40, 963, 8930,-18131,-2747,-332,-19, 242, 650, 307, 0, |
779 | 0, 80, 580, 719, 25901, 3224, 726, 62, | 854 | -1, 83, 523, 26, 26672, 3545, 740, 60, |
780 | 6, 54, 1060, 9343,-17072,-2565,-299,-17, | 855 | 5, 27, 861, 8474,-19164,-2923,-366,-21, 212, 724, 300, 0, |
781 | -6, -54,-1060, -9343, 17072, 2565, 299, 17, 274, 569, 304, | 856 | -1, 83, 482, -376, 26900, 3672, 739, 58, |
782 | -1, 82, 555, 391, 26339, 3395, 735, 61, | 857 | 4, 14, 756, 7981,-20163,-3092,-401,-24, 183, 792, 283, 0, |
783 | 5, 40, 963, 8930,-18131,-2747,-332,-19, | 858 | -1, 82, 433, -812, 27022, 3776, 735, 56, |
784 | -5, -40, -963, -8930, 18131, 2747, 332, 19, 242, 650, 307, | 859 | 4, 1, 648, 7456,-21122,-3250,-435,-26, 155, 851, 258, 0, |
785 | -1, 83, 523, 26, 26672, 3545, 740, 60, | 860 | -1, 81, 376, -1281, 27038, 3855, 726, 54, |
786 | 5, 27, 861, 8474,-19164,-2923,-366,-21, | 861 | 3, -11, 539, 6907,-22032,-3397,-470,-28, 128, 903, 226, 0, |
787 | -5, -27, -861, -8474, 19164, 2923, 366, 21, 212, 724, 300, | 862 | -1, 78, 312, -1778, 26951, 3910, 713, 52, |
788 | -1, 83, 482, -376, 26900, 3672, 739, 58, | 863 | 3, -22, 430, 6338,-22887,-3530,-503,-31, 102, 946, 188, 0, |
789 | 4, 14, 756, 7981,-20163,-3092,-401,-24, | 864 | -2, 75, 239, -2302, 26761, 3941, 696, 49, |
790 | -4, -14, -756, -7981, 20163, 3092, 401, 24, 183, 792, 283, | 865 | 3, -33, 322, 5757,-23678,-3648,-537,-34, 76, 980, 145, 0, |
791 | -1, 82, 433, -812, 27022, 3776, 735, 56, | 866 | -2, 70, 160, -2848, 26472, 3948, 676, 47, |
792 | 4, 1, 648, 7456,-21122,-3250,-435,-26, | 867 | 3, -42, 217, 5167,-24399,-3749,-568,-36, 50, 1004, 99, 0, |
793 | -4, -1, -648, -7456, 21122, 3250, 435, 26, 155, 851, 258, | 868 | -2, 65, 74, -3412, 26087, 3931, 653, 44, |
794 | -1, 81, 376, -1281, 27038, 3855, 726, 54, | 869 | 2, -51, 115, 4577,-25045,-3830,-599,-39, 25, 1019, 50, 0, |
795 | 3, -11, 539, 6907,-22032,-3397,-470,-28, | 870 | |
796 | -3, 11, -539, -6907, 22032, 3397, 470, 28, 128, 903, 226, | 871 | 25610, 3891, 627, 42,-3990, -18, 58, -2, |
797 | -1, 78, 312, -1778, 26951, 3910, 713, 52, | 872 | 21226, 10604, 1860, 1458, 576, 130, 60, 8, |
798 | 3, -22, 430, 6338,-22887,-3530,-503,-31, | ||
799 | -3, 22, -430, -6338, 22887, 3530, 503, 31, 102, 946, 188, | ||
800 | -2, 75, 239, -2302, 26761, 3941, 696, 49, | ||
801 | 3, -33, 322, 5757,-23678,-3648,-537,-34, | ||
802 | -3, 33, -322, -5757, 23678, 3648, 537, 34, 76, 980, 145, | ||
803 | -2, 70, 160, -2848, 26472, 3948, 676, 47, | ||
804 | 3, -42, 217, 5167,-24399,-3749,-568,-36, | ||
805 | -3, 42, -217, -5167, 24399, 3749, 568, 36, 50, 1004, 99, | ||
806 | -2, 65, 74, -3412, 26087, 3931, 653, 44, | ||
807 | 2, -51, 115, 4577,-25045,-3830,-599,-39, | ||
808 | -2, 51, -115, -4577, 25045, 3830, 599, 39, 25, 1019, 50, | ||
809 | |||
810 | 25610,3891,627,42,-3990,-18,58,-2, | ||
811 | 21226,-21226,10604,-10604,1860,-1860,1458,-1458,576,-576,130,-130,60,-60,8,-8 | ||
812 | }; | 873 | }; |
813 | 874 | ||
814 | static const int win_const[18][4] = { | 875 | static const int win[18][4] ICONST_ATTR = |
815 | { -3072, -134, -146, 3352 }, | 876 | { { -3072, -134, -146, 3352 }, |
816 | { -2747, -362, -471, 3579 }, | 877 | { -2747, -362, -471, 3579 }, |
817 | { -2387, -529, -831, 3747 }, | 878 | { -2387, -529, -831, 3747 }, |
818 | { -2004, -632,-1214, 3850 }, | 879 | { -2004, -632,-1214, 3850 }, |
@@ -831,19 +892,70 @@ static const int win_const[18][4] = { | |||
831 | { 362, -471,-3579,-2747 }, | 892 | { 362, -471,-3579,-2747 }, |
832 | { 134, -146,-3352,-3072 } }; | 893 | { 134, -146,-3352,-3072 } }; |
833 | 894 | ||
834 | /* forward declarations */ | 895 | static const long sampr_index[2][3] = |
835 | static int HuffmanCode( short *ix, char *xr_sign, uint32_t begin, uint32_t end, int table); | 896 | { { 22050, 24000, 16000 }, /* MPEG 2 */ |
836 | static int HuffmanCod1( short *ix, char *xr_sign, uint32_t begin, uint32_t end, int table); | 897 | { 44100, 48000, 32000 } }; /* MPEG 1 */ |
837 | static void putbits(uint32_t val, uint32_t nbit); | 898 | |
838 | static int find_best_2( short *ix, uint32_t start, uint32_t end, const uint32_t *table, | 899 | static const long bitr_index[2][15] = |
839 | uint32_t len, int *bits); | 900 | { { 0, 8,16,24,32,40,48,56, 64, 80, 96,112,128,144,160 }, /* MPEG 2 */ |
840 | static int find_best_3( short *ix, uint32_t start, uint32_t end, const uint32_t *table, | 901 | { 0,32,40,48,56,64,80,96,112,128,160,192,224,256,320 } }; /* MPEG 1 */ |
841 | uint32_t len, int *bits); | 902 | |
842 | static int count_bit1 ( short *ix, uint32_t start, uint32_t end, int *bits ); | 903 | static const int num_bands[3][15] = |
843 | static int count_bigv ( short *ix, uint32_t start, uint32_t end, int table0, int table1, | 904 | { { 0,10,10,10,10,12,14,16,20,22,24,26,28,30,32 }, /* MPEG 2 Stereo */ |
844 | int *bits); | 905 | { 0,10,10,10,10,10,12,14,18,24,26,28,30,32,32 }, /* MPEG 1 Stereo */ |
906 | { 0,10,12,14,18,24,26,28,30,32,32,32,32,32,32 } }; /* MPEG 1&2 Mono */ | ||
907 | |||
845 | 908 | ||
846 | static inline uint32_t encodeHeader( int padding, long bitr_id ) | 909 | #ifdef MP3_ENC_COP |
910 | /* Initialize the circular buffer pointers */ | ||
911 | static inline void sb_data_buf_init(void) | ||
912 | { | ||
913 | sb_data_cod = &sb_data_buf[0]; | ||
914 | sb_data_enc = &sb_data_buf[1]; | ||
915 | } | ||
916 | |||
917 | /* Switch the buffers used by CPU and COP */ | ||
918 | static inline void sb_data_buf_swap(void) | ||
919 | { | ||
920 | typeof (sb_data_cod) t = sb_data_cod; | ||
921 | sb_data_cod = sb_data_enc; | ||
922 | sb_data_enc = t; | ||
923 | } | ||
924 | #endif /* MP3_ENC_COP */ | ||
925 | |||
926 | static void putbits(uint32_t val, uint32_t nbit) | ||
927 | { | ||
928 | int new_bitpos = coded_data.bitpos + nbit; | ||
929 | int ptrpos = coded_data.bitpos >> 5; | ||
930 | |||
931 | val = val & (0xffffffff >> (32 - nbit)); | ||
932 | |||
933 | /* data fit in one uint32_t */ | ||
934 | if (((new_bitpos - 1) >> 5) == ptrpos) | ||
935 | { | ||
936 | coded_data.bbuf[ptrpos] |= val << ((32 - new_bitpos) & 31); | ||
937 | } | ||
938 | else | ||
939 | { | ||
940 | coded_data.bbuf[ptrpos ] |= val >> ((new_bitpos - 32) & 31); | ||
941 | coded_data.bbuf[ptrpos+1] |= val << ((32 - new_bitpos) & 31); | ||
942 | } | ||
943 | |||
944 | coded_data.bitpos = new_bitpos; | ||
945 | } | ||
946 | |||
947 | #define PUTLONG_INIT() \ | ||
948 | uint32_t _cc = 0, _sz = 0 | ||
949 | |||
950 | #define putlong_flush() \ | ||
951 | putbits(_cc, _sz) | ||
952 | |||
953 | #define putlong(c, s) \ | ||
954 | ({ uint32_t _c = (c), _s = (s); \ | ||
955 | if (_s + _sz <= 32) { _cc = (_cc << _s) | _c; _sz += _s; } \ | ||
956 | else { putlong_flush(); _cc = _c; _sz = _s; } }) | ||
957 | |||
958 | static inline uint32_t encode_header(int padding, long bitr_id) | ||
847 | { | 959 | { |
848 | /* | 960 | /* |
849 | * MPEG header layout: | 961 | * MPEG header layout: |
@@ -875,512 +987,516 @@ static inline uint32_t encodeHeader( int padding, long bitr_id ) | |||
875 | /* no emphasis (bits 0-1) */ | 987 | /* no emphasis (bits 0-1) */ |
876 | } | 988 | } |
877 | 989 | ||
878 | static long calcFrameSize(int bitr_id, long *frac) | 990 | static long calc_frame_size(int bitr_id, long *frac) |
879 | { | 991 | { |
880 | unsigned long v = bitr_index[cfg.mpg.type][bitr_id]; | 992 | unsigned long v = bitr_index[cfg.mpg.type][bitr_id]; |
881 | v = SAMPL2 * 16000 * v / (2 - cfg.mpg.type); | 993 | v = 576 * 16000 * v / (2 - cfg.mpg.type); |
882 | v /= cfg.samplerate; | 994 | v /= cfg.samplerate; |
883 | 995 | ||
884 | if (frac) | 996 | if (frac) |
885 | *frac = v % 64; | 997 | *frac = v % 64; |
886 | 998 | ||
887 | return v / 64; | 999 | return v / 64; |
888 | |||
889 | } | 1000 | } |
890 | static void encodeSideInfo( side_info_t si[2][2] ) | 1001 | |
891 | { | 1002 | static void encode_side_info(side_info_t si[2][2]) |
892 | int gr, ch; | 1003 | { |
893 | uint32_t cc=0, sz=0; | 1004 | PUTLONG_INIT(); |
894 | 1005 | ||
895 | putbits( encodeHeader( cfg.mpg.padding, cfg.mpg.bitr_id ), 32 ); | 1006 | putbits(encode_header(cfg.mpg.padding, cfg.mpg.bitr_id), 32); |
896 | 1007 | ||
897 | if(cfg.mpg.type == 1) | 1008 | if (cfg.mpg.type == 1) |
898 | { /* MPEG1 */ | ||
899 | if(cfg.channels == 2) { putlong( 0, 20); } | ||
900 | else { putlong( 0, 18); } | ||
901 | |||
902 | for(gr=0; gr<cfg.granules; gr++) | ||
903 | for(ch=0; ch<cfg.channels; ch++) | ||
904 | { | ||
905 | side_info_t *gi = &si[gr][ch]; | ||
906 | |||
907 | putlong((gi->part2_3_length+42),12 ); /* add scale_facs array size */ | ||
908 | putlong( gi->address3>>1, 9 ); | ||
909 | putlong( gi->global_gain, 8 ); | ||
910 | putlong( 9, 4 ); /* set scale_facs compr type */ | ||
911 | putlong( gi->table_select[0], 6 ); | ||
912 | putlong( gi->table_select[1], 5 ); | ||
913 | putlong( gi->table_select[2], 5 ); | ||
914 | putlong( gi->region_0_1, 7 ); | ||
915 | putlong( 1 , 2 ); /* set scale_facs to 1bit */ | ||
916 | putlong( gi->table_select[3], 1 ); | ||
917 | } | ||
918 | } | ||
919 | else | ||
920 | { /* MPEG2 */ | ||
921 | if(cfg.channels == 2) { putlong( 0, 10); } | ||
922 | else { putlong( 0, 9); } | ||
923 | |||
924 | for(ch=0; ch<cfg.channels; ch++) | ||
925 | { | 1009 | { |
926 | side_info_t *gi = &si[0][ch]; | 1010 | /* MPEG1 */ |
927 | 1011 | if (cfg.channels == 2) putlong(0, 20); | |
928 | putlong((gi->part2_3_length+42),12 ); /* add scale_facs array size */ | 1012 | else putlong(0, 18); |
929 | putlong( gi->address3>>1, 9 ); | 1013 | |
930 | putlong( gi->global_gain, 8 ); | 1014 | for (int gr = 0; gr < cfg.granules; gr++) |
931 | putlong( 0xCA, 9 ); /* set scale_facs compr type */ | 1015 | { |
932 | putlong( gi->table_select[0], 6 ); | 1016 | for (int ch = 0; ch < cfg.channels; ch++) |
933 | putlong( gi->table_select[1], 5 ); | 1017 | { |
934 | putlong( gi->table_select[2], 5 ); | 1018 | side_info_t *gi = &si[gr][ch]; |
935 | putlong( gi->region_0_1 , 7 ); | 1019 | |
936 | putlong( 1 , 1 ); /* set scale_facs to 1bit */ | 1020 | putlong(gi->part2_3_length + 42, 12); /* add scale_facs array size */ |
937 | putlong( gi->table_select[3], 1 ); | 1021 | putlong(gi->address3 >> 1, 9); |
1022 | putlong(gi->global_gain, 8); | ||
1023 | putlong(9, 4); /* set scale_facs compr type */ | ||
1024 | putlong(gi->table_select[0], 6); | ||
1025 | putlong(gi->table_select[1], 5); | ||
1026 | putlong(gi->table_select[2], 5); | ||
1027 | putlong(gi->region_0_1, 7); | ||
1028 | putlong(1 , 2); /* set scale_facs to 1bit */ | ||
1029 | putlong(gi->table_select[3], 1); | ||
1030 | } | ||
1031 | } | ||
938 | } | 1032 | } |
939 | } | 1033 | else |
940 | /* flush remaining bits */ | 1034 | { |
941 | putbits(cc, sz); | 1035 | /* MPEG2 */ |
1036 | if (cfg.channels == 2) putlong(0, 10); | ||
1037 | else putlong(0, 9); | ||
1038 | |||
1039 | for (int ch = 0; ch < cfg.channels; ch++) | ||
1040 | { | ||
1041 | side_info_t *gi = &si[0][ch]; | ||
1042 | |||
1043 | putlong(gi->part2_3_length + 42, 12); /* add scale_facs array size */ | ||
1044 | putlong(gi->address3 >> 1, 9); | ||
1045 | putlong(gi->global_gain, 8); | ||
1046 | putlong(0xca, 9); /* set scale_facs compr type */ | ||
1047 | putlong(gi->table_select[0], 6); | ||
1048 | putlong(gi->table_select[1], 5); | ||
1049 | putlong(gi->table_select[2], 5); | ||
1050 | putlong(gi->region_0_1 , 7); | ||
1051 | putlong(1 , 1); /* set scale_facs to 1bit */ | ||
1052 | putlong(gi->table_select[3], 1); | ||
1053 | } | ||
1054 | } | ||
1055 | |||
1056 | putlong_flush(); | ||
942 | } | 1057 | } |
943 | 1058 | ||
944 | /* Note the discussion of huffmancodebits() on pages 28 and 29 of the IS, | 1059 | /* Implements the pseudocode of page 98 of the IS */ |
945 | as well as the definitions of the side information on pages 26 and 27. */ | 1060 | static int huffman_code(short *ix, char *xr_sign, uint32_t begin, uint32_t end, |
946 | static void Huffmancodebits( short *ix, char *xr_sign, side_info_t *gi ) | 1061 | int table) |
947 | { | 1062 | { |
948 | int region1 = gi->address1; | 1063 | if (table == 0) |
949 | int region2 = gi->address2; | 1064 | return 0; |
950 | int bigvals = gi->address3; | 1065 | |
951 | int count1 = bigvals + (gi->count1 << 2); | 1066 | PUTLONG_INIT(); |
952 | int stuffBits = 0; | 1067 | int sumbit = 0; |
953 | int bits = 0; | ||
954 | int i, v; | ||
955 | 1068 | ||
956 | for(i=v=0; i<32; i+=2) | 1069 | #define sign_x xr_sign[i+0] |
957 | v |= band_scale_f[i>>1] << (30-i); | 1070 | #define sign_y xr_sign[i+1] |
958 | putbits(v, 32); // store scale_facs (part1) | ||
959 | 1071 | ||
960 | for(v=0; i<42; i+=2) | 1072 | if (table > 15) |
961 | v |= band_scale_f[i>>1] << (40-i); | 1073 | { |
962 | putbits(v, 10); // store scale_facs (part2) | 1074 | /* ESC-table is used */ |
1075 | uint32_t linbits = ht_big[table - 16].linbits; | ||
1076 | const uint16_t *hffcode = table < 24 ? t16HB : t24HB; | ||
1077 | const uint8_t *hlen = table < 24 ? t16l : t24l; | ||
1078 | uint32_t xl = 0, yl = 0; | ||
1079 | |||
1080 | for (uint32_t i = begin; i < end; i += 2) | ||
1081 | { | ||
1082 | int x = ix[i+0]; | ||
1083 | int y = ix[i+1]; | ||
963 | 1084 | ||
964 | if(region1 > 0) | 1085 | if (x > 14) { xl = x - 15; x = 15; } |
965 | bits += HuffmanCode(ix, xr_sign, 0 , region1, gi->table_select[0]); | 1086 | if (y > 14) { yl = y - 15; y = 15; } |
966 | 1087 | ||
967 | if(region2 > region1) | 1088 | uint32_t idx = x * 16 + y; |
968 | bits += HuffmanCode(ix, xr_sign, region1, region2, gi->table_select[1]); | 1089 | uint32_t code = hffcode[idx]; |
1090 | int bit = hlen [idx]; | ||
969 | 1091 | ||
970 | if(bigvals > region2) | 1092 | if (x) |
971 | bits += HuffmanCode(ix, xr_sign, region2, bigvals, gi->table_select[2]); | 1093 | { |
1094 | if (x > 14) | ||
1095 | { | ||
1096 | code = (code << linbits) | xl; | ||
1097 | bit += linbits; | ||
1098 | } | ||
972 | 1099 | ||
973 | if(count1 > bigvals) | 1100 | code = (code << 1) | sign_x; |
974 | bits += HuffmanCod1(ix, xr_sign, bigvals, count1, gi->table_select[3]); | 1101 | bit += 1; |
1102 | } | ||
975 | 1103 | ||
976 | if((stuffBits = gi->part2_3_length - bits) > 0) | 1104 | if (y) |
977 | { | 1105 | { |
978 | int stuffWords = stuffBits >> 5; | 1106 | if (y > 14) |
979 | int remainBits = stuffBits & 31; | 1107 | { |
1108 | if (bit + linbits + 1 > 32) | ||
1109 | { | ||
1110 | putlong(code, bit); | ||
1111 | sumbit += bit; | ||
1112 | code = bit = 0; | ||
1113 | } | ||
980 | 1114 | ||
981 | if( remainBits ) | 1115 | code = (code << linbits) | yl; |
982 | putbits( ~0, remainBits ); | 1116 | bit += linbits; |
1117 | } | ||
983 | 1118 | ||
984 | while( stuffWords-- ) | 1119 | code = (code << 1) | sign_y; |
985 | putbits( ~0, 32 ); /* Huffman code tables leed to padding ones */ | 1120 | bit += 1; |
986 | } | 1121 | } |
987 | } | ||
988 | 1122 | ||
989 | int HuffmanCod1( short *ix, char *xr_sign, uint32_t begin, uint32_t end, int tbl) | 1123 | putlong(code, bit); |
990 | { | 1124 | sumbit += bit; |
991 | uint32_t cc=0, sz=0; | 1125 | } |
992 | uint32_t i, d, p; | ||
993 | int sumbit=0, s=0, l=0, v, w, x, y; | ||
994 | #define sgnv xr_sign[i+0] | ||
995 | #define sgnw xr_sign[i+1] | ||
996 | #define sgnx xr_sign[i+2] | ||
997 | #define sgny xr_sign[i+3] | ||
998 | |||
999 | for(i=begin; i<end; i+=4) | ||
1000 | { | ||
1001 | v = ix[i+0]; | ||
1002 | w = ix[i+1]; | ||
1003 | x = ix[i+2]; | ||
1004 | y = ix[i+3]; | ||
1005 | p = (v << 3) + (w << 2) + (x << 1) + y; | ||
1006 | |||
1007 | switch(p) | ||
1008 | { | ||
1009 | case 0: l=0; s = 0; break; | ||
1010 | case 1: l=1; s = sgny; break; | ||
1011 | case 2: l=1; s = sgnx; break; | ||
1012 | case 3: l=2; s = (sgnx << 1) + sgny; break; | ||
1013 | case 4: l=1; s = sgnw; break; | ||
1014 | case 5: l=2; s = (sgnw << 1) + sgny; break; | ||
1015 | case 6: l=2; s = (sgnw << 1) + sgnx; break; | ||
1016 | case 7: l=3; s = (sgnw << 2) + (sgnx << 1) + sgny; break; | ||
1017 | case 8: l=1; s = sgnv; break; | ||
1018 | case 9: l=2; s = (sgnv << 1) + sgny; break; | ||
1019 | case 10: l=2; s = (sgnv << 1) + sgnx; break; | ||
1020 | case 11: l=3; s = (sgnv << 2) + (sgnx << 1) + sgny; break; | ||
1021 | case 12: l=2; s = (sgnv << 1) + sgnw; break; | ||
1022 | case 13: l=3; s = (sgnv << 2) + (sgnw << 1) + sgny; break; | ||
1023 | case 14: l=3; s = (sgnv << 2) + (sgnw << 1) + sgnx; break; | ||
1024 | case 15: l=4; s = (sgnv << 3) + (sgnw << 2) + (sgnx << 1) + sgny; break; | ||
1025 | } | 1126 | } |
1127 | else | ||
1128 | { | ||
1129 | /* No ESC-words */ | ||
1130 | const struct huffcodetab *h = &ht[table]; | ||
1131 | |||
1132 | for (uint32_t i = begin; i < end; i += 2) | ||
1133 | { | ||
1134 | int x = ix[i+0]; | ||
1135 | int y = ix[i+1]; | ||
1136 | |||
1137 | uint32_t idx = x * h->len + y; | ||
1138 | uint32_t code = h->table[idx]; | ||
1139 | int bit = h->hlen [idx]; | ||
1140 | |||
1141 | if (x) | ||
1142 | { | ||
1143 | code = (code << 1) | sign_x; | ||
1144 | bit += 1; | ||
1145 | } | ||
1146 | |||
1147 | if (y) | ||
1148 | { | ||
1149 | code = (code << 1) | sign_y; | ||
1150 | bit += 1; | ||
1151 | } | ||
1026 | 1152 | ||
1027 | d = (ht_count[tbl][0][p] << l) + s; | 1153 | putlong(code, bit); |
1028 | l = ht_count[tbl][1][p]; | 1154 | sumbit += bit; |
1029 | putlong( d, l ); | 1155 | } |
1030 | sumbit += l; | 1156 | } |
1031 | } | ||
1032 | 1157 | ||
1033 | /* flush remaining bits */ | 1158 | putlong_flush(); |
1034 | putbits(cc, sz); | ||
1035 | 1159 | ||
1036 | return sumbit; | 1160 | return sumbit; |
1037 | } | 1161 | } |
1038 | 1162 | ||
1039 | /* Implements the pseudocode of page 98 of the IS */ | 1163 | static int huffman_cod1(short *ix, char *xr_sign, uint32_t begin, |
1040 | int HuffmanCode(short *ix, char *xr_sign, uint32_t begin, uint32_t end, int table) | 1164 | uint32_t end, int tbl) |
1041 | { | 1165 | { |
1042 | uint32_t cc=0, sz=0, code; | 1166 | PUTLONG_INIT(); |
1043 | uint32_t i, xl=0, yl=0, idx; | ||
1044 | int x, y, bit, sumbit=0; | ||
1045 | #define sign_x xr_sign[i+0] | ||
1046 | #define sign_y xr_sign[i+1] | ||
1047 | 1167 | ||
1048 | if(table == 0) | 1168 | #define sgnv xr_sign[i+0] |
1049 | return 0; | 1169 | #define sgnw xr_sign[i+1] |
1050 | 1170 | #define sgnx xr_sign[i+2] | |
1051 | if( table > 15 ) | 1171 | #define sgny xr_sign[i+3] |
1052 | { /* ESC-table is used */ | ||
1053 | uint32_t linbits = ht_big[table-16].linbits; | ||
1054 | uint16_t *hffcode = table < 24 ? t16HB : t24HB; | ||
1055 | uint8_t *hlen = table < 24 ? t16l : t24l; | ||
1056 | 1172 | ||
1057 | for(i=begin; i<end; i+=2) | 1173 | int sumbit = 0, s = 0, l = 0; |
1174 | for (uint32_t i = begin; i < end; i += 4) | ||
1058 | { | 1175 | { |
1059 | x = ix[ i ]; | 1176 | int v = ix[i+0]; |
1060 | y = ix[i+1]; | 1177 | int w = ix[i+1]; |
1061 | 1178 | int x = ix[i+2]; | |
1062 | if(x > 14) { xl = x - 15; x = 15; } | 1179 | int y = ix[i+3]; |
1063 | if(y > 14) { yl = y - 15; y = 15; } | ||
1064 | 1180 | ||
1065 | idx = x * 16 + y; | 1181 | uint32_t p = (v << 3) + (w << 2) + (x << 1) + y; |
1066 | code = hffcode[idx]; | ||
1067 | bit = hlen [idx]; | ||
1068 | 1182 | ||
1069 | if(x) | 1183 | switch (p) |
1070 | { | ||
1071 | if(x > 14) | ||
1072 | { | 1184 | { |
1073 | code = (code << linbits) | xl; | 1185 | case 0: l=0; s = 0; break; |
1074 | bit += linbits; | 1186 | case 1: l=1; s = sgny; break; |
1187 | case 2: l=1; s = sgnx; break; | ||
1188 | case 3: l=2; s = (sgnx << 1) + sgny; break; | ||
1189 | case 4: l=1; s = sgnw; break; | ||
1190 | case 5: l=2; s = (sgnw << 1) + sgny; break; | ||
1191 | case 6: l=2; s = (sgnw << 1) + sgnx; break; | ||
1192 | case 7: l=3; s = (sgnw << 2) + (sgnx << 1) + sgny; break; | ||
1193 | case 8: l=1; s = sgnv; break; | ||
1194 | case 9: l=2; s = (sgnv << 1) + sgny; break; | ||
1195 | case 10: l=2; s = (sgnv << 1) + sgnx; break; | ||
1196 | case 11: l=3; s = (sgnv << 2) + (sgnx << 1) + sgny; break; | ||
1197 | case 12: l=2; s = (sgnv << 1) + sgnw; break; | ||
1198 | case 13: l=3; s = (sgnv << 2) + (sgnw << 1) + sgny; break; | ||
1199 | case 14: l=3; s = (sgnv << 2) + (sgnw << 1) + sgnx; break; | ||
1200 | case 15: l=4; s = (sgnv << 3) + (sgnw << 2) + (sgnx << 1) + sgny; break; | ||
1075 | } | 1201 | } |
1076 | 1202 | ||
1077 | code = (code << 1) | sign_x; | 1203 | uint32_t d = (ht_count[tbl][0][p] << l) + s; |
1078 | bit += 1; | 1204 | l = ht_count[tbl][1][p]; |
1079 | } | 1205 | putlong(d, l); |
1206 | sumbit += l; | ||
1207 | } | ||
1080 | 1208 | ||
1081 | if(y) | 1209 | putlong_flush(); |
1082 | { | ||
1083 | if(y > 14) | ||
1084 | { | ||
1085 | if(bit + linbits + 1 > 32) | ||
1086 | { | ||
1087 | putlong( code, bit ); | ||
1088 | sumbit += bit; | ||
1089 | code = bit = 0; | ||
1090 | } | ||
1091 | 1210 | ||
1092 | code = (code << linbits) | yl; | 1211 | return sumbit; |
1093 | bit += linbits; | 1212 | } |
1094 | } | ||
1095 | 1213 | ||
1096 | code = (code << 1) | sign_y; | 1214 | /* Note the discussion of huffmancodebits() on pages 28 and 29 of the IS, |
1097 | bit += 1; | 1215 | as well as the definitions of the side information on pages 26 and 27. */ |
1098 | } | 1216 | static void huffman_code_bits(short *ix, char *xr_sign, side_info_t *gi) |
1217 | { | ||
1218 | int region1 = gi->address1; | ||
1219 | int region2 = gi->address2; | ||
1220 | int bigvals = gi->address3; | ||
1221 | int count1 = bigvals + (gi->count1 << 2); | ||
1222 | int i, v; | ||
1099 | 1223 | ||
1100 | putlong( code, bit ); | 1224 | for (i = v = 0; i < 32; i += 2) |
1101 | sumbit += bit; | 1225 | v |= band_scale_f[i >> 1] << (30 - i); |
1102 | } | ||
1103 | } | ||
1104 | else | ||
1105 | { /* No ESC-words */ | ||
1106 | const struct huffcodetab *h = &ht[table]; | ||
1107 | 1226 | ||
1108 | for(i=begin; i<end; i+=2) | 1227 | putbits(v, 32); // store scale_facs (part1) |
1109 | { | ||
1110 | x = ix[i]; | ||
1111 | y = ix[i+1]; | ||
1112 | |||
1113 | idx = x * h->len + y; | ||
1114 | code = h->table[idx]; | ||
1115 | bit = h->hlen [idx]; | ||
1116 | |||
1117 | if(x) | ||
1118 | { | ||
1119 | code = (code << 1) | sign_x; | ||
1120 | bit += 1; | ||
1121 | } | ||
1122 | |||
1123 | if(y) | ||
1124 | { | ||
1125 | code = (code << 1) | sign_y; | ||
1126 | bit += 1; | ||
1127 | } | ||
1128 | |||
1129 | putlong( code, bit ); | ||
1130 | sumbit += bit; | ||
1131 | } | ||
1132 | } | ||
1133 | 1228 | ||
1134 | /* flush remaining bits */ | 1229 | for (v = 0; i < 42; i += 2) |
1135 | putbits(cc, sz); | 1230 | v |= band_scale_f[i >> 1] << (40 - i); |
1136 | 1231 | ||
1137 | return sumbit; | 1232 | putbits(v, 10); // store scale_facs (part2) |
1138 | } | ||
1139 | 1233 | ||
1140 | void putbits(uint32_t val, uint32_t nbit) | 1234 | int bits = 0; |
1141 | { | ||
1142 | int new_bitpos = CodedData.bitpos + nbit; | ||
1143 | int ptrpos = CodedData.bitpos >> 5; | ||
1144 | 1235 | ||
1145 | val = val & (0xffffffff >> (32 - nbit)); | 1236 | if (region1 > 0) |
1237 | bits += huffman_code(ix, xr_sign, 0, region1, gi->table_select[0]); | ||
1146 | 1238 | ||
1147 | /* data fit in one uint32_t */ | 1239 | if (region2 > region1) |
1148 | if(((new_bitpos - 1) >> 5) == ptrpos) | 1240 | bits += huffman_code(ix, xr_sign, region1, region2, gi->table_select[1]); |
1149 | CodedData.bbuf[ptrpos] |= val << ((32 - new_bitpos) & 31); | ||
1150 | else | ||
1151 | { | ||
1152 | CodedData.bbuf[ptrpos ] |= val >> ((new_bitpos - 32) & 31); | ||
1153 | CodedData.bbuf[ptrpos+1] |= val << ((32 - new_bitpos) & 31); | ||
1154 | } | ||
1155 | 1241 | ||
1156 | CodedData.bitpos = new_bitpos; | 1242 | if (bigvals > region2) |
1157 | } | 1243 | bits += huffman_code(ix, xr_sign, region2, bigvals, gi->table_select[2]); |
1158 | 1244 | ||
1159 | /***************************************************************************/ | 1245 | if (count1 > bigvals) |
1160 | /* Choose the Huffman table that will encode ix[begin..end] with */ | 1246 | bits += huffman_cod1(ix, xr_sign, bigvals, count1, gi->table_select[3]); |
1161 | /* the fewest bits. */ | ||
1162 | /* Note: This code contains knowledge about the sizes and characteristic */ | ||
1163 | /* of the Huffman tables as defined in the IS (Table B.7), and will not */ | ||
1164 | /* work with any arbitrary tables. */ | ||
1165 | /***************************************************************************/ | ||
1166 | static int choose_table( short *ix, uint32_t begin, uint32_t end, int *bits ) | ||
1167 | { | ||
1168 | uint32_t i; | ||
1169 | int max, table0, table1; | ||
1170 | 1247 | ||
1171 | for(i=begin,max=0; i<end; i++) | 1248 | int stuff_bits = gi->part2_3_length - bits; |
1172 | if(ix[i] > max) | ||
1173 | max = ix[i]; | ||
1174 | 1249 | ||
1175 | if(max < 16) | 1250 | if (stuff_bits > 0) |
1176 | { | ||
1177 | /* tables without linbits */ | ||
1178 | /* indx: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ | ||
1179 | /* len: 0, 2, 3, 3, 0, 4, 4, 6, 6, 6, 8, 8, 8, 16, 0, 16 */ | ||
1180 | switch(max) | ||
1181 | { | 1251 | { |
1182 | case 0: return 0; | 1252 | int stuff_words = stuff_bits >> 5; |
1183 | case 1: return count_bit1(ix, begin, end, bits); | 1253 | int remain_bits = stuff_bits & 31; |
1184 | case 2: return 2 + find_best_2(ix, begin, end, tab23, 3, bits); | 1254 | |
1185 | case 3: return 5 + find_best_2(ix, begin, end, tab56, 4, bits); | 1255 | if (remain_bits) |
1186 | case 4: | 1256 | putbits(~0, remain_bits); |
1187 | case 5: return 7 + find_best_3(ix, begin, end, tab789, 6, bits); | 1257 | |
1188 | case 6: | 1258 | while (stuff_words--) |
1189 | case 7: return 10 + find_best_3(ix, begin, end, tabABC, 8, bits); | 1259 | putbits(~0, 32); /* Huffman code tables leed to padding ones */ |
1190 | default: return 13 + find_best_2(ix, begin, end, tab1315, 16, bits) * 2; | ||
1191 | } | 1260 | } |
1192 | } | ||
1193 | else | ||
1194 | { | ||
1195 | /* tables with linbits */ | ||
1196 | max -= 15; | ||
1197 | |||
1198 | for(table0=0; table0<8; table0++) | ||
1199 | if(ht_big[table0].linmax >= max) | ||
1200 | break; | ||
1201 | |||
1202 | for(table1=8; table1<16; table1++) | ||
1203 | if(ht_big[table1].linmax >= max) | ||
1204 | break; | ||
1205 | |||
1206 | return 16 + count_bigv(ix, begin, end, table0, table1, bits); | ||
1207 | } | ||
1208 | } | 1261 | } |
1209 | 1262 | ||
1210 | int find_best_2(short *ix, uint32_t start, uint32_t end, const uint32_t *table, | 1263 | /*************************************************************************/ |
1211 | uint32_t len, int *bits) | 1264 | /* Function: Count the number of bits necessary to code the subregion. */ |
1265 | /*************************************************************************/ | ||
1266 | static int count_bit1(short *ix, uint32_t start, uint32_t end, int *bits) | ||
1212 | { | 1267 | { |
1213 | uint32_t i, sum = 0; | 1268 | int sum = 0; |
1214 | 1269 | ||
1215 | for(i=start; i<end; i+=2) | 1270 | for (uint32_t i = start; i < end; i += 2) |
1216 | sum += table[ix[i] * len + ix[i+1]]; | 1271 | sum += t1l[4 + ix[i] * 2 + ix[i + 1]]; |
1217 | 1272 | ||
1218 | if((sum & 0xffff) <= (sum >> 16)) | 1273 | *bits = sum; |
1219 | { | 1274 | |
1220 | *bits = (sum & 0xffff); | 1275 | return 1; /* this is table1 */ |
1221 | return 1; | ||
1222 | } | ||
1223 | else | ||
1224 | { | ||
1225 | *bits = sum >> 16; | ||
1226 | return 0; | ||
1227 | } | ||
1228 | } | 1276 | } |
1229 | 1277 | ||
1230 | int find_best_3(short *ix, uint32_t start, uint32_t end, const uint32_t *table, | 1278 | static int count_bigv(short *ix, uint32_t start, uint32_t end, int table0, |
1231 | uint32_t len, int *bits) | 1279 | int table1, int *bits) |
1232 | { | 1280 | { |
1233 | uint32_t i, j, sum = 0; | 1281 | uint32_t sum = 0, bigv = 0; |
1234 | int sum1 = 0; | ||
1235 | int sum2 = 0; | ||
1236 | int sum3 = 0; | ||
1237 | 1282 | ||
1238 | /* avoid overflow in packed additions: 78*13 < 1024 */ | 1283 | /* ESC-table is used */ |
1239 | for(i=start; i<end; ) | 1284 | for (uint32_t i = start; i < end; i += 2) |
1240 | { | 1285 | { |
1241 | j = i + 2*78 > end ? end : i + 2*78; | 1286 | uint32_t x = ix[i+0]; |
1287 | uint32_t y = ix[i+1]; | ||
1242 | 1288 | ||
1243 | for(sum=0; i<j; i+=2) | 1289 | if (x > 14) { x = 15; bigv++; } |
1244 | sum += table[ix[i] * len + ix[i+1]]; | 1290 | if (y > 14) { y = 15; bigv++; } |
1245 | 1291 | ||
1246 | sum1 += (sum >> 20); | 1292 | sum += tab1624[x * 16 + y]; |
1247 | sum2 += (sum >> 10) & 0x3ff; | 1293 | } |
1248 | sum3 += (sum >> 0) & 0x3ff; | ||
1249 | } | ||
1250 | 1294 | ||
1251 | i = 0; | 1295 | int sum0 = (sum >> 16) + bigv * ht_big[table0].linbits; |
1252 | if(sum1 > sum2) { sum1 = sum2; i = 1; } | 1296 | int sum1 = (sum & 0xffff) + bigv * ht_big[table1].linbits; |
1253 | if(sum1 > sum3) { sum1 = sum3; i = 2; } | ||
1254 | 1297 | ||
1255 | *bits = sum1; | 1298 | if (sum0 <= sum1) |
1299 | { | ||
1300 | *bits = sum0; | ||
1301 | return table0; | ||
1302 | } | ||
1303 | else | ||
1304 | { | ||
1305 | *bits = sum1; | ||
1306 | return table1; | ||
1307 | } | ||
1308 | } | ||
1256 | 1309 | ||
1257 | return i; | 1310 | static int find_best_2(short *ix, uint32_t start, uint32_t end, |
1311 | const uint32_t *table, uint32_t len, int *bits) | ||
1312 | { | ||
1313 | uint32_t sum = 0; | ||
1314 | |||
1315 | for (uint32_t i = start; i < end; i += 2) | ||
1316 | sum += table[ix[i] * len + ix[i + 1]]; | ||
1317 | |||
1318 | if ((sum & 0xffff) <= (sum >> 16)) | ||
1319 | { | ||
1320 | *bits = sum & 0xffff; | ||
1321 | return 1; | ||
1322 | } | ||
1323 | else | ||
1324 | { | ||
1325 | *bits = sum >> 16; | ||
1326 | return 0; | ||
1327 | } | ||
1258 | } | 1328 | } |
1259 | 1329 | ||
1260 | /*************************************************************************/ | 1330 | static int find_best_3(short *ix, uint32_t start, uint32_t end, |
1261 | /* Function: Count the number of bits necessary to code the subregion. */ | 1331 | const uint32_t *table, uint32_t len, int *bits) |
1262 | /*************************************************************************/ | ||
1263 | int count_bit1(short *ix, uint32_t start, uint32_t end, int *bits ) | ||
1264 | { | 1332 | { |
1265 | uint32_t i, sum = 0; | 1333 | int sum1 = 0; |
1334 | int sum2 = 0; | ||
1335 | int sum3 = 0; | ||
1266 | 1336 | ||
1267 | for(i=start; i<end; i+=2) | 1337 | /* avoid overflow in packed additions: 78*13 < 1024 */ |
1268 | sum += t1l[4 + ix[i] * 2 + ix[i+1]]; | 1338 | for (uint32_t i = start; i < end;) |
1339 | { | ||
1340 | uint32_t j = i + 2*78 > end ? end : i + 2*78; | ||
1341 | |||
1342 | uint32_t sum = 0; | ||
1343 | for (; i < j; i += 2) | ||
1344 | sum += table[ix[i] * len + ix[i + 1]]; | ||
1345 | |||
1346 | sum1 += (sum >> 20); | ||
1347 | sum2 += (sum >> 10) & 0x3ff; | ||
1348 | sum3 += (sum >> 0) & 0x3ff; | ||
1349 | } | ||
1350 | |||
1351 | int r = 0; | ||
1352 | if (sum1 > sum2) { sum1 = sum2; r = 1; } | ||
1353 | if (sum1 > sum3) { sum1 = sum3; r = 2; } | ||
1269 | 1354 | ||
1270 | *bits = sum; | 1355 | *bits = sum1; |
1271 | 1356 | ||
1272 | return 1; /* this is table1 */ | 1357 | return r; |
1273 | } | 1358 | } |
1274 | 1359 | ||
1275 | int count_bigv(short *ix, uint32_t start, uint32_t end, int table0, | 1360 | /***************************************************************************/ |
1276 | int table1, int *bits ) | 1361 | /* Choose the Huffman table that will encode ix[begin..end] with */ |
1362 | /* the fewest bits. */ | ||
1363 | /* Note: This code contains knowledge about the sizes and characteristic */ | ||
1364 | /* of the Huffman tables as defined in the IS (Table B.7), and will not */ | ||
1365 | /* work with any arbitrary tables. */ | ||
1366 | /***************************************************************************/ | ||
1367 | static int choose_table(short *ix, uint32_t begin, uint32_t end, int *bits) | ||
1277 | { | 1368 | { |
1278 | uint32_t i, sum0, sum1, sum=0, bigv=0, x, y; | 1369 | int max = 0; |
1370 | for (uint32_t i = begin; i < end; i++) | ||
1371 | { | ||
1372 | if (ix[i] > max) | ||
1373 | max = ix[i]; | ||
1374 | } | ||
1279 | 1375 | ||
1280 | /* ESC-table is used */ | 1376 | if (max < 16) |
1281 | for(i=start; i<end; i+=2) | 1377 | { |
1282 | { | 1378 | /* tables without linbits */ |
1283 | x = ix[i]; | 1379 | /* indx: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ |
1284 | y = ix[i+1]; | 1380 | /* len: 0, 2, 3, 3, 0, 4, 4, 6, 6, 6, 8, 8, 8, 16, 0, 16 */ |
1381 | switch (max) | ||
1382 | { | ||
1383 | case 0: return 0; | ||
1384 | case 1: return count_bit1(ix, begin, end, bits); | ||
1385 | case 2: return 2 + find_best_2(ix, begin, end, tab23, 3, bits); | ||
1386 | case 3: return 5 + find_best_2(ix, begin, end, tab56, 4, bits); | ||
1387 | case 4: | ||
1388 | case 5: return 7 + find_best_3(ix, begin, end, tab789, 6, bits); | ||
1389 | case 6: | ||
1390 | case 7: return 10 + find_best_3(ix, begin, end, tabABC, 8, bits); | ||
1391 | default: return 13 + find_best_2(ix, begin, end, tab1315, 16, bits)*2; | ||
1392 | } | ||
1393 | } | ||
1394 | else | ||
1395 | { | ||
1396 | /* tables with linbits */ | ||
1397 | max -= 15; | ||
1285 | 1398 | ||
1286 | if(x > 14) { x = 15; bigv++; } | 1399 | int table0, table1; |
1287 | if(y > 14) { y = 15; bigv++; } | ||
1288 | 1400 | ||
1289 | sum += tab1624[x * 16 + y]; | 1401 | for (table0 = 0; table0 < 8; table0++) |
1290 | } | 1402 | { |
1403 | if (ht_big[table0].linmax >= max) | ||
1404 | break; | ||
1405 | } | ||
1291 | 1406 | ||
1292 | sum0 = (sum >> 16) + bigv * ht_big[table0].linbits; | 1407 | for (table1 = 8; table1 < 16; table1++) |
1293 | sum1 = (sum & 0xffff) + bigv * ht_big[table1].linbits; | 1408 | { |
1409 | if (ht_big[table1].linmax >= max) | ||
1410 | break; | ||
1411 | } | ||
1294 | 1412 | ||
1295 | if(sum0 <= sum1) | 1413 | return 16 + count_bigv(ix, begin, end, table0, table1, bits); |
1296 | { | 1414 | } |
1297 | *bits = sum0; | ||
1298 | return table0; | ||
1299 | } | ||
1300 | else | ||
1301 | { | ||
1302 | *bits = sum1; | ||
1303 | return table1; | ||
1304 | } | ||
1305 | } | 1415 | } |
1306 | 1416 | ||
1307 | /*************************************************************************/ | 1417 | /*************************************************************************/ |
1308 | /* Function: Calculation of rzero, count1, address3 */ | 1418 | /* Function: Calculation of rzero, count1, address3 */ |
1309 | /* (Partitions ix into big values, quadruples and zeros). */ | 1419 | /* (Partitions ix into big values, quadruples and zeros). */ |
1310 | /*************************************************************************/ | 1420 | /*************************************************************************/ |
1311 | static int calc_runlen( short *ix, side_info_t *si ) | 1421 | static int calc_runlen(short *ix, side_info_t *si) |
1312 | { | 1422 | { |
1313 | int p, i, sum = 0; | 1423 | int i = 576; |
1314 | 1424 | ||
1315 | for(i=SAMPL2; i-=2; ) | 1425 | while (i -= 2) |
1316 | if(*(uint32_t*)&ix[i-2]) /* !!!! short *ix; !!!!! */ | 1426 | { |
1317 | break; | 1427 | if (*(uint32_t *)&ix[i - 2]) /* !!!! short *ix; !!!!! */ |
1318 | 1428 | break; | |
1319 | si->count1 = 0; | 1429 | } |
1320 | 1430 | ||
1321 | for( ; i>3; i-=4) | 1431 | si->count1 = 0; |
1322 | { | ||
1323 | int v = ix[i-1]; | ||
1324 | int w = ix[i-2]; | ||
1325 | int x = ix[i-3]; | ||
1326 | int y = ix[i-4]; | ||
1327 | 1432 | ||
1328 | if((v | w | x | y) <= 1) | 1433 | int sum = 0; |
1434 | for ( ; i > 3; i -= 4) | ||
1329 | { | 1435 | { |
1330 | p = (y<<3) + (x<<2) + (w<<1) + (v); | 1436 | int v = ix[i-1]; |
1437 | int w = ix[i-2]; | ||
1438 | int x = ix[i-3]; | ||
1439 | int y = ix[i-4]; | ||
1440 | |||
1441 | if ((v | w | x | y) <= 1) | ||
1442 | { | ||
1443 | int p = (y << 3) + (x << 2) + (w << 1) + (v); | ||
1444 | sum += tab01[p]; | ||
1445 | si->count1++; | ||
1446 | } | ||
1447 | else | ||
1448 | { | ||
1449 | break; | ||
1450 | } | ||
1451 | } | ||
1331 | 1452 | ||
1332 | sum += tab01[p]; | 1453 | si->address3 = i; |
1333 | 1454 | ||
1334 | si->count1++; | 1455 | if ((sum >> 16) < (sum & 0xffff)) |
1456 | { | ||
1457 | si->table_select[3] = 0; | ||
1458 | return sum >> 16; | ||
1459 | } | ||
1460 | else | ||
1461 | { | ||
1462 | si->table_select[3] = 1; | ||
1463 | return sum & 0xffff; | ||
1335 | } | 1464 | } |
1336 | else break; | ||
1337 | } | ||
1338 | |||
1339 | si->address3 = i; | ||
1340 | |||
1341 | if((sum >> 16) < (sum & 0xffff)) | ||
1342 | { | ||
1343 | si->table_select[3] = 0; | ||
1344 | return sum >> 16; | ||
1345 | } | ||
1346 | else | ||
1347 | { | ||
1348 | si->table_select[3] = 1; | ||
1349 | return sum & 0xffff; | ||
1350 | } | ||
1351 | } | 1465 | } |
1352 | 1466 | ||
1353 | |||
1354 | /*************************************************************************/ | 1467 | /*************************************************************************/ |
1355 | /* Function: Quantization of the vector xr ( -> ix) */ | 1468 | /* Function: Quantization of the vector xr ( -> ix) */ |
1356 | /*************************************************************************/ | 1469 | /*************************************************************************/ |
1357 | static int quantize_int(int *xr, short *ix, side_info_t *si) | 1470 | static int quantize_int(int *xr, short *ix, side_info_t *si) |
1358 | { | 1471 | { |
1359 | unsigned int i, idx, s, frac_pow[] = { 0x10000, 0xd745, 0xb505, 0x9838 }; | 1472 | static const unsigned int frac_pow[] ICONST_ATTR = |
1473 | { 0x10000, 0xd745, 0xb505, 0x9838 }; | ||
1360 | 1474 | ||
1361 | s = frac_pow[si->quantStep & 3] >> si->quantStep / 4; | 1475 | unsigned s = frac_pow[si->quantStep & 3] >> si->quantStep / 4; |
1362 | 1476 | ||
1363 | /* check for possible 'out of range' values */ | 1477 | /* check for possible 'out of range' values */ |
1364 | if(((si->max_val + 256) >> 8) * s >= (65536 << 8)) | 1478 | if (((si->max_val + 256) >> 8) * s >= (65536 << 8)) |
1365 | return 0; | 1479 | return 0; |
1366 | 1480 | ||
1367 | if(((si->max_val + 256) >> 8) * s < (4096 << 8)) | 1481 | if (((si->max_val + 256) >> 8) * s < (4096 << 8)) |
1368 | { /* all values fit the table size */ | 1482 | { |
1369 | for(i=SAMPL2; i--; ) | 1483 | /* all values fit the table size */ |
1370 | ix[i] = int2idx[(xr[i] * s + 0x8000) >> 16]; | 1484 | for (int i = 576; i--; ) |
1371 | } | 1485 | ix[i] = int2idx[(xr[i] * s + 0x8000) >> 16]; |
1372 | else | 1486 | } |
1373 | { /* check each index wether it fits the table */ | 1487 | else |
1374 | for(i=SAMPL2; i--; ) | ||
1375 | { | 1488 | { |
1376 | idx = (xr[i] * s + 0x08000) >> 16; | 1489 | /* check each index wether it fits the table */ |
1490 | for (int i = 576; i--; ) | ||
1491 | { | ||
1492 | unsigned idx = (xr[i] * s + 0x08000) >> 16; | ||
1377 | 1493 | ||
1378 | if(idx > 4095) ix[i] = int2idx[(idx + 8) >> 4] << 3; | 1494 | if (idx > 4095) ix[i] = int2idx[(idx + 8) >> 4] << 3; |
1379 | else ix[i] = int2idx[idx]; | 1495 | else ix[i] = int2idx[idx]; |
1496 | } | ||
1380 | } | 1497 | } |
1381 | } | ||
1382 | 1498 | ||
1383 | return 1; | 1499 | return 1; |
1384 | } | 1500 | } |
1385 | 1501 | ||
1386 | /*************************************************************************/ | 1502 | /*************************************************************************/ |
@@ -1388,27 +1504,27 @@ static int quantize_int(int *xr, short *ix, side_info_t *si) | |||
1388 | /*************************************************************************/ | 1504 | /*************************************************************************/ |
1389 | static void subdivide(side_info_t *si) | 1505 | static void subdivide(side_info_t *si) |
1390 | { | 1506 | { |
1391 | int scfb, count0, count1; | 1507 | if (!si->address3) |
1392 | 1508 | { | |
1393 | if( !si->address3 ) | 1509 | /* no bigvalue region */ |
1394 | { /* no bigvalue region */ | 1510 | si->region_0_1 = 0; |
1395 | si->region_0_1 = 0; | 1511 | si->address1 = 0; |
1396 | si->address1 = 0; | 1512 | si->address2 = 0; |
1397 | si->address2 = 0; | 1513 | } |
1398 | } | 1514 | else |
1399 | else | 1515 | { |
1400 | { | 1516 | /* Calculate scale factor band index */ |
1401 | /* Calculate scale factor band index */ | 1517 | int scfb = 1; |
1402 | for(scfb=0; scalefac[scfb] < si->address3; ) | 1518 | while (scalefac[scfb] < si->address3) |
1403 | scfb++; | 1519 | scfb++; |
1404 | 1520 | ||
1405 | count0 = subdv_table[scfb].region0_cnt; | 1521 | int count0 = subdv_table[scfb].region0_cnt; |
1406 | count1 = subdv_table[scfb].region1_cnt; | 1522 | int count1 = subdv_table[scfb].region1_cnt; |
1407 | 1523 | ||
1408 | si->region_0_1 = (count0 << 3) | count1; | 1524 | si->region_0_1 = (count0 << 3) | count1; |
1409 | si->address1 = scalefac[count0 + 1]; | 1525 | si->address1 = scalefac[count0]; |
1410 | si->address2 = scalefac[count0 + 1 + count1 + 1]; | 1526 | si->address2 = scalefac[count0 + count1 + 1]; |
1411 | } | 1527 | } |
1412 | } | 1528 | } |
1413 | 1529 | ||
1414 | /*******************************************************************/ | 1530 | /*******************************************************************/ |
@@ -1416,37 +1532,37 @@ static void subdivide(side_info_t *si) | |||
1416 | /*******************************************************************/ | 1532 | /*******************************************************************/ |
1417 | static int bigv_bitcount(short *ix, side_info_t *gi) | 1533 | static int bigv_bitcount(short *ix, side_info_t *gi) |
1418 | { | 1534 | { |
1419 | int b1=0, b2=0, b3=0; | 1535 | int b1 = 0, b2 = 0, b3 = 0; |
1420 | 1536 | ||
1421 | /* Select huffman code tables for bigvalues regions */ | 1537 | /* Select huffman code tables for bigvalues regions */ |
1422 | gi->table_select[0] = 0; | 1538 | gi->table_select[0] = 0; |
1423 | gi->table_select[1] = 0; | 1539 | gi->table_select[1] = 0; |
1424 | gi->table_select[2] = 0; | 1540 | gi->table_select[2] = 0; |
1425 | 1541 | ||
1426 | if( gi->address1 > 0 ) /* region0 */ | 1542 | if (gi->address1 > 0) /* region0 */ |
1427 | gi->table_select[0] = choose_table(ix, 0 , gi->address1, &b1); | 1543 | gi->table_select[0] = choose_table(ix, 0, gi->address1, &b1); |
1428 | 1544 | ||
1429 | if( gi->address2 > gi->address1 ) /* region1 */ | 1545 | if (gi->address2 > gi->address1) /* region1 */ |
1430 | gi->table_select[1] = choose_table(ix, gi->address1, gi->address2, &b2); | 1546 | gi->table_select[1] = choose_table(ix, gi->address1, gi->address2, &b2); |
1431 | 1547 | ||
1432 | if( gi->address3 > gi->address2 ) /* region2 */ | 1548 | if (gi->address3 > gi->address2) /* region2 */ |
1433 | gi->table_select[2] = choose_table(ix, gi->address2, gi->address3, &b3); | 1549 | gi->table_select[2] = choose_table(ix, gi->address2, gi->address3, &b3); |
1434 | 1550 | ||
1435 | return b1+b2+b3; | 1551 | return b1 + b2 + b3; |
1436 | } | 1552 | } |
1437 | 1553 | ||
1438 | static int quantize_and_count_bits(int *xr, short *ix, side_info_t *si) | 1554 | static int quantize_and_count_bits(int *xr, short *ix, side_info_t *si) |
1439 | { | 1555 | { |
1440 | int bits = 10000; | 1556 | int bits = 10000; |
1441 | 1557 | ||
1442 | if(quantize_int(xr, ix, si)) | 1558 | if (quantize_int(xr, ix, si)) |
1443 | { | 1559 | { |
1444 | bits = calc_runlen(ix, si); /* rzero,count1,address3 */ | 1560 | bits = calc_runlen(ix, si); /* rzero,count1,address3 */ |
1445 | subdivide(si); /* bigvalues sfb division */ | 1561 | subdivide(si); /* bigvalues sfb division */ |
1446 | bits += bigv_bitcount(ix,si); /* bit count */ | 1562 | bits += bigv_bitcount(ix,si); /* bit count */ |
1447 | } | 1563 | } |
1448 | 1564 | ||
1449 | return bits; | 1565 | return bits; |
1450 | } | 1566 | } |
1451 | 1567 | ||
1452 | /************************************************************************/ | 1568 | /************************************************************************/ |
@@ -1454,509 +1570,685 @@ static int quantize_and_count_bits(int *xr, short *ix, side_info_t *si) | |||
1454 | /************************************************************************/ | 1570 | /************************************************************************/ |
1455 | static int inner_loop(int *xr, int max_bits, side_info_t *si) | 1571 | static int inner_loop(int *xr, int max_bits, side_info_t *si) |
1456 | { | 1572 | { |
1457 | int bits; | 1573 | int bits; |
1458 | 1574 | ||
1459 | while((bits=quantize_and_count_bits(xr, enc_data, si)) < max_bits-64) | 1575 | while ((bits = quantize_and_count_bits(xr, enc_data, si)) < max_bits - 64) |
1460 | { | 1576 | { |
1461 | if(si->quantStep == 0) | 1577 | if (si->quantStep == 0) |
1462 | break; | 1578 | break; |
1463 | 1579 | ||
1464 | if(si->quantStep <= 2) | 1580 | if (si->quantStep <= 2) |
1465 | si->quantStep = 0; | 1581 | si->quantStep = 0; |
1466 | else | 1582 | else |
1467 | si->quantStep -= 2; | 1583 | si->quantStep -= 2; |
1468 | } | 1584 | } |
1469 | 1585 | ||
1470 | while(bits > max_bits) | 1586 | while (bits > max_bits) |
1471 | { | 1587 | { |
1472 | si->quantStep++; | 1588 | si->quantStep++; |
1473 | bits = quantize_and_count_bits(xr, enc_data, si); | 1589 | bits = quantize_and_count_bits(xr, enc_data, si); |
1474 | } | 1590 | } |
1475 | 1591 | ||
1476 | return bits; | 1592 | return bits; |
1477 | } | 1593 | } |
1478 | 1594 | ||
1479 | static void iteration_loop(int *xr, side_info_t *si, int gr_cnt) | 1595 | static void iteration_loop(int *xr, side_info_t *si, int gr_cnt) |
1480 | { | 1596 | { |
1481 | int remain, tar_bits, max_bits = cfg.mean_bits; | 1597 | int max_bits = cfg.mean_bits; |
1598 | |||
1599 | /* distribute reserved bits to remaining granules */ | ||
1600 | int tar_bits = max_bits + (cfg.resv_size / gr_cnt & ~7); | ||
1482 | 1601 | ||
1483 | /* distribute reserved bits to remaining granules */ | 1602 | if (tar_bits > max_bits + max_bits / 2) |
1484 | tar_bits = max_bits + (cfg.ResvSize / gr_cnt & ~7); | 1603 | tar_bits = max_bits + max_bits / 2; |
1485 | if(tar_bits > max_bits + max_bits/2) | ||
1486 | tar_bits = max_bits + max_bits/2; | ||
1487 | 1604 | ||
1488 | si->part2_3_length = inner_loop(xr, tar_bits, si); | 1605 | si->part2_3_length = inner_loop(xr, tar_bits, si); |
1489 | si->global_gain = si->quantStep + 142 - si->additStep; | 1606 | si->global_gain = si->quantStep + 142 - si->additStep; |
1490 | 1607 | ||
1491 | /* unused bits of the reservoir can be used for remaining granules */ | 1608 | /* unused bits of the reservoir can be used for remaining granules */ |
1492 | cfg.ResvSize += max_bits - si->part2_3_length; | 1609 | cfg.resv_size += max_bits - si->part2_3_length; |
1493 | 1610 | ||
1494 | /* end: distribute the reserved bits to one or two granules */ | 1611 | /* end: distribute the reserved bits to one or two granules */ |
1495 | if(gr_cnt == 1) | 1612 | if (gr_cnt == 1) |
1496 | { | ||
1497 | si->part2_3_length += cfg.ResvSize; | ||
1498 | /* mp3 format allows max 12bits for granule length */ | ||
1499 | if(si->part2_3_length > 4092) | ||
1500 | { | 1613 | { |
1501 | remain = (si->part2_3_length - 4092 + 31) >> 5; | 1614 | si->part2_3_length += cfg.resv_size; |
1502 | si->part2_3_length -= remain << 5; | 1615 | |
1503 | si[-1].part2_3_length += remain << 5; | 1616 | /* mp3 format allows max 12bits for granule length */ |
1617 | if (si->part2_3_length > 4092) | ||
1618 | { | ||
1619 | int remain = (si->part2_3_length - 4092 + 31) >> 5; | ||
1620 | si->part2_3_length -= remain << 5; | ||
1621 | si[-1].part2_3_length += remain << 5; | ||
1504 | 1622 | ||
1505 | while(remain--) | 1623 | while (remain--) |
1506 | putbits(~0, 32); | 1624 | putbits(~0, 32); |
1625 | } | ||
1507 | } | 1626 | } |
1508 | } | ||
1509 | } | 1627 | } |
1510 | 1628 | ||
1511 | |||
1512 | /* returns sum_j=0^31 a[j]*cos(PI*j*(k+1/2)/32), 0<=k<32 */ | 1629 | /* returns sum_j=0^31 a[j]*cos(PI*j*(k+1/2)/32), 0<=k<32 */ |
1513 | static void ICODE_ATTR window_subband1(short *wk, int sb0[SBLIMIT], | 1630 | #ifdef CPU_COLDFIRE |
1514 | int sb1[SBLIMIT]) | 1631 | static void ICODE_ATTR window_subband1_s(const short *wk, int a0[32], |
1632 | int a1[32]) | ||
1515 | { | 1633 | { |
1516 | int k, i, u, v; | 1634 | for (int k = 0; k < 18; k++, wk += 64, a0 += 32, a1 += 32) |
1517 | short *wp, *x1, *x2; | 1635 | { |
1636 | const short *wp = enwindow; | ||
1637 | const short *x1 = wk; | ||
1638 | const short *x2 = x1 - 124; | ||
1639 | int s0, s1, t0, t1; | ||
1518 | 1640 | ||
1519 | #ifdef CPU_COLDFIRE | 1641 | for (int i = -15; i < 0; i++) |
1520 | int s0, s1, t0, t1; | 1642 | { |
1643 | asm volatile ( | ||
1644 | "movem.l (%[wp]), %%d0-%%d3 \n" | ||
1645 | "move.l (-224*4,%[x2]), %%d4 \n" | ||
1646 | "mac.w %%d0u, %%d4u, %%acc0 \n" | ||
1647 | "mac.w %%d0u, %%d4l, (-160*4,%[x2]), %%d4, %%acc1 \n" | ||
1648 | "mac.w %%d0l, %%d4u, %%acc0 \n" | ||
1649 | "mac.w %%d0l, %%d4l, ( -96*4,%[x2]), %%d4, %%acc1 \n" | ||
1650 | "mac.w %%d1u, %%d4u, %%acc0 \n" | ||
1651 | "mac.w %%d1u, %%d4l, ( -32*4,%[x2]), %%d4, %%acc1 \n" | ||
1652 | "mac.w %%d1l, %%d4u, %%acc0 \n" | ||
1653 | "mac.w %%d1l, %%d4l, ( 32*4,%[x2]), %%d4, %%acc1 \n" | ||
1654 | "mac.w %%d2u, %%d4u, %%acc0 \n" | ||
1655 | "mac.w %%d2u, %%d4l, ( 96*4,%[x2]), %%d4, %%acc1 \n" | ||
1656 | "mac.w %%d2l, %%d4u, %%acc0 \n" | ||
1657 | "mac.w %%d2l, %%d4l, ( 160*4,%[x2]), %%d4, %%acc1 \n" | ||
1658 | "mac.w %%d3u, %%d4u, %%acc0 \n" | ||
1659 | "mac.w %%d3u, %%d4l, ( 224*4,%[x2]), %%d4, %%acc1 \n" | ||
1660 | "mac.w %%d3l, %%d4u, %%acc0 \n" | ||
1661 | "mac.w %%d3l, %%d4l, ( 224*4,%[x1]), %%d4, %%acc1 \n" | ||
1662 | "mac.w %%d0u, %%d4u, %%acc2 \n" | ||
1663 | "mac.w %%d0u, %%d4l, ( 160*4,%[x1]), %%d4, %%acc3 \n" | ||
1664 | "mac.w %%d0l, %%d4u, %%acc2 \n" | ||
1665 | "mac.w %%d0l, %%d4l, ( 96*4,%[x1]), %%d4, %%acc3 \n" | ||
1666 | "mac.w %%d1u, %%d4u, %%acc2 \n" | ||
1667 | "mac.w %%d1u, %%d4l, ( 32*4,%[x1]), %%d4, %%acc3 \n" | ||
1668 | "mac.w %%d1l, %%d4u, %%acc2 \n" | ||
1669 | "mac.w %%d1l, %%d4l, ( -32*4,%[x1]), %%d4, %%acc3 \n" | ||
1670 | "mac.w %%d2u, %%d4u, %%acc2 \n" | ||
1671 | "mac.w %%d2u, %%d4l, ( -96*4,%[x1]), %%d4, %%acc3 \n" | ||
1672 | "mac.w %%d2l, %%d4u, %%acc2 \n" | ||
1673 | "mac.w %%d2l, %%d4l, (-160*4,%[x1]), %%d4, %%acc3 \n" | ||
1674 | "mac.w %%d3u, %%d4u, %%acc2 \n" | ||
1675 | "mac.w %%d3u, %%d4l, (-224*4,%[x1]), %%d4, %%acc3 \n" | ||
1676 | "mac.w %%d3l, %%d4u, %%acc2 \n" | ||
1677 | "mac.w %%d3l, %%d4l, (-256*4,%[x1]), %%d4, %%acc3 \n" | ||
1678 | "movem.l (16,%[wp]), %%d0-%%d3 \n" | ||
1679 | "mac.w %%d0u, %%d4u, %%acc0 \n" | ||
1680 | "mac.w %%d0u, %%d4l, (-192*4,%[x1]), %%d4, %%acc1 \n" | ||
1681 | "mac.w %%d0l, %%d4u, %%acc0 \n" | ||
1682 | "mac.w %%d0l, %%d4l, (-128*4,%[x1]), %%d4, %%acc1 \n" | ||
1683 | "mac.w %%d1u, %%d4u, %%acc0 \n" | ||
1684 | "mac.w %%d1u, %%d4l, ( -64*4,%[x1]), %%d4, %%acc1 \n" | ||
1685 | "mac.w %%d1l, %%d4u, %%acc0 \n" | ||
1686 | "mac.w %%d1l, %%d4l, ( 0*4,%[x1]), %%d4, %%acc1 \n" | ||
1687 | "mac.w %%d2u, %%d4u, %%acc0 \n" | ||
1688 | "mac.w %%d2u, %%d4l, ( 64*4,%[x1]), %%d4, %%acc1 \n" | ||
1689 | "mac.w %%d2l, %%d4u, %%acc0 \n" | ||
1690 | "mac.w %%d2l, %%d4l, ( 128*4,%[x1]), %%d4, %%acc1 \n" | ||
1691 | "mac.w %%d3u, %%d4u, %%acc0 \n" | ||
1692 | "mac.w %%d3u, %%d4l, ( 192*4,%[x1]), %%d4, %%acc1 \n" | ||
1693 | "mac.w %%d3l, %%d4u, %%acc0 \n" | ||
1694 | "mac.w %%d3l, %%d4l, ( 256*4,%[x2]), %%d4, %%acc1 \n" | ||
1695 | "msac.w %%d0u, %%d4u, %%acc2 \n" | ||
1696 | "msac.w %%d0u, %%d4l, ( 192*4,%[x2]), %%d4, %%acc3 \n" | ||
1697 | "msac.w %%d0l, %%d4u, %%acc2 \n" | ||
1698 | "msac.w %%d0l, %%d4l, ( 128*4,%[x2]), %%d4, %%acc3 \n" | ||
1699 | "msac.w %%d1u, %%d4u, %%acc2 \n" | ||
1700 | "msac.w %%d1u, %%d4l, ( 64*4,%[x2]), %%d4, %%acc3 \n" | ||
1701 | "msac.w %%d1l, %%d4u, %%acc2 \n" | ||
1702 | "msac.w %%d1l, %%d4l, ( 0*4,%[x2]), %%d4, %%acc3 \n" | ||
1703 | "msac.w %%d2u, %%d4u, %%acc2 \n" | ||
1704 | "msac.w %%d2u, %%d4l, ( -64*4,%[x2]), %%d4, %%acc3 \n" | ||
1705 | "msac.w %%d2l, %%d4u, %%acc2 \n" | ||
1706 | "msac.w %%d2l, %%d4l, (-128*4,%[x2]), %%d4, %%acc3 \n" | ||
1707 | "msac.w %%d3u, %%d4u, %%acc2 \n" | ||
1708 | "msac.w %%d3u, %%d4l, (-192*4,%[x2]), %%d4, %%acc3 \n" | ||
1709 | "msac.w %%d3l, %%d4u, %%acc2 \n" | ||
1710 | "msac.w %%d3l, %%d4l, %%acc3 \n" | ||
1711 | "movclr.l %%acc0, %%d0 \n" | ||
1712 | "move.l %%d0, %[s0] \n" | ||
1713 | "movclr.l %%acc1, %%d0 \n" | ||
1714 | "move.l %%d0, %[s1] \n" | ||
1715 | "movclr.l %%acc2, %%d0 \n" | ||
1716 | "move.l %%d0, %[t0] \n" | ||
1717 | "movclr.l %%acc3, %%d0 \n" | ||
1718 | "move.l %%d0, %[t1] \n" | ||
1719 | : [x1] "+a" (x1), [x2] "+a" (x2), [s0] "+m" (s0), [t0] "+m" (t0), | ||
1720 | [s1] "+m" (s1), [t1] "+m" (t1) | ||
1721 | : [wp] "a" (wp) : "d0", "d1", "d2", "d3", "d4"); | ||
1722 | |||
1723 | a0[30+i*2] = shft4(t0) + shft13(s0) * wp[16]; | ||
1724 | a0[31+i*2] = shft13(t0) * wp[17] - shft13(s0) * wp[18]; | ||
1725 | a1[30+i*2] = shft4(t1) + shft13(s1) * wp[16]; | ||
1726 | a1[31+i*2] = shft13(t1) * wp[17] - shft13(s1) * wp[18]; | ||
1727 | wp += 20; | ||
1728 | x1 -= 2; | ||
1729 | x2 += 2; | ||
1730 | } | ||
1521 | 1731 | ||
1522 | for(k=0; k<18; k++, wk+=64, sb0+=SBLIMIT, sb1+=SBLIMIT) | 1732 | asm volatile ( |
1523 | { | 1733 | "move.l ( -32*4,%[x1]), %%d4 \n" |
1524 | wp = enwindow; | 1734 | "movem.l (%[wp]), %%d0-%%d3 \n" |
1525 | x1 = wk; | 1735 | "mac.w %%d0u, %%d4u, %%acc0 \n" |
1526 | x2 = x1 - 124; | 1736 | "mac.w %%d0u, %%d4l, ( -96*4,%[x1]), %%d4, %%acc1 \n" |
1737 | "mac.w %%d0l, %%d4u, %%acc0 \n" | ||
1738 | "mac.w %%d0l, %%d4l, (-160*4,%[x1]), %%d4, %%acc1 \n" | ||
1739 | "mac.w %%d1u, %%d4u, %%acc0 \n" | ||
1740 | "mac.w %%d1u, %%d4l, (-224*4,%[x1]), %%d4, %%acc1 \n" | ||
1741 | "mac.w %%d1l, %%d4u, %%acc0 \n" | ||
1742 | "mac.w %%d1l, %%d4l, ( 32*4,%[x1]), %%d4, %%acc1 \n" | ||
1743 | "mac.w %%d2u, %%d4u, %%acc0 \n" | ||
1744 | "mac.w %%d2u, %%d4l, ( 96*4,%[x1]), %%d4, %%acc1 \n" | ||
1745 | "mac.w %%d2l, %%d4u, %%acc0 \n" | ||
1746 | "mac.w %%d2l, %%d4l, ( 160*4,%[x1]), %%d4, %%acc1 \n" | ||
1747 | "mac.w %%d3u, %%d4u, %%acc0 \n" | ||
1748 | "mac.w %%d3u, %%d4l, ( 224*4,%[x1]), %%d4, %%acc1 \n" | ||
1749 | "mac.w %%d3l, %%d4u, %%acc0 \n" | ||
1750 | "mac.w %%d3l, %%d4l, ( -16*4,%[x1]), %%d4, %%acc1 \n" | ||
1751 | "movem.l (16,%[wp]), %%d0-%%d3 \n" | ||
1752 | "mac.w %%d0u, %%d4u, %%acc2 \n" | ||
1753 | "mac.w %%d0u, %%d4l, ( -48*4,%[x1]), %%d4, %%acc3 \n" | ||
1754 | "mac.w %%d0l, %%d4u, %%acc2 \n" | ||
1755 | "mac.w %%d0l, %%d4l, ( 16*4,%[x1]), %%d4, %%acc3 \n" | ||
1756 | "msac.w %%d0l, %%d4u, %%acc2 \n" | ||
1757 | "msac.w %%d0l, %%d4l, ( -80*4,%[x1]), %%d4, %%acc3 \n" | ||
1758 | "mac.w %%d1u, %%d4u, %%acc2 \n" | ||
1759 | "mac.w %%d1u, %%d4l, ( 48*4,%[x1]), %%d4, %%acc3 \n" | ||
1760 | "mac.w %%d1u, %%d4u, %%acc2 \n" | ||
1761 | "mac.w %%d1u, %%d4l, (-112*4,%[x1]), %%d4, %%acc3 \n" | ||
1762 | "mac.w %%d1l, %%d4u, %%acc2 \n" | ||
1763 | "mac.w %%d1l, %%d4l, ( 80*4,%[x1]), %%d4, %%acc3 \n" | ||
1764 | "msac.w %%d1l, %%d4u, %%acc2 \n" | ||
1765 | "msac.w %%d1l, %%d4l, (-144*4,%[x1]), %%d4, %%acc3 \n" | ||
1766 | "mac.w %%d2u, %%d4u, %%acc2 \n" | ||
1767 | "mac.w %%d2u, %%d4l, ( 112*4,%[x1]), %%d4, %%acc3 \n" | ||
1768 | "mac.w %%d2u, %%d4u, %%acc2 \n" | ||
1769 | "mac.w %%d2u, %%d4l, (-176*4,%[x1]), %%d4, %%acc3 \n" | ||
1770 | "mac.w %%d2l, %%d4u, %%acc2 \n" | ||
1771 | "mac.w %%d2l, %%d4l, ( 144*4,%[x1]), %%d4, %%acc3 \n" | ||
1772 | "msac.w %%d2l, %%d4u, %%acc2 \n" | ||
1773 | "msac.w %%d2l, %%d4l, (-208*4,%[x1]), %%d4, %%acc3 \n" | ||
1774 | "mac.w %%d3u, %%d4u, %%acc2 \n" | ||
1775 | "mac.w %%d3u, %%d4l, ( 176*4,%[x1]), %%d4, %%acc3 \n" | ||
1776 | "mac.w %%d3u, %%d4u, %%acc2 \n" | ||
1777 | "mac.w %%d3u, %%d4l, (-240*4,%[x1]), %%d4, %%acc3 \n" | ||
1778 | "mac.w %%d3l, %%d4u, %%acc2 \n" | ||
1779 | "mac.w %%d3l, %%d4l, ( 208*4,%[x1]), %%d4, %%acc3 \n" | ||
1780 | "msac.w %%d3l, %%d4u, %%acc2 \n" | ||
1781 | "msac.w %%d3l, %%d4l, %%acc3 \n" | ||
1782 | "movclr.l %%acc0, %%d0 \n" | ||
1783 | "move.l %%d0, %[s0] \n" | ||
1784 | "movclr.l %%acc1, %%d0 \n" | ||
1785 | "move.l %%d0, %[s1] \n" | ||
1786 | "movclr.l %%acc2, %%d0 \n" | ||
1787 | "move.l %%d0, %[t0] \n" | ||
1788 | "movclr.l %%acc3, %%d0 \n" | ||
1789 | "move.l %%d0, %[t1] \n" | ||
1790 | : [x1] "+a" (x1), [s0] "+m" (s0), [t0] "+m" (t0), | ||
1791 | [s1] "+m" (s1), [t1] "+m" (t1) | ||
1792 | : [wp] "a" (wp) : "d0", "d1", "d2", "d3", "d4"); | ||
1793 | |||
1794 | int u = shft4(s0 - t0); | ||
1795 | int v = shft4(s0 + t0); | ||
1796 | t0 = a0[14]; | ||
1797 | s0 = a0[15] - t0; | ||
1798 | |||
1799 | a0[31] = v + t0; /* A0 */ | ||
1800 | a0[30] = u + s0; /* A1 */ | ||
1801 | a0[15] = u - s0; /* A2 */ | ||
1802 | a0[14] = v - t0; /* A3 */ | ||
1803 | |||
1804 | u = shft4(s1 - t1); | ||
1805 | v = shft4(s1 + t1); | ||
1806 | t1 = a1[14]; | ||
1807 | s1 = a1[15] - t1; | ||
1808 | |||
1809 | a1[31] = v + t1; /* A0 */ | ||
1810 | a1[30] = u + s1; /* A1 */ | ||
1811 | a1[15] = u - s1; /* A2 */ | ||
1812 | a1[14] = v - t1; /* A3 */ | ||
1813 | } | ||
1814 | } | ||
1527 | 1815 | ||
1528 | for(i=-15; i<0; i++) | 1816 | static void ICODE_ATTR window_subband1_m(const short *wk, int a0[32]) |
1817 | { | ||
1818 | for (int k = 0; k < 18; k++, wk += 32, a0 += 32) | ||
1529 | { | 1819 | { |
1530 | asm volatile( | 1820 | const short *wp = enwindow; |
1531 | "move.l (-224*4,%[x2]), %%d4\n" /* d4 = x2[-224] */ | 1821 | const short *x1 = wk; |
1532 | "movem.l (%[wp]), %%d0-%%d3\n" /* load 8 values */ | 1822 | const short *x2 = x1 - 62; |
1533 | "mac.w %%d0u, %%d4u, %%acc0\n" | 1823 | int s0, t0; |
1534 | "mac.w %%d0u, %%d4l, (-160*4,%[x2]), %%d4, %%acc1\n" | 1824 | |
1535 | "mac.w %%d0l, %%d4u, %%acc0\n" | 1825 | for (int i = -15; i < 0; i++) |
1536 | "mac.w %%d0l, %%d4l, ( -96*4,%[x2]), %%d4, %%acc1\n" | 1826 | { |
1537 | "mac.w %%d1u, %%d4u, %%acc0\n" | 1827 | asm volatile ( |
1538 | "mac.w %%d1u, %%d4l, ( -32*4,%[x2]), %%d4, %%acc1\n" | 1828 | "movem.l (%[wp]), %%d0-%%d3 \n" |
1539 | "mac.w %%d1l, %%d4u, %%acc0\n" | 1829 | "move.l (-224*2,%[x2]), %%d4 \n" |
1540 | "mac.w %%d1l, %%d4l, ( 32*4,%[x2]), %%d4, %%acc1\n" | 1830 | "mac.w %%d0u, %%d4u, (-160*2,%[x2]), %%d4, %%acc0 \n" |
1541 | "mac.w %%d2u, %%d4u, %%acc0\n" | 1831 | "mac.w %%d0l, %%d4u, ( -96*2,%[x2]), %%d4, %%acc0 \n" |
1542 | "mac.w %%d2u, %%d4l, ( 96*4,%[x2]), %%d4, %%acc1\n" | 1832 | "mac.w %%d1u, %%d4u, ( -32*2,%[x2]), %%d4, %%acc0 \n" |
1543 | "mac.w %%d2l, %%d4u, %%acc0\n" | 1833 | "mac.w %%d1l, %%d4u, ( 32*2,%[x2]), %%d4, %%acc0 \n" |
1544 | "mac.w %%d2l, %%d4l, ( 160*4,%[x2]), %%d4, %%acc1\n" | 1834 | "mac.w %%d2u, %%d4u, ( 96*2,%[x2]), %%d4, %%acc0 \n" |
1545 | "mac.w %%d3u, %%d4u, %%acc0\n" | 1835 | "mac.w %%d2l, %%d4u, ( 160*2,%[x2]), %%d4, %%acc0 \n" |
1546 | "mac.w %%d3u, %%d4l, ( 224*4,%[x2]), %%d4, %%acc1\n" | 1836 | "mac.w %%d3u, %%d4u, ( 224*2,%[x2]), %%d4, %%acc0 \n" |
1547 | "mac.w %%d3l, %%d4u, %%acc0\n" | 1837 | "mac.w %%d3l, %%d4u, ( 224*2,%[x1]), %%d4, %%acc0 \n" |
1548 | "mac.w %%d3l, %%d4l, (-256*4,%[x1]), %%d4, %%acc1\n" | 1838 | "mac.w %%d0u, %%d4u, ( 160*2,%[x1]), %%d4, %%acc1 \n" |
1549 | "movem.l (16,%[wp]), %%d0-%%d3\n" /* load 8 values */ | 1839 | "mac.w %%d0l, %%d4u, ( 96*2,%[x1]), %%d4, %%acc1 \n" |
1550 | "mac.w %%d0u, %%d4u, %%acc0\n" | 1840 | "mac.w %%d1u, %%d4u, ( 32*2,%[x1]), %%d4, %%acc1 \n" |
1551 | "mac.w %%d0u, %%d4l, (-192*4,%[x1]), %%d4, %%acc1\n" | 1841 | "mac.w %%d1l, %%d4u, ( -32*2,%[x1]), %%d4, %%acc1 \n" |
1552 | "mac.w %%d0l, %%d4u, %%acc0\n" | 1842 | "mac.w %%d2u, %%d4u, ( -96*2,%[x1]), %%d4, %%acc1 \n" |
1553 | "mac.w %%d0l, %%d4l, (-128*4,%[x1]), %%d4, %%acc1\n" | 1843 | "mac.w %%d2l, %%d4u, (-160*2,%[x1]), %%d4, %%acc1 \n" |
1554 | "mac.w %%d1u, %%d4u, %%acc0\n" | 1844 | "mac.w %%d3u, %%d4u, (-224*2,%[x1]), %%d4, %%acc1 \n" |
1555 | "mac.w %%d1u, %%d4l, ( -64*4,%[x1]), %%d4, %%acc1\n" | 1845 | "mac.w %%d3l, %%d4u, (-256*2,%[x1]), %%d4, %%acc1 \n" |
1556 | "mac.w %%d1l, %%d4u, %%acc0\n" | 1846 | "movem.l (16,%[wp]), %%d0-%%d3 \n" |
1557 | "mac.w %%d1l, %%d4l, ( 0*4,%[x1]), %%d4, %%acc1\n" | 1847 | "mac.w %%d0u, %%d4u, (-192*2,%[x1]), %%d4, %%acc0 \n" |
1558 | "mac.w %%d2u, %%d4u, %%acc0\n" | 1848 | "mac.w %%d0l, %%d4u, (-128*2,%[x1]), %%d4, %%acc0 \n" |
1559 | "mac.w %%d2u, %%d4l, ( 64*4,%[x1]), %%d4, %%acc1\n" | 1849 | "mac.w %%d1u, %%d4u, ( -64*2,%[x1]), %%d4, %%acc0 \n" |
1560 | "mac.w %%d2l, %%d4u, %%acc0\n" | 1850 | "mac.w %%d1l, %%d4u, ( 0*2,%[x1]), %%d4, %%acc0 \n" |
1561 | "mac.w %%d2l, %%d4l, ( 128*4,%[x1]), %%d4, %%acc1\n" | 1851 | "mac.w %%d2u, %%d4u, ( 64*2,%[x1]), %%d4, %%acc0 \n" |
1562 | "mac.w %%d3u, %%d4u, %%acc0\n" | 1852 | "mac.w %%d2l, %%d4u, ( 128*2,%[x1]), %%d4, %%acc0 \n" |
1563 | "mac.w %%d3u, %%d4l, ( 192*4,%[x1]), %%d4, %%acc1\n" | 1853 | "mac.w %%d3u, %%d4u, ( 192*2,%[x1]), %%d4, %%acc0 \n" |
1564 | "mac.w %%d3l, %%d4u, %%acc0\n" | 1854 | "mac.w %%d3l, %%d4u, ( 256*2,%[x2]), %%d4, %%acc0 \n" |
1565 | "mac.w %%d3l, %%d4l, ( 224*4,%[x1]), %%d4, %%acc1\n" | 1855 | "msac.w %%d0u, %%d4u, ( 192*2,%[x2]), %%d4, %%acc1 \n" |
1566 | "movclr.l %%acc0, %%d0\n" | 1856 | "msac.w %%d0l, %%d4u, ( 128*2,%[x2]), %%d4, %%acc1 \n" |
1567 | "move.l %%d0, %[s0]\n" | 1857 | "msac.w %%d1u, %%d4u, ( 64*2,%[x2]), %%d4, %%acc1 \n" |
1568 | "movclr.l %%acc1, %%d0\n" | 1858 | "msac.w %%d1l, %%d4u, ( 0*2,%[x2]), %%d4, %%acc1 \n" |
1569 | "move.l %%d0, %[s1]\n" | 1859 | "msac.w %%d2u, %%d4u, ( -64*2,%[x2]), %%d4, %%acc1 \n" |
1570 | 1860 | "msac.w %%d2l, %%d4u, (-128*2,%[x2]), %%d4, %%acc1 \n" | |
1571 | "movem.l (%[wp]), %%d0-%%d3\n" /* load 8 values */ | 1861 | "msac.w %%d3u, %%d4u, (-192*2,%[x2]), %%d4, %%acc1 \n" |
1572 | "mac.w %%d0u, %%d4u, %%acc0\n" | 1862 | "msac.w %%d3l, %%d4u, %%acc1 \n" |
1573 | "mac.w %%d0u, %%d4l, ( 160*4,%[x1]), %%d4, %%acc1\n" | 1863 | "movclr.l %%acc0, %%d0 \n" |
1574 | "mac.w %%d0l, %%d4u, %%acc0\n" | 1864 | "move.l %%d0, %[s0] \n" |
1575 | "mac.w %%d0l, %%d4l, ( 96*4,%[x1]), %%d4, %%acc1\n" | 1865 | "movclr.l %%acc1, %%d0 \n" |
1576 | "mac.w %%d1u, %%d4u, %%acc0\n" | 1866 | "move.l %%d0, %[t0] \n" |
1577 | "mac.w %%d1u, %%d4l, ( 32*4,%[x1]), %%d4, %%acc1\n" | 1867 | : [x1] "+a" (x1), [x2] "+a" (x2), [s0] "+m" (s0), [t0] "+m" (t0) |
1578 | "mac.w %%d1l, %%d4u, %%acc0\n" | 1868 | : [wp] "a" (wp) : "d0", "d1", "d2", "d3", "d4"); |
1579 | "mac.w %%d1l, %%d4l, ( -32*4,%[x1]), %%d4, %%acc1\n" | 1869 | |
1580 | "mac.w %%d2u, %%d4u, %%acc0\n" | 1870 | a0[30+i*2] = shft4(t0) + shft13(s0) * wp[16]; |
1581 | "mac.w %%d2u, %%d4l, ( -96*4,%[x1]), %%d4, %%acc1\n" | 1871 | a0[31+i*2] = shft13(t0) * wp[17] - shft13(s0) * wp[18]; |
1582 | "mac.w %%d2l, %%d4u, %%acc0\n" | 1872 | wp += 20; |
1583 | "mac.w %%d2l, %%d4l, (-160*4,%[x1]), %%d4, %%acc1\n" | 1873 | x1--; |
1584 | "mac.w %%d3u, %%d4u, %%acc0\n" | 1874 | x2++; |
1585 | "mac.w %%d3u, %%d4l, (-224*4,%[x1]), %%d4, %%acc1\n" | 1875 | } |
1586 | "mac.w %%d3l, %%d4u, %%acc0\n" | 1876 | |
1587 | "mac.w %%d3l, %%d4l, ( 256*4,%[x2]), %%d4, %%acc1\n" | 1877 | asm volatile ( |
1588 | "movem.l (32,%[wp]), %%d0-%%d3\n" /* load 8 values */ | 1878 | "move.l ( -32*2,%[x1]), %%d4 \n" |
1589 | "mac.w %%d0u, %%d4u, %%acc0\n" | 1879 | "movem.l (%[wp]), %%d0-%%d3 \n" |
1590 | "mac.w %%d0u, %%d4l, ( 192*4,%[x2]), %%d4, %%acc1\n" | 1880 | "mac.w %%d0u, %%d4u, ( -96*2,%[x1]), %%d4, %%acc0 \n" |
1591 | "mac.w %%d0l, %%d4u, %%acc0\n" | 1881 | "mac.w %%d0l, %%d4u, (-160*2,%[x1]), %%d4, %%acc0 \n" |
1592 | "mac.w %%d0l, %%d4l, ( 128*4,%[x2]), %%d4, %%acc1\n" | 1882 | "mac.w %%d1u, %%d4u, (-224*2,%[x1]), %%d4, %%acc0 \n" |
1593 | "mac.w %%d1u, %%d4u, %%acc0\n" | 1883 | "mac.w %%d1l, %%d4u, ( 32*2,%[x1]), %%d4, %%acc0 \n" |
1594 | "mac.w %%d1u, %%d4l, ( 64*4,%[x2]), %%d4, %%acc1\n" | 1884 | "mac.w %%d2u, %%d4u, ( 96*2,%[x1]), %%d4, %%acc0 \n" |
1595 | "mac.w %%d1l, %%d4u, %%acc0\n" | 1885 | "mac.w %%d2l, %%d4u, ( 160*2,%[x1]), %%d4, %%acc0 \n" |
1596 | "mac.w %%d1l, %%d4l, ( 0*4,%[x2]), %%d4, %%acc1\n" | 1886 | "mac.w %%d3u, %%d4u, ( 224*2,%[x1]), %%d4, %%acc0 \n" |
1597 | "mac.w %%d2u, %%d4u, %%acc0\n" | 1887 | "mac.w %%d3l, %%d4u, ( -16*2,%[x1]), %%d4, %%acc0 \n" |
1598 | "mac.w %%d2u, %%d4l, ( -64*4,%[x2]), %%d4, %%acc1\n" | 1888 | "movem.l (16,%[wp]), %%d0-%%d3 \n" |
1599 | "mac.w %%d2l, %%d4u, %%acc0\n" | 1889 | "mac.w %%d0u, %%d4u, ( -48*2,%[x1]), %%d4, %%acc1 \n" |
1600 | "mac.w %%d2l, %%d4l, (-128*4,%[x2]), %%d4, %%acc1\n" | 1890 | "mac.w %%d0l, %%d4u, ( 16*2,%[x1]), %%d4, %%acc1 \n" |
1601 | "mac.w %%d3u, %%d4u, %%acc0\n" | 1891 | "msac.w %%d0l, %%d4u, ( -80*2,%[x1]), %%d4, %%acc1 \n" |
1602 | "mac.w %%d3u, %%d4l, (-192*4,%[x2]), %%d4, %%acc1\n" | 1892 | "mac.w %%d1u, %%d4u, ( 48*2,%[x1]), %%d4, %%acc1 \n" |
1603 | "mac.w %%d3l, %%d4u, %%acc0\n" | 1893 | "mac.w %%d1u, %%d4u, (-112*2,%[x1]), %%d4, %%acc1 \n" |
1604 | "mac.w %%d3l, %%d4l, %%acc1\n" | 1894 | "mac.w %%d1l, %%d4u, ( 80*2,%[x1]), %%d4, %%acc1 \n" |
1605 | "movclr.l %%acc0, %%d0\n" | 1895 | "msac.w %%d1l, %%d4u, (-144*2,%[x1]), %%d4, %%acc1 \n" |
1606 | "move.l %%d0, %[t0]\n" | 1896 | "mac.w %%d2u, %%d4u, ( 112*2,%[x1]), %%d4, %%acc1 \n" |
1607 | "movclr.l %%acc1, %%d0\n" | 1897 | "mac.w %%d2u, %%d4u, (-176*2,%[x1]), %%d4, %%acc1 \n" |
1608 | "move.l %%d0, %[t1]\n" | 1898 | "mac.w %%d2l, %%d4u, ( 144*2,%[x1]), %%d4, %%acc1 \n" |
1609 | 1899 | "msac.w %%d2l, %%d4u, (-208*2,%[x1]), %%d4, %%acc1 \n" | |
1610 | : [x1] "+a" (x1), [x2] "+a" (x2), [s0] "+m" (s0), [t0] "+m" (t0), | 1900 | "mac.w %%d3u, %%d4u, ( 176*2,%[x1]), %%d4, %%acc1 \n" |
1611 | [s1] "+m" (s1), [t1] "+m" (t1) | 1901 | "mac.w %%d3u, %%d4u, (-240*2,%[x1]), %%d4, %%acc1 \n" |
1612 | : [wp] "a" (wp) : "d0", "d1", "d2", "d3", "d4"); | 1902 | "mac.w %%d3l, %%d4u, ( 208*2,%[x1]), %%d4, %%acc1 \n" |
1613 | 1903 | "msac.w %%d3l, %%d4u, %%acc1 \n" | |
1614 | sb0[30+i*2] = shft4(t0) + shft13(s0) * wp[24]; | 1904 | "movclr.l %%acc0, %%d0 \n" |
1615 | sb0[31+i*2] = shft13(t0) * wp[25] - shft13(s0) * wp[26]; | 1905 | "move.l %%d0, %[s0] \n" |
1616 | sb1[30+i*2] = shft4(t1) + shft13(s1) * wp[24]; | 1906 | "movclr.l %%acc1, %%d0 \n" |
1617 | sb1[31+i*2] = shft13(t1) * wp[25] - shft13(s1) * wp[26]; | 1907 | "move.l %%d0, %[t0] \n" |
1618 | wp += 27; | 1908 | : [x1] "+a" (x1), [s0] "+m" (s0), [t0] "+m" (t0) |
1619 | x1 -= 2; | 1909 | : [wp] "a" (wp) : "d0", "d1", "d2", "d3", "d4"); |
1620 | x2 += 2; | 1910 | |
1911 | int u = shft4(s0 - t0); | ||
1912 | int v = shft4(s0 + t0); | ||
1913 | t0 = a0[14]; | ||
1914 | s0 = a0[15] - t0; | ||
1915 | |||
1916 | a0[31] = v + t0; /* A0 */ | ||
1917 | a0[30] = u + s0; /* A1 */ | ||
1918 | a0[15] = u - s0; /* A2 */ | ||
1919 | a0[14] = v - t0; /* A3 */ | ||
1621 | } | 1920 | } |
1921 | } | ||
1622 | 1922 | ||
1623 | asm volatile( | 1923 | #else /* Generic CPU */ |
1624 | "move.l ( -32*4,%[x1]), %%d4\n" /* d4 = x1[-32] */ | ||
1625 | "movem.l (%[wp]), %%d0-%%d3\n" /* load 8 values */ | ||
1626 | |||
1627 | "mac.w %%d0u, %%d4u, %%acc0\n" | ||
1628 | "mac.w %%d0u, %%d4l, ( -96*4,%[x1]), %%d4, %%acc1\n" | ||
1629 | "mac.w %%d0l, %%d4u, %%acc0\n" | ||
1630 | "mac.w %%d0l, %%d4l, (-160*4,%[x1]), %%d4, %%acc1\n" | ||
1631 | "mac.w %%d1u, %%d4u, %%acc0\n" | ||
1632 | "mac.w %%d1u, %%d4l, (-224*4,%[x1]), %%d4, %%acc1\n" | ||
1633 | "mac.w %%d1l, %%d4u, %%acc0\n" | ||
1634 | "mac.w %%d1l, %%d4l, ( 32*4,%[x1]), %%d4, %%acc1\n" | ||
1635 | "mac.w %%d2u, %%d4u, %%acc0\n" | ||
1636 | "mac.w %%d2u, %%d4l, ( 96*4,%[x1]), %%d4, %%acc1\n" | ||
1637 | "mac.w %%d2l, %%d4u, %%acc0\n" | ||
1638 | "mac.w %%d2l, %%d4l, ( 160*4,%[x1]), %%d4, %%acc1\n" | ||
1639 | "mac.w %%d3u, %%d4u, %%acc0\n" | ||
1640 | "mac.w %%d3u, %%d4l, ( 224*4,%[x1]), %%d4, %%acc1\n" | ||
1641 | "mac.w %%d3l, %%d4u, %%acc0\n" | ||
1642 | "mac.w %%d3l, %%d4l, ( -16*4,%[x1]), %%d4, %%acc1\n" | ||
1643 | "movclr.l %%acc0, %%d0\n" | ||
1644 | "move.l %%d0, %[s0]\n" | ||
1645 | "movclr.l %%acc1, %%d0\n" | ||
1646 | "move.l %%d0, %[s1]\n" | ||
1647 | |||
1648 | "movem.l (16,%[wp]), %%d0-%%d3\n" /* load 8 values */ | ||
1649 | "mac.w %%d0u, %%d4u, %%acc0\n" | ||
1650 | "mac.w %%d0u, %%d4l, ( -48*4,%[x1]), %%d4, %%acc1\n" | ||
1651 | "mac.w %%d1u, %%d4u, %%acc0\n" | ||
1652 | "mac.w %%d1u, %%d4l, ( 16*4,%[x1]), %%d4, %%acc1\n" | ||
1653 | "mac.w %%d1l, %%d4u, %%acc0\n" | ||
1654 | "mac.w %%d1l, %%d4l, ( -80*4,%[x1]), %%d4, %%acc1\n" | ||
1655 | "mac.w %%d2u, %%d4u, %%acc0\n" | ||
1656 | "mac.w %%d2u, %%d4l, ( 48*4,%[x1]), %%d4, %%acc1\n" | ||
1657 | "mac.w %%d2u, %%d4u, %%acc0\n" | ||
1658 | "mac.w %%d2u, %%d4l, (-112*4,%[x1]), %%d4, %%acc1\n" | ||
1659 | "mac.w %%d3u, %%d4u, %%acc0\n" | ||
1660 | "mac.w %%d3u, %%d4l, ( 80*4,%[x1]), %%d4, %%acc1\n" | ||
1661 | "mac.w %%d3l, %%d4u, %%acc0\n" | ||
1662 | "mac.w %%d3l, %%d4l, (-144*4,%[x1]), %%d4, %%acc1\n" | ||
1663 | "movem.l (32,%[wp]), %%d0-%%d3\n" /* load 8 values */ | ||
1664 | "mac.w %%d0u, %%d4u, %%acc0\n" | ||
1665 | "mac.w %%d0u, %%d4l, ( 112*4,%[x1]), %%d4, %%acc1\n" | ||
1666 | "mac.w %%d0u, %%d4u, %%acc0\n" | ||
1667 | "mac.w %%d0u, %%d4l, (-176*4,%[x1]), %%d4, %%acc1\n" | ||
1668 | "mac.w %%d1u, %%d4u, %%acc0\n" | ||
1669 | "mac.w %%d1u, %%d4l, ( 144*4,%[x1]), %%d4, %%acc1\n" | ||
1670 | "mac.w %%d1l, %%d4u, %%acc0\n" | ||
1671 | "mac.w %%d1l, %%d4l, (-208*4,%[x1]), %%d4, %%acc1\n" | ||
1672 | "mac.w %%d2u, %%d4u, %%acc0\n" | ||
1673 | "mac.w %%d2u, %%d4l, ( 176*4,%[x1]), %%d4, %%acc1\n" | ||
1674 | "mac.w %%d2u, %%d4u, %%acc0\n" | ||
1675 | "mac.w %%d2u, %%d4l, (-240*4,%[x1]), %%d4, %%acc1\n" | ||
1676 | "mac.w %%d3u, %%d4u, %%acc0\n" | ||
1677 | "mac.w %%d3u, %%d4l, ( 208*4,%[x1]), %%d4, %%acc1\n" | ||
1678 | "mac.w %%d3l, %%d4u, %%acc0\n" | ||
1679 | "mac.w %%d3l, %%d4l, %%acc1\n" | ||
1680 | "movclr.l %%acc0, %%d0\n" | ||
1681 | "move.l %%d0, %[t0]\n" | ||
1682 | "movclr.l %%acc1, %%d0\n" | ||
1683 | "move.l %%d0, %[t1]\n" | ||
1684 | |||
1685 | : [x1] "+a" (x1), [s0] "+m" (s0), [t0] "+m" (t0), | ||
1686 | [s1] "+m" (s1), [t1] "+m" (t1) | ||
1687 | : [wp] "a" (wp) : "d0", "d1", "d2", "d3", "d4"); | ||
1688 | |||
1689 | u = shft4(s0 - t0); | ||
1690 | v = shft4(s0 + t0); | ||
1691 | t0 = sb0[14]; | ||
1692 | s0 = sb0[15] - t0; | ||
1693 | |||
1694 | sb0[31] = v + t0; /* A0 */ | ||
1695 | sb0[30] = u + s0; /* A1 */ | ||
1696 | sb0[15] = u - s0; /* A2 */ | ||
1697 | sb0[14] = v - t0; /* A3 */ | ||
1698 | |||
1699 | u = shft4(s1 - t1); | ||
1700 | v = shft4(s1 + t1); | ||
1701 | t1 = sb1[14]; | ||
1702 | s1 = sb1[15] - t1; | ||
1703 | |||
1704 | sb1[31] = v + t1; /* A0 */ | ||
1705 | sb1[30] = u + s1; /* A1 */ | ||
1706 | sb1[15] = u - s1; /* A2 */ | ||
1707 | sb1[14] = v - t1; /* A3 */ | ||
1708 | } | ||
1709 | #else | ||
1710 | int ch, s, t, *a; | ||
1711 | 1924 | ||
1712 | for(ch=0; ch<cfg.channels; ch++) | 1925 | static void ICODE_ATTR window_subband1_s_(const short *wk, int a[32]) |
1713 | { | 1926 | { |
1714 | a = ch ? sb1 : sb0; | 1927 | for (int k = 0; k < 18; k++, wk += 64, a += 32) |
1715 | for(k=0; k<18; k++, wk+=64, a+=SBLIMIT) | ||
1716 | { | 1928 | { |
1717 | wp = enwindow; | 1929 | const short *wp = enwindow; |
1718 | x1 = wk; | 1930 | const short *x1 = wk; |
1719 | x2 = x1 - 124; | 1931 | const short *x2 = x1 - 124; |
1720 | 1932 | int s, t; | |
1721 | /* x1[-572] .... x1[448] = 1022 */ | 1933 | |
1722 | /* 18*4*16*32 */ | 1934 | /* x1[-572] .... x1[448] = 1022 */ |
1723 | for(i=-15; i<0; i++) | 1935 | /* 18*4*16*32 */ |
1724 | { | 1936 | for (int i = -15; i < 0; i++) |
1725 | s = (int)x2[-224*2] * wp[ 0]; t = (int)x1[ 224*2] * wp[ 0]; | 1937 | { |
1726 | s += (int)x2[-160*2] * wp[ 1]; t += (int)x1[ 160*2] * wp[ 1]; | 1938 | s = (int)x2[-224*2] * wp[ 0]; t = (int)x1[ 224*2] * wp[ 0]; |
1727 | s += (int)x2[- 96*2] * wp[ 2]; t += (int)x1[ 96*2] * wp[ 2]; | 1939 | s += (int)x2[-160*2] * wp[ 1]; t += (int)x1[ 160*2] * wp[ 1]; |
1728 | s += (int)x2[- 32*2] * wp[ 3]; t += (int)x1[ 32*2] * wp[ 3]; | 1940 | s += (int)x2[- 96*2] * wp[ 2]; t += (int)x1[ 96*2] * wp[ 2]; |
1729 | s += (int)x2[ 32*2] * wp[ 4]; t += (int)x1[- 32*2] * wp[ 4]; | 1941 | s += (int)x2[- 32*2] * wp[ 3]; t += (int)x1[ 32*2] * wp[ 3]; |
1730 | s += (int)x2[ 96*2] * wp[ 5]; t += (int)x1[- 96*2] * wp[ 5]; | 1942 | s += (int)x2[ 32*2] * wp[ 4]; t += (int)x1[- 32*2] * wp[ 4]; |
1731 | s += (int)x2[ 160*2] * wp[ 6]; t += (int)x1[-160*2] * wp[ 6]; | 1943 | s += (int)x2[ 96*2] * wp[ 5]; t += (int)x1[- 96*2] * wp[ 5]; |
1732 | s += (int)x2[ 224*2] * wp[ 7]; t += (int)x1[-224*2] * wp[ 7]; | 1944 | s += (int)x2[ 160*2] * wp[ 6]; t += (int)x1[-160*2] * wp[ 6]; |
1733 | s += (int)x1[-256*2] * wp[ 8]; t += (int)x2[ 256*2] * wp[16]; | 1945 | s += (int)x2[ 224*2] * wp[ 7]; t += (int)x1[-224*2] * wp[ 7]; |
1734 | s += (int)x1[-192*2] * wp[ 9]; t += (int)x2[ 192*2] * wp[17]; | 1946 | s += (int)x1[-256*2] * wp[ 8]; t -= (int)x2[ 256*2] * wp[ 8]; |
1735 | s += (int)x1[-128*2] * wp[10]; t += (int)x2[ 128*2] * wp[18]; | 1947 | s += (int)x1[-192*2] * wp[ 9]; t -= (int)x2[ 192*2] * wp[ 9]; |
1736 | s += (int)x1[- 64*2] * wp[11]; t += (int)x2[ 64*2] * wp[19]; | 1948 | s += (int)x1[-128*2] * wp[10]; t -= (int)x2[ 128*2] * wp[10]; |
1737 | s += (int)x1[ 0*2] * wp[12]; t += (int)x2[ 0*2] * wp[20]; | 1949 | s += (int)x1[- 64*2] * wp[11]; t -= (int)x2[ 64*2] * wp[11]; |
1738 | s += (int)x1[ 64*2] * wp[13]; t += (int)x2[- 64*2] * wp[21]; | 1950 | s += (int)x1[ 0*2] * wp[12]; t -= (int)x2[ 0*2] * wp[12]; |
1739 | s += (int)x1[ 128*2] * wp[14]; t += (int)x2[-128*2] * wp[22]; | 1951 | s += (int)x1[ 64*2] * wp[13]; t -= (int)x2[- 64*2] * wp[13]; |
1740 | s += (int)x1[ 192*2] * wp[15]; t += (int)x2[-192*2] * wp[23]; | 1952 | s += (int)x1[ 128*2] * wp[14]; t -= (int)x2[-128*2] * wp[14]; |
1741 | 1953 | s += (int)x1[ 192*2] * wp[15]; t -= (int)x2[-192*2] * wp[15]; | |
1742 | a[30+i*2] = shft4(t) + shft13(s) * wp[24]; | 1954 | |
1743 | a[31+i*2] = shft13(t) * wp[25] - shft13(s) * wp[26]; | 1955 | a[30+i*2] = shft4(t) + shft13(s) * wp[16]; |
1744 | wp += 27; | 1956 | a[31+i*2] = shft13(t) * wp[17] - shft13(s) * wp[18]; |
1745 | x1 -= 2; | 1957 | wp += 20; |
1746 | x2 += 2; | 1958 | x1 -= 2; |
1747 | } | 1959 | x2 += 2; |
1748 | 1960 | } | |
1749 | t = (int)x1[- 16*2] * wp[ 8]; s = (int)x1[ -32*2] * wp[0]; | 1961 | |
1750 | t += ((int)x1[- 48*2]-x1[ 16*2]) * wp[10]; s += (int)x1[ -96*2] * wp[1]; | 1962 | t = (int)x1[- 16*2] * wp[ 8]; s = (int)x1[ -32*2] * wp[0]; |
1751 | t += ((int)x1[- 80*2]+x1[ 48*2]) * wp[12]; s += (int)x1[-160*2] * wp[2]; | 1963 | t += ((int)x1[- 48*2] - x1[ 16*2]) * wp[ 9]; s += (int)x1[ -96*2] * wp[1]; |
1752 | t += ((int)x1[-112*2]-x1[ 80*2]) * wp[14]; s += (int)x1[-224*2] * wp[3]; | 1964 | t += ((int)x1[- 80*2] + x1[ 48*2]) * wp[10]; s += (int)x1[-160*2] * wp[2]; |
1753 | t += ((int)x1[-144*2]+x1[112*2]) * wp[16]; s += (int)x1[ 32*2] * wp[4]; | 1965 | t += ((int)x1[-112*2] - x1[ 80*2]) * wp[11]; s += (int)x1[-224*2] * wp[3]; |
1754 | t += ((int)x1[-176*2]-x1[144*2]) * wp[18]; s += (int)x1[ 96*2] * wp[5]; | 1966 | t += ((int)x1[-144*2] + x1[112*2]) * wp[12]; s += (int)x1[ 32*2] * wp[4]; |
1755 | t += ((int)x1[-208*2]+x1[176*2]) * wp[20]; s += (int)x1[ 160*2] * wp[6]; | 1967 | t += ((int)x1[-176*2] - x1[144*2]) * wp[13]; s += (int)x1[ 96*2] * wp[5]; |
1756 | t += ((int)x1[-240*2]-x1[208*2]) * wp[22]; s += (int)x1[ 224*2] * wp[7]; | 1968 | t += ((int)x1[-208*2] + x1[176*2]) * wp[14]; s += (int)x1[ 160*2] * wp[6]; |
1757 | 1969 | t += ((int)x1[-240*2] - x1[208*2]) * wp[15]; s += (int)x1[ 224*2] * wp[7]; | |
1758 | u = shft4(s - t); | 1970 | |
1759 | v = shft4(s + t); | 1971 | int u = shft4(s - t); |
1760 | t = a[14]; | 1972 | int v = shft4(s + t); |
1761 | s = a[15] - t; | 1973 | t = a[14]; |
1762 | 1974 | s = a[15] - t; | |
1763 | a[31] = v + t; /* A0 */ | 1975 | |
1764 | a[30] = u + s; /* A1 */ | 1976 | a[31] = v + t; /* A0 */ |
1765 | a[15] = u - s; /* A2 */ | 1977 | a[30] = u + s; /* A1 */ |
1766 | a[14] = v - t; /* A3 */ | 1978 | a[15] = u - s; /* A2 */ |
1979 | a[14] = v - t; /* A3 */ | ||
1767 | } | 1980 | } |
1768 | wk -= 18 * 64 - 1; /* rewind wk (to next channel start) */ | ||
1769 | } | ||
1770 | #endif | ||
1771 | } | 1981 | } |
1772 | 1982 | ||
1773 | static void ICODE_ATTR window_subband2(short *x1, int a[SBLIMIT]) | 1983 | static inline void window_subband1_s(const short *wk, int a0[32], int a1[32]) |
1774 | { | 1984 | { |
1775 | int xr; | 1985 | window_subband1_s_(wk , a0); |
1776 | short *wp = enwindow; | 1986 | window_subband1_s_(wk + 1, a1); |
1777 | short *x2 = x1 - 124; | 1987 | } |
1778 | 1988 | ||
1779 | wp += 27 * 15; | 1989 | static void ICODE_ATTR window_subband1_m(const short *wk, int a[32]) |
1780 | x1 -= 2 * 15; | 1990 | { |
1781 | x2 += 2 * 15; | 1991 | for (int k = 0; k < 18; k++, wk += 32, a += 32) |
1782 | 1992 | { | |
1783 | xr = a[28] - a[0]; a[0] += a[28]; a[28] = shft9(xr) * wp[-2*27+25]; | 1993 | const short *wp = enwindow; |
1784 | xr = a[29] - a[1]; a[1] += a[29]; a[29] = shft9(xr) * wp[-2*27+25]; | 1994 | const short *x1 = wk; |
1785 | xr = a[26] - a[2]; a[2] += a[26]; a[26] = shft9(xr) * wp[-4*27+25]; | 1995 | const short *x2 = x1 - 62; |
1786 | xr = a[27] - a[3]; a[3] += a[27]; a[27] = shft9(xr) * wp[-4*27+25]; | 1996 | int s, t; |
1787 | xr = a[24] - a[4]; a[4] += a[24]; a[24] = shft9(xr) * wp[-6*27+25]; | 1997 | |
1788 | xr = a[25] - a[5]; a[5] += a[25]; a[25] = shft9(xr) * wp[-6*27+25]; | 1998 | /* x1[-286] .... x1[224] = 511 */ |
1789 | xr = a[22] - a[6]; a[6] += a[22]; a[22] = shft9(xr) * SQRT ; | 1999 | /* 18*2*16*32 */ |
1790 | xr = a[23] - a[7]; a[7] += a[23]; a[23] = shft9(xr) * SQRT - a[7]; | 2000 | for (int i = -15; i < 0; i++) |
1791 | a[ 7] -= a[ 6]; | 2001 | { |
1792 | a[22] -= a[ 7]; | 2002 | s = (int)x2[-224] * wp[ 0]; t = (int)x1[ 224] * wp[ 0]; |
1793 | a[23] -= a[22]; | 2003 | s += (int)x2[-160] * wp[ 1]; t += (int)x1[ 160] * wp[ 1]; |
1794 | 2004 | s += (int)x2[- 96] * wp[ 2]; t += (int)x1[ 96] * wp[ 2]; | |
1795 | xr = a[ 6]; a[ 6] = a[31] - xr; a[31] = a[31] + xr; | 2005 | s += (int)x2[- 32] * wp[ 3]; t += (int)x1[ 32] * wp[ 3]; |
1796 | xr = a[ 7]; a[ 7] = a[30] - xr; a[30] = a[30] + xr; | 2006 | s += (int)x2[ 32] * wp[ 4]; t += (int)x1[- 32] * wp[ 4]; |
1797 | xr = a[22]; a[22] = a[15] - xr; a[15] = a[15] + xr; | 2007 | s += (int)x2[ 96] * wp[ 5]; t += (int)x1[- 96] * wp[ 5]; |
1798 | xr = a[23]; a[23] = a[14] - xr; a[14] = a[14] + xr; | 2008 | s += (int)x2[ 160] * wp[ 6]; t += (int)x1[-160] * wp[ 6]; |
1799 | 2009 | s += (int)x2[ 224] * wp[ 7]; t += (int)x1[-224] * wp[ 7]; | |
1800 | xr = a[20] - a[ 8]; a[ 8] += a[20]; a[20] = shft9(xr) * wp[-10*27+25]; | 2010 | s += (int)x1[-256] * wp[ 8]; t -= (int)x2[ 256] * wp[ 8]; |
1801 | xr = a[21] - a[ 9]; a[ 9] += a[21]; a[21] = shft9(xr) * wp[-10*27+25]; | 2011 | s += (int)x1[-192] * wp[ 9]; t -= (int)x2[ 192] * wp[ 9]; |
1802 | xr = a[18] - a[10]; a[10] += a[18]; a[18] = shft9(xr) * wp[-12*27+25]; | 2012 | s += (int)x1[-128] * wp[10]; t -= (int)x2[ 128] * wp[10]; |
1803 | xr = a[19] - a[11]; a[11] += a[19]; a[19] = shft9(xr) * wp[-12*27+25]; | 2013 | s += (int)x1[- 64] * wp[11]; t -= (int)x2[ 64] * wp[11]; |
1804 | xr = a[16] - a[12]; a[12] += a[16]; a[16] = shft9(xr) * wp[-14*27+25]; | 2014 | s += (int)x1[ 0] * wp[12]; t -= (int)x2[ 0] * wp[12]; |
1805 | xr = a[17] - a[13]; a[13] += a[17]; a[17] = shft9(xr) * wp[-14*27+25]; | 2015 | s += (int)x1[ 64] * wp[13]; t -= (int)x2[- 64] * wp[13]; |
1806 | xr =-a[20] + a[24]; a[20] += a[24]; a[24] = shft9(xr) * wp[-12*27+25]; | 2016 | s += (int)x1[ 128] * wp[14]; t -= (int)x2[-128] * wp[14]; |
1807 | xr =-a[21] + a[25]; a[21] += a[25]; a[25] = shft9(xr) * wp[-12*27+25]; | 2017 | s += (int)x1[ 192] * wp[15]; t -= (int)x2[-192] * wp[15]; |
1808 | xr = a[ 4] - a[ 8]; a[ 4] += a[ 8]; a[ 8] = shft9(xr) * wp[-12*27+25]; | 2018 | |
1809 | xr = a[ 5] - a[ 9]; a[ 5] += a[ 9]; a[ 9] = shft9(xr) * wp[-12*27+25]; | 2019 | a[30+i*2] = shft4(t) + shft13(s) * wp[16]; |
1810 | xr = a[ 0] - a[12]; a[ 0] += a[12]; a[12] = shft9(xr) * wp[ -4*27+25]; | 2020 | a[31+i*2] = shft13(t) * wp[17] - shft13(s) * wp[18]; |
1811 | xr = a[ 1] - a[13]; a[ 1] += a[13]; a[13] = shft9(xr) * wp[ -4*27+25]; | 2021 | wp += 20; |
1812 | xr = a[16] - a[28]; a[16] += a[28]; a[28] = shft9(xr) * wp[ -4*27+25]; | 2022 | x1--; |
1813 | xr =-a[17] + a[29]; a[17] += a[29]; a[29] = shft9(xr) * wp[ -4*27+25]; | 2023 | x2++; |
1814 | 2024 | } | |
1815 | xr = SQRT * shft9(a[ 2] - a[10]); a[ 2] += a[10]; a[10] = xr; | 2025 | |
1816 | xr = SQRT * shft9(a[ 3] - a[11]); a[ 3] += a[11]; a[11] = xr; | 2026 | t = (int)x1[- 16] * wp[ 8]; s = (int)x1[ -32] * wp[0]; |
1817 | xr = SQRT * shft9(a[26] - a[18]); a[18] += a[26]; a[26] = xr - a[18]; | 2027 | t += ((int)x1[- 48] - x1[ 16]) * wp[ 9]; s += (int)x1[ -96] * wp[1]; |
1818 | xr = SQRT * shft9(a[27] - a[19]); a[19] += a[27]; a[27] = xr - a[19]; | 2028 | t += ((int)x1[- 80] + x1[ 48]) * wp[10]; s += (int)x1[-160] * wp[2]; |
1819 | 2029 | t += ((int)x1[-112] - x1[ 80]) * wp[11]; s += (int)x1[-224] * wp[3]; | |
1820 | xr = a[ 2]; a[19] -= a[ 3]; a[ 3] -= xr; a[ 2] = a[31] - xr; a[31] += xr; | 2030 | t += ((int)x1[-144] + x1[112]) * wp[12]; s += (int)x1[ 32] * wp[4]; |
1821 | xr = a[ 3]; a[11] -= a[19]; a[18] -= xr; a[ 3] = a[30] - xr; a[30] += xr; | 2031 | t += ((int)x1[-176] - x1[144]) * wp[13]; s += (int)x1[ 96] * wp[5]; |
1822 | xr = a[18]; a[27] -= a[11]; a[19] -= xr; a[18] = a[15] - xr; a[15] += xr; | 2032 | t += ((int)x1[-208] + x1[176]) * wp[14]; s += (int)x1[ 160] * wp[6]; |
1823 | 2033 | t += ((int)x1[-240] - x1[208]) * wp[15]; s += (int)x1[ 224] * wp[7]; | |
1824 | xr = a[19]; a[10] -= xr; a[19] = a[14] - xr; a[14] += xr; | 2034 | |
1825 | xr = a[10]; a[11] -= xr; a[10] = a[23] - xr; a[23] += xr; | 2035 | int u = shft4(s - t); |
1826 | xr = a[11]; a[26] -= xr; a[11] = a[22] - xr; a[22] += xr; | 2036 | int v = shft4(s + t); |
1827 | xr = a[26]; a[27] -= xr; a[26] = a[ 7] - xr; a[ 7] += xr; | 2037 | t = a[14]; |
1828 | 2038 | s = a[15] - t; | |
1829 | xr = a[27]; a[27] = a[6] - xr; a[6] += xr; | 2039 | |
1830 | 2040 | a[31] = v + t; /* A0 */ | |
1831 | xr = SQRT * shft9(a[ 0] - a[ 4]); a[ 0] += a[ 4]; a[ 4] = xr; | 2041 | a[30] = u + s; /* A1 */ |
1832 | xr = SQRT * shft9(a[ 1] - a[ 5]); a[ 1] += a[ 5]; a[ 5] = xr; | 2042 | a[15] = u - s; /* A2 */ |
1833 | xr = SQRT * shft9(a[16] - a[20]); a[16] += a[20]; a[20] = xr; | 2043 | a[14] = v - t; /* A3 */ |
1834 | xr = SQRT * shft9(a[17] - a[21]); a[17] += a[21]; a[21] = xr; | 2044 | } |
1835 | xr =-SQRT * shft9(a[ 8] - a[12]); a[ 8] += a[12]; a[12] = xr - a[ 8]; | 2045 | } |
1836 | xr =-SQRT * shft9(a[ 9] - a[13]); a[ 9] += a[13]; a[13] = xr - a[ 9]; | 2046 | #endif /* CPU */ |
1837 | xr =-SQRT * shft9(a[25] - a[29]); a[25] += a[29]; a[29] = xr - a[25]; | 2047 | |
1838 | xr =-SQRT * shft9(a[24] + a[28]); a[24] -= a[28]; a[28] = xr - a[24]; | 2048 | static void ICODE_ATTR window_subband2_(int a[32]) |
1839 | 2049 | { | |
1840 | xr = a[24] - a[16]; a[24] = xr; | 2050 | /* 36864=4*18*16*32 */ |
1841 | xr = a[20] - xr; a[20] = xr; | 2051 | const short * const wp = enwindow + 20 * 15; |
1842 | xr = a[28] - xr; a[28] = xr; | 2052 | for (int k = 0; k < 18; k++, a += 32) |
1843 | 2053 | { | |
1844 | xr = a[25] - a[17]; a[25] = xr; | 2054 | int xr; |
1845 | xr = a[21] - xr; a[21] = xr; | 2055 | |
1846 | xr = a[29] - xr; a[29] = xr; | 2056 | xr = a[28] - a[0]; a[0] += a[28]; a[28] = shft9(xr) * wp[-2*20+17]; |
1847 | 2057 | xr = a[29] - a[1]; a[1] += a[29]; a[29] = shft9(xr) * wp[-2*20+17]; | |
1848 | xr = a[17] - a[1]; a[17] = xr; | 2058 | xr = a[26] - a[2]; a[2] += a[26]; a[26] = shft9(xr) * wp[-4*20+17]; |
1849 | xr = a[ 9] - xr; a[ 9] = xr; | 2059 | xr = a[27] - a[3]; a[3] += a[27]; a[27] = shft9(xr) * wp[-4*20+17]; |
1850 | xr = a[25] - xr; a[25] = xr; | 2060 | xr = a[24] - a[4]; a[4] += a[24]; a[24] = shft9(xr) * wp[-6*20+17]; |
1851 | xr = a[ 5] - xr; a[ 5] = xr; | 2061 | xr = a[25] - a[5]; a[5] += a[25]; a[25] = shft9(xr) * wp[-6*20+17]; |
1852 | xr = a[21] - xr; a[21] = xr; | 2062 | xr = a[22] - a[6]; a[6] += a[22]; a[22] = shft9(xr) * SQRT ; |
1853 | xr = a[13] - xr; a[13] = xr; | 2063 | xr = a[23] - a[7]; a[7] += a[23]; a[23] = shft9(xr) * SQRT - a[7]; |
1854 | xr = a[29] - xr; a[29] = xr; | 2064 | a[ 7] -= a[ 6]; |
1855 | 2065 | a[22] -= a[ 7]; | |
1856 | xr = a[ 1] - a[0]; a[ 1] = xr; | 2066 | a[23] -= a[22]; |
1857 | xr = a[16] - xr; a[16] = xr; | 2067 | |
1858 | xr = a[17] - xr; a[17] = xr; | 2068 | xr = a[ 6]; a[ 6] = a[31] - xr; a[31] = a[31] + xr; |
1859 | xr = a[ 8] - xr; a[ 8] = xr; | 2069 | xr = a[ 7]; a[ 7] = a[30] - xr; a[30] = a[30] + xr; |
1860 | xr = a[ 9] - xr; a[ 9] = xr; | 2070 | xr = a[22]; a[22] = a[15] - xr; a[15] = a[15] + xr; |
1861 | xr = a[24] - xr; a[24] = xr; | 2071 | xr = a[23]; a[23] = a[14] - xr; a[14] = a[14] + xr; |
1862 | xr = a[25] - xr; a[25] = xr; | 2072 | |
1863 | xr = a[ 4] - xr; a[ 4] = xr; | 2073 | xr = a[20] - a[ 8]; a[ 8] += a[20]; a[20] = shft9(xr) * wp[-10*20+17]; |
1864 | xr = a[ 5] - xr; a[ 5] = xr; | 2074 | xr = a[21] - a[ 9]; a[ 9] += a[21]; a[21] = shft9(xr) * wp[-10*20+17]; |
1865 | xr = a[20] - xr; a[20] = xr; | 2075 | xr = a[18] - a[10]; a[10] += a[18]; a[18] = shft9(xr) * wp[-12*20+17]; |
1866 | xr = a[21] - xr; a[21] = xr; | 2076 | xr = a[19] - a[11]; a[11] += a[19]; a[19] = shft9(xr) * wp[-12*20+17]; |
1867 | xr = a[12] - xr; a[12] = xr; | 2077 | xr = a[16] - a[12]; a[12] += a[16]; a[16] = shft9(xr) * wp[-14*20+17]; |
1868 | xr = a[13] - xr; a[13] = xr; | 2078 | xr = a[17] - a[13]; a[13] += a[17]; a[17] = shft9(xr) * wp[-14*20+17]; |
1869 | xr = a[28] - xr; a[28] = xr; | 2079 | xr =-a[20] + a[24]; a[20] += a[24]; a[24] = shft9(xr) * wp[-12*20+17]; |
1870 | xr = a[29] - xr; a[29] = xr; | 2080 | xr =-a[21] + a[25]; a[21] += a[25]; a[25] = shft9(xr) * wp[-12*20+17]; |
1871 | 2081 | xr = a[ 4] - a[ 8]; a[ 4] += a[ 8]; a[ 8] = shft9(xr) * wp[-12*20+17]; | |
1872 | xr = a[ 0]; a[ 0] += a[31]; a[31] -= xr; | 2082 | xr = a[ 5] - a[ 9]; a[ 5] += a[ 9]; a[ 9] = shft9(xr) * wp[-12*20+17]; |
1873 | xr = a[ 1]; a[ 1] += a[30]; a[30] -= xr; | 2083 | xr = a[ 0] - a[12]; a[ 0] += a[12]; a[12] = shft9(xr) * wp[ -4*20+17]; |
1874 | xr = a[16]; a[16] += a[15]; a[15] -= xr; | 2084 | xr = a[ 1] - a[13]; a[ 1] += a[13]; a[13] = shft9(xr) * wp[ -4*20+17]; |
1875 | xr = a[17]; a[17] += a[14]; a[14] -= xr; | 2085 | xr = a[16] - a[28]; a[16] += a[28]; a[28] = shft9(xr) * wp[ -4*20+17]; |
1876 | xr = a[ 8]; a[ 8] += a[23]; a[23] -= xr; | 2086 | xr =-a[17] + a[29]; a[17] += a[29]; a[29] = shft9(xr) * wp[ -4*20+17]; |
1877 | xr = a[ 9]; a[ 9] += a[22]; a[22] -= xr; | 2087 | |
1878 | xr = a[24]; a[24] += a[ 7]; a[ 7] -= xr; | 2088 | xr = SQRT * shft9(a[ 2] - a[10]); a[ 2] += a[10]; a[10] = xr; |
1879 | xr = a[25]; a[25] += a[ 6]; a[ 6] -= xr; | 2089 | xr = SQRT * shft9(a[ 3] - a[11]); a[ 3] += a[11]; a[11] = xr; |
1880 | xr = a[ 4]; a[ 4] += a[27]; a[27] -= xr; | 2090 | xr = SQRT * shft9(a[26] - a[18]); a[18] += a[26]; a[26] = xr - a[18]; |
1881 | xr = a[ 5]; a[ 5] += a[26]; a[26] -= xr; | 2091 | xr = SQRT * shft9(a[27] - a[19]); a[19] += a[27]; a[27] = xr - a[19]; |
1882 | xr = a[20]; a[20] += a[11]; a[11] -= xr; | 2092 | |
1883 | xr = a[21]; a[21] += a[10]; a[10] -= xr; | 2093 | xr = a[ 2]; a[19] -= a[ 3]; a[ 3] -= xr; a[ 2] = a[31] - xr; a[31] += xr; |
1884 | xr = a[12]; a[12] += a[19]; a[19] -= xr; | 2094 | xr = a[ 3]; a[11] -= a[19]; a[18] -= xr; a[ 3] = a[30] - xr; a[30] += xr; |
1885 | xr = a[13]; a[13] += a[18]; a[18] -= xr; | 2095 | xr = a[18]; a[27] -= a[11]; a[19] -= xr; a[18] = a[15] - xr; a[15] += xr; |
1886 | xr = a[28]; a[28] += a[ 3]; a[ 3] -= xr; | 2096 | |
1887 | xr = a[29]; a[29] += a[ 2]; a[ 2] -= xr; | 2097 | xr = a[19]; a[10] -= xr; a[19] = a[14] - xr; a[14] += xr; |
2098 | xr = a[10]; a[11] -= xr; a[10] = a[23] - xr; a[23] += xr; | ||
2099 | xr = a[11]; a[26] -= xr; a[11] = a[22] - xr; a[22] += xr; | ||
2100 | xr = a[26]; a[27] -= xr; a[26] = a[ 7] - xr; a[ 7] += xr; | ||
2101 | |||
2102 | xr = a[27]; a[27] = a[6] - xr; a[6] += xr; | ||
2103 | |||
2104 | xr = SQRT * shft9(a[ 0] - a[ 4]); a[ 0] += a[ 4]; a[ 4] = xr; | ||
2105 | xr = SQRT * shft9(a[ 1] - a[ 5]); a[ 1] += a[ 5]; a[ 5] = xr; | ||
2106 | xr = SQRT * shft9(a[16] - a[20]); a[16] += a[20]; a[20] = xr; | ||
2107 | xr = SQRT * shft9(a[17] - a[21]); a[17] += a[21]; a[21] = xr; | ||
2108 | xr =-SQRT * shft9(a[ 8] - a[12]); a[ 8] += a[12]; a[12] = xr - a[ 8]; | ||
2109 | xr =-SQRT * shft9(a[ 9] - a[13]); a[ 9] += a[13]; a[13] = xr - a[ 9]; | ||
2110 | xr =-SQRT * shft9(a[25] - a[29]); a[25] += a[29]; a[29] = xr - a[25]; | ||
2111 | xr =-SQRT * shft9(a[24] + a[28]); a[24] -= a[28]; a[28] = xr - a[24]; | ||
2112 | |||
2113 | xr = a[24] - a[16]; a[24] = xr; | ||
2114 | xr = a[20] - xr; a[20] = xr; | ||
2115 | xr = a[28] - xr; a[28] = xr; | ||
2116 | |||
2117 | xr = a[25] - a[17]; a[25] = xr; | ||
2118 | xr = a[21] - xr; a[21] = xr; | ||
2119 | xr = a[29] - xr; a[29] = xr; | ||
2120 | |||
2121 | xr = a[17] - a[1]; a[17] = xr; | ||
2122 | xr = a[ 9] - xr; a[ 9] = xr; | ||
2123 | xr = a[25] - xr; a[25] = xr; | ||
2124 | xr = a[ 5] - xr; a[ 5] = xr; | ||
2125 | xr = a[21] - xr; a[21] = xr; | ||
2126 | xr = a[13] - xr; a[13] = xr; | ||
2127 | xr = a[29] - xr; a[29] = xr; | ||
2128 | |||
2129 | xr = a[ 1] - a[0]; a[ 1] = xr; | ||
2130 | xr = a[16] - xr; a[16] = xr; | ||
2131 | xr = a[17] - xr; a[17] = xr; | ||
2132 | xr = a[ 8] - xr; a[ 8] = xr; | ||
2133 | xr = a[ 9] - xr; a[ 9] = xr; | ||
2134 | xr = a[24] - xr; a[24] = xr; | ||
2135 | xr = a[25] - xr; a[25] = xr; | ||
2136 | xr = a[ 4] - xr; a[ 4] = xr; | ||
2137 | xr = a[ 5] - xr; a[ 5] = xr; | ||
2138 | xr = a[20] - xr; a[20] = xr; | ||
2139 | xr = a[21] - xr; a[21] = xr; | ||
2140 | xr = a[12] - xr; a[12] = xr; | ||
2141 | xr = a[13] - xr; a[13] = xr; | ||
2142 | xr = a[28] - xr; a[28] = xr; | ||
2143 | xr = a[29] - xr; a[29] = xr; | ||
2144 | |||
2145 | xr = a[ 0]; a[ 0] += a[31]; a[31] -= xr; | ||
2146 | xr = a[ 1]; a[ 1] += a[30]; a[30] -= xr; | ||
2147 | xr = a[16]; a[16] += a[15]; a[15] -= xr; | ||
2148 | xr = a[17]; a[17] += a[14]; a[14] -= xr; | ||
2149 | xr = a[ 8]; a[ 8] += a[23]; a[23] -= xr; | ||
2150 | xr = a[ 9]; a[ 9] += a[22]; a[22] -= xr; | ||
2151 | xr = a[24]; a[24] += a[ 7]; a[ 7] -= xr; | ||
2152 | xr = a[25]; a[25] += a[ 6]; a[ 6] -= xr; | ||
2153 | xr = a[ 4]; a[ 4] += a[27]; a[27] -= xr; | ||
2154 | xr = a[ 5]; a[ 5] += a[26]; a[26] -= xr; | ||
2155 | xr = a[20]; a[20] += a[11]; a[11] -= xr; | ||
2156 | xr = a[21]; a[21] += a[10]; a[10] -= xr; | ||
2157 | xr = a[12]; a[12] += a[19]; a[19] -= xr; | ||
2158 | xr = a[13]; a[13] += a[18]; a[18] -= xr; | ||
2159 | xr = a[28]; a[28] += a[ 3]; a[ 3] -= xr; | ||
2160 | xr = a[29]; a[29] += a[ 2]; a[ 2] -= xr; | ||
2161 | |||
2162 | /* Compensate for inversion in the analysis filter */ | ||
2163 | if (k & 1) | ||
2164 | { | ||
2165 | for (int band = 1; band < 32; band += 2) | ||
2166 | a[band] *= -1; | ||
2167 | } | ||
2168 | } | ||
2169 | } | ||
2170 | |||
2171 | static inline void window_subband2_m(int a0[32]) | ||
2172 | { | ||
2173 | window_subband2_(a0); | ||
2174 | } | ||
2175 | |||
2176 | static inline void window_subband2_s(int a0[32], int a1[32]) | ||
2177 | { | ||
2178 | window_subband2_(a0); | ||
2179 | window_subband2_(a1); | ||
1888 | } | 2180 | } |
1889 | 2181 | ||
1890 | static void ICODE_ATTR mdct_long(int *out, int *in) | 2182 | static inline void mdct_long(int *out, int *in) |
1891 | { | 2183 | { |
1892 | int ct,st; | 2184 | int ct, st; |
1893 | int tc1, tc2, tc3, tc4, ts5, ts6, ts7, ts8; | 2185 | int tc1, tc2, tc3, tc4, ts5, ts6, ts7, ts8; |
1894 | int ts1, ts2, ts3, ts4, tc5, tc6, tc7, tc8; | 2186 | int ts1, ts2, ts3, ts4, tc5, tc6, tc7, tc8; |
1895 | 2187 | ||
1896 | /* 1,2, 5,6, 9,10, 13,14, 17 */ | 2188 | /* 1,2, 5,6, 9,10, 13,14, 17 */ |
1897 | tc1 = in[17] - in[ 9]; | 2189 | tc1 = in[17] - in[ 9]; |
1898 | tc3 = in[15] - in[11]; | 2190 | tc3 = in[15] - in[11]; |
1899 | tc4 = in[14] - in[12]; | 2191 | tc4 = in[14] - in[12]; |
1900 | ts5 = in[ 0] + in[ 8]; | 2192 | ts5 = in[ 0] + in[ 8]; |
1901 | ts6 = in[ 1] + in[ 7]; | 2193 | ts6 = in[ 1] + in[ 7]; |
1902 | ts7 = in[ 2] + in[ 6]; | 2194 | ts7 = in[ 2] + in[ 6]; |
1903 | ts8 = in[ 3] + in[ 5]; | 2195 | ts8 = in[ 3] + in[ 5]; |
1904 | 2196 | ||
1905 | out[17] = (ts5 + ts7 - ts8) * cx[8] - (ts6 - in[4]) * cx[8]; | 2197 | out[17] = (ts5 + ts7 - ts8) * cx[8] - (ts6 - in[4]) * cx[8]; |
1906 | st = (ts5 + ts7 - ts8) * cx[7] + (ts6 - in[4]) * cx[8]; | 2198 | st = (ts5 + ts7 - ts8) * cx[7] + (ts6 - in[4]) * cx[8]; |
1907 | ct = (tc1 - tc3 - tc4) * cx[6]; | 2199 | ct = (tc1 - tc3 - tc4) * cx[6]; |
1908 | out[5] = ct + st; | 2200 | out[5] = ct + st; |
1909 | out[6] = ct - st; | 2201 | out[6] = ct - st; |
1910 | 2202 | ||
1911 | tc2 = (in[16] - in[10]) * cx[6]; | 2203 | tc2 = (in[16] - in[10]) * cx[6]; |
1912 | ts6 = ts6 * cx[7] + in[4] * cx[8]; | 2204 | ts6 = ts6 * cx[7] + in[4] * cx[8]; |
1913 | 2205 | ||
1914 | ct = tc1 * cx[0] + tc2 + tc3 * cx[1] + tc4 * cx[2]; | 2206 | ct = tc1 * cx[0] + tc2 + tc3 * cx[1] + tc4 * cx[2]; |
1915 | st = -ts5 * cx[4] + ts6 - ts7 * cx[5] + ts8 * cx[3]; | 2207 | st = -ts5 * cx[4] + ts6 - ts7 * cx[5] + ts8 * cx[3]; |
1916 | out[1] = ct + st; | 2208 | out[1] = ct + st; |
1917 | out[2] = ct - st; | 2209 | out[2] = ct - st; |
1918 | 2210 | ||
1919 | ct = tc1 * cx[1] - tc2 - tc3 * cx[2] + tc4 * cx[0]; | 2211 | ct = tc1 * cx[1] - tc2 - tc3 * cx[2] + tc4 * cx[0]; |
1920 | st = -ts5 * cx[5] + ts6 - ts7 * cx[3] + ts8 * cx[4]; | 2212 | st = -ts5 * cx[5] + ts6 - ts7 * cx[3] + ts8 * cx[4]; |
1921 | out[ 9] = ct + st; | 2213 | out[ 9] = ct + st; |
1922 | out[10] = ct - st; | 2214 | out[10] = ct - st; |
1923 | 2215 | ||
1924 | ct = tc1 * cx[2] - tc2 + tc3 * cx[0] - tc4 * cx[1]; | 2216 | ct = tc1 * cx[2] - tc2 + tc3 * cx[0] - tc4 * cx[1]; |
1925 | st = ts5 * cx[3] - ts6 + ts7 * cx[4] - ts8 * cx[5]; | 2217 | st = ts5 * cx[3] - ts6 + ts7 * cx[4] - ts8 * cx[5]; |
1926 | out[13] = ct + st; | 2218 | out[13] = ct + st; |
1927 | out[14] = ct - st; | 2219 | out[14] = ct - st; |
1928 | 2220 | ||
1929 | ts1 = in[ 8] - in[ 0]; | 2221 | ts1 = in[ 8] - in[ 0]; |
1930 | ts3 = in[ 6] - in[ 2]; | 2222 | ts3 = in[ 6] - in[ 2]; |
1931 | ts4 = in[ 5] - in[ 3]; | 2223 | ts4 = in[ 5] - in[ 3]; |
1932 | tc5 = in[17] + in[ 9]; | 2224 | tc5 = in[17] + in[ 9]; |
1933 | tc6 = in[16] + in[10]; | 2225 | tc6 = in[16] + in[10]; |
1934 | tc7 = in[15] + in[11]; | 2226 | tc7 = in[15] + in[11]; |
1935 | tc8 = in[14] + in[12]; | 2227 | tc8 = in[14] + in[12]; |
1936 | 2228 | ||
1937 | out[0] = (tc5 + tc7 + tc8) * cx[8] + (tc6 + in[13]) * cx[8]; | 2229 | out[0] = (tc5 + tc7 + tc8) * cx[8] + (tc6 + in[13]) * cx[8]; |
1938 | ct = (tc5 + tc7 + tc8) * cx[7] - (tc6 + in[13]) * cx[8]; | 2230 | ct = (tc5 + tc7 + tc8) * cx[7] - (tc6 + in[13]) * cx[8]; |
1939 | st = (ts1 - ts3 + ts4) * cx[6]; | 2231 | st = (ts1 - ts3 + ts4) * cx[6]; |
1940 | out[11] = ct + st; | 2232 | out[11] = ct + st; |
1941 | out[12] = ct - st; | 2233 | out[12] = ct - st; |
1942 | 2234 | ||
1943 | ts2 = (in[7] - in[1]) * cx[6]; | 2235 | ts2 = (in[7] - in[1]) * cx[6]; |
1944 | tc6 = in[13] * cx[8] - tc6 * cx[7]; | 2236 | tc6 = in[13] * cx[8] - tc6 * cx[7]; |
1945 | 2237 | ||
1946 | ct = tc5 * cx[3] - tc6 + tc7 * cx[4] + tc8 * cx[5]; | 2238 | ct = tc5 * cx[3] - tc6 + tc7 * cx[4] + tc8 * cx[5]; |
1947 | st = ts1 * cx[2] + ts2 + ts3 * cx[0] + ts4 * cx[1]; | 2239 | st = ts1 * cx[2] + ts2 + ts3 * cx[0] + ts4 * cx[1]; |
1948 | out[3] = ct + st; | 2240 | out[3] = ct + st; |
1949 | out[4] = ct - st; | 2241 | out[4] = ct - st; |
1950 | 2242 | ||
1951 | ct =-tc5 * cx[5] + tc6 - tc7 * cx[3] - tc8 * cx[4]; | 2243 | ct =-tc5 * cx[5] + tc6 - tc7 * cx[3] - tc8 * cx[4]; |
1952 | st = ts1 * cx[1] + ts2 - ts3 * cx[2] - ts4 * cx[0]; | 2244 | st = ts1 * cx[1] + ts2 - ts3 * cx[2] - ts4 * cx[0]; |
1953 | out[7] = ct + st; | 2245 | out[7] = ct + st; |
1954 | out[8] = ct - st; | 2246 | out[8] = ct - st; |
1955 | 2247 | ||
1956 | ct =-tc5 * cx[4] + tc6 - tc7 * cx[5] - tc8 * cx[3]; | 2248 | ct =-tc5 * cx[4] + tc6 - tc7 * cx[5] - tc8 * cx[3]; |
1957 | st = ts1 * cx[0] - ts2 + ts3 * cx[1] - ts4 * cx[2]; | 2249 | st = ts1 * cx[0] - ts2 + ts3 * cx[1] - ts4 * cx[2]; |
1958 | out[15] = ct + st; | 2250 | out[15] = ct + st; |
1959 | out[16] = ct - st; | 2251 | out[16] = ct - st; |
1960 | } | 2252 | } |
1961 | 2253 | ||
1962 | static int find_bitrate_index(int type, int bitrate, bool stereo) | 2254 | static int find_bitrate_index(int type, int bitrate, bool stereo) |
@@ -1970,7 +2262,7 @@ static int find_bitrate_index(int type, int bitrate, bool stereo) | |||
1970 | 2262 | ||
1971 | static int find_samplerate_index(long freq, int *mp3_type) | 2263 | static int find_samplerate_index(long freq, int *mp3_type) |
1972 | { | 2264 | { |
1973 | int mpeg = freq >= (32000+24000)/2 ? 1 : 0; | 2265 | int mpeg = freq >= (32000 + 24000) / 2 ? 1 : 0; |
1974 | int i = ci->round_value_to_list32(freq, sampr_index[mpeg], 3, true); | 2266 | int i = ci->round_value_to_list32(freq, sampr_index[mpeg], 3, true); |
1975 | *mp3_type = mpeg; | 2267 | *mp3_type = mpeg; |
1976 | return i; | 2268 | return i; |
@@ -1978,12 +2270,14 @@ static int find_samplerate_index(long freq, int *mp3_type) | |||
1978 | 2270 | ||
1979 | static void mp3_encoder_reset(void) | 2271 | static void mp3_encoder_reset(void) |
1980 | { | 2272 | { |
1981 | memset(&cfg.cod_info, 0, sizeof(cfg.cod_info)); | 2273 | ci->memset(&cfg.cod_info, 0, sizeof (cfg.cod_info)); |
1982 | memset(mfbuf , 0, sizeof(mfbuf )); | 2274 | ci->memset(mfbuf , 0, sizeof (mfbuf )); |
1983 | memset(mdct_freq , 0, sizeof(mdct_freq )); | 2275 | ci->memset(sb_data , 0, sizeof (sb_data )); |
1984 | memset(enc_data , 0, sizeof(enc_data )); | 2276 | ci->memset(mdct_freq , 0, sizeof (mdct_freq )); |
1985 | memset(sb_data , 0, sizeof(sb_data )); | 2277 | ci->memset(mdct_sign , 0, sizeof (mdct_sign )); |
1986 | memset(&CodedData , 0, sizeof(CodedData )); | 2278 | ci->memset(enc_data , 0, sizeof (enc_data )); |
2279 | ci->memset(&coded_data , 0, sizeof (coded_data )); | ||
2280 | ci->memset(band_scale_f , 0, sizeof (band_scale_f)); | ||
1987 | cfg.slot_lag = 0; | 2281 | cfg.slot_lag = 0; |
1988 | } | 2282 | } |
1989 | 2283 | ||
@@ -2018,75 +2312,13 @@ static void mp3_encoder_init(unsigned long sample_rate, int num_channels, | |||
2018 | cfg.delay = 576-16; | 2312 | cfg.delay = 576-16; |
2019 | cfg.padding = 3*576+16; | 2313 | cfg.padding = 3*576+16; |
2020 | 2314 | ||
2021 | cfg.samp_buffer = mfbuf + 2*512; | 2315 | cfg.samp_buffer = mfbuf + cfg.channels*512; |
2022 | 2316 | ||
2023 | memcpy(scalefac, sfBand[cfg.mpg.smpl_id + 3*cfg.mpg.type], sizeof(scalefac)); | 2317 | ci->memcpy(scalefac, sf_band[cfg.mpg.smpl_id + 3*cfg.mpg.type], |
2024 | memcpy(ca , ca_const , sizeof(ca )); | 2318 | sizeof (scalefac)); |
2025 | memcpy(cs , cs_const , sizeof(cs )); | ||
2026 | memcpy(cx , cx_const , sizeof(cx )); | ||
2027 | memcpy(win , win_const , sizeof(win )); | ||
2028 | memcpy(enwindow , enwindow_const , sizeof(enwindow )); | ||
2029 | memcpy(int2idx , int2idx_const , sizeof(int2idx )); | ||
2030 | memcpy(ht_count , ht_count_const , sizeof(ht_count )); | ||
2031 | memcpy( tab01 , tab01_const , sizeof(tab01 )); | ||
2032 | memcpy( tab23 , tab23_const , sizeof(tab23 )); | ||
2033 | memcpy( tab56 , tab56_const , sizeof(tab56 )); | ||
2034 | memcpy( tab1315 , tab1315_const , sizeof(tab1315 )); | ||
2035 | memcpy( tab1624 , tab1624_const , sizeof(tab1624 )); | ||
2036 | memcpy( tab789 , tab789_const , sizeof(tab789 )); | ||
2037 | memcpy( tabABC , tabABC_const , sizeof(tabABC )); | ||
2038 | memcpy( t1HB , t1HB_const , sizeof(t1HB )); | ||
2039 | memcpy( t2HB , t2HB_const , sizeof(t2HB )); | ||
2040 | memcpy( t3HB , t3HB_const , sizeof(t3HB )); | ||
2041 | memcpy( t5HB , t5HB_const , sizeof(t5HB )); | ||
2042 | memcpy( t6HB , t6HB_const , sizeof(t6HB )); | ||
2043 | memcpy( t7HB , t7HB_const , sizeof(t7HB )); | ||
2044 | memcpy( t8HB , t8HB_const , sizeof(t8HB )); | ||
2045 | memcpy( t9HB , t9HB_const , sizeof(t9HB )); | ||
2046 | memcpy(t10HB , t10HB_const , sizeof(t10HB )); | ||
2047 | memcpy(t11HB , t11HB_const , sizeof(t11HB )); | ||
2048 | memcpy(t12HB , t12HB_const , sizeof(t12HB )); | ||
2049 | memcpy(t13HB , t13HB_const , sizeof(t13HB )); | ||
2050 | memcpy(t15HB , t15HB_const , sizeof(t15HB )); | ||
2051 | memcpy(t16HB , t16HB_const , sizeof(t16HB )); | ||
2052 | memcpy(t24HB , t24HB_const , sizeof(t24HB )); | ||
2053 | memcpy( t1l , t1l_const , sizeof(t1l )); | ||
2054 | memcpy( t2l , t2l_const , sizeof(t2l )); | ||
2055 | memcpy( t3l , t3l_const , sizeof(t3l )); | ||
2056 | memcpy( t5l , t5l_const , sizeof(t5l )); | ||
2057 | memcpy( t6l , t6l_const , sizeof(t6l )); | ||
2058 | memcpy( t7l , t7l_const , sizeof(t7l )); | ||
2059 | memcpy( t8l , t8l_const , sizeof(t8l )); | ||
2060 | memcpy( t9l , t9l_const , sizeof(t9l )); | ||
2061 | memcpy(t10l , t10l_const , sizeof(t10l )); | ||
2062 | memcpy(t11l , t11l_const , sizeof(t11l )); | ||
2063 | memcpy(t12l , t12l_const , sizeof(t12l )); | ||
2064 | memcpy(t13l , t13l_const , sizeof(t13l )); | ||
2065 | memcpy(t15l , t15l_const , sizeof(t15l )); | ||
2066 | memcpy(t16l , t16l_const , sizeof(t16l )); | ||
2067 | memcpy(t24l , t24l_const , sizeof(t24l )); | ||
2068 | memcpy(ht , ht_const , sizeof(ht )); | ||
2069 | memset(band_scale_f, 0 , sizeof(band_scale_f)); | ||
2070 | |||
2071 | ht[ 0].table = NULL; ht[ 0].hlen = NULL; /* Apparently not used */ | ||
2072 | ht[ 1].table = t1HB; ht[ 1].hlen = t1l; | ||
2073 | ht[ 2].table = t2HB; ht[ 2].hlen = t2l; | ||
2074 | ht[ 3].table = t3HB; ht[ 3].hlen = t3l; | ||
2075 | ht[ 4].table = NULL; ht[ 4].hlen = NULL; /* Apparently not used */ | ||
2076 | ht[ 5].table = t5HB; ht[ 5].hlen = t5l; | ||
2077 | ht[ 6].table = t6HB; ht[ 6].hlen = t6l; | ||
2078 | ht[ 7].table = t7HB; ht[ 7].hlen = t7l; | ||
2079 | ht[ 8].table = t8HB; ht[ 8].hlen = t8l; | ||
2080 | ht[ 9].table = t9HB; ht[ 9].hlen = t9l; | ||
2081 | ht[10].table = t10HB; ht[10].hlen = t10l; | ||
2082 | ht[11].table = t11HB; ht[11].hlen = t11l; | ||
2083 | ht[12].table = t12HB; ht[12].hlen = t12l; | ||
2084 | ht[13].table = t13HB; ht[13].hlen = t13l; | ||
2085 | ht[14].table = NULL; ht[14].hlen = NULL; /* Apparently not used */ | ||
2086 | ht[15].table = t15HB; ht[15].hlen = t15l; | ||
2087 | 2319 | ||
2088 | /* Figure average number of 'bytes' per frame */ | 2320 | /* Figure average number of 'bytes' per frame */ |
2089 | cfg.byte_per_frame = calcFrameSize(cfg.mpg.bitr_id, &cfg.frac_per_frame); | 2321 | cfg.byte_per_frame = calc_frame_size(cfg.mpg.bitr_id, &cfg.frac_per_frame); |
2090 | cfg.sideinfo_len = 32 + (cfg.mpg.type ? (cfg.channels == 1 ? 136 : 256) | 2322 | cfg.sideinfo_len = 32 + (cfg.mpg.type ? (cfg.channels == 1 ? 136 : 256) |
2091 | : (cfg.channels == 1 ? 72 : 136)); | 2323 | : (cfg.channels == 1 ? 72 : 136)); |
2092 | 2324 | ||
@@ -2096,107 +2328,122 @@ static void mp3_encoder_init(unsigned long sample_rate, int num_channels, | |||
2096 | 2328 | ||
2097 | static void set_scale_facs(int *mdct_freq) | 2329 | static void set_scale_facs(int *mdct_freq) |
2098 | { | 2330 | { |
2099 | unsigned int i, is, ie, k, s; | 2331 | int avrg_freq_val = 0; |
2100 | int max_freq_val, avrg_freq_val; | ||
2101 | 2332 | ||
2102 | /* calc average of first 256 frequency values */ | 2333 | /* calc average of first 256 frequency values */ |
2103 | for(avrg_freq_val=i=0; i<256; i++) | 2334 | for (int i = 0; i < 256; i++) |
2104 | avrg_freq_val += mdct_freq[i]; | 2335 | avrg_freq_val += mdct_freq[i]; |
2105 | avrg_freq_val >>= 8; | ||
2106 | 2336 | ||
2107 | /* if max of current band is smaller than average, increase precision */ | 2337 | avrg_freq_val >>= 8; |
2108 | /* last band keeps untouched (not scaled) */ | ||
2109 | for(is=k=0; is<scalefac[21]; k++) | ||
2110 | { | ||
2111 | max_freq_val = 0; | ||
2112 | 2338 | ||
2113 | for(i=is, ie=scalefac[k+1]; i<ie; i++) | 2339 | /* if max of current band is smaller than average, increase precision */ |
2114 | if(max_freq_val < mdct_freq[i]) | 2340 | /* last band keeps untouched (not scaled) */ |
2115 | max_freq_val = mdct_freq[i]; | 2341 | for (unsigned int k = 0, is = 0; is < scalefac[20]; k++) |
2342 | { | ||
2343 | int max_freq_val = 0; | ||
2344 | unsigned ie = scalefac[k]; | ||
2116 | 2345 | ||
2117 | for(s=0; s<3; s++) | 2346 | for (unsigned int i = is; i < ie; i++) |
2118 | if((max_freq_val<<s) > avrg_freq_val) | 2347 | { |
2119 | break; | 2348 | if (max_freq_val < mdct_freq[i]) |
2349 | max_freq_val = mdct_freq[i]; | ||
2350 | } | ||
2120 | 2351 | ||
2121 | band_scale_f[k] = (unsigned char)s; | 2352 | unsigned int s = 0; |
2353 | for (; s < 3; s++) | ||
2354 | { | ||
2355 | if ((max_freq_val << s) > avrg_freq_val) | ||
2356 | break; | ||
2357 | } | ||
2122 | 2358 | ||
2123 | for(i=is; s && i<ie; i++) | 2359 | band_scale_f[k] = (unsigned char)s; |
2124 | mdct_freq[i] <<= s; | ||
2125 | 2360 | ||
2126 | is = ie; | 2361 | for (unsigned int i = is; s && i < ie; i++) |
2127 | } | 2362 | mdct_freq[i] <<= s; |
2363 | |||
2364 | is = ie; | ||
2365 | } | ||
2366 | } | ||
2367 | |||
2368 | static inline void window_subband(int gr, int sbd[2][2][18][32]) | ||
2369 | { | ||
2370 | int *a0 = sbd[0][1-gr][0]; | ||
2371 | |||
2372 | if (cfg.channels == 1) | ||
2373 | { | ||
2374 | window_subband1_m(mfbuf + 286 + gr*576, a0); | ||
2375 | window_subband2_m(a0); | ||
2376 | } | ||
2377 | else | ||
2378 | { | ||
2379 | int *a1 = sbd[1][1-gr][0]; | ||
2380 | window_subband1_s(mfbuf + 572 + gr*1152, a0, a1); | ||
2381 | window_subband2_s(a0, a1); | ||
2382 | } | ||
2128 | } | 2383 | } |
2129 | 2384 | ||
2130 | static size_t ICODE_ATTR mp3_encoder_encode_frame(uint8_t *outbuf) | 2385 | static inline void get_sb_data(int gr) |
2131 | { | 2386 | { |
2132 | int gr, gr_cnt; | 2387 | #ifdef MP3_ENC_COP |
2133 | uint32_t max; | 2388 | ci->memcpy(sb_data[0][1-gr], (*sb_data_enc)[0][1-gr], |
2389 | sizeof (sb_data[0][1-gr])); | ||
2390 | |||
2391 | if (cfg.channels > 1) | ||
2392 | ci->memcpy(sb_data[1][1-gr], (*sb_data_enc)[1][1-gr], | ||
2393 | sizeof (sb_data[1][1-gr])); | ||
2394 | #else /* !MP3_ENC_COP */ | ||
2395 | window_subband(gr, sb_data); | ||
2396 | #endif /* MP3_ENC_COP */ | ||
2397 | } | ||
2134 | 2398 | ||
2135 | /* encode one mp3 frame in this loop */ | 2399 | /* Encode one mp3 frame */ |
2136 | CodedData.bitpos = 0; | 2400 | static void ICODE_ATTR compress_frame(void) |
2137 | memset(CodedData.bbuf, 0, sizeof(CodedData.bbuf)); | 2401 | { |
2402 | coded_data.bitpos = cfg.sideinfo_len; /* leave space for mp3 header */ | ||
2403 | ci->memset(coded_data.bbuf, 0, sizeof (coded_data.bbuf)); | ||
2138 | 2404 | ||
2139 | if((cfg.slot_lag += cfg.frac_per_frame) >= 64) | 2405 | if ((cfg.slot_lag += cfg.frac_per_frame) >= 64) |
2140 | { /* Padding for this frame */ | 2406 | { |
2407 | /* Padding for this frame */ | ||
2141 | cfg.slot_lag -= 64; | 2408 | cfg.slot_lag -= 64; |
2142 | cfg.mpg.padding = 1; | 2409 | cfg.mpg.padding = 1; |
2143 | } | 2410 | } |
2144 | else | 2411 | else |
2412 | { | ||
2145 | cfg.mpg.padding = 0; | 2413 | cfg.mpg.padding = 0; |
2414 | } | ||
2146 | 2415 | ||
2147 | cfg.mean_bits = (8 * cfg.byte_per_frame + 8 * cfg.mpg.padding | 2416 | cfg.mean_bits = (8 * cfg.byte_per_frame + 8 * cfg.mpg.padding |
2148 | - cfg.sideinfo_len) / cfg.granules / cfg.channels | 2417 | - cfg.sideinfo_len) / cfg.granules / cfg.channels |
2149 | - 42; // reserved for scale_facs | 2418 | - 42; // reserved for scale_facs |
2150 | 2419 | ||
2151 | cfg.ResvSize = 0; | 2420 | cfg.resv_size = 0; |
2152 | gr_cnt = cfg.granules * cfg.channels; | ||
2153 | CodedData.bitpos = cfg.sideinfo_len; /* leave space for mp3 header */ | ||
2154 | 2421 | ||
2155 | for(gr=0; gr<cfg.granules; gr++) | 2422 | int gr_cnt = cfg.granules * cfg.channels; |
2423 | for (int gr = 0; gr < cfg.granules; gr++) | ||
2156 | { | 2424 | { |
2157 | short *wk = mfbuf + 2*286 + gr*1152; | 2425 | get_sb_data(gr); |
2158 | int ch; | ||
2159 | |||
2160 | /* 16bit packed wav data can be windowed efficiently on coldfire */ | ||
2161 | window_subband1(wk, sb_data[0][1-gr][0], sb_data[1][1-gr][0]); | ||
2162 | 2426 | ||
2163 | for(ch=0; ch<cfg.channels; ch++) | 2427 | for (int ch = 0; ch < cfg.channels; ch++, gr_cnt--) |
2164 | { | 2428 | { |
2165 | int ii, k, shift; | ||
2166 | |||
2167 | wk = mfbuf + 2*286 + gr*1152 + ch; | ||
2168 | |||
2169 | /* 36864=4*18*16*32 */ | ||
2170 | for(k=0; k<18; k++, wk+=64) | ||
2171 | { | ||
2172 | window_subband2(wk, sb_data[ch][1-gr][k]); | ||
2173 | /* Compensate for inversion in the analysis filter */ | ||
2174 | if(k & 1) | ||
2175 | { | ||
2176 | int band; | ||
2177 | for(band=1; band<32; band+=2) | ||
2178 | sb_data[ch][1-gr][k][band] *= -1; | ||
2179 | } | ||
2180 | } | ||
2181 | |||
2182 | /* Perform imdct of 18 previous + 18 current subband samples */ | 2429 | /* Perform imdct of 18 previous + 18 current subband samples */ |
2183 | /* for integer precision do this loop again (if neccessary) */ | 2430 | /* for integer precision do this loop again (if neccessary) */ |
2184 | shift = 14 - (cfg.cod_info[gr][ch].additStep >> 2); | 2431 | int shift = 14 - (cfg.cod_info[gr][ch].additStep >> 2); |
2185 | for(k=1,ii=0; ii<3 && k; ii++) | 2432 | |
2433 | for (int ii = 0; ii < 3; ii++) | ||
2186 | { | 2434 | { |
2187 | int *mdct = mdct_freq; | 2435 | int *mdct = mdct_freq; |
2188 | int band; | ||
2189 | 2436 | ||
2190 | cfg.cod_info[gr][ch].additStep = 4 * (14 - shift); | 2437 | cfg.cod_info[gr][ch].additStep = 4 * (14 - shift); |
2191 | 2438 | ||
2192 | for(band=0; band<cfg.mpg.num_bands; band++, mdct+=18) | 2439 | for (int band = 0; band < cfg.mpg.num_bands; band++, mdct += 18) |
2193 | { | 2440 | { |
2194 | int *band0 = sb_data[ch][ gr][0] + order[band]; | 2441 | int *band0 = sb_data[ch][ gr][0] + order[band]; |
2195 | int *band1 = sb_data[ch][1-gr][0] + order[band]; | 2442 | int *band1 = sb_data[ch][1-gr][0] + order[band]; |
2196 | int work[18]; | 2443 | int work[18]; |
2197 | 2444 | ||
2198 | /* 9216=4*32*9*8 */ | 2445 | /* 9216=4*32*9*8 */ |
2199 | for(k=-9; k<0; k++) | 2446 | for (int k = -9; k < 0; k++) |
2200 | { | 2447 | { |
2201 | int a = shft_n(band1[(k+9)*32], shift); | 2448 | int a = shft_n(band1[(k+9)*32], shift); |
2202 | int b = shft_n(band1[(8-k)*32], shift); | 2449 | int b = shft_n(band1[(8-k)*32], shift); |
@@ -2218,25 +2465,25 @@ static size_t ICODE_ATTR mp3_encoder_encode_frame(uint8_t *outbuf) | |||
2218 | mdct_long(mdct, work); | 2465 | mdct_long(mdct, work); |
2219 | 2466 | ||
2220 | /* Perform aliasing reduction butterfly */ | 2467 | /* Perform aliasing reduction butterfly */ |
2221 | if(band != 0) | 2468 | if (band != 0) |
2222 | { | 2469 | { |
2223 | for(k=7; k>=0; --k) | 2470 | for (int k = 7; k >= 0; k--) |
2224 | { | 2471 | { |
2225 | int bu, bd; | 2472 | int bu = shft15(mdct[k]) * ca[k] + |
2226 | bu = shft15(mdct[k]) * ca[k] + | 2473 | shft15(mdct[-1-k]) * cs[k]; |
2227 | shft15(mdct[-1-k]) * cs[k]; | 2474 | int bd = shft15(mdct[k]) * cs[k] - |
2228 | bd = shft15(mdct[k]) * cs[k] - | 2475 | shft15(mdct[-1-k]) * ca[k]; |
2229 | shft15(mdct[-1-k]) * ca[k]; | ||
2230 | mdct[-1-k] = bu; | 2476 | mdct[-1-k] = bu; |
2231 | mdct[ k ] = bd; | 2477 | mdct[ k ] = bd; |
2232 | } | 2478 | } |
2233 | } | 2479 | } |
2234 | } | 2480 | } |
2235 | 2481 | ||
2236 | max = 0; | 2482 | uint32_t max = 0; |
2237 | for(k=0; k<576; k++) | 2483 | |
2484 | for (int k = 0; k < 576; k++) | ||
2238 | { | 2485 | { |
2239 | if(mdct_freq[k] < 0) | 2486 | if (mdct_freq[k] < 0) |
2240 | { | 2487 | { |
2241 | mdct_sign[k] = 1; /* negative */ | 2488 | mdct_sign[k] = 1; /* negative */ |
2242 | mdct_freq[k] = shft13(-mdct_freq[k]); | 2489 | mdct_freq[k] = shft13(-mdct_freq[k]); |
@@ -2247,15 +2494,18 @@ static size_t ICODE_ATTR mp3_encoder_encode_frame(uint8_t *outbuf) | |||
2247 | mdct_freq[k] = shft13(mdct_freq[k]); | 2494 | mdct_freq[k] = shft13(mdct_freq[k]); |
2248 | } | 2495 | } |
2249 | 2496 | ||
2250 | if(max < (uint32_t)mdct_freq[k]) | 2497 | if (max < (uint32_t)mdct_freq[k]) |
2251 | max = (uint32_t)mdct_freq[k]; | 2498 | max = (uint32_t)mdct_freq[k]; |
2252 | } | 2499 | } |
2500 | |||
2253 | cfg.cod_info[gr][ch].max_val = max; | 2501 | cfg.cod_info[gr][ch].max_val = max; |
2254 | 2502 | ||
2255 | /* calc new shift for higher integer precision */ | 2503 | /* calc new shift for higher integer precision */ |
2256 | for(k=0; max<(uint32_t)(0x7800>>k); k++) shift--; | 2504 | int i = 0; |
2257 | for( ; (max>>k)>=(uint32_t)0x10000; k++) shift++; | 2505 | while (max < (0x7800u >> i)) i++, shift--; |
2258 | if(shift < 0) shift = 0; | 2506 | while ((max >> i) >= 0x10000u) i++, shift++; |
2507 | if (i == 0) break; | ||
2508 | if (shift < 0) shift = 0; | ||
2259 | } | 2509 | } |
2260 | 2510 | ||
2261 | cfg.cod_info[gr][ch].quantStep += | 2511 | cfg.cod_info[gr][ch].quantStep += |
@@ -2264,41 +2514,56 @@ static size_t ICODE_ATTR mp3_encoder_encode_frame(uint8_t *outbuf) | |||
2264 | set_scale_facs(mdct_freq); | 2514 | set_scale_facs(mdct_freq); |
2265 | 2515 | ||
2266 | /* bit and noise allocation */ | 2516 | /* bit and noise allocation */ |
2267 | iteration_loop(mdct_freq, &cfg.cod_info[gr][ch], | 2517 | iteration_loop(mdct_freq, &cfg.cod_info[gr][ch], gr_cnt); |
2268 | gr_cnt--); | 2518 | |
2269 | /* write the frame to the bitstream */ | 2519 | /* write the frame to the bitstream */ |
2270 | Huffmancodebits(enc_data, mdct_sign, | 2520 | huffman_code_bits(enc_data, mdct_sign, &cfg.cod_info[gr][ch]); |
2271 | &cfg.cod_info[gr][ch]); | ||
2272 | 2521 | ||
2273 | cfg.cod_info[gr][ch].quantStep -= | 2522 | cfg.cod_info[gr][ch].quantStep -= |
2274 | cfg.cod_info[gr][ch].additStep; | 2523 | cfg.cod_info[gr][ch].additStep; |
2275 | 2524 | ||
2276 | if(cfg.granules == 1) | 2525 | if (cfg.granules == 1) |
2277 | { | 2526 | { |
2278 | memcpy(sb_data[ch][0], sb_data[ch][1], | 2527 | ci->memcpy(sb_data[ch][0], sb_data[ch][1], |
2279 | sizeof(sb_data[ch][0])); | 2528 | sizeof (sb_data[ch][0])); |
2280 | } | 2529 | } |
2281 | } | 2530 | } |
2282 | } | 2531 | } |
2283 | 2532 | ||
2284 | /* shift out old samples */ | ||
2285 | memmove(mfbuf, mfbuf + 2*cfg.granules*576, 4*512); | ||
2286 | |||
2287 | /* finish this chunk by adding sideinfo header data */ | 2533 | /* finish this chunk by adding sideinfo header data */ |
2288 | CodedData.bitpos = 0; | 2534 | coded_data.bitpos = 0; |
2289 | encodeSideInfo( cfg.cod_info ); | 2535 | encode_side_info(cfg.cod_info); |
2536 | } | ||
2537 | |||
2538 | /* Process the PCM data in the encoder's input buffer */ | ||
2539 | static void mp3_enc_encode_frame(void) | ||
2540 | { | ||
2541 | #ifdef MP3_ENC_COP | ||
2542 | for (int gr = 0; gr < cfg.granules; gr++) | ||
2543 | window_subband(gr, *sb_data_cod); | ||
2544 | #else | ||
2545 | compress_frame(); | ||
2546 | #endif /* MP3_ENC_COP */ | ||
2547 | |||
2548 | /* shift out old samples */ | ||
2549 | ci->memmove(mfbuf, mfbuf + cfg.channels*cfg.granules*576, | ||
2550 | cfg.channels*2*512); | ||
2551 | } | ||
2290 | 2552 | ||
2553 | /* Get the last encoded frame */ | ||
2554 | static size_t ICODE_ATTR mp3_enc_get_frame(uint8_t *outbuf) | ||
2555 | { | ||
2291 | long size = cfg.byte_per_frame + cfg.mpg.padding; | 2556 | long size = cfg.byte_per_frame + cfg.mpg.padding; |
2292 | 2557 | ||
2293 | #ifdef ROCKBOX_LITTLE_ENDIAN | 2558 | #ifdef ROCKBOX_LITTLE_ENDIAN |
2294 | /* convert frame to big endian */ | 2559 | /* convert frame to big endian */ |
2295 | const uint32_t *src = CodedData.bbuf; | 2560 | const uint32_t *src = coded_data.bbuf; |
2296 | uint32_t *dst = (uint32_t *)outbuf; | 2561 | uint32_t *dst = (uint32_t *)outbuf; |
2297 | 2562 | ||
2298 | for(long i = 0; i < size; i += sizeof(uint32_t)) | 2563 | for (long i = 0; i < size; i += sizeof (uint32_t)) |
2299 | *dst++ = swap32(*src++); | 2564 | *dst++ = swap32(*src++); |
2300 | #else | 2565 | #else |
2301 | memcpy(outbuf, CodedData.bbuf, size); | 2566 | ci->memcpy(outbuf, coded_data.bbuf, size); |
2302 | #endif /* ROCKBOX_LITTLE_ENDIAN */ | 2567 | #endif /* ROCKBOX_LITTLE_ENDIAN */ |
2303 | 2568 | ||
2304 | return size; | 2569 | return size; |
@@ -2315,42 +2580,42 @@ static size_t ICODE_ATTR mp3_encoder_encode_frame(uint8_t *outbuf) | |||
2315 | * Uses the polynomial x^16+x^15+x^2+1 */ | 2580 | * Uses the polynomial x^16+x^15+x^2+1 */ |
2316 | static const uint16_t crc16_lookup[256] ICONST_ATTR = | 2581 | static const uint16_t crc16_lookup[256] ICONST_ATTR = |
2317 | { | 2582 | { |
2318 | 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, | 2583 | 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, |
2319 | 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, | 2584 | 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440, |
2320 | 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, | 2585 | 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, |
2321 | 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, | 2586 | 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, |
2322 | 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, | 2587 | 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40, |
2323 | 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, | 2588 | 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, |
2324 | 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, | 2589 | 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, |
2325 | 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, | 2590 | 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040, |
2326 | 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, | 2591 | 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, |
2327 | 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, | 2592 | 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, |
2328 | 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, | 2593 | 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41, |
2329 | 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, | 2594 | 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, |
2330 | 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, | 2595 | 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, |
2331 | 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, | 2596 | 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40, |
2332 | 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, | 2597 | 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, |
2333 | 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, | 2598 | 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041, |
2334 | 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, | 2599 | 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240, |
2335 | 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, | 2600 | 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, |
2336 | 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, | 2601 | 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, |
2337 | 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, | 2602 | 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, |
2338 | 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, | 2603 | 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, |
2339 | 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, | 2604 | 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, |
2340 | 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, | 2605 | 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640, |
2341 | 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, | 2606 | 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, |
2342 | 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, | 2607 | 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241, |
2343 | 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, | 2608 | 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440, |
2344 | 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, | 2609 | 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, |
2345 | 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, | 2610 | 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, |
2346 | 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, | 2611 | 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, |
2347 | 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, | 2612 | 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, |
2348 | 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, | 2613 | 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, |
2349 | 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 | 2614 | 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040 |
2350 | }; | 2615 | }; |
2351 | 2616 | ||
2352 | static ssize_t header_size; | 2617 | static ssize_t header_size IBSS_ATTR; |
2353 | static unsigned int mp3_crc16; | 2618 | static unsigned int mp3_crc16 IBSS_ATTR; |
2354 | 2619 | ||
2355 | /* fast CRC-16 computation - uses table crc16_lookup 8*/ | 2620 | /* fast CRC-16 computation - uses table crc16_lookup 8*/ |
2356 | static inline unsigned int crc_update_lookup(unsigned int value, | 2621 | static inline unsigned int crc_update_lookup(unsigned int value, |
@@ -2378,7 +2643,7 @@ static bool write_info_header(bool first_encode) | |||
2378 | 2643 | ||
2379 | /* By default the MP3 frame header for the info frame is the same as | 2644 | /* By default the MP3 frame header for the info frame is the same as |
2380 | unpadded audio frames */ | 2645 | unpadded audio frames */ |
2381 | uint32_t header = encodeHeader(0, cfg.mpg.bitr_id); | 2646 | uint32_t header = encode_header(0, cfg.mpg.bitr_id); |
2382 | 2647 | ||
2383 | int i = get_info_offset(header); | 2648 | int i = get_info_offset(header); |
2384 | 2649 | ||
@@ -2390,7 +2655,7 @@ static bool write_info_header(bool first_encode) | |||
2390 | int j; | 2655 | int j; |
2391 | for (j = cfg.mpg.bitr_id + 1; j < 15; j++) | 2656 | for (j = cfg.mpg.bitr_id + 1; j < 15; j++) |
2392 | { | 2657 | { |
2393 | size = calcFrameSize(j, NULL); | 2658 | size = calc_frame_size(j, NULL); |
2394 | 2659 | ||
2395 | if (size >= i + 8 + 36) | 2660 | if (size >= i + 8 + 36) |
2396 | break; | 2661 | break; |
@@ -2403,12 +2668,12 @@ static bool write_info_header(bool first_encode) | |||
2403 | return true; | 2668 | return true; |
2404 | } | 2669 | } |
2405 | 2670 | ||
2406 | header = encodeHeader(0, j); | 2671 | header = encode_header(0, j); |
2407 | /* Info offset won't change */ | 2672 | /* Info offset won't change */ |
2408 | } | 2673 | } |
2409 | 2674 | ||
2410 | uint8_t frame[size]; | 2675 | uint8_t frame[size]; |
2411 | memset(frame, 0, size); | 2676 | ci->memset(frame, 0, size); |
2412 | 2677 | ||
2413 | frame[0] = header >> 24; | 2678 | frame[0] = header >> 24; |
2414 | frame[1] = header >> 16; | 2679 | frame[1] = header >> 16; |
@@ -2416,13 +2681,13 @@ static bool write_info_header(bool first_encode) | |||
2416 | frame[3] = header >> 0; | 2681 | frame[3] = header >> 0; |
2417 | 2682 | ||
2418 | /* 'Info' header (CBR 'Xing') */ | 2683 | /* 'Info' header (CBR 'Xing') */ |
2419 | memcpy(&frame[i], "Info", 4); | 2684 | ci->memcpy(&frame[i], "Info", 4); |
2420 | 2685 | ||
2421 | /* flags = 0; Info contains no other sections and is 8 bytes */ | 2686 | /* flags = 0; Info contains no other sections and is 8 bytes */ |
2422 | 2687 | ||
2423 | /* Just mark the LAMEness to indicate header presence; we're not | 2688 | /* Just mark the LAMEness to indicate header presence; we're not |
2424 | actually _the_ LAME so 'rbshn' is the version we give */ | 2689 | actually _the_ LAME so 'rbshn' is the version we give */ |
2425 | memcpy(&frame[i + 8], "LAMErbshn", 9); | 2690 | ci->memcpy(&frame[i + 8], "LAMErbshn", 9); |
2426 | 2691 | ||
2427 | /* Fill-in some info about us | 2692 | /* Fill-in some info about us |
2428 | * reference: http://gabriel.mp3-tech.org/mp3infotag.html | 2693 | * reference: http://gabriel.mp3-tech.org/mp3infotag.html |
@@ -2481,7 +2746,7 @@ static bool write_info_header(bool first_encode) | |||
2481 | return true; | 2746 | return true; |
2482 | } | 2747 | } |
2483 | 2748 | ||
2484 | static inline int on_stream_data(struct enc_chunk_data *data) | 2749 | static int ICODE_ATTR on_stream_data(struct enc_chunk_data *data) |
2485 | { | 2750 | { |
2486 | ssize_t size = data->hdr.size; | 2751 | ssize_t size = data->hdr.size; |
2487 | 2752 | ||
@@ -2559,6 +2824,122 @@ static int on_stream_end(union enc_chunk_hdr *hdr) | |||
2559 | return 0; | 2824 | return 0; |
2560 | } | 2825 | } |
2561 | 2826 | ||
2827 | #ifdef MP3_ENC_COP | ||
2828 | /* Divide encoding duties between CPU and COP - | ||
2829 | CPU does the windowing and COP does the remainder of the encoding */ | ||
2830 | static const char enc_thread_name[] = { "MP3 enc" }; | ||
2831 | static enum enc_status | ||
2832 | { | ||
2833 | ENC_SB_EMPTY, | ||
2834 | ENC_SB_FULL, | ||
2835 | ENC_QUIT, | ||
2836 | } enc_status IBSS_ATTR; | ||
2837 | static struct semaphore enc_sema IBSS_ATTR; | ||
2838 | static struct semaphore cod_sema IBSS_ATTR; | ||
2839 | static unsigned int enc_thread_id; | ||
2840 | |||
2841 | /* Needs two extra loops to drain sb_data_buf. | ||
2842 | * Progress at state: | ||
2843 | * |F|F|F| | ||
2844 | *|1|2| : fill 1 | ||
2845 | * |2|1| : fill 2, get 1 | ||
2846 | * |1|2| : fill 1, get 2 | ||
2847 | * |2|1| : fill 2, get 1 | ||
2848 | * |1|2| : get 2 | ||
2849 | * |2|1| : get 1 | ||
2850 | * Loops = Fcount + 2 | ||
2851 | * | ||
2852 | * Case of Fcount==1, which would otherwise fail, never happens due to | ||
2853 | * padding frames. | ||
2854 | */ | ||
2855 | #define DRAIN_FRAMES 2 | ||
2856 | |||
2857 | static void enc_thread(void) | ||
2858 | { | ||
2859 | while (1) | ||
2860 | { | ||
2861 | ci->semaphore_release(&cod_sema); | ||
2862 | ci->semaphore_wait(&enc_sema, TIMEOUT_BLOCK); | ||
2863 | |||
2864 | if (enc_status == ENC_QUIT) | ||
2865 | break; | ||
2866 | |||
2867 | compress_frame(); | ||
2868 | } | ||
2869 | } | ||
2870 | #else /* !MP3_ENC_COP */ | ||
2871 | /* No encoder delay */ | ||
2872 | #define DRAIN_FRAMES 0 | ||
2873 | #endif /* MP3_ENC_COP */ | ||
2874 | |||
2875 | static bool enc_thread_init(void *stack, size_t stack_size) | ||
2876 | { | ||
2877 | #ifdef MP3_ENC_COP | ||
2878 | enc_status = ENC_SB_EMPTY; | ||
2879 | ci->semaphore_init(&enc_sema, 1, 0); | ||
2880 | ci->semaphore_init(&cod_sema, 1, 0); | ||
2881 | |||
2882 | sb_data_buf_init(); | ||
2883 | |||
2884 | enc_thread_id = ci->create_thread(enc_thread, stack, stack_size, | ||
2885 | 0, enc_thread_name | ||
2886 | IF_PRIO(, PRIORITY_PLAYBACK) | ||
2887 | IF_COP(, COP)); | ||
2888 | |||
2889 | if (enc_thread_id == 0) | ||
2890 | return false; | ||
2891 | #endif /* MP3_ENC_COP */ | ||
2892 | |||
2893 | return true; | ||
2894 | (void)stack; (void)stack_size; | ||
2895 | } | ||
2896 | |||
2897 | static inline void enc_thread_sb_data_ready(void) | ||
2898 | { | ||
2899 | #ifdef MP3_ENC_COP | ||
2900 | sb_data_buf_swap(); | ||
2901 | ci->semaphore_release(&enc_sema); | ||
2902 | #endif /* MP3_ENC_COP */ | ||
2903 | } | ||
2904 | |||
2905 | static void enc_thread_stop(void) | ||
2906 | { | ||
2907 | #ifdef MP3_ENC_COP | ||
2908 | enc_status = ENC_QUIT; | ||
2909 | ci->semaphore_release(&enc_sema); | ||
2910 | ci->thread_wait(enc_thread_id); | ||
2911 | #endif /* MP3_ENC_COP */ | ||
2912 | } | ||
2913 | |||
2914 | static inline void encode_frame(void) | ||
2915 | { | ||
2916 | mp3_enc_encode_frame(); | ||
2917 | } | ||
2918 | |||
2919 | static inline bool wait_for_frame(void) | ||
2920 | { | ||
2921 | #ifdef MP3_ENC_COP | ||
2922 | ci->semaphore_wait(&cod_sema, TIMEOUT_BLOCK); | ||
2923 | |||
2924 | if (enc_status == ENC_SB_EMPTY) | ||
2925 | { | ||
2926 | /* Fill subband data buffer before getting frame from COP */ | ||
2927 | enc_status = ENC_SB_FULL; | ||
2928 | enc_thread_sb_data_ready(); | ||
2929 | return false; | ||
2930 | } | ||
2931 | #endif /* MP3_ENC_COP */ | ||
2932 | |||
2933 | return true; | ||
2934 | } | ||
2935 | |||
2936 | static inline size_t get_frame(uint8_t *buffer) | ||
2937 | { | ||
2938 | size_t size = mp3_enc_get_frame(buffer); | ||
2939 | enc_thread_sb_data_ready(); | ||
2940 | return size; | ||
2941 | } | ||
2942 | |||
2562 | /* this is the codec entry point */ | 2943 | /* this is the codec entry point */ |
2563 | enum codec_status codec_main(enum codec_entry_call_reason reason) | 2944 | enum codec_status codec_main(enum codec_entry_call_reason reason) |
2564 | { | 2945 | { |
@@ -2573,13 +2954,20 @@ enum codec_status codec_main(enum codec_entry_call_reason reason) | |||
2573 | /* this is called for each file to process */ | 2954 | /* this is called for each file to process */ |
2574 | enum codec_status codec_run(void) | 2955 | enum codec_status codec_run(void) |
2575 | { | 2956 | { |
2957 | /* Encoder thread stack goes on our stack - leave 4k for us | ||
2958 | Will be optimized away when single-threaded */ | ||
2959 | uint32_t enc_stack[(DEFAULT_STACK_SIZE+0x1000) / sizeof (uint32_t)]; | ||
2960 | |||
2961 | if (!enc_thread_init(enc_stack, sizeof (enc_stack))) /* MT only */ | ||
2962 | return CODEC_ERROR; | ||
2963 | |||
2576 | mp3_encoder_reset(); | 2964 | mp3_encoder_reset(); |
2577 | uint32_t first = 1; | 2965 | uint32_t first = 1; |
2578 | 2966 | ||
2579 | /* Needs to do stream finishing steps to flush-out all samples */ | 2967 | /* Needs to do stream finishing steps to flush-out all samples */ |
2580 | int frames_rem = -1; /* -1 = indeterminate */ | 2968 | int frames_rem = -1; /* < 0 = indeterminate */ |
2581 | 2969 | ||
2582 | enum { GETBUF_ENC, GETBUF_PCM } getbuf = GETBUF_ENC; | 2970 | enum { GETBUF_PCM, GETBUF_ENC } getbuf = GETBUF_PCM; |
2583 | struct enc_chunk_data *data = NULL; | 2971 | struct enc_chunk_data *data = NULL; |
2584 | 2972 | ||
2585 | /* main encoding loop */ | 2973 | /* main encoding loop */ |
@@ -2594,62 +2982,63 @@ enum codec_status codec_run(void) | |||
2594 | break; | 2982 | break; |
2595 | 2983 | ||
2596 | if (frames_rem < 0) | 2984 | if (frames_rem < 0) |
2597 | frames_rem = cfg.flush_frames; | 2985 | frames_rem = cfg.flush_frames + DRAIN_FRAMES; |
2598 | 2986 | ||
2599 | /* Reply with required space */ | 2987 | /* Reply with required space */ |
2600 | *(size_t *)param = cfg.req_byte_per_frame*frames_rem; | 2988 | *(size_t *)param = cfg.req_byte_per_frame; |
2601 | } | 2989 | } |
2602 | 2990 | ||
2603 | /* First obtain output buffer; when available, get PCM data */ | 2991 | /* First, get PCM data; when available, obtain output buffer */ |
2604 | switch (getbuf) | 2992 | switch (getbuf) |
2605 | { | 2993 | { |
2606 | case GETBUF_ENC: | ||
2607 | if (!(data = ci->enc_encbuf_get_buffer(cfg.req_byte_per_frame))) | ||
2608 | continue; | ||
2609 | getbuf = GETBUF_PCM; | ||
2610 | case GETBUF_PCM: | 2994 | case GETBUF_PCM: |
2611 | if (LIKELY(frames_rem < 0)) | 2995 | if (LIKELY(frames_rem < 0)) |
2612 | { | 2996 | { |
2613 | /* Encoding audio */ | 2997 | /* Encoding audio */ |
2614 | int count = cfg.samp_per_frame; | 2998 | if (!ci->enc_pcmbuf_read(cfg.samp_buffer, |
2615 | if (!ci->enc_pcmbuf_read(cfg.samp_buffer, count)) | 2999 | cfg.samp_per_frame)) |
2616 | continue; | 3000 | continue; |
2617 | 3001 | ||
2618 | ci->enc_pcmbuf_advance(cfg.samp_per_frame); | 3002 | ci->enc_pcmbuf_advance(cfg.samp_per_frame); |
2619 | 3003 | encode_frame(); | |
2620 | if (cfg.channels == 1) | ||
2621 | { | ||
2622 | /* Interleave the mono samples to stereo as required by | ||
2623 | encoder */ | ||
2624 | uint16_t *src = cfg.samp_buffer + count; | ||
2625 | uint32_t *dst = (uint32_t *)(src + count); | ||
2626 | |||
2627 | for (int i = count; i > 0; i--) | ||
2628 | { uint32_t s = *--src; *--dst = s | (s << 16); } | ||
2629 | } | ||
2630 | } | 3004 | } |
2631 | else | 3005 | else if (frames_rem-- > DRAIN_FRAMES) |
2632 | { | 3006 | { |
2633 | /* Flushing encoder */ | 3007 | /* Flushing encoder */ |
2634 | memset(cfg.samp_buffer, 0, cfg.samp_per_frame*4); | 3008 | ci->memset(cfg.samp_buffer, 0, |
2635 | frames_rem--; | 3009 | cfg.samp_per_frame*cfg.channels*2); |
3010 | encode_frame(); | ||
2636 | } | 3011 | } |
3012 | /* else Draining remaining buffered data */ | ||
3013 | |||
3014 | if (!wait_for_frame()) /* MT only */ | ||
3015 | continue; | ||
3016 | |||
2637 | getbuf = GETBUF_ENC; | 3017 | getbuf = GETBUF_ENC; |
3018 | case GETBUF_ENC: | ||
3019 | data = ci->enc_encbuf_get_buffer(cfg.req_byte_per_frame); | ||
3020 | |||
3021 | if (!data) | ||
3022 | continue; | ||
3023 | |||
3024 | data->hdr.aux0 = first; | ||
3025 | first = 0; | ||
3026 | data->hdr.size = get_frame(data->data); | ||
3027 | data->pcm_count = cfg.samp_per_frame; | ||
3028 | |||
3029 | ci->enc_encbuf_finish_buffer(); | ||
3030 | |||
3031 | getbuf = GETBUF_PCM; | ||
2638 | } | 3032 | } |
3033 | } /* while */ | ||
2639 | 3034 | ||
2640 | data->hdr.aux0 = first; | 3035 | enc_thread_stop(); /* MT only */ |
2641 | first = 0; | ||
2642 | data->hdr.size = mp3_encoder_encode_frame(data->data); | ||
2643 | data->pcm_count = cfg.samp_per_frame; | ||
2644 | ci->enc_encbuf_finish_buffer(); | ||
2645 | } | ||
2646 | 3036 | ||
2647 | return CODEC_OK; | 3037 | return CODEC_OK; |
2648 | } | 3038 | } |
2649 | 3039 | ||
2650 | /* this is called by recording system */ | 3040 | /* this is called by recording system */ |
2651 | int ICODE_ATTR enc_callback(enum enc_callback_reason reason, | 3041 | int enc_callback(enum enc_callback_reason reason, void *params) |
2652 | void *params) | ||
2653 | { | 3042 | { |
2654 | if (LIKELY(reason == ENC_CB_STREAM)) | 3043 | if (LIKELY(reason == ENC_CB_STREAM)) |
2655 | { | 3044 | { |
diff --git a/lib/rbcodec/codecs/wavpack_enc.c b/lib/rbcodec/codecs/wavpack_enc.c index 864012b4cd..ffb090f6ec 100644 --- a/lib/rbcodec/codecs/wavpack_enc.c +++ b/lib/rbcodec/codecs/wavpack_enc.c | |||
@@ -25,6 +25,10 @@ | |||
25 | 25 | ||
26 | CODEC_ENC_HEADER | 26 | CODEC_ENC_HEADER |
27 | 27 | ||
28 | #if NUM_CORES > 1 | ||
29 | #define WAVPACK_ENC_COP | ||
30 | #endif | ||
31 | |||
28 | /** Types **/ | 32 | /** Types **/ |
29 | typedef struct | 33 | typedef struct |
30 | { | 34 | { |
@@ -74,13 +78,24 @@ struct wvpk_chunk_data | |||
74 | /** Data **/ | 78 | /** Data **/ |
75 | static int32_t input_buffer[PCM_SAMP_PER_CHUNK*2] IBSS_ATTR; | 79 | static int32_t input_buffer[PCM_SAMP_PER_CHUNK*2] IBSS_ATTR; |
76 | 80 | ||
81 | #ifdef WAVPACK_ENC_COP | ||
82 | #if CONFIG_CPU == PP5020 || CONFIG_CPU == PP5002 | ||
83 | /* Not enough for IRAM */ | ||
84 | static uint8_t output_buffer[PCM_SAMP_PER_CHUNK*PCM_DEPTH_BYTES*2*110/100] | ||
85 | SHAREDBSS_ATTR MEM_ALIGN_ATTR; | ||
86 | #else | ||
87 | static uint8_t output_buffer[PCM_SAMP_PER_CHUNK*PCM_DEPTH_BYTES*2*110/100] | ||
88 | IBSS_ATTR MEM_ALIGN_ATTR; | ||
89 | #endif | ||
90 | #endif /* WAVPACK_ENC_COP */ | ||
91 | |||
77 | static WavpackConfig config IBSS_ATTR; | 92 | static WavpackConfig config IBSS_ATTR; |
78 | static WavpackContext *wpc; | 93 | static WavpackContext *wpc IBSS_ATTR; |
79 | static uint32_t sample_rate; | 94 | static uint32_t sample_rate IBSS_ATTR; |
80 | static int num_channels; | 95 | static int num_channels IBSS_ATTR; |
81 | static uint32_t total_samples; | 96 | static uint32_t total_samples IBSS_ATTR; |
82 | static size_t out_reqsize; | 97 | static size_t out_reqsize IBSS_ATTR; |
83 | static size_t frame_size; | 98 | static size_t frame_size IBSS_ATTR; |
84 | 99 | ||
85 | static const WavpackMetadataHeader wvpk_mdh = | 100 | static const WavpackMetadataHeader wvpk_mdh = |
86 | { | 101 | { |
@@ -230,6 +245,89 @@ static int on_stream_end(void) | |||
230 | return 0; | 245 | return 0; |
231 | } | 246 | } |
232 | 247 | ||
248 | static inline uint32_t encode_block_(uint8_t *outbuf) | ||
249 | { | ||
250 | if (WavpackStartBlock(wpc, outbuf, outbuf + out_reqsize) && | ||
251 | WavpackPackSamples(wpc, input_buffer, PCM_SAMP_PER_CHUNK)) | ||
252 | return WavpackFinishBlock(wpc); | ||
253 | |||
254 | return 0; | ||
255 | } | ||
256 | |||
257 | #ifdef WAVPACK_ENC_COP | ||
258 | /* This is to relieve CPU of encoder load since it has other significant tasks | ||
259 | to perform when recording. It is not written to provide parallelism within | ||
260 | the codec. */ | ||
261 | static const char enc_thread_name[] = { "Wavpack enc" }; | ||
262 | static bool quit IBSS_ATTR; | ||
263 | static uint32_t out_size IBSS_ATTR; | ||
264 | static struct semaphore enc_sema IBSS_ATTR; | ||
265 | static struct semaphore cod_sema IBSS_ATTR; | ||
266 | static unsigned int enc_thread_id; | ||
267 | |||
268 | static void ICODE_ATTR enc_thread(void) | ||
269 | { | ||
270 | while (1) | ||
271 | { | ||
272 | ci->semaphore_wait(&enc_sema, TIMEOUT_BLOCK); | ||
273 | |||
274 | if (quit) | ||
275 | break; | ||
276 | |||
277 | out_size = encode_block_(output_buffer); | ||
278 | |||
279 | ci->semaphore_release(&cod_sema); | ||
280 | } | ||
281 | } | ||
282 | |||
283 | static inline bool enc_thread_init(void *stack, size_t stack_size) | ||
284 | { | ||
285 | quit = false; | ||
286 | ci->semaphore_init(&enc_sema, 1, 0); | ||
287 | ci->semaphore_init(&cod_sema, 1, 0); | ||
288 | |||
289 | enc_thread_id = ci->create_thread(enc_thread, stack, stack_size, | ||
290 | 0, enc_thread_name | ||
291 | IF_PRIO(, PRIORITY_PLAYBACK) | ||
292 | IF_COP(, COP)); | ||
293 | |||
294 | return enc_thread_id != 0; | ||
295 | } | ||
296 | |||
297 | static inline void enc_thread_stop(void) | ||
298 | { | ||
299 | quit = true; | ||
300 | ci->semaphore_release(&enc_sema); | ||
301 | ci->thread_wait(enc_thread_id); | ||
302 | } | ||
303 | |||
304 | static inline uint32_t encode_block(uint8_t *outbuf) | ||
305 | { | ||
306 | ci->semaphore_release(&enc_sema); | ||
307 | ci->semaphore_wait(&cod_sema, TIMEOUT_BLOCK); | ||
308 | ci->memcpy(outbuf, output_buffer, out_size); | ||
309 | return out_size; | ||
310 | } | ||
311 | |||
312 | #else /* !WAVPACK_ENC_COP */ | ||
313 | |||
314 | static inline uint32_t encode_block(uint8_t *outbuf) | ||
315 | { | ||
316 | return encode_block_(outbuf); | ||
317 | } | ||
318 | |||
319 | static inline bool enc_thread_init(void *stack, size_t stack_size) | ||
320 | { | ||
321 | return true; | ||
322 | (void)stack; (void)stack_size; | ||
323 | } | ||
324 | |||
325 | static inline void enc_thread_stop(void) | ||
326 | { | ||
327 | } | ||
328 | |||
329 | #endif /* WAVPACK_ENC_COP */ | ||
330 | |||
233 | /* this is the codec entry point */ | 331 | /* this is the codec entry point */ |
234 | enum codec_status codec_main(enum codec_entry_call_reason reason) | 332 | enum codec_status codec_main(enum codec_entry_call_reason reason) |
235 | { | 333 | { |
@@ -242,6 +340,13 @@ enum codec_status codec_main(enum codec_entry_call_reason reason) | |||
242 | /* this is called for each file to process */ | 340 | /* this is called for each file to process */ |
243 | enum codec_status codec_run(void) | 341 | enum codec_status codec_run(void) |
244 | { | 342 | { |
343 | /* Encoder thread stack goes on our stack - leave 4k for us | ||
344 | Will be optimized away when single-threaded */ | ||
345 | uint32_t enc_stack[(DEFAULT_STACK_SIZE+0x1000) / sizeof(uint32_t)]; | ||
346 | |||
347 | if (!enc_thread_init(enc_stack, sizeof (enc_stack))) | ||
348 | return CODEC_ERROR; | ||
349 | |||
245 | enum { GETBUF_ENC, GETBUF_PCM } getbuf = GETBUF_ENC; | 350 | enum { GETBUF_ENC, GETBUF_PCM } getbuf = GETBUF_ENC; |
246 | struct enc_chunk_data *data = NULL; | 351 | struct enc_chunk_data *data = NULL; |
247 | 352 | ||
@@ -269,11 +374,12 @@ enum codec_status codec_run(void) | |||
269 | 374 | ||
270 | input_buffer_to_int32(frame_size); | 375 | input_buffer_to_int32(frame_size); |
271 | 376 | ||
272 | if (WavpackStartBlock(wpc, data->data, data->data + out_reqsize) && | 377 | uint32_t size = encode_block(data->data); |
273 | WavpackPackSamples(wpc, input_buffer, PCM_SAMP_PER_CHUNK)) | 378 | |
379 | if (size) | ||
274 | { | 380 | { |
275 | /* finish the chunk and store chunk size info */ | 381 | /* finish the chunk and store chunk size info */ |
276 | data->hdr.size = WavpackFinishBlock(wpc); | 382 | data->hdr.size = size; |
277 | data->pcm_count = PCM_SAMP_PER_CHUNK; | 383 | data->pcm_count = PCM_SAMP_PER_CHUNK; |
278 | } | 384 | } |
279 | else | 385 | else |
@@ -285,6 +391,7 @@ enum codec_status codec_run(void) | |||
285 | ci->enc_encbuf_finish_buffer(); | 391 | ci->enc_encbuf_finish_buffer(); |
286 | } | 392 | } |
287 | 393 | ||
394 | enc_thread_stop(); | ||
288 | return CODEC_OK; | 395 | return CODEC_OK; |
289 | } | 396 | } |
290 | 397 | ||