Changeset 161 for libmpc/branches/r2d/libmpcenc/encode_sv7.c
- Timestamp:
- 12/18/06 20:52:54 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 )
Note: See TracChangeset
for help on using the changeset viewer.