diff options
author | Max Horn | 2009-05-28 22:16:42 +0000 |
---|---|---|
committer | Max Horn | 2009-05-28 22:16:42 +0000 |
commit | 804242ae9fa8b52a09f3dbbf6f76ababb1506390 (patch) | |
tree | 64f995e455d0ce46d625751bfa1230c543143201 /engines/sci/sfx | |
parent | 212271f1cecee7c6c89600cc68b364f991efa2e6 (diff) | |
download | scummvm-rg350-804242ae9fa8b52a09f3dbbf6f76ababb1506390.tar.gz scummvm-rg350-804242ae9fa8b52a09f3dbbf6f76ababb1506390.tar.bz2 scummvm-rg350-804242ae9fa8b52a09f3dbbf6f76ababb1506390.zip |
SCI: Merged NewPlayer and SfxPlayer
svn-id: r40968
Diffstat (limited to 'engines/sci/sfx')
-rw-r--r-- | engines/sci/sfx/core.cpp | 131 | ||||
-rw-r--r-- | engines/sci/sfx/core.h | 31 |
2 files changed, 67 insertions, 95 deletions
diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp index 056dbbb09f..c4862812f6 100644 --- a/engines/sci/sfx/core.cpp +++ b/engines/sci/sfx/core.cpp @@ -54,19 +54,36 @@ public: /** Number of voices that can play simultaneously */ int _polyphony; +protected: + MidiPlayer *_mididrv; + + SongIterator *_iterator; + Audio::Timestamp _wakeupTime; + Audio::Timestamp _currentTime; + uint32 _pauseTimeDiff; + + bool _paused; + bool _iteratorIsDone; + uint32 _tempo; + + Common::Mutex *_mutex; + int _volume; + + void play_song(SongIterator *it); + static void player_timer_callback(void *refCon); + public: - SfxPlayer() : _polyphony(0) {} - virtual ~SfxPlayer() {} + SfxPlayer(); + ~SfxPlayer(); - virtual Common::Error init(ResourceManager *resmgr, int expected_latency) = 0; /* Initializes the player ** Parameters: (ResourceManager *) resmgr: A resource manager for driver initialization ** (int) expected_latency: Expected delay in between calls to 'maintenance' ** (in microseconds) ** Returns : (int) Common::kNoError on success, Common::kUnknownError on failure */ + Common::Error init(ResourceManager *resmgr, int expected_latency); - virtual Common::Error add_iterator(SongIterator *it, uint32 start_time) = 0; /* Adds an iterator to the song player ** Parameters: (songx_iterator_t *) it: The iterator to play ** (uint32) start_time: The time to assume as the @@ -77,13 +94,13 @@ public: ** Implementors may use the 'sfx_iterator_combine()' function ** to add iterators onto their already existing iterators */ + Common::Error add_iterator(SongIterator *it, uint32 start_time); - virtual Common::Error stop() = 0; /* Stops the currently playing song and deletes the associated iterator ** Returns : (int) Common::kNoError on success, Common::kUnknownError on failure */ + Common::Error stop(); - virtual Common::Error iterator_message(const SongIterator::Message &msg) = 0; /* Transmits a song iterator message to the active song ** Parameters: (SongIterator::Message) msg: The message to transmit ** Returns : (int) Common::kNoError on success, Common::kUnknownError on failure @@ -91,64 +108,28 @@ public: ** If this method is not present, sending messages will stop ** and re-start playing, so it is preferred that it is present */ + Common::Error iterator_message(const SongIterator::Message &msg); - virtual Common::Error pause() = 0; /* Pauses song playing ** Returns : (int) Common::kNoError on success, Common::kUnknownError on failure */ + Common::Error pause(); - virtual Common::Error resume() = 0; /* Resumes song playing after a pause ** Returns : (int) Common::kNoError on success, Common::kUnknownError on failure */ + Common::Error resume(); - virtual Common::Error exit() = 0; - /* Stops the player - ** Returns : (int) Common::kNoError on success, Common::kUnknownError on failure - */ - - virtual void tell_synth(int buf_nr, byte *buf) = 0; /* Pass a raw MIDI event to the synth Parameters: (int) argc: Length of buffer holding the midi event (byte *) argv: The buffer itself */ + void tell_synth(int buf_nr, byte *buf); }; -#pragma mark - - -class NewPlayer : public SfxPlayer { -protected: - MidiPlayer *_mididrv; - - SongIterator *_iterator; - Audio::Timestamp _wakeupTime; - Audio::Timestamp _currentTime; - uint32 _pauseTimeDiff; +SfxPlayer::SfxPlayer() { + _polyphony = 0; - bool _paused; - bool _iteratorIsDone; - uint32 _tempo; - - Common::Mutex *_mutex; - int _volume; - - void play_song(SongIterator *it); - static void player_timer_callback(void *refCon); - -public: - NewPlayer(); - - virtual Common::Error init(ResourceManager *resmgr, int expected_latency); - virtual Common::Error add_iterator(SongIterator *it, uint32 start_time); - virtual Common::Error stop(); - virtual Common::Error iterator_message(const SongIterator::Message &msg); - virtual Common::Error pause(); - virtual Common::Error resume(); - virtual Common::Error exit(); - virtual void tell_synth(int buf_nr, byte *buf); -}; - -NewPlayer::NewPlayer() { _mididrv = 0; _iterator = NULL; @@ -162,7 +143,17 @@ NewPlayer::NewPlayer() { _volume = 15; } -void NewPlayer::play_song(SongIterator *it) { +SfxPlayer::~SfxPlayer() { + if (_mididrv) { + _mididrv->close(); + delete _mididrv; + } + delete _mutex; + delete _iterator; + _iterator = NULL; +} + +void SfxPlayer::play_song(SongIterator *it) { while (_iterator && _wakeupTime.msecsDiff(_currentTime) <= 0) { int delay; byte buf[8]; @@ -201,15 +192,15 @@ void NewPlayer::play_song(SongIterator *it) { } } -void NewPlayer::tell_synth(int buf_nr, byte *buf) { +void SfxPlayer::tell_synth(int buf_nr, byte *buf) { byte op1 = (buf_nr < 2 ? 0 : buf[1]); byte op2 = (buf_nr < 3 ? 0 : buf[2]); static_cast<MidiDriver *>(_mididrv)->send(buf[0], op1, op2); } -void NewPlayer::player_timer_callback(void *refCon) { - NewPlayer *thePlayer = (NewPlayer *)refCon; +void SfxPlayer::player_timer_callback(void *refCon) { + SfxPlayer *thePlayer = (SfxPlayer *)refCon; assert(refCon); Common::StackLock lock(*thePlayer->_mutex); @@ -222,7 +213,7 @@ void NewPlayer::player_timer_callback(void *refCon) { /* API implementation */ -Common::Error NewPlayer::init(ResourceManager *resmgr, int expected_latency) { +Common::Error SfxPlayer::init(ResourceManager *resmgr, int expected_latency) { MidiDriverType musicDriver = MidiDriver::detectMusicDriver(MDT_PCSPK | MDT_ADLIB); switch(musicDriver) { @@ -257,7 +248,7 @@ Common::Error NewPlayer::init(ResourceManager *resmgr, int expected_latency) { return Common::kNoError; } -Common::Error NewPlayer::add_iterator(SongIterator *it, uint32 start_time) { +Common::Error SfxPlayer::add_iterator(SongIterator *it, uint32 start_time) { Common::StackLock lock(*_mutex); SIMSG_SEND(it, SIMSG_SET_PLAYMASK(_mididrv->getPlayMask())); SIMSG_SEND(it, SIMSG_SET_RHYTHM(_mididrv->hasRhythmChannel())); @@ -274,7 +265,7 @@ Common::Error NewPlayer::add_iterator(SongIterator *it, uint32 start_time) { return Common::kNoError; } -Common::Error NewPlayer::stop(void) { +Common::Error SfxPlayer::stop() { debug(3, "Player: Stopping song iterator %p", (void *)_iterator); Common::StackLock lock(*_mutex); delete _iterator; @@ -285,7 +276,7 @@ Common::Error NewPlayer::stop(void) { return Common::kNoError; } -Common::Error NewPlayer::iterator_message(const SongIterator::Message &msg) { +Common::Error SfxPlayer::iterator_message(const SongIterator::Message &msg) { Common::StackLock lock(*_mutex); if (!_iterator) { return Common::kUnknownError; @@ -296,7 +287,7 @@ Common::Error NewPlayer::iterator_message(const SongIterator::Message &msg) { return Common::kNoError; } -Common::Error NewPlayer::pause(void) { +Common::Error SfxPlayer::pause() { Common::StackLock lock(*_mutex); _paused = true; @@ -307,7 +298,7 @@ Common::Error NewPlayer::pause(void) { return Common::kNoError; } -Common::Error NewPlayer::resume(void) { +Common::Error SfxPlayer::resume() { Common::StackLock lock(*_mutex); _wakeupTime = Audio::Timestamp(_currentTime.msecs() + _pauseTimeDiff, SFX_TICKS_PER_SEC); @@ -317,16 +308,6 @@ Common::Error NewPlayer::resume(void) { return Common::kNoError; } -Common::Error NewPlayer::exit(void) { - _mididrv->close(); - delete _mididrv; - delete _mutex; - delete _iterator; - _iterator = NULL; - - return Common::kNoError; -} - #pragma mark - @@ -661,7 +642,7 @@ void sfx_init(SfxState *self, ResourceManager *resmgr, int flags) { return; } - player = new NewPlayer(); + player = new SfxPlayer(); if (!player) { sciprintf("[SFX] No song player found\n"); @@ -680,11 +661,8 @@ void sfx_exit(SfxState *self) { fprintf(stderr, "[sfx-core] Uninitialising\n"); #endif - if (player) { - player->exit(); - delete player; - player = 0; - } + delete player; + player = 0; g_system->getMixer()->stopAll(); @@ -723,11 +701,6 @@ void sfx_suspend(SfxState *self, int suspend) { } int sfx_poll(SfxState *self, song_handle_t *handle, int *cue) { -/* 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) -*/ if (!self->_song) return 0; /* No milk today */ diff --git a/engines/sci/sfx/core.h b/engines/sci/sfx/core.h index a65197a2e7..1f2f53a051 100644 --- a/engines/sci/sfx/core.h +++ b/engines/sci/sfx/core.h @@ -64,67 +64,66 @@ public: // FIXME, make private /* General */ /***********/ -void sfx_init(SfxState *self, ResourceManager *resmgr, int flags); /* 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); -/* Deinitializes the sound subsystem -*/ -void sfx_suspend(SfxState *self, int suspend); /* Suspends/unsuspends the sound sybsystem ** Parameters: (int) suspend: Whether to suspend (non-null) or to unsuspend */ +void sfx_suspend(SfxState *self, int suspend); -int sfx_poll(SfxState *self, song_handle_t *handle, int *cue); /* 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); -int sfx_poll_specific(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); -int sfx_get_volume(SfxState *self); /* Determines the current global volume settings ** Returns : (int) The global volume, between 0 (silent) and 127 (max. volume) */ +int sfx_get_volume(SfxState *self); -void sfx_set_volume(SfxState *self, int volume); /* 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); -void sfx_all_stop(SfxState *self); /* Stops all songs currently playing, purges song library */ +void sfx_all_stop(SfxState *self); /*****************/ /* Song basics */ /*****************/ -int sfx_add_song(SfxState *self, SongIterator *it, int priority, song_handle_t handle, int resnum); /* 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); -void sfx_remove_song(SfxState *self, song_handle_t handle); /* 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); /**********************/ @@ -132,37 +131,37 @@ void sfx_remove_song(SfxState *self, song_handle_t handle); /**********************/ -void sfx_song_set_status(SfxState *self, song_handle_t handle, int status); /* 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); -void sfx_song_renice(SfxState *self, song_handle_t handle, int priority); /* 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); -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) loops: Number of loops to set */ +void sfx_song_set_loops(SfxState *self, song_handle_t handle, int loops); -void sfx_song_set_hold(SfxState *self, song_handle_t handle, int hold); /* 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); -void sfx_song_set_fade(SfxState *self, song_handle_t handle, fade_params_t *fade_setup); /* 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: |