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.

85 lines
2.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef XWVFILE_H
  7. #define XWVFILE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #pragma pack(1)
  12. #define XWV_ID (('X'<<24)|('W'<<16)|('V'<<8)|(' '<<0))
  13. #define XWV_VERSION 4
  14. enum xwvSampleRate_t
  15. {
  16. XWV_RATE_11025 = 0,
  17. XWV_RATE_22050 = 1,
  18. XWV_RATE_44100 = 2,
  19. };
  20. enum xwvFormat_t
  21. {
  22. XWV_FORMAT_PCM = 0,
  23. XWV_FORMAT_XMA = 1,
  24. XWV_FORMAT_ADPCM = 2,
  25. };
  26. // generated in big-endian
  27. struct xwvHeader_t
  28. {
  29. unsigned int id;
  30. unsigned int version;
  31. unsigned int headerSize; // header only
  32. unsigned int staticDataSize; // follows header
  33. unsigned int dataOffset; // start of samples, possibly sector aligned
  34. unsigned int dataSize; // length of samples in bytes
  35. unsigned int numDecodedSamples; // for duration calcs
  36. int loopStart; // -1 = no loop, offset of loop in samples
  37. unsigned short loopBlock; // the xma block where the loop starts
  38. unsigned short numLeadingSamples; // number of leading samples in the loop block to discard
  39. unsigned short numTrailingSamples; // number of trailing samples at the final block to discard
  40. unsigned short vdatSize; // follows seek table
  41. byte format;
  42. byte bitsPerSample;
  43. byte sampleRate;
  44. byte channels;
  45. byte quality;
  46. byte bHasSeekTable; // indicates presence, follows header
  47. byte padding[2]; // created as 0
  48. inline unsigned int GetPreloadSize() { return headerSize + staticDataSize; }
  49. inline int GetBitsPerSample() const { return bitsPerSample; }
  50. int GetSampleRate() const
  51. {
  52. int rates[] = {11025, 22050, 44100};
  53. int rate = sampleRate;
  54. return rates[rate];
  55. }
  56. inline int GetChannels() const { return channels; }
  57. void SetSampleRate( int sampleRateIn )
  58. {
  59. byte rate = ( sampleRateIn == 11025 ) ? XWV_RATE_11025 : ( sampleRateIn==22050 )? XWV_RATE_22050 : XWV_RATE_44100;
  60. sampleRate = rate;
  61. }
  62. inline void SetChannels( int channelsIn ) { channels = channelsIn; }
  63. inline int GetSeekTableSize()
  64. {
  65. // seek table is indexed by packets
  66. return bHasSeekTable ? ( dataSize / 2048 ) * sizeof( int ) : 0;
  67. }
  68. };
  69. #pragma pack()
  70. #endif // XWVFILE_H