llaudioengine_fmod.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * @file llaudioengine_fmod.h
  3. * @brief Definition of LLAudioEngine class abstracting the audio support
  4. * as a FMOD Studio implementation
  5. *
  6. * $LicenseInfo:firstyear=2002&license=viewergpl$
  7. *
  8. * Copyright (c) 2002-2014, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_AUDIOENGINE_FMOD_H
  34. #define LL_AUDIOENGINE_FMOD_H
  35. #include "llaudioengine.h"
  36. #include "llwindgen.h"
  37. // Stubs
  38. class LLAudioStreamManagerFMOD;
  39. namespace FMOD
  40. {
  41. class System;
  42. class Channel;
  43. class ChannelGroup;
  44. class Sound;
  45. class DSP;
  46. }
  47. typedef struct FMOD_DSP_DESCRIPTION FMOD_DSP_DESCRIPTION;
  48. // Interfaces
  49. class LLAudioEngine_FMOD final : public LLAudioEngine
  50. {
  51. protected:
  52. LOG_CLASS(LLAudioEngine_FMOD);
  53. public:
  54. LLAudioEngine_FMOD(bool enable_profiler);
  55. ~LLAudioEngine_FMOD() override;
  56. // Initialization/startup/shutdown
  57. bool init(void* user_data) override;
  58. std::string getDriverName(bool verbose) override;
  59. void allocateListener() override;
  60. void shutdown() override;
  61. bool initWind() override;
  62. void cleanupWind() override;
  63. void updateWind(LLVector3 direction, F32 cam_height_above_water) override;
  64. FMOD::System* getSystem() const { return mSystem; }
  65. typedef F32 MIXBUFFERFORMAT;
  66. protected:
  67. // Get a free buffer, or flush an existing one if you have to.
  68. LLAudioBuffer* createBuffer() override;
  69. // Create a new audio channel.
  70. LLAudioChannel* createChannel() override;
  71. void setInternalGain(F32 gain) override;
  72. protected:
  73. FMOD::System* mSystem;
  74. LLWindGen<MIXBUFFERFORMAT>* mWindGen;
  75. FMOD_DSP_DESCRIPTION* mWindDSPDesc;
  76. FMOD::DSP* mWindDSP;
  77. bool mInited;
  78. bool mEnableProfiler;
  79. public:
  80. static FMOD::ChannelGroup* sChannelGroups[LLAudioEngine::AUDIO_TYPE_COUNT];
  81. #if LL_LINUX
  82. static bool sNoALSA;
  83. static bool sNoPulseAudio;
  84. #endif
  85. };
  86. class LLAudioChannelFMOD final : public LLAudioChannel
  87. {
  88. protected:
  89. LOG_CLASS(LLAudioChannelFMOD);
  90. public:
  91. LLAudioChannelFMOD(FMOD::System* system);
  92. ~LLAudioChannelFMOD() override;
  93. protected:
  94. void play() override;
  95. void playSynced(LLAudioChannel* channelp) override;
  96. void cleanup() override;
  97. bool isPlaying() override;
  98. bool updateBuffer() override;
  99. void update3DPosition() override;
  100. void updateLoop() override;
  101. void set3DMode(bool use3d);
  102. protected:
  103. FMOD::System* getSystem() const { return mSystemp; }
  104. protected:
  105. FMOD::System* mSystemp;
  106. FMOD::Channel* mChannelp;
  107. U32 mLastSamplePos;
  108. };
  109. class LLAudioBufferFMOD final : public LLAudioBuffer
  110. {
  111. friend class LLAudioChannelFMOD;
  112. protected:
  113. LOG_CLASS(LLAudioBufferFMOD);
  114. public:
  115. LLAudioBufferFMOD(FMOD::System* system);
  116. ~LLAudioBufferFMOD() override;
  117. bool loadWAV(const std::string& filename) override;
  118. U32 getLength() override;
  119. protected:
  120. FMOD::System* getSystem() const { return mSystemp; }
  121. FMOD::Sound* getSound() const { return mSoundp; }
  122. protected:
  123. FMOD::System* mSystemp;
  124. FMOD::Sound* mSoundp;
  125. };
  126. bool checkFMerr(S32 result, const char* str);
  127. #endif // LL_AUDIOENGINE_FMOD_H