Torque3D Documentation / _generateds / sfxXAudioVoice.h

sfxXAudioVoice.h

Engine/source/sfx/xaudio/sfxXAudioVoice.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _SFXXAUDIOVOICE_H_
 25#define _SFXXAUDIOVOICE_H_
 26
 27#include <xaudio2.h>
 28#include <x3daudio.h>
 29
 30#include "sfx/sfxVoice.h"
 31
 32
 33class SFXXAudioBuffer;
 34
 35
 36class SFXXAudioVoice :  public SFXVoice,
 37                        public IXAudio2VoiceCallback
 38{
 39   public:
 40
 41      typedef SFXVoice Parent;
 42
 43      friend class SFXXAudioDevice;
 44      friend class SFXXAudioBuffer;
 45
 46   protected:
 47
 48      /// This constructor does not create a valid voice.
 49      /// @see SFXXAudioVoice::create
 50      SFXXAudioVoice( SFXXAudioBuffer* buffer );
 51
 52      /// The device that created us.
 53      SFXXAudioDevice *mXAudioDevice;
 54
 55      /// The XAudio voice.
 56      IXAudio2SourceVoice *mXAudioVoice;
 57
 58      ///
 59      CRITICAL_SECTION mLock;
 60
 61      /// Used to know what sounds need positional updates.
 62      bool mIs3D;
 63
 64      /// Whether the voice has stopped playing.
 65      mutable bool mHasStopped;
 66
 67      /// Whether we have started playback.
 68      bool mHasStarted;
 69
 70      /// Whether playback is currently running.
 71      bool mIsPlaying;
 72
 73      /// Whether playback is looping.
 74      bool mIsLooping;
 75
 76      /// Since 3D sounds are pitch shifted for doppler
 77      /// effect we need to track the users base pitch.
 78      F32 mPitch;
 79
 80      /// The cached X3DAudio emitter data.
 81      X3DAUDIO_EMITTER mEmitter;
 82
 83      /// XAudio does not reset the SamplesPlayed count as is stated in the docs.  To work around
 84      /// that, we offset the values reported by XAudio through this field.
 85      S32 mSamplesPlayedOffset;
 86
 87      /// @name Data for Non-Streaming Voices
 88      /// @{
 89
 90      /// Whether we have loaded our non-streaming data.  We use an explicit
 91      /// flag here as we really can't rely on XAUDIO2_VOICE_STATE.
 92      bool mNonStreamBufferLoaded;
 93
 94      /// Audio buffer for non-streaming voice.
 95      XAUDIO2_BUFFER mNonStreamBuffer;
 96
 97      /// Sample to start playing at when seting up #mNonStreamBuffer.
 98      U32 mNonStreamSampleStartPos;
 99
100      /// @}
101
102      // IXAudio2VoiceCallback
103      void STDMETHODCALLTYPE OnStreamEnd();      
104      void STDMETHODCALLTYPE OnVoiceProcessingPassStart( UINT32 BytesRequired ) {}
105      void STDMETHODCALLTYPE OnVoiceProcessingPassEnd() {}
106      void STDMETHODCALLTYPE OnBufferEnd( void *bufferContext );
107      void STDMETHODCALLTYPE OnBufferStart( void *bufferContext ) {}
108      void STDMETHODCALLTYPE OnLoopEnd( void *bufferContext ) {}
109      void STDMETHODCALLTYPE OnVoiceError( void * bufferContext, HRESULT error ) {}
110
111      /// @deprecated This is only here for compatibility with
112      /// the March 2008 SDK version of IXAudio2VoiceCallback.
113      void STDMETHODCALLTYPE OnVoiceProcessingPassStart() {} 
114
115      void _flush();
116      void _loadNonStreamed();
117
118      // SFXVoice.
119      virtual SFXStatus _status() const;
120      virtual void _play();
121      virtual void _pause();
122      virtual void _stop();
123      virtual void _seek( U32 sample );
124      virtual U32 _tell() const;
125
126      SFXXAudioBuffer* _getBuffer() const { return ( SFXXAudioBuffer* ) mBuffer.getPointer(); }
127
128   public:
129
130      ///
131      static SFXXAudioVoice* create(   IXAudio2 *xaudio,
132                                       bool is3D,
133                                       SFXXAudioBuffer *buffer,
134                                       SFXXAudioVoice* inVoice = NULL );
135
136      ///
137      virtual ~SFXXAudioVoice();
138
139      // SFXVoice
140      void setMinMaxDistance( F32 min, F32 max );
141      void play( bool looping );
142      void setVelocity( const VectorF& velocity );
143      void setTransform( const MatrixF& transform );
144      void setVolume( F32 volume );
145      void setPitch( F32 pitch );
146      void setCone( F32 innerAngle, F32 outerAngle, F32 outerVolume );
147
148      /// Is this a 3D positional voice.
149      bool is3D() const { return mIs3D; }
150
151      ///
152      const X3DAUDIO_EMITTER& getEmitter() const { return mEmitter; }
153};
154
155#endif // _SFXXAUDIOVOICE_H_
156