diff options
author | Max Horn | 2009-10-13 18:51:59 +0000 |
---|---|---|
committer | Max Horn | 2009-10-13 18:51:59 +0000 |
commit | 8191c04056ea65169e04957d00da11550b3495e3 (patch) | |
tree | eb140d5afce8247ddc67ffa1fed868a69bf47f0f /engines | |
parent | 581b819c25e9cf0700f36dd3cf22818db30f9420 (diff) | |
download | scummvm-rg350-8191c04056ea65169e04957d00da11550b3495e3.tar.gz scummvm-rg350-8191c04056ea65169e04957d00da11550b3495e3.tar.bz2 scummvm-rg350-8191c04056ea65169e04957d00da11550b3495e3.zip |
SCI: Merge some sfx related global funcs into SfxState.
This allows us to get rid of "static SfxPlayer *s_player".
svn-id: r45038
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/engine/ksound.cpp | 4 | ||||
-rw-r--r-- | engines/sci/engine/vm.cpp | 2 | ||||
-rw-r--r-- | engines/sci/sci.h | 1 | ||||
-rw-r--r-- | engines/sci/sfx/core.cpp | 83 | ||||
-rw-r--r-- | engines/sci/sfx/core.h | 24 | ||||
-rw-r--r-- | engines/sci/sfx/iterator.cpp | 10 | ||||
-rw-r--r-- | engines/sci/sfx/misc.h | 16 |
7 files changed, 75 insertions, 65 deletions
diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp index 8daaf6f22a..a70cb1a2ea 100644 --- a/engines/sci/engine/ksound.cpp +++ b/engines/sci/engine/ksound.cpp @@ -377,7 +377,7 @@ static reg_t kDoSoundSci0(EngineState *s, int argc, reg_t *argv) { break; case _K_SCI0_SOUND_GET_POLYPHONY: - s->r_acc = make_reg(0, sfx_get_player_polyphony()); + s->r_acc = make_reg(0, s->_sound.sfx_get_player_polyphony()); break; case _K_SCI0_SOUND_PLAY_NEXT: @@ -495,7 +495,7 @@ static reg_t kDoSoundSci1Early(EngineState *s, int argc, reg_t *argv) { break; } case _K_SCI01_SOUND_GET_POLYPHONY : { - s->r_acc = make_reg(0, sfx_get_player_polyphony()); + s->r_acc = make_reg(0, s->_sound.sfx_get_player_polyphony()); break; } case _K_SCI01_SOUND_PLAY_HANDLE : { diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index dacda2b644..f534a1945d 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -1765,7 +1765,7 @@ static EngineState *_game_run(EngineState *&s, int restoring) { script_free_engine(s); script_init_engine(s); game_init(s); - sfx_reset_player(); + s->_sound.sfx_reset_player(); _init_stack_base_with_selector(s, s->_kernel->_selectorCache.play); send_selector(s, s->game_obj, s->game_obj, s->stack_base, 2, s->stack_base); diff --git a/engines/sci/sci.h b/engines/sci/sci.h index 2acfdf730f..884e895ffe 100644 --- a/engines/sci/sci.h +++ b/engines/sci/sci.h @@ -112,6 +112,7 @@ public: uint32 getFlags() const; ResourceManager *getResourceManager() const { return _resMan; } Kernel *getKernel() const { return _kernel; } + EngineState *getEngineState() const { return _gamestate; } Vocabulary *getVocabulary() const { return _vocabulary; } Common::String getSavegameName(int nr) const; diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp index 643d919da1..6222101d65 100644 --- a/engines/sci/sfx/core.cpp +++ b/engines/sci/sfx/core.cpp @@ -43,10 +43,6 @@ namespace Sci { -class SfxPlayer; -static SfxPlayer *s_player = NULL; // FIXME: Avoid non-const global vars - - /* Plays a song iterator that found a PCM through a PCM device, if possible ** Parameters: (SongIterator *) it: The iterator to play ** (SongHandle) handle: Debug handle @@ -326,24 +322,25 @@ int sfx_pcm_available() { return g_system->getMixer()->isReady(); } -void sfx_reset_player() { - if (s_player) - s_player->stop(); +void SfxState::sfx_reset_player() { + if (_player) + _player->stop(); } -void sfx_player_tell_synth(int buf_nr, byte *buf) { - if (s_player) - s_player->tell_synth(buf_nr, buf); +void SfxState::sfx_player_tell_synth(int buf_nr, byte *buf) { + if (_player) + _player->tell_synth(buf_nr, buf); } -int sfx_get_player_polyphony() { - if (s_player) - return s_player->_polyphony; +int SfxState::sfx_get_player_polyphony() { + if (_player) + return _player->_polyphony; else return 0; } SfxState::SfxState() { + _player = NULL; _it = NULL; _flags = 0; _song = NULL; @@ -421,9 +418,9 @@ static void _dump_songs(SfxState *self) { song = song->_next; } - if (s_player) { + if (self->_player) { fprintf(stderr, "Audio iterator:\n"); - s_player->iterator_message(SongIterator::Message(0, SIMSG_PRINT(1))); + self->_player->iterator_message(SongIterator::Message(0, SIMSG_PRINT(1))); } } #endif @@ -491,8 +488,8 @@ void SfxState::updateSingleSong() { if (newsong != _song) { freezeTime(); /* Store song delay time */ - if (s_player) - s_player->stop(); + if (_player) + _player->stop(); if (newsong) { if (!newsong->_it) @@ -533,10 +530,10 @@ void SfxState::updateSingleSong() { _song = newsong; thawTime(); /* Recover song delay time */ - if (newsong && s_player) { + if (newsong && _player) { SongIterator *clonesong = newsong->_it->clone(newsong->_delay); - s_player->add_iterator(clonesong, newsong->_wakeupTime.msecs()); + _player->add_iterator(clonesong, newsong->_wakeupTime.msecs()); } } } @@ -595,17 +592,17 @@ void SfxState::updateMultiSong() { setSongStatus(oldseeker, SOUND_STATUS_SUSPENDED); debugC(2, kDebugLevelSound, "[SFX] Stopping song %lx\n", oldseeker->_handle); - if (s_player && oldseeker->_it) - s_player->iterator_message(SongIterator::Message(oldseeker->_it->ID, SIMSG_STOP)); + if (_player && oldseeker->_it) + _player->iterator_message(SongIterator::Message(oldseeker->_it->ID, SIMSG_STOP)); oldseeker->_nextPlaying = NULL; /* Clear this pointer; we don't need the tag anymore */ } for (newseeker = newsong; newseeker; newseeker = newseeker->_nextPlaying) { - if (newseeker->_status != SOUND_STATUS_PLAYING && s_player) { + if (newseeker->_status != SOUND_STATUS_PLAYING && _player) { debugC(2, kDebugLevelSound, "[SFX] Adding song %lx\n", newseeker->_it->ID); SongIterator *clonesong = newseeker->_it->clone(newseeker->_delay); - s_player->add_iterator(clonesong, g_system->getMillis()); + _player->add_iterator(clonesong, g_system->getMillis()); } setSongStatus(newseeker, SOUND_STATUS_PLAYING); } @@ -646,7 +643,7 @@ void SfxState::sfx_init(ResourceManager *resMan, int flags) { _syncResource = NULL; _syncOffset = 0; - s_player = NULL; + _player = NULL; if (flags & SFX_STATE_FLAG_NOSOUND) { warning("[SFX] Sound disabled"); @@ -666,17 +663,17 @@ void SfxState::sfx_init(ResourceManager *resMan, int flags) { return; } - s_player = new SfxPlayer(); + _player = new SfxPlayer(); - if (!s_player) { + if (!_player) { warning("[SFX] No song player found"); return; } - if (s_player->init(resMan, DELAY / 1000)) { + if (_player->init(resMan, DELAY / 1000)) { warning("[SFX] Song player reported error, disabled"); - delete s_player; - s_player = NULL; + delete _player; + _player = NULL; } _resMan = resMan; @@ -687,8 +684,8 @@ void SfxState::sfx_exit() { fprintf(stderr, "[sfx-core] Uninitialising\n"); #endif - delete s_player; - s_player = 0; + delete _player; + _player = 0; g_system->getMixer()->stopAll(); @@ -703,16 +700,16 @@ void SfxState::sfx_suspend(bool suspend) { /* suspend */ freezeTime(); - if (s_player) - s_player->pause(); + if (_player) + _player->pause(); /* Suspend song player */ } else if (!suspend && (_suspended)) { /* unsuspend */ thawTime(); - if (s_player) - s_player->resume(); + if (_player) + _player->resume(); /* Unsuspend song player */ } @@ -804,8 +801,8 @@ void SfxState::sfx_add_song(SongIterator *it, int priority, SongHandle handle, i /* Tell player to shut up */ // _dump_songs(this); - if (s_player) - s_player->iterator_message(SongIterator::Message(handle, SIMSG_STOP)); + if (_player) + _player->iterator_message(SongIterator::Message(handle, SIMSG_STOP)); if (song) { setSongStatus( song, SOUND_STATUS_STOPPED); @@ -911,9 +908,9 @@ void SfxState::sfx_song_set_loops(SongHandle handle, int loops) { #endif songit_handle_message(&(song->_it), msg); - if (s_player/* && s_player->send_iterator_message*/) + if (_player/* && _player->send_iterator_message*/) /* FIXME: The above should be optional! */ - s_player->iterator_message(msg); + _player->iterator_message(msg); } void SfxState::sfx_song_set_hold(SongHandle handle, int hold) { @@ -928,9 +925,9 @@ void SfxState::sfx_song_set_hold(SongHandle handle, int hold) { #endif songit_handle_message(&(song->_it), msg); - if (s_player/* && s_player->send_iterator_message*/) + if (_player/* && _player->send_iterator_message*/) /* FIXME: The above should be optional! */ - s_player->iterator_message(msg); + _player->iterator_message(msg); } /* Different from the one in iterator.c */ @@ -979,8 +976,8 @@ Common::Error SfxState::sfx_send_midi(SongHandle handle, int channel, return Common::kUnknownError; } - if (s_player) - s_player->tell_synth(MIDI_cmdlen[command >> 4], buffer); + if (_player) + _player->tell_synth(MIDI_cmdlen[command >> 4], buffer); return Common::kNoError; } diff --git a/engines/sci/sfx/core.h b/engines/sci/sfx/core.h index 3cf958f073..0a80d1fe1a 100644 --- a/engines/sci/sfx/core.h +++ b/engines/sci/sfx/core.h @@ -33,6 +33,7 @@ namespace Sci { +class SfxPlayer; class SongIterator; struct fade_params_t; @@ -44,6 +45,9 @@ struct fade_params_t; #define SFX_STATE_FLAG_NOSOUND (1 << 1) /* Completely disable sound playing */ class SfxState { +private: + SfxPlayer *_player; + public: // FIXME, make private SongIterator *_it; /**< The song iterator at the heart of things */ uint _flags; /**< SFX_STATE_FLAG_* */ @@ -174,6 +178,26 @@ public: void pauseAudio() { g_system->getMixer()->pauseHandle(_audioHandle, true); } void resumeAudio() { g_system->getMixer()->pauseHandle(_audioHandle, false); } + // misc + + /** + * Determines the polyphony of the player in use. + * @return Number of voices the active player can emit + */ + int sfx_get_player_polyphony(); + + /** + * Tells the player to stop its internal iterator. + */ + void sfx_reset_player(); + + /** + * Pass a raw MIDI event to the synth of the player. + * @param argc Length of buffer holding the midi event + * @param argv The buffer itself + */ + void sfx_player_tell_synth(int buf_nr, byte *buf); + protected: void freezeTime(); void thawTime(); diff --git a/engines/sci/sfx/iterator.cpp b/engines/sci/sfx/iterator.cpp index 86a1e1c14b..5c458b4200 100644 --- a/engines/sci/sfx/iterator.cpp +++ b/engines/sci/sfx/iterator.cpp @@ -29,7 +29,8 @@ #include "sci/sci.h" #include "sci/sfx/iterator_internal.h" -#include "sci/sfx/misc.h" // for sfx_player_tell_synth +#include "sci/engine/state.h" // for sfx_player_tell_synth :/ +#include "sci/sfx/core.h" // for sfx_player_tell_synth #include "sci/tools.h" #include "sound/audiostream.h" @@ -130,17 +131,20 @@ void SongIteratorChannel::init(int id_, int offset_, int end_) { void SongIteratorChannel::resetSynthChannels() { byte buf[5]; + // FIXME: Evil hack + SfxState &sound = ((SciEngine*)g_engine)->getEngineState()->_sound; + for (int i = 0; i < MIDI_CHANNELS; i++) { if (playmask & (1 << i)) { buf[0] = 0xe0 | i; /* Pitch bend */ buf[1] = 0x80; /* Wheel center */ buf[2] = 0x40; - sfx_player_tell_synth(3, buf); + sound.sfx_player_tell_synth(3, buf); buf[0] = 0xb0 | i; // Set control buf[1] = 0x40; // Hold pedal buf[2] = 0x00; // Off - sfx_player_tell_synth(3, buf); + sound.sfx_player_tell_synth(3, buf); /* TODO: Reset other controls? */ } } diff --git a/engines/sci/sfx/misc.h b/engines/sci/sfx/misc.h index 40daec4a4d..ce2673a737 100644 --- a/engines/sci/sfx/misc.h +++ b/engines/sci/sfx/misc.h @@ -30,22 +30,6 @@ namespace Sci { class SongIterator; -int sfx_get_player_polyphony(); -/* Determines the polyphony of the player in use -** Returns : (int) Number of voices the active player can emit -*/ - -void sfx_reset_player(); -/* Tells the player to stop its internal iterator -** Parameters: None. -** Returns: Nothing. - */ - -void sfx_player_tell_synth(int buf_nr, byte *buf); -/* Pass a raw MIDI event to the synth of the player -Parameters: (int) argc: Length of buffer holding the midi event - (byte *) argv: The buffer itself -*/ SongIterator *sfx_iterator_combine(SongIterator *it1, SongIterator *it2); |