aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2009-07-11 06:53:39 +0000
committerFilippos Karapetis2009-07-11 06:53:39 +0000
commit2b5fac58d5323847042e53f114ad94ce2d526f3b (patch)
tree6b05334adf66855435ee1b8ed200a6decb184650
parent28dd343e08afb9eeb8318d06c8c18eb6b48fd210 (diff)
downloadscummvm-rg350-2b5fac58d5323847042e53f114ad94ce2d526f3b.tar.gz
scummvm-rg350-2b5fac58d5323847042e53f114ad94ce2d526f3b.tar.bz2
scummvm-rg350-2b5fac58d5323847042e53f114ad94ce2d526f3b.zip
Applied patch 2818733 - "SCI: Timer iterator for audio resources played via doSound"
svn-id: r42375
-rw-r--r--engines/sci/engine/ksound.cpp17
-rw-r--r--engines/sci/sfx/iterator.cpp35
-rw-r--r--engines/sci/sfx/iterator.h6
-rw-r--r--engines/sci/sfx/iterator_internal.h22
4 files changed, 75 insertions, 5 deletions
diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp
index 7614b2bc10..4ba8971397 100644
--- a/engines/sci/engine/ksound.cpp
+++ b/engines/sci/engine/ksound.cpp
@@ -148,6 +148,9 @@ SongIterator *build_iterator(EngineState *s, int song_nr, SongIteratorType type,
return songit_new(song->data, song->size, type, id);
}
+SongIterator *build_timeriterator(EngineState *s, int delta) {
+ return new_timer_iterator(delta);
+}
void process_sound_events(EngineState *s) { /* Get all sound events, apply their changes to the heap */
int result;
@@ -798,6 +801,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int looping = GET_SEL32V(obj, loop);
//int vol = GET_SEL32V(obj, vol);
int pri = GET_SEL32V(obj, pri);
+ int sampleLen = 0;
Song *song = s->_sound._songlib.findSong(handle);
if (GET_SEL32V(obj, nodePtr) && (song && number != song->_resourceNum)) {
@@ -815,8 +819,11 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
s->_version >= SCI_VERSION_1_1) {
// Found a relevant audio resource, play it
s->_sound.stopAudio();
- PUT_SEL32V(obj, signal, s->_sound.startAudio(65535, number));
- return s->r_acc;
+ warning("Initializing audio resource instead of requested sound resource %d\n", number);
+ sampleLen = s->_sound.startAudio(65535, number);
+ // Also create iterator, that will fire SI_FINISHED event, when the sound is done playing
+ s->_sound.sfx_add_song(build_timeriterator(s, sampleLen), 0, handle, number);
+ PUT_SEL32V(obj, signal, sampleLen);
} else {
if (!s->resmgr->testResource(ResourceId(kResourceTypeSound, number))) {
warning("Could not open song number %d", number);
@@ -825,11 +832,11 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
PUT_SEL32V(obj, signal, -1);
return s->r_acc;
}
+ debugC(2, kDebugLevelSound, "Initializing song number %d\n", number);
+ s->_sound.sfx_add_song(build_iterator(s, number, SCI_SONG_ITERATOR_TYPE_SCI1,
+ handle), 0, handle, number);
}
- debugC(2, kDebugLevelSound, "Initializing song number %d\n", number);
- s->_sound.sfx_add_song(build_iterator(s, number, SCI_SONG_ITERATOR_TYPE_SCI1,
- handle), 0, handle, number);
PUT_SEL32(obj, nodePtr, obj);
PUT_SEL32(obj, handle, obj);
}
diff --git a/engines/sci/sfx/iterator.cpp b/engines/sci/sfx/iterator.cpp
index ebba4bceac..6c5706a8c1 100644
--- a/engines/sci/sfx/iterator.cpp
+++ b/engines/sci/sfx/iterator.cpp
@@ -1164,6 +1164,41 @@ int CleanupSongIterator::nextCommand(byte *buf, int *result) {
return SI_FINISHED;
}
+/**********************/
+/*-- Timer iterator --*/
+/**********************/
+TimerSongIterator::TimerSongIterator(int delta)
+ : _delta(delta) {
+}
+
+int TimerSongIterator::nextCommand(byte *buf, int *result) {
+ if (_delta) {
+ return _delta;
+ }
+ return SI_FINISHED;
+}
+
+SongIterator *TimerSongIterator::handleMessage(Message msg) {
+ return NULL;
+}
+
+int TimerSongIterator::getTimepos() {
+ return 0;
+}
+
+Audio::AudioStream *TimerSongIterator::getAudioStream() {
+ return NULL;
+}
+
+SongIterator *TimerSongIterator::clone(int delta) {
+ TimerSongIterator *newit = new TimerSongIterator(*this);
+ return newit;
+}
+
+SongIterator *new_timer_iterator(int delta) {
+ return new TimerSongIterator(delta);
+}
+
/**********************************/
/*-- Fast-forward song iterator --*/
/**********************************/
diff --git a/engines/sci/sfx/iterator.h b/engines/sci/sfx/iterator.h
index 547c479bbf..4e6df367c9 100644
--- a/engines/sci/sfx/iterator.h
+++ b/engines/sci/sfx/iterator.h
@@ -281,6 +281,12 @@ int songit_next(SongIterator **it, byte *buf, int *result, int mask);
*/
SongIterator *songit_new(byte *data, uint size, SongIteratorType type, songit_id_t id);
+/* Constructs a new song timer iterator object
+** Parameters: (int) delta: The delta after which to fire SI_FINISHED
+** Returns : (SongIterator *) A newly allocated but uninitialized song
+** iterator
+*/
+SongIterator *new_timer_iterator(int delta);
/* Handles a message to the song iterator
** Parameters: (SongIterator **): A reference to the variable storing the song iterator
diff --git a/engines/sci/sfx/iterator_internal.h b/engines/sci/sfx/iterator_internal.h
index 7d5a17fd25..00044b8ab7 100644
--- a/engines/sci/sfx/iterator_internal.h
+++ b/engines/sci/sfx/iterator_internal.h
@@ -181,6 +181,28 @@ private:
#define PLAYMASK_NONE 0x0
+/***************************/
+/*--------- Timer ---------*/
+/***************************/
+
+/**
+ * A song iterator which waits a specified time and then fires
+ * SI_FINISHED. Used by DoSound, where audio resources are played (SCI1)
+ */
+class TimerSongIterator : public SongIterator {
+protected:
+ int _delta; /**!< Remaining time */
+
+public:
+ TimerSongIterator(int delta);
+
+ int nextCommand(byte *buf, int *result);
+ Audio::AudioStream *getAudioStream();
+ SongIterator *handleMessage(Message msg);
+ int getTimepos();
+ SongIterator *clone(int delta);
+};
+
/**********************************/
/*--------- Fast Forward ---------*/
/**********************************/