diff options
author | Max Horn | 2009-05-28 22:48:15 +0000 |
---|---|---|
committer | Max Horn | 2009-05-28 22:48:15 +0000 |
commit | d3bd7b622cf84a9d7f5cda9df9b68174953fe1ac (patch) | |
tree | f0a8f07c02c770759c4ee9ed02e5e02c46198580 /engines | |
parent | 56b1eb7d092188143d2487d08ee258bef1eaa4fa (diff) | |
download | scummvm-rg350-d3bd7b622cf84a9d7f5cda9df9b68174953fe1ac.tar.gz scummvm-rg350-d3bd7b622cf84a9d7f5cda9df9b68174953fe1ac.tar.bz2 scummvm-rg350-d3bd7b622cf84a9d7f5cda9df9b68174953fe1ac.zip |
SCI: Turned SfxState into a proper class (i.e., convert the sfx_ funcs to member methods)
svn-id: r40973
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/engine/game.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/ksound.cpp | 120 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 6 | ||||
-rw-r--r-- | engines/sci/engine/scriptdebug.cpp | 8 | ||||
-rw-r--r-- | engines/sci/sfx/core.cpp | 222 | ||||
-rw-r--r-- | engines/sci/sfx/core.h | 228 |
6 files changed, 283 insertions, 305 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 8adc44acee..3ae209c662 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -220,7 +220,7 @@ int game_init_sound(EngineState *s, int sound_flags) { sound_flags |= SFX_STATE_FLAG_MULTIPLAY; s->sfx_init_flags = sound_flags; - sfx_init(&s->_sound, s->resmgr, sound_flags); + s->_sound.sfx_init(s->resmgr, sound_flags); return 0; } @@ -593,7 +593,7 @@ int game_exit(EngineState *s) { s->_executionStack.clear(); if (!s->successor) { - sfx_exit(&s->_sound); + s->_sound.sfx_exit(); // Reinit because some other code depends on having a valid state game_init_sound(s, SFX_STATE_FLAG_NOSOUND); } diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp index 8edf6f5186..59937853bd 100644 --- a/engines/sci/engine/ksound.cpp +++ b/engines/sci/engine/ksound.cpp @@ -135,7 +135,7 @@ static void script_set_priority(EngineState *s, reg_t obj, int priority) { flags &= ~SCI1_SOUND_FLAG_SCRIPTED_PRI; } else flags |= SCI1_SOUND_FLAG_SCRIPTED_PRI; - sfx_song_renice(&s->_sound, FROBNICATE_HANDLE(obj), priority); + s->_sound.sfx_song_renice(FROBNICATE_HANDLE(obj), priority); PUT_SEL32V(obj, flags, flags); } @@ -158,7 +158,7 @@ void process_sound_events(EngineState *s) { /* Get all sound events, apply their return; /* SCI01 and later explicitly poll for everything */ - while ((result = sfx_poll(&s->_sound, &handle, &cue))) { + while ((result = s->_sound.sfx_poll(&handle, &cue))) { reg_t obj = DEFROBNICATE_HANDLE(handle); if (!is_object(s, obj)) { warning("Non-object %04x:%04x received sound signal (%d/%d)", PRINT_REG(obj), result, cue); @@ -272,7 +272,7 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) { case _K_SCI0_SOUND_INIT_HANDLE: if (obj.segment) { sciprintf("Initializing song number %d\n", GET_SEL32V(obj, number)); - SCRIPT_ASSERT_ZERO(sfx_add_song(&s->_sound, + SCRIPT_ASSERT_ZERO(s->_sound.sfx_add_song( build_iterator(s, number, SCI_SONG_ITERATOR_TYPE_SCI0, handle), @@ -284,10 +284,8 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) { case _K_SCI0_SOUND_PLAY_HANDLE: if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_PLAYING); - sfx_song_set_loops(&s->_sound, - handle, GET_SEL32V(obj, loop)); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_PLAYING); + s->_sound.sfx_song_set_loops(handle, GET_SEL32V(obj, loop)); PUT_SEL32V(obj, state, _K_SOUND_STATUS_PLAYING); } break; @@ -297,31 +295,28 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) { case _K_SCI0_SOUND_DISPOSE_HANDLE: if (obj.segment) { - sfx_remove_song(&s->_sound, handle); + s->_sound.sfx_remove_song(handle); } PUT_SEL32V(obj, handle, 0x0000); break; case _K_SCI0_SOUND_STOP_HANDLE: if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_STOPPED); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); PUT_SEL32V(obj, state, SOUND_STATUS_STOPPED); } break; case _K_SCI0_SOUND_SUSPEND_HANDLE: if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_SUSPENDED); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_SUSPENDED); PUT_SEL32V(obj, state, SOUND_STATUS_SUSPENDED); } break; case _K_SCI0_SOUND_RESUME_HANDLE: if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_PLAYING); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_PLAYING); PUT_SEL32V(obj, state, SOUND_STATUS_PLAYING); } break; @@ -345,16 +340,15 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) { int vol = SKPV_OR_ALT(1, -1); if (vol != -1) - sfx_set_volume(&s->_sound, vol << 0xf); + s->_sound.sfx_set_volume(vol << 0xf); else - s->r_acc = make_reg(0, sfx_get_volume(&s->_sound) >> 0xf); + s->r_acc = make_reg(0, s->_sound.sfx_get_volume() >> 0xf); } break; case _K_SCI0_SOUND_UPDATE_VOL_PRI: if (obj.segment) { - sfx_song_set_loops(&s->_sound, - handle, GET_SEL32V(obj, loop)); + s->_sound.sfx_song_set_loops(handle, GET_SEL32V(obj, loop)); script_set_priority(s, obj, GET_SEL32V(obj, pri)); } break; @@ -364,8 +358,7 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) { /* FIXME: The next couple of lines actually STOP the handle, rather ** than fading it! */ if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_STOPPED); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); PUT_SEL32V(obj, state, SOUND_STATUS_STOPPED); PUT_SEL32V(obj, signal, -1); } @@ -376,7 +369,7 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) { break; case _K_SCI0_SOUND_PLAY_NEXT: - /* sfx_all_stop(&s->_sound);*/ + /* s->_sound.sfx_all_stop();*/ break; default: @@ -467,9 +460,9 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { int vol = SKPV_OR_ALT(1, -1); if (vol != -1) - sfx_set_volume(&s->_sound, vol << 0xf); + s->_sound.sfx_set_volume(vol << 0xf); else - s->r_acc = make_reg(0, sfx_get_volume(&s->_sound) >> 0xf); + s->r_acc = make_reg(0, s->_sound.sfx_get_volume() >> 0xf); break; } case _K_SCI01_SOUND_MUTE_SOUND : { @@ -498,12 +491,9 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { RESTORE_BEHAVIOR rb = (RESTORE_BEHAVIOR) UKPV(2); /* Too lazy to look up a default value for this */ if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_PLAYING); - sfx_song_set_loops(&s->_sound, - handle, looping); - sfx_song_renice(&s->_sound, - handle, pri); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_PLAYING); + s->_sound.sfx_song_set_loops(handle, looping); + s->_sound.sfx_song_renice(handle, pri); song_lib_set_restore_behavior(s->_sound._songlib, handle, rb); } @@ -516,7 +506,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (obj.segment && (s->resmgr->testResource(kResourceTypeSound, number))) { sciprintf("Initializing song number %d\n", number); - SCRIPT_ASSERT_ZERO(sfx_add_song(&s->_sound, + SCRIPT_ASSERT_ZERO(s->_sound.sfx_add_song( build_iterator(s, number, SCI_SONG_ITERATOR_TYPE_SCI1, handle), @@ -528,9 +518,8 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { } case _K_SCI01_SOUND_DISPOSE_HANDLE : { if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_STOPPED); - sfx_remove_song(&s->_sound, handle); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); + s->_sound.sfx_remove_song(handle); } break; } @@ -546,9 +535,8 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { //int vol = GET_SEL32V(obj, vol); int pri = GET_SEL32V(obj, pri); - sfx_song_set_loops(&s->_sound, - handle, looping); - sfx_song_renice(&s->_sound, handle, pri); + s->_sound.sfx_song_set_loops(handle, looping); + s->_sound.sfx_song_renice(handle, pri); SCIkdebug(SCIkSOUND, "[sound01-update-handle] -- CUE %04x:%04x"); @@ -562,8 +550,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { case _K_SCI01_SOUND_STOP_HANDLE : { PUT_SEL32V(obj, signal, -1); if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_STOPPED); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); } break; } @@ -573,8 +560,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { SOUND_STATUS_SUSPENDED : SOUND_STATUS_PLAYING; if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, setstate); + s->_sound.sfx_song_set_status(handle, setstate); } break; } @@ -585,8 +571,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { /* FIXME: The next couple of lines actually STOP the song right away */ PUT_SEL32V(obj, signal, -1); if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_STOPPED); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); } break; } @@ -599,7 +584,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { int cue = 0; while (result == SI_LOOP) - result = sfx_poll_specific(&s->_sound, handle, &cue); + result = s->_sound.sfx_poll_specific(handle, &cue); switch (result) { @@ -645,7 +630,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { /* } */ /* break; */ /* case 0xFF: /\* May be unnecessary *\/ */ - /* sfx_song_set_status(&s->_sound, */ + /* s->_sound.sfx_song_set_status(*/ /* handle, SOUND_STATUS_STOPPED); */ /* break; */ /* default : */ @@ -673,7 +658,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { int controller = UKPV(3); int param = UKPV(4); - sfx_send_midi(&s->_sound, handle, + s->_sound.sfx_send_midi(handle, channel, midiCmd, controller, param); break; } @@ -821,9 +806,8 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { song_t *song = song_lib_find(s->_sound._songlib, handle); if (GET_SEL32V(obj, nodePtr) && (song && number != song->resource_num)) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_STOPPED); - sfx_remove_song(&s->_sound, handle); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); + s->_sound.sfx_remove_song(handle); PUT_SEL32(obj, nodePtr, NULL_REG); } @@ -834,7 +818,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { } sciprintf("Initializing song number %d\n", number); - SCRIPT_ASSERT_ZERO(sfx_add_song(&s->_sound, + SCRIPT_ASSERT_ZERO(s->_sound.sfx_add_song( build_iterator(s, number, SCI_SONG_ITERATOR_TYPE_SCI1, handle), @@ -844,12 +828,9 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { } if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_PLAYING); - sfx_song_set_loops(&s->_sound, - handle, looping); - sfx_song_renice(&s->_sound, - handle, pri); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_PLAYING); + s->_sound.sfx_song_set_loops(handle, looping); + s->_sound.sfx_song_renice(handle, pri); } break; @@ -860,14 +841,13 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { //int pri = GET_SEL32V(obj, pri); if (GET_SEL32V(obj, nodePtr)) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_STOPPED); - sfx_remove_song(&s->_sound, handle); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); + s->_sound.sfx_remove_song(handle); } if (obj.segment && (s->resmgr->testResource(kResourceTypeSound, number))) { sciprintf("Initializing song number %d\n", number); - SCRIPT_ASSERT_ZERO(sfx_add_song(&s->_sound, + SCRIPT_ASSERT_ZERO(s->_sound.sfx_add_song( build_iterator(s, number, SCI_SONG_ITERATOR_TYPE_SCI1, handle), @@ -879,17 +859,15 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { } case _K_SCI1_SOUND_DISPOSE_HANDLE : { if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_STOPPED); - sfx_remove_song(&s->_sound, handle); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); + s->_sound.sfx_remove_song(handle); } break; } case _K_SCI1_SOUND_STOP_HANDLE : { PUT_SEL32V(obj, signal, -1); if (obj.segment) { - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_STOPPED); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); } break; } @@ -906,9 +884,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { FADE_ACTION_FADE_AND_STOP : FADE_ACTION_FADE_AND_CONT; - sfx_song_set_fade(&s->_sound, - handle, - &fade); + s->_sound.sfx_song_set_fade(handle, &fade); /* FIXME: The next couple of lines actually STOP the handle, rather ** than fading it! */ @@ -916,8 +892,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { PUT_SEL32V(obj, signal, -1); PUT_SEL32V(obj, nodePtr, 0); PUT_SEL32V(obj, handle, 0); - sfx_song_set_status(&s->_sound, - handle, SOUND_STATUS_STOPPED); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); } else { // FIXME: Support fade-and-continue. For now, send signal right away. PUT_SEL32V(obj, signal, -1); @@ -928,8 +903,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { case _K_SCI1_SOUND_HOLD_HANDLE : { int value = SKPV(2); - sfx_song_set_hold(&s->_sound, - handle, value); + s->_sound.sfx_song_set_hold(handle, value); break; } case _K_SCI1_SOUND_UNUSED2 : { @@ -956,7 +930,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { int cue = 0; while (result == SI_LOOP) - result = sfx_poll_specific(&s->_sound, handle, &cue); + result = s->_sound.sfx_poll_specific(handle, &cue); switch (result) { @@ -986,7 +960,7 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { break; } case _K_SCI1_SOUND_MIDI_SEND : { - sfx_send_midi(&s->_sound, handle, + s->_sound.sfx_send_midi(handle, UKPV(2), UKPV(3), UKPV(4), UKPV(5)); break; } diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 433a01974e..76d4e7ae4e 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -720,7 +720,7 @@ static void reconstruct_sounds(EngineState *s) { oldstatus = seeker->status; seeker->status = SOUND_STATUS_STOPPED; seeker->it = ff; - sfx_song_set_status(&s->_sound, seeker->handle, oldstatus); + s->_sound.sfx_song_set_status(seeker->handle, oldstatus); seeker = seeker->next; } } @@ -770,7 +770,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { retval->saveLoadWithSerializer(ser); // FIXME: Error handling? - sfx_exit(&s->_sound); + s->_sound.sfx_exit(); // Set exec stack base to zero retval->execution_stack_base = 0; @@ -784,7 +784,7 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { retval->resmgr = s->resmgr; temp = retval->_sound._songlib; - sfx_init(&retval->_sound, retval->resmgr, s->sfx_init_flags); + retval->_sound.sfx_init(retval->resmgr, s->sfx_init_flags); retval->sfx_init_flags = s->sfx_init_flags; song_lib_free(retval->_sound._songlib); retval->_sound._songlib = temp; diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index a18fac86c4..2415194032 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -2358,8 +2358,8 @@ static int c_sfx_remove(EngineState *s, const Common::Array<cmd_param_t> &cmdPar int handle = FROBNICATE_HANDLE(id); if (id.segment) { - sfx_song_set_status(&s->_sound, handle, SOUND_STATUS_STOPPED); - sfx_remove_song(&s->_sound, handle); + s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); + s->_sound.sfx_remove_song(handle); PUT_SEL32V(id, signal, -1); PUT_SEL32V(id, nodePtr, 0); PUT_SEL32V(id, handle, 0); @@ -3257,7 +3257,7 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t * const char *commandstring; // Suspend music playing - sfx_suspend(&s->_sound, 1); + s->_sound.sfx_suspend(true); commandstring = _debug_get_input(); @@ -3270,7 +3270,7 @@ void script_debug(EngineState *s, reg_t *pc, StackPtr *sp, StackPtr *pp, reg_t * sciprintf("\n"); // Resume music playing - sfx_suspend(&s->_sound, 0); + s->_sound.sfx_suspend(false); } } diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp index c4862812f6..818cc05eb4 100644 --- a/engines/sci/sfx/core.cpp +++ b/engines/sci/sfx/core.cpp @@ -333,10 +333,10 @@ int sfx_get_player_polyphony() { return 0; } -static void _freeze_time(SfxState *self) { +void SfxState::freezeTime() { /* Freezes the top song delay time */ const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); - song_t *song = self->_song; + song_t *song = _song; while (song) { song->_delay = song->_wakeupTime.frameDiff(ctime); @@ -347,10 +347,10 @@ static void _freeze_time(SfxState *self) { } } -static void _thaw_time(SfxState *self) { - /* inverse of _freeze_time() */ +void SfxState::thawTime() { + /* inverse of freezeTime() */ const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); - song_t *song = self->_song; + song_t *song = _song; while (song) { song->_wakeupTime = ctime.addFrames(song->_delay); @@ -383,8 +383,8 @@ static void _dump_playing_list(SfxState *self, char *msg) { } #endif -static void _dump_songs(SfxState *self) { #if 0 +static void _dump_songs(SfxState *self) { song_t *song = self->_song; fprintf(stderr, "Cue iterators:\n"); @@ -400,23 +400,23 @@ static void _dump_songs(SfxState *self) { fprintf(stderr, "Audio iterator:\n"); player->iterator_message(SongIterator::Message(0, SIMSG_PRINT(1))); } -#endif } +#endif -static int is_playing(SfxState *self, song_t *song) { - song_t *playing_song = self->_song; +bool SfxState::isPlaying(song_t *song) { + song_t *playing_song = _song; - /* _dump_playing_list(self, "is-playing");*/ + /* _dump_playing_list(this, "is-playing");*/ while (playing_song) { if (playing_song == song) - return 1; + return true; playing_song = playing_song->next_playing; } - return 0; + return false; } -static void _sfx_set_song_status(SfxState *self, song_t *song, int status) { +void SfxState::setSongStatus(song_t *song, int status) { const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); switch (status) { @@ -444,7 +444,7 @@ static void _sfx_set_song_status(SfxState *self, song_t *song, int status) { song->_wakeupTime = ctime; } - if (is_playing(self, song)) + if (isPlaying(song)) status = SOUND_STATUS_PLAYING; else status = SOUND_STATUS_WAITING; @@ -460,11 +460,11 @@ static void _sfx_set_song_status(SfxState *self, song_t *song, int status) { } /* Update internal state iff only one song may be played */ -static void _update_single_song(SfxState *self) { - song_t *newsong = song_lib_find_active(self->_songlib); +void SfxState::updateSingleSong() { + song_t *newsong = song_lib_find_active(_songlib); - if (newsong != self->_song) { - _freeze_time(self); /* Store song delay time */ + if (newsong != _song) { + freezeTime(); /* Store song delay time */ if (player) player->stop(); @@ -475,25 +475,23 @@ static void _update_single_song(SfxState *self) { /* Change song */ if (newsong->status == SOUND_STATUS_WAITING) - _sfx_set_song_status(self, newsong, - SOUND_STATUS_PLAYING); + setSongStatus(newsong, SOUND_STATUS_PLAYING); /* Change instrument mappings */ } else { /* Turn off sound */ } - if (self->_song) { - if (self->_song->status == SOUND_STATUS_PLAYING) - _sfx_set_song_status(self, newsong, - SOUND_STATUS_WAITING); + if (_song) { + if (_song->status == SOUND_STATUS_PLAYING) + setSongStatus(newsong, SOUND_STATUS_WAITING); } - if (self->_debug & SFX_DEBUG_SONGS) { + if (_debug & SFX_DEBUG_SONGS) { sciprintf("[SFX] Changing active song:"); - if (!self->_song) + if (!_song) sciprintf(" New song:"); else - sciprintf(" pausing %08lx, now playing", self->_song->handle); + sciprintf(" pausing %08lx, now playing", _song->handle); if (newsong) sciprintf(" %08lx\n", newsong->handle); @@ -502,8 +500,8 @@ static void _update_single_song(SfxState *self) { } - self->_song = newsong; - _thaw_time(self); /* Recover song delay time */ + _song = newsong; + thawTime(); /* Recover song delay time */ if (newsong && player) { SongIterator *clonesong = newsong->it->clone(newsong->_delay); @@ -514,17 +512,17 @@ static void _update_single_song(SfxState *self) { } -static void _update_multi_song(SfxState *self) { - song_t *oldfirst = self->_song; +void SfxState::updateMultiSong() { + song_t *oldfirst = _song; song_t *oldseeker; - song_t *newsong = song_lib_find_active(self->_songlib); + song_t *newsong = song_lib_find_active(_songlib); song_t *newseeker; song_t not_playing_anymore; /* Dummy object, referenced by ** songs which are no longer ** active. */ - /* _dump_playing_list(self, "before");*/ - _freeze_time(self); /* Store song delay time */ + /* _dump_playing_list(this, "before");*/ + freezeTime(); /* Store song delay time */ if (!newsong) return; @@ -549,23 +547,21 @@ static void _update_multi_song(SfxState *self) { for (newseeker = newsong; newseeker; newseeker = newseeker->next_playing) { newseeker->next_playing - = song_lib_find_next_active(self->_songlib, - newseeker); + = song_lib_find_next_active(_songlib, newseeker); if (newseeker == newseeker->next_playing) { BREAKPOINT(); } } /* We now need to update the currently playing song list, because we're ** going to use some functions that require this list to be in a sane - ** state (particularly is_playing(), indirectly */ - self->_song = newsong; + ** state (particularly isPlaying(), indirectly */ + _song = newsong; /* Third, stop all old songs */ for (oldseeker = oldfirst; oldseeker; oldseeker = oldseeker->next_stopping) if (oldseeker->next_playing == ¬_playing_anymore) { - _sfx_set_song_status(self, oldseeker, - SOUND_STATUS_SUSPENDED); - if (self->_debug & SFX_DEBUG_SONGS) { + setSongStatus(oldseeker, SOUND_STATUS_SUSPENDED); + if (_debug & SFX_DEBUG_SONGS) { sciprintf("[SFX] Stopping song %lx\n", oldseeker->handle); } if (player && oldseeker->it) @@ -575,27 +571,26 @@ static void _update_multi_song(SfxState *self) { for (newseeker = newsong; newseeker; newseeker = newseeker->next_playing) { if (newseeker->status != SOUND_STATUS_PLAYING && player) { - if (self->_debug & SFX_DEBUG_SONGS) + if (_debug & SFX_DEBUG_SONGS) sciprintf("[SFX] Adding song %lx\n", newseeker->it->ID); SongIterator *clonesong = newseeker->it->clone(newseeker->_delay); player->add_iterator(clonesong, g_system->getMillis()); } - _sfx_set_song_status(self, newseeker, - SOUND_STATUS_PLAYING); + setSongStatus(newseeker, SOUND_STATUS_PLAYING); } - self->_song = newsong; - _thaw_time(self); - /* _dump_playing_list(self, "after");*/ + _song = newsong; + thawTime(); + /* _dump_playing_list(this, "after");*/ } /* Update internal state */ -static void _update(SfxState *self) { - if (self->_flags & SFX_STATE_FLAG_MULTIPLAY) - _update_multi_song(self); +void SfxState::update() { + if (_flags & SFX_STATE_FLAG_MULTIPLAY) + updateMultiSong(); else - _update_single_song(self); + updateSingleSong(); } int sfx_play_iterator_pcm(SongIterator *it, song_handle_t handle) { @@ -614,13 +609,13 @@ int sfx_play_iterator_pcm(SongIterator *it, song_handle_t handle) { #define DELAY (1000000 / SFX_TICKS_PER_SEC) -void sfx_init(SfxState *self, ResourceManager *resmgr, int flags) { - song_lib_init(&self->_songlib); - self->_song = NULL; - self->_flags = flags; - self->_debug = 0; /* Disable all debugging by default */ - self->_soundSync = NULL; - self->_audioResource = NULL; +void SfxState::sfx_init(ResourceManager *resmgr, int flags) { + song_lib_init(&_songlib); + _song = NULL; + _flags = flags; + _debug = 0; /* Disable all debugging by default */ + _soundSync = NULL; + _audioResource = NULL; player = NULL; @@ -656,7 +651,7 @@ void sfx_init(SfxState *self, ResourceManager *resmgr, int flags) { } } -void sfx_exit(SfxState *self) { +void SfxState::sfx_exit() { #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Uninitialising\n"); #endif @@ -666,55 +661,55 @@ void sfx_exit(SfxState *self) { g_system->getMixer()->stopAll(); - song_lib_free(self->_songlib); + song_lib_free(_songlib); // Delete audio resources for CD talkie games - if (self->_audioResource) { - delete self->_audioResource; - self->_audioResource = 0; + if (_audioResource) { + delete _audioResource; + _audioResource = 0; } } -void sfx_suspend(SfxState *self, int suspend) { +void SfxState::sfx_suspend(bool suspend) { #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Suspending? = %d\n", suspend); #endif - if (suspend && (!self->_suspended)) { + if (suspend && (!_suspended)) { /* suspend */ - _freeze_time(self); + freezeTime(); if (player) player->pause(); /* Suspend song player */ - } else if (!suspend && (self->_suspended)) { + } else if (!suspend && (_suspended)) { /* unsuspend */ - _thaw_time(self); + thawTime(); if (player) player->resume(); /* Unsuspend song player */ } - self->_suspended = suspend; + _suspended = suspend; } -int sfx_poll(SfxState *self, song_handle_t *handle, int *cue) { - if (!self->_song) +int SfxState::sfx_poll(song_handle_t *handle, int *cue) { + if (!_song) return 0; /* No milk today */ - *handle = self->_song->handle; + *handle = _song->handle; #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Polling any (%08lx)\n", *handle); #endif - return sfx_poll_specific(self, *handle, cue); + return sfx_poll_specific(*handle, cue); } -int sfx_poll_specific(SfxState *self, song_handle_t handle, int *cue) { +int SfxState::sfx_poll_specific(song_handle_t handle, int *cue) { const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); - song_t *song = self->_song; + song_t *song = _song; while (song && song->handle != handle) song = song->next_playing; @@ -722,7 +717,7 @@ int sfx_poll_specific(SfxState *self, song_handle_t handle, int *cue) { if (!song) return 0; /* Song not playing */ - if (self->_debug & SFX_DEBUG_CUES) { + if (_debug & SFX_DEBUG_CUES) { fprintf(stderr, "[SFX:CUE] Polled song %08lx ", handle); } @@ -736,13 +731,13 @@ int sfx_poll_specific(SfxState *self, song_handle_t handle, int *cue) { switch (result) { case SI_FINISHED: - _sfx_set_song_status(self, song, SOUND_STATUS_STOPPED); - _update(self); + setSongStatus(song, SOUND_STATUS_STOPPED); + update(); /* ...fall through... */ case SI_LOOP: case SI_RELATIVE_CUE: case SI_ABSOLUTE_CUE: - if (self->_debug & SFX_DEBUG_CUES) { + if (_debug & SFX_DEBUG_CUES) { sciprintf(" => "); if (result == SI_FINISHED) @@ -766,7 +761,7 @@ int sfx_poll_specific(SfxState *self, song_handle_t handle, int *cue) { break; } } - if (self->_debug & SFX_DEBUG_CUES) { + if (_debug & SFX_DEBUG_CUES) { fprintf(stderr, "\n"); } } @@ -776,8 +771,8 @@ int sfx_poll_specific(SfxState *self, song_handle_t handle, int *cue) { /* Song basics */ /*****************/ -int sfx_add_song(SfxState *self, SongIterator *it, int priority, song_handle_t handle, int number) { - song_t *song = song_lib_find(self->_songlib, handle); +int SfxState::sfx_add_song(SongIterator *it, int priority, song_handle_t handle, int number) { + song_t *song = song_lib_find(_songlib, handle); #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Adding song: %08lx at %d, it=%p\n", handle, priority, it); @@ -791,13 +786,13 @@ int sfx_add_song(SfxState *self, SongIterator *it, int priority, song_handle_t h /* If we're already playing this, stop it */ /* Tell player to shut up */ - _dump_songs(self); +// _dump_songs(this); if (player) player->iterator_message(SongIterator::Message(handle, SIMSG_STOP)); if (song) { - _sfx_set_song_status(self, song, SOUND_STATUS_STOPPED); + setSongStatus( song, SOUND_STATUS_STOPPED); fprintf(stderr, "Overwriting old song (%08lx) ...\n", handle); if (song->status == SOUND_STATUS_PLAYING @@ -807,7 +802,7 @@ int sfx_add_song(SfxState *self, SongIterator *it, int priority, song_handle_t h delete it; return -1; } else - song_lib_remove(self->_songlib, handle); /* No duplicates */ + song_lib_remove(_songlib, handle); /* No duplicates */ } @@ -816,22 +811,22 @@ int sfx_add_song(SfxState *self, SongIterator *it, int priority, song_handle_t h song->hold = 0; song->loops = 0; song->_wakeupTime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); - song_lib_add(self->_songlib, song); - self->_song = NULL; /* As above */ - _update(self); + song_lib_add(_songlib, song); + _song = NULL; /* As above */ + update(); return 0; } -void sfx_remove_song(SfxState *self, song_handle_t handle) { +void SfxState::sfx_remove_song(song_handle_t handle) { #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Removing song: %08lx\n", handle); #endif - if (self->_song && self->_song->handle == handle) - self->_song = NULL; + if (_song && _song->handle == handle) + _song = NULL; - song_lib_remove(self->_songlib, handle); - _update(self); + song_lib_remove(_songlib, handle); + update(); } @@ -842,25 +837,24 @@ void sfx_remove_song(SfxState *self, song_handle_t handle) { #define ASSERT_SONG(s) if (!(s)) { warning("Looking up song handle %08lx failed in %s, L%d", handle, __FILE__, __LINE__); return; } -void sfx_song_set_status(SfxState *self, song_handle_t handle, int status) { - song_t *song = song_lib_find(self->_songlib, handle); +void SfxState::sfx_song_set_status(song_handle_t handle, int status) { + song_t *song = song_lib_find(_songlib, handle); ASSERT_SONG(song); #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Setting song status to %d" " (0:stop, 1:play, 2:susp, 3:wait): %08lx\n", status, handle); #endif - _sfx_set_song_status(self, song, status); + setSongStatus(song, status); - _update(self); + update(); } -void sfx_song_set_fade(SfxState *self, song_handle_t handle, - fade_params_t *params) { +void SfxState::sfx_song_set_fade(song_handle_t handle, fade_params_t *params) { #ifdef DEBUG_SONG_API static const char *stopmsg[] = {"??? Should not happen", "Do not stop afterwards", "Stop afterwards"}; #endif - song_t *song = song_lib_find(self->_songlib, handle); + song_t *song = song_lib_find(_songlib, handle); ASSERT_SONG(song); @@ -873,11 +867,11 @@ void sfx_song_set_fade(SfxState *self, song_handle_t handle, SIMSG_SEND_FADE(song->it, params); - _update(self); + update(); } -void sfx_song_renice(SfxState *self, song_handle_t handle, int priority) { - song_t *song = song_lib_find(self->_songlib, handle); +void SfxState::sfx_song_renice(song_handle_t handle, int priority) { + song_t *song = song_lib_find(_songlib, handle); ASSERT_SONG(song); #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] Renicing song %08lx to %d\n", @@ -886,11 +880,11 @@ void sfx_song_renice(SfxState *self, song_handle_t handle, int priority) { song->priority = priority; - _update(self); + update(); } -void sfx_song_set_loops(SfxState *self, song_handle_t handle, int loops) { - song_t *song = song_lib_find(self->_songlib, handle); +void SfxState::sfx_song_set_loops(song_handle_t handle, int loops) { + song_t *song = song_lib_find(_songlib, handle); SongIterator::Message msg = SongIterator::Message(handle, SIMSG_SET_LOOPS(loops)); ASSERT_SONG(song); @@ -906,8 +900,8 @@ void sfx_song_set_loops(SfxState *self, song_handle_t handle, int loops) { player->iterator_message(msg); } -void sfx_song_set_hold(SfxState *self, song_handle_t handle, int hold) { - song_t *song = song_lib_find(self->_songlib, handle); +void SfxState::sfx_song_set_hold(song_handle_t handle, int hold) { + song_t *song = song_lib_find(_songlib, handle); SongIterator::Message msg = SongIterator::Message(handle, SIMSG_SET_HOLD(hold)); ASSERT_SONG(song); @@ -930,7 +924,7 @@ static const int MIDI_cmdlen[16] = {0, 0, 0, 0, 0, 0, 0, 0, static const song_handle_t midi_send_base = 0xffff0000; -Common::Error sfx_send_midi(SfxState *self, song_handle_t handle, int channel, +Common::Error SfxState::sfx_send_midi(song_handle_t handle, int channel, int command, int arg1, int arg2) { byte buffer[5]; @@ -975,22 +969,22 @@ Common::Error sfx_send_midi(SfxState *self, song_handle_t handle, int channel, return Common::kNoError; } -int sfx_get_volume(SfxState *self) { +int SfxState::sfx_get_volume() { warning("FIXME: Implement volume"); return 0; } -void sfx_set_volume(SfxState *self, int volume) { +void SfxState::sfx_set_volume(int volume) { warning("FIXME: Implement volume"); } -void sfx_all_stop(SfxState *self) { +void SfxState::sfx_all_stop() { #ifdef DEBUG_SONG_API fprintf(stderr, "[sfx-core] All stop\n"); #endif - song_lib_free(self->_songlib); - _update(self); + song_lib_free(_songlib); + update(); } } // End of namespace Sci diff --git a/engines/sci/sfx/core.h b/engines/sci/sfx/core.h index 1f2f53a051..2c327e1f6d 100644 --- a/engines/sci/sfx/core.h +++ b/engines/sci/sfx/core.h @@ -58,116 +58,126 @@ public: // FIXME, make private uint _debug; /**< Debug flags */ ResourceSync *_soundSync; /**< Used by kDoSync for speech syncing in CD talkie games */ AudioResource *_audioResource; /**< Used for audio resources in CD talkie games */ -}; - -/***********/ -/* General */ -/***********/ - -/* Initializes the sound engine -** Parameters: (ResourceManager *) resmgr: Resource manager for initialization -** (int) flags: SFX_STATE_FLAG_* -*/ -void sfx_init(SfxState *self, ResourceManager *resmgr, int flags); - -/** Deinitializes the sound subsystem. */ -void sfx_exit(SfxState *self); - -/* Suspends/unsuspends the sound sybsystem -** Parameters: (int) suspend: Whether to suspend (non-null) or to unsuspend -*/ -void sfx_suspend(SfxState *self, int suspend); - -/* Polls the sound server for cues etc. -** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise -** (song_handle_t) *handle: The affected handle -** (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP) -*/ -int sfx_poll(SfxState *self, song_handle_t *handle, int *cue); - -/* Polls the sound server for cues etc. -** Parameters: (song_handle_t) handle: The handle to poll -** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise -** (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP) -*/ -int sfx_poll_specific(SfxState *self, song_handle_t handle, int *cue); - -/* Determines the current global volume settings -** Returns : (int) The global volume, between 0 (silent) and 127 (max. volume) -*/ -int sfx_get_volume(SfxState *self); - -/* Determines the current global volume settings -** Parameters: (int) volume: The new global volume, between 0 and 127 (see above) -*/ -void sfx_set_volume(SfxState *self, int volume); - -/* Stops all songs currently playing, purges song library -*/ -void sfx_all_stop(SfxState *self); - - -/*****************/ -/* Song basics */ -/*****************/ - -/* Adds a song to the internal sound library -** Parameters: (SongIterator *) it: The iterator describing the song -** (int) priority: Initial song priority (higher <-> more important) -** (song_handle_t) handle: The handle to associate with the song -** Returns : (int) 0 on success, nonzero on error -*/ -int sfx_add_song(SfxState *self, SongIterator *it, int priority, song_handle_t handle, int resnum); - - -/* Deletes a song and its associated song iterator from the song queue -** Parameters: (song_handle_t) handle: The song to remove -*/ -void sfx_remove_song(SfxState *self, song_handle_t handle); - - -/**********************/ -/* Song modifications */ -/**********************/ - - -/* Sets the song status, i.e. whether it is playing, suspended, or stopped. -** Parameters: (song_handle_t) handle: Handle of the song to modify -** (int) status: The song status the song should assume -** WAITING and PLAYING are set implicitly and essentially describe the same state -** as far as this function is concerned. -*/ -void sfx_song_set_status(SfxState *self, song_handle_t handle, int status); - -/* Sets the new song priority -** Parameters: (song_handle_t) handle: The handle to modify -** (int) priority: The priority to set -*/ -void sfx_song_renice(SfxState *self, song_handle_t handle, int priority); - -/* Sets the number of loops for the specified song -** Parameters: (song_handle_t) handle: The song handle to reference -** (int) loops: Number of loops to set -*/ -void sfx_song_set_loops(SfxState *self, song_handle_t handle, int loops); - -/* Sets the number of loops for the specified song -** Parameters: (song_handle_t) handle: The song handle to reference -** (int) hold: Number of loops to setn -*/ -void sfx_song_set_hold(SfxState *self, song_handle_t handle, int hold); - -/* Instructs a song to be faded out -** Parameters: (song_handle_t) handle: The song handle to reference -** (fade_params_t *) fade_setup: The precise fade-out configuration to use -*/ -void sfx_song_set_fade(SfxState *self, song_handle_t handle, fade_params_t *fade_setup); - - -// Previously undocumented: -Common::Error sfx_send_midi(SfxState *self, song_handle_t handle, int channel, - int command, int arg1, int arg2); +public: + /***********/ + /* General */ + /***********/ + + /* Initializes the sound engine + ** Parameters: (ResourceManager *) resmgr: Resource manager for initialization + ** (int) flags: SFX_STATE_FLAG_* + */ + void sfx_init(ResourceManager *resmgr, int flags); + + /** Deinitializes the sound subsystem. */ + void sfx_exit(); + + /* Suspends/unsuspends the sound sybsystem + ** Parameters: (int) suspend: Whether to suspend (non-null) or to unsuspend + */ + void sfx_suspend(bool suspend); + + /* Polls the sound server for cues etc. + ** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise + ** (song_handle_t) *handle: The affected handle + ** (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP) + */ + int sfx_poll(song_handle_t *handle, int *cue); + + /* Polls the sound server for cues etc. + ** Parameters: (song_handle_t) handle: The handle to poll + ** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise + ** (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP) + */ + int sfx_poll_specific(song_handle_t handle, int *cue); + + /* Determines the current global volume settings + ** Returns : (int) The global volume, between 0 (silent) and 127 (max. volume) + */ + int sfx_get_volume(); + + /* Determines the current global volume settings + ** Parameters: (int) volume: The new global volume, between 0 and 127 (see above) + */ + void sfx_set_volume(int volume); + + /* Stops all songs currently playing, purges song library + */ + void sfx_all_stop(); + + + /*****************/ + /* Song basics */ + /*****************/ + + /* Adds a song to the internal sound library + ** Parameters: (SongIterator *) it: The iterator describing the song + ** (int) priority: Initial song priority (higher <-> more important) + ** (song_handle_t) handle: The handle to associate with the song + ** Returns : (int) 0 on success, nonzero on error + */ + int sfx_add_song(SongIterator *it, int priority, song_handle_t handle, int resnum); + + + /* Deletes a song and its associated song iterator from the song queue + ** Parameters: (song_handle_t) handle: The song to remove + */ + void sfx_remove_song(song_handle_t handle); + + + /**********************/ + /* Song modifications */ + /**********************/ + + + /* Sets the song status, i.e. whether it is playing, suspended, or stopped. + ** Parameters: (song_handle_t) handle: Handle of the song to modify + ** (int) status: The song status the song should assume + ** WAITING and PLAYING are set implicitly and essentially describe the same state + ** as far as this function is concerned. + */ + void sfx_song_set_status(song_handle_t handle, int status); + + /* Sets the new song priority + ** Parameters: (song_handle_t) handle: The handle to modify + ** (int) priority: The priority to set + */ + void sfx_song_renice(song_handle_t handle, int priority); + + /* Sets the number of loops for the specified song + ** Parameters: (song_handle_t) handle: The song handle to reference + ** (int) loops: Number of loops to set + */ + void sfx_song_set_loops(song_handle_t handle, int loops); + + /* Sets the number of loops for the specified song + ** Parameters: (song_handle_t) handle: The song handle to reference + ** (int) hold: Number of loops to setn + */ + void sfx_song_set_hold(song_handle_t handle, int hold); + + /* Instructs a song to be faded out + ** Parameters: (song_handle_t) handle: The song handle to reference + ** (fade_params_t *) fade_setup: The precise fade-out configuration to use + */ + void sfx_song_set_fade(song_handle_t handle, fade_params_t *fade_setup); + + + // Previously undocumented: + Common::Error sfx_send_midi(song_handle_t handle, int channel, + int command, int arg1, int arg2); + +protected: + void freezeTime(); + void thawTime(); + + bool isPlaying(song_t *song); + void setSongStatus(song_t *song, int status); + void updateSingleSong(); + void updateMultiSong(); + void update(); +}; } // End of namespace Sci |