[Scummvm-cvs-logs] scummvm master -> 9c47fdae293e05888d3b4ec45fd4b374d1022c0b

digitall digitall at scummvm.org
Sat Aug 4 20:18:19 CEST 2012


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b79221729b AUDIO: Fix DVI ADPCM to work with Mono streams using odd sized buffers.
9c47fdae29 AUDIO: Fix Oki ADPCM to work with Mono streams using odd sized buffers.


Commit: b79221729bd06a737bf140bf7cb5c0ff2a578681
    https://github.com/scummvm/scummvm/commit/b79221729bd06a737bf140bf7cb5c0ff2a578681
Author: D G Turner (digitall at scummvm.org)
Date: 2012-08-04T10:36:13-07:00

Commit Message:
AUDIO: Fix DVI ADPCM to work with Mono streams using odd sized buffers.

Changed paths:
    audio/decoders/adpcm.cpp
    audio/decoders/adpcm_intern.h



diff --git a/audio/decoders/adpcm.cpp b/audio/decoders/adpcm.cpp
index 535652a..5c96d52 100644
--- a/audio/decoders/adpcm.cpp
+++ b/audio/decoders/adpcm.cpp
@@ -117,13 +117,19 @@ int DVI_ADPCMStream::readBuffer(int16 *buffer, const int numSamples) {
 	int samples;
 	byte data;
 
-	assert(numSamples % 2 == 0);
+	for (samples = 0; samples < numSamples && !_stream->eos() && (_stream->pos() < _endpos); samples++) {
+		if (_decodedSampleCount == 0) {
+			data = _stream->readByte();
+			_decodedSamples[0] = decodeIMA((data >> 4) & 0x0f, 0);
+			_decodedSamples[1] = decodeIMA((data >> 0) & 0x0f, _channels == 2 ? 1 : 0);
+			_decodedSampleCount = 2;
+		}
 
-	for (samples = 0; samples < numSamples && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
-		data = _stream->readByte();
-		buffer[samples] = decodeIMA((data >> 4) & 0x0f);
-		buffer[samples + 1] = decodeIMA(data & 0x0f, _channels == 2 ? 1 : 0);
+		// (1 - (count - 1)) ensures that _decodedSamples acts as a FIFO of depth 2
+		buffer[samples] = _decodedSamples[1 - (_decodedSampleCount - 1)];
+		_decodedSampleCount--;
 	}
+
 	return samples;
 }
 
diff --git a/audio/decoders/adpcm_intern.h b/audio/decoders/adpcm_intern.h
index 31747aa..537ae02 100644
--- a/audio/decoders/adpcm_intern.h
+++ b/audio/decoders/adpcm_intern.h
@@ -108,9 +108,13 @@ public:
 class DVI_ADPCMStream : public Ima_ADPCMStream {
 public:
 	DVI_ADPCMStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse, uint32 size, int rate, int channels, uint32 blockAlign)
-		: Ima_ADPCMStream(stream, disposeAfterUse, size, rate, channels, blockAlign) {}
+		: Ima_ADPCMStream(stream, disposeAfterUse, size, rate, channels, blockAlign) { _decodedSampleCount = 0; }
 
 	virtual int readBuffer(int16 *buffer, const int numSamples);
+
+private:
+	uint8 _decodedSampleCount;
+	int16 _decodedSamples[2];
 };
 
 class Apple_ADPCMStream : public Ima_ADPCMStream {


Commit: 9c47fdae293e05888d3b4ec45fd4b374d1022c0b
    https://github.com/scummvm/scummvm/commit/9c47fdae293e05888d3b4ec45fd4b374d1022c0b
Author: D G Turner (digitall at scummvm.org)
Date: 2012-08-04T10:38:12-07:00

Commit Message:
AUDIO: Fix Oki ADPCM to work with Mono streams using odd sized buffers.

Changed paths:
    audio/decoders/adpcm.cpp
    audio/decoders/adpcm_intern.h



diff --git a/audio/decoders/adpcm.cpp b/audio/decoders/adpcm.cpp
index 5c96d52..e729742 100644
--- a/audio/decoders/adpcm.cpp
+++ b/audio/decoders/adpcm.cpp
@@ -71,13 +71,19 @@ int Oki_ADPCMStream::readBuffer(int16 *buffer, const int numSamples) {
 	int samples;
 	byte data;
 
-	assert(numSamples % 2 == 0);
+	for (samples = 0; samples < numSamples && !_stream->eos() && (_stream->pos() < _endpos); samples++) {
+		if (_decodedSampleCount == 0) {
+			data = _stream->readByte();
+			_decodedSamples[0] = decodeOKI((data >> 4) & 0x0f);
+			_decodedSamples[1] = decodeOKI((data >> 0) & 0x0f);
+			_decodedSampleCount = 2;
+		}
 
-	for (samples = 0; samples < numSamples && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
-		data = _stream->readByte();
-		buffer[samples] = decodeOKI((data >> 4) & 0x0f);
-		buffer[samples + 1] = decodeOKI(data & 0x0f);
+		// (1 - (count - 1)) ensures that _decodedSamples acts as a FIFO of depth 2
+		buffer[samples] = _decodedSamples[1 - (_decodedSampleCount - 1)];
+		_decodedSampleCount--;
 	}
+
 	return samples;
 }
 
diff --git a/audio/decoders/adpcm_intern.h b/audio/decoders/adpcm_intern.h
index 537ae02..423c4af 100644
--- a/audio/decoders/adpcm_intern.h
+++ b/audio/decoders/adpcm_intern.h
@@ -89,6 +89,10 @@ public:
 
 protected:
 	int16 decodeOKI(byte);
+
+private:
+	uint8 _decodedSampleCount;
+	int16 _decodedSamples[2];
 };
 
 class Ima_ADPCMStream : public ADPCMStream {






More information about the Scummvm-git-logs mailing list