Annotation of /trunk/indra/newview/llvoicevisualizer.cpp
Parent Directory
|
Revision Log
Revision 135 - (view) (download)
| 1 : | mjm | 135 | /** |
| 2 : | * @file llvoicevisualizer.cpp | ||
| 3 : | * @brief Draws in-world speaking indicators. | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2000&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | * Copyright (c) 2000-2009, 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 : | //---------------------------------------------------------------------- | ||
| 34 : | // Voice Visualizer | ||
| 35 : | // author: JJ Ventrella | ||
| 36 : | // (information about this stuff can be found in "llvoicevisualizer.h") | ||
| 37 : | //---------------------------------------------------------------------- | ||
| 38 : | #include "llviewerprecompiledheaders.h" | ||
| 39 : | #include "llviewercontrol.h" | ||
| 40 : | #include "llglheaders.h" | ||
| 41 : | #include "llsphere.h" | ||
| 42 : | #include "llvoicevisualizer.h" | ||
| 43 : | #include "llviewercamera.h" | ||
| 44 : | #include "llviewerobject.h" | ||
| 45 : | #include "llimagegl.h" | ||
| 46 : | #include "llviewerimage.h" | ||
| 47 : | #include "llviewerimagelist.h" | ||
| 48 : | #include "llvoiceclient.h" | ||
| 49 : | #include "llrender.h" | ||
| 50 : | |||
| 51 : | //brent's wave image | ||
| 52 : | //29de489d-0491-fb00-7dab-f9e686d31e83 | ||
| 53 : | |||
| 54 : | |||
| 55 : | //-------------------------------------------------------------------------------------- | ||
| 56 : | // sound symbol constants | ||
| 57 : | //-------------------------------------------------------------------------------------- | ||
| 58 : | const F32 HEIGHT_ABOVE_HEAD = 0.3f; // how many meters vertically above the av's head the voice symbol will appear | ||
| 59 : | const F32 RED_THRESHOLD = LLVoiceClient::OVERDRIVEN_POWER_LEVEL; // value above which speaking amplitude causes the voice symbol to turn red | ||
| 60 : | const F32 GREEN_THRESHOLD = 0.2f; // value above which speaking amplitude causes the voice symbol to turn green | ||
| 61 : | const F32 FADE_OUT_DURATION = 0.4f; // how many seconds it takes for a pair of waves to fade away | ||
| 62 : | const F32 EXPANSION_RATE = 1.0f; // how many seconds it takes for the waves to expand to twice their original size | ||
| 63 : | const F32 EXPANSION_MAX = 1.5f; // maximum size scale to which the waves can expand before popping back to 1.0 | ||
| 64 : | const F32 WAVE_WIDTH_SCALE = 0.03f; // base width of the waves | ||
| 65 : | const F32 WAVE_HEIGHT_SCALE = 0.02f; // base height of the waves | ||
| 66 : | const F32 BASE_BRIGHTNESS = 0.7f; // gray level of the voice indicator when quiet (below green threshold) | ||
| 67 : | const F32 DOT_SIZE = 0.05f; // size of the dot billboard texture | ||
| 68 : | const F32 DOT_OPACITY = 0.7f; // how opaque the dot is | ||
| 69 : | const F32 WAVE_MOTION_RATE = 1.5f; // scalar applied to consecutive waves as a function of speaking amplitude | ||
| 70 : | |||
| 71 : | //-------------------------------------------------------------------------------------- | ||
| 72 : | // gesticulation constants | ||
| 73 : | //-------------------------------------------------------------------------------------- | ||
| 74 : | const F32 DEFAULT_MINIMUM_GESTICULATION_AMPLITUDE = 0.2f; | ||
| 75 : | const F32 DEFAULT_MAXIMUM_GESTICULATION_AMPLITUDE = 1.0f; | ||
| 76 : | |||
| 77 : | //-------------------------------------------------------------------------------------- | ||
| 78 : | // other constants | ||
| 79 : | //-------------------------------------------------------------------------------------- | ||
| 80 : | const F32 ONE_HALF = 1.0f; // to clarify intent and reduce magic numbers in the code. | ||
| 81 : | const LLVector3 WORLD_UPWARD_DIRECTION = LLVector3( 0.0f, 0.0f, 1.0f ); // Z is up in SL | ||
| 82 : | |||
| 83 : | |||
| 84 : | //------------------------------------------------------------------ | ||
| 85 : | // handles parameter updates | ||
| 86 : | //------------------------------------------------------------------ | ||
| 87 : | static bool handleVoiceVisualizerPrefsChanged(const LLSD& newvalue) | ||
| 88 : | { | ||
| 89 : | // Note: Ignore the specific event value, we look up the ones we want | ||
| 90 : | LLVoiceVisualizer::setPreferences(); | ||
| 91 : | return true; | ||
| 92 : | } | ||
| 93 : | |||
| 94 : | //------------------------------------------------------------------ | ||
| 95 : | // Initialize the statics | ||
| 96 : | //------------------------------------------------------------------ | ||
| 97 : | bool LLVoiceVisualizer::sPrefsInitialized = false; | ||
| 98 : | BOOL LLVoiceVisualizer::sLipSyncEnabled = FALSE; | ||
| 99 : | F32* LLVoiceVisualizer::sOoh = NULL; | ||
| 100 : | F32* LLVoiceVisualizer::sAah = NULL; | ||
| 101 : | U32 LLVoiceVisualizer::sOohs = 0; | ||
| 102 : | U32 LLVoiceVisualizer::sAahs = 0; | ||
| 103 : | F32 LLVoiceVisualizer::sOohAahRate = 0.0f; | ||
| 104 : | F32* LLVoiceVisualizer::sOohPowerTransfer = NULL; | ||
| 105 : | U32 LLVoiceVisualizer::sOohPowerTransfers = 0; | ||
| 106 : | F32 LLVoiceVisualizer::sOohPowerTransfersf = 0.0f; | ||
| 107 : | F32* LLVoiceVisualizer::sAahPowerTransfer = NULL; | ||
| 108 : | U32 LLVoiceVisualizer::sAahPowerTransfers = 0; | ||
| 109 : | F32 LLVoiceVisualizer::sAahPowerTransfersf = 0.0f; | ||
| 110 : | |||
| 111 : | |||
| 112 : | //----------------------------------------------- | ||
| 113 : | // constructor | ||
| 114 : | //----------------------------------------------- | ||
| 115 : | LLVoiceVisualizer::LLVoiceVisualizer( const U8 type ) | ||
| 116 : | :LLHUDEffect( type ) | ||
| 117 : | { | ||
| 118 : | mCurrentTime = mTimer.getTotalSeconds(); | ||
| 119 : | mPreviousTime = mCurrentTime; | ||
| 120 : | mStartTime = mCurrentTime; | ||
| 121 : | mVoiceSourceWorldPosition = LLVector3( 0.0f, 0.0f, 0.0f ); | ||
| 122 : | mSpeakingAmplitude = 0.0f; | ||
| 123 : | mCurrentlySpeaking = false; | ||
| 124 : | mVoiceEnabled = false; | ||
| 125 : | mMinGesticulationAmplitude = DEFAULT_MINIMUM_GESTICULATION_AMPLITUDE; | ||
| 126 : | mMaxGesticulationAmplitude = DEFAULT_MAXIMUM_GESTICULATION_AMPLITUDE; | ||
| 127 : | mSoundSymbol.mActive = true; | ||
| 128 : | mSoundSymbol.mPosition = LLVector3( 0.0f, 0.0f, 0.0f ); | ||
| 129 : | |||
| 130 : | mTimer.reset(); | ||
| 131 : | |||
| 132 : | const char* sound_level_img[] = | ||
| 133 : | { | ||
| 134 : | "041ee5a0-cb6a-9ac5-6e49-41e9320507d5.j2c", | ||
| 135 : | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", | ||
| 136 : | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", | ||
| 137 : | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", | ||
| 138 : | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", | ||
| 139 : | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", | ||
| 140 : | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c" | ||
| 141 : | }; | ||
| 142 : | |||
| 143 : | for (int i=0; i<NUM_VOICE_SYMBOL_WAVES; i++) | ||
| 144 : | { | ||
| 145 : | mSoundSymbol.mWaveFadeOutStartTime [i] = mCurrentTime; | ||
| 146 : | mSoundSymbol.mTexture [i] = gImageList.getImageFromFile(sound_level_img[i], FALSE, TRUE); | ||
| 147 : | mSoundSymbol.mWaveActive [i] = false; | ||
| 148 : | mSoundSymbol.mWaveOpacity [i] = 1.0f; | ||
| 149 : | mSoundSymbol.mWaveExpansion [i] = 1.0f; | ||
| 150 : | } | ||
| 151 : | |||
| 152 : | mSoundSymbol.mTexture[0]->setFilteringOption(LLTexUnit::TFO_ANISOTROPIC); | ||
| 153 : | |||
| 154 : | // The first instance loads the initial state from prefs. | ||
| 155 : | if (!sPrefsInitialized) | ||
| 156 : | { | ||
| 157 : | setPreferences(); | ||
| 158 : | |||
| 159 : | // Set up our listener to get updates on all prefs values we care about. | ||
| 160 : | gSavedSettings.getControl("LipSyncEnabled")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _1)); | ||
| 161 : | gSavedSettings.getControl("LipSyncOohAahRate")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _1)); | ||
| 162 : | gSavedSettings.getControl("LipSyncOoh")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _1)); | ||
| 163 : | gSavedSettings.getControl("LipSyncAah")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _1)); | ||
| 164 : | gSavedSettings.getControl("LipSyncOohPowerTransfer")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _1)); | ||
| 165 : | gSavedSettings.getControl("LipSyncAahPowerTransfer")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _1)); | ||
| 166 : | |||
| 167 : | sPrefsInitialized = true; | ||
| 168 : | } | ||
| 169 : | |||
| 170 : | }//--------------------------------------------------- | ||
| 171 : | |||
| 172 : | //--------------------------------------------------- | ||
| 173 : | void LLVoiceVisualizer::setMinGesticulationAmplitude( F32 m ) | ||
| 174 : | { | ||
| 175 : | mMinGesticulationAmplitude = m; | ||
| 176 : | |||
| 177 : | }//--------------------------------------------------- | ||
| 178 : | |||
| 179 : | //--------------------------------------------------- | ||
| 180 : | void LLVoiceVisualizer::setMaxGesticulationAmplitude( F32 m ) | ||
| 181 : | { | ||
| 182 : | mMaxGesticulationAmplitude = m; | ||
| 183 : | |||
| 184 : | }//--------------------------------------------------- | ||
| 185 : | |||
| 186 : | //--------------------------------------------------- | ||
| 187 : | void LLVoiceVisualizer::setVoiceEnabled( bool v ) | ||
| 188 : | { | ||
| 189 : | mVoiceEnabled = v; | ||
| 190 : | |||
| 191 : | }//--------------------------------------------------- | ||
| 192 : | |||
| 193 : | //--------------------------------------------------- | ||
| 194 : | void LLVoiceVisualizer::setStartSpeaking() | ||
| 195 : | { | ||
| 196 : | mStartTime = mTimer.getTotalSeconds(); | ||
| 197 : | mCurrentlySpeaking = true; | ||
| 198 : | mSoundSymbol.mActive = true; | ||
| 199 : | |||
| 200 : | }//--------------------------------------------------- | ||
| 201 : | |||
| 202 : | |||
| 203 : | //--------------------------------------------------- | ||
| 204 : | bool LLVoiceVisualizer::getCurrentlySpeaking() | ||
| 205 : | { | ||
| 206 : | return mCurrentlySpeaking; | ||
| 207 : | |||
| 208 : | }//--------------------------------------------------- | ||
| 209 : | |||
| 210 : | |||
| 211 : | //--------------------------------------------------- | ||
| 212 : | void LLVoiceVisualizer::setStopSpeaking() | ||
| 213 : | { | ||
| 214 : | mCurrentlySpeaking = false; | ||
| 215 : | mSpeakingAmplitude = 0.0f; | ||
| 216 : | |||
| 217 : | }//--------------------------------------------------- | ||
| 218 : | |||
| 219 : | |||
| 220 : | //--------------------------------------------------- | ||
| 221 : | void LLVoiceVisualizer::setSpeakingAmplitude( F32 a ) | ||
| 222 : | { | ||
| 223 : | mSpeakingAmplitude = a; | ||
| 224 : | |||
| 225 : | }//--------------------------------------------------- | ||
| 226 : | |||
| 227 : | |||
| 228 : | //--------------------------------------------------- | ||
| 229 : | void LLVoiceVisualizer::setPreferences( ) | ||
| 230 : | { | ||
| 231 : | sLipSyncEnabled = gSavedSettings.getBOOL("LipSyncEnabled"); | ||
| 232 : | sOohAahRate = gSavedSettings.getF32("LipSyncOohAahRate"); | ||
| 233 : | |||
| 234 : | std::string oohString = gSavedSettings.getString("LipSyncOoh"); | ||
| 235 : | lipStringToF32s (oohString, sOoh, sOohs); | ||
| 236 : | |||
| 237 : | std::string aahString = gSavedSettings.getString("LipSyncAah"); | ||
| 238 : | lipStringToF32s (aahString, sAah, sAahs); | ||
| 239 : | |||
| 240 : | std::string oohPowerString = gSavedSettings.getString("LipSyncOohPowerTransfer"); | ||
| 241 : | lipStringToF32s (oohPowerString, sOohPowerTransfer, sOohPowerTransfers); | ||
| 242 : | sOohPowerTransfersf = (F32) sOohPowerTransfers; | ||
| 243 : | |||
| 244 : | std::string aahPowerString = gSavedSettings.getString("LipSyncAahPowerTransfer"); | ||
| 245 : | lipStringToF32s (aahPowerString, sAahPowerTransfer, sAahPowerTransfers); | ||
| 246 : | sAahPowerTransfersf = (F32) sAahPowerTransfers; | ||
| 247 : | |||
| 248 : | }//--------------------------------------------------- | ||
| 249 : | |||
| 250 : | |||
| 251 : | //--------------------------------------------------- | ||
| 252 : | // convert a string of digits to an array of floats. | ||
| 253 : | // the result for each digit is the value of the | ||
| 254 : | // digit multiplied by 0.11 | ||
| 255 : | //--------------------------------------------------- | ||
| 256 : | void LLVoiceVisualizer::lipStringToF32s ( std::string& in_string, F32*& out_F32s, U32& count_F32s ) | ||
| 257 : | { | ||
| 258 : | delete[] out_F32s; // get rid of the current array | ||
| 259 : | |||
| 260 : | count_F32s = in_string.length(); | ||
| 261 : | if (count_F32s == 0) | ||
| 262 : | { | ||
| 263 : | // we don't like zero length arrays | ||
| 264 : | |||
| 265 : | count_F32s = 1; | ||
| 266 : | out_F32s = new F32[1]; | ||
| 267 : | out_F32s[0] = 0.0f; | ||
| 268 : | } | ||
| 269 : | else | ||
| 270 : | { | ||
| 271 : | out_F32s = new F32[count_F32s]; | ||
| 272 : | |||
| 273 : | for (U32 i=0; i<count_F32s; i++) | ||
| 274 : | { | ||
| 275 : | // we convert the characters 0 to 9 to their numeric value | ||
| 276 : | // anything else we take the low order four bits with a ceiling of 9 | ||
| 277 : | |||
| 278 : | U8 digit = in_string[i]; | ||
| 279 : | U8 four_bits = digit % 16; | ||
| 280 : | if (four_bits > 9) | ||
| 281 : | { | ||
| 282 : | four_bits = 9; | ||
| 283 : | } | ||
| 284 : | out_F32s[i] = 0.11f * (F32) four_bits; | ||
| 285 : | } | ||
| 286 : | } | ||
| 287 : | |||
| 288 : | }//--------------------------------------------------- | ||
| 289 : | |||
| 290 : | |||
| 291 : | //-------------------------------------------------------------------------- | ||
| 292 : | // find the amount to blend the ooh and aah mouth morphs | ||
| 293 : | //-------------------------------------------------------------------------- | ||
| 294 : | void LLVoiceVisualizer::lipSyncOohAah( F32& ooh, F32& aah ) | ||
| 295 : | { | ||
| 296 : | if( ( sLipSyncEnabled == TRUE ) && mCurrentlySpeaking ) | ||
| 297 : | { | ||
| 298 : | U32 transfer_index = (U32) (sOohPowerTransfersf * mSpeakingAmplitude); | ||
| 299 : | if (transfer_index >= sOohPowerTransfers) | ||
| 300 : | { | ||
| 301 : | transfer_index = sOohPowerTransfers - 1; | ||
| 302 : | } | ||
| 303 : | F32 transfer_ooh = sOohPowerTransfer[transfer_index]; | ||
| 304 : | |||
| 305 : | transfer_index = (U32) (sAahPowerTransfersf * mSpeakingAmplitude); | ||
| 306 : | if (transfer_index >= sAahPowerTransfers) | ||
| 307 : | { | ||
| 308 : | transfer_index = sAahPowerTransfers - 1; | ||
| 309 : | } | ||
| 310 : | F32 transfer_aah = sAahPowerTransfer[transfer_index]; | ||
| 311 : | |||
| 312 : | F64 current_time = mTimer.getTotalSeconds(); | ||
| 313 : | F64 elapsed_time = current_time - mStartTime; | ||
| 314 : | U32 elapsed_frames = (U32) (elapsed_time * sOohAahRate); | ||
| 315 : | U32 elapsed_oohs = elapsed_frames % sOohs; | ||
| 316 : | U32 elapsed_aahs = elapsed_frames % sAahs; | ||
| 317 : | |||
| 318 : | ooh = transfer_ooh * sOoh[elapsed_oohs]; | ||
| 319 : | aah = transfer_aah * sAah[elapsed_aahs]; | ||
| 320 : | |||
| 321 : | /* | ||
| 322 : | llinfos << " elapsed frames " << elapsed_frames | ||
| 323 : | << " ooh " << ooh | ||
| 324 : | << " aah " << aah | ||
| 325 : | << " transfer ooh" << transfer_ooh | ||
| 326 : | << " transfer aah" << transfer_aah | ||
| 327 : | << " start time " << mStartTime | ||
| 328 : | << " current time " << current_time | ||
| 329 : | << " elapsed time " << elapsed_time | ||
| 330 : | << " elapsed oohs " << elapsed_oohs | ||
| 331 : | << " elapsed aahs " << elapsed_aahs | ||
| 332 : | << llendl; | ||
| 333 : | */ | ||
| 334 : | } | ||
| 335 : | else | ||
| 336 : | { | ||
| 337 : | ooh = 0.0f; | ||
| 338 : | aah = 0.0f; | ||
| 339 : | } | ||
| 340 : | |||
| 341 : | }//--------------------------------------------------- | ||
| 342 : | |||
| 343 : | |||
| 344 : | //--------------------------------------------------- | ||
| 345 : | // this method is inherited from HUD Effect | ||
| 346 : | //--------------------------------------------------- | ||
| 347 : | void LLVoiceVisualizer::render() | ||
| 348 : | { | ||
| 349 : | if ( ! mVoiceEnabled ) | ||
| 350 : | { | ||
| 351 : | return; | ||
| 352 : | } | ||
| 353 : | |||
| 354 : | if ( mSoundSymbol.mActive ) | ||
| 355 : | { | ||
| 356 : | mPreviousTime = mCurrentTime; | ||
| 357 : | mCurrentTime = mTimer.getTotalSeconds(); | ||
| 358 : | |||
| 359 : | //--------------------------------------------------------------- | ||
| 360 : | // set the sound symbol position over the source (avatar's head) | ||
| 361 : | //--------------------------------------------------------------- | ||
| 362 : | mSoundSymbol.mPosition = mVoiceSourceWorldPosition + WORLD_UPWARD_DIRECTION * HEIGHT_ABOVE_HEAD; | ||
| 363 : | |||
| 364 : | //--------------------------------------------------------------- | ||
| 365 : | // some gl state | ||
| 366 : | //--------------------------------------------------------------- | ||
| 367 : | LLGLSPipelineAlpha alpha_blend; | ||
| 368 : | LLGLDepthTest depth(GL_TRUE, GL_FALSE); | ||
| 369 : | |||
| 370 : | //------------------------------------------------------------- | ||
| 371 : | // create coordinates of the geometry for the dot | ||
| 372 : | //------------------------------------------------------------- | ||
| 373 : | LLVector3 l = LLViewerCamera::getInstance()->getLeftAxis() * DOT_SIZE; | ||
| 374 : | LLVector3 u = LLViewerCamera::getInstance()->getUpAxis() * DOT_SIZE; | ||
| 375 : | |||
| 376 : | LLVector3 bottomLeft = mSoundSymbol.mPosition + l - u; | ||
| 377 : | LLVector3 bottomRight = mSoundSymbol.mPosition - l - u; | ||
| 378 : | LLVector3 topLeft = mSoundSymbol.mPosition + l + u; | ||
| 379 : | LLVector3 topRight = mSoundSymbol.mPosition - l + u; | ||
| 380 : | |||
| 381 : | //----------------------------- | ||
| 382 : | // bind texture 0 (the dot) | ||
| 383 : | //----------------------------- | ||
| 384 : | gGL.getTexUnit(0)->bind(mSoundSymbol.mTexture[0]); | ||
| 385 : | |||
| 386 : | //------------------------------------------------------------- | ||
| 387 : | // now render the dot | ||
| 388 : | //------------------------------------------------------------- | ||
| 389 : | gGL.color4fv( LLColor4( 1.0f, 1.0f, 1.0f, DOT_OPACITY ).mV ); | ||
| 390 : | |||
| 391 : | gGL.begin( LLRender::TRIANGLE_STRIP ); | ||
| 392 : | gGL.texCoord2i( 0, 0 ); gGL.vertex3fv( bottomLeft.mV ); | ||
| 393 : | gGL.texCoord2i( 1, 0 ); gGL.vertex3fv( bottomRight.mV ); | ||
| 394 : | gGL.texCoord2i( 0, 1 ); gGL.vertex3fv( topLeft.mV ); | ||
| 395 : | gGL.end(); | ||
| 396 : | |||
| 397 : | gGL.begin( LLRender::TRIANGLE_STRIP ); | ||
| 398 : | gGL.texCoord2i( 1, 0 ); gGL.vertex3fv( bottomRight.mV ); | ||
| 399 : | gGL.texCoord2i( 1, 1 ); gGL.vertex3fv( topRight.mV ); | ||
| 400 : | gGL.texCoord2i( 0, 1 ); gGL.vertex3fv( topLeft.mV ); | ||
| 401 : | gGL.end(); | ||
| 402 : | |||
| 403 : | |||
| 404 : | |||
| 405 : | //-------------------------------------------------------------------------------------- | ||
| 406 : | // if currently speaking, trigger waves (1 through 6) based on speaking amplitude | ||
| 407 : | //-------------------------------------------------------------------------------------- | ||
| 408 : | if ( mCurrentlySpeaking ) | ||
| 409 : | { | ||
| 410 : | F32 min = 0.2f; | ||
| 411 : | F32 max = 0.7f; | ||
| 412 : | F32 fraction = ( mSpeakingAmplitude - min ) / ( max - min ); | ||
| 413 : | |||
| 414 : | // in case mSpeakingAmplitude > max.... | ||
| 415 : | if ( fraction > 1.0f ) | ||
| 416 : | { | ||
| 417 : | fraction = 1.0f; | ||
| 418 : | } | ||
| 419 : | |||
| 420 : | S32 level = 1 + (int)( fraction * ( NUM_VOICE_SYMBOL_WAVES - 2 ) ); | ||
| 421 : | |||
| 422 : | for (int i=0; i<level+1; i++) | ||
| 423 : | { | ||
| 424 : | mSoundSymbol.mWaveActive [i] = true; | ||
| 425 : | mSoundSymbol.mWaveOpacity [i] = 1.0f; | ||
| 426 : | mSoundSymbol.mWaveFadeOutStartTime [i] = mCurrentTime; | ||
| 427 : | } | ||
| 428 : | |||
| 429 : | } // if currently speaking | ||
| 430 : | |||
| 431 : | //--------------------------------------------------- | ||
| 432 : | // determine color | ||
| 433 : | //--------------------------------------------------- | ||
| 434 : | F32 red = 0.0f; | ||
| 435 : | F32 green = 0.0f; | ||
| 436 : | F32 blue = 0.0f; | ||
| 437 : | if ( mSpeakingAmplitude < RED_THRESHOLD ) | ||
| 438 : | { | ||
| 439 : | if ( mSpeakingAmplitude < GREEN_THRESHOLD ) | ||
| 440 : | { | ||
| 441 : | red = BASE_BRIGHTNESS; | ||
| 442 : | green = BASE_BRIGHTNESS; | ||
| 443 : | blue = BASE_BRIGHTNESS; | ||
| 444 : | } | ||
| 445 : | else | ||
| 446 : | { | ||
| 447 : | //--------------------------------------------------- | ||
| 448 : | // fade from gray to bright green | ||
| 449 : | //--------------------------------------------------- | ||
| 450 : | F32 fraction = ( mSpeakingAmplitude - GREEN_THRESHOLD ) / ( 1.0f - GREEN_THRESHOLD ); | ||
| 451 : | red = BASE_BRIGHTNESS - ( fraction * BASE_BRIGHTNESS ); | ||
| 452 : | green = BASE_BRIGHTNESS + fraction * ( 1.0f - BASE_BRIGHTNESS ); | ||
| 453 : | blue = BASE_BRIGHTNESS - ( fraction * BASE_BRIGHTNESS ); | ||
| 454 : | } | ||
| 455 : | } | ||
| 456 : | else | ||
| 457 : | { | ||
| 458 : | //--------------------------------------------------- | ||
| 459 : | // redish | ||
| 460 : | //--------------------------------------------------- | ||
| 461 : | red = 1.0f; | ||
| 462 : | green = 0.2f; | ||
| 463 : | blue = 0.2f; | ||
| 464 : | } | ||
| 465 : | |||
| 466 : | for (int i=0; i<NUM_VOICE_SYMBOL_WAVES; i++) | ||
| 467 : | { | ||
| 468 : | if ( mSoundSymbol.mWaveActive[i] ) | ||
| 469 : | { | ||
| 470 : | F32 fadeOutFraction = (F32)( mCurrentTime - mSoundSymbol.mWaveFadeOutStartTime[i] ) / FADE_OUT_DURATION; | ||
| 471 : | |||
| 472 : | mSoundSymbol.mWaveOpacity[i] = 1.0f - fadeOutFraction; | ||
| 473 : | |||
| 474 : | if ( mSoundSymbol.mWaveOpacity[i] < 0.0f ) | ||
| 475 : | { | ||
| 476 : | mSoundSymbol.mWaveFadeOutStartTime [i] = mCurrentTime; | ||
| 477 : | mSoundSymbol.mWaveOpacity [i] = 0.0f; | ||
| 478 : | mSoundSymbol.mWaveActive [i] = false; | ||
| 479 : | } | ||
| 480 : | |||
| 481 : | //---------------------------------------------------------------------------------- | ||
| 482 : | // This is where we calculate the expansion of the waves - that is, the | ||
| 483 : | // rate at which they are scaled greater than 1.0 so that they grow over time. | ||
| 484 : | //---------------------------------------------------------------------------------- | ||
| 485 : | F32 timeSlice = (F32)( mCurrentTime - mPreviousTime ); | ||
| 486 : | F32 waveSpeed = mSpeakingAmplitude * WAVE_MOTION_RATE; | ||
| 487 : | mSoundSymbol.mWaveExpansion[i] *= ( 1.0f + EXPANSION_RATE * timeSlice * waveSpeed ); | ||
| 488 : | |||
| 489 : | if ( mSoundSymbol.mWaveExpansion[i] > EXPANSION_MAX ) | ||
| 490 : | { | ||
| 491 : | mSoundSymbol.mWaveExpansion[i] = 1.0f; | ||
| 492 : | } | ||
| 493 : | |||
| 494 : | //---------------------------------------------------------------------------------- | ||
| 495 : | // create geometry for the wave billboard textures | ||
| 496 : | //---------------------------------------------------------------------------------- | ||
| 497 : | F32 width = i * WAVE_WIDTH_SCALE * mSoundSymbol.mWaveExpansion[i]; | ||
| 498 : | F32 height = i * WAVE_HEIGHT_SCALE * mSoundSymbol.mWaveExpansion[i]; | ||
| 499 : | |||
| 500 : | LLVector3 l = LLViewerCamera::getInstance()->getLeftAxis() * width; | ||
| 501 : | LLVector3 u = LLViewerCamera::getInstance()->getUpAxis() * height; | ||
| 502 : | |||
| 503 : | LLVector3 bottomLeft = mSoundSymbol.mPosition + l - u; | ||
| 504 : | LLVector3 bottomRight = mSoundSymbol.mPosition - l - u; | ||
| 505 : | LLVector3 topLeft = mSoundSymbol.mPosition + l + u; | ||
| 506 : | LLVector3 topRight = mSoundSymbol.mPosition - l + u; | ||
| 507 : | |||
| 508 : | gGL.color4fv( LLColor4( red, green, blue, mSoundSymbol.mWaveOpacity[i] ).mV ); | ||
| 509 : | gGL.getTexUnit(0)->bind(mSoundSymbol.mTexture[i]); | ||
| 510 : | |||
| 511 : | |||
| 512 : | //--------------------------------------------------- | ||
| 513 : | // now, render the mofo | ||
| 514 : | //--------------------------------------------------- | ||
| 515 : | gGL.begin( LLRender::TRIANGLE_STRIP ); | ||
| 516 : | gGL.texCoord2i( 0, 0 ); gGL.vertex3fv( bottomLeft.mV ); | ||
| 517 : | gGL.texCoord2i( 1, 0 ); gGL.vertex3fv( bottomRight.mV ); | ||
| 518 : | gGL.texCoord2i( 0, 1 ); gGL.vertex3fv( topLeft.mV ); | ||
| 519 : | gGL.end(); | ||
| 520 : | |||
| 521 : | gGL.begin( LLRender::TRIANGLE_STRIP ); | ||
| 522 : | gGL.texCoord2i( 1, 0 ); gGL.vertex3fv( bottomRight.mV ); | ||
| 523 : | gGL.texCoord2i( 1, 1 ); gGL.vertex3fv( topRight.mV ); | ||
| 524 : | gGL.texCoord2i( 0, 1 ); gGL.vertex3fv( topLeft.mV ); | ||
| 525 : | gGL.end(); | ||
| 526 : | |||
| 527 : | } //if ( mSoundSymbol.mWaveActive[i] ) | ||
| 528 : | |||
| 529 : | }// for loop | ||
| 530 : | |||
| 531 : | }//if ( mSoundSymbol.mActive ) | ||
| 532 : | |||
| 533 : | }//--------------------------------------------------- | ||
| 534 : | |||
| 535 : | |||
| 536 : | |||
| 537 : | |||
| 538 : | |||
| 539 : | //--------------------------------------------------- | ||
| 540 : | void LLVoiceVisualizer::setVoiceSourceWorldPosition( const LLVector3 &p ) | ||
| 541 : | { | ||
| 542 : | mVoiceSourceWorldPosition = p; | ||
| 543 : | |||
| 544 : | }//--------------------------------------------------- | ||
| 545 : | |||
| 546 : | //--------------------------------------------------- | ||
| 547 : | VoiceGesticulationLevel LLVoiceVisualizer::getCurrentGesticulationLevel() | ||
| 548 : | { | ||
| 549 : | VoiceGesticulationLevel gesticulationLevel = VOICE_GESTICULATION_LEVEL_OFF; //default | ||
| 550 : | |||
| 551 : | //----------------------------------------------------------------------------------------- | ||
| 552 : | // Within the range of gesticulation amplitudes, the sound signal is split into | ||
| 553 : | // three equal amplitude regimes, each specifying one of three gesticulation levels. | ||
| 554 : | //----------------------------------------------------------------------------------------- | ||
| 555 : | F32 range = mMaxGesticulationAmplitude - mMinGesticulationAmplitude; | ||
| 556 : | |||
| 557 : | if ( mSpeakingAmplitude > mMinGesticulationAmplitude + range * 0.5f ) { gesticulationLevel = VOICE_GESTICULATION_LEVEL_HIGH; } | ||
| 558 : | else if ( mSpeakingAmplitude > mMinGesticulationAmplitude + range * 0.25f ) { gesticulationLevel = VOICE_GESTICULATION_LEVEL_MEDIUM; } | ||
| 559 : | else if ( mSpeakingAmplitude > mMinGesticulationAmplitude + range * 0.00000f ) { gesticulationLevel = VOICE_GESTICULATION_LEVEL_LOW; } | ||
| 560 : | |||
| 561 : | return gesticulationLevel; | ||
| 562 : | |||
| 563 : | }//--------------------------------------------------- | ||
| 564 : | |||
| 565 : | |||
| 566 : | |||
| 567 : | //------------------------------------ | ||
| 568 : | // Destructor | ||
| 569 : | //------------------------------------ | ||
| 570 : | LLVoiceVisualizer::~LLVoiceVisualizer() | ||
| 571 : | { | ||
| 572 : | }//---------------------------------------------- | ||
| 573 : | |||
| 574 : | |||
| 575 : | //--------------------------------------------------- | ||
| 576 : | // "packData" is inherited from HUDEffect | ||
| 577 : | //--------------------------------------------------- | ||
| 578 : | void LLVoiceVisualizer::packData(LLMessageSystem *mesgsys) | ||
| 579 : | { | ||
| 580 : | // Pack the default data | ||
| 581 : | LLHUDEffect::packData(mesgsys); | ||
| 582 : | |||
| 583 : | // TODO -- pack the relevant data for voice effects | ||
| 584 : | // we'll come up with some cool configurations....TBD | ||
| 585 : | //U8 packed_data[41]; | ||
| 586 : | //mesgsys->addBinaryDataFast(_PREHASH_TypeData, packed_data, 41); | ||
| 587 : | U8 packed_data = 0; | ||
| 588 : | mesgsys->addBinaryDataFast(_PREHASH_TypeData, &packed_data, 1); | ||
| 589 : | } | ||
| 590 : | |||
| 591 : | |||
| 592 : | //--------------------------------------------------- | ||
| 593 : | // "unpackData" is inherited from HUDEffect | ||
| 594 : | //--------------------------------------------------- | ||
| 595 : | void LLVoiceVisualizer::unpackData(LLMessageSystem *mesgsys, S32 blocknum) | ||
| 596 : | { | ||
| 597 : | // TODO -- find the speaker, unpack binary data, set the properties of this effect | ||
| 598 : | /* | ||
| 599 : | LLHUDEffect::unpackData(mesgsys, blocknum); | ||
| 600 : | LLUUID source_id; | ||
| 601 : | LLUUID target_id; | ||
| 602 : | S32 size = mesgsys->getSizeFast(_PREHASH_Effect, blocknum, _PREHASH_TypeData); | ||
| 603 : | if (size != 1) | ||
| 604 : | { | ||
| 605 : | llwarns << "Voice effect with bad size " << size << llendl; | ||
| 606 : | return; | ||
| 607 : | } | ||
| 608 : | mesgsys->getBinaryDataFast(_PREHASH_Effect, _PREHASH_TypeData, packed_data, 1, blocknum); | ||
| 609 : | */ | ||
| 610 : | } | ||
| 611 : | |||
| 612 : | |||
| 613 : | //------------------------------------------------------------------ | ||
| 614 : | // this method is inherited from HUD Effect | ||
| 615 : | //------------------------------------------------------------------ | ||
| 616 : | void LLVoiceVisualizer::markDead() | ||
| 617 : | { | ||
| 618 : | mCurrentlySpeaking = false; | ||
| 619 : | mVoiceEnabled = false; | ||
| 620 : | mSoundSymbol.mActive = false; | ||
| 621 : | |||
| 622 : | LLHUDEffect::markDead(); | ||
| 623 : | }//------------------------------------------------------------------ | ||
| 624 : | |||
| 625 : | |||
| 626 : | |||
| 627 : | |||
| 628 : | |||
| 629 : | |||
| 630 : | |||
| 631 : |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

