diff options
author | Jacek Antonelli | 2008-08-15 23:45:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:50 -0500 |
commit | 2a4dea528f670b9bb1f77ef27a8a1dd16603d114 (patch) | |
tree | 95c68e362703c9099d571ecbdc6142b1cda1e005 /linden/indra/newview/llvoicevisualizer.cpp | |
parent | Second Life viewer sources 1.20.6 (diff) | |
download | meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.zip meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.gz meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.bz2 meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.xz |
Second Life viewer sources 1.20.7
Diffstat (limited to 'linden/indra/newview/llvoicevisualizer.cpp')
-rw-r--r-- | linden/indra/newview/llvoicevisualizer.cpp | 177 |
1 files changed, 174 insertions, 3 deletions
diff --git a/linden/indra/newview/llvoicevisualizer.cpp b/linden/indra/newview/llvoicevisualizer.cpp index 6b2a3e6..ba16feb 100644 --- a/linden/indra/newview/llvoicevisualizer.cpp +++ b/linden/indra/newview/llvoicevisualizer.cpp | |||
@@ -45,7 +45,7 @@ | |||
45 | #include "llviewerimage.h" | 45 | #include "llviewerimage.h" |
46 | #include "llviewerimagelist.h" | 46 | #include "llviewerimagelist.h" |
47 | #include "llvoiceclient.h" | 47 | #include "llvoiceclient.h" |
48 | #include "llglimmediate.h" | 48 | #include "llrender.h" |
49 | 49 | ||
50 | //brent's wave image | 50 | //brent's wave image |
51 | //29de489d-0491-fb00-7dab-f9e686d31e83 | 51 | //29de489d-0491-fb00-7dab-f9e686d31e83 |
@@ -79,6 +79,35 @@ const F32 DEFAULT_MAXIMUM_GESTICULATION_AMPLITUDE = 1.0f; | |||
79 | const F32 ONE_HALF = 1.0f; // to clarify intent and reduce magic numbers in the code. | 79 | const F32 ONE_HALF = 1.0f; // to clarify intent and reduce magic numbers in the code. |
80 | const LLVector3 WORLD_UPWARD_DIRECTION = LLVector3( 0.0f, 0.0f, 1.0f ); // Z is up in SL | 80 | const LLVector3 WORLD_UPWARD_DIRECTION = LLVector3( 0.0f, 0.0f, 1.0f ); // Z is up in SL |
81 | 81 | ||
82 | |||
83 | //------------------------------------------------------------------ | ||
84 | // handles parameter updates | ||
85 | //------------------------------------------------------------------ | ||
86 | static bool handleVoiceVisualizerPrefsChanged(const LLSD& newvalue) | ||
87 | { | ||
88 | // Note: Ignore the specific event value, we look up the ones we want | ||
89 | LLVoiceVisualizer::setPreferences(); | ||
90 | return true; | ||
91 | } | ||
92 | |||
93 | //------------------------------------------------------------------ | ||
94 | // Initialize the statics | ||
95 | //------------------------------------------------------------------ | ||
96 | bool LLVoiceVisualizer::sPrefsInitialized = false; | ||
97 | BOOL LLVoiceVisualizer::sLipSyncEnabled = FALSE; | ||
98 | F32* LLVoiceVisualizer::sOoh = NULL; | ||
99 | F32* LLVoiceVisualizer::sAah = NULL; | ||
100 | U32 LLVoiceVisualizer::sOohs = 0; | ||
101 | U32 LLVoiceVisualizer::sAahs = 0; | ||
102 | F32 LLVoiceVisualizer::sOohAahRate = 0.0f; | ||
103 | F32* LLVoiceVisualizer::sOohPowerTransfer = NULL; | ||
104 | U32 LLVoiceVisualizer::sOohPowerTransfers = 0; | ||
105 | F32 LLVoiceVisualizer::sOohPowerTransfersf = 0.0f; | ||
106 | F32* LLVoiceVisualizer::sAahPowerTransfer = NULL; | ||
107 | U32 LLVoiceVisualizer::sAahPowerTransfers = 0; | ||
108 | F32 LLVoiceVisualizer::sAahPowerTransfersf = 0.0f; | ||
109 | |||
110 | |||
82 | //----------------------------------------------- | 111 | //----------------------------------------------- |
83 | // constructor | 112 | // constructor |
84 | //----------------------------------------------- | 113 | //----------------------------------------------- |
@@ -87,6 +116,7 @@ LLVoiceVisualizer::LLVoiceVisualizer( const U8 type ) | |||
87 | { | 116 | { |
88 | mCurrentTime = mTimer.getTotalSeconds(); | 117 | mCurrentTime = mTimer.getTotalSeconds(); |
89 | mPreviousTime = mCurrentTime; | 118 | mPreviousTime = mCurrentTime; |
119 | mStartTime = mCurrentTime; | ||
90 | mVoiceSourceWorldPosition = LLVector3( 0.0f, 0.0f, 0.0f ); | 120 | mVoiceSourceWorldPosition = LLVector3( 0.0f, 0.0f, 0.0f ); |
91 | mSpeakingAmplitude = 0.0f; | 121 | mSpeakingAmplitude = 0.0f; |
92 | mCurrentlySpeaking = false; | 122 | mCurrentlySpeaking = false; |
@@ -105,7 +135,7 @@ LLVoiceVisualizer::LLVoiceVisualizer( const U8 type ) | |||
105 | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", | 135 | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", |
106 | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", | 136 | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", |
107 | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", | 137 | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", |
108 | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", | 138 | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c", |
109 | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c" | 139 | "29de489d-0491-fb00-7dab-f9e686d31e83.j2c" |
110 | }; | 140 | }; |
111 | 141 | ||
@@ -117,7 +147,23 @@ LLVoiceVisualizer::LLVoiceVisualizer( const U8 type ) | |||
117 | mSoundSymbol.mWaveOpacity [i] = 1.0f; | 147 | mSoundSymbol.mWaveOpacity [i] = 1.0f; |
118 | mSoundSymbol.mWaveExpansion [i] = 1.0f; | 148 | mSoundSymbol.mWaveExpansion [i] = 1.0f; |
119 | } | 149 | } |
120 | 150 | ||
151 | // The first instance loads the initial state from prefs. | ||
152 | if (!sPrefsInitialized) | ||
153 | { | ||
154 | setPreferences(); | ||
155 | |||
156 | // Set up our listener to get updates on all prefs values we care about. | ||
157 | gSavedSettings.getControl("LipSyncEnabled")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _1)); | ||
158 | gSavedSettings.getControl("LipSyncOohAahRate")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _1)); | ||
159 | gSavedSettings.getControl("LipSyncOoh")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _1)); | ||
160 | gSavedSettings.getControl("LipSyncAah")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _1)); | ||
161 | gSavedSettings.getControl("LipSyncOohPowerTransfer")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _1)); | ||
162 | gSavedSettings.getControl("LipSyncAahPowerTransfer")->getSignal()->connect(boost::bind(&handleVoiceVisualizerPrefsChanged, _1)); | ||
163 | |||
164 | sPrefsInitialized = true; | ||
165 | } | ||
166 | |||
121 | }//--------------------------------------------------- | 167 | }//--------------------------------------------------- |
122 | 168 | ||
123 | //--------------------------------------------------- | 169 | //--------------------------------------------------- |
@@ -144,6 +190,7 @@ void LLVoiceVisualizer::setVoiceEnabled( bool v ) | |||
144 | //--------------------------------------------------- | 190 | //--------------------------------------------------- |
145 | void LLVoiceVisualizer::setStartSpeaking() | 191 | void LLVoiceVisualizer::setStartSpeaking() |
146 | { | 192 | { |
193 | mStartTime = mTimer.getTotalSeconds(); | ||
147 | mCurrentlySpeaking = true; | 194 | mCurrentlySpeaking = true; |
148 | mSoundSymbol.mActive = true; | 195 | mSoundSymbol.mActive = true; |
149 | 196 | ||
@@ -176,6 +223,130 @@ void LLVoiceVisualizer::setSpeakingAmplitude( F32 a ) | |||
176 | 223 | ||
177 | 224 | ||
178 | //--------------------------------------------------- | 225 | //--------------------------------------------------- |
226 | void LLVoiceVisualizer::setPreferences( ) | ||
227 | { | ||
228 | sLipSyncEnabled = gSavedSettings.getBOOL("LipSyncEnabled"); | ||
229 | sOohAahRate = gSavedSettings.getF32("LipSyncOohAahRate"); | ||
230 | |||
231 | std::string oohString = gSavedSettings.getString("LipSyncOoh"); | ||
232 | lipStringToF32s (oohString, sOoh, sOohs); | ||
233 | |||
234 | std::string aahString = gSavedSettings.getString("LipSyncAah"); | ||
235 | lipStringToF32s (aahString, sAah, sAahs); | ||
236 | |||
237 | std::string oohPowerString = gSavedSettings.getString("LipSyncOohPowerTransfer"); | ||
238 | lipStringToF32s (oohPowerString, sOohPowerTransfer, sOohPowerTransfers); | ||
239 | sOohPowerTransfersf = (F32) sOohPowerTransfers; | ||
240 | |||
241 | std::string aahPowerString = gSavedSettings.getString("LipSyncAahPowerTransfer"); | ||
242 | lipStringToF32s (aahPowerString, sAahPowerTransfer, sAahPowerTransfers); | ||
243 | sAahPowerTransfersf = (F32) sAahPowerTransfers; | ||
244 | |||
245 | }//--------------------------------------------------- | ||
246 | |||
247 | |||
248 | //--------------------------------------------------- | ||
249 | // convert a string of digits to an array of floats. | ||
250 | // the result for each digit is the value of the | ||
251 | // digit multiplied by 0.11 | ||
252 | //--------------------------------------------------- | ||
253 | void LLVoiceVisualizer::lipStringToF32s ( std::string& in_string, F32*& out_F32s, U32& count_F32s ) | ||
254 | { | ||
255 | delete[] out_F32s; // get rid of the current array | ||
256 | |||
257 | count_F32s = in_string.length(); | ||
258 | if (count_F32s == 0) | ||
259 | { | ||
260 | // we don't like zero length arrays | ||
261 | |||
262 | count_F32s = 1; | ||
263 | out_F32s = new F32[1]; | ||
264 | out_F32s[0] = 0.0f; | ||
265 | } | ||
266 | else | ||
267 | { | ||
268 | out_F32s = new F32[count_F32s]; | ||
269 | |||
270 | for (U32 i=0; i<count_F32s; i++) | ||
271 | { | ||
272 | // we convert the characters 0 to 9 to their numeric value | ||
273 | // anything else we take the low order four bits with a ceiling of 9 | ||
274 | |||
275 | U8 digit = in_string[i]; | ||
276 | U8 four_bits = digit % 16; | ||
277 | if (four_bits > 9) | ||
278 | { | ||
279 | four_bits = 9; | ||
280 | } | ||
281 | out_F32s[i] = 0.11f * (F32) four_bits; | ||
282 | } | ||
283 | } | ||
284 | |||
285 | }//--------------------------------------------------- | ||
286 | |||
287 | |||
288 | //-------------------------------------------------------------------------- | ||
289 | // find the amount to blend the ooh and aah mouth morphs | ||
290 | //-------------------------------------------------------------------------- | ||
291 | void LLVoiceVisualizer::lipSyncOohAah( F32& ooh, F32& aah ) | ||
292 | { | ||
293 | if( ( sLipSyncEnabled == TRUE ) && mCurrentlySpeaking ) | ||
294 | { | ||
295 | U32 transfer_index = (U32) (sOohPowerTransfersf * mSpeakingAmplitude); | ||
296 | if (transfer_index < 0) | ||
297 | { | ||
298 | transfer_index = 0; | ||
299 | } | ||
300 | if (transfer_index >= sOohPowerTransfers) | ||
301 | { | ||
302 | transfer_index = sOohPowerTransfers - 1; | ||
303 | } | ||
304 | F32 transfer_ooh = sOohPowerTransfer[transfer_index]; | ||
305 | |||
306 | transfer_index = (U32) (sAahPowerTransfersf * mSpeakingAmplitude); | ||
307 | if (transfer_index < 0) | ||
308 | { | ||
309 | transfer_index = 0; | ||
310 | } | ||
311 | if (transfer_index >= sAahPowerTransfers) | ||
312 | { | ||
313 | transfer_index = sAahPowerTransfers - 1; | ||
314 | } | ||
315 | F32 transfer_aah = sAahPowerTransfer[transfer_index]; | ||
316 | |||
317 | F64 current_time = mTimer.getTotalSeconds(); | ||
318 | F64 elapsed_time = current_time - mStartTime; | ||
319 | U32 elapsed_frames = (U32) (elapsed_time * sOohAahRate); | ||
320 | U32 elapsed_oohs = elapsed_frames % sOohs; | ||
321 | U32 elapsed_aahs = elapsed_frames % sAahs; | ||
322 | |||
323 | ooh = transfer_ooh * sOoh[elapsed_oohs]; | ||
324 | aah = transfer_aah * sAah[elapsed_aahs]; | ||
325 | |||
326 | /* | ||
327 | llinfos << " elapsed frames " << elapsed_frames | ||
328 | << " ooh " << ooh | ||
329 | << " aah " << aah | ||
330 | << " transfer ooh" << transfer_ooh | ||
331 | << " transfer aah" << transfer_aah | ||
332 | << " start time " << mStartTime | ||
333 | << " current time " << current_time | ||
334 | << " elapsed time " << elapsed_time | ||
335 | << " elapsed oohs " << elapsed_oohs | ||
336 | << " elapsed aahs " << elapsed_aahs | ||
337 | << llendl; | ||
338 | */ | ||
339 | } | ||
340 | else | ||
341 | { | ||
342 | ooh = 0.0f; | ||
343 | aah = 0.0f; | ||
344 | } | ||
345 | |||
346 | }//--------------------------------------------------- | ||
347 | |||
348 | |||
349 | //--------------------------------------------------- | ||
179 | // this method is inherited from HUD Effect | 350 | // this method is inherited from HUD Effect |
180 | //--------------------------------------------------- | 351 | //--------------------------------------------------- |
181 | void LLVoiceVisualizer::render() | 352 | void LLVoiceVisualizer::render() |