aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra/lol.cpp
diff options
context:
space:
mode:
authorFlorian Kagerer2009-05-23 23:33:31 +0000
committerFlorian Kagerer2009-05-23 23:33:31 +0000
commit5a4b3c54414d7415af6a0838ba558177586a4427 (patch)
tree325e9e8d48c0900eff926b7b844dc4914d0dd6de /engines/kyra/lol.cpp
parenta19c23ab7a3f0daaf3e047d96865d78c92f4841c (diff)
downloadscummvm-rg350-5a4b3c54414d7415af6a0838ba558177586a4427.tar.gz
scummvm-rg350-5a4b3c54414d7415af6a0838ba558177586a4427.tar.bz2
scummvm-rg350-5a4b3c54414d7415af6a0838ba558177586a4427.zip
KYRA/LOL: restructured voice playing code so that audio compression can be supported
svn-id: r40839
Diffstat (limited to 'engines/kyra/lol.cpp')
-rw-r--r--engines/kyra/lol.cpp262
1 files changed, 6 insertions, 256 deletions
diff --git a/engines/kyra/lol.cpp b/engines/kyra/lol.cpp
index da0703f5e0..02f3020ec0 100644
--- a/engines/kyra/lol.cpp
+++ b/engines/kyra/lol.cpp
@@ -412,6 +412,10 @@ LoLEngine::~LoLEngine() {
for (Common::Array<const SpellProc*>::iterator i = _spellProcs.begin(); i != _spellProcs.end(); ++i)
delete *i;
_spellProcs.clear();
+
+ for (Common::List<Audio::AudioStream *>::iterator i = _speechList.begin(); i != _speechList.end(); ++i)
+ delete *i;
+ _speechList.clear();
}
Screen *LoLEngine::screen() {
@@ -896,7 +900,7 @@ void LoLEngine::update() {
if (_gameFlags[15] & 0x4000 && !(_updateFlags & 4) && (_compassDirection == -1 || (_currentDirection << 6) != _compassDirection || _compassStep))
updateCompass();
- snd_characterSpeaking();
+ snd_updateCharacterSpeech();
fadeText();
updateInput();
@@ -1096,7 +1100,7 @@ void LoLEngine::updatePortraitSpeechAnim() {
f += 7;
if (_speechFlag) {
- if (snd_characterSpeaking() == 2)
+ if (snd_updateCharacterSpeech() == 2)
_updatePortraitSpeechAnimDuration = 2;
else
_updatePortraitSpeechAnimDuration = 1;
@@ -1670,260 +1674,6 @@ void LoLEngine::loadTalkFile(int index) {
_res->loadPakFile(file);
}
-bool LoLEngine::snd_playCharacterSpeech(int id, int8 speaker, int) {
- if (!_speechFlag)
- return false;
-
- if (speaker < 65) {
- if (_characters[speaker].flags & 1)
- speaker = (int) _characters[speaker].name[0];
- else
- speaker = 0;
- }
-
- if (_lastSpeechId == id && speaker == _lastSpeaker)
- return true;
-
- _lastSpeechId = id;
- _lastSpeaker = speaker;
- _nextSpeechId = _nextSpeaker = -1;
-
- Common::List<const char*> playList;
-
- char pattern1[8];
- char pattern2[5];
- char file1[13];
- char file2[13];
- char file3[13];
- file3[0] = 0;
-
- snprintf(pattern2, sizeof(pattern2), "%02d", id & 0x4000 ? 0 : _curTlkFile);
-
- if (id & 0x4000) {
- snprintf(pattern1, sizeof(pattern1), "%03X", id & 0x3fff);
- } else if (id < 1000) {
- snprintf(pattern1, sizeof(pattern1), "%03d", id);
- } else {
- snprintf(file3, sizeof(file3), "@%04d%c.%s", id - 1000, (char)speaker, pattern2);
- if (_res->exists(file3)) {
- char *f = new char[strlen(file3) + 1];
- strcpy(f, file3);
- playList.push_back(f);
- }
- }
-
- if (!file3[0]) {
- for (char i = 0; ; i++) {
- char symbol = '0' + i;
- snprintf(file1, sizeof(file1), "%s%c%c.%s", pattern1, (char)speaker, symbol, pattern2);
- snprintf(file2, sizeof(file2), "%s%c%c.%s", pattern1, '_', symbol, pattern2);
- if (_res->exists(file1)) {
- char *f = new char[strlen(file1) + 1];
- strcpy(f, file1);
- playList.push_back(f);
- } else if (_res->exists(file2)) {
- char *f = new char[strlen(file2) + 1];
- strcpy(f, file2);
- playList.push_back(f);
- } else {
- break;
- }
- }
- }
-
- if (playList.empty())
- return false;
-
- while (_sound->voiceIsPlaying(_activeVoiceFile))
- delay(_tickLength, true, false);
-
- while (_sound->allVoiceChannelsPlaying())
- delay(_tickLength, false, true);
-
- strcpy(_activeVoiceFile, *playList.begin());
- _activeVoiceFileTotalTime = _sound->voicePlayFromList(playList);
-
- for (Common::List<const char*>::iterator i = playList.begin(); i != playList.end(); i++)
- delete []*i;
- playList.clear();
-
- _tim->_abortFlag = 0;
-
- return true;
-}
-
-int LoLEngine::snd_characterSpeaking() {
- if (_sound->voiceIsPlaying(_activeVoiceFile))
- return 2;
-
- _lastSpeechId = _lastSpeaker = -1;
- _activeVoiceFileTotalTime = 0;
-
- if (_nextSpeechId != -1) {
- if (snd_playCharacterSpeech(_nextSpeechId, _nextSpeaker, 0))
- return 2;
- }
-
- return 0;
-}
-
-void LoLEngine::snd_stopSpeech(bool setFlag) {
- if (!_sound->voiceIsPlaying(_activeVoiceFile))
- return;
-
- //_dlgTimer = 0;
- _sound->voiceStop(_activeVoiceFile);
- _activeVoiceFileTotalTime = 0;
- _nextSpeechId = _nextSpeaker = -1;
-
- if (setFlag)
- _tim->_abortFlag = 1;
-}
-
-void LoLEngine::snd_playSoundEffect(int track, int volume) {
- if (track == 1 && (_lastSfxTrack == -1 || _lastSfxTrack == 1))
- return;
-
- _lastSfxTrack = track;
- if (track == -1)
- return;
-
- int16 volIndex = (int16)READ_LE_UINT16(&_ingameSoundIndex[track * 2 + 1]);
-
- if (volIndex > 0)
- volume = (volIndex * volume) >> 8;
- else if (volIndex < 0)
- volume = -volIndex;
-
- // volume TODO
- volume = 254 - volume;
-
- int16 vocIndex = (int16)READ_LE_UINT16(&_ingameSoundIndex[track * 2]);
-
- bool hasVocFile = false;
- if (vocIndex != -1) {
- if (scumm_stricmp(_ingameSoundList[vocIndex], "EMPTY"))
- hasVocFile = true;
- }
-
- if (hasVocFile) {
- _sound->voicePlay(_ingameSoundList[vocIndex], volume & 0xff, true);
- } else if (_flags.platform == Common::kPlatformPC) {
- if (_sound->getSfxType() == Sound::kMidiMT32)
- track = track < _ingameMT32SoundIndexSize ? _ingameMT32SoundIndex[track] - 1 : -1;
- else if (_sound->getSfxType() == Sound::kMidiGM)
- track = track < _ingameGMSoundIndexSize ? _ingameGMSoundIndex[track] - 1: -1;
-
- if (track == 168)
- track = 167;
-
- if (track != -1)
- KyraEngine_v1::snd_playSoundEffect(track, volume);
- }
-}
-
-void LoLEngine::snd_processEnvironmentalSoundEffect(int soundId, int block) {
- if (!_sound->sfxEnabled())
- return;
-
- if (_environmentSfx)
- snd_playSoundEffect(_environmentSfx, _environmentSfxVol);
-
- int dist = 0;
- if (block) {
- dist = getMonsterDistance(_currentBlock, block);
- if (dist > _envSfxDistThreshold) {
- _environmentSfx = 0;
- return;
- }
- }
-
- _environmentSfx = soundId;
- _environmentSfxVol = (15 - ((block || dist < 2) ? dist : 0)) << 4;
-
- if (block != _currentBlock) {
- static const int8 blockShiftTable[] = { -32, -31, 1, 33, 32, 31, -1, -33 };
- uint16 cbl = _currentBlock;
-
- for (int i = 3; i > 0; i--) {
- int dir = calcMonsterDirection(cbl & 0x1f, cbl >> 5, block & 0x1f, block >> 5);
- cbl += blockShiftTable[dir];
- if (cbl != block) {
- if (testWallFlag(cbl, 0, 1))
- _environmentSfxVol >>= 1;
- }
- }
- }
-
- if (!soundId || _sceneUpdateRequired)
- return;
-
- snd_processEnvironmentalSoundEffect(0, 0);
-}
-
-void LoLEngine::snd_queueEnvironmentalSoundEffect(int soundId, int block) {
- if (_envSfxUseQueue && _envSfxNumTracksInQueue < 10) {
- _envSfxQueuedTracks[_envSfxNumTracksInQueue] = soundId;
- _envSfxQueuedBlocks[_envSfxNumTracksInQueue] = block;
- _envSfxNumTracksInQueue++;
- } else {
- snd_processEnvironmentalSoundEffect(soundId, block);
- }
-}
-
-void LoLEngine::snd_playQueuedEffects() {
- for (int i = 0; i < _envSfxNumTracksInQueue; i++)
- snd_processEnvironmentalSoundEffect(_envSfxQueuedTracks[i], _envSfxQueuedBlocks[i]);
- _envSfxNumTracksInQueue = 0;
-}
-
-void LoLEngine::snd_loadSoundFile(int track) {
- if (_sound->musicEnabled()) {
- char filename[13];
- int t = (track - 250) * 3;
-
- if (_curMusicFileIndex != _musicTrackMap[t] || _curMusicFileExt != (char)_musicTrackMap[t + 1]) {
- snd_stopMusic();
- snprintf(filename, sizeof(filename), "LORE%02d%c", _musicTrackMap[t], (char)_musicTrackMap[t + 1]);
- _sound->loadSoundFile(filename);
- _curMusicFileIndex = _musicTrackMap[t];
- _curMusicFileExt = (char)_musicTrackMap[t + 1];
- } else {
- snd_stopMusic();
- }
- } else {
- //XXX
- }
-}
-
-int LoLEngine::snd_playTrack(int track) {
- if (track == -1)
- return _lastMusicTrack;
-
- int res = _lastMusicTrack;
- _lastMusicTrack = track;
-
- if (_sound->musicEnabled()) {
- snd_loadSoundFile(track);
- int t = (track - 250) * 3;
- _sound->playTrack(_musicTrackMap[t + 2]);
- }
-
- return res;
-}
-
-int LoLEngine::snd_stopMusic() {
- if (_sound->musicEnabled()) {
- if (_sound->isPlaying()) {
- _sound->beginFadeOut();
- _system->delayMillis(3 * _tickLength);
- }
-
- _sound->haltTrack();
- }
- return snd_playTrack(-1);
-}
-
int LoLEngine::characterSays(int track, int charId, bool redraw) {
if (charId == 1) {
charId = _selectedCharacter;