XA2_SoundVoice.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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_SOUNDVOICE_H__
  21. #define __XA2_SOUNDVOICE_H__
  22. static const int MAX_QUEUED_BUFFERS = 3;
  23. /*
  24. ================================================
  25. idSoundVoice_XAudio2
  26. ================================================
  27. */
  28. class idSoundVoice_XAudio2 : public idSoundVoice_Base {
  29. public:
  30. idSoundVoice_XAudio2();
  31. ~idSoundVoice_XAudio2();
  32. void Create( const idSoundSample * leadinSample, const idSoundSample * loopingSample );
  33. // Start playing at a particular point in the buffer. Does an Update() too
  34. void Start( int offsetMS, int ssFlags );
  35. // Stop playing.
  36. void Stop();
  37. // Stop consuming buffers
  38. void Pause();
  39. // Start consuming buffers again
  40. void UnPause();
  41. // Sends new position/volume/pitch information to the hardware
  42. bool Update();
  43. // returns the RMS levels of the most recently processed block of audio, SSF_FLICKER must have been passed to Start
  44. float GetAmplitude();
  45. // returns true if we can re-use this voice
  46. bool CompatibleFormat( idSoundSample_XAudio2 * s );
  47. uint32 GetSampleRate() const { return sampleRate; }
  48. // callback function
  49. void OnBufferStart( idSoundSample_XAudio2 * sample, int bufferNumber );
  50. private:
  51. friend class idSoundHardware_XAudio2;
  52. // Returns true when all the buffers are finished processing
  53. bool IsPlaying();
  54. // Called after the voice has been stopped
  55. void FlushSourceBuffers();
  56. // Destroy the internal hardware resource
  57. void DestroyInternal();
  58. // Helper function used by the initial start as well as for looping a streamed buffer
  59. int RestartAt( int offsetSamples );
  60. // Helper function to submit a buffer
  61. int SubmitBuffer( idSoundSample_XAudio2 * sample, int bufferNumber, int offset );
  62. // Adjust the voice frequency based on the new sample rate for the buffer
  63. void SetSampleRate( uint32 newSampleRate, uint32 operationSet );
  64. IXAudio2SourceVoice * pSourceVoice;
  65. idSoundSample_XAudio2 * leadinSample;
  66. idSoundSample_XAudio2 * loopingSample;
  67. // These are the fields from the sample format that matter to us for voice reuse
  68. uint16 formatTag;
  69. uint16 numChannels;
  70. uint32 sourceVoiceRate;
  71. uint32 sampleRate;
  72. bool hasVUMeter;
  73. bool paused;
  74. };
  75. /*
  76. ================================================
  77. idSoundVoice
  78. ================================================
  79. */
  80. class idSoundVoice : public idSoundVoice_XAudio2 {
  81. };
  82. #endif