sfxALBuffer.h

Engine/source/sfx/openal/sfxALBuffer.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 _SFXALBUFFER_H_
 25#define _SFXALBUFFER_H_
 26
 27#ifndef _LOADOAL_H
 28   #include "sfx/openal/LoadOAL.h"
 29#endif
 30#ifndef _SFXINTERNAL_H_
 31   #include "sfx/sfxInternal.h"
 32#endif
 33#ifndef _TVECTOR_H_
 34   #include "core/util/tVector.h"
 35#endif
 36
 37
 38class SFXALVoice;
 39
 40
 41class SFXALBuffer : public SFXBuffer
 42{
 43   public:
 44
 45      typedef SFXBuffer Parent;
 46
 47      friend class SFXALDevice;
 48      friend class SFXALVoice;
 49
 50   protected:
 51      
 52      /// AL buffer in case this is a static, non-streaming buffer.
 53      ALuint mALBuffer;
 54      
 55      /// Free buffers for use in queuing in case this is a streaming buffer.
 56      Vector< ALuint> mFreeBuffers;
 57
 58      ///
 59      SFXALBuffer(   const OPENALFNTABLE &oalft, 
 60                     const ThreadSafeRef< SFXStream>& stream,
 61                     SFXDescription* description,
 62                     bool useHardware );
 63
 64      ///
 65      bool mIs3d;
 66
 67      ///
 68      bool mUseHardware;
 69
 70      const OPENALFNTABLE &mOpenAL;
 71
 72      ///
 73      ALenum _getALFormat() const
 74      {
 75         return _sfxFormatToALFormat( getFormat() );
 76      }
 77
 78      ///
 79      static ALenum _sfxFormatToALFormat( const SFXFormat& format )
 80      {
 81         if( format.getChannels() == 2 )
 82         {
 83            const U32 bps = format.getBitsPerSample();
 84            if( bps == 16 )
 85               return AL_FORMAT_STEREO8;
 86            else if( bps == 32 )
 87               return AL_FORMAT_STEREO16;
 88         }
 89         else if( format.getChannels() == 1 )
 90         {
 91            const U32 bps = format.getBitsPerSample();
 92            if( bps == 8 )
 93               return AL_FORMAT_MONO8;
 94            else if( bps == 16 )
 95               return AL_FORMAT_MONO16;
 96         }
 97         return 0;
 98      }
 99
100      ///
101      SFXALVoice* _getUniqueVoice() const
102      {
103         return ( SFXALVoice* ) mUniqueVoice.getPointer();
104      }
105
106      // SFXBuffer.
107      virtual void write( SFXInternal::SFXStreamPacket* const* packets, U32 num );
108      void _flush();
109
110   public:
111
112      static SFXALBuffer* create(   const OPENALFNTABLE &oalft, 
113                                    const ThreadSafeRef< SFXStream>& stream,
114                                    SFXDescription* description,
115                                    bool useHardware );
116
117      virtual ~SFXALBuffer();
118};
119
120#endif // _SFXALBUFFER_H_
121