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.
|
2014-02-18 01:34:24 +00:00
|
|
|
*
|
2004-04-12 21:40:49 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:24 +00:00
|
|
|
*
|
2004-04-12 21:40:49 +00:00
|
|
|
* 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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"
|
2011-12-23 04:48:18 +00:00
|
|
|
#include "common/substream.h"
|
2004-05-17 16:11:04 +00:00
|
|
|
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/audiostream.h"
|
|
|
|
#include "audio/decoders/adpcm.h"
|
|
|
|
#include "audio/decoders/aiff.h"
|
2011-12-24 00:26:25 +00:00
|
|
|
#include "audio/decoders/flac.h"
|
2011-12-23 04:48:18 +00:00
|
|
|
#include "audio/decoders/mac_snd.h"
|
2011-12-24 00:26:25 +00:00
|
|
|
#include "audio/decoders/mp3.h"
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/decoders/raw.h"
|
|
|
|
#include "audio/decoders/voc.h"
|
2011-12-24 00:26:25 +00:00
|
|
|
#include "audio/decoders/vorbis.h"
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/decoders/wave.h"
|
2010-01-27 08:40:48 +00:00
|
|
|
#ifdef ENABLE_SAGA2
|
|
|
|
#include "saga/shorten.h"
|
|
|
|
#endif
|
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
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
SndRes::SndRes(SagaEngine *vm) : _vm(vm), _sfxContext(NULL), _voiceContext(NULL), _voiceSerial(-1) {
|
|
|
|
|
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
|
|
|
setVoiceBank(0);
|
2005-08-07 00:00:43 +00:00
|
|
|
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_ITE) {
|
2010-10-22 23:13:17 +00:00
|
|
|
_fxTable.resize(ITE_SFXCOUNT);
|
|
|
|
for (uint i = 0; i < _fxTable.size(); i++) {
|
|
|
|
_fxTable[i].res = ITE_SfxTable[i].res;
|
|
|
|
_fxTable[i].vol = ITE_SfxTable[i].vol;
|
|
|
|
}
|
2009-01-02 16:52:38 +00:00
|
|
|
#ifdef ENABLE_IHNM
|
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");
|
|
|
|
}
|
|
|
|
|
2010-10-24 22:17:44 +00:00
|
|
|
ByteArray resourceData;
|
2005-08-07 00:00:43 +00:00
|
|
|
|
2010-05-16 10:36:21 +00:00
|
|
|
if (_vm->isIHNMDemo()) {
|
2010-10-24 22:17:44 +00:00
|
|
|
_vm->_resource->loadResource(resourceContext, RID_IHNMDEMO_SFX_LUT, resourceData);
|
2007-07-18 16:14:40 +00:00
|
|
|
} else {
|
2010-10-24 22:17:44 +00:00
|
|
|
_vm->_resource->loadResource(resourceContext, RID_IHNM_SFX_LUT, resourceData);
|
2007-07-18 16:14:40 +00:00
|
|
|
}
|
2005-08-07 00:00:43 +00:00
|
|
|
|
2010-10-24 22:17:44 +00:00
|
|
|
if (resourceData.empty()) {
|
2005-08-07 00:00:43 +00:00
|
|
|
error("Sndres::SndRes can't read SfxIDs table");
|
|
|
|
}
|
|
|
|
|
2010-10-24 22:17:44 +00:00
|
|
|
_fxTableIDs.resize(resourceData.size() / 2);
|
2005-08-07 00:00:43 +00:00
|
|
|
|
2010-10-24 22:17:44 +00:00
|
|
|
ByteArrayReadStreamEndian metaS(resourceData);
|
2010-10-22 23:13:17 +00:00
|
|
|
for (uint i = 0; i < _fxTableIDs.size(); i++) {
|
2005-08-07 00:00:43 +00:00
|
|
|
_fxTableIDs[i] = metaS.readSint16LE();
|
2010-10-22 23:13:17 +00:00
|
|
|
}
|
2009-01-02 16:52:38 +00:00
|
|
|
#endif
|
2009-01-02 19:10:51 +00:00
|
|
|
#ifdef ENABLE_SAGA2
|
2008-12-21 22:52:44 +00:00
|
|
|
} else if (_vm->getGameId() == GID_DINO) {
|
|
|
|
// TODO
|
|
|
|
} else if (_vm->getGameId() == GID_FTA2) {
|
|
|
|
// TODO
|
2009-01-02 19:10:51 +00:00
|
|
|
#endif
|
2005-08-07 00:00:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-27 04:38:48 +00:00
|
|
|
SndRes::~SndRes() {
|
|
|
|
#ifdef ENABLE_IHNM
|
|
|
|
if (_vm->getGameId() == GID_IHNM && _vm->isMacResources()) {
|
|
|
|
// Delete the dummy voice context. See setVoiceBank()
|
|
|
|
delete _voiceContext;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-09-10 13:17:20 +00:00
|
|
|
void SndRes::setVoiceBank(int serial) {
|
2009-12-04 17:52:42 +00:00
|
|
|
Common::File *file;
|
2008-02-27 18:17:50 +00:00
|
|
|
if (_voiceSerial == serial)
|
|
|
|
return;
|
|
|
|
|
2009-01-02 19:10:51 +00:00
|
|
|
#ifdef ENABLE_IHNM
|
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
|
2009-12-04 17:52:42 +00:00
|
|
|
_voiceContext = new VoiceResourceContext_RES();
|
2008-04-05 13:19:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-01-02 19:10:51 +00:00
|
|
|
#endif
|
2008-04-05 13:19:12 +00:00
|
|
|
|
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
|
2009-12-04 17:52:42 +00:00
|
|
|
if (_voiceContext != NULL) {
|
|
|
|
file = _voiceContext->getFile(NULL);
|
|
|
|
if (file->isOpen()) {
|
|
|
|
file->close();
|
|
|
|
}
|
|
|
|
}
|
2008-01-27 14:32:08 +00:00
|
|
|
|
2005-07-26 19:40:58 +00:00
|
|
|
_voiceSerial = serial;
|
|
|
|
|
|
|
|
_voiceContext = _vm->_resource->getContext(GAME_VOICEFILE, _voiceSerial);
|
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
|
|
|
}
|
|
|
|
|
2010-06-15 10:25:34 +00:00
|
|
|
_vm->_sound->playSound(buffer, volume, loop, resourceId);
|
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
|
|
|
}
|
|
|
|
|
2011-12-24 00:26:25 +00:00
|
|
|
enum GameSoundType {
|
|
|
|
kSoundPCM = 0,
|
|
|
|
kSoundVOX = 1,
|
|
|
|
kSoundVOC = 2,
|
|
|
|
kSoundWAV = 3,
|
|
|
|
kSoundMP3 = 4,
|
|
|
|
kSoundOGG = 5,
|
|
|
|
kSoundFLAC = 6,
|
|
|
|
kSoundAIFF = 7,
|
|
|
|
kSoundShorten = 8,
|
|
|
|
kSoundMacSND = 9
|
|
|
|
};
|
|
|
|
|
|
|
|
// Use a macro to read in the sound data based on if we actually want to buffer it or not
|
|
|
|
#define READ_STREAM(streamSize) \
|
|
|
|
(onlyHeader \
|
|
|
|
? new Common::SeekableSubReadStream(&readS, readS.pos(), readS.pos() + (streamSize)) \
|
|
|
|
: readS.readStream(streamSize))
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buffer, bool onlyHeader) {
|
|
|
|
size_t soundResourceLength;
|
|
|
|
bool result = false;
|
2011-12-24 00:26:25 +00:00
|
|
|
GameSoundType resourceType = kSoundPCM;
|
2009-01-17 21:17:58 +00:00
|
|
|
int rate = 0, size = 0;
|
2011-12-23 04:48:18 +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
|
|
|
|
2009-01-02 19:10:51 +00:00
|
|
|
#ifdef ENABLE_IHNM
|
2009-12-04 17:52:42 +00:00
|
|
|
//TODO: move to resource_res so we can use normal "getResourceData" and "getFile" methods
|
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
|
|
|
|
2009-12-04 17:52:42 +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();
|
2009-05-24 15:17:42 +00:00
|
|
|
} else
|
2009-01-02 19:10:51 +00:00
|
|
|
#endif
|
|
|
|
{
|
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
|
|
|
|
2011-12-24 00:26:25 +00:00
|
|
|
Common::SeekableReadStream &readS = *file;
|
2010-10-02 09:08:05 +00:00
|
|
|
bool uncompressedSound = false;
|
2008-09-09 07:05:47 +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;
|
2013-07-02 00:32:34 +00:00
|
|
|
} else if (!memcmp(header, "RIFF", 4)) {
|
2005-07-26 19:40:58 +00:00
|
|
|
resourceType = kSoundWAV;
|
2013-07-02 00:32:34 +00:00
|
|
|
} else if (!memcmp(header, "FORM", 4)) {
|
2008-04-05 12:36:52 +00:00
|
|
|
resourceType = kSoundAIFF;
|
2013-07-02 00:32:34 +00:00
|
|
|
} else if (!memcmp(header, "ajkg", 4)) {
|
2008-12-29 18:35:18 +00:00
|
|
|
resourceType = kSoundShorten;
|
2008-01-27 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
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
|
2009-12-04 17:52:42 +00:00
|
|
|
if (_vm->getGameId() == GID_ITE && resourceId == 4 && context->getResourceData(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
|
2009-12-04 17:52:42 +00:00
|
|
|
if (_vm->getGameId() == GID_IHNM && (context->fileType() & GAME_SOUNDFILE))
|
2007-08-01 14:19:55 +00:00
|
|
|
uncompressedSound = true;
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
if (context->isCompressed() && !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
|
|
|
}
|
|
|
|
|
2011-12-24 00:26:25 +00:00
|
|
|
// Default sound type is 16-bit signed PCM, used in ITE
|
|
|
|
byte rawFlags = Audio::FLAG_16BITS;
|
|
|
|
|
2009-01-04 15:44:33 +00:00
|
|
|
if (_vm->getGameId() == GID_ITE) {
|
2011-12-23 04:48:18 +00:00
|
|
|
if (context->fileType() & GAME_MACBINARY) {
|
|
|
|
// ITE Mac has sound in the Mac snd format
|
|
|
|
resourceType = kSoundMacSND;
|
|
|
|
} else if (_vm->getFeatures() & GF_8BIT_UNSIGNED_PCM) { // older ITE demos
|
2011-12-24 00:26:25 +00:00
|
|
|
rawFlags |= Audio::FLAG_UNSIGNED;
|
|
|
|
rawFlags &= ~Audio::FLAG_16BITS;
|
|
|
|
} else if (!uncompressedSound && !scumm_stricmp(context->fileName(), "voicesd.rsc")) {
|
2011-07-09 12:59:30 +00:00
|
|
|
// Voice files in newer ITE demo versions are OKI ADPCM (VOX) encoded.
|
2011-12-24 00:26:25 +00:00
|
|
|
resourceType = kSoundVOX;
|
2009-01-04 15:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-24 00:26:25 +00:00
|
|
|
|
|
|
|
buffer.stream = 0;
|
2009-01-01 16:02:43 +00:00
|
|
|
|
2009-08-17 11:49:07 +00:00
|
|
|
// Check for LE sounds
|
2009-12-04 17:52:42 +00:00
|
|
|
if (!context->isBigEndian())
|
2011-12-24 00:26:25 +00:00
|
|
|
rawFlags |= Audio::FLAG_LITTLE_ENDIAN;
|
2009-08-17 11:49:07 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
switch (resourceType) {
|
2011-12-24 00:26:25 +00:00
|
|
|
case kSoundPCM: {
|
|
|
|
// In ITE CD German, some voices are absent and contain just 5 zero bytes.
|
|
|
|
// Round down to an even number when the audio is 16-bit so makeRawStream
|
|
|
|
// will accept the data (needs to be an even size for 16-bit data).
|
|
|
|
// See bug #1256701
|
|
|
|
|
|
|
|
if ((soundResourceLength & 1) && (rawFlags & Audio::FLAG_16BITS))
|
|
|
|
soundResourceLength &= ~1;
|
|
|
|
|
|
|
|
Audio::SeekableAudioStream *audStream = Audio::makeRawStream(READ_STREAM(soundResourceLength), 22050, rawFlags);
|
|
|
|
buffer.stream = audStream;
|
|
|
|
buffer.streamLength = audStream->getLength();
|
2005-08-04 10:23:49 +00:00
|
|
|
result = true;
|
2011-12-24 00:26:25 +00:00
|
|
|
} break;
|
2005-07-26 19:40:58 +00:00
|
|
|
case kSoundVOX:
|
2011-12-24 00:26:25 +00:00
|
|
|
buffer.stream = Audio::makeADPCMStream(READ_STREAM(soundResourceLength), DisposeAfterUse::YES, soundResourceLength, Audio::kADPCMOki, 22050, 1);
|
|
|
|
buffer.streamLength = Audio::Timestamp(0, soundResourceLength * 2, buffer.stream->getRate());
|
2005-07-19 19:05:52 +00:00
|
|
|
result = true;
|
2004-04-12 21:40:49 +00:00
|
|
|
break;
|
2011-12-23 04:48:18 +00:00
|
|
|
case kSoundMacSND: {
|
2011-12-24 00:26:25 +00:00
|
|
|
Audio::SeekableAudioStream *audStream = Audio::makeMacSndStream(READ_STREAM(soundResourceLength), DisposeAfterUse::YES);
|
|
|
|
buffer.stream = audStream;
|
|
|
|
buffer.streamLength = audStream->getLength();
|
|
|
|
result = true;
|
|
|
|
} break;
|
|
|
|
case kSoundAIFF: {
|
|
|
|
Audio::SeekableAudioStream *audStream = Audio::makeAIFFStream(READ_STREAM(soundResourceLength), DisposeAfterUse::YES);
|
|
|
|
buffer.stream = audStream;
|
|
|
|
buffer.streamLength = audStream->getLength();
|
|
|
|
result = true;
|
|
|
|
} break;
|
|
|
|
case kSoundVOC: {
|
|
|
|
Audio::SeekableAudioStream *audStream = Audio::makeVOCStream(READ_STREAM(soundResourceLength), Audio::FLAG_UNSIGNED, DisposeAfterUse::YES);
|
|
|
|
buffer.stream = audStream;
|
|
|
|
buffer.streamLength = audStream->getLength();
|
2011-12-23 04:48:18 +00:00
|
|
|
result = true;
|
|
|
|
} break;
|
2005-07-26 19:40:58 +00:00
|
|
|
case kSoundWAV:
|
2008-12-29 18:35:18 +00:00
|
|
|
case kSoundShorten:
|
2009-01-01 16:02:43 +00:00
|
|
|
if (resourceType == kSoundWAV) {
|
2011-12-24 00:26:25 +00:00
|
|
|
result = Audio::loadWAVFromStream(readS, size, rate, rawFlags);
|
2009-08-17 11:49:07 +00:00
|
|
|
#ifdef ENABLE_SAGA2
|
|
|
|
} else if (resourceType == kSoundShorten) {
|
2011-12-24 00:26:25 +00:00
|
|
|
result = loadShortenFromStream(readS, size, rate, rawFlags);
|
2009-08-17 11:49:07 +00:00
|
|
|
#endif
|
2009-01-01 16:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (result) {
|
2011-12-24 00:26:25 +00:00
|
|
|
Audio::SeekableAudioStream *audStream = Audio::makeRawStream(READ_STREAM(size), rate, rawFlags);
|
|
|
|
buffer.stream = audStream;
|
|
|
|
buffer.streamLength = audStream->getLength();
|
2008-12-29 18:35:18 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-06-25 18:23:01 +00:00
|
|
|
case kSoundMP3:
|
|
|
|
case kSoundOGG:
|
2011-12-24 00:26:25 +00:00
|
|
|
case kSoundFLAC: {
|
|
|
|
readS.skip(9); // skip sfx header
|
|
|
|
|
|
|
|
Audio::SeekableAudioStream *audStream = 0;
|
|
|
|
Common::SeekableReadStream *memStream = READ_STREAM(soundResourceLength - 9);
|
|
|
|
|
|
|
|
if (resourceType == kSoundMP3) {
|
|
|
|
#ifdef USE_MAD
|
|
|
|
audStream = Audio::makeMP3Stream(memStream, DisposeAfterUse::YES);
|
|
|
|
#endif
|
|
|
|
} else if (resourceType == kSoundOGG) {
|
|
|
|
#ifdef USE_VORBIS
|
|
|
|
audStream = Audio::makeVorbisStream(memStream, DisposeAfterUse::YES);
|
|
|
|
#endif
|
|
|
|
} else /* if (resourceType == kSoundFLAC) */ {
|
|
|
|
#ifdef USE_FLAC
|
|
|
|
audStream = Audio::makeFLACStream(memStream, DisposeAfterUse::YES);
|
|
|
|
#endif
|
2009-08-17 11:06:27 +00:00
|
|
|
}
|
|
|
|
|
2011-12-24 00:26:25 +00:00
|
|
|
if (audStream) {
|
|
|
|
buffer.stream = audStream;
|
|
|
|
buffer.streamLength = audStream->getLength();
|
|
|
|
result = true;
|
|
|
|
} else {
|
|
|
|
delete memStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
} 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-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_IHNM && _vm->isMacResources()) {
|
2008-09-09 07:05:47 +00:00
|
|
|
delete file;
|
|
|
|
}
|
|
|
|
|
2011-12-24 00:26:25 +00:00
|
|
|
if (onlyHeader) {
|
|
|
|
delete buffer.stream;
|
|
|
|
buffer.stream = 0;
|
|
|
|
}
|
2005-08-11 15:04:12 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
return result;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2011-12-24 00:26:25 +00:00
|
|
|
#undef READ_STREAM
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
int SndRes::getVoiceLength(uint32 resourceId) {
|
|
|
|
SoundBuffer buffer;
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2007-12-23 02:33:58 +00:00
|
|
|
if (!(_vm->_voiceFilesExist))
|
|
|
|
return -1;
|
|
|
|
|
2011-12-24 00:26:25 +00:00
|
|
|
if (!load(_voiceContext, resourceId, buffer, true))
|
2005-07-19 19:05:52 +00:00
|
|
|
return -1;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2011-12-24 00:26:25 +00:00
|
|
|
return buffer.streamLength.msecs();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|