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.

397 lines
10 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: xact2wb.h
  6. * Content: XACT 2 wave bank definitions.
  7. *
  8. ****************************************************************************/
  9. #ifndef __XACTWB_H__
  10. #define __XACTWB_H__
  11. #ifdef _XBOX
  12. # include <xauddefs.h>
  13. #else
  14. # include <math.h>
  15. #endif
  16. #include <xact.h>
  17. #pragma warning(push)
  18. #pragma warning(disable:4201)
  19. #pragma warning(disable:4214) // nonstandard extension used : bit field types other than int
  20. #pragma pack(push, 1)
  21. #ifdef _M_PPCBE
  22. #pragma bitfield_order(push, lsb_to_msb)
  23. #endif
  24. #define WAVEBANK_HEADER_SIGNATURE 'DNBW' // WaveBank RIFF chunk signature
  25. #define WAVEBANK_HEADER_VERSION 42 // Current wavebank file version
  26. #define WAVEBANK_BANKNAME_LENGTH 64 // Wave bank friendly name length, in characters
  27. #define WAVEBANK_ENTRYNAME_LENGTH 64 // Wave bank entry friendly name length, in characters
  28. #define WAVEBANK_MAX_DATA_SEGMENT_SIZE 0xFFFFFFFF // Maximum wave bank data segment size, in bytes
  29. #define WAVEBANK_MAX_COMPACT_DATA_SEGMENT_SIZE 0x001FFFFF // Maximum compact wave bank data segment size, in bytes
  30. typedef DWORD WAVEBANKOFFSET;
  31. //
  32. // Bank flags
  33. //
  34. #define WAVEBANK_TYPE_BUFFER 0x00000000 // In-memory buffer
  35. #define WAVEBANK_TYPE_STREAMING 0x00000001 // Streaming
  36. #define WAVEBANK_TYPE_MASK 0x00000001
  37. #define WAVEBANK_FLAGS_ENTRYNAMES 0x00010000 // Bank includes entry names
  38. #define WAVEBANK_FLAGS_COMPACT 0x00020000 // Bank uses compact format
  39. #define WAVEBANK_FLAGS_SYNC_DISABLED 0x00040000 // Bank is disabled for audition sync
  40. #define WAVEBANK_FLAGS_SEEKTABLES 0x00080000 // Bank includes seek tables.
  41. #define WAVEBANK_FLAGS_MASK 0x000F0000
  42. //
  43. // Entry flags
  44. //
  45. #define WAVEBANKENTRY_FLAGS_READAHEAD 0x00000001 // Enable stream read-ahead
  46. #define WAVEBANKENTRY_FLAGS_LOOPCACHE 0x00000002 // One or more looping sounds use this wave
  47. #define WAVEBANKENTRY_FLAGS_REMOVELOOPTAIL 0x00000004 // Remove data after the end of the loop region
  48. #define WAVEBANKENTRY_FLAGS_IGNORELOOP 0x00000008 // Used internally when the loop region can't be used
  49. #define WAVEBANKENTRY_FLAGS_MASK 0x00000008
  50. //
  51. // Entry wave format identifiers
  52. //
  53. #define WAVEBANKMINIFORMAT_TAG_PCM 0x0 // PCM data
  54. #define WAVEBANKMINIFORMAT_TAG_XMA 0x1 // XMA data
  55. #define WAVEBANKMINIFORMAT_TAG_ADPCM 0x2 // ADPCM data
  56. #define WAVEBANKMINIFORMAT_BITDEPTH_8 0x0 // 8-bit data (PCM only)
  57. #define WAVEBANKMINIFORMAT_BITDEPTH_16 0x1 // 16-bit data (PCM only)
  58. //
  59. // Arbitrary fixed sizes
  60. //
  61. #define WAVEBANKENTRY_XMASTREAMS_MAX 3 // enough for 5.1 channel audio
  62. #define WAVEBANKENTRY_XMACHANNELS_MAX 6 // enough for 5.1 channel audio (cf. XAUDIOCHANNEL_SOURCEMAX)
  63. //
  64. // DVD data sizes
  65. //
  66. #define WAVEBANK_DVD_SECTOR_SIZE 2048
  67. #define WAVEBANK_DVD_BLOCK_SIZE (WAVEBANK_DVD_SECTOR_SIZE * 16)
  68. //
  69. // Bank alignment presets
  70. //
  71. #define WAVEBANK_ALIGNMENT_MIN 4 // Minimum alignment
  72. #define WAVEBANK_ALIGNMENT_DVD WAVEBANK_DVD_SECTOR_SIZE // DVD-optimized alignment
  73. //
  74. // Wave bank segment identifiers
  75. //
  76. typedef enum WAVEBANKSEGIDX
  77. {
  78. WAVEBANK_SEGIDX_BANKDATA = 0, // Bank data
  79. WAVEBANK_SEGIDX_ENTRYMETADATA, // Entry meta-data
  80. WAVEBANK_SEGIDX_SEEKTABLES, // Storage for seek tables for the encoded waves.
  81. WAVEBANK_SEGIDX_ENTRYNAMES, // Entry friendly names
  82. WAVEBANK_SEGIDX_ENTRYWAVEDATA, // Entry wave data
  83. WAVEBANK_SEGIDX_COUNT
  84. } WAVEBANKSEGIDX, *LPWAVEBANKSEGIDX;
  85. typedef const WAVEBANKSEGIDX *LPCWAVEBANKSEGIDX;
  86. //
  87. // Endianness
  88. //
  89. #ifdef __cplusplus
  90. namespace XACTWaveBank
  91. {
  92. __inline void SwapBytes(DWORD &dw)
  93. {
  94. #ifdef _X86_
  95. __asm
  96. {
  97. mov edi, dw
  98. mov eax, [edi]
  99. bswap eax
  100. mov [edi], eax
  101. }
  102. #else // _X86_
  103. dw = _byteswap_ulong(dw);
  104. #endif // _X86_
  105. }
  106. __inline void SwapBytes(WORD &w)
  107. {
  108. #ifdef _X86_
  109. __asm
  110. {
  111. mov edi, w
  112. mov ax, [edi]
  113. xchg ah, al
  114. mov [edi], ax
  115. }
  116. #else // _X86_
  117. w = _byteswap_ushort(w);
  118. #endif // _X86_
  119. }
  120. }
  121. #endif // __cplusplus
  122. //
  123. // Wave bank region in bytes.
  124. //
  125. typedef struct WAVEBANKREGION
  126. {
  127. DWORD dwOffset; // Region offset, in bytes.
  128. DWORD dwLength; // Region length, in bytes.
  129. #ifdef __cplusplus
  130. void SwapBytes(void)
  131. {
  132. XACTWaveBank::SwapBytes(dwOffset);
  133. XACTWaveBank::SwapBytes(dwLength);
  134. }
  135. #endif // __cplusplus
  136. } WAVEBANKREGION, *LPWAVEBANKREGION;
  137. typedef const WAVEBANKREGION *LPCWAVEBANKREGION;
  138. //
  139. // Wave bank region in samples.
  140. //
  141. typedef struct WAVEBANKSAMPLEREGION
  142. {
  143. DWORD dwStartSample; // Start sample for the region.
  144. DWORD dwTotalSamples; // Region length in samples.
  145. #ifdef __cplusplus
  146. void SwapBytes(void)
  147. {
  148. XACTWaveBank::SwapBytes(dwStartSample);
  149. XACTWaveBank::SwapBytes(dwTotalSamples);
  150. }
  151. #endif // __cplusplus
  152. } WAVEBANKSAMPLEREGION, *LPWAVEBANKSAMPLEREGION;
  153. typedef const WAVEBANKSAMPLEREGION *LPCWAVEBANKSAMPLEREGION;
  154. //
  155. // Wave bank file header
  156. //
  157. typedef struct WAVEBANKHEADER
  158. {
  159. DWORD dwSignature; // File signature
  160. DWORD dwVersion; // Version of the tool that created the file
  161. DWORD dwHeaderVersion; // Version of the file format
  162. WAVEBANKREGION Segments[WAVEBANK_SEGIDX_COUNT]; // Segment lookup table
  163. #ifdef __cplusplus
  164. void SwapBytes(void)
  165. {
  166. XACTWaveBank::SwapBytes(dwSignature);
  167. XACTWaveBank::SwapBytes(dwVersion);
  168. XACTWaveBank::SwapBytes(dwHeaderVersion);
  169. for(int i = 0; i < WAVEBANK_SEGIDX_COUNT; i++)
  170. {
  171. Segments[i].SwapBytes();
  172. }
  173. }
  174. #endif // __cplusplus
  175. } WAVEBANKHEADER, *LPWAVEBANKHEADER;
  176. typedef const WAVEBANKHEADER *LPCWAVEBANKHEADER;
  177. //
  178. // Entry compressed data format
  179. //
  180. typedef union WAVEBANKMINIWAVEFORMAT
  181. {
  182. struct
  183. {
  184. DWORD wFormatTag : 2; // Format tag
  185. DWORD nChannels : 3; // Channel count (1 - 6)
  186. DWORD nSamplesPerSec : 18; // Sampling rate
  187. DWORD wBlockAlign : 8; // Block alignment
  188. DWORD wBitsPerSample : 1; // Bits per sample (8 vs. 16, PCM only)
  189. };
  190. DWORD dwValue;
  191. #ifdef __cplusplus
  192. void SwapBytes(void)
  193. {
  194. XACTWaveBank::SwapBytes(dwValue);
  195. }
  196. WORD BitsPerSample() const
  197. {
  198. return wBitsPerSample == WAVEBANKMINIFORMAT_BITDEPTH_16 ? 16 : 8;
  199. }
  200. #define ADPCM_MINIWAVEFORMAT_BLOCKALIGN_CONVERSION_OFFSET 22
  201. DWORD BlockAlign() const
  202. {
  203. return wFormatTag != WAVEBANKMINIFORMAT_TAG_ADPCM ? wBlockAlign :
  204. (wBlockAlign + ADPCM_MINIWAVEFORMAT_BLOCKALIGN_CONVERSION_OFFSET) * nChannels;
  205. }
  206. #endif // __cplusplus
  207. } WAVEBANKMINIWAVEFORMAT, *LPWAVEBANKMINIWAVEFORMAT;
  208. typedef const WAVEBANKMINIWAVEFORMAT *LPCWAVEBANKMINIWAVEFORMAT;
  209. //
  210. // Entry meta-data
  211. //
  212. typedef struct WAVEBANKENTRY
  213. {
  214. union
  215. {
  216. struct
  217. {
  218. // Entry flags
  219. DWORD dwFlags : 4;
  220. // Duration of the wave, in units of one sample.
  221. // For instance, a ten second long wave sampled
  222. // at 48KHz would have a duration of 480,000.
  223. // This value is not affected by the number of
  224. // channels, the number of bits per sample, or the
  225. // compression format of the wave.
  226. DWORD Duration : 28;
  227. };
  228. DWORD dwFlagsAndDuration;
  229. };
  230. WAVEBANKMINIWAVEFORMAT Format; // Entry format.
  231. WAVEBANKREGION PlayRegion; // Region within the wave data segment that contains this entry.
  232. WAVEBANKSAMPLEREGION LoopRegion; // Region within the wave data (in samples) that should loop.
  233. #ifdef __cplusplus
  234. void SwapBytes(void)
  235. {
  236. XACTWaveBank::SwapBytes(dwFlagsAndDuration);
  237. Format.SwapBytes();
  238. PlayRegion.SwapBytes();
  239. LoopRegion.SwapBytes();
  240. }
  241. #endif // __cplusplus
  242. } WAVEBANKENTRY, *LPWAVEBANKENTRY;
  243. typedef const WAVEBANKENTRY *LPCWAVEBANKENTRY;
  244. //
  245. // Compact entry meta-data
  246. //
  247. typedef struct WAVEBANKENTRYCOMPACT
  248. {
  249. DWORD dwOffset : 21; // Data offset, in sectors
  250. DWORD dwLengthDeviation : 11; // Data length deviation, in bytes
  251. #ifdef __cplusplus
  252. void SwapBytes(void)
  253. {
  254. XACTWaveBank::SwapBytes(*(LPDWORD)this);
  255. }
  256. #endif // __cplusplus
  257. } WAVEBANKENTRYCOMPACT, *LPWAVEBANKENTRYCOMPACT;
  258. typedef const WAVEBANKENTRYCOMPACT *LPCWAVEBANKENTRYCOMPACT;
  259. //
  260. // Bank data segment
  261. //
  262. typedef struct WAVEBANKDATA
  263. {
  264. DWORD dwFlags; // Bank flags
  265. DWORD dwEntryCount; // Number of entries in the bank
  266. CHAR szBankName[WAVEBANK_BANKNAME_LENGTH]; // Bank friendly name
  267. DWORD dwEntryMetaDataElementSize; // Size of each entry meta-data element, in bytes
  268. DWORD dwEntryNameElementSize; // Size of each entry name element, in bytes
  269. DWORD dwAlignment; // Entry alignment, in bytes
  270. WAVEBANKMINIWAVEFORMAT CompactFormat; // Format data for compact bank
  271. FILETIME BuildTime; // Build timestamp
  272. #ifdef __cplusplus
  273. void SwapBytes(void)
  274. {
  275. XACTWaveBank::SwapBytes(dwFlags);
  276. XACTWaveBank::SwapBytes(dwEntryCount);
  277. XACTWaveBank::SwapBytes(dwEntryMetaDataElementSize);
  278. XACTWaveBank::SwapBytes(dwEntryNameElementSize);
  279. XACTWaveBank::SwapBytes(dwAlignment);
  280. CompactFormat.SwapBytes();
  281. XACTWaveBank::SwapBytes(BuildTime.dwLowDateTime);
  282. XACTWaveBank::SwapBytes(BuildTime.dwHighDateTime);
  283. }
  284. #endif // __cplusplus
  285. } WAVEBANKDATA, *LPWAVEBANKDATA;
  286. typedef const WAVEBANKDATA *LPCWAVEBANKDATA;
  287. #ifdef _M_PPCBE
  288. #pragma bitfield_order(pop)
  289. #endif
  290. #pragma warning(pop)
  291. #pragma pack(pop)
  292. #endif // __XACTWB_H__