[Scummvm-cvs-logs] CVS: scummvm/scumm/imuse_digi dimuse_sndmgr.cpp,1.47,1.48 dimuse_sndmgr.h,1.25,1.26

Pawel Kolodziejski aquadran at users.sourceforge.net
Sat Jun 19 10:49:03 CEST 2004


Update of /cvsroot/scummvm/scummvm/scumm/imuse_digi
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22273/scummvm/scumm/imuse_digi

Modified Files:
	dimuse_sndmgr.cpp dimuse_sndmgr.h 
Log Message:
some optimisations

Index: dimuse_sndmgr.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse_sndmgr.cpp,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- dimuse_sndmgr.cpp	19 Jun 2004 14:41:04 -0000	1.47
+++ dimuse_sndmgr.cpp	19 Jun 2004 17:48:06 -0000	1.48
@@ -79,7 +79,7 @@
 	} while (tag != MKID_BE('DATA'));
 }
 
-void ImuseDigiSndMgr::prepareSound(byte *ptr, int slot) {
+void ImuseDigiSndMgr::prepareSound(byte *ptr, soundStruct *sound) {
 	if (READ_UINT32(ptr) == MKID('Crea')) {
 		bool quit = false;
 		int len;
@@ -87,11 +87,11 @@
 		int32 offset = READ_LE_UINT16(ptr + 20);
 		int16 code = READ_LE_UINT16(ptr + 24);
 
-		_sounds[slot].region = (_region *)malloc(sizeof(_region) * 70);
-		_sounds[slot].jump = (_jump *)malloc(sizeof(_jump));
-		_sounds[slot].resPtr = ptr;
-		_sounds[slot].bits = 8;
-		_sounds[slot].channels = 1;
+		sound->region = (_region *)malloc(sizeof(_region) * 70);
+		sound->jump = (_jump *)malloc(sizeof(_jump));
+		sound->resPtr = ptr;
+		sound->bits = 8;
+		sound->channels = 1;
 
 		while (!quit) {
 			len = READ_LE_UINT32(ptr + offset);
@@ -116,23 +116,23 @@
 					int time_constant = ptr[offset];
 					offset += 2;
 					len -= 2;
-					_sounds[slot].freq = getSampleRateFromVOCRate(time_constant);
-					_sounds[slot].region[_sounds[slot].numRegions].offset = offset;
-					_sounds[slot].region[_sounds[slot].numRegions].length = len;
-					_sounds[slot].numRegions++;
+					sound->freq = getSampleRateFromVOCRate(time_constant);
+					sound->region[sound->numRegions].offset = offset;
+					sound->region[sound->numRegions].length = len;
+					sound->numRegions++;
 				}
 				break;
 			case 6:	// begin of loop
-				_sounds[slot].jump[0].dest = offset + 8;
-				_sounds[slot].jump[0].hookId = 0;
-				_sounds[slot].jump[0].fadeDelay = 0;
+				sound->jump[0].dest = offset + 8;
+				sound->jump[0].hookId = 0;
+				sound->jump[0].fadeDelay = 0;
 				break;
 			case 7:	// end of loop
-				_sounds[slot].jump[0].offset = offset - 4;
-				_sounds[slot].numJumps++;
-				_sounds[slot].region[_sounds[slot].numRegions].offset = offset - 4;
-				_sounds[slot].region[_sounds[slot].numRegions].length = 0;
-				_sounds[slot].numRegions++;
+				sound->jump[0].offset = offset - 4;
+				sound->numJumps++;
+				sound->region[sound->numRegions].offset = offset - 4;
+				sound->region[sound->numRegions].length = 0;
+				sound->numRegions++;
 				break;
 			default:
 				error("Invalid code in VOC file : %d", code);
@@ -151,22 +151,22 @@
 		int curIndexJump = 0;
 		int curIndexSync = 0;
 
-		_sounds[slot].numRegions = 0;
-		_sounds[slot].numJumps = 0;
-		_sounds[slot].numSyncs = 0;
-		countElements(ptr, _sounds[slot].numRegions, _sounds[slot].numJumps, _sounds[slot].numSyncs);
-		_sounds[slot].region = (_region *)malloc(sizeof(_region) * _sounds[slot].numRegions);
-		_sounds[slot].jump = (_jump *)malloc(sizeof(_jump) * _sounds[slot].numJumps);
-		_sounds[slot].sync = (_sync *)malloc(sizeof(_sync) * _sounds[slot].numSyncs);
+		sound->numRegions = 0;
+		sound->numJumps = 0;
+		sound->numSyncs = 0;
+		countElements(ptr, sound->numRegions, sound->numJumps, sound->numSyncs);
+		sound->region = (_region *)malloc(sizeof(_region) * sound->numRegions);
+		sound->jump = (_jump *)malloc(sizeof(_jump) * sound->numJumps);
+		sound->sync = (_sync *)malloc(sizeof(_sync) * sound->numSyncs);
 
 		do {
 			tag = READ_BE_UINT32(ptr); ptr += 4;
 			switch(tag) {
 			case MKID_BE('FRMT'):
 				ptr += 12;
-				_sounds[slot].bits = READ_BE_UINT32(ptr); ptr += 4;
-				_sounds[slot].freq = READ_BE_UINT32(ptr); ptr += 4;
-				_sounds[slot].channels = READ_BE_UINT32(ptr); ptr += 4;
+				sound->bits = READ_BE_UINT32(ptr); ptr += 4;
+				sound->freq = READ_BE_UINT32(ptr); ptr += 4;
+				sound->channels = READ_BE_UINT32(ptr); ptr += 4;
 				break;
 			case MKID_BE('TEXT'):
 			case MKID_BE('STOP'):
@@ -174,23 +174,23 @@
 				break;
 			case MKID_BE('REGN'):
 				ptr += 4;
-				_sounds[slot].region[curIndexRegion].offset = READ_BE_UINT32(ptr); ptr += 4;
-				_sounds[slot].region[curIndexRegion].length = READ_BE_UINT32(ptr); ptr += 4;
+				sound->region[curIndexRegion].offset = READ_BE_UINT32(ptr); ptr += 4;
+				sound->region[curIndexRegion].length = READ_BE_UINT32(ptr); ptr += 4;
 				curIndexRegion++;
 				break;
 			case MKID_BE('JUMP'):
 				ptr += 4;
-				_sounds[slot].jump[curIndexJump].offset = READ_BE_UINT32(ptr); ptr += 4;
-				_sounds[slot].jump[curIndexJump].dest = READ_BE_UINT32(ptr); ptr += 4;
-				_sounds[slot].jump[curIndexJump].hookId = READ_BE_UINT32(ptr); ptr += 4;
-				_sounds[slot].jump[curIndexJump].fadeDelay = READ_BE_UINT32(ptr); ptr += 4;
+				sound->jump[curIndexJump].offset = READ_BE_UINT32(ptr); ptr += 4;
+				sound->jump[curIndexJump].dest = READ_BE_UINT32(ptr); ptr += 4;
+				sound->jump[curIndexJump].hookId = READ_BE_UINT32(ptr); ptr += 4;
+				sound->jump[curIndexJump].fadeDelay = READ_BE_UINT32(ptr); ptr += 4;
 				curIndexJump++;
 				break;
 			case MKID_BE('SYNC'):
 				size = READ_BE_UINT32(ptr); ptr += 4;
-				_sounds[slot].sync[curIndexSync].size = size;
-				_sounds[slot].sync[curIndexSync].ptr = (byte *)malloc(size);
-				memcpy(_sounds[slot].sync[curIndexSync].ptr, ptr, size);
+				sound->sync[curIndexSync].size = size;
+				sound->sync[curIndexSync].ptr = (byte *)malloc(size);
+				memcpy(sound->sync[curIndexSync].ptr, ptr, size);
 				curIndexSync++;
 				ptr += size;
 				break;
@@ -198,33 +198,33 @@
 				ptr += 4;
 				break;
 			default:
-				error("ImuseDigiSndMgr::prepareSound(%d/%s) Unknown sfx header '%s'", _sounds[slot].soundId, _sounds[slot].name, tag2str(tag));
+				error("ImuseDigiSndMgr::prepareSound(%d/%s) Unknown sfx header '%s'", sound->soundId, sound->name, tag2str(tag));
 			}
 		} while (tag != MKID_BE('DATA'));
-		_sounds[slot].offsetData =  ptr - s_ptr;
+		sound->offsetData =  ptr - s_ptr;
 	} else {
 		error("ImuseDigiSndMgr::prepareSound(): Unknown sound format");
 	}
 }
 
-int ImuseDigiSndMgr::allocSlot() {
+ImuseDigiSndMgr::soundStruct *ImuseDigiSndMgr::allocSlot() {
 	for (int l = 0; l < MAX_IMUSE_SOUNDS; l++) {
 		if (!_sounds[l].inUse) {
 			_sounds[l].inUse = true;
-			return l;
+			return &_sounds[l];
 		}
 	}
 
-	return -1;
+	return NULL;
 }
 
-bool ImuseDigiSndMgr::openMusicBundle(int slot, int disk) {
+bool ImuseDigiSndMgr::openMusicBundle(soundStruct *sound, int disk) {
 	bool result = false;
 
-	_sounds[slot].bundle = new BundleMgr(_cacheBundleDir);
+	sound->bundle = new BundleMgr(_cacheBundleDir);
 	if (_vm->_gameId == GID_CMI) {
 		if (_vm->_features & GF_DEMO) {
-			result = _sounds[slot].bundle->openFile("music.bun", _vm->getGameDataPath());
+			result = sound->bundle->openFile("music.bun", _vm->getGameDataPath());
 		} else {
 			char musicfile[20];
 			if (disk == -1)
@@ -235,30 +235,30 @@
 //				_vm->_imuseDigital->parseScriptCmds(0x1000, 0, 0, 0, 0, 0, 0, 0);
 //				_vm->_imuseDigital->parseScriptCmds(0x2000, 0, 0, 0, 0, 0, 0, 0);
 //				_vm->_imuseDigital->stopAllSounds();
-//				_sounds[slot].bundle->closeFile();
+//				sound->bundle->closeFile();
 //			}
 
-			result = _sounds[slot].bundle->openFile(musicfile, _vm->getGameDataPath());
+			result = sound->bundle->openFile(musicfile, _vm->getGameDataPath());
 
 			if (result == false)
-				result = _sounds[slot].bundle->openFile("music.bun", _vm->getGameDataPath());
+				result = sound->bundle->openFile("music.bun", _vm->getGameDataPath());
 			_disk = (byte)_vm->VAR(_vm->VAR_CURRENTDISK);
 		}
 	} else if (_vm->_gameId == GID_DIG)
-		result = _sounds[slot].bundle->openFile("digmusic.bun", _vm->getGameDataPath());
+		result = sound->bundle->openFile("digmusic.bun", _vm->getGameDataPath());
 	else
 		error("ImuseDigiSndMgr::openMusicBundle() Don't know which bundle file to load");
 
 	return result;
 }
 
-bool ImuseDigiSndMgr::openVoiceBundle(int slot, int disk) {
+bool ImuseDigiSndMgr::openVoiceBundle(soundStruct *sound, int disk) {
 	bool result = false;
 
-	_sounds[slot].bundle = new BundleMgr(_cacheBundleDir);
+	sound->bundle = new BundleMgr(_cacheBundleDir);
 	if (_vm->_gameId == GID_CMI) {
 		if (_vm->_features & GF_DEMO) {
-			result = _sounds[slot].bundle->openFile("voice.bun", _vm->getGameDataPath());
+			result = sound->bundle->openFile("voice.bun", _vm->getGameDataPath());
 		} else {
 			char voxfile[20];
 			if (disk == -1)
@@ -269,17 +269,17 @@
 //				_vm->_imuseDigital->parseScriptCmds(0x1000, 0, 0, 0, 0, 0, 0, 0);
 //				_vm->_imuseDigital->parseScriptCmds(0x2000, 0, 0, 0, 0, 0, 0, 0);
 //				_vm->_imuseDigital->stopAllSounds();
-//				_sounds[slot].bundle->closeFile();
+//				sound->bundle->closeFile();
 //			}
 
-			result = _sounds[slot].bundle->openFile(voxfile, _vm->getGameDataPath());
+			result = sound->bundle->openFile(voxfile, _vm->getGameDataPath());
 
 			if (result == false)
-				result = _sounds[slot].bundle->openFile("voice.bun", _vm->getGameDataPath());
+				result = sound->bundle->openFile("voice.bun", _vm->getGameDataPath());
 			_disk = (byte)_vm->VAR(_vm->VAR_CURRENTDISK);
 		}
 	} else if (_vm->_gameId == GID_DIG)
-		result = _sounds[slot].bundle->openFile("digvoice.bun", _vm->getGameDataPath());
+		result = sound->bundle->openFile("digvoice.bun", _vm->getGameDataPath());
 	else
 		error("ImuseDigiSndMgr::openVoiceBundle() Don't know which bundle file to load");
 
@@ -290,8 +290,8 @@
 	assert(soundId >= 0);
 	assert(soundType);
 
-	int slot = allocSlot();
-	if (slot == -1) {
+	soundStruct *sound = allocSlot();
+	if (!sound) {
 		error("ImuseDigiSndMgr::openSound() can't alloc free sound slot");
 	}
 
@@ -299,36 +299,36 @@
 	byte *ptr = NULL;
 
 	if (soundName[0] == 0) {
-		_sounds[slot].name[0] = 0;
+		sound->name[0] = 0;
 		if ((soundType == IMUSE_RESOURCE)) {
 			_vm->ensureResourceLoaded(rtSound, soundId);
 			_vm->lock(rtSound, soundId);
 			ptr = _vm->getResourceAddress(rtSound, soundId);
 			if (ptr == NULL) {
-				closeSound(&_sounds[slot]);
+				closeSound(sound);
 				return NULL;
 			}
-			_sounds[slot].resPtr = ptr;
-			_sounds[slot].soundId = soundId;
-			_sounds[slot].type = soundType;
-			_sounds[slot].volGroupId = volGroupId;
+			sound->resPtr = ptr;
+			sound->soundId = soundId;
+			sound->type = soundType;
+			sound->volGroupId = volGroupId;
 			result = true;
 		} else if (soundType == IMUSE_BUNDLE) {
 			bool header_outside = ((_vm->_gameId == GID_CMI) && !(_vm->_features & GF_DEMO));
 			if (volGroupId == IMUSE_VOLGRP_VOICE)
-				result = openVoiceBundle(slot, disk);
+				result = openVoiceBundle(sound, disk);
 			else if (volGroupId == IMUSE_VOLGRP_MUSIC)
-				result = openMusicBundle(slot, disk);
+				result = openMusicBundle(sound, disk);
 			else
 				error("ImuseDigiSndMgr::openSound() Don't know how load sound: %d", soundId);
 			if (!result) {
-				closeSound(&_sounds[slot]);
+				closeSound(sound);
 				return NULL;
 			}
-			_sounds[slot].bundle->decompressSampleByIndex(soundId, 0, 0x2000, &ptr, 0, header_outside);
-			_sounds[slot].soundId = soundId;
-			_sounds[slot].type = soundType;
-			_sounds[slot].volGroupId = volGroupId;
+			sound->bundle->decompressSampleByIndex(soundId, 0, 0x2000, &ptr, 0, header_outside);
+			sound->soundId = soundId;
+			sound->type = soundType;
+			sound->volGroupId = volGroupId;
 		} else {
 			error("ImuseDigiSndMgr::openSound() Don't know how load sound: %d", soundId);
 		}
@@ -336,20 +336,20 @@
 		if (soundType == IMUSE_BUNDLE) {
 			bool header_outside = ((_vm->_gameId == GID_CMI) && !(_vm->_features & GF_DEMO));
 			if (volGroupId == IMUSE_VOLGRP_VOICE)
-				result = openVoiceBundle(slot, disk);
+				result = openVoiceBundle(sound, disk);
 			else if (volGroupId == IMUSE_VOLGRP_MUSIC)
-				result = openMusicBundle(slot, disk);
+				result = openMusicBundle(sound, disk);
 			else
 				error("ImuseDigiSndMgr::openSound() Don't know how load sound: %d", soundId);
 			if (!result) {
-				closeSound(&_sounds[slot]);
+				closeSound(sound);
 				return NULL;
 			}
-			_sounds[slot].bundle->decompressSampleByName(soundName, 0, 0x2000, &ptr, header_outside);
-			strcpy(_sounds[slot].name, soundName);
-			_sounds[slot].soundId = soundId;
-			_sounds[slot].type = soundType;
-			_sounds[slot].volGroupId = volGroupId;
+			sound->bundle->decompressSampleByName(soundName, 0, 0x2000, &ptr, header_outside);
+			strcpy(sound->name, soundName);
+			sound->soundId = soundId;
+			sound->type = soundType;
+			sound->volGroupId = volGroupId;
 		} else {
 			error("ImuseDigiSndMgr::openSound() Don't know how load sound: %s", soundName);
 		}
@@ -357,12 +357,12 @@
 
 	if (result) {
 		if (ptr == NULL) {
-			closeSound(&_sounds[slot]);
+			closeSound(sound);
 			return NULL;
 		}
-		_sounds[slot].disk = _disk;
-		prepareSound(ptr, slot);
-		return &_sounds[slot];
+		sound->disk = _disk;
+		prepareSound(ptr, sound);
+		return sound;
 	}
 
 	return NULL;

Index: dimuse_sndmgr.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse_digi/dimuse_sndmgr.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- dimuse_sndmgr.h	1 Jun 2004 19:32:36 -0000	1.25
+++ dimuse_sndmgr.h	19 Jun 2004 17:48:06 -0000	1.26
@@ -91,15 +91,15 @@
 	soundStruct _sounds[MAX_IMUSE_SOUNDS];
 
 	bool checkForProperHandle(soundStruct *soundHandle);
-	int allocSlot();
-	void prepareSound(byte *ptr, int slot);
+	soundStruct *allocSlot();
+	void prepareSound(byte *ptr, soundStruct *sound);
 
 	ScummEngine *_vm;
 	byte _disk;
 	BundleDirCache *_cacheBundleDir;
 
-	bool openMusicBundle(int slot, int disk);
-	bool openVoiceBundle(int slot, int disk);
+	bool openMusicBundle(soundStruct *sound, int disk);
+	bool openVoiceBundle(soundStruct *sound, int disk);
 
 	void countElements(byte *ptr, int &numRegions, int &numJumps, int &numSyncs);
 





More information about the Scummvm-git-logs mailing list