XA2_SoundSample.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __XA2_SOUNDSAMPLE_H__
  21. #define __XA2_SOUNDSAMPLE_H__
  22. /*
  23. ================================================
  24. idSoundSample_XAudio2
  25. ================================================
  26. */
  27. class idSampleInfo;
  28. class idSoundSample_XAudio2 {
  29. public:
  30. idSoundSample_XAudio2();
  31. // Loads and initializes the resource based on the name.
  32. virtual void LoadResource();
  33. void SetName( const char * n ) { name = n; }
  34. const char * GetName() const { return name; }
  35. ID_TIME_T GetTimestamp() const { return timestamp; }
  36. // turns it into a beep
  37. void MakeDefault();
  38. // frees all data
  39. void FreeData();
  40. int LengthInMsec() const { return SamplesToMsec( NumSamples(), SampleRate() ); }
  41. int SampleRate() const { return format.basic.samplesPerSec; }
  42. int NumSamples() const { return playLength; }
  43. int NumChannels() const { return format.basic.numChannels; }
  44. int BufferSize() const { return totalBufferSize; }
  45. bool IsCompressed() const { return ( format.basic.formatTag != idWaveFile::FORMAT_PCM ); }
  46. bool IsDefault() const { return timestamp == FILE_NOT_FOUND_TIMESTAMP; }
  47. bool IsLoaded() const { return loaded; }
  48. void SetNeverPurge() { neverPurge = true; }
  49. bool GetNeverPurge() const { return neverPurge; }
  50. void SetLevelLoadReferenced() { levelLoadReferenced = true; }
  51. void ResetLevelLoadReferenced() { levelLoadReferenced = false; }
  52. bool GetLevelLoadReferenced() const { return levelLoadReferenced; }
  53. int GetLastPlayedTime() const { return lastPlayedTime; }
  54. void SetLastPlayedTime( int t ) { lastPlayedTime = t; }
  55. float GetAmplitude( int timeMS ) const;
  56. protected:
  57. friend class idSoundHardware_XAudio2;
  58. friend class idSoundVoice_XAudio2;
  59. ~idSoundSample_XAudio2();
  60. bool LoadWav( const idStr & name );
  61. bool LoadAmplitude( const idStr & name );
  62. void WriteAllSamples( const idStr &sampleName );
  63. bool LoadGeneratedSample( const idStr &name );
  64. void WriteGeneratedSample( idFile *fileOut );
  65. struct sampleBuffer_t {
  66. void * buffer;
  67. int bufferSize;
  68. int numSamples;
  69. };
  70. idStr name;
  71. ID_TIME_T timestamp;
  72. bool loaded;
  73. bool neverPurge;
  74. bool levelLoadReferenced;
  75. bool usesMapHeap;
  76. uint32 lastPlayedTime;
  77. int totalBufferSize; // total size of all the buffers
  78. idList<sampleBuffer_t, TAG_AUDIO> buffers;
  79. int playBegin;
  80. int playLength;
  81. idWaveFile::waveFmt_t format;
  82. idList<byte, TAG_AMPLITUDE> amplitude;
  83. };
  84. /*
  85. ================================================
  86. idSoundSample
  87. This reverse-inheritance purportedly makes working on
  88. multiple platforms easier.
  89. ================================================
  90. */
  91. class idSoundSample : public idSoundSample_XAudio2 {
  92. public:
  93. };
  94. #endif