00001 00032 #include "llviewerprecompiledheaders.h" 00033 00034 #include "audioengine.h" 00035 #include "llagent.h" 00036 #include "llappviewer.h" 00037 #include "llvieweraudio.h" 00038 #include "llviewercamera.h" 00039 #include "llviewercontrol.h" 00040 #include "llviewerwindow.h" 00041 #include "llvoiceclient.h" 00042 #include "llviewermedia.h" 00043 00045 00046 void init_audio() 00047 { 00048 if (!gAudiop) 00049 { 00050 llwarns << "Failed to create an appropriate Audio Engine" << llendl; 00051 return; 00052 } 00053 LLVector3d lpos_global = gAgent.getCameraPositionGlobal(); 00054 LLVector3 lpos_global_f; 00055 00056 lpos_global_f.setVec(lpos_global); 00057 00058 gAudiop->setListener(lpos_global_f, 00059 LLVector3::zero, // LLViewerCamera::getInstance()->getVelocity(), // !!! BUG need to replace this with smoothed velocity! 00060 LLViewerCamera::getInstance()->getUpAxis(), 00061 LLViewerCamera::getInstance()->getAtAxis()); 00062 00063 // load up our initial set of sounds we'll want so they're in memory and ready to be played 00064 00065 BOOL mute_audio = gSavedSettings.getBOOL("MuteAudio"); 00066 00067 if (!mute_audio && FALSE == gSavedSettings.getBOOL("NoPreload")) 00068 { 00069 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndAlert"))); 00070 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndBadKeystroke"))); 00071 //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndChatFromObject"))); 00072 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndClick"))); 00073 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndClickRelease"))); 00074 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndHealthReductionF"))); 00075 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndHealthReductionM"))); 00076 //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndIncomingChat"))); 00077 //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndIncomingIM"))); 00078 //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndInvApplyToObject"))); 00079 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndInvalidOp"))); 00080 //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndInventoryCopyToInv"))); 00081 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndMoneyChangeDown"))); 00082 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndMoneyChangeUp"))); 00083 //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndObjectCopyToInv"))); 00084 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndObjectCreate"))); 00085 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndObjectDelete"))); 00086 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndObjectRezIn"))); 00087 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndObjectRezOut"))); 00088 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuAppear"))); 00089 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuHide"))); 00090 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight0"))); 00091 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight1"))); 00092 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight2"))); 00093 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight3"))); 00094 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight4"))); 00095 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight5"))); 00096 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight6"))); 00097 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight7"))); 00098 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndSnapshot"))); 00099 //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndStartAutopilot"))); 00100 //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndStartFollowpilot"))); 00101 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndStartIM"))); 00102 //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndStopAutopilot"))); 00103 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndTeleportOut"))); 00104 //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndTextureApplyToObject"))); 00105 //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndTextureCopyToInv"))); 00106 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndTyping"))); 00107 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndWindowClose"))); 00108 gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndWindowOpen"))); 00109 } 00110 00111 audio_update_volume(true); 00112 } 00113 00114 void audio_update_volume(bool force_update) 00115 { 00116 F32 master_volume = gSavedSettings.getF32("AudioLevelMaster"); 00117 BOOL mute_audio = gSavedSettings.getBOOL("MuteAudio"); 00118 if (!gViewerWindow->getActive() && (gSavedSettings.getBOOL("MuteWhenMinimized"))) 00119 { 00120 mute_audio = TRUE; 00121 } 00122 F32 mute_volume = mute_audio ? 0.0f : 1.0f; 00123 00124 // Sound Effects 00125 if (gAudiop) 00126 { 00127 gAudiop->setMasterGain ( master_volume ); 00128 00129 gAudiop->setDopplerFactor(gSavedSettings.getF32("AudioLevelDoppler")); 00130 gAudiop->setDistanceFactor(gSavedSettings.getF32("AudioLevelDistance")); 00131 gAudiop->setRolloffFactor(gSavedSettings.getF32("AudioLevelRolloff")); 00132 #ifdef kAUDIO_ENABLE_WIND 00133 gAudiop->enableWind(!mute_audio); 00134 #endif 00135 00136 gAudiop->setMuted(mute_audio); 00137 00138 if (force_update) 00139 { 00140 audio_update_wind(true); 00141 } 00142 } 00143 00144 // Streaming Music 00145 if (gAudiop) 00146 { 00147 F32 music_volume = gSavedSettings.getF32("AudioLevelMusic"); 00148 BOOL music_muted = gSavedSettings.getBOOL("MuteMusic"); 00149 music_volume = mute_volume * master_volume * (music_volume*music_volume); 00150 gAudiop->setInternetStreamGain ( music_muted ? 0.f : music_volume ); 00151 00152 } 00153 00154 // Streaming Media 00155 F32 media_volume = gSavedSettings.getF32("AudioLevelMedia"); 00156 BOOL media_muted = gSavedSettings.getBOOL("MuteMedia"); 00157 media_volume = mute_volume * master_volume * (media_volume*media_volume); 00158 LLViewerMedia::setVolume( media_muted ? 0.0f : media_volume ); 00159 00160 // Voice 00161 if (gVoiceClient) 00162 { 00163 F32 voice_volume = gSavedSettings.getF32("AudioLevelVoice"); 00164 voice_volume = mute_volume * master_volume * voice_volume; 00165 BOOL voice_mute = gSavedSettings.getBOOL("MuteVoice"); 00166 gVoiceClient->setVoiceVolume(voice_mute ? 0.f : voice_volume); 00167 gVoiceClient->setMicGain(voice_mute ? 0.f : gSavedSettings.getF32("AudioLevelMic")); 00168 00169 if (!gViewerWindow->getActive() && (gSavedSettings.getBOOL("MuteWhenMinimized"))) 00170 { 00171 gVoiceClient->setMuteMic(true); 00172 } 00173 else 00174 { 00175 gVoiceClient->setMuteMic(false); 00176 } 00177 } 00178 } 00179 00180 void audio_update_listener() 00181 { 00182 if (gAudiop) 00183 { 00184 // update listener position because agent has moved 00185 LLVector3d lpos_global = gAgent.getCameraPositionGlobal(); 00186 LLVector3 lpos_global_f; 00187 lpos_global_f.setVec(lpos_global); 00188 00189 gAudiop->setListener(lpos_global_f, 00190 // LLViewerCamera::getInstance()VelocitySmoothed, 00191 // LLVector3::zero, 00192 gAgent.getVelocity(), // !!! *TODO: need to replace this with smoothed velocity! 00193 LLViewerCamera::getInstance()->getUpAxis(), 00194 LLViewerCamera::getInstance()->getAtAxis()); 00195 } 00196 } 00197 00198 void audio_update_wind(bool force_update) 00199 { 00200 #ifdef kAUDIO_ENABLE_WIND 00201 // 00202 // Extract height above water to modulate filter by whether above/below water 00203 // 00204 LLViewerRegion* region = gAgent.getRegion(); 00205 if (region) 00206 { 00207 static F32 last_camera_water_height = -1000.f; 00208 LLVector3 camera_pos = gAgent.getCameraPositionAgent(); 00209 F32 camera_water_height = camera_pos.mV[VZ] - region->getWaterHeight(); 00210 00211 // 00212 // Don't update rolloff factor unless water surface has been crossed 00213 // 00214 if (force_update || (last_camera_water_height * camera_water_height) < 0.f) 00215 { 00216 if (camera_water_height < 0.f) 00217 { 00218 gAudiop->setRolloffFactor(gSavedSettings.getF32("AudioLevelRolloff") * LL_ROLLOFF_MULTIPLIER_UNDER_WATER); 00219 } 00220 else 00221 { 00222 gAudiop->setRolloffFactor(gSavedSettings.getF32("AudioLevelRolloff")); 00223 } 00224 } 00225 // this line rotates the wind vector to be listener (agent) relative 00226 // unfortunately we have to pre-translate to undo the translation that 00227 // occurs in the transform call 00228 gRelativeWindVec = gAgent.getFrameAgent().rotateToLocal(gWindVec - gAgent.getVelocity()); 00229 00230 // don't use the setter setMaxWindGain() because we don't 00231 // want to screw up the fade-in on startup by setting actual source gain 00232 // outside the fade-in. 00233 F32 ambient_volume = gSavedSettings.getF32("AudioLevelAmbient"); 00234 gAudiop->mMaxWindGain = gSavedSettings.getBOOL("MuteAmbient") 00235 ? 0.f 00236 : ambient_volume * ambient_volume; 00237 00238 last_camera_water_height = camera_water_height; 00239 gAudiop->updateWind(gRelativeWindVec, camera_water_height); 00240 } 00241 #endif 00242 }