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.

202 lines
5.4 KiB

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