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.

125 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Uses mp3 code from: http://www.codeproject.com/audio/MPEGAudioInfo.asp
  4. //
  5. // There don't appear to be any licensing restrictions for using this code:
  6. //
  7. /*
  8. - Readme - MPEG Audio Info Tool V2.0 - 2004-11-01
  9. Description:
  10. This tool can display information about MPEG audio files. It supports
  11. MPEG1, MPEG2, MPEG2.5 in all three layers. You can get all the fields
  12. from the MPEG audio frame in each frame of the file. Additionally you
  13. can check the whole file for inconsistencies.
  14. This tool was written as an example on how to use the classes:
  15. CMPAFile, CMPAHeader, CVBRHeader and CMPAException.
  16. The article MPEG Audio Frame Header on Sourceproject
  17. [http://www.codeproject.com/audio/MPEGAudioInfo.asp]
  18. provides additional information about these classes and the frame header
  19. in general.
  20. This tool was written with MS Visual C++ 7.1. The MFC library is
  21. statically linked.
  22. */
  23. //=============================================================================
  24. #ifndef MPAFILE_H
  25. #define MPAFILE_H
  26. #ifdef _WIN32
  27. #pragma once
  28. #endif
  29. #pragma once
  30. #include "VBRHeader.h"
  31. #include "MPAHeader.h"
  32. #include "filesystem.h"
  33. // exception class
  34. class CMPAException
  35. {
  36. public:
  37. enum ErrorIDs
  38. {
  39. ErrOpenFile,
  40. ErrSetPosition,
  41. ErrReadFile,
  42. EndOfBuffer,
  43. NoVBRHeader,
  44. IncompleteVBRHeader,
  45. NoFrameInTolerance,
  46. NoFrame
  47. };
  48. CMPAException( ErrorIDs ErrorID, const char *szFile, const char *szFunction = NULL, bool bGetLastError=false );
  49. // copy constructor (necessary because of LPSTR members)
  50. CMPAException(const CMPAException& Source);
  51. ~CMPAException(void);
  52. ErrorIDs GetErrorID() { return m_ErrorID; }
  53. void ShowError();
  54. private:
  55. ErrorIDs m_ErrorID;
  56. bool m_bGetLastError;
  57. const char *m_szFunction;
  58. const char *m_szFile;
  59. };
  60. class CMPAFile
  61. {
  62. public:
  63. CMPAFile( const char *szFile, uint32 dwFileOffset, FileHandle_t hFile = FILESYSTEM_INVALID_HANDLE );
  64. ~CMPAFile(void);
  65. uint32 ExtractBytes( uint32 &dwOffset, uint32 dwNumBytes, bool bMoveOffset = true );
  66. const char *GetFilename() const { return m_szFile; };
  67. bool GetNextFrame();
  68. bool GetPrevFrame();
  69. bool GetFirstFrame();
  70. bool GetLastFrame();
  71. private:
  72. static const uint32 m_dwInitBufferSize;
  73. // methods for file access
  74. void Open( const char *szFilename );
  75. void SetPosition( int offset );
  76. uint32 Read( void *pData, uint32 dwSize, uint32 dwOffset );
  77. void FillBuffer( uint32 dwOffsetToRead );
  78. static uint32 m_dwBufferSizes[MAXTIMESREAD];
  79. // concerning file itself
  80. FileHandle_t m_hFile;
  81. const char *m_szFile;
  82. bool m_bMustReleaseFile;
  83. public:
  84. uint32 m_dwBegin; // offset of first MPEG Audio frame
  85. uint32 m_dwEnd; // offset of last MPEG Audio frame (estimated)
  86. bool m_bVBRFile;
  87. uint32 m_dwBytesPerSec;
  88. CMPAHeader* m_pMPAHeader;
  89. uint32 m_dwFrameNo;
  90. CVBRHeader* m_pVBRHeader; // XING or VBRI
  91. // concerning read-buffer
  92. uint32 m_dwNumTimesRead;
  93. char *m_pBuffer;
  94. uint32 m_dwBufferSize;
  95. };
  96. #endif // MPAFILE_H