llvoicevisualizer.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:22k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llvoicevisualizer.cpp
  3.  * @brief Draws in-world speaking indicators.
  4.  *
  5.  * $LicenseInfo:firstyear=2000&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2000-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. //----------------------------------------------------------------------
  33. // Voice Visualizer
  34. // author: JJ Ventrella
  35. // (information about this stuff can be found in "llvoicevisualizer.h")
  36. //----------------------------------------------------------------------
  37. #include "llviewerprecompiledheaders.h"
  38. #include "llviewercontrol.h"
  39. #include "llglheaders.h"
  40. #include "llsphere.h"
  41. #include "llvoicevisualizer.h"
  42. #include "llviewercamera.h"
  43. #include "llviewerobject.h"
  44. #include "llviewertexture.h"
  45. #include "llviewertexturelist.h"
  46. #include "llvoiceclient.h"
  47. #include "llrender.h"
  48. //brent's wave image
  49. //29de489d-0491-fb00-7dab-f9e686d31e83
  50. //--------------------------------------------------------------------------------------
  51. // sound symbol constants
  52. //--------------------------------------------------------------------------------------
  53. const F32 HEIGHT_ABOVE_HEAD = 0.3f; // how many meters vertically above the av's head the voice symbol will appear
  54. const F32 RED_THRESHOLD = LLVoiceClient::OVERDRIVEN_POWER_LEVEL; // value above which speaking amplitude causes the voice symbol to turn red
  55. const F32 GREEN_THRESHOLD = 0.2f; // value above which speaking amplitude causes the voice symbol to turn green
  56. const F32 FADE_OUT_DURATION = 0.4f; // how many seconds it takes for a pair of waves to fade away
  57. const F32 EXPANSION_RATE = 1.0f; // how many seconds it takes for the waves to expand to twice their original size
  58. const F32 EXPANSION_MAX = 1.5f; // maximum size scale to which the waves can expand before popping back to 1.0 
  59. const F32 WAVE_WIDTH_SCALE = 0.03f; // base width of the waves 
  60. const F32 WAVE_HEIGHT_SCALE = 0.02f; // base height of the waves 
  61. const F32 BASE_BRIGHTNESS = 0.7f; // gray level of the voice indicator when quiet (below green threshold)
  62. const F32 DOT_SIZE = 0.05f; // size of the dot billboard texture
  63. const F32 DOT_OPACITY = 0.7f; // how opaque the dot is
  64. const F32 WAVE_MOTION_RATE = 1.5f; // scalar applied to consecutive waves as a function of speaking amplitude
  65. //--------------------------------------------------------------------------------------
  66. // gesticulation constants
  67. //--------------------------------------------------------------------------------------
  68. const F32 DEFAULT_MINIMUM_GESTICULATION_AMPLITUDE = 0.2f; 
  69. const F32 DEFAULT_MAXIMUM_GESTICULATION_AMPLITUDE = 1.0f;
  70. //--------------------------------------------------------------------------------------
  71. // other constants
  72. //--------------------------------------------------------------------------------------
  73. const F32 ONE_HALF = 1.0f; // to clarify intent and reduce magic numbers in the code. 
  74. const LLVector3 WORLD_UPWARD_DIRECTION = LLVector3( 0.0f, 0.0f, 1.0f ); // Z is up in SL
  75. //------------------------------------------------------------------
  76. // handles parameter updates
  77. //------------------------------------------------------------------
  78. static bool handleVoiceVisualizerPrefsChanged(const LLSD& newvalue)
  79. {
  80. // Note: Ignore the specific event value, we look up the ones we want
  81. LLVoiceVisualizer::setPreferences();
  82. return true;
  83. }
  84. //------------------------------------------------------------------
  85. // Initialize the statics
  86. //------------------------------------------------------------------
  87. bool LLVoiceVisualizer::sPrefsInitialized = false;
  88. BOOL LLVoiceVisualizer::sLipSyncEnabled = FALSE;
  89. F32* LLVoiceVisualizer::sOoh = NULL;
  90. F32* LLVoiceVisualizer::sAah = NULL;
  91. U32  LLVoiceVisualizer::sOohs = 0;
  92. U32  LLVoiceVisualizer::sAahs = 0;
  93. F32  LLVoiceVisualizer::sOohAahRate = 0.0f;
  94. F32* LLVoiceVisualizer::sOohPowerTransfer = NULL;
  95. U32  LLVoiceVisualizer::sOohPowerTransfers = 0;
  96. F32  LLVoiceVisualizer::sOohPowerTransfersf = 0.0f;
  97. F32* LLVoiceVisualizer::sAahPowerTransfer = NULL;
  98. U32  LLVoiceVisualizer::sAahPowerTransfers = 0;
  99. F32  LLVoiceVisualizer::sAahPowerTransfersf = 0.0f;
  100. //-----------------------------------------------
  101. // constructor
  102. //-----------------------------------------------
  103. LLVoiceVisualizer::LLVoiceVisualizer( const U8 type )
  104. :LLHUDEffect( type )
  105. {
  106. mCurrentTime = mTimer.getTotalSeconds();
  107. mPreviousTime = mCurrentTime;
  108. mStartTime = mCurrentTime;
  109. mVoiceSourceWorldPosition = LLVector3( 0.0f, 0.0f, 0.0f );
  110. mSpeakingAmplitude = 0.0f;
  111. mCurrentlySpeaking = false;
  112. mVoiceEnabled = false;
  113. mMinGesticulationAmplitude = DEFAULT_MINIMUM_GESTICULATION_AMPLITUDE;
  114. mMaxGesticulationAmplitude = DEFAULT_MAXIMUM_GESTICULATION_AMPLITUDE;
  115. mSoundSymbol.mActive = true;
  116. mSoundSymbol.mPosition = LLVector3( 0.0f, 0.0f, 0.0f );
  117. mTimer.reset();
  118. const char* sound_level_img[] = 
  119. {
  120. "voice_meter_dot.j2c",
  121. "voice_meter_rings.j2c",
  122. "voice_meter_rings.j2c",
  123. "voice_meter_rings.j2c",
  124. "voice_meter_rings.j2c",
  125. "voice_meter_rings.j2c",
  126. "voice_meter_rings.j2c"
  127. };
  128. for (int i=0; i<NUM_VOICE_SYMBOL_WAVES; i++)
  129. {
  130. mSoundSymbol.mWaveFadeOutStartTime [i] = mCurrentTime;
  131. mSoundSymbol.mTexture [i] = LLViewerTextureManager::getFetchedTextureFromFile(sound_level_img[i], FALSE, LLViewerTexture::BOOST_UI);
  132. mSoundSymbol.mWaveActive [i] = false;
  133. mSoundSymbol.mWaveOpacity [i] = 1.0f;
  134. mSoundSymbol.mWaveExpansion [i] = 1.0f;
  135. }
  136. mSoundSymbol.mTexture[0]->setFilteringOption(LLTexUnit::TFO_ANISOTROPIC);
  137. // The first instance loads the initial state from prefs.
  138. if (!sPrefsInitialized)
  139. {
  140. setPreferences();
  141.        
  142. // Set up our listener to get updates on all prefs values we care about.
  143. gSavedSettings.getControl("LipSyncEnabled")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _2));
  144. gSavedSettings.getControl("LipSyncOohAahRate")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _2));
  145. gSavedSettings.getControl("LipSyncOoh")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _2));
  146. gSavedSettings.getControl("LipSyncAah")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _2));
  147. gSavedSettings.getControl("LipSyncOohPowerTransfer")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _2));
  148. gSavedSettings.getControl("LipSyncAahPowerTransfer")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _2));
  149. sPrefsInitialized = true;
  150. }
  151. }//---------------------------------------------------
  152. //---------------------------------------------------
  153. void LLVoiceVisualizer::setMinGesticulationAmplitude( F32 m )
  154. {
  155. mMinGesticulationAmplitude = m;
  156. }//---------------------------------------------------
  157. //---------------------------------------------------
  158. void LLVoiceVisualizer::setMaxGesticulationAmplitude( F32 m )
  159. {
  160. mMaxGesticulationAmplitude = m;
  161. }//---------------------------------------------------
  162. //---------------------------------------------------
  163. void LLVoiceVisualizer::setVoiceEnabled( bool v )
  164. {
  165. mVoiceEnabled = v;
  166. }//---------------------------------------------------
  167. //---------------------------------------------------
  168. void LLVoiceVisualizer::setStartSpeaking()
  169. {
  170. mStartTime = mTimer.getTotalSeconds();
  171. mCurrentlySpeaking = true;
  172. mSoundSymbol.mActive = true;
  173. }//---------------------------------------------------
  174. //---------------------------------------------------
  175. bool LLVoiceVisualizer::getCurrentlySpeaking()
  176. {
  177. return mCurrentlySpeaking;
  178. }//---------------------------------------------------
  179. //---------------------------------------------------
  180. void LLVoiceVisualizer::setStopSpeaking()
  181. {
  182. mCurrentlySpeaking = false;
  183. mSpeakingAmplitude = 0.0f;
  184. }//---------------------------------------------------
  185. //---------------------------------------------------
  186. void LLVoiceVisualizer::setSpeakingAmplitude( F32 a )
  187. {
  188. mSpeakingAmplitude = a;
  189. }//---------------------------------------------------
  190. //---------------------------------------------------
  191. void LLVoiceVisualizer::setPreferences( )
  192. {
  193. sLipSyncEnabled = gSavedSettings.getBOOL("LipSyncEnabled");
  194. sOohAahRate = gSavedSettings.getF32("LipSyncOohAahRate");
  195. std::string oohString = gSavedSettings.getString("LipSyncOoh");
  196. lipStringToF32s (oohString, sOoh, sOohs);
  197. std::string aahString = gSavedSettings.getString("LipSyncAah");
  198. lipStringToF32s (aahString, sAah, sAahs);
  199. std::string oohPowerString = gSavedSettings.getString("LipSyncOohPowerTransfer");
  200. lipStringToF32s (oohPowerString, sOohPowerTransfer, sOohPowerTransfers);
  201. sOohPowerTransfersf = (F32) sOohPowerTransfers;
  202. std::string aahPowerString = gSavedSettings.getString("LipSyncAahPowerTransfer");
  203. lipStringToF32s (aahPowerString, sAahPowerTransfer, sAahPowerTransfers);
  204. sAahPowerTransfersf = (F32) sAahPowerTransfers;
  205. }//---------------------------------------------------
  206. //---------------------------------------------------
  207. // convert a string of digits to an array of floats.
  208. // the result for each digit is the value of the
  209. // digit multiplied by 0.11
  210. //---------------------------------------------------
  211. void LLVoiceVisualizer::lipStringToF32s ( std::string& in_string, F32*& out_F32s, U32& count_F32s )
  212. {
  213. delete[] out_F32s; // get rid of the current array
  214. count_F32s = in_string.length();
  215. if (count_F32s == 0)
  216. {
  217. // we don't like zero length arrays
  218. count_F32s  = 1;
  219. out_F32s    = new F32[1];
  220. out_F32s[0] = 0.0f;
  221. }
  222. else
  223. {
  224. out_F32s = new F32[count_F32s];
  225. for (U32 i=0; i<count_F32s; i++)
  226. {
  227. // we convert the characters 0 to 9 to their numeric value
  228. // anything else we take the low order four bits with a ceiling of 9
  229.     U8 digit = in_string[i];
  230. U8 four_bits = digit % 16;
  231. if (four_bits > 9)
  232. {
  233. four_bits = 9;
  234. }
  235. out_F32s[i] = 0.11f * (F32) four_bits;
  236. }
  237. }//---------------------------------------------------
  238. //--------------------------------------------------------------------------
  239. // find the amount to blend the ooh and aah mouth morphs
  240. //--------------------------------------------------------------------------
  241. void LLVoiceVisualizer::lipSyncOohAah( F32& ooh, F32& aah )
  242. {
  243. if( ( sLipSyncEnabled == TRUE ) && mCurrentlySpeaking )
  244. {
  245. U32 transfer_index = (U32) (sOohPowerTransfersf * mSpeakingAmplitude);
  246. if (transfer_index >= sOohPowerTransfers)
  247. {
  248.    transfer_index = sOohPowerTransfers - 1;
  249. }
  250. F32 transfer_ooh = sOohPowerTransfer[transfer_index];
  251. transfer_index = (U32) (sAahPowerTransfersf * mSpeakingAmplitude);
  252. if (transfer_index >= sAahPowerTransfers)
  253. {
  254.    transfer_index = sAahPowerTransfers - 1;
  255. }
  256. F32 transfer_aah = sAahPowerTransfer[transfer_index];
  257. F64 current_time   = mTimer.getTotalSeconds();
  258. F64 elapsed_time   = current_time - mStartTime;
  259. U32 elapsed_frames = (U32) (elapsed_time * sOohAahRate);
  260. U32 elapsed_oohs   = elapsed_frames % sOohs;
  261. U32 elapsed_aahs   = elapsed_frames % sAahs;
  262. ooh = transfer_ooh * sOoh[elapsed_oohs];
  263. aah = transfer_aah * sAah[elapsed_aahs];
  264. /*
  265. llinfos << " elapsed frames " << elapsed_frames
  266. << " ooh "            << ooh
  267. << " aah "            << aah
  268. << " transfer ooh"    << transfer_ooh
  269. << " transfer aah"    << transfer_aah
  270. << " start time "     << mStartTime
  271. << " current time "   << current_time
  272. << " elapsed time "   << elapsed_time
  273. << " elapsed oohs "   << elapsed_oohs
  274. << " elapsed aahs "   << elapsed_aahs
  275. << llendl;
  276. */
  277. }
  278. else
  279. {
  280. ooh = 0.0f;
  281. aah = 0.0f;
  282. }
  283. }//---------------------------------------------------
  284. //---------------------------------------------------
  285. // this method is inherited from HUD Effect
  286. //---------------------------------------------------
  287. void LLVoiceVisualizer::render()
  288. {
  289. if ( ! mVoiceEnabled )
  290. {
  291. return;
  292. }
  293. if ( mSoundSymbol.mActive ) 
  294. {
  295. mPreviousTime = mCurrentTime;
  296. mCurrentTime = mTimer.getTotalSeconds();
  297. //---------------------------------------------------------------
  298. // set the sound symbol position over the source (avatar's head)
  299. //---------------------------------------------------------------
  300. mSoundSymbol.mPosition = mVoiceSourceWorldPosition + WORLD_UPWARD_DIRECTION * HEIGHT_ABOVE_HEAD;
  301. //---------------------------------------------------------------
  302. // some gl state
  303. //---------------------------------------------------------------
  304. LLGLSPipelineAlpha alpha_blend;
  305. LLGLDepthTest depth(GL_TRUE, GL_FALSE);
  306. //-------------------------------------------------------------
  307. // create coordinates of the geometry for the dot
  308. //-------------------------------------------------------------
  309. LLViewerCamera* camera = LLViewerCamera::getInstance();
  310. LLVector3 l = camera->getLeftAxis() * DOT_SIZE;
  311. LLVector3 u = camera->getUpAxis()   * DOT_SIZE;
  312. LLVector3 bottomLeft = mSoundSymbol.mPosition + l - u;
  313. LLVector3 bottomRight = mSoundSymbol.mPosition - l - u;
  314. LLVector3 topLeft = mSoundSymbol.mPosition + l + u;
  315. LLVector3 topRight = mSoundSymbol.mPosition - l + u;
  316. //-----------------------------
  317. // bind texture 0 (the dot)
  318. //-----------------------------
  319. gGL.getTexUnit(0)->bind(mSoundSymbol.mTexture[0]);
  320. //-------------------------------------------------------------
  321. // now render the dot
  322. //-------------------------------------------------------------
  323. gGL.color4fv( LLColor4( 1.0f, 1.0f, 1.0f, DOT_OPACITY ).mV );
  324. gGL.begin( LLRender::TRIANGLE_STRIP );
  325. gGL.texCoord2i( 0, 0 ); gGL.vertex3fv( bottomLeft.mV );
  326. gGL.texCoord2i( 1, 0 ); gGL.vertex3fv( bottomRight.mV );
  327. gGL.texCoord2i( 0, 1 ); gGL.vertex3fv( topLeft.mV );
  328. gGL.end();
  329. gGL.begin( LLRender::TRIANGLE_STRIP );
  330. gGL.texCoord2i( 1, 0 ); gGL.vertex3fv( bottomRight.mV );
  331. gGL.texCoord2i( 1, 1 ); gGL.vertex3fv( topRight.mV );
  332. gGL.texCoord2i( 0, 1 ); gGL.vertex3fv( topLeft.mV );
  333. gGL.end();
  334. //--------------------------------------------------------------------------------------
  335. // if currently speaking, trigger waves (1 through 6) based on speaking amplitude
  336. //--------------------------------------------------------------------------------------
  337. if ( mCurrentlySpeaking )
  338. {
  339. F32 min = 0.2f;
  340. F32 max = 0.7f;
  341. F32 fraction = ( mSpeakingAmplitude - min ) / ( max - min );
  342. // in case mSpeakingAmplitude > max....
  343. if ( fraction > 1.0f )
  344. {
  345. fraction = 1.0f;
  346. }
  347. S32 level = 1 + (int)( fraction * ( NUM_VOICE_SYMBOL_WAVES - 2 ) );
  348. for (int i=0; i<level+1; i++)
  349. {
  350. mSoundSymbol.mWaveActive [i] = true;
  351. mSoundSymbol.mWaveOpacity [i] = 1.0f;
  352. mSoundSymbol.mWaveFadeOutStartTime [i] = mCurrentTime;
  353. }
  354. } // if currently speaking
  355. //---------------------------------------------------
  356. // determine color
  357. //---------------------------------------------------
  358. F32 red = 0.0f;
  359. F32 green = 0.0f;
  360. F32 blue = 0.0f;
  361.         if ( mSpeakingAmplitude < RED_THRESHOLD )
  362.         {
  363. if ( mSpeakingAmplitude < GREEN_THRESHOLD )
  364. {
  365. red = BASE_BRIGHTNESS;
  366. green = BASE_BRIGHTNESS;
  367. blue = BASE_BRIGHTNESS;
  368. }
  369. else
  370. {
  371. //---------------------------------------------------
  372. // fade from gray to bright green
  373. //---------------------------------------------------
  374. F32 fraction = ( mSpeakingAmplitude - GREEN_THRESHOLD ) / ( 1.0f - GREEN_THRESHOLD );
  375. red = BASE_BRIGHTNESS - ( fraction * BASE_BRIGHTNESS );
  376. green = BASE_BRIGHTNESS +   fraction * ( 1.0f - BASE_BRIGHTNESS );
  377. blue = BASE_BRIGHTNESS - ( fraction * BASE_BRIGHTNESS );
  378. }
  379.         }
  380.         else
  381.         {
  382. //---------------------------------------------------
  383. // redish
  384. //---------------------------------------------------
  385. red = 1.0f;
  386. green = 0.2f;
  387. blue = 0.2f;
  388.         }
  389. for (int i=0; i<NUM_VOICE_SYMBOL_WAVES; i++)
  390. {
  391. if ( mSoundSymbol.mWaveActive[i] ) 
  392. {
  393. F32 fadeOutFraction = (F32)( mCurrentTime - mSoundSymbol.mWaveFadeOutStartTime[i] ) / FADE_OUT_DURATION;
  394. mSoundSymbol.mWaveOpacity[i] = 1.0f - fadeOutFraction;
  395. if ( mSoundSymbol.mWaveOpacity[i] < 0.0f )
  396. {
  397. mSoundSymbol.mWaveFadeOutStartTime [i] = mCurrentTime;
  398. mSoundSymbol.mWaveOpacity [i] = 0.0f;
  399. mSoundSymbol.mWaveActive [i] = false;
  400. }
  401. //----------------------------------------------------------------------------------
  402. // This is where we calculate the expansion of the waves - that is, the
  403. // rate at which they are scaled greater than 1.0 so that they grow over time.
  404. //----------------------------------------------------------------------------------
  405. F32 timeSlice = (F32)( mCurrentTime - mPreviousTime );
  406. F32 waveSpeed = mSpeakingAmplitude * WAVE_MOTION_RATE;
  407. mSoundSymbol.mWaveExpansion[i] *= ( 1.0f + EXPANSION_RATE * timeSlice * waveSpeed );
  408. if ( mSoundSymbol.mWaveExpansion[i] > EXPANSION_MAX )
  409. {
  410. mSoundSymbol.mWaveExpansion[i] = 1.0f;
  411. }
  412. //----------------------------------------------------------------------------------
  413. // create geometry for the wave billboard textures
  414. //----------------------------------------------------------------------------------
  415. F32 width = i * WAVE_WIDTH_SCALE  * mSoundSymbol.mWaveExpansion[i];
  416. F32 height = i * WAVE_HEIGHT_SCALE * mSoundSymbol.mWaveExpansion[i];
  417. LLVector3 l = camera->getLeftAxis() * width;
  418. LLVector3 u = camera->getUpAxis()   * height;
  419. LLVector3 bottomLeft = mSoundSymbol.mPosition + l - u;
  420. LLVector3 bottomRight = mSoundSymbol.mPosition - l - u;
  421. LLVector3 topLeft = mSoundSymbol.mPosition + l + u;
  422. LLVector3 topRight = mSoundSymbol.mPosition - l + u;
  423. gGL.color4fv( LLColor4( red, green, blue, mSoundSymbol.mWaveOpacity[i] ).mV );
  424. gGL.getTexUnit(0)->bind(mSoundSymbol.mTexture[i]);
  425. //---------------------------------------------------
  426. // now, render the mofo
  427. //---------------------------------------------------
  428. gGL.begin( LLRender::TRIANGLE_STRIP );
  429. gGL.texCoord2i( 0, 0 ); gGL.vertex3fv( bottomLeft.mV );
  430. gGL.texCoord2i( 1, 0 ); gGL.vertex3fv( bottomRight.mV );
  431. gGL.texCoord2i( 0, 1 ); gGL.vertex3fv( topLeft.mV );
  432. gGL.end();
  433. gGL.begin( LLRender::TRIANGLE_STRIP );
  434. gGL.texCoord2i( 1, 0 ); gGL.vertex3fv( bottomRight.mV );
  435. gGL.texCoord2i( 1, 1 ); gGL.vertex3fv( topRight.mV );
  436. gGL.texCoord2i( 0, 1 ); gGL.vertex3fv( topLeft.mV );
  437. gGL.end();
  438. } //if ( mSoundSymbol.mWaveActive[i] ) 
  439. }// for loop
  440. }//if ( mSoundSymbol.mActive ) 
  441. }//---------------------------------------------------
  442. //---------------------------------------------------
  443. void LLVoiceVisualizer::setVoiceSourceWorldPosition( const LLVector3 &p )
  444. {
  445. mVoiceSourceWorldPosition = p;
  446. }//---------------------------------------------------
  447. //---------------------------------------------------
  448. VoiceGesticulationLevel LLVoiceVisualizer::getCurrentGesticulationLevel()
  449. {
  450. VoiceGesticulationLevel gesticulationLevel = VOICE_GESTICULATION_LEVEL_OFF; //default
  451. //-----------------------------------------------------------------------------------------
  452. // Within the range of gesticulation amplitudes, the sound signal is split into
  453. // three equal amplitude regimes, each specifying one of three gesticulation levels.
  454. //-----------------------------------------------------------------------------------------
  455. F32 range = mMaxGesticulationAmplitude - mMinGesticulationAmplitude;
  456. if ( mSpeakingAmplitude > mMinGesticulationAmplitude + range * 0.5f ) { gesticulationLevel = VOICE_GESTICULATION_LEVEL_HIGH; }
  457. else if ( mSpeakingAmplitude > mMinGesticulationAmplitude + range * 0.25f ) { gesticulationLevel = VOICE_GESTICULATION_LEVEL_MEDIUM; }
  458. else if ( mSpeakingAmplitude > mMinGesticulationAmplitude + range * 0.00000f ) { gesticulationLevel = VOICE_GESTICULATION_LEVEL_LOW; }
  459. return gesticulationLevel;
  460. }//---------------------------------------------------
  461. //------------------------------------
  462. // Destructor
  463. //------------------------------------
  464. LLVoiceVisualizer::~LLVoiceVisualizer()
  465. {
  466. }//----------------------------------------------
  467. //---------------------------------------------------
  468. // "packData" is inherited from HUDEffect
  469. //---------------------------------------------------
  470. void LLVoiceVisualizer::packData(LLMessageSystem *mesgsys)
  471. {
  472. // Pack the default data
  473. LLHUDEffect::packData(mesgsys);
  474. // TODO -- pack the relevant data for voice effects
  475. // we'll come up with some cool configurations....TBD
  476. //U8 packed_data[41];
  477. //mesgsys->addBinaryDataFast(_PREHASH_TypeData, packed_data, 41);
  478. U8 packed_data = 0;
  479. mesgsys->addBinaryDataFast(_PREHASH_TypeData, &packed_data, 1);
  480. }
  481. //---------------------------------------------------
  482. // "unpackData" is inherited from HUDEffect
  483. //---------------------------------------------------
  484. void LLVoiceVisualizer::unpackData(LLMessageSystem *mesgsys, S32 blocknum)
  485. {
  486. // TODO -- find the speaker, unpack binary data, set the properties of this effect
  487. /*
  488. LLHUDEffect::unpackData(mesgsys, blocknum);
  489. LLUUID source_id;
  490. LLUUID target_id;
  491. S32 size = mesgsys->getSizeFast(_PREHASH_Effect, blocknum, _PREHASH_TypeData);
  492. if (size != 1)
  493. {
  494. llwarns << "Voice effect with bad size " << size << llendl;
  495. return;
  496. }
  497. mesgsys->getBinaryDataFast(_PREHASH_Effect, _PREHASH_TypeData, packed_data, 1, blocknum);
  498. */
  499. }
  500. //------------------------------------------------------------------
  501. // this method is inherited from HUD Effect
  502. //------------------------------------------------------------------
  503. void LLVoiceVisualizer::markDead()
  504. {
  505. mCurrentlySpeaking = false;
  506. mVoiceEnabled = false;
  507. mSoundSymbol.mActive = false;
  508. LLHUDEffect::markDead();
  509. }//------------------------------------------------------------------