Ticket #8751: imuse.patch
File imuse.patch, 8.7 KB (added by , 17 years ago) |
---|
-
engines/scumm/imuse_digi/dimuse.cpp
158 158 if (!ser->isSaving()) { 159 159 if (!track->used) 160 160 continue; 161 track->readyToRemove = false;162 161 if ((track->toBeRemoved) || (track->souStreamUsed) || (track->curRegion == -1)) { 163 162 track->streamSou= NULL; 164 163 track->stream = NULL; … … 231 230 232 231 for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) { 233 232 Track *track = _track[l]; 234 if (track->used && !track->readyToRemove) { 233 if (track->used) { 234 // Remove tracks if necessary 235 235 if (track->toBeRemoved) { 236 track->readyToRemove = true;236 flushTrack(track); 237 237 continue; 238 238 } 239 239 … … 249 249 track->volFadeUsed = false; 250 250 } 251 251 if (track->vol == 0) { 252 track->toBeRemoved = true; 252 // Fade out complete -> remove this track 253 flushTrack(track); 254 continue; 253 255 } 254 256 } 255 257 } else if (track->volFadeStep > 0) { … … 357 359 } while (feedSize != 0); 358 360 } else if (track->streamSou) { 359 361 if (_mixer->isReady()) { 362 // FIXME: Can't we replace track->mixerStreamRunning by 363 // _mixer->isSoundHandleActive(track->mixChanHandle) ? 360 364 if (!track->mixerStreamRunning) { 361 365 track->mixerStreamRunning = true; 362 366 _mixer->playInputStream(type, &track->mixChanHandle, track->streamSou, -1, vol, pan, false); … … 375 379 debug(5, "switchToNextRegion(track:%d)", track->trackId); 376 380 377 381 if (track->trackId >= MAX_DIGITAL_TRACKS) { 378 track->toBeRemoved = true;382 flushTrack(track); 379 383 debug(5, "exit (fadetrack can't go next region) switchToNextRegion(trackId:%d)", track->trackId); 380 384 return; 381 385 } … … 383 387 int num_regions = _sound->getNumRegions(track->soundDesc); 384 388 385 389 if (++track->curRegion == num_regions) { 386 track->toBeRemoved = true;390 flushTrack(track); 387 391 debug(5, "exit (end of regions) switchToNextRegion(track:%d)", track->trackId); 388 392 return; 389 393 } -
engines/scumm/imuse_digi/dimuse_script.cpp
163 163 } 164 164 } 165 165 166 void IMuseDigital::flushTrack(Track *track) { 167 track->toBeRemoved = true; 168 if (track->stream) { 169 // Finalize the appendable stream 170 track->stream->finish(); 171 // There might still be some data left in the buffers of the 172 // appendable stream. We play it nice and wait till all of it 173 // played. 174 if (track->stream->endOfStream()) { 175 _mixer->stopHandle(track->mixChanHandle); 176 delete track->stream; 177 track->stream = NULL; 178 _sound->closeSound(track->soundDesc); 179 track->soundDesc = NULL; 180 track->used = false; 181 } 182 } else if (track->streamSou) { 183 _mixer->stopHandle(track->mixChanHandle); 184 delete track->streamSou; 185 track->streamSou = NULL; 186 track->used = false; 187 } 188 } 189 166 190 void IMuseDigital::flushTracks() { 167 191 Common::StackLock lock(_mutex, "IMuseDigital::flushTracks()"); 168 192 debug(5, "flushTracks()"); 169 193 for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) { 170 194 Track *track = _track[l]; 171 if (track->used && track->readyToRemove) { 172 if (track->stream) { 173 // Finalize the appendable stream 174 track->stream->finish(); 175 // There might still be some data left in the buffers of the 176 // appendable stream. We play it nice and wait till all of it 177 // played. 178 if (track->stream->endOfStream()) { 179 _mixer->stopHandle(track->mixChanHandle); 180 delete track->stream; 181 track->stream = NULL; 182 _sound->closeSound(track->soundDesc); 183 track->soundDesc = NULL; 184 track->used = false; 185 } 186 } else if (track->streamSou) { 187 _mixer->stopHandle(track->mixChanHandle); 188 delete track->streamSou; 189 track->streamSou = NULL; 190 track->used = false; 191 } 195 if (track->used && track->toBeRemoved) { 196 flushTrack(track); 192 197 } 193 198 } 194 199 } … … 288 293 Track *track = _track[l]; 289 294 if (track->soundId == sound) { 290 295 if ((track->streamSou && _mixer->isSoundHandleActive(track->mixChanHandle)) || 291 (track->stream && track->used && !track->readyToRemove)) {296 (track->stream && !track->stream->endOfStream())) { 292 297 return 1; 293 298 } 294 299 } -
engines/scumm/imuse_digi/dimuse_track.cpp
59 59 } 60 60 if (lowest_priority <= priority) { 61 61 assert(trackId != -1); 62 _track[trackId]->toBeRemoved = true; 62 Track *track = _track[trackId]; 63 while (1) { 64 if (!track->used) { 65 break; 66 } 67 // The designated track is not yet available. So, we call flushTrack() 68 // to get it processed (and thus made ready for us). Since the actual 69 // processing is done by another thread, we also call parseEvents to 70 // give it some time (and to avoid busy waiting/looping). 71 flushTrack(track); 72 _mutex.unlock(); 73 #ifndef __PLAYSTATION2__ 74 _vm->parseEvents(); 75 #endif 76 _mutex.lock(); 77 } 63 78 debug(5, "IMuseDigital::allocSlot(): Removed sound %d from track %d", _track[trackId]->soundId, trackId); 64 79 } else { 65 80 debug(5, "IMuseDigital::allocSlot(): Priority sound too low"); … … 71 86 } 72 87 73 88 void IMuseDigital::startSound(int soundId, const char *soundName, int soundType, int volGroupId, Audio::AudioStream *input, int hookId, int volume, int priority) { 89 Common::StackLock lock(_mutex, "IMuseDigital::startSound()"); 74 90 debug(5, "IMuseDigital::startSound(%d)", soundId); 75 91 76 92 int l = allocSlot(priority); … … 80 96 } 81 97 82 98 Track *track = _track[l]; 83 while (1) {84 _mutex.lock();85 if (!track->used) {86 break;87 }88 // The designated track is not yet available. So, we call flushTracks()89 // to get it processed (and thus made ready for us). Since the actual90 // processing is done by another thread, we also call parseEvents to91 // give it some time (and to avoid busy waiting/looping).92 flushTracks();93 _mutex.unlock();94 #ifndef __PLAYSTATION2__95 _vm->parseEvents();96 #endif97 }98 99 99 100 track->pan = 64; 100 101 track->vol = volume * 1000; … … 113 114 track->dataMod12Bit = 0; 114 115 track->mixerFlags = 0; 115 116 track->toBeRemoved = false; 116 track->readyToRemove = false;117 117 track->soundType = soundType; 118 118 119 119 int bits = 0, freq = 0, channels = 0; … … 191 191 } 192 192 193 193 track->used = true; 194 _mutex.unlock();195 194 } 196 195 197 196 void IMuseDigital::setPriority(int soundId, int priority) { … … 309 308 Track *track = _track[l]; 310 309 if (track->used && !track->toBeRemoved && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) { 311 310 cloneToFadeOutTrack(track, fadeDelay); 312 track->toBeRemoved = true;311 flushTrack(track); 313 312 } 314 313 } 315 314 } … … 319 318 Track *fadeTrack = 0; 320 319 321 320 debug(0, "IMuseDigital::cloneToFadeOutTrack(%d, %d)", track->trackId, fadeDelay); 321 322 if (track->toBeRemoved) { 323 error("IMuseDigital::cloneToFadeOutTrack: Tried to clone a track to be removed"); 324 return NULL; 325 } 322 326 323 327 if (_track[track->trackId + MAX_DIGITAL_TRACKS]->used) { 324 warning("IMuseDigital::cloneToFadeOutTrack: No tfree fade track");328 warning("IMuseDigital::cloneToFadeOutTrack: No free fade track"); 325 329 return NULL; 326 330 } 327 331 … … 360 364 } 361 365 fadeTrack->stream = Audio::makeAppendableAudioStream(_sound->getFreq(fadeTrack->soundDesc), makeMixerFlags(fadeTrack->mixerFlags)); 362 366 _mixer->playInputStream(type, &fadeTrack->mixChanHandle, fadeTrack->stream, -1, fadeTrack->vol / 1000, fadeTrack->pan, false); 363 364 367 fadeTrack->mixerStreamRunning = true; 365 368 fadeTrack->used = true; 366 369 -
engines/scumm/imuse_digi/dimuse.h
83 83 char soundName[15]; // sound name but also filename of sound in bundle data 84 84 bool used; // flag mean that track is used 85 85 bool toBeRemoved; // flag mean that track need to be free 86 bool readyToRemove; // flag mean that track is ready to stop87 86 bool mixerStreamRunning; // flag mean sound mixer's stream is running 88 87 bool souStreamUsed; // flag mean that track use stream from sou file 89 88 bool sndDataExtComp;// flag mean that sound data is compressed by scummvm tools … … 152 151 void setDigMusicSequence(int seqId); 153 152 void playDigMusic(const char *songName, const imuseDigTable *table, int atribPos, bool sequence); 154 153 154 void flushTrack(Track *track); 155 155 156 public: 156 157 IMuseDigital(ScummEngine_v7 *scumm, Audio::Mixer *mixer, int fps); 157 158 virtual ~IMuseDigital();