[Scummvm-cvs-logs] CVS: residual/imuse imuse.cpp,1.4,1.5 imuse.h,1.1,1.2 imuse_mcmp_mgr.cpp,1.1,1.2 imuse_music.cpp,1.2,1.3 imuse_script.cpp,1.1,1.2 imuse_sndmgr.cpp,1.2,1.3 imuse_sndmgr.h,1.2,1.3 imuse_tables.cpp,1.5,1.6 imuse_track.cpp,1.2,1.3

Pawel Kolodziejski aquadran at users.sourceforge.net
Tue Dec 28 10:26:02 CET 2004


Update of /cvsroot/scummvm/residual/imuse
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6644/imuse

Modified Files:
	imuse.cpp imuse.h imuse_mcmp_mgr.cpp imuse_music.cpp 
	imuse_script.cpp imuse_sndmgr.cpp imuse_sndmgr.h 
	imuse_tables.cpp imuse_track.cpp 
Log Message:
synced with local tree

Index: imuse.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- imuse.cpp	28 Dec 2004 08:05:18 -0000	1.4
+++ imuse.cpp	28 Dec 2004 18:25:14 -0000	1.5
@@ -26,7 +26,7 @@
 #include "imuse_sndmgr.h"
 
 Imuse::Track::Track()
-	: soundId(-1), used(false), stream(NULL) {
+	: soundName(NULL), used(false), stream(NULL) {
 }
 
 void Imuse::timerHandler(void *refCon) {
@@ -46,19 +46,21 @@
 	_volMusic = 0;
 	_callbackFps = fps;
 	resetState();
-	for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) {
+	for (int l = 0; l < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; l++) {
 		_track[l] = new Track;
 		_track[l]->trackId = l;
 		_track[l]->used = false;
 	}
 	vimaInit(imuseDestTable);
+	_stateMusicTable = grimStateMusicTable;
+	_seqMusicTable = grimSeqMusicTable;
 	g_timer->installTimerProc(timerHandler, 1000000 / _callbackFps, this);
 }
 
 Imuse::~Imuse() {
 	stopAllSounds();
 	g_timer->removeTimerProc(timerHandler);
-	for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) {
+	for (int l = 0; l < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; l++) {
 		delete _track[l];
 	}
 	delete _sound;
@@ -78,7 +80,7 @@
 void Imuse::callback() {
 	StackLock lock(_mutex);
 
-	for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) {
+	for (int l = 0; l < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; l++) {
 		Track *track = _track[l];
 		if (track->used && !track->readyToRemove) {
 			if (track->toBeRemoved) {
@@ -110,7 +112,7 @@
 						}
 					}
 				}
-				debug(5, "Fade: sound(%d), Vol(%d)", track->soundId, track->vol / 1000);
+				debug(5, "Fade: sound(%s), Vol(%d)", track->soundName, track->vol / 1000);
 			}
 
 			int pan = (track->pan != 64) ? 2 * track->pan - 127 : 0;
@@ -190,7 +192,7 @@
 	assert(track);
 	debug(5, "switchToNextRegion(track:%d)", track->trackId);
 
-	if (track->trackId >= MAX_DIGITAL_TRACKS) {
+	if (track->trackId >= MAX_IMUSE_TRACKS) {
 		track->toBeRemoved = true;
 		debug(5, "exit (fadetrack can't go next region) switchToNextRegion(trackId:%d)", track->trackId);
 		return;
@@ -220,11 +222,11 @@
 					Track *fadeTrack = cloneToFadeOutTrack(track, fadeDelay);
 					fadeTrack->dataOffset = _sound->getRegionOffset(fadeTrack->soundHandle, fadeTrack->curRegion);
 					fadeTrack->regionOffset = 0;
-					debug(5, "switchToNextRegion-sound(%d) select %d region, curHookId: %d", fadeTrack->soundId, fadeTrack->curRegion, fadeTrack->curHookId);
+					debug(5, "switchToNextRegion-sound(%s) select %d region, curHookId: %d", fadeTrack->soundName, fadeTrack->curRegion, fadeTrack->curHookId);
 					fadeTrack->curHookId = 0;
 				}
 				track->curRegion = region;
-				debug(5, "switchToNextRegion-sound(%d) jump to %d region, curHookId: %d", track->soundId, track->curRegion, track->curHookId);
+				debug(5, "switchToNextRegion-sound(%s) jump to %d region, curHookId: %d", track->soundName, track->curRegion, track->curHookId);
 				track->curHookId = 0;
 			}
 		} else {
@@ -232,14 +234,14 @@
 				Track *fadeTrack = cloneToFadeOutTrack(track, fadeDelay);
 				fadeTrack->dataOffset = _sound->getRegionOffset(fadeTrack->soundHandle, fadeTrack->curRegion);
 				fadeTrack->regionOffset = 0;
-				debug(5, "switchToNextRegion-sound(%d) select %d region, curHookId: %d", fadeTrack->soundId, fadeTrack->curRegion, fadeTrack->curHookId);
+				debug(5, "switchToNextRegion-sound(%s) select %d region, curHookId: %d", fadeTrack->soundName, fadeTrack->curRegion, fadeTrack->curHookId);
 			}
 			track->curRegion = region;
-			debug(5, "switchToNextRegion-sound(%d) jump to %d region, curHookId: %d", track->soundId, track->curRegion, track->curHookId);
+			debug(5, "switchToNextRegion-sound(%s) jump to %d region, curHookId: %d", track->soundName, track->curRegion, track->curHookId);
 		}
 	}
 
