llvoicevisualizer.h

Go to the documentation of this file.
00001 
00032 //--------------------------------------------------------------------
00033 //
00034 // VOICE VISUALIZER
00035 // author: JJ Ventrella, Linden Lab
00036 // (latest update to this info: Jan 18, 2007)
00037 //
00038 // The Voice Visualizer is responsible for taking realtime signals from actual users speaking and 
00039 // visualizing this speech in two forms: 
00040 //
00041 // (1) as a dynamic sound symbol (also referred to as the "voice indicator" that appears over the avatar's head
00042 // (2) as gesticulation events that are used to trigger avatr gestures 
00043 //
00044 // The input for the voice visualizer is a continual stream of voice amplitudes. 
00045 
00046 //-----------------------------------------------------------------------------
00047 #ifndef LL_VOICE_VISUALIZER_H
00048 #define LL_VOICE_VISUALIZER_H
00049 
00050 #include "llhudeffect.h"
00051 
00052 //-----------------------------------------------------------------------------------------------
00053 // The values of voice gesticulation represent energy levels for avatar animation, based on 
00054 // amplitude surge events parsed from the voice signal. These are made available so that 
00055 // the appropriate kind of avatar animation can be triggered, and thereby simulate the physical
00056 // motion effects of speech. It is recommended that multiple body parts be animated as well as 
00057 // lips, such as head, shoulders, and hands, with large gestures used when the energy level is high.
00058 //-----------------------------------------------------------------------------------------------
00059 enum VoiceGesticulationLevel
00060 {
00061         VOICE_GESTICULATION_LEVEL_OFF = -1,
00062         VOICE_GESTICULATION_LEVEL_LOW = 0,
00063         VOICE_GESTICULATION_LEVEL_MEDIUM,
00064         VOICE_GESTICULATION_LEVEL_HIGH,
00065         NUM_VOICE_GESTICULATION_LEVELS
00066 };
00067 
00068 const static int NUM_VOICE_SYMBOL_WAVES = 7;
00069 
00070 //----------------------------------------------------
00071 // LLVoiceVisualizer class 
00072 //----------------------------------------------------
00073 class LLVoiceVisualizer : public LLHUDEffect
00074 {
00075         //---------------------------------------------------
00076         // public methods 
00077         //---------------------------------------------------
00078         public:
00079                 LLVoiceVisualizer ( const U8 type );    //constructor
00080                 ~LLVoiceVisualizer();                                   //destructor
00081                 
00082                 friend class LLHUDObject;
00083 
00084                 void                                    setVoiceSourceWorldPosition( const LLVector3 &p );              // this should be the position of the speaking avatar's head
00085                 void                                    setMinGesticulationAmplitude( F32 );                                    // the lower range of meaningful amplitude for setting gesticulation level 
00086                 void                                    setMaxGesticulationAmplitude( F32 );                                    // the upper range of meaningful amplitude for setting gesticulation level 
00087                 void                                    setStartSpeaking();                                                                             // tell me when the av starts speaking
00088                 void                                    setVoiceEnabled( bool );                                                                // tell me whether or not the user is voice enabled
00089                 void                                    setSpeakingAmplitude( F32 );                                                    // tell me how loud the av is speaking (ranges from 0 to 1)
00090                 void                                    setStopSpeaking();                                                                              // tell me when the av stops speaking
00091                 bool                                    getCurrentlySpeaking();                                                                 // the get for the above set
00092                 VoiceGesticulationLevel getCurrentGesticulationLevel();                                                 // based on voice amplitude, I'll give you the current "energy level" of avatar speech
00093 
00094                 void                                    render();                                                                                               // inherited from HUD Effect
00095                 void                                    packData(LLMessageSystem *mesgsys);                                             // inherited from HUD Effect
00096                 void                                    unpackData(LLMessageSystem *mesgsys, S32 blocknum);             // inherited from HUD Effect
00097                 void                                    markDead();                                                                                     // inherited from HUD Effect
00098                 
00099                 //----------------------------------------------------------------------------------------------
00100                 // "setMaxGesticulationAmplitude" and "setMinGesticulationAmplitude" allow for the tuning of the 
00101                 // gesticulation level detector to be responsive to different kinds of signals. For instance, we 
00102                 // may find that the average voice amplitude rarely exceeds 0.7 (in a range from 0 to 1), and 
00103                 // therefore we may want to set 0.7 as the max, so we can more easily catch all the variance 
00104                 // within that range. Also, we may find that there is often noise below a certain range like 0.1, 
00105                 // and so we would want to set 0.1 as the min so as not to accidentally use this as signal.
00106                 //----------------------------------------------------------------------------------------------
00107                 void setMaxGesticulationAmplitude(); 
00108                 void setMinGesticulationAmplitude(); 
00109 
00110         //---------------------------------------------------
00111         // private members 
00112         //---------------------------------------------------
00113         private:
00114         
00115                 struct SoundSymbol
00116                 {
00117                         F32                                             mWaveExpansion                  [ NUM_VOICE_SYMBOL_WAVES ];
00118                         bool                                    mWaveActive                             [ NUM_VOICE_SYMBOL_WAVES ];
00119                         F64                                             mWaveFadeOutStartTime   [ NUM_VOICE_SYMBOL_WAVES ];
00120                         F32                                             mWaveOpacity                    [ NUM_VOICE_SYMBOL_WAVES ];
00121                         LLPointer<LLImageGL>    mTexture                                [ NUM_VOICE_SYMBOL_WAVES ];
00122                         bool                                    mActive;
00123                         LLVector3                               mPosition;
00124                 };
00125 
00126                 LLFrameTimer                    mTimer;                                                 // so I can ask the current time in seconds
00127                 F64                                             mCurrentTime;                                   // current time in seconds, captured every step
00128                 F64                                             mPreviousTime;                                  // copy of "current time" from last frame
00129                 SoundSymbol                             mSoundSymbol;                                   // the sound symbol that appears over the avatar's head
00130                 bool                                    mVoiceEnabled;                                  // if off, no rendering should happen
00131                 bool                                    mCurrentlySpeaking;                             // is the user currently speaking?
00132                 LLVector3                               mVoiceSourceWorldPosition;              // give this to me every step - I need it to update the sound symbol
00133                 F32                                             mSpeakingAmplitude;                             // this should be set as often as possible when the user is speaking
00134                 F32                                             mMaxGesticulationAmplitude;             // this is the upper-limit of the envelope of detectable gesticulation leves
00135                 F32                                             mMinGesticulationAmplitude;             // this is the lower-limit of the envelope of detectable gesticulation leves
00136                 
00137 };//-----------------------------------------------------------------
00138  //   end of LLVoiceVisualizer class
00139 //------------------------------------------------------------------
00140 
00141 #endif //LL_VOICE_VISUALIZER_H
00142 

Generated on Thu Jul 1 06:09:38 2010 for Second Life Viewer by  doxygen 1.4.7