sfxALVoice.h

Engine/source/sfx/openal/sfxALVoice.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 _SFXALVOICE_H_
 25#define _SFXALVOICE_H_
 26
 27#ifndef _SFXVOICE_H_
 28   #include "sfx/sfxVoice.h"
 29#endif
 30#ifndef _OPENALFNTABLE
 31   #include "sfx/openal/LoadOAL.h"
 32#endif
 33#ifndef _PLATFORM_THREADS_MUTEX_H_
 34   #include "platform/threads/mutex.h"
 35#endif
 36
 37
 38class SFXALBuffer;
 39class SFXALDevice;
 40
 41class SFXALVoice : public SFXVoice
 42{
 43   public:
 44
 45      typedef SFXVoice Parent;
 46      friend class SFXALDevice;
 47      friend class SFXALBuffer;
 48
 49   protected:
 50
 51      SFXALVoice( const OPENALFNTABLE &oalft,
 52                  SFXALBuffer *buffer, 
 53                  ALuint sourceName );
 54
 55      ALuint mSourceName;
 56
 57      /// Buggy OAL jumps around when pausing.  Save playback cursor here.
 58      F32 mResumeAtSampleOffset;
 59      
 60      /// Amount by which OAL's reported sample position is offset.
 61      ///
 62      /// OAL's sample position is relative to the current queue state,
 63      /// so we manually need to keep track of how far into the total
 64      /// queue we are.
 65      U32 mSampleOffset;
 66
 67      Mutex mMutex;
 68
 69      const OPENALFNTABLE &mOpenAL;
 70
 71      ///
 72      SFXALBuffer* _getBuffer() const
 73      {
 74         return ( SFXALBuffer* ) mBuffer.getPointer();
 75      }
 76      
 77      /// For non-streaming buffers, late-bind the audio buffer
 78      /// to the source as OAL will not accept writes to buffers
 79      /// already bound.
 80      void _lateBindStaticBufferIfNecessary();
 81
 82      // SFXVoice.
 83      virtual SFXStatus _status() const;
 84      virtual void _play();
 85      virtual void _pause();
 86      virtual void _stop();
 87      virtual void _seek( U32 sample );
 88      virtual U32 _tell() const;
 89
 90   public:
 91
 92      static SFXALVoice* create( SFXALDevice* device,
 93                                 SFXALBuffer *buffer );
 94
 95      virtual ~SFXALVoice();
 96
 97      /// SFXVoice
 98      void setMinMaxDistance( F32 min, F32 max );
 99      void play( bool looping );
100      void setVelocity( const VectorF& velocity );
101      void setTransform( const MatrixF& transform );
102      void setVolume( F32 volume );
103      void setPitch( F32 pitch );
104      void setCone( F32 innerAngle, F32 outerAngle, F32 outerVolume );
105      void setRolloffFactor( F32 factor );
106};
107
108#endif // _SFXALVOICE_H_
109