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"
|
2008-12-22 14:13:15 +00:00
|
|
|
#include "saga/resource.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"
|
2008-12-31 11:46:21 +00:00
|
|
|
#include "sound/shorten.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 {
|
|
|
|
|
2008-05-26 11:10:46 +00:00
|
|
|
#define RID_IHNM_SFX_LUT 265
|
|
|
|
#define RID_IHNMDEMO_SFX_LUT 222
|
|
|
|
|
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
|
|
|
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_ITE) {
|
2005-08-07 00:00:43 +00:00
|
|
|
_fxTable = ITE_SfxTable;
|
|
|
|
_fxTableLen = ITE_SFXCOUNT;
|
2008-12-21 22:52:44 +00:00
|
|
|
} else if (_vm->getGameId() == GID_IHNM) {
|
2005-08-07 00:00:43 +00:00
|
|
|
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;
|
|
|
|
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getFeatures() & GF_IHNM_DEMO) {
|
2007-07-18 16:14:40 +00:00
|
|
|
_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;
|
2008-12-21 22:52:44 +00:00
|
|
|
} else if (_vm->getGameId() == GID_DINO) {
|
|
|
|
// TODO
|
|
|
|
} else if (_vm->getGameId() == GID_FTA2) {
|
|
|
|
// TODO
|
2005-08-07 00:00:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SndRes::~SndRes() {
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_IHNM) {
|
2005-08-07 00:00:43 +00:00
|
|
|
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
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_IHNM && _vm->isMacResources()) {
|
2008-04-05 13:19:12 +00:00
|
|
|
_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;
|
|
|
|
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_IHNM && !(_vm->_voicesEnabled))
|
2007-06-13 19:41:27 +00:00
|
|
|
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) {
|
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;
|
2009-01-01 16:02:43 +00:00
|
|
|
byte *data = 0;
|
2005-07-19 19:05:52 +00:00
|
|
|
int rate;
|
|
|
|
int size;
|
2009-01-01 16:02:43 +00:00
|
|
|
byte flags = 0;
|
2005-07-19 19:05:52 +00:00
|
|
|
size_t voxSize;
|
2008-12-31 22:10:09 +00:00
|
|
|
const GameSoundInfo *soundInfo = 0;
|
2008-09-09 07:05:47 +00:00
|
|
|
Common::File* file;
|
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-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_IHNM && _vm->isMacResources()) {
|
2008-04-05 12:36:52 +00:00
|
|
|
char soundFileName[40];
|
2008-04-05 16:02:28 +00:00
|
|
|
int dirIndex = resourceId / 64;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-04-05 12:36:52 +00:00
|
|
|
if ((context->fileType & GAME_VOICEFILE) != 0) {
|
2008-04-05 13:19:12 +00:00
|
|
|
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 14:28:24 +00:00
|
|
|
sprintf(soundFileName, "SFX/SFX%d/SFX%03x", dirIndex, resourceId);
|
2008-04-05 12:36:52 +00:00
|
|
|
}
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-09 07:05:47 +00:00
|
|
|
file = new Common::File();
|
|
|
|
|
|
|
|
file->open(soundFileName);
|
|
|
|
soundResourceLength = file->size();
|
2008-04-05 12:36:52 +00:00
|
|
|
} else {
|
2008-09-09 07:05:47 +00:00
|
|
|
|
2008-09-30 12:58:27 +00:00
|
|
|
ResourceData* resourceData = context->getResourceData(resourceId);
|
2008-09-09 07:05:47 +00:00
|
|
|
file = context->getFile(resourceData);
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-09-09 07:05:47 +00:00
|
|
|
file->seek(resourceData->offset);
|
|
|
|
soundResourceLength = resourceData->size;
|
|
|
|
|
2008-04-05 12:36:52 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2008-09-09 07:05:47 +00:00
|
|
|
Common::SeekableReadStream& readS = *file;
|
|
|
|
|
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
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
if (soundResourceLength >= 8) {
|
2008-09-09 07:05:47 +00:00
|
|
|
byte header[8];
|
|
|
|
|
|
|
|
readS.read(&header, 8);
|
|
|
|
readS.seek(readS.pos() - 8);
|
|
|
|
|
|
|
|
if (!memcmp(header, "Creative", 8)) {
|
2005-07-26 19:40:58 +00:00
|
|
|
resourceType = kSoundVOC;
|
2008-09-09 07:05:47 +00:00
|
|
|
} else if (!memcmp(header, "RIFF", 4) != 0) {
|
2005-07-26 19:40:58 +00:00
|
|
|
resourceType = kSoundWAV;
|
2008-09-09 07:05:47 +00:00
|
|
|
} else if (!memcmp(header, "FORM", 4) != 0) {
|
2008-04-05 12:36:52 +00:00
|
|
|
resourceType = kSoundAIFF;
|
2008-12-29 18:35:18 +00:00
|
|
|
} else if (!memcmp(header, "ajkg", 4) != 0) {
|
|
|
|
resourceType = kSoundShorten;
|
2008-12-31 22:10:09 +00:00
|
|
|
} else if (soundInfo) {
|
2008-12-29 18:35:18 +00:00
|
|
|
resourceType = soundInfo->resourceType;
|
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
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_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
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_IHNM && (context->fileType & GAME_SOUNDFILE))
|
2007-08-01 14:19:55 +00:00
|
|
|
uncompressedSound = true;
|
|
|
|
|
|
|
|
if ((_vm->getFeatures() & GF_COMPRESSED_SOUNDS) && !uncompressedSound) {
|
2008-09-09 07:05:47 +00:00
|
|
|
if (header[0] == char(0)) {
|
2007-06-25 18:23:01 +00:00
|
|
|
resourceType = kSoundMP3;
|
2008-09-09 07:05:47 +00:00
|
|
|
} else if (header[0] == char(1)) {
|
2007-06-25 20:20:59 +00:00
|
|
|
resourceType = kSoundOGG;
|
2008-09-09 07:05:47 +00:00
|
|
|
} else if (header[0] == char(2)) {
|
2007-06-25 20:20:59 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-12-29 17:30:29 +00:00
|
|
|
buffer.isBigEndian = _vm->isMacResources();
|
2007-07-10 23:22:44 +00:00
|
|
|
buffer.soundType = resourceType;
|
|
|
|
buffer.originalSize = 0;
|
2008-12-31 22:10:09 +00:00
|
|
|
buffer.stereo = false;
|
2009-01-01 16:02:43 +00:00
|
|
|
buffer.frequency = 22050; // default for PCM and VOX
|
|
|
|
buffer.buffer = NULL;
|
|
|
|
|
|
|
|
// Older Mac versions of ITE were Macbinary packed
|
|
|
|
int soundOffset = (context->fileType & GAME_MACBINARY) ? 36 : 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:
|
2005-08-04 10:23:49 +00:00
|
|
|
buffer.isSigned = soundInfo->isSigned;
|
|
|
|
buffer.sampleBits = soundInfo->sampleBits;
|
2008-12-31 22:10:09 +00:00
|
|
|
buffer.size = soundResourceLength - soundOffset;
|
2009-01-01 16:02:43 +00:00
|
|
|
if (!onlyHeader) {
|
2008-12-31 22:10:09 +00:00
|
|
|
buffer.buffer = (byte *) malloc(buffer.size);
|
|
|
|
if (soundOffset > 0)
|
|
|
|
readS.seek(soundOffset, SEEK_CUR);
|
2008-09-09 07:05:47 +00:00
|
|
|
readS.read(buffer.buffer, buffer.size);
|
2005-08-04 10:23:49 +00:00
|
|
|
}
|
|
|
|
result = true;
|
|
|
|
break;
|
2005-07-26 19:40:58 +00:00
|
|
|
case kSoundVOX:
|
|
|
|
buffer.isSigned = soundInfo->isSigned;
|
|
|
|
buffer.sampleBits = soundInfo->sampleBits;
|
|
|
|
buffer.size = soundResourceLength * 4;
|
2009-01-01 16:02:43 +00:00
|
|
|
if (!onlyHeader) {
|
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 kSoundWAV:
|
2008-04-05 12:36:52 +00:00
|
|
|
case kSoundAIFF:
|
2008-12-29 18:35:18 +00:00
|
|
|
case kSoundShorten:
|
2009-01-01 16:02:43 +00:00
|
|
|
case kSoundVOC:
|
|
|
|
if (resourceType == kSoundWAV) {
|
|
|
|
result = Audio::loadWAVFromStream(readS, size, rate, flags);
|
|
|
|
} else if (resourceType == kSoundAIFF) {
|
|
|
|
result = Audio::loadAIFFFromStream(readS, size, rate, flags);
|
|
|
|
} else if (resourceType == kSoundShorten) {
|
|
|
|
result = Audio::loadShortenFromStream(readS, size, rate, flags);
|
|
|
|
} else if (resourceType == kSoundVOC) {
|
|
|
|
data = Audio::loadVOCFromStream(readS, size, rate);
|
|
|
|
result = (data != 0);
|
|
|
|
if (onlyHeader)
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result) {
|
2008-12-29 18:35:18 +00:00
|
|
|
buffer.frequency = rate;
|
2008-12-31 11:46:21 +00:00
|
|
|
buffer.sampleBits = (flags & Audio::Mixer::FLAG_16BITS) ? 16 : 8;
|
|
|
|
buffer.stereo = flags & Audio::Mixer::FLAG_STEREO;
|
2009-01-01 16:02:43 +00:00
|
|
|
buffer.isSigned = (resourceType == kSoundVOC) ? false : !(flags & Audio::Mixer::FLAG_UNSIGNED);
|
2008-12-29 18:35:18 +00:00
|
|
|
buffer.size = size;
|
2009-01-01 16:02:43 +00:00
|
|
|
|
|
|
|
if (!onlyHeader && resourceType != kSoundVOC) {
|
2008-12-29 18:35:18 +00:00
|
|
|
buffer.buffer = (byte *)malloc(size);
|
|
|
|
readS.read(buffer.buffer, size);
|
2009-01-01 16:02:43 +00:00
|
|
|
} else if (!onlyHeader && resourceType == kSoundVOC) {
|
|
|
|
buffer.buffer = data;
|
2008-12-29 18:35:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2007-06-25 18:23:01 +00:00
|
|
|
case kSoundMP3:
|
|
|
|
case kSoundOGG:
|
|
|
|
case kSoundFLAC:
|
|
|
|
ResourceData *resourceData;
|
2008-09-30 12:58:27 +00:00
|
|
|
resourceData = context->getResourceData(resourceId);
|
2007-06-25 18:23:01 +00:00
|
|
|
|
2007-06-26 13:38:24 +00:00
|
|
|
// Read compressed sfx header
|
2008-12-12 22:56:56 +00:00
|
|
|
readS.readByte(); // Skip compression identifier byte
|
2007-06-25 18:23:01 +00:00
|
|
|
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
|
|
|
|
|
|
|
result = true;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-09-09 07:05:47 +00:00
|
|
|
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_IHNM && _vm->isMacResources()) {
|
2008-09-09 07:05:47 +00:00
|
|
|
delete file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|