From 13356dfa1784820a4f56aad79e162436ff3d7c6a Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sat, 28 Aug 2004 14:19:56 +0000 Subject: [PATCH] Reduce code duplication svn-id: r14815 --- scumm/imuse_digi/dimuse_sndmgr.cpp | 111 +++++++++++------------------ 1 file changed, 43 insertions(+), 68 deletions(-) diff --git a/scumm/imuse_digi/dimuse_sndmgr.cpp b/scumm/imuse_digi/dimuse_sndmgr.cpp index 8e164d02628..f92b8f94bd4 100644 --- a/scumm/imuse_digi/dimuse_sndmgr.cpp +++ b/scumm/imuse_digi/dimuse_sndmgr.cpp @@ -305,83 +305,58 @@ ImuseDigiSndMgr::soundStruct *ImuseDigiSndMgr::openSound(int32 soundId, const ch error("ImuseDigiSndMgr::openSound() can't alloc free sound slot"); } + const bool header_outside = ((_vm->_gameId == GID_CMI) && !(_vm->_features & GF_DEMO)); bool result = false; byte *ptr = NULL; + + switch (soundType) { + case IMUSE_RESOURCE: + assert(soundName[0] == 0); // Paranoia check - if (soundName[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(sound); - return NULL; - } - 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(sound, disk); - else if (volGroupId == IMUSE_VOLGRP_MUSIC) - result = openMusicBundle(sound, disk); - else - error("ImuseDigiSndMgr::openSound() Don't know how load sound: %d", soundId); - if (!result) { - closeSound(sound); - return NULL; - } - if (sound->bundle->decompressSampleByIndex(soundId, 0, 0x2000, &ptr, 0, header_outside) == 0) { - closeSound(sound); - return NULL; - } - sound->soundId = soundId; - sound->type = soundType; - sound->volGroupId = volGroupId; - } else { - error("ImuseDigiSndMgr::openSound() Don't know how load sound: %d", soundId); - } - } else { - if (soundType == IMUSE_BUNDLE) { - bool header_outside = ((_vm->_gameId == GID_CMI) && !(_vm->_features & GF_DEMO)); - if (volGroupId == IMUSE_VOLGRP_VOICE) - result = openVoiceBundle(sound, disk); - else if (volGroupId == IMUSE_VOLGRP_MUSIC) - result = openMusicBundle(sound, disk); - else - error("ImuseDigiSndMgr::openSound() Don't know how load sound: %d", soundId); - if (!result) { - closeSound(sound); - return NULL; - } - if (sound->bundle->decompressSampleByName(soundName, 0, 0x2000, &ptr, header_outside) == 0) { - closeSound(sound); - return NULL; - } - 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); - } - } - - if (result) { + _vm->ensureResourceLoaded(rtSound, soundId); + _vm->lock(rtSound, soundId); + ptr = _vm->getResourceAddress(rtSound, soundId); if (ptr == NULL) { closeSound(sound); return NULL; } - sound->disk = _disk; - prepareSound(ptr, sound); - return sound; + sound->resPtr = ptr; + break; + case IMUSE_BUNDLE: + if (volGroupId == IMUSE_VOLGRP_VOICE) + result = openVoiceBundle(sound, disk); + else if (volGroupId == IMUSE_VOLGRP_MUSIC) + result = openMusicBundle(sound, disk); + else + error("ImuseDigiSndMgr::openSound() Don't know how load sound: %d", soundId); + if (!result) { + closeSound(sound); + return NULL; + } + if (soundName[0] == 0) { + if (sound->bundle->decompressSampleByIndex(soundId, 0, 0x2000, &ptr, 0, header_outside) == 0 || ptr == NULL) { + closeSound(sound); + return NULL; + } + } else { + if (sound->bundle->decompressSampleByName(soundName, 0, 0x2000, &ptr, header_outside) == 0 || ptr == NULL) { + closeSound(sound); + return NULL; + } + } + sound->resPtr = 0; + break; + default: + error("ImuseDigiSndMgr::openSound() Unknown soundType %d (trying to load sound %d)", soundType, soundId); } - return NULL; + strcpy(sound->name, soundName); + sound->soundId = soundId; + sound->type = soundType; + sound->volGroupId = volGroupId; + sound->disk = _disk; + prepareSound(ptr, sound); + return sound; } void ImuseDigiSndMgr::closeSound(soundStruct *soundHandle) {