2001-10-09 14:30:12 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2004-01-06 12:45:34 +00:00
|
|
|
* Copyright (C) 2001-2004 The ScummVM project
|
2001-10-09 14:30:12 +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.
|
2002-08-08 21:54:49 +00:00
|
|
|
|
2001-10-09 14:30:12 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
2001-11-06 20:00:47 +00:00
|
|
|
* $Header$
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2003-10-03 18:33:57 +00:00
|
|
|
#include "scumm/actor.h"
|
|
|
|
#include "scumm/imuse.h"
|
2004-01-06 17:28:29 +00:00
|
|
|
#include "scumm/imuse_digi/dimuse.h"
|
2003-10-03 18:33:57 +00:00
|
|
|
#include "scumm/scumm.h"
|
|
|
|
#include "scumm/sound.h"
|
2003-09-07 20:30:02 +00:00
|
|
|
|
2003-10-08 21:59:23 +00:00
|
|
|
#include "common/config-manager.h"
|
2003-06-15 01:42:19 +00:00
|
|
|
#include "common/timer.h"
|
2002-09-13 12:20:55 +00:00
|
|
|
#include "common/util.h"
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2003-11-29 12:11:01 +00:00
|
|
|
#include "sound/audiocd.h"
|
2003-09-07 20:30:02 +00:00
|
|
|
#include "sound/mididrv.h"
|
|
|
|
#include "sound/mixer.h"
|
2004-01-03 00:55:40 +00:00
|
|
|
#include "sound/mp3.h"
|
2003-09-07 20:30:02 +00:00
|
|
|
#include "sound/voc.h"
|
2004-01-03 00:55:40 +00:00
|
|
|
#include "sound/vorbis.h"
|
2004-04-11 22:20:41 +00:00
|
|
|
#include "sound/flac.h"
|
2003-05-19 05:04:38 +00:00
|
|
|
|
2003-06-15 00:54:14 +00:00
|
|
|
|
2003-10-03 18:33:57 +00:00
|
|
|
namespace Scumm {
|
|
|
|
|
2003-09-15 19:48:54 +00:00
|
|
|
struct MP3OffsetTable { /* Compressed Sound (.SO3) */
|
|
|
|
int org_offset;
|
|
|
|
int new_offset;
|
|
|
|
int num_tags;
|
|
|
|
int compressed_size;
|
|
|
|
};
|
2003-06-15 00:54:14 +00:00
|
|
|
|
|
|
|
|
2004-04-11 22:20:41 +00:00
|
|
|
Sound::Sound(ScummEngine *parent)
|
|
|
|
:
|
|
|
|
_vm(parent),
|
|
|
|
_soundQuePos(0),
|
|
|
|
_soundQue2Pos(0),
|
|
|
|
_sfxFile(0),
|
|
|
|
_offsetTable(0),
|
|
|
|
_numSoundEffects(0),
|
|
|
|
_soundMode(kVOCMode),
|
|
|
|
_talk_sound_a1(0),
|
|
|
|
_talk_sound_a2(0),
|
|
|
|
_talk_sound_b1(0),
|
|
|
|
_talk_sound_b2(0),
|
|
|
|
_talk_sound_mode(0),
|
|
|
|
_talk_sound_frame(0),
|
|
|
|
_mouthSyncMode(false),
|
|
|
|
_endOfMouthSync(false),
|
|
|
|
_curSoundPos(0),
|
|
|
|
_currentCDSound(0),
|
|
|
|
_soundsPaused(false),
|
|
|
|
_sfxMode(0) {
|
2003-04-30 13:23:31 +00:00
|
|
|
|
2004-04-11 22:20:41 +00:00
|
|
|
memset(_soundQue, 0, sizeof(_soundQue));
|
|
|
|
memset(_soundQue2, 0, sizeof(_soundQue2));
|
|
|
|
memset(_mouthSyncTimes, 0, sizeof(_mouthSyncTimes));
|
2002-08-14 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sound::~Sound() {
|
2003-12-27 21:33:34 +00:00
|
|
|
stopCDTimer();
|
2003-06-26 23:04:41 +00:00
|
|
|
delete _sfxFile;
|
2002-08-14 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::addSoundToQueue(int sound) {
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->VAR(_vm->VAR_LAST_SOUND) = sound;
|
|
|
|
_vm->ensureResourceLoaded(rtSound, sound);
|
2003-12-25 11:14:05 +00:00
|
|
|
addSoundToQueue2(sound);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::addSoundToQueue2(int sound) {
|
2004-02-14 04:12:22 +00:00
|
|
|
if ((_vm->_features & GF_HUMONGOUS) && _soundQue2Pos) {
|
|
|
|
int i = _soundQue2Pos;
|
|
|
|
while (i--) {
|
|
|
|
if (_soundQue2[i] == sound)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-27 20:31:19 +00:00
|
|
|
assert(_soundQue2Pos < ARRAYSIZE(_soundQue2));
|
|
|
|
_soundQue2[_soundQue2Pos++] = sound;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::processSoundQues() {
|
2003-07-14 22:24:18 +00:00
|
|
|
int i = 0, d, num;
|
2003-08-06 18:20:15 +00:00
|
|
|
int data[16];
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2003-12-25 14:01:38 +00:00
|
|
|
processSfxQueues();
|
2003-12-25 13:56:22 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_features & GF_DIGI_IMUSE)
|
2003-12-25 13:56:22 +00:00
|
|
|
return;
|
2001-10-09 14:30:12 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
while (_soundQue2Pos) {
|
|
|
|
d = _soundQue2[--_soundQue2Pos];
|
2001-10-09 14:30:12 +00:00
|
|
|
if (d)
|
|
|
|
playSound(d);
|
|
|
|
}
|
|
|
|
|
2003-07-14 22:24:18 +00:00
|
|
|
while (i < _soundQuePos) {
|
2001-10-09 14:30:12 +00:00
|
|
|
num = _soundQue[i++];
|
2001-11-05 19:21:49 +00:00
|
|
|
if (i + num > _soundQuePos) {
|
|
|
|
warning("processSoundQues: invalid num value");
|
|
|
|
break;
|
|
|
|
}
|
2003-03-18 16:13:52 +00:00
|
|
|
memset(data, 0, sizeof(data));
|
2002-04-11 17:19:16 +00:00
|
|
|
if (num > 0) {
|
2003-03-18 16:13:52 +00:00
|
|
|
for (int j = 0; j < num; j++)
|
2002-04-11 17:19:16 +00:00
|
|
|
data[j] = _soundQue[i + j];
|
2001-10-09 14:30:12 +00:00
|
|
|
i += num;
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_IMUSE, "processSoundQues(%d,%d,%d,%d,%d,%d,%d,%d,%d)",
|
2003-12-25 11:14:05 +00:00
|
|
|
data[0] >> 8, data[0] & 0xFF,
|
|
|
|
data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuse) {
|
|
|
|
_vm->VAR(_vm->VAR_SOUNDRESULT) = (short)_vm->_imuse->doCommand (num, data);
|
2002-03-06 00:18:22 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_soundQuePos = 0;
|
|
|
|
}
|
|
|
|
|
2002-10-23 00:24:43 +00:00
|
|
|
void Sound::playSound(int soundID) {
|
2002-03-16 05:33:25 +00:00
|
|
|
byte *ptr;
|
2002-10-23 00:24:43 +00:00
|
|
|
char *sound;
|
2004-04-24 20:57:42 +00:00
|
|
|
int size = -1;
|
2002-09-09 11:15:44 +00:00
|
|
|
int rate;
|
2003-03-18 22:07:49 +00:00
|
|
|
byte flags = SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE;
|
2002-08-20 09:58:35 +00:00
|
|
|
|
2004-01-10 11:01:47 +00:00
|
|
|
debugC(DEBUG_SOUND, "playSound #%d (room %d)", soundID,
|
|
|
|
_vm->getResourceRoomNr(rtSound, soundID));
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
ptr = _vm->getResourceAddress(rtSound, soundID);
|
2003-09-07 00:03:55 +00:00
|
|
|
if (!ptr) {
|
|
|
|
return;
|
|
|
|
}
|
2003-09-07 16:16:19 +00:00
|
|
|
|
2003-09-07 00:03:55 +00:00
|
|
|
// Support for SFX in Monkey Island 1, Mac version
|
|
|
|
// This is rather hackish right now, but works OK. SFX are not sounding
|
|
|
|
// 100% correct, though, not sure right now what is causing this.
|
|
|
|
else if (READ_UINT32(ptr) == MKID('Mac1')) {
|
|
|
|
|
|
|
|
// Read info from the header
|
|
|
|
size = READ_BE_UINT32(ptr+0x60);
|
2003-09-07 20:30:02 +00:00
|
|
|
rate = READ_BE_UINT16(ptr+0x64);
|
2003-09-07 00:03:55 +00:00
|
|
|
|
|
|
|
// Skip over the header (fixed size)
|
|
|
|
ptr += 0x72;
|
|
|
|
|
|
|
|
// Allocate a sound buffer, copy the data into it, and play
|
|
|
|
sound = (char *)malloc(size);
|
|
|
|
memcpy(sound, ptr, size);
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_mixer->playRaw(NULL, sound, size, rate, flags, soundID);
|
2003-09-07 00:03:55 +00:00
|
|
|
}
|
|
|
|
// Support for Putt-Putt sounds - very hackish, too 8-)
|
|
|
|
else if (READ_UINT32(ptr) == MKID('DIGI')) {
|
|
|
|
// TODO - discover what data the first chunk, HSHD, contains
|
|
|
|
// it might be useful here.
|
|
|
|
ptr += 8 + READ_BE_UINT32(ptr+12);
|
|
|
|
if (READ_UINT32(ptr) != MKID('SDAT'))
|
|
|
|
return; // abort
|
|
|
|
|
|
|
|
size = READ_BE_UINT32(ptr+4) - 8;
|
|
|
|
// FIXME - what value here ?!? 11025 is just a guess based on strings in w32 bin, prev guess 8000
|
|
|
|
rate = 11025;
|
|
|
|
|
|
|
|
// Allocate a sound buffer, copy the data into it, and play
|
|
|
|
sound = (char *)malloc(size);
|
|
|
|
memcpy(sound, ptr + 8, size);
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_mixer->playRaw(NULL, sound, size, rate, flags, soundID);
|
2003-09-07 00:03:55 +00:00
|
|
|
}
|
|
|
|
else if (READ_UINT32(ptr) == MKID('MRAW')) {
|
|
|
|
// pcm music in 3DO humongous games
|
|
|
|
// TODO play via imuse so isSoundRunning can properly report music value?
|
|
|
|
ptr += 8 + READ_BE_UINT32(ptr+12);
|
|
|
|
if (READ_UINT32(ptr) != MKID('SDAT'))
|
2002-08-29 23:45:15 +00:00
|
|
|
return;
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2003-09-07 00:03:55 +00:00
|
|
|
size = READ_BE_UINT32(ptr+4) - 8;
|
|
|
|
rate = 22050;
|
|
|
|
flags = SoundMixer::FLAG_AUTOFREE;
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2003-09-07 00:03:55 +00:00
|
|
|
// Allocate a sound buffer, copy the data into it, and play
|
|
|
|
sound = (char *)malloc(size);
|
|
|
|
memcpy(sound, ptr + 8, size);
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_mixer->playRaw(NULL, sound, size, rate, flags, soundID);
|
2003-09-07 00:03:55 +00:00
|
|
|
}
|
|
|
|
// Support for sampled sound effects in Monkey Island 1 and 2
|
|
|
|
else if (READ_UINT32(ptr) == MKID('SBL ')) {
|
|
|
|
debug(2, "Using SBL sound effect");
|
2003-09-07 20:30:02 +00:00
|
|
|
|
|
|
|
// SBL resources essentially contain VOC sound data.
|
|
|
|
// There are at least two main variants: in one,
|
|
|
|
// there are two subchunks AUhd and AUdt, in the other
|
|
|
|
// the chunks are called WVhd and WVdt. Besides that,
|
|
|
|
// the two variants seem pretty similiar.
|
|
|
|
|
|
|
|
// The first subchunk (AUhd resp. WVhd) seems to always
|
|
|
|
// contain three bytes (00 00 80) of unknown meaning.
|
|
|
|
// After that, a second subchunk contains VOC data.
|
|
|
|
// Two real examples:
|
2003-09-07 00:03:55 +00:00
|
|
|
//
|
|
|
|
// 53 42 4c 20 00 00 11 ae |SBL ....|
|
|
|
|
// 41 55 68 64 00 00 00 03 |AUhd....|
|
|
|
|
// 00 00 80 41 55 64 74 00 |...AUdt.|
|
|
|
|
// 00 11 9b 01 96 11 00 a6 |........|
|
|
|
|
// 00 7f 7f 7e 7e 7e 7e 7e |...~~~~~|
|
|
|
|
// 7e 7f 7f 80 80 7f 7f 7f |~.......|
|
|
|
|
// 7f 80 80 7f 7e 7d 7d 7e |....~}}~|
|
|
|
|
// 7e 7e 7e 7e 7e 7e 7e 7f |~~~~~~~.|
|
|
|
|
//
|
2003-09-07 20:30:02 +00:00
|
|
|
// And from the non-interactive Sam & Max demo:
|
2003-09-07 00:03:55 +00:00
|
|
|
//
|
|
|
|
// 53 42 4c 20 00 01 15 6e |SBL ...n|
|
|
|
|
// 57 56 68 64 00 00 00 03 |WVhd....|
|
|
|
|
// 00 00 80 57 56 64 74 00 |...WVdt.|
|
|
|
|
// 01 15 5b 01 56 15 01 a6 |..[.V...|
|
|
|
|
// 00 80 80 80 80 80 80 80 |........|
|
|
|
|
// 80 80 80 80 80 80 80 80 |........|
|
|
|
|
// 80 80 80 80 80 80 80 80 |........|
|
|
|
|
// 80 80 80 80 80 80 80 80 |........|
|
|
|
|
|
2004-04-24 20:57:42 +00:00
|
|
|
size = READ_BE_UINT32(ptr + 4) - 27;
|
|
|
|
ptr += 27;
|
|
|
|
|
2003-09-07 20:53:05 +00:00
|
|
|
// Fingolfin says: after eyeballing a single SEGA
|
|
|
|
// SBL resource, it would seem as if the content of the
|
|
|
|
// data subchunk (AUdt) is XORed with 0x16. At least
|
|
|
|
// then a semi-sane VOC header is revealed, with
|
|
|
|
// a sampling rate of ~25000 Hz (does that make sense?).
|
|
|
|
// I'll add some code to test that theory for now.
|
2004-06-05 12:02:36 +00:00
|
|
|
|
|
|
|
// Check if the resource has already been demangled
|
|
|
|
if ((_vm->_gameId == GID_MONKEY_SEGA) && (ptr[0] != 1)) {
|
2004-04-24 20:57:42 +00:00
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
ptr[i] ^= 0x16;
|
|
|
|
if (ptr[i] >= 0x7F) {
|
|
|
|
ptr[i] = 0xFE - ptr[i];
|
|
|
|
ptr[i] ^= 0x80;
|
|
|
|
}
|
|
|
|
}
|
2003-09-07 20:53:05 +00:00
|
|
|
}
|
2004-04-24 20:57:42 +00:00
|
|
|
|
|
|
|
// TODO: It would be nice if we could use readVOCFromMemory() here.
|
|
|
|
// We'd have to add the 'Creative Voice File' header for this, though,
|
|
|
|
// or make readVOCFromMemory() less strict.
|
2003-09-07 20:53:05 +00:00
|
|
|
|
2004-04-24 20:57:42 +00:00
|
|
|
VocBlockHeader &voc_block_hdr = *(VocBlockHeader *)ptr;
|
2003-09-07 20:53:05 +00:00
|
|
|
assert(voc_block_hdr.blocktype == 1);
|
|
|
|
size = voc_block_hdr.size[0] + (voc_block_hdr.size[1] << 8) + (voc_block_hdr.size[2] << 16) - 2;
|
|
|
|
rate = getSampleRateFromVOCRate(voc_block_hdr.sr);
|
|
|
|
assert(voc_block_hdr.pack == 0);
|
2002-10-03 09:16:14 +00:00
|
|
|
|
2003-09-07 00:03:55 +00:00
|
|
|
// Allocate a sound buffer, copy the data into it, and play
|
|
|
|
sound = (char *)malloc(size);
|
2004-04-24 20:57:42 +00:00
|
|
|
memcpy(sound, ptr + 6, size);
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_mixer->playRaw(NULL, sound, size, rate, flags, soundID);
|
2003-09-07 16:32:23 +00:00
|
|
|
}
|
2004-01-08 20:37:26 +00:00
|
|
|
else if ((_vm->_features & GF_FMTOWNS) || READ_UINT32(ptr) == MKID('SOUN') || READ_UINT32(ptr) == MKID('TOWS')) {
|
2003-12-13 20:01:35 +00:00
|
|
|
|
2003-09-30 17:53:42 +00:00
|
|
|
bool tows = READ_UINT32(ptr) == MKID('TOWS');
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_features & GF_FMTOWNS) {
|
2003-09-30 17:53:42 +00:00
|
|
|
size = READ_LE_UINT32(ptr);
|
2003-12-13 20:01:35 +00:00
|
|
|
} else {
|
2003-09-30 17:53:42 +00:00
|
|
|
size = READ_BE_UINT32(ptr + 4) - 2;
|
|
|
|
if (tows)
|
|
|
|
size += 8;
|
|
|
|
ptr += 2;
|
|
|
|
}
|
2003-12-13 20:01:35 +00:00
|
|
|
|
2003-09-07 00:03:55 +00:00
|
|
|
rate = 11025;
|
|
|
|
int type = *(ptr + 0x0D);
|
2003-09-24 06:33:59 +00:00
|
|
|
int numInstruments;
|
|
|
|
|
2003-09-30 17:53:42 +00:00
|
|
|
if (tows)
|
|
|
|
type = 0;
|
2003-12-13 20:01:35 +00:00
|
|
|
|
2003-09-30 17:53:42 +00:00
|
|
|
switch (type) {
|
2003-09-24 06:33:59 +00:00
|
|
|
case 0: // Sound effect
|
|
|
|
numInstruments = *(ptr + 0x14);
|
2003-09-30 17:53:42 +00:00
|
|
|
if (tows)
|
|
|
|
numInstruments = 1;
|
2003-09-24 06:33:59 +00:00
|
|
|
ptr += 0x16;
|
|
|
|
size -= 0x16;
|
2003-12-13 20:01:35 +00:00
|
|
|
|
2003-09-24 06:33:59 +00:00
|
|
|
while (numInstruments--) {
|
|
|
|
int waveSize = READ_LE_UINT32(ptr + 0x0C);
|
2003-12-13 20:01:35 +00:00
|
|
|
int loopStart = READ_LE_UINT32(ptr + 0x10) * 2;
|
|
|
|
int loopEnd = READ_LE_UINT32(ptr + 0x14) - 1;
|
2003-10-07 03:58:29 +00:00
|
|
|
rate = READ_LE_UINT32(ptr + 0x18) * 1000 / 0x62;
|
2003-09-24 06:33:59 +00:00
|
|
|
ptr += 0x20;
|
|
|
|
size -= 0x20;
|
|
|
|
if (size < waveSize) {
|
|
|
|
warning("Wrong wave size in sound #%i: %i", soundID, waveSize);
|
|
|
|
waveSize = size;
|
2003-07-06 06:47:26 +00:00
|
|
|
}
|
2003-09-24 06:33:59 +00:00
|
|
|
sound = (char *)malloc(waveSize);
|
|
|
|
for (int x = 0; x < waveSize; x++) {
|
2003-12-13 20:01:35 +00:00
|
|
|
int b = *ptr++;
|
|
|
|
if (b < 0x80)
|
|
|
|
sound[x] = 0x7F - b;
|
2003-09-24 06:33:59 +00:00
|
|
|
else
|
2003-12-13 20:01:35 +00:00
|
|
|
sound[x] = b;
|
2003-09-24 06:33:59 +00:00
|
|
|
}
|
|
|
|
size -= waveSize;
|
2003-07-12 15:27:41 +00:00
|
|
|
|
2003-09-24 06:33:59 +00:00
|
|
|
if (loopEnd > 0)
|
|
|
|
flags |= SoundMixer::FLAG_LOOP;
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_mixer->playRaw(NULL, sound, waveSize, rate, flags, soundID, 255, 0, loopStart, loopEnd);
|
2003-07-04 14:10:44 +00:00
|
|
|
}
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2003-12-13 20:01:35 +00:00
|
|
|
case 255: // 255 is the type used in Indy3 FMTowns
|
2003-09-24 06:33:59 +00:00
|
|
|
// Music (Euphony format)
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_musicEngine)
|
|
|
|
_vm->_musicEngine->startSound(soundID);
|
2003-09-24 06:33:59 +00:00
|
|
|
break;
|
|
|
|
case 2: // CD track resource
|
|
|
|
ptr += 0x16;
|
|
|
|
|
|
|
|
if (soundID == _currentCDSound)
|
|
|
|
if (pollCD() == 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
{
|
2003-09-07 00:03:55 +00:00
|
|
|
int track = ptr[0];
|
|
|
|
int loops = ptr[1];
|
|
|
|
int start = (ptr[2] * 60 + ptr[3]) * 75 + ptr[4];
|
|
|
|
int end = (ptr[5] * 60 + ptr[6]) * 75 + ptr[7];
|
|
|
|
|
2003-09-30 17:53:42 +00:00
|
|
|
playCDTrack(track, loops == 0xff ? -1 : loops, start, end <= start ? 0 : end - start);
|
2003-09-24 06:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_currentCDSound = soundID;
|
|
|
|
break;
|
2003-12-13 20:01:35 +00:00
|
|
|
default: // Unsupported sound type
|
|
|
|
warning("Unsupported sound sub-type %d", type);
|
|
|
|
break;
|
2002-07-25 15:37:31 +00:00
|
|
|
}
|
|
|
|
}
|
2004-01-08 20:37:26 +00:00
|
|
|
else if ((_vm->_gameId == GID_LOOM) && (_vm->_features & GF_MACINTOSH)) {
|
2003-07-04 12:34:09 +00:00
|
|
|
// Mac version of Loom uses yet another sound format
|
|
|
|
/*
|
|
|
|
playSound #9 (room 70)
|
|
|
|
000000: 55 00 00 45 73 6f 00 64 01 00 00 00 00 00 00 00 |U..Eso.d........|
|
|
|
|
000010: 00 05 00 8e 2a 8f 2d 1c 2a 8f 2a 8f 2d 1c 00 28 |....*.-.*.*.-..(|
|
|
|
|
000020: 00 31 00 3a 00 43 00 4c 00 01 00 00 00 01 00 64 |.1.:.C.L.......d|
|
|
|
|
000030: 5a 00 01 00 00 00 01 00 64 00 00 01 00 00 00 01 |Z.......d.......|
|
|
|
|
000040: 00 64 5a 00 01 00 00 00 01 00 64 5a 00 01 00 00 |.dZ.......dZ....|
|
|
|
|
000050: 00 01 00 64 00 00 00 00 00 00 00 07 00 00 00 64 |...d...........d|
|
|
|
|
000060: 64 00 00 4e 73 6f 00 64 01 00 00 00 00 00 00 00 |d..Nso.d........|
|
|
|
|
000070: 00 05 00 89 3d 57 2d 1c 3d 57 3d 57 2d 1c 00 28 |....=W-.=W=W-..(|
|
|
|
|
playSound #16 (room 69)
|
|
|
|
000000: dc 00 00 a5 73 6f 00 64 01 00 00 00 00 00 00 00 |....so.d........|
|
|
|
|
000010: 00 05 00 00 2a 8f 03 e8 03 e8 03 e8 03 e8 00 28 |....*..........(|
|
|
|
|
000020: 00 79 00 7f 00 85 00 d6 00 01 00 00 00 19 01 18 |.y..............|
|
|
|
|
000030: 2f 00 18 00 01 18 32 00 18 00 01 18 36 00 18 00 |/.....2.....6...|
|
|
|
|
000040: 01 18 3b 00 18 00 01 18 3e 00 18 00 01 18 42 00 |..;.....>.....B.|
|
|
|
|
000050: 18 00 01 18 47 00 18 00 01 18 4a 00 18 00 01 18 |....G.....J.....|
|
|
|
|
000060: 4e 00 10 00 01 18 53 00 10 00 01 18 56 00 10 00 |N.....S.....V...|
|
|
|
|
000070: 01 18 5a 00 10 00 02 28 5f 00 01 00 00 00 00 00 |..Z....(_.......|
|
|
|
|
*/
|
|
|
|
}
|
2004-01-08 20:37:26 +00:00
|
|
|
else if ((_vm->_features & GF_MACINTOSH) && (_vm->_gameId == GID_INDY3) && (ptr[26] == 0)) {
|
2003-09-07 16:32:23 +00:00
|
|
|
size = READ_BE_UINT16(ptr + 12);
|
|
|
|
rate = 3579545 / READ_BE_UINT16(ptr + 20);
|
|
|
|
sound = (char *)malloc(size);
|
|
|
|
int vol = ptr[24] * 4;
|
|
|
|
memcpy(sound,ptr + READ_BE_UINT16(ptr + 8), size);
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_mixer->playRaw(NULL, sound, size, rate, SoundMixer::FLAG_AUTOFREE, soundID, vol, 0);
|
2003-07-15 07:29:23 +00:00
|
|
|
}
|
2003-09-07 20:30:02 +00:00
|
|
|
else {
|
|
|
|
|
2004-04-11 12:31:46 +00:00
|
|
|
if (_vm->_gameId == GID_MONKEY_VGA || _vm->_gameId == GID_MONKEY_EGA
|
|
|
|
|| (_vm->_gameId == GID_MONKEY && _vm->_features & GF_MACINTOSH)) {
|
2003-09-07 20:30:02 +00:00
|
|
|
// Sound is currently not supported at all in the amiga versions of these games
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_features & GF_AMIGA) {
|
2003-12-29 08:19:57 +00:00
|
|
|
int track = -1;
|
|
|
|
if (soundID == 50)
|
|
|
|
track = 17;
|
2004-04-17 07:22:02 +00:00
|
|
|
else if (ptr[6] == 0x7F && ptr[7] == 0x00 && ptr[8] == 0x80)
|
|
|
|
{
|
|
|
|
char tracks[16] = {13,14,10,3,4,9,16,5,1,8,2,15,6,7,11,12};
|
|
|
|
if (ptr[9] == 0x0E)
|
|
|
|
track = 18;
|
|
|
|
else track = tracks[ptr[9] - 0x23];
|
2003-12-29 08:19:57 +00:00
|
|
|
}
|
|
|
|
if (track != -1) {
|
|
|
|
playCDTrack(track,((track < 5) || (track > 16)) ? 1 : -1,0,0);
|
|
|
|
stopCDTimer();
|
|
|
|
_currentCDSound = soundID;
|
|
|
|
}
|
2003-09-07 20:30:02 +00:00
|
|
|
return;
|
2003-12-29 08:19:57 +00:00
|
|
|
}
|
2003-09-07 16:32:23 +00:00
|
|
|
|
2003-09-07 20:30:02 +00:00
|
|
|
// Works around the fact that in some places in MonkeyEGA/VGA,
|
|
|
|
// the music is never explicitly stopped.
|
|
|
|
// Rather it seems that starting a new music is supposed to
|
|
|
|
// automatically stop the old song.
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuse) {
|
2003-09-07 20:30:02 +00:00
|
|
|
if (READ_UINT32(ptr) != MKID('ASFX'))
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_imuse->stopAllSounds();
|
2003-09-07 20:30:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_musicEngine) {
|
|
|
|
_vm->_musicEngine->startSound(soundID);
|
2003-08-14 09:27:33 +00:00
|
|
|
}
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::processSfxQueues() {
|
2001-11-05 19:21:49 +00:00
|
|
|
|
|
|
|
if (_talk_sound_mode != 0) {
|
2002-09-13 11:59:43 +00:00
|
|
|
if (_talk_sound_mode & 1)
|
|
|
|
startTalkSound(_talk_sound_a1, _talk_sound_b1, 1);
|
2004-01-15 20:39:24 +00:00
|
|
|
if (_talk_sound_mode & 2)
|
2003-07-14 21:37:45 +00:00
|
|
|
startTalkSound(_talk_sound_a2, _talk_sound_b2, 2, &_talkChannelHandle);
|
2001-11-05 19:21:49 +00:00
|
|
|
_talk_sound_mode = 0;
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2004-04-11 22:13:20 +00:00
|
|
|
const int act = _vm->getTalkingActor();
|
2004-01-15 20:39:24 +00:00
|
|
|
if ((_sfxMode & 2) && act != 0) {
|
|
|
|
Actor *a;
|
|
|
|
bool b, finished;
|
2003-07-15 20:51:18 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuseDigital) {
|
2003-12-26 13:13:56 +00:00
|
|
|
finished = !isSoundRunning(kTalkSoundID);
|
2003-12-26 12:15:23 +00:00
|
|
|
} else {
|
|
|
|
finished = !_talkChannelHandle.isActive();
|
|
|
|
}
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2004-01-15 20:39:24 +00:00
|
|
|
if ((uint) act < 0x80 && !_vm->_string[0].no_talk_anim && (finished || !_endOfMouthSync)) {
|
2004-01-08 20:37:26 +00:00
|
|
|
a = _vm->derefActor(act, "processSfxQueues");
|
2004-01-15 20:39:24 +00:00
|
|
|
if (a->isInCurrentRoom()) {
|
2003-12-23 19:18:20 +00:00
|
|
|
b = finished || isMouthSyncOff(_curSoundPos);
|
2001-11-05 19:21:49 +00:00
|
|
|
if (_mouthSyncMode != b) {
|
|
|
|
_mouthSyncMode = b;
|
2002-09-11 13:28:34 +00:00
|
|
|
if (_talk_sound_frame != -1) {
|
|
|
|
a->startAnimActor(_talk_sound_frame);
|
|
|
|
_talk_sound_frame = -1;
|
|
|
|
} else
|
2003-05-22 09:58:33 +00:00
|
|
|
a->startAnimActor(b ? a->talkStopFrame : a->talkStartFrame);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-11-08 21:59:32 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (finished && _vm->_talkDelay == 0) {
|
|
|
|
_vm->stopTalk();
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
2002-04-22 08:16:16 +00:00
|
|
|
}
|
2003-11-08 21:59:32 +00:00
|
|
|
|
2002-09-26 09:59:47 +00:00
|
|
|
if (_sfxMode & 1) {
|
2001-11-05 19:21:49 +00:00
|
|
|
if (isSfxFinished()) {
|
2002-09-26 09:59:47 +00:00
|
|
|
_sfxMode &= ~1;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-18 16:13:52 +00:00
|
|
|
static int compareMP3OffsetTable(const void *a, const void *b) {
|
2003-05-21 18:09:49 +00:00
|
|
|
return ((const MP3OffsetTable *)a)->org_offset - ((const MP3OffsetTable *)b)->org_offset;
|
2002-03-06 23:17:16 +00:00
|
|
|
}
|
|
|
|
|
2003-07-14 21:37:45 +00:00
|
|
|
void Sound::startTalkSound(uint32 offset, uint32 b, int mode, PlayingSoundHandle *handle) {
|
2002-03-06 23:17:16 +00:00
|
|
|
int num = 0, i;
|
2003-12-24 17:47:51 +00:00
|
|
|
int size = 0;
|
2003-03-06 17:58:13 +00:00
|
|
|
byte *sound;
|
2003-12-23 19:18:20 +00:00
|
|
|
int id = -1;
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2004-01-15 20:39:24 +00:00
|
|
|
if (_vm->_gameId == GID_CMI) {
|
|
|
|
_sfxMode |= mode;
|
|
|
|
return;
|
2004-01-20 00:21:24 +00:00
|
|
|
} else if (_vm->_gameId == GID_DIG) {
|
|
|
|
_sfxMode |= mode;
|
|
|
|
if (!(_vm->_features & GF_DEMO))
|
|
|
|
return;
|
2004-01-15 20:39:24 +00:00
|
|
|
|
2003-11-17 22:21:59 +00:00
|
|
|
char filename[30];
|
|
|
|
char roomname[10];
|
|
|
|
|
|
|
|
if (offset == 1)
|
|
|
|
strcpy(roomname, "logo");
|
|
|
|
else if (offset == 15)
|
|
|
|
strcpy(roomname, "canyon");
|
|
|
|
else if (offset == 17)
|
|
|
|
strcpy(roomname, "pig");
|
|
|
|
else if (offset == 18)
|
|
|
|
strcpy(roomname, "derelict");
|
|
|
|
else if (offset == 19)
|
|
|
|
strcpy(roomname, "wreck");
|
|
|
|
else if (offset == 20)
|
|
|
|
strcpy(roomname, "grave");
|
|
|
|
else if (offset == 23)
|
|
|
|
strcpy(roomname, "nexus");
|
|
|
|
else if (offset == 79)
|
|
|
|
strcpy(roomname, "newton");
|
|
|
|
else {
|
|
|
|
warning("startTalkSound: dig demo: unknown room number: %d", offset);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_sfxFile->close();
|
2003-11-17 22:52:21 +00:00
|
|
|
sprintf(filename, "audio/%s.%d/%d.voc", roomname, offset, b);
|
2003-11-17 22:21:59 +00:00
|
|
|
_sfxFile->open(filename);
|
|
|
|
if (!_sfxFile->isOpen()) {
|
2003-11-17 22:52:21 +00:00
|
|
|
sprintf(filename, "%d.%d.voc", offset, b);
|
|
|
|
_sfxFile->open(filename);
|
|
|
|
}
|
|
|
|
if (!_sfxFile->isOpen()) {
|
|
|
|
warning("startTalkSound: dig demo: voc file not found");
|
2003-11-17 22:21:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-12-24 17:47:51 +00:00
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-12-24 17:47:51 +00:00
|
|
|
if (!_sfxFile->isOpen()) {
|
|
|
|
warning("startTalkSound: SFX file is not open");
|
2003-07-14 21:37:45 +00:00
|
|
|
return;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
2003-12-26 12:15:23 +00:00
|
|
|
|
2003-12-24 17:47:51 +00:00
|
|
|
// FIXME hack until more is known
|
|
|
|
// the size of the data after the sample isn't known
|
|
|
|
// 64 is just a guess
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_features & GF_HUMONGOUS) {
|
2003-12-24 17:47:51 +00:00
|
|
|
// SKIP TLKB (8) TALK (8) HSHD (24) and SDAT (8)
|
2003-12-26 07:59:55 +00:00
|
|
|
_sfxMode |= mode;
|
2003-12-24 17:47:51 +00:00
|
|
|
_sfxFile->seek(offset + 48, SEEK_SET);
|
|
|
|
sound = (byte *)malloc(b - 64);
|
|
|
|
_sfxFile->read(sound, b - 64);
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_mixer->playRaw(handle, sound, b - 64, 11025, SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE);
|
2003-12-24 17:47:51 +00:00
|
|
|
return;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
2003-12-26 12:15:23 +00:00
|
|
|
|
2003-12-24 17:47:51 +00:00
|
|
|
// Some games frequently assume that starting one sound effect will
|
|
|
|
// automatically stop any other that may be playing at that time. So
|
|
|
|
// that is what we do here, but we make an exception for speech.
|
|
|
|
//
|
|
|
|
// Do any other games than these need this hack?
|
|
|
|
//
|
|
|
|
// HACK: Checking for script 99 in Sam & Max is to keep Conroy's song
|
|
|
|
// from being interrupted.
|
2003-12-26 12:15:23 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (mode == 1 && (_vm->_gameId == GID_TENTACLE
|
|
|
|
|| (_vm->_gameId == GID_SAMNMAX && !_vm->isScriptRunning(99)))) {
|
2003-12-24 17:47:51 +00:00
|
|
|
id = 777777;
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_mixer->stopID(id);
|
2003-12-24 17:47:51 +00:00
|
|
|
}
|
2003-12-26 12:15:23 +00:00
|
|
|
|
2003-12-24 17:47:51 +00:00
|
|
|
if (b > 8) {
|
|
|
|
num = (b - 8) >> 1;
|
|
|
|
}
|
2003-12-26 12:15:23 +00:00
|
|
|
|
2004-04-11 22:20:41 +00:00
|
|
|
if (_offsetTable != NULL) {
|
2003-12-24 17:47:51 +00:00
|
|
|
MP3OffsetTable *result = NULL, key;
|
|
|
|
|
|
|
|
key.org_offset = offset;
|
2004-04-11 22:20:41 +00:00
|
|
|
result = (MP3OffsetTable *)bsearch(&key, _offsetTable, _numSoundEffects,
|
2003-12-24 17:47:51 +00:00
|
|
|
sizeof(MP3OffsetTable), compareMP3OffsetTable);
|
2003-12-26 12:15:23 +00:00
|
|
|
|
2003-12-24 17:47:51 +00:00
|
|
|
if (result == NULL) {
|
|
|
|
warning("startTalkSound: did not find sound at offset %d !", offset);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (2 * num != result->num_tags) {
|
|
|
|
warning("startTalkSound: number of tags do not match (%d - %d) !", b,
|
|
|
|
result->num_tags);
|
|
|
|
num = result->num_tags;
|
|
|
|
}
|
|
|
|
offset = result->new_offset;
|
|
|
|
size = result->compressed_size;
|
|
|
|
} else {
|
|
|
|
offset += 8;
|
|
|
|
size = -1;
|
|
|
|
}
|
2003-12-26 12:15:23 +00:00
|
|
|
|
2003-12-24 17:47:51 +00:00
|
|
|
_sfxFile->seek(offset, SEEK_SET);
|
2003-12-26 12:15:23 +00:00
|
|
|
|
|
|
|
assert(num + 1 < (int)ARRAYSIZE(_mouthSyncTimes));
|
2003-12-24 17:47:51 +00:00
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
_mouthSyncTimes[i] = _sfxFile->readUint16BE();
|
|
|
|
|
|
|
|
_mouthSyncTimes[i] = 0xFFFF;
|
|
|
|
_sfxMode |= mode;
|
|
|
|
_curSoundPos = 0;
|
|
|
|
_mouthSyncMode = true;
|
2002-03-06 23:17:16 +00:00
|
|
|
}
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (!_soundsPaused && _vm->_mixer->isReady())
|
2003-12-27 15:22:59 +00:00
|
|
|
startSfxSound(_sfxFile, size, handle, id);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::stopTalkSound() {
|
2002-09-26 09:59:47 +00:00
|
|
|
if (_sfxMode & 2) {
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuseDigital) {
|
|
|
|
_vm->_imuseDigital->stopSound(kTalkSoundID);
|
2003-12-26 12:15:23 +00:00
|
|
|
} else {
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_mixer->stopHandle(_talkChannelHandle);
|
2003-12-26 12:15:23 +00:00
|
|
|
}
|
2002-09-26 09:59:47 +00:00
|
|
|
_sfxMode &= ~2;
|
2001-11-14 18:40:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
bool Sound::isMouthSyncOff(uint pos) {
|
2001-11-05 19:21:49 +00:00
|
|
|
uint j;
|
|
|
|
bool val = true;
|
|
|
|
uint16 *ms = _mouthSyncTimes;
|
|
|
|
|
|
|
|
_endOfMouthSync = false;
|
|
|
|
do {
|
2003-03-23 13:14:54 +00:00
|
|
|
val = !val;
|
2001-11-05 19:21:49 +00:00
|
|
|
j = *ms++;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (j == 0xFFFF) {
|
2001-11-05 19:21:49 +00:00
|
|
|
_endOfMouthSync = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (pos > j);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
int Sound::isSoundRunning(int sound) const {
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuseDigital)
|
|
|
|
return (_vm->_imuseDigital->getSoundStatus(sound) != 0);
|
2003-12-25 13:56:22 +00:00
|
|
|
|
2003-06-30 23:18:20 +00:00
|
|
|
if (sound == _currentCDSound)
|
2002-08-29 23:45:15 +00:00
|
|
|
return pollCD();
|
2003-11-08 21:59:32 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_features & GF_HUMONGOUS) {
|
2003-05-23 18:35:53 +00:00
|
|
|
if (sound == -2) {
|
|
|
|
return isSfxFinished();
|
|
|
|
} else if (sound == -1) {
|
|
|
|
// getSoundStatus(), with a -1, will return the
|
|
|
|
// ID number of the first active music it finds.
|
2003-07-06 15:02:13 +00:00
|
|
|
// TODO handle MRAW (pcm music) in humongous games
|
2004-01-08 20:37:26 +00:00
|
|
|
return _vm->_imuse->getSoundStatus(sound);
|
2003-05-23 18:35:53 +00:00
|
|
|
}
|
2003-05-19 08:04:47 +00:00
|
|
|
}
|
2003-11-08 21:59:32 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
if (isSoundInQueue(sound))
|
|
|
|
return 1;
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (!_vm->isResourceLoaded(rtSound, sound))
|
2001-11-05 19:21:49 +00:00
|
|
|
return 0;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_musicEngine)
|
|
|
|
return _vm->_musicEngine->getSoundStatus(sound);
|
2003-09-07 07:23:20 +00:00
|
|
|
|
2003-03-18 22:07:49 +00:00
|
|
|
return 0;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2003-09-07 17:14:56 +00:00
|
|
|
/**
|
|
|
|
* Check whether the sound resource with the specified ID is still
|
2003-10-02 22:42:03 +00:00
|
|
|
* used. This is invoked by ScummEngine::isResourceInUse, to determine
|
2003-09-07 17:14:56 +00:00
|
|
|
* which resources can be expired from memory.
|
|
|
|
* Technically, this works very similar to isSoundRunning, however it
|
|
|
|
* calls IMuse::get_sound_active() instead of IMuse::getSoundStatus().
|
|
|
|
* The difference between those two is in how they treat sounds which
|
|
|
|
* are being faded out: get_sound_active() returns true even when the
|
|
|
|
* sound is being faded out, while getSoundStatus() returns false in
|
|
|
|
* that case.
|
|
|
|
*/
|
|
|
|
bool Sound::isSoundInUse(int sound) const {
|
2002-12-05 21:45:55 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuseDigital)
|
|
|
|
return (_vm->_imuseDigital->getSoundStatus(sound) != 0);
|
2003-12-25 13:56:22 +00:00
|
|
|
|
2003-12-25 15:09:23 +00:00
|
|
|
if (sound == _currentCDSound)
|
|
|
|
return pollCD() != 0;
|
|
|
|
|
2002-12-05 21:45:55 +00:00
|
|
|
if (isSoundInQueue(sound))
|
|
|
|
return true;
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (!_vm->isResourceLoaded(rtSound, sound))
|
2002-12-05 21:45:55 +00:00
|
|
|
return false;
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuse)
|
|
|
|
return _vm->_imuse->get_sound_active(sound);
|
2003-09-07 17:14:56 +00:00
|
|
|
|
|
|
|
return false;
|
2002-12-05 21:45:55 +00:00
|
|
|
}
|
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
bool Sound::isSoundInQueue(int sound) const {
|
2003-12-25 15:09:23 +00:00
|
|
|
int i, num;
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2003-09-07 17:14:56 +00:00
|
|
|
i = _soundQue2Pos;
|
|
|
|
while (i--) {
|
|
|
|
if (_soundQue2[i] == sound)
|
2003-12-25 15:09:23 +00:00
|
|
|
return true;
|
2003-09-07 17:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
2001-11-05 19:21:49 +00:00
|
|
|
while (i < _soundQuePos) {
|
|
|
|
num = _soundQue[i++];
|
|
|
|
|
|
|
|
if (num > 0) {
|
2003-12-25 15:09:23 +00:00
|
|
|
if (_soundQue[i + 0] == 0x10F && _soundQue[i + 1] == 8 && _soundQue[i + 2] == sound)
|
|
|
|
return true;
|
2001-11-05 19:21:49 +00:00
|
|
|
i += num;
|
|
|
|
}
|
|
|
|
}
|
2003-12-25 15:09:23 +00:00
|
|
|
return false;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::stopSound(int a) {
|
2001-11-05 19:21:49 +00:00
|
|
|
int i;
|
|
|
|
|
2004-02-11 03:21:21 +00:00
|
|
|
if (_vm->_features & GF_HUMONGOUS) {
|
|
|
|
if (a == -2) {
|
|
|
|
// Stop current sfx
|
|
|
|
} else if (a == -1) {
|
|
|
|
// Stop current music
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-30 23:18:20 +00:00
|
|
|
if (a != 0 && a == _currentCDSound) {
|
|
|
|
_currentCDSound = 0;
|
2002-08-29 23:45:15 +00:00
|
|
|
stopCD();
|
2003-09-10 22:36:46 +00:00
|
|
|
stopCDTimer();
|
2002-03-16 05:33:25 +00:00
|
|
|
}
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (!(_vm->_features & GF_DIGI_IMUSE))
|
|
|
|
_vm->_mixer->stopID(a);
|
2003-12-25 13:56:22 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_musicEngine)
|
|
|
|
_vm->_musicEngine->stopSound(a);
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2003-12-25 15:09:23 +00:00
|
|
|
for (i = 0; i < ARRAYSIZE(_soundQue2); i++)
|
2002-09-30 22:59:42 +00:00
|
|
|
if (_soundQue2[i] == a)
|
2001-11-05 19:21:49 +00:00
|
|
|
_soundQue2[i] = 0;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Sound::stopAllSounds() {
|
2003-06-30 23:18:20 +00:00
|
|
|
if (_currentCDSound != 0) {
|
|
|
|
_currentCDSound = 0;
|
2002-08-29 23:45:15 +00:00
|
|
|
stopCD();
|
2003-09-10 22:36:46 +00:00
|
|
|
stopCDTimer();
|
2002-03-16 05:33:25 +00:00
|
|
|
}
|
|
|
|
|
2003-09-07 19:28:45 +00:00
|
|
|
// Clear the (secondary) sound queue
|
2001-11-05 19:21:49 +00:00
|
|
|
_soundQue2Pos = 0;
|
|
|
|
memset(_soundQue2, 0, sizeof(_soundQue2));
|
2003-09-07 19:28:45 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_musicEngine) {
|
|
|
|
_vm->_musicEngine->stopAllSounds();
|
2003-09-08 17:06:44 +00:00
|
|
|
}
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuse) {
|
2003-09-08 17:06:44 +00:00
|
|
|
// FIXME: Maybe we could merge this call to clear_queue()
|
|
|
|
// into IMuse::stopAllSounds() ?
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_imuse->clear_queue();
|
2003-09-08 17:06:44 +00:00
|
|
|
}
|
|
|
|
|
2003-09-07 19:28:45 +00:00
|
|
|
// Stop all SFX
|
2004-01-08 20:37:26 +00:00
|
|
|
if (!_vm->_imuseDigital) {
|
|
|
|
_vm->_mixer->stopAll();
|
2003-09-07 19:28:45 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
2001-10-16 10:01:48 +00:00
|
|
|
|
2002-12-25 14:46:39 +00:00
|
|
|
void Sound::soundKludge(int *list, int num) {
|
2001-10-16 10:01:48 +00:00
|
|
|
int i;
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuseDigital) {
|
|
|
|
_vm->_imuseDigital->parseScriptCmds(list[0], list[1], list[2], list[3], list[4],
|
2003-12-25 13:56:22 +00:00
|
|
|
list[5], list[6], list[7]);
|
2001-10-16 10:01:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-01-29 04:00:45 +00:00
|
|
|
|
2003-12-25 13:56:22 +00:00
|
|
|
if (list[0] == -1) {
|
|
|
|
processSoundQues();
|
2003-12-25 15:09:23 +00:00
|
|
|
} else {
|
|
|
|
_soundQue[_soundQuePos++] = num;
|
|
|
|
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
_soundQue[_soundQuePos++] = list[i];
|
|
|
|
}
|
2003-01-29 04:00:45 +00:00
|
|
|
}
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-09-11 13:28:34 +00:00
|
|
|
void Sound::talkSound(uint32 a, uint32 b, int mode, int frame) {
|
2002-09-13 11:59:43 +00:00
|
|
|
if (mode == 1) {
|
|
|
|
_talk_sound_a1 = a;
|
|
|
|
_talk_sound_b1 = b;
|
|
|
|
} else {
|
|
|
|
_talk_sound_a2 = a;
|
|
|
|
_talk_sound_b2 = b;
|
|
|
|
}
|
|
|
|
|
2002-09-11 13:28:34 +00:00
|
|
|
_talk_sound_frame = frame;
|
2002-09-13 11:59:43 +00:00
|
|
|
_talk_sound_mode |= mode;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2001-11-14 18:40:39 +00:00
|
|
|
/* The sound code currently only supports General Midi.
|
|
|
|
* General Midi is used in Day Of The Tentacle.
|
|
|
|
* Roland music is also playable, but doesn't sound well.
|
|
|
|
* A mapping between roland instruments and GM instruments
|
|
|
|
* is needed.
|
|
|
|
*/
|
2002-03-06 23:17:16 +00:00
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::setupSound() {
|
2003-06-26 23:04:41 +00:00
|
|
|
delete _sfxFile;
|
2001-11-06 20:25:08 +00:00
|
|
|
_sfxFile = openSfxFile();
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::pauseSounds(bool pause) {
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuse)
|
|
|
|
_vm->_imuse->pause(pause);
|
2002-07-22 12:44:57 +00:00
|
|
|
|
2003-01-13 13:13:36 +00:00
|
|
|
// Don't pause sounds if the game isn't active
|
2003-03-07 21:38:46 +00:00
|
|
|
// FIXME - this is quite a nasty hack, replace with something cleaner, and w/o
|
|
|
|
// having to access member vars directly!
|
2004-01-08 20:37:26 +00:00
|
|
|
if (!_vm->_roomResource)
|
2003-01-13 13:13:36 +00:00
|
|
|
return;
|
|
|
|
|
2001-11-14 18:40:39 +00:00
|
|
|
_soundsPaused = pause;
|
2003-09-06 10:47:30 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_mixer->pauseAll(pause);
|
2002-09-21 13:48:03 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuseDigital) {
|
|
|
|
_vm->_imuseDigital->pause(pause);
|
2002-10-15 06:53:42 +00:00
|
|
|
}
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if ((_vm->_features & GF_AUDIOTRACKS) && _vm->VAR(_vm->VAR_MUSIC_TIMER) > 0) {
|
2002-09-21 13:48:03 +00:00
|
|
|
if (pause)
|
|
|
|
stopCDTimer();
|
|
|
|
else
|
|
|
|
startCDTimer();
|
|
|
|
}
|
2001-11-14 18:40:39 +00:00
|
|
|
}
|
|
|
|
|
2003-12-23 19:18:20 +00:00
|
|
|
void Sound::startSfxSound(File *file, int file_size, PlayingSoundHandle *handle, int id) {
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2004-04-11 22:20:41 +00:00
|
|
|
AudioStream *input = NULL;
|
2004-01-03 00:55:40 +00:00
|
|
|
|
2004-04-11 22:20:41 +00:00
|
|
|
switch (_soundMode) {
|
|
|
|
case kMP3Mode:
|
|
|
|
#ifdef USE_MAD
|
|
|
|
assert(file_size > 0);
|
|
|
|
input = makeMP3Stream(file, file_size);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case kVorbisMode:
|
2003-11-29 12:11:01 +00:00
|
|
|
#ifdef USE_VORBIS
|
2004-04-11 22:20:41 +00:00
|
|
|
assert(file_size > 0);
|
|
|
|
input = makeVorbisStream(file, file_size);
|
2003-11-29 12:11:01 +00:00
|
|
|
#endif
|
2004-04-11 22:20:41 +00:00
|
|
|
break;
|
|
|
|
case kFlacMode:
|
|
|
|
#ifdef USE_FLAC
|
|
|
|
assert(file_size > 0);
|
|
|
|
input = makeFlacStream(file, file_size);
|
2002-10-27 11:41:08 +00:00
|
|
|
#endif
|
2004-04-11 22:20:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-01-03 00:55:40 +00:00
|
|
|
input = makeVOCStream(_sfxFile);
|
2002-03-06 23:17:16 +00:00
|
|
|
}
|
2004-02-03 08:53:13 +00:00
|
|
|
|
|
|
|
if (!input) {
|
|
|
|
warning("startSfxSound failed to load sound");
|
2004-02-03 09:04:38 +00:00
|
|
|
return;
|
2004-02-03 08:53:13 +00:00
|
|
|
}
|
2002-10-28 12:56:42 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuseDigital) {
|
|
|
|
//_vm->_imuseDigital->stopSound(kTalkSoundID);
|
|
|
|
_vm->_imuseDigital->startVoice(kTalkSoundID, input);
|
2002-01-02 11:50:28 +00:00
|
|
|
} else {
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_mixer->playInputStream(handle, input, false, 255, 0, id);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
File *Sound::openSfxFile() {
|
2002-05-15 19:29:36 +00:00
|
|
|
char buf[256];
|
2004-04-17 16:29:03 +00:00
|
|
|
XORFile *file = new XORFile();
|
2004-04-11 22:20:41 +00:00
|
|
|
_offsetTable = NULL;
|
|
|
|
|
|
|
|
struct SoundFileExtensions {
|
|
|
|
const char *ext;
|
|
|
|
SoundMode mode;
|
|
|
|
};
|
|
|
|
|
|
|
|
const SoundFileExtensions extensions[] = {
|
|
|
|
#ifdef USE_FLAC
|
|
|
|
{ "sof", kFlacMode },
|
|
|
|
#endif
|
|
|
|
#ifdef USE_MAD
|
|
|
|
{ "so3", kMP3Mode },
|
|
|
|
#endif
|
|
|
|
#ifdef USE_VORBIS
|
|
|
|
{ "sog", kVorbisMode },
|
|
|
|
#endif
|
|
|
|
{ "sou", kVOCMode },
|
|
|
|
{ 0, kVOCMode }
|
|
|
|
};
|
2004-04-10 00:07:58 +00:00
|
|
|
|
|
|
|
/* Try opening the file <_gameName>.sou first, eg tentacle.sou.
|
|
|
|
* That way, you can keep .sou files for multiple games in the
|
|
|
|
* same directory */
|
2004-04-11 22:20:41 +00:00
|
|
|
|
|
|
|
int i, j;
|
|
|
|
const char *basename[3] = { 0, 0, 0 };
|
|
|
|
basename[0] = _vm->getGameName();
|
|
|
|
basename[1] = "monster";
|
|
|
|
|
|
|
|
for (j = 0; basename[j] && !file->isOpen(); ++j) {
|
|
|
|
for (i = 0; extensions[i].ext; ++i) {
|
|
|
|
sprintf(buf, "%s.%s", basename[j], extensions[i].ext);
|
|
|
|
if (file->open(buf)) {
|
|
|
|
_soundMode = extensions[i].mode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-04-10 00:07:58 +00:00
|
|
|
}
|
2002-10-27 11:41:08 +00:00
|
|
|
|
2004-04-10 00:07:58 +00:00
|
|
|
if (!file->isOpen()) {
|
2004-04-11 22:20:41 +00:00
|
|
|
sprintf(buf, "%s.tlk", _vm->getGameName());
|
2004-04-25 16:54:59 +00:00
|
|
|
if (file->open(buf))
|
|
|
|
file->setEnc(0x69);
|
2004-04-11 22:20:41 +00:00
|
|
|
_soundMode = kVOCMode;
|
|
|
|
} else if (_soundMode != kVOCMode) {
|
2002-04-11 17:19:16 +00:00
|
|
|
/* Now load the 'offset' index in memory to be able to find the MP3 data
|
|
|
|
|
|
|
|
The format of the .SO3 file is easy :
|
|
|
|
- number of bytes of the 'index' part
|
|
|
|
- N times the following fields (4 bytes each) :
|
|
|
|
+ offset in the original sound file
|
|
|
|
+ offset of the MP3 data in the .SO3 file WITHOUT taking into account
|
|
|
|
the index field and the 'size' field
|
|
|
|
+ the number of 'tags'
|
|
|
|
+ the size of the MP3 data
|
|
|
|
- and then N times :
|
|
|
|
+ the tags
|
|
|
|
+ the MP3 data
|
|
|
|
*/
|
|
|
|
int size, compressed_offset;
|
|
|
|
MP3OffsetTable *cur;
|
2002-10-21 13:23:25 +00:00
|
|
|
compressed_offset = file->readUint32BE();
|
2004-04-11 22:20:41 +00:00
|
|
|
_offsetTable = (MP3OffsetTable *) malloc(compressed_offset);
|
|
|
|
_numSoundEffects = compressed_offset / 16;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
size = compressed_offset;
|
2004-04-11 22:20:41 +00:00
|
|
|
cur = _offsetTable;
|
2002-04-11 17:19:16 +00:00
|
|
|
while (size > 0) {
|
2004-04-11 22:20:41 +00:00
|
|
|
cur->org_offset = file->readUint32BE();
|
|
|
|
cur->new_offset = file->readUint32BE() + compressed_offset + 4; /* The + 4 is to take into accound the 'size' field */
|
|
|
|
cur->num_tags = file->readUint32BE();
|
|
|
|
cur->compressed_size = file->readUint32BE();
|
2002-04-11 17:19:16 +00:00
|
|
|
size -= 4 * 4;
|
|
|
|
cur++;
|
|
|
|
}
|
2002-02-27 22:48:55 +00:00
|
|
|
}
|
2003-03-01 12:44:52 +00:00
|
|
|
|
2001-11-29 22:29:38 +00:00
|
|
|
return file;
|
2001-11-14 18:40:39 +00:00
|
|
|
}
|
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
bool Sound::isSfxFinished() const {
|
2004-01-08 20:37:26 +00:00
|
|
|
return !_vm->_mixer->hasActiveSFXChannel();
|
2002-08-14 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
2002-09-21 13:48:03 +00:00
|
|
|
// We use a real timer in an attempt to get better sync with CD tracks. This is
|
|
|
|
// necessary for games like Loom CD.
|
|
|
|
|
2003-09-10 12:43:54 +00:00
|
|
|
static void cd_timer_handler(void *refCon) {
|
2003-10-02 22:42:03 +00:00
|
|
|
ScummEngine *scumm = (ScummEngine *)refCon;
|
2002-09-21 13:48:03 +00:00
|
|
|
|
|
|
|
// FIXME: Turn off the timer when it's no longer needed. In theory, it
|
|
|
|
// should be possible to check with pollCD(), but since CD sound isn't
|
|
|
|
// properly restarted when reloading a saved game, I don't dare to.
|
|
|
|
|
2003-05-08 15:48:50 +00:00
|
|
|
scumm->VAR(scumm->VAR_MUSIC_TIMER) += 6;
|
2002-09-21 13:48:03 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Sound::startCDTimer() {
|
2002-09-21 13:48:03 +00:00
|
|
|
int timer_interval;
|
|
|
|
|
|
|
|
// The timer interval has been tuned for Loom CD and the Monkey 1
|
|
|
|
// intro. I have to use 100 for Loom, or there will be a nasty stutter
|
|
|
|
// when Chaos first appears, and I have to use 101 for Monkey 1 or the
|
|
|
|
// intro music will be cut short.
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_gameId == GID_LOOM256)
|
2002-09-21 13:48:03 +00:00
|
|
|
timer_interval = 100;
|
|
|
|
else
|
|
|
|
timer_interval = 101;
|
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_timer->removeTimerProc(&cd_timer_handler);
|
|
|
|
_vm->_timer->installTimerProc(&cd_timer_handler, 1000 * timer_interval, _vm);
|
2002-09-21 13:48:03 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Sound::stopCDTimer() {
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_timer->removeTimerProc(&cd_timer_handler);
|
2002-09-21 13:48:03 +00:00
|
|
|
}
|
|
|
|
|
2003-07-22 20:27:54 +00:00
|
|
|
void Sound::playCDTrack(int track, int numLoops, int startFrame, int duration) {
|
2003-09-07 19:47:58 +00:00
|
|
|
// Reset the music timer variable at the start of a new track
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->VAR(_vm->VAR_MUSIC_TIMER) = 0;
|
2003-09-07 19:47:58 +00:00
|
|
|
|
2003-11-29 12:11:01 +00:00
|
|
|
// Play it
|
|
|
|
if (!_soundsPaused)
|
2003-11-29 13:56:33 +00:00
|
|
|
AudioCD.play(track, numLoops, startFrame, duration);
|
2002-09-21 13:48:03 +00:00
|
|
|
|
|
|
|
// Start the timer after starting the track. Starting an MP3 track is
|
|
|
|
// almost instantaneous, but a CD player may take some time. Hopefully
|
|
|
|
// play_cdrom() will block during that delay.
|
|
|
|
startCDTimer();
|
2002-08-29 23:45:15 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Sound::stopCD() {
|
2003-11-29 13:56:33 +00:00
|
|
|
AudioCD.stop();
|
2002-08-29 23:45:15 +00:00
|
|
|
}
|
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
int Sound::pollCD() const {
|
2003-11-29 13:56:33 +00:00
|
|
|
return AudioCD.isPlaying();
|
2002-08-29 23:45:15 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Sound::updateCD() {
|
2003-11-29 12:11:01 +00:00
|
|
|
AudioCD.updateCD();
|
2002-04-17 20:23:45 +00:00
|
|
|
}
|
2002-04-22 11:36:41 +00:00
|
|
|
|
2003-10-03 18:33:57 +00:00
|
|
|
} // End of namespace Scumm
|