lllistener_fmod.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * @file lllistener_fmod.cpp
  3. * @brief implementation of LISTENER class abstracting the audio support
  4. * as a FMOD implementation
  5. *
  6. * $LicenseInfo:firstyear=2002&license=viewergpl$
  7. *
  8. * Copyright (c) 2002-2009, 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. #include "linden_common.h"
  34. #include "fmod.hpp"
  35. #include "lllistener_fmod.h"
  36. #include "llaudioengine.h"
  37. LLListener_FMOD::LLListener_FMOD(FMOD::System* system)
  38. : LLListener(),
  39. mSystem(system)
  40. {
  41. }
  42. //virtual
  43. void LLListener_FMOD::translate(const LLVector3& offset)
  44. {
  45. if (mSystem)
  46. {
  47. LLListener::translate(offset);
  48. mSystem->set3DListenerAttributes(0, (FMOD_VECTOR*)mPosition.mV, NULL,
  49. (FMOD_VECTOR*)mListenAt.mV,
  50. (FMOD_VECTOR*)mListenUp.mV);
  51. }
  52. }
  53. //virtual
  54. void LLListener_FMOD::setPosition(const LLVector3& pos)
  55. {
  56. if (mSystem)
  57. {
  58. LLListener::setPosition(pos);
  59. mSystem->set3DListenerAttributes(0, (FMOD_VECTOR*)mPosition.mV, NULL,
  60. (FMOD_VECTOR*)mListenAt.mV,
  61. (FMOD_VECTOR*)mListenUp.mV);
  62. }
  63. }
  64. //virtual
  65. void LLListener_FMOD::setVelocity(const LLVector3& vel)
  66. {
  67. if (mSystem)
  68. {
  69. LLListener::setVelocity(vel);
  70. mSystem->set3DListenerAttributes(0, NULL, (FMOD_VECTOR*)mVelocity.mV,
  71. (FMOD_VECTOR*)mListenAt.mV,
  72. (FMOD_VECTOR*)mListenUp.mV);
  73. }
  74. }
  75. //virtual
  76. void LLListener_FMOD::orient(const LLVector3& up, const LLVector3& at)
  77. {
  78. if (mSystem)
  79. {
  80. LLListener::orient(up, at);
  81. mSystem->set3DListenerAttributes(0, NULL, NULL, (FMOD_VECTOR*)at.mV,
  82. (FMOD_VECTOR*)up.mV);
  83. }
  84. }
  85. //virtual
  86. void LLListener_FMOD::setRolloffFactor(F32 factor)
  87. {
  88. // An internal FMOD Studio optimization skips 3D updates if there have not
  89. // been changes to the 3D sound environment. Sadly, a change in rolloff is
  90. // not accounted for, thus we must touch the listener properties as well.
  91. // In short: Changing the position ticks a dirtyflag inside FMOD Studio,
  92. // which makes it not skip 3D processing next update call.
  93. if (mSystem)
  94. {
  95. if (mRolloffFactor != factor)
  96. {
  97. LLVector3 pos = mPosition;
  98. pos.mV[VZ] -= 0.1f;
  99. mSystem->set3DListenerAttributes(0, (FMOD_VECTOR*)pos.mV, NULL,
  100. NULL, NULL);
  101. mSystem->set3DListenerAttributes(0, (FMOD_VECTOR*)mPosition.mV,
  102. NULL, NULL, NULL);
  103. }
  104. mRolloffFactor = factor;
  105. mSystem->set3DSettings(mDopplerFactor, 1.f, mRolloffFactor);
  106. }
  107. }
  108. //virtual
  109. void LLListener_FMOD::setDopplerFactor(F32 factor)
  110. {
  111. if (mSystem)
  112. {
  113. mDopplerFactor = factor;
  114. mSystem->set3DSettings(mDopplerFactor, 1.f, mRolloffFactor);
  115. }
  116. }
  117. //virtual
  118. void LLListener_FMOD::commitDeferredChanges()
  119. {
  120. if (mSystem)
  121. {
  122. mSystem->update();
  123. }
  124. }