[Scummvm-cvs-logs] SF.net SVN: scummvm:[40968] scummvm/trunk/engines/sci/sfx

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri May 29 00:16:42 CEST 2009


Revision: 40968
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40968&view=rev
Author:   fingolfin
Date:     2009-05-28 22:16:42 +0000 (Thu, 28 May 2009)

Log Message:
-----------
SCI: Merged NewPlayer and SfxPlayer

Modified Paths:
--------------
    scummvm/trunk/engines/sci/sfx/core.cpp
    scummvm/trunk/engines/sci/sfx/core.h

Modified: scummvm/trunk/engines/sci/sfx/core.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/core.cpp	2009-05-28 22:13:17 UTC (rev 40967)
+++ scummvm/trunk/engines/sci/sfx/core.cpp	2009-05-28 22:16:42 UTC (rev 40968)
@@ -54,19 +54,36 @@
 	/** 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 @@
 	** 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 @@
 	** 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 -
+SfxPlayer::SfxPlayer() {
+	_polyphony = 0;
 
-class NewPlayer : public SfxPlayer {
-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:
-	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 @@
 	_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::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 @@
 
 /* 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 @@
 	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 @@
 	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 @@
 	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 @@
 	return Common::kNoError;
 }
 
-Common::Error NewPlayer::pause(void) {
+Common::Error SfxPlayer::pause() {
 	Common::StackLock lock(*_mutex);
 
 	_paused = true;
@@ -307,7 +298,7 @@
 	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,17 +308,7 @@
 	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 @@
 		return;
 	}
 
-	player = new NewPlayer();
+	player = new SfxPlayer();
 
 	if (!player) {
 		sciprintf("[SFX] No song player found\n");
@@ -680,11 +661,8 @@
 	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 @@
 }
 
 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 */
 

Modified: scummvm/trunk/engines/sci/sfx/core.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/core.h	2009-05-28 22:13:17 UTC (rev 40967)
+++ scummvm/trunk/engines/sci/sfx/core.h	2009-05-28 22:16:42 UTC (rev 40968)
@@ -64,67 +64,66 @@
 /* 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_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:


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list