Torque3D Documentation / _generateds / sfxFMODDevice.h

sfxFMODDevice.h

Engine/source/sfx/fmod/sfxFMODDevice.h

More...

Classes:

class

FMOD API function table.

Public Defines

define
FMOD_EVENT_FUNCTION(fn_name, fn_args)    typedef FMOD_RESULT ( *FMODFNPTR##fn_name)fn_args;
define
FMOD_EVENT_FUNCTION(fn_name, fn_args)    Thunk< FMODFNPTR##fn_name > fn_name;
define
FMOD_FN_FILE() "sfx/fmod/fmodFunctions.h"
define
FMOD_FUNCTION(fn_name, fn_args)    typedef FMOD_RESULT ( *FMODFNPTR##fn_name)fn_args;
define
FMOD_FUNCTION(fn_name, fn_args)    Thunk< FMODFNPTR##fn_name > fn_name;
define
FModAssert(x, msg)    { FMOD_RESULT result = ( x ); \
     ( result == FMOD_OK, ( "%s: %s", msg, FMOD_ErrorString( result ) ) ); }
define

Public Functions

FMODResultToString(FMOD_RESULT result)
TorqueTransformToFMODVectors(const MatrixF & transform, FMOD_VECTOR & position, FMOD_VECTOR & forward, FMOD_VECTOR & up)
TorqueVectorToFMODVector(const Point3F & torque, FMOD_VECTOR & fmod)

Detailed Description

Public Defines

FMOD_EVENT_FUNCTION(fn_name, fn_args)    typedef FMOD_RESULT ( *FMODFNPTR##fn_name)fn_args;
FMOD_EVENT_FUNCTION(fn_name, fn_args)    Thunk< FMODFNPTR##fn_name > fn_name;
FMOD_FN_FILE() "sfx/fmod/fmodFunctions.h"
FMOD_FUNCTION(fn_name, fn_args)    typedef FMOD_RESULT ( *FMODFNPTR##fn_name)fn_args;
FMOD_FUNCTION(fn_name, fn_args)    Thunk< FMODFNPTR##fn_name > fn_name;
FModAssert(x, msg)    { FMOD_RESULT result = ( x ); \
     ( result == FMOD_OK, ( "%s: %s", msg, FMOD_ErrorString( result ) ) ); }
WINAPI() 

Public Functions

FMODEventPathToTorqueName(const String & path)

FMODEventPathToTorqueName(const String & projectName, const String & path)

FMODResultToString(FMOD_RESULT result)

TorquePriorityToFMODPriority(F32 priority)

TorqueTransformToFMODVectors(const MatrixF & transform, FMOD_VECTOR & position, FMOD_VECTOR & forward, FMOD_VECTOR & up)

TorqueVectorToFMODVector(const Point3F & torque, FMOD_VECTOR & fmod)

  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 _SFXFMODDEVICE_H_
 25#define _SFXFMODDEVICE_H_
 26
 27#ifndef _SFXDEVICE_H_
 28   #include "sfx/sfxDevice.h"
 29#endif
 30#ifndef _SFXFMODVOICE_H_
 31   #include "sfx/fmod/sfxFMODVoice.h"
 32#endif
 33#ifndef _SFXFMODBUFFER_H_
 34   #include "sfx/fmod/sfxFMODBuffer.h"
 35#endif
 36#ifndef _SFXFMODPLUGIN_H_
 37   #include "sfx/fmod/sfxFMODPlugin.h"
 38#endif
 39
 40#include "core/util/tDictionary.h"
 41
 42
 43// Disable warning for unused static functions.
 44#ifdef TORQUE_COMPILER_VISUALC
 45   #pragma warning( disable : 4505 )
 46#endif
 47
 48#if defined( TORQUE_OS_XENON ) || defined( TORQUE_OS_PS3 )
 49   #define TORQUE_FMOD_STATIC
 50   #define TORQUE_FMOD_NO_EVENTS //TEMP
 51#endif
 52
 53
 54#include "fmod.h"
 55#include "fmod_errors.h"
 56#include "fmod_event.h"
 57
 58#include "platform/platformDlibrary.h"
 59#include "platform/threads/mutex.h"
 60
 61
 62// This doesn't appear to exist in some contexts, so let's just add it.
 63#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XENON)
 64#ifndef WINAPI
 65#define WINAPI __stdcall
 66#endif
 67#else
 68#define WINAPI
 69#endif
 70
 71
 72#define FModAssert(x, msg) \
 73   { FMOD_RESULT result = ( x ); \
 74     AssertISV( result == FMOD_OK, String::ToString( "%s: %s", msg, FMOD_ErrorString( result ) ) ); }
 75
 76#define FMOD_FN_FILE "sfx/fmod/fmodFunctions.h"
 77
 78
 79// Typedefs
 80#define FMOD_FUNCTION(fn_name, fn_args) \
 81   typedef FMOD_RESULT (WINAPI *FMODFNPTR##fn_name)fn_args;
 82#define FMOD_EVENT_FUNCTION(fn_name, fn_args) \
 83   typedef FMOD_RESULT (WINAPI *FMODFNPTR##fn_name)fn_args;
 84#include FMOD_FN_FILE
 85#undef FMOD_FUNCTION
 86#undef FMOD_EVENT_FUNCTION
 87
 88
 89/// FMOD API function table.
 90///
 91/// FMOD doesn't want to be called concurrently so in order to
 92/// not force everything to the main thread (where sound updates
 93/// would just stall during loading), we thunk all the API
 94/// calls and lock all API entry points to a single mutex.
 95struct FModFNTable
 96{
 97   FModFNTable()
 98      : isLoaded( false ),
 99        eventIsLoaded( false ),
100        dllRef( NULL ),
101        eventDllRef( NULL )
102   {
103      AssertFatal( mutex == NULL,
104         "FModFNTable::FModFNTable() - this should be a singleton" );
105      mutex = new Mutex;
106   }
107   ~FModFNTable()
108   {
109      dllRef = NULL;
110      eventDllRef = NULL;      
111      delete mutex;
112   }
113
114   bool isLoaded;
115   bool eventIsLoaded;
116   DLibraryRef dllRef;
117   DLibraryRef eventDllRef;
118   static Mutex* mutex;
119
120   template< typename FN >
121   struct Thunk
122   {
123      FN fn;
124
125      template< typename A >
126      FMOD_RESULT operator()( A a )
127      {
128         mutex->lock();
129         FMOD_RESULT result = fn( a );
130         mutex->unlock();
131         return result;
132      }
133      template< typename A, typename B >
134      FMOD_RESULT operator()( A a, B b )
135      {
136         mutex->lock();
137         FMOD_RESULT result = fn( a, b );
138         mutex->unlock();
139         return result;
140      }
141      template< typename A, typename B, typename C >
142      FMOD_RESULT operator()( A a, B b, C c )
143      {
144         mutex->lock();
145         FMOD_RESULT result = fn( a, b, c );
146         mutex->unlock();
147         return result;
148      }
149      template< typename A, typename B, typename C, typename D >
150      FMOD_RESULT operator()( A a, B b, C c, D d )
151      {
152         mutex->lock();
153         FMOD_RESULT result = fn( a, b, c, d );
154         mutex->unlock();
155         return result;
156      }
157      template< typename A, typename B, typename C, typename D, typename E >
158      FMOD_RESULT operator()( A a, B b, C c, D d, E e )
159      {
160         mutex->lock();
161         FMOD_RESULT result = fn( a, b, c, d, e );
162         mutex->unlock();
163         return result;
164      }
165      template< typename A, typename B, typename C, typename D, typename E, typename F >
166      FMOD_RESULT operator()( A a, B b, C c, D d, E e, F f )
167      {
168         mutex->lock();
169         FMOD_RESULT result = fn( a, b, c, d, e, f );
170         mutex->unlock();
171         return result;
172      }
173      template< typename A, typename B, typename C, typename D, typename E, typename F, typename G >
174      FMOD_RESULT operator()( A a, B b, C c, D d, E e, F f, G g )
175      {
176         mutex->lock();
177         FMOD_RESULT result = fn( a, b, c, d, e, f, g );
178         mutex->unlock();
179         return result;
180      }
181      template< typename A, typename B, typename C, typename D, typename E, typename F, typename G, typename H >
182      FMOD_RESULT operator()( A a, B b, C c, D d, E e, F f, G g, H h )
183      {
184         mutex->lock();
185         FMOD_RESULT result = fn( a, b, c, d, e, f, g, h );
186         mutex->unlock();
187         return result;
188      }
189   };
190
191#define FMOD_FUNCTION(fn_name, fn_args) \
192   Thunk< FMODFNPTR##fn_name > fn_name;
193#define FMOD_EVENT_FUNCTION(fn_name, fn_args) \
194   Thunk< FMODFNPTR##fn_name > fn_name;
195#include FMOD_FN_FILE
196#undef FMOD_FUNCTION
197#undef FMOD_EVENT_FUNCTION
198};
199
200
201inline void TorqueVectorToFMODVector( const Point3F& torque, FMOD_VECTOR& fmod )
202{
203   fmod.x = torque.x;
204   fmod.y = torque.z;
205   fmod.z = torque.y;
206}
207
208inline void TorqueTransformToFMODVectors( const MatrixF& transform, FMOD_VECTOR& position, FMOD_VECTOR& forward, FMOD_VECTOR& up )
209{
210   Point3F _pos, _fwd, _up;
211   
212   transform.getColumn( 3, &_pos );
213   transform.getColumn( 1, &_fwd );
214   transform.getColumn( 2, &_up );
215
216   TorqueVectorToFMODVector( _pos, position );
217   TorqueVectorToFMODVector( _fwd, forward );
218   TorqueVectorToFMODVector( _up, up );
219}
220
221inline int TorquePriorityToFMODPriority( F32 priority )
222{
223   // Map [-2,2] to [256,0].
224   
225   F32 n = mClampF( priority, -2.0f, 2.0f ) + 2.0f;
226   return ( n * 256.0f / 4.0f );
227}
228
229inline String FMODEventPathToTorqueName( const String& path )
230{
231   String p = path;
232   p.replace( '/', '_' );
233   p.replace( '-', '_' );
234   p.replace( ' ', '_' );
235   p.replace( '(', '_' );
236   p.replace( ')', '_' );
237   p.replace( '%', '_' );
238   p.replace( '$', '_' );
239   return p;
240}
241
242inline String FMODEventPathToTorqueName( const String& projectName, const String& path )
243{
244   return String::ToString( "%s_%s", projectName.c_str(), FMODEventPathToTorqueName( path ).c_str() );
245}
246
247extern String FMODResultToString( FMOD_RESULT result );
248
249
250class SFXProvider;
251class SFXFMODPlugin;
252
253
254
255class SFXFMODDevice : public SFXDevice
256{
257   public:
258
259      typedef SFXDevice Parent;
260      friend class SFXFMODProvider; // _init
261      friend class SFXFMODEventSource; // smStatNumEventSources
262
263      explicit SFXFMODDevice();
264
265      SFXFMODDevice( SFXProvider* provider, FModFNTable *fmodFnTbl, int deviceIdx, String name );
266
267      virtual ~SFXFMODDevice();
268
269   protected:
270
271      FMOD_MODE m3drolloffmode;
272      int mDeviceIndex;
273      
274      /// The FMOD SFXSystemPlugin instance.
275      SFXFMODPlugin mPlugin;
276      
277      /// @name Console Variables
278      /// @{
279      
280      /// Current core FMOD memory usage in bytes.
281      static U32 smStatMemUsageCore;
282      
283      /// Current FMOD Event DLL memory usage in bytes.
284      static U32 smStatMemUsageEvents;
285      
286      /// Current number of SFXFMODEventSource instances.
287      static U32 smStatNumEventSources;
288      
289      ///
290      static bool smPrefDisableSoftware;
291      
292      ///
293      static bool smPrefUseSoftwareOcclusion;
294      
295      ///
296      static bool smPrefUseSoftwareHRTF;
297      
298      ///
299      static bool smPrefEnableProfile;
300      
301      ///
302      static bool smPrefGeometryUseClosest;
303      
304      ///
305      static const char* smPrefDSoundHRTF;
306      
307      ///
308      static const char* smPrefPluginPath;
309      
310      /// @}
311      
312      bool _init();
313      
314      static SFXFMODDevice* smInstance;
315      
316   public:
317   
318      static SFXFMODDevice* instance() { return smInstance; }
319   
320      FMOD_MODE get3dRollOffMode() { return m3drolloffmode; }
321
322      static FMOD_SYSTEM* smSystem;
323      static FMOD_EVENTSYSTEM* smEventSystem;
324      static FModFNTable* smFunc;
325      
326      // Update memory usage stats for metrics display.
327      void updateMemUsageStats();
328
329      // SFXDevice.
330      virtual SFXBuffer* createBuffer( const ThreadSafeRef< SFXStream>& stream, SFXDescription* description );
331      virtual SFXBuffer* createBuffer( const String& filename, SFXDescription* description );
332      virtual SFXVoice* createVoice( bool is3D, SFXBuffer* buffer );
333      virtual void update();
334      virtual void setNumListeners( U32 num );
335      virtual void setListener( U32 index, const SFXListenerProperties& listener );
336      virtual void setDistanceModel( SFXDistanceModel model );
337      virtual void setDopplerFactor( F32 factor );
338      virtual void setRolloffFactor( F32 factor );
339      virtual void setReverb( const SFXReverbProperties& reverb );
340      virtual void resetReverb();
341};
342
343#endif // _SFXFMODDEVICE_H_
344