summaryrefslogtreecommitdiff
path: root/indra/newview/llvoicevisualizer.cpp
blob: a361a1160c48a2a4962dcbece85196b69689a36a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
/** 
 * @file llvoicevisualizer.cpp
 * @brief Draws in-world speaking indicators.
 *
 * $LicenseInfo:firstyear=2000&license=viewergpl$
 * 
 * Copyright (c) 2000-2009, Linden Research, Inc.
 * 
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
 * 
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at
 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

//----------------------------------------------------------------------
// Voice Visualizer
// author: JJ Ventrella
// (information about this stuff can be found in "llvoicevisualizer.h")
//----------------------------------------------------------------------
#include "llviewerprecompiledheaders.h"
#include "llviewercontrol.h"
#include "llglheaders.h"
#include "llsphere.h"
#include "llvoicevisualizer.h"
#include "llviewercamera.h"
#include "llviewerobject.h"
#include "llimagegl.h"
#include "llviewerimage.h"
#include "llviewerimagelist.h"
#include "llvoiceclient.h"
#include "llrender.h"

//brent's wave image
//29de489d-0491-fb00-7dab-f9e686d31e83


//--------------------------------------------------------------------------------------
// sound symbol constants
//--------------------------------------------------------------------------------------
const F32	HEIGHT_ABOVE_HEAD	= 0.3f;		// how many meters vertically above the av's head the voice symbol will appear
const F32	RED_THRESHOLD		= LLVoiceClient::OVERDRIVEN_POWER_LEVEL;		// value above which speaking amplitude causes the voice symbol to turn red
const F32	GREEN_THRESHOLD		= 0.2f;		// value above which speaking amplitude causes the voice symbol to turn green
const F32	FADE_OUT_DURATION	= 0.4f;		// how many seconds it takes for a pair of waves to fade away
const F32	EXPANSION_RATE		= 1.0f;		// how many seconds it takes for the waves to expand to twice their original size
const F32	EXPANSION_MAX		= 1.5f;		// maximum size scale to which the waves can expand before popping back to 1.0 
const F32	WAVE_WIDTH_SCALE	= 0.03f;	// base width of the waves 
const F32	WAVE_HEIGHT_SCALE	= 0.02f;	// base height of the waves 
const F32	BASE_BRIGHTNESS		= 0.7f;		// gray level of the voice indicator when quiet (below green threshold)
const F32	DOT_SIZE			= 0.05f;	// size of the dot billboard texture
const F32	DOT_OPACITY			= 0.7f;		// how opaque the dot is
const F32	WAVE_MOTION_RATE	= 1.5f;		// scalar applied to consecutive waves as a function of speaking amplitude

//--------------------------------------------------------------------------------------
// gesticulation constants
//--------------------------------------------------------------------------------------
const F32 DEFAULT_MINIMUM_GESTICULATION_AMPLITUDE	= 0.2f; 
const F32 DEFAULT_MAXIMUM_GESTICULATION_AMPLITUDE	= 1.0f;

//--------------------------------------------------------------------------------------
// other constants
//--------------------------------------------------------------------------------------
const F32 ONE_HALF = 1.0f; // to clarify intent and reduce magic numbers in the code. 
const LLVector3 WORLD_UPWARD_DIRECTION = LLVector3( 0.0f, 0.0f, 1.0f ); // Z is up in SL


//------------------------------------------------------------------
// handles parameter updates
//------------------------------------------------------------------
static bool handleVoiceVisualizerPrefsChanged(const LLSD& newvalue)
{
	// Note: Ignore the specific event value, we look up the ones we want
	LLVoiceVisualizer::setPreferences();
	return true;
}

//------------------------------------------------------------------
// Initialize the statics
//------------------------------------------------------------------
bool LLVoiceVisualizer::sPrefsInitialized	= false;
BOOL LLVoiceVisualizer::sLipSyncEnabled		= FALSE;
F32* LLVoiceVisualizer::sOoh				= NULL;
F32* LLVoiceVisualizer::sAah				= NULL;
U32	 LLVoiceVisualizer::sOohs				= 0;
U32	 LLVoiceVisualizer::sAahs				= 0;
F32	 LLVoiceVisualizer::sOohAahRate			= 0.0f;
F32* LLVoiceVisualizer::sOohPowerTransfer	= NULL;
U32	 LLVoiceVisualizer::sOohPowerTransfers	= 0;
F32	 LLVoiceVisualizer::sOohPowerTransfersf = 0.0f;
F32* LLVoiceVisualizer::sAahPowerTransfer	= NULL;
U32	 LLVoiceVisualizer::sAahPowerTransfers	= 0;
F32	 LLVoiceVisualizer::sAahPowerTransfersf = 0.0f;


//-----------------------------------------------
// constructor
//-----------------------------------------------
LLVoiceVisualizer::LLVoiceVisualizer( const U8 type )
:LLHUDEffect( type )
{
	mCurrentTime					= mTimer.getTotalSeconds();
	mPreviousTime					= mCurrentTime;
	mStartTime						= mCurrentTime;
	mVoiceSourceWorldPosition		= LLVector3( 0.0f, 0.0f, 0.0f );
	mSpeakingAmplitude				= 0.0f;
	mCurrentlySpeaking				= false;
	mVoiceEnabled					= false;
	mMinGesticulationAmplitude		= DEFAULT_MINIMUM_GESTICULATION_AMPLITUDE;
	mMaxGesticulationAmplitude		= DEFAULT_MAXIMUM_GESTICULATION_AMPLITUDE;
	mSoundSymbol.mActive			= true;
	mSoundSymbol.mPosition			= LLVector3( 0.0f, 0.0f, 0.0f );
	
	mTimer.reset();
	
	const char* sound_level_img[] = 
	{
		"voice_meter_dot.j2c",
		"voice_meter_rings.j2c",
		"voice_meter_rings.j2c",
		"voice_meter_rings.j2c",
		"voice_meter_rings.j2c",
		"voice_meter_rings.j2c",
		"voice_meter_rings.j2c"
	};

	for (int i=0; i<NUM_VOICE_SYMBOL_WAVES; i++)
	{
		mSoundSymbol.mWaveFadeOutStartTime	[i] = mCurrentTime;
		mSoundSymbol.mTexture				[i] = gImageList.getImageFromFile(sound_level_img[i], FALSE, TRUE);
		mSoundSymbol.mWaveActive			[i] = false;
		mSoundSymbol.mWaveOpacity			[i] = 1.0f;
		mSoundSymbol.mWaveExpansion			[i] = 1.0f;
	}

	mSoundSymbol.mTexture[0]->setFilteringOption(LLTexUnit::TFO_ANISOTROPIC);

	// The first instance loads the initial state from prefs.
	if (!sPrefsInitialized)
	{
		setPreferences();
       
		// Set up our listener to get updates on all prefs values we care about.
		gSavedSettings.getControl("LipSyncEnabled")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _2));
		gSavedSettings.getControl("LipSyncOohAahRate")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _2));
		gSavedSettings.getControl("LipSyncOoh")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _2));
		gSavedSettings.getControl("LipSyncAah")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _2));
		gSavedSettings.getControl("LipSyncOohPowerTransfer")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _2));
		gSavedSettings.getControl("LipSyncAahPowerTransfer")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _2));
		
		sPrefsInitialized = true;
	}

}//---------------------------------------------------

//---------------------------------------------------
void LLVoiceVisualizer::setMinGesticulationAmplitude( F32 m )
{
	mMinGesticulationAmplitude = m;

}//---------------------------------------------------

//---------------------------------------------------
void LLVoiceVisualizer::setMaxGesticulationAmplitude( F32 m )
{
	mMaxGesticulationAmplitude = m;

}//---------------------------------------------------

//---------------------------------------------------
void LLVoiceVisualizer::setVoiceEnabled( bool v )
{
	mVoiceEnabled = v;

}//---------------------------------------------------

//---------------------------------------------------
void LLVoiceVisualizer::setStartSpeaking()
{
	mStartTime				= mTimer.getTotalSeconds();
	mCurrentlySpeaking		= true;
	mSoundSymbol.mActive	= true;
		
}//---------------------------------------------------


//---------------------------------------------------
bool LLVoiceVisualizer::getCurrentlySpeaking()
{
	return mCurrentlySpeaking;
	
}//---------------------------------------------------


//---------------------------------------------------
void LLVoiceVisualizer::setStopSpeaking()
{
	mCurrentlySpeaking = false;
	mSpeakingAmplitude = 0.0f;
	
}//---------------------------------------------------


//---------------------------------------------------
void LLVoiceVisualizer::setSpeakingAmplitude( F32 a )
{
	mSpeakingAmplitude = a;
	
}//---------------------------------------------------


//---------------------------------------------------
void LLVoiceVisualizer::setPreferences( )
{
	sLipSyncEnabled = gSavedSettings.getBOOL("LipSyncEnabled");
	sOohAahRate		= gSavedSettings.getF32("LipSyncOohAahRate");

	std::string oohString = gSavedSettings.getString("LipSyncOoh");
	lipStringToF32s (oohString, sOoh, sOohs);

	std::string aahString = gSavedSettings.getString("LipSyncAah");
	lipStringToF32s (aahString, sAah, sAahs);

	std::string oohPowerString = gSavedSettings.getString("LipSyncOohPowerTransfer");
	lipStringToF32s (oohPowerString, sOohPowerTransfer, sOohPowerTransfers);
	sOohPowerTransfersf = (F32) sOohPowerTransfers;

	std::string aahPowerString = gSavedSettings.getString("LipSyncAahPowerTransfer");
	lipStringToF32s (aahPowerString, sAahPowerTransfer, sAahPowerTransfers);
	sAahPowerTransfersf = (F32) sAahPowerTransfers;

}//---------------------------------------------------


//---------------------------------------------------
// convert a string of digits to an array of floats.
// the result for each digit is the value of the
// digit multiplied by 0.11
//---------------------------------------------------
void LLVoiceVisualizer::lipStringToF32s ( std::string& in_string, F32*& out_F32s, U32& count_F32s )
{
	delete[] out_F32s;	// get rid of the current array

	count_F32s = in_string.length();
	if (count_F32s == 0)
	{
		// we don't like zero length arrays

		count_F32s  = 1;
		out_F32s	   = new F32[1];
		out_F32s[0] = 0.0f;
	}
	else
	{
		out_F32s = new F32[count_F32s];

		for (U32 i=0; i<count_F32s; i++)
		{
			// we convert the characters 0 to 9 to their numeric value
			// anything else we take the low order four bits with a ceiling of 9

		    U8 digit = in_string[i];
			U8 four_bits = digit % 16;
			if (four_bits > 9)
			{
				four_bits = 9;
			}
			out_F32s[i] = 0.11f * (F32) four_bits;
		} 
	}

}//---------------------------------------------------


//--------------------------------------------------------------------------
// find the amount to blend the ooh and aah mouth morphs
//--------------------------------------------------------------------------
void LLVoiceVisualizer::lipSyncOohAah( F32& ooh, F32& aah )
{
	if( ( sLipSyncEnabled == TRUE ) && mCurrentlySpeaking )
	{
		U32 transfer_index = (U32) (sOohPowerTransfersf * mSpeakingAmplitude);
		if (transfer_index >= sOohPowerTransfers)
		{
		   transfer_index = sOohPowerTransfers - 1;
		}
		F32 transfer_ooh = sOohPowerTransfer[transfer_index];

		transfer_index = (U32) (sAahPowerTransfersf * mSpeakingAmplitude);
		if (transfer_index >= sAahPowerTransfers)
		{
		   transfer_index = sAahPowerTransfers - 1;
		}
		F32 transfer_aah = sAahPowerTransfer[transfer_index];

		F64 current_time   = mTimer.getTotalSeconds();
		F64 elapsed_time   = current_time - mStartTime;
		U32 elapsed_frames = (U32) (elapsed_time * sOohAahRate);
		U32 elapsed_oohs   = elapsed_frames % sOohs;
		U32 elapsed_aahs   = elapsed_frames % sAahs;

		ooh = transfer_ooh * sOoh[elapsed_oohs];
		aah = transfer_aah * sAah[elapsed_aahs];

		/*
		llinfos << " elapsed frames " << elapsed_frames
				<< " ooh "            << ooh
				<< " aah "            << aah
				<< " transfer ooh"    << transfer_ooh
				<< " transfer aah"    << transfer_aah
				<< " start time "     << mStartTime
				<< " current time "   << current_time
				<< " elapsed time "   << elapsed_time
				<< " elapsed oohs "   << elapsed_oohs
				<< " elapsed aahs "   << elapsed_aahs
				<< llendl;
		*/
	}
	else
	{
		ooh = 0.0f;
		aah = 0.0f;
	}
	
}//---------------------------------------------------


