Counter Strike : Global Offensive Source Code
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.

212 lines
5.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #ifndef RIFF_H
  14. #define RIFF_H
  15. #pragma once
  16. #include "filesystem.h"
  17. #include "commonmacros.h"
  18. //-----------------------------------------------------------------------------
  19. // Purpose: This is a simple abstraction that the RIFF classes use to read from
  20. // files/memory
  21. //-----------------------------------------------------------------------------
  22. class IFileReadBinary
  23. {
  24. public:
  25. virtual FileHandle_t open( const char *pFileName ) = 0;
  26. virtual int read( void *pOutput, int size, FileHandle_t file ) = 0;
  27. virtual void close( FileHandle_t file ) = 0;
  28. virtual void seek( FileHandle_t file, int pos ) = 0;
  29. virtual unsigned int tell( FileHandle_t file ) = 0;
  30. virtual unsigned int size( FileHandle_t file ) = 0;
  31. };
  32. //-----------------------------------------------------------------------------
  33. // Purpose: Used to read/parse a RIFF format file
  34. //-----------------------------------------------------------------------------
  35. class InFileRIFF
  36. {
  37. public:
  38. InFileRIFF( const char *pFileName, IFileReadBinary &io );
  39. ~InFileRIFF( void );
  40. unsigned int RIFFName( void ) { return m_riffName; }
  41. unsigned int RIFFSize( void ) { return m_riffSize; }
  42. unsigned int GetFileSize() const { return m_nFileSize; }
  43. int ReadInt( void );
  44. int ReadData( void *pOutput, int dataSize );
  45. int PositionGet( void );
  46. void PositionSet( int position );
  47. bool IsValid( void ) { return m_file != 0; }
  48. private:
  49. const InFileRIFF & operator=( const InFileRIFF & );
  50. IFileReadBinary &m_io;
  51. FileHandle_t m_file;
  52. unsigned int m_riffName;
  53. unsigned int m_riffSize;
  54. unsigned int m_nFileSize;
  55. };
  56. //-----------------------------------------------------------------------------
  57. // Purpose: Used to iterate over an InFileRIFF
  58. //-----------------------------------------------------------------------------
  59. class IterateRIFF
  60. {
  61. public:
  62. IterateRIFF( InFileRIFF &riff, int size );
  63. IterateRIFF( IterateRIFF &parent );
  64. bool ChunkAvailable( void );
  65. bool ChunkNext( void );
  66. unsigned int ChunkName( void );
  67. unsigned int ChunkSize( void );
  68. int ChunkRead( void *pOutput );
  69. int ChunkReadPartial( void *pOutput, int dataSize );
  70. int ChunkReadInt( void );
  71. int ChunkFilePosition( void ) { return m_chunkPosition; }
  72. private:
  73. const IterateRIFF & operator=( const IterateRIFF & );
  74. void ChunkSetup( void );
  75. void ChunkClear( void );
  76. InFileRIFF &m_riff;
  77. int m_start;
  78. int m_size;
  79. unsigned int m_chunkName;
  80. int m_chunkSize;
  81. int m_chunkPosition;
  82. };
  83. class IFileWriteBinary
  84. {
  85. public:
  86. virtual FileHandle_t create( const char *pFileName ) = 0;
  87. virtual int write( void *pData, int size, FileHandle_t file ) = 0;
  88. virtual void close( FileHandle_t file ) = 0;
  89. virtual void seek( FileHandle_t file, int pos ) = 0;
  90. virtual unsigned int tell( FileHandle_t file ) = 0;
  91. };
  92. //-----------------------------------------------------------------------------
  93. // Purpose: Used to write a RIFF format file
  94. //-----------------------------------------------------------------------------
  95. class OutFileRIFF
  96. {
  97. public:
  98. OutFileRIFF( const char *pFileName, IFileWriteBinary &io );
  99. ~OutFileRIFF( void );
  100. bool WriteInt( int number );
  101. bool WriteData( void *pOutput, int dataSize );
  102. int PositionGet( void );
  103. void PositionSet( int position );
  104. bool IsValid( void ) { return m_file != 0; }
  105. void HasLISETData( int position );
  106. private:
  107. const OutFileRIFF & operator=( const OutFileRIFF & );
  108. IFileWriteBinary &m_io;
  109. FileHandle_t m_file;
  110. unsigned int m_riffName;
  111. unsigned int m_riffSize;
  112. unsigned int m_nNamePos;
  113. // hack to make liset work correctly
  114. bool m_bUseIncorrectLISETLength;
  115. int m_nLISETSize;
  116. };
  117. //-----------------------------------------------------------------------------
  118. // Purpose: Used to iterate over an InFileRIFF
  119. //-----------------------------------------------------------------------------
  120. class IterateOutputRIFF
  121. {
  122. public:
  123. IterateOutputRIFF( OutFileRIFF &riff );
  124. IterateOutputRIFF( IterateOutputRIFF &parent );
  125. void ChunkStart( unsigned int chunkname );
  126. void ChunkFinish( void );
  127. void ChunkWrite( unsigned int chunkname, void *pOutput, int size );
  128. void ChunkWriteInt( int number );
  129. void ChunkWriteData( void *pOutput, int size );
  130. int ChunkFilePosition( void ) { return m_chunkPosition; }
  131. unsigned int ChunkGetPosition( void );
  132. void ChunkSetPosition( int position );
  133. void CopyChunkData( IterateRIFF& input );
  134. void SetLISETData( int position );
  135. private:
  136. const IterateOutputRIFF & operator=( const IterateOutputRIFF & );
  137. OutFileRIFF &m_riff;
  138. int m_start;
  139. int m_size;
  140. unsigned int m_chunkName;
  141. int m_chunkSize;
  142. int m_chunkPosition;
  143. int m_chunkStart;
  144. };
  145. #define RIFF_ID MAKEID('R','I','F','F')
  146. #define RIFF_WAVE MAKEID('W','A','V','E')
  147. #define WAVE_FMT MAKEID('f','m','t',' ')
  148. #define WAVE_DATA MAKEID('d','a','t','a')
  149. #define WAVE_FACT MAKEID('f','a','c','t')
  150. #define WAVE_CUE MAKEID('c','u','e',' ')
  151. #define WAVE_SAMPLER MAKEID('s','m','p','l')
  152. #define WAVE_VALVEDATA MAKEID('V','D','A','T')
  153. #define WAVE_PADD MAKEID('P','A','D','D')
  154. #define WAVE_LIST MAKEID('L','I','S','T')
  155. #ifndef WAVE_FORMAT_PCM
  156. #define WAVE_FORMAT_PCM 0x0001
  157. #endif
  158. #ifndef WAVE_FORMAT_ADPCM
  159. #define WAVE_FORMAT_ADPCM 0x0002
  160. #endif
  161. #define WAVE_FORMAT_XBOX_ADPCM 0x0069
  162. #ifndef WAVE_FORMAT_XMA
  163. #define WAVE_FORMAT_XMA 0x0165
  164. #endif
  165. #ifndef WAVE_FORMAT_MP3
  166. #define WAVE_FORMAT_MP3 0x0003
  167. #endif
  168. // Used when doing some tests
  169. #ifndef WAVE_FORMAT_TEMP
  170. #define WAVE_FORMAT_TEMP 0x0004
  171. #endif
  172. #endif // RIFF_H