aboutsummaryrefslogtreecommitdiff
path: root/engines/lastexpress/sound
diff options
context:
space:
mode:
Diffstat (limited to 'engines/lastexpress/sound')
-rw-r--r--engines/lastexpress/sound/entry.cpp27
-rw-r--r--engines/lastexpress/sound/queue.cpp30
-rw-r--r--engines/lastexpress/sound/queue.h2
-rw-r--r--engines/lastexpress/sound/sound.cpp25
4 files changed, 56 insertions, 28 deletions
diff --git a/engines/lastexpress/sound/entry.cpp b/engines/lastexpress/sound/entry.cpp
index 44cc68a57b..3d22657124 100644
--- a/engines/lastexpress/sound/entry.cpp
+++ b/engines/lastexpress/sound/entry.cpp
@@ -30,11 +30,9 @@
#include "lastexpress/sound/sound.h"
#include "lastexpress/graphics.h"
-#include "lastexpress/helpers.h"
#include "lastexpress/lastexpress.h"
#include "lastexpress/resource.h"
-#include "common/stream.h"
namespace LastExpress {
@@ -47,6 +45,8 @@ namespace LastExpress {
SoundEntry::SoundEntry(LastExpressEngine *engine) : _engine(engine) {
_type = kSoundTypeNone;
+ _currentDataPtr = NULL;
+
_blockCount = 0;
_time = 0;
@@ -71,7 +71,13 @@ SoundEntry::~SoundEntry() {
// Entries that have been queued will have their streamed disposed automatically
if (!_soundStream)
SAFE_DELETE(_stream);
- delete _soundStream;
+
+ SAFE_DELETE(_soundStream);
+
+ free(_currentDataPtr);
+
+ _subtitle = NULL;
+ _stream = NULL;
// Zero passed pointers
_engine = NULL;
@@ -110,10 +116,8 @@ void SoundEntry::close() {
}
void SoundEntry::play() {
- if (!_stream) {
- warning("[SoundEntry::play] stream has been disposed");
- return;
- }
+ if (!_stream)
+ error("[SoundEntry::play] stream has been disposed");
// Prepare sound stream
if (!_soundStream)
@@ -277,7 +281,7 @@ bool SoundEntry::updateSound() {
int l = strlen(sub) + 1;
if (l - 1 > 4)
- sub[l - 1 - 4] = 0;
+ sub[l - (1 + 4)] = 0;
showSubtitle(sub);
}
} else {
@@ -393,6 +397,10 @@ SubtitleEntry::SubtitleEntry(LastExpressEngine *engine) : _engine(engine) {
SubtitleEntry::~SubtitleEntry() {
SAFE_DELETE(_data);
+
+ // Zero-out passed pointers
+ _sound = NULL;
+ _engine = NULL;
}
void SubtitleEntry::load(Common::String filename, SoundEntry *soundEntry) {
@@ -423,6 +431,9 @@ void SubtitleEntry::loadData() {
}
void SubtitleEntry::setupAndDraw() {
+ if (!_sound)
+ error("[SubtitleEntry::setupAndDraw] Sound entry not initialized");
+
if (!_data) {
_data = new SubtitleManager(_engine->getFont());
_data->load(getArchive(_filename));
diff --git a/engines/lastexpress/sound/queue.cpp b/engines/lastexpress/sound/queue.cpp
index 33b4c06793..8904b48930 100644
--- a/engines/lastexpress/sound/queue.cpp
+++ b/engines/lastexpress/sound/queue.cpp
@@ -26,6 +26,7 @@
#include "lastexpress/game/state.h"
#include "lastexpress/sound/entry.h"
+#include "lastexpress/sound/sound.h"
#include "lastexpress/helpers.h"
#include "lastexpress/lastexpress.h"
@@ -39,6 +40,7 @@ SoundQueue::SoundQueue(LastExpressEngine *engine) : _engine(engine) {
_subtitlesFlag = 0;
_currentSubtitle = NULL;
+ //_soundCacheData = NULL;
}
SoundQueue::~SoundQueue() {
@@ -51,6 +53,7 @@ SoundQueue::~SoundQueue() {
_subtitles.clear();
_currentSubtitle = NULL;
+ //SAFE_DELETE(_soundCacheData);
// Zero passed pointers
_engine = NULL;
@@ -64,6 +67,8 @@ void SoundQueue::handleTimer() {
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) {
SoundEntry *entry = (*i);
+ if (entry == NULL)
+ error("[SoundQueue::handleTimer] Invalid entry found in sound queue");
// When the entry has stopped playing, we remove his buffer
if (entry->isFinished()) {
@@ -120,6 +125,8 @@ void SoundQueue::updateQueue() {
for (Common::List<SoundEntry *>::iterator it = _soundList.begin(); it != _soundList.end(); ++it) {
SoundEntry *entry = *it;
+ if (entry == NULL)
+ error("[SoundQueue::updateQueue] Invalid entry found in sound queue");
// Original removes the entry data from the cache and sets the archive as not loaded
// and if the sound data buffer is not full, loads a new entry to be played based on
@@ -134,7 +141,7 @@ void SoundQueue::updateQueue() {
// Original update the current entry, loading another set of samples to be decoded
- getFlags()->flag_3 = 0;
+ getFlags()->flag_3 = false;
--_flag;
}
@@ -176,6 +183,8 @@ void SoundQueue::clearQueue() {
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) {
SoundEntry *entry = (*i);
+ if (entry == NULL)
+ error("[SoundQueue::clearQueue] Invalid entry found in sound queue");
// Delete entry
entry->close();
@@ -340,13 +349,14 @@ void SoundQueue::updateSubtitles() {
return;
}
+ if (!subtitle)
+ return;
+
if (_subtitlesFlag & 1)
subtitle->drawOnScreen();
- if (subtitle) {
- subtitle->loadData();
- subtitle->setupAndDraw();
- }
+ subtitle->loadData();
+ subtitle->setupAndDraw();
}
//////////////////////////////////////////////////////////////////////////
@@ -368,7 +378,15 @@ void SoundQueue::saveLoadWithSerializer(Common::Serializer &s) {
(*i)->saveLoadWithSerializer(s);
} else {
warning("[Sound::saveLoadWithSerializer] Loading not implemented");
- s.skip(numEntries * 64);
+
+ uint32 unusedDataSize = numEntries * 64;
+ if (s.isLoading()) {
+ byte *empty = (byte *)malloc(unusedDataSize);
+ s.syncBytes(empty, unusedDataSize);
+ free(empty);
+ } else {
+ s.skip(unusedDataSize);
+ }
}
}
diff --git a/engines/lastexpress/sound/queue.h b/engines/lastexpress/sound/queue.h
index 75fe06883a..e1f9be1cf7 100644
--- a/engines/lastexpress/sound/queue.h
+++ b/engines/lastexpress/sound/queue.h
@@ -106,7 +106,7 @@ private:
// Entries
Common::List<SoundEntry *> _soundList; ///< List of all sound entries
- void *_soundCacheData;
+ //void *_soundCacheData;
// Subtitles
int _subtitlesFlag;
diff --git a/engines/lastexpress/sound/sound.cpp b/engines/lastexpress/sound/sound.cpp
index 2f7bb4a601..319f7cd4f4 100644
--- a/engines/lastexpress/sound/sound.cpp
+++ b/engines/lastexpress/sound/sound.cpp
@@ -33,7 +33,6 @@
#include "lastexpress/sound/entry.h"
#include "lastexpress/sound/queue.h"
-#include "lastexpress/helpers.h"
#include "lastexpress/graphics.h"
#include "lastexpress/lastexpress.h"
#include "lastexpress/resource.h"
@@ -675,7 +674,7 @@ const char *SoundManager::getDialogName(EntityIndex entity) const {
//////////////////////////////////////////////////////////////////////////
// Letters & Messages
//////////////////////////////////////////////////////////////////////////
-void SoundManager::readText(int id){
+void SoundManager::readText(int id) {
if (!_queue->isBuffered(kEntityTables4))
return;
@@ -1330,23 +1329,23 @@ void SoundManager::playLoopingSound(int param) {
}
} else {
switch (getEntityData(kEntityPlayer)->car) {
- case 1:
- case 6:
+ case kCarBaggageRear:
+ case kCarBaggage:
partNumber = 4;
break;
- case 2:
- case 3:
- case 4:
- case 5:
+ case kCarKronos:
+ case kCarGreenSleeping:
+ case kCarRedSleeping:
+ case kCarRestaurant:
partNumber = 1;
break;
- case 7:
+ case kCarCoalTender:
partNumber = 5;
break;
- case 8:
+ case kCarLocomotive:
partNumber = 99;
break;
- case 9:
+ case kCar9:
partNumber = 3;
break;
default:
@@ -1357,13 +1356,13 @@ void SoundManager::playLoopingSound(int param) {
}
if (partNumber != 99)
- sprintf(tmp, "LOOP%d%c.SND", partNumber, _engine->getRandom().getRandomNumber(numLoops[partNumber] - 1) + 'A');
+ sprintf(tmp, "LOOP%d%c.SND", partNumber, (char)(_engine->getRandom().getRandomNumber(numLoops[partNumber] - 1) + 'A'));
}
if (getFlags()->flag_3)
fnameLen = 5;
- if (!entry || scumm_strnicmp(entry->getName2().c_str(), tmp, fnameLen)) {
+ if (!entry || scumm_strnicmp(entry->getName2().c_str(), tmp, (uint)fnameLen)) {
_loopingSoundDuration = _engine->getRandom().getRandomNumber(319) + 260;
if (partNumber != 99) {