[Scummvm-cvs-logs] scummvm master -> 4e849092d23689f7a82f834e51279401b4349893

clone2727 clone2727 at gmail.com
Wed Aug 24 15:58:59 CEST 2011


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

Summary:
adb69a5a39 AUDIO: Rename Vag to XA
40fd9ce27c AUDIO: Remove default rate parameter from xa
4e849092d2 AUDIO: Add a DisposeAfterUse parameter to makeXAStream


Commit: adb69a5a39bb58a0ac6866b64ede228692a80488
    https://github.com/scummvm/scummvm/commit/adb69a5a39bb58a0ac6866b64ede228692a80488
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2011-08-24T06:54:19-07:00

Commit Message:
AUDIO: Rename Vag to XA

Vag is really an XA container, and one that we do not have a decoder for (nor need)

Changed paths:
  A audio/decoders/xa.cpp
  A audio/decoders/xa.h
  R audio/decoders/vag.cpp
  R audio/decoders/vag.h
    audio/module.mk
    engines/sword1/music.cpp
    engines/sword1/sound.cpp
    engines/sword2/music.cpp
    engines/sword2/sound.cpp
    engines/tinsel/sound.cpp



diff --git a/audio/decoders/vag.cpp b/audio/decoders/vag.cpp
deleted file mode 100644
index 10ef697..0000000
--- a/audio/decoders/vag.cpp
+++ /dev/null
@@ -1,147 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "audio/decoders/vag.h"
-#include "audio/audiostream.h"
-#include "common/stream.h"
-
-namespace Audio {
-
-class VagStream : public Audio::RewindableAudioStream {
-public:
-	VagStream(Common::SeekableReadStream *stream, int rate);
-	~VagStream();
-
-	bool isStereo() const { return false; }
-	bool endOfData() const { return _stream->pos() == _stream->size(); }
-	int getRate() const { return _rate; }
-	int readBuffer(int16 *buffer, const int numSamples);
-
-	bool rewind();
-private:
-	Common::SeekableReadStream *_stream;
-
-	byte _predictor;
-	double _samples[28];
-	byte _samplesRemaining;
-	int _rate;
-	double _s1, _s2;
-};
-
-VagStream::VagStream(Common::SeekableReadStream *stream, int rate) : _stream(stream) {
-	_samplesRemaining = 0;
-	_predictor = 0;
-	_s1 = _s2 = 0.0;
-	_rate = rate;
-}
-
-
-VagStream::~VagStream() {
-	delete _stream;
-}
-
-static const double s_vagDataTable[5][2] =
-	{
-		{  0.0, 0.0 },
-		{  60.0 / 64.0,  0.0 },
-		{  115.0 / 64.0, -52.0 / 64.0 },
-		{  98.0 / 64.0, -55.0 / 64.0 },
-		{  122.0 / 64.0, -60.0 / 64.0 }
-	};
-
-int VagStream::readBuffer(int16 *buffer, const int numSamples) {
-	int32 samplesDecoded = 0;
-
-	if (_samplesRemaining) {
-		byte i = 0;
-
-		for (i = 28 - _samplesRemaining; i < 28 && samplesDecoded < numSamples; i++) {
-			_samples[i] = _samples[i] + _s1 * s_vagDataTable[_predictor][0] + _s2 * s_vagDataTable[_predictor][1];
-			_s2 = _s1;
-			_s1 = _samples[i];
-			int16 d = (int) (_samples[i] + 0.5);
-			buffer[samplesDecoded] = d;
-			samplesDecoded++;
-		}
-
-#if 0
-		assert(i == 28); // We're screwed if this fails :P
-#endif
-		// This might mean the file is corrupted, or that the stream has
-		// been closed.
-		if (i != 28) return 0;
-
-		_samplesRemaining = 0;
-	}
-
-	while (samplesDecoded < numSamples) {
-		byte i = 0;
-
-		_predictor = _stream->readByte();
-		byte shift = _predictor & 0xf;
-		_predictor >>= 4;
-
-		if (_stream->readByte() == 7)
-			return samplesDecoded;
-
-		for (i = 0; i < 28; i += 2) {
-			byte d = _stream->readByte();
-			int16 s = (d & 0xf) << 12;
-			if (s & 0x8000)
-				s |= 0xffff0000;
-			_samples[i] = (double)(s >> shift);
-			s = (d & 0xf0) << 8;
-			if (s & 0x8000)
-				s |= 0xffff0000;
-			_samples[i + 1] = (double)(s >> shift);
-		}
-
-		for (i = 0; i < 28 && samplesDecoded < numSamples; i++) {
-			_samples[i] = _samples[i] + _s1 * s_vagDataTable[_predictor][0] + _s2 * s_vagDataTable[_predictor][1];
-			_s2 = _s1;
-			_s1 = _samples[i];
-			int16 d = (int) (_samples[i] + 0.5);
-			buffer[samplesDecoded] = d;
-			samplesDecoded++;
-		}
-
-		if (i != 27)
-			_samplesRemaining = 28 - i;
-	}
-
-	return samplesDecoded;
-}
-
-bool VagStream::rewind() {
-	_stream->seek(0);
-	_samplesRemaining = 0;
-	_predictor = 0;
-	_s1 = _s2 = 0.0;
-
-	return true;
-}
-
-RewindableAudioStream *makeVagStream(Common::SeekableReadStream *stream, int rate) {
-	return new VagStream(stream, rate);
-}
-
-}
diff --git a/audio/decoders/vag.h b/audio/decoders/vag.h
deleted file mode 100644
index b80fbdb..0000000
--- a/audio/decoders/vag.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-/**
- * @file
- * Sound decoder used in engines:
- * - sword1 (PSX port of the game)
- * - sword2 (PSX port of the game)
- * - tinsel (PSX port of the game)
- */
-
-#ifndef SOUND_VAG_H
-#define SOUND_VAG_H
-
-namespace Common {
-class SeekableReadStream;
-}
-
-namespace Audio {
-
-class RewindableAudioStream;
-
-/**
- * Takes an input stream containing Vag sound data and creates
- * an RewindableAudioStream from that.
- *
- * @param stream            the SeekableReadStream from which to read the ADPCM data
- * @param rate              the sampling rate
- * @return   a new RewindableAudioStream, or NULL, if an error occurred
- */
-RewindableAudioStream *makeVagStream(
-	Common::SeekableReadStream *stream,
-	int rate = 11025);
-
-} // End of namespace Sword1
-
-#endif
diff --git a/audio/decoders/xa.cpp b/audio/decoders/xa.cpp
new file mode 100644
index 0000000..2b8c9b2
--- /dev/null
+++ b/audio/decoders/xa.cpp
@@ -0,0 +1,147 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "audio/decoders/xa.h"
+#include "audio/audiostream.h"
+#include "common/stream.h"
+
+namespace Audio {
+
+class XAStream : public Audio::RewindableAudioStream {
+public:
+	XAStream(Common::SeekableReadStream *stream, int rate);
+	~XAStream();
+
+	bool isStereo() const { return false; }
+	bool endOfData() const { return _stream->pos() == _stream->size(); }
+	int getRate() const { return _rate; }
+	int readBuffer(int16 *buffer, const int numSamples);
+
+	bool rewind();
+private:
+	Common::SeekableReadStream *_stream;
+
+	byte _predictor;
+	double _samples[28];
+	byte _samplesRemaining;
+	int _rate;
+	double _s1, _s2;
+};
+
+XAStream::XAStream(Common::SeekableReadStream *stream, int rate) : _stream(stream) {
+	_samplesRemaining = 0;
+	_predictor = 0;
+	_s1 = _s2 = 0.0;
+	_rate = rate;
+}
+
+
+XAStream::~XAStream() {
+	delete _stream;
+}
+
+static const double s_xaDataTable[5][2] =
+	{
+		{  0.0, 0.0 },
+		{  60.0 / 64.0,  0.0 },
+		{  115.0 / 64.0, -52.0 / 64.0 },
+		{  98.0 / 64.0, -55.0 / 64.0 },
+		{  122.0 / 64.0, -60.0 / 64.0 }
+	};
+
+int XAStream::readBuffer(int16 *buffer, const int numSamples) {
+	int32 samplesDecoded = 0;
+
+	if (_samplesRemaining) {
+		byte i = 0;
+
+		for (i = 28 - _samplesRemaining; i < 28 && samplesDecoded < numSamples; i++) {
+			_samples[i] = _samples[i] + _s1 * s_xaDataTable[_predictor][0] + _s2 * s_xaDataTable[_predictor][1];
+			_s2 = _s1;
+			_s1 = _samples[i];
+			int16 d = (int) (_samples[i] + 0.5);
+			buffer[samplesDecoded] = d;
+			samplesDecoded++;
+		}
+
+#if 0
+		assert(i == 28); // We're screwed if this fails :P
+#endif
+		// This might mean the file is corrupted, or that the stream has
+		// been closed.
+		if (i != 28) return 0;
+
+		_samplesRemaining = 0;
+	}
+
+	while (samplesDecoded < numSamples) {
+		byte i = 0;
+
+		_predictor = _stream->readByte();
+		byte shift = _predictor & 0xf;
+		_predictor >>= 4;
+
+		if (_stream->readByte() == 7)
+			return samplesDecoded;
+
+		for (i = 0; i < 28; i += 2) {
+			byte d = _stream->readByte();
+			int16 s = (d & 0xf) << 12;
+			if (s & 0x8000)
+				s |= 0xffff0000;
+			_samples[i] = (double)(s >> shift);
+			s = (d & 0xf0) << 8;
+			if (s & 0x8000)
+				s |= 0xffff0000;
+			_samples[i + 1] = (double)(s >> shift);
+		}
+
+		for (i = 0; i < 28 && samplesDecoded < numSamples; i++) {
+			_samples[i] = _samples[i] + _s1 * s_xaDataTable[_predictor][0] + _s2 * s_xaDataTable[_predictor][1];
+			_s2 = _s1;
+			_s1 = _samples[i];
+			int16 d = (int) (_samples[i] + 0.5);
+			buffer[samplesDecoded] = d;
+			samplesDecoded++;
+		}
+
+		if (i != 27)
+			_samplesRemaining = 28 - i;
+	}
+
+	return samplesDecoded;
+}
+
+bool XAStream::rewind() {
+	_stream->seek(0);
+	_samplesRemaining = 0;
+	_predictor = 0;
+	_s1 = _s2 = 0.0;
+
+	return true;
+}
+
+RewindableAudioStream *makeXAStream(Common::SeekableReadStream *stream, int rate) {
+	return new XAStream(stream, rate);
+}
+
+} // End of namespace Audio
diff --git a/audio/decoders/xa.h b/audio/decoders/xa.h
new file mode 100644
index 0000000..ed3213f
--- /dev/null
+++ b/audio/decoders/xa.h
@@ -0,0 +1,56 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/**
+ * @file
+ * Sound decoder used in engines:
+ * - sword1 (PSX port of the game)
+ * - sword2 (PSX port of the game)
+ * - tinsel (PSX port of the game)
+ */
+
+#ifndef AUDIO_DECODERS_XA_H
+#define AUDIO_DECODERS_XA_H
+
+namespace Common {
+class SeekableReadStream;
+}
+
+namespace Audio {
+
+class RewindableAudioStream;
+
+/**
+ * Takes an input stream containing XA ADPCM sound data and creates
+ * an RewindableAudioStream from that.
+ *
+ * @param stream            the SeekableReadStream from which to read the XA ADPCM data
+ * @param rate              the sampling rate
+ * @return   a new RewindableAudioStream, or NULL, if an error occurred
+ */
+RewindableAudioStream *makeXAStream(
+	Common::SeekableReadStream *stream,
+	int rate = 11025);
+
+} // End of namespace Audio
+
+#endif
diff --git a/audio/module.mk b/audio/module.mk
index 46cb994..e3aa0aa 100644
--- a/audio/module.mk
+++ b/audio/module.mk
@@ -23,10 +23,10 @@ MODULE_OBJS := \
 	decoders/qdm2.o \
 	decoders/quicktime.o \
 	decoders/raw.o \
