aboutsummaryrefslogtreecommitdiff
path: root/scumm
diff options
context:
space:
mode:
authorPaweł Kołodziejski2004-06-19 17:48:06 +0000
committerPaweł Kołodziejski2004-06-19 17:48:06 +0000
commit8f1191b3792ed777e7d6ea7c137b65987a556b2e (patch)
tree1626ce6c84c95160813e09462404aafa4fb27022 /scumm
parent4b9aa09f03ec16179c2f74dc8c6b8735e9f1fd74 (diff)
downloadscummvm-rg350-8f1191b3792ed777e7d6ea7c137b65987a556b2e.tar.gz
scummvm-rg350-8f1191b3792ed777e7d6ea7c137b65987a556b2e.tar.bz2
scummvm-rg350-8f1191b3792ed777e7d6ea7c137b65987a556b2e.zip
some optimisations
svn-id: r13969
Diffstat (limited to 'scumm')
-rw-r--r--scumm/imuse_digi/dimuse_sndmgr.cpp166
-rw-r--r--scumm/imuse_digi/dimuse_sndmgr.h8
2 files changed, 87 insertions, 87 deletions
diff --git a/scumm/imuse_digi/dimuse_sndmgr.cpp b/scumm/imuse_digi/dimuse_sndmgr.cpp
index b2298517a4..505eff5434 100644
--- a/scumm/imuse_digi/dimuse_sndmgr.cpp
+++ b/scumm/imuse_digi/dimuse_sndmgr.cpp
@@ -79,7 +79,7 @@ void ImuseDigiSndMgr::countElements(byte *ptr, int &numRegions, int &numJumps, i
} 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 @@ void ImuseDigiSndMgr::prepareSound(byte *ptr, int slot) {
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 @@ void ImuseDigiSndMgr::prepareSound(byte *ptr, int slot) {
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 @@ void ImuseDigiSndMgr::prepareSound(byte *ptr, int slot) {
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 @@ void ImuseDigiSndMgr::prepareSound(byte *ptr, int slot) {
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 @@ void ImuseDigiSndMgr::prepareSound(byte *ptr, int slot) {
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 @@ bool ImuseDigiSndMgr::openMusicBundle(int slot, int disk) {
// _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 @@ bool ImuseDigiSndMgr::openVoiceBundle(int slot, int disk) {
// _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 @@ ImuseDigiSndMgr::soundStruct *ImuseDigiSndMgr::openSound(int32 soundId, const ch
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 @@ ImuseDigiSndMgr::soundStruct *ImuseDigiSndMgr::openSound(int32 soundId, const ch
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 @@ ImuseDigiSndMgr::soundStruct *ImuseDigiSndMgr::openSound(int32 soundId, const ch
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 @@ ImuseDigiSndMgr::soundStruct *ImuseDigiSndMgr::openSound(int32 soundId, const ch
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;
diff --git a/scumm/imuse_digi/dimuse_sndmgr.h b/scumm/imuse_digi/dimuse_sndmgr.h
index e95f0b22c5..e4043fb56c 100644
--- a/scumm/imuse_digi/dimuse_sndmgr.h
+++ b/scumm/imuse_digi/dimuse_sndmgr.h
@@ -91,15 +91,15 @@ private:
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);