huffmantable.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /***************************************************************************\
  2. *
  3. * MPEG Layer3-Audio Decoder
  4. * © 1997-2006 by Fraunhofer IIS
  5. * All Rights Reserved
  6. *
  7. * filename: huffmantable.h
  8. * project : MPEG Decoder
  9. * author : Martin Sieler
  10. * date : 1998-01-05
  11. * contents/description: HEADER - huffman table object
  12. *
  13. *
  14. \***************************************************************************/
  15. /*
  16. * $Date: 2011/01/18 23:00:53 $
  17. * $Id: huffmantable.h,v 1.3 2011/01/18 23:00:53 audiodsp Exp $
  18. */
  19. #ifndef __HUFFMANTABLE_H__
  20. #define __HUFFMANTABLE_H__
  21. /* ------------------------ includes --------------------------------------*/
  22. /*-------------------------- defines --------------------------------------*/
  23. #define HUFFMAN_BITS_4
  24. /*-------------------------------------------------------------------------*/
  25. // Huffman tables.
  26. //
  27. // This object holds the huffman table for ISO/MPEG Layer-3.
  28. //
  29. typedef struct
  30. {
  31. const unsigned char length;
  32. const unsigned char value;
  33. } huffman_entry_t;
  34. class CHuffmanTable
  35. {
  36. public:
  37. /*unsigned int nTableIndex; */
  38. CHuffmanTable();
  39. virtual ~CHuffmanTable();
  40. void SetTableIndex(unsigned int _nTableIndex)
  41. { nTableIndex = _nTableIndex; }
  42. unsigned int GetBitsPerLevel() const
  43. { return BITS_PER_LEVEL; }
  44. unsigned int GetLinBits() const
  45. { return ht[nTableIndex].linbits; }
  46. unsigned char GetCode (unsigned int nIndex, unsigned int nValue) const
  47. { return (ht[nTableIndex].table[nIndex][nValue] & 0xff); }
  48. unsigned char GetLength(unsigned int nIndex, unsigned int nValue) const
  49. { return ((ht[nTableIndex].table[nIndex][nValue] >> 8) & 0xff); }
  50. bool IsTableValid() const
  51. { return (ht[nTableIndex].table ? true:false); }
  52. bool IsLengthZero(unsigned int nIndex, unsigned int nValue) const
  53. { return ((ht[nTableIndex].table[nIndex][nValue] & 0xff00) == 0); }
  54. enum
  55. {
  56. #if defined HUFFMAN_BITS_2 /* HuffmanBits parallel huffman tables */
  57. BITS_PER_LEVEL = 2,
  58. ENTRIES_PER_LEVEL = 4
  59. #elif defined HUFFMAN_BITS_3
  60. BITS_PER_LEVEL = 3,
  61. ENTRIES_PER_LEVEL = 8
  62. #elif defined HUFFMAN_BITS_4 /* HuffmanBits parallel huffman tables */
  63. BITS_PER_LEVEL = 4,
  64. ENTRIES_PER_LEVEL = 16
  65. #endif
  66. };
  67. protected:
  68. private:
  69. typedef struct
  70. {
  71. unsigned int linbits;
  72. const unsigned short(*table)[ENTRIES_PER_LEVEL];
  73. } huffmantab;
  74. static const huffmantab ht[];
  75. unsigned int nTableIndex;
  76. };
  77. /*-------------------------------------------------------------------------*/
  78. #endif