Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef MPAHEADER_H
  7. #define MPAHEADER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #pragma once
  12. #define MPA_HEADER_SIZE 4 // MPEG-Audio Header Size 32bit
  13. #define MAXTIMESREAD 5
  14. class CMPAFile;
  15. class CMPAHeader
  16. {
  17. public:
  18. CMPAHeader( CMPAFile* pMPAFile, uint32 dwExpectedOffset = 0, bool bSubsequentFrame = false, bool bReverse = false );
  19. ~CMPAHeader();
  20. bool SkipEmptyFrames();
  21. // bitrate is in bit per second, to calculate in bytes => (/ 8)
  22. uint32 GetBytesPerSecond() const { return m_dwBitrate / 8; };
  23. // calc number of seconds from number of frames
  24. uint32 GetLengthSecond(uint32 dwNumFrames) const { return dwNumFrames * m_dwSamplesPerFrame / m_dwSamplesPerSec; };
  25. uint32 GetBytesPerSecond( uint32 dwNumFrames, uint32 dwNumBytes ) const { return dwNumBytes / GetLengthSecond( dwNumFrames ); };
  26. bool IsMono() const { return (m_ChannelMode == SingleChannel)?true:false; };
  27. // true if MPEG2/2.5 otherwise false
  28. bool IsLSF() const { return m_bLSF; };
  29. private:
  30. static const uint32 m_dwMaxRange;
  31. static const uint32 m_dwTolerance;
  32. static const uint32 m_dwSamplingRates[4][3];
  33. static const uint32 m_dwPaddingSizes[3];
  34. static const uint32 m_dwBitrates[2][3][15];
  35. static const uint32 m_dwSamplesPerFrames[2][3];
  36. static const uint32 m_dwCoefficients[2][3];
  37. // necessary for CRC check (not yet implemented)
  38. static const uint32 m_dwSideinfoSizes[2][3][2];
  39. static const uint16 wCRC16Table[256];
  40. bool m_bLSF; // true means lower sampling frequencies (=MPEG2/MPEG2.5)
  41. CMPAFile* m_pMPAFile;
  42. public:
  43. static const char * m_szLayers[];
  44. static const char * m_szMPEGVersions[];
  45. static const char * m_szChannelModes[];
  46. static const char * m_szEmphasis[];
  47. enum MPAVersion
  48. {
  49. MPEG25 = 0,
  50. MPEGReserved,
  51. MPEG2,
  52. MPEG1
  53. }m_Version;
  54. enum MPALayer
  55. {
  56. Layer1 = 0,
  57. Layer2,
  58. Layer3,
  59. LayerReserved
  60. }m_Layer;
  61. enum Emphasis
  62. {
  63. EmphNone = 0,
  64. Emph5015,
  65. EmphReserved,
  66. EmphCCITJ17
  67. }m_Emphasis;
  68. enum ChannelMode
  69. {
  70. Stereo,
  71. JointStereo,
  72. DualChannel,
  73. SingleChannel
  74. }m_ChannelMode;
  75. uint32 m_dwSamplesPerSec;
  76. uint32 m_dwSamplesPerFrame;
  77. uint32 m_dwBitrate; // in bit per second (1 kb = 1000 bit, not 1024)
  78. uint32 m_dwSyncOffset;
  79. uint32 m_dwComputedFrameSize, m_dwRealFrameSize;
  80. uint32 m_dwPaddingSize;
  81. // flags
  82. bool m_bCopyright, m_bPrivate, m_bOriginal;
  83. bool m_bCRC;
  84. uint8 m_ModeExt;
  85. private:
  86. enum HeaderError
  87. {
  88. noError,
  89. noSync,
  90. freeBitrate,
  91. headerCorrupt
  92. };
  93. HeaderError DecodeHeader( uint32 dwHeader, bool bSimpleDecode = false );
  94. inline HeaderError IsSync( uint32 dwOffset, bool bExtended );
  95. };
  96. #endif // MPAHEADER_H