Changeset 161 for libmpc/branches/r2d/libmpcenc
- Timestamp:
- 12/18/06 20:52:54 (18 years ago)
- Location:
- libmpc/branches/r2d/libmpcenc
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/branches/r2d/libmpcenc/bitstream.c
r149 r161 25 25 unsigned long crc32(unsigned char *buf, int len); 26 26 27 #define MAX_ENUM 32 28 29 static const mpc_uint32_t Cnk[MAX_ENUM / 2][MAX_ENUM] = 30 { 31 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, 32 {0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465}, 33 {0, 0, 0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 364, 455, 560, 680, 816, 969, 1140, 1330, 1540, 1771, 2024, 2300, 2600, 2925, 3276, 3654, 4060, 4495}, 34 {0, 0, 0, 0, 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 8855, 10626, 12650, 14950, 17550, 20475, 23751, 27405, 31465}, 35 {0, 0, 0, 0, 0, 1, 6, 21, 56, 126, 252, 462, 792, 1287, 2002, 3003, 4368, 6188, 8568, 11628, 15504, 20349, 26334, 33649, 42504, 53130, 65780, 80730, 98280, 118755, 142506, 169911}, 36 {0, 0, 0, 0, 0, 0, 1, 7, 28, 84, 210, 462, 924, 1716, 3003, 5005, 8008, 12376, 18564, 27132, 38760, 54264, 74613, 100947, 134596, 177100, 230230, 296010, 376740, 475020, 593775, 736281}, 37 {0, 0, 0, 0, 0, 0, 0, 1, 8, 36, 120, 330, 792, 1716, 3432, 6435, 11440, 19448, 31824, 50388, 77520, 116280, 170544, 245157, 346104, 480700, 657800, 888030, 1184040, 1560780, 2035800, 2629575}, 38 {0, 0, 0, 0, 0, 0, 0, 0, 1, 9, 45, 165, 495, 1287, 3003, 6435, 12870, 24310, 43758, 75582, 125970, 203490, 319770, 490314, 735471, 1081575, 1562275, 2220075, 3108105, 4292145, 5852925, 7888725}, 39 {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 10, 55, 220, 715, 2002, 5005, 11440, 24310, 48620, 92378, 167960, 293930, 497420, 817190, 1307504, 2042975, 3124550, 4686825, 6906900, 10015005, 14307150, 20160075}, 40 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 11, 66, 286, 1001, 3003, 8008, 19448, 43758, 92378, 184756, 352716, 646646, 1144066, 1961256, 3268760, 5311735, 8436285, 13123110, 20030010, 30045015, 44352165}, 41 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 12, 78, 364, 1365, 4368, 12376, 31824, 75582, 167960, 352716, 705432, 1352078, 2496144, 4457400, 7726160, 13037895, 21474180, 34597290, 54627300, 84672315}, 42 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 13, 91, 455, 1820, 6188, 18564, 50388, 125970, 293930, 646646, 1352078, 2704156, 5200300, 9657700, 17383860, 30421755, 51895935, 86493225, 141120525}, 43 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 14, 105, 560, 2380, 8568, 27132, 77520, 203490, 497420, 1144066, 2496144, 5200300, 10400600, 20058300, 37442160, 67863915, 119759850, 206253075}, 44 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 15, 120, 680, 3060, 11628, 38760, 116280, 319770, 817190, 1961256, 4457400, 9657700, 20058300, 40116600, 77558760, 145422675, 265182525}, 45 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 16, 136, 816, 3876, 15504, 54264, 170544, 490314, 1307504, 3268760, 7726160, 17383860, 37442160, 77558760, 155117520, 300540195}, 46 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 17, 153, 969, 4845, 20349, 74613, 245157, 735471, 2042975, 5311735, 13037895, 30421755, 67863915, 145422675, 300540195} 47 }; 48 49 static const mpc_uint8_t Cnk_len[MAX_ENUM / 2][MAX_ENUM] = 50 { 51 {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, 52 {0, 0, 2, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9}, 53 {0, 0, 0, 2, 4, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13}, 54 {0, 0, 0, 0, 3, 4, 6, 7, 7, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 16}, 55 {0, 0, 0, 0, 0, 3, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18}, 56 {0, 0, 0, 0, 0, 0, 3, 5, 7, 8, 9, 10, 11, 12, 13, 13, 14, 15, 15, 16, 16, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20}, 57 {0, 0, 0, 0, 0, 0, 0, 3, 6, 7, 9, 10, 11, 12, 13, 14, 15, 15, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 21, 22, 22}, 58 {0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 8, 9, 11, 12, 13, 14, 15, 16, 17, 17, 18, 19, 19, 20, 21, 21, 22, 22, 23, 23, 23, 24}, 59 {0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 8, 10, 11, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 21, 22, 23, 23, 24, 24, 25, 25}, 60 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 9, 10, 12, 13, 15, 16, 17, 18, 19, 20, 21, 21, 22, 23, 24, 24, 25, 25, 26, 26}, 61 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 9, 11, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 23, 24, 25, 26, 26, 27, 27}, 62 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 9, 11, 13, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 25, 26, 27, 28, 28}, 63 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 10, 12, 14, 15, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 27, 28, 29}, 64 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 10, 12, 14, 16, 17, 19, 20, 21, 23, 24, 25, 26, 27, 28, 28, 29}, 65 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 10, 12, 14, 16, 18, 19, 21, 22, 23, 25, 26, 27, 28, 29, 30}, 66 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 10, 13, 15, 17, 18, 20, 21, 23, 24, 25, 27, 28, 29, 30} 67 68 }; 69 70 static const mpc_uint32_t Cnk_lost[MAX_ENUM / 2][MAX_ENUM] = 71 { 72 {0, 0, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, 73 {0, 0, 1, 2, 6, 1, 11, 4, 28, 19, 9, 62, 50, 37, 23, 8, 120, 103, 85, 66, 46, 25, 3, 236, 212, 187, 161, 134, 106, 77, 47, 16}, 74 {0, 0, 0, 0, 6, 12, 29, 8, 44, 8, 91, 36, 226, 148, 57, 464, 344, 208, 55, 908, 718, 508, 277, 24, 1796, 1496, 1171, 820, 442, 36, 3697, 3232}, 75 {0, 0, 0, 0, 3, 1, 29, 58, 2, 46, 182, 17, 309, 23, 683, 228, 1716, 1036, 220, 3347, 2207, 877, 7529, 5758, 3734, 1434, 15218, 12293, 9017, 5363, 1303, 29576}, 76 {0, 0, 0, 0, 0, 2, 11, 8, 2, 4, 50, 232, 761, 46, 1093, 3824, 2004, 7816, 4756, 880, 12419, 6434, 31887, 23032, 12406, 65292, 50342, 32792, 12317, 119638, 92233, 60768}, 77 {0, 0, 0, 0, 0, 0, 1, 4, 44, 46, 50, 100, 332, 1093, 3187, 184, 4008, 14204, 5636, 26776, 11272, 56459, 30125, 127548, 85044, 31914, 228278, 147548, 49268, 454801, 312295, 142384}, 78 {0, 0, 0, 0, 0, 0, 0, 0, 28, 8, 182, 232, 332, 664, 1757, 4944, 13320, 944, 15148, 53552, 14792, 91600, 16987, 178184, 43588, 390776, 160546, 913112, 536372, 61352, 1564729, 828448}, 79 {0, 0, 0, 0, 0, 0, 0, 0, 7, 19, 91, 17, 761, 1093, 1757, 3514, 8458, 21778, 55490, 5102, 58654, 204518, 33974, 313105, 1015577, 534877, 1974229, 1086199, 4096463, 2535683, 499883, 6258916}, 80 {0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 9, 36, 309, 46, 3187, 4944, 8458, 16916, 38694, 94184, 230358, 26868, 231386, 789648, 54177, 1069754, 3701783, 1481708, 6762211, 2470066, 13394357, 5505632}, 81 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 62, 226, 23, 1093, 184, 13320, 21778, 38694, 77388, 171572, 401930, 953086, 135896, 925544, 3076873, 8340931, 3654106, 13524422, 3509417, 22756699, 2596624}, 82 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 50, 148, 683, 3824, 4008, 944, 55490, 94184, 171572, 343144, 745074, 1698160, 3931208, 662448, 3739321, 12080252, 32511574, 12481564, 49545413, 5193248}, 83 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 37, 57, 228, 2004, 14204, 15148, 5102, 230358, 401930, 745074, 1490148, 3188308, 7119516, 16170572, 3132677, 15212929, 47724503, 127314931, 42642616}, 84 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 23, 464, 1716, 7816, 5636, 53552, 58654, 26868, 953086, 1698160, 3188308, 6376616, 13496132, 29666704, 66353813, 14457878, 62182381, 189497312}, 85 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 8, 344, 1036, 4756, 26776, 14792, 204518, 231386, 135896, 3931208, 7119516, 13496132, 26992264, 56658968, 123012781, 3252931, 65435312}, 86 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 208, 220, 880, 11272, 91600, 33974, 789648, 925544, 662448, 16170572, 29666704, 56658968, 113317936, 236330717, 508019104}, 87 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 103, 55, 3347, 12419, 56459, 16987, 313105, 54177, 3076873, 3739321, 3132677, 66353813, 123012781, 236330717} 88 }; 89 90 static const mpc_uint8_t log2[32] = 91 { 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6}; 92 93 static const mpc_uint8_t log2_lost[32] = 94 { 0, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31}; 95 27 96 void emptyBits(mpc_encoder_t * e) 28 97 { … … 81 150 writeBits(e, 1, l); 82 151 writeBits(e, nb, k); 152 } 153 154 void encodeEnum(mpc_encoder_t * e, const mpc_uint32_t bits, const mpc_uint_t N) 155 { 156 mpc_uint32_t code = 0; 157 const mpc_uint32_t * C = Cnk[0]; 158 unsigned int n = 0, k = 0; 159 160 for( ; n < N; n++){ 161 if ((bits >> n) & 1) { 162 code += C[n]; 163 C += MAX_ENUM; 164 k++; 165 } 166 } 167 168 if (k == 0) return; 169 170 if (code < Cnk_lost[k-1][n-1]) 171 writeBits(e, code, Cnk_len[k-1][n-1] - 1); 172 else 173 writeBits(e, code + Cnk_lost[k-1][n-1], Cnk_len[k-1][n-1]); 174 } 175 176 void encodeLog(mpc_encoder_t * e, mpc_uint32_t value, mpc_uint32_t max) 177 { 178 if (value < log2_lost[max - 1]) 179 writeBits(e, value, log2[max - 1] - 1); 180 else 181 writeBits(e, value + log2_lost[max - 1], log2[max - 1]); 83 182 } 84 183 -
libmpc/branches/r2d/libmpcenc/encode_sv7.c
r150 r161 22 22 23 23 #include "libmpcenc.h" 24 #include <mpc/minimax.h> 24 25 25 26 // bitstream.c 26 27 void writeBits (mpc_encoder_t * e, mpc_uint32_t input, unsigned int bits ); 27 28 unsigned int encodeSize(mpc_uint64_t, char *, mpc_bool_t); 29 void encodeEnum(mpc_encoder_t * e, const mpc_uint32_t bits, const mpc_uint_t N); 30 void encodeLog(mpc_encoder_t * e, mpc_uint32_t value, mpc_uint32_t max); 28 31 void writeBlock ( mpc_encoder_t * e, const char * key, const mpc_bool_t addCRC); 29 32 … … 35 38 36 39 // huffsv7.c 37 extern Huffman_t HuffHdr [10]; // contains tables for SV7-header 38 extern Huffman_t HuffSCFI [ 4]; // contains tables for SV7-scalefactor select 39 extern Huffman_t HuffDSCF [16]; // contains tables for SV7-scalefactor coding 40 extern const Huffman_t* HuffQ [2] [8]; // points to tables for SV7-sample coding 40 extern const Huffman_t HuffBands [33]; 41 extern const Huffman_t HuffRes [2][17]; 42 extern Huffman_t HuffSCFI_1 [4]; // contains tables for SV7-scalefactor select 43 extern Huffman_t HuffSCFI_2 [16]; // contains tables for SV7-scalefactor select 44 extern Huffman_t HuffDSCF_1 [64]; // contains tables for SV7-scalefactor coding 45 extern Huffman_t HuffDSCF_2 [65]; // contains tables for SV7-scalefactor coding 46 extern const Huffman_t * HuffQ [2][8]; // points to tables for SV7-sample coding 47 extern const Huffman_t HuffQ9up [256]; 41 48 42 49 /* … … 61 68 int SCF_Index_R [32] [3]; // Scalefactor index for quantized subband values 62 69 63 64 70 // initialize SV8 65 71 void 66 72 Init_SV8 ( mpc_encoder_t * e ) 67 73 { 68 Init_Huffman_Encoder_SV7 ();69 74 Init_Skalenfaktoren (); 70 75 Klemm (); 71 76 72 e->pos = 0; 73 e->bitsCount = 0; 74 e->outputBits = 0; 75 e->bitsBuff = 0; 76 e->Overflows = 0; 77 e->seek_pos = 0; 78 e->block_cnt = 0; 77 memset(e, 0, sizeof(*e)); 79 78 e->seek_pwr = 1; 80 79 } … … 146 145 } 147 146 148 #define ENCODE_SCF1( new, old, rll ) \149 d = new - old + 7; \150 if ( d <= 14u && rll < 1) { \151 writeBits ( e, Table[d].Code, Table[d].Length ); \152 } else { \153 if ( new < 0 ) new = 0, e->Overflows++; \154 writeBits ( e, Table[15].Code, Table[15].Length ); \155 writeBits ( e, (unsigned int)new, 6 ); \156 rll = 0; \157 }158 159 #define ENCODE_SCFn( new, old, rll ) \160 d = new - old + 7; \161 if ( d <= 14u ) { \162 writeBits ( e, Table[d].Code, Table[d].Length ); \163 } else { \164 if ( new < 0 ) new = 0, e->Overflows++; \165 writeBits ( e, Table[15].Code, Table[15].Length ); \166 writeBits ( e, (unsigned int)new, 6 ); \167 rll = 0; \168 }169 170 171 147 // formatting and writing SV7-bitstream for one frame 172 148 void 173 WriteBitstream_SV7 ( mpc_encoder_t* e, 174 const int MaxBand, 175 const SubbandQuantTyp* Q ) 176 { 177 int n; 178 int k; 179 unsigned int d; 180 unsigned int idx; 181 unsigned int book; 182 const Huffman_t* Table; 183 const Huffman_t* Table0; 184 const Huffman_t* Table1; 185 int sum; 186 const unsigned int* q; 187 unsigned char SCFI_L [32]; 188 unsigned char SCFI_R [32]; 189 190 /************************************ Resolution *********************************/ 191 writeBits ( e, (unsigned int)Res_L[0], 4 ); // subband 0 192 writeBits ( e, (unsigned int)Res_R[0], 4 ); 193 if ( e->MS_Channelmode > 0 && !(Res_L[0]==0 && Res_R[0]==0) ) 194 writeBits ( e, MS_Flag[0] , 1 ); 195 196 Table = HuffHdr; // subband 1...MaxBand 197 for ( n = 1; n <= MaxBand; n++ ) { 198 d = Res_L[n] - Res_L[n-1] + 5; 199 if ( d <= 8u ) { 200 writeBits ( e, Table[d].Code, Table[d].Length ); 201 } 202 else { 203 writeBits ( e, Table[9].Code, Table[9].Length ); 204 writeBits ( e, Res_L[n] , 4 ); 205 } 206 207 d = Res_R[n] - Res_R[n-1] + 5; 208 if ( d <= 8u ) { 209 writeBits ( e, Table[d].Code, Table[d].Length ); 210 } 211 else { 212 writeBits ( e, Table[9].Code, Table[9].Length ); 213 writeBits ( e, Res_R[n] , 4 ); 214 } 215 if ( e->MS_Channelmode > 0 && !(Res_L[n]==0 && Res_R[n]==0) ) 216 writeBits ( e, MS_Flag[n], 1 ); 217 } 218 219 /************************************ SCF encoding type ***********************************/ 220 Table = HuffSCFI; 221 for ( n = 0; n <= MaxBand; n++ ) { 222 if ( Res_L[n] ) { 223 SCFI_L[n] = 2 * (SCF_Index_L[n][0] == SCF_Index_L[n][1]) + (SCF_Index_L[n][1] == SCF_Index_L[n][2]); 224 writeBits ( e, Table[SCFI_L[n]].Code, Table[SCFI_L[n]].Length ); 225 } 226 if ( Res_R[n] ) { 227 SCFI_R[n] = 2 * (SCF_Index_R[n][0] == SCF_Index_R[n][1]) + (SCF_Index_R[n][1] == SCF_Index_R[n][2]); 228 writeBits ( e, Table[SCFI_R[n]].Code, Table[SCFI_R[n]].Length ); 229 } 230 } 231 232 /************************************* SCF **********************************/ 233 Table = HuffDSCF; 234 for ( n = 0; n <= MaxBand; n++ ) { 235 if (e->framesInBlock == 0){ 149 writeBitstream_SV8 ( mpc_encoder_t* e, int MaxBand, const SubbandQuantTyp* Q ) 150 { 151 int n; 152 const Huffman_t * Table, * Tables[2]; 153 154 for( n = MaxBand; n >= 0; n--) 155 if (Res_L[n] != 0 || Res_R[n] != 0) break; 156 157 n++; 158 if (e->framesInBlock == 0) { 159 encodeLog(e, n, MaxBand); 160 MaxBand = e->MaxBand = n; 161 } else { 162 n = n - e->MaxBand; 163 MaxBand = e->MaxBand = n + e->MaxBand; 164 if (n < 0) n += 33; 165 writeBits(e, HuffBands[n].Code, HuffBands[n].Length); 166 } 167 168 /************************************ Resolution *********************************/ 169 170 if (MaxBand) { 171 writeBits(e, HuffRes[0][Res_L[MaxBand - 1]].Code, HuffRes[0][Res_L[MaxBand - 1]].Length); 172 writeBits(e, HuffRes[0][Res_R[MaxBand - 1]].Code, HuffRes[0][Res_R[MaxBand - 1]].Length); 173 for ( n = MaxBand - 2; n >= 0; n--) { 174 int tmp = Res_L[n] - Res_L[n + 1]; 175 if (tmp < 0) tmp += 17; 176 writeBits(e, HuffRes[Res_L[n + 1] > 2][tmp].Code, HuffRes[Res_L[n + 1] > 2][tmp].Length); 177 178 tmp = Res_R[n] - Res_R[n + 1]; 179 if (tmp < 0) tmp += 17; 180 writeBits(e, HuffRes[Res_R[n + 1] > 2][tmp].Code, HuffRes[Res_R[n + 1] > 2][tmp].Length); 181 } 182 183 if (e->MS_Channelmode > 0) { 184 mpc_uint32_t tmp = 0; 185 int cnt = 0, tot = 0; 186 for( n = 0; n < MaxBand; n++) { 187 if ( Res_L[n] != 0 || Res_R[n] != 0 ) { 188 tmp = (tmp << 1) | MS_Flag[n]; 189 cnt += MS_Flag[n]; 190 tot++; 191 } 192 } 193 encodeLog(e, cnt, tot); 194 if (cnt * 2 > tot) tmp = ~tmp; 195 encodeEnum(e, tmp, tot); 196 } 197 } 198 199 /************************************ SCF encoding type ***********************************/ 200 201 if (e->framesInBlock == 0){ 202 for( n = 0; n < 32; n++) 236 203 DSCF_RLL_L[n] = DSCF_RLL_R[n] = 1; // new block -> force key frame 237 } 238 239 if ( Res_L[n] ) { 240 switch ( SCFI_L[n] ) { 241 default: 242 ENCODE_SCF1 ( SCF_Index_L[n][0], SCF_Last_L [n] , DSCF_RLL_L[n] ); 243 ENCODE_SCFn ( SCF_Index_L[n][1], SCF_Index_L[n][0], DSCF_RLL_L[n] ); 244 ENCODE_SCFn ( SCF_Index_L[n][2], SCF_Index_L[n][1], DSCF_RLL_L[n] ); 245 SCF_Last_L[n] = SCF_Index_L[n][2]; 246 break; 247 case 1: 248 ENCODE_SCF1 ( SCF_Index_L[n][0], SCF_Last_L [n] , DSCF_RLL_L[n] ); 249 ENCODE_SCFn ( SCF_Index_L[n][1], SCF_Index_L[n][0], DSCF_RLL_L[n] ); 250 SCF_Last_L[n] = SCF_Index_L[n][1]; 251 break; 252 case 2: 253 ENCODE_SCF1 ( SCF_Index_L[n][0], SCF_Last_L[n] , DSCF_RLL_L[n] ); 254 ENCODE_SCFn ( SCF_Index_L[n][2], SCF_Index_L[n][0], DSCF_RLL_L[n] ); 255 SCF_Last_L[n] = SCF_Index_L[n][2]; 256 break; 257 case 3: 258 ENCODE_SCF1 ( SCF_Index_L[n][0], SCF_Last_L[n] , DSCF_RLL_L[n] ); 259 SCF_Last_L[n] = SCF_Index_L[n][0]; 260 break; 261 } 262 } 263 264 if ( Res_R[n] ) { 265 switch ( SCFI_R[n] ) { 266 default: 267 ENCODE_SCF1 ( SCF_Index_R[n][0], SCF_Last_R[n] , DSCF_RLL_R[n] ); 268 ENCODE_SCFn ( SCF_Index_R[n][1], SCF_Index_R[n][0], DSCF_RLL_R[n] ); 269 ENCODE_SCFn ( SCF_Index_R[n][2], SCF_Index_R[n][1], DSCF_RLL_R[n] ); 270 SCF_Last_R[n] = SCF_Index_R[n][2]; 271 break; 272 case 1: 273 ENCODE_SCF1 ( SCF_Index_R[n][0], SCF_Last_R[n] , DSCF_RLL_R[n] ); 274 ENCODE_SCFn ( SCF_Index_R[n][1], SCF_Index_R[n][0], DSCF_RLL_R[n] ); 275 SCF_Last_R[n] = SCF_Index_R[n][1]; 276 break; 277 case 2: 278 ENCODE_SCF1 ( SCF_Index_R[n][0], SCF_Last_R[n] , DSCF_RLL_R[n] ); 279 ENCODE_SCFn ( SCF_Index_R[n][2], SCF_Index_R[n][0], DSCF_RLL_R[n] ); 280 SCF_Last_R[n] = SCF_Index_R[n][2]; 281 break; 282 case 3: 283 ENCODE_SCF1 ( SCF_Index_R[n][0], SCF_Last_R[n] , DSCF_RLL_R[n] ); 284 SCF_Last_R[n] = SCF_Index_R[n][0]; 285 break; 286 } 287 } 288 } 289 290 /*********************************** Samples *********************************/ 291 for ( n = 0; n <= MaxBand; n++ ) { 292 293 sum = 0; 294 q = Q[n].L; 295 296 switch ( Res_L[n] ) { 297 case -1: 298 case 0: 299 break; 300 case 1: 301 Table0 = HuffQ [0][1]; 302 Table1 = HuffQ [1][1]; 303 for ( k = 0; k < 36; k += 3 ) { 304 idx = q[k+0] + 3*q[k+1] + 9*q[k+2]; 305 sum += Table0 [idx].Length; 306 sum -= Table1 [idx].Length; 307 } 308 book = sum >= 0; 309 writeBits ( e, book, 1 ); 310 Table = HuffQ [book][1]; 311 for ( k = 0; k < 36; k += 3 ) { 312 idx = q[k+0] + 3*q[k+1] + 9*q[k+2]; 313 writeBits ( e, Table[idx].Code, Table[idx].Length ); 314 } 315 break; 316 case 2: 317 Table0 = HuffQ [0][2]; 318 Table1 = HuffQ [1][2]; 319 for ( k = 0; k < 36; k += 2 ) { 320 idx = q[k+0] + 5*q[k+1]; 321 sum += Table0 [idx].Length; 322 sum -= Table1 [idx].Length; 323 } 324 book = sum >= 0; 325 writeBits ( e, book, 1 ); 326 Table = HuffQ [book][2]; 327 for ( k = 0; k < 36; k += 2 ) { 328 idx = q[k+0] + 5*q[k+1]; 329 writeBits ( e, Table[idx].Code, Table[idx].Length ); 330 } 331 break; 332 case 3: 333 case 4: 334 case 5: 335 case 6: 336 case 7: 337 Table0 = HuffQ [0][Res_L[n]]; 338 Table1 = HuffQ [1][Res_L[n]]; 339 for ( k = 0; k < 36; k++ ) { 340 sum += Table0 [q[k]].Length; 341 sum -= Table1 [q[k]].Length; 342 } 343 book = sum >= 0; 344 writeBits ( e, book, 1 ); 345 Table = HuffQ [book][Res_L[n]]; 346 for ( k = 0; k < 36; k++ ) { 347 idx = q[k]; 348 writeBits ( e, Table[idx].Code, Table[idx].Length ); 349 } 350 break; 351 default: 352 for ( k = 0; k < 36; k++ ) 353 writeBits ( e, q[k], Res_L[n]-1 ); 354 break; 355 } 356 357 sum = 0; 358 q = Q[n].R; 359 360 switch ( Res_R[n] ) { 361 case -1: 362 case 0: 363 break; 364 case 1: 365 Table0 = HuffQ [0][1]; 366 Table1 = HuffQ [1][1]; 367 for ( k = 0; k < 36; k += 3 ) { 368 idx = q[k+0] + 3*q[k+1] + 9*q[k+2]; 369 sum += Table0 [idx].Length; 370 sum -= Table1 [idx].Length; 371 } 372 book = sum >= 0; 373 writeBits ( e, book, 1 ); 374 Table = HuffQ [book][1]; 375 for ( k = 0; k < 36; k += 3 ) { 376 idx = q[k+0] + 3*q[k+1] + 9*q[k+2]; 377 writeBits ( e, Table[idx].Code, Table[idx].Length ); 378 } 379 break; 380 case 2: 381 Table0 = HuffQ [0][2]; 382 Table1 = HuffQ [1][2]; 383 for ( k = 0; k < 36; k += 2 ) { 384 idx = q[k+0] + 5*q[k+1]; 385 sum += Table0 [idx].Length; 386 sum -= Table1 [idx].Length; 387 } 388 book = sum >= 0; 389 writeBits ( e, book, 1 ); 390 Table = HuffQ [book][2]; 391 for ( k = 0; k < 36; k += 2 ) { 392 idx = q[k+0] + 5*q[k+1]; 393 writeBits ( e, Table[idx].Code, Table[idx].Length ); 394 } 395 break; 396 case 3: 397 case 4: 398 case 5: 399 case 6: 400 case 7: 401 Table0 = HuffQ [0][Res_R[n]]; 402 Table1 = HuffQ [1][Res_R[n]]; 403 for ( k = 0; k < 36; k++ ) { 404 sum += Table0 [q[k]].Length; 405 sum -= Table1 [q[k]].Length; 406 } 407 book = sum >= 0; 408 writeBits ( e, book, 1 ); 409 Table = HuffQ [book][Res_R[n]]; 410 for ( k = 0; k < 36; k++ ) { 411 idx = q[k]; 412 writeBits ( e, Table[idx].Code, Table[idx].Length ); 413 } 414 break; 415 default: 416 for ( k = 0; k < 36; k++ ) 417 writeBits ( e, q[k], Res_R[n] - 1 ); 418 break; 419 } 420 421 } 204 } 205 206 Tables[0] = HuffSCFI_1; 207 Tables[1] = HuffSCFI_2; 208 for ( n = 0; n < MaxBand; n++ ) { 209 int tmp = 0, cnt = -1; 210 if (Res_L[n]) { 211 tmp = (SCF_Index_L[n][1] == SCF_Index_L[n][0]) * 2 + (SCF_Index_L[n][2] == SCF_Index_L[n][1]); 212 cnt++; 213 } 214 if (Res_R[n]) { 215 tmp = (tmp << 2) | ((SCF_Index_R[n][1] == SCF_Index_R[n][0]) * 2 + (SCF_Index_R[n][2] == SCF_Index_R[n][1])); 216 cnt++; 217 } 218 if (cnt >= 0) 219 writeBits(e, Tables[cnt][tmp].Code, Tables[cnt][tmp].Length); 220 } 221 222 /************************************* SCF **********************************/ 223 224 for ( n = 0; n < MaxBand; n++ ) { 225 if ( Res_L[n] ) { 226 int m; 227 if (DSCF_RLL_L[n] == 1) { 228 writeBits(e, SCF_Index_L[n][0] + 6, 7); 229 DSCF_RLL_L[n] = 0; 230 } else { 231 unsigned int tmp = (SCF_Index_L[n][0] - SCF_Last_L[n] + 31) & 127; 232 if (tmp < 64) 233 writeBits(e, HuffDSCF_2[tmp].Code, HuffDSCF_2[tmp].Length); 234 else { 235 writeBits(e, HuffDSCF_2[64].Code, HuffDSCF_2[64].Length); 236 writeBits(e, tmp - 64, 6); 237 } 238 } 239 for( m = 0; m < 2; m++){ 240 if (SCF_Index_L[n][m+1] != SCF_Index_L[n][m]) { 241 unsigned int tmp = (SCF_Index_L[n][m+1] - SCF_Index_L[n][m] + 31) & 127; 242 if (tmp < 64) 243 writeBits(e, HuffDSCF_1[tmp].Code, HuffDSCF_1[tmp].Length); 244 else { 245 writeBits(e, HuffDSCF_1[31].Code, HuffDSCF_1[31].Length); 246 writeBits(e, tmp - 64, 6); 247 } 248 } 249 } 250 SCF_Last_L[n] = SCF_Index_L[n][2]; 251 } 252 if ( Res_R[n] ) { 253 int m; 254 if (DSCF_RLL_R[n] == 1) { 255 writeBits(e, SCF_Index_R[n][0] + 6, 7); 256 DSCF_RLL_R[n] = 0; 257 } else { 258 unsigned int tmp = (SCF_Index_R[n][0] - SCF_Last_R[n] + 31) & 127; 259 if (tmp < 64) 260 writeBits(e, HuffDSCF_2[tmp].Code, HuffDSCF_2[tmp].Length); 261 else { 262 writeBits(e, HuffDSCF_2[64].Code, HuffDSCF_2[64].Length); 263 writeBits(e, tmp - 64, 6); 264 } 265 } 266 for( m = 0; m < 2; m++){ 267 if (SCF_Index_R[n][m+1] != SCF_Index_R[n][m]) { 268 unsigned int tmp = (SCF_Index_R[n][m+1] - SCF_Index_R[n][m] + 31) & 127; 269 if (tmp < 64) 270 writeBits(e, HuffDSCF_1[tmp].Code, HuffDSCF_1[tmp].Length); 271 else { 272 writeBits(e, HuffDSCF_1[31].Code, HuffDSCF_1[31].Length); 273 writeBits(e, tmp - 64, 6); 274 } 275 } 276 } 277 SCF_Last_R[n] = SCF_Index_R[n][2]; 278 } 279 } 280 281 /*********************************** Samples *********************************/ 282 for ( n = 0; n < MaxBand; n++ ) { 283 int Res = Res_L[n]; 284 const unsigned int * q = Q[n].L; 285 static const unsigned int thres[] = {0, 0, 3, 7, 9, 1, 3, 4, 8}; 286 static const int HuffQ2_var[5*5*5] = 287 {6, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 6}; 288 289 do { 290 int k = 0, idx = 1, cnt = 0, sng; 291 switch ( Res ) { 292 case -1: 293 case 0: 294 break; 295 case 1: 296 Table = HuffQ [0][0]; 297 for( ; k < 36; ){ 298 int kmax = k + 18; 299 cnt = 0, sng = 0; 300 for ( ; k < kmax; k++) { 301 idx <<= 1; 302 if (q[k] != 1) { 303 cnt++; 304 idx |= 1; 305 sng = (sng << 1) | (q[k] >> 1); 306 } 307 } 308 writeBits(e, Table[cnt].Code, Table[cnt].Length); 309 if (cnt > 0) { 310 if (cnt > 9) idx = ~idx; 311 encodeEnum(e, idx, 18); 312 writeBits(e, sng, cnt); 313 } 314 } 315 break; 316 case 2: 317 Tables[0] = HuffQ [0][1]; 318 Tables[1] = HuffQ [1][1]; 319 idx = 2 * thres[Res]; 320 for ( ; k < 36; k += 3) { 321 int tmp = q[k] + 5*q[k+1] + 25*q[k+2]; 322 writeBits ( e, Tables[idx > thres[Res]][tmp].Code, 323 Tables[idx > thres[Res]][tmp].Length ); 324 idx = (idx >> 1) + HuffQ2_var[tmp]; 325 } 326 break; 327 case 3: 328 case 4: 329 Table = HuffQ [0][Res - 1]; 330 for ( ; k < 36; k += 2 ) { 331 int tmp = q[k] + thres[Res]*q[k+1]; 332 writeBits ( e, Table[tmp].Code, Table[tmp].Length ); 333 } 334 break; 335 case 5: 336 case 6: 337 case 7: 338 case 8: 339 Tables[0] = HuffQ [0][Res - 1]; 340 Tables[1] = HuffQ [1][Res - 1]; 341 idx = 2 * thres[Res]; 342 for ( ; k < 36; k++ ) { 343 int tmp = q[k] - (1 << (Res - 2)) + 1; 344 writeBits ( e, Tables[idx > thres[Res]][q[k]].Code, 345 Tables[idx > thres[Res]][q[k]].Length ); 346 if (tmp < 0) tmp = -tmp; 347 idx = (idx >> 1) + tmp; 348 } 349 break; 350 default: 351 for ( ; k < 36; k++ ) { 352 writeBits ( e, HuffQ9up[q[k] >> (Res - 9)].Code, 353 HuffQ9up[q[k] >> (Res - 9)].Length ); 354 if (Res != 9) 355 writeBits ( e, q[k] & ((1 << (Res - 9)) - 1), Res - 9); 356 } 357 break; 358 } 359 360 Res = Res_R[n]; 361 } while (q == Q[n].L && (q = Q[n].R)); 362 } 422 363 423 364 e->framesInBlock++; … … 432 373 } 433 374 434 #undef ENCODE_SCF1435 #undef ENCODE_SCFn436 437 438 375 #if 0 376 377 typedef struct { 378 int Symbol; 379 unsigned int Count; 380 unsigned int Code; 381 unsigned int Bits; 382 } huff_sym_t; 383 384 void _Huffman_MakeTree( huff_sym_t *sym, unsigned int num_symbols); 385 void _Huffman_PrintCodes(huff_sym_t * sym, unsigned int num_symbols, int print_type, int offset); 386 387 void print_histo(void) 388 { 389 int i, j; 390 huff_sym_t sym[HISTO_NB][HISTO_LEN]; 391 unsigned int dist[HISTO_NB]; 392 unsigned int size[HISTO_NB]; 393 unsigned int cnt[HISTO_NB]; 394 unsigned int total_cnt, total_size, full_count = 0, full_size = 0; 395 double optim_size, full_optim = 0; 396 397 return; 398 399 memset(dist, 1, sizeof dist); 400 memset(sym, 0, sizeof(huff_sym_t) * HISTO_LEN * HISTO_NB); 401 402 for(j = 0 ; j < HISTO_NB ; j++) { 403 for(i = 0 ; i < HISTO_LEN; i++) { 404 sym[j][i].Symbol = i; 405 sym[j][i].Count = histo[j][i]; 406 if (sym[j][i].Count == 0) 407 sym[j][i].Count = 1; 408 } 409 _Huffman_MakeTree(sym[j], HISTO_LEN); 410 _Huffman_PrintCodes(sym[j], HISTO_LEN, 3, 0); 411 _Huffman_PrintCodes(sym[j], HISTO_LEN, 0, 0); 412 _Huffman_PrintCodes(sym[j], HISTO_LEN, 1, 0); 413 total_cnt = 0; 414 total_size = 0; 415 optim_size = 0; 416 for( i = 0; i < HISTO_LEN; i++) { 417 total_cnt += sym[j][i].Count; 418 total_size += sym[j][i].Count * sym[j][i].Bits; 419 if (sym[j][i].Count != 0) 420 optim_size += sym[j][i].Count * __builtin_log2(sym[j][i].Count); 421 } 422 full_count += total_cnt; 423 full_size += total_size; 424 optim_size = total_cnt * __builtin_log2(total_cnt) - optim_size; 425 full_optim += optim_size; 426 size[j] = total_size; 427 cnt[j] = total_cnt; 428 printf("%u count : %u huff : %f bps ", j, total_cnt, (float)total_size / total_cnt); 429 printf("opt : %f bps ", (float)optim_size / total_cnt); 430 printf("loss : %f bps (%f %%)\n", (float)(total_size - optim_size) / total_cnt, (float)(total_size - optim_size) * 100 / optim_size); 431 for( i = 0; i < HISTO_LEN; i++){ 432 printf("%u ", sym[j][i].Bits); 433 } 434 435 printf("\n\n"); 436 } 437 printf("cnt : %u size %f optim %f\n", full_count, (float)full_size / full_count, (float)full_optim / full_count); 438 printf("loss : %f bps (%f %%)\n", (float)(full_size - full_optim) / full_count, (float)(full_size - full_optim) * 100 / full_optim); 439 440 441 printf("\n"); 442 } 443 439 444 void 440 445 Dump ( const unsigned int* q, const int Res ) -
libmpc/branches/r2d/libmpcenc/huffsv7.c
r78 r161 20 20 #include "libmpcenc.h" 21 21 22 Huffman_t HuffHdr [10]; // 9 bit 23 Huffman_t HuffSCFI [ 4]; // 3 bit 24 Huffman_t HuffDSCF [16]; // 6 bit 25 Huffman_t HuffQ1 [2] [ 3*3*3]; // 6+ 9 bit 26 Huffman_t HuffQ2 [2] [ 5*5]; // 7+10 bit 27 Huffman_t HuffQ3 [2] [ 7]; // 4+ 5 bit 28 Huffman_t HuffQ4 [2] [ 9]; // 4+ 5 bit 29 Huffman_t HuffQ5 [2] [15]; // 6+ 8 bit 30 Huffman_t HuffQ6 [2] [31]; // 7+13 bit 31 Huffman_t HuffQ7 [2] [63]; // 8+14 bit 32 // 4608 Bytes 33 mpc_uint8_t LUT1_0 [1<< 6]; 34 mpc_uint8_t LUT1_1 [1<< 9]; // 576 Bytes 35 mpc_uint8_t LUT2_0 [1<< 7]; 36 mpc_uint8_t LUT2_1 [1<<10]; // 1152 Bytes 37 mpc_uint8_t LUT3_0 [1<< 4]; 38 mpc_uint8_t LUT3_1 [1<< 5]; // 48 Bytes 39 mpc_uint8_t LUT4_0 [1<< 4]; 40 mpc_uint8_t LUT4_1 [1<< 5]; // 48 Bytes 41 mpc_uint8_t LUT5_0 [1<< 6]; 42 mpc_uint8_t LUT5_1 [1<< 8]; // 320 Bytes 43 mpc_uint8_t LUT6_0 [1<< 7]; 44 mpc_uint8_t LUT6_1 [1<< 7]; // 256 Bytes 45 mpc_uint8_t LUT7_0 [1<< 8]; 46 mpc_uint8_t LUT7_1 [1<< 8]; // 512 Bytes 47 mpc_uint8_t LUTDSCF [1<< 6]; // 64 Bytes = 2976 Bytes 22 const Huffman_t HuffBands [33] = { 23 {1, 1}, {1, 3}, {2, 5}, {2, 6}, {3, 7}, {3, 8}, {4, 8}, {4, 9}, {5, 10}, {6, 11}, {1, 12}, {2, 12}, {3, 12}, {0, 13}, {4, 12}, {5, 12}, {6, 12}, {7, 12}, {8, 12}, {1, 13}, {9, 12}, {10, 12}, {11, 12}, {7, 11}, {8, 11}, {9, 11}, {6, 10}, {7, 10}, {5, 9}, {5, 8}, {3, 6}, {3, 5}, {1, 2} 24 }; 25 26 const Huffman_t HuffRes [2] [17] = { 27 { 28 {1, 1}, {1, 2}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 9}, {1, 10}, {1, 11}, {1, 12}, {1, 13}, {1, 14}, {1, 15}, {0, 16}, {1, 16}, {1, 8}, {1, 3} 29 }, { 30 {1, 2}, {2, 2}, {1, 3}, {1, 5}, {1, 7}, {1, 8}, {1, 10}, {1, 12}, {0, 14}, {1, 14}, {2, 14}, {3, 14}, {1, 11}, {1, 9}, {1, 6}, {1, 4}, {3, 2} 31 } 32 }; 33 34 const Huffman_t HuffSCFI_1 [4] = { 35 {0, 3}, {1, 3}, {1, 1}, {1, 2} 36 }; 37 38 const Huffman_t HuffSCFI_2 [16] = { 39 {1, 6}, {0, 7}, {2, 6}, {3, 6}, {1, 7}, {3, 5}, {4, 5}, {5, 5}, {4, 6}, {6, 5}, {2, 2}, {2, 3}, {5, 6}, {7, 5}, {3, 3}, {3, 2} 40 }; 41 42 const Huffman_t HuffDSCF_1 [64] = { 43 {3, 12}, {4, 12}, {5, 12}, {4, 11}, {5, 11}, {6, 11}, {5, 10}, {6, 10}, {7, 10}, {8, 10}, {9, 10}, {7, 9}, {8, 9}, {9, 9}, {10, 9}, {7, 8}, {8, 8}, {9, 8}, {10, 8}, {7, 7}, {8, 7}, {9, 7}, {10, 7}, {6, 6}, {7, 6}, {5, 5}, {4, 4}, {5, 4}, {6, 5}, {6, 4}, {7, 4}, {10, 10}, {8, 4}, {5, 3}, {6, 3}, {7, 3}, {9, 4}, {7, 5}, {8, 6}, {9, 6}, {11, 7}, {11, 8}, {12, 8}, {13, 8}, {11, 9}, {12, 9}, {13, 9}, {11, 10}, {12, 10}, {13, 10}, {7, 11}, {8, 11}, {9, 11}, {6, 12}, {7, 12}, {3, 13}, {4, 13}, {5, 13}, {0, 14}, {1, 14}, {2, 14}, {3, 14}, {4, 14}, {5, 14} 44 }; 45 46 const Huffman_t HuffDSCF_2 [65] = { 47 {0, 15}, {3, 14}, {4, 14}, {4, 13}, {5, 13}, {6, 13}, {5, 12}, {6, 12}, {7, 12}, {8, 12}, {7, 11}, {8, 11}, {9, 11}, {10, 11}, {7, 10}, {8, 10}, {9, 10}, {10, 10}, {7, 9}, {8, 9}, {9, 9}, {6, 8}, {7, 8}, {5, 7}, {6, 7}, {4, 6}, {3, 5}, {3, 4}, {4, 4}, {3, 3}, {4, 3}, {5, 3}, {6, 3}, {7, 3}, {5, 4}, {4, 5}, {5, 5}, {5, 6}, {7, 7}, {8, 8}, {9, 8}, {10, 9}, {11, 9}, {11, 10}, {12, 10}, {13, 10}, {11, 11}, {12, 11}, {13, 11}, {9, 12}, {10, 12}, {11, 12}, {12, 12}, {7, 13}, {8, 13}, {9, 13}, {5, 14}, {6, 14}, {7, 14}, {1, 15}, {2, 15}, {3, 15}, {4, 15}, {5, 15}, {13, 12} 48 }; 49 50 static const Huffman_t HuffQ1 [19] = { 51 {1, 6}, {1, 4}, {2, 4}, {3, 3}, {4, 3}, {5, 3}, {6, 3}, {7, 3}, {3, 4}, {4, 4}, {5, 4}, {1, 5}, {1, 7}, {1, 8}, {1, 9}, {1, 10}, {1, 11}, {0, 12}, {1, 12} 52 }; 53 54 static const Huffman_t HuffQ2 [2] [5*5*5] = { 55 { 56 {2, 12}, {3, 11}, {15, 10}, {4, 11}, {0, 13}, {5, 11}, {12, 9}, {18, 8}, {13, 9}, {6, 11}, {7, 11}, {19, 8}, {21, 7}, {20, 8}, {8, 11}, {9, 11}, {14, 9}, {21, 8}, {15, 9}, {10, 11}, {3, 12}, {11, 11}, {16, 10}, {12, 11}, {1, 13}, {13, 11}, {16, 9}, {22, 8}, {17, 9}, {14, 11}, {18, 9}, {15, 6}, {16, 6}, {22, 7}, {19, 9}, {23, 8}, {17, 6}, {8, 4}, {18, 6}, {24, 8}, {20, 9}, {19, 6}, {20, 6}, {23, 7}, {21, 9}, {15, 11}, {22, 9}, {25, 8}, {23, 9}, {16, 11}, {17, 10}, {26, 8}, {24, 7}, {27, 8}, {18, 10}, {28, 8}, {21, 6}, {9, 4}, {22, 6}, {29, 8}, {25, 7}, {10, 4}, {7, 3}, {11, 4}, {26, 7}, {30, 8}, {23, 6}, {12, 4}, {24, 6}, {31, 8}, {19, 10}, {32, 8}, {27, 7}, {33, 8}, {20, 10}, {17, 11}, {24, 9}, {34, 8}, {25, 9}, {18, 11}, {26, 9}, {25, 6}, {26, 6}, {27, 6}, {27, 9}, {35, 8}, {28, 6}, {13, 4}, {29, 6}, {36, 8}, {28, 9}, {28, 7}, {30, 6}, {31, 6}, {29, 9}, {19, 11}, {30, 9}, {37, 8}, {31, 9}, {20, 11}, {2, 13}, {21, 11}, {21, 10}, {22, 11}, {4, 12}, {23, 11}, {32, 9}, {38, 8}, {33, 9}, {24, 11}, {22, 10}, {39, 8}, {29, 7}, {40, 8}, {25, 11}, {26, 11}, {34, 9}, {41, 8}, {35, 9}, {27, 11}, {3, 13}, {28, 11}, {23, 10}, {29, 11}, {5, 12} 57 }, { 58 {2, 11}, {3, 10}, {15, 9}, {4, 10}, {0, 12}, {5, 10}, {12, 8}, {13, 8}, {14, 8}, {6, 10}, {7, 10}, {15, 8}, {30, 7}, {16, 8}, {16, 9}, {8, 10}, {17, 8}, {18, 8}, {19, 8}, {9, 10}, {3, 11}, {10, 10}, {17, 9}, {11, 10}, {1, 12}, {12, 10}, {20, 8}, {21, 8}, {22, 8}, {13, 10}, {23, 8}, {18, 6}, {14, 5}, {19, 6}, {24, 8}, {25, 8}, {20, 6}, {15, 5}, {16, 5}, {26, 8}, {27, 8}, {21, 6}, {17, 5}, {22, 6}, {28, 8}, {14, 10}, {29, 8}, {30, 8}, {31, 8}, {15, 10}, {18, 9}, {32, 8}, {31, 7}, {33, 8}, {19, 9}, {34, 8}, {18, 5}, {19, 5}, {20, 5}, {35, 8}, {32, 7}, {21, 5}, {15, 4}, {22, 5}, {33, 7}, {36, 8}, {23, 5}, {24, 5}, {25, 5}, {37, 8}, {20, 9}, {38, 8}, {34, 7}, {39, 8}, {21, 9}, {16, 10}, {40, 8}, {41, 8}, {42, 8}, {17, 10}, {43, 8}, {23, 6}, {26, 5}, {24, 6}, {44, 8}, {45, 8}, {27, 5}, {28, 5}, {25, 6}, {46, 8}, {47, 8}, {26, 6}, {29, 5}, {27, 6}, {48, 8}, {18, 10}, {49, 8}, {50, 8}, {51, 8}, {19, 10}, {2, 12}, {20, 10}, {21, 10}, {22, 10}, {4, 11}, {23, 10}, {52, 8}, {53, 8}, {54, 8}, {24, 10}, {22, 9}, {55, 8}, {35, 7}, {56, 8}, {25, 10}, {26, 10}, {57, 8}, {58, 8}, {59, 8}, {27, 10}, {3, 12}, {28, 10}, {23, 9}, {29, 10}, {5, 11} 59 } 60 }; 61 62 static const Huffman_t HuffQ3 [49] = { 63 {0, 9}, {2, 8}, {5, 7}, {6, 7}, {7, 7}, {3, 8}, {1, 9}, {4, 8}, {9, 6}, {10, 6}, {10, 5}, {11, 6}, {8, 7}, {5, 8}, {9, 7}, {12, 6}, {8, 4}, {9, 4}, {11, 5}, {13, 6}, {10, 7}, {11, 7}, {12, 5}, {10, 4}, {7, 3}, {11, 4}, {13, 5}, {12, 7}, {13, 7}, {14, 6}, {14, 5}, {12, 4}, {13, 4}, {15, 6}, {14, 7}, {6, 8}, {16, 6}, {17, 6}, {15, 5}, {18, 6}, {19, 6}, {7, 8}, {2, 9}, {8, 8}, {15, 7}, {16, 7}, {17, 7}, {9, 8}, {3, 9} 64 }; 65 66 static const Huffman_t HuffQ4 [81] = { 67 {0, 10}, {2, 9}, {5, 8}, {12, 7}, {13, 7}, {6, 8}, {7, 8}, {3, 9}, {1, 10}, {4, 9}, {8, 8}, {14, 7}, {13, 6}, {14, 6}, {15, 6}, {15, 7}, {9, 8}, {5, 9}, {10, 8}, {16, 7}, {16, 6}, {17, 6}, {18, 5}, {18, 6}, {19, 6}, {17, 7}, {11, 8}, {12, 8}, {20, 6}, {21, 6}, {19, 5}, {20, 5}, {21, 5}, {22, 6}, {23, 6}, {13, 8}, {18, 7}, {24, 6}, {22, 5}, {23, 5}, {15, 4}, {24, 5}, {25, 5}, {25, 6}, {19, 7}, {14, 8}, {26, 6}, {27, 6}, {26, 5}, {27, 5}, {28, 5}, {28, 6}, {29, 6}, {15, 8}, {16, 8}, {20, 7}, {30, 6}, {31, 6}, {29, 5}, {32, 6}, {33, 6}, {21, 7}, {17, 8}, {6, 9}, {18, 8}, {22, 7}, {23, 7}, {34, 6}, {35, 6}, {24, 7}, {19, 8}, {7, 9}, {2, 10}, {8, 9}, {20, 8}, {21, 8}, {25, 7}, {22, 8}, {23, 8}, {9, 9}, {3, 10} 68 }; 69 70 static const Huffman_t HuffQ5 [2] [15] = { 71 { 72 {0, 7}, {1, 7}, {2, 6}, {2, 5}, {2, 4}, {2, 3}, {3, 3}, {3, 2}, {4, 3}, {5, 3}, {3, 4}, {3, 5}, {3, 6}, {2, 7}, {3, 7} 73 }, { 74 {0, 6}, {1, 6}, {2, 5}, {2, 4}, {3, 4}, {3, 3}, {4, 3}, {5, 3}, {6, 3}, {7, 3}, {4, 4}, {5, 4}, {3, 5}, {2, 6}, {3, 6} 75 } 76 }; 77 78 static const Huffman_t HuffQ6 [2] [31] = { 79 { 80 {0, 9}, {1, 9}, {2, 9}, {3, 9}, {4, 8}, {5, 8}, {4, 7}, {3, 6}, {4, 6}, {5, 6}, {5, 5}, {6, 5}, {4, 4}, {5, 4}, {4, 3}, {3, 2}, {5, 3}, {6, 4}, {7, 4}, {7, 5}, {6, 6}, {7, 6}, {8, 6}, {9, 6}, {5, 7}, {6, 8}, {7, 8}, {4, 9}, {5, 9}, {6, 9}, {7, 9} 81 }, { 82 {0, 8}, {1, 8}, {2, 7}, {3, 7}, {4, 7}, {4, 6}, {5, 6}, {4, 5}, {5, 5}, {6, 5}, {5, 4}, {6, 4}, {7, 4}, {8, 4}, {9, 4}, {10, 4}, {11, 4}, {12, 4}, {13, 4}, {14, 4}, {15, 4}, {7, 5}, {8, 5}, {9, 5}, {6, 6}, {7, 6}, {5, 7}, {6, 7}, {7, 7}, {2, 8}, {3, 8} 83 } 84 }; 85 86 static const Huffman_t HuffQ7 [2] [63] = { 87 { 88 {0, 10}, {1, 10}, {2, 10}, {8, 9}, {9, 9}, {3, 10}, {4, 10}, {5, 10}, {6, 10}, {7, 10}, {10, 9}, {11, 9}, {12, 9}, {13, 9}, {10, 8}, {11, 8}, {12, 8}, {13, 8}, {14, 8}, {10, 7}, {11, 7}, {12, 7}, {13, 7}, {14, 7}, {10, 6}, {11, 6}, {12, 6}, {8, 5}, {9, 5}, {6, 4}, {4, 3}, {3, 2}, {5, 3}, {7, 4}, {10, 5}, {11, 5}, {13, 6}, {14, 6}, {15, 6}, {15, 7}, {16, 7}, {17, 7}, {18, 7}, {15, 8}, {19, 7}, {16, 8}, {17, 8}, {18, 8}, {19, 8}, {14, 9}, {15, 9}, {16, 9}, {17, 9}, {8, 10}, {9, 10}, {10, 10}, {11, 10}, {12, 10}, {18, 9}, {19, 9}, {13, 10}, {14, 10}, {15, 10} 89 }, { 90 {0, 9}, {1, 9}, {2, 8}, {3, 8}, {4, 8}, {5, 8}, {6, 8}, {7, 8}, {8, 8}, {8, 7}, {9, 7}, {10, 7}, {11, 7}, {12, 7}, {9, 6}, {10, 6}, {11, 6}, {12, 6}, {13, 6}, {14, 6}, {15, 6}, {16, 6}, {12, 5}, {13, 5}, {14, 5}, {15, 5}, {16, 5}, {17, 5}, {18, 5}, {19, 5}, {20, 5}, {21, 5}, {22, 5}, {23, 5}, {24, 5}, {25, 5}, {26, 5}, {27, 5}, {28, 5}, {29, 5}, {30, 5}, {31, 5}, {17, 6}, {18, 6}, {19, 6}, {20, 6}, {21, 6}, {22, 6}, {23, 6}, {13, 7}, {14, 7}, {15, 7}, {16, 7}, {17, 7}, {9, 8}, {10, 8}, {11, 8}, {12, 8}, {13, 8}, {14, 8}, {15, 8}, {2, 9}, {3, 9} 91 } 92 }; 93 94 static const Huffman_t HuffQ8 [2] [127] = { 95 { 96 {3, 11}, {4, 11}, {10, 10}, {11, 10}, {12, 10}, {13, 10}, {14, 10}, {26, 9}, {15, 10}, {27, 9}, {16, 10}, {0, 12}, {1, 12}, {5, 11}, {6, 11}, {7, 11}, {8, 11}, {9, 11}, {10, 11}, {11, 11}, {17, 10}, {12, 11}, {18, 10}, {19, 10}, {20, 10}, {21, 10}, {22, 10}, {23, 10}, {24, 10}, {25, 10}, {28, 9}, {26, 10}, {27, 10}, {28, 10}, {29, 10}, {30, 10}, {29, 9}, {30, 9}, {31, 9}, {32, 9}, {33, 9}, {34, 9}, {35, 9}, {36, 9}, {25, 8}, {37, 9}, {26, 8}, {27, 8}, {28, 8}, {29, 8}, {30, 8}, {31, 8}, {20, 7}, {21, 7}, {22, 7}, {23, 7}, {14, 6}, {15, 6}, {16, 6}, {17, 6}, {11, 5}, {7, 4}, {4, 3}, {3, 2}, {5, 3}, {12, 5}, {13, 5}, {18, 6}, {19, 6}, {20, 6}, {21, 6}, {24, 7}, {25, 7}, {26, 7}, {27, 7}, {32, 8}, {33, 8}, {34, 8}, {35, 8}, {36, 8}, {37, 8}, {38, 8}, {39, 8}, {38, 9}, {39, 9}, {40, 9}, {41, 9}, {42, 9}, {43, 9}, {44, 9}, {45, 9}, {46, 9}, {31, 10}, {32, 10}, {47, 9}, {33, 10}, {34, 10}, {35, 10}, {36, 10}, {37, 10}, {38, 10}, {39, 10}, {40, 10}, {41, 10}, {13, 11}, {14, 11}, {42, 10}, {15, 11}, {16, 11}, {17, 11}, {18, 11}, {2, 12}, {19, 11}, {3, 12}, {4, 12}, {5, 12}, {43, 10}, {44, 10}, {48, 9}, {49, 9}, {45, 10}, {46, 10}, {47, 10}, {48, 10}, {49, 10}, {50, 10}, {51, 10} 97 }, { 98 {0, 9}, {1, 9}, {2, 9}, {3, 9}, {4, 8}, {5, 8}, {6, 8}, {7, 8}, {8, 8}, {9, 8}, {10, 8}, {11, 8}, {12, 8}, {13, 8}, {14, 8}, {15, 8}, {16, 8}, {17, 8}, {18, 8}, {19, 8}, {20, 8}, {21, 8}, {21, 7}, {22, 7}, {23, 7}, {24, 7}, {25, 7}, {26, 7}, {27, 7}, {28, 7}, {29, 7}, {30, 7}, {31, 7}, {32, 7}, {33, 7}, {34, 7}, {35, 7}, {36, 7}, {37, 7}, {38, 7}, {39, 7}, {40, 7}, {41, 7}, {42, 7}, {43, 7}, {44, 7}, {45, 7}, {46, 7}, {47, 7}, {48, 7}, {38, 6}, {39, 6}, {40, 6}, {41, 6}, {42, 6}, {43, 6}, {44, 6}, {45, 6}, {46, 6}, {47, 6}, {48, 6}, {49, 6}, {50, 6}, {51, 6}, {52, 6}, {53, 6}, {54, 6}, {55, 6}, {56, 6}, {57, 6}, {58, 6}, {59, 6}, {60, 6}, {61, 6}, {62, 6}, {49, 7}, {63, 6}, {50, 7}, {51, 7}, {52, 7}, {53, 7}, {54, 7}, {55, 7}, {56, 7}, {57, 7}, {58, 7}, {59, 7}, {60, 7}, {61, 7}, {62, 7}, {63, 7}, {64, 7}, {65, 7}, {66, 7}, {67, 7}, {68, 7}, {69, 7}, {70, 7}, {71, 7}, {72, 7}, {73, 7}, {74, 7}, {75, 7}, {22, 8}, {23, 8}, {24, 8}, {25, 8}, {26, 8}, {27, 8}, {28, 8}, {29, 8}, {30, 8}, {31, 8}, {32, 8}, {33, 8}, {34, 8}, {35, 8}, {36, 8}, {37, 8}, {38, 8}, {39, 8}, {40, 8}, {41, 8}, {4, 9}, {5, 9}, {6, 9}, {7, 9} 99 } 100 }; 101 102 const Huffman_t HuffQ9up [256] = { 103 {1, 10}, {2, 10}, {3, 10}, {4, 10}, {5, 10}, {5, 9}, {6, 9}, {7, 9}, {8, 9}, {9, 9}, {10, 9}, {11, 9}, {12, 9}, {13, 9}, {14, 9}, {15, 9}, {16, 9}, {17, 9}, {18, 9}, {38, 8}, {39, 8}, {19, 9}, {20, 9}, {21, 9}, {22, 9}, {23, 9}, {24, 9}, {25, 9}, {26, 9}, {27, 9}, {28, 9}, {29, 9}, {30, 9}, {31, 9}, {32, 9}, {33, 9}, {34, 9}, {35, 9}, {36, 9}, {37, 9}, {40, 8}, {38, 9}, {41, 8}, {42, 8}, {43, 8}, {44, 8}, {45, 8}, {46, 8}, {47, 8}, {48, 8}, {49, 8}, {50, 8}, {51, 8}, {52, 8}, {53, 8}, {54, 8}, {55, 8}, {56, 8}, {57, 8}, {58, 8}, {59, 8}, {60, 8}, {61, 8}, {62, 8}, {63, 8}, {64, 8}, {65, 8}, {66, 8}, {67, 8}, {68, 8}, {69, 8}, {70, 8}, {71, 8}, {72, 8}, {73, 8}, {74, 8}, {75, 8}, {76, 8}, {77, 8}, {78, 8}, {79, 8}, {80, 8}, {81, 8}, {82, 8}, {83, 8}, {84, 8}, {85, 8}, {86, 8}, {87, 8}, {88, 8}, {89, 8}, {90, 8}, {91, 8}, {92, 8}, {93, 8}, {94, 8}, {95, 8}, {96, 8}, {97, 8}, {98, 8}, {99, 8}, {100, 8}, {101, 8}, {102, 8}, {103, 8}, {104, 8}, {105, 8}, {106, 8}, {86, 7}, {87, 7}, {88, 7}, {89, 7}, {90, 7}, {91, 7}, {92, 7}, {93, 7}, {94, 7}, {95, 7}, {96, 7}, {97, 7}, {98, 7}, {99, 7}, {100, 7}, {101, 7}, {102, 7}, {103, 7}, {104, 7}, {62, 6}, {63, 6}, {105, 7}, {106, 7}, {107, 7}, {108, 7}, {109, 7}, {110, 7}, {111, 7}, {112, 7}, {113, 7}, {114, 7}, {115, 7}, {116, 7}, {117, 7}, {118, 7}, {119, 7}, {120, 7}, {121, 7}, {122, 7}, {107, 8}, {123, 7}, {108, 8}, {109, 8}, {110, 8}, {111, 8}, {112, 8}, {113, 8}, {114, 8}, {115, 8}, {116, 8}, {117, 8}, {118, 8}, {119, 8}, {120, 8}, {121, 8}, {122, 8}, {123, 8}, {124, 8}, {125, 8}, {126, 8}, {127, 8}, {128, 8}, {129, 8}, {130, 8}, {131, 8}, {132, 8}, {133, 8}, {134, 8}, {135, 8}, {136, 8}, {137, 8}, {138, 8}, {139, 8}, {140, 8}, {141, 8}, {142, 8}, {143, 8}, {144, 8}, {145, 8}, {146, 8}, {147, 8}, {148, 8}, {149, 8}, {150, 8}, {151, 8}, {152, 8}, {153, 8}, {154, 8}, {155, 8}, {156, 8}, {157, 8}, {158, 8}, {159, 8}, {160, 8}, {161, 8}, {162, 8}, {163, 8}, {164, 8}, {165, 8}, {166, 8}, {167, 8}, {168, 8}, {169, 8}, {170, 8}, {171, 8}, {39, 9}, {40, 9}, {41, 9}, {42, 9}, {43, 9}, {44, 9}, {45, 9}, {46, 9}, {47, 9}, {48, 9}, {49, 9}, {50, 9}, {51, 9}, {52, 9}, {53, 9}, {54, 9}, {55, 9}, {56, 9}, {57, 9}, {58, 9}, {59, 9}, {60, 9}, {61, 9}, {62, 9}, {63, 9}, {64, 9}, {65, 9}, {66, 9}, {67, 9}, {68, 9}, {69, 9}, {70, 9}, {71, 9}, {72, 9}, {73, 9}, {74, 9}, {75, 9}, {6, 10}, {7, 10}, {8, 10}, {9, 10}, {0, 11}, {1, 11} 104 }; 48 105 49 106 const Huffman_t* HuffQ [2] [8] = { 50 { NULL, HuffQ1[0], HuffQ2[0], HuffQ3[0], HuffQ4[0], HuffQ5[0], HuffQ6[0], HuffQ7[0] },51 { NULL, HuffQ1[1], HuffQ2[1], HuffQ3[1], HuffQ4[1], HuffQ5[1], HuffQ6[1], HuffQ7[1] }107 { HuffQ1, HuffQ2[0], HuffQ3, HuffQ4, HuffQ5[0], HuffQ6[0], HuffQ7[0], HuffQ8[0] }, 108 { HuffQ1, HuffQ2[1], HuffQ3, HuffQ4, HuffQ5[1], HuffQ6[1], HuffQ7[1], HuffQ8[1] } 52 109 }; 53 110 54 #ifdef USE_SV855 Huffman_t HuffN3 [2] [ 7*7]; // 8+ 9 bit56 Huffman_t HuffN8 [2][127]; //13+12 bit57 58 const Huffman_t* HuffN [2] [9] = {59 { NULL, HuffQ1[0], HuffQ2[0], HuffN3[0], HuffQ4[0], HuffQ5[0], HuffQ6[0], HuffQ7[0], HuffN8[0] },60 { NULL, HuffQ1[1], HuffQ2[1], HuffN3[1], HuffQ4[1], HuffQ5[1], HuffQ6[1], HuffQ7[1], HuffN8[1] }61 };62 #endif63 64 static const Huffman_t HuffSCFI_src [4] = {65 { 2, 3 }, { 1, 1 }, { 3, 3 }, { 0, 2 }66 };67 68 static const Huffman_t HuffDSCF_src [16] = {69 { 32, 6 }, { 4, 5 }, { 17, 5 }, { 30, 5 }, { 13, 4 }, { 0, 3 }, { 3, 3 }, { 9, 4 },70 { 5, 3 }, { 2, 3 }, { 14, 4 }, { 3, 4 }, { 31, 5 }, { 5, 5 }, { 33, 6 }, { 12, 4 }71 };72 73 static const Huffman_t HuffHdr_src [10] = {74 { 92, 8 }, { 47, 7 }, { 10, 5 }, { 4, 4 }, { 0, 2 },75 { 1, 1 }, { 3, 3 }, { 22, 6 }, { 187, 9 }, { 186, 9 }76 };77 78 static const Huffman_t HuffQ1_src [2] [3*3*3] = { {79 { 54, 6 }, { 9, 5 }, { 32, 6 }, { 5, 5 }, { 10, 4 }, { 7, 5 }, { 52, 6 }, { 0, 5 }, { 35, 6 },80 { 10, 5 }, { 6, 4 }, { 4, 5 }, { 11, 4 }, { 7, 3 }, { 12, 4 }, { 3, 5 }, { 7, 4 }, { 11, 5 },81 { 34, 6 }, { 1, 5 }, { 53, 6 }, { 6, 5 }, { 9, 4 }, { 2, 5 }, { 33, 6 }, { 8, 5 }, { 55, 6 }82 }, {83 { 103, 8 }, { 62, 7 }, { 225, 9 }, { 55, 7 }, { 3, 4 }, { 52, 7 }, { 101, 8 }, { 60, 7 }, { 227, 9 },84 { 24, 6 }, { 0, 4 }, { 61, 7 }, { 4, 4 }, { 1, 1 }, { 5, 4 }, { 63, 7 }, { 1, 4 }, { 59, 7 },85 { 226, 9 }, { 57, 7 }, { 100, 8 }, { 53, 7 }, { 2, 4 }, { 54, 7 }, { 224, 9 }, { 58, 7 }, { 102, 8 }86 } };87 88 static const Huffman_t HuffQ2_src [2] [5*5] = { {89 { 89, 7 }, { 47, 6 }, { 15, 5 }, { 0, 5 }, { 91, 7 },90 { 4, 5 }, { 6, 4 }, { 13, 4 }, { 4, 4 }, { 5, 5 },91 { 20, 5 }, { 12, 4 }, { 4, 3 }, { 15, 4 }, { 14, 5 },92 { 3, 5 }, { 3, 4 }, { 14, 4 }, { 5, 4 }, { 1, 5 },93 { 90, 7 }, { 2, 5 }, { 21, 5 }, { 46, 6 }, { 88, 7 }94 }, {95 { 921, 10 }, { 113, 7 }, { 51, 6 }, { 231, 8 }, { 922, 10 },96 { 104, 7 }, { 30, 5 }, { 0, 3 }, { 29, 5 }, { 105, 7 },97 { 50, 6 }, { 1, 3 }, { 2, 2 }, { 3, 3 }, { 49, 6 },98 { 107, 7 }, { 27, 5 }, { 2, 3 }, { 31, 5 }, { 112, 7 },99 { 920, 10 }, { 106, 7 }, { 48, 6 }, { 114, 7 }, { 923, 10 }100 } };101 102 #ifdef USE_SV8103 static const Huffman_t HuffN3_src [2] [7*7] = { {104 { 78, 7 }, { 20, 6 }, { 36, 6 }, { 51, 6 }, { 21, 6 }, { 101, 7 }, { 255, 8 },105 { 37, 6 }, { 0, 5 }, { 62, 6 }, { 7, 5 }, { 60, 6 }, { 49, 6 }, { 100, 7 },106 { 30, 6 }, { 53, 6 }, { 8, 5 }, { 14, 5 }, { 5, 5 }, { 54, 6 }, { 26, 6 },107 { 43, 6 }, { 1, 5 }, { 20, 5 }, { 14, 4 }, { 22, 5 }, { 9, 5 }, { 46, 6 },108 { 47, 6 }, { 61, 6 }, { 17, 5 }, { 16, 5 }, { 11, 5 }, { 4, 5 }, { 38, 6 },109 { 6, 6 }, { 52, 6 }, { 6, 5 }, { 12, 5 }, { 2, 5 }, { 55, 6 }, { 27, 6 },110 { 254, 8 }, { 126, 7 }, { 31, 6 }, { 48, 6 }, { 42, 6 }, { 7, 6 }, { 79, 7 }111 }, {112 { 65, 9 }, { 161, 8 }, { 109, 7 }, { 11, 6 }, { 116, 7 }, { 160, 8 }, { 71, 9 },113 { 34, 8 }, { 97, 7 }, { 56, 6 }, { 8, 5 }, { 55, 6 }, { 85, 7 }, { 166, 8 },114 { 84, 7 }, { 52, 6 }, { 3, 4 }, { 11, 4 }, { 5, 4 }, { 59, 6 }, { 86, 7 },115 { 10, 6 }, { 13, 5 }, { 9, 4 }, { 0, 3 }, { 8, 4 }, { 12, 5 }, { 9, 6 },116 { 98, 7 }, { 51, 6 }, { 31, 5 }, { 7, 4 }, { 30, 5 }, { 53, 6 }, { 99, 7 },117 { 162, 8 }, { 108, 7 }, { 50, 6 }, { 9, 5 }, { 57, 6 }, { 82, 7 }, { 163, 8 },118 { 64, 9 }, { 167, 8 }, { 87, 7 }, { 117, 7 }, { 96, 7 }, { 33, 8 }, { 70, 9 }119 } };120 #endif121 122 static const Huffman_t HuffQ3_src [2] [ 7] = { {123 { 12, 4 }, { 4, 3 }, { 0, 2 }, { 1, 2 }, { 7, 3 }, { 5, 3 }, { 13, 4 }124 }, {125 { 4, 5 }, { 3, 4 }, { 2, 2 }, { 3, 2 }, { 1, 2 }, { 0, 3 }, { 5, 5 }126 } };127 128 static const Huffman_t HuffQ4_src [2] [ 9] = { {129 { 5, 4 }, { 0, 3 }, { 4, 3 }, { 6, 3 }, { 7, 3 }, { 5, 3 }, { 3, 3 }, { 1, 3 }, { 4, 4 }130 }, {131 { 9, 5 }, { 12, 4 }, { 3, 3 }, { 0, 2 }, { 2, 2 }, { 7, 3 }, { 13, 4 }, { 5, 4 }, { 8, 5 }132 } };133 134 static const Huffman_t HuffQ5_src [2] [15] = { {135 { 57, 6 }, { 23, 5 }, { 8, 4 }, { 10, 4 }, { 13, 4 }, { 0, 3 }, { 2, 3 }, { 3, 3 },136 { 1, 3 }, { 15, 4 }, { 12, 4 }, { 9, 4 }, { 29, 5 }, { 22, 5 }, { 56, 6 }137 }, {138 { 229, 8 }, { 56, 6 }, { 7, 5 }, { 2, 4 }, { 0, 3 }, { 3, 3 }, { 5, 3 }, { 6, 3 },139 { 4, 3 }, { 2, 3 }, { 15, 4 }, { 29, 5 }, { 6, 5 }, { 115, 7 }, { 228, 8 },140 } };141 142 static const Huffman_t HuffQ6_src [2] [31] = { {143 { 65, 7 }, { 6, 6 }, { 44, 6 }, { 45, 6 }, { 59, 6 }, { 13, 5 }, { 17, 5 }, { 19, 5 },144 { 23, 5 }, { 21, 5 }, { 26, 5 }, { 30, 5 }, { 0, 4 }, { 2, 4 }, { 5, 4 }, { 7, 4 },145 { 3, 4 }, { 4, 4 }, { 31, 5 }, { 28, 5 }, { 25, 5 }, { 27, 5 }, { 24, 5 }, { 20, 5 },146 { 18, 5 }, { 12, 5 }, { 2, 5 }, { 58, 6 }, { 33, 6 }, { 7, 6 }, { 64, 7 },147 }, {148 { 6472, 13 }, { 6474, 13 }, { 808, 10 }, { 405, 9 }, { 203, 8 }, { 102, 7 }, { 49, 6 }, { 9, 5 },149 { 15, 5 }, { 31, 5 }, { 2, 4 }, { 6, 4 }, { 8, 4 }, { 11, 4 }, { 13, 4 }, { 0, 3 },150 { 14, 4 }, { 10, 4 }, { 9, 4 }, { 5, 4 }, { 3, 4 }, { 30, 5 }, { 14, 5 }, { 8, 5 },151 { 48, 6 }, { 103, 7 }, { 201, 8 }, { 200, 8 }, { 1619, 11 }, { 6473, 13 }, { 6475, 13 },152 } };153 154 static const Huffman_t HuffQ7_src [2] [63] = { {155 { 103, 8 }, // 0.3338 01100111156 { 153, 8 }, // 0.3766 10011001157 { 181, 8 }, // 0.4715 10110101158 { 233, 8 }, // 0.5528 11101001159 { 64, 7 }, // 0.6677 1000000160 { 65, 7 }, // 0.7041 1000001161 { 77, 7 }, // 0.7733 1001101162 { 81, 7 }, // 0.8296 1010001163 { 91, 7 }, // 0.9295 1011011164 { 113, 7 }, // 1.0814 1110001165 { 112, 7 }, // 1.0807 1110000166 { 24, 6 }, // 1.2748 011000167 { 29, 6 }, // 1.3390 011101168 { 35, 6 }, // 1.4224 100011169 { 37, 6 }, // 1.5201 100101170 { 41, 6 }, // 1.6642 101001171 { 44, 6 }, // 1.7292 101100172 { 46, 6 }, // 1.8647 101110173 { 51, 6 }, // 2.0473 110011174 { 49, 6 }, // 2.0152 110001175 { 54, 6 }, // 2.1315 110110176 { 55, 6 }, // 2.1358 110111177 { 57, 6 }, // 2.1700 111001178 { 60, 6 }, // 2.2449 111100179 { 0, 5 }, // 2.3063 00000180 { 2, 5 }, // 2.3854 00010181 { 10, 5 }, // 2.5481 01010182 { 5, 5 }, // 2.4867 00101183 { 9, 5 }, // 2.5352 01001184 { 6, 5 }, // 2.5074 00110185 { 13, 5 }, // 2.5745 01101186 { 7, 5 }, // 2.5195 00111187 { 11, 5 }, // 2.5502 01011188 { 15, 5 }, // 2.6251 01111189 { 8, 5 }, // 2.5260 01000190 { 4, 5 }, // 2.4418 00100191 { 3, 5 }, // 2.3983 00011192 { 1, 5 }, // 2.3697 00001193 { 63, 6 }, // 2.3041 111111194 { 62, 6 }, // 2.2656 111110195 { 61, 6 }, // 2.2549 111101196 { 53, 6 }, // 2.1151 110101197 { 59, 6 }, // 2.2042 111011198 { 52, 6 }, // 2.0837 110100199 { 48, 6 }, // 1.9446 110000200 { 47, 6 }, // 1.9189 101111201 { 43, 6 }, // 1.7177 101011202 { 42, 6 }, // 1.7035 101010203 { 39, 6 }, // 1.5287 100111204 { 36, 6 }, // 1.4559 100100205 { 33, 6 }, // 1.4117 100001206 { 28, 6 }, // 1.2776 011100207 { 117, 7 }, // 1.1107 1110101208 { 101, 7 }, // 1.0636 1100101209 { 100, 7 }, // 0.9751 1100100210 { 80, 7 }, // 0.8132 1010000211 { 69, 7 }, // 0.7091 1000101212 { 68, 7 }, // 0.7084 1000100213 { 50, 7 }, // 0.6277 0110010214 { 232, 8 }, // 0.5386 11101000215 { 180, 8 }, // 0.4408 10110100216 { 152, 8 }, // 0.3759 10011000217 { 102, 8 }, // 0.3160 01100110218 }, {219 { 14244, 14 }, // 0.0059 11011110100100220 { 14253, 14 }, // 0.0098 11011110101101221 { 14246, 14 }, // 0.0078 11011110100110222 { 14254, 14 }, // 0.0111 11011110101110223 { 3562, 12 }, // 0.0320 110111101010224 { 752, 10 }, // 0.0920 1011110000225 { 753, 10 }, // 0.1057 1011110001226 { 160, 9 }, // 0.1403 010100000227 { 162, 9 }, // 0.1579 010100010228 { 444, 9 }, // 0.2486 110111100229 { 122, 8 }, // 0.3772 01111010230 { 223, 8 }, // 0.5710 11011111231 { 60, 7 }, // 0.6858 0111100232 { 73, 7 }, // 0.8033 1001001233 { 110, 7 }, // 0.9827 1101110234 { 14, 6 }, // 1.2601 001110235 { 24, 6 }, // 1.3194 011000236 { 25, 6 }, // 1.3938 011001237 { 34, 6 }, // 1.5693 100010238 { 37, 6 }, // 1.7846 100101239 { 54, 6 }, // 2.0078 110110240 { 3, 5 }, // 2.2975 00011241 { 9, 5 }, // 2.5631 01001242 { 11, 5 }, // 2.7021 01011243 { 16, 5 }, // 3.1465 10000244 { 19, 5 }, // 3.4244 10011245 { 21, 5 }, // 3.5921 10101246 { 24, 5 }, // 3.7938 11000247 { 26, 5 }, // 3.9595 11010248 { 29, 5 }, // 4.1546 11101249 { 31, 5 }, // 4.2623 11111250 { 2, 4 }, // 4.5180 0010251 { 0, 4 }, // 4.3151 0000252 { 30, 5 }, // 4.2538 11110253 { 28, 5 }, // 4.1422 11100254 { 25, 5 }, // 3.9145 11001255 { 22, 5 }, // 3.6691 10110256 { 20, 5 }, // 3.4955 10100257 { 14, 5 }, // 2.9155 01110258 { 13, 5 }, // 2.7921 01101259 { 8, 5 }, // 2.5553 01000260 { 6, 5 }, // 2.3093 00110261 { 2, 5 }, // 2.1200 00010262 { 46, 6 }, // 1.8134 101110263 { 35, 6 }, // 1.5824 100011264 { 31, 6 }, // 1.4701 011111265 { 21, 6 }, // 1.3187 010101266 { 15, 6 }, // 1.2776 001111267 { 95, 7 }, // 0.9664 1011111268 { 72, 7 }, // 0.7922 1001000269 { 41, 7 }, // 0.6838 0101001270 { 189, 8 }, // 0.5024 10111101271 { 123, 8 }, // 0.3830 01111011272 { 377, 9 }, // 0.2232 101111001273 { 161, 9 }, // 0.1566 010100001274 { 891, 10 }, // 0.1383 1101111011275 { 327, 10 }, // 0.0900 0101000111276 { 326, 10 }, // 0.0790 0101000110277 { 3560, 12 }, // 0.0254 110111101000278 { 14255, 14 }, // 0.0117 11011110101111279 { 14247, 14 }, // 0.0085 11011110100111280 { 14252, 14 }, // 0.0085 11011110101100281 { 14245, 14 }, // 0.0065 11011110100101282 } };283 284 #ifdef USE_SV8285 static const Huffman_t HuffN8_src [2] [127] = { {286 { 2426, 13 }, { 4943, 13 }, { 787, 12 }, { 2470, 12 }, { 7270, 13 }, { 1764, 12 },287 { 3632, 12 }, { 3633, 12 }, { 2486, 12 }, { 395, 11 }, { 607, 11 }, { 1242, 11 },288 { 108, 10 }, { 300, 10 }, { 199, 10 }, { 440, 10 }, { 442, 10 }, { 616, 10 },289 { 909, 10 }, { 897, 10 }, { 178, 9 }, { 309, 9 }, { 311, 9 }, { 451, 9 },290 { 449, 9 }, { 26, 8 }, { 74, 8 }, { 94, 8 }, { 122, 8 }, { 136, 8 },291 { 12, 7 }, { 29, 7 }, { 28, 7 }, { 36, 7 }, { 39, 7 }, { 46, 7 },292 { 60, 7 }, { 69, 7 }, { 76, 7 }, { 92, 7 }, { 126, 7 }, { 11, 6 },293 { 15, 6 }, { 10, 6 }, { 16, 6 }, { 21, 6 }, { 25, 6 }, { 28, 6 },294 { 32, 6 }, { 31, 6 }, { 37, 6 }, { 47, 6 }, { 43, 6 }, { 35, 6 },295 { 45, 6 }, { 48, 6 }, { 52, 6 }, { 53, 6 }, { 54, 6 }, { 62, 6 },296 { 59, 6 }, { 0, 5 }, { 61, 6 }, { 51, 6 }, { 2, 5 }, { 1, 5 },297 { 60, 6 }, { 57, 6 }, { 58, 6 }, { 55, 6 }, { 50, 6 }, { 49, 6 },298 { 42, 6 }, { 40, 6 }, { 44, 6 }, { 41, 6 }, { 39, 6 }, { 33, 6 },299 { 29, 6 }, { 26, 6 }, { 24, 6 }, { 20, 6 }, { 17, 6 }, { 13, 6 },300 { 8, 6 }, { 9, 6 }, { 127, 7 }, { 93, 7 }, { 73, 7 }, { 72, 7 },301 { 54, 7 }, { 38, 7 }, { 45, 7 }, { 14, 7 }, { 25, 7 }, { 15, 7 },302 { 226, 8 }, { 137, 8 }, { 111, 8 }, { 95, 8 }, { 88, 8 }, { 48, 8 },303 { 455, 9 }, { 450, 9 }, { 246, 9 }, { 247, 9 }, { 179, 9 }, { 55, 9 },304 { 896, 10 }, { 620, 10 }, { 443, 10 }, { 302, 10 }, { 301, 10 }, { 198, 10 },305 { 109, 10 }, { 1234, 11 }, { 883, 11 }, { 392, 11 }, { 394, 11 }, { 3634, 12 },306 { 2487, 12 }, { 786, 12 }, { 1765, 12 }, { 1212, 12 }, { 7271, 13 }, { 2427, 13 },307 { 4942, 13 }308 }, {309 { 3728, 12 }, { 4005, 12 }, { 264, 11 }, { 4004, 12 }, { 4044, 12 }, { 4045, 12 },310 { 4046, 12 }, { 1424, 11 }, { 449, 11 }, { 448, 11 }, { 139, 10 }, { 231, 10 },311 { 133, 10 }, { 719, 10 }, { 641, 10 }, { 676, 10 }, { 225, 10 }, { 677, 10 },312 { 620, 10 }, { 72, 9 }, { 23, 9 }, { 67, 9 }, { 75, 9 }, { 113, 9 },313 { 311, 9 }, { 68, 9 }, { 316, 9 }, { 467, 9 }, { 10, 8 }, { 468, 9 },314 { 35, 8 }, { 27, 8 }, { 358, 9 }, { 32, 8 }, { 26, 8 }, { 501, 9 },315 { 44, 8 }, { 45, 8 }, { 142, 8 }, { 173, 8 }, { 161, 8 }, { 188, 8 },316 { 189, 8 }, { 190, 8 }, { 191, 8 }, { 254, 8 }, { 251, 8 }, { 255, 8 },317 { 19, 7 }, { 26, 7 }, { 70, 7 }, { 76, 7 }, { 87, 7 }, { 85, 7 },318 { 124, 7 }, { 7, 6 }, { 15, 6 }, { 41, 6 }, { 46, 6 }, { 2, 5 },319 { 16, 5 }, { 28, 5 }, { 12, 4 }, { 1, 2 }, { 13, 4 }, { 30, 5 },320 { 18, 5 }, { 0, 5 }, { 45, 6 }, { 34, 6 }, { 12, 6 }, { 3, 6 },321 { 118, 7 }, { 88, 7 }, { 81, 7 }, { 29, 7 }, { 78, 7 }, { 23, 7 },322 { 27, 7 }, { 253, 8 }, { 12, 7 }, { 232, 8 }, { 235, 8 }, { 159, 8 },323 { 238, 8 }, { 172, 8 }, { 168, 8 }, { 143, 8 }, { 154, 8 }, { 40, 8 },324 { 8, 8 }, { 478, 9 }, { 9, 8 }, { 479, 9 }, { 469, 9 }, { 42, 8 },325 { 43, 8 }, { 504, 9 }, { 357, 9 }, { 321, 9 }, { 339, 9 }, { 317, 9 },326 { 114, 9 }, { 82, 9 }, { 83, 9 }, { 73, 9 }, { 74, 9 }, { 1000, 10 },327 { 933, 10 }, { 621, 10 }, { 718, 10 }, { 2003, 11 }, { 713, 10 }, { 2020, 11 },328 { 230, 10 }, { 1865, 11 }, { 44, 10 }, { 138, 10 }, { 1280, 11 }, { 2021, 11 },329 { 3729, 12 }, { 4047, 12 }, { 90, 11 }, { 265, 11 }, { 1281, 11 }, { 1425, 11 },330 { 91, 11 }331 } };332 #endif333 334 /*335 * Fills out the items Code and Length (but not Value) of a Huffman table336 * from a bit packed Huffman table 'src'. Table is not sorted, so this is337 * the table which is suitable for an encoder. Be careful: To get a table338 * usable for a decoder you must use Resort_HuffTable() after this339 * function. It's a little bit dangerous to divide the functionality, maybe340 * there is a more secure and handy solution to this problem.341 */342 343 void Make_HuffTable ( Huffman_t* dst, const Huffman_t* src, mpc_size_t len )344 {345 mpc_size_t i;346 347 for ( i = 0; i < len; i++,src++,dst++ ) {348 dst->Code = src->Code ;349 dst->Length = src->Length;350 }351 }352 353 354 /*355 * Generates a Lookup table for quick Huffman decoding. This table must356 * have a size of a power of 2. Input is the pre-sorted Huffman table,357 * sorted by Resort_HuffTable() and its length, and the length of the358 * lookup table. Output is the Lookup table. It can be used for table based359 * decoding (Huffman_decode_fastest) which fully decodes by means of the360 * LUT. This is only handy for small huffman codes up to 9...10 bit361 * maximum length. For longer codes partial lookup is possible with362 * Huffman_decode_faster() which first estimates possible codes by means363 * of LUT and then searches the exact code like the tableless version364 * Huffman_decode().365 */366 367 void Make_LookupTable ( mpc_uint8_t* LUT,368 mpc_size_t LUT_len,369 const Huffman_t* const Table,370 const mpc_size_t elements )371 {372 mpc_size_t i;373 mpc_size_t idx = elements;374 mpc_uint32_t dval = (mpc_uint32_t)0x80000000L / LUT_len * 2;375 mpc_uint32_t val = dval - 1;376 377 for ( i = 0; i < LUT_len; i++, val += dval ) {378 while ( idx > 0 && val >= Table[idx-1].Code )379 idx--;380 *LUT++ = (mpc_uint8_t)idx;381 }382 383 return;384 }385 386 #define MAKE(d,s) Make_HuffTable ( (d), (s), sizeof(s)/sizeof(*(s)) )387 #define LOOKUP(x,q) Make_LookupTable ( (q), sizeof(q), (x), sizeof(x)/sizeof(*(x)) )388 389 390 void391 Init_Huffman_Encoder_SV7 ( void )392 {393 // Splitting of the 36 Samples394 MAKE ( HuffSCFI, HuffSCFI_src );395 396 // Differential Scalefactors397 MAKE ( HuffDSCF, HuffDSCF_src );398 399 // resolution, differential quantizer indizes400 MAKE ( HuffHdr, HuffHdr_src );401 402 // 3-step quantizer, 3 bundled samples403 MAKE ( HuffQ1[0], HuffQ1_src[0] ); // less shaped, book 0404 MAKE ( HuffQ1[1], HuffQ1_src[1] ); // more shaped, book 1405 406 // 5-step quantizer, 2 bundled samples407 MAKE ( HuffQ2[0], HuffQ2_src[0] ); // less shaped, book 0408 MAKE ( HuffQ2[1], HuffQ2_src[1] ); // more shaped, book 1409 410 // 7-step quantizer, single samples411 MAKE ( HuffQ3[0], HuffQ3_src[0] ); // less shaped, book 0412 MAKE ( HuffQ3[1], HuffQ3_src[1] ); // more shaped, book 1413 414 #ifdef USE_SV8415 // 7-step quantizer, 2 bundled samples416 MAKE ( HuffN3[0], HuffN3_src[0] ); // less shaped, book 0417 MAKE ( HuffN3[1], HuffN3_src[1] ); // more shaped, book 1418 #endif419 420 // 9-step quantizer, single samples421 MAKE ( HuffQ4[0], HuffQ4_src[0] ); // less shaped, book 0422 MAKE ( HuffQ4[1], HuffQ4_src[1] ); // more shaped, book 1423 424 // 15-step quantizer, single samples425 MAKE ( HuffQ5[0], HuffQ5_src[0] ); // less shaped, book 0426 MAKE ( HuffQ5[1], HuffQ5_src[1] ); // more shaped, book 1427 428 // 31-step quantizer, single samples429 MAKE ( HuffQ6[0], HuffQ6_src[0] ); // less shaped, book 0430 MAKE ( HuffQ6[1], HuffQ6_src[1] ); // more shaped, book 1431 432 // 63-step quantizer, single samples433 MAKE ( HuffQ7[0], HuffQ7_src[0] ); // less shaped, book 0434 MAKE ( HuffQ7[1], HuffQ7_src[1] ); // more shaped, book 1435 436 #ifdef USE_SV8437 // 127-step quantizer, single samples438 MAKE ( HuffN8[0], HuffN8_src[0] ); // book 0439 MAKE ( HuffN8[1], HuffN8_src[1] ); // book 1440 #endif441 }442 443 111 /* end of huffsv7.c */ -
libmpc/branches/r2d/libmpcenc/libmpcenc.h
r150 r161 65 65 unsigned int MS_Channelmode; 66 66 unsigned int Overflows; // = 0; // number of internal (filterbank) clippings 67 unsigned int MaxBand; /// number of non zero bands in last frame 67 68 } mpc_encoder_t; 68 69
Note: See TracChangeset
for help on using the changeset viewer.