-	debug(5, "switchToNextRegion-sound(%d) select %d region, curHookId: %d", track->soundId, track->curRegion, track->curHookId);
+	debug(5, "switchToNextRegion-sound(%s) select %d region, curHookId: %d", track->soundName, track->curRegion, track->curHookId);
 	track->dataOffset = _sound->getRegionOffset(soundHandle, track->curRegion);
 	track->regionOffset = 0;
 }

Index: imuse.h
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- imuse.h	26 Dec 2004 12:21:33 -0000	1.1
+++ imuse.h	28 Dec 2004 18:25:14 -0000	1.2
@@ -27,8 +27,8 @@
 #include "../mixer/mixer.h"
 #include "../mixer/audiostream.h"
 
-#define MAX_DIGITAL_TRACKS 8
-#define MAX_DIGITAL_FADETRACKS 8
+#define MAX_IMUSE_TRACKS 8
+#define MAX_IMUSE_FADETRACKS 8
 
 class Imuse {
 private:
@@ -45,8 +45,7 @@
 		int32 volFadeDelay;
 		bool volFadeUsed;
 
-		int32 soundId;
-		char soundName[15];
+		char soundName[32];
 		bool used;
 		bool toBeRemoved;
 		bool readyToRemove;
@@ -57,7 +56,6 @@
 		int32 curRegion;
 		int32 curHookId;
 		int32 volGroupId;
-		int32 soundType;
 		int32 iteration;
 		int32 mixerFlags;
 		int32 mixerVol;
@@ -70,7 +68,7 @@
 		Track();
 	};
 
-	Track *_track[MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS];
+	Track *_track[MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS];
 
 	MutexRef _mutex;
 	ImuseSndMgr *_sound;
@@ -85,30 +83,32 @@
 	int32 _curMusicState;
 	int32 _curMusicSeq;
 
+	const ImuseTable *_stateMusicTable;
+	const ImuseTable *_seqMusicTable;
+
 	static void timerHandler(void *refConf);
 	void callback();
 	void switchToNextRegion(Track *track);
 	int allocSlot(int priority);
-	void startSound(int soundId, const char *soundName, int soundType, int volGroupId, AudioStream *input, int hookId, int volume, int priority);
-	void selectVolumeGroup(int soundId, int volGroupId);
+	void startSound(const char *soundName, int volGroupId, int hookId, int volume, int pan, int priority);
+	void selectVolumeGroup(const char *soundName, int volGroupId);
 
-	int32 getPosInMs(int soundId);
+	int32 getPosInMs(const char *soundName);
 
-	int getSoundIdByName(const char *soundName);
 	void fadeOutMusic(int fadeDelay);
 	Track *cloneToFadeOutTrack(Track *track, int fadeDelay);
 
 	void setMusicState(int stateId);
 	void setMusicSequence(int seqId);
-	void playMusic(const char *songName, const imuseComiTable *table, int atribPos, bool sequence);
+	void playMusic(const char *songName, const ImuseTable *table, int atribPos, bool sequence);
 
 public:
 	Imuse(int fps);
 	~Imuse();
 
-	void startVoice(const char *soundName, int soundId);
-	void startMusic(const char *soundName, int soundId, int hookId, int volume, int pan);
-	void startSfx(int soundId, int priority);
+	void startVoice(const char *soundName);
+	void startMusic(const char *soundName, int hookId, int volume, int pan);
+	void startSfx(const char *soundName, int priority);
 
 //	void saveOrLoad(Serializer *ser);
 	void resetState();
@@ -120,22 +120,21 @@
 	int getGroupSfxVolume() { return _volSfx; }
 	int getGroupMusicVolume() { return _volMusic; }
 
-	void setPriority(int soundId, int priority);
-	void setVolume(int soundId, int volume);
-	void setPan(int soundId, int pan);
-	void setFade(int soundId, int destVolume, int delay60HzTicks);
-	void setMusicVolume(int vol) {}
-	void stopSound(int sound);
+	void setPriority(const char *soundName, int priority);
+	void setVolume(const char *soundName, int volume);
+	void setPan(const char *soundName, int pan);
+	void setFade(const char *soundName, int destVolume, int delay60HzTicks);
+	void stopSound(const char *soundName);
 	void stopAllSounds();
 	void pause(bool pause);
-	void parseScriptCmds(int cmd, int soundId, int sub_cmd, int d, int e, int f, int g, int h);
+//	void parseScriptCmds(int cmd, int soundId, int sub_cmd, int d, int e, int f, int g, int h);
 	void refreshScripts();
 	void flushTracks();
-	int getSoundStatus(int sound) const;
+	int getSoundStatus(const char *soundName) const;
 	int32 getCurMusicPosInMs();
 };
 
