aboutsummaryrefslogtreecommitdiff
path: root/engines/illusions
diff options
context:
space:
mode:
authorjohndoe1232014-04-18 23:12:10 +0200
committerEugene Sandulenko2018-07-20 06:43:33 +0000
commit9885a050f2e9b718e3fb7bab224dcfdc18292231 (patch)
treee2190c88225d8a8a22501374ebe9971eb040cc51 /engines/illusions
parentd57ae261791f17c8c83f51c8327d908b32afad3b (diff)
downloadscummvm-rg350-9885a050f2e9b718e3fb7bab224dcfdc18292231.tar.gz
scummvm-rg350-9885a050f2e9b718e3fb7bab224dcfdc18292231.tar.bz2
scummvm-rg350-9885a050f2e9b718e3fb7bab224dcfdc18292231.zip
ILLUSIONS: Implement VoicePlayer
Diffstat (limited to 'engines/illusions')
-rw-r--r--engines/illusions/illusions.cpp23
-rw-r--r--engines/illusions/illusions.h5
-rw-r--r--engines/illusions/sound.cpp87
-rw-r--r--engines/illusions/sound.h29
-rw-r--r--engines/illusions/talkthread.cpp13
-rw-r--r--engines/illusions/talkthread_duckman.cpp20
6 files changed, 132 insertions, 45 deletions
diff --git a/engines/illusions/illusions.cpp b/engines/illusions/illusions.cpp
index 1260714d17..c58eb85c0d 100644
--- a/engines/illusions/illusions.cpp
+++ b/engines/illusions/illusions.cpp
@@ -257,32 +257,9 @@ void IllusionsEngine::playVideo(uint32 videoId, uint32 objectId, uint32 priority
bool IllusionsEngine::isSoundActive() {
// TODO
- return false;
-}
-
-bool IllusionsEngine::cueVoice(byte *voiceName) {
- // TODO
return true;
}
-bool IllusionsEngine::isVoiceCued() {
- // TODO
- return false;
-}
-
-void IllusionsEngine::startVoice(int volume, int panX) {
- // TODO
-}
-
-void IllusionsEngine::stopVoice() {
- // TODO
-}
-
-bool IllusionsEngine::isVoicePlaying() {
- // TODO
- return false;
-}
-
void IllusionsEngine::updateFader() {
if (_fader && !_fader->_paused && _fader->_active) {
int32 currTime = getCurrentTime();
diff --git a/engines/illusions/illusions.h b/engines/illusions/illusions.h
index 1a1f542001..522d1dc9c3 100644
--- a/engines/illusions/illusions.h
+++ b/engines/illusions/illusions.h
@@ -157,11 +157,6 @@ public:
bool calcPointDirection(Common::Point &srcPt, Common::Point &dstPt, uint &facing);
void playVideo(uint32 videoId, uint32 objectId, uint32 value, uint32 threadId);
bool isSoundActive();
- bool cueVoice(byte *voiceName);
- bool isVoiceCued();
- void startVoice(int volume, int panX);
- void stopVoice();
- bool isVoicePlaying();
void updateFader();
diff --git a/engines/illusions/sound.cpp b/engines/illusions/sound.cpp
index 632b842d6f..0f60e5d14c 100644
--- a/engines/illusions/sound.cpp
+++ b/engines/illusions/sound.cpp
@@ -33,6 +33,7 @@ MusicPlayer::MusicPlayer(Audio::Mixer *mixer)
}
MusicPlayer::~MusicPlayer() {
+ stop();
}
void MusicPlayer::play(uint32 musicId, bool looping, int16 volume, int16 pan) {
@@ -40,7 +41,6 @@ void MusicPlayer::play(uint32 musicId, bool looping, int16 volume, int16 pan) {
if (_flags & 1) {
stop();
_musicId = musicId;
- Common::String filename = Common::String::format("%08x.wav", _musicId);
_flags |= 2;
_flags &= ~4;
if (looping) {
@@ -48,6 +48,7 @@ void MusicPlayer::play(uint32 musicId, bool looping, int16 volume, int16 pan) {
} else {
_flags &= ~8;
}
+ Common::String filename = Common::String::format("%08x.wav", _musicId);
Common::File *fd = new Common::File();
fd->open(filename);
Audio::AudioStream *audioStream = Audio::makeLoopingAudioStream(Audio::makeWAVStream(fd, DisposeAfterUse::YES), looping ? 0 : 1);
@@ -71,15 +72,71 @@ bool MusicPlayer::isPlaying() {
return (_flags & 1) && (_flags & 2) && _mixer->isSoundHandleActive(_soundHandle);
}
+// VoicePlayer
+
+VoicePlayer::VoicePlayer(Audio::Mixer *mixer)
+ : _mixer(mixer) {
+}
+
+VoicePlayer::~VoicePlayer() {
+ stop();
+}
+
+bool VoicePlayer::cue(const char *voiceName) {
+debug("VoicePlayer::cue(%s)", voiceName);
+ _voiceName = voiceName;
+ _voiceStatus = 2;
+ if (!isEnabled()) {
+ _voiceStatus = 3;
+ return false;
+ }
+ return true;
+}
+
+void VoicePlayer::stopCueing() {
+ _voiceStatus = 3;
+}
+
+void VoicePlayer::start(int16 volume, int16 pan) {
+ Common::String filename = Common::String::format("%s.wav", _voiceName.c_str());
+ Common::File *fd = new Common::File();
+ fd->open(filename);
+ Audio::AudioStream *audioStream = Audio::makeWAVStream(fd, DisposeAfterUse::YES);
+ _mixer->playStream(Audio::Mixer::kSpeechSoundType, &_soundHandle, audioStream, -1, volume, pan);
+ _voiceStatus = 4;
+}
+
+void VoicePlayer::stop() {
+ if (_mixer->isSoundHandleActive(_soundHandle))
+ _mixer->stopHandle(_soundHandle);
+ _voiceStatus = 1;
+ _voiceName.clear();
+}
+
+bool VoicePlayer::isPlaying() {
+ return _mixer->isSoundHandleActive(_soundHandle);
+}
+
+bool VoicePlayer::isEnabled() {
+ // TODO
+ return true;
+}
+
+bool VoicePlayer::isCued() {
+ return _voiceStatus == 2;
+}
+
// SoundMan
SoundMan::SoundMan(IllusionsEngine *vm)
: _vm(vm), _musicNotifyThreadId(0) {
_musicPlayer = new MusicPlayer(_vm->_mixer);
+ _voicePlayer = new VoicePlayer(_vm->_mixer);
}
SoundMan::~SoundMan() {
delete _musicPlayer;
+ delete _voicePlayer;
}
void SoundMan::update() {
@@ -98,4 +155,32 @@ void SoundMan::stopMusic() {
_musicPlayer->stop();
}
+bool SoundMan::cueVoice(const char *voiceName) {
+ return _voicePlayer->cue(voiceName);
+}
+
+void SoundMan::stopCueingVoice() {
+ _voicePlayer->stopCueing();
+}
+
+void SoundMan::startVoice(int16 volume, int16 pan) {
+ _voicePlayer->start(volume, pan);
+}
+
+void SoundMan::stopVoice() {
+ _voicePlayer->stop();
+}
+
+bool SoundMan::isVoicePlaying() {
+ return _voicePlayer->isPlaying();
+}
+
+bool SoundMan::isVoiceEnabled() {
+ return _voicePlayer->isEnabled();
+}
+
+bool SoundMan::isVoiceCued() {
+ return _voicePlayer->isCued();
+}
+
} // End of namespace Illusions
diff --git a/engines/illusions/sound.h b/engines/illusions/sound.h
index e5139d3161..9e2cd43fa1 100644
--- a/engines/illusions/sound.h
+++ b/engines/illusions/sound.h
@@ -47,17 +47,46 @@ protected:
uint _flags;
};
+class VoicePlayer {
+public:
+ VoicePlayer(Audio::Mixer *mixer);
+ ~VoicePlayer();
+ bool cue(const char *voiceName);
+ void stopCueing();
+ void start(int16 volume, int16 pan);
+ void stop();
+ bool isPlaying();
+ bool isEnabled();
+ bool isCued();
+protected:
+ Audio::Mixer *_mixer;
+ Audio::SoundHandle _soundHandle;
+ Common::String _voiceName;
+ uint _voiceStatus;
+};
+
class SoundMan {
public:
SoundMan(IllusionsEngine *vm);
~SoundMan();
void update();
+
void playMusic(uint32 musicId, int16 type, int16 volume, int16 pan, uint32 notifyThreadId);
void stopMusic();
+
+ bool cueVoice(const char *voiceName);
+ void stopCueingVoice();
+ void startVoice(int16 volume, int16 pan);
+ void stopVoice();
+ bool isVoicePlaying();
+ bool isVoiceEnabled();
+ bool isVoiceCued();
+
protected:
IllusionsEngine *_vm;
uint32 _musicNotifyThreadId;
MusicPlayer *_musicPlayer;
+ VoicePlayer *_voicePlayer;
};
} // End of namespace Illusions
diff --git a/engines/illusions/talkthread.cpp b/engines/illusions/talkthread.cpp
index 5ad6f7214a..783e9d2361 100644
--- a/engines/illusions/talkthread.cpp
+++ b/engines/illusions/talkthread.cpp
@@ -26,6 +26,7 @@
#include "illusions/dictionary.h"
#include "illusions/input.h"
#include "illusions/scriptman.h"
+#include "illusions/sound.h"
#include "illusions/talkresource.h"
#include "illusions/time.h"
@@ -118,7 +119,7 @@ int TalkThread::onUpdate() {
_flags |= 1;
}
if (_vm->isSoundActive()) {
- if (!_vm->cueVoice(talkEntry->_voiceName) && !_durationMult)
+ if (!_vm->_soundMan->cueVoice((char*)talkEntry->_voiceName) && !_durationMult)
_durationMult = _defDurationMult;
} else {
_flags |= 4;
@@ -131,7 +132,7 @@ int TalkThread::onUpdate() {
// Fallthrough to status 4
case 4:
- if (!(_flags & 4) && !_vm->isVoiceCued())
+ if (!(_flags & 4) && !_vm->_soundMan->isVoiceCued())
return kTSYield;
_status = 5;
// Fallthrough to status 5
@@ -149,14 +150,14 @@ int TalkThread::onUpdate() {
// TODO pt.x = (unsigned int)artcntrlGetNamedPointPosition((Point)_namedPointId);
// TODO panX = convertPanXCoord(pt.x);
}
- _vm->startVoice(255, panX);
+ _vm->_soundMan->startVoice(255, panX);
}
_vm->_input->discardButtons(0x10);
_status = 6;
return kTSYield;
case 6:
- if (!(_flags & 4) && !_vm->isVoicePlaying())
+ if (!(_flags & 4) && !_vm->_soundMan->isVoicePlaying())
_flags |= 4;
if (!(_flags & 8) && isTimerExpired(_textStartTime, _textEndTime)) {
// TODO _vm->removeText();
@@ -188,7 +189,7 @@ int TalkThread::onUpdate() {
}
if (_flags & 8) {
if (!(_flags & 4)) {
- _vm->stopVoice();
+ _vm->_soundMan->stopVoice();
_flags |= 4;
}
if (!(_flags & 2)) {
@@ -228,7 +229,7 @@ int TalkThread::onUpdate() {
_flags |= 8;
}
if (!(_flags & 4)) {
- _vm->stopVoice();
+ _vm->_soundMan->stopVoice();
_flags |= 4;
}
return kTSTerminate;
diff --git a/engines/illusions/talkthread_duckman.cpp b/engines/illusions/talkthread_duckman.cpp
index 990d1be90b..788126810b 100644
--- a/engines/illusions/talkthread_duckman.cpp
+++ b/engines/illusions/talkthread_duckman.cpp
@@ -27,6 +27,7 @@
#include "illusions/input.h"
#include "illusions/screentext.h"
#include "illusions/scriptman.h"
+#include "illusions/sound.h"
#include "illusions/talkresource.h"
#include "illusions/time.h"
@@ -79,24 +80,23 @@ int TalkThread_Duckman::onUpdate() {
case 2:
talkEntry = getTalkResourceEntry(_talkId);
_flags = 0;
- _entryText = talkEntry->_text;
_currEntryText = 0;
+ _entryText = talkEntry->_text;
_entryTblPtr = talkEntry->_tblPtr;
- _flags = 0;
if (_sequenceId1) {
- _pauseCtr = 0;
_pauseCtrPtr = &_pauseCtr;
+ _pauseCtr = 0;
} else {
_pauseCtrPtr = 0;
_flags |= 2;
_flags |= 1;
}
if (_vm->isSoundActive()) {
- if (!_vm->cueVoice(talkEntry->_voiceName) && !_durationMult)
+ if (!_vm->_soundMan->cueVoice((char*)talkEntry->_voiceName) && !_durationMult)
_durationMult = _defDurationMult;
} else {
_flags |= 4;
- if (!_durationMult)
+ if (_durationMult == 0)
_durationMult = _defDurationMult;
}
if (_objectId == 0 || _durationMult == 0)
@@ -105,7 +105,7 @@ int TalkThread_Duckman::onUpdate() {
// Fallthrough to status 3
case 3:
- if (!(_flags & 4) && !_vm->isVoiceCued())
+ if (!(_flags & 4) && !_vm->_soundMan->isVoiceCued())
return kTSYield;
_status = 4;
// Fallthrough to status 4
@@ -132,14 +132,14 @@ int TalkThread_Duckman::onUpdate() {
panX = control->getActorPosition().x;
panX = _vm->convertPanXCoord(panX);
}
- _vm->startVoice(255, panX);
+ _vm->_soundMan->startVoice(255, panX);
}
_vm->_input->discardButtons(0x20);
_status = 5;
return kTSYield;
case 5:
- if (!(_flags & 4) && !_vm->isVoicePlaying())
+ if (!(_flags & 4) && !_vm->_soundMan->isVoicePlaying())
_flags |= 4;
if (!(_flags & 8) && isTimerExpired(_textStartTime, _textEndTime)) {
_vm->_screenText->removeText();
@@ -168,7 +168,7 @@ int TalkThread_Duckman::onUpdate() {
}
if (_flags & 8) {
if (!(_flags & 4)) {
- _vm->stopVoice();
+ _vm->_soundMan->stopVoice();
_flags |= 4;
}
if (!(_flags & 2)) {
@@ -219,7 +219,7 @@ void TalkThread_Duckman::onResume() {
void TalkThread_Duckman::onTerminated() {
if (_status == 5) {
if (!(_flags & 4))
- _vm->stopVoice();
+ _vm->_soundMan->stopVoice();
if (!(_flags & 8)) {
_vm->_screenText->removeText();
}