[Scummvm-git-logs] scummvm master -> d400bb5833c6ef75ab52fe1e1e2beeb2456aafe1

bluegr noreply at scummvm.org
Wed Feb 5 08:59:18 UTC 2025


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

Summary:
d400bb5833 SCUMM: WIP code for headerless WMA streams used in MI1:SE and MI2:SE


Commit: d400bb5833c6ef75ab52fe1e1e2beeb2456aafe1
    https://github.com/scummvm/scummvm/commit/d400bb5833c6ef75ab52fe1e1e2beeb2456aafe1
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2025-02-05T10:57:25+02:00

Commit Message:
SCUMM: WIP code for headerless WMA streams used in MI1:SE and MI2:SE

It still doesn't sound right, so it's disabled, for now

Changed paths:
    engines/scumm/soundse.cpp
    engines/scumm/soundse.h


diff --git a/engines/scumm/soundse.cpp b/engines/scumm/soundse.cpp
index cb0b61d57fe..e7b0a44757a 100644
--- a/engines/scumm/soundse.cpp
+++ b/engines/scumm/soundse.cpp
@@ -32,6 +32,7 @@
 #include "audio/decoders/adpcm.h"
 #include "audio/decoders/mp3.h"
 #include "audio/decoders/raw.h"
+#include "audio/decoders/wma.h"
 
 namespace Scumm {
 
@@ -662,17 +663,12 @@ Audio::SeekableAudioStream *SoundSE::createSoundStream(Common::SeekableSubReadSt
 	}
 	case kXWBCodecWMA:
 		// TODO: Implement WMA codec
-		/*return new Audio::WMACodec(
-			2,
-			entry.rate,
-			entry.channels,
-			entry.bits,
-			entry.align,
-			stream
-		);*/
 		warning("createSoundStream: WMA codec not implemented");
 		delete stream;
 		return nullptr;
+#if 0
+		return new HeaderlessWMAStream(stream, entry, disposeAfterUse);
+#endif
 	case kFSBCodecMP3:
 #ifdef USE_MAD
 		return Audio::makeMP3Stream(
@@ -929,4 +925,67 @@ void SoundSE::stopAmbience() {
 	_mixer->stopHandle(_ambienceHandle);
 }
 
+#if 0
+HeaderlessWMAStream::HeaderlessWMAStream(
+					Common::SeekableReadStream *stream,
+					AudioEntry entry,
+					DisposeAfterUse::Flag disposeAfterUse) :
+					_stream(stream), _entry(entry), _disposeAfterUse(disposeAfterUse) {
+	// Taken from https://github.com/bgbennyboy/Monkey-Island-Explorer/blob/master/uMIExplorer_XWBManager.pas
+	const uint16 blockAlignArray[] = {
+		929, 1487, 1280, 2230, 8917,
+		8192, 4459, 5945, 2304, 1536,
+		1485, 1008, 2731, 4096, 6827,
+		5462, 1280
+	};
+
+	const uint16 index = _entry.align < ARRAYSIZE(blockAlignArray) ? _entry.align : 0;
+	const uint32 blockAlign = blockAlignArray[index];
+	const uint32 bitRate = (_entry.bits + 1) * 8;
+
+	_wmaCodec = new Audio::WMACodec(2, _entry.rate, _entry.channels, bitRate, blockAlign);
+	_audioStream = _wmaCodec->decodeFrame(*stream);
+}
+
+HeaderlessWMAStream::~HeaderlessWMAStream() {
+	delete _wmaCodec;
+	delete _audioStream;
+	if (_disposeAfterUse == DisposeAfterUse::Flag::YES)
+		delete _stream;
+}
+
+bool HeaderlessWMAStream::seek(const Audio::Timestamp &where) {
+	if (where == 0) {
+		return rewind();
+	}
+
+	// Seeking is not supported
+	return false;
+}
+
+int HeaderlessWMAStream::readBuffer(int16 *buffer, const int numSamples) {
+	int samplesDecoded = 0;
+
+	for (;;) {
+		if (_audioStream) {
+			samplesDecoded += _audioStream->readBuffer(buffer + samplesDecoded, numSamples - samplesDecoded);
+
+			if (_audioStream->endOfData()) {
+				delete _audioStream;
+				_audioStream = nullptr;
+			}
+		}
+
+		if (samplesDecoded == numSamples || endOfData())
+			break;
+
+		if (!_audioStream) {
+			_audioStream = _wmaCodec->decodeFrame(*_stream);
+		}
+	}
+
+	return samplesDecoded;
+}
+#endif
+
 } // End of namespace Scumm
diff --git a/engines/scumm/soundse.h b/engines/scumm/soundse.h
index 5879be30efa..4836af84ddc 100644
--- a/engines/scumm/soundse.h
+++ b/engines/scumm/soundse.h
@@ -23,6 +23,7 @@
 #define SCUMM_SOUNDSE_H
 
 #include "common/scummsys.h"
+#include "audio/audiostream.h"
 #include "audio/mixer.h"
 #include "scumm/file.h"
 
@@ -31,7 +32,7 @@ class SeekableSubReadStream;
 }
 
 namespace Audio {
-class SeekableAudioStream;
+class WMACodec;
 }
 
 namespace Scumm {
@@ -48,6 +49,26 @@ enum SoundSEType {
 	kSoundSETypePatch
 };
 
+enum AudioCodec {
+	kXWBCodecPCM = 0,
+	kXWBCodecXMA = 1,
+	kXWBCodecADPCM = 2,
+	kXWBCodecWMA = 3,
+	kFSBCodecMP3 = 4
+};
+
+struct AudioEntry {
+	uint64 offset;
+	uint32 length;
+	AudioCodec codec;
+	byte channels;
+	uint16 rate;
+	uint16 align;
+	byte bits;
+	Common::String name;
+	bool isPatched;
+};
+
 class SoundSE {
 
 public:
@@ -72,14 +93,6 @@ public:
 	void stopAmbience();
 
 private:
-	enum AudioCodec {
-		kXWBCodecPCM = 0,
-		kXWBCodecXMA = 1,
-		kXWBCodecADPCM = 2,
-		kXWBCodecWMA = 3,
-		kFSBCodecMP3 = 4
-	};
-
 	enum XWBSegmentType {
 		kXWBSegmentBankData = 0,
 		kXWBSegmentEntryMetaData = 1,
@@ -107,18 +120,6 @@ private:
 		int32 hashFourCharString; // Hash calculated on a four char string, from disasm
 	};
 
-	struct AudioEntry {
-		uint64 offset;
-		uint32 length;
-		AudioCodec codec;
-		byte channels;
-		uint16 rate;
-		uint16 align;
-		byte bits;
-		Common::String name;
-		bool isPatched;
-	};
-
 	ScummEngine *_vm;
 	Audio::Mixer *_mixer;
 
@@ -177,6 +178,35 @@ private:
 	Audio::SeekableAudioStream *createSoundStream(Common::SeekableSubReadStream *stream, AudioEntry entry, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
 };
 
+#if 0
+/**
+ * A special headerless WMA stream, used in MI1:SE and MI2:SE
+ */
+class HeaderlessWMAStream : public Audio::SeekableAudioStream {
+public:
+	HeaderlessWMAStream(Common::SeekableReadStream *stream,
+						AudioEntry entry,
+						DisposeAfterUse::Flag disposeAfterUse);
+	~HeaderlessWMAStream() override;
+
+	int readBuffer(int16 *buffer, const int numSamples) override;
+
+	bool endOfData() const override { return _stream->eos(); }
+	bool isStereo() const override { return _entry.channels == 2; }
+	int getRate() const override { return _entry.rate; }
+	Audio::Timestamp getLength() const override {
+		return Audio::Timestamp(_entry.length / 10000, _entry.rate);
+	}
+	bool seek(const Audio::Timestamp &where) override;
+
+private:
+	Common::SeekableReadStream *_stream = nullptr;
+	AudioStream *_audioStream = nullptr;
+	AudioEntry _entry;
+	DisposeAfterUse::Flag _disposeAfterUse;
+	Audio::WMACodec *_wmaCodec = nullptr;
+};
+#endif
 
 } // End of namespace Scumm
 




More information about the Scummvm-git-logs mailing list