aboutsummaryrefslogtreecommitdiff
path: root/saga
diff options
context:
space:
mode:
authorEugene Sandulenko2005-06-19 21:18:00 +0000
committerEugene Sandulenko2005-06-19 21:18:00 +0000
commitecf8da7230678466cf56c9c03716723653e7dcd6 (patch)
tree9c4ca7dad27011ba2d40bf001810818f0206979d /saga
parent1844a9c5449108537b5ec19bf618b17420d995aa (diff)
downloadscummvm-rg350-ecf8da7230678466cf56c9c03716723653e7dcd6.tar.gz
scummvm-rg350-ecf8da7230678466cf56c9c03716723653e7dcd6.tar.bz2
scummvm-rg350-ecf8da7230678466cf56c9c03716723653e7dcd6.zip
Implement sfPlayLoopedSound, sfFadeMusic and sfPlayVoice.
sfPlayVoice is untested. Please, inform me where you encounter it. svn-id: r18412
Diffstat (limited to 'saga')
-rw-r--r--saga/music.cpp46
-rw-r--r--saga/music.h9
-rw-r--r--saga/saga.cpp3
-rw-r--r--saga/script.h6
-rw-r--r--saga/sfuncs.cpp55
5 files changed, 94 insertions, 25 deletions
diff --git a/saga/music.cpp b/saga/music.cpp
index c8021fcffe..2ec8e1ed13 100644
--- a/saga/music.cpp
+++ b/saga/music.cpp
@@ -282,7 +282,7 @@ void MusicPlayer::stopMusic() {
Music::Music(Audio::Mixer *mixer, MidiDriver *driver, int enabled) : _mixer(mixer), _enabled(enabled), _adlib(false) {
_player = new MusicPlayer(driver);
_musicInitialized = 1;
- _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
+ _currentVolume = 0;
if (_vm->getGameType() == GType_ITE) {
Common::File file;
@@ -336,6 +336,50 @@ Music::~Music() {
delete _player;
}
+void Music::musicVolumeGaugeCallback(void *refCon) {
+ ((Music *)refCon)->musicVolumeGauge();
+}
+
+void Music::musicVolumeGauge() {
+ int volume;
+
+ _currentVolumePercent += 10;
+
+ if (_currentVolume - _targetVolume > 0) { // Volume decrease
+ volume = _targetVolume + (_currentVolume - _targetVolume) * (100 - _currentVolumePercent) / 100;
+ } else {
+ volume = _currentVolume + (_targetVolume - _currentVolume) * _currentVolumePercent / 100;
+ }
+
+ if (volume < 0)
+ volume = 1;
+
+ _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume);
+ _player->setVolume(volume);
+
+ if (_currentVolumePercent == 100) {
+ Common::g_timer->removeTimerProc(&musicVolumeGaugeCallback);
+ _currentVolume = _targetVolume;
+ }
+}
+
+void Music::setVolume(int volume, int time) {
+ _targetVolume = volume * 2; // ScummVM has different volume scale
+ _currentVolumePercent = 0;
+
+ if (volume == -1) // Set Full volume
+ volume = ConfMan.getInt("music_volume");
+
+ if (time == 1) {
+ _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume);
+ Common::g_timer->removeTimerProc(&musicVolumeGaugeCallback);
+ _currentVolume = volume;
+ return;
+ }
+
+ Common::g_timer->installTimerProc(&musicVolumeGaugeCallback, time * 100L, this);
+}
+
bool Music::isPlaying() {
return _mixer->isSoundHandleActive(_musicHandle) || _player->isPlaying();
}
diff --git a/saga/music.h b/saga/music.h
index 9d9701397f..0a8ac87d64 100644
--- a/saga/music.h
+++ b/saga/music.h
@@ -120,6 +120,8 @@ public:
int resume(void);
int stop(void);
+ void setVolume(int volume, int time);
+
private:
Audio::Mixer *_mixer;
@@ -136,8 +138,15 @@ private:
bool _hasDigiMusic;
bool _adlib;
+ int _targetVolume;
+ int _currentVolume;
+ int _currentVolumePercent;
+
RSCFILE_CONTEXT *_musicContext;
const char *_musicFname;
+
+ static void musicVolumeGaugeCallback(void *refCon);
+ void musicVolumeGauge(void);
};
} // End of namespace Saga
diff --git a/saga/saga.cpp b/saga/saga.cpp
index 168625dbd1..ff6db8fa8a 100644
--- a/saga/saga.cpp
+++ b/saga/saga.cpp
@@ -164,7 +164,6 @@ SagaEngine::SagaEngine(GameDetector *detector, OSystem *syst)
}
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
- _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
_vm = this;
}
@@ -293,6 +292,8 @@ int SagaEngine::init(GameDetector &detector) {
_interface->converseInit();
_script->setVerb(kVerbWalkTo);
+ _music->setVolume(-1, 1);
+
return SUCCESS;
}
diff --git a/saga/script.h b/saga/script.h
index 3a3cafe9bd..4e12131aa9 100644
--- a/saga/script.h
+++ b/saga/script.h
@@ -534,13 +534,13 @@ private:
void sfPuzzleWon(SCRIPTFUNC_PARAMS);
void sfEnableEscape(SCRIPTFUNC_PARAMS);
void sfPlaySound(SCRIPTFUNC_PARAMS);
- void SF_playLoopedSound(SCRIPTFUNC_PARAMS);
+ void sfPlayLoopedSound(SCRIPTFUNC_PARAMS);
void sfGetDeltaFrame(SCRIPTFUNC_PARAMS);
void sfShowProtect(SCRIPTFUNC_PARAMS);
void sfProtectResult(SCRIPTFUNC_PARAMS);
void sfRand(SCRIPTFUNC_PARAMS);
- void SF_fadeMusic(SCRIPTFUNC_PARAMS);
- void SF_playVoice(SCRIPTFUNC_PARAMS);
+ void sfFadeMusic(SCRIPTFUNC_PARAMS);
+ void sfPlayVoice(SCRIPTFUNC_PARAMS);
void SF_stub(SCRIPTFUNC_PARAMS);
};
diff --git a/saga/sfuncs.cpp b/saga/sfuncs.cpp
index cd09a4fd07..8985a2d58c 100644
--- a/saga/sfuncs.cpp
+++ b/saga/sfuncs.cpp
@@ -45,6 +45,8 @@
#include "saga/scene.h"
#include "saga/isomap.h"
+#include "common/config-manager.h"
+
namespace Saga {
#define OPCODE(x) {&Script::x, #x}
@@ -122,13 +124,13 @@ void Script::setupScriptFuncList(void) {
OPCODE(sfPuzzleWon),
OPCODE(sfEnableEscape),
OPCODE(sfPlaySound),
- OPCODE(SF_playLoopedSound),
+ OPCODE(sfPlayLoopedSound),
OPCODE(sfGetDeltaFrame),
OPCODE(sfShowProtect),
OPCODE(sfProtectResult),
OPCODE(sfRand),
- OPCODE(SF_fadeMusic),
- OPCODE(SF_playVoice),
+ OPCODE(sfFadeMusic),
+ OPCODE(sfPlayVoice),
OPCODE(SF_stub),
OPCODE(SF_stub),
OPCODE(SF_stub),
@@ -634,7 +636,7 @@ void Script::SF_cycleColors(SCRIPTFUNC_PARAMS) {
for (int i = 0; i < nArgs; i++)
thread->pop();
- debug(0, "STUB: SF_cycleColors(), %d args", nArgs);
+ error("STUB: SF_cycleColors(), %d args", nArgs);
}
// Script function #25 (0x19)
@@ -1573,10 +1575,12 @@ void Script::sfPlayMusic(SCRIPTFUNC_PARAMS) {
if (_vm->getGameType() == GType_ITE) {
int16 param = thread->pop() + 9;
- if (param >= 9 && param <= 34)
+ if (param >= 9 && param <= 34) {
+ _vm->_music->setVolume(-1, 1);
_vm->_music->play(param);
- else
+ } else {
_vm->_music->stop();
+ }
} else {
int16 param1 = thread->pop();
int16 param2 = thread->pop();
@@ -1591,7 +1595,7 @@ void Script::SF_pickClimbOutPos(SCRIPTFUNC_PARAMS) {
for (int i = 0; i < nArgs; i++)
thread->pop();
- debug(0, "STUB: SF_pickClimbOutPos(), %d args", nArgs);
+ error("STUB: SF_pickClimbOutPos(), %d args", nArgs);
}
// Script function #65 (0x41)
@@ -1599,7 +1603,7 @@ void Script::SF_tossRif(SCRIPTFUNC_PARAMS) {
for (int i = 0; i < nArgs; i++)
thread->pop();
- debug(0, "STUB: SF_tossRif(), %d args", nArgs);
+ error("STUB: SF_tossRif(), %d args", nArgs);
}
// Script function #66 (0x42)
@@ -1607,7 +1611,7 @@ void Script::SF_showControls(SCRIPTFUNC_PARAMS) {
for (int i = 0; i < nArgs; i++)
thread->pop();
- debug(0, "STUB: SF_showControls(), %d args", nArgs);
+ error("STUB: SF_showControls(), %d args", nArgs);
}
// Script function #67 (0x43)
@@ -1718,15 +1722,22 @@ void Script::sfPlaySound(SCRIPTFUNC_PARAMS) {
} else {
_vm->_sound->stopSound();
}
-
}
// Script function #71 (0x47)
-void Script::SF_playLoopedSound(SCRIPTFUNC_PARAMS) {
- for (int i = 0; i < nArgs; i++)
- thread->pop();
+void Script::sfPlayLoopedSound(SCRIPTFUNC_PARAMS) {
+ int16 param = thread->pop();
+ int res;
+
+ if (param < ARRAYSIZE(sfxTable)) {
+ res = sfxTable[param].res;
+ if (_vm->getFeatures() & GF_CD_FX)
+ res -= 14;
- debug(0, "STUB: SF_playLoopedSound(), %d args", nArgs);
+ _vm->_sndRes->playSound(res, sfxTable[param].vol, true);
+ } else {
+ _vm->_sound->stopSound();
+ }
}
// Script function #72 (0x48)
@@ -1775,16 +1786,20 @@ void Script::sfRand(SCRIPTFUNC_PARAMS) {
}
// Script function #76 (0x4c)
-void Script::SF_fadeMusic(SCRIPTFUNC_PARAMS) {
- debug(0, "STUB: SF_fadeMusic()");
+void Script::sfFadeMusic(SCRIPTFUNC_PARAMS) {
+ _vm->_music->setVolume(0, 1000);
}
// Script function #77 (0x4d)
-void Script::SF_playVoice(SCRIPTFUNC_PARAMS) {
- for (int i = 0; i < nArgs; i++)
- thread->pop();
+void Script::sfPlayVoice(SCRIPTFUNC_PARAMS) {
+ int16 param = thread->pop();
- debug(0, "STUB: SF_playVoice(), %d args", nArgs);
+ warning("sfPlayVoice(%d)", param);
+ if (param > 0) {
+ _vm->_sndRes->playVoice(param + 3712);
+ } else {
+ _vm->_sound->stopSound();
+ }
}
void Script::finishDialog(int replyID, int flags, int bitOffset) {