//---------------------------------------------------
// this method is inherited from HUD Effect
//---------------------------------------------------
void LLVoiceVisualizer::render()
{
	if ( ! mVoiceEnabled )
	{
		return;
	}
	
	if ( mSoundSymbol.mActive ) 
	{				
		mPreviousTime = mCurrentTime;
		mCurrentTime = mTimer.getTotalSeconds();
	
		//---------------------------------------------------------------
		// set the sound symbol position over the source (avatar's head)
		//---------------------------------------------------------------
		mSoundSymbol.mPosition = mVoiceSourceWorldPosition + WORLD_UPWARD_DIRECTION * HEIGHT_ABOVE_HEAD;
	
		//---------------------------------------------------------------
		// some gl state
		//---------------------------------------------------------------
		LLGLSPipelineAlpha alpha_blend;
		LLGLDepthTest depth(GL_TRUE, GL_FALSE);
		
		//-------------------------------------------------------------
		// create coordinates of the geometry for the dot
		//-------------------------------------------------------------
		LLVector3 l	= LLViewerCamera::getInstance()->getLeftAxis() * DOT_SIZE;
		LLVector3 u	= LLViewerCamera::getInstance()->getUpAxis()   * DOT_SIZE;

		LLVector3 bottomLeft	= mSoundSymbol.mPosition + l - u;
		LLVector3 bottomRight	= mSoundSymbol.mPosition - l - u;
		LLVector3 topLeft		= mSoundSymbol.mPosition + l + u;
		LLVector3 topRight		= mSoundSymbol.mPosition - l + u;
		
		//-----------------------------
		// bind texture 0 (the dot)
		//-----------------------------
		gGL.getTexUnit(0)->bind(mSoundSymbol.mTexture[0]);
		
		//-------------------------------------------------------------
		// now render the dot
		//-------------------------------------------------------------
		gGL.color4fv( LLColor4( 1.0f, 1.0f, 1.0f, DOT_OPACITY ).mV );	
		
		gGL.begin( LLRender::TRIANGLE_STRIP );
			gGL.texCoord2i( 0,	0	); gGL.vertex3fv( bottomLeft.mV );
			gGL.texCoord2i( 1,	0	); gGL.vertex3fv( bottomRight.mV );
			gGL.texCoord2i( 0,	1	); gGL.vertex3fv( topLeft.mV );
		gGL.end();

		gGL.begin( LLRender::TRIANGLE_STRIP );
			gGL.texCoord2i( 1,	0	); gGL.vertex3fv( bottomRight.mV );
			gGL.texCoord2i( 1,	1	); gGL.vertex3fv( topRight.mV );
			gGL.texCoord2i( 0,	1	); gGL.vertex3fv( topLeft.mV );
		gGL.end();
		
		
		
		//--------------------------------------------------------------------------------------
		// if currently speaking, trigger waves (1 through 6) based on speaking amplitude
		//--------------------------------------------------------------------------------------
		if ( mCurrentlySpeaking )
		{
			F32 min = 0.2f;
			F32 max = 0.7f;
			F32 fraction = ( mSpeakingAmplitude - min ) / ( max - min );
		
			// in case mSpeakingAmplitude > max....
			if ( fraction > 1.0f )
			{
				fraction = 1.0f;
			}
														
			S32 level = 1 + (int)( fraction * ( NUM_VOICE_SYMBOL_WAVES - 2 ) );
																										
			for (int i=0; i<level+1; i++)
			{
				mSoundSymbol.mWaveActive			[i] = true;
				mSoundSymbol.mWaveOpacity			[i] = 1.0f;
				mSoundSymbol.mWaveFadeOutStartTime	[i] = mCurrentTime;
			}			
			
		} // if currently speaking
								
		//---------------------------------------------------
		// determine color
		//---------------------------------------------------
		F32 red		= 0.0f;
		F32 green	= 0.0f;
		F32 blue	= 0.0f;
        if ( mSpeakingAmplitude < RED_THRESHOLD )
        {
			if ( mSpeakingAmplitude < GREEN_THRESHOLD )
			{
				red		= BASE_BRIGHTNESS;
				green	= BASE_BRIGHTNESS;
				blue	= BASE_BRIGHTNESS;
			}
			else
			{
				//---------------------------------------------------
				// fade from gray to bright green
				//---------------------------------------------------
				F32 fraction = ( mSpeakingAmplitude - GREEN_THRESHOLD ) / ( 1.0f - GREEN_THRESHOLD );
				red		= BASE_BRIGHTNESS - ( fraction * BASE_BRIGHTNESS );
				green	= BASE_BRIGHTNESS +   fraction * ( 1.0f - BASE_BRIGHTNESS );
				blue	= BASE_BRIGHTNESS - ( fraction * BASE_BRIGHTNESS );
			}
        }
        else
        {
			//---------------------------------------------------
			// redish
			//---------------------------------------------------
			red		= 1.0f;
			green	= 0.2f;
			blue	= 0.2f;
        }
														
		for (int i=0; i<NUM_VOICE_SYMBOL_WAVES; i++)
		{
			if ( mSoundSymbol.mWaveActive[i] ) 
			{
				F32 fadeOutFraction = (F32)( mCurrentTime - mSoundSymbol.mWaveFadeOutStartTime[i] ) / FADE_OUT_DURATION;

				mSoundSymbol.mWaveOpacity[i] = 1.0f - fadeOutFraction;
				
				if ( mSoundSymbol.mWaveOpacity[i] < 0.0f )
				{
					mSoundSymbol.mWaveFadeOutStartTime	[i] = mCurrentTime;
					mSoundSymbol.mWaveOpacity			[i] = 0.0f;
					mSoundSymbol.mWaveActive			[i] = false;
				}
				
				//----------------------------------------------------------------------------------
				// This is where we calculate the expansion of the waves - that is, the
				// rate at which they are scaled greater than 1.0 so that they grow over time.
				//----------------------------------------------------------------------------------
				F32 timeSlice = (F32)( mCurrentTime - mPreviousTime );
				F32 waveSpeed = mSpeakingAmplitude * WAVE_MOTION_RATE;
				mSoundSymbol.mWaveExpansion[i] *= ( 1.0f + EXPANSION_RATE * timeSlice * waveSpeed );
				
				if ( mSoundSymbol.mWaveExpansion[i] > EXPANSION_MAX )
				{
					mSoundSymbol.mWaveExpansion[i] = 1.0f;
				}			
								
				//----------------------------------------------------------------------------------
				// create geometry for the wave billboard textures
				//----------------------------------------------------------------------------------
				F32 width	= i * WAVE_WIDTH_SCALE  * mSoundSymbol.mWaveExpansion[i];
				F32 height	= i * WAVE_HEIGHT_SCALE * mSoundSymbol.mWaveExpansion[i];

				LLVector3 l	= LLViewerCamera::getInstance()->getLeftAxis() * width;
				LLVector3 u	= LLViewerCamera::getInstance()->getUpAxis()   * height;

				LLVector3 bottomLeft	= mSoundSymbol.mPosition + l - u;
				LLVector3 bottomRight	= mSoundSymbol.mPosition - l - u;
				LLVector3 topLeft		= mSoundSymbol.mPosition + l + u;
				LLVector3 topRight		= mSoundSymbol.mPosition - l + u;
							
				gGL.color4fv( LLColor4( red, green, blue, mSoundSymbol.mWaveOpacity[i] ).mV );		
				gGL.getTexUnit(0)->bind(mSoundSymbol.mTexture[i]);

				
				//---------------------------------------------------
				// now, render the mofo
				//---------------------------------------------------
				gGL.begin( LLRender::TRIANGLE_STRIP );
					gGL.texCoord2i( 0, 0 ); gGL.vertex3fv( bottomLeft.mV );
					gGL.texCoord2i( 1, 0 ); gGL.vertex3fv( bottomRight.mV );
					gGL.texCoord2i( 0, 1 ); gGL.vertex3fv( topLeft.mV );
				gGL.end();

				gGL.begin( LLRender::TRIANGLE_STRIP );
					gGL.texCoord2i( 1, 0 ); gGL.vertex3fv( bottomRight.mV );
					gGL.texCoord2i( 1, 1 ); gGL.vertex3fv( topRight.mV );
					gGL.texCoord2i( 0, 1 ); gGL.vertex3fv( topLeft.mV );
				gGL.end();
				
			} //if ( mSoundSymbol.mWaveActive[i] ) 
			
		}// for loop
											
	}//if ( mSoundSymbol.mActive ) 

}//---------------------------------------------------





