aboutsummaryrefslogtreecommitdiff
path: root/engines/scumm/player_v4a.cpp
diff options
context:
space:
mode:
authorNorbert Lange2009-08-01 16:10:00 +0000
committerNorbert Lange2009-08-01 16:10:00 +0000
commit27ee1eb33179aa2cae92a9790867bfa5eaa0e471 (patch)
tree7bcd54e8db2a86bf73df5755ad8ae85d0ca4e456 /engines/scumm/player_v4a.cpp
parent1becc072f91994425abc9d9e8a3759fc45f63017 (diff)
downloadscummvm-rg350-27ee1eb33179aa2cae92a9790867bfa5eaa0e471.tar.gz
scummvm-rg350-27ee1eb33179aa2cae92a9790867bfa5eaa0e471.tar.bz2
scummvm-rg350-27ee1eb33179aa2cae92a9790867bfa5eaa0e471.zip
refactored and commented player_va4 a bit
fix waitcommand in Tfmx try making tfmxplayer compile again svn-id: r42976
Diffstat (limited to 'engines/scumm/player_v4a.cpp')
-rw-r--r--engines/scumm/player_v4a.cpp72
1 files changed, 36 insertions, 36 deletions
diff --git a/engines/scumm/player_v4a.cpp b/engines/scumm/player_v4a.cpp
index 7c2b17ac3c..649f198f70 100644
--- a/engines/scumm/player_v4a.cpp
+++ b/engines/scumm/player_v4a.cpp
@@ -33,8 +33,9 @@
namespace Scumm {
Player_V4A::Player_V4A(ScummEngine *scumm, Audio::Mixer *mixer)
- : _vm(scumm), _mixer(mixer), _musicId(), _sfxSlots(), _tfmxPlay(0), _tfmxSfx(0), _musicHandle(), _sfxHandle() {
- init();
+ : _vm(scumm), _mixer(mixer), _musicId(), _sfxSlots(), _initState(0), _tfmxMusic(0), _tfmxSfx(0), _musicHandle(), _sfxHandle(), _signal(0) {
+ assert(scumm);
+ assert(mixer);
}
bool Player_V4A::init() {
@@ -49,8 +50,8 @@ bool Player_V4A::init() {
if (mdatExists && sampleExists) {
Audio::Tfmx *play = new Audio::Tfmx(_mixer->getOutputRate(), true);
if (play->load(fileMdat, fileSample)) {
- play->setSignalPtr(_signal, ARRAYSIZE(_signal));
- _tfmxPlay = play;
+ play->setSignalPtr(&_signal, 1);
+ _tfmxMusic = play;
} else
delete play;
@@ -62,13 +63,13 @@ bool Player_V4A::init() {
} else
delete play;
}
- return _tfmxPlay != 0;
+ return _tfmxMusic != 0;
}
Player_V4A::~Player_V4A() {
_mixer->stopHandle(_musicHandle);
_mixer->stopHandle(_sfxHandle);
- delete _tfmxPlay;
+ delete _tfmxMusic;
delete _tfmxSfx;
}
@@ -78,9 +79,9 @@ void Player_V4A::setMusicVolume(int vol) {
void Player_V4A::stopAllSounds() {
debug(5, "player_v4a: stopAllSounds");
- if (_tfmxPlay) {
- _tfmxPlay->stopSong();
- _signal[0] = 0;
+ if (_tfmxMusic) {
+ _tfmxMusic->stopSong();
+ _signal = 0;
}
_musicId = 0;
if (_tfmxSfx)
@@ -94,8 +95,8 @@ void Player_V4A::stopSound(int nr) {
return;
if (nr == _musicId) {
_musicId = 0;
- _tfmxPlay->stopSong();
- _signal[0] = 0;
+ _tfmxMusic->stopSong();
+ _signal = 0;
} else {
const int chan = getSfxChan(nr);
if (chan != -1) {
@@ -106,10 +107,6 @@ void Player_V4A::stopSound(int nr) {
}
void Player_V4A::startSound(int nr) {
- assert(_vm);
- const byte *ptr = _vm->getResourceAddress(rtSound, nr);
- assert(ptr);
-
static const int8 monkeyCommands[52] = {
-1, -2, -3, -4, -5, -6, -7, -8,
-9, -10, -11, -12, -13, -14, 18, 17,
@@ -120,67 +117,70 @@ void Player_V4A::startSound(int nr) {
6, 13, 9, 19
};
+ const byte *ptr = _vm->getResourceAddress(rtSound, nr);
+ assert(ptr);
+
const int val = ptr[9];
if (val < 0 || val >= ARRAYSIZE(monkeyCommands)) {
warning("player_v4a: illegal Songnumber %i", val);
return;
}
- if (!_tfmxSfx || !_tfmxPlay)
+ if (!_initState)
+ _initState = init() ? 1 : -1;
+
+ if (_initState <= 0)
return;
int index = monkeyCommands[val];
const byte type = ptr[6];
- if (index < 0) {
- // SoundFX
+ if (index < 0) { // SoundFX
index = -index - 1;
debug(3, "player_v4a: play %d: custom %i - %02X", nr, index, type);
+ // start an empty Song so timing is setup
if (_tfmxSfx->getSongIndex() < 0)
_tfmxSfx->doSong(0x18);
+
const int chan = _tfmxSfx->doSfx((uint16)index);
if (chan >= 0 && chan < ARRAYSIZE(_sfxSlots))
setSfxSlot(chan, nr, type);
else
warning("player_v4a: custom %i is not of required type", index);
+ // the Tfmx-player newer "ends" the output by itself, so this should be threadsafe
if (!_mixer->isSoundHandleActive(_sfxHandle))
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, _tfmxSfx, -1, Audio::Mixer::kMaxChannelVolume, 0, false);
- } else {
- // Song
+
+ } else { // Song
debug(3, "player_v4a: play %d: song %i - %02X", nr, index, type);
if (ptr[6] != 0x7F)
warning("player_v4a: Song has wrong type");
- _tfmxPlay->doSong(index);
- _signal[0] = 2;
+ _tfmxMusic->doSong(index);
+ _signal = 2;
_musicId = nr;
+ // the Tfmx-player newer "ends" the output by itself, so this should be threadsafe
if (!_mixer->isSoundHandleActive(_musicHandle))
- _mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, _tfmxPlay, -1, Audio::Mixer::kMaxChannelVolume, 0, false);
+ _mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, _tfmxMusic, -1, Audio::Mixer::kMaxChannelVolume, 0, false);
}
}
int Player_V4A::getMusicTimer() const {
if (_musicId) {
- // TODO: The titlesong is running with ~70 ticks per second and the scale seems to be based on that.
- // Other songs dont and I have no clue if this scalevalue is anything close to correct for them.
- // The Amiga-Game doesnt counts the ticks of the song, but has an own timer and I hope thespeed is constant through the game
- const int magicScale = 357; // ~ 1000 * 25 * (10173 / 709379.0)
- return (_mixer->getSoundElapsedTime(_musicHandle)) / magicScale;
+ // The titlesong (and a few others) is running with ~70 ticks per second and the scale seems to be based on that.
+ // The Game itself doesnt get the timing from the Tfmx Player however, so we just use the elapsed time
+ // 357 ~ 1000 * 25 * (1 / 70)
+ return (_mixer->getSoundElapsedTime(_musicHandle)) / 357;
}
return 0;
}
int Player_V4A::getSoundStatus(int nr) const {
- bool a = nr == _musicId;
- bool b = _tfmxPlay->getSongIndex() >= 0;
- int c = _signal[0];
-
- debug(5, "player_v4a: getSoundStatus music=%d, active=%d, signal=%d", a, b, c);
- if (nr == _musicId)
- return _signal[0];
- return 0;
+ // For music the game queues a variable the Tfmx Player sets through a special command.
+ // For sfx there seems to be no way to queue them, and the game doesnt try to.
+ return (nr == _musicId) ? _signal : 0;
}
} // End of namespace Scumm