DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

XA2_SoundVoice.h (4005B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 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.
     23 
     24 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.
     25 
     26 ===========================================================================
     27 */
     28 #ifndef __XA2_SOUNDVOICE_H__
     29 #define __XA2_SOUNDVOICE_H__
     30 
     31 static const int MAX_QUEUED_BUFFERS = 3;
     32 
     33 /*
     34 ================================================
     35 idSoundVoice_XAudio2
     36 ================================================
     37 */
     38 class idSoundVoice_XAudio2 : public idSoundVoice_Base {
     39 public:
     40 							idSoundVoice_XAudio2();
     41 							~idSoundVoice_XAudio2();
     42 
     43 	void					Create( const idSoundSample * leadinSample, const idSoundSample * loopingSample );
     44 
     45 	// Start playing at a particular point in the buffer.  Does an Update() too
     46 	void					Start( int offsetMS, int ssFlags );
     47 
     48 	// Stop playing.
     49 	void					Stop();
     50 
     51 	// Stop consuming buffers
     52 	void					Pause();
     53 	// Start consuming buffers again
     54 	void					UnPause();
     55 
     56 	// Sends new position/volume/pitch information to the hardware
     57 	bool					Update();
     58 
     59 	// returns the RMS levels of the most recently processed block of audio, SSF_FLICKER must have been passed to Start
     60 	float					GetAmplitude();
     61 
     62 	// returns true if we can re-use this voice
     63 	bool					CompatibleFormat( idSoundSample_XAudio2 * s );
     64 
     65 	uint32					GetSampleRate() const { return sampleRate; }
     66 
     67 	// callback function
     68 	void					OnBufferStart( idSoundSample_XAudio2 * sample, int bufferNumber );
     69 
     70 private:
     71 	friend class idSoundHardware_XAudio2;
     72 
     73 	// Returns true when all the buffers are finished processing
     74 	bool					IsPlaying();
     75 
     76 	// Called after the voice has been stopped
     77 	void					FlushSourceBuffers();
     78 
     79 	// Destroy the internal hardware resource
     80 	void					DestroyInternal();
     81 
     82 	// Helper function used by the initial start as well as for looping a streamed buffer
     83 	int						RestartAt( int offsetSamples );
     84 
     85 	// Helper function to submit a buffer
     86 	int						SubmitBuffer( idSoundSample_XAudio2 * sample, int bufferNumber, int offset );
     87 
     88 	// Adjust the voice frequency based on the new sample rate for the buffer
     89 	void					SetSampleRate( uint32 newSampleRate, uint32 operationSet );
     90 
     91 	IXAudio2SourceVoice *	pSourceVoice;
     92 	idSoundSample_XAudio2 * leadinSample;
     93 	idSoundSample_XAudio2 * loopingSample;
     94 
     95 	// These are the fields from the sample format that matter to us for voice reuse
     96 	uint16					formatTag;
     97 	uint16					numChannels;
     98 
     99 	uint32					sourceVoiceRate;
    100 	uint32					sampleRate;
    101 
    102 	bool					hasVUMeter;
    103 	bool					paused;
    104 };
    105 
    106 /*
    107 ================================================
    108 idSoundVoice
    109 ================================================
    110 */
    111 class idSoundVoice : public idSoundVoice_XAudio2 {
    112 };
    113 
    114 #endif