PageRenderTime 43ms CodeModel.GetById 12ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 1ms

/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
  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//
 29// VOICE VISUALIZER
 30// author: JJ Ventrella, Linden Lab
 31// (latest update to this info: Jan 18, 2007)
 32//
 33// The Voice Visualizer is responsible for taking realtime signals from actual users speaking and 
 34// visualizing this speech in two forms: 
 35//
 36// (1) as a dynamic sound symbol (also referred to as the "voice indicator" that appears over the avatar's head
 37// (2) as gesticulation events that are used to trigger avatr gestures 
 38//
 39// The input for the voice visualizer is a continual stream of voice amplitudes. 
 40
 41//-----------------------------------------------------------------------------
 42#ifndef LL_VOICE_VISUALIZER_H
 43#define LL_VOICE_VISUALIZER_H
 44
 45#include "llhudeffect.h"
 46
 47//-----------------------------------------------------------------------------------------------
 48// The values of voice gesticulation represent energy levels for avatar animation, based on 
 49// amplitude surge events parsed from the voice signal. These are made available so that 
 50// the appropriate kind of avatar animation can be triggered, and thereby simulate the physical
 51// motion effects of speech. It is recommended that multiple body parts be animated as well as 
 52// lips, such as head, shoulders, and hands, with large gestures used when the energy level is high.
 53//-----------------------------------------------------------------------------------------------
 54enum VoiceGesticulationLevel
 55{
 56	VOICE_GESTICULATION_LEVEL_OFF = -1,
 57	VOICE_GESTICULATION_LEVEL_LOW = 0,
 58	VOICE_GESTICULATION_LEVEL_MEDIUM,
 59	VOICE_GESTICULATION_LEVEL_HIGH,
 60	NUM_VOICE_GESTICULATION_LEVELS
 61};
 62
 63const static int NUM_VOICE_SYMBOL_WAVES = 7;
 64
 65//----------------------------------------------------
 66// LLVoiceVisualizer class 
 67//----------------------------------------------------
 68class LLVoiceVisualizer : public LLHUDEffect
 69{
 70	//---------------------------------------------------
 71	// public methods 
 72	//---------------------------------------------------
 73	public:
 74		LLVoiceVisualizer ( const U8 type );	//constructor
 75		~LLVoiceVisualizer();					//destructor
 76		
 77		friend class LLHUDObject;
 78
 79		void					setVoiceSourceWorldPosition( const LLVector3 &p );		// this should be the position of the speaking avatar's head
 80		void					setMinGesticulationAmplitude( F32 );					// the lower range of meaningful amplitude for setting gesticulation level 
 81		void					setMaxGesticulationAmplitude( F32 );					// the upper range of meaningful amplitude for setting gesticulation level 
 82		void					setStartSpeaking();										// tell me when the av starts speaking
 83		void					setVoiceEnabled( bool );								// tell me whether or not the user is voice enabled
 84		void					setSpeakingAmplitude( F32 );							// tell me how loud the av is speaking (ranges from 0 to 1)
 85		void					setStopSpeaking();										// tell me when the av stops speaking
 86		bool					getCurrentlySpeaking();									// the get for the above set
 87		VoiceGesticulationLevel	getCurrentGesticulationLevel();							// based on voice amplitude, I'll give you the current "energy level" of avatar speech
 88		static void				setPreferences( );
 89		static void				lipStringToF32s ( std::string& in_string, F32*& out_F32s, U32& count_F32s ); // convert a string of digits to an array of floats
 90		void					lipSyncOohAah( F32& ooh, F32& aah );
 91		void					render();												// inherited from HUD Effect
 92		void 					packData(LLMessageSystem *mesgsys);						// inherited from HUD Effect
 93		void 					unpackData(LLMessageSystem *mesgsys, S32 blocknum);		// inherited from HUD Effect
 94		void					markDead();											// inherited from HUD Effect
 95		
 96		//----------------------------------------------------------------------------------------------
 97		// "setMaxGesticulationAmplitude" and "setMinGesticulationAmplitude" allow for the tuning of the 
 98		// gesticulation level detector to be responsive to different kinds of signals. For instance, we 
 99		// may find that the average voice amplitude rarely exceeds 0.7 (in a range from 0 to 1), and 
100		// therefore we may want to set 0.7 as the max, so we can more easily catch all the variance 
101		// within that range. Also, we may find that there is often noise below a certain range like 0.1, 
102		// and so we would want to set 0.1 as the min so as not to accidentally use this as signal.
103		//----------------------------------------------------------------------------------------------
104		void setMaxGesticulationAmplitude(); 
105		void setMinGesticulationAmplitude(); 
106
107	//---------------------------------------------------
108	// private members 
109	//---------------------------------------------------
110	private:
111	
112		struct SoundSymbol
113		{
114			F32						mWaveExpansion			[ NUM_VOICE_SYMBOL_WAVES ];
115			bool					mWaveActive				[ NUM_VOICE_SYMBOL_WAVES ];
116			F64						mWaveFadeOutStartTime	[ NUM_VOICE_SYMBOL_WAVES ];
117			F32						mWaveOpacity			[ NUM_VOICE_SYMBOL_WAVES ];
118			LLPointer<LLViewerFetchedTexture>	mTexture				[ NUM_VOICE_SYMBOL_WAVES ];
119			bool					mActive;
120			LLVector3				mPosition;
121		};
122
123		LLFrameTimer			mTimer;							// so I can ask the current time in seconds
124		F64						mStartTime;						// time in seconds when speaking started
125		F64						mCurrentTime;					// current time in seconds, captured every step
126		F64						mPreviousTime;					// copy of "current time" from last frame
127		SoundSymbol				mSoundSymbol;					// the sound symbol that appears over the avatar's head
128		bool					mVoiceEnabled;					// if off, no rendering should happen
129		bool					mCurrentlySpeaking;				// is the user currently speaking?
130		LLVector3				mVoiceSourceWorldPosition;		// give this to me every step - I need it to update the sound symbol
131		F32						mSpeakingAmplitude;				// this should be set as often as possible when the user is speaking
132		F32						mMaxGesticulationAmplitude;		// this is the upper-limit of the envelope of detectable gesticulation leves
133		F32						mMinGesticulationAmplitude;		// this is the lower-limit of the envelope of detectable gesticulation leves
134		
135	//---------------------------------------------------
136	// private static members 
137	//---------------------------------------------------
138
139		static BOOL	  sLipSyncEnabled;		 // 0 disabled, 1 babble loop
140		static bool	  sPrefsInitialized;	 // the first instance will initialize the static members
141		static F32*	  sOoh;					 // the babble loop of amplitudes for the ooh morph
142		static F32*	  sAah;					 // the babble loop of amplitudes for the ooh morph
143		static U32	  sOohs;				 // the number of entries in the ooh loop
144		static U32	  sAahs;				 // the number of entries in the aah loop
145		static F32	  sOohAahRate;			 // frames per second for the babble loop
146		static F32*	  sOohPowerTransfer;	 // the power transfer characteristics for the ooh amplitude
147		static U32	  sOohPowerTransfers;	 // the number of entries in the ooh transfer characteristics
148		static F32	  sOohPowerTransfersf;	 // the number of entries in the ooh transfer characteristics as a float
149		static F32*	  sAahPowerTransfer;	 // the power transfer characteristics for the aah amplitude
150		static U32	  sAahPowerTransfers;	 // the number of entries in the aah transfer characteristics
151		static F32	  sAahPowerTransfersf;	 // the number of entries in the aah transfer characteristics as a float
152
153};//-----------------------------------------------------------------
154 //   end of LLVoiceVisualizer class
155//------------------------------------------------------------------
156
157#endif //LL_VOICE_VISUALIZER_H
158