aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrichiesams2013-07-16 16:56:15 -0500
committerrichiesams2013-08-04 13:32:20 -0500
commit76f4d2b3d898710f5fefba47aafafc889037968b (patch)
treeb5e5801da495bc2265b742c49566d8e65ebe6a43
parent9f7ff84fe4b9362a80ccf6b0f40602e01fb991d1 (diff)
downloadscummvm-rg350-76f4d2b3d898710f5fefba47aafafc889037968b.tar.gz
scummvm-rg350-76f4d2b3d898710f5fefba47aafafc889037968b.tar.bz2
scummvm-rg350-76f4d2b3d898710f5fefba47aafafc889037968b.zip
ZVISION: Create logic to decode sound rate and isStereo from fileName
-rw-r--r--engines/zvision/zork_avi_decoder.cpp10
-rw-r--r--engines/zvision/zork_raw.cpp62
-rw-r--r--engines/zvision/zork_raw.h49
3 files changed, 96 insertions, 25 deletions
diff --git a/engines/zvision/zork_avi_decoder.cpp b/engines/zvision/zork_avi_decoder.cpp
index 4ceff48891..d9b9511175 100644
--- a/engines/zvision/zork_avi_decoder.cpp
+++ b/engines/zvision/zork_avi_decoder.cpp
@@ -26,13 +26,13 @@
#include "common/stream.h"
#include "audio/audiostream.h"
-#include "engines/zvision/zork_avi_decoder.h"
-#include "engines/zvision/zork_raw.h"
+#include "zvision/zork_avi_decoder.h"
+#include "zvision/zork_raw.h"
namespace ZVision {
-Video::AVIDecoder::AVIAudioTrack *ZVision::ZorkAVIDecoder::createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo) {
- ZVision::ZorkAVIDecoder::ZorkAVIAudioTrack *audioTrack = new ZVision::ZorkAVIDecoder::ZorkAVIAudioTrack(sHeader, wvInfo, _soundType);
+Video::AVIDecoder::AVIAudioTrack *ZorkAVIDecoder::createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo) {
+ ZorkAVIDecoder::ZorkAVIAudioTrack *audioTrack = new ZorkAVIDecoder::ZorkAVIAudioTrack(sHeader, wvInfo, _soundType);
return (Video::AVIDecoder::AVIAudioTrack *)audioTrack;
}
@@ -40,7 +40,7 @@ void ZorkAVIDecoder::ZorkAVIAudioTrack::queueSound(Common::SeekableReadStream *s
if (_audStream) {
if (_wvInfo.tag == kWaveFormatZorkPCM) {
assert(_wvInfo.size == 8);
- _audStream->queueAudioStream(makeRawZorkStream(stream, _wvInfo.samplesPerSec, DisposeAfterUse::YES), DisposeAfterUse::YES);
+ _audStream->queueAudioStream(makeRawZorkStream(stream, _wvInfo.samplesPerSec, _audStream->isStereo(), DisposeAfterUse::YES), DisposeAfterUse::YES);
}
} else {
delete stream;
diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp
index c4b76d91fe..9f71b7602c 100644
--- a/engines/zvision/zork_raw.cpp
+++ b/engines/zvision/zork_raw.cpp
@@ -22,18 +22,24 @@
#include "common/scummsys.h"
+#include "common/file.h"
+#include "common/str.h"
#include "common/stream.h"
#include "common/memstream.h"
+#include "common/bufferedstream.h"
#include "common/util.h"
#include "audio/audiostream.h"
-#include "engines/zvision/zork_raw.h"
+#include "zvision/zork_raw.h"
+#include "zvision/zvision.h"
+#include "zvision/detection.h"
+#include "zvision/utility.h"
namespace ZVision {
-const int16 RawZorkStream::stepAdjustmentTable[8] = {-1, -1, -1, 1, 4, 7, 10, 12};
+const int16 RawZorkStream::_stepAdjustmentTable[8] = {-1, -1, -1, 1, 4, 7, 10, 12};
-const int32 RawZorkStream::amplitudeLookupTable[89] = {0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E,
+const int32 RawZorkStream::_amplitudeLookupTable[89] = {0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E,
0x0010, 0x0011, 0x0013, 0x0015, 0x0017, 0x0019, 0x001C, 0x001F,
0x0022, 0x0025, 0x0029, 0x002D, 0x0032, 0x0037, 0x003C, 0x0042,
0x0049, 0x0050, 0x0058, 0x0061, 0x006B, 0x0076, 0x0082, 0x008F,
@@ -45,9 +51,10 @@ const int32 RawZorkStream::amplitudeLookupTable[89] = {0x0007, 0x0008, 0x0009, 0
0x1BDC, 0x1EA5, 0x21B6, 0x2515, 0x28CA, 0x2CDF, 0x315B, 0x364B,
0x3BB9, 0x41B2, 0x4844, 0x4F7E, 0x5771, 0x602F, 0x69CE, 0x7462, 0x7FFF};
-RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream)
+RawZorkStream::RawZorkStream(uint32 rate, bool stereo, bool packed, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream)
: _rate(rate),
_stereo(stereo),
+ _packed(packed),
_stream(stream, disposeStream),
_endOfData(false) {
_lastSample[0] = {0, 0};
@@ -58,6 +65,18 @@ RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag dis
}
int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) {
+ if (_packed)
+ return decodeADPCM(buffer, numSamples);
+ else {
+ uint32 bytesRead = _stream->read(buffer, numSamples);
+ if (_stream->eos())
+ _endOfData = true;
+
+ return bytesRead;
+ }
+}
+
+int RawZorkStream::decodeADPCM(int16 *buffer, const int numSamples) {
uint16 bytesRead = 0;
// 0: Left, 1: Right
@@ -72,7 +91,7 @@ int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) {
bytesRead++;
int16 index = _lastSample[channel].index;
- uint32 lookUpSample = amplitudeLookupTable[index];
+ uint32 lookUpSample = _amplitudeLookupTable[index];
int32 sample = 0;
@@ -98,7 +117,7 @@ int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) {
buffer[bytesRead - 1] = (int16)sample;
- index += stepAdjustmentTable[(encodedSample >> 4) & 7];
+ index += _stepAdjustmentTable[(encodedSample >> 4) & 7];
index = CLIP<uint16>(index, 0, 88);
_lastSample[channel].sample = sample;
@@ -124,16 +143,43 @@ bool RawZorkStream::rewind() {
Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream,
int rate,
bool stereo,
+ bool packed,
DisposeAfterUse::Flag disposeAfterUse) {
assert(stream->size() % 2 == 0);
- return new RawZorkStream(rate, stereo, disposeAfterUse, stream);
+ return new RawZorkStream(rate, stereo, packed, disposeAfterUse, stream);
}
Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size,
int rate,
bool stereo,
+ bool packed,
DisposeAfterUse::Flag disposeAfterUse) {
- return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, stereo, DisposeAfterUse::YES);
+ return makeRawZorkStream(new Common::MemoryReadStream(buffer, size, disposeAfterUse), rate, stereo, packed, DisposeAfterUse::YES);
+}
+
+Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine) {
+ Common::File *file = new Common::File();
+ assert(file->open(filePath));
+
+ Common::String fileName = getFileName(filePath);
+ fileName.toLowercase();
+
+ SoundParams soundParams;
+
+ if (engine->getGameId() == ZorkNemesis) {
+ for (int i = 0; i < 6; i++) {
+ if (zNemSoundParamLookupTable[i].identifier == (fileName[6]))
+ soundParams = zNemSoundParamLookupTable[i];
+ }
+ }
+ else if (engine->getGameId() == ZorkGrandInquisitor) {
+ for (int i = 0; i < 6; i++) {
+ if (zgiSoundParamLookupTable[i].identifier == (fileName[7]))
+ soundParams = zgiSoundParamLookupTable[i];
+ }
+ }
+
+ return makeRawZorkStream(wrapBufferedSeekableReadStream(file, 2048, DisposeAfterUse::YES), soundParams.rate, soundParams.stereo, soundParams.packed, DisposeAfterUse::YES);
}
} // End of namespace ZVision
diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h
index 7386c87f86..5efa27a1e3 100644
--- a/engines/zvision/zork_raw.h
+++ b/engines/zvision/zork_raw.h
@@ -31,22 +31,51 @@ class SeekableReadStream;
}
namespace ZVision {
+
+class ZVision;
+
+struct SoundParams {
+ char identifier;
+ uint16 rate;
+ bool stereo;
+ bool packed;
+};
+
+const SoundParams zNemSoundParamLookupTable[6] = {{'6', 0x2B11, false, false},
+ {'a', 0x5622, false, true},
+ {'b', 0x5622, true, true},
+ {'n', 0x2B11, false, true},
+ {'s', 0x5622, false, true},
+ {'t', 0x5622, true, true}
+};
+
+const SoundParams zgiSoundParamLookupTable[5] = {{'a',0x5622, false, false},
+ {'k',0x2B11, true, true},
+ {'p',0x5622, false, true},
+ {'q',0x5622, true, true},
+ {'u',0xAC44, true, true}
+};
+
/**
* This is a stream, which allows for playing raw ADPCM data from a stream.
*/
class RawZorkStream : public Audio::RewindableAudioStream {
public:
- RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream);
+ RawZorkStream(uint32 rate, bool stereo, bool packed, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream);
+ RawZorkStream(const Common::String &filePath, ZVision *engine);
~RawZorkStream() {
}
+public:
+
private:
const int _rate; // Sample rate of stream
Audio::Timestamp _playtime; // Calculated total play time
Common::DisposablePtr<Common::SeekableReadStream> _stream; // Stream to read data from
bool _endOfData; // Whether the stream end has been reached
bool _stereo;
+ bool _packed;
/**
* Holds the frequency and index from the last sample
@@ -57,9 +86,8 @@ private:
int16 index;
} _lastSample[2];
- static const int16 stepAdjustmentTable[8];
-
- static const int32 amplitudeLookupTable[89];
+ static const int16 _stepAdjustmentTable[8];
+ static const int32 _amplitudeLookupTable[89];
public:
int readBuffer(int16 *buffer, const int numSamples);
@@ -73,14 +101,7 @@ public:
bool rewind();
private:
- /**
- * Fill the temporary sample buffer used in readBuffer.
- *
- * @param maxSamples Maximum samples to read.
- * @return actual count of samples read.
- */
- int fillBuffer(int maxSamples);
- uint32 processBlock();
+ int decodeADPCM(int16 *buffer, const int numSamples);
};
/**
@@ -95,6 +116,7 @@ private:
Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size,
int rate,
bool stereo,
+ bool packed,
DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
/**
@@ -108,8 +130,11 @@ Audio::RewindableAudioStream *makeRawZorkStream(const byte *buffer, uint32 size,
Audio::RewindableAudioStream *makeRawZorkStream(Common::SeekableReadStream *stream,
int rate,
bool stereo,
+ bool packed,
DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
+Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine);
+
} // End of namespace ZVision
#endif