aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLittleboy2011-06-29 12:06:33 -0400
committerLittleboy2011-06-29 12:06:33 -0400
commit3385fd37b974088e1cd7117e67c87e935742d729 (patch)
tree7db30d897963827c3230ba37c686618478134b5c
parent2788cb8bf72f0897a8bed32fbb5730f892b10edf (diff)
downloadscummvm-rg350-3385fd37b974088e1cd7117e67c87e935742d729.tar.gz
scummvm-rg350-3385fd37b974088e1cd7117e67c87e935742d729.tar.bz2
scummvm-rg350-3385fd37b974088e1cd7117e67c87e935742d729.zip
LASTEXPRESS: Hook up preliminary sound filtering
- Add debug checks in soundFilter() - Rename kSoundStatusClear1 to kSoundStatusFilterVariant
-rw-r--r--engines/lastexpress/shared.h36
-rw-r--r--engines/lastexpress/sound/entry.cpp63
-rw-r--r--engines/lastexpress/sound/entry.h4
-rw-r--r--engines/lastexpress/sound/queue.cpp8
4 files changed, 64 insertions, 47 deletions
diff --git a/engines/lastexpress/shared.h b/engines/lastexpress/shared.h
index 6969e437ea..b4ced96ee1 100644
--- a/engines/lastexpress/shared.h
+++ b/engines/lastexpress/shared.h
@@ -90,24 +90,24 @@ enum SoundState {
};
enum SoundStatus {
- kSoundStatus_20 = 0x20,
- kSoundStatus_40 = 0x40,
- kSoundStatus_180 = 0x180,
- kSoundStatusRemoved = 0x200,
- kSoundStatus_400 = 0x400,
-
- kSoundStatus_8000 = 0x8000,
- kSoundStatus_20000 = 0x20000,
- kSoundStatus_100000 = 0x100000,
- kSoundStatus_20000000 = 0x20000000,
- kSoundStatus_40000000 = 0x40000000,
-
- kSoundStatusClear0 = 0x10,
- kSoundStatusClear1 = 0x1F,
- kSoundStatusClear2 = 0x80,
- kSoundStatusClear3 = 0x200,
- kSoundStatusClear4 = 0x800,
- kSoundStatusClearAll = 0xFFFFFFE0
+ kSoundStatus_20 = 0x20,
+ kSoundStatus_40 = 0x40,
+ kSoundStatus_180 = 0x180,
+ kSoundStatusRemoved = 0x200,
+ kSoundStatus_400 = 0x400,
+
+ kSoundStatus_8000 = 0x8000,
+ kSoundStatus_20000 = 0x20000,
+ kSoundStatus_100000 = 0x100000,
+ kSoundStatus_20000000 = 0x20000000,
+ kSoundStatus_40000000 = 0x40000000,
+
+ kSoundStatusClear0 = 0x10,
+ kSoundStatusFilterVariant = 0x1F,
+ kSoundStatusClear2 = 0x80,
+ kSoundStatusClear3 = 0x200,
+ kSoundStatusClear4 = 0x800,
+ kSoundStatusClearAll = 0xFFFFFFE0
};
//////////////////////////////////////////////////////////////////////////
diff --git a/engines/lastexpress/sound/entry.cpp b/engines/lastexpress/sound/entry.cpp
index 5cbc593d29..4bdb9f7f96 100644
--- a/engines/lastexpress/sound/entry.cpp
+++ b/engines/lastexpress/sound/entry.cpp
@@ -47,7 +47,7 @@ namespace LastExpress {
SoundEntry::SoundEntry(LastExpressEngine *engine) : _engine(engine) {
_type = kSoundTypeNone;
- _currentDataPtr = 0;
+ _currentDataPtr = NULL;
_soundBuffer = NULL;
_blockCount = 0;
@@ -58,7 +58,7 @@ SoundEntry::SoundEntry(LastExpressEngine *engine) : _engine(engine) {
_field_34 = 0;
_field_38 = 0;
_field_3C = 0;
- _field_40 = 0;
+ _variant = 0;
_entity = kEntityPlayer;
_field_48 = 0;
_priority = 0;
@@ -118,32 +118,37 @@ void SoundEntry::close() {
}
void SoundEntry::play() {
- if (!_soundStream)
- _soundStream = new StreamedSound();
-
- if (_queued)
- return;
-
if (!_stream) {
warning("[SoundEntry::play] stream has been disposed");
return;
}
- // Stream the contents of the sound buffer
- /*int16 *buffer = (int16 *)malloc(FILTER_BUFFER_SIZE);
+ if (_queued)
+ return;
+
+ // Apply filter
+ int16 *buffer = (int16 *)malloc(FILTER_BUFFER_SIZE);
memset(buffer, 0, FILTER_BUFFER_SIZE);
applyFilter(buffer);
- _soundStream->queueBuffer((const byte *)buffer, FILTER_BUFFER_SIZE, true);
+ // Queue the filtered data
+#if 0
+ if (!_soundStream)
+ _soundStream = new AppendableSound();
+ // FIXME: make sure the filtered sound buffer is disposed
+ _soundStream->queueBuffer((const byte *)buffer, FILTER_BUFFER_SIZE /* true */);
+#else
+ free(buffer);
- // Skip header
- _stream->seek(12, SEEK_SET);
- */
+ // DEBUG: unfiltered stream
+ if (!_soundStream)
+ _soundStream = new StreamedSound();
_stream->seek(0);
_soundStream->load(_stream);
+#endif
_queued = true;
}
@@ -233,7 +238,7 @@ void SoundEntry::setType(SoundFlag flag) {
void SoundEntry::setupStatus(SoundFlag flag) {
SoundStatus statusFlag = (SoundStatus)flag;
- if (!((statusFlag & 0xFF) & kSoundStatusClear1))
+ if (!((statusFlag & 0xFF) & kSoundStatusFilterVariant))
statusFlag = (SoundStatus)(statusFlag | kSoundStatusClear2);
if (((statusFlag & 0xFF00) >> 8) & kSoundStatusClear0)
@@ -269,6 +274,7 @@ void SoundEntry::loadSoundData(Common::String name) {
if (_stream) {
_stream->read(_soundBuffer, MIN(SOUNDCACHE_ENTRY_SIZE, _stream->size()));
+ _currentDataPtr = _soundBuffer + 6;
} else {
_status.status = kSoundStatusRemoved;
}
@@ -282,7 +288,7 @@ void SoundEntry::update(uint val) {
if (val) {
if (getSoundQueue()->getFlag() & 32) {
- _field_40 = val;
+ _variant = val;
value2 = val * 2 + 1;
}
@@ -297,12 +303,12 @@ void SoundEntry::update(uint val) {
void SoundEntry::updateState() {
if (getSoundQueue()->getFlag() & 32) {
if (_type != kSoundType9 && _type != kSoundType7 && _type != kSoundType5) {
- uint32 newStatus = _status.status & kSoundStatusClear1;
+ uint32 variant = _status.status & kSoundStatusFilterVariant;
_status.status &= kSoundStatusClearAll;
- _field_40 = newStatus;
- _status.status |= newStatus * 2 + 1;
+ _variant = variant;
+ _status.status |= variant * 2 + 1;
}
}
@@ -680,16 +686,16 @@ static const int p2s[17] = { 0, 1, 1, 3, 1, 5, 3, 7, 1, 9, 5, 11, 3, 13, 7, 15,
static void soundFilter(byte *data, int16 *buffer, int p1, int p2);
void SoundEntry::applyFilter(int16 *buffer) {
- if ((_soundBuffer[1] << 6) > 5632) {
+ if ((READ_UINT16((int16 *)(_currentDataPtr + 2)) << 6) > 5632) {
_status.status |= kSoundStatus_20000000;
} else {
- int variant = _status.status & 0x1f;
+ int variant = _status.status & kSoundStatusFilterVariant;
- soundFilter(_soundBuffer, buffer, p1s[variant], p2s[variant]);
+ soundFilter(_currentDataPtr, buffer, p1s[variant], p2s[variant]);
+ _currentDataPtr += 739;
}
}
-
static void soundFilter(byte *data, int16 *buffer, int p1, int p2) {
int data1, data2, data1p, data2p;
byte idx;
@@ -701,6 +707,12 @@ static void soundFilter(byte *data, int16 *buffer, int p1, int p2) {
for (int count = 0; count < 735; count++) {
idx = data[count] >> 4;
+
+ if ((idx + data1) > ARRAYSIZE(filterData)) {
+ warning("Error in sound filter, aborting...");
+ return;
+ }
+
data1p = filterData[idx + data1];
data2p = CLIP(filterData2[idx + data1] + data2, -32767, 32767);
@@ -708,6 +720,11 @@ static void soundFilter(byte *data, int16 *buffer, int p1, int p2) {
idx = data[count] & 0xF;
+ if ((idx + data1p) > ARRAYSIZE(filterData)) {
+ warning("Error in sound filter, aborting...");
+ return;
+ }
+
data1 = filterData[idx + data1p];
data2 = CLIP(filterData2[idx + data1p] + data2p, -32767, 32767);
buffer[2 * count + 1] = (p2 * data2) >> p1;
diff --git a/engines/lastexpress/sound/entry.h b/engines/lastexpress/sound/entry.h
index 8da780f294..a466d31b3a 100644
--- a/engines/lastexpress/sound/entry.h
+++ b/engines/lastexpress/sound/entry.h
@@ -134,7 +134,7 @@ private:
SoundType _type; // int
//int _data;
//int _endOffset;
- int _currentDataPtr;
+ byte * _currentDataPtr;
//int _currentBufferPtr;
int _blockCount;
uint32 _time;
@@ -145,7 +145,7 @@ private:
int _field_34;
int _field_38;
int _field_3C;
- int _field_40;
+ int _variant;
EntityIndex _entity;
int _field_48;
uint32 _priority;
diff --git a/engines/lastexpress/sound/queue.cpp b/engines/lastexpress/sound/queue.cpp
index d5475a27de..ad5c9bf4e3 100644
--- a/engines/lastexpress/sound/queue.cpp
+++ b/engines/lastexpress/sound/queue.cpp
@@ -102,9 +102,9 @@ void SoundQueue::removeFromQueue(Common::String filename) {
}
void SoundQueue::updateQueue() {
- Common::StackLock locker(_mutex);
+ //Common::StackLock locker(_mutex);
- warning("[Sound::updateQueue] Not implemented");
+ //warning("[Sound::updateQueue] Not implemented");
}
void SoundQueue::resetQueue() {
@@ -292,11 +292,11 @@ void SoundQueue::updateSubtitles() {
if (!(status & kSoundStatus_40)
|| status & kSoundStatus_180
|| soundEntry->getTime() == 0
- || (status & kSoundStatusClear1) < 6
+ || (status & kSoundStatusFilterVariant) < 6
|| ((getFlags()->nis & 0x8000) && soundEntry->getPriority() < 90)) {
current_index = 0;
} else {
- current_index = soundEntry->getPriority() + (status & kSoundStatusClear1);
+ current_index = soundEntry->getPriority() + (status & kSoundStatusFilterVariant);
if (_currentSubtitle == (*i))
current_index += 4;