home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 March / PCWELT_3_2004.ISO / pcwsoft / flaskmpeg_078_39_src.z.exe / flaskmpeg / Audio / MPEG / AMPBitstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  1.9 KB  |  114 lines

  1. #ifndef f_AMPLIB_BITSTREAM_H
  2. #define f_AMPLIB_BITSTREAM_H
  3.  
  4. #include "IAMPDecoder.h"
  5.  
  6. // max layer2 buffer -> 144000 * 384 / 32000 + 1 - 4 = 1725 bytes
  7. // max layer3 buffer -> 144000 * 320 / 32000 + 512 - 4 = 1948 bytes
  8.  
  9. #define BUFFER_SIZE        (2048)
  10. #define BUFFER_MASK        (BUFFER_SIZE - 1)
  11.  
  12. class AMPBitstream {
  13. protected:
  14.     IAMPBitsource *pSource;
  15.  
  16. private:
  17.     unsigned char buf[BUFFER_SIZE];
  18.     int bitcnt;
  19.     int bufpoint;
  20.     int bufindex, bufindexw;
  21.     unsigned long bitheap;
  22.  
  23.     long _getbits(unsigned char bits);
  24.     long _getbitsL2(unsigned char bits);
  25.     long _peekbits(unsigned char bits);
  26.     long _peekbits2(unsigned char bits);
  27.  
  28. public:
  29.  
  30.     void resetbits(int bytes);
  31.     void resetbitsL2(int bytes);
  32.     void fillbits(int bytes);
  33.     void rewind(int bytes);
  34.     void rewindbits(int bits);
  35.     int tellbits();
  36.  
  37.     long peekbits(unsigned char bits) {
  38.         if (bitcnt > 24-(int)bits)
  39.             return _peekbits(bits);
  40.  
  41.         return bitheap >> (32-bits);
  42.     }
  43.  
  44.     long peekbits2(unsigned char bits) {
  45.         if (bitcnt > 24-(int)bits)
  46.             return _peekbits2(bits);
  47.  
  48.         return bitheap >> (32-bits);
  49.     }
  50.  
  51.     void skipbits(unsigned char bits) {
  52.         bitcnt += bits;
  53.         bitheap <<= bits;
  54.     }
  55.  
  56.     void skipbit() {
  57.         bitcnt++;
  58.         bitheap += bitheap;
  59.     }
  60.  
  61.     long getbits(unsigned char bits) {
  62.         long rv;
  63.         
  64.         if (!bits)
  65.             return 0;
  66.  
  67.         if (bitcnt > 24-(int)bits)
  68.             return _getbits(bits);
  69.  
  70.         rv = bitheap >> (32-bits);
  71.  
  72.         bitcnt += bits;
  73.  
  74.         bitheap <<= bits;
  75.  
  76.         return rv;
  77.     }
  78.  
  79.     long getbitsL2(unsigned char bits) {
  80.         long rv;
  81.         
  82.         if (!bits)
  83.             return 0;
  84.  
  85.         if (bitcnt < bits)
  86.             return _getbitsL2(bits);
  87.  
  88.         rv = bitheap >> (32-bits);
  89.  
  90.         bitcnt -= bits;
  91.  
  92.         bitheap <<= bits;
  93.  
  94.         return rv;
  95.     }
  96.  
  97.     unsigned long getflag() {
  98.         long rv;
  99.         
  100.         if (bitcnt > 23)
  101.             return _getbits(1);
  102.  
  103.         rv = bitheap;
  104.  
  105.         ++bitcnt;
  106.  
  107.         bitheap <<= 1;
  108.  
  109.         return rv&0x80000000;
  110.     }
  111. };
  112.  
  113. #endif
  114.