aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarisa-Chan2013-10-17 21:03:08 +0000
committerMarisa-Chan2013-10-18 19:48:57 +0000
commit2050987fa1ecc347bdc707b58d185804a875106d (patch)
tree4ab35f2ea10589ddf878f6b52d9b6b1e7b4d304e
parent7a3518d7c3c81b2e34dcbba0682dd8dc6e43b80d (diff)
downloadscummvm-rg350-2050987fa1ecc347bdc707b58d185804a875106d.tar.gz
scummvm-rg350-2050987fa1ecc347bdc707b58d185804a875106d.tar.bz2
scummvm-rg350-2050987fa1ecc347bdc707b58d185804a875106d.zip
ZVISION: Detach raw stream reader from RawZorkStream for creating correct avi raw reader.
-rw-r--r--engines/zvision/zork_avi_decoder.cpp8
-rw-r--r--engines/zvision/zork_avi_decoder.h22
-rw-r--r--engines/zvision/zork_raw.cpp130
-rw-r--r--engines/zvision/zork_raw.h51
4 files changed, 145 insertions, 66 deletions
diff --git a/engines/zvision/zork_avi_decoder.cpp b/engines/zvision/zork_avi_decoder.cpp
index a614f77bb7..0711cdf9d7 100644
--- a/engines/zvision/zork_avi_decoder.cpp
+++ b/engines/zvision/zork_avi_decoder.cpp
@@ -30,6 +30,7 @@
#include "common/stream.h"
#include "audio/audiostream.h"
+#include "audio/decoders/raw.h"
namespace ZVision {
@@ -43,9 +44,14 @@ void ZorkAVIDecoder::ZorkAVIAudioTrack::queueSound(Common::SeekableReadStream *s
if (_audStream) {
if (_wvInfo.tag == kWaveFormatZorkPCM) {
assert(_wvInfo.size == 8);
- _audStream->queueAudioStream(makeRawZorkStream(stream, _wvInfo.samplesPerSec, _audStream->isStereo(), DisposeAfterUse::YES), DisposeAfterUse::YES);
+ RawChunkStream::RawChunk chunk = decoder->readNextChunk(stream);
+ delete stream;
+
+ if (chunk.data)
+ _audStream->queueBuffer((byte *)chunk.data, chunk.size, DisposeAfterUse::YES, Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN | Audio::FLAG_STEREO);
}
} else {
+ warning("Got %d wave format in AVI\n", _wvInfo.tag);
delete stream;
}
}
diff --git a/engines/zvision/zork_avi_decoder.h b/engines/zvision/zork_avi_decoder.h
index ec2be1bb13..dc3e3327ed 100644
--- a/engines/zvision/zork_avi_decoder.h
+++ b/engines/zvision/zork_avi_decoder.h
@@ -25,25 +25,35 @@
#define ZORK_AVI_DECODER_H
#include "video/avi_decoder.h"
-
+#include "zork_raw.h"
namespace ZVision {
class ZorkAVIDecoder : public Video::AVIDecoder {
public:
ZorkAVIDecoder(Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType) :
- Video::AVIDecoder(soundType) {}
+ Video::AVIDecoder(soundType) {}
- virtual ~ZorkAVIDecoder() {}
+ virtual ~ZorkAVIDecoder() {}
private:
class ZorkAVIAudioTrack : public Video::AVIDecoder::AVIAudioTrack {
public:
ZorkAVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType) :
- Video::AVIDecoder::AVIAudioTrack(streamHeader, waveFormat, soundType) {}
- virtual ~ZorkAVIAudioTrack() {}
+ Video::AVIDecoder::AVIAudioTrack(streamHeader, waveFormat, soundType),
+ decoder(NULL) {
+ if (_audStream) {
+ decoder = new RawChunkStream(_audStream->isStereo());
+ }
+ }
+ virtual ~ZorkAVIAudioTrack() {
+ if (decoder)
+ delete decoder;
+ }
void queueSound(Common::SeekableReadStream *stream);
+ private:
+ RawChunkStream *decoder;
};
Video::AVIDecoder::AVIAudioTrack *createAudioTrack(Video::AVIDecoder::AVIStreamHeader sHeader, Video::AVIDecoder::PCMWaveFormat wvInfo);
@@ -51,7 +61,7 @@ private:
private:
// Audio Codecs
enum {
- kWaveFormatZorkPCM = 17 // special Zork PCM audio format (clashes with MS IMA ADPCM)
+ kWaveFormatZorkPCM = 17 // special Zork PCM audio format (clashes with MS IMA ADPCM)
};
};
diff --git a/engines/zvision/zork_raw.cpp b/engines/zvision/zork_raw.cpp
index 21613d9043..029600b758 100644
--- a/engines/zvision/zork_raw.cpp
+++ b/engines/zvision/zork_raw.cpp
@@ -41,65 +41,62 @@
namespace ZVision {
-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,
- 0x0010, 0x0011, 0x0013, 0x0015, 0x0017, 0x0019, 0x001C, 0x001F,
- 0x0022, 0x0025, 0x0029, 0x002D, 0x0032, 0x0037, 0x003C, 0x0042,
- 0x0049, 0x0050, 0x0058, 0x0061, 0x006B, 0x0076, 0x0082, 0x008F,
- 0x009D, 0x00AD, 0x00BE, 0x00D1, 0x00E6, 0x00FD, 0x0117, 0x0133,
- 0x0151, 0x0173, 0x0198, 0x01C1, 0x01EE, 0x0220, 0x0256, 0x0292,
- 0x02D4, 0x031C, 0x036C, 0x03C3, 0x0424, 0x048E, 0x0502, 0x0583,
- 0x0610, 0x06AB, 0x0756, 0x0812, 0x08E0, 0x09C3, 0x0ABD, 0x0BD0,
- 0x0CFF, 0x0E4C, 0x0FBA, 0x114C, 0x1307, 0x14EE, 0x1706, 0x1954,
- 0x1BDC, 0x1EA5, 0x21B6, 0x2515, 0x28CA, 0x2CDF, 0x315B, 0x364B,
- 0x3BB9, 0x41B2, 0x4844, 0x4F7E, 0x5771, 0x602F, 0x69CE, 0x7462, 0x7FFF};
-
-const SoundParams RawZorkStream::_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 RawZorkStream::_zgiSoundParamLookupTable[5] = {{'a',0x5622, false, false},
- {'k',0x2B11, true, true},
- {'p',0x5622, false, true},
- {'q',0x5622, true, true},
- {'u',0xAC44, true, true}
-};
-
-RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream)
- : _rate(rate),
- _stereo(0),
- _stream(stream, disposeStream),
- _endOfData(false) {
+const int16 RawChunkStream::_stepAdjustmentTable[8] = { -1, -1, -1, 1, 4, 7, 10, 12};
+
+const int32 RawChunkStream::_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,
+ 0x009D, 0x00AD, 0x00BE, 0x00D1, 0x00E6, 0x00FD, 0x0117, 0x0133,
+ 0x0151, 0x0173, 0x0198, 0x01C1, 0x01EE, 0x0220, 0x0256, 0x0292,
+ 0x02D4, 0x031C, 0x036C, 0x03C3, 0x0424, 0x048E, 0x0502, 0x0583,
+ 0x0610, 0x06AB, 0x0756, 0x0812, 0x08E0, 0x09C3, 0x0ABD, 0x0BD0,
+ 0x0CFF, 0x0E4C, 0x0FBA, 0x114C, 0x1307, 0x14EE, 0x1706, 0x1954,
+ 0x1BDC, 0x1EA5, 0x21B6, 0x2515, 0x28CA, 0x2CDF, 0x315B, 0x364B,
+ 0x3BB9, 0x41B2, 0x4844, 0x4F7E, 0x5771, 0x602F, 0x69CE, 0x7462, 0x7FFF
+ };
+
+RawChunkStream::RawChunkStream(bool stereo) {
if (stereo)
_stereo = 1;
+ else
+ _stereo = 0;
+
+ init();
+}
+void RawChunkStream::init() {
_lastSample[0].index = 0;
_lastSample[0].sample = 0;
_lastSample[1].index = 0;
_lastSample[1].sample = 0;
+}
- // Calculate the total playtime of the stream
- if (stereo)
- _playtime = Audio::Timestamp(0, _stream->size() / 2, rate);
- else
- _playtime = Audio::Timestamp(0, _stream->size(), rate);
+RawChunkStream::RawChunk RawChunkStream::readNextChunk(Common::SeekableReadStream *stream) {
+ RawChunk tmp;
+ tmp.size = 0;
+ tmp.data = NULL;
+
+ if (stream && (stream->size() == 0 || stream->eos()))
+ return tmp;
+
+ tmp.size = (stream->size() - stream->pos()) * 2;
+ tmp.data = (int16 *)calloc(tmp.size, 1);
+
+ readBuffer(tmp.data, stream, stream->size() - stream->pos());
+
+ return tmp;
}
-int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) {
- int bytesRead = 0;
+int RawChunkStream::readBuffer(int16 *buffer, Common::SeekableReadStream *stream, const int numSamples) {
+ int32 bytesRead = 0;
// 0: Left, 1: Right
uint channel = 0;
while (bytesRead < numSamples) {
- byte encodedSample = _stream->readByte();
- if (_stream->eos()) {
- _endOfData = true;
+ byte encodedSample = stream->readByte();
+ if (stream->eos()) {
return bytesRead;
}
bytesRead++;
@@ -140,6 +137,46 @@ int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) {
// Increment and wrap the channel
channel = (channel + 1) & _stereo;
}
+ return bytesRead;
+}
+
+const SoundParams RawZorkStream::_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 RawZorkStream::_zgiSoundParamLookupTable[5] = {{'a', 0x5622, false, false},
+ {'k', 0x2B11, true, true},
+ {'p', 0x5622, false, true},
+ {'q', 0x5622, true, true},
+ {'u', 0xAC44, true, true}
+};
+
+RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream)
+ : _rate(rate),
+ _stereo(0),
+ _stream(stream, disposeStream),
+ _endOfData(false),
+ _streamReader(stereo) {
+ if (stereo)
+ _stereo = 1;
+
+ // Calculate the total playtime of the stream
+ if (stereo)
+ _playtime = Audio::Timestamp(0, _stream->size() / 2, rate);
+ else
+ _playtime = Audio::Timestamp(0, _stream->size(), rate);
+}
+
+int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) {
+
+ int32 bytesRead = _streamReader.readBuffer(buffer, _stream.get(), numSamples);
+
+ if (_stream->eos())
+ _endOfData = true;
return bytesRead;
}
@@ -148,10 +185,7 @@ bool RawZorkStream::rewind() {
_stream->seek(0, 0);
_stream->clearErr();
_endOfData = false;
- _lastSample[0].index = 0;
- _lastSample[0].sample = 0;
- _lastSample[1].index = 0;
- _lastSample[1].sample = 0;
+ _streamReader.init();
return true;
}
diff --git a/engines/zvision/zork_raw.h b/engines/zvision/zork_raw.h
index 481ea79f2d..1f261ae139 100644
--- a/engines/zvision/zork_raw.h
+++ b/engines/zvision/zork_raw.h
@@ -41,6 +41,45 @@ struct SoundParams {
bool packed;
};
+
+/**
+ * This is a ADPCM stream-reader, this class holds context for multi-chunk reading and no buffers.
+ */
+class RawChunkStream {
+public:
+ RawChunkStream(bool stereo);
+
+ ~RawChunkStream() {
+ }
+private:
+ uint _stereo;
+
+ /**
+ * Holds the frequency and index from the last sample
+ * 0 holds the left channel, 1 holds the right channel
+ */
+ struct {
+ int32 sample;
+ int16 index;
+ } _lastSample[2];
+
+ static const int16 _stepAdjustmentTable[8];
+ static const int32 _amplitudeLookupTable[89];
+
+public:
+
+ struct RawChunk {
+ int16 *data;
+ uint32 size;
+ };
+
+ void init();
+ //Read next audio portion in new stream (needed for avi), return structure with buffer
+ RawChunk readNextChunk(Common::SeekableReadStream *stream);
+ //Read numSamples from stream to buffer
+ int readBuffer(int16 *buffer, Common::SeekableReadStream *stream, const int numSamples);
+};
+
/**
* This is a stream, which allows for playing raw ADPCM data from a stream.
*/
@@ -62,17 +101,7 @@ private:
bool _endOfData; // Whether the stream end has been reached
uint _stereo;
- /**
- * Holds the frequency and index from the last sample
- * 0 holds the left channel, 1 holds the right channel
- */
- struct {
- int32 sample;
- int16 index;
- } _lastSample[2];
-
- static const int16 _stepAdjustmentTable[8];
- static const int32 _amplitudeLookupTable[89];
+ RawChunkStream _streamReader;
public:
int readBuffer(int16 *buffer, const int numSamples);