//---------------------------------------------------
void LLVoiceVisualizer::setVoiceSourceWorldPosition( const LLVector3 &p )
{
	mVoiceSourceWorldPosition	= p;

}//---------------------------------------------------

//---------------------------------------------------
VoiceGesticulationLevel LLVoiceVisualizer::getCurrentGesticulationLevel()
{
	VoiceGesticulationLevel gesticulationLevel = VOICE_GESTICULATION_LEVEL_OFF; //default
	
	//-----------------------------------------------------------------------------------------
	// Within the range of gesticulation amplitudes, the sound signal is split into
	// three equal amplitude regimes, each specifying one of three gesticulation levels.
	//-----------------------------------------------------------------------------------------
	F32 range = mMaxGesticulationAmplitude - mMinGesticulationAmplitude;
	
			if ( mSpeakingAmplitude > mMinGesticulationAmplitude + range * 0.5f	)	{ gesticulationLevel = VOICE_GESTICULATION_LEVEL_HIGH;		}
	else	if ( mSpeakingAmplitude > mMinGesticulationAmplitude + range * 0.25f	)	{ gesticulationLevel = VOICE_GESTICULATION_LEVEL_MEDIUM;	}
	else	if ( mSpeakingAmplitude > mMinGesticulationAmplitude + range * 0.00000f	)	{ gesticulationLevel = VOICE_GESTICULATION_LEVEL_LOW;		}

	return gesticulationLevel;

}//---------------------------------------------------



