bitsequence.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /***************************************************************************\
  2. *
  3. * MPEG Layer3-Audio Decoder
  4. * © 1997-2006 by Fraunhofer IIS
  5. * All Rights Reserved
  6. *
  7. * filename: bitsequence.h
  8. * project : MPEG Decoder
  9. * author : Martin Sieler
  10. * date : 1997-12-23
  11. * contents/description: HEADER - bitsequence object
  12. *
  13. *
  14. \***************************************************************************/
  15. /*
  16. * $Date: 2010/11/17 20:46:01 $
  17. * $Id: bitsequence.h,v 1.1 2010/11/17 20:46:01 audiodsp Exp $
  18. */
  19. #ifndef __BITSEQUENCE_H__
  20. #define __BITSEQUENCE_H__
  21. /* ------------------------ includes --------------------------------------*/
  22. #include "bitstream.h"
  23. /*-------------------------- defines --------------------------------------*/
  24. /*-------------------------------------------------------------------------*/
  25. //
  26. // Bitstream parser class.
  27. //
  28. // This helper class is basically a numerical value that can read itself from
  29. // a CBitStream interface for convenience. The decoder almost completely
  30. // does the bitstream parsing through CBitSequence rather than CBitStream
  31. // directly.
  32. //
  33. class CBitSequence
  34. {
  35. public:
  36. CBitSequence(int nBits = 0) { m_nBits = nBits; m_nValue = 0; }
  37. virtual ~CBitSequence() {}
  38. void SetNumberOfBits(int nBits) { m_nBits = nBits; }
  39. int GetNumberOfBits() const { return m_nBits; }
  40. bool ReadFrom(CBitStream &Bs) { m_nValue = Bs.GetBits(m_nBits); return true; }
  41. bool ReadFrom_Bit(CBitStream &Bs) { m_nValue = Bs.Get1Bit(); return true; }
  42. bool ReadFrom(CBitStream &Bs, int nBits) { SetNumberOfBits(nBits); return ReadFrom(Bs); }
  43. bool Equals(int nValue) const { return (m_nValue == nValue); }
  44. int ToInt() const { return m_nValue; }
  45. void FromInt(int nValue) { m_nValue = nValue; }
  46. protected:
  47. private:
  48. int m_nBits;
  49. int m_nValue;
  50. };
  51. /*-------------------------------------------------------------------------*/
  52. #endif