[Scummvm-git-logs] scummvm master -> 763cf2f6a498348ae566a0d5709deaab95645eb3

Strangerke Strangerke at scummvm.org
Wed Apr 18 07:20:37 CEST 2018


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:
763cf2f6a4 LILLIPUT: Add code to load & decompress MUS file


Commit: 763cf2f6a498348ae566a0d5709deaab95645eb3
    https://github.com/scummvm/scummvm/commit/763cf2f6a498348ae566a0d5709deaab95645eb3
Author: Strangerke (strangerke at scummvm.org)
Date: 2018-04-18T07:18:05+02:00

Commit Message:
LILLIPUT: Add code to load & decompress MUS file

Changed paths:
    engines/lilliput/lilliput.cpp
    engines/lilliput/sound.cpp
    engines/lilliput/sound.h


diff --git a/engines/lilliput/lilliput.cpp b/engines/lilliput/lilliput.cpp
index 4fca379..e2b2ced 100644
--- a/engines/lilliput/lilliput.cpp
+++ b/engines/lilliput/lilliput.cpp
@@ -2727,8 +2727,9 @@ Common::Error LilliputEngine::run() {
 
 	// Setup mixer
 	syncSoundSettings();
-	//TODO: Init sound/music player
+	_soundHandler->init();
 
+	// Init palette
 	initPalette();
 
 	// Load files. In the original, the size was hardcoded
diff --git a/engines/lilliput/sound.cpp b/engines/lilliput/sound.cpp
index 78de105..6ea5ab9 100644
--- a/engines/lilliput/sound.cpp
+++ b/engines/lilliput/sound.cpp
@@ -28,10 +28,30 @@
 namespace Lilliput {
 
 LilliputSound::LilliputSound(LilliputEngine *vm) : _vm(vm) {
+	_unpackedFiles = nullptr;
+	_unpackedSizes = nullptr;
 }
 
 LilliputSound::~LilliputSound() {
-	free(_musicBuff);
+	if (_unpackedFiles) {
+		for (int i = 0; i < _fileNumb; i++)
+			free(_unpackedFiles[i]);
+	}
+	free(_unpackedFiles);
+	free(_unpackedSizes);
+}
+
+byte LilliputSound::readByte(const byte *data, uint32 offset) {
+	uint16 al = data[0x201 + (offset >> 1)];
+	return data[1 + (offset & 1) + (al << 1)];
+}
+
+uint32 LilliputSound::decode(const byte *src, byte *dst, uint32 len) {
+	uint32 i = 0;
+	for (; i < len; ++i) {
+		*dst++ = readByte(src, i);
+	}
+	return i;
 }
 
 void LilliputSound::loadMusic(Common::String filename) {
@@ -42,17 +62,51 @@ void LilliputSound::loadMusic(Common::String filename) {
 	if (!f.open(filename))
 		error("Missing music file %s", filename.c_str());
 
-	byte *res = (byte *)malloc(sizeof(byte) * 50000);
-	for (int i = 0; i < 50000; ++i)
-		res[i] = f.readByte();
-
-//	f.close();
-	f.seek(0);
-	int filenumb = f.readUint16LE();
-
-
-
-	free(res);
+	_fileNumb = f.readUint16LE();
+
+	int *fileSizes = new int[_fileNumb + 1];
+	for (int i = 0; i < _fileNumb; ++i)
+		fileSizes[i] = f.readUint16LE();
+	f.seek(0, SEEK_END);
+	fileSizes[_fileNumb] = f.pos();
+
+	_unpackedFiles = new byte *[_fileNumb];
+	_unpackedSizes = new uint16[_fileNumb];
+	int pos = (_fileNumb + 1) * 2; // file number + file sizes
+	for (int i = 0; i < _fileNumb; ++i) {
+		int packedSize = fileSizes[i + 1] - fileSizes[i];
+		byte *srcBuf = new byte[packedSize];
+		f.seek(pos, SEEK_SET);
+		f.read(srcBuf, packedSize);
+		if (srcBuf[0] == 'c' || srcBuf[0] == 'C') {
+			int shift = (srcBuf[0] == 'c') ? 1 : 0;
+			_unpackedSizes[i] = (1 + packedSize - 0x201) * 2 - shift;
+			byte *dstBuf = new byte[_unpackedSizes[i]];
+			decode(srcBuf + shift, dstBuf, _unpackedSizes[i]);
+			_unpackedFiles[i] = dstBuf;
+		} else {
+			_unpackedSizes[i] = packedSize;
+			byte *dstBuf = new byte[packedSize];
+			for (int j = 0; j < packedSize; ++j)
+				dstBuf[j] = srcBuf[j];
+			_unpackedFiles[i] = dstBuf;
+		}
+		delete srcBuf;
+		pos += packedSize;
+	}
+
+	delete fileSizes;
+	f.close();
+
+	// Debug code
+	for (int i = 0; i < _fileNumb; ++i) {
+		Common::DumpFile dmp;
+		Common::String name = Common::String::format("dmp%d.mid", i);
+		dmp.open(name);
+		dmp.write(_unpackedFiles[i], _unpackedSizes[i]);
+		dmp.close();
+	}
+	//
 }
 
 // Used during initialization
diff --git a/engines/lilliput/sound.h b/engines/lilliput/sound.h
index ee052c4..e9f5a03 100644
--- a/engines/lilliput/sound.h
+++ b/engines/lilliput/sound.h
@@ -43,7 +43,12 @@ public:
 private:
 	LilliputEngine *_vm;
 
-	byte *_musicBuff;
+	int _fileNumb;
+	byte **_unpackedFiles;
+	uint16 *_unpackedSizes;
+
+	uint32 decode(const byte *src, byte *dst, uint32 len);
+	byte readByte(const byte *data, uint32 offset);
 
 	void loadMusic(Common::String filename);
 };





More information about the Scummvm-git-logs mailing list