//------------------------------------
// Destructor
//------------------------------------
LLVoiceVisualizer::~LLVoiceVisualizer()
{
}//----------------------------------------------


//---------------------------------------------------
// "packData" is inherited from HUDEffect
//---------------------------------------------------
void LLVoiceVisualizer::packData(LLMessageSystem *mesgsys)
{
	// Pack the default data
	LLHUDEffect::packData(mesgsys);

	// TODO -- pack the relevant data for voice effects
	// we'll come up with some cool configurations....TBD
	//U8 packed_data[41];
	//mesgsys->addBinaryDataFast(_PREHASH_TypeData, packed_data, 41);
	U8 packed_data = 0;
	mesgsys->addBinaryDataFast(_PREHASH_TypeData, &packed_data, 1);
}


//---------------------------------------------------
// "unpackData" is inherited from HUDEffect
//---------------------------------------------------
void LLVoiceVisualizer::unpackData(LLMessageSystem *mesgsys, S32 blocknum)
{
	// TODO -- find the speaker, unpack binary data, set the properties of this effect
	/*
	LLHUDEffect::unpackData(mesgsys, blocknum);
	LLUUID source_id;
	LLUUID target_id;
	S32 size = mesgsys->getSizeFast(_PREHASH_Effect, blocknum, _PREHASH_TypeData);
	if (size != 1)
	{
		llwarns << "Voice effect with bad size " << size << llendl;
		return;
	}
	mesgsys->getBinaryDataFast(_PREHASH_Effect, _PREHASH_TypeData, packed_data, 1, blocknum);
	*/
}


//------------------------------------------------------------------
// this method is inherited from HUD Effect
//------------------------------------------------------------------
void LLVoiceVisualizer::markDead()
{
	mCurrentlySpeaking		= false;
	mVoiceEnabled			= false;
	mSoundSymbol.mActive	= false;

	LLHUDEffect::markDead();
}//------------------------------------------------------------------