aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llaudio/audioengine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llaudio/audioengine.cpp')
-rw-r--r--linden/indra/llaudio/audioengine.cpp198
1 files changed, 47 insertions, 151 deletions
diff --git a/linden/indra/llaudio/audioengine.cpp b/linden/indra/llaudio/audioengine.cpp
index 0a450e9..5fb38c0 100644
--- a/linden/indra/llaudio/audioengine.cpp
+++ b/linden/indra/llaudio/audioengine.cpp
@@ -51,6 +51,9 @@ extern void request_sound(const LLUUID &sound_guid);
51 51
52LLAudioEngine* gAudiop = NULL; 52LLAudioEngine* gAudiop = NULL;
53 53
54// Maximum amount of time we wait for a transfer to complete before starting
55// off another one.
56const F32 MAX_CURRENT_TRANSFER_TIME = 60.f;
54 57
55// 58//
56// LLAudioEngine implementation 59// LLAudioEngine implementation
@@ -74,8 +77,7 @@ void LLAudioEngine::setDefaults()
74 77
75 mListenerp = NULL; 78 mListenerp = NULL;
76 79
77 mMuted = false; 80 mMuted = FALSE;
78 mUserData = NULL;
79 81
80 mLastStatus = 0; 82 mLastStatus = 0;
81 83
@@ -96,17 +98,16 @@ void LLAudioEngine::setDefaults()
96 mInternetStreamGain = 0.125f; 98 mInternetStreamGain = 0.125f;
97 mNextWindUpdate = 0.f; 99 mNextWindUpdate = 0.f;
98 100
99 mInternetStreamMedia = NULL; 101 for (U32 i = 0; i < LLAudioEngine::AUDIO_TYPE_COUNT; i++)
100 mInternetStreamURL.clear(); 102 mSecondaryGain[i] = 1.0f;
101} 103}
102 104
103 105
104bool LLAudioEngine::init(const S32 num_channels, void* userdata) 106BOOL LLAudioEngine::init(const S32 num_channels)
105{ 107{
106 setDefaults(); 108 setDefaults();
107 109
108 mNumChannels = num_channels; 110 mNumChannels = num_channels;
109 mUserData = userdata;
110 111
111 allocateListener(); 112 allocateListener();
112 113
@@ -145,146 +146,22 @@ void LLAudioEngine::shutdown()
145 S32 i; 146 S32 i;
146 for (i = 0; i < MAX_CHANNELS; i++) 147 for (i = 0; i < MAX_CHANNELS; i++)
147 { 148 {
148 delete mChannels[i]; 149 if (mChannels[i])
149 mChannels[i] = NULL; 150 {
151 delete mChannels[i];
152 mChannels[i] = NULL;
153 }
150 } 154 }
151 155
152 // Clean up buffers 156 // Clean up buffers
153 for (i = 0; i < MAX_BUFFERS; i++) 157 for (i = 0; i < MAX_BUFFERS; i++)
154 { 158 {
155 delete mBuffers[i]; 159 if (mBuffers[i])
156 mBuffers[i] = NULL;
157 }
158
159 delete mInternetStreamMedia;
160 mInternetStreamMedia = NULL;
161 mInternetStreamURL.clear();
162}
163
164
165// virtual
166void LLAudioEngine::startInternetStream(const std::string& url)
167{
168 llinfos << "entered startInternetStream()" << llendl;
169
170 if (!mInternetStreamMedia)
171 {
172 LLMediaManager* mgr = LLMediaManager::getInstance();
173 if (mgr)
174 { 160 {
175 mInternetStreamMedia = mgr->createSourceFromMimeType(LLURI(url).scheme(), "audio/mpeg"); // assumes that whatever media implementation supports mp3 also supports vorbis. 161 delete mBuffers[i];
176 llinfos << "mInternetStreamMedia is now " << mInternetStreamMedia << llendl; 162 mBuffers[i] = NULL;
177 }
178 }
179
180 if(!mInternetStreamMedia)
181 return;
182
183 if (!url.empty()) {
184 llinfos << "Starting internet stream: " << url << llendl;
185 mInternetStreamURL = url;
186 mInternetStreamMedia->navigateTo ( url );
187 llinfos << "Playing....." << llendl;
188 mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_START);
189 mInternetStreamMedia->updateMedia();
190 } else {
191 llinfos << "setting stream to NULL"<< llendl;
192 mInternetStreamURL.clear();
193 mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_STOP);
194 mInternetStreamMedia->updateMedia();
195 }
196 //#endif
197}
198
199// virtual
200void LLAudioEngine::stopInternetStream()
201{
202 llinfos << "entered stopInternetStream()" << llendl;
203
204 if(mInternetStreamMedia)
205 {
206 if( ! mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_STOP)){
207 llinfos << "attempting to stop stream failed!" << llendl;
208 } 163 }
209 mInternetStreamMedia->updateMedia();
210 } 164 }
211
212 mInternetStreamURL.clear();
213}
214
215// virtual
216void LLAudioEngine::pauseInternetStream(int pause)
217{
218 llinfos << "entered pauseInternetStream()" << llendl;
219
220 if(!mInternetStreamMedia)
221 return;
222
223 if(pause)
224 {
225 if(! mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_PAUSE))
226 {
227 llinfos << "attempting to pause stream failed!" << llendl;
228 }
229 } else {
230 if(! mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_START))
231 {
232 llinfos << "attempting to unpause stream failed!" << llendl;
233 }
234 }
235 mInternetStreamMedia->updateMedia();
236}
237
238// virtual
239void LLAudioEngine::updateInternetStream()
240{
241 if (mInternetStreamMedia)
242 mInternetStreamMedia->updateMedia();
243}
244
245// virtual
246int LLAudioEngine::isInternetStreamPlaying()
247{
248 if (!mInternetStreamMedia)
249 return 0;
250
251 if (mInternetStreamMedia->getStatus() == LLMediaBase::STATUS_STARTED)
252 {
253 return 1; // Active and playing
254 }
255
256 if (mInternetStreamMedia->getStatus() == LLMediaBase::STATUS_PAUSED)
257 {
258 return 2; // paused
259 }
260
261 return 0; // Stopped
262}
263
264// virtual
265void LLAudioEngine::getInternetStreamInfo(char* artist, char* title)
266{
267 artist[0] = 0;
268 title[0] = 0;
269}
270
271// virtual
272void LLAudioEngine::setInternetStreamGain(F32 vol)
273{
274 mInternetStreamGain = vol;
275
276 if(!mInternetStreamMedia)
277 return;
278
279 vol = llclamp(vol, 0.f, 1.f);
280 mInternetStreamMedia->setVolume(vol);
281 mInternetStreamMedia->updateMedia();
282}
283
284// virtual
285const std::string& LLAudioEngine::getInternetStreamURL()
286{
287 return mInternetStreamURL;
288} 165}
289 166
290 167
@@ -295,6 +172,13 @@ void LLAudioEngine::updateChannels()
295 { 172 {
296 if (mChannels[i]) 173 if (mChannels[i])
297 { 174 {
175 // set secondary gain if type is available
176 LLAudioSource* source = mChannels[i]->getSource();
177 if (source)
178 {
179 mChannels[i]->setSecondaryGain(mSecondaryGain[source->getType()]);
180 }
181
298 mChannels[i]->updateBuffer(); 182 mChannels[i]->updateBuffer();
299 mChannels[i]->update3DPosition(); 183 mChannels[i]->update3DPosition();
300 mChannels[i]->updateLoop(); 184 mChannels[i]->updateLoop();
@@ -565,8 +449,6 @@ void LLAudioEngine::idle(F32 max_decode_time)
565 // missed picking it up in all the places that can add 449 // missed picking it up in all the places that can add
566 // or request new data. 450 // or request new data.
567 startNextTransfer(); 451 startNextTransfer();
568
569 updateInternetStream();
570} 452}
571 453
572 454
@@ -775,6 +657,18 @@ F32 LLAudioEngine::getMasterGain()
775 return mMasterGain; 657 return mMasterGain;
776} 658}
777 659
660void LLAudioEngine::setSecondaryGain(S32 type, F32 gain)
661{
662 llassert(type < LLAudioEngine::AUDIO_TYPE_COUNT);
663
664 mSecondaryGain[type] = gain;
665}
666
667F32 LLAudioEngine::getSecondaryGain(S32 type)
668{
669 return mSecondaryGain[type];
670}
671
778F32 LLAudioEngine::getInternetStreamGain() 672F32 LLAudioEngine::getInternetStreamGain()
779{ 673{
780 return mInternetStreamGain; 674 return mInternetStreamGain;
@@ -850,7 +744,8 @@ F64 LLAudioEngine::mapWindVecToPan(LLVector3 wind_vec)
850} 744}
851 745
852 746
853void LLAudioEngine::triggerSound(const LLUUID &audio_uuid, const LLUUID& owner_id, const F32 gain, const LLVector3d &pos_global) 747void LLAudioEngine::triggerSound(const LLUUID &audio_uuid, const LLUUID& owner_id, const F32 gain,
748 const S32 type, const LLVector3d &pos_global)
854{ 749{
855 // Create a new source (since this can't be associated with an existing source. 750 // Create a new source (since this can't be associated with an existing source.
856 //llinfos << "Localized: " << audio_uuid << llendl; 751 //llinfos << "Localized: " << audio_uuid << llendl;
@@ -1317,12 +1212,13 @@ LLAudioSource::LLAudioSource(const LLUUID& id, const LLUUID& owner_id, const F32
1317 mOwnerID(owner_id), 1212 mOwnerID(owner_id),
1318 mPriority(0.f), 1213 mPriority(0.f),
1319 mGain(gain), 1214 mGain(gain),
1320 mAmbient(false), 1215 mType(type),
1321 mLoop(false), 1216 mAmbient(FALSE),
1322 mSyncMaster(false), 1217 mLoop(FALSE),
1323 mSyncSlave(false), 1218 mSyncMaster(FALSE),
1324 mQueueSounds(false), 1219 mSyncSlave(FALSE),
1325 mPlayedOnce(false), 1220 mQueueSounds(FALSE),
1221 mPlayedOnce(FALSE),
1326 mChannelp(NULL), 1222 mChannelp(NULL),
1327 mCurrentDatap(NULL), 1223 mCurrentDatap(NULL),
1328 mQueuedDatap(NULL) 1224 mQueuedDatap(NULL)
@@ -1468,8 +1364,7 @@ bool LLAudioSource::play(const LLUUID &audio_uuid)
1468bool LLAudioSource::isDone() 1364bool LLAudioSource::isDone()
1469{ 1365{
1470 const F32 MAX_AGE = 60.f; 1366 const F32 MAX_AGE = 60.f;
1471 const F32 MAX_UNPLAYED_AGE = 15.f; 1367 const F32 MAX_UNPLAYED_AGE = 30.f;
1472
1473 if (isLoop()) 1368 if (isLoop())
1474 { 1369 {
1475 // Looped sources never die on their own. 1370 // Looped sources never die on their own.
@@ -1647,8 +1542,9 @@ LLAudioBuffer *LLAudioSource::getCurrentBuffer()
1647LLAudioChannel::LLAudioChannel() : 1542LLAudioChannel::LLAudioChannel() :
1648 mCurrentSourcep(NULL), 1543 mCurrentSourcep(NULL),
1649 mCurrentBufferp(NULL), 1544 mCurrentBufferp(NULL),
1650 mLoopedThisFrame(false), 1545 mLoopedThisFrame(FALSE),
1651 mWaiting(false) 1546 mWaiting(FALSE),
1547 mSecondaryGain(1.0f)
1652{ 1548{
1653} 1549}
1654 1550