[Scummvm-cvs-logs] SF.net SVN: scummvm:[45038] scummvm/trunk/engines/sci
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Tue Oct 13 20:52:00 CEST 2009
Revision: 45038
http://scummvm.svn.sourceforge.net/scummvm/?rev=45038&view=rev
Author: fingolfin
Date: 2009-10-13 18:51:59 +0000 (Tue, 13 Oct 2009)
Log Message:
-----------
SCI: Merge some sfx related global funcs into SfxState.
This allows us to get rid of "static SfxPlayer *s_player".
Modified Paths:
--------------
scummvm/trunk/engines/sci/engine/ksound.cpp
scummvm/trunk/engines/sci/engine/vm.cpp
scummvm/trunk/engines/sci/sci.h
scummvm/trunk/engines/sci/sfx/core.cpp
scummvm/trunk/engines/sci/sfx/core.h
scummvm/trunk/engines/sci/sfx/iterator.cpp
scummvm/trunk/engines/sci/sfx/misc.h
Modified: scummvm/trunk/engines/sci/engine/ksound.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/ksound.cpp 2009-10-13 18:51:14 UTC (rev 45037)
+++ scummvm/trunk/engines/sci/engine/ksound.cpp 2009-10-13 18:51:59 UTC (rev 45038)
@@ -377,7 +377,7 @@
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 @@
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 : {
Modified: scummvm/trunk/engines/sci/engine/vm.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.cpp 2009-10-13 18:51:14 UTC (rev 45037)
+++ scummvm/trunk/engines/sci/engine/vm.cpp 2009-10-13 18:51:59 UTC (rev 45038)
@@ -1765,7 +1765,7 @@
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);
Modified: scummvm/trunk/engines/sci/sci.h
===================================================================
--- scummvm/trunk/engines/sci/sci.h 2009-10-13 18:51:14 UTC (rev 45037)
+++ scummvm/trunk/engines/sci/sci.h 2009-10-13 18:51:59 UTC (rev 45038)
@@ -112,6 +112,7 @@
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;
Modified: scummvm/trunk/engines/sci/sfx/core.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/core.cpp 2009-10-13 18:51:14 UTC (rev 45037)
+++ scummvm/trunk/engines/sci/sfx/core.cpp 2009-10-13 18:51:59 UTC (rev 45038)
@@ -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 @@
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 @@
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 @@
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 @@
_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 @@
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 @@
_syncResource = NULL;
_syncOffset = 0;
- s_player = NULL;
+ _player = NULL;
if (flags & SFX_STATE_FLAG_NOSOUND) {
warning("[SFX] Sound disabled");
@@ -666,17 +663,17 @@
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 @@
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 @@
/* 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 @@
/* 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 @@
#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 @@
#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 @@
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;
}
Modified: scummvm/trunk/engines/sci/sfx/core.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/core.h 2009-10-13 18:51:14 UTC (rev 45037)
+++ scummvm/trunk/engines/sci/sfx/core.h 2009-10-13 18:51:59 UTC (rev 45038)
@@ -33,6 +33,7 @@
namespace Sci {
+class SfxPlayer;
class SongIterator;
struct fade_params_t;
@@ -44,6 +45,9 @@
#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 @@
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();
Modified: scummvm/trunk/engines/sci/sfx/iterator.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/iterator.cpp 2009-10-13 18:51:14 UTC (rev 45037)
+++ scummvm/trunk/engines/sci/sfx/iterator.cpp 2009-10-13 18:51:59 UTC (rev 45038)
@@ -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::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? */
}
}
Modified: scummvm/trunk/engines/sci/sfx/misc.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/misc.h 2009-10-13 18:51:14 UTC (rev 45037)
+++ scummvm/trunk/engines/sci/sfx/misc.h 2009-10-13 18:51:59 UTC (rev 45038)
@@ -30,24 +30,8 @@
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);
/* Combines two song iterators into one
** Parameters: (sfx_iterator_t *) it1: One of the two iterators, or NULL
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