-struct imuseTable {
+struct ImuseTable {
 	byte opcode;
 	int16 soundId;
 	byte atribPos;

Index: imuse_mcmp_mgr.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse_mcmp_mgr.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- imuse_mcmp_mgr.cpp	28 Dec 2004 08:05:18 -0000	1.1
+++ imuse_mcmp_mgr.cpp	28 Dec 2004 18:25:14 -0000	1.2
@@ -48,28 +48,22 @@
 	_compInput = NULL;
 }
 
-bool McmpMgr::openSound(const char *filename, byte *ptr) {
+bool McmpMgr::openSound(const char *filename, byte *resPtr, int &offsetData) {
+	_outputSize = 0;
+	_lastBlock = -1;
+
 	_file = ResourceLoader::instance()->openNewStream(filename);
 
 	if (!_file) {
-		warning("McmpMgr::openFile() Can't open mcmp file: %s", filename);
+		warning("McmpMgr::openFile() Can't open MCMP file: %s", filename);
 		return false;
 	}
 
-	_outputSize = 0;
-	_lastBlock = -1;
-
-	loadCompTable(ptr);
-}
-
-void McmpMgr::loadCompTable(byte *ptr) {
 	uint32 tag;
-	int i;
-
 	fread(&tag, 1, 4, _file);
 	tag = MKID_BE32(tag);
 	if (tag != MKID_BE('MCMP')) {
-		error("McmpMgr::loadCompTable() Compressed sound %d invalid (%s)", index, tag2str(tag));
+		error("McmpMgr::loadCompTable() Expected MCMP tag");
 	}
 
 	fread(&_numCompItems, 1, 2, _file);
@@ -84,6 +78,7 @@
 	fread(_compTable[i].decompSize, 1, 4, _file);
 
 	int32 maxSize = 0;
+	int i;
 	for (i = 0; i < _numCompItems; i++) {
 		fread(_compTable[i].codec, 1, 1, _file);
 		fread(_compTable[i].decompSize, 1, 4, _file);
@@ -104,7 +99,8 @@
 	fseek(_file, sizeCodecs, SEEK_CUR);
 	_compInput = (byte *)malloc(maxSize);
 	fread(_compInput, 1, _compTable[0].decompSize);
-	*ptr = _compInput;
+	*resPtr = _compInput;
+	offsetData = _compTable[0].compSize;
 }
 
 int32 McmpMgr::decompressSample(int32 offset, int32 size, byte **comp_final) {

Index: imuse_music.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse_music.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- imuse_music.cpp	26 Dec 2004 12:21:33 -0000	1.2
+++ imuse_music.cpp	28 Dec 2004 18:25:14 -0000	1.3
@@ -25,9 +25,9 @@
 	if (stateId == 0)
 		stateId = 1000;
 
-	for (l = 0; _stateMusicTable[l].soundId != -1; l++) {
-		if (_stateMusicTable[l].soundId == stateId) {
-			debug(5, "Set music state: %s", _stateMusicTable[l].filename);
+	for (l = 0; _stateMusicTable[l]->soundId != -1; l++) {
+		if (_stateMusicTable[l]->soundId == stateId) {
+			debug(5, "Set music state: %s", _stateMusicTable[l]->filename);
 			num = l;
 			break;
 		}
@@ -38,7 +38,7 @@
 		return;
 
 	if (_curMusicSeq == 0) {
-		playMusic(&_stateMusicTable[num], num, false);
+		playMusic(_stateMusicTable[num], num, false);
 	}
 
 	_curMusicState = num;
@@ -50,9 +50,9 @@
 	if (seqId == 0)
 		seqId = 2000;
 
-	for (l = 0; _seqMusicTable[l].soundId != -1; l++) {
-		if (_seqMusicTable[l].soundId == seqId) {
-			debug(5, "Set music sequence: %s", _seqMusicTable[l].filename);
+	for (l = 0; _seqMusicTable[l]->soundId != -1; l++) {
+		if (_seqMusicTable[l]->soundId == seqId) {
+			debug(5, "Set music sequence: %s", _seqMusicTable[l]->filename);
 			num = l;
 			break;
 		}
@@ -63,16 +63,16 @@
 		return;
 
 	if (num != 0) {
-		playMusic(&_seqMusicTable[num], 0, true);
+		playMusic(_seqMusicTable[num], 0, true);
 	} else {
-		playMusic(&_stateMusicTable[_curMusicState], _curMusicState, true);
+		playMusic(_stateMusicTable[_curMusicState], _curMusicState, true);
 		num = 0;
 	}
 
 	_curMusicSeq = num;
 }
 
-void Imuse::playMusic(const imuseComiTable *table, int atribPos, bool sequence) {
+void Imuse::playMusic(const imuseTable *table, int atribPos, bool sequence) {
 	int hookId = 0;
 
 	if (atribPos != 0) {
@@ -100,13 +100,13 @@
 		} else {
 			fadeOutMusic(table->fadeOut60TicksDelay);
 			if ((table->opcode == 3) && (!sequence) &&
-					(table->atribPos != 0) && (table->atribPos == _stateMusicTable[_curMusicState].atribPos)) {
+					(table->atribPos != 0) && (table->atribPos == _stateMusicTable[_curMusicState]->atribPos)) {
 				if (hookId == 100)
 					hookId = 0;
 				else
 					hookId = 100;
 			}
-			startMusic(table->filename, table->soundId, hookId, table->volume, table->pan);
+			startMusic(table->filename, hookId, table->volume, table->pan);
 		}
 	}
 }

Index: imuse_script.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse_script.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- imuse_script.cpp	26 Dec 2004 13:43:43 -0000	1.1
+++ imuse_script.cpp	28 Dec 2004 18:25:14 -0000	1.2
@@ -24,7 +24,7 @@
 #include "../mixer/audiostream.h"
 
 #include "imuse_sndmgr.h"
-
+/*
 void Imuse::parseScriptCmds(int cmd, int b, int c, int d, int e, int f, int g, int h) {
 	int soundId = b;
 	int sub_cmd = c;
@@ -101,7 +101,7 @@
 		error("Imuse::doCommand DEFAULT command %d", cmd);
 	}
 }
-
+*/
 void Imuse::flushTracks() {
 	debug(5, "flushTracks()");
 	for (int l = 0; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) {
@@ -140,25 +140,25 @@
 	}
 }
 
-void Imuse::startVoice(const char *soundName, int soundId) {
-	debug(5, "startVoiceBundle(%s)", soundName);
-	startSound(soundId, soundName, IMUSE_VOLGRP_VOICE, NULL, 0, 127, 127);
+void Imuse::startVoice(const char *soundName) {
+	debug(5, "startVoice(%s)", soundName);
+	startSound(soundName, IMUSE_VOLGRP_VOICE, 0, 127, 0, 127);
 }
 
-void Imuse::startMusic(const char *soundName, int soundId, int hookId, int volume, int pan) {
-	debug(5, "startMusicBundle(%s)", soundName);
-	startSound(soundId, soundName, IMUSE_VOLGRP_MUSIC, NULL, hookId, volume, pan, 126);
+void Imuse::startMusic(const char *soundName, int hookId, int volume, int pan) {
+	debug(5, "startMusic(%s)", soundName);
+	startSound(soundName, IMUSE_VOLGRP_MUSIC, hookId, volume, pan, 126);
 }
 
-void Imuse::startSfx(const char *soundName, int soundId, int priority) {
-	debug(5, "startSfx(%d)", soundId);
-	startSound(soundId, soundName, IMUSE_VOLGRP_SFX, NULL, 0, 127, priority);
+void Imuse::startSfx(const char *soundName, int priority) {
+	debug(5, "startSfx(%s)", soundName);
+	startSound(soundName, IMUSE_VOLGRP_SFX, 0, 127, 0, priority);
 }
 
-int32 Imuse::getPosInMs(int soundId) {
+int32 Imuse::getPosInMs(const char *soundName) {
 	for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) {
 		Track *track = _track[l];
-		if ((track->soundId == soundId) && track->used && !track->toBeRemoved) {
+		if (track->used && !track->toBeRemoved && (strcmp(track->soundName, soundName) == 0)) {
 			int32 pos = (5 * (track->dataOffset + track->regionOffset)) / (track->iteration / 200);
 			return pos;
 		}
@@ -167,13 +167,13 @@
 	return 0;
 }
 
-bool Imuse::getSoundStatus(int sound) const {
-	debug(5, "Imuse::getSoundStatus(%d)", sound);
+bool Imuse::getSoundStatus(const char *soundName) const {
+	debug(5, "Imuse::getSoundStatus(%s)", soundName);
 	for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) {
 		Track *track = _track[l];
-		if (track->soundId == sound) {
+		if (strcmp(track->soundName, soundName) == 0) {
 			if (track->handle.isActive() || (track->stream && track->used && !track->readyToRemove)) {
-					return true;
+				return true;
 			}
 		}
 	}
@@ -181,28 +181,28 @@
 	return false;
 }
 
-void Imuse::stopSound(int soundId) {
-	debug(5, "Imuse::stopSound(%d)", soundId);
+void Imuse::stopSound(const char *soundName) {
+	debug(5, "Imuse::stopSound(%s)", soundName);
 	for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) {
 		Track *track = _track[l];
-		if ((track->soundId == soundId) && track->used && !track->toBeRemoved) {
+		if (track->used && !track->toBeRemoved && (strcmp(track->soundName, soundName) == 0)) {
 			track->toBeRemoved = true;
 		}
 	}
 }
 
 int32 Imuse::getCurMusicPosInMs() {
-	int soundId = -1;
+	const char *soundName = NULL;
 
 	for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) {
 		Track *track = _track[l];
 		if (track->used && !track->toBeRemoved && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) {
-			soundId = track->soundId;
+			soundName = track->soundName;
 		}
 	}
 
-	int32 msPos = getPosInMs(soundId);
-	debug(5, "Imuse::getCurMusicPosInMs(%d) = %d", soundId, msPos);
+	int32 msPos = getPosInMs(soundName);
+	debug(5, "Imuse::getCurMusicPosInMs(%s) = %d", soundName, msPos);
 	return msPos;
 }
 

Index: imuse_sndmgr.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse_sndmgr.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- imuse_sndmgr.cpp	28 Dec 2004 08:05:18 -0000	1.2
+++ imuse_sndmgr.cpp	28 Dec 2004 18:25:14 -0000	1.3
@@ -30,8 +30,6 @@
 	for (int l = 0; l < MAX_IMUSE_SOUNDS; l++) {
 		memset(&_sounds[l], 0, sizeof(soundStruct));
 	}
-	_vm = scumm;
-	_disk = 0;
 }
 
 ImuseSndMgr::~ImuseSndMgr() {
@@ -62,20 +60,24 @@
 			size = READ_BE_UINT32(ptr); ptr += size + 4;
 			break;
 		default:
-			error("ImuseSndMgr::countElements() Unknown sfx header '%s'", tag2str(tag));
+			error("ImuseSndMgr::countElements() Unknown MAP tag '%s'", tag2str(tag));
 		}
 	} while (tag != MKID_BE('DATA'));
 }
 
-void ImuseSndMgr::prepareSound(byte *ptr, soundStruct *sound) {
-//		numBlocks = READ_BE_UINT16(data + 4);
-//		codecsStart = data + 8 + numBlocks * 9;
-//		codecsLen = READ_BE_UINT16(codecsStart - 2);
-//		headerPos = codecsStart + codecsLen;
-//		_numChannels = READ_LE_UINT16(headerPos + 22);
-//		dataStart = headerPos + 28 + READ_LE_UINT32(headerPos + 16);
-//		dataSize = READ_LE_UINT32(dataStart - 4);
-	if (READ_UINT32(ptr) == MKID('iMUS')) {
+void ImuseSndMgr::parseSoundSound(byte *ptr, soundStruct *sound, int &headerSize) {
+	if (READ_UINT32(ptr) == MKID('RIFF')) {
+		sound->region = (_region *)malloc(sizeof(_region));
+		sound->jump = (_jump *)malloc(0);
+		sound->numJumps = 0;
+		sound->numRegions = 1;
+		sound->region[0].offset = 0;
+		sound->region[0].length = READ_LE_UINT32(ptr + 40);
+		sound->bits = *(ptr + 34);
+		sound->freq = READ_LE_UINT32(ptr + 24);
+		sound->channels = *(ptr + 22);
+		headerSize = 44;
+	} else if (READ_UINT32(ptr) == MKID('iMUS')) {
 		uint32 tag;
 		int32 size = 0;
 		byte *s_ptr = ptr;
@@ -121,12 +123,19 @@
 				ptr += 4;
 				break;
 			default:
-				error("ImuseSndMgr::prepareSound(%d/%s) Unknown sfx header '%s'", sound->soundId, sound->name, tag2str(tag));
+				error("ImuseSndMgr::prepareSound(%s) Unknown MAP tag '%s'", sound->name, tag2str(tag));
 			}
 		} while (tag != MKID_BE('DATA'));
-		sound->ptr = ptr;
+		headerSize = ptr - s_ptr;
+		int i;
+		for (i = 0; i < sound->numRegions; i++) {
+			sound->region[i].offset -= headerSize;
+		}
+		for (i = 0; i < sound->numJumps; i++) {
+			sound->jump[i].offset -= headerSize;
+		}
 	} else {
-		error("ImuseSndMgr::prepareSound(): Unknown sound format");
+		error("ImuseSndMgr::prepareSound() Unknown sound format");
 	}
 }
 
@@ -141,79 +150,74 @@
 	return NULL;
 }
 
-ImuseSndMgr::soundStruct *ImuseSndMgr::openSound(const char *soundName, int32 soundId, int volGroupId) {
-	assert(soundId >= 0);
-	assert(soundType);
+ImuseSndMgr::soundStruct *ImuseSndMgr::openSound(const char *soundName, int volGroupId) {
+	assert(oundType);
 	const char *extension = soundName + std::strlen(soundName) - 3;
 	byte *ptr = NULL;
+	int headerSize = 0;
 
 	soundStruct *sound = allocSlot();
 	if (!sound) {
-		error("ImuseSndMgr::openSound() can't alloc free sound slot");
+		error("ImuseSndMgr::openSound() Can't alloc free sound slot");
 	}
 
+	strcpy(sound->name, soundName);
+	sound->volGroupId = volGroupId;
+
 	if (strcasecmp(extension, "imu") == 0) {
 		Block *b = getFileBlock(soundName);
 		if (b != NULL) {
 			ptr = b->data();
 			delete b;
+			parseSoundHeader(ptr, sound, headerSize);
 			sound->mcmpData = false;
+			sound->resPtr = ptr + headerSize;
 		} else {
 			closeSound(sound);
 			return NULL;
 		}
 	} else if (strcasecmp(extension, "wav") == 0 || strcasecmp(extension, "imc") == 0) {
+		sound->mcmpMgr = new McmpMgr();
 		if (!sound->mcmpMgr->openSound(soundName, &ptr)) {
 			closeSound(sound);
 			return NULL;
 		}
+		parseSoundHeader(ptr, sound, headerSize);
 		sound->mcmpData = true;
 	} else {
-		error("ImuseSndMgr::openSound() Unrecognized extension for sound file %s\n", soundName);
+		error("ImuseSndMgr::openSound() Unrecognized extension for sound file %s", soundName);
 	}
 
-	strcpy(sound->name, soundName);
-	sound->volGroupId = volGroupId;
-	sound->soundId = soundId;
-	prepareSound(ptr, sound);
 	return sound;
 }
 
 void ImuseSndMgr::closeSound(soundStruct *soundHandle) {
 	assert(checkForProperHandle(soundHandle));
 
-	if (soundHandle->resPtr) {
-		bool found = false;
-		for (int l = 0; l < MAX_IMUSE_SOUNDS; l++) {
-			if ((_sounds[l].soundId == soundHandle->soundId) && (&_sounds[l] != soundHandle))
-				found = true;
-		}
-		if (!found)
-			_vm->unlock(rtSound, soundHandle->soundId);
-	}
+	if (soundHandle->mcmpMgr)
+		delete soundHandle->mcmpMgr;
 
-	delete soundHandle->bundle;
-	for (int r = 0; r < soundHandle->numSyncs; r++)
-		free(soundHandle->sync[r].ptr);
 	free(soundHandle->region);
 	free(soundHandle->jump);
-	free(soundHandle->sync);
+
 	memset(soundHandle, 0, sizeof(soundStruct));
 }
 
-ImuseSndMgr::soundStruct *ImuseDSndMgr::cloneSound(soundStruct *soundHandle) {
+ImuseSndMgr::soundStruct *ImuseSndMgr::cloneSound(soundStruct *soundHandle) {
 	assert(checkForProperHandle(soundHandle));
 
-	return openSound(soundHandle->soundId, soundHandle->name, soundHandle->type, soundHandle->volGroupId, soundHandle->disk);
+	return openSound(soundHandle->name, soundHandle->volGroupId);
 }
 
 bool ImuseSndMgr::checkForProperHandle(soundStruct *soundHandle) {
 	if (!soundHandle)
 		return false;
+
 	for (int l = 0; l < MAX_IMUSE_SOUNDS; l++) {
 		if (soundHandle == &_sounds[l])
 			return true;
 	}
+
 	return false;
 }
 

Index: imuse_sndmgr.h
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse_sndmgr.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- imuse_sndmgr.h	28 Dec 2004 08:05:18 -0000	1.2
+++ imuse_sndmgr.h	28 Dec 2004 18:25:14 -0000	1.3
@@ -60,13 +60,10 @@
 		_jump *jump;
 		bool endFlag;
 		bool inUse;
-		int32 offsetData;
 		char name[32];
-		int16 soundId;
 		McmpMgr *_mcmpMgr;
-		int type;
 		int volGroupId;
-		byte *ptr;
+		byte *resPtr;
 	};
 
 private:
@@ -75,7 +72,7 @@
 
 	bool checkForProperHandle(soundStruct *soundHandle);
 	soundStruct *allocSlot();
-	void prepareSound(byte *ptr, soundStruct *sound);
+	void parseSoundHeader(byte *ptr, soundStruct *sound, int &headerSize);
 	void countElements(byte *ptr, int &numRegions, int &numJumps);
 
 public:
@@ -83,7 +80,7 @@
 	ImuseSndMgr();
 	~ImuseSndMgr();
 
-	soundStruct *openSound(int32 soundId, const char *soundName, int soundType, int volGroupId, int disk);
+	soundStruct *openSound(const char *soundName, int volGroupId);
 	void closeSound(soundStruct *soundHandle);
 	soundStruct *cloneSound(soundStruct *soundHandle);
 

Index: imuse_tables.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse_tables.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- imuse_tables.cpp	26 Dec 2004 12:01:40 -0000	1.5
+++ imuse_tables.cpp	28 Dec 2004 18:25:14 -0000	1.6
@@ -19,7 +19,7 @@
 #include "../bits.h"
 #include "../debug.h"
 
-const imuseTable _grimStateMusicTable[] = {
+const ImuseTable grimStateMusicTable[] = {
 	{0, 1000,   0, 0, 60, 127,   0, ""},
 	{0, 1999,   0, 0, 60, 127,   0, ""},
 	{3, 1001,   0, 0, 60, 127,   0, "1001 - Manny's Office.IMC" },
@@ -204,7 +204,7 @@
 	{0,   -1,   0, 0,  0,   0,   0, ""}
 };
 
-const imuseTable _grimSeqMusicTable[] = {
+const ImuseTable grimSeqMusicTable[] = {
 	{0, 2000,   0, 0, 20, 127,   0, ""},
 	{2, 2001,   0, 0, 20, 127,   0, "2001 - Climb Rope.IMC"},
 	{2, 2010,   0, 0, 20, 127,   0, "2010 - Glottis OK.IMC"},
@@ -249,7 +249,7 @@
 	{0,   -1,   0, 0,  0,   0,   0, ""}
 };
 
-const imuseTable _grimDemoStateMusicTable[] = {
+const ImuseTable grimDemoStateMusicTable[] = {
 	{0, 0,      0, 0, 60, 127,   0, ""},
 	{0, 1000,   0, 0, 60, 127,   0, ""},
 	{3, 1001,   0, 0, 60, 127,   0, "MO - Manny's Office.IMC"},
@@ -275,7 +275,7 @@
 	{0,   -1,   0, 0,  0,   0,   0, ""}
 };
 
-const imuseTable _grimDemoSeqMusicTable[] = {
+const ImuseTable grimDemoSeqMusicTable[] = {
 	{0, 2000,   0, 0, 60, 127,   0, ""},
 	{3, 2100,   0, 0, 60, 127,   0, "Rope Climb.IMC"},
 	{0,   -1,   0, 0,  0,   0,   0, ""}

Index: imuse_track.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/imuse/imuse_track.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- imuse_track.cpp	28 Dec 2004 08:05:18 -0000	1.2
+++ imuse_track.cpp	28 Dec 2004 18:25:14 -0000	1.3
@@ -29,7 +29,7 @@
 	int l, lowest_priority = 127;
 	int trackId = -1;
 
-	for (l = 0; l < MAX_DIGITAL_TRACKS; l++) {
+	for (l = 0; l < MAX_IMUSE_TRACKS; l++) {
 		if (!_track[l]->used) {
 			trackId = l;
 			break;
@@ -38,7 +38,7 @@
 
 	if (trackId == -1) {
 		debug(5, "Imuse::startSound(): All slots are full");
-		for (l = 0; l < MAX_DIGITAL_TRACKS; l++) {
+		for (l = 0; l < MAX_IMUSE_TRACKS; l++) {
 			Track *track = _track[l];
 			if (track->used && !track->toBeRemoved && lowest_priority > track->priority) {
 				lowest_priority = track->priority;
@@ -48,7 +48,7 @@
 		if (lowest_priority <= priority) {
 			assert(trackId != -1);
 			_track[trackId]->toBeRemoved = true;
-			debug(5, "Imuse::startSound(): Removed sound %d from track %d", _track[trackId]->soundId, trackId);
+			debug(5, "Imuse::startSound(): Removed sound %s from track %d", _track[trackId]->soundName, trackId);
 		} else {
 			debug(5, "Imuse::startSound(): Priority sound too low");
 			return -1;
@@ -58,8 +58,8 @@
 	return trackId;
 }
 
-void Imuse::startSound(int soundId, const char *soundName, int soundType, int volGroupId, AudioStream *input, int hookId, int volume, int pan = 64, int priority) {
-	debug(5, "Imuse::startSound(%d)", soundId);
+void Imuse::startSound(const char *soundName, int volGroupId, int hookId, int volume, int pan = 64, int priority) {
+	debug(5, "Imuse::startSound(%s)", soundName);
 
 	int l = allocSlot(priority);
 	if (l == -1) {
@@ -82,7 +82,6 @@
 	track->volFadeStep = 0;
 	track->volFadeDelay = 0;
 	track->volFadeUsed = false;
-	track->soundId = soundId;
 	track->started = false;
 	track->volGroupId = volGroupId;
 	track->curHookId = hookId;
@@ -95,12 +94,11 @@
 	track->mixerVol = volume;
 	track->toBeRemoved = false;
 	track->readyToRemove = false;
-	track->soundType = soundType;
 
 	int bits = 0, freq = 0, channels = 0;
 
 	strcpy(track->soundName, soundName);
-	track->soundHandle = _sound->openSound(soundId, soundName, soundType, volGroupId, -1);
+	track->soundHandle = _sound->openSound(soundName, volGroupId, -1);
 
 	if (track->soundHandle == NULL)
 		return;
@@ -118,15 +116,14 @@
 		}
 	}
 */
-		assert(bits == 8 || bits == 12 || bits == 16);
-		assert(channels == 1 || channels == 2);
-		assert(0 < freq && freq <= 65535);
+	assert(bits == 8 || bits == 12 || bits == 16);
+	assert(channels == 1 || channels == 2);
+	assert(0 < freq && freq <= 65535);
 
-		track->iteration = freq * channels * 2;
-		track->mixerFlags = SoundMixer::FLAG_16BITS;
-		if (channels == 2)
-			track->mixerFlags |= SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO;
-	}
+	track->iteration = freq * channels * 2;
+	track->mixerFlags = SoundMixer::FLAG_16BITS;
+	if (channels == 2)
+		track->mixerFlags |= SoundMixer::FLAG_STEREO | SoundMixer::FLAG_REVERSE_STEREO;
 
 	pan = (track->pan != 64) ? 2 * track->pan - 127 : 0;
 	volume = track->vol / 1000;
@@ -138,75 +135,73 @@
 	if (track->volGroupId == 3)
 		volume = (volume * _volMusic) / 128;
 
-		track->mixerPan = pan;
-		track->mixerVol = volume;
-
-		// setup 1 second stream wrapped buffer
-		int32 streamBufferSize = track->iteration;
-		track->stream = makeAppendableAudioStream(freq, track->mixerFlags, streamBufferSize);
-		_vm->_mixer->playInputStream(&track->handle, track->stream, false, -1, track->mixerVol, track->mixerPan, false);
-		track->started = true;
-	}
+	track->mixerPan = pan;
+	track->mixerVol = volume;
 
+	// setup 1 second stream wrapped buffer
+	int32 streamBufferSize = track->iteration;
+	track->stream = makeAppendableAudioStream(freq, track->mixerFlags, streamBufferSize);
+	_vm->_mixer->playInputStream(&track->handle, track->stream, false, -1, track->mixerVol, track->mixerPan, false);
+	track->started = true;
 	track->used = true;
 }
 
-void Imuse::setPriority(int soundId, int priority) {
-	debug(5, "Imuse::setPriority(%d, %d)", soundId, priority);
+void Imuse::setPriority(const char *soundName, int priority) {
+	debug(5, "Imuse::setPriority(%s, %d)", soundName, priority);
 	assert ((priority >= 0) && (priority <= 127));
 
-	for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) {
+	for (int l = 0; l < MAX_IMUSE_TRACKS; l++) {
 		Track *track = _track[l];
-		if ((track->soundId == soundId) && track->used && !track->toBeRemoved) {
+		if (track->used && !track->toBeRemoved && (strcmp(track->soundName, soundName) == 0)) {
 			track->priority = priority;
 		}
 	}
 }
 
-void Imuse::setVolume(int soundId, int volume) {
-	debug(5, "IMuseDigital::setVolume(%d, %d)", soundId, volume);
+void Imuse::setVolume(int soundName, int volume) {
+	debug(5, "IMuseDigital::setVolume(%s, %d)", soundName, volume);
 
-	for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) {
+	for (int l = 0; l < MAX_IMUSE_TRACKS; l++) {
 		Track *track = _track[l];
-		if ((track->soundId == soundId) && track->used && !track->toBeRemoved) {
+		if (track->used && !track->toBeRemoved && (strcmp(track->soundName, soundName) == 0)) {
 			track->vol = volume * 1000;
 		}
 	}
 }
 
-void Imuse::setPan(int soundId, int pan) {
-	debug(5, "Imuse::setPan(%d, %d)", soundId, pan);
+void Imuse::setPan(const char *soundName, int pan) {
+	debug(5, "Imuse::setPan(%s, %d)", soundName, pan);
 
-	for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) {
+	for (int l = 0; l < MAX_IMUSE_TRACKS; l++) {
 		Track *track = _track[l];
-		if ((track->soundId == soundId) && track->used && !track->toBeRemoved) {
+		if (track->used && !track->toBeRemoved && (strcmp(track->soundName, soundName) == 0)) {
 			track->pan = pan;
 		}
 	}
 }
 
-void Imuse::selectVolumeGroup(int soundId, int volGroupId) {
-	debug(5, "Imuse::setGroupVolume(%d, %d)", soundId, volGroupId);
+void Imuse::selectVolumeGroup(const char *soundName, int volGroupId) {
+	debug(5, "Imuse::setGroupVolume(%s, %d)", soundName, volGroupId);
 	assert((volGroupId >= 1) && (volGroupId <= 4));
 
 	if (volGroupId == 4)
 		volGroupId = 3;
 
-	for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) {
+	for (int l = 0; l < MAX_IMUSE_TRACKS; l++) {
 		Track *track = _track[l];
-		if ((track->soundId == soundId) && track->used && !track->toBeRemoved) {
+		if (track->used && !track->toBeRemoved && (strcmp(track->soundName, soundName) == 0)) {
 			track->volGroupId = volGroupId;
 		}
 	}
 }
 
-void Imuse::setFade(int soundId, int destVolume, int delay60HzTicks) {
+void Imuse::setFade(const char *soundName, int destVolume, int delay60HzTicks) {
 	StackLock lock(_mutex);
-	debug(5, "Imuse::setFade(%d, %d, %d)", soundId, destVolume, delay60HzTicks);
+	debug(5, "Imuse::setFade(%s, %d, %d)", soundName, destVolume, delay60HzTicks);
 
-	for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) {
+	for (int l = 0; l < MAX_IMUSE_TRACKS; l++) {
 		Track *track = _track[l];
-		if ((track->soundId == soundId) && track->used && !track->toBeRemoved) {
+		if (track->used && !track->toBeRemoved && (strcmp(track->soundName, soundName) == 0)) {
 			track->volFadeDelay = delay60HzTicks;
 			track->volFadeDest = destVolume * 1000;
 			track->volFadeStep = (track->volFadeDest - track->vol) * 60 * (1000 / _callbackFps) / (1000 * delay60HzTicks);
@@ -217,7 +212,7 @@
 
 void Imuse::fadeOutMusic(int fadeDelay) {
 	debug(5, "Imuse::fadeOutMusic");
-	for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) {
+	for (int l = 0; l < MAX_IMUSE_TRACKS; l++) {
 		Track *track = _track[l];
 		if (track->used && !track->toBeRemoved && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) {
 			cloneToFadeOutTrack(track, fadeDelay);
@@ -226,7 +221,7 @@
 	}
 }
 
-ImuseDigital::Track *Imuse::cloneToFadeOutTrack(Track *track, int fadeDelay) {
+Imuse::Track *Imuse::cloneToFadeOutTrack(Track *track, int fadeDelay) {
 	assert(track);
 	Track *fadeTrack = 0;
 
@@ -234,20 +229,19 @@
 
 	{
 		StackLock lock(_mutex);
-		for (int l = MAX_DIGITAL_TRACKS; l < MAX_DIGITAL_TRACKS + MAX_DIGITAL_FADETRACKS; l++) {
+		for (int l = MAX_IMUSE_TRACKS; l < MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS; l++) {
 			if (!_track[l]->used) {
 				fadeTrack = _track[l];
 				break;
 			}
 		}
 		if (fadeTrack == 0)
-			error("IMuseDigital::cloneTofadeTrackId() Can't find free fade track");
+			error("Imuse::cloneTofadeTrackId() Can't find free fade track");
 
 		fadeTrack->pan = track->pan;
 		fadeTrack->vol = track->vol;
 		fadeTrack->volGroupId = track->volGroupId;
 		fadeTrack->priority = track->priority;
-		fadeTrack->soundId = track->soundId;
 		fadeTrack->dataOffset = track->dataOffset;
 		fadeTrack->regionOffset = track->regionOffset;
 		fadeTrack->curRegion = track->curRegion;
@@ -260,7 +254,6 @@
 		fadeTrack->readyToRemove = track->readyToRemove;
 		fadeTrack->started = track->started;
 		strcpy(fadeTrack->soundName, track->soundName);
-		fadeTrack->soundType = track->soundType;
 		fadeTrack->soundHandle = _sound->cloneSound(track->soundHandle);
 		assert(fadeTrack->soundHandle);
 		fadeTrack->volFadeDelay = fadeDelay;





More information about the Scummvm-git-logs mailing list