diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/mp3_encoder.c | 3582 |
1 files changed, 2017 insertions, 1565 deletions
diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c index e5b7cc8f6e..b31f428496 100644 --- a/apps/plugins/mp3_encoder.c +++ b/apps/plugins/mp3_encoder.c | |||
@@ -1,44 +1,21 @@ | |||
1 | /* Shine is an MP3 encoder | 1 | /* Shine is an MP3 encoder |
2 | * Copyright (C) 1999-2000 Gabriel Bouvigne | 2 | * Copyright (C) 1999-2000 Gabriel Bouvigne |
3 | * | 3 | * |
4 | * This library is free software; you can redistribute it and/or | 4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public | 5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either | 6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. | 7 | * version 2 of the License, or (at your option) any later version. |
8 | * | 8 | * |
9 | * This library is distributed in the hope that it will be useful, | 9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. */ | 12 | * Library General Public License for more details. */ |
13 | |||
14 | #define samp_per_frame 1152 | ||
15 | #define samp_per_frame2 576 | ||
16 | #define HAN_SIZE 512 | ||
17 | #define SBLIMIT 32 | ||
18 | #define WAVE_RIFF_PCM 0 | ||
19 | #define MAX_CHANNELS 2 | ||
20 | #define MAX_GRANULES 2 | ||
21 | #define HTN 34 | ||
22 | #define true 1 | ||
23 | #define false 0 | ||
24 | #define uint32 unsigned int | ||
25 | #define uint16 unsigned short | ||
26 | #define uint8 unsigned char | ||
27 | #define enct8 unsigned char | ||
28 | #ifndef bool | ||
29 | #define bool int | ||
30 | #endif | ||
31 | |||
32 | enum e_byte_order { order_unknown, order_bigEndian, order_littleEndian }; | ||
33 | 13 | ||
34 | #include "plugin.h" | 14 | #include "plugin.h" |
35 | #define PFILE int* | ||
36 | #define memcpy rb->memcpy | ||
37 | #define memset rb->memset | ||
38 | 15 | ||
39 | PLUGIN_HEADER | 16 | PLUGIN_HEADER |
40 | 17 | ||
41 | static struct plugin_api* rb; | 18 | static struct plugin_api* rb; |
42 | 19 | ||
43 | #ifdef USE_IRAM | 20 | #ifdef USE_IRAM |
44 | extern char iramcopy[]; | 21 | extern char iramcopy[]; |
@@ -48,242 +25,461 @@ extern char iedata[]; | |||
48 | extern char iend[]; | 25 | extern char iend[]; |
49 | #endif | 26 | #endif |
50 | 27 | ||
51 | typedef struct { | 28 | #define SAMP_PER_FRAME 1152 |
52 | PFILE file; | 29 | #define SAMPL2 576 |
53 | int channels; | 30 | #define SBLIMIT 32 |
54 | int bits; | 31 | #define HTN 16 |
55 | long samplerate; | 32 | #define memcpy rb->memcpy |
56 | long total_samples; | 33 | #define memset rb->memset |
57 | long length; | 34 | #define putlong(c, s) if(s+sz <= 32) { cc = (cc << s) | c; sz+= s; } \ |
58 | } wave_t; | 35 | else { putbits(cc, sz); cc = c; sz = s; } |
36 | |||
37 | enum e_byte_order { order_unknown, order_bigEndian, order_littleEndian }; | ||
38 | |||
39 | typedef unsigned long uint32; | ||
40 | typedef unsigned short uint16; | ||
41 | typedef unsigned char uint8; | ||
42 | |||
59 | 43 | ||
60 | typedef struct { | 44 | typedef struct { |
61 | int type; | 45 | int type; /* 0=(22.05,24,16kHz) 1=(44.1,48,32kHz) */ |
62 | int layr; | 46 | int mode; /* 0=stereo, 1=jstereo, 2=dual, 3=mono */ |
63 | int mode; | 47 | int bitrate; |
64 | int bitr; | 48 | int padding; |
65 | int emph; | 49 | int num_bands; |
66 | int padding; | 50 | long bitr_id; |
67 | long bits_per_frame; | 51 | int smpl_id; |
68 | long bitrate_index; | ||
69 | int samplerate_index; | ||
70 | int crc; | ||
71 | int ext; | ||
72 | int mode_ext; | ||
73 | int copyright; | ||
74 | int original; | ||
75 | } mpeg_t; | 52 | } mpeg_t; |
76 | 53 | ||
54 | /* Side information */ | ||
77 | typedef struct { | 55 | typedef struct { |
78 | enum e_byte_order byte_order; | 56 | uint32 part2_3_length; |
79 | char* infile; | 57 | int count1; /* number of 0-1-quadruples */ |
80 | wave_t wave; | 58 | uint32 global_gain; |
81 | char* outfile; | 59 | uint32 table_select[4]; |
82 | mpeg_t mpeg; | 60 | uint32 region_0_1; |
83 | } config_t; | 61 | uint32 address1; |
62 | uint32 address2; | ||
63 | uint32 address3; | ||
64 | long quantStep; | ||
65 | long additStep; | ||
66 | long max_val; | ||
67 | } side_info_t; | ||
84 | 68 | ||
85 | typedef struct { | 69 | typedef struct { |
86 | int bitpos; | 70 | enum e_byte_order byte_order; |
87 | uint32 bbuf[257]; | 71 | side_info_t cod_info[2][2]; |
88 | } BF_Data; | 72 | mpeg_t mpg; |
73 | long frac_per_frame; | ||
74 | long byte_per_frame; | ||
75 | long slot_lag; | ||
76 | int sideinfo_len; | ||
77 | int mean_bits; | ||
78 | int ResvSize; | ||
79 | int channels; | ||
80 | int granules; | ||
81 | int resample; | ||
82 | long samplerate; | ||
83 | } config_t; | ||
89 | 84 | ||
90 | /* Side information */ | ||
91 | typedef struct { | 85 | typedef struct { |
92 | unsigned part2_3_length; | 86 | int bitpos; /* current bitpos for writing */ |
93 | unsigned big_values; | 87 | uint32 bbuf[263]; |
94 | int count1; | 88 | } BF_Data; |
95 | unsigned global_gain; | ||
96 | unsigned table_select[4]; | ||
97 | unsigned region0_count; | ||
98 | unsigned region1_count; | ||
99 | unsigned address1; | ||
100 | unsigned address2; | ||
101 | unsigned address3; | ||
102 | long quantizerStepSize; | ||
103 | } side_info_t; | ||
104 | 89 | ||
105 | struct huffcodetab { | 90 | struct huffcodetab { |
106 | int xlen; /*max. x-index+ */ | 91 | int len; /* max. index */ |
107 | int ylen; /*max. y-index+ */ | 92 | const uint8 *table; /* pointer to array[len][len] */ |
108 | int linbits; /*number of linbits */ | 93 | const uint8 *hlen; /* pointer to array[len][len] */ |
109 | int linmax; /*max number stored in linbits */ | ||
110 | const uint16 *table; /*pointer to array[xlen][ylen] */ | ||
111 | const uint8 *hlen; /*pointer to array[xlen][ylen] */ | ||
112 | }; | 94 | }; |
113 | 95 | ||
114 | /* !!!!!!!! start of IRAM area: do not insert before x_int1 array !!!!!!!!!!!!! */ | 96 | struct huffcodebig { |
115 | short x_int0 [HAN_SIZE] IBSS_ATTR; /* 1024 Bytes */ | 97 | int len; /* max. index */ |
116 | int mdct_freq [2][2][samp_per_frame2] IBSS_ATTR; /* 9216 Bytes */ | 98 | int linbits; /* number of linbits */ |
117 | short x_int1 [HAN_SIZE] IBSS_ATTR; /* 1024 Bytes */ | 99 | int linmax; /* max number stored in linbits */ |
118 | /* !!!!!!!!!!!!!!!!!!!!! here you may insert other data !!!!!!!!!!!!!!!!!!!!!!! */ | 100 | }; |
119 | uint8 int2idx [4096] IBSS_ATTR; /* 4096 Bytes */ | 101 | |
120 | enct8 enc_data [2][2][samp_per_frame2] IBSS_ATTR; /* 4608 Bytes */ | 102 | #define shft4(x) ((x + 8) >> 4) |
121 | short y_int [64] IBSS_ATTR; /* 256 Bytes */ | 103 | #define shft9(x) ((x + 256) >> 9) |
122 | int off [2] IBSS_ATTR; /* 16 Bytes */ | 104 | #define shft13(x) ((x + 4096) >> 13) |
123 | int scalefac_long[23] IBSS_ATTR; /* 96 Bytes */ | 105 | #define shft15(x) ((x + 16384) >> 15) |
124 | int mdct_in [36] IBSS_ATTR; /* 144 Bytes */ | 106 | #define shft16(x) ((x + 32768) >> 16) |
125 | int sb_sample [2][3][18][SBLIMIT] IBSS_ATTR; /* 13824 Bytes */ | 107 | #define shft_n(x,n) ((x) >> n) |
126 | BF_Data CodedData IBSS_ATTR; /* 1040 Bytes */ | 108 | #define SQRT 724 /* sqrt(2) * 512 */ |
127 | int ca_int [8] IBSS_ATTR; /* 32 Bytes */ | 109 | |
128 | int cs_int [8] IBSS_ATTR; /* 32 Bytes */ | 110 | short mfbuf [2*(1152+512)] IBSS_ATTR; /* 3328 Bytes */ |
129 | int win_int [18][36] IBSS_ATTR; /* 2592 Bytes */ | 111 | int sb_data [2][2][18][SBLIMIT] IBSS_ATTR; /* 13824 Bytes */ |
130 | short filter_int [SBLIMIT][64] IBSS_ATTR; /* 8192 Bytes */ | 112 | int mdct_freq [SAMPL2] IBSS_ATTR; /* 9216 Bytes */ |
131 | short enwindow_int[512] IBSS_ATTR; /* 1024 Bytes */ | 113 | short enc_data [SAMPL2] IBSS_ATTR; /* 4608 Bytes */ |
132 | uint8 ht_count1 [2][2][16] IBSS_ATTR; /* 64 Bytes */ | 114 | uint32 scalefac [23] IBSS_ATTR; /* 92 Bytes */ |
133 | uint16 t1HB [ 4] IBSS_ATTR; /* Bytes */ | 115 | BF_Data CodedData IBSS_ATTR; /* 1056 Bytes */ |
134 | uint16 t2HB [ 9] IBSS_ATTR; /* Bytes */ | 116 | int ca [8] IBSS_ATTR; /* 32 Bytes */ |
135 | uint16 t3HB [ 9] IBSS_ATTR; /* Bytes */ | 117 | int cs [8] IBSS_ATTR; /* 32 Bytes */ |
136 | uint16 t5HB [ 16] IBSS_ATTR; /* Bytes */ | 118 | int cx [9] IBSS_ATTR; /* 36 Bytes */ |
137 | uint16 t6HB [ 16] IBSS_ATTR; /* Bytes */ | 119 | int win [18][4] IBSS_ATTR; /* 288 Bytes */ |
138 | uint16 t7HB [ 36] IBSS_ATTR; /* Bytes */ | 120 | short enwindow [15*27+24] IBSS_ATTR; /* 862 Bytes */ |
139 | uint16 t8HB [ 36] IBSS_ATTR; /* Bytes */ | 121 | short int2idx [4096] IBSS_ATTR; /* 8192 Bytes */ |
140 | uint16 t9HB [ 36] IBSS_ATTR; /* Bytes */ | 122 | uint8 ht_count [2][2][16] IBSS_ATTR; /* 64 Bytes */ |
141 | uint16 t10HB [ 64] IBSS_ATTR; /* Bytes */ | 123 | uint32 tab01 [ 16] IBSS_ATTR; /* 64 Bytes */ |
142 | uint16 t11HB [ 64] IBSS_ATTR; /* Bytes */ | 124 | uint32 tab23 [ 9] IBSS_ATTR; /* 36 Bytes */ |
143 | uint16 t12HB [ 64] IBSS_ATTR; /* Bytes */ | 125 | uint32 tab56 [ 16] IBSS_ATTR; /* 64 Bytes */ |
144 | uint16 t13HB [256] IBSS_ATTR; /* Bytes */ | 126 | uint32 tab1315 [256] IBSS_ATTR; /* 1024 Bytes */ |
145 | uint16 t15HB [256] IBSS_ATTR; /* Bytes */ | 127 | uint32 tab1624 [256] IBSS_ATTR; /* 1024 Bytes */ |
146 | uint16 t16HB [256] IBSS_ATTR; /* Bytes */ | 128 | uint32 tab789 [ 36] IBSS_ATTR; /* 144 Bytes */ |
147 | uint16 t24HB [256] IBSS_ATTR; /* Bytes */ | 129 | uint32 tabABC [ 64] IBSS_ATTR; /* 256 Bytes */ |
148 | uint8 t1l [ 4] IBSS_ATTR; /* Bytes */ | 130 | uint8 t1HB [ 4] IBSS_ATTR; |
149 | uint8 t2l [ 9] IBSS_ATTR; /* Bytes */ | 131 | uint8 t2HB [ 9] IBSS_ATTR; |
150 | uint8 t3l [ 9] IBSS_ATTR; /* Bytes */ | 132 | uint8 t3HB [ 9] IBSS_ATTR; |
151 | uint8 t5l [ 16] IBSS_ATTR; /* Bytes */ | 133 | uint8 t5HB [ 16] IBSS_ATTR; |
152 | uint8 t6l [ 16] IBSS_ATTR; /* Bytes */ | 134 | uint8 t6HB [ 16] IBSS_ATTR; |
153 | uint8 t7l [ 36] IBSS_ATTR; /* Bytes */ | 135 | uint8 t7HB [ 36] IBSS_ATTR; |
154 | uint8 t8l [ 36] IBSS_ATTR; /* Bytes */ | 136 | uint8 t8HB [ 36] IBSS_ATTR; |
155 | uint8 t9l [ 36] IBSS_ATTR; /* Bytes */ | 137 | uint8 t9HB [ 36] IBSS_ATTR; |
156 | uint8 t10l [ 64] IBSS_ATTR; /* Bytes */ | 138 | uint8 t10HB [ 64] IBSS_ATTR; |
157 | uint8 t11l [ 64] IBSS_ATTR; /* Bytes */ | 139 | uint8 t11HB [ 64] IBSS_ATTR; |
158 | uint8 t12l [ 64] IBSS_ATTR; /* Bytes */ | 140 | uint8 t12HB [ 64] IBSS_ATTR; |
159 | uint8 t13l [256] IBSS_ATTR; /* Bytes */ | 141 | uint8 t13HB [256] IBSS_ATTR; |
160 | uint8 t15l [256] IBSS_ATTR; /* Bytes */ | 142 | uint8 t15HB [256] IBSS_ATTR; |
161 | uint8 t16l [256] IBSS_ATTR; /* Bytes */ | 143 | uint16 t16HB [256] IBSS_ATTR; |
162 | uint8 t24l [256] IBSS_ATTR; /* Bytes */ | 144 | uint16 t24HB [256] IBSS_ATTR; |
163 | struct huffcodetab ht [HTN] IBSS_ATTR; /* Bytes */ | 145 | uint8 t1l [ 8] IBSS_ATTR; |
164 | 146 | uint8 t2l [ 9] IBSS_ATTR; | |
165 | static const uint8 ht_count1_const[2][2][16] = | 147 | uint8 t3l [ 9] IBSS_ATTR; |
148 | uint8 t5l [ 16] IBSS_ATTR; | ||
149 | uint8 t6l [ 16] IBSS_ATTR; | ||
150 | uint8 t7l [ 36] IBSS_ATTR; | ||
151 | uint8 t8l [ 36] IBSS_ATTR; | ||
152 | uint8 t9l [ 36] IBSS_ATTR; | ||
153 | uint8 t10l [ 64] IBSS_ATTR; | ||
154 | uint8 t11l [ 64] IBSS_ATTR; | ||
155 | uint8 t12l [ 64] IBSS_ATTR; | ||
156 | uint8 t13l [256] IBSS_ATTR; | ||
157 | uint8 t15l [256] IBSS_ATTR; | ||
158 | uint8 t16l [256] IBSS_ATTR; | ||
159 | uint8 t24l [256] IBSS_ATTR; | ||
160 | struct huffcodetab ht [HTN] IBSS_ATTR; | ||
161 | |||
162 | static const uint8 ht_count_const[2][2][16] = | ||
166 | { { { 1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1 }, /* table0 */ | 163 | { { { 1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1 }, /* table0 */ |
167 | { 1, 5, 5, 7, 5, 8, 7, 9, 5, 7, 7, 9, 7, 9, 9,10 } }, /* hleng0 */ | 164 | { 1, 5, 5, 7, 5, 8, 7, 9, 5, 7, 7, 9, 7, 9, 9,10 } }, /* hleng0 */ |
168 | { {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, /* table1 */ | 165 | { {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, /* table1 */ |
169 | { 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 } } }; /* hleng1 */ | 166 | { 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 } } }; /* hleng1 */ |
170 | 167 | ||
171 | static const uint16 t1HB_const[4] = {1, 1, 1, 0}; | 168 | static const uint8 t1HB_const[4] = {1,1,1,0}; |
172 | static const uint16 t2HB_const[9] = {1, 2, 1, 3, 1, 1, 3, 2, 0}; | 169 | static const uint8 t2HB_const[9] = {1,2,1,3,1,1,3,2,0}; |
173 | static const uint16 t3HB_const[9] = {3, 2, 1, 1, 1, 1, 3, 2, 0}; | 170 | static const uint8 t3HB_const[9] = {3,2,1,1,1,1,3,2,0}; |
174 | static const uint16 t5HB_const[16] = {1, 2, 6, 5, 3, 1, 4, 4, 7, 5, 7, 1, 6, 1, 1, 0}; | 171 | static const uint8 t5HB_const[16] = {1,2,6,5,3,1,4,4,7,5,7,1,6,1,1,0}; |
175 | static const uint16 t6HB_const[16] = {7, 3, 5, 1, 6, 2, 3, 2, 5, 4, 4, 1, 3, 3, 2, 0}; | 172 | static const uint8 t6HB_const[16] = {7,3,5,1,6,2,3,2,5,4,4,1,3,3,2,0}; |
176 | static const uint16 t7HB_const[36] = {1, 2, 10, 19, 16, 10, 3, 3, 7, 10, 5, 3, 11, 4, 13, 17, 8, 4, 12, 11, 18, 15, 11, 2, 7, 6, 9, 14, 3, 1, 6, 4, 5, 3, 2, 0}; | 173 | |
177 | static const uint16 t8HB_const[36] = {3, 4, 6, 18, 12, 5, 5, 1, 2, 16, 9, 3, 7, 3, 5, 14, 7, 3, 19, 17, 15, 13, 10, 4, 13, 5, 8, 11, 5, 1, 12, 4, 4, 1, 1, 0}; | 174 | static const uint8 t7HB_const[36] = |
178 | static const uint16 t9HB_const[36] = {7, 5, 9, 14, 15, 7, 6, 4, 5, 5, 6, 7, 7, 6, 8, 8, 8, 5, 15, 6, 9, 10, 5, 1, 11, 7, 9, 6, 4, 1, 14, 4, 6, 2, 6, 0}; | 175 | { 1, 2,10,19,16,10, 3, 3, 7,10, 5, 3,11, 4,13,17, 8, 4, |
179 | static const uint16 t10HB_const[64] = {1, 2, 10, 23, 35, 30, 12, 17, 3, 3, 8, 12, 18, 21, 12, 7, 11, 9, 15, 21, 32, 40, 19, 6, 14, 13, 22, 34, 46, 23, 18, 7, 20, 19, 33, 47, 27, 22, 9, 3, 31, 22, 41, 26, 21, 20, 5, 3, 14, 13, 10, 11, 16, 6, 5, 1, 9, 8, 7, 8, 4 , 4, 2, 0}; | 176 | 12,11,18,15,11, 2, 7, 6, 9,14, 3, 1, 6, 4, 5, 3, 2, 0 }; |
180 | static const uint16 t11HB_const[64] = {3, 4, 10, 24, 34, 33, 21, 15, 5, 3, 4, 10, 32, 17, 11, 10, 11, 7, 13, 18, 30, 31, 20, 5, 25, 11, 19, 59, 27, 18, 12, 5, 35, 33, 31, 58, 30, 16, 7, 5, 28, 26, 32, 19, 17, 15, 8, 14, 14, 12, 9, 13, 14, 9, 4, 1, 11, 4, 6, 6, 6, 3, 2, 0}; | 177 | |
181 | static const uint16 t12HB_const[64] = {9, 6, 16, 33, 41, 39, 38, 26, 7, 5, 6, 9, 23, 16, 26, 11, 17, 7, 11, 14, 21, 30, 10, 7, 17, 10, 15, 12, 18, 28, 14, 5, 32, 13, 22, 19, 18, 16, 9, 5, 40, 17, 31, 29, 17, 13, 4, 2, 27, 12, 11, 15, 10, 7, 4, 1, 27, 12, 8, 12 , 6, 3, 1, 0}; | 178 | static const uint8 t8HB_const[36] = |
182 | static const uint16 t13HB_const[256] = {1, 5, 14, 21, 34, 51, 46, 71, 42, 52, 68, 52, 67, 44, 43, 19, 3, 4, 12, 19, 31, 26, 44, 33, 31, 24, 32, 24, 31, 35, 22, 14, 15, 13, 23, 36, 59, 49, 77, 65, 29, 40, 30, 40, 27, 33, 42, 16, 22, | 179 | { 3, 4, 6,18,12, 5, 5, 1, 2,16, 9, 3, 7, 3, 5,14, 7, 3, |
183 | 20, 37, 61, 56, 79, 73, 64, 43, 76, 56, 37, 26, 31, 25, 14, 35, 16, 60, 57, 97, 75, 114, 91, 54, 73, 55, 41, 48, 53, 23, 24, 58, 27, 50, 96, 76, 70, 93, 84, 77, 58, 79, 29, 74, 49, 41, 17, 47, | 180 | 19,17,15,13,10, 4,13, 5, 8,11, 5, 1,12, 4, 4, 1, 1, 0 }; |
184 | 45, 78, 74, 115, 94, 90, 79, 69, 83, 71, 50, 59, 38, 36, 15, 72, 34, 56, 95, 92, 85, 91, 90, 86, 73, 77, 65, 51, 44, 43, 42, 43, 20, 30, 44, 55, 78, 72, 87, 78, 61, 46, 54, 37, 30, 20, 16, 53, | 181 | |
185 | 25, 41, 37, 44, 59, 54, 81, 66, 76, 57, 54, 37, 18, 39, 11, 35, 33, 31, 57, 42, 82, 72, 80, 47, 58, 55, 21, 22, 26, 38, 22, 53, 25, 23, 38, 70, 60, 51, 36, 55, 26, 34, 23, 27, 14, 9, 7, 34, 32, | 182 | static const uint8 t9HB_const[36] = |
186 | 28, 39, 49, 75, 30, 52, 48, 40, 52, 28, 18, 17, 9, 5, 45, 21, 34, 64, 56, 50, 49, 45, 31, 19, 12, 15, 10, 7, 6, 3, 48, 23, 20, 39, 36, 35, 53, 21, 16, 23, 13, 10, 6, 1, 4, 2, 16, 15, 17, 27, 25, | 183 | { 7, 5, 9,14,15, 7, 6, 4, 5, 5, 6, 7, 7, 6, 8, 8, 8, 5, |
187 | 20, 29, 11, 17, 12, 16, 8, 1, 1, 0, 1}; | 184 | 15, 6, 9,10, 5, 1,11, 7, 9, 6, 4, 1,14, 4, 6, 2, 6, 0 }; |
188 | static const uint16 t15HB_const[256] = {7, 12, 18, 53, 47, 76, 124, 108, 89, 123, 108, 119, 107, 81, 122, 63, 13, 5, 16, 27, 46, 36, 61, 51, 42, 70, 52, 83, 65, 41, 59, 36, 19, 17, 15, 24, 41, 34, 59, 48, 40, 64, 50, 78, 62, 80, 56, | 185 | |
189 | 33, 29, 28, 25, 43, 39, 63, 55, 93, 76, 59, 93, 72, 54, 75, 50, 29, 52, 22, 42, 40, 67, 57, 95, 79, 72, 57, 89, 69, 49, 66, 46, 27, 77, 37, 35, 66, 58, 52, 91, 74, 62, 48, 79, 63, 90, 62, 40, 38, | 186 | static const uint8 t10HB_const[64] = |
190 | 125, 32, 60, 56, 50, 92, 78, 65, 55, 87, 71, 51, 73, 51, 70, 30, 109, 53, 49, 94, 88, 75, 66, 122, 91, 73, 56, 42, 64, 44, 21, 25, 90, 43, 41, 77, 73, 63, 56, 92, 77, 66, 47, 67, 48, 53, 36, 20, | 187 | {1,2,10,23,35,30,12,17,3,3,8,12,18,21,12,7,11,9,15,21,32, |
191 | 71, 34, 67, 60, 58, 49, 88, 76, 67, 106, 71, 54, 38, 39, 23, 15, 109, 53, 51, 47, 90, 82, 58, 57, 48, 72, 57, 41, 23, 27, 62, 9, 86, 42, 40, 37, 70, 64, 52, 43, 70, 55, 42, 25, 29, 18, 11, 11, | 188 | 40,19,6,14,13,22,34,46,23,18,7,20,19,33,47,27,22,9,3,31,22, |
192 | 118, 68, 30, 55, 50, 46, 74, 65, 49, 39, 24, 16, 22, 13, 14, 7, 91, 44, 39, 38, 34, 63, 52, 45, 31, 52, 28, 19, 14, 8, 9, 3, 123, 60, 58, 53, 47, 43, 32, 22, 37, 24, 17, 12, 15, 10, 2, 1, 71, | 189 | 41,26,21,20,5,3,14,13,10,11,16,6,5,1,9,8,7,8,4,4,2,0 }; |
193 | 37, 34, 30, 28, 20, 17, 26, 21, 16, 10, 6, 8, 6, 2, 0}; | 190 | |
194 | static const uint16 t16HB_const[256] = {1, 5, 14, 44, 74, 63, 110, 93, 172, 149, 138, 242, 225, 195, 376, 17, 3, 4, 12, 20, 35, 62, 53, 47, 83, 75, 68, 119, 201, 107, 207, 9, 15, 13, 23, 38, 67, 58, 103, 90, 161, 72, 127, 117, | 191 | static const uint8 t11HB_const[64] = |
195 | 110, 209, 206, 16, 45, 21, 39, 69, 64, 114, 99, 87, 158, 140, 252, 212, 199, 387, 365, 26, 75, 36, 68, 65, 115, 101, 179, 164, 155, 264, 246, 226, 395, 382, 362, 9, 66, 30, 59, 56, 102, | 192 | {3,4,10,24,34,33,21,15,5,3,4,10,32,17,11,10,11,7,13,18,30, |
196 | 185, 173, 265, 142, 253, 232, 400, 388, 378, 445, 16, 111, 54, 52, 100, 184, 178, 160, 133, 257, 244, 228, 217, 385, 366, 715, 10, 98, 48, 91, 88, 165, 157, 148, 261, 248, 407, 397, 372, | 193 | 31,20,5,25,11,19,59,27,18,12,5,35,33,31,58,30,16,7,5,28,26, |
197 | 380, 889, 884, 8, 85, 84, 81, 159, 156, 143, 260, 249, 427, 401, 392, 383, 727, 713, 708, 7, 154, 76, 73, 141, 131, 256, 245, 426, 406, 394, 384, 735, 359, 710, 352, 11, 139, 129, 67, 125, | 194 | 32,19,17,15,8,14,14,12,9,13,14,9,4,1,11,4,6,6,6,3,2,0 }; |
198 | 247, 233, 229, 219, 393, 743, 737, 720, 885, 882, 439, 4, 243, 120, 118, 115, 227, 223, 396, 746, 742, 736, 721, 712, 706, 223, 436, 6, 202, 224, 222, 218, 216, 389, 386, 381, 364, 888, | 195 | |
199 | 443, 707, 440, 437, 1728, 4, 747, 211, 210, 208, 370, 379, 734, 723, 714, 1735, 883, 877, 876, 3459, 865, 2, 377, 369, 102, 187, 726, 722, 358, 711, 709, 866, 1734, 871, 3458, 870, 434, | 196 | static const uint8 t12HB_const[64] = |
200 | 0, 12, 10, 7, 11, 10, 17, 11, 9, 13, 12, 10, 7, 5, 3, 1, 3}; | 197 | {9,6,16,33,41,39,38,26,7,5,6,9,23,16,26,11,17,7,11,14,21, |
201 | static const uint16 t24HB_const[256] = {15, 13, 46, 80, 146, 262, 248, 434, 426, 669, 653, 649, 621, 517, 1032, 88, 14, 12, 21, 38, 71, 130, 122, 216, 209, 198, 327, 345, 319, 297, 279, 42, 47, 22, 41, 74, 68, 128, 120, 221, | 198 | 30,10,7,17,10,15,12,18,28,14,5,32,13,22,19,18,16,9,5,40,17, |
202 | 207, 194, 182, 340, 315, 295, 541, 18, 81, 39, 75, 70, 134, 125, 116, 220, 204, 190, 178, 325, 311, 293, 271, 16, 147, 72, 69, 135, 127, 118, 112, 210, 200, 188, 352, 323, 306, 285, | 199 | 31,29,17,13,4,2,27,12,11,15,10,7,4,1,27,12,8,12,6,3,1,0 }; |
203 | 540, 14, 263, 66, 129, 126, 119, 114, 214, 202, 192, 180, 341, 317, 301, 281, 262, 12, 249, 123, 121, 117, 113, 215, 206, 195, 185, 347, 330, 308, 291, 272, 520, 10, 435, 115, 111, | 200 | |
204 | 109, 211, 203, 196, 187, 353, 332, 313, 298, 283, 531, 381, 17, 427, 212, 208, 205, 201, 193, 186, 177, 169, 320, 303, 286, 268, 514, 377, 16, 335, 199, 197, 191, 189, 181, 174, 333, | 201 | static const uint8 t13HB_const[256] = |
205 | 321, 305, 289, 275, 521, 379, 371, 11, 668, 184, 183, 179, 175, 344, 331, 314, 304, 290, 277, 530, 383, 373, 366, 10, 652, 346, 171, 168, 164, 318, 309, 299, 287, 276, 263, 513, 375, | 202 | {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, |
206 | 368, 362, 6, 648, 322, 316, 312, 307, 302, 292, 284, 269, 261, 512, 376, 370, 364, 359, 4, 620, 300, 296, 294, 288, 282, 273, 266, 515, 380, 374, 369, 365, 361, 357, 2, 1033, 280, 278, | 203 | 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, |
207 | 274, 267, 264, 259, 382, 378, 372, 367, 363, 360, 358, 356, 0, 43, 20, 19, 17, 15, 13, 11, 9, 7, 6, 4, 7, 5, 3, 1, 3}; | 204 | 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, |
208 | 205 | 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, | |
209 | static const uint8 t1l_const[4] = {1, 3, 2, 3}; | 206 | 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, |
210 | static const uint8 t2l_const[9] = {1, 3, 6, 3, 3, 5, 5, 5, 6}; | 207 | 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, |
211 | static const uint8 t3l_const[9] = {2, 2, 6, 3, 2, 5, 5, 5, 6}; | 208 | 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, |
212 | static const uint8 t5l_const[16] = {1, 3, 6, 7, 3, 3, 6, 7, 6, 6, 7, 8, 7, 6, 7, 8}; | 209 | 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, |
213 | static const uint8 t6l_const[16] = {3, 3, 5, 7, 3, 2, 4, 5, 4, 4, 5, 6, 6, 5, 6, 7}; | 210 | 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, |
214 | static const uint8 t7l_const[36] = {1, 3, 6, 8, 8, 9, 3, 4, 6, 7, 7, 8, 6, 5, 7, 8, 8, 9, 7, 7, 8, 9, 9, 9, 7, 7, 8, 9, 9, 10, 8, 8, 9, 10, 10, 10}; | 211 | 10,6,1,4,2,16,15,17,27,25,20,29,11,17,12,16,8,1,1,0,1 }; |
215 | static const uint8 t8l_const[36] = {2, 3, 6, 8, 8, 9, 3, 2, 4, 8, 8, 8, 6, 4, 6, 8, 8, 9, 8, 8, 8, 9, 9, 10, 8, 7, 8, 9, 10, 10, 9, 8, 9, 9, 11, 11}; | 212 | |
216 | static const uint8 t9l_const[36] = {3, 3, 5, 6, 8, 9, 3, 3, 4, 5, 6, 8, 4, 4, 5, 6, 7, 8, 6, 5, 6, 7, 7, 8, 7, 6, 7, 7, 8, 9, 8, 7, 8, 8, 9, 9}; | 213 | static const uint8 t15HB_const[256] = |
217 | static const uint8 t10l_const[64] = {1, 3, 6, 8, 9, 9, 9, 10, 3, 4, 6, 7, 8, 9, 8, 8, 6, 6, 7, 8, 9, 10, 9, 9, 7, 7, 8, 9, 10, 10, 9, 10, 8, 8, 9, 10, 10, 10, 10, 10, 9, 9, 10, 10, 11, 11, 10, 11, 8, 8, 9, 10, 10, 10, 11, 11, 9, 8, 9, 10, 10, 11, 11, 11}; | 214 | {7,12,18,53,47,76,124,108,89,123,108,119,107,81,122,63,13,5,16,27,46,36,61,51, |
218 | static const uint8 t11l_const[64] = {2, 3, 5, 7, 8, 9, 8, 9, 3, 3, 4, 6, 8, 8, 7, 8, 5, 5, 6, 7, 8, 9, 8, 8, 7, 6, 7, 9, 8, 10, 8, 9, 8, 8, 8, 9, 9, 10, 9, 10, 8, 8, 9, 10, 10, 11, 10, 11, 8, 7, 7, 8, 9, 10, 10, 10, 8, 7, 8, 9, 10, 10, 10, 10}; | 215 | 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, |
219 | static const uint8 t12l_const[64] = {4, 3, 5, 7, 8, 9, 9, 9, 3, 3, 4, 5, 7, 7, 8, 8, 5, 4, 5, 6, 7, 8, 7, 8, 6, 5, 6, 6, 7, 8, 8, 8, 7, 6, 7, 7, 8, 8, 8, 9, 8, 7, 8, 8, 8, 9, 8, 9, 8, 7, 7, 8, 8, 9, 9, 10, 9, 8, 8, 9, 9, 9, 9, 10}; | 216 | 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, |
220 | static const uint8 t13l_const[256] = {1, 4, 6, 7, 8, 9, 9, 10, 9, 10, 11, 11, 12, 12, 13, 13, 3, 4, 6, 7, 8, 8, 9, 9, 9, 9, 10, 10, 11, 12, 12, 12, 6, 6, 7, 8, 9, 9, 10, 10, 9, 10, 10, 11, 11, 12, 13, 13, 7, 7, 8, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 13, 13, | 217 | 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, |
221 | 8, 7, 9, 9, 10, 10, 11, 11, 10, 11, 11, 12, 12, 13, 13, 14, 9, 8, 9, 10, 10, 10, 11, 11, 11, 11, 12, 11, 13, 13, 14, 14, 9, 9, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 13, 13, 14, 14, 10, 9, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 16, 16, 9, 8, 9, 10, | 218 | 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, |
222 | 10, 11, 11, 12, 12, 12, 12, 13, 13, 14, 15, 15, 10, 9, 10, 10, 11, 11, 11, 13, 12, 13, 13, 14, 14, 14, 16, 15, 10, 10, 10, 11, 11, 12, 12, 13, 12, 13, 14, 13, 14, 15, 16, 17, 11, 10, 10, 11, 12, 12, 12, 12, 13, 13, 13, 14, 15, 15, 15, 16, 11, 11, 11, 12, 12, | 219 | 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, |
223 | 13, 12, 13, 14, 14, 15, 15, 15, 16, 16, 16, 12, 11, 12, 13, 13, 13, 14, 14, 14, 14, 14, 15, 16, 15, 16, 16, 13, 12, 12, 13, 13, 13, 15, 14, 14, 17, 15, 15, 15, 17, 16, 16, 12, 12, 13, 14, 14, 14, 15, 14, 15, 15, 16, 16, 19, 18, 19, 16}; | 220 | 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, |
224 | static const uint8 t15l_const[256] = {3, 4, 5, 7, 7, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, 13, 4, 3, 5, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 5, 5, 5, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 11, 11, 11, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 7, 6, 7, | 221 | 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, |
225 | 7, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 8, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 11, 12, 9, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 9, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 12, 9, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, | 222 | 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, |
226 | 12, 12, 12, 9, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 10, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 11, 12, 13, 12, 10, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 11, 10, 9, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 13, 13, | 223 | 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}; |
227 | 11, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 12, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 12, 13, 12, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13}; | 224 | |
228 | static const uint8 t16l_const[256] = {1, 4, 6, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 9, 3, 4, 6, 7, 8, 9, 9, 9, 10, 10, 10, 11, 12, 11, 12, 8, 6, 6, 7, 8, 9, 9, 10, 10, 11, 10, 11, 11, 11, 12, 12, 9, 8, 7, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, | 225 | static const uint16 t16HB_const[256] = |
229 | 10, 9, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 9, 9, 8, 9, 9, 10, 11, 11, 12, 11, 12, 12, 13, 13, 13, 14, 10, 10, 9, 9, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 14, 10, 10, 9, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 13, 15, 15, 10, 10, 10, | 226 | {1,5,14,44,74,63,110,93,172,149,138,242,225,195,376,17,3,4,12,20,35,62,53,47, |
230 | 10, 11, 11, 11, 12, 12, 13, 13, 13, 13, 14, 14, 14, 10, 11, 10, 10, 11, 11, 12, 12, 13, 13, 13, 13, 14, 13, 14, 13, 11, 11, 11, 10, 11, 12, 12, 12, 12, 13, 14, 14, 14, 15, 15, 14, 10, 12, 11, 11, 11, 12, 12, 13, 14, 14, 14, 14, 14, 14, 13, 14, 11, 12, 12, | 227 | 83,75,68,119,201,107,207,9,15,13,23,38,67,58,103,90,161,72,127,117,110,209, |
231 | 12, 12, 12, 13, 13, 13, 13, 15, 14, 14, 14, 14, 16, 11, 14, 12, 12, 12, 13, 13, 14, 14, 14, 16, 15, 15, 15, 17, 15, 11, 13, 13, 11, 12, 14, 14, 13, 14, 14, 15, 16, 15, 17, 15, 14, 11, 9, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 8}; | 228 | 206,16,45,21,39,69,64,114,99,87,158,140,252,212,199,387,365,26,75,36,68,65, |
232 | static const uint8 t24l_const[256] = {4, 4, 6, 7, 8, 9, 9, 10, 10, 11, 11, 11, 11, 11, 12, 9, 4, 4, 5, 6, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10, 8, 6, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 7, 7, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 7, 8, 7, 7, 8, | 229 | 115,101,179,164,155,264,246,226,395,382,362,9,66,30,59,56,102,185,173,265,142, |
233 | 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 7, 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 7, 9, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 7, 10, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 8, 10, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, | 230 | 253,232,400,388,378,445,16,111,54,52,100,184,178,160,133,257,244,228,217,385, |
234 | 8, 10, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, 8, 11, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 8, 11, 10, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 8, 11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 8, 11, 10, 10, | 231 | 366,715,10,98,48,91,88,165,157,148,261,248,407,397,372,380,889,884,8,85,84,81, |
235 | 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 8, 12, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 4}; | 232 | 159,156,143,260,249,427,401,392,383,727,713,708,7,154,76,73,141,131,256,245, |
236 | 233 | 426,406,394,384,735,359,710,352,11,139,129,67,125,247,233,229,219,393,743,737, | |
237 | const struct huffcodetab ht_const[HTN] = | 234 | 720,885,882,439,4,243,120,118,115,227,223,396,746,742,736,721,712,706,223,436, |
238 | { | 235 | 6,202,224,222,218,216,389,386,381,364,888,443,707,440,437,1728,4,747,211,210, |
239 | { 0, 0, 0, 0, NULL, NULL}, | 236 | 208,370,379,734,723,714,1735,883,877,876,3459,865,2,377,369,102,187,726,722, |
240 | { 2, 2, 0, 0, t1HB, t1l}, | 237 | 358,711,709,866,1734,871,3458,870,434,0,12,10,7,11,10,17,11,9,13,12,10,7,5,3, |
241 | { 3, 3, 0, 0, t2HB, t2l}, | 238 | 1,3}; |
242 | { 3, 3, 0, 0, t3HB, t3l}, | 239 | |
243 | { 0, 0, 0, 0, NULL, NULL},/* Apparently not used */ | 240 | static const uint16 t24HB_const[256] = |
244 | { 4, 4, 0, 0, t5HB, t5l}, | 241 | {15,13,46,80,146,262,248,434,426,669,653,649,621,517,1032,88,14,12,21,38,71, |
245 | { 4, 4, 0, 0, t6HB, t6l}, | 242 | 130,122,216,209,198,327,345,319,297,279,42,47,22,41,74,68,128,120,221,207,194, |
246 | { 6, 6, 0, 0, t7HB, t7l}, | 243 | 182,340,315,295,541,18,81,39,75,70,134,125,116,220,204,190,178,325,311,293, |
247 | { 6, 6, 0, 0, t8HB, t8l}, | 244 | 271,16,147,72,69,135,127,118,112,210,200,188,352,323,306,285,540,14,263,66, |
248 | { 6, 6, 0, 0, t9HB, t9l}, | 245 | 129,126,119,114,214,202,192,180,341,317,301,281,262,12,249,123,121,117,113, |
249 | { 8, 8, 0, 0,t10HB, t10l}, | 246 | 215,206,195,185,347,330,308,291,272,520,10,435,115,111,109,211,203,196,187, |
250 | { 8, 8, 0, 0,t11HB, t11l}, | 247 | 353,332,313,298,283,531,381,17,427,212,208,205,201,193,186,177,169,320,303, |
251 | { 8, 8, 0, 0,t12HB, t12l}, | 248 | 286,268,514,377,16,335,199,197,191,189,181,174,333,321,305,289,275,521,379, |
252 | {16,16, 0, 0,t13HB, t13l}, | 249 | 371,11,668,184,183,179,175,344,331,314,304,290,277,530,383,373,366,10,652,346, |
253 | { 0, 0, 0, 0, NULL, NULL},/* Apparently not used */ | 250 | 171,168,164,318,309,299,287,276,263,513,375,368,362,6,648,322,316,312,307,302, |
254 | {16,16, 0, 0,t15HB, t15l}, | 251 | 292,284,269,261,512,376,370,364,359,4,620,300,296,294,288,282,273,266,515,380, |
255 | {16,16, 1, 1,t16HB, t16l}, | 252 | 374,369,365,361,357,2,1033,280,278,274,267,264,259,382,378,372,367,363,360, |
256 | {16,16, 2, 3,t16HB, t16l}, | 253 | 358,356,0,43,20,19,17,15,13,11,9,7,6,4,7,5,3,1,3}; |
257 | {16,16, 3, 7,t16HB, t16l}, | 254 | |
258 | {16,16, 4, 15,t16HB, t16l}, | 255 | static const uint32 tab1315_const[256] = |
259 | {16,16, 6, 63,t16HB, t16l}, | 256 | { 0x010003,0x050005,0x070006,0x080008,0x090008,0x0a0009,0x0a000a,0x0b000a, |
260 | {16,16, 8, 255,t16HB, t16l}, | 257 | 0x0a000a,0x0b000b,0x0c000b,0x0c000c,0x0d000c,0x0d000c,0x0e000d,0x0e000e, |
261 | {16,16,10,1023,t16HB, t16l}, | 258 | 0x040005,0x060005,0x080007,0x090008,0x0a0009,0x0a0009,0x0b000a,0x0b000a, |
262 | {16,16,13,8191,t16HB, t16l}, | 259 | 0x0b000a,0x0b000b,0x0c000b,0x0c000c,0x0d000c,0x0e000c,0x0e000d,0x0e000d, |
263 | {16,16, 4, 15,t24HB, t24l}, | 260 | 0x070006,0x080007,0x090007,0x0a0008,0x0b0009,0x0b0009,0x0c000a,0x0c000a, |
264 | {16,16, 5, 31,t24HB, t24l}, | 261 | 0x0b000a,0x0c000b,0x0c000b,0x0d000c,0x0d000c,0x0e000d,0x0f000d,0x0f000d, |
265 | {16,16, 6, 63,t24HB, t24l}, | 262 | 0x080007,0x090008,0x0a0008,0x0b0009,0x0b0009,0x0c000a,0x0c000a,0x0c000b, |
266 | {16,16, 7, 127,t24HB, t24l}, | 263 | 0x0c000b,0x0d000b,0x0d000c,0x0d000c,0x0d000c,0x0e000d,0x0f000d,0x0f000d, |
267 | {16,16, 8, 255,t24HB, t24l}, | 264 | 0x090008,0x090008,0x0b0009,0x0b0009,0x0c000a,0x0c000a,0x0d000b,0x0d000b, |
268 | {16,16, 9, 511,t24HB, t24l}, | 265 | 0x0c000b,0x0d000b,0x0d000c,0x0e000c,0x0e000c,0x0f000d,0x0f000d,0x10000d, |
269 | {16,16,11,2047,t24HB, t24l}, | 266 | 0x0a0009,0x0a0009,0x0b0009,0x0c000a,0x0c000a,0x0c000a,0x0d000b,0x0d000b, |
270 | {16,16,13,8191,t24HB, t24l} }; | 267 | 0x0d000b,0x0d000b,0x0e000c,0x0d000c,0x0f000d,0x0f000d,0x10000d,0x10000e, |
271 | 268 | 0x0a000a,0x0b0009,0x0c000a,0x0c000a,0x0d000a,0x0d000b,0x0d000b,0x0d000b, | |
272 | const struct | 269 | 0x0d000b,0x0e000c,0x0e000c,0x0e000c,0x0f000d,0x0f000d,0x10000e,0x10000e, |
270 | 0x0b000a,0x0b000a,0x0c000a,0x0d000b,0x0d000b,0x0d000b,0x0e000b,0x0e000c, | ||
271 | 0x0e000c,0x0e000c,0x0f000c,0x0f000c,0x0f000d,0x10000d,0x12000d,0x12000e, | ||
272 | 0x0a000a,0x0a000a,0x0b000a,0x0c000b,0x0c000b,0x0d000b,0x0d000b,0x0e000c, | ||
273 | 0x0e000c,0x0e000c,0x0e000c,0x0f000d,0x0f000d,0x10000e,0x11000e,0x11000e, | ||
274 | 0x0b000a,0x0b000a,0x0c000b,0x0c000b,0x0d000b,0x0d000b,0x0d000c,0x0f000c, | ||
275 | 0x0e000c,0x0f000d,0x0f000d,0x10000d,0x10000d,0x10000e,0x12000e,0x11000e, | ||
276 | 0x0b000b,0x0c000b,0x0c000b,0x0d000b,0x0d000c,0x0e000c,0x0e000c,0x0f000c, | ||
277 | 0x0e000c,0x0f000d,0x10000d,0x0f000d,0x10000d,0x11000e,0x12000f,0x13000e, | ||
278 | 0x0c000b,0x0c000b,0x0c000b,0x0d000b,0x0e000c,0x0e000c,0x0e000c,0x0e000c, | ||
279 | 0x0f000d,0x0f000d,0x0f000d,0x10000d,0x11000e,0x11000e,0x11000e,0x12000f, | ||
280 | 0x0c000c,0x0d000c,0x0d000b,0x0e000c,0x0e000c,0x0f000c,0x0e000d,0x0f000d, | ||
281 | 0x10000d,0x10000d,0x11000d,0x11000d,0x11000e,0x12000e,0x12000f,0x12000f, | ||
282 | 0x0d000c,0x0d000c,0x0e000c,0x0f000c,0x0f000c,0x0f000d,0x10000d,0x10000d, | ||
283 | 0x10000d,0x10000e,0x10000e,0x11000e,0x12000e,0x11000e,0x12000f,0x12000f, | ||
284 | 0x0e000d,0x0e000d,0x0e000d,0x0f000d,0x0f000d,0x0f000d,0x11000d,0x10000d, | ||
285 | 0x10000e,0x13000e,0x11000e,0x11000e,0x11000f,0x13000f,0x12000e,0x12000f, | ||
286 | 0x0d000d,0x0e000d,0x0f000d,0x10000d,0x10000d,0x10000d,0x11000d,0x10000e, | ||
287 | 0x11000e,0x11000e,0x12000e,0x12000e,0x15000f,0x14000f,0x15000f,0x12000f }; | ||
288 | |||
289 | static const uint32 tab01_const[16] = | ||
290 | { 0x10004,0x50005,0x50005,0x70006,0x50005,0x80006,0x70006,0x90007, | ||
291 | 0x50005,0x70006,0x70006,0x90007,0x70006,0x90007,0x90007,0xa0008 }; | ||
292 | |||
293 | static const uint32 tab23_const[ 9] = | ||
294 | { 0x10002,0x40003,0x70007,0x40004,0x50004,0x70007,0x60006,0x70007,0x80008 }; | ||
295 | |||
296 | static const uint32 tab56_const[16] = | ||
297 | { 0x10003,0x40004,0x70006,0x80008,0x40004,0x50004,0x80006,0x90007, | ||
298 | 0x70005,0x80006,0x90007,0xa0008,0x80007,0x80007,0x90008,0xa0009 }; | ||
299 | |||
300 | static const uint32 tab789_const[36] = | ||
301 | {0x00100803,0x00401004,0x00701c06,0x00902407,0x00902409,0x00a0280a,0x00401004, | ||
302 | 0x00601005,0x00801806,0x00902807,0x00902808,0x00a0280a,0x00701c05,0x00701806, | ||
303 | 0x00902007,0x00a02808,0x00a02809,0x00b02c0a,0x00802407,0x00902807,0x00a02808, | ||
304 | 0x00b02c09,0x00b02c09,0x00b0300a,0x00802408,0x00902408,0x00a02809,0x00b02c09, | ||
305 | 0x00b0300a,0x00c0300b,0x00902809,0x00a02809,0x00b02c0a,0x00c02c0a,0x00c0340b, | ||
306 | 0x00c0340b}; | ||
307 | |||
308 | static const uint32 tabABC_const[64] = | ||
309 | {0x00100804,0x00401004,0x00701806,0x00902008,0x00a02409,0x00a0280a,0x00a0240a, | ||
310 | 0x00b0280a,0x00401004,0x00601405,0x00801806,0x00902007,0x00a02809,0x00b02809, | ||
311 | 0x00a0240a,0x00a0280a,0x00701806,0x00801c06,0x00902007,0x00a02408,0x00b02809, | ||
312 | 0x00c02c0a,0x00b02809,0x00b0280a,0x00802007,0x00902007,0x00a02408,0x00b02c08, | ||
313 | 0x00c02809,0x00c0300a,0x00b0280a,0x00c02c0a,0x00902408,0x00a02808,0x00b02809, | ||
314 | 0x00c02c09,0x00c02c0a,0x00c0300a,0x00c02c0a,0x00c0300b,0x00a02409,0x00b02809, | ||
315 | 0x00c02c0a,0x00c0300a,0x00d0300a,0x00d0340b,0x00c0300a,0x00d0340b,0x00902409, | ||
316 | 0x00a02409,0x00b02409,0x00c0280a,0x00c02c0a,0x00c0300b,0x00d0300b,0x00d0300c, | ||
317 | 0x00a0240a,0x00a0240a,0x00b0280a,0x00c02c0b,0x00c0300b,0x00d0300b,0x00d0300b, | ||
318 | 0x00d0300c}; | ||
319 | |||
320 | static const uint32 tab1624_const[256] = | ||
321 | {0x00010004,0x00050005,0x00070007,0x00090008,0x000a0009,0x000a000a,0x000b000a, | ||
322 | 0x000b000b,0x000c000b,0x000c000c,0x000c000c,0x000d000c,0x000d000c,0x000d000c, | ||
323 | 0x000e000d,0x000a000a,0x00040005,0x00060006,0x00080007,0x00090008,0x000a0009, | ||
324 | 0x000b000a,0x000b000a,0x000b000b,0x000c000b,0x000c000b,0x000c000c,0x000d000c, | ||
325 | 0x000e000c,0x000d000c,0x000e000c,0x000a000a,0x00070007,0x00080007,0x00090008, | ||
326 | 0x000a0009,0x000b0009,0x000b000a,0x000c000a,0x000c000b,0x000d000b,0x000c000b, | ||
327 | 0x000d000b,0x000d000c,0x000d000c,0x000e000c,0x000e000d,0x000b0009,0x00090008, | ||
328 | 0x00090008,0x000a0009,0x000b0009,0x000b000a,0x000c000a,0x000c000a,0x000c000b, | ||
329 | 0x000d000b,0x000d000b,0x000e000b,0x000e000c,0x000e000c,0x000f000c,0x000f000c, | ||
330 | 0x000c0009,0x000a0009,0x000a0009,0x000b0009,0x000b000a,0x000c000a,0x000c000a, | ||
331 | 0x000d000a,0x000d000b,0x000d000b,0x000e000b,0x000e000c,0x000e000c,0x000f000c, | ||
332 | 0x000f000c,0x000f000d,0x000b0009,0x000a000a,0x000a0009,0x000b000a,0x000b000a, | ||
333 | 0x000c000a,0x000d000a,0x000d000b,0x000e000b,0x000d000b,0x000e000b,0x000e000c, | ||
334 | 0x000f000c,0x000f000c,0x000f000c,0x0010000c,0x000c0009,0x000b000a,0x000b000a, | ||
335 | 0x000b000a,0x000c000a,0x000d000a,0x000d000b,0x000d000b,0x000d000b,0x000e000b, | ||
336 | 0x000e000c,0x000e000c,0x000e000c,0x000f000c,0x000f000c,0x0010000d,0x000c0009, | ||
337 | 0x000b000b,0x000b000a,0x000c000a,0x000c000a,0x000d000b,0x000d000b,0x000d000b, | ||
338 | 0x000e000b,0x000e000c,0x000f000c,0x000f000c,0x000f000c,0x000f000c,0x0011000d, | ||
339 | 0x0011000d,0x000c000a,0x000b000b,0x000c000b,0x000c000b,0x000d000b,0x000d000b, | ||
340 | 0x000d000b,0x000e000b,0x000e000b,0x000f000b,0x000f000c,0x000f000c,0x000f000c, | ||
341 | 0x0010000c,0x0010000d,0x0010000d,0x000c000a,0x000c000b,0x000c000b,0x000c000b, | ||
342 | 0x000d000b,0x000d000b,0x000e000b,0x000e000b,0x000f000c,0x000f000c,0x000f000c, | ||
343 | 0x000f000c,0x0010000c,0x000f000d,0x0010000d,0x000f000d,0x000d000a,0x000c000c, | ||
344 | 0x000d000b,0x000c000b,0x000d000b,0x000e000b,0x000e000c,0x000e000c,0x000e000c, | ||
345 | 0x000f000c,0x0010000c,0x0010000c,0x0010000d,0x0011000d,0x0011000d,0x0010000d, | ||
346 | 0x000c000a,0x000d000c,0x000d000c,0x000d000b,0x000d000b,0x000e000b,0x000e000c, | ||
347 | 0x000f000c,0x0010000c,0x0010000c,0x0010000c,0x0010000c,0x0010000d,0x0010000d, | ||
348 | 0x000f000d,0x0010000d,0x000d000a,0x000d000c,0x000e000c,0x000e000c,0x000e000c, | ||
349 | 0x000e000c,0x000f000c,0x000f000c,0x000f000c,0x000f000c,0x0011000c,0x0010000d, | ||
350 | 0x0010000d,0x0010000d,0x0010000d,0x0012000d,0x000d000a,0x000f000c,0x000e000c, | ||
351 | 0x000e000c,0x000e000c,0x000f000c,0x000f000c,0x0010000c,0x0010000c,0x0010000d, | ||
352 | 0x0012000d,0x0011000d,0x0011000d,0x0011000d,0x0013000d,0x0011000d,0x000d000a, | ||
353 | 0x000e000d,0x000f000c,0x000d000c,0x000e000c,0x0010000c,0x0010000c,0x000f000c, | ||
354 | 0x0010000d,0x0010000d,0x0011000d,0x0012000d,0x0011000d,0x0013000d,0x0011000d, | ||
355 | 0x0010000d,0x000d000a,0x000a0009,0x000a0009,0x000a0009,0x000b0009,0x000b0009, | ||
356 | 0x000c0009,0x000c0009,0x000c0009,0x000d0009,0x000d0009,0x000d0009,0x000d000a, | ||
357 | 0x000d000a,0x000d000a,0x000d000a,0x000a0006}; | ||
358 | |||
359 | static const uint8 t1l_const[8] = {1,3,2,3,1,4,3,5}; | ||
360 | static const uint8 t2l_const[9] = {1,3,6,3,3,5,5,5,6}; | ||
361 | static const uint8 t3l_const[9] = {2,2,6,3,2,5,5,5,6}; | ||
362 | static const uint8 t5l_const[16] = {1,3,6,7,3,3,6,7,6,6,7,8,7,6,7,8}; | ||
363 | static const uint8 t6l_const[16] = {3,3,5,7,3,2,4,5,4,4,5,6,6,5,6,7}; | ||
364 | |||
365 | static const uint8 t7l_const[36] = | ||
366 | {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}; | ||
367 | |||
368 | static const uint8 t8l_const[36] = | ||
369 | {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}; | ||
370 | |||
371 | static const uint8 t9l_const[36] = | ||
372 | {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}; | ||
373 | |||
374 | static const uint8 t10l_const[64] = | ||
375 | {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, | ||
376 | 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}; | ||
377 | |||
378 | static const uint8 t11l_const[64] = | ||
379 | {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, | ||
380 | 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}; | ||
381 | |||
382 | static const uint8 t12l_const[64] = | ||
383 | {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, | ||
384 | 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}; | ||
385 | |||
386 | static const uint8 t13l_const[256] = | ||
387 | {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, | ||
388 | 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, | ||
389 | 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, | ||
390 | 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, | ||
391 | 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, | ||
392 | 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, | ||
393 | 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, | ||
394 | 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, | ||
395 | 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, | ||
396 | 15,15,16,16,19,18,19,16}; | ||
397 | |||
398 | static const uint8 t15l_const[256] = | ||
399 | {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, | ||
400 | 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, | ||
401 | 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, | ||
402 | 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, | ||
403 | 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, | ||
404 | 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, | ||
405 | 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, | ||
406 | 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, | ||
407 | 13,12,11,11,11,11,11,11,12,12,12,12,12,13,13,13,13}; | ||
408 | |||
409 | static const uint8 t16l_const[256] = | ||
410 | {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, | ||
411 | 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, | ||
412 | 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, | ||
413 | 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, | ||
414 | 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, | ||
415 | 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, | ||
416 | 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, | ||
417 | 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, | ||
418 | 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, | ||
419 | 11,11,11,11,11,11,11,8}; | ||
420 | |||
421 | static const uint8 t24l_const[256] = | ||
422 | {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, | ||
423 | 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, | ||
424 | 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, | ||
425 | 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, | ||
426 | 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, | ||
427 | 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, | ||
428 | 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, | ||
429 | 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, | ||
430 | 7,7,7,7,7,7,8,8,8,8,4}; | ||
431 | |||
432 | static const struct huffcodetab ht_const[HTN] = | ||
433 | { { 0, NULL, NULL}, /* Apparently not used */ | ||
434 | { 2, t1HB, t1l}, | ||
435 | { 3, t2HB, t2l}, | ||
436 | { 3, t3HB, t3l}, | ||
437 | { 0, NULL, NULL}, /* Apparently not used */ | ||
438 | { 4, t5HB, t5l}, | ||
439 | { 4, t6HB, t6l}, | ||
440 | { 6, t7HB, t7l}, | ||
441 | { 6, t8HB, t8l}, | ||
442 | { 6, t9HB, t9l}, | ||
443 | { 8, t10HB, t10l}, | ||
444 | { 8, t11HB, t11l}, | ||
445 | { 8, t12HB, t12l}, | ||
446 | {16, t13HB, t13l}, | ||
447 | { 0, NULL, NULL}, /* Apparently not used */ | ||
448 | {16, t15HB, t15l} }; | ||
449 | |||
450 | static const struct huffcodebig ht_big[HTN] = | ||
451 | { { 16, 1, 1 }, | ||
452 | { 16, 2, 3 }, | ||
453 | { 16, 3, 7 }, | ||
454 | { 16, 4, 15 }, | ||
455 | { 16, 6, 63 }, | ||
456 | { 16, 8, 255 }, | ||
457 | { 16, 10, 1023 }, | ||
458 | { 16, 13, 8191 }, | ||
459 | { 16, 4, 15 }, | ||
460 | { 16, 5, 31 }, | ||
461 | { 16, 6, 63 }, | ||
462 | { 16, 7, 127 }, | ||
463 | { 16, 8, 255 }, | ||
464 | { 16, 9, 511 }, | ||
465 | { 16, 11, 2047 }, | ||
466 | { 16, 13, 8191 } }; | ||
467 | |||
468 | static const struct | ||
273 | { | 469 | { |
274 | unsigned region0_count; | 470 | uint32 region0_cnt; |
275 | unsigned region1_count; | 471 | uint32 region1_cnt; |
276 | } subdv_table[23] = | 472 | } subdv_table[23] = |
277 | { {0, 0}, /* 0 bands */ | 473 | { {0, 0}, /* 0 bands */ |
278 | {0, 0}, /* 1 bands */ | 474 | {0, 0}, /* 1 bands */ |
279 | {0, 0}, /* 2 bands */ | 475 | {0, 0}, /* 2 bands */ |
280 | {0, 0}, /* 3 bands */ | 476 | {0, 0}, /* 3 bands */ |
281 | {0, 0}, /* 4 bands */ | 477 | {0, 0}, /* 4 bands */ |
282 | {0, 1}, /* 5 bands */ | 478 | {0, 1}, /* 5 bands */ |
283 | {1, 1}, /* 6 bands */ | 479 | {1, 1}, /* 6 bands */ |
284 | {1, 1}, /* 7 bands */ | 480 | {1, 1}, /* 7 bands */ |
285 | {1, 2}, /* 8 bands */ | 481 | {1, 2}, /* 8 bands */ |
286 | {2, 2}, /* 9 bands */ | 482 | {2, 2}, /* 9 bands */ |
287 | {2, 3}, /* 10 bands */ | 483 | {2, 3}, /* 10 bands */ |
288 | {2, 3}, /* 11 bands */ | 484 | {2, 3}, /* 11 bands */ |
289 | {3, 4}, /* 12 bands */ | 485 | {3, 4}, /* 12 bands */ |
@@ -299,64 +495,7 @@ const struct | |||
299 | {6, 7}, /* 22 bands */ | 495 | {6, 7}, /* 22 bands */ |
300 | }; | 496 | }; |
301 | 497 | ||
302 | /* This is table B.9: coefficients for aliasing reduction */ | 498 | static const uint32 sfBand[6][23] = |
303 | static const int ca_int_const[8] = {0xffffbe25,0xffffc39e,0xffffd7e3,0xffffe8b7,0xfffff3e5,0xfffffac2,0xfffffe2f,0xffffff87}; | ||
304 | static const int cs_int_const[8] = {0x00006dc2,0x000070dd,0x0000798d,0x00007ddd,0x00007f6d,0x00007fe4,0x00007ffd,0x00008000}; | ||
305 | static const int win_int_const[18][36] = { | ||
306 | { 0x0000006b,0x00000121,0x000001a7,0x000001f9,0x00000215,0x000001f9,0x000001a7,0x00000121,0x0000006b,0xffffff8b,0xfffffe87,0xfffffd68,0xfffffc35,0xfffffaf9,0xfffff9bd,0xfffff88b,0xfffff76b,0xfffff667,0xfffff587,0xfffff4d1,0xfffff44b,0xfffff3f8,0xfffff3dd,0xfffff3f8,0xfffff44b,0xfffff4d1,0xfffff587,0xfffff667,0xfffff76b,0xfffff88b,0xfffff9bd,0xfffffaf9,0xfffffc35,0xfffffd68,0xfffffe87,0xffffff8b,}, | ||
307 | { 0xffffff83,0xfffffe49,0xfffffcf3,0xfffffbc3,0xfffffaf9,0xfffffacb,0xfffffb5a,0xfffffcb0,0xfffffebf,0x0000015e,0x00000451,0x0000074d,0x00000a02,0x00000c23,0x00000d72,0x00000dc4,0x00000d06,0x00000b45,0x000008a6,0x00000565,0x000001cf,0xfffffe3b,0xfffffaf9,0xfffff853,0xfffff67c,0xfffff594,0xfffff59b,0xfffff67a,0xfffff801,0xfffff9f1,0xfffffc01,0xfffffdeb,0xffffff72,0x00000066,0x000000b5,0x00000060,}, | ||
308 | { 0xffffffab,0xffffffc2,0x000000ec,0x000002e3,0x00000507,0x0000068f,0x000006c7,0x00000545,0x00000214,0xfffffdbc,0xfffff922,0xfffff55d,0xfffff366,0xfffff3dd,0xfffff6d7,0xfffffbd4,0x000001d7,0x000007a2,0x00000bfb,0x00000dfa,0x00000d3e,0x00000a00,0x00000507,0xffffff74,0xfffffa77,0xfffff70d,0xfffff5c4,0xfffff69f,0xfffff922,0xfffffc79,0xffffffb7,0x00000215,0x00000327,0x000002ef,0x000001d7,0x00000085,}, | ||
309 | { 0x0000008c,0x000001d7,0x00000244,0x000000ec,0xfffffdeb,0xfffffa77,0xfffff85e,0xfffff922,0xfffffd1d,0x00000327,0x000008f3,0x00000bfb,0x00000aa3,0x00000507,0xfffffd11,0xfffff5c4,0xfffff206,0xfffff366,0xfffff971,0x000001d7,0x00000961,0x00000d3e,0x00000c23,0x000006c7,0xffffff7b,0xfffff922,0xfffff600,0xfffff6d7,0xfffffabb,0xffffffab,0x00000387,0x00000507,0x0000042c,0x00000214,0x0000003e,0xffffffb7,}, | ||
310 | { 0x0000003c,0xffffff4b,0xfffffd28,0xfffffc0d,0xfffffdeb,0x00000283,0x0000070f,0x000007ff,0x000003ad,0xfffffbfd,0xfffff594,0xfffff4ec,0xfffffb2d,0x00000507,0x00000c88,0x00000cd4,0x00000565,0xfffffa91,0xfffff2e0,0xfffff2fa,0xfffffab0,0x00000530,0x00000c23,0x00000ba7,0x00000497,0xfffffbaf,0xfffff650,0xfffff720,0xfffffcb0,0x000002ec,0x00000611,0x00000507,0x000001a2,0xfffffed3,0xfffffe49,0xffffff6e,}, | ||
311 | { 0xffffff69,0xfffffe87,0x00000022,0x0000039b,0x00000507,0x0000016b,0xfffffad7,0xfffff76b,0xfffffb91,0x000004d7,0x00000b2f,0x0000081a,0xfffffd46,0xfffff3dd,0xfffff490,0xffffff65,0x00000b2f,0x00000d8d,0x00000445,0xfffff76b,0xfffff221,0xfffff8b7,0x00000507,0x00000c50,0x000008d7,0xfffffe87,0xfffff6b3,0xfffff77b,0xfffffedf,0x000005a2,0x00000669,0x00000215,0xfffffdb4,0xfffffced,0xfffffedf,0x0000002f,}, | ||
312 | { 0xffffffde,0x00000179,0x000002ba,0xffffffd1,0xfffffaf9,0xfffffb29,0x0000024c,0x00000895,0x00000529,0xfffffa5e,0xfffff4d1,0xfffffc65,0x0000094d,0x00000c23,0x00000097,0xfffff3b0,0xfffff4d1,0x00000313,0x00000ddf,0x00000895,0xfffff997,0xfffff273,0xfffffaf9,0x00000885,0x00000b70,0x00000179,0xfffff729,0xfffff7e6,0x00000121,0x00000749,0x0000046f,0xfffffdeb,0xfffffbbb,0xfffffe95,0x00000121,0x0000009b,}, | ||
313 | { 0x0000009d,0x000000b5,0xfffffd8f,0xfffffc9c,0x00000215,0x00000682,0x000000ff,0xfffff801,0xfffffa27,0x00000662,0x00000a6c,0xfffffe70,0xfffff37f,0xfffffaf9,0x00000ac2,0x00000b04,0xfffffa9b,0xfffff1ea,0xfffffe26,0x00000d06,0x00000873,0xfffff7bf,0xfffff3dd,0x000001a5,0x00000be4,0x00000451,0xfffff7af,0xfffff861,0x00000350,0x00000793,0x000000db,0xfffffaf9,0xfffffd66,0x000001df,0x000001b7,0xffffffec,}, | ||
314 | { 0x00000006,0xfffffe29,0xffffff56,0x00000414,0x00000215,0xfffffa2d,0xfffffbe5,0x000006de,0x0000067d,0xfffff8eb,0xfffff70d,0x00000671,0x00000b30,0xfffffaf9,0xfffff311,0x00000301,0x00000dfa,0xffffff62,0xfffff1cf,0xfffffe29,0x00000d8e,0x00000414,0xfffff3dd,0xfffffa2d,0x00000a1d,0x000006de,0xfffff845,0xfffff8eb,0x00000545,0x00000671,0xfffffcf8,0xfffffaf9,0x00000149,0x00000301,0xffffffc2,0xffffff62,}, | ||
315 | { 0xffffff62,0x0000003e,0x00000301,0xfffffeb7,0xfffffaf9,0x00000308,0x00000671,0xfffffabb,0xfffff8eb,0x000007bb,0x000006de,0xfffff5e3,0xfffffa2d,0x00000c23,0x00000414,0xfffff272,0xfffffe29,0x00000e31,0xffffff62,0xfffff206,0x00000301,0x00000cef,0xfffffaf9,0xfffff4d0,0x00000671,0x000008f3,0xfffff8eb,0xfffff983,0x000006de,0x0000041b,0xfffffa2d,0xfffffdeb,0x00000414,0x000000aa,0xfffffe29,0xfffffffa,}, | ||
316 | { 0x00000014,0x000001b7,0xfffffe21,0xfffffd66,0x00000507,0x000000db,0xfffff86d,0x00000350,0x0000079f,0xfffff7af,0xfffffbaf,0x00000be4,0xfffffe5b,0xfffff3dd,0x00000841,0x00000873,0xfffff2fa,0xfffffe26,0x00000e16,0xfffffa9b,0xfffff4fc,0x00000ac2,0x00000507,0xfffff37f,0x00000190,0x00000a6c,0xfffff99e,0xfffffa27,0x000007ff,0x000000ff,0xfffff97e,0x00000215,0x00000364,0xfffffd8f,0xffffff4b,0x0000009d,}, | ||
317 | { 0x0000009b,0xfffffedf,0xfffffe95,0x00000445,0xfffffdeb,0xfffffb91,0x00000749,0xfffffedf,0xfffff7e6,0x000008d7,0x00000179,0xfffff490,0x00000885,0x00000507,0xfffff273,0x00000669,0x00000895,0xfffff221,0x00000313,0x00000b2f,0xfffff3b0,0xffffff69,0x00000c23,0xfffff6b3,0xfffffc65,0x00000b2f,0xfffffa5e,0xfffffad7,0x00000895,0xfffffdb4,0xfffffb29,0x00000507,0xffffffd1,0xfffffd46,0x00000179,0x00000022,}, | ||
318 | { 0xffffffd1,0xfffffedf,0x00000313,0xfffffdb4,0xfffffdeb,0x00000669,0xfffffa5e,0xfffffedf,0x00000885,0xfffff6b3,0x00000179,0x000008d7,0xfffff3b0,0x00000507,0x00000749,0xfffff221,0x00000895,0x00000445,0xfffff273,0x00000b2f,0x0000009b,0xfffff490,0x00000c23,0xfffffd46,0xfffff7e6,0x00000b2f,0xfffffb29,0xfffffb91,0x00000895,0xfffffad7,0xfffffe95,0x00000507,0xfffffc65,0x00000022,0x00000179,0xffffff69,}, | ||
319 | { 0xffffff6e,0x000001b7,0xfffffed3,0xfffffe5e,0x00000507,0xfffff9ef,0x000002ec,0x00000350,0xfffff720,0x000009b0,0xfffffbaf,0xfffffb69,0x00000ba7,0xfffff3dd,0x00000530,0x00000550,0xfffff2fa,0x00000d20,0xfffffa91,0xfffffa9b,0x00000cd4,0xfffff378,0x00000507,0x000004d3,0xfffff4ec,0x00000a6c,0xfffffbfd,0xfffffc53,0x000007ff,0xfffff8f1,0x00000283,0x00000215,0xfffffc0d,0x000002d8,0xffffff4b,0xffffffc4,}, | ||
320 | { 0x00000049,0x0000003e,0xfffffdec,0x0000042c,0xfffffaf9,0x00000387,0x00000055,0xfffffabb,0x00000929,0xfffff600,0x000006de,0xffffff7b,0xfffff939,0x00000c23,0xfffff2c2,0x00000961,0xfffffe29,0xfffff971,0x00000c9a,0xfffff206,0x00000a3c,0xfffffd11,0xfffffaf9,0x00000aa3,0xfffff405,0x000008f3,0xfffffcd9,0xfffffd1d,0x000006de,0xfffff85e,0x00000589,0xfffffdeb,0xffffff14,0x00000244,0xfffffe29,0x0000008c,}, | ||
321 | { 0x00000085,0xfffffe29,0x000002ef,0xfffffcd9,0x00000215,0x00000049,0xfffffc79,0x000006de,0xfffff69f,0x00000a3c,0xfffff70d,0x00000589,0xffffff74,0xfffffaf9,0x00000a00,0xfffff2c2,0x00000dfa,0xfffff405,0x000007a2,0xfffffe29,0xfffffbd4,0x00000929,0xfffff3dd,0x00000c9a,0xfffff55d,0x000006de,0xfffffdbc,0xfffffdec,0x00000545,0xfffff939,0x0000068f,0xfffffaf9,0x000002e3,0xffffff14,0xffffffc2,0x00000055,}, | ||
322 | { 0xffffffa0,0x000000b5,0xffffff9a,0xffffff72,0x00000215,0xfffffc01,0x0000060f,0xfffff801,0x00000986,0xfffff59b,0x00000a6c,0xfffff67c,0x000007ad,0xfffffaf9,0x000001c5,0x000001cf,0xfffffa9b,0x000008a6,0xfffff4bb,0x00000d06,0xfffff23c,0x00000d72,0xfffff3dd,0x00000a02,0xfffff8b3,0x00000451,0xfffffea2,0xfffffebf,0x00000350,0xfffffb5a,0x00000535,0xfffffaf9,0x0000043d,0xfffffcf3,0x000001b7,0xffffff83,}, | ||
323 | { 0xffffff8b,0x00000179,0xfffffd68,0x000003cb,0xfffffaf9,0x00000643,0xfffff88b,0x00000895,0xfffff667,0x00000a79,0xfffff4d1,0x00000bb5,0xfffff3f8,0x00000c23,0xfffff3f8,0x00000bb5,0xfffff4d1,0x00000a79,0xfffff667,0x00000895,0xfffff88b,0x00000643,0xfffffaf9,0x000003cb,0xfffffd68,0x00000179,0xffffff8b,0xffffff95,0x00000121,0xfffffe59,0x000001f9,0xfffffdeb,0x000001f9,0xfffffe59,0x00000121,0xffffff95,}}; | ||
324 | |||
325 | const short filter_int_const[SBLIMIT][64] = { | ||
326 | { 23170, 24279, 25330, 26320, 27246, 28106, 28899, 29622, 30274, 30853, 31357, 31786, 32138, 32413, 32610, 32729, 32767, 32729, 32610, 32413, 32138, 31786, 31357, 30853, 30274, 29622, 28899, 28106, 27246, 26320, 25330, 24279, 23170, 22006, 20788, 19520, 18205, 16846, 15447, 14010, 12540, 11039, 9512, 7962, 6393, 4808, 3212, 1608, 0, -1607, -3211, -4807, -6392, -7961, -9511,-11038,-12539,-14009,-15446,-16845,-18204,-19519,-20787,-22005, }, | ||
327 | { -23169,-19519,-15446,-11038, -6392, -1607, 3212, 7962, 12540, 16846, 20788, 24279, 27246, 29622, 31357, 32413, 32767, 32413, 31357, 29622, 27246, 24279, 20788, 16846, 12540, 7962, 3212, -1607, -6392,-11038,-15446,-19519,-23169,-26319,-28898,-30852,-32137,-32728,-32609,-31785,-30273,-28105,-25329,-22005,-18204,-14009, -9511, -4807, 0, 4808, 9512, 14010, 18205, 22006, 25330, 28106, 30274, 31786, 32610, 32729, 32138, 30853, 28899, 26320, }, | ||
328 | { -23169,-28105,-31356,-32728,-32137,-29621,-25329,-19519,-12539, -4807, 3212, 11039, 18205, 24279, 28899, 31786, 32767, 31786, 28899, 24279, 18205, 11039, 3212, -4807,-12539,-19519,-25329,-29621,-32137,-32728,-31356,-28105,-23169,-16845, -9511, -1607, 6393, 14010, 20788, 26320, 30274, 32413, 32610, 30853, 27246, 22006, 15447, 7962, 0, -7961,-15446,-22005,-27245,-30852,-32609,-32412,-30273,-26319,-20787,-14009, -6392, 1608, 9512, 16846, }, | ||
329 | { 23170, 14010, 3212, -7961,-18204,-26319,-31356,-32728,-30273,-24278,-15446, -4807, 6393, 16846, 25330, 30853, 32767, 30853, 25330, 16846, 6393, -4807,-15446,-24278,-30273,-32728,-31356,-26319,-18204, -7961, 3212, 14010, 23170, 29622, 32610, 31786, 27246, 19520, 9512, -1607,-12539,-22005,-28898,-32412,-32137,-28105,-20787,-11038, 0, 11039, 20788, 28106, 32138, 32413, 28899, 22006, 12540, 1608, -9511,-19519,-27245,-31785,-32609,-29621, }, | ||
330 | { 23170, 30853, 32610, 28106, 18205, 4808, -9511,-22005,-30273,-32728,-28898,-19519, -6392, 7962, 20788, 29622, 32767, 29622, 20788, 7962, -6392,-19519,-28898,-32728,-30273,-22005, -9511, 4808, 18205, 28106, 32610, 30853, 23170, 11039, -3211,-16845,-27245,-32412,-31356,-24278,-12539, 1608, 15447, 26320, 32138, 31786, 25330, 14010, 0,-14009,-25329,-31785,-32137,-26319,-15446, -1607, 12540, 24279, 31357, 32413, 27246, 16846, 3212,-11038, }, | ||
331 | { -23169, -7961, 9512, 24279, 32138, 30853, 20788, 4808,-12539,-26319,-32609,-29621,-18204, -1607, 15447, 28106, 32767, 28106, 15447, -1607,-18204,-29621,-32609,-26319,-12539, 4808, 20788, 30853, 32138, 24279, 9512, -7961,-23169,-31785,-31356,-22005, -6392, 11039, 25330, 32413, 30274, 19520, 3212,-14009,-27245,-32728,-28898,-16845, 0, 16846, 28899, 32729, 27246, 14010, -3211,-19519,-30273,-32412,-25329,-11038, 6393, 22006, 31357, 31786, }, | ||
332 | { -23169,-32412,-28898,-14009, 6393, 24279, 32610, 28106, 12540, -7961,-25329,-32728,-27245,-11038, 9512, 26320, 32767, 26320, 9512,-11038,-27245,-32728,-25329, -7961, 12540, 28106, 32610, 24279, 6393,-14009,-28898,-32412,-23169, -4807, 15447, 29622, 32138, 22006, 3212,-16845,-30273,-31785,-20787, -1607, 18205, 30853, 31357, 19520, 0,-19519,-31356,-30852,-18204, 1608, 20788, 31786, 30274, 16846, -3211,-22005,-32137,-29621,-15446, 4808, }, | ||
333 | { 23170, 1608,-20787,-32412,-27245, -7961, 15447, 30853, 30274, 14010, -9511,-28105,-32137,-19519, 3212, 24279, 32767, 24279, 3212,-19519,-32137,-28105, -9511, 14010, 30274, 30853, 15447, -7961,-27245,-32412,-20787, 1608, 23170, 32729, 25330, 4808,-18204,-31785,-28898,-11038, 12540, 29622, 31357, 16846, -6392,-26319,-32609,-22005, 0, 22006, 32610, 26320, 6393,-16845,-31356,-29621,-12539, 11039, 28899, 31786, 18205, -4807,-25329,-32728, }, | ||
334 | { 23170, 32729, 20788, -4807,-27245,-31785,-15446, 11039, 30274, 29622, 9512,-16845,-32137,-26319, -3211, 22006, 32767, 22006, -3211,-26319,-32137,-16845, 9512, 29622, 30274, 11039,-15446,-31785,-27245, -4807, 20788, 32729, 23170, -1607,-25329,-32412,-18204, 7962, 28899, 30853, 12540,-14009,-31356,-28105, -6392, 19520, 32610, 24279, 0,-24278,-32609,-19519, 6393, 28106, 31357, 14010,-12539,-30852,-28898, -7961, 18205, 32413, 25330, 1608, }, | ||
335 | { -23169, 4808, 28899, 29622, 6393,-22005,-32609,-16845, 12540, 31786, 25330, -1607,-27245,-30852, -9511, 19520, 32767, 19520, -9511,-30852,-27245, -1607, 25330, 31786, 12540,-16845,-32609,-22005, 6393, 29622, 28899, 4808,-23169,-32412,-15446, 14010, 32138, 24279, -3211,-28105,-30273, -7961, 20788, 32729, 18205,-11038,-31356,-26319, 0, 26320, 31357, 11039,-18204,-32728,-20787, 7962, 30274, 28106, 3212,-24278,-32137,-14009, 15447, 32413, }, | ||
336 | { -23169,-31785, -9511, 22006, 32138, 11039,-20787,-32412,-12539, 19520, 32610, 14010,-18204,-32728,-15446, 16846, 32767, 16846,-15446,-32728,-18204, 14010, 32610, 19520,-12539,-32412,-20787, 11039, 32138, 22006, -9511,-31785,-23169, 7962, 31357, 24279, -6392,-30852,-25329, 4808, 30274, 26320, -3211,-29621,-27245, 1608, 28899, 28106, 0,-28105,-28898, -1607, 27246, 29622, 3212,-26319,-30273, -4807, 25330, 30853, 6393,-24278,-31356, -7961, }, | ||
337 | { 23170,-11038,-32609,-16845, 18205, 32413, 9512,-24278,-30273, -1607, 28899, 26320, -6392,-31785,-20787, 14010, 32767, 14010,-20787,-31785, -6392, 26320, 28899, -1607,-30273,-24278, 9512, 32413, 18205,-16845,-32609,-11038, 23170, 30853, 3212,-28105,-27245, 4808, 31357, 22006,-12539,-32728,-15446, 19520, 32138, 7962,-25329,-29621, 0, 29622, 25330, -7961,-32137,-19519, 15447, 32729, 12540,-22005,-31356, -4807, 27246, 28106, -3211,-30852, }, | ||
338 | { 23170, 29622, -3211,-31785,-18204, 19520, 31357, 1608,-30273,-22005, 15447, 32413, 6393,-28105,-25329, 11039, 32767, 11039,-25329,-28105, 6393, 32413, 15447,-22005,-30273, 1608, 31357, 19520,-18204,-31785, -3211, 29622, 23170,-14009,-32609, -7961, 27246, 26320, -9511,-32728,-12539, 24279, 28899, -4807,-32137,-16845, 20788, 30853, 0,-30852,-20787, 16846, 32138, 4808,-28898,-24278, 12540, 32729, 9512,-26319,-27245, 7962, 32610, 14010, }, | ||
339 | { -23169, 16846, 31357, -1607,-32137,-14009, 25330, 26320,-12539,-32412, -3211, 30853, 18205,-22005,-28898, 7962, 32767, 7962,-28898,-22005, 18205, 30853, -3211,-32412,-12539, 26320, 25330,-14009,-32137, -1607, 31357, 16846,-23169,-28105, 9512, 32729, 6393,-29621,-20787, 19520, 30274, -4807,-32609,-11038, 27246, 24279,-15446,-31785, 0, 31786, 15447,-24278,-27245, 11039, 32610, 4808,-30273,-19519, 20788, 29622, -6392,-32728, -9511, 28106, }, | ||
340 | { -23169,-26319, 15447, 30853, -6392,-32728, -3211, 31786, 12540,-28105,-20787, 22006, 27246,-14009,-31356, 4808, 32767, 4808,-31356,-14009, 27246, 22006,-20787,-28105, 12540, 31786, -3211,-32728, -6392, 30853, 15447,-26319,-23169, 19520, 28899,-11038,-32137, 1608, 32610, 7962,-30273,-16845, 25330, 24279,-18204,-29621, 9512, 32413, 0,-32412, -9511, 29622, 18205,-24278,-25329, 16846, 30274, -7961,-32609, -1607, 32138, 11039,-28898,-19519, }, | ||
341 | { 23170,-22005,-25329, 19520, 27246,-16845,-28898, 14010, 30274,-11038,-31356, 7962, 32138, -4807,-32609, 1608, 32767, 1608,-32609, -4807, 32138, 7962,-31356,-11038, 30274, 14010,-28898,-16845, 27246, 19520,-25329,-22005, 23170, 24279,-20787,-26319, 18205, 28106,-15446,-29621, 12540, 30853, -9511,-31785, 6393, 32413, -3211,-32728, 0, 32729, 3212,-32412, -6392, 31786, 9512,-30852,-12539, 29622, 15447,-28105,-18204, 26320, 20788,-24278, }, | ||
342 | { 23170, 22006,-25329,-19519, 27246, 16846,-28898,-14009, 30274, 11039,-31356, -7961, 32138, 4808,-32609, -1607, 32767, -1607,-32609, 4808, 32138, -7961,-31356, 11039, 30274,-14009,-28898, 16846, 27246,-19519,-25329, 22006, 23170,-24278,-20787, 26320, 18205,-28105,-15446, 29622, 12540,-30852, -9511, 31786, 6393,-32412, -3211, 32729, 0,-32728, 3212, 32413, -6392,-31785, 9512, 30853,-12539,-29621, 15447, 28106,-18204,-26319, 20788, 24279, }, | ||
343 | { -23169, 26320, 15447,-30852, -6392, 32729, -3211,-31785, 12540, 28106,-20787,-22005, 27246, 14010,-31356, -4807, 32767, -4807,-31356, 14010, 27246,-22005,-20787, 28106, 12540,-31785, -3211, 32729, -6392,-30852, 15447, 26320,-23169,-19519, 28899, 11039,-32137, -1607, 32610, -7961,-30273, 16846, 25330,-24278,-18204, 29622, 9512,-32412, 0, 32413, -9511,-29621, 18205, 24279,-25329,-16845, 30274, 7962,-32609, 1608, 32138,-11038,-28898, 19520, }, | ||
344 | { -23169,-16845, 31357, 1608,-32137, 14010, 25330,-26319,-12539, 32413, -3211,-30852, 18205, 22006,-28898, -7961, 32767, -7961,-28898, 22006, 18205,-30852, -3211, 32413,-12539,-26319, 25330, 14010,-32137, 1608, 31357,-16845,-23169, 28106, 9512,-32728, 6393, 29622,-20787,-19519, 30274, 4808,-32609, 11039, 27246,-24278,-15446, 31786, 0,-31785, 15447, 24279,-27245,-11038, 32610, -4807,-30273, 19520, 20788,-29621, -6392, 32729, -9511,-28105, }, | ||
345 | { 23170,-29621, -3211, 31786,-18204,-19519, 31357, -1607,-30273, 22006, 15447,-32412, 6393, 28106,-25329,-11038, 32767,-11038,-25329, 28106, 6393,-32412, 15447, 22006,-30273, -1607, 31357,-19519,-18204, 31786, -3211,-29621, 23170, 14010,-32609, 7962, 27246,-26319, -9511, 32729,-12539,-24278, 28899, 4808,-32137, 16846, 20788,-30852, 0, 30853,-20787,-16845, 32138, -4807,-28898, 24279, 12540,-32728, 9512, 26320,-27245, -7961, 32610,-14009, }, | ||
346 | { 23170, 11039,-32609, 16846, 18205,-32412, 9512, 24279,-30273, 1608, 28899,-26319, -6392, 31786,-20787,-14009, 32767,-14009,-20787, 31786, -6392,-26319, 28899, 1608,-30273, 24279, 9512,-32412, 18205, 16846,-32609, 11039, 23170,-30852, 3212, 28106,-27245, -4807, 31357,-22005,-12539, 32729,-15446,-19519, 32138, -7961,-25329, 29622, 0,-29621, 25330, 7962,-32137, 19520, 15447,-32728, 12540, 22006,-31356, 4808, 27246,-28105, -3211, 30853, }, | ||
347 | { -23169, 31786, -9511,-22005, 32138,-11038,-20787, 32413,-12539,-19519, 32610,-14009,-18204, 32729,-15446,-16845, 32767,-16845,-15446, 32729,-18204,-14009, 32610,-19519,-12539, 32413,-20787,-11038, 32138,-22005, -9511, 31786,-23169, -7961, 31357,-24278, -6392, 30853,-25329, -4807, 30274,-26319, -3211, 29622,-27245, -1607, 28899,-28105, 0, 28106,-28898, 1608, 27246,-29621, 3212, 26320,-30273, 4808, 25330,-30852, 6393, 24279,-31356, 7962, }, | ||
348 | { -23169, -4807, 28899,-29621, 6393, 22006,-32609, 16846, 12540,-31785, 25330, 1608,-27245, 30853, -9511,-19519, 32767,-19519, -9511, 30853,-27245, 1608, 25330,-31785, 12540, 16846,-32609, 22006, 6393,-29621, 28899, -4807,-23169, 32413,-15446,-14009, 32138,-24278, -3211, 28106,-30273, 7962, 20788,-32728, 18205, 11039,-31356, 26320, 0,-26319, 31357,-11038,-18204, 32729,-20787, -7961, 30274,-28105, 3212, 24279,-32137, 14010, 15447,-32412, }, | ||
349 | { 23170,-32728, 20788, 4808,-27245, 31786,-15446,-11038, 30274,-29621, 9512, 16846,-32137, 26320, -3211,-22005, 32767,-22005, -3211, 26320,-32137, 16846, 9512,-29621, 30274,-11038,-15446, 31786,-27245, 4808, 20788,-32728, 23170, 1608,-25329, 32413,-18204, -7961, 28899,-30852, 12540, 14010,-31356, 28106, -6392,-19519, 32610,-24278, 0, 24279,-32609, 19520, 6393,-28105, 31357,-14009,-12539, 30853,-28898, 7962, 18205,-32412, 25330, -1607, }, | ||
350 | { 23170, -1607,-20787, 32413,-27245, 7962, 15447,-30852, 30274,-14009, -9511, 28106,-32137, 19520, 3212,-24278, 32767,-24278, 3212, 19520,-32137, 28106, -9511,-14009, 30274,-30852, 15447, 7962,-27245, 32413,-20787, -1607, 23170,-32728, 25330, -4807,-18204, 31786,-28898, 11039, 12540,-29621, 31357,-16845, -6392, 26320,-32609, 22006, 0,-22005, 32610,-26319, 6393, 16846,-31356, 29622,-12539,-11038, 28899,-31785, 18205, 4808,-25329, 32729, }, | ||
351 | { -23169, 32413,-28898, 14010, 6393,-24278, 32610,-28105, 12540, 7962,-25329, 32729,-27245, 11039, 9512,-26319, 32767,-26319, 9512, 11039,-27245, 32729,-25329, 7962, 12540,-28105, 32610,-24278, 6393, 14010,-28898, 32413,-23169, 4808, 15447,-29621, 32138,-22005, 3212, 16846,-30273, 31786,-20787, 1608, 18205,-30852, 31357,-19519, 0, 19520,-31356, 30853,-18204, -1607, 20788,-31785, 30274,-16845, -3211, 22006,-32137, 29622,-15446, -4807, }, | ||
352 | { -23169, 7962, 9512,-24278, 32138,-30852, 20788, -4807,-12539, 26320,-32609, 29622,-18204, 1608, 15447,-28105, 32767,-28105, 15447, 1608,-18204, 29622,-32609, 26320,-12539, -4807, 20788,-30852, 32138,-24278, 9512, 7962,-23169, 31786,-31356, 22006, -6392,-11038, 25330,-32412, 30274,-19519, 3212, 14010,-27245, 32729,-28898, 16846, 0,-16845, 28899,-32728, 27246,-14009, -3211, 19520,-30273, 32413,-25329, 11039, 6393,-22005, 31357,-31785, }, | ||
353 | { 23170,-30852, 32610,-28105, 18205, -4807, -9511, 22006,-30273, 32729,-28898, 19520, -6392, -7961, 20788,-29621, 32767,-29621, 20788, -7961, -6392, 19520,-28898, 32729,-30273, 22006, -9511, -4807, 18205,-28105, 32610,-30852, 23170,-11038, -3211, 16846,-27245, 32413,-31356, 24279,-12539, -1607, 15447,-26319, 32138,-31785, 25330,-14009, 0, 14010,-25329, 31786,-32137, 26320,-15446, 1608, 12540,-24278, 31357,-32412, 27246,-16845, 3212, 11039, }, | ||
354 | { 23170,-14009, 3212, 7962,-18204, 26320,-31356, 32729,-30273, 24279,-15446, 4808, 6393,-16845, 25330,-30852, 32767,-30852, 25330,-16845, 6393, 4808,-15446, 24279,-30273, 32729,-31356, 26320,-18204, 7962, 3212,-14009, 23170,-29621, 32610,-31785, 27246,-19519, 9512, 1608,-12539, 22006,-28898, 32413,-32137, 28106,-20787, 11039, 0,-11038, 20788,-28105, 32138,-32412, 28899,-22005, 12540, -1607, -9511, 19520,-27245, 31786,-32609, 29622, }, | ||
355 | { -23169, 28106,-31356, 32729,-32137, 29622,-25329, 19520,-12539, 4808, 3212,-11038, 18205,-24278, 28899,-31785, 32767,-31785, 28899,-24278, 18205,-11038, 3212, 4808,-12539, 19520,-25329, 29622,-32137, 32729,-31356, 28106,-23169, 16846, -9511, 1608, 6393,-14009, 20788,-26319, 30274,-32412, 32610,-30852, 27246,-22005, 15447, -7961, 0, 7962,-15446, 22006,-27245, 30853,-32609, 32413,-30273, 26320,-20787, 14010, -6392, -1607, 9512,-16845, }, | ||
356 | { -23169, 19520,-15446, 11039, -6392, 1608, 3212, -7961, 12540,-16845, 20788,-24278, 27246,-29621, 31357,-32412, 32767,-32412, 31357,-29621, 27246,-24278, 20788,-16845, 12540, -7961, 3212, 1608, -6392, 11039,-15446, 19520,-23169, 26320,-28898, 30853,-32137, 32729,-32609, 31786,-30273, 28106,-25329, 22006,-18204, 14010, -9511, 4808, 0, -4807, 9512,-14009, 18205,-22005, 25330,-28105, 30274,-31785, 32610,-32728, 32138,-30852, 28899,-26319, }, | ||
357 | { 23170,-24278, 25330,-26319, 27246,-28105, 28899,-29621, 30274,-30852, 31357,-31785, 32138,-32412, 32610,-32728, 32767,-32728, 32610,-32412, 32138,-31785, 31357,-30852, 30274,-29621, 28899,-28105, 27246,-26319, 25330,-24278, 23170,-22005, 20788,-19519, 18205,-16845, 15447,-14009, 12540,-11038, 9512, -7961, 6393, -4807, 3212, -1607, 0, 1608, -3211, 4808, -6392, 7962, -9511, 11039,-12539, 14010,-15446, 16846,-18204, 19520,-20787, 22006, } }; | ||
358 | |||
359 | const int sfBandIndex[6][23] = | ||
360 | { | 499 | { |
361 | /* Table B.2.b: 22.05 kHz */ | 500 | /* Table B.2.b: 22.05 kHz */ |
362 | {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, | 501 | {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, |
@@ -371,744 +510,830 @@ const int sfBandIndex[6][23] = | |||
371 | /* Table B.8.a: 32 kHz */ | 510 | /* Table B.8.a: 32 kHz */ |
372 | {0,4, 8,12,16,20,24,30,36,44,54,66, 82,102,126,156,194,240,296,364,448,550,576} }; | 511 | {0,4, 8,12,16,20,24,30,36,44,54,66, 82,102,126,156,194,240,296,364,448,550,576} }; |
373 | 512 | ||
374 | const unsigned short enwindow_int_const[512] = { | 513 | |
375 | 0x0000,0x0035,0x01fd,0x066c,0x4948,0x066c,0x01fd,0x0035,0x0000,0x0037,0x01f4,0x05d2,0x493c,0x06f8,0x0204,0x0034, | 514 | static const short int2idx_const[4096] = /* int2idx[i] = sqrt(i*sqrt(i)); */ |
376 | 0x0000,0x0038,0x01e8,0x052a,0x491a,0x0776,0x0208,0x0032,0x0000,0x0038,0x01d9,0x0474,0x48e1,0x07e7,0x020a,0x0031, | 515 | { |
377 | 0x0000,0x0039,0x01c8,0x03b0,0x4892,0x084b,0x0209,0x0030,0x0000,0x0039,0x01b3,0x02de,0x482d,0x08a2,0x0207,0x002e, | 516 | 0, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, |
378 | 0x0000,0x0039,0x019b,0x01fd,0x47b2,0x08ed,0x0202,0x002c,0x0000,0x0039,0x0180,0x010f,0x4721,0x092b,0x01fc,0x002a, | 517 | 9, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, |
379 | 0x0000,0x0038,0x0161,0x0011,0x467a,0x095e,0x01f4,0x0028,0x0000,0x0037,0x0140,0xff07,0x45bf,0x0985,0x01eb,0x0026, | 518 | 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, |
380 | 0x0000,0x0036,0x011b,0xfdee,0x44f0,0x09a2,0x01e0,0x0025,0x0000,0x0034,0x00f3,0xfcc8,0x440c,0x09b4,0x01d4,0x0023, | 519 | 22, 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, 25, 25, 26, 26, 26, 26, |
381 | 0x0000,0x0032,0x00c7,0xfb93,0x4315,0x09bb,0x01c6,0x0021,0x0000,0x002f,0x0097,0xfa53,0x420b,0x09ba,0x01b8,0x001f, | 520 | 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, |
382 | 0x0000,0x002c,0x0065,0xf905,0x40f0,0x09af,0x01a9,0x001d,0x0000,0x0029,0x002e,0xf7aa,0x3fc3,0x099b,0x0198,0x001c, | 521 | 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 34, 35, 35, 35, 35, 36, 36, 36, |
383 | 0x0000,0x0025,0xfff6,0xf643,0x3e85,0x0980,0x0188,0x001a,0xffff,0x0020,0xffb9,0xf4d1,0x3d37,0x095c,0x0176,0x0018, | 522 | 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 38, 39, 39, 39, 39, 40, 40, 40, 40, 40, |
384 | 0xffff,0x001b,0xff79,0xf354,0x3bda,0x0932,0x0165,0x0017,0xffff,0x0015,0xff36,0xf1cc,0x3a70,0x0901,0x0153,0x0015, | 523 | 41, 41, 41, 41, 42, 42, 42, 42, 42, 43, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45, |
385 | 0xffff,0x000e,0xfeef,0xf03a,0x38f7,0x08ca,0x0141,0x0014,0xffff,0x0007,0xfea6,0xee9f,0x3773,0x088d,0x012f,0x0012, | 524 | 45, 45, 45, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 48, 48, 48, 48, 49, 49, 49, |
386 | 0xfffe,0x0000,0xfe5a,0xecfb,0x35e3,0x084b,0x011c,0x0011,0xfffe,0xfff8,0xfe0b,0xeb50,0x3447,0x0804,0x010a,0x0010, | 525 | 49, 49, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 53, 53, 53, |
387 | 0xfffe,0xffef,0xfdbb,0xe99d,0x32a3,0x07ba,0x00f8,0x000f,0xfffd,0xffe5,0xfd67,0xe7e4,0x30f6,0x076b,0x00e6,0x000d, | 526 | 53, 53, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 56, 56, 56, 56, 56, 57, 57, 57, |
388 | 0xfffd,0xffdb,0xfd12,0xe624,0x2f41,0x071a,0x00d4,0x000c,0xfffd,0xffd0,0xfcbb,0xe461,0x2d86,0x06c6,0x00c3,0x000b, | 527 | 57, 57, 58, 58, 58, 58, 58, 58, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 61, 61, |
389 | 0xfffc,0xffc4,0xfc63,0xe299,0x2bc5,0x066f,0x00b2,0x000a,0xfffc,0xffb8,0xfc09,0xe0ce,0x2a00,0x0617,0x00a1,0x0009, | 528 | 61, 61, 61, 62, 62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 65, |
390 | 0xfffb,0xffaa,0xfbaf,0xdf01,0x2836,0x05be,0x0091,0x0009,0xfffb,0xff9d,0xfb54,0xdd33,0x266a,0x0563,0x0081,0x0008, | 529 | 65, 65, 65, 65, 65, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68, |
391 | 0xfffa,0xff8e,0xfaf9,0xdb65,0x249c,0x0508,0x0073,0x0007,0xfff9,0xff80,0xfa9e,0xd997,0x22ce,0x04ad,0x0064,0x0006, | 530 | 68, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 72, 72, 72, |
392 | 0xfff8,0xff70,0xfa43,0xd7cb,0x2100,0x0452,0x0057,0x0006,0xfff8,0xff60,0xf9ea,0xd601,0x1f33,0x03f8,0x0049,0x0005, | 531 | 72, 72, 72, 73, 73, 73, 73, 73, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, |
393 | 0xfff7,0xff4f,0xf992,0xd43c,0x1d68,0x039e,0x003d,0x0005,0xfff6,0xff3e,0xf93b,0xd27b,0x1ba0,0x0346,0x0031,0x0004, | 532 | 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 79, 79, 79, |
394 | 0xfff5,0xff2d,0xf8e7,0xd0c0,0x19dd,0x02ef,0x0026,0x0004,0xfff4,0xff1b,0xf896,0xcf0b,0x181d,0x029a,0x001c,0x0004, | 533 | 79, 79, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, |
395 | 0xfff2,0xff09,0xf847,0xcd5e,0x1664,0x0246,0x0012,0x0003,0xfff1,0xfef7,0xf7fd,0xcbba,0x14b1,0x01f6,0x0009,0x0003, | 534 | 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 86, 86, 86, |
396 | 0xfff0,0xfee5,0xf7b6,0xca1e,0x1306,0x01a7,0x0001,0x0003,0xffef,0xfed2,0xf774,0xc88e,0x1162,0x015b,0xfffa,0x0002, | 535 | 86, 86, 86, 87, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 89, 89, 89, 89, 89, |
397 | 0xffed,0xfec0,0xf737,0xc70a,0x0fc7,0x0112,0xfff3,0x0002,0xffec,0xfeae,0xf700,0xc591,0x0e35,0x00cb,0xffec,0x0002, | 536 | 89, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 93, |
398 | 0xffea,0xfe9c,0xf6cf,0xc427,0x0cad,0x0088,0xffe6,0x0002,0xffe9,0xfe8b,0xf6a5,0xc2ca,0x0b30,0x0048,0xffe1,0x0002, | 537 | 93, 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95, 95, 95, 96, 96, 96, |
399 | 0xffe7,0xfe79,0xf681,0xc17c,0x09be,0x000b,0xffdc,0x0001,0xffe5,0xfe69,0xf666,0xc03e,0x0857,0xffd3,0xffd8,0x0001, | 538 | 96, 96, 96, 97, 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 98, 99, 99, 99, 99, 99, |
400 | 0xffe4,0xfe58,0xf652,0xbf11,0x06fc,0xff9c,0xffd5,0x0001,0xffe2,0xfe49,0xf647,0xbdf6,0x05ae,0xff6a,0xffd2,0x0001, | 539 | 99, 99,100,100,100,100,100,100,101,101,101,101,101,101,102,102,102,102,102,102, |
401 | 0xffe0,0xfe3b,0xf646,0xbcec,0x046e,0xff3a,0xffcf,0x0001,0xffde,0xfe2d,0xf64d,0xbbf5,0x0339,0xff0e,0xffcd,0x0001, | 540 | 103,103,103,103,103,103,104,104,104,104,104,104,104,105,105,105,105,105,105,106, |
402 | 0xffdc,0xfe21,0xf65f,0xbb11,0x0213,0xfee6,0xffcb,0x0001,0xffdb,0xfe16,0xf67c,0xba42,0x00fa,0xfec1,0xffca,0x0001, | 541 | 106,106,106,106,106,107,107,107,107,107,107,107,108,108,108,108,108,108,109,109, |
403 | 0xffd9,0xfe0d,0xf6a3,0xb987,0xfff0,0xfea0,0xffc9,0x0001,0xffd7,0xfe05,0xf6d6,0xb8e0,0xfef2,0xfe81,0xffc8,0x0001, | 542 | 109,109,109,109,110,110,110,110,110,110,110,111,111,111,111,111,111,112,112,112, |
404 | 0xffd5,0xfdff,0xf714,0xb84f,0xfe04,0xfe66,0xffc8,0x0000,0xffd3,0xfdfa,0xf75f,0xb7d4,0xfd23,0xfe4e,0xffc8,0x0000, | 543 | 112,112,112,112,113,113,113,113,113,113,114,114,114,114,114,114,115,115,115,115, |
405 | 0xffd1,0xfdf8,0xf7b6,0xb76f,0xfc51,0xfe39,0xffc8,0x0000,0xffd0,0xfdf7,0xf81a,0xb720,0xfb8d,0xfe28,0xffc9,0x0000, | 544 | 115,115,115,116,116,116,116,116,116,117,117,117,117,117,117,117,118,118,118,118, |
406 | 0xffcf,0xfdf9,0xf88b,0xb6e7,0xfad7,0xfe19,0xffc9,0x0000,0xffcd,0xfdfd,0xf909,0xb6c5,0xfa2f,0xfe0d,0xffca,0x0000, | 545 | 118,118,118,119,119,119,119,119,119,120,120,120,120,120,120,120,121,121,121,121, |
546 | 121,121,122,122,122,122,122,122,122,123,123,123,123,123,123,123,124,124,124,124, | ||
547 | 124,124,125,125,125,125,125,125,125,126,126,126,126,126,126,126,127,127,127,127, | ||
548 | 127,127,128,128,128,128,128,128,128,129,129,129,129,129,129,129,130,130,130,130, | ||
549 | 130,130,131,131,131,131,131,131,131,132,132,132,132,132,132,132,133,133,133,133, | ||
550 | 133,133,133,134,134,134,134,134,134,134,135,135,135,135,135,135,136,136,136,136, | ||
551 | 136,136,136,137,137,137,137,137,137,137,138,138,138,138,138,138,138,139,139,139, | ||
552 | 139,139,139,139,140,140,140,140,140,140,140,141,141,141,141,141,141,141,142,142, | ||
553 | 142,142,142,142,142,143,143,143,143,143,143,143,144,144,144,144,144,144,144,145, | ||
554 | 145,145,145,145,145,145,146,146,146,146,146,146,146,147,147,147,147,147,147,147, | ||
555 | 148,148,148,148,148,148,148,149,149,149,149,149,149,149,150,150,150,150,150,150, | ||
556 | 150,151,151,151,151,151,151,151,152,152,152,152,152,152,152,153,153,153,153,153, | ||
557 | 153,153,154,154,154,154,154,154,154,154,155,155,155,155,155,155,155,156,156,156, | ||
558 | 156,156,156,156,157,157,157,157,157,157,157,158,158,158,158,158,158,158,159,159, | ||
559 | 159,159,159,159,159,160,160,160,160,160,160,160,160,161,161,161,161,161,161,161, | ||
560 | 162,162,162,162,162,162,162,163,163,163,163,163,163,163,163,164,164,164,164,164, | ||
561 | 164,164,165,165,165,165,165,165,165,166,166,166,166,166,166,166,167,167,167,167, | ||
562 | 167,167,167,167,168,168,168,168,168,168,168,169,169,169,169,169,169,169,169,170, | ||
563 | 170,170,170,170,170,170,171,171,171,171,171,171,171,172,172,172,172,172,172,172, | ||
564 | 172,173,173,173,173,173,173,173,174,174,174,174,174,174,174,174,175,175,175,175, | ||
565 | 175,175,175,176,176,176,176,176,176,176,176,177,177,177,177,177,177,177,178,178, | ||
566 | 178,178,178,178,178,178,179,179,179,179,179,179,179,180,180,180,180,180,180,180, | ||
567 | 180,181,181,181,181,181,181,181,182,182,182,182,182,182,182,182,183,183,183,183, | ||
568 | 183,183,183,184,184,184,184,184,184,184,184,185,185,185,185,185,185,185,186,186, | ||
569 | 186,186,186,186,186,186,187,187,187,187,187,187,187,187,188,188,188,188,188,188, | ||
570 | 188,189,189,189,189,189,189,189,189,190,190,190,190,190,190,190,190,191,191,191, | ||
571 | 191,191,191,191,192,192,192,192,192,192,192,192,193,193,193,193,193,193,193,193, | ||
572 | 194,194,194,194,194,194,194,195,195,195,195,195,195,195,195,196,196,196,196,196, | ||
573 | 196,196,196,197,197,197,197,197,197,197,197,198,198,198,198,198,198,198,199,199, | ||
574 | 199,199,199,199,199,199,200,200,200,200,200,200,200,200,201,201,201,201,201,201, | ||
575 | 201,201,202,202,202,202,202,202,202,202,203,203,203,203,203,203,203,204,204,204, | ||
576 | 204,204,204,204,204,205,205,205,205,205,205,205,205,206,206,206,206,206,206,206, | ||
577 | 206,207,207,207,207,207,207,207,207,208,208,208,208,208,208,208,208,209,209,209, | ||
578 | 209,209,209,209,209,210,210,210,210,210,210,210,210,211,211,211,211,211,211,211, | ||
579 | 211,212,212,212,212,212,212,212,212,213,213,213,213,213,213,213,213,214,214,214, | ||
580 | 214,214,214,214,214,215,215,215,215,215,215,215,215,216,216,216,216,216,216,216, | ||
581 | 216,217,217,217,217,217,217,217,217,218,218,218,218,218,218,218,218,219,219,219, | ||
582 | 219,219,219,219,219,220,220,220,220,220,220,220,220,221,221,221,221,221,221,221, | ||
583 | 221,222,222,222,222,222,222,222,222,223,223,223,223,223,223,223,223,224,224,224, | ||
584 | 224,224,224,224,224,225,225,225,225,225,225,225,225,226,226,226,226,226,226,226, | ||
585 | 226,227,227,227,227,227,227,227,227,228,228,228,228,228,228,228,228,229,229,229, | ||
586 | 229,229,229,229,229,229,230,230,230,230,230,230,230,230,231,231,231,231,231,231, | ||
587 | 231,231,232,232,232,232,232,232,232,232,233,233,233,233,233,233,233,233,234,234, | ||
588 | 234,234,234,234,234,234,234,235,235,235,235,235,235,235,235,236,236,236,236,236, | ||
589 | 236,236,236,237,237,237,237,237,237,237,237,238,238,238,238,238,238,238,238,238, | ||
590 | 239,239,239,239,239,239,239,239,240,240,240,240,240,240,240,240,241,241,241,241, | ||
591 | 241,241,241,241,242,242,242,242,242,242,242,242,242,243,243,243,243,243,243,243, | ||
592 | 243,244,244,244,244,244,244,244,244,245,245,245,245,245,245,245,245,245,246,246, | ||
593 | 246,246,246,246,246,246,247,247,247,247,247,247,247,247,248,248,248,248,248,248, | ||
594 | 248,248,248,249,249,249,249,249,249,249,249,250,250,250,250,250,250,250,250,250, | ||
595 | 251,251,251,251,251,251,251,251,252,252,252,252,252,252,252,252,253,253,253,253, | ||
596 | 253,253,253,253,253,254,254,254,254,254,254,254,254,255,255,255,255,255,255,255, | ||
597 | 255,255,256,256,256,256,256,256,256,256,257,257,257,257,257,257,257,257,257,258, | ||
598 | 258,258,258,258,258,258,258,259,259,259,259,259,259,259,259,259,260,260,260,260, | ||
599 | 260,260,260,260,261,261,261,261,261,261,261,261,261,262,262,262,262,262,262,262, | ||
600 | 262,263,263,263,263,263,263,263,263,263,264,264,264,264,264,264,264,264,265,265, | ||
601 | 265,265,265,265,265,265,265,266,266,266,266,266,266,266,266,267,267,267,267,267, | ||
602 | 267,267,267,267,268,268,268,268,268,268,268,268,268,269,269,269,269,269,269,269, | ||
603 | 269,270,270,270,270,270,270,270,270,270,271,271,271,271,271,271,271,271,271,272, | ||
604 | 272,272,272,272,272,272,272,273,273,273,273,273,273,273,273,273,274,274,274,274, | ||
605 | 274,274,274,274,275,275,275,275,275,275,275,275,275,276,276,276,276,276,276,276, | ||
606 | 276,276,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,279, | ||
607 | 279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,281,281,281, | ||
608 | 281,281,281,281,281,282,282,282,282,282,282,282,282,282,283,283,283,283,283,283, | ||
609 | 283,283,283,284,284,284,284,284,284,284,284,284,285,285,285,285,285,285,285,285, | ||
610 | 286,286,286,286,286,286,286,286,286,287,287,287,287,287,287,287,287,287,288,288, | ||
611 | 288,288,288,288,288,288,288,289,289,289,289,289,289,289,289,289,290,290,290,290, | ||
612 | 290,290,290,290,291,291,291,291,291,291,291,291,291,292,292,292,292,292,292,292, | ||
613 | 292,292,293,293,293,293,293,293,293,293,293,294,294,294,294,294,294,294,294,294, | ||
614 | 295,295,295,295,295,295,295,295,295,296,296,296,296,296,296,296,296,296,297,297, | ||
615 | 297,297,297,297,297,297,297,298,298,298,298,298,298,298,298,299,299,299,299,299, | ||
616 | 299,299,299,299,300,300,300,300,300,300,300,300,300,301,301,301,301,301,301,301, | ||
617 | 301,301,302,302,302,302,302,302,302,302,302,303,303,303,303,303,303,303,303,303, | ||
618 | 304,304,304,304,304,304,304,304,304,305,305,305,305,305,305,305,305,305,306,306, | ||
619 | 306,306,306,306,306,306,306,307,307,307,307,307,307,307,307,307,308,308,308,308, | ||
620 | 308,308,308,308,308,309,309,309,309,309,309,309,309,309,310,310,310,310,310,310, | ||
621 | 310,310,310,311,311,311,311,311,311,311,311,311,312,312,312,312,312,312,312,312, | ||
622 | 312,313,313,313,313,313,313,313,313,313,314,314,314,314,314,314,314,314,314,315, | ||
623 | 315,315,315,315,315,315,315,315,316,316,316,316,316,316,316,316,316,317,317,317, | ||
624 | 317,317,317,317,317,317,318,318,318,318,318,318,318,318,318,318,319,319,319,319, | ||
625 | 319,319,319,319,319,320,320,320,320,320,320,320,320,320,321,321,321,321,321,321, | ||
626 | 321,321,321,322,322,322,322,322,322,322,322,322,323,323,323,323,323,323,323,323, | ||
627 | 323,324,324,324,324,324,324,324,324,324,325,325,325,325,325,325,325,325,325,325, | ||
628 | 326,326,326,326,326,326,326,326,326,327,327,327,327,327,327,327,327,327,328,328, | ||
629 | 328,328,328,328,328,328,328,329,329,329,329,329,329,329,329,329,330,330,330,330, | ||
630 | 330,330,330,330,330,330,331,331,331,331,331,331,331,331,331,332,332,332,332,332, | ||
631 | 332,332,332,332,333,333,333,333,333,333,333,333,333,334,334,334,334,334,334,334, | ||
632 | 334,334,335,335,335,335,335,335,335,335,335,335,336,336,336,336,336,336,336,336, | ||
633 | 336,337,337,337,337,337,337,337,337,337,338,338,338,338,338,338,338,338,338,338, | ||
634 | 339,339,339,339,339,339,339,339,339,340,340,340,340,340,340,340,340,340,341,341, | ||
635 | 341,341,341,341,341,341,341,341,342,342,342,342,342,342,342,342,342,343,343,343, | ||
636 | 343,343,343,343,343,343,344,344,344,344,344,344,344,344,344,344,345,345,345,345, | ||
637 | 345,345,345,345,345,346,346,346,346,346,346,346,346,346,347,347,347,347,347,347, | ||
638 | 347,347,347,347,348,348,348,348,348,348,348,348,348,349,349,349,349,349,349,349, | ||
639 | 349,349,350,350,350,350,350,350,350,350,350,350,351,351,351,351,351,351,351,351, | ||
640 | 351,352,352,352,352,352,352,352,352,352,352,353,353,353,353,353,353,353,353,353, | ||
641 | 354,354,354,354,354,354,354,354,354,355,355,355,355,355,355,355,355,355,355,356, | ||
642 | 356,356,356,356,356,356,356,356,357,357,357,357,357,357,357,357,357,357,358,358, | ||
643 | 358,358,358,358,358,358,358,359,359,359,359,359,359,359,359,359,359,360,360,360, | ||
644 | 360,360,360,360,360,360,361,361,361,361,361,361,361,361,361,361,362,362,362,362, | ||
645 | 362,362,362,362,362,363,363,363,363,363,363,363,363,363,363,364,364,364,364,364, | ||
646 | 364,364,364,364,365,365,365,365,365,365,365,365,365,365,366,366,366,366,366,366, | ||
647 | 366,366,366,367,367,367,367,367,367,367,367,367,367,368,368,368,368,368,368,368, | ||
648 | 368,368,369,369,369,369,369,369,369,369,369,369,370,370,370,370,370,370,370,370, | ||
649 | 370,370,371,371,371,371,371,371,371,371,371,372,372,372,372,372,372,372,372,372, | ||
650 | 372,373,373,373,373,373,373,373,373,373,374,374,374,374,374,374,374,374,374,374, | ||
651 | 375,375,375,375,375,375,375,375,375,375,376,376,376,376,376,376,376,376,376,377, | ||
652 | 377,377,377,377,377,377,377,377,377,378,378,378,378,378,378,378,378,378,379,379, | ||
653 | 379,379,379,379,379,379,379,379,380,380,380,380,380,380,380,380,380,380,381,381, | ||
654 | 381,381,381,381,381,381,381,382,382,382,382,382,382,382,382,382,382,383,383,383, | ||
655 | 383,383,383,383,383,383,383,384,384,384,384,384,384,384,384,384,385,385,385,385, | ||
656 | 385,385,385,385,385,385,386,386,386,386,386,386,386,386,386,386,387,387,387,387, | ||
657 | 387,387,387,387,387,387,388,388,388,388,388,388,388,388,388,389,389,389,389,389, | ||
658 | 389,389,389,389,389,390,390,390,390,390,390,390,390,390,390,391,391,391,391,391, | ||
659 | 391,391,391,391,391,392,392,392,392,392,392,392,392,392,393,393,393,393,393,393, | ||
660 | 393,393,393,393,394,394,394,394,394,394,394,394,394,394,395,395,395,395,395,395, | ||
661 | 395,395,395,395,396,396,396,396,396,396,396,396,396,397,397,397,397,397,397,397, | ||
662 | 397,397,397,398,398,398,398,398,398,398,398,398,398,399,399,399,399,399,399,399, | ||
663 | 399,399,399,400,400,400,400,400,400,400,400,400,400,401,401,401,401,401,401,401, | ||
664 | 401,401,402,402,402,402,402,402,402,402,402,402,403,403,403,403,403,403,403,403, | ||
665 | 403,403,404,404,404,404,404,404,404,404,404,404,405,405,405,405,405,405,405,405, | ||
666 | 405,405,406,406,406,406,406,406,406,406,406,406,407,407,407,407,407,407,407,407, | ||
667 | 407,407,408,408,408,408,408,408,408,408,408,408,409,409,409,409,409,409,409,409, | ||
668 | 409,410,410,410,410,410,410,410,410,410,410,411,411,411,411,411,411,411,411,411, | ||
669 | 411,412,412,412,412,412,412,412,412,412,412,413,413,413,413,413,413,413,413,413, | ||
670 | 413,414,414,414,414,414,414,414,414,414,414,415,415,415,415,415,415,415,415,415, | ||
671 | 415,416,416,416,416,416,416,416,416,416,416,417,417,417,417,417,417,417,417,417, | ||
672 | 417,418,418,418,418,418,418,418,418,418,418,419,419,419,419,419,419,419,419,419, | ||
673 | 419,420,420,420,420,420,420,420,420,420,420,421,421,421,421,421,421,421,421,421, | ||
674 | 421,422,422,422,422,422,422,422,422,422,422,423,423,423,423,423,423,423,423,423, | ||
675 | 423,424,424,424,424,424,424,424,424,424,424,425,425,425,425,425,425,425,425,425, | ||
676 | 425,426,426,426,426,426,426,426,426,426,426,427,427,427,427,427,427,427,427,427, | ||
677 | 427,428,428,428,428,428,428,428,428,428,428,429,429,429,429,429,429,429,429,429, | ||
678 | 429,430,430,430,430,430,430,430,430,430,430,431,431,431,431,431,431,431,431,431, | ||
679 | 431,432,432,432,432,432,432,432,432,432,432,433,433,433,433,433,433,433,433,433, | ||
680 | 433,434,434,434,434,434,434,434,434,434,434,435,435,435,435,435,435,435,435,435, | ||
681 | 435,435,436,436,436,436,436,436,436,436,436,436,437,437,437,437,437,437,437,437, | ||
682 | 437,437,438,438,438,438,438,438,438,438,438,438,439,439,439,439,439,439,439,439, | ||
683 | 439,439,440,440,440,440,440,440,440,440,440,440,441,441,441,441,441,441,441,441, | ||
684 | 441,441,442,442,442,442,442,442,442,442,442,442,443,443,443,443,443,443,443,443, | ||
685 | 443,443,443,444,444,444,444,444,444,444,444,444,444,445,445,445,445,445,445,445, | ||
686 | 445,445,445,446,446,446,446,446,446,446,446,446,446,447,447,447,447,447,447,447, | ||
687 | 447,447,447,448,448,448,448,448,448,448,448,448,448,448,449,449,449,449,449,449, | ||
688 | 449,449,449,449,450,450,450,450,450,450,450,450,450,450,451,451,451,451,451,451, | ||
689 | 451,451,451,451,452,452,452,452,452,452,452,452,452,452,453,453,453,453,453,453, | ||
690 | 453,453,453,453,453,454,454,454,454,454,454,454,454,454,454,455,455,455,455,455, | ||
691 | 455,455,455,455,455,456,456,456,456,456,456,456,456,456,456,457,457,457,457,457, | ||
692 | 457,457,457,457,457,457,458,458,458,458,458,458,458,458,458,458,459,459,459,459, | ||
693 | 459,459,459,459,459,459,460,460,460,460,460,460,460,460,460,460,460,461,461,461, | ||
694 | 461,461,461,461,461,461,461,462,462,462,462,462,462,462,462,462,462,463,463,463, | ||
695 | 463,463,463,463,463,463,463,463,464,464,464,464,464,464,464,464,464,464,465,465, | ||
696 | 465,465,465,465,465,465,465,465,466,466,466,466,466,466,466,466,466,466,466,467, | ||
697 | 467,467,467,467,467,467,467,467,467,468,468,468,468,468,468,468,468,468,468,469, | ||
698 | 469,469,469,469,469,469,469,469,469,469,470,470,470,470,470,470,470,470,470,470, | ||
699 | 471,471,471,471,471,471,471,471,471,471,472,472,472,472,472,472,472,472,472,472, | ||
700 | 472,473,473,473,473,473,473,473,473,473,473,474,474,474,474,474,474,474,474,474, | ||
701 | 474,475,475,475,475,475,475,475,475,475,475,475,476,476,476,476,476,476,476,476, | ||
702 | 476,476,477,477,477,477,477,477,477,477,477,477,477,478,478,478,478,478,478,478, | ||
703 | 478,478,478,479,479,479,479,479,479,479,479,479,479,479,480,480,480,480,480,480, | ||
704 | 480,480,480,480,481,481,481,481,481,481,481,481,481,481,482,482,482,482,482,482, | ||
705 | 482,482,482,482,482,483,483,483,483,483,483,483,483,483,483,484,484,484,484,484, | ||
706 | 484,484,484,484,484,484,485,485,485,485,485,485,485,485,485,485,486,486,486,486, | ||
707 | 486,486,486,486,486,486,486,487,487,487,487,487,487,487,487,487,487,488,488,488, | ||
708 | 488,488,488,488,488,488,488,488,489,489,489,489,489,489,489,489,489,489,490,490, | ||
709 | 490,490,490,490,490,490,490,490,490,491,491,491,491,491,491,491,491,491,491,492, | ||
710 | 492,492,492,492,492,492,492,492,492,492,493,493,493,493,493,493,493,493,493,493, | ||
711 | 494,494,494,494,494,494,494,494,494,494,494,495,495,495,495,495,495,495,495,495, | ||
712 | 495,496,496,496,496,496,496,496,496,496,496,496,497,497,497,497,497,497,497,497, | ||
713 | 497,497,497,498,498,498,498,498,498,498,498,498,498,499,499,499,499,499,499,499, | ||
714 | 499,499,499,499,500,500,500,500,500,500,500,500,500,500,501,501,501,501,501,501, | ||
715 | 501,501,501,501,501,502,502,502,502,502,502,502,502,502,502,503,503,503,503,503, | ||
716 | 503,503,503,503,503,503,504,504,504,504,504,504,504,504,504,504,504,505,505,505, | ||
717 | 505,505,505,505,505,505,505,506,506,506,506,506,506,506,506,506,506,506,507,507, | ||
718 | 507,507,507,507,507,507,507,507,507,508,508,508,508,508,508,508,508,508,508,509, | ||
719 | 509,509,509,509,509,509,509,509,509,509,510,510,510,510,510,510,510,510,510,510, | ||
720 | 510,511,511,511,511,511,511,511,511,511,511,512,512,512,512,512 }; | ||
721 | |||
722 | static const int order[32] = | ||
723 | { 0, 1, 16, 17, 8, 9, 24, 25, 4, 5, 20, 21, 12, 13, 28, 29, | ||
724 | 2, 3, 18, 19,10,11, 26, 27, 6, 7, 22, 23, 14, 15, 30, 31 }; | ||
725 | |||
726 | static const int bitr_index[2][15] = | ||
727 | { {0, 8,16,24,32,40,48,56, 64, 80, 96,112,128,144,160}, | ||
728 | {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320} }; | ||
729 | |||
730 | static const int num_bands[3][15] = | ||
731 | { {0,10,10,10,10,12,14,16, 20, 22, 24, 26, 28, 30, 32}, | ||
732 | {0,10,10,10,10,10,12,14, 18, 24, 26, 28, 30, 32, 32}, | ||
733 | {0,10,12,14,18,24,26,28, 30, 32, 32, 32, 32, 32, 32} }; | ||
734 | |||
735 | static const int cx_const[9] = | ||
736 | { 16135, 10531, 5604, 15396, -2845,-12551, 14189, 8192, 16384 }; | ||
737 | |||
738 | static const int ca_const[8] = | ||
739 | {-16859,-15458,-10269, -5961, -3099, -1342, -465, -121 }; | ||
740 | |||
741 | static const int cs_const[8] = | ||
742 | { 28098, 28893, 31117, 32221, 32621, 32740, 32765, 32768 }; | ||
743 | |||
744 | static const short enwindow_const[15*27+24] = | ||
745 | { 0, 65, 593, 1766, 22228, 2115, 611, 62, | ||
746 | 8, 119, 1419, 10564,-11659,-1635,-154, -9, | ||
747 | -8, -119,-1419,-10564, 11659, 1635, 154, 9, 464, 100, 91, | ||
748 | 0, 69, 604, 1635, 23148, 2363, 643, 62, | ||
749 | 7, 107, 1368, 10449,-12733,-1818,-180,-11, | ||
750 | -7, -107,-1368,-10449, 12733, 1818, 180, 11, 420, 200, 164, | ||
751 | 0, 72, 608, 1465, 23979, 2600, 671, 63, | ||
752 | 7, 94, 1305, 10265,-13818,-2004,-207,-12, | ||
753 | -7, -94,-1305,-10265, 13818, 2004, 207, 12, 380, 297, 220, | ||
754 | 0, 76, 606, 1256, 24718, 2825, 693, 63, | ||
755 | 6, 81, 1232, 10016,-14908,-2192,-236,-14, | ||
756 | -6, -81,-1232,-10016, 14908, 2192, 236, 14, 342, 392, 262, | ||
757 | 0, 78, 597, 1007, 25359, 3033, 712, 63, | ||
758 | 6, 68, 1150, 9706,-15995,-2380,-267,-15, | ||
759 | -6, -68,-1150, -9706, 15995, 2380, 267, 15, 307, 483, 289, | ||
760 | 0, 80, 580, 719, 25901, 3224, 726, 62, | ||
761 | 6, 54, 1060, 9343,-17072,-2565,-299,-17, | ||
762 | -6, -54,-1060, -9343, 17072, 2565, 299, 17, 274, 569, 304, | ||
763 | -1, 82, 555, 391, 26339, 3395, 735, 61, | ||
764 | 5, 40, 963, 8930,-18131,-2747,-332,-19, | ||
765 | -5, -40, -963, -8930, 18131, 2747, 332, 19, 242, 650, 307, | ||
766 | -1, 83, 523, 26, 26672, 3545, 740, 60, | ||
767 | 5, 27, 861, 8474,-19164,-2923,-366,-21, | ||
768 | -5, -27, -861, -8474, 19164, 2923, 366, 21, 212, 724, 300, | ||
769 | -1, 83, 482, -376, 26900, 3672, 739, 58, | ||
770 | 4, 14, 756, 7981,-20163,-3092,-401,-24, | ||
771 | -4, -14, -756, -7981, 20163, 3092, 401, 24, 183, 792, 283, | ||
772 | -1, 82, 433, -812, 27022, 3776, 735, 56, | ||
773 | 4, 1, 648, 7456,-21122,-3250,-435,-26, | ||
774 | -4, -1, -648, -7456, 21122, 3250, 435, 26, 155, 851, 258, | ||
775 | -1, 81, 376, -1281, 27038, 3855, 726, 54, | ||
776 | 3, -11, 539, 6907,-22032,-3397,-470,-28, | ||
777 | -3, 11, -539, -6907, 22032, 3397, 470, 28, 128, 903, 226, | ||
778 | -1, 78, 312, -1778, 26951, 3910, 713, 52, | ||
779 | 3, -22, 430, 6338,-22887,-3530,-503,-31, | ||
780 | -3, 22, -430, -6338, 22887, 3530, 503, 31, 102, 946, 188, | ||
781 | -2, 75, 239, -2302, 26761, 3941, 696, 49, | ||
782 | 3, -33, 322, 5757,-23678,-3648,-537,-34, | ||
783 | -3, 33, -322, -5757, 23678, 3648, 537, 34, 76, 980, 145, | ||
784 | -2, 70, 160, -2848, 26472, 3948, 676, 47, | ||
785 | 3, -42, 217, 5167,-24399,-3749,-568,-36, | ||
786 | -3, 42, -217, -5167, 24399, 3749, 568, 36, 50, 1004, 99, | ||
787 | -2, 65, 74, -3412, 26087, 3931, 653, 44, | ||
788 | 2, -51, 115, 4577,-25045,-3830,-599,-39, | ||
789 | -2, 51, -115, -4577, 25045, 3830, 599, 39, 25, 1019, 50, | ||
790 | |||
791 | 25610,3891,627,42,-3990,-18,58,-2, | ||
792 | 21226,-21226,10604,-10604,1860,-1860,1458,-1458,576,-576,130,-130,60,-60,8,-8 | ||
407 | }; | 793 | }; |
408 | 794 | ||
409 | const uint8 int2idx_const[4096] = { | 795 | static const int win_const[18][4] = { |
410 | 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, | 796 | { -3072, -134, -146, 3352 }, |
411 | 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, | 797 | { -2747, -362, -471, 3579 }, |
412 | 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, | 798 | { -2387, -529, -831, 3747 }, |
413 | 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, | 799 | { -2004, -632,-1214, 3850 }, |
414 | 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, | 800 | { -1609, -666,-1609, 3884 }, |
415 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, | 801 | { -1214, -632,-2004, 3850 }, |
416 | 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, | 802 | { -831, -529,-2387, 3747 }, |
417 | 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, | 803 | { -471, -362,-2747, 3579 }, |
418 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, | 804 | { -146, -134,-3072, 3352 }, |
419 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, | 805 | { 134,-3072,-3352, -146 }, |
420 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, | 806 | { 362,-2747,-3579, -471 }, |
421 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31, | 807 | { 529,-2387,-3747, -831 }, |
422 | 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, | 808 | { 632,-2004,-3850,-1214 }, |
423 | 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, | 809 | { 666,-1609,-3884,-1609 }, |
424 | 34, 34, 34, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, | 810 | { 632,-1214,-3850,-2004 }, |
425 | 36, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38, | 811 | { 529, -831,-3747,-2387 }, |
426 | 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 40, 40, 40, 40, | 812 | { 362, -471,-3579,-2747 }, |
427 | 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, | 813 | { 134, -146,-3352,-3072 } }; |
428 | 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | 814 | |
429 | 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 45, 45, | 815 | |
430 | 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 47, 47, | 816 | static char* wav_filename; |
431 | 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, | 817 | static int mp3file, wavfile, wav_size, frames; |
432 | 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 50, 50, | 818 | static uint32 enc_buffer[16384]; /* storage for 65536 Bytes */ |
433 | 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, | 819 | static int enc_chunk = 0; /* encode chunk counter */ |
434 | 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, | 820 | static int enc_size; |
435 | 53, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, | 821 | static config_t cfg; |
436 | 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, | ||
437 | 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 58, 58, 58, 58, 58, 58, 58, | ||
438 | 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, | ||
439 | 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 61, 61, 61, 61, 61, 61, 61, 61, | ||
440 | 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, | ||
441 | 62, 62, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, | ||
442 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, | ||
443 | 65, 65, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, 67, 67, 67, | ||
444 | 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, 68, | ||
445 | 68, 68, 68, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 70, 70, 70, 70, 70, 70, 70, | ||
446 | 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, | ||
447 | 71, 71, 71, 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73, | ||
448 | 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, | ||
449 | 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 76, 76, | ||
450 | 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, | ||
451 | 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, | ||
452 | 78, 78, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80, | ||
453 | 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, | ||
454 | 81, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 82, 83, | ||
455 | 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, | ||
456 | 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, | ||
457 | 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 87, 87, 87, 87, | ||
458 | 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, | ||
459 | 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, | ||
460 | 89, 89, 89, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, | ||
461 | 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, | ||
462 | 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, | ||
463 | 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95, | ||
464 | 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, | ||
465 | 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, | ||
466 | 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 99, 99, | ||
467 | 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,100,100,100,100,100,100,100,100,100,100, | ||
468 | 100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101, | ||
469 | 101,101,101,101,101,101,101,101,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102, | ||
470 | 102,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,103,104,104,104,104,104,104, | ||
471 | 104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,104,105,105,105,105,105,105,105,105,105,105,105,105,105, | ||
472 | 105,105,105,105,105,105,105,105,105,105,105,105,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106,106, | ||
473 | 106,106,106,106,106,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,107,108, | ||
474 | 108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,108,109,109,109,109,109,109,109,109, | ||
475 | 109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,109,110,110,110,110,110,110,110,110,110,110,110,110,110,110, | ||
476 | 110,110,110,110,110,110,110,110,110,110,110,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111, | ||
477 | 111,111,111,111,111,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,112,113, | ||
478 | 113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,113,114,114,114,114,114,114,114,114, | ||
479 | 114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,114,115,115,115,115,115,115,115,115,115,115,115,115,115,115, | ||
480 | 115,115,115,115,115,115,115,115,115,115,115,115,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116,116, | ||
481 | 116,116,116,116,116,116,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117,117, | ||
482 | 118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,118,119,119,119,119,119,119, | ||
483 | 119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,119,120,120,120,120,120,120,120,120,120,120,120, | ||
484 | 120,120,120,120,120,120,120,120,120,120,120,120,120,120,120,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121,121, | ||
485 | 121,121,121,121,121,121,121,121,121,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122,122, | ||
486 | 122,122,122,122,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,123,124,124, | ||
487 | 124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,125,125,125,125,125,125,125, | ||
488 | 125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,126,126,126,126,126,126,126,126,126,126,126,126, | ||
489 | 126,126,126,126,126,126,126,126,126,126,126,126,126,126,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127, | ||
490 | 127,127,127,127,127,127,127,127,127,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, | ||
491 | 128,128,128,128,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,130, | ||
492 | 130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,131,131,131,131,131,131, | ||
493 | 131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,132,132,132,132,132,132,132,132,132,132,132, | ||
494 | 132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133, | ||
495 | 133,133,133,133,133,133,133,133,133,133,133,133,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134, | ||
496 | 134,134,134,134,134,134,134,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135, | ||
497 | 135,135,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,137,137, | ||
498 | 137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,138,138,138,138,138,138,138, | ||
499 | 138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,139,139,139,139,139,139,139,139,139,139,139, | ||
500 | 139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140, | ||
501 | 140,140,140,140,140,140,140,140,140,140,140,140,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141, | ||
502 | 141,141,141,141,141,141,141,141,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142, | ||
503 | 142,142,142,142,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,144, | ||
504 | 144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,144,145,145,145,145,145, | ||
505 | 145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,145,146,146,146,146,146,146,146,146,146, | ||
506 | 146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,146,147,147,147,147,147,147,147,147,147,147,147,147, | ||
507 | 147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,147,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148,148, | ||
508 | 148,148,148,148,148,148,148,148,148,148,148,148,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149,149, | ||
509 | 149,149,149,149,149,149,149,149,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150, | ||
510 | 150,150,150,150,150,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151,151, | ||
511 | 151,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,152,153,153,153, | ||
512 | 153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,153,154,154,154,154,154,154, | ||
513 | 154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,154,155,155,155,155,155,155,155,155,155, | ||
514 | 155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,155,156,156,156,156,156,156,156,156,156,156,156,156,156, | ||
515 | 156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,156,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157,157, | ||
516 | 157,157,157,157,157,157,157,157,157,157,157,157,157,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158,158, | ||
517 | 158,158,158,158,158,158,158,158,158,158,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159,159, | ||
518 | 159,159,159,159,159,159,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160, | ||
519 | 160,160,160,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161, | ||
520 | 162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,163,163,163, | ||
521 | 163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,164,164,164,164,164, | ||
522 | 164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,165,165,165,165,165,165,165,165, | ||
523 | 165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,166,166,166,166,166,166,166,166,166,166,166, | ||
524 | 166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,167,167,167,167,167,167,167,167,167,167,167,167,167,167, | ||
525 | 167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168, | ||
526 | 168,168,168,168,168,168,168,168,168,168,168,168,168,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169, | ||
527 | 169,169,169,169,169,169,169,169,169,169,169,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170, | ||
528 | 170,170,170,170,170,170,170,170,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171, | ||
529 | 171,171,171,171,171,171,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172, | ||
530 | 172,172,172,172,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173, | ||
531 | 173,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,175, | ||
532 | 175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,176,176,176, | ||
533 | 176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,177,177,177,177,177, | ||
534 | 177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,178,178,178,178,178,178,178, | ||
535 | 178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,179,179,179,179,179,179,179,179,179, | ||
536 | 179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,180,180,180,180,180,180,180,180,180,180,180, | ||
537 | 180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,181,181,181,181,181,181,181,181,181,181,181,181,181}; | ||
538 | |||
539 | short *x_int[2]; | ||
540 | short buffer[2*samp_per_frame]; | ||
541 | config_t config; | ||
542 | PFILE mp3file; | ||
543 | int mp3_hdl, file_hdl; | ||
544 | int frames_processed; | ||
545 | long wav_size; | ||
546 | uint32 enc_buffer[16384]; /* storage for 64 CodedData buffers */ | ||
547 | int enc_chunk = 0; /* chunk (each 256Byte) counter */ | ||
548 | 822 | ||
549 | /* forward declarations */ | 823 | /* forward declarations */ |
550 | void encodeSideInfo( side_info_t si[2][2] ); | 824 | int HuffmanCode( short *ix, int *xr, uint32 begin, uint32 end, int table); |
551 | void Huffmancodebits( enct8 *ix, int *xr, side_info_t *gi ); | 825 | int HuffmanCod1( short *ix, int *xr, uint32 begin, uint32 end, int table); |
552 | int HuffmanCode(int table_select, enct8 *ix, int *xr); | ||
553 | int HuffmanCount1(unsigned tbl, enct8 *ix, int *xr ); | ||
554 | int new_choose_table( enct8 ix[samp_per_frame2], unsigned int begin, unsigned int end ); | ||
555 | void putbits(uint32 val, uint32 nbit); | 826 | void putbits(uint32 val, uint32 nbit); |
556 | int count_bit(enct8 ix[samp_per_frame2], unsigned int start, unsigned int end, unsigned int table ); | 827 | int find_best_2( short *ix, uint32 start, uint32 end, const uint32 *table, |
557 | int bigv_bitcount(enct8 ix[samp_per_frame2], side_info_t *gi); | 828 | uint32 len, int *bits); |
558 | void bigv_tab_select( enct8 ix[samp_per_frame2], side_info_t *cod_info ); | 829 | int find_best_3( short *ix, uint32 start, uint32 end, const uint32 *table, |
559 | void subdivide(side_info_t *cod_info); | 830 | uint32 len, int *bits); |
560 | void mdct_sub_int(int sb_sample[2][3][18][SBLIMIT], int (*mdct_freq)[2][samp_per_frame2]); | 831 | int count_bit1 ( short *ix, uint32 start, uint32 end, int *bits ); |
561 | void filter_subband(short *buffer, int s[SBLIMIT], int k); | 832 | int count_bigv ( short *ix, uint32 start, uint32 end, int table0, int table1, |
562 | int read_samples(short *sample_buffer, int frame_size); | 833 | int *bits); |
563 | 834 | ||
564 | 835 | ||
565 | bool checkString(int *file, char *string) | 836 | bool checkString(int fd, char *string) |
566 | { | 837 | { |
567 | char temp[4]; | 838 | char temp[4]; |
568 | 839 | ||
569 | rb->read(*file, temp, 4); | 840 | rb->read(fd, temp, 4); |
570 | 841 | ||
571 | return (*(long*)temp == *(long*)string) ? 1 : 0; | 842 | return (*(long*)temp == *(long*)string) ? 1 : 0; |
572 | } | 843 | } |
573 | 844 | ||
574 | int Read16BitsLowHigh(PFILE fp) | 845 | int Read16BitsLowHigh(int fd) |
575 | { | 846 | { |
576 | char first, second; | 847 | char first, second; |
577 | 848 | ||
578 | rb->read(*fp, &first, 1); | 849 | rb->read(fd, &first, 1); |
579 | rb->read(*fp, &second, 1); | 850 | rb->read(fd, &second, 1); |
580 | 851 | ||
581 | return ((int)second << 8) | (first & 0xff); | 852 | return ((int)second << 8) | (first & 0xff); |
582 | } | 853 | } |
583 | 854 | ||
584 | 855 | ||
585 | int Read32BitsLowHigh(PFILE fp) | 856 | int Read32BitsLowHigh(int fd) |
586 | { | 857 | { |
587 | int first, second, result; | 858 | int first = 0xffff & Read16BitsLowHigh(fd); |
588 | 859 | int second = 0xffff & Read16BitsLowHigh(fd); | |
589 | first = 0xffff & Read16BitsLowHigh(fp); | ||
590 | second = 0xffff & Read16BitsLowHigh(fp); | ||
591 | result = (second << 16) + first; | ||
592 | |||
593 | return result; | ||
594 | } | ||
595 | 860 | ||
596 | void wave_close(void) | 861 | return (second << 16) + first; |
597 | { | ||
598 | rb->close(*config.wave.file); | ||
599 | } | ||
600 | |||
601 | PFILE fread_open(char *filename) | ||
602 | { | ||
603 | file_hdl = rb->open(filename, O_RDONLY); | ||
604 | return file_hdl < 0 ? NULL : &file_hdl; | ||
605 | } | 862 | } |
606 | 863 | ||
607 | int wave_open(void) | 864 | int wave_open(void) |
608 | { | 865 | { |
609 | unsigned short wFormatTag; | 866 | unsigned short wFormatTag; |
610 | unsigned long dAvgBytesPerSec; | 867 | unsigned long dAvgBytesPerSec; |
611 | unsigned short wBlockAlign; | 868 | unsigned short wBlockAlign; |
612 | long header_size; | 869 | unsigned short bits_per_samp; |
613 | 870 | long header_size; | |
614 | if((config.wave.file = fread_open(config.infile)) == NULL) | ||
615 | return -1; | ||
616 | |||
617 | if(!checkString(config.wave.file,"RIFF")) return -2; | ||
618 | Read32BitsLowHigh(config.wave.file); /* complete wave chunk size */ | ||
619 | if(!checkString(config.wave.file,"WAVE")) return -3; | ||
620 | if(!checkString(config.wave.file,"fmt ")) return -4; | ||
621 | |||
622 | header_size = Read32BitsLowHigh(config.wave.file); /* chunk size */ | ||
623 | wFormatTag = Read16BitsLowHigh(config.wave.file); | ||
624 | |||
625 | config.wave.channels = Read16BitsLowHigh(config.wave.file); | ||
626 | config.wave.samplerate = Read32BitsLowHigh(config.wave.file); | ||
627 | dAvgBytesPerSec = Read32BitsLowHigh(config.wave.file); | ||
628 | wBlockAlign = Read16BitsLowHigh(config.wave.file); | ||
629 | config.wave.bits = Read16BitsLowHigh(config.wave.file); | ||
630 | |||
631 | if(wFormatTag != 0x0001) return -5; | ||
632 | if(config.wave.bits != 16) return -6; | ||
633 | if(config.wave.channels > 2) return -7; | ||
634 | if(!checkString(config.wave.file,"data")) return -8; | ||
635 | 871 | ||
636 | header_size = 0x28; | 872 | if((wavfile = rb->open(wav_filename, O_RDONLY)) < 0) |
637 | wav_size = rb->filesize(*config.wave.file); | 873 | return -1; |
638 | rb->lseek(*config.wave.file, header_size, SEEK_SET); | 874 | |
639 | 875 | if(!checkString(wavfile,"RIFF")) return -2; | |
640 | config.wave.total_samples = (wav_size-header_size) / (2*config.wave.channels); | 876 | Read32BitsLowHigh(wavfile); /* complete wave chunk size */ |
641 | config.wave.length = config.wave.total_samples / config.wave.samplerate; | 877 | if(!checkString(wavfile,"WAVE")) return -3; |
642 | 878 | if(!checkString(wavfile,"fmt ")) return -4; | |
643 | return 0; | 879 | |
880 | header_size = Read32BitsLowHigh(wavfile); /* chunk size */ | ||
881 | wFormatTag = Read16BitsLowHigh(wavfile); | ||
882 | |||
883 | cfg.channels = Read16BitsLowHigh(wavfile); | ||
884 | cfg.samplerate = Read32BitsLowHigh(wavfile); | ||
885 | dAvgBytesPerSec = Read32BitsLowHigh(wavfile); | ||
886 | wBlockAlign = Read16BitsLowHigh(wavfile); | ||
887 | bits_per_samp = Read16BitsLowHigh(wavfile); | ||
888 | |||
889 | if(wFormatTag != 0x0001) return -5; | ||
890 | if(bits_per_samp != 16) return -6; | ||
891 | if(cfg.channels > 2) return -7; | ||
892 | if(!checkString(wavfile,"data")) return -8; | ||
893 | |||
894 | header_size = 0x28; | ||
895 | wav_size = rb->filesize(wavfile); | ||
896 | rb->lseek(wavfile, header_size, SEEK_SET); | ||
897 | |||
898 | return 0; | ||
644 | } | 899 | } |
645 | 900 | ||
646 | int read_samples(short *sample_buffer, int frame_size) | 901 | int read_samples(uint32 *buffer, int num_samples) |
647 | { | 902 | { |
648 | int samples = rb->read(*config.wave.file, sample_buffer, sizeof(short) * frame_size) / sizeof(short); | 903 | int s, samples = rb->read(wavfile, buffer, 4 * num_samples) / 4; |
649 | /* Pad last sample with zeros */ | 904 | /* Pad last sample with zeros */ |
650 | if((samples < frame_size) && (samples > 0)) | 905 | for(s=samples; s<num_samples; s++) |
651 | while(samples < frame_size) | 906 | buffer[s] = 0; |
652 | sample_buffer[samples++] = 0; | ||
653 | 907 | ||
654 | return samples; | 908 | return samples; |
655 | } | 909 | } |
656 | 910 | ||
657 | inline uint32 myswap32(uint32 val) | 911 | inline uint32 myswap32(uint32 val) |
658 | { | 912 | { |
659 | const uint8* src = (const uint8*)&val; | 913 | const uint8* v = (const uint8*)&val; |
660 | |||
661 | return (uint32)src[3] | ((uint32)src[2] << 8) | ((uint32)src[1] << 16) | ((uint32)src[0] << 24); | ||
662 | } | ||
663 | |||
664 | void putbits(uint32 val, uint32 nbit) | ||
665 | { | ||
666 | int new_bitpos = CodedData.bitpos + nbit; | ||
667 | int i, ptrpos = CodedData.bitpos >> 5; | ||
668 | |||
669 | val = val & (0xffffffff >> (32 - nbit)); | ||
670 | |||
671 | /* data fit in one uint32 */ | ||
672 | if(((new_bitpos - 1) >> 5) == ptrpos) | ||
673 | CodedData.bbuf[ptrpos] |= val << ((32 - new_bitpos) & 31); | ||
674 | else | ||
675 | { | ||
676 | CodedData.bbuf[ptrpos ] |= val >> ((new_bitpos - 32) & 31); | ||
677 | CodedData.bbuf[ptrpos+1] |= val << ((32 - new_bitpos) & 31); | ||
678 | } | ||
679 | |||
680 | CodedData.bitpos = new_bitpos; | ||
681 | |||
682 | /* copy iram mp3 buffer to sdram/file */ | ||
683 | if(new_bitpos >= 256 * 32) | ||
684 | { | ||
685 | if(config.byte_order != order_bigEndian) | ||
686 | for(i=0; i<256; i++) | ||
687 | CodedData.bbuf[i] = myswap32(CodedData.bbuf[i]); | ||
688 | |||
689 | if(enc_chunk >= 64) /* sdram encoder buffer full? */ | ||
690 | { | ||
691 | rb->write(*mp3file, enc_buffer, 16384*sizeof(uint32)); | ||
692 | enc_chunk = 0; | ||
693 | } | ||
694 | |||
695 | /* copy iram buffer to sdram */ | ||
696 | memcpy(enc_buffer + enc_chunk*256, CodedData.bbuf, 256*sizeof(uint32)); | ||
697 | enc_chunk++; | ||
698 | |||
699 | CodedData.bbuf[0] = CodedData.bbuf[256]; | ||
700 | memset(CodedData.bbuf+1, 0, 256*sizeof(uint32)); | ||
701 | CodedData.bitpos &=31; | ||
702 | } | ||
703 | } | ||
704 | |||
705 | /* open the device to write the bit stream into it */ | ||
706 | void open_bitstream(char *bs_filenam) /* name of the bit stream file */ | ||
707 | { | ||
708 | mp3file = (mp3_hdl=rb->open(bs_filenam, O_WRONLY|O_CREAT|O_TRUNC)) < 0 ? NULL : &mp3_hdl; | ||
709 | } | ||
710 | |||
711 | /* This is called after a frame of audio has been quantized and coded. | ||
712 | It will write the encoded audio to the bitstream. Note that from a | ||
713 | layer3 encoder's perspective the bit stream is primarily a series | ||
714 | of main_data() blocks, with header and side information inserted at | ||
715 | the proper locations to maintain framing. See Figure A.7 in the IS */ | ||
716 | void format_bitstream( enct8 enc[2][2][samp_per_frame2], side_info_t side[2][2], int (*xr)[2][samp_per_frame2] ) | ||
717 | { | ||
718 | int gr, ch; | ||
719 | 914 | ||
720 | encodeSideInfo( side ); | 915 | return ((uint32)v[0]<<24) | ((uint32)v[1]<<16) | ((uint32)v[2]<<8) | v[3]; |
721 | |||
722 | for(gr=0; gr<2; gr++) | ||
723 | for(ch=0; ch<config.wave.channels; ch++) | ||
724 | Huffmancodebits( &enc[gr][ch][0], &xr[gr][ch][0], &side[gr][ch] ); | ||
725 | } | 916 | } |
726 | 917 | ||
727 | void encodeSideInfo( side_info_t si[2][2] ) | 918 | void encodeSideInfo( side_info_t si[2][2] ) |
728 | { | 919 | { |
729 | int gr, ch, header; | 920 | int gr, ch, header; |
921 | uint32 cc=0, sz=0; | ||
730 | 922 | ||
731 | header = 0xfff00000; | 923 | header = 0xfff00000; |
732 | header |= config.mpeg.type << 19; | 924 | header |= cfg.mpg.type << 19; /* mp3 type: 1 */ |
733 | header |= 1 /*config.mpeg.layr*/ << 17; | 925 | header |= 1 << 17; /* mp3 layer: 1 */ |
734 | header |= !config.mpeg.crc << 16; | 926 | header |= 1 << 16; /* mp3 crc: 0 */ |
735 | header |= config.mpeg.bitrate_index << 12; | 927 | header |= cfg.mpg.bitr_id << 12; |
736 | header |= config.mpeg.samplerate_index << 10; | 928 | header |= cfg.mpg.smpl_id << 10; |
737 | header |= config.mpeg.padding << 9; | 929 | header |= cfg.mpg.padding << 9; |
738 | header |= config.mpeg.ext << 8; | 930 | header |= cfg.mpg.mode << 6; |
739 | header |= config.mpeg.mode << 6; | 931 | header |= 1 << 2; /* mp3 original: 1 */ |
740 | header |= config.mpeg.mode_ext << 4; | ||
741 | header |= config.mpeg.copyright << 3; | ||
742 | header |= config.mpeg.original << 2; | ||
743 | header |= config.mpeg.emph << 0; | ||
744 | |||
745 | putbits( header, 32 ); | 932 | putbits( header, 32 ); |
746 | putbits( 0, config.wave.channels == 2 ? 20 : 18 ); | ||
747 | 933 | ||
748 | for(gr=0; gr<2; gr++) | 934 | if(cfg.mpg.type) |
749 | for(ch=0; ch<config.wave.channels; ch++) | 935 | { /* MPEG1 */ |
936 | if(cfg.channels == 2) { putlong( 0, 20); } | ||
937 | else { putlong( 0, 18); } | ||
938 | |||
939 | for(gr=0; gr<cfg.granules; gr++) | ||
940 | for(ch=0; ch<cfg.channels; ch++) | ||
941 | { | ||
942 | side_info_t *gi = &si[gr][ch]; | ||
943 | |||
944 | putlong( gi->part2_3_length, 12 ); | ||
945 | putlong( gi->address3>>1, 9 ); | ||
946 | putlong( gi->global_gain, 8 ); | ||
947 | putlong( gi->table_select[0], 10 ); | ||
948 | putlong( gi->table_select[1], 5 ); | ||
949 | putlong( gi->table_select[2], 5 ); | ||
950 | putlong( gi->region_0_1, 7 ); | ||
951 | putlong( gi->table_select[3], 3 ); | ||
952 | } | ||
953 | } | ||
954 | else | ||
955 | { /* MPEG2 */ | ||
956 | if(cfg.channels == 2) { putlong( 0, 10); } | ||
957 | else { putlong( 0, 9); } | ||
958 | |||
959 | for(ch=0; ch<cfg.channels; ch++) | ||
750 | { | 960 | { |
751 | side_info_t *gi = &si[gr][ch]; | 961 | side_info_t *gi = &si[0][ch]; |
752 | 962 | ||
753 | putbits( gi->part2_3_length, 12 ); | 963 | putlong( gi->part2_3_length, 12); |
754 | putbits( gi->big_values, 9 ); | 964 | putlong( gi->address3>>1, 9); |
755 | putbits( gi->global_gain, 8 ); | 965 | putlong( gi->global_gain, 8); |
756 | putbits( gi->table_select[0], 10 ); | 966 | putlong( gi->table_select[0], 15); |
757 | putbits( gi->table_select[1], 5 ); | 967 | putlong( gi->table_select[1], 5); |
758 | putbits( gi->table_select[2], 5 ); | 968 | putlong( gi->table_select[2], 5); |
759 | putbits( gi->region0_count, 4 ); | 969 | putlong( gi->region_0_1, 7); |
760 | putbits( gi->region1_count, 3 ); | 970 | putlong( gi->table_select[3], 2); |
761 | putbits( gi->table_select[3], 3 ); | ||
762 | } | 971 | } |
972 | } | ||
973 | /* flush remaining bits */ | ||
974 | putbits(cc, sz); | ||
763 | } | 975 | } |
764 | 976 | ||
765 | /* Note the discussion of huffmancodebits() on pages 28 and 29 of the IS, | 977 | /* Note the discussion of huffmancodebits() on pages 28 and 29 of the IS, |
766 | as well as the definitions of the side information on pages 26 and 27. */ | 978 | as well as the definitions of the side information on pages 26 and 27. */ |
767 | void Huffmancodebits( enct8 *ix, int *xr, side_info_t *gi ) | 979 | void Huffmancodebits( short *ix, int *xr, side_info_t *gi ) |
768 | { | 980 | { |
769 | int region1Start; | 981 | int region1 = gi->address1; |
770 | int region2Start; | 982 | int region2 = gi->address2; |
771 | int i, bigvalues, count1End; | 983 | int bigvals = gi->address3; |
772 | int stuffingBits; | 984 | int count1 = bigvals + (gi->count1 << 2); |
773 | int bitsWritten = 0; | 985 | int stuffBits = 0; |
774 | unsigned scalefac_index; | 986 | int bits = 0; |
775 | 987 | ||
776 | /* 1: Write the bigvalues */ | 988 | if(region1 > 0) |
777 | bigvalues = gi->big_values << 1; | 989 | bits += HuffmanCode(ix, xr, 0 , region1, gi->table_select[0]); |
778 | scalefac_index = gi->region0_count + 1; | 990 | |
779 | region1Start = scalefac_long[ scalefac_index ]; | 991 | if(region2 > region1) |
780 | scalefac_index += gi->region1_count + 1; | 992 | bits += HuffmanCode(ix, xr, region1, region2, gi->table_select[1]); |
781 | region2Start = scalefac_long[ scalefac_index ]; | 993 | |
782 | 994 | if(bigvals > region2) | |
783 | for(i=0; i<region1Start; i+=2) | 995 | bits += HuffmanCode(ix, xr, region2, bigvals, gi->table_select[2]); |
784 | bitsWritten += HuffmanCode(gi->table_select[0], ix+i, xr+i); | 996 | |
785 | 997 | if(count1 > bigvals) | |
786 | for( ; i<region2Start; i+=2) | 998 | bits += HuffmanCod1(ix, xr, bigvals, count1, gi->table_select[3]); |
787 | bitsWritten += HuffmanCode(gi->table_select[1], ix+i, xr+i); | 999 | |
788 | 1000 | if((stuffBits = gi->part2_3_length - bits) > 0) | |
789 | for( ; i<bigvalues; i+=2) | ||
790 | bitsWritten += HuffmanCode(gi->table_select[2], ix+i, xr+i); | ||
791 | |||
792 | /* 2: Write count1 area */ | ||
793 | count1End = bigvalues + (gi->count1 << 2); | ||
794 | for(i=bigvalues; i<count1End; i+=4) | ||
795 | bitsWritten += HuffmanCount1(gi->table_select[3], ix+i, xr+i); | ||
796 | |||
797 | if((stuffingBits = gi->part2_3_length - bitsWritten) != 0) | ||
798 | { | 1001 | { |
799 | int stuffingWords = stuffingBits / 32; | 1002 | int stuffWords = stuffBits >> 5; |
800 | int remainingBits = stuffingBits % 32; | 1003 | int remainBits = stuffBits & 31; |
801 | |||
802 | if( remainingBits ) | ||
803 | putbits( ~0, remainingBits ); | ||
804 | 1004 | ||
805 | /* Due to the nature of the Huffman code tables, we will pad with ones */ | 1005 | if( remainBits ) |
806 | while( stuffingWords-- ) | 1006 | putbits( ~0, remainBits ); |
807 | putbits( ~0, 32 ); | ||
808 | 1007 | ||
809 | bitsWritten += stuffingBits; | 1008 | while( stuffWords-- ) |
1009 | putbits( ~0, 32 ); /* Huffman code tables leed to padding ones */ | ||
810 | } | 1010 | } |
811 | } | 1011 | } |
812 | 1012 | ||
813 | int HuffmanCount1(unsigned tbl, enct8 *ix, int *xr) | 1013 | int HuffmanCod1( short *ix, int *xr, uint32 begin, uint32 end, int tbl) |
814 | { | 1014 | { |
815 | uint32 dat, p, s; | 1015 | uint32 cc=0, sz=0; |
816 | int len, v, w, x, y; | 1016 | uint32 i, d, p; |
817 | #define signv (xr[0] < 0 ? 1 : 0) | 1017 | int sumbit=0, s=0, l=0, v, w, x, y; |
818 | #define signw (xr[1] < 0 ? 1 : 0) | 1018 | #define sgnv (xr[i+0] < 0 ? 1 : 0) |
819 | #define signx (xr[2] < 0 ? 1 : 0) | 1019 | #define sgnw (xr[i+1] < 0 ? 1 : 0) |
820 | #define signy (xr[3] < 0 ? 1 : 0) | 1020 | #define sgnx (xr[i+2] < 0 ? 1 : 0) |
821 | 1021 | #define sgny (xr[i+3] < 0 ? 1 : 0) | |
822 | v = ix[0]; | 1022 | |
823 | w = ix[1]; | 1023 | for(i=begin; i<end; i+=4) |
824 | x = ix[2]; | ||
825 | y = ix[3]; | ||
826 | p = v + (w << 1) + (x << 2) + (y << 3); | ||
827 | |||
828 | switch(p) | ||
829 | { | 1024 | { |
830 | default: len = 0; s = 0; break; | 1025 | v = ix[i+0]; |
831 | case 1: len = 1; s = signv; break; | 1026 | w = ix[i+1]; |
832 | case 2: len = 1; s = signw; break; | 1027 | x = ix[i+2]; |
833 | case 3: len = 2; s = (signv << 1) + signw; break; | 1028 | y = ix[i+3]; |
834 | case 4: len = 1; s = signx; break; | 1029 | p = (v << 3) + (w << 2) + (x << 1) + y; |
835 | case 5: len = 2; s = (signv << 1) + signx; break; | 1030 | |
836 | case 6: len = 2; s = (signw << 1) + signx; break; | 1031 | switch(p) |
837 | case 7: len = 3; s = (signv << 2) + (signw << 1) + signx; break; | 1032 | { |
838 | case 8: len = 1; s = signy; break; | 1033 | case 0: l=0; s = 0; break; |
839 | case 9: len = 2; s = (signv << 1) + signy; break; | 1034 | case 1: l=1; s = sgnv; break; |
840 | case 10: len = 2; s = (signw << 1) + signy; break; | 1035 | case 2: l=1; s = sgnw; break; |
841 | case 11: len = 3; s = (signv << 2) + (signw << 1) + signy; break; | 1036 | case 3: l=2; s = (sgnv << 1) + sgnw; break; |
842 | case 12: len = 2; s = (signx << 1) + signy; break; | 1037 | case 4: l=1; s = sgnx; break; |
843 | case 13: len = 3; s = (signv << 2) + (signx << 1) + signy; break; | 1038 | case 5: l=2; s = (sgnv << 1) + sgnx; break; |
844 | case 14: len = 3; s = (signw << 2) + (signx << 1) + signy; break; | 1039 | case 6: l=2; s = (sgnw << 1) + sgnx; break; |
845 | case 15: len = 4; s = (signv << 3) + (signw << 2) + (signx << 1) + signy; break; | 1040 | case 7: l=3; s = (sgnv << 2) + (sgnw << 1) + sgnx; break; |
1041 | case 8: l=1; s = sgny; break; | ||
1042 | case 9: l=2; s = (sgnv << 1) + sgny; break; | ||
1043 | case 10: l=2; s = (sgnw << 1) + sgny; break; | ||
1044 | case 11: l=3; s = (sgnv << 2) + (sgnw << 1) + sgny; break; | ||
1045 | case 12: l=2; s = (sgnx << 1) + sgny; break; | ||
1046 | case 13: l=3; s = (sgnv << 2) + (sgnx << 1) + sgny; break; | ||
1047 | case 14: l=3; s = (sgnw << 2) + (sgnx << 1) + sgny; break; | ||
1048 | case 15: l=4; s = (sgnv << 3) + (sgnw << 2) + (sgnx << 1) + sgny; break; | ||
1049 | } | ||
1050 | |||
1051 | d = (ht_count[tbl][0][p] << l) + s; | ||
1052 | l = ht_count[tbl][1][p]; | ||
1053 | putlong( d, l ); | ||
1054 | sumbit += l; | ||
846 | } | 1055 | } |
847 | 1056 | ||
848 | dat = (ht_count1[tbl][0][p] << len) + s; | 1057 | /* flush remaining bits */ |
849 | len = ht_count1[tbl][1][p]; | 1058 | putbits(cc, sz); |
850 | putbits( dat, len ); | ||
851 | 1059 | ||
852 | return len; | 1060 | return sumbit; |
853 | } | 1061 | } |
854 | 1062 | ||
855 | /* Implements the pseudocode of page 98 of the IS */ | 1063 | /* Implements the pseudocode of page 98 of the IS */ |
856 | int HuffmanCode(int table_select, enct8 *ix, int *xr) | 1064 | int HuffmanCode( short *ix, int *xr, uint32 begin, uint32 end, int table) |
857 | { | 1065 | { |
858 | unsigned linbitsx, linbitsy, linbits, idx; | 1066 | uint32 cc=0, sz=0, code; |
859 | const struct huffcodetab *h; | 1067 | uint32 i, xl=0, yl=0, idx; |
860 | int x, y, bit; | 1068 | int x, y, bit, sumbit=0; |
861 | uint32 code; | 1069 | #define sign_x (xr[i+0] < 0 ? 1 : 0) |
862 | #define sign_x (xr[0] < 0 ? 1 : 0) | 1070 | #define sign_y (xr[i+1] < 0 ? 1 : 0) |
863 | #define sign_y (xr[1] < 0 ? 1 : 0) | ||
864 | |||
865 | if(table_select == 0) | ||
866 | return 0; | ||
867 | 1071 | ||
868 | x = ix[0]; | 1072 | if(table == 0) |
869 | y = ix[1]; | 1073 | return 0; |
870 | h = &ht[table_select]; | ||
871 | linbits = h->linbits; | ||
872 | linbitsx = linbitsy = 0; | ||
873 | 1074 | ||
874 | if( table_select > 15 ) | 1075 | if( table > 15 ) |
875 | { /* ESC-table is used */ | 1076 | { /* ESC-table is used */ |
876 | if(x > 14) { linbitsx = x - 15; x = 15; } | 1077 | uint32 linbits = ht_big[table-16].linbits; |
877 | if(y > 14) { linbitsy = y - 15; y = 15; } | 1078 | uint16 *hffcode = table < 24 ? t16HB : t24HB; |
1079 | uint8 *hlen = table < 24 ? t16l : t24l; | ||
878 | 1080 | ||
879 | idx = (x * h->ylen) + y; | 1081 | for(i=begin; i<end; i+=2) |
880 | code = h->table[idx]; | ||
881 | bit = h->hlen [idx]; | ||
882 | |||
883 | if(x) | ||
884 | { | 1082 | { |
885 | if(x > 14) | 1083 | x = ix[ i ]; |
1084 | y = ix[i+1]; | ||
1085 | |||
1086 | if(x > 14) { xl = x - 15; x = 15; } | ||
1087 | if(y > 14) { yl = y - 15; y = 15; } | ||
1088 | |||
1089 | idx = x * 16 + y; | ||
1090 | code = hffcode[idx]; | ||
1091 | bit = hlen [idx]; | ||
1092 | |||
1093 | if(x) | ||
886 | { | 1094 | { |
887 | code = (code << linbits) | linbitsx; | 1095 | if(x > 14) |
888 | bit += linbits; | 1096 | { |
889 | } | 1097 | code = (code << linbits) | xl; |
1098 | bit += linbits; | ||
1099 | } | ||
890 | 1100 | ||
891 | code = (code << 1) | sign_x; | 1101 | code = (code << 1) | sign_x; |
892 | bit += 1; | 1102 | bit += 1; |
893 | } | 1103 | } |
894 | 1104 | ||
895 | if(y) | 1105 | if(y) |
896 | { | ||
897 | if(y > 14) | ||
898 | { | 1106 | { |
899 | code = (code << linbits) | linbitsy; | 1107 | if(y > 14) |
900 | bit += linbits; | 1108 | { |
1109 | code = (code << linbits) | yl; | ||
1110 | bit += linbits; | ||
1111 | } | ||
1112 | |||
1113 | code = (code << 1) | sign_y; | ||
1114 | bit += 1; | ||
901 | } | 1115 | } |
902 | 1116 | ||
903 | code = (code << 1) | sign_y; | 1117 | putlong( code, bit ); |
904 | bit += 1; | 1118 | sumbit += bit; |
905 | } | 1119 | } |
906 | } | 1120 | } |
907 | else | 1121 | else |
908 | { /* No ESC-words */ | 1122 | { /* No ESC-words */ |
909 | idx = (x * h->ylen) + y; | 1123 | const struct huffcodetab *h = &ht[table]; |
910 | code = h->table[idx]; | ||
911 | bit = h->hlen [idx]; | ||
912 | 1124 | ||
913 | if(x) | 1125 | for(i=begin; i<end; i+=2) |
914 | { | 1126 | { |
915 | code = (code << 1) | sign_x; | 1127 | x = ix[i]; |
916 | bit += 1; | 1128 | y = ix[i+1]; |
917 | } | ||
918 | 1129 | ||
919 | if(y) | 1130 | idx = x * h->len + y; |
920 | { | 1131 | code = h->table[idx]; |
921 | code = (code << 1) | sign_y; | 1132 | bit = h->hlen [idx]; |
922 | bit += 1; | 1133 | |
1134 | if(x) | ||
1135 | { | ||
1136 | code = (code << 1) | sign_x; | ||
1137 | bit += 1; | ||
1138 | } | ||
1139 | |||
1140 | if(y) | ||
1141 | { | ||
1142 | code = (code << 1) | sign_y; | ||
1143 | bit += 1; | ||
1144 | } | ||
1145 | |||
1146 | putlong( code, bit ); | ||
1147 | sumbit += bit; | ||
923 | } | 1148 | } |
924 | } | 1149 | } |
925 | 1150 | ||
926 | putbits( code, bit ); | 1151 | /* flush remaining bits */ |
927 | 1152 | putbits(cc, sz); | |
928 | return bit; | 1153 | |
1154 | return sumbit; | ||
929 | } | 1155 | } |
930 | 1156 | ||
931 | /*************************************************************************/ | 1157 | void putbits(uint32 val, uint32 nbit) |
932 | /* Choose the Huffman table that will encode ix[begin..end] with */ | 1158 | { |
933 | /* the fewest bits. */ | 1159 | int new_bitpos = CodedData.bitpos + nbit; |
934 | /* Note: This code contains knowledge about the sizes and characteristics */ | 1160 | int ptrpos = CodedData.bitpos >> 5; |
935 | /* of the Huffman tables as defined in the IS (Table B.7), and will not work */ | 1161 | |
936 | /* with any arbitrary tables. */ | 1162 | val = val & (0xffffffff >> (32 - nbit)); |
937 | /*************************************************************************/ | 1163 | |
938 | int new_choose_table( enct8 ix[samp_per_frame2], uint32 begin, uint32 end ) | 1164 | /* data fit in one uint32 */ |
1165 | if(((new_bitpos - 1) >> 5) == ptrpos) | ||
1166 | CodedData.bbuf[ptrpos] |= val << ((32 - new_bitpos) & 31); | ||
1167 | else | ||
1168 | { | ||
1169 | CodedData.bbuf[ptrpos ] |= val >> ((new_bitpos - 32) & 31); | ||
1170 | CodedData.bbuf[ptrpos+1] |= val << ((32 - new_bitpos) & 31); | ||
1171 | } | ||
1172 | |||
1173 | CodedData.bitpos = new_bitpos; | ||
1174 | } | ||
1175 | |||
1176 | /***************************************************************************/ | ||
1177 | /* Choose the Huffman table that will encode ix[begin..end] with */ | ||
1178 | /* the fewest bits. */ | ||
1179 | /* Note: This code contains knowledge about the sizes and characteristic */ | ||
1180 | /* of the Huffman tables as defined in the IS (Table B.7), and will not */ | ||
1181 | /* work with any arbitrary tables. */ | ||
1182 | /***************************************************************************/ | ||
1183 | int choose_table( short *ix, uint32 begin, uint32 end, int *bits ) | ||
939 | { | 1184 | { |
940 | uint32 i; | 1185 | uint32 i; |
941 | int max, sum0, sum1, table0, table1; | 1186 | int max, table0, table1; |
942 | 1187 | ||
943 | for(i=begin,max=0; i<end; i++) | 1188 | for(i=begin,max=0; i<end; i++) |
944 | if(ix[i] > max) | 1189 | if(ix[i] > max) |
945 | max = ix[i]; | 1190 | max = ix[i]; |
946 | 1191 | ||
947 | if(!max) | 1192 | if(max < 16) |
948 | return 0; | ||
949 | |||
950 | table0 = 0; | ||
951 | table1 = 0; | ||
952 | |||
953 | if(max <= 15) | ||
954 | { | 1193 | { |
955 | /* try tables with no linbits */ | 1194 | /* tables without linbits */ |
956 | /* indx: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ | 1195 | /* indx: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ |
957 | /* xlen: 0, 2, 3, 3, 0, 4, 4, 6, 6, 6, 8, 8, 8, 16, 0, 16 */ | 1196 | /* len: 0, 2, 3, 3, 0, 4, 4, 6, 6, 6, 8, 8, 8, 16, 0, 16 */ |
958 | for(table0=0; table0<14; table0++) | 1197 | switch(max) |
959 | if(ht[table0].xlen > max) | ||
960 | break; | ||
961 | |||
962 | sum0 = count_bit(ix, begin, end, table0); | ||
963 | |||
964 | switch( table0 ) | ||
965 | { | 1198 | { |
966 | case 2: sum1 = count_bit( ix, begin, end, 3 ); | 1199 | case 0: return 0; |
967 | if(sum1 <= sum0) table0 = 3; break; | 1200 | case 1: return count_bit1(ix, begin, end, bits); |
968 | 1201 | case 2: return 2 + find_best_2(ix, begin, end, tab23, 3, bits); | |
969 | case 5: sum1 = count_bit( ix, begin, end, 6 ); | 1202 | case 3: return 5 + find_best_2(ix, begin, end, tab56, 4, bits); |
970 | if(sum1 <= sum0) table0 = 6; break; | 1203 | case 4: |
971 | 1204 | case 5: return 7 + find_best_3(ix, begin, end, tab789, 6, bits); | |
972 | case 7: sum1 = count_bit( ix, begin, end, 8 ); | 1205 | case 6: |
973 | if(sum1 <= sum0) { table0 = 8; sum0 = sum1; } | 1206 | case 7: return 10 + find_best_3(ix, begin, end, tabABC, 8, bits); |
974 | sum1 = count_bit( ix, begin, end, 9 ); | 1207 | default: return 13 + find_best_2(ix, begin, end, tab1315, 16, bits) * 2; |
975 | if(sum1 <= sum0) table0 = 9; break; | ||
976 | |||
977 | case 10: sum1 = count_bit( ix, begin, end, 11 ); | ||
978 | if(sum1 <= sum0) { table0 =11; sum0 = sum1; } | ||
979 | sum1 = count_bit( ix, begin, end, 12); | ||
980 | if(sum1 <= sum0) table0 = 12; break; | ||
981 | |||
982 | case 13: sum1 = count_bit( ix, begin, end, 15 ); | ||
983 | if(sum1 <= sum0) table0 = 15; break; | ||
984 | } | 1208 | } |
985 | } | 1209 | } |
986 | else | 1210 | else |
987 | { | 1211 | { |
988 | /* try tables with linbits */ | 1212 | /* tables with linbits */ |
989 | max -= 15; | 1213 | max -= 15; |
990 | 1214 | ||
991 | /* index : 15 16 17 18 19 20 21 22 23 */ | 1215 | for(table0=0; table0<8; table0++) |
992 | /* linmax: 0 1 3 7 15 63 255 1023 8191 */ | 1216 | if(ht_big[table0].linmax >= max) |
993 | for(table0=15; table0<24; table0++) | ||
994 | if(ht[table0].linmax >= max) | ||
995 | break; | 1217 | break; |
996 | 1218 | ||
997 | /* index : 24 25 26 27 28 29 30 31 */ | 1219 | for(table1=8; table1<16; table1++) |
998 | /* linmax: 15 31 63 127 255 511 2047 8191 */ | 1220 | if(ht_big[table1].linmax >= max) |
999 | for(table1=24; table1<32; table1++) | ||
1000 | if(ht[table1].linmax >= max) | ||
1001 | break; | 1221 | break; |
1002 | 1222 | ||
1003 | sum0 = count_bit(ix, begin, end, table0); | 1223 | return 16 + count_bigv(ix, begin, end, table0, table1, bits); |
1004 | sum1 = count_bit(ix, begin, end, table1); | ||
1005 | |||
1006 | if(sum1 < sum0) | ||
1007 | table0 = table1; | ||
1008 | } | 1224 | } |
1009 | return table0; | ||
1010 | } | 1225 | } |
1011 | 1226 | ||
1012 | /*************************************************************************/ | 1227 | int find_best_2(short *ix, uint32 start, uint32 end, const uint32 *table, |
1013 | /* Function: Count the number of bits necessary to code the subregion. */ | 1228 | uint32 len, int *bits) |
1014 | /*************************************************************************/ | ||
1015 | int count_bit(enct8 ix[samp_per_frame2], unsigned int start, unsigned int end, unsigned int table ) | ||
1016 | { | 1229 | { |
1017 | uint32 i; | 1230 | uint32 i, sum = 0; |
1018 | int sum; | ||
1019 | int x, y; | ||
1020 | unsigned linbits, ylen; | ||
1021 | const struct huffcodetab *h; | ||
1022 | |||
1023 | h = &ht[table]; | ||
1024 | sum = 0; | ||
1025 | ylen = h->ylen; | ||
1026 | |||
1027 | if(table > 15) | ||
1028 | { /* ESC-table is used */ | ||
1029 | linbits = h->linbits; | ||
1030 | for(i=start; i<end; i+=2) | ||
1031 | { | ||
1032 | x = ix[i]; | ||
1033 | y = ix[i+1]; | ||
1034 | 1231 | ||
1035 | if(x) | 1232 | for(i=start; i<end; i+=2) |
1036 | { | 1233 | sum += table[ix[i] * len + ix[i+1]]; |
1037 | if(x > 14) { x = 15; sum += linbits; } | ||
1038 | sum++; | ||
1039 | } | ||
1040 | 1234 | ||
1041 | if(y) | 1235 | if((sum & 0xffff) <= (sum >> 16)) |
1042 | { | 1236 | { |
1043 | if(y > 14) { y = 15; sum += linbits; } | 1237 | *bits = (sum & 0xffff); |
1044 | sum++; | 1238 | return 1; |
1045 | } | ||
1046 | |||
1047 | sum += h->hlen[(x * ylen) + y]; | ||
1048 | } | ||
1049 | } | 1239 | } |
1050 | else | 1240 | else |
1051 | { /* No ESC-words */ | 1241 | { |
1052 | for(i=start; i<end; i+=2) | 1242 | *bits = sum >> 16; |
1053 | { | 1243 | return 0; |
1054 | x = ix[i]; | 1244 | } |
1055 | y = ix[i+1]; | 1245 | } |
1056 | 1246 | ||
1057 | sum += h->hlen[(x * ylen) + y]; | 1247 | int find_best_3(short *ix, uint32 start, uint32 end, const uint32 *table, |
1248 | uint32 len, int *bits) | ||
1249 | { | ||
1250 | uint32 i, j, sum = 0; | ||
1251 | int sum1 = 0; | ||
1252 | int sum2 = 0; | ||
1253 | int sum3 = 0; | ||
1058 | 1254 | ||
1059 | if(x) sum++; | 1255 | /* avoid overflow in packed additions: 78*13 < 1024 */ |
1060 | if(y) sum++; | 1256 | for(i=start; i<end; ) |
1061 | } | 1257 | { |
1258 | j = i + 2*78 > end ? end : i + 2*78; | ||
1259 | |||
1260 | for(sum=0; i<j; i+=2) | ||
1261 | sum += table[ix[i] * len + ix[i+1]]; | ||
1262 | |||
1263 | sum1 += (sum >> 20); | ||
1264 | sum2 += (sum >> 10) & 0x3ff; | ||
1265 | sum3 += (sum >> 0) & 0x3ff; | ||
1062 | } | 1266 | } |
1063 | 1267 | ||
1064 | return sum; | 1268 | i = 0; |
1269 | if(sum1 > sum2) { sum1 = sum2; i = 1; } | ||
1270 | if(sum1 > sum3) { sum1 = sum3; i = 2; } | ||
1271 | |||
1272 | *bits = sum1; | ||
1273 | |||
1274 | return i; | ||
1065 | } | 1275 | } |
1066 | 1276 | ||
1067 | /*************************************************************************/ | 1277 | /*************************************************************************/ |
1068 | /* Function: Quantization of the vector xr ( -> ix) */ | 1278 | /* Function: Count the number of bits necessary to code the subregion. */ |
1069 | /*************************************************************************/ | 1279 | /*************************************************************************/ |
1070 | int quantize_int(int xr[samp_per_frame2], enct8 ix[samp_per_frame2], side_info_t *cod_info) | 1280 | int count_bit1(short *ix, uint32 start, uint32 end, int *bits ) |
1071 | { | 1281 | { |
1072 | int i; | 1282 | uint32 i, sum = 0; |
1073 | #if 0 | ||
1074 | long step; | ||
1075 | uint32 frac_pow[] = { 0, 12400, 27146, 44682 }; | ||
1076 | 1283 | ||
1077 | step = 1 << cod_info->quantizerStepSize / 4; | 1284 | for(i=start; i<end; i+=2) |
1078 | step += (step * frac_pow[cod_info->quantizerStepSize & 3] + 32768) >> 16; | 1285 | sum += t1l[4 + ix[i] * 2 + ix[i+1]]; |
1079 | 1286 | ||
1080 | for(i=samp_per_frame2; i--; ) | 1287 | *bits = sum; |
1081 | ix[i] = int2idx[4 * abs(xr[i]) / step]; | ||
1082 | 1288 | ||
1083 | return 1; | 1289 | return 1; /* this is table1 */ |
1084 | #else | 1290 | } |
1085 | uint32 max=0, val, step, frac_pow[] = { 0x40000, 0x35d14, 0x2d414,0x260e0 }; | ||
1086 | 1291 | ||
1087 | step = frac_pow[cod_info->quantizerStepSize & 3] >> cod_info->quantizerStepSize / 4; | 1292 | int count_bigv(short *ix, uint32 start, uint32 end, int table0, |
1293 | int table1, int *bits ) | ||
1294 | { | ||
1295 | uint32 i, sum0, sum1, sum=0, bigv=0, x, y; | ||
1088 | 1296 | ||
1089 | for(i=samp_per_frame2; i--; ) | 1297 | /* ESC-table is used */ |
1298 | for(i=start; i<end; i+=2) | ||
1090 | { | 1299 | { |
1091 | val = (((unsigned long)abs(xr[i]) * step + 32768) >> 16); | 1300 | x = ix[i]; |
1092 | max |= val; | 1301 | y = ix[i+1]; |
1093 | ix[i] = int2idx[val]; | 1302 | |
1303 | if(x > 14) { x = 15; bigv++; } | ||
1304 | if(y > 14) { y = 15; bigv++; } | ||
1305 | |||
1306 | sum += tab1624[x * 16 + y]; | ||
1307 | } | ||
1308 | |||
1309 | sum0 = (sum >> 16) + bigv * ht_big[table0].linbits; | ||
1310 | sum1 = (sum & 0xffff) + bigv * ht_big[table1].linbits; | ||
1311 | |||
1312 | if(sum0 <= sum1) | ||
1313 | { | ||
1314 | *bits = sum0; | ||
1315 | return table0; | ||
1316 | } | ||
1317 | else | ||
1318 | { | ||
1319 | *bits = sum1; | ||
1320 | return table1; | ||
1094 | } | 1321 | } |
1095 | return max < 4096 ? 1 : 0; | ||
1096 | #endif | ||
1097 | } | 1322 | } |
1098 | 1323 | ||
1099 | /*************************************************************************/ | 1324 | /*************************************************************************/ |
1100 | /* Function: Calculation of rzero, count1, big_values */ | 1325 | /* Function: Calculation of rzero, count1, address3 */ |
1101 | /* (Partitions ix into big values, quadruples and zeros). */ | 1326 | /* (Partitions ix into big values, quadruples and zeros). */ |
1102 | /*************************************************************************/ | 1327 | /*************************************************************************/ |
1103 | int calc_runlen( enct8 ix[samp_per_frame2], side_info_t *cod_info ) | 1328 | int calc_runlen( short *ix, side_info_t *si ) |
1104 | { | 1329 | { |
1105 | int p, i, sum0 = 0, sum1 = 0; | 1330 | int p, i, sum = 0; |
1106 | 1331 | ||
1107 | for(i=samp_per_frame2; i-=2; ) | 1332 | for(i=SAMPL2; i-=2; ) |
1108 | if(ix[i-1] | ix[i-2]) | 1333 | if(*(uint32*)&ix[i-2]) /* !!!! short *ix; !!!!! */ |
1109 | break; | 1334 | break; |
1110 | 1335 | ||
1111 | cod_info->count1 = 0; | 1336 | si->count1 = 0; |
1112 | 1337 | ||
1113 | for( ; i>3; i-=4) | 1338 | for( ; i>3; i-=4) |
1114 | { | 1339 | { |
@@ -1119,583 +1344,741 @@ int calc_runlen( enct8 ix[samp_per_frame2], side_info_t *cod_info ) | |||
1119 | 1344 | ||
1120 | if((v | w | x | y) <= 1) | 1345 | if((v | w | x | y) <= 1) |
1121 | { | 1346 | { |
1122 | p = (y) + (x<<1) + (w<<2) + (v<<3); | 1347 | p = (y<<3) + (x<<2) + (w<<1) + (v); |
1123 | 1348 | ||
1124 | sum0 += ht_count1[0][1][p]; /* add table0 hlength */ | 1349 | sum += tab01[p]; |
1125 | sum1 += ht_count1[1][1][p]; /* add table1 hlength */ | ||
1126 | 1350 | ||
1127 | cod_info->count1++; | 1351 | si->count1++; |
1128 | } | 1352 | } |
1129 | else break; | 1353 | else break; |
1130 | } | 1354 | } |
1131 | 1355 | ||
1132 | cod_info->big_values = i >> 1; | 1356 | si->address3 = i; |
1133 | 1357 | ||
1134 | if(sum0 < sum1) | 1358 | if((sum >> 16) < (sum & 0xffff)) |
1135 | { | 1359 | { |
1136 | cod_info->table_select[3] = 0; | 1360 | si->table_select[3] = 0; |
1137 | return sum0; | 1361 | return sum >> 16; |
1138 | } | 1362 | } |
1139 | else | 1363 | else |
1140 | { | 1364 | { |
1141 | cod_info->table_select[3] = 1; | 1365 | si->table_select[3] = 1; |
1142 | return sum1; | 1366 | return sum & 0xffff; |
1143 | } | 1367 | } |
1144 | } | 1368 | } |
1145 | 1369 | ||
1370 | |||
1146 | /*************************************************************************/ | 1371 | /*************************************************************************/ |
1147 | /* presumable subdivides the bigvalue region which will use separate Huffman tables */ | 1372 | /* Function: Quantization of the vector xr ( -> ix) */ |
1148 | /*************************************************************************/ | 1373 | /*************************************************************************/ |
1149 | void subdivide(side_info_t *cod_info) | 1374 | int quantize_int(int *xr, short *ix, side_info_t *si) |
1150 | { | 1375 | { |
1151 | int scfb_anz = 0; | 1376 | int i, s, frac_pow[] = { 0x10000, 0xd745, 0xb505, 0x9838 }; |
1152 | int bigvalues_region; | 1377 | |
1153 | int thiscount, index; | 1378 | s = frac_pow[si->quantStep & 3] >> si->quantStep / 4; |
1154 | 1379 | ||
1155 | if( !cod_info->big_values ) | 1380 | /* check for integer overflow */ |
1156 | { /* no big_values region */ | 1381 | if(((si->max_val + 256) >> 8) * s >= (1622 << 8)) |
1157 | cod_info->region0_count = 0; | 1382 | return 0; |
1158 | cod_info->region1_count = 0; | 1383 | |
1159 | } | 1384 | for(i=SAMPL2; i--; ) |
1160 | else | 1385 | ix[i] = int2idx[(abs(xr[i]) * s + 0x8000) >> 16]; |
1161 | { | 1386 | |
1162 | bigvalues_region = 2 * cod_info->big_values; | 1387 | return 1; |
1163 | |||
1164 | /* Calculate scfb_anz */ | ||
1165 | while( scalefac_long[scfb_anz] < bigvalues_region ) | ||
1166 | scfb_anz++; | ||
1167 | |||
1168 | cod_info->region0_count = subdv_table[scfb_anz].region0_count; | ||
1169 | thiscount = cod_info->region0_count; | ||
1170 | index = thiscount + 1; | ||
1171 | while(thiscount && (scalefac_long[index] > bigvalues_region)) | ||
1172 | { | ||
1173 | thiscount--; | ||
1174 | index--; | ||
1175 | } | ||
1176 | cod_info->region0_count = thiscount; | ||
1177 | cod_info->region1_count = subdv_table[scfb_anz].region1_count; | ||
1178 | index = cod_info->region0_count + cod_info->region1_count + 2; | ||
1179 | thiscount = cod_info->region1_count; | ||
1180 | while(thiscount && (scalefac_long[index] > bigvalues_region)) | ||
1181 | { | ||
1182 | thiscount--; | ||
1183 | index--; | ||
1184 | } | ||
1185 | cod_info->region1_count = thiscount; | ||
1186 | cod_info->address1 = scalefac_long[cod_info->region0_count+1]; | ||
1187 | cod_info->address2 = scalefac_long[cod_info->region0_count+cod_info->region1_count+2]; | ||
1188 | cod_info->address3 = bigvalues_region; | ||
1189 | } | ||
1190 | } | 1388 | } |
1191 | 1389 | ||
1192 | /*************************************************************************/ | 1390 | /*************************************************************************/ |
1193 | /* Function: Select huffman code tables for bigvalues regions */ | 1391 | /* subdivides the bigvalue region which will use separate Huffman tables */ |
1194 | /*************************************************************************/ | 1392 | /*************************************************************************/ |
1195 | void bigv_tab_select( enct8 ix[samp_per_frame2], side_info_t *cod_info ) | 1393 | void subdivide(side_info_t *si) |
1196 | { | 1394 | { |
1197 | cod_info->table_select[0] = 0; | 1395 | int scfb, count0, count1; |
1198 | cod_info->table_select[1] = 0; | ||
1199 | cod_info->table_select[2] = 0; | ||
1200 | 1396 | ||
1201 | if( cod_info->address1 > 0 ) | 1397 | if( !si->address3 ) |
1202 | cod_info->table_select[0] = new_choose_table(ix, 0 , cod_info->address1); | 1398 | { /* no bigvalue region */ |
1203 | 1399 | si->region_0_1 = 0; | |
1204 | if( cod_info->address2 > cod_info->address1 ) | 1400 | si->address1 = 0; |
1205 | cod_info->table_select[1] = new_choose_table(ix, cod_info->address1, cod_info->address2); | 1401 | si->address2 = 0; |
1206 | 1402 | } | |
1207 | if( cod_info->big_values<<1 > cod_info->address2 ) | 1403 | else |
1208 | cod_info->table_select[2] = new_choose_table(ix, cod_info->address2, cod_info->big_values<<1); | 1404 | { |
1405 | /* Calculate scale factor band index */ | ||
1406 | for(scfb=0; scalefac[scfb] < si->address3; ) | ||
1407 | scfb++; | ||
1408 | |||
1409 | count0 = subdv_table[scfb].region0_cnt; | ||
1410 | count1 = subdv_table[scfb].region1_cnt; | ||
1411 | |||
1412 | si->region_0_1 = (count0 << 3) | count1; | ||
1413 | si->address1 = scalefac[count0 + 1]; | ||
1414 | si->address2 = scalefac[count0 + 1 + count1 + 1]; | ||
1415 | } | ||
1209 | } | 1416 | } |
1210 | 1417 | ||
1211 | /*************************************************************************/ | 1418 | /*******************************************************************/ |
1212 | /* Function: Count the number of bits necessary to code the bigvalues region */ | 1419 | /* Count the number of bits necessary to code the bigvalues region */ |
1213 | /*************************************************************************/ | 1420 | /*******************************************************************/ |
1214 | int bigv_bitcount(enct8 ix[samp_per_frame2], side_info_t *gi) | 1421 | int bigv_bitcount(short *ix, side_info_t *gi) |
1215 | { | 1422 | { |
1216 | int bits = 0; | 1423 | int b1=0, b2=0, b3=0; |
1217 | uint32 table; | ||
1218 | 1424 | ||
1219 | if((table=gi->table_select[0])) /* region0 */ | 1425 | /* Select huffman code tables for bigvalues regions */ |
1220 | bits += count_bit(ix, 0 , gi->address1, table); | 1426 | gi->table_select[0] = 0; |
1427 | gi->table_select[1] = 0; | ||
1428 | gi->table_select[2] = 0; | ||
1221 | 1429 | ||
1222 | if((table=gi->table_select[1])) /* region1 */ | 1430 | if( gi->address1 > 0 ) /* region0 */ |
1223 | bits += count_bit(ix, gi->address1, gi->address2, table); | 1431 | gi->table_select[0] = choose_table(ix, 0 , gi->address1, &b1); |
1224 | 1432 | ||
1225 | if((table=gi->table_select[2])) /* region2 */ | 1433 | if( gi->address2 > gi->address1 ) /* region1 */ |
1226 | bits += count_bit(ix, gi->address2, gi->address3, table); | 1434 | gi->table_select[1] = choose_table(ix, gi->address1, gi->address2, &b2); |
1227 | 1435 | ||
1228 | return bits; | 1436 | if( gi->address3 > gi->address2 ) /* region2 */ |
1229 | } | 1437 | gi->table_select[2] = choose_table(ix, gi->address2, gi->address3, &b3); |
1230 | 1438 | ||
1231 | int quantcnt; | 1439 | return b1+b2+b3; |
1440 | } | ||
1232 | 1441 | ||
1233 | /* Speed up the outer_loop code which is called by iteration_loop. | 1442 | int quantize_and_count_bits(int *xr, short *ix, side_info_t *si) |
1234 | The outer_loop function precedes the call to the function inner_loop | ||
1235 | with a call to bin_search gain defined below, | ||
1236 | which returns a good starting quantizerStepSize. */ | ||
1237 | int quantize_and_count_bits(int xr[samp_per_frame2], enct8 ix[samp_per_frame2], side_info_t *cod_info) | ||
1238 | { | 1443 | { |
1239 | int bits = 10000; | 1444 | int bits = 10000; |
1240 | 1445 | ||
1241 | quantcnt++; | 1446 | if(quantize_int(xr, ix, si)) |
1242 | |||
1243 | if(quantize_int(xr, ix, cod_info)) | ||
1244 | { | 1447 | { |
1245 | bits = calc_runlen(ix, cod_info); /* rzero,count1,big_values*/ | 1448 | bits = calc_runlen(ix, si); /* rzero,count1,address3 */ |
1246 | subdivide(cod_info); /* bigvalues sfb division */ | 1449 | subdivide(si); /* bigvalues sfb division */ |
1247 | bigv_tab_select(ix,cod_info); /* codebook selection*/ | 1450 | bits += bigv_bitcount(ix,si); /* bit count */ |
1248 | bits += bigv_bitcount(ix,cod_info); /* bit count */ | ||
1249 | } | 1451 | } |
1250 | 1452 | ||
1251 | return bits; | 1453 | return bits; |
1252 | } | 1454 | } |
1253 | 1455 | ||
1254 | /******************************************************************************/ | 1456 | /***********************************************************************/ |
1255 | /* The code selects the best quantizerStepSize for a particular set of scalefacs */ | 1457 | /* The code selects the best quantStep for a particular set of scalefacs */ |
1256 | /******************************************************************************/ | 1458 | /***********************************************************************/ |
1257 | int inner_loop_int(int xr[2][2][samp_per_frame2], int max_bits, side_info_t *cod_info, int gr, int ch ) | 1459 | int inner_loop(int *xr, int max_bits, side_info_t *si) |
1258 | { | 1460 | { |
1259 | int *xrs; /* int[samp_per_frame2] *xr; */ | 1461 | int bits; |
1260 | enct8 *ix; /* int[samp_per_frame2] *ix; */ | ||
1261 | int bits; | ||
1262 | 1462 | ||
1263 | xrs = &xr[gr][ch][0]; | 1463 | while((bits=quantize_and_count_bits(xr, enc_data, si)) < max_bits-64) |
1264 | ix = enc_data[gr][ch]; | ||
1265 | |||
1266 | while((bits=quantize_and_count_bits(xrs, ix, cod_info)) < max_bits- 128) | ||
1267 | { | 1464 | { |
1268 | if(cod_info->quantizerStepSize == 0) | 1465 | if(si->quantStep == 0) |
1269 | break; | 1466 | break; |
1270 | 1467 | ||
1271 | if(cod_info->quantizerStepSize <= 2) | 1468 | if(si->quantStep <= 2) |
1272 | cod_info->quantizerStepSize = 0; | 1469 | si->quantStep = 0; |
1273 | else | 1470 | else |
1274 | cod_info->quantizerStepSize -= 2; | 1471 | si->quantStep -= 2; |
1275 | } | 1472 | } |
1276 | 1473 | ||
1277 | while(bits > max_bits) | 1474 | while(bits > max_bits) |
1278 | { | 1475 | { |
1279 | cod_info->quantizerStepSize++; | 1476 | si->quantStep++; |
1280 | bits = quantize_and_count_bits(xrs, ix, cod_info); | 1477 | bits = quantize_and_count_bits(xr, enc_data, si); |
1281 | } | 1478 | } |
1282 | 1479 | ||
1283 | return bits; | 1480 | return bits; |
1284 | } | 1481 | } |
1285 | 1482 | ||
1286 | /************************************************************************/ | 1483 | void iteration_loop(int *xr, side_info_t *si, int gr_cnt) |
1287 | /* iteration_loop() */ | ||
1288 | /************************************************************************/ | ||
1289 | void iteration_loop(int mdct_freq_org[2][2][samp_per_frame2], side_info_t cod_info[2][2], int mean_bits) | ||
1290 | { | 1484 | { |
1291 | int max_bits; | 1485 | int remain, tar_bits, max_bits = cfg.mean_bits; |
1292 | int ch, gr; | 1486 | |
1293 | int ResvSize = 0; /* Layer3 bit reservoir: Described in C.1.5.4.2.2 of the IS */ | 1487 | /* distribute reserved bits to remaining granules */ |
1294 | 1488 | tar_bits = max_bits + (cfg.ResvSize / gr_cnt & ~7); | |
1295 | for(gr=2; gr--; ) | 1489 | if(tar_bits > max_bits + max_bits/2) |
1490 | tar_bits = max_bits + max_bits/2; | ||
1491 | |||
1492 | si->part2_3_length = inner_loop(xr, tar_bits, si); | ||
1493 | si->global_gain = si->quantStep + 142 - si->additStep; | ||
1494 | |||
1495 | /* unused bits of the reservoir can be used for remaining granules */ | ||
1496 | cfg.ResvSize += max_bits - si->part2_3_length; | ||
1497 | |||
1498 | /* end: distribute the reserved bits to one or two granules */ | ||
1499 | if(gr_cnt == 1) | ||
1296 | { | 1500 | { |
1297 | for(ch=config.wave.channels; ch--; ) | 1501 | si->part2_3_length += cfg.ResvSize; |
1502 | /* mp3 format allows max 12bits for granule length */ | ||
1503 | if(si->part2_3_length > 4092) | ||
1298 | { | 1504 | { |
1299 | /* calculation of number of available bit( per granule ) */ | 1505 | remain = (si->part2_3_length - 4092 + 31) >> 5; |
1300 | max_bits = mean_bits / config.wave.channels; | 1506 | si->part2_3_length -= remain << 5; |
1301 | 1507 | si[-1].part2_3_length += remain << 5; | |
1302 | cod_info[gr][ch].big_values = 0; | 1508 | |
1303 | cod_info[gr][ch].count1 = 0; | 1509 | while(remain--) |
1304 | cod_info[gr][ch].table_select[0] = 0; | 1510 | putbits(~0, 32); |
1305 | cod_info[gr][ch].table_select[1] = 0; | ||
1306 | cod_info[gr][ch].table_select[2] = 0; | ||
1307 | cod_info[gr][ch].region0_count = 0; | ||
1308 | cod_info[gr][ch].region1_count = 0; | ||
1309 | cod_info[gr][ch].table_select[3] = 0; | ||
1310 | cod_info[gr][ch].part2_3_length = inner_loop_int(mdct_freq_org, max_bits, &cod_info[gr][ch], gr, ch); | ||
1311 | cod_info[gr][ch].global_gain = cod_info[gr][ch].quantizerStepSize + 210 - 0x3c; | ||
1312 | |||
1313 | /* Readjusts the size of the reservoir to reflect the granule's usage */ | ||
1314 | ResvSize += max_bits - cod_info[gr][ch].part2_3_length; | ||
1315 | } | 1511 | } |
1316 | } | 1512 | } |
1317 | |||
1318 | /* Makes sure that the reservoir size is within limits, possibly by adding stuffing | ||
1319 | bits. Note that stuffing bits are added by increasing a granule's part2_3_length */ | ||
1320 | cod_info[0][0].part2_3_length += ResvSize; | ||
1321 | } | 1513 | } |
1322 | 1514 | ||
1323 | /*-------------------------------------------------------------------*/ | ||
1324 | /* Function: Calculation of the MDCT */ | ||
1325 | /* In the case of long blocks ( block_type 0,1,3 ) there are */ | ||
1326 | /* 36 coefficents in the time domain and 18 in the frequency */ | ||
1327 | /* domain. */ | ||
1328 | /*-------------------------------------------------------------------*/ | ||
1329 | 1515 | ||
1330 | /* TODO: This MDCT implementation is very crude, and should be replaced by | 1516 | /* returns sum_j=0^31 a[j]*cos(PI*j*(k+1/2)/32), 0<=k<32 */ |
1331 | a completely different algorithm. */ | 1517 | void window_subband1(short *wk, int sb0[SBLIMIT], int sb1[SBLIMIT]) ICODE_ATTR; |
1332 | void mdct_int( int *in, int *out ) | 1518 | void window_subband1(short *wk, int sb0[SBLIMIT], int sb1[SBLIMIT]) |
1333 | { | 1519 | { |
1334 | int m, tmp=0; | 1520 | int k, i, u, v; |
1335 | 1521 | short *wp, *x1, *x2; | |
1336 | for(m=18; m--; ) | 1522 | |
1337 | { | ||
1338 | #ifdef CPU_COLDFIRE | 1523 | #ifdef CPU_COLDFIRE |
1339 | { int *wint = win_int[m]; | 1524 | int s0, s1, t0, t1; |
1340 | int *indat = in; | ||
1341 | 1525 | ||
1526 | for(k=0; k<18; k++, wk+=64, sb0+=SBLIMIT, sb1+=SBLIMIT) | ||
1527 | { | ||
1528 | wp = enwindow; | ||
1529 | x1 = wk; | ||
1530 | x2 = x1 - 124; | ||
1531 | |||
1532 | for(i=-15; i<0; i++) | ||
1533 | { | ||
1342 | asm volatile( | 1534 | asm volatile( |
1343 | "movem.l (%[indat]), %%d0-%%d7\n" | 1535 | "move.l (-224*4,%[x2]), %%d4\n" /* d4 = x2[-224] */ |
1344 | "move.l (%[wint])+, %%a5\n" | 1536 | "movem.l (%[wp]), %%d0-%%d3\n" /* load 8 values */ |
1345 | "mac.l %%d0, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1537 | "mac.w %%d0u, %%d4u, %%acc0\n" |
1346 | "mac.l %%d1, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1538 | "mac.w %%d0u, %%d4l, (-160*4,%[x2]), %%d4, %%acc1\n" |
1347 | "mac.l %%d2, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1539 | "mac.w %%d0l, %%d4u, %%acc0\n" |
1348 | "mac.l %%d3, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1540 | "mac.w %%d0l, %%d4l, ( -96*4,%[x2]), %%d4, %%acc1\n" |
1349 | "mac.l %%d4, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1541 | "mac.w %%d1u, %%d4u, %%acc0\n" |
1350 | "mac.l %%d5, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1542 | "mac.w %%d1u, %%d4l, ( -32*4,%[x2]), %%d4, %%acc1\n" |
1351 | "mac.l %%d6, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1543 | "mac.w %%d1l, %%d4u, %%acc0\n" |
1352 | "mac.l %%d7, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1544 | "mac.w %%d1l, %%d4l, ( 32*4,%[x2]), %%d4, %%acc1\n" |
1353 | "movem.l (32,%[indat]), %%d0-%%d7\n" | 1545 | "mac.w %%d2u, %%d4u, %%acc0\n" |
1354 | "mac.l %%d0, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1546 | "mac.w %%d2u, %%d4l, ( 96*4,%[x2]), %%d4, %%acc1\n" |
1355 | "mac.l %%d1, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1547 | "mac.w %%d2l, %%d4u, %%acc0\n" |
1356 | "mac.l %%d2, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1548 | "mac.w %%d2l, %%d4l, ( 160*4,%[x2]), %%d4, %%acc1\n" |
1357 | "mac.l %%d3, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1549 | "mac.w %%d3u, %%d4u, %%acc0\n" |
1358 | "mac.l %%d4, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1550 | "mac.w %%d3u, %%d4l, ( 224*4,%[x2]), %%d4, %%acc1\n" |
1359 | "mac.l %%d5, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1551 | "mac.w %%d3l, %%d4u, %%acc0\n" |
1360 | "mac.l %%d6, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1552 | "mac.w %%d3l, %%d4l, (-256*4,%[x1]), %%d4, %%acc1\n" |
1361 | "mac.l %%d7, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1553 | "movem.l (16,%[wp]), %%d0-%%d3\n" /* load 8 values */ |
1362 | "movem.l (64,%[indat]), %%d0-%%d7\n" | 1554 | "mac.w %%d0u, %%d4u, %%acc0\n" |
1363 | "mac.l %%d0, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1555 | "mac.w %%d0u, %%d4l, (-192*4,%[x1]), %%d4, %%acc1\n" |
1364 | "mac.l %%d1, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1556 | "mac.w %%d0l, %%d4u, %%acc0\n" |
1365 | "mac.l %%d2, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1557 | "mac.w %%d0l, %%d4l, (-128*4,%[x1]), %%d4, %%acc1\n" |
1366 | "mac.l %%d3, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1558 | "mac.w %%d1u, %%d4u, %%acc0\n" |
1367 | "mac.l %%d4, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1559 | "mac.w %%d1u, %%d4l, ( -64*4,%[x1]), %%d4, %%acc1\n" |
1368 | "mac.l %%d5, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1560 | "mac.w %%d1l, %%d4u, %%acc0\n" |
1369 | "mac.l %%d6, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1561 | "mac.w %%d1l, %%d4l, ( 0*4,%[x1]), %%d4, %%acc1\n" |
1370 | "mac.l %%d7, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1562 | "mac.w %%d2u, %%d4u, %%acc0\n" |
1371 | "movem.l (96,%[indat]), %%d0-%%d7\n" | 1563 | "mac.w %%d2u, %%d4l, ( 64*4,%[x1]), %%d4, %%acc1\n" |
1372 | "mac.l %%d0, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1564 | "mac.w %%d2l, %%d4u, %%acc0\n" |
1373 | "mac.l %%d1, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1565 | "mac.w %%d2l, %%d4l, ( 128*4,%[x1]), %%d4, %%acc1\n" |
1374 | "mac.l %%d2, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1566 | "mac.w %%d3u, %%d4u, %%acc0\n" |
1375 | "mac.l %%d3, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1567 | "mac.w %%d3u, %%d4l, ( 192*4,%[x1]), %%d4, %%acc1\n" |
1376 | "mac.l %%d4, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1568 | "mac.w %%d3l, %%d4u, %%acc0\n" |
1377 | "mac.l %%d5, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1569 | "mac.w %%d3l, %%d4l, ( 224*4,%[x1]), %%d4, %%acc1\n" |
1378 | "mac.l %%d6, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1570 | "movclr.l %%acc0, %%d0\n" |
1379 | "mac.l %%d7, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1571 | "move.l %%d0, %[s0]\n" |
1380 | "movem.l (128,%[indat]), %%d0-%%d3\n" | 1572 | "movclr.l %%acc1, %%d0\n" |
1381 | "mac.l %%d0, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1573 | "move.l %%d0, %[s1]\n" |
1382 | "mac.l %%d1, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1574 | |
1383 | "mac.l %%d2, %%a5, (%[wint])+, %%a5, %%acc0\n" | 1575 | "movem.l (%[wp]), %%d0-%%d3\n" /* load 8 values */ |
1384 | "mac.l %%d3, %%a5, %%acc0\n" | 1576 | "mac.w %%d0u, %%d4u, %%acc0\n" |
1385 | "movclr.l %%acc0, %[tmp]" | 1577 | "mac.w %%d0u, %%d4l, ( 160*4,%[x1]), %%d4, %%acc1\n" |
1386 | : [wint] "+a" (wint), [tmp] "+r" (tmp) : [indat] "a" (indat) | 1578 | "mac.w %%d0l, %%d4u, %%acc0\n" |
1387 | : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5"); | 1579 | "mac.w %%d0l, %%d4l, ( 96*4,%[x1]), %%d4, %%acc1\n" |
1580 | "mac.w %%d1u, %%d4u, %%acc0\n" | ||
1581 | "mac.w %%d1u, %%d4l, ( 32*4,%[x1]), %%d4, %%acc1\n" | ||
1582 | "mac.w %%d1l, %%d4u, %%acc0\n" | ||
1583 | "mac.w %%d1l, %%d4l, ( -32*4,%[x1]), %%d4, %%acc1\n" | ||
1584 | "mac.w %%d2u, %%d4u, %%acc0\n" | ||
1585 | "mac.w %%d2u, %%d4l, ( -96*4,%[x1]), %%d4, %%acc1\n" | ||
1586 | "mac.w %%d2l, %%d4u, %%acc0\n" | ||
1587 | "mac.w %%d2l, %%d4l, (-160*4,%[x1]), %%d4, %%acc1\n" | ||
1588 | "mac.w %%d3u, %%d4u, %%acc0\n" | ||
1589 | "mac.w %%d3u, %%d4l, (-224*4,%[x1]), %%d4, %%acc1\n" | ||
1590 | "mac.w %%d3l, %%d4u, %%acc0\n" | ||
1591 | "mac.w %%d3l, %%d4l, ( 256*4,%[x2]), %%d4, %%acc1\n" | ||
1592 | "movem.l (32,%[wp]), %%d0-%%d3\n" /* load 8 values */ | ||
1593 | "mac.w %%d0u, %%d4u, %%acc0\n" | ||
1594 | "mac.w %%d0u, %%d4l, ( 192*4,%[x2]), %%d4, %%acc1\n" | ||
1595 | "mac.w %%d0l, %%d4u, %%acc0\n" | ||
1596 | "mac.w %%d0l, %%d4l, ( 128*4,%[x2]), %%d4, %%acc1\n" | ||
1597 | "mac.w %%d1u, %%d4u, %%acc0\n" | ||
1598 | "mac.w %%d1u, %%d4l, ( 64*4,%[x2]), %%d4, %%acc1\n" | ||
1599 | "mac.w %%d1l, %%d4u, %%acc0\n" | ||
1600 | "mac.w %%d1l, %%d4l, ( 0*4,%[x2]), %%d4, %%acc1\n" | ||
1601 | "mac.w %%d2u, %%d4u, %%acc0\n" | ||
1602 | "mac.w %%d2u, %%d4l, ( -64*4,%[x2]), %%d4, %%acc1\n" | ||
1603 | "mac.w %%d2l, %%d4u, %%acc0\n" | ||
1604 | "mac.w %%d2l, %%d4l, (-128*4,%[x2]), %%d4, %%acc1\n" | ||
1605 | "mac.w %%d3u, %%d4u, %%acc0\n" | ||
1606 | "mac.w %%d3u, %%d4l, (-192*4,%[x2]), %%d4, %%acc1\n" | ||
1607 | "mac.w %%d3l, %%d4u, %%acc0\n" | ||
1608 | "mac.w %%d3l, %%d4l, %%acc1\n" | ||
1609 | "movclr.l %%acc0, %%d0\n" | ||
1610 | "move.l %%d0, %[t0]\n" | ||
1611 | "movclr.l %%acc1, %%d0\n" | ||
1612 | "move.l %%d0, %[t1]\n" | ||
1613 | |||
1614 | : [x1] "+a" (x1), [x2] "+a" (x2), [s0] "+m" (s0), [t0] "+m" (t0), | ||
1615 | [s1] "+m" (s1), [t1] "+m" (t1) | ||
1616 | : [wp] "a" (wp) : "d0", "d1", "d2", "d3", "d4"); | ||
1617 | |||
1618 | sb0[30+i*2] = shft4(t0) + shft13(s0) * wp[24]; | ||
1619 | sb0[31+i*2] = shft13(t0) * wp[25] - shft13(s0) * wp[26]; | ||
1620 | sb1[30+i*2] = shft4(t1) + shft13(s1) * wp[24]; | ||
1621 | sb1[31+i*2] = shft13(t1) * wp[25] - shft13(s1) * wp[26]; | ||
1622 | wp += 27; | ||
1623 | x1 -= 2; | ||
1624 | x2 += 2; | ||
1388 | } | 1625 | } |
1389 | #else | ||
1390 | int k; | ||
1391 | for(k=36,tmp=0; k--; ) | ||
1392 | tmp += in[k] * win_int[m][k]; | ||
1393 | #endif | ||
1394 | out[m] = (tmp + 16384) >> 15; | ||
1395 | } | ||
1396 | } | ||
1397 | 1626 | ||
1627 | asm volatile( | ||
1628 | "move.l ( -32*4,%[x1]), %%d4\n" /* d4 = x1[-32] */ | ||
1629 | "movem.l (%[wp]), %%d0-%%d3\n" /* load 8 values */ | ||
1630 | |||
1631 | "mac.w %%d0u, %%d4u, %%acc0\n" | ||
1632 | "mac.w %%d0u, %%d4l, ( -96*4,%[x1]), %%d4, %%acc1\n" | ||
1633 | "mac.w %%d0l, %%d4u, %%acc0\n" | ||
1634 | "mac.w %%d0l, %%d4l, (-160*4,%[x1]), %%d4, %%acc1\n" | ||
1635 | "mac.w %%d1u, %%d4u, %%acc0\n" | ||
1636 | "mac.w %%d1u, %%d4l, (-224*4,%[x1]), %%d4, %%acc1\n" | ||
1637 | "mac.w %%d1l, %%d4u, %%acc0\n" | ||
1638 | "mac.w %%d1l, %%d4l, ( 32*4,%[x1]), %%d4, %%acc1\n" | ||
1639 | "mac.w %%d2u, %%d4u, %%acc0\n" | ||
1640 | "mac.w %%d2u, %%d4l, ( 96*4,%[x1]), %%d4, %%acc1\n" | ||
1641 | "mac.w %%d2l, %%d4u, %%acc0\n" | ||
1642 | "mac.w %%d2l, %%d4l, ( 160*4,%[x1]), %%d4, %%acc1\n" | ||
1643 | "mac.w %%d3u, %%d4u, %%acc0\n" | ||
1644 | "mac.w %%d3u, %%d4l, ( 224*4,%[x1]), %%d4, %%acc1\n" | ||
1645 | "mac.w %%d3l, %%d4u, %%acc0\n" | ||
1646 | "mac.w %%d3l, %%d4l, ( -16*4,%[x1]), %%d4, %%acc1\n" | ||
1647 | "movclr.l %%acc0, %%d0\n" | ||
1648 | "move.l %%d0, %[s0]\n" | ||
1649 | "movclr.l %%acc1, %%d0\n" | ||
1650 | "move.l %%d0, %[s1]\n" | ||
1651 | |||
1652 | "movem.l (16,%[wp]), %%d0-%%d3\n" /* load 8 values */ | ||
1653 | "mac.w %%d0u, %%d4u, %%acc0\n" | ||
1654 | "mac.w %%d0u, %%d4l, ( -48*4,%[x1]), %%d4, %%acc1\n" | ||
1655 | "mac.w %%d1u, %%d4u, %%acc0\n" | ||
1656 | "mac.w %%d1u, %%d4l, ( 16*4,%[x1]), %%d4, %%acc1\n" | ||
1657 | "mac.w %%d1l, %%d4u, %%acc0\n" | ||
1658 | "mac.w %%d1l, %%d4l, ( -80*4,%[x1]), %%d4, %%acc1\n" | ||
1659 | "mac.w %%d2u, %%d4u, %%acc0\n" | ||
1660 | "mac.w %%d2u, %%d4l, ( 48*4,%[x1]), %%d4, %%acc1\n" | ||
1661 | "mac.w %%d2u, %%d4u, %%acc0\n" | ||
1662 | "mac.w %%d2u, %%d4l, (-112*4,%[x1]), %%d4, %%acc1\n" | ||
1663 | "mac.w %%d3u, %%d4u, %%acc0\n" | ||
1664 | "mac.w %%d3u, %%d4l, ( 80*4,%[x1]), %%d4, %%acc1\n" | ||
1665 | "mac.w %%d3l, %%d4u, %%acc0\n" | ||
1666 | "mac.w %%d3l, %%d4l, (-144*4,%[x1]), %%d4, %%acc1\n" | ||
1667 | "movem.l (32,%[wp]), %%d0-%%d3\n" /* load 8 values */ | ||
1668 | "mac.w %%d0u, %%d4u, %%acc0\n" | ||
1669 | "mac.w %%d0u, %%d4l, ( 112*4,%[x1]), %%d4, %%acc1\n" | ||
1670 | "mac.w %%d0u, %%d4u, %%acc0\n" | ||
1671 | "mac.w %%d0u, %%d4l, (-176*4,%[x1]), %%d4, %%acc1\n" | ||
1672 | "mac.w %%d1u, %%d4u, %%acc0\n" | ||
1673 | "mac.w %%d1u, %%d4l, ( 144*4,%[x1]), %%d4, %%acc1\n" | ||
1674 | "mac.w %%d1l, %%d4u, %%acc0\n" | ||
1675 | "mac.w %%d1l, %%d4l, (-208*4,%[x1]), %%d4, %%acc1\n" | ||
1676 | "mac.w %%d2u, %%d4u, %%acc0\n" | ||
1677 | "mac.w %%d2u, %%d4l, ( 176*4,%[x1]), %%d4, %%acc1\n" | ||
1678 | "mac.w %%d2u, %%d4u, %%acc0\n" | ||
1679 | "mac.w %%d2u, %%d4l, (-240*4,%[x1]), %%d4, %%acc1\n" | ||
1680 | "mac.w %%d3u, %%d4u, %%acc0\n" | ||
1681 | "mac.w %%d3u, %%d4l, ( 208*4,%[x1]), %%d4, %%acc1\n" | ||
1682 | "mac.w %%d3l, %%d4u, %%acc0\n" | ||
1683 | "mac.w %%d3l, %%d4l, %%acc1\n" | ||
1684 | "movclr.l %%acc0, %%d0\n" | ||
1685 | "move.l %%d0, %[t0]\n" | ||
1686 | "movclr.l %%acc1, %%d0\n" | ||
1687 | "move.l %%d0, %[t1]\n" | ||
1688 | |||
1689 | : [x1] "+a" (x1), [s0] "+m" (s0), [t0] "+m" (t0), | ||
1690 | [s1] "+m" (s1), [t1] "+m" (t1) | ||
1691 | : [wp] "a" (wp) : "d0", "d1", "d2", "d3", "d4"); | ||
1692 | |||
1693 | u = shft4(s0 - t0); | ||
1694 | v = shft4(s0 + t0); | ||
1695 | t0 = sb0[14]; | ||
1696 | s0 = sb0[15] - t0; | ||
1697 | |||
1698 | sb0[31] = v + t0; /* A0 */ | ||
1699 | sb0[30] = u + s0; /* A1 */ | ||
1700 | sb0[15] = u - s0; /* A2 */ | ||
1701 | sb0[14] = v - t0; /* A3 */ | ||
1702 | |||
1703 | u = shft4(s1 - t1); | ||
1704 | v = shft4(s1 + t1); | ||
1705 | t1 = sb1[14]; | ||
1706 | s1 = sb1[15] - t1; | ||
1707 | |||
1708 | sb1[31] = v + t1; /* A0 */ | ||
1709 | sb1[30] = u + s1; /* A1 */ | ||
1710 | sb1[15] = u - s1; /* A2 */ | ||
1711 | sb1[14] = v - t1; /* A3 */ | ||
1712 | } | ||
1713 | #else | ||
1714 | int ch, s, t, *a; | ||
1398 | 1715 | ||
1399 | void mdct_sub_int(int sb_sample[2][3][18][SBLIMIT], int (*mdct_freq)[2][samp_per_frame2]) | 1716 | for(ch=0; ch<cfg.channels; ch++) |
1400 | { | 1717 | { |
1401 | int (*mdct_enc)[2][32][18] = (int (*)[2][32][18]) mdct_freq; | 1718 | a = ch ? sb1 : sb0; |
1402 | int ch, gr, band, k, bu, bd; | 1719 | for(k=0; k<18; k++, wk+=64, a+=SBLIMIT) |
1403 | |||
1404 | for(gr=0; gr<2; gr++) | ||
1405 | for(ch=config.wave.channels; ch--; ) | ||
1406 | { | 1720 | { |
1407 | /* 576=4*16*9: Compensate for inversion in the analysis filter */ | 1721 | wp = enwindow; |
1408 | for(band=33; (band-=2)>0; ) | 1722 | x1 = wk; |
1409 | for(k=19; (k-=2)>0; ) | 1723 | x2 = x1 - 124; |
1410 | sb_sample[ch][gr+1][k][band] = -sb_sample[ch][gr+1][k][band]; | ||
1411 | 1724 | ||
1412 | /* 82944=4*32*648: Perform imdct of 18 previous subband samples + 18 current subband samples */ | 1725 | /* x1[-572] .... x1[448] = 1022 */ |
1413 | for(band=32; band--; ) | 1726 | /* 18*4*16*32 */ |
1727 | for(i=-15; i<0; i++) | ||
1414 | { | 1728 | { |
1415 | for(k=18; k--; ) | 1729 | s = (int)x2[-224*2] * wp[ 0]; t = (int)x1[ 224*2] * wp[ 0]; |
1416 | { | 1730 | s += (int)x2[-160*2] * wp[ 1]; t += (int)x1[ 160*2] * wp[ 1]; |
1417 | mdct_in[k] = sb_sample[ch][ gr ][k][band]; | 1731 | s += (int)x2[- 96*2] * wp[ 2]; t += (int)x1[ 96*2] * wp[ 2]; |
1418 | mdct_in[k+18] = sb_sample[ch][gr+1][k][band]; | 1732 | s += (int)x2[- 32*2] * wp[ 3]; t += (int)x1[ 32*2] * wp[ 3]; |
1419 | } | 1733 | s += (int)x2[ 32*2] * wp[ 4]; t += (int)x1[- 32*2] * wp[ 4]; |
1420 | 1734 | s += (int)x2[ 96*2] * wp[ 5]; t += (int)x1[- 96*2] * wp[ 5]; | |
1421 | mdct_int(mdct_in, &mdct_enc[gr][ch][band][0]); | 1735 | s += (int)x2[ 160*2] * wp[ 6]; t += (int)x1[-160*2] * wp[ 6]; |
1736 | s += (int)x2[ 224*2] * wp[ 7]; t += (int)x1[-224*2] * wp[ 7]; | ||
1737 | s += (int)x1[-256*2] * wp[ 8]; t += (int)x2[ 256*2] * wp[16]; | ||
1738 | s += (int)x1[-192*2] * wp[ 9]; t += (int)x2[ 192*2] * wp[17]; | ||
1739 | s += (int)x1[-128*2] * wp[10]; t += (int)x2[ 128*2] * wp[18]; | ||
1740 | s += (int)x1[- 64*2] * wp[11]; t += (int)x2[ 64*2] * wp[19]; | ||
1741 | s += (int)x1[ 0*2] * wp[12]; t += (int)x2[ 0*2] * wp[20]; | ||
1742 | s += (int)x1[ 64*2] * wp[13]; t += (int)x2[- 64*2] * wp[21]; | ||
1743 | s += (int)x1[ 128*2] * wp[14]; t += (int)x2[-128*2] * wp[22]; | ||
1744 | s += (int)x1[ 192*2] * wp[15]; t += (int)x2[-192*2] * wp[23]; | ||
1745 | |||
1746 | a[30+i*2] = shft4(t) + shft13(s) * wp[24]; | ||
1747 | a[31+i*2] = shft13(t) * wp[25] - shft13(s) * wp[26]; | ||
1748 | wp += 27; | ||
1749 | x1 -= 2; | ||
1750 | x2 += 2; | ||
1422 | } | 1751 | } |
1423 | 1752 | ||
1424 | /* 1024=4*256: Perform aliasing reduction butterfly*/ | 1753 | t = (int)x1[- 16*2] * wp[ 8]; s = (int)x1[ -32*2] * wp[0]; |
1425 | for(band=31; band--; ) | 1754 | t += ((int)x1[- 48*2]-x1[ 16*2]) * wp[10]; s += (int)x1[ -96*2] * wp[1]; |
1426 | for(k=8; k--; ) | 1755 | t += ((int)x1[- 80*2]+x1[ 48*2]) * wp[12]; s += (int)x1[-160*2] * wp[2]; |
1427 | { | 1756 | t += ((int)x1[-112*2]-x1[ 80*2]) * wp[14]; s += (int)x1[-224*2] * wp[3]; |
1428 | bu = mdct_enc[gr][ch][band][17-k] * cs_int[k] + mdct_enc[gr][ch][band+1][k] * ca_int[k]; | 1757 | t += ((int)x1[-144*2]+x1[112*2]) * wp[16]; s += (int)x1[ 32*2] * wp[4]; |
1429 | bd = mdct_enc[gr][ch][band+1][k] * cs_int[k] - mdct_enc[gr][ch][band][17-k] * ca_int[k]; | 1758 | t += ((int)x1[-176*2]-x1[144*2]) * wp[18]; s += (int)x1[ 96*2] * wp[5]; |
1430 | mdct_enc[gr][ch][band][17-k] = (bu + 16384) >> 15; | 1759 | t += ((int)x1[-208*2]+x1[176*2]) * wp[20]; s += (int)x1[ 160*2] * wp[6]; |
1431 | mdct_enc[gr][ch][band+1][k] = (bd + 16384) >> 15; | 1760 | t += ((int)x1[-240*2]-x1[208*2]) * wp[22]; s += (int)x1[ 224*2] * wp[7]; |
1432 | } | 1761 | |
1762 | u = shft4(s - t); | ||
1763 | v = shft4(s + t); | ||
1764 | t = a[14]; | ||
1765 | s = a[15] - t; | ||
1766 | |||
1767 | a[31] = v + t; /* A0 */ | ||
1768 | a[30] = u + s; /* A1 */ | ||
1769 | a[15] = u - s; /* A2 */ | ||
1770 | a[14] = v - t; /* A3 */ | ||
1433 | } | 1771 | } |
1772 | wk -= 18 * 64 - 1; /* rewind wk (to next channel start) */ | ||
1773 | } | ||
1774 | #endif | ||
1775 | } | ||
1434 | 1776 | ||
1435 | /* Save latest granule's subband samples to be used in the next mdct call */ | 1777 | void window_subband2(short *x1, int a[SBLIMIT]) ICODE_ATTR; |
1436 | for(ch=config.wave.channels ;ch--; ) | 1778 | void window_subband2(short *x1, int a[SBLIMIT]) |
1437 | memcpy(sb_sample[ch][0], sb_sample[ch][2], 18 * 32 * sizeof(int)); | 1779 | { |
1780 | int xr; | ||
1781 | short *wp = enwindow; | ||
1782 | short *x2 = x1 - 124; | ||
1783 | |||
1784 | wp += 27 * 15; | ||
1785 | x1 -= 2 * 15; | ||
1786 | x2 += 2 * 15; | ||
1787 | |||
1788 | xr = a[28] - a[0]; a[0] += a[28]; a[28] = shft9(xr) * wp[-2*27+25]; | ||
1789 | xr = a[29] - a[1]; a[1] += a[29]; a[29] = shft9(xr) * wp[-2*27+25]; | ||
1790 | xr = a[26] - a[2]; a[2] += a[26]; a[26] = shft9(xr) * wp[-4*27+25]; | ||
1791 | xr = a[27] - a[3]; a[3] += a[27]; a[27] = shft9(xr) * wp[-4*27+25]; | ||
1792 | xr = a[24] - a[4]; a[4] += a[24]; a[24] = shft9(xr) * wp[-6*27+25]; | ||
1793 | xr = a[25] - a[5]; a[5] += a[25]; a[25] = shft9(xr) * wp[-6*27+25]; | ||
1794 | xr = a[22] - a[6]; a[6] += a[22]; a[22] = shft9(xr) * SQRT ; | ||
1795 | xr = a[23] - a[7]; a[7] += a[23]; a[23] = shft9(xr) * SQRT - a[7]; | ||
1796 | a[ 7] -= a[ 6]; | ||
1797 | a[22] -= a[ 7]; | ||
1798 | a[23] -= a[22]; | ||
1799 | |||
1800 | xr = a[ 6]; a[ 6] = a[31] - xr; a[31] = a[31] + xr; | ||
1801 | xr = a[ 7]; a[ 7] = a[30] - xr; a[30] = a[30] + xr; | ||
1802 | xr = a[22]; a[22] = a[15] - xr; a[15] = a[15] + xr; | ||
1803 | xr = a[23]; a[23] = a[14] - xr; a[14] = a[14] + xr; | ||
1804 | |||
1805 | xr = a[20] - a[ 8]; a[ 8] += a[20]; a[20] = shft9(xr) * wp[-10*27+25]; | ||
1806 | xr = a[21] - a[ 9]; a[ 9] += a[21]; a[21] = shft9(xr) * wp[-10*27+25]; | ||
1807 | xr = a[18] - a[10]; a[10] += a[18]; a[18] = shft9(xr) * wp[-12*27+25]; | ||
1808 | xr = a[19] - a[11]; a[11] += a[19]; a[19] = shft9(xr) * wp[-12*27+25]; | ||
1809 | xr = a[16] - a[12]; a[12] += a[16]; a[16] = shft9(xr) * wp[-14*27+25]; | ||
1810 | xr = a[17] - a[13]; a[13] += a[17]; a[17] = shft9(xr) * wp[-14*27+25]; | ||
1811 | xr =-a[20] + a[24]; a[20] += a[24]; a[24] = shft9(xr) * wp[-12*27+25]; | ||
1812 | xr =-a[21] + a[25]; a[21] += a[25]; a[25] = shft9(xr) * wp[-12*27+25]; | ||
1813 | xr = a[ 4] - a[ 8]; a[ 4] += a[ 8]; a[ 8] = shft9(xr) * wp[-12*27+25]; | ||
1814 | xr = a[ 5] - a[ 9]; a[ 5] += a[ 9]; a[ 9] = shft9(xr) * wp[-12*27+25]; | ||
1815 | xr = a[ 0] - a[12]; a[ 0] += a[12]; a[12] = shft9(xr) * wp[ -4*27+25]; | ||
1816 | xr = a[ 1] - a[13]; a[ 1] += a[13]; a[13] = shft9(xr) * wp[ -4*27+25]; | ||
1817 | xr = a[16] - a[28]; a[16] += a[28]; a[28] = shft9(xr) * wp[ -4*27+25]; | ||
1818 | xr =-a[17] + a[29]; a[17] += a[29]; a[29] = shft9(xr) * wp[ -4*27+25]; | ||
1819 | |||
1820 | xr = SQRT * shft9(a[ 2] - a[10]); a[ 2] += a[10]; a[10] = xr; | ||
1821 | xr = SQRT * shft9(a[ 3] - a[11]); a[ 3] += a[11]; a[11] = xr; | ||
1822 | xr = SQRT * shft9(a[26] - a[18]); a[18] += a[26]; a[26] = xr - a[18]; | ||
1823 | xr = SQRT * shft9(a[27] - a[19]); a[19] += a[27]; a[27] = xr - a[19]; | ||
1824 | |||
1825 | xr = a[ 2]; a[19] -= a[ 3]; a[ 3] -= xr; a[ 2] = a[31] - xr; a[31] += xr; | ||
1826 | xr = a[ 3]; a[11] -= a[19]; a[18] -= xr; a[ 3] = a[30] - xr; a[30] += xr; | ||
1827 | xr = a[18]; a[27] -= a[11]; a[19] -= xr; a[18] = a[15] - xr; a[15] += xr; | ||
1828 | |||
1829 | xr = a[19]; a[10] -= xr; a[19] = a[14] - xr; a[14] += xr; | ||
1830 | xr = a[10]; a[11] -= xr; a[10] = a[23] - xr; a[23] += xr; | ||
1831 | xr = a[11]; a[26] -= xr; a[11] = a[22] - xr; a[22] += xr; | ||
1832 | xr = a[26]; a[27] -= xr; a[26] = a[ 7] - xr; a[ 7] += xr; | ||
1833 | |||
1834 | xr = a[27]; a[27] = a[6] - xr; a[6] += xr; | ||
1835 | |||
1836 | xr = SQRT * shft9(a[ 0] - a[ 4]); a[ 0] += a[ 4]; a[ 4] = xr; | ||
1837 | xr = SQRT * shft9(a[ 1] - a[ 5]); a[ 1] += a[ 5]; a[ 5] = xr; | ||
1838 | xr = SQRT * shft9(a[16] - a[20]); a[16] += a[20]; a[20] = xr; | ||
1839 | xr = SQRT * shft9(a[17] - a[21]); a[17] += a[21]; a[21] = xr; | ||
1840 | xr =-SQRT * shft9(a[ 8] - a[12]); a[ 8] += a[12]; a[12] = xr - a[ 8]; | ||
1841 | xr =-SQRT * shft9(a[ 9] - a[13]); a[ 9] += a[13]; a[13] = xr - a[ 9]; | ||
1842 | xr =-SQRT * shft9(a[25] - a[29]); a[25] += a[29]; a[29] = xr - a[25]; | ||
1843 | xr =-SQRT * shft9(a[24] + a[28]); a[24] -= a[28]; a[28] = xr - a[24]; | ||
1844 | |||
1845 | xr = a[24] - a[16]; a[24] = xr; | ||
1846 | xr = a[20] - xr; a[20] = xr; | ||
1847 | xr = a[28] - xr; a[28] = xr; | ||
1848 | |||
1849 | xr = a[25] - a[17]; a[25] = xr; | ||
1850 | xr = a[21] - xr; a[21] = xr; | ||
1851 | xr = a[29] - xr; a[29] = xr; | ||
1852 | |||
1853 | xr = a[17] - a[1]; a[17] = xr; | ||
1854 | xr = a[ 9] - xr; a[ 9] = xr; | ||
1855 | xr = a[25] - xr; a[25] = xr; | ||
1856 | xr = a[ 5] - xr; a[ 5] = xr; | ||
1857 | xr = a[21] - xr; a[21] = xr; | ||
1858 | xr = a[13] - xr; a[13] = xr; | ||
1859 | xr = a[29] - xr; a[29] = xr; | ||
1860 | |||
1861 | xr = a[ 1] - a[0]; a[ 1] = xr; | ||
1862 | xr = a[16] - xr; a[16] = xr; | ||
1863 | xr = a[17] - xr; a[17] = xr; | ||
1864 | xr = a[ 8] - xr; a[ 8] = xr; | ||
1865 | xr = a[ 9] - xr; a[ 9] = xr; | ||
1866 | xr = a[24] - xr; a[24] = xr; | ||
1867 | xr = a[25] - xr; a[25] = xr; | ||
1868 | xr = a[ 4] - xr; a[ 4] = xr; | ||
1869 | xr = a[ 5] - xr; a[ 5] = xr; | ||
1870 | xr = a[20] - xr; a[20] = xr; | ||
1871 | xr = a[21] - xr; a[21] = xr; | ||
1872 | xr = a[12] - xr; a[12] = xr; | ||
1873 | xr = a[13] - xr; a[13] = xr; | ||
1874 | xr = a[28] - xr; a[28] = xr; | ||
1875 | xr = a[29] - xr; a[29] = xr; | ||
1876 | |||
1877 | xr = a[ 0]; a[ 0] += a[31]; a[31] -= xr; | ||
1878 | xr = a[ 1]; a[ 1] += a[30]; a[30] -= xr; | ||
1879 | xr = a[16]; a[16] += a[15]; a[15] -= xr; | ||
1880 | xr = a[17]; a[17] += a[14]; a[14] -= xr; | ||
1881 | xr = a[ 8]; a[ 8] += a[23]; a[23] -= xr; | ||
1882 | xr = a[ 9]; a[ 9] += a[22]; a[22] -= xr; | ||
1883 | xr = a[24]; a[24] += a[ 7]; a[ 7] -= xr; | ||
1884 | xr = a[25]; a[25] += a[ 6]; a[ 6] -= xr; | ||
1885 | xr = a[ 4]; a[ 4] += a[27]; a[27] -= xr; | ||
1886 | xr = a[ 5]; a[ 5] += a[26]; a[26] -= xr; | ||
1887 | xr = a[20]; a[20] += a[11]; a[11] -= xr; | ||
1888 | xr = a[21]; a[21] += a[10]; a[10] -= xr; | ||
1889 | xr = a[12]; a[12] += a[19]; a[19] -= xr; | ||
1890 | xr = a[13]; a[13] += a[18]; a[18] -= xr; | ||
1891 | xr = a[28]; a[28] += a[ 3]; a[ 3] -= xr; | ||
1892 | xr = a[29]; a[29] += a[ 2]; a[ 2] -= xr; | ||
1438 | } | 1893 | } |
1439 | 1894 | ||
1440 | void filter_subband(short *buffer, int s[SBLIMIT], int k) | 1895 | void mdct_long(int *out, int *in) ICODE_ATTR; |
1896 | void mdct_long(int *out, int *in) | ||
1441 | { | 1897 | { |
1442 | short *enwindow = enwindow_int; | 1898 | int ct,st; |
1443 | int i, j, tmp = 0; | 1899 | int tc1, tc2, tc3, tc4, ts5, ts6, ts7, ts8; |
1444 | #ifdef CPU_COLDFIRE | 1900 | int ts1, ts2, ts3, ts4, tc5, tc6, tc7, tc8; |
1445 | int reg_buff[14]; /* register storage buffer */ | 1901 | |
1446 | #endif | 1902 | /* 1,2, 5,6, 9,10, 13,14, 17 */ |
1903 | tc1 = in[17] - in[ 9]; | ||
1904 | tc3 = in[15] - in[11]; | ||
1905 | tc4 = in[14] - in[12]; | ||
1906 | ts5 = in[ 0] + in[ 8]; | ||
1907 | ts6 = in[ 1] + in[ 7]; | ||
1908 | ts7 = in[ 2] + in[ 6]; | ||
1909 | ts8 = in[ 3] + in[ 5]; | ||
1910 | |||
1911 | out[17] = (ts5 + ts7 - ts8) * cx[8] - (ts6 - in[4]) * cx[8]; | ||
1912 | st = (ts5 + ts7 - ts8) * cx[7] + (ts6 - in[4]) * cx[8]; | ||
1913 | ct = (tc1 - tc3 - tc4) * cx[6]; | ||
1914 | out[5] = ct + st; | ||
1915 | out[6] = ct - st; | ||
1916 | |||
1917 | tc2 = (in[16] - in[10]) * cx[6]; | ||
1918 | ts6 = ts6 * cx[7] + in[4] * cx[8]; | ||
1447 | 1919 | ||
1448 | /* replace 32 oldest samples with 32 new samples */ | 1920 | ct = tc1 * cx[0] + tc2 + tc3 * cx[1] + tc4 * cx[2]; |
1449 | /* 2304=72*32: PCM Samples are little-endian, swap if necessary */ | 1921 | st = -ts5 * cx[4] + ts6 - ts7 * cx[5] + ts8 * cx[3]; |
1450 | if(config.byte_order == order_bigEndian) | 1922 | out[1] = ct + st; |
1451 | { | 1923 | out[2] = ct - st; |
1452 | for(i=32; i--; ) | 1924 | |
1453 | { | 1925 | ct = tc1 * cx[1] - tc2 - tc3 * cx[2] + tc4 * cx[0]; |
1454 | j = *(unsigned short*)(buffer+=2); | 1926 | st = -ts5 * cx[5] + ts6 - ts7 * cx[3] + ts8 * cx[4]; |
1455 | x_int[k][i+off[k]] = (short)((j >> 8) | (j << 8)); | 1927 | out[ 9] = ct + st; |
1456 | } | 1928 | out[10] = ct - st; |
1457 | } | 1929 | |
1458 | else | 1930 | ct = tc1 * cx[2] - tc2 + tc3 * cx[0] - tc4 * cx[1]; |
1459 | { | 1931 | st = ts5 * cx[3] - ts6 + ts7 * cx[4] - ts8 * cx[5]; |
1460 | for(i=32; i--; ) | 1932 | out[13] = ct + st; |
1461 | x_int[k][i+off[k]] = (short)*(buffer+=2); | 1933 | out[14] = ct - st; |
1462 | } | 1934 | |
1935 | ts1 = in[ 8] - in[ 0]; | ||
1936 | ts3 = in[ 6] - in[ 2]; | ||
1937 | ts4 = in[ 5] - in[ 3]; | ||
1938 | tc5 = in[17] + in[ 9]; | ||
1939 | tc6 = in[16] + in[10]; | ||
1940 | tc7 = in[15] + in[11]; | ||
1941 | tc8 = in[14] + in[12]; | ||
1942 | |||
1943 | out[0] = (tc5 + tc7 + tc8) * cx[8] + (tc6 + in[13]) * cx[8]; | ||
1944 | ct = (tc5 + tc7 + tc8) * cx[7] - (tc6 + in[13]) * cx[8]; | ||
1945 | st = (ts1 - ts3 + ts4) * cx[6]; | ||
1946 | out[11] = ct + st; | ||
1947 | out[12] = ct - st; | ||
1948 | |||
1949 | ts2 = (in[7] - in[1]) * cx[6]; | ||
1950 | tc6 = in[13] * cx[8] - tc6 * cx[7]; | ||
1951 | |||
1952 | ct = tc5 * cx[3] - tc6 + tc7 * cx[4] + tc8 * cx[5]; | ||
1953 | st = ts1 * cx[2] + ts2 + ts3 * cx[0] + ts4 * cx[1]; | ||
1954 | out[3] = ct + st; | ||
1955 | out[4] = ct - st; | ||
1956 | |||
1957 | ct =-tc5 * cx[5] + tc6 - tc7 * cx[3] - tc8 * cx[4]; | ||
1958 | st = ts1 * cx[1] + ts2 - ts3 * cx[2] - ts4 * cx[0]; | ||
1959 | out[7] = ct + st; | ||
1960 | out[8] = ct - st; | ||
1961 | |||
1962 | ct =-tc5 * cx[4] + tc6 - tc7 * cx[5] - tc8 * cx[3]; | ||
1963 | st = ts1 * cx[0] - ts2 + ts3 * cx[1] - ts4 * cx[2]; | ||
1964 | out[15] = ct + st; | ||
1965 | out[16] = ct - st; | ||
1966 | } | ||
1463 | 1967 | ||
1464 | /* 36864=72*512: shift samples into proper window positions */ | 1968 | static int find_bitrate_index(int type, int bitrate) |
1465 | #ifdef CPU_COLDFIRE | 1969 | { |
1466 | { short *xint = &x_int[k][off[k]]; | 1970 | int i; |
1467 | short *yint = y_int; | ||
1468 | 1971 | ||
1469 | asm volatile ("movem.l %%d0/%%d2-%%d7/%%a2-%%a7,(%0)\n" : : "a" (reg_buff) : "d0"); | 1972 | for(i=0;i<14;i++) |
1470 | asm volatile( | 1973 | if(bitrate == bitr_index[type][i]) |
1471 | "moveq.l #32, %%d0\n" | 1974 | break; |
1472 | "move.l %%d0, %%acc2\n" /* set loop counter */ | ||
1473 | "move.l %[xint], %%d0\n" /* d0 = x_int[k] */ | ||
1474 | "or.l #0x3ff, %%d0\n" | ||
1475 | "move.l %%d0, %%mask\n" /* set address mask */ | ||
1476 | "move.l (%[xint]), %%d4\n" /* d4 = x_int[k][off[k]] */ | ||
1477 | |||
1478 | "loop_start:\n" | ||
1479 | "movem.l (%[enwindow]), %%d0-%%d3\n" /* load 4 values */ | ||
1480 | "mac.w %%d0u, %%d4u, (0x080,%[xint])&, %%d5, %%acc0\n" | ||
1481 | "mac.w %%d0l, %%d5u, (0x100,%[xint])&, %%d6, %%acc0\n" | ||
1482 | "mac.w %%d1u, %%d6u, (0x180,%[xint])&, %%d7, %%acc0\n" | ||
1483 | "mac.w %%d1l, %%d7u, (0x200,%[xint])&, %%a2, %%acc0\n" | ||
1484 | "mac.w %%d2u, %%a2u, (0x280,%[xint])&, %%a3, %%acc0\n" | ||
1485 | "mac.w %%d2l, %%a3u, (0x300,%[xint])&, %%a4, %%acc0\n" | ||
1486 | "mac.w %%d3u, %%a4u, (0x380,%[xint])&, %%a5, %%acc0\n" | ||
1487 | "mac.w %%d3l, %%a5u, %%acc0\n" | ||
1488 | |||
1489 | "movem.l (16,%[enwindow]), %%d0-%%d3\n" /* load 8 values */ | ||
1490 | "mac.w %%d0u, %%d4l, %%acc1\n" | ||
1491 | "mac.w %%d0l, %%d5l, %%acc1\n" | ||
1492 | "mac.w %%d1u, %%d6l, %%acc1\n" | ||
1493 | "mac.w %%d1l, %%d7l, %%acc1\n" | ||
1494 | "mac.w %%d2u, %%a2l, %%acc1\n" | ||
1495 | "mac.w %%d2l, %%a3l, %%acc1\n" | ||
1496 | "mac.w %%d3u, %%a4l, %%acc1\n" | ||
1497 | "addq.l #4, %[xint]\n" /* xint += 2 */ | ||
1498 | "mac.w %%d3l, %%a5l, (%[xint])&, %%d4, %%acc1\n" | ||
1499 | |||
1500 | "movclr.l %%acc0, %%d5\n" | ||
1501 | "movclr.l %%acc1, %%d6\n" | ||
1502 | "move.l #262144, %%d7\n" | ||
1503 | "add.l %%d7, %%d5\n" | ||
1504 | "add.l %%d7, %%d6\n" | ||
1505 | "moveq.l #19, %%d7\n" | ||
1506 | "asr.l %%d7, %%d5\n" | ||
1507 | "asr.l %%d7, %%d6\n" | ||
1508 | "move.w %%d5, (%[yint])+\n" | ||
1509 | "move.w %%d6, (%[yint])+\n" | ||
1510 | |||
1511 | "add.l #32, %[enwindow]\n" /* enwindow += 16 */ | ||
1512 | |||
1513 | "moveq.l #1, %%d0\n" | ||
1514 | "msac.l %%d0, %%d0, %%acc2\n" | ||
1515 | "move.l %%acc2, %%d0\n" | ||
1516 | "tst.b %%d0\n" | ||
1517 | "jbne loop_start\n" | ||
1518 | |||
1519 | : [xint] "+a" (xint), [yint] "+a" (yint) | ||
1520 | : [enwindow] "a" (enwindow) | ||
1521 | : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a2", "a3", "a4", "a5"); | ||
1522 | |||
1523 | asm volatile ("movem.l (%0),%%d0/%%d2-%%d7/%%a2-%%a7\n" : : "a" (reg_buff) : "d0"); | ||
1524 | } | ||
1525 | #else | ||
1526 | for(i=0; i<64; i++) | ||
1527 | { | ||
1528 | for(j=0, tmp=0; j<512; j+=64) | ||
1529 | tmp += (int)x_int[k][(i+0+j+off[k])&(HAN_SIZE-1)] * (int)*(enwindow++); | ||
1530 | y_int[i] = (short)((tmp + (1<<18)) >> 19); | ||
1531 | } | ||
1532 | #endif | ||
1533 | |||
1534 | /* 147456=72*2048 */ | ||
1535 | for(i=SBLIMIT; i--; ) /* SBLIMIT: 32 */ | ||
1536 | { | ||
1537 | short *filt = filter_int[i]; | ||
1538 | 1975 | ||
1539 | #ifdef CPU_COLDFIRE | 1976 | return i; |
1540 | { | 1977 | } |
1541 | asm volatile( | 1978 | |
1542 | "move.l (%[yint])+, %%a5\n" | 1979 | static int find_samplerate_index(long freq, int *mp3_type) |
1543 | "movem.l (%[filt]), %%d0-%%d7\n" | 1980 | { /* MPEG 2 */ /* MPEG 1 */ |
1544 | "mac.w %%d0u, %%a5u, %%acc0\n" | 1981 | static long mpeg[2][3] = { {22050, 24000, 16000}, {44100, 48000, 32000} }; |
1545 | "mac.w %%d0l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | 1982 | int mpg, rate; |
1546 | "mac.w %%d1u, %%a5u, %%acc0\n" | 1983 | |
1547 | "mac.w %%d1l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | 1984 | /* set default values: MPEG1 at 44100/s */ |
1548 | "mac.w %%d2u, %%a5u, %%acc0\n" | 1985 | *mp3_type = 1; |
1549 | "mac.w %%d2l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | 1986 | |
1550 | "mac.w %%d3u, %%a5u, %%acc0\n" | 1987 | for(mpg=0; mpg<2; mpg++) |
1551 | "mac.w %%d3l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | 1988 | for(rate=0; rate<3; rate++) |
1552 | "mac.w %%d4u, %%a5u, %%acc0\n" | 1989 | if(freq == mpeg[mpg][rate]) |
1553 | "mac.w %%d4l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | 1990 | { *mp3_type = mpg; return rate; } |
1554 | "mac.w %%d5u, %%a5u, %%acc0\n" | ||
1555 | "mac.w %%d5l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1556 | "mac.w %%d6u, %%a5u, %%acc0\n" | ||
1557 | "mac.w %%d6l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1558 | "mac.w %%d7u, %%a5u, %%acc0\n" | ||
1559 | "mac.w %%d7l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1560 | "movem.l (32,%[filt]), %%d0-%%d7\n" | ||
1561 | "mac.w %%d0u, %%a5u, %%acc0\n" | ||
1562 | "mac.w %%d0l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1563 | "mac.w %%d1u, %%a5u, %%acc0\n" | ||
1564 | "mac.w %%d1l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1565 | "mac.w %%d2u, %%a5u, %%acc0\n" | ||
1566 | "mac.w %%d2l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1567 | "mac.w %%d3u, %%a5u, %%acc0\n" | ||
1568 | "mac.w %%d3l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1569 | "mac.w %%d4u, %%a5u, %%acc0\n" | ||
1570 | "mac.w %%d4l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1571 | "mac.w %%d5u, %%a5u, %%acc0\n" | ||
1572 | "mac.w %%d5l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1573 | "mac.w %%d6u, %%a5u, %%acc0\n" | ||
1574 | "mac.w %%d6l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1575 | "mac.w %%d7u, %%a5u, %%acc0\n" | ||
1576 | "mac.w %%d7l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1577 | "movem.l (64,%[filt]), %%d0-%%d7\n" | ||
1578 | "mac.w %%d0u, %%a5u, %%acc0\n" | ||
1579 | "mac.w %%d0l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1580 | "mac.w %%d1u, %%a5u, %%acc0\n" | ||
1581 | "mac.w %%d1l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1582 | "mac.w %%d2u, %%a5u, %%acc0\n" | ||
1583 | "mac.w %%d2l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1584 | "mac.w %%d3u, %%a5u, %%acc0\n" | ||
1585 | "mac.w %%d3l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1586 | "mac.w %%d4u, %%a5u, %%acc0\n" | ||
1587 | "mac.w %%d4l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1588 | "mac.w %%d5u, %%a5u, %%acc0\n" | ||
1589 | "mac.w %%d5l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1590 | "mac.w %%d6u, %%a5u, %%acc0\n" | ||
1591 | "mac.w %%d6l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1592 | "mac.w %%d7u, %%a5u, %%acc0\n" | ||
1593 | "mac.w %%d7l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1594 | "movem.l (96,%[filt]), %%d0-%%d7\n" | ||
1595 | "mac.w %%d0u, %%a5u, %%acc0\n" | ||
1596 | "mac.w %%d0l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1597 | "mac.w %%d1u, %%a5u, %%acc0\n" | ||
1598 | "mac.w %%d1l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1599 | "mac.w %%d2u, %%a5u, %%acc0\n" | ||
1600 | "mac.w %%d2l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1601 | "mac.w %%d3u, %%a5u, %%acc0\n" | ||
1602 | "mac.w %%d3l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1603 | "mac.w %%d4u, %%a5u, %%acc0\n" | ||
1604 | "mac.w %%d4l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1605 | "mac.w %%d5u, %%a5u, %%acc0\n" | ||
1606 | "mac.w %%d5l, %%a5l, (%[yint])+, %%a5, %%acc0\n" | ||
1607 | "mac.w %%d6u, %%a5u, %%acc0\n" | ||
1608 | "mac.w %%d6l, %%a5l, (%[yint]), %%a5, %%acc0\n" | ||
1609 | "mac.w %%d7u, %%a5u, %%acc0\n" | ||
1610 | "mac.w %%d7l, %%a5l, %%acc0\n" | ||
1611 | "lea.l (-31*4, %[yint]), %[yint]\n" /* wrap yint back to start */ | ||
1612 | "movclr.l %%acc0, %[tmp]" | ||
1613 | : [tmp] "=r" (tmp) : [filt] "a" (filt), [yint] "a" (y_int) | ||
1614 | : "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "a5" ); | ||
1615 | } | ||
1616 | #else | ||
1617 | for(j=64, tmp=0; j--; ) | ||
1618 | tmp += (long)filt[j] * (long)y_int[j]; | ||
1619 | #endif | ||
1620 | s[i] = (tmp + 16384) >> 15; | ||
1621 | } | ||
1622 | 1991 | ||
1623 | off[k] = (off[k] + 480) & (HAN_SIZE-1); /* offset is modulo HAN_SIZE */ | 1992 | return 0; |
1624 | } | 1993 | } |
1625 | 1994 | ||
1626 | void compress(void) | 1995 | void init_mp3_encoder_engine(bool stereo, int bitrate, int sample_rate) |
1627 | { | 1996 | { |
1628 | int channel; | 1997 | uint32 avg_byte_per_frame; |
1629 | int i; | 1998 | |
1630 | char stg[20]; | 1999 | #ifdef ROCKBOX_LITTLE_ENDIAN |
1631 | int gr; | 2000 | cfg.byte_order = order_littleEndian; |
1632 | side_info_t cod_info[2][2]; | 2001 | #else |
1633 | short *buffer_window[2]; | 2002 | cfg.byte_order = order_bigEndian; |
1634 | unsigned long avg_slots_per_frame; | 2003 | #endif |
1635 | long frac_slots_per_frame; | 2004 | |
1636 | long whole_slots_per_frame; | 2005 | if(bitrate < 96 && stereo && sample_rate >= 32000) |
1637 | long slot_lag; | 2006 | { /* use MPEG2 format */ |
1638 | int mean_bits; | 2007 | sample_rate >>= 1; |
1639 | int sideinfo_len; | 2008 | cfg.resample = 1; |
1640 | 2009 | cfg.granules = 1; | |
1641 | open_bitstream(config.outfile); | 2010 | } |
1642 | 2011 | else | |
1643 | memset(cod_info , 0 , sizeof(cod_info )); | 2012 | { /* use MPEG1 format */ |
1644 | memset(x_int0 , 0 , sizeof(x_int0 )); | 2013 | cfg.resample = 0; |
1645 | memset(x_int1 , 0 , sizeof(x_int1 )); | 2014 | cfg.granules = 2; |
1646 | memset(y_int , 0 , sizeof(y_int )); | 2015 | } |
1647 | memset(mdct_freq , 0 , sizeof(mdct_freq )); | 2016 | |
1648 | memset(enc_data , 0 , sizeof(enc_data )); | 2017 | cfg.samplerate = sample_rate; |
1649 | memset(off , 0 , sizeof(off )); | 2018 | cfg.channels = stereo ? 2 : 1; |
1650 | memset(mdct_in , 0 , sizeof(mdct_in )); | 2019 | cfg.mpg.mode = stereo ? 0 : 3; /* 0=stereo, 3=mono */ |
1651 | memset(sb_sample , 0 , sizeof(sb_sample )); | 2020 | cfg.mpg.bitrate = stereo ? bitrate : bitrate > 160 ? 160 : bitrate; |
1652 | memset(&CodedData , 0 , sizeof(CodedData )); | 2021 | cfg.mpg.smpl_id = find_samplerate_index(cfg.samplerate, &cfg.mpg.type); |
1653 | memcpy(scalefac_long, sfBandIndex[config.mpeg.samplerate_index + (config.mpeg.type * 3)], sizeof(scalefac_long)); | 2022 | cfg.mpg.bitr_id = find_bitrate_index(cfg.mpg.type, cfg.mpg.bitrate); |
1654 | memcpy(ca_int , ca_int_const , sizeof(ca_int )); | 2023 | cfg.mpg.num_bands = num_bands[stereo ? cfg.mpg.type : 2][cfg.mpg.bitr_id]; |
1655 | memcpy(cs_int , cs_int_const , sizeof(cs_int )); | 2024 | |
1656 | memcpy(win_int , win_int_const , sizeof(win_int )); | 2025 | memcpy(scalefac, sfBand[cfg.mpg.smpl_id + 3*cfg.mpg.type], sizeof(scalefac)); |
1657 | memcpy(filter_int , filter_int_const , sizeof(filter_int )); | 2026 | memset(mfbuf , 0 , sizeof(mfbuf )); |
1658 | memcpy(enwindow_int, enwindow_int_const, sizeof(enwindow_int)); | 2027 | memset(mdct_freq , 0 , sizeof(mdct_freq )); |
1659 | memcpy(int2idx , int2idx_const , sizeof(int2idx )); | 2028 | memset(enc_data , 0 , sizeof(enc_data )); |
1660 | memcpy(ht_count1 , ht_count1_const , sizeof(ht_count1 )); | 2029 | memset(sb_data , 0 , sizeof(sb_data )); |
1661 | memcpy( t1HB , t1HB_const , sizeof(t1HB )); | 2030 | memset(&CodedData, 0 , sizeof(CodedData )); |
1662 | memcpy( t2HB , t2HB_const , sizeof(t2HB )); | 2031 | memcpy(ca , ca_const , sizeof(ca )); |
1663 | memcpy( t3HB , t3HB_const , sizeof(t3HB )); | 2032 | memcpy(cs , cs_const , sizeof(cs )); |
1664 | memcpy( t5HB , t5HB_const , sizeof(t5HB )); | 2033 | memcpy(cx , cx_const , sizeof(cx )); |
1665 | memcpy( t6HB , t6HB_const , sizeof(t6HB )); | 2034 | memcpy(win , win_const , sizeof(win )); |
1666 | memcpy( t7HB , t7HB_const , sizeof(t7HB )); | 2035 | memcpy(enwindow , enwindow_const , sizeof(enwindow )); |
1667 | memcpy( t8HB , t8HB_const , sizeof(t8HB )); | 2036 | memcpy(int2idx , int2idx_const , sizeof(int2idx )); |
1668 | memcpy( t9HB , t9HB_const , sizeof(t9HB )); | 2037 | memcpy(ht_count , ht_count_const , sizeof(ht_count )); |
1669 | memcpy(t10HB , t10HB_const , sizeof(t10HB )); | 2038 | memcpy( tab01 , tab01_const , sizeof(tab01 )); |
1670 | memcpy(t11HB , t11HB_const , sizeof(t11HB )); | 2039 | memcpy( tab23 , tab23_const , sizeof(tab23 )); |
1671 | memcpy(t12HB , t12HB_const , sizeof(t12HB )); | 2040 | memcpy( tab56 , tab56_const , sizeof(tab56 )); |
1672 | memcpy(t13HB , t13HB_const , sizeof(t13HB )); | 2041 | memcpy( tab1315 , tab1315_const , sizeof(tab1315 )); |
1673 | memcpy(t15HB , t15HB_const , sizeof(t15HB )); | 2042 | memcpy( tab1624 , tab1624_const , sizeof(tab1624 )); |
1674 | memcpy(t16HB , t16HB_const , sizeof(t16HB )); | 2043 | memcpy( tab789 , tab789_const , sizeof(tab789 )); |
1675 | memcpy(t24HB , t24HB_const , sizeof(t24HB )); | 2044 | memcpy( tabABC , tabABC_const , sizeof(tabABC )); |
1676 | memcpy( t1l , t1l_const , sizeof(t1l )); | 2045 | memcpy( t1HB , t1HB_const , sizeof(t1HB )); |
1677 | memcpy( t2l , t2l_const , sizeof(t2l )); | 2046 | memcpy( t2HB , t2HB_const , sizeof(t2HB )); |
1678 | memcpy( t3l , t3l_const , sizeof(t3l )); | 2047 | memcpy( t3HB , t3HB_const , sizeof(t3HB )); |
1679 | memcpy( t5l , t5l_const , sizeof(t5l )); | 2048 | memcpy( t5HB , t5HB_const , sizeof(t5HB )); |
1680 | memcpy( t6l , t6l_const , sizeof(t6l )); | 2049 | memcpy( t6HB , t6HB_const , sizeof(t6HB )); |
1681 | memcpy( t7l , t7l_const , sizeof(t7l )); | 2050 | memcpy( t7HB , t7HB_const , sizeof(t7HB )); |
1682 | memcpy( t8l , t8l_const , sizeof(t8l )); | 2051 | memcpy( t8HB , t8HB_const , sizeof(t8HB )); |
1683 | memcpy( t9l , t9l_const , sizeof(t9l )); | 2052 | memcpy( t9HB , t9HB_const , sizeof(t9HB )); |
1684 | memcpy(t10l , t10l_const , sizeof(t10l )); | 2053 | memcpy(t10HB , t10HB_const , sizeof(t10HB )); |
1685 | memcpy(t11l , t11l_const , sizeof(t11l )); | 2054 | memcpy(t11HB , t11HB_const , sizeof(t11HB )); |
1686 | memcpy(t12l , t12l_const , sizeof(t12l )); | 2055 | memcpy(t12HB , t12HB_const , sizeof(t12HB )); |
1687 | memcpy(t13l , t13l_const , sizeof(t13l )); | 2056 | memcpy(t13HB , t13HB_const , sizeof(t13HB )); |
1688 | memcpy(t15l , t15l_const , sizeof(t15l )); | 2057 | memcpy(t15HB , t15HB_const , sizeof(t15HB )); |
1689 | memcpy(t16l , t16l_const , sizeof(t16l )); | 2058 | memcpy(t16HB , t16HB_const , sizeof(t16HB )); |
1690 | memcpy(t24l , t24l_const , sizeof(t24l )); | 2059 | memcpy(t24HB , t24HB_const , sizeof(t24HB )); |
1691 | memcpy(ht , ht_const , sizeof(ht )); | 2060 | memcpy( t1l , t1l_const , sizeof(t1l )); |
1692 | 2061 | memcpy( t2l , t2l_const , sizeof(t2l )); | |
1693 | /* I don't know, wether this is really necessary */ | 2062 | memcpy( t3l , t3l_const , sizeof(t3l )); |
1694 | ht[ 0].table = NULL; ht[ 0].hlen = NULL;/* Apparently not used */ | 2063 | memcpy( t5l , t5l_const , sizeof(t5l )); |
2064 | memcpy( t6l , t6l_const , sizeof(t6l )); | ||
2065 | memcpy( t7l , t7l_const , sizeof(t7l )); | ||
2066 | memcpy( t8l , t8l_const , sizeof(t8l )); | ||
2067 | memcpy( t9l , t9l_const , sizeof(t9l )); | ||
2068 | memcpy(t10l , t10l_const , sizeof(t10l )); | ||
2069 | memcpy(t11l , t11l_const , sizeof(t11l )); | ||
2070 | memcpy(t12l , t12l_const , sizeof(t12l )); | ||
2071 | memcpy(t13l , t13l_const , sizeof(t13l )); | ||
2072 | memcpy(t15l , t15l_const , sizeof(t15l )); | ||
2073 | memcpy(t16l , t16l_const , sizeof(t16l )); | ||
2074 | memcpy(t24l , t24l_const , sizeof(t24l )); | ||
2075 | memcpy(ht , ht_const , sizeof(ht )); | ||
2076 | |||
2077 | ht[ 0].table = NULL; ht[ 0].hlen = NULL; /* Apparently not used */ | ||
1695 | ht[ 1].table = t1HB; ht[ 1].hlen = t1l; | 2078 | ht[ 1].table = t1HB; ht[ 1].hlen = t1l; |
1696 | ht[ 2].table = t2HB; ht[ 2].hlen = t2l; | 2079 | ht[ 2].table = t2HB; ht[ 2].hlen = t2l; |
1697 | ht[ 3].table = t3HB; ht[ 3].hlen = t3l; | 2080 | ht[ 3].table = t3HB; ht[ 3].hlen = t3l; |
1698 | ht[ 4].table = NULL; ht[ 4].hlen = NULL;/* Apparently not used */ | 2081 | ht[ 4].table = NULL; ht[ 4].hlen = NULL; /* Apparently not used */ |
1699 | ht[ 5].table = t5HB; ht[ 5].hlen = t5l; | 2082 | ht[ 5].table = t5HB; ht[ 5].hlen = t5l; |
1700 | ht[ 6].table = t6HB; ht[ 6].hlen = t6l; | 2083 | ht[ 6].table = t6HB; ht[ 6].hlen = t6l; |
1701 | ht[ 7].table = t7HB; ht[ 7].hlen = t7l; | 2084 | ht[ 7].table = t7HB; ht[ 7].hlen = t7l; |
@@ -1705,126 +2088,197 @@ void compress(void) | |||
1705 | ht[11].table = t11HB; ht[11].hlen = t11l; | 2088 | ht[11].table = t11HB; ht[11].hlen = t11l; |
1706 | ht[12].table = t12HB; ht[12].hlen = t12l; | 2089 | ht[12].table = t12HB; ht[12].hlen = t12l; |
1707 | ht[13].table = t13HB; ht[13].hlen = t13l; | 2090 | ht[13].table = t13HB; ht[13].hlen = t13l; |
1708 | ht[14].table = NULL; ht[14].hlen = NULL;/* Apparently not used */ | 2091 | ht[14].table = NULL; ht[14].hlen = NULL; /* Apparently not used */ |
1709 | ht[15].table = t15HB; ht[15].hlen = t15l; | 2092 | ht[15].table = t15HB; ht[15].hlen = t15l; |
1710 | ht[16].table = t16HB; ht[16].hlen = t16l; | ||
1711 | ht[17].table = t16HB; ht[17].hlen = t16l; | ||
1712 | ht[18].table = t16HB; ht[18].hlen = t16l; | ||
1713 | ht[19].table = t16HB; ht[19].hlen = t16l; | ||
1714 | ht[20].table = t16HB; ht[20].hlen = t16l; | ||
1715 | ht[21].table = t16HB; ht[21].hlen = t16l; | ||
1716 | ht[22].table = t16HB; ht[22].hlen = t16l; | ||
1717 | ht[23].table = t16HB; ht[23].hlen = t16l; | ||
1718 | ht[24].table = t24HB; ht[24].hlen = t24l; | ||
1719 | ht[25].table = t24HB; ht[25].hlen = t24l; | ||
1720 | ht[26].table = t24HB; ht[26].hlen = t24l; | ||
1721 | ht[27].table = t24HB; ht[27].hlen = t24l; | ||
1722 | ht[28].table = t24HB; ht[28].hlen = t24l; | ||
1723 | ht[29].table = t24HB; ht[29].hlen = t24l; | ||
1724 | ht[30].table = t24HB; ht[30].hlen = t24l; | ||
1725 | ht[31].table = t24HB; ht[31].hlen = t24l; | ||
1726 | |||
1727 | x_int[0] = x_int0; | ||
1728 | x_int[1] = x_int1; | ||
1729 | 2093 | ||
1730 | #ifdef CPU_COLDFIRE | 2094 | /* Figure average number of 'bytes' per frame */ |
1731 | asm volatile ("move.l #0, %macsr"); /* integer mode */ | 2095 | avg_byte_per_frame = SAMPL2 * 16000 * cfg.mpg.bitrate / (2 - cfg.mpg.type); |
1732 | #endif | 2096 | avg_byte_per_frame = avg_byte_per_frame / cfg.samplerate; |
1733 | 2097 | cfg.byte_per_frame = avg_byte_per_frame / 64; | |
1734 | #ifndef SIMULATOR | 2098 | cfg.frac_per_frame = avg_byte_per_frame & 63; |
1735 | if(((long)x_int0 | (long)x_int1) & 0x7ff) | 2099 | cfg.slot_lag = 0; |
1736 | return; /* both arrays must be aligned to 0x800 boundary */ | 2100 | cfg.sideinfo_len = 32 + (cfg.mpg.type ? (cfg.channels == 1 ? 136 : 256) |
1737 | #endif | 2101 | : (cfg.channels == 1 ? 72 : 136)); |
2102 | } | ||
1738 | 2103 | ||
1739 | if(config.wave.channels == 1) | 2104 | void compress(void) |
1740 | sideinfo_len = 32 + 136; | 2105 | { |
1741 | else | 2106 | int i, ii, gr, k, ch, shift, gr_cnt; |
1742 | sideinfo_len = 32 + 256; | 2107 | int max, min; |
1743 | 2108 | char stg[20]; | |
1744 | /* Set initial step size */ | ||
1745 | cod_info[0][0].quantizerStepSize = 0x10; | ||
1746 | cod_info[0][1].quantizerStepSize = 0x10; | ||
1747 | cod_info[1][0].quantizerStepSize = 0x10; | ||
1748 | cod_info[1][1].quantizerStepSize = 0x10; | ||
1749 | |||
1750 | /* Figure average number of 'slots' per frame. */ | ||
1751 | frames_processed = 0; | ||
1752 | avg_slots_per_frame = (uint32)(samp_per_frame * 8000 * config.mpeg.bitr) / config.wave.samplerate; | ||
1753 | whole_slots_per_frame = avg_slots_per_frame / 64; | ||
1754 | frac_slots_per_frame = avg_slots_per_frame - 64 * whole_slots_per_frame; | ||
1755 | slot_lag = -frac_slots_per_frame; | ||
1756 | if(frac_slots_per_frame == 0) | ||
1757 | config.mpeg.padding = 0; | ||
1758 | 2109 | ||
1759 | while(1) | 2110 | while(1) |
1760 | { | 2111 | { |
1761 | rb->lcd_clear_display(); | 2112 | if((frames & 7) == 0) |
1762 | rb->snprintf(stg, 20, "Frame %d / %d", frames_processed++, wav_size/samp_per_frame/4); | 2113 | { rb->lcd_clear_display(); |
1763 | rb->lcd_putsxy(4, 20, stg); | 2114 | rb->snprintf(stg, 20, "Frame %d / %d", frames, wav_size/SAMPL2/8); |
1764 | rb->lcd_update(); | 2115 | rb->lcd_putsxy(4, 20, stg); |
2116 | rb->lcd_update(); | ||
2117 | } | ||
2118 | /* encode one mp3 frame in this loop */ | ||
2119 | memset(CodedData.bbuf, 0, sizeof(CodedData.bbuf)); | ||
2120 | |||
2121 | if((cfg.slot_lag += cfg.frac_per_frame) >= 64) | ||
2122 | { /* Padding for this frame */ | ||
2123 | cfg.slot_lag -= 64; | ||
2124 | cfg.mpg.padding = 1; | ||
2125 | } | ||
2126 | else | ||
2127 | cfg.mpg.padding = 0; | ||
1765 | 2128 | ||
1766 | if(read_samples(buffer, samp_per_frame<<1) == 0) | 2129 | cfg.mean_bits = (8 * cfg.byte_per_frame + 8 * cfg.mpg.padding |
1767 | break; | 2130 | - cfg.sideinfo_len) / cfg.granules / cfg.channels; |
1768 | 2131 | ||
1769 | buffer_window[0] = &buffer[-2]; | 2132 | /* shift out old samples */ |
1770 | buffer_window[1] = &buffer[-1]; | 2133 | memcpy(mfbuf, mfbuf + 2*cfg.granules*576, 4*512); |
1771 | 2134 | ||
1772 | if(frac_slots_per_frame) | 2135 | /* read new samples to iram for further processing */ |
1773 | { | 2136 | if(read_samples((uint32*)(mfbuf + 2*512), SAMP_PER_FRAME) == 0) |
1774 | if(slot_lag > frac_slots_per_frame - 64) | 2137 | break; |
1775 | { /* No padding for this frame */ | 2138 | |
1776 | slot_lag -= frac_slots_per_frame; | 2139 | /* swap bytes if neccessary */ |
1777 | config.mpeg.padding = 0; | 2140 | if(cfg.byte_order == order_bigEndian) |
2141 | for(i=0; i<SAMP_PER_FRAME; i++) | ||
2142 | { | ||
2143 | uint32 t = ((uint32*)mfbuf)[512 + i]; | ||
2144 | t = ((t >> 8) & 0xff00ff) | ((t << 8) & 0xff00ff00); | ||
2145 | ((uint32*)mfbuf)[512 + i] = t; | ||
1778 | } | 2146 | } |
1779 | else | 2147 | |
1780 | { /* Padding for this frame */ | 2148 | if(cfg.resample) /* downsample to half of original */ |
1781 | slot_lag += (64 - frac_slots_per_frame); | 2149 | for(i=2*512; i<2*512+2*SAMP_PER_FRAME; i+=4) |
1782 | config.mpeg.padding = 1; | 2150 | { |
2151 | mfbuf[i/2+512] = (short)(((int)mfbuf[i+0] + mfbuf[i+2]) >> 1); | ||
2152 | mfbuf[i/2+513] = (short)(((int)mfbuf[i+1] + mfbuf[i+3]) >> 1); | ||
1783 | } | 2153 | } |
1784 | } | ||
1785 | 2154 | ||
1786 | config.mpeg.bits_per_frame = 8 * (whole_slots_per_frame + config.mpeg.padding); | 2155 | if(cfg.channels == 1) /* mix left and right channels to mono */ |
1787 | mean_bits = (config.mpeg.bits_per_frame - sideinfo_len) >> 1; | 2156 | for(i=2*512; i<2*512+2*SAMP_PER_FRAME; i+=2) |
2157 | mfbuf[i] = mfbuf[i+1] = (short)(((int)mfbuf[i] + mfbuf[i+1]) >> 1); | ||
2158 | |||
2159 | cfg.ResvSize = 0; | ||
2160 | gr_cnt = cfg.granules * cfg.channels; | ||
2161 | CodedData.bitpos = cfg.sideinfo_len; /* leave space for mp3 header */ | ||
2162 | for(gr=0; gr<cfg.granules; gr++) | ||
2163 | { | ||
2164 | short *wk = mfbuf + 2*286 + gr*1152; | ||
2165 | |||
2166 | /* 16bit packed wav data can be windowed efficiently on coldfire */ | ||
2167 | window_subband1(wk, sb_data[0][1-gr][0], sb_data[1][1-gr][0]); | ||
2168 | |||
2169 | for(ch=0; ch<cfg.channels; ch++) | ||
2170 | { | ||
2171 | int band; | ||
2172 | int *mdct; | ||
1788 | 2173 | ||
1789 | /* polyphase filtering */ | 2174 | wk = mfbuf + 2*286 + gr*1152 + ch; |
1790 | for(gr=0; gr<2; gr++) | 2175 | |
1791 | for(channel=config.wave.channels; channel--; ) | 2176 | /* 36864=4*18*16*32 */ |
1792 | for(i=0; i<18; i++) | 2177 | for(k=0; k<18; k++, wk+=64) |
1793 | { | 2178 | { |
1794 | filter_subband(buffer_window[channel], &sb_sample[channel][gr+1][i][0], channel); | 2179 | window_subband2(wk, sb_data[ch][1-gr][k]); |
1795 | buffer_window[channel] += 64; | 2180 | /* Compensate for inversion in the analysis filter */ |
2181 | if(k & 1) | ||
2182 | for(band=1; band<32; band+=2) | ||
2183 | sb_data[ch][1-gr][k][band] *= -1; | ||
1796 | } | 2184 | } |
1797 | 2185 | ||
1798 | mdct_sub_int(sb_sample, mdct_freq); | 2186 | /* Perform imdct of 18 previous + 18 current subband samples */ |
1799 | /* bit and noise allocation */ | 2187 | /* for integer precision do this loop twice (if neccessary) */ |
1800 | iteration_loop(mdct_freq, cod_info, mean_bits); | 2188 | shift = k = 14; |
1801 | /* write the frame to the bitstream */ | 2189 | for(ii=0; ii<2 && k; ii++) |
1802 | format_bitstream(enc_data, cod_info, mdct_freq); | 2190 | { |
1803 | } | 2191 | mdct = mdct_freq; |
1804 | /* write last chunks to disk */ | 2192 | cfg.cod_info[gr][ch].additStep = 4 * (14 - shift); |
1805 | rb->write(*mp3file, enc_buffer, enc_chunk*256*sizeof(uint32)); | 2193 | for(band=0; band<cfg.mpg.num_bands; band++, mdct+=18) |
1806 | } | 2194 | { |
2195 | int *band0 = sb_data[ch][ gr][0] + order[band]; | ||
2196 | int *band1 = sb_data[ch][1-gr][0] + order[band]; | ||
2197 | int work[18]; | ||
2198 | |||
2199 | /* 9216=4*32*9*8 */ | ||
2200 | for(k=-9; k<0; k++) | ||
2201 | { | ||
2202 | int a = shft_n(band1[(k+9)*32], shift); | ||
2203 | int b = shft_n(band1[(8-k)*32], shift); | ||
2204 | int c = shft_n(band0[(k+9)*32], shift); | ||
2205 | int d = shft_n(band0[(8-k)*32], shift); | ||
1807 | 2206 | ||
1808 | static int find_bitrate_index(int bitr) | 2207 | work[k+ 9] = shft16(a * win[k+ 9][0] + b * win[k+ 9][1] |
1809 | { | 2208 | + c * win[k+ 9][2] + d * win[k+ 9][3]); |
1810 | static long mpeg1[15] = {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320}; | ||
1811 | int i; | ||
1812 | 2209 | ||
1813 | for(i=0;i<15;i++) | 2210 | work[k+18] = shft16(c * win[k+18][0] + d * win[k+18][1] |
1814 | if(bitr==mpeg1[i]) return i; | 2211 | + a * win[k+18][2] + b * win[k+18][3]); |
2212 | } | ||
1815 | 2213 | ||
1816 | return -1; | 2214 | /* 7200=4*18*100 */ |
1817 | } | 2215 | mdct_long(mdct, work); |
2216 | |||
2217 | /* Perform aliasing reduction butterfly */ | ||
2218 | if(band != 0) | ||
2219 | for(k=7; k>=0; --k) | ||
2220 | { | ||
2221 | int bu, bd; | ||
2222 | bu = shft15(mdct[k]) * ca[k] + shft15(mdct[-1-k]) * cs[k]; | ||
2223 | bd = shft15(mdct[k]) * cs[k] - shft15(mdct[-1-k]) * ca[k]; | ||
2224 | mdct[-1-k] = bu; | ||
2225 | mdct[ k ] = bd; | ||
2226 | } | ||
2227 | } | ||
2228 | |||
2229 | max = min = 0; | ||
2230 | for(k=0; k<576; k++) | ||
2231 | { | ||
2232 | mdct_freq[k] = shft13(mdct_freq[k]); | ||
2233 | if(max < mdct_freq[k]) max = mdct_freq[k]; | ||
2234 | if(min > mdct_freq[k]) min = mdct_freq[k]; | ||
2235 | } | ||
2236 | |||
2237 | max = (max > -min) ? max : -min; | ||
2238 | cfg.cod_info[gr][ch].max_val = (long)max; | ||
2239 | |||
2240 | /* calc new shift for higher integer precision */ | ||
2241 | for(k=0; max<(0x3c00>>k); k++); | ||
2242 | shift = 12 - k; | ||
2243 | } | ||
1818 | 2244 | ||
1819 | static int find_samplerate_index(long freq) | 2245 | cfg.cod_info[gr][ch].quantStep += cfg.cod_info[gr][ch].additStep; |
1820 | { | ||
1821 | static long mpeg1[3] = {44100, 48000, 32000}; | ||
1822 | int i; | ||
1823 | 2246 | ||
1824 | for(i=0;i<3;i++) | 2247 | /* bit and noise allocation */ |
1825 | if(freq==mpeg1[i]) return i; | 2248 | iteration_loop(mdct_freq, &cfg.cod_info[gr][ch], gr_cnt--); |
2249 | /* write the frame to the bitstream */ | ||
2250 | Huffmancodebits(enc_data, mdct_freq, &cfg.cod_info[gr][ch]); | ||
1826 | 2251 | ||
1827 | return -1; | 2252 | cfg.cod_info[gr][ch].quantStep -= cfg.cod_info[gr][ch].additStep; |
2253 | |||
2254 | if(cfg.granules == 1) | ||
2255 | memcpy(sb_data[ch][0], sb_data[ch][1], sizeof(sb_data[ch][0])); | ||
2256 | } | ||
2257 | } | ||
2258 | |||
2259 | enc_size = (CodedData.bitpos + 7) >> 3; | ||
2260 | /* finish this chunk by adding sideinfo header data */ | ||
2261 | CodedData.bitpos = 0; | ||
2262 | encodeSideInfo( cfg.cod_info ); | ||
2263 | |||
2264 | if(cfg.byte_order != order_bigEndian) | ||
2265 | for(i=0; i<(enc_size+3)/4; i++) | ||
2266 | CodedData.bbuf[i] = myswap32(CodedData.bbuf[i]); | ||
2267 | |||
2268 | if(enc_chunk + enc_size > 65536) | ||
2269 | { | ||
2270 | /* copy iram mp3 buffer to sdram/file */ | ||
2271 | rb->write(mp3file, enc_buffer, enc_chunk & ~3); | ||
2272 | memcpy(enc_buffer, enc_buffer + (enc_chunk >> 2), enc_chunk & 3); | ||
2273 | enc_chunk &= 3; | ||
2274 | } | ||
2275 | |||
2276 | memcpy((char*)enc_buffer + enc_chunk, CodedData.bbuf, enc_size); | ||
2277 | enc_chunk += enc_size; | ||
2278 | frames++; | ||
2279 | } | ||
2280 | /* write last chunks to disk */ | ||
2281 | rb->write(mp3file, enc_buffer, enc_chunk); | ||
1828 | } | 2282 | } |
1829 | 2283 | ||
1830 | 2284 | ||
@@ -1834,45 +2288,43 @@ char mp3_name[80]; | |||
1834 | 2288 | ||
1835 | void read_wav_files(char *dirname) | 2289 | void read_wav_files(char *dirname) |
1836 | { | 2290 | { |
1837 | DIR *dir = rb->opendir(dirname); | 2291 | DIR *dir = rb->opendir(dirname); |
1838 | 2292 | ||
1839 | if(!dir) | 2293 | if(!dir) |
1840 | return; | 2294 | return; |
1841 | 2295 | ||
1842 | while(true) | 2296 | while(true) |
1843 | { | 2297 | { |
1844 | struct dirent *entry; | 2298 | struct dirent *entry; |
1845 | 2299 | ||
1846 | entry = rb->readdir(dir); | 2300 | entry = rb->readdir(dir); |
1847 | if(!entry) | 2301 | if(!entry) |
1848 | break; | 2302 | break; |
1849 | 2303 | ||
1850 | if( !(entry->attribute & ATTR_DIRECTORY) ) | 2304 | if( !(entry->attribute & ATTR_DIRECTORY) ) |
1851 | { | 2305 | { |
1852 | int slen = rb->strlen(entry->d_name); | 2306 | int slen = rb->strlen(entry->d_name); |
1853 | 2307 | ||
1854 | /* add all wav audio files */ | 2308 | /* add all wav audio files */ |
1855 | if(!rb->strcasecmp(entry->d_name + slen - 4, ".wav")) | 2309 | if(!rb->strcasecmp(entry->d_name + slen - 4, ".wav")) |
1856 | { | 2310 | { |
1857 | if(num_file >= 12) | 2311 | if(num_file >= 12) |
1858 | break; | 2312 | break; |
1859 | 2313 | ||
1860 | rb->strncpy(filename[num_file], dirname, 79); | 2314 | rb->strncpy(filename[num_file], dirname, 79); |
1861 | slen = rb->strlen(filename[num_file]); | 2315 | slen = rb->strlen(filename[num_file]); |
1862 | rb->strncpy(filename[num_file++] + slen, entry->d_name, 79); | 2316 | rb->strncpy(filename[num_file++] + slen, entry->d_name, 79); |
1863 | } | 2317 | } |
1864 | } | ||
1865 | } | 2318 | } |
1866 | rb->closedir(dir); | 2319 | } |
2320 | rb->closedir(dir); | ||
1867 | } | 2321 | } |
1868 | 2322 | ||
1869 | char *get_mp3_filename(char *wav_name) | 2323 | void get_mp3_filename(char *wav_name) |
1870 | { | 2324 | { |
1871 | int slen = rb->strlen(wav_name); | 2325 | int slen = rb->strlen(wav_name); |
1872 | rb->strncpy(mp3_name, wav_name, 79); | 2326 | rb->strncpy(mp3_name, wav_name, 79); |
1873 | rb->strncpy(mp3_name + slen - 4, ".mp3", 5); | 2327 | rb->strncpy(mp3_name + slen - 4, ".mp3", 5); |
1874 | |||
1875 | return mp3_name; | ||
1876 | } | 2328 | } |
1877 | 2329 | ||
1878 | #if CONFIG_KEYPAD == IRIVER_H100_PAD || CONFIG_KEYPAD == IRIVER_H300_PAD | 2330 | #if CONFIG_KEYPAD == IRIVER_H100_PAD || CONFIG_KEYPAD == IRIVER_H300_PAD |
@@ -1902,16 +2354,20 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
1902 | { | 2354 | { |
1903 | int fil, sfil, nfil; /* for file selection */ | 2355 | int fil, sfil, nfil; /* for file selection */ |
1904 | int rat, srat, nrat; /* for rate selection */ | 2356 | int rat, srat, nrat; /* for rate selection */ |
1905 | int i, cont, butt; | 2357 | int cont = 1, butt; |
1906 | long tim = 0; | 2358 | long tim = 0; |
1907 | char stg[40]; | 2359 | char stg[40]; |
1908 | char *bitratename[] = { "64","80","96","112","128","160","192","224","256","320" }; | 2360 | char* bstrg[] = {"64","80","96","112","128","160","192","224","256","320"}; |
1909 | int brate[] = { 64,80,96,112,128,160,192,224,256,320 }; | 2361 | int brate[] = { 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 }; |
1910 | 2362 | ||
1911 | (void)parameter; | 2363 | (void)parameter; |
1912 | rb = api; | 2364 | rb = api; |
1913 | 2365 | ||
1914 | #ifdef USE_IRAM | 2366 | #ifdef CPU_COLDFIRE |
2367 | asm volatile ("move.l #0, %macsr"); /* integer mode */ | ||
2368 | #endif | ||
2369 | |||
2370 | #ifdef USE_IRAM | ||
1915 | memcpy(iramstart, iramcopy, iramend - iramstart); | 2371 | memcpy(iramstart, iramcopy, iramend - iramstart); |
1916 | memset(iedata, 0, iend - iedata); | 2372 | memset(iedata, 0, iend - iedata); |
1917 | #endif | 2373 | #endif |
@@ -1923,31 +2379,40 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
1923 | #endif | 2379 | #endif |
1924 | rb->button_clear_queue(); | 2380 | rb->button_clear_queue(); |
1925 | 2381 | ||
1926 | read_wav_files("/"); | 2382 | /* check 'viewer' or 'plugin' call */ |
1927 | read_wav_files(REC_BASE_DIR"/"); | 2383 | if(parameter == NULL || *(char*)parameter == 0) |
2384 | { | ||
2385 | read_wav_files("/"); | ||
2386 | read_wav_files(REC_BASE_DIR"/"); | ||
1928 | 2387 | ||
1929 | nfil = num_file - 1; | 2388 | nfil = num_file - 1; |
1930 | sfil = 0; /* set first file as default */ | 2389 | sfil = 0; /* set first file as default */ |
1931 | cont = 1; | ||
1932 | 2390 | ||
1933 | while(cont && (butt = rb->button_get_w_tmo(HZ/10)) != MP3ENC_SELECT) | 2391 | while(cont && (butt = rb->button_get_w_tmo(HZ/10)) != MP3ENC_SELECT) |
1934 | { | ||
1935 | switch(butt) | ||
1936 | { | 2392 | { |
1937 | case MP3ENC_DONE: cont = 0; break; | 2393 | switch(butt) |
1938 | case MP3ENC_PREV: if(sfil > 0 ) sfil--; break; | 2394 | { |
1939 | case MP3ENC_NEXT: if(sfil < nfil) sfil++; break; | 2395 | case MP3ENC_DONE: cont = 0; break; |
1940 | } | 2396 | case MP3ENC_PREV: if(sfil > 0 ) sfil--; break; |
2397 | case MP3ENC_NEXT: if(sfil < nfil) sfil++; break; | ||
2398 | } | ||
1941 | 2399 | ||
1942 | rb->lcd_clear_display(); | 2400 | rb->lcd_clear_display(); |
1943 | rb->lcd_putsxy(2, 2, "-- Select WAV-File --"); | 2401 | rb->lcd_putsxy(2, 2, "-- Select WAV-File --"); |
1944 | 2402 | ||
1945 | for(fil=0; fil<=nfil; fil++) | 2403 | for(fil=0; fil<=nfil; fil++) |
1946 | rb->lcd_putsxy(2, 12 + fil*8, filename[fil]); | 2404 | rb->lcd_putsxy(2, 12 + fil*8, filename[fil]); |
1947 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | 2405 | |
1948 | rb->lcd_fillrect(0, 12 + sfil*8, 127, 8); | 2406 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); |
1949 | rb->lcd_set_drawmode(DRMODE_SOLID); | 2407 | rb->lcd_fillrect(0, 12 + sfil*8, 127, 8); |
1950 | rb->lcd_update(); | 2408 | rb->lcd_set_drawmode(DRMODE_SOLID); |
2409 | rb->lcd_update(); | ||
2410 | } | ||
2411 | } | ||
2412 | else | ||
2413 | { | ||
2414 | sfil = 0; | ||
2415 | rb->strncpy(filename[0], (char*)parameter, 79); | ||
1951 | } | 2416 | } |
1952 | 2417 | ||
1953 | nrat = 9; | 2418 | nrat = 9; |
@@ -1966,58 +2431,45 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
1966 | rb->lcd_putsxy(2, 2, "-- Select Bitrate --"); | 2431 | rb->lcd_putsxy(2, 2, "-- Select Bitrate --"); |
1967 | 2432 | ||
1968 | for(rat=0; rat<=nrat; rat++) | 2433 | for(rat=0; rat<=nrat; rat++) |
1969 | rb->lcd_putsxy(2, 12 + rat*8, bitratename[rat]); | 2434 | rb->lcd_putsxy(2, 12 + rat*8, bstrg[rat]); |
1970 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | 2435 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); |
1971 | rb->lcd_fillrect(0, 12 + srat*8, 127, 8); | 2436 | rb->lcd_fillrect(0, 12 + srat*8, 127, 8); |
1972 | rb->lcd_set_drawmode(DRMODE_SOLID); | 2437 | rb->lcd_set_drawmode(DRMODE_SOLID); |
1973 | rb->lcd_update(); | 2438 | rb->lcd_update(); |
1974 | } | 2439 | } |
1975 | 2440 | ||
1976 | config.infile = filename[sfil]; | 2441 | wav_filename = filename[sfil]; |
1977 | config.outfile = get_mp3_filename(filename[sfil]); | ||
1978 | #ifdef ROCKBOX_LITTLE_ENDIAN | ||
1979 | config.byte_order = order_littleEndian; | ||
1980 | #else | ||
1981 | config.byte_order = order_bigEndian; | ||
1982 | #endif | ||
1983 | config.mpeg.type = 1; | ||
1984 | config.mpeg.layr = 2; | ||
1985 | config.mpeg.mode = 0; | ||
1986 | config.mpeg.bitr = brate[srat]; | ||
1987 | config.mpeg.emph = 0; | ||
1988 | config.mpeg.crc = 0; | ||
1989 | config.mpeg.ext = 0; | ||
1990 | config.mpeg.mode_ext = 0; | ||
1991 | config.mpeg.copyright = 0; | ||
1992 | config.mpeg.original = 1; | ||
1993 | config.mpeg.bitrate_index = find_bitrate_index(config.mpeg.bitr); | ||
1994 | 2442 | ||
1995 | if(cont) | 2443 | if(cont) |
1996 | { | 2444 | { |
1997 | if((i=wave_open()) == 0) | 2445 | if(wave_open() == 0) |
1998 | { | 2446 | { |
1999 | config.mpeg.samplerate_index = find_samplerate_index(config.wave.samplerate); | 2447 | init_mp3_encoder_engine(true, brate[srat], cfg.samplerate); |
2448 | get_mp3_filename(wav_filename); | ||
2449 | mp3file = rb->open(mp3_name , O_WRONLY|O_CREAT|O_TRUNC); | ||
2450 | frames = 0; | ||
2000 | 2451 | ||
2001 | tim = *rb->current_tick; | 2452 | tim = *rb->current_tick; |
2002 | compress(); | 2453 | compress(); |
2003 | tim = *rb->current_tick - tim; | 2454 | tim = *rb->current_tick - tim; |
2004 | 2455 | ||
2005 | wave_close(); | 2456 | rb->close(wavfile); |
2006 | rb->close(*mp3file); | 2457 | rb->close(mp3file); |
2007 | } | 2458 | } |
2008 | else | 2459 | else |
2009 | { | 2460 | { |
2010 | rb->snprintf(stg, 20, "WaveOpen failed: %d", i); | 2461 | rb->close(wavfile); |
2462 | rb->snprintf(stg, 20, "WaveOpen failed %d", wave_open()); | ||
2011 | rb->lcd_putsxy(0, 20, stg); | 2463 | rb->lcd_putsxy(0, 20, stg); |
2012 | rb->lcd_update(); | 2464 | rb->lcd_update(); |
2013 | rb->sleep(2*HZ); | 2465 | rb->sleep(5*HZ); |
2014 | } | 2466 | } |
2015 | 2467 | ||
2016 | rb->lcd_clear_display(); | 2468 | rb->lcd_clear_display(); |
2017 | rb->snprintf(stg, 30, " Conversion: %d.%02ds ", tim/100, tim%100); | 2469 | rb->snprintf(stg, 30, " Conversion: %d.%02ds ", tim/100, tim%100); |
2018 | rb->lcd_putsxy(0, 30, stg); | 2470 | rb->lcd_putsxy(0, 30, stg); |
2019 | tim = frames_processed * samp_per_frame * 100 / 44100; /* unit=.01s */ | 2471 | tim = frames * SAMP_PER_FRAME * 100 / 44100; /* unit=.01s */ |
2020 | rb->snprintf(stg, 30, " WAV-Length: %d.%02ds ", tim/100, tim%100); | 2472 | rb->snprintf(stg, 30, " WAV-Length: %d.%02ds ", tim/100, tim%100); |
2021 | rb->lcd_putsxy(0, 20, stg); | 2473 | rb->lcd_putsxy(0, 20, stg); |
2022 | rb->lcd_update(); | 2474 | rb->lcd_update(); |
2023 | rb->sleep(5*HZ); | 2475 | rb->sleep(5*HZ); |