#include <BitVector.hh>
Public Member Functions | |
| BitVector (unsigned char *baseBytePtr, unsigned baseBitOffset, unsigned totNumBits) | |
| void | setup (unsigned char *baseBytePtr, unsigned baseBitOffset, unsigned totNumBits) |
| void | putBits (unsigned from, unsigned numBits) |
| void | put1Bit (unsigned bit) |
| unsigned | getBits (unsigned numBits) |
| unsigned | get1Bit () |
| void | skipBits (unsigned numBits) |
| unsigned | curBitIndex () const |
| unsigned | totNumBits () const |
| unsigned | numBitsRemaining () const |
Private Attributes | |
| unsigned char * | fBaseBytePtr |
| unsigned | fBaseBitOffset |
| unsigned | fTotNumBits |
| unsigned | fCurBitIndex |
Definition at line 24 of file BitVector.hh.
| BitVector::BitVector | ( | unsigned char * | baseBytePtr, | |
| unsigned | baseBitOffset, | |||
| unsigned | totNumBits | |||
| ) |
Definition at line 23 of file BitVector.cpp.
References setup().
00025 { 00026 setup(baseBytePtr, baseBitOffset, totNumBits); 00027 }
| void BitVector::setup | ( | unsigned char * | baseBytePtr, | |
| unsigned | baseBitOffset, | |||
| unsigned | totNumBits | |||
| ) |
Definition at line 29 of file BitVector.cpp.
References fBaseBitOffset, fBaseBytePtr, fCurBitIndex, and fTotNumBits.
Referenced by BitVector(), and MP3FrameParams::setBytePointer().
00031 { 00032 fBaseBytePtr = baseBytePtr; 00033 fBaseBitOffset = baseBitOffset; 00034 fTotNumBits = totNumBits; 00035 fCurBitIndex = 0; 00036 }
| void BitVector::putBits | ( | unsigned | from, | |
| unsigned | numBits | |||
| ) |
Definition at line 43 of file BitVector.cpp.
References fBaseBitOffset, fBaseBytePtr, fCurBitIndex, fTotNumBits, MAX_LENGTH, and shiftBits().
Referenced by putSideInfo1(), and putSideInfo2().
00043 { 00044 unsigned char tmpBuf[4]; 00045 unsigned overflowingBits = 0; 00046 00047 if (numBits > MAX_LENGTH) { 00048 numBits = MAX_LENGTH; 00049 } 00050 00051 if (numBits > fTotNumBits - fCurBitIndex) { 00052 overflowingBits = numBits - (fTotNumBits - fCurBitIndex); 00053 } 00054 00055 tmpBuf[0] = (unsigned char)(from>>24); 00056 tmpBuf[1] = (unsigned char)(from>>16); 00057 tmpBuf[2] = (unsigned char)(from>>8); 00058 tmpBuf[3] = (unsigned char)from; 00059 00060 shiftBits(fBaseBytePtr, fBaseBitOffset + fCurBitIndex, /* to */ 00061 tmpBuf, MAX_LENGTH - numBits, /* from */ 00062 numBits - overflowingBits /* num bits */); 00063 fCurBitIndex += numBits - overflowingBits; 00064 }
| void BitVector::put1Bit | ( | unsigned | bit | ) |
Definition at line 67 of file BitVector.cpp.
References fBaseBitOffset, fBaseBytePtr, fCurBitIndex, fTotNumBits, and singleBitMask.
Referenced by putSideInfo1(), and putSideInfo2().
00067 { 00068 // The following is equivalent to "putBits(..., 1)", except faster: 00069 if (fCurBitIndex >= fTotNumBits) { /* overflow */ 00070 return; 00071 } else { 00072 unsigned totBitOffset = fBaseBitOffset + fCurBitIndex++; 00073 unsigned char mask = singleBitMask[totBitOffset%8]; 00074 if (bit) { 00075 fBaseBytePtr[totBitOffset/8] |= mask; 00076 } else { 00077 fBaseBytePtr[totBitOffset/8] &=~ mask; 00078 } 00079 } 00080 }
| unsigned BitVector::getBits | ( | unsigned | numBits | ) |
Definition at line 83 of file BitVector.cpp.
References fBaseBitOffset, fBaseBytePtr, fCurBitIndex, fTotNumBits, MAX_LENGTH, and shiftBits().
Referenced by MP3FrameParams::getBits(), MPEG4GenericRTPSource::processSpecialHeader(), and rsf_huffman_decoder().
00083 { 00084 unsigned char tmpBuf[4]; 00085 unsigned overflowingBits = 0; 00086 00087 if (numBits > MAX_LENGTH) { 00088 numBits = MAX_LENGTH; 00089 } 00090 00091 if (numBits > fTotNumBits - fCurBitIndex) { 00092 overflowingBits = numBits - (fTotNumBits - fCurBitIndex); 00093 } 00094 00095 shiftBits(tmpBuf, 0, /* to */ 00096 fBaseBytePtr, fBaseBitOffset + fCurBitIndex, /* from */ 00097 numBits - overflowingBits /* num bits */); 00098 fCurBitIndex += numBits - overflowingBits; 00099 00100 unsigned result 00101 = (tmpBuf[0]<<24) | (tmpBuf[1]<<16) | (tmpBuf[2]<<8) | tmpBuf[3]; 00102 result >>= (MAX_LENGTH - numBits); // move into low-order part of word 00103 result &= (0xFFFFFFFF << overflowingBits); // so any overflow bits are 0 00104 return result; 00105 }
| unsigned BitVector::get1Bit | ( | ) |
Definition at line 107 of file BitVector.cpp.
References fBaseBitOffset, fBaseBytePtr, fCurBitIndex, and fTotNumBits.
Referenced by MP3FrameParams::get1Bit(), and rsf_huffman_decoder().
00107 { 00108 // The following is equivalent to "getBits(1)", except faster: 00109 00110 if (fCurBitIndex >= fTotNumBits) { /* overflow */ 00111 return 0; 00112 } else { 00113 unsigned totBitOffset = fBaseBitOffset + fCurBitIndex++; 00114 unsigned char curFromByte = fBaseBytePtr[totBitOffset/8]; 00115 unsigned result = (curFromByte >> (7-(totBitOffset%8))) & 0x01; 00116 return result; 00117 } 00118 }
| void BitVector::skipBits | ( | unsigned | numBits | ) |
Definition at line 120 of file BitVector.cpp.
References fCurBitIndex, and fTotNumBits.
Referenced by MP3HuffmanDecode().
00120 { 00121 if (numBits > fTotNumBits - fCurBitIndex) { /* overflow */ 00122 fCurBitIndex = fTotNumBits; 00123 } else { 00124 fCurBitIndex += numBits; 00125 } 00126 }
| unsigned BitVector::curBitIndex | ( | ) | const [inline] |
Definition at line 42 of file BitVector.hh.
References fCurBitIndex.
Referenced by MP3HuffmanDecode().
00042 { return fCurBitIndex; }
| unsigned BitVector::totNumBits | ( | ) | const [inline] |
| unsigned BitVector::numBitsRemaining | ( | ) | const [inline] |
Definition at line 44 of file BitVector.hh.
References fCurBitIndex, and fTotNumBits.
00044 { return fTotNumBits - fCurBitIndex; }
unsigned char* BitVector::fBaseBytePtr [private] |
unsigned BitVector::fBaseBitOffset [private] |
unsigned BitVector::fTotNumBits [private] |
Definition at line 49 of file BitVector.hh.
Referenced by get1Bit(), getBits(), numBitsRemaining(), put1Bit(), putBits(), setup(), skipBits(), and totNumBits().
unsigned BitVector::fCurBitIndex [private] |
Definition at line 50 of file BitVector.hh.
Referenced by curBitIndex(), get1Bit(), getBits(), numBitsRemaining(), put1Bit(), putBits(), setup(), and skipBits().
1.5.2