sfxDSBuffer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SFXDSBUFFER_H_
  23. #define _SFXDSBUFFER_H_
  24. #include <dsound.h>
  25. #ifndef _SFXINTERNAL_H_
  26. # include "sfx/sfxInternal.h"
  27. #endif
  28. /// DirectSound SFXBuffer implementation.
  29. ///
  30. /// Note that the actual sound buffer held by the buffer may
  31. /// get duplicated around for individual voices. This is kind
  32. /// of ugly as the resulting buffers aren't tied to a SFXDSBuffer
  33. /// anymore.
  34. class SFXDSBuffer : public SFXInternal::SFXWrapAroundBuffer
  35. {
  36. typedef SFXInternal::SFXWrapAroundBuffer Parent;
  37. friend class SFXDSDevice;
  38. friend class SFXDSVoice;
  39. protected:
  40. ///
  41. bool mIs3d;
  42. ///
  43. bool mUseHardware;
  44. IDirectSound8 *mDSound;
  45. /// The buffer used when duplication is allowed.
  46. IDirectSoundBuffer8 *mBuffer;
  47. /// We set this to true when the original buffer has
  48. /// been handed out and duplicates need to be made.
  49. bool mDuplicate;
  50. ///
  51. SFXDSBuffer( IDirectSound8 *dsound,
  52. const ThreadSafeRef< SFXStream >& stream,
  53. SFXDescription* description,
  54. bool useHardware );
  55. virtual ~SFXDSBuffer();
  56. /// Set up a DirectSound buffer.
  57. /// @note This method will not fill the buffer with data.
  58. /// @note If this is a streaming buffer, the resulting buffer
  59. /// will have its notification positions set up and already
  60. /// be registered with SFXDSStreamThread.
  61. bool _createBuffer( IDirectSoundBuffer8 **buffer8 );
  62. ///
  63. bool _duplicateBuffer( IDirectSoundBuffer8 **buffer8 );
  64. // SFXWrapAroundBuffer.
  65. virtual bool _copyData( U32 offset, const U8* data, U32 length );
  66. virtual void _flush();
  67. public:
  68. ///
  69. static SFXDSBuffer* create( IDirectSound8* dsound,
  70. const ThreadSafeRef< SFXStream >& stream,
  71. SFXDescription* description,
  72. bool useHardware );
  73. //
  74. bool createVoice( IDirectSoundBuffer8 **buffer );
  75. //
  76. void releaseVoice( IDirectSoundBuffer8 **buffer );
  77. };
  78. #endif // _SFXDSBUFFER_H_