sfxALProvider.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #include "platform/platform.h"
  23. #include "sfx/sfxProvider.h"
  24. #include "sfx/openal/sfxALDevice.h"
  25. #include "sfx/openal/aldlist.h"
  26. #include "sfx/openal/LoadOAL.h"
  27. #include "core/strings/stringFunctions.h"
  28. #include "console/console.h"
  29. #include "core/module.h"
  30. class SFXALProvider : public SFXProvider
  31. {
  32. public:
  33. SFXALProvider()
  34. : SFXProvider( "OpenAL" ) { dMemset(&mOpenAL,0,sizeof(mOpenAL)); mALDL = NULL; }
  35. virtual ~SFXALProvider();
  36. protected:
  37. OPENALFNTABLE mOpenAL;
  38. ALDeviceList *mALDL;
  39. struct ALDeviceInfo : SFXDeviceInfo
  40. {
  41. };
  42. void init();
  43. public:
  44. SFXDevice *createDevice( const String& deviceName, bool useHardware, S32 maxBuffers );
  45. };
  46. MODULE_BEGIN( OpenAL )
  47. MODULE_INIT_BEFORE( SFX )
  48. MODULE_SHUTDOWN_AFTER( SFX )
  49. SFXALProvider* mProvider;
  50. MODULE_INIT
  51. {
  52. mProvider = new SFXALProvider;
  53. }
  54. MODULE_SHUTDOWN
  55. {
  56. delete mProvider;
  57. }
  58. MODULE_END;
  59. void SFXALProvider::init()
  60. {
  61. if( LoadOAL10Library( NULL, &mOpenAL ) != AL_TRUE )
  62. {
  63. Con::printf( "SFXALProvider - OpenAL not available." );
  64. return;
  65. }
  66. mALDL = new ALDeviceList( mOpenAL );
  67. // Did we get any devices?
  68. if ( mALDL->GetNumDevices() < 1 )
  69. {
  70. Con::printf( "SFXALProvider - No valid devices found!" );
  71. return;
  72. }
  73. // Cool, loop through them, and caps em
  74. const char *deviceFormat = "OpenAL v%d.%d %s";
  75. char temp[256];
  76. for( S32 i = 0; i < mALDL->GetNumDevices(); i++ )
  77. {
  78. ALDeviceInfo* info = new ALDeviceInfo;
  79. info->internalName = String( mALDL->GetInternalDeviceName( i ) );
  80. info->name = String( mALDL->GetDeviceName( i ) );
  81. mDeviceInfo.push_back( info );
  82. }
  83. regProvider( this );
  84. }
  85. SFXALProvider::~SFXALProvider()
  86. {
  87. UnloadOAL10Library();
  88. if (mALDL)
  89. delete mALDL;
  90. }
  91. SFXDevice *SFXALProvider::createDevice( const String& deviceName, bool useHardware, S32 maxBuffers )
  92. {
  93. ALDeviceInfo *info = dynamic_cast< ALDeviceInfo* >
  94. ( _findDeviceInfo( deviceName) );
  95. // Do we find one to create?
  96. if (info)
  97. return new SFXALDevice(this, mOpenAL, info->internalName, useHardware, maxBuffers);
  98. return NULL;
  99. }