-	decoders/vag.o \
 	decoders/voc.o \
 	decoders/vorbis.o \
 	decoders/wave.o \
+	decoders/xa.o \
 	mods/infogrames.o \
 	mods/maxtrax.o \
 	mods/module.o \
diff --git a/engines/sword1/music.cpp b/engines/sword1/music.cpp
index b4656ff..7a19944 100644
--- a/engines/sword1/music.cpp
+++ b/engines/sword1/music.cpp
@@ -35,7 +35,7 @@
 #include "audio/decoders/mp3.h"
 #include "audio/decoders/vorbis.h"
 #include "audio/decoders/wave.h"
-#include "audio/decoders/vag.h"
+#include "audio/decoders/xa.h"
 
 #define SMP_BUFSIZE 8192
 
@@ -131,7 +131,7 @@ bool MusicHandle::playPSX(uint16 id, bool loop) {
 	// not over file size
 	if ((size != 0) && (size != 0xffffffff) && ((int32)(offset + size) <= _file.size())) {
 		_file.seek(offset, SEEK_SET);
-		_audioSource = Audio::makeLoopingAudioStream(Audio::makeVagStream(_file.readStream(size)), loop ? 0 : 1);
+		_audioSource = Audio::makeLoopingAudioStream(Audio::makeXAStream(_file.readStream(size)), loop ? 0 : 1);
 		fadeUp();
 	} else {
 		_audioSource = NULL;
diff --git a/engines/sword1/sound.cpp b/engines/sword1/sound.cpp
index f7ab9ca..ae693bc 100644
--- a/engines/sword1/sound.cpp
+++ b/engines/sword1/sound.cpp
@@ -38,7 +38,7 @@
 #include "audio/decoders/raw.h"
 #include "audio/decoders/vorbis.h"
 #include "audio/decoders/wave.h"
-#include "audio/decoders/vag.h"
+#include "audio/decoders/xa.h"
 
 namespace Sword1 {
 
@@ -256,7 +256,7 @@ void Sound::playSample(QueueElement *elem) {
 
 					if (SwordEngine::isPsx()) {
 						uint32 size = READ_LE_UINT32(sampleData);
-						Audio::AudioStream *audStream = Audio::makeLoopingAudioStream(Audio::makeVagStream(new Common::MemoryReadStream(sampleData + 4, size-4)), (_fxList[elem->id].type == FX_LOOP) ? 0 : 1);
+						Audio::AudioStream *audStream = Audio::makeLoopingAudioStream(Audio::makeXAStream(new Common::MemoryReadStream(sampleData + 4, size-4)), (_fxList[elem->id].type == FX_LOOP) ? 0 : 1);
 						_mixer->playStream(Audio::Mixer::kSFXSoundType, &elem->handle, audStream, elem->id, volume, pan);
 					} else {
 						uint32 size = READ_LE_UINT32(sampleData + 0x28);
@@ -364,7 +364,7 @@ bool Sound::startSpeech(uint16 roomNo, uint16 localNo) {
 			_cowFile.seek(index * 2048);
 			Common::SeekableReadStream *tmp = _cowFile.readStream(sampleSize);
 			assert(tmp);
-			stream = Audio::makeVagStream(tmp);
+			stream = Audio::makeXAStream(tmp);
 			_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, stream, SOUND_SPEECH_ID, speechVol, speechPan);
 			// with compressed audio, we can't calculate the wave volume.
 			// so default to talking.
diff --git a/engines/sword2/music.cpp b/engines/sword2/music.cpp
index 63116e9..1e52cc2 100644
--- a/engines/sword2/music.cpp
+++ b/engines/sword2/music.cpp
@@ -39,7 +39,7 @@
 #include "audio/decoders/vorbis.h"
 #include "audio/decoders/flac.h"
 #include "audio/decoders/wave.h"
-#include "audio/decoders/vag.h"
+#include "audio/decoders/xa.h"
 #include "audio/rate.h"
 
 #include "sword2/sword2.h"
@@ -267,7 +267,7 @@ Audio::AudioStream *makePSXCLUStream(Common::File *file, int size) {
 
 	byte *buffer = (byte *)malloc(size);
 	file->read(buffer, size);
-	return Audio::makeVagStream(new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES));
+	return Audio::makeXAStream(new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES));
 }
 
 // ----------------------------------------------------------------------------
diff --git a/engines/sword2/sound.cpp b/engines/sword2/sound.cpp
index 19e244e..d9260cc 100644
--- a/engines/sword2/sound.cpp
+++ b/engines/sword2/sound.cpp
@@ -47,7 +47,7 @@
 #include "sword2/sound.h"
 
 #include "audio/decoders/wave.h"
-#include "audio/decoders/vag.h"
+#include "audio/decoders/xa.h"
 
 #define Debug_Printf _vm->_debugger->DebugPrintf
 
@@ -234,7 +234,7 @@ void Sound::playMovieSound(int32 res, int type) {
 		Audio::RewindableAudioStream *input = 0;
 
 		if (Sword2Engine::isPsx()) {
-			input = Audio::makeVagStream(stream);
+			input = Audio::makeXAStream(stream);
 		} else {
 			input = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
 		}
@@ -361,7 +361,7 @@ int32 Sound::playFx(Audio::SoundHandle *handle, byte *data, uint32 len, uint8 vo
 	Audio::RewindableAudioStream *input = 0;
 
 	if (Sword2Engine::isPsx())
-		input = Audio::makeVagStream(stream);
+		input = Audio::makeXAStream(stream);
 	else
 		input = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
 
diff --git a/engines/tinsel/sound.cpp b/engines/tinsel/sound.cpp
index bf48dd1..130928d 100644
--- a/engines/tinsel/sound.cpp
+++ b/engines/tinsel/sound.cpp
@@ -41,8 +41,9 @@
 #include "audio/decoders/flac.h"
 #include "audio/decoders/mp3.h"
 #include "audio/decoders/raw.h"
-#include "audio/decoders/vag.h"
 #include "audio/decoders/vorbis.h"
+#include "audio/decoders/xa.h"
+
 
 #include "gui/message.h"
 
@@ -106,8 +107,8 @@ bool SoundManager::playSample(int id, Audio::Mixer::SoundType type, Audio::Sound
 		error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage));
 
 	if (TinselV1PSX) {
-		// Read the stream and create a VAG Audio stream
-		Audio::AudioStream *vagStream = Audio::makeVagStream(_sampleStream.readStream(sampleLen), 44100);
+		// Read the stream and create a XA ADPCM audio stream
+		Audio::AudioStream *xaStream = Audio::makeXAStream(_sampleStream.readStream(sampleLen), 44100);
 
 		// FIXME: Should set this in a different place ;)
 		_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, _vm->_config->_soundVolume);
@@ -115,7 +116,7 @@ bool SoundManager::playSample(int id, Audio::Mixer::SoundType type, Audio::Sound
 		_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, _vm->_config->_voiceVolume);
 
 		// Play the audio stream
-		_vm->_mixer->playStream(type, &curChan.handle, vagStream);
+		_vm->_mixer->playStream(type, &curChan.handle, xaStream);
 	} else {
 		// allocate a buffer
 		byte *sampleBuf = (byte *)malloc(sampleLen);


Commit: 40fd9ce27c8579f97e8ca5c0917366b1a069c5e9
    https://github.com/scummvm/scummvm/commit/40fd9ce27c8579f97e8ca5c0917366b1a069c5e9
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2011-08-24T06:54:19-07:00

Commit Message:
AUDIO: Remove default rate parameter from xa

Changed paths:
    audio/decoders/xa.h
    engines/sword1/music.cpp
    engines/sword1/sound.cpp
    engines/sword2/music.cpp
    engines/sword2/sound.cpp



diff --git a/audio/decoders/xa.h b/audio/decoders/xa.h
index ed3213f..68c0715 100644
--- a/audio/decoders/xa.h
+++ b/audio/decoders/xa.h
@@ -49,7 +49,7 @@ class RewindableAudioStream;
  */
 RewindableAudioStream *makeXAStream(
 	Common::SeekableReadStream *stream,
-	int rate = 11025);
+	int rate);
 
 } // End of namespace Audio
 
diff --git a/engines/sword1/music.cpp b/engines/sword1/music.cpp
index 7a19944..f31faff 100644
--- a/engines/sword1/music.cpp
+++ b/engines/sword1/music.cpp
@@ -131,7 +131,7 @@ bool MusicHandle::playPSX(uint16 id, bool loop) {
 	// not over file size
 	if ((size != 0) && (size != 0xffffffff) && ((int32)(offset + size) <= _file.size())) {
 		_file.seek(offset, SEEK_SET);
-		_audioSource = Audio::makeLoopingAudioStream(Audio::makeXAStream(_file.readStream(size)), loop ? 0 : 1);
+		_audioSource = Audio::makeLoopingAudioStream(Audio::makeXAStream(_file.readStream(size), 11025), loop ? 0 : 1);
 		fadeUp();
 	} else {
 		_audioSource = NULL;
diff --git a/engines/sword1/sound.cpp b/engines/sword1/sound.cpp
index ae693bc..faa07b1 100644
--- a/engines/sword1/sound.cpp
+++ b/engines/sword1/sound.cpp
@@ -256,7 +256,7 @@ void Sound::playSample(QueueElement *elem) {
 
 					if (SwordEngine::isPsx()) {
 						uint32 size = READ_LE_UINT32(sampleData);
-						Audio::AudioStream *audStream = Audio::makeLoopingAudioStream(Audio::makeXAStream(new Common::MemoryReadStream(sampleData + 4, size-4)), (_fxList[elem->id].type == FX_LOOP) ? 0 : 1);
+						Audio::AudioStream *audStream = Audio::makeLoopingAudioStream(Audio::makeXAStream(new Common::MemoryReadStream(sampleData + 4, size-4), 11025), (_fxList[elem->id].type == FX_LOOP) ? 0 : 1);
 						_mixer->playStream(Audio::Mixer::kSFXSoundType, &elem->handle, audStream, elem->id, volume, pan);
 					} else {
 						uint32 size = READ_LE_UINT32(sampleData + 0x28);
@@ -364,7 +364,7 @@ bool Sound::startSpeech(uint16 roomNo, uint16 localNo) {
 			_cowFile.seek(index * 2048);
 			Common::SeekableReadStream *tmp = _cowFile.readStream(sampleSize);
 			assert(tmp);
-			stream = Audio::makeXAStream(tmp);
+			stream = Audio::makeXAStream(tmp, 11025);
 			_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, stream, SOUND_SPEECH_ID, speechVol, speechPan);
 			// with compressed audio, we can't calculate the wave volume.
 			// so default to talking.
diff --git a/engines/sword2/music.cpp b/engines/sword2/music.cpp
index 1e52cc2..1bb08fd 100644
--- a/engines/sword2/music.cpp
+++ b/engines/sword2/music.cpp
@@ -267,7 +267,7 @@ Audio::AudioStream *makePSXCLUStream(Common::File *file, int size) {
 
 	byte *buffer = (byte *)malloc(size);
 	file->read(buffer, size);
-	return Audio::makeXAStream(new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES));
+	return Audio::makeXAStream(new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES), 11025);
 }
 
 // ----------------------------------------------------------------------------
diff --git a/engines/sword2/sound.cpp b/engines/sword2/sound.cpp
index d9260cc..aea33e9 100644
--- a/engines/sword2/sound.cpp
+++ b/engines/sword2/sound.cpp
@@ -234,7 +234,7 @@ void Sound::playMovieSound(int32 res, int type) {
 		Audio::RewindableAudioStream *input = 0;
 
 		if (Sword2Engine::isPsx()) {
-			input = Audio::makeXAStream(stream);
+			input = Audio::makeXAStream(stream, 11025);
 		} else {
 			input = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
 		}
@@ -361,7 +361,7 @@ int32 Sound::playFx(Audio::SoundHandle *handle, byte *data, uint32 len, uint8 vo
 	Audio::RewindableAudioStream *input = 0;
 
 	if (Sword2Engine::isPsx())
-		input = Audio::makeXAStream(stream);
+		input = Audio::makeXAStream(stream, 11025);
 	else
 		input = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
 


Commit: 4e849092d23689f7a82f834e51279401b4349893
    https://github.com/scummvm/scummvm/commit/4e849092d23689f7a82f834e51279401b4349893
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2011-08-24T06:54:19-07:00

Commit Message:
AUDIO: Add a DisposeAfterUse parameter to makeXAStream

Changed paths:
    audio/decoders/xa.cpp
    audio/decoders/xa.h



diff --git a/audio/decoders/xa.cpp b/audio/decoders/xa.cpp
index 2b8c9b2..9871775 100644
--- a/audio/decoders/xa.cpp
+++ b/audio/decoders/xa.cpp
@@ -28,7 +28,7 @@ namespace Audio {
 
 class XAStream : public Audio::RewindableAudioStream {
 public:
-	XAStream(Common::SeekableReadStream *stream, int rate);
+	XAStream(Common::SeekableReadStream *stream, int rate, DisposeAfterUse::Flag disposeAfterUse);
 	~XAStream();
 
 	bool isStereo() const { return false; }
@@ -39,6 +39,7 @@ public:
 	bool rewind();
 private:
 	Common::SeekableReadStream *_stream;
+	DisposeAfterUse::Flag _disposeAfterUse;
 
 	byte _predictor;
 	double _samples[28];
@@ -47,7 +48,8 @@ private:
 	double _s1, _s2;
 };
 
-XAStream::XAStream(Common::SeekableReadStream *stream, int rate) : _stream(stream) {
+XAStream::XAStream(Common::SeekableReadStream *stream, int rate, DisposeAfterUse::Flag disposeAfterUse)
+		: _stream(stream), _disposeAfterUse(disposeAfterUse) {
 	_samplesRemaining = 0;
 	_predictor = 0;
 	_s1 = _s2 = 0.0;
@@ -56,7 +58,8 @@ XAStream::XAStream(Common::SeekableReadStream *stream, int rate) : _stream(strea
 
 
 XAStream::~XAStream() {
-	delete _stream;
+	if (_disposeAfterUse == DisposeAfterUse::YES)
+		delete _stream;
 }
 
 static const double s_xaDataTable[5][2] =
@@ -140,8 +143,8 @@ bool XAStream::rewind() {
 	return true;
 }
 
-RewindableAudioStream *makeXAStream(Common::SeekableReadStream *stream, int rate) {
-	return new XAStream(stream, rate);
+RewindableAudioStream *makeXAStream(Common::SeekableReadStream *stream, int rate, DisposeAfterUse::Flag disposeAfterUse) {
+	return new XAStream(stream, rate, disposeAfterUse);
 }
 
 } // End of namespace Audio
diff --git a/audio/decoders/xa.h b/audio/decoders/xa.h
index 68c0715..cf28d80 100644
--- a/audio/decoders/xa.h
+++ b/audio/decoders/xa.h
@@ -31,6 +31,8 @@
 #ifndef AUDIO_DECODERS_XA_H
 #define AUDIO_DECODERS_XA_H
 
+#include "common/types.h"
+
 namespace Common {
 class SeekableReadStream;
 }
@@ -45,11 +47,13 @@ class RewindableAudioStream;
  *
  * @param stream            the SeekableReadStream from which to read the XA ADPCM data
  * @param rate              the sampling rate
+ * @param disposeAfterUse   whether to delete the stream after use.
  * @return   a new RewindableAudioStream, or NULL, if an error occurred
  */
 RewindableAudioStream *makeXAStream(
 	Common::SeekableReadStream *stream,
-	int rate);
+	int rate,
+	DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
 
 } // End of namespace Audio
 






More information about the Scummvm-git-logs mailing list