#include "MP3InternalsHuffman.hh"#include <stdio.h>#include <string.h>#include <stdlib.h>Include dependency graph for MP3InternalsHuffman.cpp:

Go to the source code of this file.
Data Structures | |
| struct | huffcodetab |
Defines | |
| #define | TRUNC_FAVORa |
| #define | HUFFBITS unsigned long int |
| #define | SIZEOF_HUFFBITS 4 |
| #define | HTN 34 |
| #define | MXOFF 250 |
Functions | |
| void | updateSideInfoForHuffman (MP3SideInfo &sideInfo, Boolean isMPEG2, unsigned char const *mainDataPtr, unsigned p23L0, unsigned p23L1, unsigned &part23Length0a, unsigned &part23Length0aTruncation, unsigned &part23Length0b, unsigned &part23Length0bTruncation, unsigned &part23Length1a, unsigned &part23Length1aTruncation, unsigned &part23Length1b, unsigned &part23Length1bTruncation) |
| static void | rsf_getline (char *line, unsigned max, unsigned char **fi) |
| static void | rsfscanf (unsigned char **fi, unsigned int *v) |
| static int | read_decoder_table (unsigned char *fi) |
| static void | initialize_huffman () |
| static unsigned | rsf_get_scale_factors_1 (MP3SideInfo::gr_info_s_t *gr_info) |
| static unsigned | rsf_get_scale_factors_2 (MP3SideInfo::gr_info_s_t *gr_info) |
| static unsigned | getScaleFactorsLength (MP3SideInfo::gr_info_s_t *gr, Boolean isMPEG2) |
| static int | rsf_huffman_decoder (BitVector &bv, struct huffcodetab const *h, int *x, int *y, int *v, int *w) |
| void | MP3HuffmanDecode (MP3SideInfo::gr_info_s_t *gr, Boolean isMPEG2, unsigned char const *fromBasePtr, unsigned fromBitOffset, unsigned fromLength, unsigned &scaleFactorsLength, MP3HuffmanEncodingInfo &hei) |
Variables | |
| static unsigned | debugCount = 0 |
| static struct huffcodetab | rsf_ht [HTN] |
| static unsigned char const | slen [2][16] |
| static unsigned char const | stab [3][6][4] |
| unsigned | n_slen2 [] |
| unsigned | i_slen2 [] |
| HUFFBITS | dmask = 1 << (SIZEOF_HUFFBITS*8-1) |
| unsigned int | hs = SIZEOF_HUFFBITS*8 |
| #define HTN 34 |
Definition at line 319 of file MP3InternalsHuffman.cpp.
Referenced by initialize_huffman(), and read_decoder_table().
| #define HUFFBITS unsigned long int |
| #define MXOFF 250 |
| #define SIZEOF_HUFFBITS 4 |
Definition at line 318 of file MP3InternalsHuffman.cpp.
| #define TRUNC_FAVORa |
Definition at line 43 of file MP3InternalsHuffman.cpp.
| static unsigned getScaleFactorsLength | ( | MP3SideInfo::gr_info_s_t * | gr, | |
| Boolean | isMPEG2 | |||
| ) | [static] |
Definition at line 531 of file MP3InternalsHuffman.cpp.
References rsf_get_scale_factors_1(), and rsf_get_scale_factors_2().
Referenced by MP3HuffmanDecode().
00532 { 00533 return isMPEG2 ? rsf_get_scale_factors_2(gr) 00534 : rsf_get_scale_factors_1(gr); 00535 }
| static void initialize_huffman | ( | ) | [static] |
Definition at line 420 of file MP3InternalsHuffman.cpp.
References False, HTN, huffdec, read_decoder_table(), and True.
Referenced by MP3HuffmanDecode().
00420 { 00421 static Boolean huffman_initialized = False; 00422 00423 if (huffman_initialized) return; 00424 00425 if (read_decoder_table(huffdec) != HTN) { 00426 #ifdef DEBUG 00427 fprintf(stderr,"decoder table read error\n"); 00428 #endif 00429 return; 00430 } 00431 huffman_initialized = True; 00432 }
| void MP3HuffmanDecode | ( | MP3SideInfo::gr_info_s_t * | gr, | |
| Boolean | isMPEG2, | |||
| unsigned char const * | fromBasePtr, | |||
| unsigned | fromBitOffset, | |||
| unsigned | fromLength, | |||
| unsigned & | scaleFactorsLength, | |||
| MP3HuffmanEncodingInfo & | hei | |||
| ) |
Definition at line 541 of file MP3InternalsHuffman.cpp.
References MP3HuffmanEncodingInfo::allBitOffsets, MP3SideInfo::gr_info_s::big_values, BitVector::curBitIndex(), MP3HuffmanEncodingInfo::decodedValues, getScaleFactorsLength(), if(), initialize_huffman(), NULL, MP3HuffmanEncodingInfo::numSamples, MP3HuffmanEncodingInfo::reg1Start, MP3HuffmanEncodingInfo::reg2Start, MP3SideInfo::gr_info_s::region1start, MP3SideInfo::gr_info_s::region2start, rsf_ht, rsf_huffman_decoder(), BitVector::skipBits(), and MP3SideInfo::gr_info_s::table_select.
Referenced by updateSideInfoForHuffman().
00545 { 00546 unsigned i; 00547 int x, y, v, w; 00548 struct huffcodetab *h; 00549 BitVector bv((unsigned char*)fromBasePtr, fromBitOffset, fromLength); 00550 00551 /* Compute the size of the scale factors (& also advance bv): */ 00552 scaleFactorsLength = getScaleFactorsLength(gr, isMPEG2); 00553 bv.skipBits(scaleFactorsLength); 00554 00555 initialize_huffman(); 00556 00557 hei.reg1Start = hei.reg2Start = hei.numSamples = 0; 00558 00559 /* Read bigvalues area. */ 00560 if (gr->big_values < gr->region1start + gr->region2start) { 00561 gr->big_values = gr->region1start + gr->region2start; /* sanity check */ 00562 } 00563 for (i = 0; i < gr->big_values; ++i) { 00564 if (i < gr->region1start) { 00565 /* in region 0 */ 00566 h = &rsf_ht[gr->table_select[0]]; 00567 } else if (i < gr->region2start) { 00568 /* in region 1 */ 00569 h = &rsf_ht[gr->table_select[1]]; 00570 if (hei.reg1Start == 0) { 00571 hei.reg1Start = bv.curBitIndex(); 00572 } 00573 } else { 00574 /* in region 2 */ 00575 h = &rsf_ht[gr->table_select[2]]; 00576 if (hei.reg2Start == 0) { 00577 hei.reg2Start = bv.curBitIndex(); 00578 } 00579 } 00580 00581 hei.allBitOffsets[i] = bv.curBitIndex(); 00582 rsf_huffman_decoder(bv, h, &x, &y, &v, &w); 00583 if (hei.decodedValues != NULL) { 00584 // Record the decoded values: 00585 unsigned* ptr = &hei.decodedValues[4*i]; 00586 ptr[0] = x; ptr[1] = y; ptr[2] = v; ptr[3] = w; 00587 } 00588 } 00589 hei.bigvalStart = bv.curBitIndex(); 00590 00591 /* Read count1 area. */ 00592 h = &rsf_ht[gr->count1table_select+32]; 00593 while (bv.curBitIndex() < bv.totNumBits() && i < SSLIMIT*SBLIMIT) { 00594 hei.allBitOffsets[i] = bv.curBitIndex(); 00595 rsf_huffman_decoder(bv, h, &x, &y, &v, &w); 00596 if (hei.decodedValues != NULL) { 00597 // Record the decoded values: 00598 unsigned* ptr = &hei.decodedValues[4*i]; 00599 ptr[0] = x; ptr[1] = y; ptr[2] = v; ptr[3] = w; 00600 } 00601 ++i; 00602 } 00603 00604 hei.allBitOffsets[i] = bv.curBitIndex(); 00605 hei.numSamples = i; 00606 }
| static int read_decoder_table | ( | unsigned char * | fi | ) | [static] |
Definition at line 340 of file MP3InternalsHuffman.cpp.
References huffcodetab::hlen, HTN, huffcodetab::linbits, huffcodetab::linmax, NULL, huffcodetab::ref, rsf_getline(), rsf_ht, rsfscanf(), huffcodetab::table, huffcodetab::tablename, huffcodetab::treelen, huffcodetab::val, huffcodetab::xlen, and huffcodetab::ylen.
Referenced by initialize_huffman().
00340 { 00341 int n,i,nn,t; 00342 unsigned int v0,v1; 00343 char command[100],line[100]; 00344 for (n=0;n<HTN;n++) { 00345 rsf_ht[n].table = NULL; 00346 rsf_ht[n].hlen = NULL; 00347 00348 /* .table number treelen xlen ylen linbits */ 00349 do { 00350 rsf_getline(line,99,&fi); 00351 } while ((line[0] == '#') || (line[0] < ' ')); 00352 00353 sscanf(line,"%s %s %u %u %u %u",command,rsf_ht[n].tablename, 00354 &rsf_ht[n].treelen, &rsf_ht[n].xlen, &rsf_ht[n].ylen, &rsf_ht[n].linbits); 00355 if (strcmp(command,".end")==0) 00356 return n; 00357 else if (strcmp(command,".table")!=0) { 00358 #ifdef DEBUG 00359 fprintf(stderr,"huffman table %u data corrupted\n",n); 00360 #endif 00361 return -1; 00362 } 00363 rsf_ht[n].linmax = (1<<rsf_ht[n].linbits)-1; 00364 00365 sscanf(rsf_ht[n].tablename,"%u",&nn); 00366 if (nn != n) { 00367 #ifdef DEBUG 00368 fprintf(stderr,"wrong table number %u\n",n); 00369 #endif 00370 return(-2); 00371 } 00372 do { 00373 rsf_getline(line,99,&fi); 00374 } while ((line[0] == '#') || (line[0] < ' ')); 00375 00376 sscanf(line,"%s %u",command,&t); 00377 if (strcmp(command,".reference")==0) { 00378 rsf_ht[n].ref = t; 00379 rsf_ht[n].val = rsf_ht[t].val; 00380 rsf_ht[n].treelen = rsf_ht[t].treelen; 00381 if ( (rsf_ht[n].xlen != rsf_ht[t].xlen) || 00382 (rsf_ht[n].ylen != rsf_ht[t].ylen) ) { 00383 #ifdef DEBUG 00384 fprintf(stderr,"wrong table %u reference\n",n); 00385 #endif 00386 return (-3); 00387 }; 00388 while ((line[0] == '#') || (line[0] < ' ') ) { 00389 rsf_getline(line,99,&fi); 00390 } 00391 } 00392 else if (strcmp(command,".treedata")==0) { 00393 rsf_ht[n].ref = -1; 00394 rsf_ht[n].val = (unsigned char (*)[2]) 00395 new unsigned char[2*(rsf_ht[n].treelen)]; 00396 if ((rsf_ht[n].val == NULL) && ( rsf_ht[n].treelen != 0 )){ 00397 #ifdef DEBUG 00398 fprintf(stderr, "heaperror at table %d\n",n); 00399 #endif 00400 return -1; 00401 } 00402 for (i=0;(unsigned)i<rsf_ht[n].treelen; i++) { 00403 rsfscanf(&fi, &v0); 00404 rsfscanf(&fi, &v1); 00405 /*replaces fscanf(fi,"%x %x",&v0, &v1);*/ 00406 rsf_ht[n].val[i][0]=(unsigned char)v0; 00407 rsf_ht[n].val[i][1]=(unsigned char)v1; 00408 } 00409 rsf_getline(line,99,&fi); /* read the rest of the line */ 00410 } 00411 else { 00412 #ifdef DEBUG 00413 fprintf(stderr,"huffman decodertable error at table %d\n",n); 00414 #endif 00415 } 00416 } 00417 return n; 00418 }
| static unsigned rsf_get_scale_factors_1 | ( | MP3SideInfo::gr_info_s_t * | gr_info | ) | [static] |
Definition at line 448 of file MP3InternalsHuffman.cpp.
References MP3SideInfo::gr_info_s::block_type, MP3SideInfo::gr_info_s::mixed_block_flag, MP3SideInfo::gr_info_s::scalefac_compress, MP3SideInfo::gr_info_s::scfsi, and slen.
Referenced by getScaleFactorsLength().
00448 { 00449 int numbits; 00450 int num0 = slen[0][gr_info->scalefac_compress]; 00451 int num1 = slen[1][gr_info->scalefac_compress]; 00452 00453 if (gr_info->block_type == 2) 00454 { 00455 numbits = (num0 + num1) * 18; 00456 00457 if (gr_info->mixed_block_flag) { 00458 numbits -= num0; /* num0 * 17 + num1 * 18 */ 00459 } 00460 } 00461 else 00462 { 00463 int scfsi = gr_info->scfsi; 00464 00465 if(scfsi < 0) { /* scfsi < 0 => granule == 0 */ 00466 numbits = (num0 + num1) * 10 + num0; 00467 } 00468 else { 00469 numbits = 0; 00470 if(!(scfsi & 0x8)) { 00471 numbits += num0 * 6; 00472 } 00473 else { 00474 } 00475 00476 if(!(scfsi & 0x4)) { 00477 numbits += num0 * 5; 00478 } 00479 else { 00480 } 00481 00482 if(!(scfsi & 0x2)) { 00483 numbits += num1 * 5; 00484 } 00485 else { 00486 } 00487 00488 if(!(scfsi & 0x1)) { 00489 numbits += num1 * 5; 00490 } 00491 else { 00492 } 00493 } 00494 } 00495 00496 return numbits; 00497 }
| static unsigned rsf_get_scale_factors_2 | ( | MP3SideInfo::gr_info_s_t * | gr_info | ) | [static] |
Definition at line 502 of file MP3InternalsHuffman.cpp.
References MP3SideInfo::gr_info_s::block_type, MP3SideInfo::gr_info_s::mixed_block_flag, n_slen2, MP3SideInfo::gr_info_s::preflag, MP3SideInfo::gr_info_s::scalefac_compress, slen, and stab.
Referenced by getScaleFactorsLength().
00502 { 00503 unsigned char const* pnt; 00504 int i; 00505 unsigned int slen; 00506 int n = 0; 00507 int numbits = 0; 00508 00509 slen = n_slen2[gr_info->scalefac_compress]; 00510 00511 gr_info->preflag = (slen>>15) & 0x1; 00512 00513 n = 0; 00514 if( gr_info->block_type == 2 ) { 00515 n++; 00516 if(gr_info->mixed_block_flag) 00517 n++; 00518 } 00519 00520 pnt = stab[n][(slen>>12)&0x7]; 00521 00522 for(i=0;i<4;i++) { 00523 int num = slen & 0x7; 00524 slen >>= 3; 00525 numbits += pnt[i] * num; 00526 } 00527 00528 return numbits; 00529 }
| static void rsf_getline | ( | char * | line, | |
| unsigned | max, | |||
| unsigned char ** | fi | |||
| ) | [static] |
Definition at line 292 of file MP3InternalsHuffman.cpp.
Referenced by read_decoder_table().
00292 { 00293 unsigned i; 00294 for (i = 0; i < max; ++i) { 00295 line[i] = *(*fi)++; 00296 if (line[i] == '\n') { 00297 line[i++] = '\0'; 00298 return; 00299 } 00300 } 00301 line[i] = '\0'; 00302 }
| static int rsf_huffman_decoder | ( | BitVector & | bv, | |
| struct huffcodetab const * | h, | |||
| int * | x, | |||
| int * | y, | |||
| int * | v, | |||
| int * | w | |||
| ) | [static] |
Definition at line 612 of file MP3InternalsHuffman.cpp.
References BitVector::get1Bit(), BitVector::getBits(), HUFFBITS, huffcodetab::linbits, MXOFF, NULL, huffcodetab::tablename, huffcodetab::treelen, huffcodetab::val, huffcodetab::xlen, and huffcodetab::ylen.
Referenced by MP3HuffmanDecode().
00616 { 00617 HUFFBITS level; 00618 unsigned point = 0; 00619 int error = 1; 00620 level = dmask; 00621 *x = *y = *v = *w = 0; 00622 if (h->val == NULL) return 2; 00623 00624 /* table 0 needs no bits */ 00625 if (h->treelen == 0) return 0; 00626 00627 /* Lookup in Huffman table. */ 00628 00629 do { 00630 if (h->val[point][0]==0) { /*end of tree*/ 00631 *x = h->val[point][1] >> 4; 00632 *y = h->val[point][1] & 0xf; 00633 00634 error = 0; 00635 break; 00636 } 00637 if (bv.get1Bit()) { 00638 while (h->val[point][1] >= MXOFF) point += h->val[point][1]; 00639 point += h->val[point][1]; 00640 } 00641 else { 00642 while (h->val[point][0] >= MXOFF) point += h->val[point][0]; 00643 point += h->val[point][0]; 00644 } 00645 level >>= 1; 00646 } while (level || (point < h->treelen) ); 00648 00649 /* Check for error. */ 00650 00651 if (error) { /* set x and y to a medium value as a simple concealment */ 00652 printf("Illegal Huffman code in data.\n"); 00653 *x = ((h->xlen-1) << 1); 00654 *y = ((h->ylen-1) << 1); 00655 } 00656 00657 /* Process sign encodings for quadruples tables. */ 00658 00659 if (h->tablename[0] == '3' 00660 && (h->tablename[1] == '2' || h->tablename[1] == '3')) { 00661 *v = (*y>>3) & 1; 00662 *w = (*y>>2) & 1; 00663 *x = (*y>>1) & 1; 00664 *y = *y & 1; 00665 00666 if (*v) 00667 if (bv.get1Bit() == 1) *v = -*v; 00668 if (*w) 00669 if (bv.get1Bit() == 1) *w = -*w; 00670 if (*x) 00671 if (bv.get1Bit() == 1) *x = -*x; 00672 if (*y) 00673 if (bv.get1Bit() == 1) *y = -*y; 00674 } 00675 00676 /* Process sign and escape encodings for dual tables. */ 00677 00678 else { 00679 if (h->linbits) 00680 if ((h->xlen-1) == (unsigned)*x) 00681 *x += bv.getBits(h->linbits); 00682 if (*x) 00683 if (bv.get1Bit() == 1) *x = -*x; 00684 if (h->linbits) 00685 if ((h->ylen-1) == (unsigned)*y) 00686 *y += bv.getBits(h->linbits); 00687 if (*y) 00688 if (bv.get1Bit() == 1) *y = -*y; 00689 } 00690 00691 return error; 00692 }
| static void rsfscanf | ( | unsigned char ** | fi, | |
| unsigned int * | v | |||
| ) | [static] |
Definition at line 304 of file MP3InternalsHuffman.cpp.
Referenced by read_decoder_table().
00304 { 00305 while (sscanf((char*)*fi, "%x", v) == 0) { 00306 /* skip past the next '\0' */ 00307 while (*(*fi)++ != '\0') {} 00308 } 00309 00310 /* skip past any white-space before the value: */ 00311 while (*(*fi) <= ' ') ++(*fi); 00312 00313 /* skip past the value: */ 00314 while (*(*fi) > ' ') ++(*fi); 00315 }
| void updateSideInfoForHuffman | ( | MP3SideInfo & | sideInfo, | |
| Boolean | isMPEG2, | |||
| unsigned char const * | mainDataPtr, | |||
| unsigned | p23L0, | |||
| unsigned | p23L1, | |||
| unsigned & | part23Length0a, | |||
| unsigned & | part23Length0aTruncation, | |||
| unsigned & | part23Length0b, | |||
| unsigned & | part23Length0bTruncation, | |||
| unsigned & | part23Length1a, | |||
| unsigned & | part23Length1aTruncation, | |||
| unsigned & | part23Length1b, | |||
| unsigned & | part23Length1bTruncation | |||
| ) |
Definition at line 45 of file MP3InternalsHuffman.cpp.
References MP3HuffmanEncodingInfo::allBitOffsets, MP3SideInfo::gr_info_s::big_values, MP3HuffmanEncodingInfo::bigvalStart, MP3SideInfo::ch, debugCount, MP3SideInfo::gr, MP3HuffmanDecode(), MP3HuffmanEncodingInfo::numSamples, MP3SideInfo::gr_info_s::part2_3_length, MP3HuffmanEncodingInfo::reg1Start, and MP3HuffmanEncodingInfo::reg2Start.
Referenced by updateSideInfoSizes().
00055 { 00056 int i, j; 00057 unsigned sfLength, origTotABsize, adjustment; 00058 MP3SideInfo::gr_info_s_t* gr; 00059 00060 /* First, Huffman-decode each part of the segment's main data, 00061 to see at which bit-boundaries the samples appear: 00062 */ 00063 MP3HuffmanEncodingInfo hei; 00064 00065 ++debugCount; 00066 #ifdef DEBUG 00067 fprintf(stderr, "usifh-start: p23L0: %d, p23L1: %d\n", p23L0, p23L1); 00068 #endif 00069 00070 /* Process granule 0 */ 00071 { 00072 gr = &(sideInfo.ch[0].gr[0]); 00073 origTotABsize = gr->part2_3_length; 00074 00075 MP3HuffmanDecode(gr, isMPEG2, mainDataPtr, 0, origTotABsize, sfLength, hei); 00076 00077 /* Begin by computing new sizes for parts a & b (& their truncations) */ 00078 #ifdef DEBUG 00079 fprintf(stderr, "usifh-0: %d, %d:%d, %d:%d, %d:%d, %d:%d, %d:%d\n", 00080 hei.numSamples, 00081 sfLength/8, sfLength%8, 00082 hei.reg1Start/8, hei.reg1Start%8, 00083 hei.reg2Start/8, hei.reg2Start%8, 00084 hei.bigvalStart/8, hei.bigvalStart%8, 00085 origTotABsize/8, origTotABsize%8); 00086 #endif 00087 if (p23L0 < sfLength) { 00088 /* We can't use this, so give it all to the next granule: */ 00089 p23L1 += p23L0; 00090 p23L0 = 0; 00091 } 00092 00093 part23Length0a = hei.bigvalStart; 00094 part23Length0b = origTotABsize - hei.bigvalStart; 00095 part23Length0aTruncation = part23Length0bTruncation = 0; 00096 if (origTotABsize > p23L0) { 00097 /* We need to shorten one or both of fields a & b */ 00098 unsigned truncation = origTotABsize - p23L0; 00099 #ifdef TRUNC_FAIRLY 00100 part23Length0aTruncation = (truncation*(part23Length0a-sfLength)) 00101 /(origTotABsize-sfLength); 00102 part23Length0bTruncation = truncation - part23Length0aTruncation; 00103 #endif 00104 #ifdef TRUNC_FAVORa 00105 part23Length0bTruncation 00106 = (truncation > part23Length0b) ? part23Length0b : truncation; 00107 part23Length0aTruncation = truncation - part23Length0bTruncation; 00108 #endif 00109 #ifdef TRUNC_FAVORb 00110 part23Length0aTruncation = (truncation > part23Length0a-sfLength) 00111 ? (part23Length0a-sfLength) : truncation; 00112 part23Length0bTruncation = truncation - part23Length0aTruncation; 00113 #endif 00114 } 00115 /* ASSERT: part23Length0xTruncation <= part23Length0x */ 00116 part23Length0a -= part23Length0aTruncation; 00117 part23Length0b -= part23Length0bTruncation; 00118 #ifdef DEBUG 00119 fprintf(stderr, "usifh-0: interim sizes: %d (%d), %d (%d)\n", 00120 part23Length0a, part23Length0aTruncation, 00121 part23Length0b, part23Length0bTruncation); 00122 #endif 00123 00124 /* Adjust these new lengths so they end on sample bit boundaries: */ 00125 for (i = 0; i < (int)hei.numSamples; ++i) { 00126 if (hei.allBitOffsets[i] == part23Length0a) break; 00127 else if (hei.allBitOffsets[i] > part23Length0a) {--i; break;} 00128 } 00129 if (i < 0) { /* should happen only if we couldn't fit sfLength */ 00130 i = 0; adjustment = 0; 00131 } else { 00132 adjustment = part23Length0a - hei.allBitOffsets[i]; 00133 } 00134 #ifdef DEBUG 00135 fprintf(stderr, "%d usifh-0: adjustment 1: %d\n", debugCount, adjustment); 00136 #endif 00137 part23Length0a -= adjustment; 00138 part23Length0aTruncation += adjustment; 00139 /* Assign the bits we just shaved to field b and granule 1: */ 00140 if (part23Length0bTruncation < adjustment) { 00141 p23L1 += (adjustment - part23Length0bTruncation); 00142 adjustment = part23Length0bTruncation; 00143 } 00144 part23Length0b += adjustment; 00145 part23Length0bTruncation -= adjustment; 00146 for (j = i; j < (int)hei.numSamples; ++j) { 00147 if (hei.allBitOffsets[j] 00148 == part23Length0a + part23Length0aTruncation + part23Length0b) 00149 break; 00150 else if (hei.allBitOffsets[j] 00151 > part23Length0a + part23Length0aTruncation + part23Length0b) 00152 {--j; break;} 00153 } 00154 if (j < 0) { /* should happen only if we couldn't fit sfLength */ 00155 j = 0; adjustment = 0; 00156 } else { 00157 adjustment = part23Length0a+part23Length0aTruncation+part23Length0b 00158 - hei.allBitOffsets[j]; 00159 } 00160 #ifdef DEBUG 00161 fprintf(stderr, "%d usifh-0: adjustment 2: %d\n", debugCount, adjustment); 00162 #endif 00163 if (adjustment > part23Length0b) adjustment = part23Length0b; /*sanity*/ 00164 part23Length0b -= adjustment; 00165 part23Length0bTruncation += adjustment; 00166 /* Assign the bits we just shaved to granule 1 */ 00167 p23L1 += adjustment; 00168 00169 if (part23Length0aTruncation > 0) { 00170 /* Change the granule's 'big_values' field to reflect the truncation */ 00171 gr->big_values = i; 00172 } 00173 } 00174 00175 /* Process granule 1 (MPEG-1 only) */ 00176 00177 if (isMPEG2) { 00178 part23Length1a = part23Length1b = 0; 00179 part23Length1aTruncation = part23Length1bTruncation = 0; 00180 } else { 00181 unsigned granule1Offset 00182 = origTotABsize + sideInfo.ch[1].gr[0].part2_3_length; 00183 00184 gr = &(sideInfo.ch[0].gr[1]); 00185 origTotABsize = gr->part2_3_length; 00186 00187 MP3HuffmanDecode(gr, isMPEG2, mainDataPtr, granule1Offset, 00188 origTotABsize, sfLength, hei); 00189 00190 /* Begin by computing new sizes for parts a & b (& their truncations) */ 00191 #ifdef DEBUG 00192 fprintf(stderr, "usifh-1: %d, %d:%d, %d:%d, %d:%d, %d:%d, %d:%d\n", 00193 hei.numSamples, 00194 sfLength/8, sfLength%8, 00195 hei.reg1Start/8, hei.reg1Start%8, 00196 hei.reg2Start/8, hei.reg2Start%8, 00197 hei.bigvalStart/8, hei.bigvalStart%8, 00198 origTotABsize/8, origTotABsize%8); 00199 #endif 00200 if (p23L1 < sfLength) { 00201 /* We can't use this, so give up on this granule: */ 00202 p23L1 = 0; 00203 } 00204 00205 part23Length1a = hei.bigvalStart; 00206 part23Length1b = origTotABsize - hei.bigvalStart; 00207 part23Length1aTruncation = part23Length1bTruncation = 0; 00208 if (origTotABsize > p23L1) { 00209 /* We need to shorten one or both of fields a & b */ 00210 unsigned truncation = origTotABsize - p23L1; 00211 #ifdef TRUNC_FAIRLY 00212 part23Length1aTruncation = (truncation*(part23Length1a-sfLength)) 00213 /(origTotABsize-sfLength); 00214 part23Length1bTruncation = truncation - part23Length1aTruncation; 00215 #endif 00216 #ifdef TRUNC_FAVORa 00217 part23Length1bTruncation 00218 = (truncation > part23Length1b) ? part23Length1b : truncation; 00219 part23Length1aTruncation = truncation - part23Length1bTruncation; 00220 #endif 00221 #ifdef TRUNC_FAVORb 00222 part23Length1aTruncation = (truncation > part23Length1a-sfLength) 00223 ? (part23Length1a-sfLength) : truncation; 00224 part23Length1bTruncation = truncation - part23Length1aTruncation; 00225 #endif 00226 } 00227 /* ASSERT: part23Length1xTruncation <= part23Length1x */ 00228 part23Length1a -= part23Length1aTruncation; 00229 part23Length1b -= part23Length1bTruncation; 00230 #ifdef DEBUG 00231 fprintf(stderr, "usifh-1: interim sizes: %d (%d), %d (%d)\n", 00232 part23Length1a, part23Length1aTruncation, 00233 part23Length1b, part23Length1bTruncation); 00234 #endif 00235 00236 /* Adjust these new lengths so they end on sample bit boundaries: */ 00237 for (i = 0; i < (int)hei.numSamples; ++i) { 00238 if (hei.allBitOffsets[i] == part23Length1a) break; 00239 else if (hei.allBitOffsets[i] > part23Length1a) {--i; break;} 00240 } 00241 if (i < 0) { /* should happen only if we couldn't fit sfLength */ 00242 i = 0; adjustment = 0; 00243 } else { 00244 adjustment = part23Length1a - hei.allBitOffsets[i]; 00245 } 00246 #ifdef DEBUG 00247 fprintf(stderr, "%d usifh-1: adjustment 0: %d\n", debugCount, adjustment); 00248 #endif 00249 part23Length1a -= adjustment; 00250 part23Length1aTruncation += adjustment; 00251 /* Assign the bits we just shaved to field b: */ 00252 if (part23Length1bTruncation < adjustment) { 00253 adjustment = part23Length1bTruncation; 00254 } 00255 part23Length1b += adjustment; 00256 part23Length1bTruncation -= adjustment; 00257 for (j = i; j < (int)hei.numSamples; ++j) { 00258 if (hei.allBitOffsets[j] 00259 == part23Length1a + part23Length1aTruncation + part23Length1b) 00260 break; 00261 else if (hei.allBitOffsets[j] 00262 > part23Length1a + part23Length1aTruncation + part23Length1b) 00263 {--j; break;} 00264 } 00265 if (j < 0) { /* should happen only if we couldn't fit sfLength */ 00266 j = 0; adjustment = 0; 00267 } else { 00268 adjustment = part23Length1a+part23Length1aTruncation+part23Length1b 00269 - hei.allBitOffsets[j]; 00270 } 00271 #ifdef DEBUG 00272 fprintf(stderr, "%d usifh-1: adjustment 1: %d\n", debugCount, adjustment); 00273 #endif 00274 if (adjustment > part23Length1b) adjustment = part23Length1b; /*sanity*/ 00275 part23Length1b -= adjustment; 00276 part23Length1bTruncation += adjustment; 00277 00278 if (part23Length1aTruncation > 0) { 00279 /* Change the granule's 'big_values' field to reflect the truncation */ 00280 gr->big_values = i; 00281 } 00282 } 00283 #ifdef DEBUG 00284 fprintf(stderr, "usifh-end, new vals: %d (%d), %d (%d), %d (%d), %d (%d)\n", 00285 part23Length0a, part23Length0aTruncation, 00286 part23Length0b, part23Length0bTruncation, 00287 part23Length1a, part23Length1aTruncation, 00288 part23Length1b, part23Length1bTruncation); 00289 #endif 00290 }
unsigned debugCount = 0 [static] |
| HUFFBITS dmask = 1 << (SIZEOF_HUFFBITS*8-1) |
Definition at line 608 of file MP3InternalsHuffman.cpp.
| unsigned int hs = SIZEOF_HUFFBITS*8 |
Definition at line 609 of file MP3InternalsHuffman.cpp.
| unsigned i_slen2[] |
| unsigned n_slen2[] |
Definition at line 91 of file MP3Internals.cpp.
Referenced by MP3FrameParams::MP3FrameParams(), and rsf_get_scale_factors_2().
struct huffcodetab rsf_ht[HTN] [static] |
Definition at line 335 of file MP3InternalsHuffman.cpp.
Referenced by MP3HuffmanDecode(), and read_decoder_table().
unsigned char const slen[2][16] [static] |
Initial value:
{
{0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
{0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}
}
Definition at line 434 of file MP3InternalsHuffman.cpp.
Referenced by rsf_get_scale_factors_1(), and rsf_get_scale_factors_2().
unsigned char const stab[3][6][4] [static] |
Initial value:
{
{ { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0} ,
{ 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0} } ,
{ { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} ,
{12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } ,
{ { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} ,
{ 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0} }
}
Definition at line 439 of file MP3InternalsHuffman.cpp.
Referenced by rsf_get_scale_factors_2().
1.5.2