aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llaudio/audioengine.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-12-06 14:03:10 -0600
committerJacek Antonelli2008-12-06 14:03:10 -0600
commitb29b13ad98c5c79fd63bae10b4b099a03fa9dc35 (patch)
treeffc14fd638344c84287d1c4a72d2de5f765bf3c8 /linden/indra/llaudio/audioengine.cpp
parentopenal on windows branch (diff)
downloadmeta-impy-b29b13ad98c5c79fd63bae10b4b099a03fa9dc35.zip
meta-impy-b29b13ad98c5c79fd63bae10b4b099a03fa9dc35.tar.gz
meta-impy-b29b13ad98c5c79fd63bae10b4b099a03fa9dc35.tar.bz2
meta-impy-b29b13ad98c5c79fd63bae10b4b099a03fa9dc35.tar.xz
Updated audio engine to LL's openal branch r1532.
Diffstat (limited to 'linden/indra/llaudio/audioengine.cpp')
-rw-r--r--linden/indra/llaudio/audioengine.cpp184
1 files changed, 158 insertions, 26 deletions
diff --git a/linden/indra/llaudio/audioengine.cpp b/linden/indra/llaudio/audioengine.cpp
index 5fb38c0..239981b 100644
--- a/linden/indra/llaudio/audioengine.cpp
+++ b/linden/indra/llaudio/audioengine.cpp
@@ -51,9 +51,6 @@ 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;
57 54
58// 55//
59// LLAudioEngine implementation 56// LLAudioEngine implementation
@@ -77,7 +74,8 @@ void LLAudioEngine::setDefaults()
77 74
78 mListenerp = NULL; 75 mListenerp = NULL;
79 76
80 mMuted = FALSE; 77 mMuted = false;
78 mUserData = NULL;
81 79
82 mLastStatus = 0; 80 mLastStatus = 0;
83 81
@@ -98,16 +96,20 @@ void LLAudioEngine::setDefaults()
98 mInternetStreamGain = 0.125f; 96 mInternetStreamGain = 0.125f;
99 mNextWindUpdate = 0.f; 97 mNextWindUpdate = 0.f;
100 98
99 mInternetStreamMedia = NULL;
100 mInternetStreamURL.clear();
101
101 for (U32 i = 0; i < LLAudioEngine::AUDIO_TYPE_COUNT; i++) 102 for (U32 i = 0; i < LLAudioEngine::AUDIO_TYPE_COUNT; i++)
102 mSecondaryGain[i] = 1.0f; 103 mSecondaryGain[i] = 1.0f;
103} 104}
104 105
105 106
106BOOL LLAudioEngine::init(const S32 num_channels) 107bool LLAudioEngine::init(const S32 num_channels, void* userdata)
107{ 108{
108 setDefaults(); 109 setDefaults();
109 110
110 mNumChannels = num_channels; 111 mNumChannels = num_channels;
112 mUserData = userdata;
111 113
112 allocateListener(); 114 allocateListener();
113 115
@@ -126,6 +128,9 @@ void LLAudioEngine::shutdown()
126 delete gAudioDecodeMgrp; 128 delete gAudioDecodeMgrp;
127 gAudioDecodeMgrp = NULL; 129 gAudioDecodeMgrp = NULL;
128 130
131 // Clean up wind source
132 cleanupWind();
133
129 // Clean up audio sources 134 // Clean up audio sources
130 source_map::iterator iter_src; 135 source_map::iterator iter_src;
131 for (iter_src = mAllSources.begin(); iter_src != mAllSources.end(); iter_src++) 136 for (iter_src = mAllSources.begin(); iter_src != mAllSources.end(); iter_src++)
@@ -146,22 +151,146 @@ void LLAudioEngine::shutdown()
146 S32 i; 151 S32 i;
147 for (i = 0; i < MAX_CHANNELS; i++) 152 for (i = 0; i < MAX_CHANNELS; i++)
148 { 153 {
149 if (mChannels[i]) 154 delete mChannels[i];
150 { 155 mChannels[i] = NULL;
151 delete mChannels[i];
152 mChannels[i] = NULL;
153 }
154 } 156 }
155 157
156 // Clean up buffers 158 // Clean up buffers
157 for (i = 0; i < MAX_BUFFERS; i++) 159 for (i = 0; i < MAX_BUFFERS; i++)
158 { 160 {
159 if (mBuffers[i]) 161 delete mBuffers[i];
162 mBuffers[i] = NULL;
163 }
164
165 delete mInternetStreamMedia;
166 mInternetStreamMedia = NULL;
167 mInternetStreamURL.clear();
168}
169
170
171// virtual
172void LLAudioEngine::startInternetStream(const std::string& url)
173{
174 llinfos << "entered startInternetStream()" << llendl;
175
176 if (!mInternetStreamMedia)
177 {
178 LLMediaManager* mgr = LLMediaManager::getInstance();
179 if (mgr)
160 { 180 {
161 delete mBuffers[i]; 181 mInternetStreamMedia = mgr->createSourceFromMimeType(LLURI(url).scheme(), "audio/mpeg"); // assumes that whatever media implementation supports mp3 also supports vorbis.
162 mBuffers[i] = NULL; 182 llinfos << "mInternetStreamMedia is now " << mInternetStreamMedia << llendl;
183 }
184 }
185
186 if(!mInternetStreamMedia)
187 return;
188
189 if (!url.empty()) {
190 llinfos << "Starting internet stream: " << url << llendl;
191 mInternetStreamURL = url;
192 mInternetStreamMedia->navigateTo ( url );
193 llinfos << "Playing....." << llendl;
194 mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_START);
195 mInternetStreamMedia->updateMedia();
196 } else {
197 llinfos << "setting stream to NULL"<< llendl;
198 mInternetStreamURL.clear();
199 mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_STOP);
200 mInternetStreamMedia->updateMedia();
201 }
202 //#endif
203}
204
205// virtual
206void LLAudioEngine::stopInternetStream()
207{
208 llinfos << "entered stopInternetStream()" << llendl;
209
210 if(mInternetStreamMedia)
211 {
212 if( ! mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_STOP)){
213 llinfos << "attempting to stop stream failed!" << llendl;
214 }
215 mInternetStreamMedia->updateMedia();
216 }
217
218 mInternetStreamURL.clear();
219}
220
221// virtual
222void LLAudioEngine::pauseInternetStream(int pause)
223{
224 llinfos << "entered pauseInternetStream()" << llendl;
225
226 if(!mInternetStreamMedia)
227 return;
228
229 if(pause)
230 {
231 if(! mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_PAUSE))
232 {
233 llinfos << "attempting to pause stream failed!" << llendl;
163 } 234 }
235 } else {
236 if(! mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_START))
237 {
238 llinfos << "attempting to unpause stream failed!" << llendl;
239 }
240 }
241 mInternetStreamMedia->updateMedia();
242}
243
244// virtual
245void LLAudioEngine::updateInternetStream()
246{
247 if (mInternetStreamMedia)
248 mInternetStreamMedia->updateMedia();
249}
250
251// virtual
252int LLAudioEngine::isInternetStreamPlaying()
253{
254 if (!mInternetStreamMedia)
255 return 0;
256
257 if (mInternetStreamMedia->getStatus() == LLMediaBase::STATUS_STARTED)
258 {
259 return 1; // Active and playing
260 }
261
262 if (mInternetStreamMedia->getStatus() == LLMediaBase::STATUS_PAUSED)
263 {
264 return 2; // paused
164 } 265 }
266
267 return 0; // Stopped
268}
269
270// virtual
271void LLAudioEngine::getInternetStreamInfo(char* artist, char* title)
272{
273 artist[0] = 0;
274 title[0] = 0;
275}
276
277// virtual
278void LLAudioEngine::setInternetStreamGain(F32 vol)
279{
280 mInternetStreamGain = vol;
281
282 if(!mInternetStreamMedia)
283 return;
284
285 vol = llclamp(vol, 0.f, 1.f);
286 mInternetStreamMedia->setVolume(vol);
287 mInternetStreamMedia->updateMedia();
288}
289
290// virtual
291const std::string& LLAudioEngine::getInternetStreamURL()
292{
293 return mInternetStreamURL;
165} 294}
166 295
167 296
@@ -449,6 +578,8 @@ void LLAudioEngine::idle(F32 max_decode_time)
449 // missed picking it up in all the places that can add 578 // missed picking it up in all the places that can add
450 // or request new data. 579 // or request new data.
451 startNextTransfer(); 580 startNextTransfer();
581
582 updateInternetStream();
452} 583}
453 584
454 585
@@ -758,7 +889,7 @@ void LLAudioEngine::triggerSound(const LLUUID &audio_uuid, const LLUUID& owner_i
758 LLUUID source_id; 889 LLUUID source_id;
759 source_id.generate(); 890 source_id.generate();
760 891
761 LLAudioSource *asp = new LLAudioSource(source_id, owner_id, gain); 892 LLAudioSource *asp = new LLAudioSource(source_id, owner_id, gain, type);
762 gAudiop->addAudioSource(asp); 893 gAudiop->addAudioSource(asp);
763 if (pos_global.isExactlyZero()) 894 if (pos_global.isExactlyZero())
764 { 895 {
@@ -1207,18 +1338,18 @@ void LLAudioEngine::assetCallback(LLVFS *vfs, const LLUUID &uuid, LLAssetType::E
1207// 1338//
1208 1339
1209 1340
1210LLAudioSource::LLAudioSource(const LLUUID& id, const LLUUID& owner_id, const F32 gain) 1341LLAudioSource::LLAudioSource(const LLUUID& id, const LLUUID& owner_id, const F32 gain, const S32 type)
1211: mID(id), 1342: mID(id),
1212 mOwnerID(owner_id), 1343 mOwnerID(owner_id),
1213 mPriority(0.f), 1344 mPriority(0.f),
1214 mGain(gain), 1345 mGain(gain),
1215 mType(type), 1346 mType(type),
1216 mAmbient(FALSE), 1347 mAmbient(false),
1217 mLoop(FALSE), 1348 mLoop(false),
1218 mSyncMaster(FALSE), 1349 mSyncMaster(false),
1219 mSyncSlave(FALSE), 1350 mSyncSlave(false),
1220 mQueueSounds(FALSE), 1351 mQueueSounds(false),
1221 mPlayedOnce(FALSE), 1352 mPlayedOnce(false),
1222 mChannelp(NULL), 1353 mChannelp(NULL),
1223 mCurrentDatap(NULL), 1354 mCurrentDatap(NULL),
1224 mQueuedDatap(NULL) 1355 mQueuedDatap(NULL)
@@ -1364,7 +1495,8 @@ bool LLAudioSource::play(const LLUUID &audio_uuid)
1364bool LLAudioSource::isDone() 1495bool LLAudioSource::isDone()
1365{ 1496{
1366 const F32 MAX_AGE = 60.f; 1497 const F32 MAX_AGE = 60.f;
1367 const F32 MAX_UNPLAYED_AGE = 30.f; 1498 const F32 MAX_UNPLAYED_AGE = 15.f;
1499
1368 if (isLoop()) 1500 if (isLoop())
1369 { 1501 {
1370 // Looped sources never die on their own. 1502 // Looped sources never die on their own.
@@ -1542,8 +1674,8 @@ LLAudioBuffer *LLAudioSource::getCurrentBuffer()
1542LLAudioChannel::LLAudioChannel() : 1674LLAudioChannel::LLAudioChannel() :
1543 mCurrentSourcep(NULL), 1675 mCurrentSourcep(NULL),
1544 mCurrentBufferp(NULL), 1676 mCurrentBufferp(NULL),
1545 mLoopedThisFrame(FALSE), 1677 mLoopedThisFrame(false),
1546 mWaiting(FALSE), 1678 mWaiting(false),
1547 mSecondaryGain(1.0f) 1679 mSecondaryGain(1.0f)
1548{ 1680{
1549} 1681}
@@ -1609,8 +1741,8 @@ bool LLAudioChannel::updateBuffer()
1609 } 1741 }
1610 1742
1611 // 1743 //
1612 // The source changed what buffer it's playing. Whe need to clean up the 1744 // The source changed what buffer it's playing. We need to clean up
1613 // existing fmod channel 1745 // the existing channel
1614 // 1746 //
1615 cleanup(); 1747 cleanup();
1616 1748