sfxDSBuffer.h

Engine/source/sfx/dsound/sfxDSBuffer.h

More...

Classes:

class

DirectSound SFXBuffer implementation.

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 _SFXDSBUFFER_H_
 25#define _SFXDSBUFFER_H_
 26
 27#include <dsound.h>
 28
 29#ifndef _SFXINTERNAL_H_
 30#  include "sfx/sfxInternal.h"
 31#endif
 32
 33
 34/// DirectSound SFXBuffer implementation.
 35///
 36/// Note that the actual sound buffer held by the buffer may
 37/// get duplicated around for individual voices.  This is kind
 38/// of ugly as the resulting buffers aren't tied to a SFXDSBuffer
 39/// anymore.
 40class SFXDSBuffer : public SFXInternal::SFXWrapAroundBuffer
 41{
 42      typedef SFXInternal::SFXWrapAroundBuffer Parent;
 43
 44      friend class SFXDSDevice;
 45      friend class SFXDSVoice;
 46
 47   protected:
 48
 49      ///
 50      bool mIs3d;
 51
 52      ///
 53      bool mUseHardware;
 54
 55      IDirectSound8 *mDSound;
 56
 57      /// The buffer used when duplication is allowed.
 58      IDirectSoundBuffer8 *mBuffer;
 59    
 60      /// We set this to true when the original buffer has
 61      /// been handed out and duplicates need to be made.
 62      bool mDuplicate;
 63
 64      ///
 65      SFXDSBuffer(   IDirectSound8 *dsound,
 66                     const ThreadSafeRef< SFXStream>& stream,
 67                     SFXDescription* description,
 68                     bool useHardware );
 69
 70      virtual ~SFXDSBuffer();
 71
 72      /// Set up a DirectSound buffer.
 73      /// @note This method will not fill the buffer with data.
 74      /// @note If this is a streaming buffer, the resulting buffer
 75      ///    will have its notification positions set up and already
 76      ///    be registered with SFXDSStreamThread.
 77      bool _createBuffer( IDirectSoundBuffer8 **buffer8 );
 78
 79      ///
 80      bool _duplicateBuffer( IDirectSoundBuffer8 **buffer8 );
 81
 82      // SFXWrapAroundBuffer.
 83      virtual bool _copyData( U32 offset, const U8* data, U32 length );
 84      virtual void _flush();
 85
 86public:
 87
 88      ///
 89      static SFXDSBuffer* create(   IDirectSound8* dsound, 
 90                                    const ThreadSafeRef< SFXStream>& stream,
 91                                    SFXDescription* description,
 92                                    bool useHardware );
 93
 94      //
 95      bool createVoice( IDirectSoundBuffer8 **buffer );
 96
 97      //
 98      void releaseVoice( IDirectSoundBuffer8 **buffer );
 99
100};
101
102#endif // _SFXDSBUFFER_H_
103