2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-04-12 21:40:49 +00:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2006-02-11 12:44:16 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 16:15:55 +00:00
|
|
|
// Sound resource management class
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-08-07 00:00:43 +00:00
|
|
|
#include "saga/itedata.h"
|
2006-05-13 10:30:38 +00:00
|
|
|
#include "saga/sagaresnames.h"
|
2005-07-19 19:05:52 +00:00
|
|
|
#include "saga/rscfile.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/sndres.h"
|
|
|
|
#include "saga/sound.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-17 16:11:04 +00:00
|
|
|
#include "common/file.h"
|
|
|
|
|
2004-12-11 23:36:17 +00:00
|
|
|
#include "sound/voc.h"
|
2005-01-09 15:57:38 +00:00
|
|
|
#include "sound/wave.h"
|
2005-07-19 19:05:52 +00:00
|
|
|
#include "sound/adpcm.h"
|
2008-04-05 12:36:52 +00:00
|
|
|
#include "sound/aiff.h"
|
2005-07-19 19:05:52 +00:00
|
|
|
#include "sound/audiostream.h"
|
2004-12-11 23:36:17 +00:00
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
namespace Saga {
|
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
SndRes::SndRes(SagaEngine *vm) : _vm(vm) {
|
2007-07-31 18:08:40 +00:00
|
|
|
// Load sound module resource file contexts
|
2005-07-19 19:05:52 +00:00
|
|
|
_sfxContext = _vm->_resource->getContext(GAME_SOUNDFILE);
|
|
|
|
if (_sfxContext == NULL) {
|
|
|
|
error("SndRes::SndRes resource context not found");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-26 19:40:58 +00:00
|
|
|
_voiceSerial = -1;
|
|
|
|
|
|
|
|
setVoiceBank(0);
|
2005-08-07 00:00:43 +00:00
|
|
|
|
|
|
|
if (_vm->getGameType() == GType_ITE) {
|
|
|
|
_fxTable = ITE_SfxTable;
|
|
|
|
_fxTableLen = ITE_SFXCOUNT;
|
|
|
|
} else {
|
|
|
|
ResourceContext *resourceContext;
|
|
|
|
|
2005-09-29 15:27:10 +00:00
|
|
|
resourceContext = _vm->_resource->getContext(GAME_SOUNDFILE);
|
2005-08-07 00:00:43 +00:00
|
|
|
if (resourceContext == NULL) {
|
|
|
|
error("Resource::loadGlobalResources() resource context not found");
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *resourcePointer;
|
|
|
|
size_t resourceLength;
|
|
|
|
|
2007-07-18 16:14:40 +00:00
|
|
|
if (_vm->getGameId() == GID_IHNM_DEMO) {
|
|
|
|
_vm->_resource->loadResource(resourceContext, RID_IHNMDEMO_SFX_LUT,
|
|
|
|
resourcePointer, resourceLength);
|
|
|
|
} else {
|
|
|
|
_vm->_resource->loadResource(resourceContext, RID_IHNM_SFX_LUT,
|
|
|
|
resourcePointer, resourceLength);
|
|
|
|
}
|
2005-08-07 00:00:43 +00:00
|
|
|
|
|
|
|
if (resourceLength == 0) {
|
|
|
|
error("Sndres::SndRes can't read SfxIDs table");
|
|
|
|
}
|
|
|
|
|
|
|
|
_fxTableIDsLen = resourceLength / 2;
|
|
|
|
_fxTableIDs = (int16 *)malloc(_fxTableIDsLen * sizeof(int16));
|
|
|
|
|
|
|
|
MemoryReadStream metaS(resourcePointer, resourceLength);
|
|
|
|
for (int i = 0; i < _fxTableIDsLen; i++)
|
|
|
|
_fxTableIDs[i] = metaS.readSint16LE();
|
|
|
|
|
|
|
|
free(resourcePointer);
|
|
|
|
|
|
|
|
_fxTable = 0;
|
|
|
|
_fxTableLen = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SndRes::~SndRes() {
|
|
|
|
if (_vm->getGameType() == GType_IHNM) {
|
|
|
|
free(_fxTable);
|
|
|
|
free(_fxTableIDs);
|
|
|
|
}
|
2005-07-26 19:40:58 +00:00
|
|
|
}
|
|
|
|
|
2007-09-10 13:17:20 +00:00
|
|
|
void SndRes::setVoiceBank(int serial) {
|
2008-02-27 18:17:50 +00:00
|
|
|
if (_voiceSerial == serial)
|
|
|
|
return;
|
|
|
|
|
2008-04-05 13:19:12 +00:00
|
|
|
// If we got the Macintosh version of IHNM, just set the voice bank
|
|
|
|
// so that we know which voices* subfolder to look for later
|
|
|
|
if (_vm->getGameType() == GType_IHNM && _vm->isMacResources()) {
|
|
|
|
_voiceSerial = serial;
|
|
|
|
// Set a dummy voice context
|
|
|
|
_voiceContext = new ResourceContext();
|
|
|
|
_voiceContext->fileType = GAME_VOICEFILE;
|
|
|
|
_voiceContext->count = 0;
|
|
|
|
_voiceContext->serial = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-27 18:17:50 +00:00
|
|
|
// If there are no voice files present, don't set the voice bank
|
|
|
|
if (!_vm->_voiceFilesExist)
|
|
|
|
return;
|
2005-07-26 19:40:58 +00:00
|
|
|
|
2008-01-27 14:32:08 +00:00
|
|
|
// Close previous voice bank file
|
|
|
|
if (_voiceSerial >= 0 && _voiceContext->file->isOpen())
|
|
|
|
_voiceContext->file->close();
|
|
|
|
|
2005-07-26 19:40:58 +00:00
|
|
|
_voiceSerial = serial;
|
|
|
|
|
|
|
|
_voiceContext = _vm->_resource->getContext(GAME_VOICEFILE, _voiceSerial);
|
2008-01-27 14:32:08 +00:00
|
|
|
|
|
|
|
// Open new voice bank file
|
|
|
|
if (!_voiceContext->file->isOpen())
|
|
|
|
_voiceContext->file->open(_voiceContext->fileName);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void SndRes::playSound(uint32 resourceId, int volume, bool loop) {
|
|
|
|
SoundBuffer buffer;
|
2004-10-19 17:12:53 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
debug(4, "SndRes::playSound %i", resourceId);
|
2004-10-19 17:12:53 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
if (!load(_sfxContext, resourceId, buffer, false)) {
|
2005-07-05 16:58:36 +00:00
|
|
|
warning("Failed to load sound");
|
2005-07-19 19:05:52 +00:00
|
|
|
return;
|
2004-10-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
_vm->_sound->playSound(buffer, volume, loop);
|
2004-10-19 17:12:53 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void SndRes::playVoice(uint32 resourceId) {
|
|
|
|
SoundBuffer buffer;
|
2004-11-15 03:03:48 +00:00
|
|
|
|
2007-12-23 02:33:58 +00:00
|
|
|
if (!(_vm->_voiceFilesExist))
|
|
|
|
return;
|
|
|
|
|
2007-06-13 19:41:27 +00:00
|
|
|
if (_vm->getGameType() == GType_IHNM && !(_vm->_voicesEnabled))
|
|
|
|
return;
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
debug(4, "SndRes::playVoice %i", resourceId);
|
2004-04-30 17:49:33 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
if (!load(_voiceContext, resourceId, buffer, false)) {
|
|
|
|
warning("Failed to load voice");
|
|
|
|
return;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
_vm->_sound->playVoice(buffer);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buffer, bool onlyHeader) {
|
|
|
|
byte *soundResource;
|
2006-04-29 22:33:31 +00:00
|
|
|
Audio::AudioStream *voxStream;
|
2005-07-19 19:05:52 +00:00
|
|
|
size_t soundResourceLength;
|
|
|
|
bool result = false;
|
|
|
|
GameSoundTypes resourceType;
|
|
|
|
byte *data;
|
|
|
|
int rate;
|
|
|
|
int size;
|
|
|
|
byte flags;
|
|
|
|
size_t voxSize;
|
2005-07-26 19:40:58 +00:00
|
|
|
const GameSoundInfo *soundInfo;
|
2005-07-19 19:05:52 +00:00
|
|
|
|
2005-07-31 16:51:14 +00:00
|
|
|
if (resourceId == (uint32)-1) {
|
2005-07-19 19:05:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2008-04-05 12:36:52 +00:00
|
|
|
if (_vm->getGameType() == GType_IHNM && _vm->isMacResources()) {
|
|
|
|
Common::File soundFile;
|
|
|
|
char soundFileName[40];
|
|
|
|
int dirIndex = 0;
|
|
|
|
|
|
|
|
if ((context->fileType & GAME_VOICEFILE) != 0) {
|
2008-04-05 13:19:12 +00:00
|
|
|
dirIndex = floor((float)(resourceId / 64));
|
|
|
|
|
|
|
|
if (_voiceSerial == 0) {
|
2008-04-05 14:18:32 +00:00
|
|
|
sprintf(soundFileName, "Voices/VoicesS/Voices%d/VoicesS%03x", dirIndex, resourceId);
|
2008-04-05 13:19:12 +00:00
|
|
|
} else {
|
2008-04-05 14:18:32 +00:00
|
|
|
sprintf(soundFileName, "Voices/Voices%d/Voices%d/Voices%d%03x", _voiceSerial, dirIndex, _voiceSerial, resourceId);
|
2008-04-05 13:19:12 +00:00
|
|
|
}
|
2008-04-05 12:36:52 +00:00
|
|
|
} else {
|
2008-04-05 13:19:12 +00:00
|
|
|
dirIndex = floor((float)(resourceId / 64));
|
2008-04-05 12:36:52 +00:00
|
|
|
|
2008-04-05 14:18:32 +00:00
|
|
|
sprintf(soundFileName, "SFX/SFX%d/SFX%02x", dirIndex, resourceId);
|
2008-04-05 12:36:52 +00:00
|
|
|
}
|
|
|
|
soundFile.open(soundFileName);
|
|
|
|
soundResourceLength = soundFile.size();
|
|
|
|
soundResource = new byte[soundResourceLength];
|
|
|
|
soundFile.read(soundResource, soundResourceLength);
|
|
|
|
soundFile.close();
|
|
|
|
} else {
|
|
|
|
_vm->_resource->loadResource(context, resourceId, soundResource, soundResourceLength);
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-26 19:40:58 +00:00
|
|
|
if ((context->fileType & GAME_VOICEFILE) != 0) {
|
|
|
|
soundInfo = _vm->getVoiceInfo();
|
|
|
|
} else {
|
|
|
|
soundInfo = _vm->getSfxInfo();
|
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2008-04-05 13:19:12 +00:00
|
|
|
if (_vm->getGameType() == GType_IHNM && _vm->isMacResources() && (context->fileType & GAME_VOICEFILE) != 0) {
|
|
|
|
// No sound patch data for the voice files in the Mac version of IHNM
|
|
|
|
} else {
|
|
|
|
context->table[resourceId].fillSoundPatch(soundInfo);
|
|
|
|
}
|
2005-07-26 19:40:58 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
MemoryReadStream readS(soundResource, soundResourceLength);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-26 19:40:58 +00:00
|
|
|
resourceType = soundInfo->resourceType;
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
if (soundResourceLength >= 8) {
|
2005-08-04 10:23:49 +00:00
|
|
|
if (!memcmp(soundResource, "Creative", 8)) {
|
2005-07-26 19:40:58 +00:00
|
|
|
resourceType = kSoundVOC;
|
2007-06-25 18:23:01 +00:00
|
|
|
} else if (!memcmp(soundResource, "RIFF", 4) != 0) {
|
2005-07-26 19:40:58 +00:00
|
|
|
resourceType = kSoundWAV;
|
2008-04-05 12:36:52 +00:00
|
|
|
} else if (!memcmp(soundResource, "FORM", 4) != 0) {
|
|
|
|
resourceType = kSoundAIFF;
|
2008-01-27 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
2007-08-01 14:19:55 +00:00
|
|
|
bool uncompressedSound = false;
|
2007-09-06 08:35:08 +00:00
|
|
|
// If patch data exists for sound resource 4 (used in ITE intro), don't treat this sound as compressed
|
|
|
|
// Patch data for this resource is in file p2_a.iaf or p2_a.voc
|
|
|
|
if (_vm->getGameType() == GType_ITE && resourceId == 4 && context->table[resourceId].patchData != NULL)
|
2007-08-01 14:19:55 +00:00
|
|
|
uncompressedSound = true;
|
2007-07-14 14:18:45 +00:00
|
|
|
|
2007-08-01 14:19:55 +00:00
|
|
|
// FIXME: Currently, the SFX.RES file in IHNM cannot be compressed
|
|
|
|
if (_vm->getGameType() == GType_IHNM && (context->fileType & GAME_SOUNDFILE))
|
|
|
|
uncompressedSound = true;
|
|
|
|
|
|
|
|
if ((_vm->getFeatures() & GF_COMPRESSED_SOUNDS) && !uncompressedSound) {
|
2007-06-25 20:20:59 +00:00
|
|
|
if (soundResource[0] == char(0)) {
|
2007-06-25 18:23:01 +00:00
|
|
|
resourceType = kSoundMP3;
|
2007-06-25 20:20:59 +00:00
|
|
|
} else if (soundResource[0] == char(1)) {
|
|
|
|
resourceType = kSoundOGG;
|
|
|
|
} else if (soundResource[0] == char(2)) {
|
|
|
|
resourceType = kSoundFLAC;
|
|
|
|
}
|
2005-07-19 19:05:52 +00:00
|
|
|
}
|
2007-06-25 20:20:59 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
}
|
|
|
|
|
2007-07-10 23:22:44 +00:00
|
|
|
buffer.isBigEndian = soundInfo->isBigEndian;
|
|
|
|
buffer.soundType = resourceType;
|
|
|
|
buffer.originalSize = 0;
|
2005-07-26 19:40:58 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
switch (resourceType) {
|
2005-07-26 19:40:58 +00:00
|
|
|
case kSoundPCM:
|
|
|
|
buffer.frequency = soundInfo->frequency;
|
|
|
|
buffer.isSigned = soundInfo->isSigned;
|
|
|
|
buffer.sampleBits = soundInfo->sampleBits;
|
|
|
|
buffer.size = soundResourceLength;
|
|
|
|
buffer.stereo = soundInfo->stereo;
|
|
|
|
if (onlyHeader) {
|
|
|
|
buffer.buffer = NULL;
|
|
|
|
free(soundResource);
|
|
|
|
} else {
|
|
|
|
buffer.buffer = soundResource;
|
2005-07-19 19:05:52 +00:00
|
|
|
}
|
2005-07-26 19:40:58 +00:00
|
|
|
result = true;
|
|
|
|
break;
|
2005-08-04 10:23:49 +00:00
|
|
|
case kSoundMacPCM:
|
|
|
|
buffer.frequency = soundInfo->frequency;
|
|
|
|
buffer.isSigned = soundInfo->isSigned;
|
|
|
|
buffer.sampleBits = soundInfo->sampleBits;
|
|
|
|
buffer.size = soundResourceLength - 36;
|
|
|
|
buffer.stereo = soundInfo->stereo;
|
|
|
|
if (onlyHeader) {
|
|
|
|
buffer.buffer = NULL;
|
|
|
|
} else {
|
|
|
|
buffer.buffer = (byte *)malloc(buffer.size);
|
|
|
|
memcpy(buffer.buffer, soundResource + 36, buffer.size);
|
|
|
|
}
|
|
|
|
free(soundResource);
|
|
|
|
result = true;
|
|
|
|
break;
|
2005-07-26 19:40:58 +00:00
|
|
|
case kSoundVOX:
|
|
|
|
buffer.frequency = soundInfo->frequency;
|
|
|
|
buffer.isSigned = soundInfo->isSigned;
|
|
|
|
buffer.sampleBits = soundInfo->sampleBits;
|
|
|
|
buffer.stereo = soundInfo->stereo;
|
|
|
|
buffer.size = soundResourceLength * 4;
|
|
|
|
if (onlyHeader) {
|
|
|
|
buffer.buffer = NULL;
|
|
|
|
free(soundResource);
|
2005-07-19 19:05:52 +00:00
|
|
|
} else {
|
2007-11-16 10:05:18 +00:00
|
|
|
voxStream = Audio::makeADPCMStream(&readS, false, soundResourceLength, Audio::kADPCMOki);
|
2005-07-26 19:40:58 +00:00
|
|
|
buffer.buffer = (byte *)malloc(buffer.size);
|
|
|
|
voxSize = voxStream->readBuffer((int16*)buffer.buffer, soundResourceLength * 2);
|
|
|
|
if (voxSize != soundResourceLength * 2) {
|
|
|
|
error("SndRes::load() wrong VOX output size");
|
2005-07-19 19:05:52 +00:00
|
|
|
}
|
2005-07-26 19:40:58 +00:00
|
|
|
delete voxStream;
|
2005-07-19 19:05:52 +00:00
|
|
|
}
|
|
|
|
result = true;
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-07-26 19:40:58 +00:00
|
|
|
case kSoundVOC:
|
2006-04-29 22:33:31 +00:00
|
|
|
data = Audio::loadVOCFromStream(readS, size, rate);
|
2005-07-19 19:05:52 +00:00
|
|
|
if (data) {
|
|
|
|
buffer.frequency = rate;
|
|
|
|
buffer.sampleBits = 8;
|
|
|
|
buffer.stereo = false;
|
|
|
|
buffer.isSigned = false;
|
|
|
|
buffer.size = size;
|
|
|
|
if (onlyHeader) {
|
|
|
|
buffer.buffer = NULL;
|
|
|
|
free(data);
|
|
|
|
} else {
|
|
|
|
buffer.buffer = data;
|
|
|
|
}
|
|
|
|
result = true;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2005-07-19 19:05:52 +00:00
|
|
|
free(soundResource);
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2005-07-26 19:40:58 +00:00
|
|
|
case kSoundWAV:
|
2006-04-29 22:33:31 +00:00
|
|
|
if (Audio::loadWAVFromStream(readS, size, rate, flags)) {
|
2005-07-19 19:05:52 +00:00
|
|
|
buffer.frequency = rate;
|
|
|
|
buffer.sampleBits = 16;
|
|
|
|
buffer.stereo = ((flags & Audio::Mixer::FLAG_STEREO) != 0);
|
|
|
|
buffer.isSigned = true;
|
|
|
|
buffer.size = size;
|
|
|
|
if (onlyHeader) {
|
|
|
|
buffer.buffer = NULL;
|
|
|
|
} else {
|
|
|
|
buffer.buffer = (byte *)malloc(size);
|
|
|
|
readS.read(buffer.buffer, size);
|
|
|
|
}
|
|
|
|
result = true;
|
2004-11-18 17:34:54 +00:00
|
|
|
}
|
2005-07-19 19:05:52 +00:00
|
|
|
free(soundResource);
|
2004-11-18 17:34:54 +00:00
|
|
|
break;
|
2008-04-05 12:36:52 +00:00
|
|
|
case kSoundAIFF:
|
|
|
|
if (Audio::loadAIFFFromStream(readS, size, rate, flags)) {
|
|
|
|
buffer.frequency = rate;
|
|
|
|
buffer.sampleBits = 16;
|
|
|
|
buffer.stereo = ((flags & Audio::Mixer::FLAG_STEREO) != 0);
|
|
|
|
buffer.isSigned = true;
|
|
|
|
buffer.size = size;
|
|
|
|
if (onlyHeader) {
|
|
|
|
buffer.buffer = NULL;
|
|
|
|
} else {
|
|
|
|
buffer.buffer = (byte *)malloc(size);
|
|
|
|
readS.read(buffer.buffer, size);
|
|
|
|
}
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
free(soundResource);
|
|
|
|
break;
|
2007-06-25 18:23:01 +00:00
|
|
|
case kSoundMP3:
|
|
|
|
case kSoundOGG:
|
|
|
|
case kSoundFLAC:
|
|
|
|
ResourceData *resourceData;
|
|
|
|
resourceData = _vm->_resource->getResourceData(context, resourceId);
|
|
|
|
|
2007-06-26 13:38:24 +00:00
|
|
|
// Read compressed sfx header
|
2007-06-25 18:23:01 +00:00
|
|
|
readS.seek(1); // Skip compression identifier byte
|
|
|
|
buffer.frequency = readS.readUint16LE();
|
|
|
|
buffer.originalSize = readS.readUint32LE();
|
|
|
|
buffer.sampleBits = readS.readByte();
|
|
|
|
buffer.stereo = (readS.readByte() == char(0)) ? false : true;
|
2007-06-26 13:38:24 +00:00
|
|
|
|
|
|
|
buffer.size = soundResourceLength;
|
2007-06-25 18:23:01 +00:00
|
|
|
buffer.soundType = resourceType;
|
|
|
|
buffer.soundFile = context->getFile(resourceData);
|
2007-06-26 13:38:24 +00:00
|
|
|
buffer.fileOffset = resourceData->offset + 9; // skip compressed sfx header: byte + uint16 + uint32 + byte + byte
|
2007-06-25 18:23:01 +00:00
|
|
|
|
|
|
|
buffer.buffer = NULL;
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
free(soundResource);
|
|
|
|
break;
|
2004-04-12 21:40:49 +00:00
|
|
|
default:
|
2005-07-19 19:05:52 +00:00
|
|
|
error("SndRes::load Unknown sound type");
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-08-11 15:04:12 +00:00
|
|
|
// In ITE CD De some voices are absent and contain just 5 bytes header
|
|
|
|
// Round it to even number so soundmanager will not crash.
|
|
|
|
// See bug #1256701
|
|
|
|
buffer.size &= ~(0x1);
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
return result;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
int SndRes::getVoiceLength(uint32 resourceId) {
|
|
|
|
double msDouble;
|
|
|
|
SoundBuffer buffer;
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2007-12-23 02:33:58 +00:00
|
|
|
if (!(_vm->_voiceFilesExist))
|
|
|
|
return -1;
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
if (!load(_voiceContext, resourceId, buffer, true)) {
|
|
|
|
return -1;
|
2004-10-10 12:27:43 +00:00
|
|
|
}
|
|
|
|
|
2007-07-10 23:22:44 +00:00
|
|
|
if (!(_vm->getFeatures() & GF_COMPRESSED_SOUNDS) || buffer.originalSize == 0)
|
2007-06-25 18:23:01 +00:00
|
|
|
msDouble = (double)buffer.size;
|
|
|
|
else
|
|
|
|
msDouble = (double)buffer.originalSize;
|
2005-07-19 19:05:52 +00:00
|
|
|
if (buffer.sampleBits == 16) {
|
|
|
|
msDouble /= 2.0;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2005-07-19 19:05:52 +00:00
|
|
|
if (buffer.stereo) {
|
|
|
|
msDouble /= 2.0;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
msDouble = msDouble / buffer.frequency * 1000.0;
|
|
|
|
return (int)msDouble;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|