2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* 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.
|
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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2001-10-09 14:30:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-07-29 20:35:50 +00:00
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/timer.h"
|
|
|
|
#include "common/util.h"
|
2011-11-02 22:56:45 +00:00
|
|
|
#include "common/ptr.h"
|
|
|
|
#include "common/substream.h"
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2003-10-03 18:33:57 +00:00
|
|
|
#include "scumm/actor.h"
|
2006-03-03 15:16:02 +00:00
|
|
|
#include "scumm/file.h"
|
2006-02-20 20:57:26 +00:00
|
|
|
#include "scumm/imuse/imuse.h"
|
2005-05-14 23:28:22 +00:00
|
|
|
#include "scumm/imuse_digi/dimuse.h"
|
2010-08-18 21:38:43 +00:00
|
|
|
#include "scumm/player_towns.h"
|
2011-05-11 14:03:50 +00:00
|
|
|
#include "scumm/resource.h"
|
2003-10-03 18:33:57 +00:00
|
|
|
#include "scumm/scumm.h"
|
|
|
|
#include "scumm/sound.h"
|
2005-04-10 12:59:17 +00:00
|
|
|
#include "scumm/util.h"
|
2003-09-07 20:30:02 +00:00
|
|
|
|
2010-11-08 23:07:42 +00:00
|
|
|
#include "backends/audiocd/audiocd.h"
|
|
|
|
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/decoders/adpcm.h"
|
|
|
|
#include "audio/decoders/flac.h"
|
|
|
|
#include "audio/mididrv.h"
|
|
|
|
#include "audio/mixer.h"
|
|
|
|
#include "audio/decoders/mp3.h"
|
|
|
|
#include "audio/decoders/raw.h"
|
|
|
|
#include "audio/decoders/voc.h"
|
|
|
|
#include "audio/decoders/vorbis.h"
|
|
|
|
#include "audio/decoders/wave.h"
|
2005-04-04 11:43:25 +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
|
|
|
|
|
|
|
|
2006-10-21 12:44:10 +00:00
|
|
|
Sound::Sound(ScummEngine *parent, Audio::Mixer *mixer)
|
2004-04-11 22:20:41 +00:00
|
|
|
:
|
|
|
|
_vm(parent),
|
2006-10-21 12:44:10 +00:00
|
|
|
_mixer(mixer),
|
2004-04-11 22:20:41 +00:00
|
|
|
_soundQuePos(0),
|
|
|
|
_soundQue2Pos(0),
|
2011-11-02 22:56:45 +00:00
|
|
|
_sfxFilename(),
|
|
|
|
_sfxFileEncByte(0),
|
2004-04-11 22:20:41 +00:00
|
|
|
_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),
|
2004-08-09 00:58:21 +00:00
|
|
|
_talk_sound_channel(0),
|
2004-04-11 22:20:41 +00:00
|
|
|
_mouthSyncMode(false),
|
|
|
|
_endOfMouthSync(false),
|
|
|
|
_curSoundPos(0),
|
|
|
|
_currentCDSound(0),
|
2004-07-12 09:02:18 +00:00
|
|
|
_currentMusic(0),
|
2010-09-18 14:18:48 +00:00
|
|
|
_lastSound(0),
|
2004-04-11 22:20:41 +00:00
|
|
|
_soundsPaused(false),
|
2006-04-23 18:52:39 +00:00
|
|
|
_sfxMode(0) {
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-04-11 22:20:41 +00:00
|
|
|
memset(_soundQue, 0, sizeof(_soundQue));
|
2004-10-13 07:52:42 +00:00
|
|
|
memset(_soundQue2, 0, sizeof(_soundQue2));
|
2004-04-11 22:20:41 +00:00
|
|
|
memset(_mouthSyncTimes, 0, sizeof(_mouthSyncTimes));
|
2011-08-05 12:33:42 +00:00
|
|
|
|
|
|
|
_musicType = MDT_NONE;
|
2002-08-14 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sound::~Sound() {
|
2003-12-27 21:33:34 +00:00
|
|
|
stopCDTimer();
|
2010-06-15 04:13:12 +00:00
|
|
|
g_system->getAudioCDManager()->stop();
|
2012-01-15 12:27:52 +00:00
|
|
|
free(_offsetTable);
|
2002-08-14 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
2004-10-13 07:52:42 +00:00
|
|
|
void Sound::addSoundToQueue(int sound, int heOffset, int heChannel, int heFlags) {
|
2005-09-24 05:26:12 +00:00
|
|
|
if (_vm->VAR_LAST_SOUND != 0xFF)
|
|
|
|
_vm->VAR(_vm->VAR_LAST_SOUND) = sound;
|
2010-09-18 14:18:48 +00:00
|
|
|
_lastSound = sound;
|
2006-01-05 07:06:47 +00:00
|
|
|
|
2004-09-04 09:26:08 +00:00
|
|
|
// HE music resources are in separate file
|
|
|
|
if (sound <= _vm->_numSounds)
|
2004-07-12 09:02:18 +00:00
|
|
|
_vm->ensureResourceLoaded(rtSound, sound);
|
2006-01-05 07:06:47 +00:00
|
|
|
|
2004-10-13 07:52:42 +00:00
|
|
|
addSoundToQueue2(sound, heOffset, heChannel, heFlags);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2004-10-13 07:52:42 +00:00
|
|
|
void Sound::addSoundToQueue2(int sound, int heOffset, int heChannel, int heFlags) {
|
|
|
|
assert(_soundQue2Pos < ARRAYSIZE(_soundQue2));
|
|
|
|
_soundQue2[_soundQue2Pos].sound = sound;
|
|
|
|
_soundQue2[_soundQue2Pos].offset = heOffset;
|
|
|
|
_soundQue2[_soundQue2Pos].channel = heChannel;
|
|
|
|
_soundQue2[_soundQue2Pos].flags = heFlags;
|
2004-07-14 07:29:09 +00:00
|
|
|
_soundQue2Pos++;
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2005-06-04 06:30:35 +00:00
|
|
|
void Sound::processSound() {
|
2007-02-10 02:05:59 +00:00
|
|
|
if (_vm->_game.version >= 7) {
|
2006-04-23 23:00:32 +00:00
|
|
|
processSfxQueues();
|
2009-10-16 02:02:09 +00:00
|
|
|
} else if (_vm->_game.heversion >= 80) {
|
2005-06-04 06:30:35 +00:00
|
|
|
processSoundQueues();
|
|
|
|
} else {
|
|
|
|
processSfxQueues();
|
|
|
|
processSoundQueues();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::processSoundQueues() {
|
2004-10-13 07:52:42 +00:00
|
|
|
int i = 0, num;
|
2006-04-23 18:52:39 +00:00
|
|
|
int snd;
|
2003-08-06 18:20:15 +00:00
|
|
|
int data[16];
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2006-04-23 18:52:39 +00:00
|
|
|
while (_soundQue2Pos) {
|
|
|
|
_soundQue2Pos--;
|
|
|
|
snd = _soundQue2[_soundQue2Pos].sound;
|
|
|
|
if (snd)
|
|
|
|
playSound(snd);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2005-08-14 01:41:52 +00:00
|
|
|
error("processSoundQues: invalid num value");
|
2001-11-05 19:21:49 +00:00
|
|
|
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]);
|
|
|
|
|
2010-08-18 21:38:43 +00:00
|
|
|
if (_vm->_townsPlayer)
|
|
|
|
_vm->VAR(_vm->VAR_SOUNDRESULT) = (short)_vm->_townsPlayer->doCommand(num, data);
|
|
|
|
else if (_vm->_imuse)
|
2006-11-12 02:34:09 +00:00
|
|
|
_vm->VAR(_vm->VAR_SOUNDRESULT) = (short)_vm->_imuse->doCommand(num, data);
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_soundQuePos = 0;
|
|
|
|
}
|
|
|
|
|
2006-01-05 07:06:47 +00:00
|
|
|
void Sound::playSound(int soundID) {
|
2002-03-16 05:33:25 +00:00
|
|
|
byte *ptr;
|
2010-01-19 11:20:58 +00:00
|
|
|
byte *sound;
|
|
|
|
Audio::AudioStream *stream;
|
2004-04-24 20:57:42 +00:00
|
|
|
int size = -1;
|
2002-09-09 11:15:44 +00:00
|
|
|
int rate;
|
2005-02-15 08:15:35 +00:00
|
|
|
|
2009-10-24 03:52:38 +00:00
|
|
|
if (_vm->_game.id == GID_LOOM && _vm->_game.platform == Common::kPlatformPCEngine) {
|
|
|
|
if (soundID >= 13 && soundID <= 32) {
|
2009-10-24 12:33:18 +00:00
|
|
|
static const char tracks[20] = {3, 4, 5, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 19, 20, 21};
|
2009-10-24 03:52:38 +00:00
|
|
|
|
|
|
|
_currentCDSound = soundID;
|
2010-08-15 11:37:57 +00:00
|
|
|
|
|
|
|
// The original game had hard-coded lengths for all
|
|
|
|
// tracks, but this one track is the only one (as far
|
|
|
|
// as we know) where this actually matters. See bug
|
|
|
|
// #3024173 - LOOM-PCE: Music stops prematurely.
|
|
|
|
|
|
|
|
int track = tracks[soundID - 13];
|
|
|
|
if (track == 6) {
|
|
|
|
playCDTrack(track, 1, 0, 260);
|
|
|
|
} else {
|
|
|
|
playCDTrack(track, 1, 0, 0);
|
|
|
|
}
|
2009-10-24 03:52:38 +00:00
|
|
|
} else {
|
2009-11-23 23:17:15 +00:00
|
|
|
if (_vm->_musicEngine) {
|
|
|
|
_vm->_musicEngine->startSound(soundID);
|
|
|
|
}
|
2009-10-24 03:52:38 +00:00
|
|
|
}
|
2007-03-03 23:02:54 +00:00
|
|
|
return;
|
2009-10-24 03:52:38 +00:00
|
|
|
}
|
2007-03-03 23:02:54 +00:00
|
|
|
|
2011-04-05 11:43:54 +00:00
|
|
|
debugC(DEBUG_SOUND, "playSound #%d", soundID);
|
2004-07-12 09:02:18 +00:00
|
|
|
|
2006-01-05 07:06:47 +00:00
|
|
|
ptr = _vm->getResourceAddress(rtSound, soundID);
|
2004-07-12 09:02:18 +00:00
|
|
|
|
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.
|
2011-04-12 14:53:15 +00:00
|
|
|
else if (READ_BE_UINT32(ptr) == MKTAG('M','a','c','1')) {
|
2003-09-07 00:03:55 +00:00
|
|
|
// 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
|
2010-01-19 11:20:58 +00:00
|
|
|
sound = (byte *)malloc(size);
|
2003-09-07 00:03:55 +00:00
|
|
|
memcpy(sound, ptr, size);
|
2010-01-19 22:19:43 +00:00
|
|
|
|
2010-01-30 15:26:54 +00:00
|
|
|
stream = Audio::makeRawStream(sound, size, rate, Audio::FLAG_UNSIGNED);
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kSFXSoundType, NULL, stream, soundID);
|
2003-09-07 00:03:55 +00:00
|
|
|
}
|
2005-10-23 14:21:20 +00:00
|
|
|
// WORKAROUND bug # 1311447
|
2006-02-25 02:12:58 +00:00
|
|
|
else if (READ_BE_UINT32(ptr) == 0x460e200d) {
|
2005-10-23 14:21:20 +00:00
|
|
|
// This sound resource occurs in the Macintosh version of Monkey Island.
|
|
|
|
// I do now know whether it is used in any place other than the one
|
2007-09-19 08:40:12 +00:00
|
|
|
// mentioned in the bug report above; in case it is, I put a check here.
|
2005-10-23 14:21:20 +00:00
|
|
|
assert(soundID == 39);
|
|
|
|
|
|
|
|
// The samplerate is copied from the sound resouce 39 of the PC CD/VGA
|
|
|
|
// version of Monkey Island.
|
|
|
|
|
|
|
|
// Read info from the header
|
|
|
|
size = READ_BE_UINT32(ptr+4);
|
|
|
|
rate = 6849;
|
|
|
|
|
|
|
|
// Skip over the header (fixed size)
|
|
|
|
ptr += 0x26;
|
|
|
|
|
|
|
|
// Allocate a sound buffer, copy the data into it, and play
|
2010-01-19 11:20:58 +00:00
|
|
|
sound = (byte *)malloc(size);
|
2005-10-23 14:21:20 +00:00
|
|
|
memcpy(sound, ptr, size);
|
2010-01-30 15:26:54 +00:00
|
|
|
stream = Audio::makeRawStream(sound, size, rate, Audio::FLAG_UNSIGNED);
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kSFXSoundType, NULL, stream, soundID);
|
2005-10-23 14:21:20 +00:00
|
|
|
}
|
2003-09-07 00:03:55 +00:00
|
|
|
// Support for sampled sound effects in Monkey Island 1 and 2
|
2012-09-19 13:19:55 +00:00
|
|
|
else if (_vm->_game.platform != Common::kPlatformFMTowns
|
2012-09-20 16:00:13 +00:00
|
|
|
// The Macintosh m68k versions of MI2/Indy4 just ignore SBL effects.
|
2012-09-20 15:58:04 +00:00
|
|
|
&& !_vm->isMacM68kIMuse()
|
2012-09-19 13:19:55 +00:00
|
|
|
&& READ_BE_UINT32(ptr) == MKTAG('S','B','L',' ')) {
|
2004-08-22 09:30:08 +00:00
|
|
|
debugC(DEBUG_SOUND, "Using SBL sound effect");
|
2005-07-30 21:11:48 +00:00
|
|
|
|
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.
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-09-07 20:30:02 +00:00
|
|
|
// 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
|
2006-02-20 16:51:30 +00:00
|
|
|
if ((_vm->_game.platform == Common::kPlatformSegaCD) && (ptr[0] != 1)) {
|
2004-04-24 20:57:42 +00:00
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
ptr[i] ^= 0x16;
|
2005-02-15 08:15:35 +00:00
|
|
|
if (ptr[i] >= 0x7F) {
|
|
|
|
ptr[i] = 0xFE - ptr[i];
|
|
|
|
ptr[i] ^= 0x80;
|
2004-04-24 20:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
2003-09-07 20:53:05 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +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
|
|
|
|
2006-04-29 22:33:31 +00:00
|
|
|
Audio::VocBlockHeader &voc_block_hdr = *(Audio::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;
|
2006-04-29 22:33:31 +00:00
|
|
|
rate = Audio::getSampleRateFromVOCRate(voc_block_hdr.sr);
|
2003-09-07 20:53:05 +00:00
|
|
|
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
|
2010-01-19 11:20:58 +00:00
|
|
|
sound = (byte *)malloc(size);
|
2004-04-24 20:57:42 +00:00
|
|
|
memcpy(sound, ptr + 6, size);
|
2010-01-30 15:26:54 +00:00
|
|
|
stream = Audio::makeRawStream(sound, size, rate, Audio::FLAG_UNSIGNED);
|
2011-06-19 22:59:48 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kSFXSoundType, NULL, stream, soundID);
|
2003-09-07 16:32:23 +00:00
|
|
|
}
|
2011-04-12 14:53:15 +00:00
|
|
|
else if (_vm->_game.platform != Common::kPlatformFMTowns && READ_BE_UINT32(ptr) == MKTAG('S','O','U','N')) {
|
2010-08-22 20:37:48 +00:00
|
|
|
if (_vm->_game.version != 3)
|
2003-09-30 17:53:42 +00:00
|
|
|
ptr += 2;
|
2003-12-13 20:01:35 +00:00
|
|
|
|
2003-09-07 00:03:55 +00:00
|
|
|
int type = *(ptr + 0x0D);
|
2003-12-13 20:01:35 +00:00
|
|
|
|
2010-08-22 20:37:48 +00:00
|
|
|
if (type == 2) {
|
|
|
|
// CD track resource
|
2003-09-24 06:33:59 +00:00
|
|
|
ptr += 0x16;
|
2010-08-22 20:37:48 +00:00
|
|
|
if (soundID == _currentCDSound && pollCD() == 1)
|
2005-02-15 08:15:35 +00:00
|
|
|
return;
|
2003-09-24 06:33:59 +00:00
|
|
|
|
2010-08-22 20:37:48 +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-24 06:33:59 +00:00
|
|
|
|
2010-08-22 20:37:48 +00:00
|
|
|
playCDTrack(track, loops == 0xff ? -1 : loops, start, end <= start ? 0 : end - start);
|
2003-09-24 06:33:59 +00:00
|
|
|
_currentCDSound = soundID;
|
2010-08-22 20:37:48 +00:00
|
|
|
} else {
|
2005-09-04 04:18:36 +00:00
|
|
|
// All other sound types are ignored
|
2010-08-22 20:37:48 +00:00
|
|
|
warning("Scumm::Sound::playSound: encountered audio resoure with chunk type 'SOUN' and sound type %d", type);
|
2002-07-25 15:37:31 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-10 23:01:11 +00:00
|
|
|
else if ((_vm->_game.platform == Common::kPlatformMacintosh) && (_vm->_game.id == GID_INDY3) && READ_BE_UINT16(ptr + 8) == 0x1C) {
|
|
|
|
// Sound format as used in Indy3 EGA Mac.
|
2007-12-24 15:36:50 +00:00
|
|
|
// It seems to be closely related to the Amiga format, see player_v3a.cpp
|
|
|
|
// The following is known:
|
|
|
|
// offset 0, 16 LE: total size
|
|
|
|
// offset 2-7: ?
|
|
|
|
// offset 8, 16BE: offset to sound data (0x1C = 28 -> header size 28?)
|
|
|
|
// offset 10-11: ? another offset, maybe related to looping?
|
|
|
|
// offset 12, 16BE: size of sound data
|
|
|
|
// offset 14-15: ? often the same as 12-13: maybe loop size/end?
|
|
|
|
// offset 16-19: ? all 0?
|
|
|
|
// offset 20, 16BE: rate divisor
|
|
|
|
// offset 22-23: ? often identical to the rate divisior? (but not in sound 8, which loops)
|
|
|
|
// offset 24, byte (?): volume
|
|
|
|
// offset 25: ? same as volume -- maybe left vs. right channel?
|
|
|
|
// offset 26: ? if != 0: stop current sound?
|
|
|
|
// offset 27: ? loopcount? 0xff == -1 for infinite?
|
|
|
|
|
2003-09-07 16:32:23 +00:00
|
|
|
size = READ_BE_UINT16(ptr + 12);
|
2009-08-10 23:01:11 +00:00
|
|
|
assert(size);
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2003-09-07 16:32:23 +00:00
|
|
|
rate = 3579545 / READ_BE_UINT16(ptr + 20);
|
2010-01-19 11:20:58 +00:00
|
|
|
sound = (byte *)malloc(size);
|
2003-09-07 16:32:23 +00:00
|
|
|
int vol = ptr[24] * 4;
|
2007-12-24 15:36:50 +00:00
|
|
|
int loopStart = 0, loopEnd = 0;
|
|
|
|
int loopcount = ptr[27];
|
2010-01-30 15:19:15 +00:00
|
|
|
|
|
|
|
memcpy(sound, ptr + READ_BE_UINT16(ptr + 8), size);
|
|
|
|
Audio::SeekableAudioStream *plainStream = Audio::makeRawStream(sound, size, rate, 0);
|
|
|
|
|
2007-12-24 15:36:50 +00:00
|
|
|
if (loopcount > 1) {
|
|
|
|
loopStart = READ_BE_UINT16(ptr + 10) - READ_BE_UINT16(ptr + 8);
|
|
|
|
loopEnd = READ_BE_UINT16(ptr + 14);
|
2010-01-30 15:19:15 +00:00
|
|
|
|
|
|
|
// TODO: Currently we will only ever play till "loopEnd", even when we only have
|
2010-01-30 15:30:53 +00:00
|
|
|
// a finite repetition count.
|
2010-01-30 18:15:17 +00:00
|
|
|
stream = new Audio::SubLoopingAudioStream(plainStream, loopcount == 255 ? 0 : loopcount, Audio::Timestamp(0, loopStart, rate), Audio::Timestamp(0, loopEnd, rate));
|
2010-01-30 15:19:15 +00:00
|
|
|
} else {
|
|
|
|
stream = plainStream;
|
2007-12-24 15:36:50 +00:00
|
|
|
}
|
2007-12-24 14:40:39 +00:00
|
|
|
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kSFXSoundType, NULL, stream, soundID, vol, 0);
|
2003-07-15 07:29:23 +00:00
|
|
|
}
|
2003-09-07 20:30:02 +00:00
|
|
|
else {
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2012-11-14 21:12:46 +00:00
|
|
|
if (_vm->_game.id == GID_MONKEY_VGA || _vm->_game.id == GID_MONKEY_EGA) {
|
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) {
|
2011-04-12 14:53:15 +00:00
|
|
|
if (READ_BE_UINT32(ptr) != MKTAG('A','S','F','X'))
|
2004-01-08 20:37:26 +00:00
|
|
|
_vm->_imuse->stopAllSounds();
|
2003-09-07 20:30:02 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-30 21:11:48 +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
|
|
|
}
|
2010-08-18 21:38:43 +00:00
|
|
|
|
|
|
|
if (_vm->_townsPlayer)
|
|
|
|
_currentCDSound = _vm->_townsPlayer->getCurrentCdaSound();
|
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;
|
2004-07-24 13:36:26 +00:00
|
|
|
bool 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);
|
2006-02-20 16:51:30 +00:00
|
|
|
} else if (_vm->_game.heversion >= 60) {
|
2005-04-04 11:58:42 +00:00
|
|
|
finished = !isSoundRunning(1);
|
2003-12-26 12:15:23 +00:00
|
|
|
} else {
|
2006-10-21 12:44:10 +00:00
|
|
|
finished = !_mixer->isSoundHandleActive(_talkChannelHandle);
|
2003-12-26 12:15:23 +00:00
|
|
|
}
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if ((uint) act < 0x80 && ((_vm->_game.version == 8) || (_vm->_game.version <= 7 && !_vm->_string[0].no_talk_anim))) {
|
2004-01-08 20:37:26 +00:00
|
|
|
a = _vm->derefActor(act, "processSfxQueues");
|
2004-01-15 20:39:24 +00:00
|
|
|
if (a->isInCurrentRoom()) {
|
2004-07-24 13:36:26 +00:00
|
|
|
if (isMouthSyncOff(_curSoundPos) && !_mouthSyncMode) {
|
|
|
|
if (!_endOfMouthSync)
|
2004-09-28 19:28:59 +00:00
|
|
|
a->runActorTalkScript(a->_talkStopFrame);
|
2004-07-24 13:36:26 +00:00
|
|
|
_mouthSyncMode = 0;
|
|
|
|
} else if (isMouthSyncOff(_curSoundPos) == 0 && !_mouthSyncMode) {
|
2004-09-28 19:28:59 +00:00
|
|
|
a->runActorTalkScript(a->_talkStartFrame);
|
2004-07-24 13:36:26 +00:00
|
|
|
_mouthSyncMode = 1;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
2004-07-24 13:36:26 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_vm->_game.version <= 6 && finished)
|
2004-09-28 19:28:59 +00:00
|
|
|
a->runActorTalkScript(a->_talkStopFrame);
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-08 21:59:32 +00:00
|
|
|
|
2009-01-11 06:15:30 +00:00
|
|
|
if ((!ConfMan.getBool("subtitles") && finished) || (finished && _vm->_talkDelay == 0)) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (!(_vm->_game.version == 8 && _vm->VAR(_vm->VAR_HAVE_MSG) == 0))
|
2004-07-16 03:39:23 +00:00
|
|
|
_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
|
|
|
}
|
|
|
|
|
2005-05-11 00:01:44 +00:00
|
|
|
void Sound::startTalkSound(uint32 offset, uint32 b, int mode, Audio::SoundHandle *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-12-23 19:18:20 +00:00
|
|
|
int id = -1;
|
2011-11-02 22:56:45 +00:00
|
|
|
Common::ScopedPtr<ScummFile> file;
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_vm->_game.id == GID_CMI) {
|
2004-01-15 20:39:24 +00:00
|
|
|
_sfxMode |= mode;
|
|
|
|
return;
|
2006-02-20 16:51:30 +00:00
|
|
|
} else if (_vm->_game.id == GID_DIG) {
|
2004-01-20 00:21:24 +00:00
|
|
|
_sfxMode |= mode;
|
2006-02-20 16:51:30 +00:00
|
|
|
if (!(_vm->_game.features & GF_DEMO))
|
2004-01-20 00:21:24 +00:00
|
|
|
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 {
|
2005-11-17 23:41:53 +00:00
|
|
|
warning("startTalkSound: dig demo: unknown room number: %d", offset);
|
2003-11-17 22:21:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-02 22:56:45 +00:00
|
|
|
file.reset(new ScummFile());
|
|
|
|
if (!file)
|
|
|
|
error("startTalkSound: Out of memory");
|
|
|
|
|
2011-11-03 01:32:27 +00:00
|
|
|
sprintf(filename, "audio/%s.%u/%u.voc", roomname, offset, b);
|
2011-11-02 22:56:45 +00:00
|
|
|
if (!_vm->openFile(*file, filename)) {
|
2011-11-03 01:32:27 +00:00
|
|
|
sprintf(filename, "audio/%s_%u/%u.voc", roomname, offset, b);
|
2011-11-02 22:56:45 +00:00
|
|
|
_vm->openFile(*file, filename);
|
2011-05-02 14:49:29 +00:00
|
|
|
}
|
2011-11-02 22:56:45 +00:00
|
|
|
|
|
|
|
if (!file->isOpen()) {
|
2011-11-03 01:32:27 +00:00
|
|
|
sprintf(filename, "%u.%u.voc", offset, b);
|
2011-11-02 22:56:45 +00:00
|
|
|
_vm->openFile(*file, filename);
|
2003-11-17 22:52:21 +00:00
|
|
|
}
|
2011-11-02 22:56:45 +00:00
|
|
|
|
|
|
|
if (!file->isOpen()) {
|
2005-11-17 23:41:53 +00:00
|
|
|
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
|
|
|
|
2011-11-02 22:56:45 +00:00
|
|
|
if (_sfxFilename.empty()) {
|
|
|
|
warning("startTalkSound: SFX file not found");
|
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
|
|
|
// 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.
|
2003-12-26 12:15:23 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (mode == 1 && (_vm->_game.id == GID_TENTACLE || _vm->_game.id == GID_SAMNMAX)) {
|
2004-08-09 00:58:21 +00:00
|
|
|
id = 777777 + _talk_sound_channel;
|
2006-10-21 12:44:10 +00:00
|
|
|
_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;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-24 17:47:51 +00:00
|
|
|
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) {
|
2006-04-04 22:21:10 +00:00
|
|
|
warning("startTalkSound: did not find sound at offset %d", offset);
|
2003-12-24 17:47:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (2 * num != result->num_tags) {
|
2006-04-04 22:21:10 +00:00
|
|
|
warning("startTalkSound: number of tags do not match (%d - %d)", b,
|
2003-12-24 17:47:51 +00:00
|
|
|
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
|
|
|
|
2011-11-02 22:56:45 +00:00
|
|
|
file.reset(new ScummFile());
|
|
|
|
if (!file)
|
|
|
|
error("startTalkSound: Out of memory");
|
|
|
|
|
|
|
|
if (!_vm->openFile(*file, _sfxFilename)) {
|
|
|
|
warning("startTalkSound: could not open sfx file %s", _sfxFilename.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
file->setEnc(_sfxFileEncByte);
|
|
|
|
file->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++)
|
2011-11-02 22:56:45 +00:00
|
|
|
_mouthSyncTimes[i] = file->readUint16BE();
|
|
|
|
|
|
|
|
// Adjust offset to account for the mouth sync times. It is noteworthy
|
|
|
|
// that we do not adjust the size here for compressed streams, since
|
|
|
|
// they only set size to the size of the compressed sound data.
|
|
|
|
offset += num * 2;
|
|
|
|
// TODO: In case we ever set up the size for VOC streams, we should
|
|
|
|
// really check whether the size contains the _mouthSyncTimes.
|
|
|
|
//if (_soundMode == kVOCMode)
|
|
|
|
// size -= num * 2;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-24 17:47:51 +00:00
|
|
|
_mouthSyncTimes[i] = 0xFFFF;
|
|
|
|
_sfxMode |= mode;
|
|
|
|
_curSoundPos = 0;
|
|
|
|
_mouthSyncMode = true;
|
2002-03-06 23:17:16 +00:00
|
|
|
}
|
|
|
|
|
2006-10-21 12:44:10 +00:00
|
|
|
if (!_soundsPaused && _mixer->isReady()) {
|
2006-04-29 22:33:31 +00:00
|
|
|
Audio::AudioStream *input = NULL;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-27 16:24:49 +00:00
|
|
|
switch (_soundMode) {
|
|
|
|
case kMP3Mode:
|
2010-02-03 09:42:11 +00:00
|
|
|
#ifdef USE_MAD
|
2010-04-17 23:57:50 +00:00
|
|
|
{
|
2004-12-27 16:24:49 +00:00
|
|
|
assert(size > 0);
|
2011-11-02 22:56:45 +00:00
|
|
|
input = Audio::makeMP3Stream(new Common::SeekableSubReadStream(file.release(), offset, offset + size, DisposeAfterUse::YES), DisposeAfterUse::YES);
|
2010-04-17 23:57:50 +00:00
|
|
|
}
|
2010-02-03 09:42:11 +00:00
|
|
|
#endif
|
2004-12-27 16:24:49 +00:00
|
|
|
break;
|
|
|
|
case kVorbisMode:
|
2010-02-03 09:42:11 +00:00
|
|
|
#ifdef USE_VORBIS
|
2010-04-17 23:57:50 +00:00
|
|
|
{
|
2004-12-27 16:24:49 +00:00
|
|
|
assert(size > 0);
|
2011-11-02 22:56:45 +00:00
|
|
|
input = Audio::makeVorbisStream(new Common::SeekableSubReadStream(file.release(), offset, offset + size, DisposeAfterUse::YES), DisposeAfterUse::YES);
|
2010-04-17 23:57:50 +00:00
|
|
|
}
|
2010-02-03 09:42:11 +00:00
|
|
|
#endif
|
2004-12-27 16:24:49 +00:00
|
|
|
break;
|
2010-02-03 09:42:40 +00:00
|
|
|
case kFLACMode:
|
2010-02-03 09:42:11 +00:00
|
|
|
#ifdef USE_FLAC
|
2010-04-17 23:57:50 +00:00
|
|
|
{
|
2004-12-27 16:24:49 +00:00
|
|
|
assert(size > 0);
|
2011-11-02 22:56:45 +00:00
|
|
|
input = Audio::makeFLACStream(new Common::SeekableSubReadStream(file.release(), offset, offset + size, DisposeAfterUse::YES), DisposeAfterUse::YES);
|
2010-04-17 23:57:50 +00:00
|
|
|
}
|
2010-02-03 09:42:11 +00:00
|
|
|
#endif
|
2004-12-27 16:24:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-11-02 22:56:45 +00:00
|
|
|
input = Audio::makeVOCStream(file.release(), Audio::FLAG_UNSIGNED, DisposeAfterUse::YES);
|
2006-06-18 06:23:22 +00:00
|
|
|
break;
|
2004-12-27 16:24:49 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-27 16:24:49 +00:00
|
|
|
if (!input) {
|
2005-11-17 23:41:53 +00:00
|
|
|
warning("startSfxSound failed to load sound");
|
2004-12-27 16:24:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-27 16:24:49 +00:00
|
|
|
if (_vm->_imuseDigital) {
|
2008-05-06 03:00:26 +00:00
|
|
|
#ifdef ENABLE_SCUMM_7_8
|
2004-12-27 16:24:49 +00:00
|
|
|
//_vm->_imuseDigital->stopSound(kTalkSoundID);
|
|
|
|
_vm->_imuseDigital->startVoice(kTalkSoundID, input);
|
2005-05-14 22:56:41 +00:00
|
|
|
#endif
|
2004-12-27 16:24:49 +00:00
|
|
|
} else {
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kSpeechSoundType, handle, input, id);
|
2004-12-27 16:24:49 +00:00
|
|
|
}
|
|
|
|
}
|
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) {
|
2008-05-06 03:00:26 +00:00
|
|
|
#ifdef ENABLE_SCUMM_7_8
|
2005-04-04 11:47:38 +00:00
|
|
|
_vm->_imuseDigital->stopSound(kTalkSoundID);
|
2005-05-14 22:56:41 +00:00
|
|
|
#endif
|
2006-02-20 16:51:30 +00:00
|
|
|
} else if (_vm->_game.heversion >= 60) {
|
2005-10-23 13:16:39 +00:00
|
|
|
stopSound(1);
|
2003-12-26 12:15:23 +00:00
|
|
|
} else {
|
2006-10-21 12:44:10 +00:00
|
|
|
_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 {
|
2008-05-06 03:00:26 +00:00
|
|
|
#ifdef ENABLE_SCUMM_7_8
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuseDigital)
|
|
|
|
return (_vm->_imuseDigital->getSoundStatus(sound) != 0);
|
2005-05-14 22:56:41 +00:00
|
|
|
#endif
|
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
|
|
|
|
2006-10-21 12:44:10 +00:00
|
|
|
if (_mixer->isSoundIDActive(sound))
|
2004-09-21 01:07:29 +00:00
|
|
|
return 1;
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
if (isSoundInQueue(sound))
|
|
|
|
return 1;
|
|
|
|
|
2006-09-17 20:36:48 +00:00
|
|
|
if (sound > _vm->_numSounds || !_vm->_res->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
|
|
|
|
2008-05-06 03:00:26 +00:00
|
|
|
#ifdef ENABLE_SCUMM_7_8
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuseDigital)
|
|
|
|
return (_vm->_imuseDigital->getSoundStatus(sound) != 0);
|
2005-05-14 22:56:41 +00:00
|
|
|
#endif
|
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;
|
|
|
|
|
2006-09-17 20:36:48 +00:00
|
|
|
if (!_vm->_res->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
|
|
|
|
2006-10-21 12:44:10 +00:00
|
|
|
if (_mixer->isSoundIDActive(sound))
|
2006-01-14 04:29:30 +00:00
|
|
|
return 1;
|
|
|
|
|
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--) {
|
2004-10-13 07:52:42 +00:00
|
|
|
if (_soundQue2[i].sound == 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
|
|
|
}
|
|
|
|
|
2004-09-02 04:23:13 +00:00
|
|
|
void Sound::stopSound(int sound) {
|
2001-11-05 19:21:49 +00:00
|
|
|
int i;
|
|
|
|
|
2004-09-02 04:23:13 +00:00
|
|
|
if (sound != 0 && sound == _currentCDSound) {
|
2003-06-30 23:18:20 +00:00
|
|
|
_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
|
|
|
}
|
|
|
|
|
2007-02-10 02:05:59 +00:00
|
|
|
if (_vm->_game.version < 7)
|
2006-10-21 12:44:10 +00:00
|
|
|
_mixer->stopID(sound);
|
2003-12-25 13:56:22 +00:00
|
|
|
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_musicEngine)
|
2004-09-02 04:23:13 +00:00
|
|
|
_vm->_musicEngine->stopSound(sound);
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2004-10-13 07:52:42 +00:00
|
|
|
for (i = 0; i < ARRAYSIZE(_soundQue2); i++) {
|
|
|
|
if (_soundQue2[i].sound == sound) {
|
|
|
|
_soundQue2[i].sound = 0;
|
|
|
|
_soundQue2[i].offset = 0;
|
|
|
|
_soundQue2[i].channel = 0;
|
|
|
|
_soundQue2[i].flags = 0;
|
2004-07-14 07:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
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
|
2010-09-18 14:18:48 +00:00
|
|
|
_lastSound = 0;
|
2001-11-05 19:21:49 +00:00
|
|
|
_soundQue2Pos = 0;
|
2004-10-13 07:52:42 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-09-07 19:28:45 +00:00
|
|
|
// Stop all SFX
|
2004-01-08 20:37:26 +00:00
|
|
|
if (!_vm->_imuseDigital) {
|
2006-10-21 12:44:10 +00:00
|
|
|
_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;
|
|
|
|
|
2008-05-06 03:00:26 +00:00
|
|
|
#ifdef ENABLE_SCUMM_7_8
|
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;
|
|
|
|
}
|
2005-05-14 22:56:41 +00:00
|
|
|
#endif
|
2003-01-29 04:00:45 +00:00
|
|
|
|
2003-12-25 13:56:22 +00:00
|
|
|
if (list[0] == -1) {
|
2005-06-04 06:30:35 +00:00
|
|
|
processSound();
|
2003-12-25 15:09:23 +00:00
|
|
|
} else {
|
|
|
|
_soundQue[_soundQuePos++] = num;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-12-25 15:09:23 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-08-09 00:58:21 +00:00
|
|
|
void Sound::talkSound(uint32 a, uint32 b, int mode, int channel) {
|
2007-08-04 05:56:38 +00:00
|
|
|
if (_vm->_game.version >= 5 && ConfMan.getBool("speech_mute"))
|
2005-03-12 00:47:17 +00:00
|
|
|
return;
|
|
|
|
|
2002-09-13 11:59:43 +00:00
|
|
|
if (mode == 1) {
|
|
|
|
_talk_sound_a1 = a;
|
|
|
|
_talk_sound_b1 = b;
|
2004-08-09 00:58:21 +00:00
|
|
|
_talk_sound_channel = channel;
|
2002-09-13 11:59:43 +00:00
|
|
|
} else {
|
|
|
|
_talk_sound_a2 = a;
|
|
|
|
_talk_sound_b2 = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
_talk_sound_mode |= mode;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::setupSound() {
|
2011-11-02 22:56:45 +00:00
|
|
|
setupSfxFile();
|
2004-07-17 05:29:56 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_vm->_game.id == GID_FT) {
|
2011-11-02 22:56:45 +00:00
|
|
|
_vm->VAR(_vm->VAR_VOICE_BUNDLE_LOADED) = _sfxFilename.empty() ? 0 : 1;
|
2005-04-25 05:44:12 +00:00
|
|
|
}
|
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
|
|
|
|
2008-05-06 03:00:26 +00:00
|
|
|
#ifdef ENABLE_SCUMM_7_8
|
2004-01-08 20:37:26 +00:00
|
|
|
if (_vm->_imuseDigital) {
|
|
|
|
_vm->_imuseDigital->pause(pause);
|
2002-10-15 06:53:42 +00:00
|
|
|
}
|
2005-05-14 22:56:41 +00:00
|
|
|
#endif
|
2002-10-15 06:53:42 +00:00
|
|
|
|
2006-10-21 12:44:10 +00:00
|
|
|
_mixer->pauseAll(pause);
|
2004-07-19 10:51:00 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if ((_vm->_game.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
|
|
|
}
|
|
|
|
|
2011-11-02 22:56:45 +00:00
|
|
|
void Sound::setupSfxFile() {
|
2004-04-11 22:20:41 +00:00
|
|
|
struct SoundFileExtensions {
|
|
|
|
const char *ext;
|
|
|
|
SoundMode mode;
|
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-07-26 17:14:57 +00:00
|
|
|
static const SoundFileExtensions extensions[] = {
|
2004-07-26 23:15:01 +00:00
|
|
|
{ "sou", kVOCMode },
|
2010-02-03 09:42:40 +00:00
|
|
|
#ifdef USE_FLAC
|
|
|
|
{ "sof", kFLACMode },
|
|
|
|
#endif
|
|
|
|
#ifdef USE_VORBIS
|
2004-04-11 22:20:41 +00:00
|
|
|
{ "sog", kVorbisMode },
|
2010-02-03 09:42:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_MAD
|
2004-07-26 23:15:01 +00:00
|
|
|
{ "so3", kMP3Mode },
|
2010-02-03 09:42:40 +00:00
|
|
|
#endif
|
2004-04-11 22:20:41 +00:00
|
|
|
{ 0, kVOCMode }
|
|
|
|
};
|
2004-04-10 00:07:58 +00:00
|
|
|
|
2011-11-02 22:56:45 +00:00
|
|
|
ScummFile file;
|
2004-07-26 17:14:57 +00:00
|
|
|
_offsetTable = NULL;
|
2011-11-02 22:56:45 +00:00
|
|
|
_sfxFileEncByte = 0;
|
|
|
|
_sfxFilename.clear();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-01-21 13:01:20 +00:00
|
|
|
/* Try opening the file <baseName>.sou first, e.g. tentacle.sou.
|
2004-04-10 00:07:58 +00:00
|
|
|
* That way, you can keep .sou files for multiple games in the
|
|
|
|
* same directory */
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-04-23 17:33:16 +00:00
|
|
|
Common::String basename[2];
|
2007-02-17 01:21:00 +00:00
|
|
|
Common::String tmp;
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-04-23 17:33:16 +00:00
|
|
|
const char *ptr = strchr(_vm->_filenamePattern.pattern, '.');
|
|
|
|
if (ptr) {
|
|
|
|
basename[0] = Common::String(_vm->_filenamePattern.pattern, ptr - _vm->_filenamePattern.pattern + 1);
|
|
|
|
} else {
|
|
|
|
basename[0] = _vm->_filenamePattern.pattern;
|
|
|
|
basename[0] += '.';
|
2005-09-04 12:42:19 +00:00
|
|
|
}
|
2006-04-23 17:33:16 +00:00
|
|
|
basename[1] = "monster.";
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-02-17 01:23:52 +00:00
|
|
|
if (_vm->_game.heversion >= 60) {
|
2010-04-04 09:36:10 +00:00
|
|
|
if ((_vm->_game.heversion <= 62 && _vm->_game.platform == Common::kPlatformMacintosh) || (_vm->_game.heversion >= 70)) {
|
2007-02-17 01:21:00 +00:00
|
|
|
tmp = _vm->generateFilename(-2);
|
2005-01-29 17:58:47 +00:00
|
|
|
} else {
|
2007-02-17 01:21:00 +00:00
|
|
|
tmp = basename[0] + "tlk";
|
2005-01-29 17:58:47 +00:00
|
|
|
}
|
2005-02-11 03:45:10 +00:00
|
|
|
|
2011-11-02 22:56:45 +00:00
|
|
|
if (file.open(tmp))
|
|
|
|
_sfxFilename = tmp;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2011-11-02 22:56:45 +00:00
|
|
|
if (_vm->_game.heversion <= 74)
|
|
|
|
_sfxFileEncByte = 0x69;
|
|
|
|
|
2004-04-11 22:20:41 +00:00
|
|
|
_soundMode = kVOCMode;
|
2007-02-19 09:46:45 +00:00
|
|
|
} else {
|
2011-11-02 22:56:45 +00:00
|
|
|
for (uint j = 0; j < 2 && !file.isOpen(); ++j) {
|
2007-02-17 01:23:52 +00:00
|
|
|
for (int i = 0; extensions[i].ext; ++i) {
|
|
|
|
tmp = basename[j] + extensions[i].ext;
|
2011-11-02 22:56:45 +00:00
|
|
|
if (_vm->openFile(file, tmp)) {
|
2007-02-17 01:23:52 +00:00
|
|
|
_soundMode = extensions[i].mode;
|
2011-11-02 22:56:45 +00:00
|
|
|
_sfxFilename = tmp;
|
2007-02-17 01:23:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-26 17:14:57 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-07-26 17:14:57 +00:00
|
|
|
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;
|
2011-11-02 22:56:45 +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) {
|
2011-11-02 22:56:45 +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
|
|
|
}
|
2001-11-14 18:40:39 +00:00
|
|
|
}
|
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
bool Sound::isSfxFinished() const {
|
2006-10-21 12:44:10 +00:00
|
|
|
return !_mixer->hasActiveChannelOfType(Audio::Mixer::kSFXSoundType);
|
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() {
|
2007-02-19 21:09:23 +00:00
|
|
|
// This timer interval is based on two scenes: The Monkey Island 1
|
|
|
|
// intro, and the scene in Loom CD where Chaos appears. In both cases
|
|
|
|
// the game plays the scene as two separate sounds, even though both
|
|
|
|
// halves are right next to each other in the CD track. Probably so
|
|
|
|
// that you can hit Escape to skip the first half.
|
|
|
|
//
|
|
|
|
// Make it too low, and the Monkey Island theme will be cut short. Make
|
|
|
|
// it too high, and there will be a nasty "hiccup" just as Chaos
|
|
|
|
// appears.
|
2002-09-21 13:48:03 +00:00
|
|
|
|
2008-12-25 20:53:59 +00:00
|
|
|
_vm->getTimerManager()->removeTimerProc(&cd_timer_handler);
|
2011-08-05 09:15:20 +00:00
|
|
|
_vm->getTimerManager()->installTimerProc(&cd_timer_handler, 100700, _vm, "scummCDtimer");
|
2002-09-21 13:48:03 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Sound::stopCDTimer() {
|
2008-12-25 20:53:59 +00:00
|
|
|
_vm->getTimerManager()->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)
|
2010-06-15 04:13:12 +00:00
|
|
|
g_system->getAudioCDManager()->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
|
2004-09-28 20:19:37 +00:00
|
|
|
// playCD() will block during that delay.
|
2002-09-21 13:48:03 +00:00
|
|
|
startCDTimer();
|
2002-08-29 23:45:15 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Sound::stopCD() {
|
2010-06-15 04:13:12 +00:00
|
|
|
g_system->getAudioCDManager()->stop();
|
2002-08-29 23:45:15 +00:00
|
|
|
}
|
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
int Sound::pollCD() const {
|
2010-06-15 04:13:12 +00:00
|
|
|
return g_system->getAudioCDManager()->isPlaying();
|
2002-08-29 23:45:15 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Sound::updateCD() {
|
2010-06-15 04:13:12 +00:00
|
|
|
g_system->getAudioCDManager()->updateCD();
|
2002-04-17 20:23:45 +00:00
|
|
|
}
|
2002-04-22 11:36:41 +00:00
|
|
|
|
2005-10-21 23:04:58 +00:00
|
|
|
void Sound::saveLoadWithSerializer(Serializer *ser) {
|
2004-08-09 01:07:48 +00:00
|
|
|
static const SaveLoadEntry soundEntries[] = {
|
|
|
|
MKLINE(Sound, _currentCDSound, sleInt16, VER(35)),
|
|
|
|
MKLINE(Sound, _currentMusic, sleInt16, VER(35)),
|
|
|
|
MKEND()
|
|
|
|
};
|
|
|
|
|
2005-10-21 23:04:58 +00:00
|
|
|
ser->saveLoadEntries(this, soundEntries);
|
2004-08-09 01:07:48 +00:00
|
|
|
}
|
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark --- Sound resource handling ---
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: The way we handle sound/music resources really is one huge hack.
|
2005-07-30 21:11:48 +00:00
|
|
|
* We probably should reconsider how we do this, and maybe come up with a
|
2004-12-17 22:27:15 +00:00
|
|
|
* better/cleaner solution. Even if we keep the existing code, it really
|
|
|
|
* could stand a thorough cleanup!
|
|
|
|
*/
|
|
|
|
|
2011-05-13 12:02:53 +00:00
|
|
|
int ScummEngine::readSoundResource(ResId idx) {
|
2004-12-17 22:27:15 +00:00
|
|
|
uint32 pos, total_size, size, tag, basetag, max_total_size;
|
|
|
|
int pri, best_pri;
|
|
|
|
uint32 best_size = 0, best_offs = 0;
|
2005-05-25 19:40:30 +00:00
|
|
|
byte *ptr;
|
2004-12-17 22:27:15 +00:00
|
|
|
|
|
|
|
debugC(DEBUG_RESOURCE, "readSoundResource(%d)", idx);
|
|
|
|
|
|
|
|
pos = 0;
|
|
|
|
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->readUint32LE();
|
|
|
|
max_total_size = _fileHandle->readUint32BE() - 8;
|
2006-02-25 02:12:58 +00:00
|
|
|
basetag = _fileHandle->readUint32BE();
|
2005-03-30 21:59:12 +00:00
|
|
|
total_size = _fileHandle->readUint32BE();
|
2004-12-17 22:27:15 +00:00
|
|
|
|
2006-02-25 02:12:58 +00:00
|
|
|
debugC(DEBUG_RESOURCE, " basetag: %s, total_size=%d", tag2str(basetag), total_size);
|
2004-12-17 22:27:15 +00:00
|
|
|
|
2005-05-25 19:40:30 +00:00
|
|
|
switch (basetag) {
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('M','I','D','I'):
|
|
|
|
case MKTAG('i','M','U','S'):
|
2011-08-05 12:33:42 +00:00
|
|
|
if (_sound->_musicType != MDT_PCSPK && _sound->_musicType != MDT_PCJR) {
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(-8, SEEK_CUR);
|
2007-12-24 14:20:53 +00:00
|
|
|
_fileHandle->read(_res->createResource(rtSound, idx, total_size + 8), total_size + 8);
|
2004-12-17 22:27:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2005-05-25 19:40:30 +00:00
|
|
|
break;
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('S','O','U',' '):
|
2004-12-17 22:27:15 +00:00
|
|
|
best_pri = -1;
|
|
|
|
while (pos < total_size) {
|
2006-02-25 02:12:58 +00:00
|
|
|
tag = _fileHandle->readUint32BE();
|
2005-03-30 21:59:12 +00:00
|
|
|
size = _fileHandle->readUint32BE() + 8;
|
2004-12-17 22:27:15 +00:00
|
|
|
pos += size;
|
|
|
|
|
|
|
|
pri = -1;
|
|
|
|
|
|
|
|
switch (tag) {
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('T','O','W','S'):
|
2004-12-17 22:27:15 +00:00
|
|
|
pri = 16;
|
|
|
|
break;
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('S','B','L',' '):
|
2004-12-17 22:27:15 +00:00
|
|
|
pri = 15;
|
|
|
|
break;
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('A','D','L',' '):
|
2004-12-17 22:27:15 +00:00
|
|
|
pri = 1;
|
2011-08-05 12:33:42 +00:00
|
|
|
if (_sound->_musicType == MDT_ADLIB || _sound->_musicType == MDT_TOWNS)
|
2004-12-17 22:27:15 +00:00
|
|
|
pri = 10;
|
|
|
|
break;
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('A','M','I',' '):
|
2004-12-17 22:27:15 +00:00
|
|
|
pri = 3;
|
|
|
|
break;
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('R','O','L',' '):
|
2004-12-17 22:27:15 +00:00
|
|
|
pri = 3;
|
|
|
|
if (_native_mt32)
|
|
|
|
pri = 5;
|
|
|
|
break;
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('G','M','D',' '):
|
2004-12-17 22:27:15 +00:00
|
|
|
pri = 4;
|
|
|
|
break;
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('M','A','C',' '): // Occurs in Mac MI2, FOA
|
2004-12-17 22:27:15 +00:00
|
|
|
pri = 2;
|
|
|
|
break;
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('S','P','K',' '):
|
2004-12-17 22:27:15 +00:00
|
|
|
pri = -1;
|
2011-08-05 12:33:42 +00:00
|
|
|
if (_sound->_musicType == MDT_PCSPK || _sound->_musicType == MDT_PCJR)
|
2011-07-08 02:43:45 +00:00
|
|
|
pri = 11;
|
2004-12-17 22:27:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-08 18:15:24 +00:00
|
|
|
// We only allow SPK resources for PC Speaker and PCJr here
|
2011-07-16 22:08:52 +00:00
|
|
|
// since other resource would sound horribly with their output
|
|
|
|
// drivers.
|
2011-08-08 18:15:24 +00:00
|
|
|
if ((_sound->_musicType == MDT_PCSPK || _sound->_musicType == MDT_PCJR) && pri != 11)
|
2004-12-17 22:27:15 +00:00
|
|
|
pri = -1;
|
|
|
|
|
2011-09-17 19:13:14 +00:00
|
|
|
// We only allow ADL, SBL and TOWS resources when AdLib
|
|
|
|
// or FM-Towns is used as primary audio output. This fixes some
|
|
|
|
// odd sounds when Indy and Sophia leave Atlantis with the
|
|
|
|
// submarine in Indy4. (Easy to check with bootparam 4061 in
|
|
|
|
// the CD version). It seems the game only contains a ROL resource
|
|
|
|
// for sound id 60. Formerly we tried to play that via the AdLib
|
|
|
|
// or FM-Towns audio driver resulting in strange noises. Now we
|
|
|
|
// behave like the original did.
|
2011-08-19 12:39:35 +00:00
|
|
|
// We make an exception for Macintosh, which uses priority 2 for
|
|
|
|
// its sound resources, and Amiga games, which feature only ROL
|
|
|
|
// resources, since we are a doing Midi -> AdLib conversion for
|
|
|
|
// these.
|
2012-09-26 02:17:31 +00:00
|
|
|
if ((_sound->_musicType == MDT_ADLIB || _sound->_musicType == MDT_TOWNS) && pri != 16
|
2011-09-17 19:13:14 +00:00
|
|
|
&& pri != 15 && pri != 10 && pri != 2 && _game.platform != Common::kPlatformAmiga)
|
2011-07-17 00:27:33 +00:00
|
|
|
pri = -1;
|
|
|
|
|
2006-02-25 02:12:58 +00:00
|
|
|
debugC(DEBUG_RESOURCE, " tag: %s, total_size=%d, pri=%d", tag2str(tag), size, pri);
|
2004-12-17 22:27:15 +00:00
|
|
|
|
|
|
|
if (pri > best_pri) {
|
|
|
|
best_pri = pri;
|
|
|
|
best_size = size;
|
2005-03-30 21:59:12 +00:00
|
|
|
best_offs = _fileHandle->pos();
|
2004-12-17 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(size - 8, SEEK_CUR);
|
2004-12-17 22:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (best_pri != -1) {
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(best_offs - 8, SEEK_SET);
|
2007-12-24 14:20:53 +00:00
|
|
|
ptr = _res->createResource(rtSound, idx, best_size);
|
2005-05-25 19:40:30 +00:00
|
|
|
_fileHandle->read(ptr, best_size);
|
2005-10-23 14:21:20 +00:00
|
|
|
//dumpResource("sound-", idx, ptr);
|
2004-12-17 22:27:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2005-05-25 19:40:30 +00:00
|
|
|
break;
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('M','a','c','0'):
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(-12, SEEK_CUR);
|
|
|
|
total_size = _fileHandle->readUint32BE() - 8;
|
2012-11-11 12:56:06 +00:00
|
|
|
ptr = _res->createResource(rtSound, idx, total_size);
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->read(ptr, total_size);
|
2005-10-23 14:21:20 +00:00
|
|
|
//dumpResource("sound-", idx, ptr);
|
2004-12-17 22:27:15 +00:00
|
|
|
return 1;
|
2005-05-25 19:40:30 +00:00
|
|
|
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('M','a','c','1'):
|
|
|
|
case MKTAG('R','I','F','F'):
|
|
|
|
case MKTAG('T','A','L','K'):
|
|
|
|
case MKTAG('D','I','G','I'):
|
|
|
|
case MKTAG('C','r','e','a'):
|
2006-02-25 02:12:58 +00:00
|
|
|
case 0x460e200d: // WORKAROUND bug # 1311447
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(-12, SEEK_CUR);
|
|
|
|
total_size = _fileHandle->readUint32BE();
|
2007-12-24 14:20:53 +00:00
|
|
|
ptr = _res->createResource(rtSound, idx, total_size);
|
2005-10-23 14:21:20 +00:00
|
|
|
_fileHandle->read(ptr, total_size - 8);
|
|
|
|
//dumpResource("sound-", idx, ptr);
|
2004-12-17 22:27:15 +00:00
|
|
|
return 1;
|
2005-05-25 19:40:30 +00:00
|
|
|
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('H','S','H','D'):
|
2006-01-05 11:38:45 +00:00
|
|
|
// HE sound type without SOUN header
|
|
|
|
_fileHandle->seek(-16, SEEK_CUR);
|
|
|
|
total_size = max_total_size + 8;
|
2007-12-24 14:20:53 +00:00
|
|
|
ptr = _res->createResource(rtSound, idx, total_size);
|
2006-01-06 05:40:40 +00:00
|
|
|
_fileHandle->read(ptr, total_size);
|
2006-01-05 11:38:45 +00:00
|
|
|
//dumpResource("sound-", idx, ptr);
|
|
|
|
return 1;
|
|
|
|
|
2011-04-12 14:53:15 +00:00
|
|
|
case MKTAG('F','M','U','S'): {
|
2004-12-17 22:27:15 +00:00
|
|
|
// Used in 3DO version of puttputt joins the parade and probably others
|
|
|
|
// Specifies a separate file to be used for music from what I gather.
|
|
|
|
int tmpsize;
|
2005-05-10 22:56:25 +00:00
|
|
|
Common::File dmuFile;
|
2004-12-17 22:27:15 +00:00
|
|
|
char buffer[128];
|
|
|
|
debugC(DEBUG_SOUND, "Found base tag FMUS in sound %d, size %d", idx, total_size);
|
2005-03-30 21:59:12 +00:00
|
|
|
debugC(DEBUG_SOUND, "It was at position %d", _fileHandle->pos());
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(4, SEEK_CUR);
|
2004-12-17 22:27:15 +00:00
|
|
|
// HSHD size
|
2005-03-30 21:59:12 +00:00
|
|
|
tmpsize = _fileHandle->readUint32BE();
|
2004-12-17 22:27:15 +00:00
|
|
|
// skip to size part of the SDAT block
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(tmpsize - 4, SEEK_CUR);
|
2004-12-17 22:27:15 +00:00
|
|
|
// SDAT size
|
2005-03-30 21:59:12 +00:00
|
|
|
tmpsize = _fileHandle->readUint32BE();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
// SDAT contains name of file we want
|
2007-12-07 23:39:19 +00:00
|
|
|
_fileHandle->read(buffer, MIN(128, tmpsize - 8));
|
|
|
|
// files seem to be 11 chars (8.3)
|
|
|
|
char *p = (char *)memchr(buffer, '.', 12);
|
|
|
|
if (!p) p = &buffer[8];
|
|
|
|
strcpy(p, ".dmu");
|
2004-12-17 22:27:15 +00:00
|
|
|
debugC(DEBUG_SOUND, "FMUS file %s", buffer);
|
2007-12-07 23:39:19 +00:00
|
|
|
|
|
|
|
if (!dmuFile.open(buffer)) {
|
|
|
|
error("Can't open music file %s", buffer);
|
2011-05-13 12:48:01 +00:00
|
|
|
_res->_types[rtSound][idx]._roomoffs = RES_INVALID_OFFSET;
|
2004-12-17 22:27:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dmuFile.seek(4, SEEK_SET);
|
|
|
|
total_size = dmuFile.readUint32BE();
|
|
|
|
debugC(DEBUG_SOUND, "dmu file size %d", total_size);
|
|
|
|
dmuFile.seek(-8, SEEK_CUR);
|
2007-12-24 14:20:53 +00:00
|
|
|
dmuFile.read(_res->createResource(rtSound, idx, total_size), total_size);
|
2004-12-17 22:27:15 +00:00
|
|
|
dmuFile.close();
|
2005-05-25 19:40:30 +00:00
|
|
|
}
|
2004-12-17 22:27:15 +00:00
|
|
|
return 1;
|
2005-05-25 19:40:30 +00:00
|
|
|
|
|
|
|
default:
|
2006-02-25 02:12:58 +00:00
|
|
|
if (SWAP_BYTES_32(basetag) == max_total_size) {
|
2005-05-25 19:40:30 +00:00
|
|
|
_fileHandle->seek(-12, SEEK_CUR);
|
|
|
|
total_size = _fileHandle->readUint32BE();
|
|
|
|
_fileHandle->seek(-8, SEEK_CUR);
|
2007-12-24 14:20:53 +00:00
|
|
|
ptr = _res->createResource(rtSound, idx, total_size);
|
2005-10-23 14:21:20 +00:00
|
|
|
_fileHandle->read(ptr, total_size);
|
|
|
|
//dumpResource("sound-", idx, ptr);
|
2005-05-25 19:40:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2006-02-25 02:12:58 +00:00
|
|
|
error("Unrecognized base tag 0x%08x in sound %d", basetag, idx);
|
2004-12-17 22:27:15 +00:00
|
|
|
}
|
2011-05-13 12:48:01 +00:00
|
|
|
_res->_types[rtSound][idx]._roomoffs = RES_INVALID_OFFSET;
|
2004-12-17 22:27:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-25 00:13:32 +00:00
|
|
|
// AdLib MIDI-SYSEX to set MIDI instruments for small header games.
|
2009-05-26 11:30:21 +00:00
|
|
|
static const byte ADLIB_INSTR_MIDI_HACK[95] = {
|
2004-12-17 22:27:15 +00:00
|
|
|
0x00, 0xf0, 0x14, 0x7d, 0x00, // sysex 00: part on/off
|
|
|
|
0x00, 0x00, 0x03, // part/channel (offset 5)
|
2005-07-30 21:11:48 +00:00
|
|
|
0x00, 0x00, 0x07, 0x0f, 0x00, 0x00, 0x08, 0x00,
|
2004-12-17 22:27:15 +00:00
|
|
|
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0xf7,
|
|
|
|
0x00, 0xf0, 0x41, 0x7d, 0x10, // sysex 16: set instrument
|
|
|
|
0x00, 0x01, // part/channel (offset 28)
|
2005-07-30 21:11:48 +00:00
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
2004-12-17 22:27:15 +00:00
|
|
|
0x00, 0x00, 0xf7,
|
|
|
|
0x00, 0xb0, 0x07, 0x64 // Controller 7 = 100 (offset 92)
|
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
static const byte map_param[7] = {
|
|
|
|
0, 2, 3, 4, 8, 9, 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const byte freq2note[128] = {
|
2005-07-30 21:11:48 +00:00
|
|
|
/*128*/ 6, 6, 6, 6,
|
2004-12-17 22:27:15 +00:00
|
|
|
/*132*/ 7, 7, 7, 7, 7, 7, 7,
|
|
|
|
/*139*/ 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
|
|
|
/*148*/ 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
|
|
|
/*157*/ 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
|
|
|
/*166*/ 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
|
|
|
|
/*176*/ 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
|
|
|
|
/*186*/ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
|
|
|
|
/*197*/ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
|
|
|
|
/*209*/ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
|
|
|
/*222*/ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
|
|
|
|
/*235*/ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17,
|
|
|
|
/*249*/ 18, 18, 18, 18, 18, 18, 18
|
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
static const uint16 num_steps_table[] = {
|
|
|
|
1, 2, 4, 5,
|
|
|
|
6, 7, 8, 9,
|
|
|
|
10, 12, 14, 16,
|
|
|
|
18, 21, 24, 30,
|
|
|
|
36, 50, 64, 82,
|
|
|
|
100, 136, 160, 192,
|
|
|
|
240, 276, 340, 460,
|
|
|
|
600, 860, 1200, 1600
|
|
|
|
};
|
|
|
|
|
2006-09-09 17:21:19 +00:00
|
|
|
static int convert_extraflags(byte * ptr, byte * src_ptr) {
|
2004-12-17 22:27:15 +00:00
|
|
|
int flags = src_ptr[0];
|
|
|
|
|
|
|
|
int t1, t2, t3, t4, time;
|
|
|
|
int v1, v2, v3;
|
|
|
|
|
|
|
|
if (!(flags & 0x80))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
t1 = (src_ptr[1] & 0xf0) >> 3;
|
|
|
|
t2 = (src_ptr[2] & 0xf0) >> 3;
|
|
|
|
t3 = (src_ptr[3] & 0xf0) >> 3 | (flags & 0x40 ? 0x80 : 0);
|
|
|
|
t4 = (src_ptr[3] & 0x0f) << 1;
|
|
|
|
v1 = (src_ptr[1] & 0x0f);
|
|
|
|
v2 = (src_ptr[2] & 0x0f);
|
|
|
|
v3 = 31;
|
|
|
|
if ((flags & 0x7) == 0) {
|
|
|
|
v1 = v1 + 31 + 8;
|
|
|
|
v2 = v2 + 31 + 8;
|
|
|
|
} else {
|
|
|
|
v1 = v1 * 2 + 31;
|
|
|
|
v2 = v2 * 2 + 31;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
/* flags a */
|
|
|
|
if ((flags & 0x7) == 6)
|
|
|
|
ptr[0] = 0;
|
|
|
|
else {
|
|
|
|
ptr[0] = (flags >> 4) & 0xb;
|
|
|
|
ptr[1] = map_param[flags & 0x7];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* extra a */
|
|
|
|
ptr[2] = 0;
|
|
|
|
ptr[3] = 0;
|
|
|
|
ptr[4] = t1 >> 4;
|
|
|
|
ptr[5] = t1 & 0xf;
|
|
|
|
ptr[6] = v1 >> 4;
|
|
|
|
ptr[7] = v1 & 0xf;
|
|
|
|
ptr[8] = t2 >> 4;
|
|
|
|
ptr[9] = t2 & 0xf;
|
|
|
|
ptr[10] = v2 >> 4;
|
|
|
|
ptr[11] = v2 & 0xf;
|
|
|
|
ptr[12] = t3 >> 4;
|
|
|
|
ptr[13] = t3 & 0xf;
|
|
|
|
ptr[14] = t4 >> 4;
|
|
|
|
ptr[15] = t4 & 0xf;
|
|
|
|
ptr[16] = v3 >> 4;
|
|
|
|
ptr[17] = v3 & 0xf;
|
|
|
|
|
|
|
|
time = num_steps_table[t1] + num_steps_table[t2]
|
|
|
|
+ num_steps_table[t3 & 0x7f] + num_steps_table[t4];
|
|
|
|
if (flags & 0x20) {
|
2005-07-30 21:11:48 +00:00
|
|
|
int playtime = ((src_ptr[4] >> 4) & 0xf) * 118 +
|
2004-12-17 22:27:15 +00:00
|
|
|
(src_ptr[4] & 0xf) * 8;
|
|
|
|
if (playtime > time)
|
|
|
|
time = playtime;
|
|
|
|
}
|
|
|
|
/*
|
2005-07-30 21:11:48 +00:00
|
|
|
time = ((src_ptr[4] >> 4) & 0xf) * 118 +
|
2004-12-17 22:27:15 +00:00
|
|
|
(src_ptr[4] & 0xf) * 8;
|
|
|
|
*/
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define kMIDIHeaderSize 46
|
2006-09-09 17:21:19 +00:00
|
|
|
static byte *writeMIDIHeader(byte *ptr, const char *type, int ppqn, int total_size) {
|
2004-12-17 22:27:15 +00:00
|
|
|
uint32 dw = TO_BE_32(total_size);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
memcpy(ptr, type, 4); ptr += 4;
|
|
|
|
memcpy(ptr, &dw, 4); ptr += 4;
|
|
|
|
memcpy(ptr, "MDhd", 4); ptr += 4;
|
|
|
|
ptr[0] = 0; ptr[1] = 0; ptr[2] = 0; ptr[3] = 8;
|
|
|
|
ptr += 4;
|
2009-12-23 13:34:19 +00:00
|
|
|
memset(ptr, 0, 8); ptr += 8;
|
2004-12-17 22:27:15 +00:00
|
|
|
memcpy(ptr, "MThd", 4); ptr += 4;
|
|
|
|
ptr[0] = 0; ptr[1] = 0; ptr[2] = 0; ptr[3] = 6;
|
|
|
|
ptr += 4;
|
|
|
|
ptr[0] = 0; ptr[1] = 0; ptr[2] = 0; ptr[3] = 1; // MIDI format 0 with 1 track
|
|
|
|
ptr += 4;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
*ptr++ = ppqn >> 8;
|
|
|
|
*ptr++ = ppqn & 0xFF;
|
|
|
|
|
|
|
|
memcpy(ptr, "MTrk", 4); ptr += 4;
|
|
|
|
memcpy(ptr, &dw, 4); ptr += 4;
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2006-09-09 17:21:19 +00:00
|
|
|
static byte *writeVLQ(byte *ptr, int value) {
|
2004-12-17 22:27:15 +00:00
|
|
|
if (value > 0x7f) {
|
|
|
|
if (value > 0x3fff) {
|
|
|
|
*ptr++ = (value >> 14) | 0x80;
|
|
|
|
value &= 0x3fff;
|
|
|
|
}
|
|
|
|
*ptr++ = (value >> 7) | 0x80;
|
|
|
|
value &= 0x7f;
|
|
|
|
}
|
|
|
|
*ptr++ = value;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2011-05-13 12:02:53 +00:00
|
|
|
static void convertADResource(ResourceManager *res, const GameSettings& game, ResId idx, byte *src_ptr, int size) {
|
2004-12-17 22:27:15 +00:00
|
|
|
// We will ignore the PPQN in the original resource, because
|
|
|
|
// it's invalid anyway. We use a constant PPQN of 480.
|
|
|
|
const int ppqn = 480;
|
|
|
|
uint32 dw;
|
|
|
|
int i, ch;
|
|
|
|
byte *ptr;
|
|
|
|
int total_size = kMIDIHeaderSize + 7 + 8 * sizeof(ADLIB_INSTR_MIDI_HACK) + size;
|
|
|
|
total_size += 24; // Up to 24 additional bytes are needed for the jump sysex
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-12-24 14:20:53 +00:00
|
|
|
ptr = res->createResource(rtSound, idx, total_size);
|
2004-12-17 22:27:15 +00:00
|
|
|
|
|
|
|
src_ptr += 2;
|
|
|
|
size -= 2;
|
|
|
|
|
|
|
|
// 0x80 marks a music resource. Otherwise it's a SFX
|
|
|
|
if (*src_ptr == 0x80) {
|
|
|
|
byte ticks, play_once;
|
|
|
|
byte num_instr;
|
|
|
|
byte *channel, *instr, *track;
|
|
|
|
|
|
|
|
ptr = writeMIDIHeader(ptr, "ADL ", ppqn, total_size);
|
|
|
|
|
|
|
|
// The "speed" of the song
|
|
|
|
ticks = *(src_ptr + 1);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
// Flag that tells us whether we should loop the song (0) or play it only once (1)
|
|
|
|
play_once = *(src_ptr + 2);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
// Number of instruments used
|
|
|
|
num_instr = *(src_ptr + 8); // Normally 8
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
// copy the pointer to instrument data
|
|
|
|
channel = src_ptr + 9;
|
|
|
|
instr = src_ptr + 0x11;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
// skip over the rest of the header and copy the MIDI data into a buffer
|
|
|
|
src_ptr += 0x11 + 8 * 16;
|
|
|
|
size -= 0x11 + 8 * 16;
|
|
|
|
|
|
|
|
track = src_ptr;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
|
|
|
// Convert the ticks into a MIDI tempo.
|
2004-12-17 22:27:15 +00:00
|
|
|
// Unfortunate LOOM and INDY3 have different interpretation
|
|
|
|
// of the ticks value.
|
2006-09-09 17:21:19 +00:00
|
|
|
if (game.id == GID_INDY3) {
|
2004-12-17 22:27:15 +00:00
|
|
|
// Note: since we fix ppqn at 480, ppqn/473 is almost 1
|
|
|
|
dw = 500000 * 256 / 473 * ppqn / ticks;
|
2006-09-09 17:21:19 +00:00
|
|
|
} else if (game.id == GID_LOOM && game.version == 3) {
|
2004-12-17 22:27:15 +00:00
|
|
|
dw = 500000 * ppqn / 4 / ticks;
|
|
|
|
} else {
|
|
|
|
dw = 500000 * 256 / ticks;
|
|
|
|
}
|
2009-07-03 10:40:49 +00:00
|
|
|
debugC(DEBUG_SOUND, " ticks = %d, speed = %d", ticks, dw);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
// Write a tempo change Meta event
|
|
|
|
memcpy(ptr, "\x00\xFF\x51\x03", 4); ptr += 4;
|
|
|
|
*ptr++ = (byte)((dw >> 16) & 0xFF);
|
|
|
|
*ptr++ = (byte)((dw >> 8) & 0xFF);
|
|
|
|
*ptr++ = (byte)(dw & 0xFF);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
// Copy our hardcoded instrument table into it
|
|
|
|
// Then, convert the instrument table as given in this song resource
|
|
|
|
// And write it *over* the hardcoded table.
|
|
|
|
// Note: we deliberately.
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
/* now fill in the instruments */
|
|
|
|
for (i = 0; i < num_instr; i++) {
|
|
|
|
ch = channel[i] - 1;
|
|
|
|
if (ch < 0 || ch > 15)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (instr[i*16 + 13])
|
2005-08-14 01:41:52 +00:00
|
|
|
debugC(DEBUG_SOUND, "Sound %d instrument %d uses percussion", idx, i);
|
2004-12-17 22:27:15 +00:00
|
|
|
|
|
|
|
debugC(DEBUG_SOUND, "Sound %d: instrument %d on channel %d.", idx, i, ch);
|
|
|
|
|
|
|
|
memcpy(ptr, ADLIB_INSTR_MIDI_HACK, sizeof(ADLIB_INSTR_MIDI_HACK));
|
|
|
|
|
|
|
|
ptr[5] += ch;
|
|
|
|
ptr[28] += ch;
|
|
|
|
ptr[92] += ch;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* mod_characteristics */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 0] = (instr[i * 16 + 3] >> 4) & 0xf;
|
|
|
|
ptr[30 + 1] = instr[i * 16 + 3] & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* mod_scalingOutputLevel */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 2] = (instr[i * 16 + 4] >> 4) & 0xf;
|
|
|
|
ptr[30 + 3] = instr[i * 16 + 4] & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* mod_attackDecay */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 4] = ((~instr[i * 16 + 5]) >> 4) & 0xf;
|
|
|
|
ptr[30 + 5] = (~instr[i * 16 + 5]) & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* mod_sustainRelease */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 6] = ((~instr[i * 16 + 6]) >> 4) & 0xf;
|
|
|
|
ptr[30 + 7] = (~instr[i * 16 + 6]) & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* mod_waveformSelect */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 8] = (instr[i * 16 + 7] >> 4) & 0xf;
|
|
|
|
ptr[30 + 9] = instr[i * 16 + 7] & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* car_characteristic */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 10] = (instr[i * 16 + 8] >> 4) & 0xf;
|
|
|
|
ptr[30 + 11] = instr[i * 16 + 8] & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* car_scalingOutputLevel */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 12] = (instr[i * 16 + 9] >> 4) & 0xf;
|
|
|
|
ptr[30 + 13] = instr[i * 16 + 9] & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* car_attackDecay */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 14] = ((~instr[i * 16 + 10]) >> 4) & 0xf;
|
|
|
|
ptr[30 + 15] = (~instr[i * 16 + 10]) & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* car_sustainRelease */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 16] = ((~instr[i * 16 + 11]) >> 4) & 0xf;
|
|
|
|
ptr[30 + 17] = (~instr[i * 16 + 11]) & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* car_waveFormSelect */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 18] = (instr[i * 16 + 12] >> 4) & 0xf;
|
|
|
|
ptr[30 + 19] = instr[i * 16 + 12] & 0xf;
|
|
|
|
|
|
|
|
/* feedback */
|
|
|
|
ptr[30 + 20] = (instr[i * 16 + 2] >> 4) & 0xf;
|
|
|
|
ptr[30 + 21] = instr[i * 16 + 2] & 0xf;
|
|
|
|
ptr += sizeof(ADLIB_INSTR_MIDI_HACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
// There is a constant delay of ppqn/3 before the music starts.
|
|
|
|
if (ppqn / 3 >= 128)
|
2010-06-08 20:29:33 +00:00
|
|
|
*ptr++ = ((ppqn / 3) >> 7) | 0x80;
|
2004-12-17 22:27:15 +00:00
|
|
|
*ptr++ = ppqn / 3 & 0x7f;
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
// Now copy the actual music data
|
2004-12-17 22:27:15 +00:00
|
|
|
memcpy(ptr, track, size);
|
|
|
|
ptr += size;
|
|
|
|
|
|
|
|
if (!play_once) {
|
|
|
|
// The song is meant to be looped. We achieve this by inserting just
|
|
|
|
// before the song end a jump to the song start. More precisely we abuse
|
|
|
|
// a S&M sysex, "maybe_jump" to achieve this effect. We could also
|
|
|
|
// use a set_loop sysex, but it's a bit longer, a little more complicated,
|
|
|
|
// and has no advantage either.
|
|
|
|
|
|
|
|
// First, find the track end
|
|
|
|
byte *end = ptr;
|
|
|
|
ptr -= size;
|
|
|
|
for (; ptr < end; ptr++) {
|
|
|
|
if (*ptr == 0xff && *(ptr + 1) == 0x2f)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(ptr < end);
|
|
|
|
|
|
|
|
// Now insert the jump. The jump offset is measured in ticks.
|
|
|
|
// We have ppqn/3 ticks before the first note.
|
|
|
|
|
|
|
|
const int jump_offset = ppqn / 3;
|
|
|
|
memcpy(ptr, "\xf0\x13\x7d\x30\00", 5); ptr += 5; // maybe_jump
|
|
|
|
memcpy(ptr, "\x00\x00", 2); ptr += 2; // cmd -> 0 means always jump
|
|
|
|
memcpy(ptr, "\x00\x00\x00\x00", 4); ptr += 4; // track -> there is only one track, 0
|
|
|
|
memcpy(ptr, "\x00\x00\x00\x01", 4); ptr += 4; // beat -> for now, 1 (first beat)
|
|
|
|
// Ticks
|
|
|
|
*ptr++ = (byte)((jump_offset >> 12) & 0x0F);
|
|
|
|
*ptr++ = (byte)((jump_offset >> 8) & 0x0F);
|
|
|
|
*ptr++ = (byte)((jump_offset >> 4) & 0x0F);
|
|
|
|
*ptr++ = (byte)(jump_offset & 0x0F);
|
|
|
|
memcpy(ptr, "\x00\xf7", 2); ptr += 2; // sysex end marker
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* This is a sfx resource. First parse it quickly to find the parallel
|
|
|
|
* tracks.
|
|
|
|
*/
|
|
|
|
ptr = writeMIDIHeader(ptr, "ASFX", ppqn, total_size);
|
|
|
|
|
|
|
|
byte current_instr[3][14];
|
|
|
|
int current_note[3];
|
|
|
|
int track_time[3];
|
|
|
|
byte *track_data[3];
|
|
|
|
|
|
|
|
int track_ctr = 0;
|
|
|
|
byte chunk_type = 0;
|
|
|
|
int delay, delay2, olddelay;
|
|
|
|
|
|
|
|
// Write a tempo change Meta event
|
|
|
|
// 473 / 4 Hz, convert to micro seconds.
|
|
|
|
dw = 1000000 * ppqn * 4 / 473;
|
|
|
|
memcpy(ptr, "\x00\xFF\x51\x03", 4); ptr += 4;
|
|
|
|
*ptr++ = (byte)((dw >> 16) & 0xFF);
|
|
|
|
*ptr++ = (byte)((dw >> 8) & 0xFF);
|
|
|
|
*ptr++ = (byte)(dw & 0xFF);
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
track_time[i] = -1;
|
|
|
|
current_note[i] = -1;
|
|
|
|
}
|
|
|
|
while (size > 0) {
|
|
|
|
assert(track_ctr < 3);
|
|
|
|
track_data[track_ctr] = src_ptr;
|
|
|
|
track_time[track_ctr] = 0;
|
|
|
|
track_ctr++;
|
|
|
|
while (size > 0) {
|
|
|
|
chunk_type = *(src_ptr);
|
|
|
|
if (chunk_type == 1) {
|
|
|
|
src_ptr += 15;
|
|
|
|
size -= 15;
|
|
|
|
} else if (chunk_type == 2) {
|
|
|
|
src_ptr += 11;
|
|
|
|
size -= 11;
|
|
|
|
} else if (chunk_type == 0x80) {
|
|
|
|
src_ptr ++;
|
|
|
|
size --;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chunk_type == 0xff)
|
|
|
|
break;
|
|
|
|
src_ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int curtime = 0;
|
|
|
|
for (;;) {
|
|
|
|
int mintime = -1;
|
|
|
|
ch = -1;
|
|
|
|
for (i = 0; i < 3; i++) {
|
2005-07-30 21:11:48 +00:00
|
|
|
if (track_time[i] >= 0 &&
|
2004-12-17 22:27:15 +00:00
|
|
|
(mintime == -1 || mintime > track_time[i])) {
|
|
|
|
mintime = track_time[i];
|
|
|
|
ch = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mintime < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
src_ptr = track_data[ch];
|
|
|
|
chunk_type = *src_ptr;
|
|
|
|
|
|
|
|
if (current_note[ch] >= 0) {
|
|
|
|
delay = mintime - curtime;
|
|
|
|
curtime = mintime;
|
|
|
|
ptr = writeVLQ(ptr, delay);
|
|
|
|
*ptr++ = 0x80 + ch; // key off channel;
|
|
|
|
*ptr++ = current_note[ch];
|
|
|
|
*ptr++ = 0;
|
|
|
|
current_note[ch] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (chunk_type) {
|
|
|
|
case 1:
|
|
|
|
/* Instrument definition */
|
|
|
|
memcpy(current_instr[ch], src_ptr + 1, 14);
|
|
|
|
src_ptr += 15;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
/* tone/parammodulation */
|
2005-07-30 21:11:48 +00:00
|
|
|
memcpy(ptr, ADLIB_INSTR_MIDI_HACK,
|
2004-12-17 22:27:15 +00:00
|
|
|
sizeof(ADLIB_INSTR_MIDI_HACK));
|
|
|
|
|
|
|
|
ptr[5] += ch;
|
|
|
|
ptr[28] += ch;
|
|
|
|
ptr[92] += ch;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* mod_characteristic */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 0] = (current_instr[ch][3] >> 4) & 0xf;
|
|
|
|
ptr[30 + 1] = current_instr[ch][3] & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* mod_scalingOutputLevel */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 2] = (current_instr[ch][4] >> 4) & 0xf;
|
|
|
|
ptr[30 + 3] = current_instr[ch][4] & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* mod_attackDecay */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 4] = ((~current_instr[ch][5]) >> 4) & 0xf;
|
|
|
|
ptr[30 + 5] = (~current_instr[ch][5]) & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* mod_sustainRelease */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 6] = ((~current_instr[ch][6]) >> 4) & 0xf;
|
|
|
|
ptr[30 + 7] = (~current_instr[ch][6]) & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* mod_waveformSelect */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 8] = (current_instr[ch][7] >> 4) & 0xf;
|
|
|
|
ptr[30 + 9] = current_instr[ch][7] & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* car_characteristic */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 10] = (current_instr[ch][8] >> 4) & 0xf;
|
|
|
|
ptr[30 + 11] = current_instr[ch][8] & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* car_scalingOutputLevel */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 12] = ((current_instr[ch][9]) >> 4) & 0xf;
|
|
|
|
ptr[30 + 13] = (current_instr[ch][9]) & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* car_attackDecay */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 14] = ((~current_instr[ch][10]) >> 4) & 0xf;
|
|
|
|
ptr[30 + 15] = (~current_instr[ch][10]) & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* car_sustainRelease */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 16] = ((~current_instr[ch][11]) >> 4) & 0xf;
|
|
|
|
ptr[30 + 17] = (~current_instr[ch][11]) & 0xf;
|
|
|
|
|
2006-06-18 10:06:45 +00:00
|
|
|
/* car_waveFormSelect */
|
2004-12-17 22:27:15 +00:00
|
|
|
ptr[30 + 18] = (current_instr[ch][12] >> 4) & 0xf;
|
|
|
|
ptr[30 + 19] = current_instr[ch][12] & 0xf;
|
|
|
|
|
|
|
|
/* feedback */
|
|
|
|
ptr[30 + 20] = (current_instr[ch][2] >> 4) & 0xf;
|
|
|
|
ptr[30 + 21] = current_instr[ch][2] & 0xf;
|
|
|
|
|
|
|
|
delay = mintime - curtime;
|
|
|
|
curtime = mintime;
|
|
|
|
|
|
|
|
{
|
|
|
|
delay = convert_extraflags(ptr + 30 + 22, src_ptr + 1);
|
|
|
|
delay2 = convert_extraflags(ptr + 30 + 40, src_ptr + 6);
|
|
|
|
debugC(DEBUG_SOUND, "delays: %d / %d", delay, delay2);
|
|
|
|
if (delay2 >= 0 && delay2 < delay)
|
|
|
|
delay = delay2;
|
|
|
|
if (delay == -1)
|
|
|
|
delay = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* duration */
|
|
|
|
ptr[30 + 58] = 0; // ((delay * 17 / 63) >> 4) & 0xf;
|
|
|
|
ptr[30 + 59] = 0; // (delay * 17 / 63) & 0xf;
|
|
|
|
|
|
|
|
ptr += sizeof(ADLIB_INSTR_MIDI_HACK);
|
|
|
|
|
|
|
|
olddelay = mintime - curtime;
|
|
|
|
curtime = mintime;
|
|
|
|
ptr = writeVLQ(ptr, olddelay);
|
|
|
|
|
|
|
|
{
|
|
|
|
int freq = ((current_instr[ch][1] & 3) << 8)
|
|
|
|
| current_instr[ch][0];
|
|
|
|
if (!freq)
|
|
|
|
freq = 0x80;
|
2006-06-20 21:36:09 +00:00
|
|
|
freq <<= (((current_instr[ch][1] >> 2) + 1) & 7);
|
2004-12-17 22:27:15 +00:00
|
|
|
int note = -11;
|
|
|
|
while (freq >= 0x100) {
|
|
|
|
note += 12;
|
|
|
|
freq >>= 1;
|
|
|
|
}
|
|
|
|
debugC(DEBUG_SOUND, "Freq: %d (%x) Note: %d", freq, freq, note);
|
|
|
|
if (freq < 0x80)
|
|
|
|
note = 0;
|
|
|
|
else
|
|
|
|
note += freq2note[freq - 0x80];
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-17 22:27:15 +00:00
|
|
|
debugC(DEBUG_SOUND, "Note: %d", note);
|
|
|
|
if (note <= 0)
|
|
|
|
note = 1;
|
|
|
|
else if (note > 127)
|
|
|
|
note = 127;
|
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
// Insert a note on event
|
2004-12-17 22:27:15 +00:00
|
|
|
*ptr++ = 0x90 + ch; // key on channel
|
|
|
|
*ptr++ = note;
|
|
|
|
*ptr++ = 63;
|
|
|
|
current_note[ch] = note;
|
|
|
|
track_time[ch] = curtime + delay;
|
|
|
|
}
|
|
|
|
src_ptr += 11;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x80:
|
2011-08-03 03:06:29 +00:00
|
|
|
// FIXME: This is incorrect. The original uses 0x80 for
|
|
|
|
// looping a single channel. We currently interpret it as stop
|
|
|
|
// thus we won't get looping for sound effects. It should
|
|
|
|
// always jump to the start of the channel.
|
|
|
|
//
|
2011-08-03 03:15:29 +00:00
|
|
|
// Since we convert the data to MIDI and we cannot only loop a
|
2011-08-03 03:06:29 +00:00
|
|
|
// single channel via MIDI fixing this will require some more
|
|
|
|
// thought.
|
2004-12-17 22:27:15 +00:00
|
|
|
track_time[ch] = -1;
|
|
|
|
src_ptr ++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
track_time[ch] = -1;
|
2006-06-18 06:23:22 +00:00
|
|
|
break;
|
2004-12-17 22:27:15 +00:00
|
|
|
}
|
|
|
|
track_data[ch] = src_ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert end of song sysex
|
|
|
|
memcpy(ptr, "\x00\xff\x2f\x00\x00", 5); ptr += 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-13 12:02:53 +00:00
|
|
|
int ScummEngine::readSoundResourceSmallHeader(ResId idx) {
|
2004-12-17 22:27:15 +00:00
|
|
|
uint32 pos, total_size, size, tag;
|
|
|
|
uint32 ad_size = 0, ad_offs = 0;
|
|
|
|
uint32 ro_size = 0, ro_offs = 0;
|
|
|
|
uint32 wa_size = 0, wa_offs = 0;
|
|
|
|
|
|
|
|
debug(4, "readSoundResourceSmallHeader(%d)", idx);
|
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if ((_game.id == GID_LOOM) && (_game.version == 3) && (_game.platform == Common::kPlatformPC) && VAR(VAR_SOUNDCARD) == 4) {
|
2004-12-17 22:27:15 +00:00
|
|
|
// Roland resources in Loom are tagless
|
|
|
|
// So we add an RO tag to allow imuse to detect format
|
|
|
|
byte *ptr, *src_ptr;
|
2005-03-30 21:59:12 +00:00
|
|
|
ro_offs = _fileHandle->pos();
|
|
|
|
ro_size = _fileHandle->readUint16LE();
|
2004-12-17 22:27:15 +00:00
|
|
|
|
|
|
|
src_ptr = (byte *) calloc(ro_size - 4, 1);
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(ro_offs + 4, SEEK_SET);
|
|
|
|
_fileHandle->read(src_ptr, ro_size -4);
|
2004-12-17 22:27:15 +00:00
|
|
|
|
2007-12-24 14:20:53 +00:00
|
|
|
ptr = _res->createResource(rtSound, idx, ro_size + 2);
|
2004-12-17 22:27:15 +00:00
|
|
|
memcpy(ptr, "RO", 2); ptr += 2;
|
|
|
|
memcpy(ptr, src_ptr, ro_size - 4); ptr += ro_size - 4;
|
2010-01-20 00:01:42 +00:00
|
|
|
free(src_ptr);
|
2004-12-17 22:27:15 +00:00
|
|
|
return 1;
|
2006-02-20 16:51:30 +00:00
|
|
|
} else if (_game.features & GF_OLD_BUNDLE) {
|
2005-03-30 21:59:12 +00:00
|
|
|
wa_offs = _fileHandle->pos();
|
|
|
|
wa_size = _fileHandle->readUint16LE();
|
|
|
|
_fileHandle->seek(wa_size - 2, SEEK_CUR);
|
2004-12-17 22:27:15 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (!(_game.platform == Common::kPlatformAtariST || _game.platform == Common::kPlatformMacintosh)) {
|
2005-03-30 21:59:12 +00:00
|
|
|
ad_offs = _fileHandle->pos();
|
|
|
|
ad_size = _fileHandle->readUint16LE();
|
2004-12-17 22:27:15 +00:00
|
|
|
}
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(4, SEEK_CUR);
|
2004-12-17 22:27:15 +00:00
|
|
|
total_size = wa_size + ad_size;
|
|
|
|
} else {
|
2005-03-30 21:59:12 +00:00
|
|
|
total_size = size = _fileHandle->readUint32LE();
|
|
|
|
tag = _fileHandle->readUint16LE();
|
2004-12-17 22:27:15 +00:00
|
|
|
debug(4, " tag='%c%c', size=%d", (char) (tag & 0xff),
|
|
|
|
(char) ((tag >> 8) & 0xff), size);
|
|
|
|
|
|
|
|
if (tag == 0x4F52) { // RO
|
2005-03-30 21:59:12 +00:00
|
|
|
ro_offs = _fileHandle->pos();
|
2004-12-17 22:27:15 +00:00
|
|
|
ro_size = size;
|
|
|
|
} else {
|
|
|
|
pos = 6;
|
|
|
|
while (pos < total_size) {
|
2005-03-30 21:59:12 +00:00
|
|
|
size = _fileHandle->readUint32LE();
|
|
|
|
tag = _fileHandle->readUint16LE();
|
2004-12-17 22:27:15 +00:00
|
|
|
debug(4, " tag='%c%c', size=%d", (char) (tag & 0xff),
|
|
|
|
(char) ((tag >> 8) & 0xff), size);
|
|
|
|
pos += size;
|
|
|
|
|
|
|
|
// MI1 and Indy3 uses one or more nested SO resources, which contains AD and WA
|
|
|
|
// resources.
|
|
|
|
if ((tag == 0x4441) && !(ad_offs)) { // AD
|
|
|
|
ad_size = size;
|
2005-03-30 21:59:12 +00:00
|
|
|
ad_offs = _fileHandle->pos();
|
2004-12-17 22:27:15 +00:00
|
|
|
} else if ((tag == 0x4157) && !(wa_offs)) { // WA
|
|
|
|
wa_size = size;
|
2005-03-30 21:59:12 +00:00
|
|
|
wa_offs = _fileHandle->pos();
|
2004-12-17 22:27:15 +00:00
|
|
|
} else { // other AD, WA and nested SO resources
|
|
|
|
if (tag == 0x4F53) { // SO
|
|
|
|
pos -= size;
|
|
|
|
size = 6;
|
|
|
|
pos += 6;
|
|
|
|
}
|
|
|
|
}
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(size - 6, SEEK_CUR);
|
2004-12-17 22:27:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-05 12:33:42 +00:00
|
|
|
if ((_sound->_musicType == MDT_PCSPK || _sound->_musicType == MDT_PCJR) && wa_offs != 0) {
|
2008-04-11 08:13:47 +00:00
|
|
|
if (_game.features & GF_OLD_BUNDLE) {
|
|
|
|
_fileHandle->seek(wa_offs, SEEK_SET);
|
|
|
|
_fileHandle->read(_res->createResource(rtSound, idx, wa_size), wa_size);
|
|
|
|
} else {
|
|
|
|
_fileHandle->seek(wa_offs - 6, SEEK_SET);
|
|
|
|
_fileHandle->read(_res->createResource(rtSound, idx, wa_size + 6), wa_size + 6);
|
|
|
|
}
|
|
|
|
return 1;
|
2011-08-06 10:39:37 +00:00
|
|
|
} else if (_sound->_musicType == MDT_CMS) {
|
2009-06-06 18:21:49 +00:00
|
|
|
if (_game.features & GF_OLD_BUNDLE) {
|
2011-08-05 20:46:26 +00:00
|
|
|
bool hasAdLibMusicTrack = false;
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2011-08-05 20:46:26 +00:00
|
|
|
if (ad_offs) {
|
|
|
|
_fileHandle->seek(ad_offs + 4 + 2, SEEK_SET);
|
|
|
|
hasAdLibMusicTrack = (_fileHandle->readByte() == 0x80);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasAdLibMusicTrack) {
|
2009-06-06 18:21:49 +00:00
|
|
|
_fileHandle->seek(ad_offs, SEEK_SET);
|
|
|
|
_fileHandle->read(_res->createResource(rtSound, idx, ad_size), ad_size);
|
|
|
|
} else {
|
|
|
|
_fileHandle->seek(wa_offs, SEEK_SET);
|
|
|
|
_fileHandle->read(_res->createResource(rtSound, idx, wa_size), wa_size);
|
|
|
|
}
|
2011-08-05 20:46:26 +00:00
|
|
|
} else {
|
|
|
|
bool hasAdLibMusicTrack = false;
|
|
|
|
|
|
|
|
if (ad_offs) {
|
|
|
|
_fileHandle->seek(ad_offs + 2, SEEK_SET);
|
|
|
|
hasAdLibMusicTrack = (_fileHandle->readByte() == 0x80);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasAdLibMusicTrack) {
|
|
|
|
_fileHandle->seek(ad_offs - 4, SEEK_SET);
|
|
|
|
_fileHandle->read(_res->createResource(rtSound, idx, ad_size + 4), ad_size + 4);
|
|
|
|
} else {
|
|
|
|
_fileHandle->seek(wa_offs - 6, SEEK_SET);
|
|
|
|
_fileHandle->read(_res->createResource(rtSound, idx, wa_size + 6), wa_size + 6);
|
|
|
|
}
|
2009-06-06 18:21:49 +00:00
|
|
|
}
|
2008-04-11 08:13:47 +00:00
|
|
|
} else if (ad_offs != 0) {
|
2004-12-17 22:27:15 +00:00
|
|
|
// AD resources have a header, instrument definitions and one MIDI track.
|
|
|
|
// We build an 'ADL ' resource from that:
|
|
|
|
// 8 bytes resource header
|
|
|
|
// 16 bytes MDhd header
|
|
|
|
// 14 bytes MThd header
|
|
|
|
// 8 bytes MTrk header
|
|
|
|
// 7 bytes MIDI tempo sysex
|
|
|
|
// + some default instruments
|
|
|
|
byte *ptr;
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.features & GF_OLD_BUNDLE) {
|
2006-01-29 17:47:38 +00:00
|
|
|
ad_size -= 4;
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(ad_offs + 4, SEEK_SET);
|
2004-12-17 22:27:15 +00:00
|
|
|
} else {
|
2006-01-29 17:47:38 +00:00
|
|
|
ad_size -= 6;
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(ad_offs, SEEK_SET);
|
2005-07-30 21:11:48 +00:00
|
|
|
}
|
2006-01-29 17:47:38 +00:00
|
|
|
ptr = (byte *) calloc(ad_size, 1);
|
|
|
|
_fileHandle->read(ptr, ad_size);
|
2007-12-24 14:20:53 +00:00
|
|
|
convertADResource(_res, _game, idx, ptr, ad_size);
|
2006-01-29 17:47:38 +00:00
|
|
|
free(ptr);
|
|
|
|
return 1;
|
2004-12-17 22:27:15 +00:00
|
|
|
} else if (ro_offs != 0) {
|
2005-03-30 21:59:12 +00:00
|
|
|
_fileHandle->seek(ro_offs - 2, SEEK_SET);
|
2007-12-24 14:20:53 +00:00
|
|
|
_fileHandle->read(_res->createResource(rtSound, idx, ro_size - 4), ro_size - 4);
|
2004-12-17 22:27:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2011-05-13 12:48:01 +00:00
|
|
|
_res->_types[rtSound][idx]._roomoffs = RES_INVALID_OFFSET;
|
2004-12-17 22:27:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-03 18:33:57 +00:00
|
|
|
} // End of namespace Scumm
|