sfxDSDevice.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 _SFXDSDEVICE_H_
  23. #define _SFXDSDEVICE_H_
  24. #ifndef _STRINGFUNCTIONS_H_
  25. # include "core/strings/stringFunctions.h"
  26. #endif
  27. #ifndef _SFXDEVICE_H_
  28. #include "sfx/sfxDevice.h"
  29. #endif
  30. #ifndef _SFXDSVOICE_H_
  31. #include "sfx/dsound/sfxDSVoice.h"
  32. #endif
  33. #ifndef OS_DLIBRARY_H
  34. #include "platform/platformDlibrary.h"
  35. #endif
  36. #include <dsound.h>
  37. // Typedefs
  38. #define DS_FUNCTION(fn_name, fn_return, fn_args) \
  39. typedef fn_return (WINAPI *DSFNPTR##fn_name##)##fn_args##;
  40. #include "sfx/dsound/dsFunctions.h"
  41. #undef DS_FUNCTION
  42. // Function table
  43. struct DSoundFNTable
  44. {
  45. DSoundFNTable() : isLoaded( false ) {};
  46. bool isLoaded;
  47. DLibraryRef dllRef;
  48. #define DS_FUNCTION(fn_name, fn_return, fn_args) \
  49. DSFNPTR##fn_name fn_name;
  50. #include "sfx/dsound/dsFunctions.h"
  51. #undef DS_FUNCTION
  52. };
  53. /// Helper for asserting on dsound HRESULTS.
  54. inline void DSAssert( HRESULT hr, const char *info )
  55. {
  56. #ifdef TORQUE_DEBUG
  57. if( FAILED( hr ) )
  58. {
  59. char buf[256];
  60. dSprintf( buf, 256, "Error code: %x\n%s", hr, info );
  61. AssertFatal( false, buf );
  62. }
  63. #endif
  64. }
  65. /// The DirectSound device implementation exposes a couple
  66. /// of settings to script that you should be aware of:
  67. ///
  68. /// $DirectSound::dopplerFactor - This controls the scale of
  69. /// the doppler effect. Valid factors are 0.0 to 10.0 and it
  70. /// defaults to 0.75.
  71. ///
  72. /// $DirectSound::distanceFactor - This sets the unit conversion
  73. /// for
  74. ///
  75. /// $DirectSound::rolloffFactor - ;
  76. ///
  77. ///
  78. class SFXDSDevice : public SFXDevice
  79. {
  80. typedef SFXDevice Parent;
  81. friend class SFXDSVoice;
  82. friend class SFXDSProvider; // _init
  83. public:
  84. //explicit SFXDSDevice();
  85. SFXDSDevice( SFXProvider* provider,
  86. DSoundFNTable *dsFnTbl,
  87. GUID* guid,
  88. String name,
  89. bool useHardware,
  90. S32 maxBuffers );
  91. virtual ~SFXDSDevice();
  92. protected:
  93. IDirectSound8 *mDSound;
  94. IDirectSound3DListener8 *mListener;
  95. IDirectSoundBuffer *mPrimaryBuffer;
  96. DSoundFNTable *mDSoundTbl;
  97. DSCAPS mCaps;
  98. GUID* mGUID;
  99. bool _init();
  100. /// Called from SFXDSVoice to commit any deferred
  101. /// settings before playback begins.
  102. void _commitDeferred();
  103. public:
  104. // SFXDevice
  105. virtual SFXBuffer* createBuffer( const ThreadSafeRef< SFXStream >& stream, SFXDescription* description );
  106. virtual SFXVoice* createVoice( bool is3D, SFXBuffer *buffer );
  107. virtual void update();
  108. virtual void setListener( U32 index, const SFXListenerProperties& listener );
  109. virtual void setDistanceModel( SFXDistanceModel mode );
  110. virtual void setDopplerFactor( F32 factor );
  111. virtual void setRolloffFactor( F32 factor );
  112. };
  113. #endif // _SFXDSDEVICE_H_