diff options
author | Jacek Antonelli | 2008-08-15 23:45:19 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:19 -0500 |
commit | b235c59d60472f818a9142c0886b95a0ff4191d7 (patch) | |
tree | d323c55587584b19cc43a03f58a178823f12d3cd /linden/indra/newview/llvieweraudio.cpp | |
parent | Second Life viewer sources 1.18.5.3 (diff) | |
download | meta-impy-b235c59d60472f818a9142c0886b95a0ff4191d7.zip meta-impy-b235c59d60472f818a9142c0886b95a0ff4191d7.tar.gz meta-impy-b235c59d60472f818a9142c0886b95a0ff4191d7.tar.bz2 meta-impy-b235c59d60472f818a9142c0886b95a0ff4191d7.tar.xz |
Second Life viewer sources 1.18.6.0-RC
Diffstat (limited to 'linden/indra/newview/llvieweraudio.cpp')
-rw-r--r-- | linden/indra/newview/llvieweraudio.cpp | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/linden/indra/newview/llvieweraudio.cpp b/linden/indra/newview/llvieweraudio.cpp new file mode 100644 index 0000000..fc11915 --- /dev/null +++ b/linden/indra/newview/llvieweraudio.cpp | |||
@@ -0,0 +1,228 @@ | |||
1 | /** | ||
2 | * @file llvieweraudio.cpp | ||
3 | * @brief Audio functions moved from viewer.cpp | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2000&license=internal$ | ||
6 | * | ||
7 | * Copyright (c) 2000-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * The following source code is PROPRIETARY AND CONFIDENTIAL. Use of | ||
10 | * this source code is governed by the Linden Lab Source Code Disclosure | ||
11 | * Agreement ("Agreement") previously entered between you and Linden | ||
12 | * Lab. By accessing, using, copying, modifying or distributing this | ||
13 | * software, you acknowledge that you have been informed of your | ||
14 | * obligations under the Agreement and agree to abide by those obligations. | ||
15 | * | ||
16 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
17 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
18 | * COMPLETENESS OR PERFORMANCE. | ||
19 | * $/LicenseInfo$ | ||
20 | */ | ||
21 | |||
22 | #include "llviewerprecompiledheaders.h" | ||
23 | |||
24 | #include "llvieweraudio.h" | ||
25 | #include "audioengine.h" | ||
26 | #include "llviewercontrol.h" | ||
27 | #include "llmediaengine.h" | ||
28 | #include "llagent.h" | ||
29 | #include "llappviewer.h" | ||
30 | #include "llvoiceclient.h" | ||
31 | #include "llviewerwindow.h" | ||
32 | #include "llviewercamera.h" | ||
33 | |||
34 | ///////////////////////////////////////////////////////// | ||
35 | |||
36 | void init_audio() | ||
37 | { | ||
38 | if (!gAudiop) | ||
39 | { | ||
40 | llwarns << "Failed to create an appropriate Audio Engine" << llendl; | ||
41 | return; | ||
42 | } | ||
43 | LLVector3d lpos_global = gAgent.getCameraPositionGlobal(); | ||
44 | LLVector3 lpos_global_f; | ||
45 | |||
46 | lpos_global_f.setVec(lpos_global); | ||
47 | |||
48 | gAudiop->setListener(lpos_global_f, | ||
49 | LLVector3::zero, // gCamera->getVelocity(), // !!! BUG need to replace this with smoothed velocity! | ||
50 | gCamera->getUpAxis(), | ||
51 | gCamera->getAtAxis()); | ||
52 | |||
53 | // load up our initial set of sounds we'll want so they're in memory and ready to be played | ||
54 | |||
55 | BOOL mute_audio = gSavedSettings.getBOOL("MuteAudio"); | ||
56 | |||
57 | if (!mute_audio && gPreloadSounds) | ||
58 | { | ||
59 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndAlert"))); | ||
60 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndBadKeystroke"))); | ||
61 | //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndChatFromObject"))); | ||
62 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndClick"))); | ||
63 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndClickRelease"))); | ||
64 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndHealthReductionF"))); | ||
65 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndHealthReductionM"))); | ||
66 | //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndIncomingChat"))); | ||
67 | //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndIncomingIM"))); | ||
68 | //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndInvApplyToObject"))); | ||
69 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndInvalidOp"))); | ||
70 | //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndInventoryCopyToInv"))); | ||
71 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndMoneyChangeDown"))); | ||
72 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndMoneyChangeUp"))); | ||
73 | //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndObjectCopyToInv"))); | ||
74 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndObjectCreate"))); | ||
75 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndObjectDelete"))); | ||
76 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndObjectRezIn"))); | ||
77 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndObjectRezOut"))); | ||
78 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuAppear"))); | ||
79 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuHide"))); | ||
80 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight0"))); | ||
81 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight1"))); | ||
82 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight2"))); | ||
83 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight3"))); | ||
84 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight4"))); | ||
85 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight5"))); | ||
86 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight6"))); | ||
87 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndPieMenuSliceHighlight7"))); | ||
88 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndSnapshot"))); | ||
89 | //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndStartAutopilot"))); | ||
90 | //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndStartFollowpilot"))); | ||
91 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndStartIM"))); | ||
92 | //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndStopAutopilot"))); | ||
93 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndTeleportOut"))); | ||
94 | //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndTextureApplyToObject"))); | ||
95 | //gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndTextureCopyToInv"))); | ||
96 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndTyping"))); | ||
97 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndWindowClose"))); | ||
98 | gAudiop->preloadSound(LLUUID(gSavedSettings.getString("UISndWindowOpen"))); | ||
99 | } | ||
100 | |||
101 | audio_update_volume(true); | ||
102 | } | ||
103 | |||
104 | void audio_update_volume(bool force_update) | ||
105 | { | ||
106 | F32 master_volume = gSavedSettings.getF32("AudioLevelMaster"); | ||
107 | BOOL mute_audio = gSavedSettings.getBOOL("MuteAudio"); | ||
108 | if (!gViewerWindow->getActive() && (gSavedSettings.getBOOL("MuteWhenMinimized"))) | ||
109 | { | ||
110 | mute_audio = TRUE; | ||
111 | } | ||
112 | F32 mute_volume = mute_audio ? 0.0f : 1.0f; | ||
113 | |||
114 | // Sound Effects | ||
115 | if (gAudiop) | ||
116 | { | ||
117 | gAudiop->setMasterGain ( master_volume ); | ||
118 | |||
119 | gAudiop->setDopplerFactor(gSavedSettings.getF32("AudioLevelDoppler")); | ||
120 | gAudiop->setDistanceFactor(gSavedSettings.getF32("AudioLevelDistance")); | ||
121 | gAudiop->setRolloffFactor(gSavedSettings.getF32("AudioLevelRolloff")); | ||
122 | #ifdef kAUDIO_ENABLE_WIND | ||
123 | gAudiop->enableWind(!mute_audio); | ||
124 | #endif | ||
125 | |||
126 | gAudiop->setMuted(mute_audio); | ||
127 | |||
128 | if (force_update) | ||
129 | { | ||
130 | audio_update_wind(true); | ||
131 | } | ||
132 | } | ||
133 | |||
134 | // Streaming Music | ||
135 | if (gAudiop) | ||
136 | { | ||
137 | F32 music_volume = gSavedSettings.getF32("AudioLevelMusic"); | ||
138 | music_volume = mute_volume * master_volume * (music_volume*music_volume); | ||
139 | gAudiop->setInternetStreamGain ( music_volume ); | ||
140 | } | ||
141 | |||
142 | // Streaming Media | ||
143 | if(LLMediaEngine::getInstance()) | ||
144 | { | ||
145 | F32 media_volume = gSavedSettings.getF32("AudioLevelMedia"); | ||
146 | media_volume = mute_volume * master_volume * (media_volume*media_volume); | ||
147 | LLMediaEngine::getInstance()->setVolume(media_volume); | ||
148 | } | ||
149 | |||
150 | // Voice | ||
151 | if (gVoiceClient) | ||
152 | { | ||
153 | F32 voice_volume = gSavedSettings.getF32("AudioLevelVoice"); | ||
154 | voice_volume = mute_volume * master_volume * voice_volume; | ||
155 | gVoiceClient->setVoiceVolume(voice_volume); | ||
156 | gVoiceClient->setMicGain(gSavedSettings.getF32("AudioLevelMic")); | ||
157 | |||
158 | if (!gViewerWindow->getActive() && (gSavedSettings.getBOOL("MuteWhenMinimized"))) | ||
159 | { | ||
160 | gVoiceClient->setMuteMic(true); | ||
161 | } | ||
162 | else | ||
163 | { | ||
164 | gVoiceClient->setMuteMic(false); | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | |||
169 | void audio_update_listener() | ||
170 | { | ||
171 | if (gAudiop) | ||
172 | { | ||
173 | // update listener position because agent has moved | ||
174 | LLVector3d lpos_global = gAgent.getCameraPositionGlobal(); | ||
175 | LLVector3 lpos_global_f; | ||
176 | lpos_global_f.setVec(lpos_global); | ||
177 | |||
178 | gAudiop->setListener(lpos_global_f, | ||
179 | // gCameraVelocitySmoothed, | ||
180 | // LLVector3::zero, | ||
181 | gAgent.getVelocity(), // !!! *TODO: need to replace this with smoothed velocity! | ||
182 | gCamera->getUpAxis(), | ||
183 | gCamera->getAtAxis()); | ||
184 | } | ||
185 | } | ||
186 | |||
187 | void audio_update_wind(bool force_update) | ||
188 | { | ||
189 | #ifdef kAUDIO_ENABLE_WIND | ||
190 | // | ||
191 | // Extract height above water to modulate filter by whether above/below water | ||
192 | // | ||
193 | LLViewerRegion* region = gAgent.getRegion(); | ||
194 | if (region) | ||
195 | { | ||
196 | static F32 last_camera_water_height = -1000.f; | ||
197 | LLVector3 camera_pos = gAgent.getCameraPositionAgent(); | ||
198 | F32 camera_water_height = camera_pos.mV[VZ] - region->getWaterHeight(); | ||
199 | |||
200 | // | ||
201 | // Don't update rolloff factor unless water surface has been crossed | ||
202 | // | ||
203 | if (force_update || (last_camera_water_height * camera_water_height) < 0.f) | ||
204 | { | ||
205 | if (camera_water_height < 0.f) | ||
206 | { | ||
207 | gAudiop->setRolloffFactor(gSavedSettings.getF32("AudioLevelRolloff") * LL_ROLLOFF_MULTIPLIER_UNDER_WATER); | ||
208 | } | ||
209 | else | ||
210 | { | ||
211 | gAudiop->setRolloffFactor(gSavedSettings.getF32("AudioLevelRolloff")); | ||
212 | } | ||
213 | } | ||
214 | // this line rotates the wind vector to be listener (agent) relative | ||
215 | // unfortunately we have to pre-translate to undo the translation that | ||
216 | // occurs in the transform call | ||
217 | gRelativeWindVec = gAgent.getFrameAgent().rotateToLocal(gWindVec - gAgent.getVelocity()); | ||
218 | |||
219 | // don't use the setter setMaxWindGain() because we don't | ||
220 | // want to screw up the fade-in on startup by setting actual source gain | ||
221 | // outside the fade-in. | ||
222 | gAudiop->mMaxWindGain = gSavedSettings.getF32("AudioLevelAmbient"); | ||
223 | |||
224 | last_camera_water_height = camera_water_height; | ||
225 | gAudiop->updateWind(gRelativeWindVec, camera_water_height); | ||
226 | } | ||
227 | #endif | ||
228 | } | ||