PageRenderTime 29ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llvoicevisualizer.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 158 lines | 73 code | 17 blank | 68 comment | 0 complexity | 8036855e4b5e6355bd35168c5827370e MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llvoicevisualizer.h
  3. * @brief Draws in-world speaking indicators.
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. //--------------------------------------------------------------------
  27. //
  28. // VOICE VISUALIZER
  29. // author: JJ Ventrella, Linden Lab
  30. // (latest update to this info: Jan 18, 2007)
  31. //
  32. // The Voice Visualizer is responsible for taking realtime signals from actual users speaking and
  33. // visualizing this speech in two forms:
  34. //
  35. // (1) as a dynamic sound symbol (also referred to as the "voice indicator" that appears over the avatar's head
  36. // (2) as gesticulation events that are used to trigger avatr gestures
  37. //
  38. // The input for the voice visualizer is a continual stream of voice amplitudes.
  39. //-----------------------------------------------------------------------------
  40. #ifndef LL_VOICE_VISUALIZER_H
  41. #define LL_VOICE_VISUALIZER_H
  42. #include "llhudeffect.h"
  43. //-----------------------------------------------------------------------------------------------
  44. // The values of voice gesticulation represent energy levels for avatar animation, based on
  45. // amplitude surge events parsed from the voice signal. These are made available so that
  46. // the appropriate kind of avatar animation can be triggered, and thereby simulate the physical
  47. // motion effects of speech. It is recommended that multiple body parts be animated as well as
  48. // lips, such as head, shoulders, and hands, with large gestures used when the energy level is high.
  49. //-----------------------------------------------------------------------------------------------
  50. enum VoiceGesticulationLevel
  51. {
  52. VOICE_GESTICULATION_LEVEL_OFF = -1,
  53. VOICE_GESTICULATION_LEVEL_LOW = 0,
  54. VOICE_GESTICULATION_LEVEL_MEDIUM,
  55. VOICE_GESTICULATION_LEVEL_HIGH,
  56. NUM_VOICE_GESTICULATION_LEVELS
  57. };
  58. const static int NUM_VOICE_SYMBOL_WAVES = 7;
  59. //----------------------------------------------------
  60. // LLVoiceVisualizer class
  61. //----------------------------------------------------
  62. class LLVoiceVisualizer : public LLHUDEffect
  63. {
  64. //---------------------------------------------------
  65. // public methods
  66. //---------------------------------------------------
  67. public:
  68. LLVoiceVisualizer ( const U8 type ); //constructor
  69. ~LLVoiceVisualizer(); //destructor
  70. friend class LLHUDObject;
  71. void setVoiceSourceWorldPosition( const LLVector3 &p ); // this should be the position of the speaking avatar's head
  72. void setMinGesticulationAmplitude( F32 ); // the lower range of meaningful amplitude for setting gesticulation level
  73. void setMaxGesticulationAmplitude( F32 ); // the upper range of meaningful amplitude for setting gesticulation level
  74. void setStartSpeaking(); // tell me when the av starts speaking
  75. void setVoiceEnabled( bool ); // tell me whether or not the user is voice enabled
  76. void setSpeakingAmplitude( F32 ); // tell me how loud the av is speaking (ranges from 0 to 1)
  77. void setStopSpeaking(); // tell me when the av stops speaking
  78. bool getCurrentlySpeaking(); // the get for the above set
  79. VoiceGesticulationLevel getCurrentGesticulationLevel(); // based on voice amplitude, I'll give you the current "energy level" of avatar speech
  80. static void setPreferences( );
  81. static void lipStringToF32s ( std::string& in_string, F32*& out_F32s, U32& count_F32s ); // convert a string of digits to an array of floats
  82. void lipSyncOohAah( F32& ooh, F32& aah );
  83. void render(); // inherited from HUD Effect
  84. void packData(LLMessageSystem *mesgsys); // inherited from HUD Effect
  85. void unpackData(LLMessageSystem *mesgsys, S32 blocknum); // inherited from HUD Effect
  86. void markDead(); // inherited from HUD Effect
  87. //----------------------------------------------------------------------------------------------
  88. // "setMaxGesticulationAmplitude" and "setMinGesticulationAmplitude" allow for the tuning of the
  89. // gesticulation level detector to be responsive to different kinds of signals. For instance, we
  90. // may find that the average voice amplitude rarely exceeds 0.7 (in a range from 0 to 1), and
  91. // therefore we may want to set 0.7 as the max, so we can more easily catch all the variance
  92. // within that range. Also, we may find that there is often noise below a certain range like 0.1,
  93. // and so we would want to set 0.1 as the min so as not to accidentally use this as signal.
  94. //----------------------------------------------------------------------------------------------
  95. void setMaxGesticulationAmplitude();
  96. void setMinGesticulationAmplitude();
  97. //---------------------------------------------------
  98. // private members
  99. //---------------------------------------------------
  100. private:
  101. struct SoundSymbol
  102. {
  103. F32 mWaveExpansion [ NUM_VOICE_SYMBOL_WAVES ];
  104. bool mWaveActive [ NUM_VOICE_SYMBOL_WAVES ];
  105. F64 mWaveFadeOutStartTime [ NUM_VOICE_SYMBOL_WAVES ];
  106. F32 mWaveOpacity [ NUM_VOICE_SYMBOL_WAVES ];
  107. LLPointer<LLViewerFetchedTexture> mTexture [ NUM_VOICE_SYMBOL_WAVES ];
  108. bool mActive;
  109. LLVector3 mPosition;
  110. };
  111. LLFrameTimer mTimer; // so I can ask the current time in seconds
  112. F64 mStartTime; // time in seconds when speaking started
  113. F64 mCurrentTime; // current time in seconds, captured every step
  114. F64 mPreviousTime; // copy of "current time" from last frame
  115. SoundSymbol mSoundSymbol; // the sound symbol that appears over the avatar's head
  116. bool mVoiceEnabled; // if off, no rendering should happen
  117. bool mCurrentlySpeaking; // is the user currently speaking?
  118. LLVector3 mVoiceSourceWorldPosition; // give this to me every step - I need it to update the sound symbol
  119. F32 mSpeakingAmplitude; // this should be set as often as possible when the user is speaking
  120. F32 mMaxGesticulationAmplitude; // this is the upper-limit of the envelope of detectable gesticulation leves
  121. F32 mMinGesticulationAmplitude; // this is the lower-limit of the envelope of detectable gesticulation leves
  122. //---------------------------------------------------
  123. // private static members
  124. //---------------------------------------------------
  125. static BOOL sLipSyncEnabled; // 0 disabled, 1 babble loop
  126. static bool sPrefsInitialized; // the first instance will initialize the static members
  127. static F32* sOoh; // the babble loop of amplitudes for the ooh morph
  128. static F32* sAah; // the babble loop of amplitudes for the ooh morph
  129. static U32 sOohs; // the number of entries in the ooh loop
  130. static U32 sAahs; // the number of entries in the aah loop
  131. static F32 sOohAahRate; // frames per second for the babble loop
  132. static F32* sOohPowerTransfer; // the power transfer characteristics for the ooh amplitude
  133. static U32 sOohPowerTransfers; // the number of entries in the ooh transfer characteristics
  134. static F32 sOohPowerTransfersf; // the number of entries in the ooh transfer characteristics as a float
  135. static F32* sAahPowerTransfer; // the power transfer characteristics for the aah amplitude
  136. static U32 sAahPowerTransfers; // the number of entries in the aah transfer characteristics
  137. static F32 sAahPowerTransfersf; // the number of entries in the aah transfer characteristics as a float
  138. };//-----------------------------------------------------------------
  139. // end of LLVoiceVisualizer class
  140. //------------------------------------------------------------------
  141. #endif //LL_VOICE_VISUALIZER_H