2001-10-09 14:30:12 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2003-03-06 21:46:56 +00:00
|
|
|
* Copyright (C) 2001-2003 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-06-15 01:42:19 +00:00
|
|
|
#include "actor.h"
|
|
|
|
#include "bundle.h"
|
|
|
|
#include "imuse.h"
|
|
|
|
#include "imuse_digi.h"
|
|
|
|
#include "player_v2.h"
|
2002-09-13 12:20:55 +00:00
|
|
|
#include "scumm.h"
|
2002-08-29 23:45:15 +00:00
|
|
|
#include "sound.h"
|
2002-04-19 11:12:27 +00:00
|
|
|
#include "sound/mididrv.h"
|
2003-06-15 00:54:14 +00:00
|
|
|
#include "sound/mixer.h"
|
2002-09-13 12:20:55 +00:00
|
|
|
#include "common/config-file.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-05-19 05:04:38 +00:00
|
|
|
#include "sound/midiparser.h"
|
|
|
|
|
2003-06-15 00:54:14 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
SOUND_HEADER_SIZE = 26,
|
|
|
|
SOUND_HEADER_BIG_SIZE = 26 + 8
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class DigitalTrackInfo {
|
|
|
|
public:
|
|
|
|
virtual bool error() = 0;
|
2003-06-30 22:25:08 +00:00
|
|
|
virtual int play(SoundMixer *mixer, int startFrame, int endFrame) = 0;
|
2003-06-15 00:54:14 +00:00
|
|
|
virtual ~DigitalTrackInfo() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef USE_MAD
|
|
|
|
class MP3TrackInfo : public DigitalTrackInfo {
|
|
|
|
private:
|
|
|
|
struct mad_header _mad_header;
|
|
|
|
long _size;
|
|
|
|
File *_file;
|
|
|
|
bool _error_flag;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MP3TrackInfo(File *file);
|
|
|
|
~MP3TrackInfo();
|
|
|
|
bool error() { return _error_flag; }
|
2003-06-30 22:25:08 +00:00
|
|
|
int play(SoundMixer *mixer, int startFrame, int endFrame);
|
2003-06-15 00:54:14 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_VORBIS
|
|
|
|
class VorbisTrackInfo : public DigitalTrackInfo {
|
|
|
|
private:
|
|
|
|
File *_file;
|
|
|
|
OggVorbis_File _ov_file;
|
|
|
|
bool _error_flag;
|
|
|
|
|
|
|
|
public:
|
|
|
|
VorbisTrackInfo(File *file);
|
|
|
|
~VorbisTrackInfo();
|
|
|
|
bool error() { return _error_flag; }
|
2003-06-30 22:25:08 +00:00
|
|
|
int play(SoundMixer *mixer, int startFrame, int endFrame);
|
2003-06-15 00:54:14 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
Sound::Sound(Scumm *parent) {
|
2003-04-30 13:23:31 +00:00
|
|
|
memset(this,0,sizeof(Sound)); // palmos
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
_scumm = parent;
|
2003-06-23 21:23:10 +00:00
|
|
|
_nameBundleMusic = "";
|
2002-08-14 20:43:56 +00:00
|
|
|
_musicBundleBufFinal = NULL;
|
|
|
|
_musicBundleBufOutput = NULL;
|
2003-01-12 19:15:30 +00:00
|
|
|
_musicDisk = 0;
|
2003-07-14 21:37:45 +00:00
|
|
|
_talkChannelHandle = 0;
|
2003-06-15 00:54:14 +00:00
|
|
|
_current_cache = 0;
|
2003-06-30 23:18:20 +00:00
|
|
|
_currentCDSound = 0;
|
2003-06-25 23:25:52 +00:00
|
|
|
|
2003-06-26 23:04:41 +00:00
|
|
|
_sfxFile = 0;
|
|
|
|
|
2003-06-25 23:25:52 +00:00
|
|
|
_bundle = new Bundle();
|
2002-08-14 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Sound::~Sound() {
|
2003-06-26 23:04:41 +00:00
|
|
|
delete _sfxFile;
|
2003-06-25 23:25:52 +00:00
|
|
|
delete _bundle;
|
2002-08-14 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::addSoundToQueue(int sound) {
|
2003-06-07 00:13:26 +00:00
|
|
|
if (!(_scumm->_features & GF_DIGI_IMUSE)) {
|
2003-05-08 15:48:50 +00:00
|
|
|
_scumm->VAR(_scumm->VAR_LAST_SOUND) = sound;
|
2002-08-14 20:43:56 +00:00
|
|
|
_scumm->ensureResourceLoaded(rtSound, sound);
|
2002-03-06 00:18:22 +00:00
|
|
|
addSoundToQueue2(sound);
|
2002-08-20 09:58:35 +00:00
|
|
|
} else {
|
2003-06-07 00:49:36 +00:00
|
|
|
// WARNING ! This may break something, maybe this sould be put inside if (_gameID == GID_FT) ?
|
2002-08-20 09:58:35 +00:00
|
|
|
// But why addSoundToQueue should not queue sound ?
|
|
|
|
_scumm->ensureResourceLoaded(rtSound, sound);
|
|
|
|
addSoundToQueue2(sound);
|
2002-03-06 00:18:22 +00:00
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::addSoundToQueue2(int sound) {
|
2001-10-09 14:30:12 +00:00
|
|
|
if (_soundQue2Pos < 10) {
|
|
|
|
_soundQue2[_soundQue2Pos++] = sound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::processSoundQues() {
|
2003-07-14 22:24:18 +00:00
|
|
|
int i = 0, d, num;
|
2001-10-09 14:30:12 +00:00
|
|
|
int16 data[16];
|
2001-11-05 19:21:49 +00:00
|
|
|
|
|
|
|
processSfxQueues();
|
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
|
|
|
|
|
|
|
#if 0
|
2002-04-11 17:19:16 +00:00
|
|
|
debug(1, "processSoundQues(%d,%d,%d,%d,%d,%d,%d,%d,%d)",
|
|
|
|
data[0] >> 8,
|
|
|
|
data[0] & 0xFF,
|
|
|
|
data[1], data[2], data[3], data[4], data[5], data[6], data[7]
|
2001-11-05 19:21:49 +00:00
|
|
|
);
|
|
|
|
#endif
|
2002-08-04 16:30:59 +00:00
|
|
|
|
2003-06-07 00:13:26 +00:00
|
|
|
if (_scumm->_features & GF_DIGI_IMUSE) {
|
2003-05-12 19:53:18 +00:00
|
|
|
if (_scumm->_imuseDigital)
|
|
|
|
_scumm->_imuseDigital->doCommand(data[0], data[1], data[2], data[3], data[4],
|
2002-04-11 17:19:16 +00:00
|
|
|
data[5], data[6], data[7]);
|
2002-09-29 07:08:31 +00:00
|
|
|
} else {
|
2003-05-12 19:53:18 +00:00
|
|
|
if (_scumm->_imuse)
|
2003-05-08 15:48:50 +00:00
|
|
|
_scumm->VAR(_scumm->VAR_SOUNDRESULT) =
|
2003-05-12 19:53:18 +00:00
|
|
|
(short)_scumm->_imuse->doCommand(data[0], data[1], data[2], data[3], data[4],
|
2003-03-18 16:13:52 +00:00
|
|
|
data[5], data[6], data[7]);
|
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;
|
2002-09-09 11:15:44 +00:00
|
|
|
int size;
|
|
|
|
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
|
|
|
|
2003-03-18 16:13:52 +00:00
|
|
|
debug(3,"playSound #%d (room %d)", soundID, _scumm->getResourceRoomNr(rtSound, soundID));
|
2002-10-23 00:24:43 +00:00
|
|
|
ptr = _scumm->getResourceAddress(rtSound, soundID);
|
2002-08-29 23:45:15 +00:00
|
|
|
if (ptr) {
|
2003-06-14 18:52:30 +00:00
|
|
|
if (READ_UINT32(ptr) == MKID('iMUS')){
|
2003-05-03 20:45:31 +00:00
|
|
|
assert(_scumm->_imuseDigital);
|
|
|
|
_scumm->_imuseDigital->startSound(soundID);
|
|
|
|
return;
|
|
|
|
}
|
2003-06-14 18:52:30 +00:00
|
|
|
else if (READ_UINT32(ptr) == MKID('Crea')) {
|
2003-05-03 20:45:31 +00:00
|
|
|
assert(_scumm->_imuseDigital);
|
|
|
|
_scumm->_imuseDigital->startSound(soundID);
|
2002-10-03 23:16:10 +00:00
|
|
|
return;
|
2002-09-29 07:08:31 +00:00
|
|
|
}
|
2003-06-14 18:52:30 +00:00
|
|
|
else if (READ_UINT32(ptr) == MKID('SOUN')) {
|
2003-06-30 22:25:08 +00:00
|
|
|
ptr += 24;
|
|
|
|
int track = ptr[0];
|
|
|
|
int loops = ptr[1];
|
|
|
|
int start = (ptr[2] * 60 + ptr[3]) * 75 + ptr[4];
|
2003-05-08 15:48:50 +00:00
|
|
|
_scumm->VAR(_scumm->VAR_MUSIC_TIMER) = 0;
|
2003-06-30 22:25:08 +00:00
|
|
|
playCDTrack(track, loops == 0xff ? -1 : loops, start, 0);
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2003-06-30 23:18:20 +00:00
|
|
|
_currentCDSound = soundID;
|
2002-08-29 23:45:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// 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.
|
2003-06-14 18:52:30 +00:00
|
|
|
else if (READ_UINT32(ptr) == MKID('Mac1')) {
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2002-08-29 23:45:15 +00:00
|
|
|
// Read info from the header
|
2003-06-14 18:52:30 +00:00
|
|
|
size = READ_BE_UINT32(ptr+0x60);
|
|
|
|
rate = READ_BE_UINT32(ptr+0x64) >> 16;
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2002-08-29 23:45:15 +00:00
|
|
|
// Skip over the header (fixed size)
|
|
|
|
ptr += 0x72;
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2002-08-29 23:45:15 +00:00
|
|
|
// Allocate a sound buffer, copy the data into it, and play
|
2003-03-06 17:58:13 +00:00
|
|
|
sound = (char *)malloc(size);
|
2002-08-29 23:45:15 +00:00
|
|
|
memcpy(sound, ptr, size);
|
2003-03-18 22:07:49 +00:00
|
|
|
_scumm->_mixer->playRaw(NULL, sound, size, rate, flags, soundID);
|
2002-08-29 23:45:15 +00:00
|
|
|
return;
|
2002-08-20 09:58:35 +00:00
|
|
|
}
|
2002-08-29 23:45:15 +00:00
|
|
|
// Support for Putt-Putt sounds - very hackish, too 8-)
|
2003-06-14 18:52:30 +00:00
|
|
|
else if (READ_UINT32(ptr) == MKID('DIGI')) {
|
2002-08-29 23:45:15 +00:00
|
|
|
// TODO - discover what data the first chunk, HSHD, contains
|
|
|
|
// it might be useful here.
|
2003-06-14 18:52:30 +00:00
|
|
|
ptr += 8 + READ_BE_UINT32(ptr+12);
|
|
|
|
if (READ_UINT32(ptr) != MKID('SDAT'))
|
2002-08-29 23:45:15 +00:00
|
|
|
return; // abort
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2003-06-14 18:52:30 +00:00
|
|
|
size = READ_BE_UINT32(ptr+4) - 8;
|
2003-02-28 11:32:43 +00:00
|
|
|
// FIXME - what value here ?!? 11025 is just a guess based on strings in w32 bin, prev guess 8000
|
|
|
|
rate = 11025;
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2002-08-29 23:45:15 +00:00
|
|
|
// Allocate a sound buffer, copy the data into it, and play
|
2003-03-06 17:58:13 +00:00
|
|
|
sound = (char *)malloc(size);
|
2002-08-29 23:45:15 +00:00
|
|
|
memcpy(sound, ptr + 8, size);
|
2003-03-18 22:07:49 +00:00
|
|
|
_scumm->_mixer->playRaw(NULL, sound, size, rate, flags, soundID);
|
2002-08-29 23:45:15 +00:00
|
|
|
return;
|
2002-07-25 16:29:07 +00:00
|
|
|
}
|
2003-07-06 15:02:13 +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'))
|
|
|
|
return;
|
|
|
|
|
|
|
|
size = READ_BE_UINT32(ptr+4) - 8;
|
|
|
|
rate = 22050;
|
|
|
|
flags = SoundMixer::FLAG_AUTOFREE;
|
|
|
|
|
|
|
|
// Allocate a sound buffer, copy the data into it, and play
|
|
|
|
sound = (char *)malloc(size);
|
|
|
|
memcpy(sound, ptr + 8, size);
|
|
|
|
_scumm->_mixer->playRaw(NULL, sound, size, rate, flags, soundID);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2003-05-19 08:04:47 +00:00
|
|
|
// XMIDI
|
2003-06-14 18:52:30 +00:00
|
|
|
else if ((READ_UINT32(ptr) == MKID('MIDI')) && (_scumm->_features & GF_HUMONGOUS)) {
|
2003-05-23 18:35:53 +00:00
|
|
|
// Pass XMIDI on to IMuse unprocessed.
|
|
|
|
// IMuse can handle XMIDI resources now.
|
2003-04-22 11:34:46 +00:00
|
|
|
}
|
2003-06-14 18:52:30 +00:00
|
|
|
else if (READ_UINT32(ptr) == MKID('ADL ')) {
|
2002-09-21 13:48:03 +00:00
|
|
|
// played as MIDI, just to make perhaps the later use
|
|
|
|
// of WA possible (see "else if" with GF_OLD256 below)
|
|
|
|
}
|
2002-08-29 23:45:15 +00:00
|
|
|
// Support for sampled sound effects in Monkey1 and Monkey2
|
2003-06-14 18:52:30 +00:00
|
|
|
else if (READ_UINT32(ptr) == MKID('SBL ')) {
|
2002-08-29 23:45:15 +00:00
|
|
|
debug(2, "Using SBL sound effect");
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2002-10-03 09:16:14 +00:00
|
|
|
// TODO - Figuring out how the SBL chunk works. Here's
|
|
|
|
// an example:
|
2002-08-29 23:45:15 +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 |~~~~~~~.|
|
|
|
|
//
|
2002-10-03 09:16:14 +00:00
|
|
|
// The length of the AUhd chunk always seems to be 3
|
|
|
|
// bytes. Let's skip that for now.
|
2002-08-29 23:45:15 +00:00
|
|
|
//
|
2002-10-03 09:16:14 +00:00
|
|
|
// The starting offset, length and sample rate is all
|
|
|
|
// pure guesswork. The result sounds reasonable to me,
|
|
|
|
// but I've never heard the original.
|
|
|
|
//
|
|
|
|
// I've since discovered that the non-interactive
|
|
|
|
// Sam & Max demo also uses SBL sound effects, but
|
|
|
|
// with different sub-chunks. Example:
|
|
|
|
//
|
|
|
|
// 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 |........|
|
|
|
|
//
|
|
|
|
// I'm going to assume that the sample frequency is
|
|
|
|
// the only important difference between the two.
|
|
|
|
|
2003-06-19 12:29:13 +00:00
|
|
|
// FIXME: SBL resources are apparently horribly
|
|
|
|
// distorted on segacd even though it shares the same
|
|
|
|
// header etc. So don't try to play them for now.
|
|
|
|
if (_scumm->_gameId == GID_MONKEY_SEGA) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-06-14 18:52:30 +00:00
|
|
|
if (READ_UINT32(ptr + 8) == MKID('WVhd'))
|
2002-10-03 09:16:14 +00:00
|
|
|
rate = 11025;
|
|
|
|
else
|
|
|
|
rate = 8000;
|
|
|
|
|
2003-06-14 18:52:30 +00:00
|
|
|
size = READ_BE_UINT32(ptr + 4) - 27;
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2002-08-29 23:45:15 +00:00
|
|
|
// Allocate a sound buffer, copy the data into it, and play
|
2003-03-06 17:58:13 +00:00
|
|
|
sound = (char *)malloc(size);
|
2002-08-29 23:45:15 +00:00
|
|
|
memcpy(sound, ptr + 33, size);
|
2003-03-18 22:07:49 +00:00
|
|
|
_scumm->_mixer->playRaw(NULL, sound, size, rate, flags, soundID);
|
2002-08-29 23:45:15 +00:00
|
|
|
return;
|
|
|
|
} else if (_scumm->_features & GF_OLD256) {
|
2002-09-09 11:15:44 +00:00
|
|
|
size = READ_LE_UINT32(ptr);
|
2003-07-06 06:47:26 +00:00
|
|
|
#if 0
|
2002-08-29 23:45:15 +00:00
|
|
|
// FIXME - this is just some debug output for Zak256
|
|
|
|
if (size != 30) {
|
|
|
|
char name[9];
|
|
|
|
memcpy(name, ptr+22, 8);
|
|
|
|
name[8] = 0;
|
|
|
|
printf("Going to play Zak256 sound '%s':\n", name);
|
|
|
|
hexdump(ptr, 0x40);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
There seems to be some pattern in the Zak256 sound data. Two typical
|
|
|
|
examples are these:
|
|
|
|
|
|
|
|
d7 10 00 00 53 4f d1 10 |....SO..|
|
|
|
|
00 00 00 00 04 00 ff 00 |........|
|
|
|
|
64 00 00 00 01 00 64 6f |d.....do|
|
|
|
|
6f 72 6f 70 65 6e 40 a8 |oropen@.|
|
|
|
|
57 14 a1 10 00 00 50 08 |W.....P.|
|
|
|
|
00 00 00 00 00 00 b3 07 |........|
|
|
|
|
00 00 3c 00 00 00 04 80 |..<.....|
|
|
|
|
03 02 0a 01 8c 82 87 81 |........|
|
|
|
|
|
|
|
|
5b 07 00 00 53 4f 55 07 |[...SOU.|
|
|
|
|
00 00 00 00 04 00 ff 00 |........|
|
|
|
|
64 00 00 00 01 00 64 72 |d.....dr|
|
|
|
|
77 6f 70 65 6e 00 53 a8 |wopen.S.|
|
|
|
|
57 14 25 07 00 00 92 03 |W.%.....|
|
|
|
|
00 00 00 00 00 00 88 03 |........|
|
|
|
|
00 00 3c 00 00 00 82 82 |..<.....|
|
|
|
|
83 84 86 88 89 8b 89 89 |........|
|
|
|
|
|
|
|
|
As you can see, there are quite some patterns, e.g.
|
2003-07-06 06:47:26 +00:00
|
|
|
the "3c 00 00 00" - the sound data starts at offset 0x36
|
2002-09-09 11:15:44 +00:00
|
|
|
|
2003-05-25 00:04:16 +00:00
|
|
|
Indy 3 uses a different format. The very first sound played
|
2002-09-09 11:15:44 +00:00
|
|
|
in Indy 3 looks as follows:
|
|
|
|
5a 25 00 00 53 4f 54 25 |Z%..SOT%|
|
|
|
|
00 00 53 4f db 0a 00 00 |..SO....|
|
|
|
|
57 41 c8 00 18 00 00 00 |WA......|
|
|
|
|
00 00 00 00 9e 05 00 00 |........|
|
|
|
|
00 00 00 00 fd 32 00 f8 |.....2..|
|
|
|
|
02 f9 08 ff 22 08 00 ff |...."...|
|
|
|
|
20 5c 00 ff 10 03 00 fd | \......|
|
|
|
|
64 00 f8 00 f9 00 ff 22 |d......"|
|
|
|
|
|
|
|
|
Indy 3, opening a door:
|
|
|
|
d1 00 00 00 53 4f cb 00 |....SO..|
|
|
|
|
00 00 53 4f a2 00 00 00 |..SO....|
|
|
|
|
57 41 64 00 18 00 00 00 |WAd.....|
|
|
|
|
00 00 00 00 00 00 00 00 |........|
|
|
|
|
00 00 7e 00 f9 0c ff 20 |..~.... |
|
|
|
|
90 01 ff 22 c2 01 ff 0a |..."....|
|
|
|
|
03 00 ff 04 57 06 ff 00 |....W...|
|
|
|
|
04 00 ff 0a 00 00 ff 00 |........|
|
|
|
|
|
|
|
|
So there seems to be a "SO" chunk which contains again a SO chunk and a WA chunk.
|
|
|
|
WA probably again contains audio data?
|
2002-08-29 23:45:15 +00:00
|
|
|
*/
|
2003-07-06 06:47:26 +00:00
|
|
|
#endif
|
2003-07-18 05:59:32 +00:00
|
|
|
rate = 11025;
|
2003-06-30 22:25:08 +00:00
|
|
|
int type = *(ptr + 0x0D);
|
|
|
|
|
2003-07-12 15:27:41 +00:00
|
|
|
switch(type) {
|
|
|
|
case 0: { // Sound effect
|
2003-07-19 03:54:33 +00:00
|
|
|
int numInstruments = *(ptr + 0x14);
|
|
|
|
ptr += 0x16;
|
|
|
|
size -= 0x16;
|
|
|
|
while (numInstruments--) {
|
|
|
|
int waveSize = READ_LE_UINT32(ptr + 0x0C);
|
|
|
|
int loopStart = READ_LE_UINT32(ptr + 0x10);
|
|
|
|
int loopEnd = READ_LE_UINT32(ptr + 0x14);
|
|
|
|
// it's not exactly * 10, maybe it's not even linear, but * 10 sounds ok.
|
|
|
|
rate = READ_LE_UINT32(ptr + 0x18) * 10;
|
|
|
|
|
|
|
|
ptr += 0x20;
|
|
|
|
size -= 0x20;
|
|
|
|
if (size < waveSize) {
|
2003-07-19 07:32:26 +00:00
|
|
|
warning("Wrong wave size in sound #%i: %i", soundID, waveSize);
|
2003-07-19 07:43:13 +00:00
|
|
|
waveSize = size;
|
2003-07-19 03:54:33 +00:00
|
|
|
}
|
|
|
|
sound = (char *)malloc(waveSize);
|
|
|
|
for (int x = 0; x < waveSize; x++) {
|
|
|
|
int bit = *ptr++;
|
|
|
|
if (bit < 0x80)
|
|
|
|
sound[x] = 0x7F - bit;
|
|
|
|
else
|
|
|
|
sound[x] = bit;
|
|
|
|
}
|
|
|
|
size -= waveSize;
|
2003-07-12 15:27:41 +00:00
|
|
|
|
2003-07-19 03:54:33 +00:00
|
|
|
if (loopEnd > 0) {
|
|
|
|
flags |= SoundMixer::FLAG_LOOP;
|
|
|
|
if ((loopEnd < waveSize) || (loopStart > 0)) {
|
|
|
|
// FIXME: Implement partial loops
|
|
|
|
warning("Partial loops not implemented. Loop at 0x%X thru 0x%X", loopStart, loopEnd);
|
|
|
|
}
|
2003-07-12 15:27:41 +00:00
|
|
|
}
|
|
|
|
|
2003-07-19 03:54:33 +00:00
|
|
|
_scumm->_mixer->playRaw(NULL, sound, waveSize, rate, flags, soundID);
|
|
|
|
}
|
2003-07-12 15:27:41 +00:00
|
|
|
break;
|
2003-07-06 06:47:26 +00:00
|
|
|
}
|
2003-07-12 15:27:41 +00:00
|
|
|
|
|
|
|
case 1: { // Music (Euphony format)
|
|
|
|
int numInstruments = *(ptr + 0x14);
|
|
|
|
int tuneSize = 0, tempo = 0;
|
|
|
|
|
|
|
|
ptr += (0x16 + (numInstruments * 48)); // Skip instrument definitions
|
|
|
|
ptr += (32*4); // Skip preset values (mute, channel, volume, transpose)
|
|
|
|
ptr += 8; // (Unknown)
|
|
|
|
|
2003-07-19 03:54:33 +00:00
|
|
|
ptr += 6; // Instrument channel's. Always 6 bytes according to the disassembly.
|
2003-07-12 15:27:41 +00:00
|
|
|
|
|
|
|
tuneSize = READ_LE_UINT32(ptr);
|
|
|
|
ptr += 5;
|
|
|
|
|
|
|
|
tempo = *ptr++;
|
|
|
|
ptr += 2;
|
|
|
|
// Music data begins here
|
|
|
|
|
|
|
|
warning("Euphony tune #%d unsupported", soundID);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2: { // CD track resource
|
|
|
|
ptr += 0x16;
|
|
|
|
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];
|
|
|
|
|
|
|
|
if (soundID == _currentCDSound)
|
|
|
|
if (pollCD() == 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
playCDTrack(track, loops == 0xff ? -1 : loops, start, end);
|
|
|
|
_currentCDSound = soundID;
|
|
|
|
break;
|
|
|
|
}
|
2003-07-04 14:10:44 +00:00
|
|
|
}
|
2003-07-12 15:27:41 +00:00
|
|
|
return;
|
2002-07-25 15:37:31 +00:00
|
|
|
}
|
2002-08-29 23:45:15 +00:00
|
|
|
|
2002-07-25 15:37:31 +00:00
|
|
|
}
|
2003-04-12 19:42:12 +00:00
|
|
|
|
2003-07-04 12:35:08 +00:00
|
|
|
if (_scumm->_gameId == GID_LOOM && (READ_LE_UINT16(ptr + 4) == 'so')) {
|
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....(_.......|
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-07-15 07:29:23 +00:00
|
|
|
if ((_scumm->_features & GF_AMIGA) && (_scumm->_version == 3))
|
|
|
|
{
|
|
|
|
// experimental support for Indy3 Amiga sound effects
|
2003-07-17 12:27:13 +00:00
|
|
|
if (READ_BE_UINT16(ptr + 26) == 0x00FF) // looped sound
|
|
|
|
// TODO: support looping sounds
|
|
|
|
// ptr + 14 seems to be looping duration
|
|
|
|
flags = 0;
|
|
|
|
else if (READ_BE_UINT16(ptr + 26) == 0x0001) // nonlooped sound
|
|
|
|
flags = 0; //
|
|
|
|
else if (READ_BE_UINT16(ptr + 26) == 0x0101) // background music
|
|
|
|
// TODO: support music
|
2003-07-15 07:29:23 +00:00
|
|
|
return;
|
2003-07-17 12:27:13 +00:00
|
|
|
size = READ_BE_UINT16(ptr + 12);
|
|
|
|
rate = 11000;
|
2003-07-19 16:07:33 +00:00
|
|
|
sound = (char *)malloc(size);
|
|
|
|
memcpy(sound,ptr + 28,size);
|
|
|
|
_scumm->_mixer->playRaw(NULL, sound, size, rate, SoundMixer::FLAG_AUTOFREE, soundID);
|
2003-07-17 12:27:13 +00:00
|
|
|
return;
|
2003-07-15 07:29:23 +00:00
|
|
|
}
|
|
|
|
|
2003-07-14 08:42:02 +00:00
|
|
|
if (_scumm->_features & GF_OLD_BUNDLE) {
|
|
|
|
//TODO: support maniac v1 sounds
|
|
|
|
if ((_scumm->_version == 1) && (_scumm->_gameId == GID_MANIAC))
|
|
|
|
return;
|
2003-05-26 23:23:44 +00:00
|
|
|
// other versions seem to be 0000 at this point...
|
|
|
|
// hopefully this test is correct
|
|
|
|
// 0xfe7f seems to be sound and 0x764a music
|
2003-07-04 12:34:09 +00:00
|
|
|
bool amigatest = (READ_LE_UINT16(ptr + 12) == 0xfe7f) || (READ_LE_UINT16(ptr + 12) == 0x764a);
|
|
|
|
if (amigatest) {
|
|
|
|
// TODO: support amiga sounds
|
|
|
|
} else {
|
2003-05-26 23:23:44 +00:00
|
|
|
if (_scumm->_playerV2)
|
|
|
|
_scumm->_playerV2->startSound (soundID, ptr);
|
|
|
|
}
|
2003-05-26 22:03:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-07-25 15:37:31 +00:00
|
|
|
|
2003-05-03 11:42:25 +00:00
|
|
|
if (_scumm->_gameId == GID_MONKEY_VGA || _scumm->_gameId == GID_MONKEY_EGA) {
|
2003-07-06 10:39:02 +00:00
|
|
|
// Sound is currently not supported at all in the amiga versions of these games
|
|
|
|
if (_scumm->_features & GF_AMIGA)
|
|
|
|
return;
|
|
|
|
|
2003-05-03 11:42:25 +00:00
|
|
|
// FIXME: This evil hack works around the fact that in some
|
|
|
|
// places in MonkeyVGA, the music is never explicitly stopped.
|
|
|
|
// Rather it seems that starting a new music is supposed to
|
|
|
|
// automatically stop the old song.
|
|
|
|
// This hack relays on the fact that we currently don't support SFX
|
|
|
|
// in these games, only music. Once we add SFX support, we'll have to
|
|
|
|
// revise it / replace it by a proper fix.
|
2003-07-06 10:39:02 +00:00
|
|
|
if (ptr) {
|
2003-05-03 12:41:35 +00:00
|
|
|
_scumm->_imuse->stop_all_sounds();
|
2003-05-03 11:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-18 16:13:52 +00:00
|
|
|
if (_scumm->_imuse) {
|
2002-10-23 00:24:43 +00:00
|
|
|
_scumm->getResourceAddress(rtSound, soundID);
|
2003-03-18 16:13:52 +00:00
|
|
|
_scumm->_imuse->startSound(soundID);
|
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
|
|
|
Actor *a;
|
|
|
|
int act;
|
2002-04-11 17:19:16 +00:00
|
|
|
bool b, finished;
|
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);
|
2003-07-14 21:37:45 +00:00
|
|
|
if (_talk_sound_mode & 2) {
|
|
|
|
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
|
|
|
|
2003-07-15 22:21:30 +00:00
|
|
|
if ((_sfxMode & 2) && _scumm->VAR(_scumm->VAR_TALK_ACTOR)) {
|
2003-05-08 15:48:50 +00:00
|
|
|
act = _scumm->VAR(_scumm->VAR_TALK_ACTOR);
|
2003-07-15 20:51:18 +00:00
|
|
|
|
2003-07-15 22:21:30 +00:00
|
|
|
finished = !_talkChannelHandle;
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2002-09-22 01:17:53 +00:00
|
|
|
if (act != 0 && (uint) act < 0x80 && !_scumm->_string[0].no_talk_anim) {
|
2003-05-23 13:24:41 +00:00
|
|
|
a = _scumm->derefActor(act, "processSfxQueues");
|
2003-05-24 22:13:01 +00:00
|
|
|
if (a->isInCurrentRoom() && (finished || !_endOfMouthSync)) {
|
2001-11-05 19:21:49 +00:00
|
|
|
b = true;
|
|
|
|
if (!finished)
|
|
|
|
b = isMouthSyncOff(_curSoundPos);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-04-22 08:16:16 +00:00
|
|
|
|
2003-06-01 13:11:30 +00:00
|
|
|
if (finished && _scumm->_talkDelay == 0) {
|
2002-08-14 20:43:56 +00:00
|
|
|
_scumm->stopTalk();
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
2002-04-22 08:16:16 +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;
|
|
|
|
int size;
|
2003-03-06 17:58:13 +00:00
|
|
|
byte *sound;
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2002-09-02 07:53:43 +00:00
|
|
|
if (_sfxFile->isOpen() == false) {
|
2001-11-05 19:21:49 +00:00
|
|
|
warning("startTalkSound: SFX file is not open");
|
2003-07-14 21:37:45 +00:00
|
|
|
return;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2003-03-01 12:44:52 +00:00
|
|
|
// FIXME hack until more is known
|
|
|
|
// the size of the data after the sample isn't known
|
|
|
|
// 64 is just a guess
|
|
|
|
if (_scumm->_features & GF_HUMONGOUS) {
|
|
|
|
// SKIP TLKB (8) TALK (8) HSHD (24) and SDAT (8)
|
|
|
|
_sfxFile->seek(offset + 48, SEEK_SET);
|
2003-03-06 17:58:13 +00:00
|
|
|
sound = (byte *)malloc(b - 64);
|
2003-03-01 12:44:52 +00:00
|
|
|
_sfxFile->read(sound, b - 64);
|
2003-07-14 21:37:45 +00:00
|
|
|
_scumm->_mixer->playRaw(handle, sound, b - 64, 11025, SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE);
|
|
|
|
return;
|
2003-03-01 12:44:52 +00:00
|
|
|
}
|
|
|
|
|
2002-10-02 17:30:26 +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.
|
2002-10-21 16:27:23 +00:00
|
|
|
//
|
2002-10-02 17:30:26 +00:00
|
|
|
// Do any other games than these need this hack?
|
2002-10-21 16:27:23 +00:00
|
|
|
//
|
|
|
|
// HACK: Checking for script 99 in Sam & Max is to keep Conroy's song
|
|
|
|
// from being interrupted.
|
2002-10-02 17:30:26 +00:00
|
|
|
|
2003-07-14 21:37:45 +00:00
|
|
|
int talkChannel = (_talkChannelHandle - 1);
|
2002-10-21 16:27:23 +00:00
|
|
|
if (mode == 1 && (_scumm->_gameId == GID_TENTACLE
|
|
|
|
|| (_scumm->_gameId == GID_SAMNMAX && !_scumm->isScriptRunning(99)))) {
|
2002-10-22 11:48:24 +00:00
|
|
|
for (i = 0; i < _scumm->_mixer->NUM_CHANNELS; i++) {
|
2003-07-14 21:37:45 +00:00
|
|
|
if (i != talkChannel) {
|
2002-10-02 17:30:26 +00:00
|
|
|
_scumm->_mixer->stop(i);
|
2003-07-14 21:37:45 +00:00
|
|
|
}
|
2002-10-02 17:30:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (b > 8) {
|
|
|
|
num = (b - 8) >> 1;
|
2002-03-06 23:17:16 +00:00
|
|
|
}
|
2002-10-28 12:56:42 +00:00
|
|
|
|
2002-03-06 23:17:16 +00:00
|
|
|
if (offset_table != NULL) {
|
2002-04-11 17:19:16 +00:00
|
|
|
MP3OffsetTable *result = NULL, key;
|
|
|
|
|
|
|
|
key.org_offset = offset;
|
2003-03-06 17:58:13 +00:00
|
|
|
result = (MP3OffsetTable *)bsearch(&key, offset_table, num_sound_effects,
|
2003-03-18 16:13:52 +00:00
|
|
|
sizeof(MP3OffsetTable), compareMP3OffsetTable);
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
if (result == NULL) {
|
|
|
|
warning("startTalkSound: did not find sound at offset %d !", offset);
|
2003-07-14 21:37:45 +00:00
|
|
|
return;
|
2002-04-11 17:19:16 +00:00
|
|
|
}
|
|
|
|
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;
|
2002-10-28 12:56:42 +00:00
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
offset += 8;
|
|
|
|
size = -1;
|
2002-03-06 23:17:16 +00:00
|
|
|
}
|
|
|
|
|
2002-09-02 07:53:43 +00:00
|
|
|
_sfxFile->seek(offset, SEEK_SET);
|
2003-03-23 13:14:54 +00:00
|
|
|
|
|
|
|
assert(num+1 < (int)ARRAYSIZE(_mouthSyncTimes));
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
_mouthSyncTimes[i] = _sfxFile->readUint16BE();
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
_mouthSyncTimes[i] = 0xFFFF;
|
2002-09-26 09:59:47 +00:00
|
|
|
_sfxMode |= mode;
|
2001-11-05 19:21:49 +00:00
|
|
|
_curSoundPos = 0;
|
|
|
|
_mouthSyncMode = true;
|
|
|
|
|
2003-07-14 21:37:45 +00:00
|
|
|
startSfxSound(_sfxFile, size, handle);
|
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) {
|
2003-07-14 21:37:45 +00:00
|
|
|
_scumm->_mixer->stopHandle(_talkChannelHandle);
|
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
|
|
|
int i;
|
|
|
|
|
2003-06-30 23:18:20 +00:00
|
|
|
if (sound == _currentCDSound)
|
2002-08-29 23:45:15 +00:00
|
|
|
return pollCD();
|
2003-03-18 22:07:49 +00:00
|
|
|
|
2003-05-19 08:04:47 +00:00
|
|
|
if (_scumm->_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
|
2003-06-25 23:49:54 +00:00
|
|
|
return _scumm->_imuse->getSoundStatus(sound);
|
2003-05-23 18:35:53 +00:00
|
|
|
}
|
2003-05-19 08:04:47 +00:00
|
|
|
}
|
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
i = _soundQue2Pos;
|
|
|
|
while (i--) {
|
|
|
|
if (_soundQue2[i] == sound)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSoundInQueue(sound))
|
|
|
|
return 1;
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
if (!_scumm->isResourceLoaded(rtSound, sound))
|
2001-11-05 19:21:49 +00:00
|
|
|
return 0;
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2003-03-18 22:07:49 +00:00
|
|
|
if (_scumm->_imuseDigital)
|
2002-09-29 07:08:31 +00:00
|
|
|
return _scumm->_imuseDigital->getSoundStatus(sound);
|
2002-10-02 10:12:19 +00:00
|
|
|
|
2003-03-18 22:07:49 +00:00
|
|
|
if (_scumm->_imuse)
|
2003-03-23 13:14:54 +00:00
|
|
|
return _scumm->_imuse->getSoundStatus(sound);
|
2003-03-18 22:07:49 +00:00
|
|
|
|
2003-05-26 22:03:04 +00:00
|
|
|
if (_scumm->_playerV2)
|
2003-06-25 23:49:54 +00:00
|
|
|
return _scumm->_playerV2->getSoundStatus(sound);
|
2003-05-26 22:03:04 +00:00
|
|
|
|
2003-03-18 22:07:49 +00:00
|
|
|
return 0;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-12-05 21:45:55 +00:00
|
|
|
// This is exactly the same as isSoundRunning except that it
|
2003-03-23 13:14:54 +00:00
|
|
|
// calls IMuse::get_sound_active() instead of IMuse::getSoundStatus().
|
2002-12-05 21:45:55 +00:00
|
|
|
// This is necessary when determining what resources to
|
|
|
|
// expire from memory.
|
2003-06-25 23:49:54 +00:00
|
|
|
bool Sound::isSoundActive(int sound) const {
|
2002-12-05 21:45:55 +00:00
|
|
|
int i;
|
|
|
|
|
2003-06-30 23:18:20 +00:00
|
|
|
if (sound == _currentCDSound)
|
2002-12-05 21:45:55 +00:00
|
|
|
return pollCD() != 0;
|
|
|
|
|
|
|
|
i = _soundQue2Pos;
|
|
|
|
while (i--) {
|
|
|
|
if (_soundQue2[i] == sound)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSoundInQueue(sound))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!_scumm->isResourceLoaded(rtSound, sound))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (_scumm->_imuseDigital) {
|
|
|
|
return _scumm->_imuseDigital->getSoundStatus(sound) != 0;
|
|
|
|
}
|
|
|
|
|
2003-03-18 16:13:52 +00:00
|
|
|
if (!_scumm->_imuse)
|
2002-12-05 21:45:55 +00:00
|
|
|
return false;
|
2003-03-18 16:13:52 +00:00
|
|
|
return _scumm->_imuse->get_sound_active(sound);
|
2002-12-05 21:45:55 +00:00
|
|
|
}
|
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
bool Sound::isSoundInQueue(int sound) const {
|
2002-04-11 17:19:16 +00:00
|
|
|
int i = 0, j, num;
|
2001-11-05 19:21:49 +00:00
|
|
|
int16 table[16];
|
|
|
|
|
|
|
|
while (i < _soundQuePos) {
|
|
|
|
num = _soundQue[i++];
|
|
|
|
|
|
|
|
memset(table, 0, sizeof(table));
|
|
|
|
|
|
|
|
if (num > 0) {
|
2002-04-11 17:19:16 +00:00
|
|
|
for (j = 0; j < num; j++)
|
|
|
|
table[j] = _soundQue[i + j];
|
2001-11-05 19:21:49 +00:00
|
|
|
i += num;
|
2002-04-11 17:19:16 +00:00
|
|
|
if (table[0] == 0x10F && table[1] == 8 && table[2] == sound)
|
2001-11-05 19:21:49 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2001-10-09 14:30:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::stopSound(int a) {
|
2001-11-05 19:21:49 +00:00
|
|
|
int i;
|
|
|
|
|
2003-06-30 23:18:20 +00:00
|
|
|
if (a != 0 && a == _currentCDSound) {
|
|
|
|
_currentCDSound = 0;
|
2002-08-29 23:45:15 +00:00
|
|
|
stopCD();
|
2002-03-16 05:33:25 +00:00
|
|
|
}
|
|
|
|
|
2003-07-18 05:49:21 +00:00
|
|
|
if (_scumm->_features & GF_FMTOWNS) {
|
2003-07-04 14:10:44 +00:00
|
|
|
_scumm->_mixer->stopID(a);
|
|
|
|
} else if (_scumm->_imuseDigital) {
|
2002-09-29 07:08:31 +00:00
|
|
|
_scumm->_imuseDigital->stopSound(a);
|
2003-03-18 16:13:52 +00:00
|
|
|
} else if (_scumm->_imuse) {
|
|
|
|
_scumm->_imuse->stopSound(a);
|
2003-05-26 22:03:04 +00:00
|
|
|
} else if (_scumm->_playerV2) {
|
|
|
|
_scumm->_playerV2->stopSound (a);
|
2003-07-04 14:10:44 +00:00
|
|
|
}
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
for (i = 0; i < 10; 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();
|
2002-03-16 05:33:25 +00:00
|
|
|
}
|
|
|
|
|
2003-03-18 16:13:52 +00:00
|
|
|
if (_scumm->_imuse) {
|
|
|
|
_scumm->_imuse->stop_all_sounds();
|
|
|
|
_scumm->_imuse->clear_queue();
|
2003-05-26 22:03:04 +00:00
|
|
|
} else if (_scumm->_playerV2) {
|
|
|
|
_scumm->_playerV2->stopAllSounds();
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
2003-05-26 22:03:04 +00:00
|
|
|
|
2001-11-05 19:21:49 +00:00
|
|
|
clearSoundQue();
|
2001-11-14 18:40:39 +00:00
|
|
|
stopSfxSound();
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::clearSoundQue() {
|
2001-11-05 19:21:49 +00:00
|
|
|
_soundQue2Pos = 0;
|
|
|
|
memset(_soundQue2, 0, sizeof(_soundQue2));
|
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;
|
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
if (list[0] == -1) {
|
2001-11-05 19:21:49 +00:00
|
|
|
processSoundQues();
|
2001-10-16 10:01:48 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-01-29 04:00:45 +00:00
|
|
|
|
|
|
|
if ((_soundQuePos + num) > 0x100) {
|
2003-07-14 22:24:18 +00:00
|
|
|
// FIXME: temporarily changed this to an error to help track down what
|
|
|
|
// is causing the sound queue overflows(in particular, to figure out
|
|
|
|
// the room/script/offset where the bug occurs). Please report your
|
|
|
|
// findings to Fingolfin.
|
|
|
|
error("Sound que buffer overflow (%d + %d = %d)", _soundQuePos, num, _soundQuePos+num);
|
2003-01-29 04:00:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-12-31 21:56:58 +00:00
|
|
|
_soundQue[_soundQuePos++] = num;
|
|
|
|
|
2003-01-29 04:00:45 +00:00
|
|
|
for (i = 0; i < num; i++) {
|
2002-12-31 21:56:58 +00:00
|
|
|
_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() {
|
|
|
|
if (_scumm->_imuse) {
|
|
|
|
_scumm->_imuse->setBase(_scumm->res.address[rtSound]);
|
2002-07-27 14:55:40 +00:00
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
_scumm->_imuse->set_master_volume(_sound_volume_master);
|
|
|
|
_scumm->_imuse->set_music_volume(_sound_volume_music);
|
2002-03-07 08:11:48 +00:00
|
|
|
}
|
2003-06-26 23:04:41 +00:00
|
|
|
_scumm->_mixer->setVolume(_sound_volume_sfx * _sound_volume_master / 255);
|
|
|
|
_scumm->_mixer->setMusicVolume(_sound_volume_music);
|
|
|
|
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) {
|
2003-03-18 16:13:52 +00:00
|
|
|
if (_scumm->_imuse)
|
|
|
|
_scumm->_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!
|
2003-01-13 13:13:36 +00:00
|
|
|
if (!_scumm->_roomResource)
|
|
|
|
return;
|
|
|
|
|
2001-11-14 18:40:39 +00:00
|
|
|
_soundsPaused = pause;
|
2003-03-06 17:58:13 +00:00
|
|
|
_scumm->_mixer->pause(pause);
|
2002-09-21 13:48:03 +00:00
|
|
|
|
2002-10-15 06:53:42 +00:00
|
|
|
_scumm->_sound->pauseBundleMusic(pause);
|
|
|
|
|
|
|
|
if (_scumm->_imuseDigital) {
|
|
|
|
_scumm->_imuseDigital->pause(pause);
|
|
|
|
}
|
|
|
|
|
2003-05-08 15:48:50 +00:00
|
|
|
if ((_scumm->_features & GF_AUDIOTRACKS) && _scumm->VAR(_scumm->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-07-14 21:37:45 +00:00
|
|
|
void Sound::startSfxSound(File *file, int file_size, PlayingSoundHandle *handle) {
|
2002-01-02 11:50:28 +00:00
|
|
|
char ident[8];
|
2001-11-05 19:21:49 +00:00
|
|
|
int block_type;
|
|
|
|
byte work[8];
|
2002-08-14 16:18:45 +00:00
|
|
|
uint size = 0;
|
2002-04-11 17:19:16 +00:00
|
|
|
int rate, comp;
|
2001-11-05 19:21:49 +00:00
|
|
|
byte *data;
|
|
|
|
|
2003-01-24 06:41:10 +00:00
|
|
|
if (_scumm->_noDigitalSamples)
|
2003-07-14 21:37:45 +00:00
|
|
|
return;
|
2003-01-24 06:41:10 +00:00
|
|
|
|
2002-03-06 23:17:16 +00:00
|
|
|
if (file_size > 0) {
|
2002-10-27 11:41:08 +00:00
|
|
|
int alloc_size = file_size;
|
|
|
|
#ifdef USE_MAD
|
2002-10-28 12:56:42 +00:00
|
|
|
if (!_vorbis_mode)
|
2002-10-27 11:41:08 +00:00
|
|
|
alloc_size += MAD_BUFFER_GUARD;
|
|
|
|
#endif
|
|
|
|
data = (byte *)calloc(alloc_size, 1);
|
2002-03-06 23:17:16 +00:00
|
|
|
|
2002-09-22 00:04:04 +00:00
|
|
|
if (file->read(data, file_size) != (uint)file_size) {
|
2002-04-11 17:19:16 +00:00
|
|
|
/* no need to free the memory since error will shut down */
|
|
|
|
error("startSfxSound: cannot read %d bytes", size);
|
|
|
|
}
|
2002-10-27 11:41:08 +00:00
|
|
|
if (_vorbis_mode)
|
2003-07-14 21:37:45 +00:00
|
|
|
playSfxSound_Vorbis(data, file_size, handle);
|
2002-10-27 11:41:08 +00:00
|
|
|
else
|
2003-07-14 21:37:45 +00:00
|
|
|
playSfxSound_MP3(data, file_size, handle);
|
|
|
|
return;
|
2002-03-06 23:17:16 +00:00
|
|
|
}
|
2002-10-28 12:56:42 +00:00
|
|
|
|
2002-09-02 07:53:43 +00:00
|
|
|
if (file->read(ident, 8) != 8)
|
2002-01-02 11:50:28 +00:00
|
|
|
goto invalid;
|
2001-12-27 17:51:58 +00:00
|
|
|
|
2002-01-02 11:50:28 +00:00
|
|
|
if (!memcmp(ident, "VTLK", 4)) {
|
2002-09-02 07:53:43 +00:00
|
|
|
file->seek(SOUND_HEADER_BIG_SIZE - 8, SEEK_CUR);
|
2002-01-02 11:50:28 +00:00
|
|
|
} else if (!memcmp(ident, "Creative", 8)) {
|
2002-09-02 07:53:43 +00:00
|
|
|
file->seek(SOUND_HEADER_SIZE - 8, SEEK_CUR);
|
2002-01-02 11:50:28 +00:00
|
|
|
} else {
|
2002-04-11 17:19:16 +00:00
|
|
|
invalid:;
|
2001-11-05 19:21:49 +00:00
|
|
|
warning("startSfxSound: invalid header");
|
2003-07-14 21:37:45 +00:00
|
|
|
return;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-09-02 07:53:43 +00:00
|
|
|
block_type = file->readByte();
|
2001-11-05 19:21:49 +00:00
|
|
|
if (block_type != 1) {
|
|
|
|
warning("startSfxSound: Expecting block_type == 1, got %d", block_type);
|
2003-07-14 21:37:45 +00:00
|
|
|
return;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
|
|
|
|
2002-09-02 07:53:43 +00:00
|
|
|
file->read(work, 3);
|
2001-11-05 19:21:49 +00:00
|
|
|
|
2002-04-11 17:19:16 +00:00
|
|
|
size = (work[0] | (work[1] << 8) | (work[2] << 16)) - 2;
|
2002-09-02 07:53:43 +00:00
|
|
|
rate = file->readByte();
|
|
|
|
comp = file->readByte();
|
2001-11-05 19:21:49 +00:00
|
|
|
|
|
|
|
if (comp != 0) {
|
|
|
|
warning("startSfxSound: Unsupported compression type %d", comp);
|
2003-07-14 21:37:45 +00:00
|
|
|
return;
|
2001-11-05 19:21:49 +00:00
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
|
|
|
data = (byte *)malloc(size);
|
|
|
|
if (data == NULL) {
|
2001-11-05 19:21:49 +00:00
|
|
|
error("startSfxSound: out of memory");
|
|
|
|
}
|
2002-04-11 17:19:16 +00:00
|
|
|
|
2002-09-02 07:53:43 +00:00
|
|
|
if (file->read(data, size) != size) {
|
2001-11-05 19:21:49 +00:00
|
|
|
/* no need to free the memory since error will shut down */
|
|
|
|
error("startSfxSound: cannot read %d bytes", size);
|
|
|
|
}
|
2002-03-14 16:49:59 +00:00
|
|
|
|
2003-07-14 21:37:45 +00:00
|
|
|
playSfxSound(data, size, 1000000 / (256 - rate), true, handle);
|
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];
|
2003-03-06 17:58:13 +00:00
|
|
|
File *file = new File();
|
2001-11-29 22:29:38 +00:00
|
|
|
|
|
|
|
/* Try opening the file <_exe_name>.sou first, eg tentacle.sou.
|
|
|
|
* That way, you can keep .sou files for multiple games in the
|
|
|
|
* same directory */
|
2002-03-06 23:17:16 +00:00
|
|
|
offset_table = NULL;
|
2001-11-29 22:29:38 +00:00
|
|
|
|
2002-10-27 11:41:08 +00:00
|
|
|
#ifdef USE_MAD
|
2003-02-08 00:38:17 +00:00
|
|
|
sprintf(buf, "%s.so3", _scumm->getExeName());
|
2002-09-15 19:28:34 +00:00
|
|
|
if (!file->open(buf, _scumm->getGameDataPath())) {
|
|
|
|
file->open("monster.so3", _scumm->getGameDataPath());
|
2002-03-06 23:17:16 +00:00
|
|
|
}
|
2002-10-27 11:41:08 +00:00
|
|
|
if (file->isOpen())
|
|
|
|
_vorbis_mode = false;
|
|
|
|
#endif
|
2002-10-28 12:56:42 +00:00
|
|
|
|
2002-10-27 11:41:08 +00:00
|
|
|
#ifdef USE_VORBIS
|
2002-10-28 12:56:42 +00:00
|
|
|
if (!file->isOpen()) {
|
2003-02-08 00:38:17 +00:00
|
|
|
sprintf(buf, "%s.sog", _scumm->getExeName());
|
2002-10-28 12:56:42 +00:00
|
|
|
if (!file->open(buf, _scumm->getGameDataPath()))
|
|
|
|
file->open("monster.sog", _scumm->getGameDataPath());
|
|
|
|
if (file->isOpen())
|
|
|
|
_vorbis_mode = true;
|
|
|
|
}
|
2002-10-27 11:41:08 +00:00
|
|
|
#endif
|
|
|
|
|
2002-10-28 12:56:42 +00:00
|
|
|
if (file->isOpen()) {
|
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();
|
2002-04-11 17:19:16 +00:00
|
|
|
offset_table = (MP3OffsetTable *) malloc(compressed_offset);
|
|
|
|
num_sound_effects = compressed_offset / 16;
|
|
|
|
|
|
|
|
size = compressed_offset;
|
|
|
|
cur = offset_table;
|
|
|
|
while (size > 0) {
|
2002-10-21 13:23:25 +00:00
|
|
|
cur[0].org_offset = file->readUint32BE();
|
|
|
|
cur[0].new_offset = file->readUint32BE() + compressed_offset + 4; /* The + 4 is to take into accound the 'size' field */
|
|
|
|
cur[0].num_tags = file->readUint32BE();
|
|
|
|
cur[0].compressed_size = file->readUint32BE();
|
2002-04-11 17:19:16 +00:00
|
|
|
size -= 4 * 4;
|
|
|
|
cur++;
|
|
|
|
}
|
|
|
|
return file;
|
2002-03-06 23:17:16 +00:00
|
|
|
}
|
2002-10-28 12:56:42 +00:00
|
|
|
|
2003-02-08 00:38:17 +00:00
|
|
|
sprintf(buf, "%s.sou", _scumm->getExeName());
|
2002-09-15 19:28:34 +00:00
|
|
|
if (!file->open(buf, _scumm->getGameDataPath())) {
|
|
|
|
file->open("monster.sou", _scumm->getGameDataPath());
|
2002-02-27 22:48:55 +00:00
|
|
|
}
|
2003-03-01 12:44:52 +00:00
|
|
|
|
|
|
|
if (!file->isOpen()) {
|
|
|
|
sprintf(buf, "%s.tlk", _scumm->getExeName());
|
|
|
|
file->open(buf, _scumm->getGameDataPath(), 1, 0x69);
|
|
|
|
}
|
2001-11-29 22:29:38 +00:00
|
|
|
return file;
|
2001-11-14 18:40:39 +00:00
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::stopSfxSound() {
|
2002-10-03 23:16:10 +00:00
|
|
|
if (_scumm->_imuseDigital) {
|
|
|
|
_scumm->_imuseDigital->stopAll();
|
2002-10-15 06:53:42 +00:00
|
|
|
} else {
|
|
|
|
_scumm->_mixer->stopAll();
|
2002-10-03 23:16:10 +00:00
|
|
|
}
|
2001-11-14 18:40:39 +00:00
|
|
|
}
|
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
bool Sound::isSfxFinished() const {
|
2003-06-22 01:55:53 +00:00
|
|
|
return !_scumm->_mixer->hasActiveSFXChannel();
|
2002-08-14 20:43:56 +00:00
|
|
|
}
|
|
|
|
|
2003-07-02 11:04:48 +00:00
|
|
|
uint32 Sound::decode12BitsSample(byte *src, byte **dst, uint32 size, bool stereo) {
|
2002-09-30 19:10:35 +00:00
|
|
|
uint32 s_size = (size / 3) * 4;
|
|
|
|
uint32 loop_size = s_size / 4;
|
2003-06-27 00:10:17 +00:00
|
|
|
if (stereo) {
|
2002-10-02 17:31:55 +00:00
|
|
|
s_size *= 2;
|
|
|
|
}
|
2003-03-06 17:58:13 +00:00
|
|
|
byte *ptr = *dst = (byte *)malloc(s_size);
|
2002-09-30 19:10:35 +00:00
|
|
|
|
|
|
|
uint32 tmp;
|
2003-06-07 00:49:36 +00:00
|
|
|
while (loop_size--) {
|
2002-09-30 19:10:35 +00:00
|
|
|
byte v1 = *src++;
|
|
|
|
byte v2 = *src++;
|
|
|
|
byte v3 = *src++;
|
|
|
|
tmp = ((((v2 & 0x0f) << 8) | v1) << 4) - 0x8000;
|
|
|
|
*ptr++ = (byte)((tmp >> 8) & 0xff);
|
|
|
|
*ptr++ = (byte)(tmp & 0xff);
|
2003-06-27 00:10:17 +00:00
|
|
|
if (stereo) {
|
2002-10-02 17:31:55 +00:00
|
|
|
*ptr++ = (byte)((tmp >> 8) & 0xff);
|
|
|
|
*ptr++ = (byte)(tmp & 0xff);
|
|
|
|
}
|
2002-09-30 19:10:35 +00:00
|
|
|
tmp = ((((v2 & 0xf0) << 4) | v3) << 4) - 0x8000;
|
|
|
|
*ptr++ = (byte)((tmp >> 8) & 0xff);
|
|
|
|
*ptr++ = (byte)(tmp & 0xff);
|
2003-06-27 00:10:17 +00:00
|
|
|
if (stereo) {
|
2002-10-02 17:31:55 +00:00
|
|
|
*ptr++ = (byte)((tmp >> 8) & 0xff);
|
|
|
|
*ptr++ = (byte)(tmp & 0xff);
|
|
|
|
}
|
2002-09-30 19:10:35 +00:00
|
|
|
}
|
|
|
|
return s_size;
|
2002-03-06 23:17:16 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
static void music_handler (void *engine) {
|
2002-09-18 10:22:36 +00:00
|
|
|
g_scumm->_sound->bundleMusicHandler(g_scumm);
|
2002-08-04 16:30:59 +00:00
|
|
|
}
|
|
|
|
|
2003-05-21 18:09:49 +00:00
|
|
|
void Sound::playBundleMusic(const char *song) {
|
2003-06-27 00:10:17 +00:00
|
|
|
if (_scumm->_silentDigitalImuse) {
|
2002-10-27 19:32:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-06-23 21:23:10 +00:00
|
|
|
if (_nameBundleMusic[0] == 0) {
|
2002-12-29 01:28:44 +00:00
|
|
|
_outputMixerSize = 66150; // ((22050 * 2 * 2) / 4) * 3
|
2002-12-27 11:47:00 +00:00
|
|
|
if (_scumm->_gameId == GID_CMI) {
|
2003-01-02 10:36:17 +00:00
|
|
|
char bunfile[20];
|
2003-05-08 15:48:50 +00:00
|
|
|
sprintf(bunfile, "musdisk%d.bun", _scumm->VAR(_scumm->VAR_CURRENTDISK));
|
|
|
|
if (_musicDisk != _scumm->VAR(_scumm->VAR_CURRENTDISK))
|
2003-06-25 23:25:52 +00:00
|
|
|
_bundle->closeMusicFile();
|
2003-01-12 19:15:30 +00:00
|
|
|
|
2003-06-25 23:25:52 +00:00
|
|
|
if (_bundle->openMusicFile(bunfile, _scumm->getGameDataPath()) == false) {
|
|
|
|
if (_bundle->openMusicFile("music.bun", _scumm->getGameDataPath()) == false) {
|
2003-03-04 06:10:07 +00:00
|
|
|
_outputMixerSize = 0;
|
|
|
|
return;
|
|
|
|
}
|
2003-01-12 19:15:30 +00:00
|
|
|
}
|
|
|
|
|
2003-05-08 15:48:50 +00:00
|
|
|
_musicDisk = (byte)_scumm->VAR(_scumm->VAR_CURRENTDISK);
|
2002-12-29 01:28:44 +00:00
|
|
|
_outputMixerSize = 88140; // ((22050 * 2 * 2)
|
2002-12-27 11:47:00 +00:00
|
|
|
} else {
|
2003-06-25 23:25:52 +00:00
|
|
|
if (_bundle->openMusicFile("digmusic.bun", _scumm->getGameDataPath()) == false)
|
2002-12-27 11:47:00 +00:00
|
|
|
return;
|
2002-08-31 09:50:36 +00:00
|
|
|
}
|
2003-03-06 17:58:13 +00:00
|
|
|
_musicBundleBufFinal = (byte *)malloc(_outputMixerSize);
|
|
|
|
_musicBundleBufOutput = (byte *)malloc(((_outputMixerSize / 0x2000) + 1) * _outputMixerSize);
|
2002-08-04 16:30:59 +00:00
|
|
|
_currentSampleBundleMusic = 0;
|
|
|
|
_offsetSampleBundleMusic = 0;
|
|
|
|
_offsetBufBundleMusic = 0;
|
2003-01-26 14:26:03 +00:00
|
|
|
_bundleMusicPosition = 0;
|
2002-10-08 19:35:39 +00:00
|
|
|
_pauseBundleMusic = false;
|
2002-10-15 06:53:42 +00:00
|
|
|
_musicBundleToBeRemoved = false;
|
|
|
|
_musicBundleToBeChanged = false;
|
2002-10-08 19:35:39 +00:00
|
|
|
_bundleMusicTrack = -1;
|
2003-06-25 23:25:52 +00:00
|
|
|
_numberSamplesBundleMusic = _bundle->getNumberOfMusicSamplesByName(song);
|
2002-10-08 19:35:39 +00:00
|
|
|
_nameBundleMusic = song;
|
2003-01-25 12:13:41 +00:00
|
|
|
_scumm->_timer->installProcedure(&music_handler, 1000000);
|
2002-08-04 16:30:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-10-08 19:35:39 +00:00
|
|
|
if (strcmp(_nameBundleMusic, song) != 0) {
|
2002-10-15 06:53:42 +00:00
|
|
|
_newNameBundleMusic = song;
|
|
|
|
_musicBundleToBeRemoved = false;
|
|
|
|
_musicBundleToBeChanged = true;
|
2002-08-04 16:30:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::pauseBundleMusic(bool state) {
|
2002-08-08 07:48:57 +00:00
|
|
|
_pauseBundleMusic = state;
|
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
void Sound::stopBundleMusic() {
|
2002-10-15 06:53:42 +00:00
|
|
|
_musicBundleToBeRemoved = true;
|
2002-08-04 16:30:59 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Sound::bundleMusicHandler(Scumm *scumm) {
|
|
|
|
byte *ptr;
|
2002-08-04 16:30:59 +00:00
|
|
|
int32 l, num = _numberSamplesBundleMusic, length, k;
|
2002-12-29 01:28:44 +00:00
|
|
|
int32 rate = 22050;
|
2002-08-04 16:30:59 +00:00
|
|
|
int32 tag, size = -1, header_size = 0;
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2002-08-08 07:48:57 +00:00
|
|
|
if (_pauseBundleMusic)
|
2002-08-14 16:18:45 +00:00
|
|
|
return;
|
2002-08-04 16:30:59 +00:00
|
|
|
|
2003-06-26 23:04:41 +00:00
|
|
|
if (_musicBundleToBeRemoved) {
|
2002-10-15 06:53:42 +00:00
|
|
|
_scumm->_timer->releaseProcedure(&music_handler);
|
2003-06-23 21:23:10 +00:00
|
|
|
_nameBundleMusic = "";
|
2002-10-16 07:59:11 +00:00
|
|
|
if (_bundleMusicTrack != -1) {
|
|
|
|
_scumm->_mixer->stop(_bundleMusicTrack);
|
2003-07-02 00:46:24 +00:00
|
|
|
_bundleMusicTrack = -1;
|
2002-10-16 07:59:11 +00:00
|
|
|
}
|
2002-10-15 06:53:42 +00:00
|
|
|
if (_musicBundleBufFinal) {
|
|
|
|
free(_musicBundleBufFinal);
|
|
|
|
_musicBundleBufFinal = NULL;
|
|
|
|
}
|
|
|
|
if (_musicBundleBufOutput) {
|
|
|
|
free(_musicBundleBufOutput);
|
|
|
|
_musicBundleBufOutput = NULL;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-06-27 00:10:17 +00:00
|
|
|
if (_musicBundleToBeChanged) {
|
2002-10-15 06:53:42 +00:00
|
|
|
_nameBundleMusic = _newNameBundleMusic;
|
2003-06-25 23:25:52 +00:00
|
|
|
_numberSamplesBundleMusic = _bundle->getNumberOfMusicSamplesByName(_nameBundleMusic);
|
2002-10-15 06:53:42 +00:00
|
|
|
_currentSampleBundleMusic = 0;
|
|
|
|
_offsetSampleBundleMusic = 0;
|
|
|
|
_offsetBufBundleMusic = 0;
|
|
|
|
_musicBundleToBeChanged = false;
|
2003-01-26 14:26:03 +00:00
|
|
|
_bundleMusicPosition = 0;
|
2002-10-15 06:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr = _musicBundleBufOutput;
|
|
|
|
|
2002-08-04 16:30:59 +00:00
|
|
|
for (k = 0, l = _currentSampleBundleMusic; l < num; k++) {
|
2003-06-25 23:25:52 +00:00
|
|
|
length = _bundle->decompressMusicSampleByName(_nameBundleMusic, l, (_musicBundleBufOutput + ((k * 0x2000) + _offsetBufBundleMusic)));
|
2002-08-04 16:30:59 +00:00
|
|
|
_offsetSampleBundleMusic += length;
|
|
|
|
|
|
|
|
if (l == 0) {
|
|
|
|
tag = READ_BE_UINT32(ptr); ptr += 4;
|
|
|
|
if (tag != MKID_BE('iMUS')) {
|
2002-10-08 19:35:39 +00:00
|
|
|
warning("Decompression of bundle song failed");
|
2002-10-15 06:53:42 +00:00
|
|
|
_musicBundleToBeRemoved = true;
|
2002-08-14 16:18:45 +00:00
|
|
|
return;
|
2002-08-04 16:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr += 12;
|
2003-06-07 00:49:36 +00:00
|
|
|
while (tag != MKID_BE('DATA')) {
|
2002-08-04 16:30:59 +00:00
|
|
|
tag = READ_BE_UINT32(ptr); ptr += 4;
|
|
|
|
switch(tag) {
|
|
|
|
case MKID_BE('FRMT'):
|
2002-12-28 21:46:49 +00:00
|
|
|
ptr += 12;
|
|
|
|
_bundleMusicSampleBits = READ_BE_UINT32(ptr); ptr += 4;
|
|
|
|
rate = READ_BE_UINT32(ptr); ptr += 4;
|
2002-12-29 01:28:44 +00:00
|
|
|
_bundleSampleChannels = READ_BE_UINT32(ptr); ptr += 4;
|
2002-08-04 16:30:59 +00:00
|
|
|
break;
|
|
|
|
case MKID_BE('TEXT'):
|
|
|
|
case MKID_BE('REGN'):
|
|
|
|
case MKID_BE('STOP'):
|
|
|
|
case MKID_BE('JUMP'):
|
2003-01-10 08:25:16 +00:00
|
|
|
case MKID_BE('SYNC'):
|
2002-08-04 16:30:59 +00:00
|
|
|
size = READ_BE_UINT32(ptr); ptr += size + 4;
|
|
|
|
break;
|
|
|
|
case MKID_BE('DATA'):
|
|
|
|
size = READ_BE_UINT32(ptr); ptr += 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2003-06-13 18:09:18 +00:00
|
|
|
error("Unknown sound header %c%c%c%c",
|
|
|
|
(byte)(tag >> 24),
|
|
|
|
(byte)(tag >> 16),
|
|
|
|
(byte)(tag >> 8),
|
|
|
|
(byte)tag);
|
2002-08-04 16:30:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (size < 0) {
|
|
|
|
warning("Decompression sound failed (no size field)");
|
2002-10-15 06:53:42 +00:00
|
|
|
_musicBundleToBeRemoved = true;
|
2002-08-14 16:18:45 +00:00
|
|
|
return;
|
2002-08-04 16:30:59 +00:00
|
|
|
}
|
|
|
|
header_size = (ptr - _musicBundleBufOutput);
|
|
|
|
}
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2002-08-04 16:30:59 +00:00
|
|
|
l++;
|
|
|
|
_currentSampleBundleMusic = l;
|
|
|
|
|
2002-12-29 01:28:44 +00:00
|
|
|
if (_offsetSampleBundleMusic >= _outputMixerSize + header_size) {
|
|
|
|
memcpy(_musicBundleBufFinal, (_musicBundleBufOutput + header_size), _outputMixerSize);
|
|
|
|
_offsetBufBundleMusic = _offsetSampleBundleMusic - _outputMixerSize - header_size;
|
|
|
|
memcpy(_musicBundleBufOutput, (_musicBundleBufOutput + (_outputMixerSize + header_size)), _offsetBufBundleMusic);
|
2002-08-04 16:30:59 +00:00
|
|
|
_offsetSampleBundleMusic = _offsetBufBundleMusic;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-15 06:53:42 +00:00
|
|
|
if (_currentSampleBundleMusic == num) {
|
2002-08-23 20:27:42 +00:00
|
|
|
_currentSampleBundleMusic = 0;
|
2002-10-15 06:53:42 +00:00
|
|
|
_offsetSampleBundleMusic = 0;
|
|
|
|
_offsetBufBundleMusic = 0;
|
2003-01-26 14:26:03 +00:00
|
|
|
_bundleMusicPosition = 0;
|
2002-10-15 06:53:42 +00:00
|
|
|
}
|
2002-08-04 16:30:59 +00:00
|
|
|
|
|
|
|
ptr = _musicBundleBufFinal;
|
2002-08-18 22:47:11 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
byte *buffer = NULL;
|
2002-12-28 21:46:49 +00:00
|
|
|
uint32 final_size;
|
|
|
|
if (_bundleMusicSampleBits == 12) {
|
2003-07-02 11:04:48 +00:00
|
|
|
final_size = decode12BitsSample(ptr, &buffer, _outputMixerSize, false);
|
2002-12-28 21:46:49 +00:00
|
|
|
} else if (_bundleMusicSampleBits == 16) {
|
2003-03-06 17:58:13 +00:00
|
|
|
buffer = (byte *)malloc(_outputMixerSize);
|
2002-12-29 01:28:44 +00:00
|
|
|
final_size = _outputMixerSize;
|
|
|
|
memcpy(buffer, ptr, _outputMixerSize);
|
2002-12-28 21:46:49 +00:00
|
|
|
} else {
|
2003-06-22 11:47:03 +00:00
|
|
|
warning("Sound::bundleMusicHandler TODO: more newStream options...");
|
2002-12-28 21:55:32 +00:00
|
|
|
return;
|
2002-12-28 21:46:49 +00:00
|
|
|
}
|
2002-10-15 06:53:42 +00:00
|
|
|
|
2003-01-26 14:26:03 +00:00
|
|
|
_bundleMusicPosition += final_size;
|
2002-10-08 19:35:39 +00:00
|
|
|
if (_bundleMusicTrack == -1) {
|
2003-06-22 11:47:03 +00:00
|
|
|
_bundleMusicTrack = _scumm->_mixer->newStream(buffer, final_size, rate,
|
2003-06-21 23:29:34 +00:00
|
|
|
SoundMixer::FLAG_16BITS | SoundMixer::FLAG_STEREO, 300000);
|
2002-09-30 19:31:41 +00:00
|
|
|
} else {
|
2003-06-22 11:47:03 +00:00
|
|
|
_scumm->_mixer->appendStream(_bundleMusicTrack, buffer, final_size);
|
2002-09-30 19:31:41 +00:00
|
|
|
}
|
2003-06-21 21:17:08 +00:00
|
|
|
free(buffer);
|
2002-08-04 16:30:59 +00:00
|
|
|
}
|
|
|
|
|
2003-07-14 21:37:45 +00:00
|
|
|
void Sound::playBundleSound(char *sound, PlayingSoundHandle *handle) {
|
|
|
|
byte *ptr = 0, *orig_ptr = 0;
|
2003-03-08 00:05:27 +00:00
|
|
|
byte *final;
|
2002-12-26 21:50:13 +00:00
|
|
|
bool result;
|
2003-01-24 06:41:10 +00:00
|
|
|
|
|
|
|
if (_scumm->_noDigitalSamples)
|
2003-07-14 21:37:45 +00:00
|
|
|
return;
|
2003-01-24 06:41:10 +00:00
|
|
|
|
2003-01-02 10:36:17 +00:00
|
|
|
if (_scumm->_gameId == GID_CMI) {
|
|
|
|
char voxfile[20];
|
2003-05-08 15:48:50 +00:00
|
|
|
sprintf(voxfile, "voxdisk%d.bun", _scumm->VAR(_scumm->VAR_CURRENTDISK));
|
|
|
|
if (_voiceDisk != _scumm->VAR(_scumm->VAR_CURRENTDISK))
|
2003-06-25 23:25:52 +00:00
|
|
|
_bundle->closeVoiceFile();
|
2003-01-20 05:59:25 +00:00
|
|
|
|
2003-06-25 23:25:52 +00:00
|
|
|
result = _bundle->openVoiceFile(voxfile, _scumm->getGameDataPath());
|
2003-01-20 05:59:25 +00:00
|
|
|
|
2003-03-04 06:10:07 +00:00
|
|
|
if (result == false)
|
2003-06-25 23:25:52 +00:00
|
|
|
result = _bundle->openVoiceFile("voice.bun", _scumm->getGameDataPath());
|
2003-05-08 15:48:50 +00:00
|
|
|
_voiceDisk = (byte)_scumm->VAR(_scumm->VAR_CURRENTDISK);
|
2003-01-02 10:36:17 +00:00
|
|
|
} else if (_scumm->_gameId == GID_DIG)
|
2003-06-25 23:25:52 +00:00
|
|
|
result = _bundle->openVoiceFile("digvoice.bun", _scumm->getGameDataPath());
|
2002-12-26 21:50:13 +00:00
|
|
|
else
|
|
|
|
error("Don't know which bundle file to load");
|
|
|
|
|
2003-07-14 21:37:45 +00:00
|
|
|
if (!result)
|
|
|
|
return;
|
2002-08-31 09:50:36 +00:00
|
|
|
|
2003-01-25 20:01:23 +00:00
|
|
|
int32 rate = 22050, channels, output_size = 0;
|
2002-12-28 16:38:15 +00:00
|
|
|
int32 tag, size = -1, bits = 0;
|
2002-04-29 08:28:27 +00:00
|
|
|
|
2002-12-28 15:02:23 +00:00
|
|
|
if (_scumm->_gameId == GID_CMI) {
|
|
|
|
char name[20];
|
|
|
|
strcpy(name, sound);
|
2003-03-04 06:10:07 +00:00
|
|
|
if (_scumm->_maxRooms != 6) // CMI demo does not have .IMX for voice but does for music...
|
|
|
|
strcat(name, ".IMX");
|
2003-06-25 23:25:52 +00:00
|
|
|
output_size = _bundle->decompressVoiceSampleByName(name, &ptr);
|
2002-12-28 15:02:23 +00:00
|
|
|
} else {
|
2003-06-25 23:25:52 +00:00
|
|
|
output_size = _bundle->decompressVoiceSampleByName(sound, &ptr);
|
2002-12-28 15:02:23 +00:00
|
|
|
}
|
2003-03-08 00:05:27 +00:00
|
|
|
|
2003-03-07 01:35:54 +00:00
|
|
|
orig_ptr = ptr;
|
2003-03-08 00:05:27 +00:00
|
|
|
if (output_size == 0 || orig_ptr == 0) {
|
|
|
|
goto bail;
|
|
|
|
}
|
2002-04-29 08:28:27 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
tag = READ_BE_UINT32(ptr); ptr += 4;
|
2002-07-28 15:35:26 +00:00
|
|
|
if (tag != MKID_BE('iMUS')) {
|
|
|
|
warning("Decompression of bundle sound failed");
|
2003-03-08 00:05:27 +00:00
|
|
|
goto bail;
|
2002-07-28 15:35:26 +00:00
|
|
|
}
|
2002-04-29 08:28:27 +00:00
|
|
|
|
2002-07-28 15:35:26 +00:00
|
|
|
ptr += 12;
|
2003-06-07 00:49:36 +00:00
|
|
|
while (tag != MKID_BE('DATA')) {
|
2002-12-28 15:02:23 +00:00
|
|
|
tag = READ_BE_UINT32(ptr); ptr += 4;
|
2002-07-28 15:35:26 +00:00
|
|
|
switch(tag) {
|
|
|
|
case MKID_BE('FRMT'):
|
2002-12-28 15:02:23 +00:00
|
|
|
ptr += 12;
|
|
|
|
bits = READ_BE_UINT32(ptr); ptr += 4;
|
|
|
|
rate = READ_BE_UINT32(ptr); ptr += 4;
|
|
|
|
channels = READ_BE_UINT32(ptr); ptr += 4;
|
2002-04-29 08:28:27 +00:00
|
|
|
break;
|
2002-07-28 15:35:26 +00:00
|
|
|
case MKID_BE('TEXT'):
|
|
|
|
case MKID_BE('REGN'):
|
|
|
|
case MKID_BE('STOP'):
|
|
|
|
case MKID_BE('JUMP'):
|
2002-12-28 15:02:23 +00:00
|
|
|
case MKID_BE('SYNC'):
|
|
|
|
size = READ_BE_UINT32(ptr); ptr += size + 4;
|
2002-04-29 08:28:27 +00:00
|
|
|
break;
|
|
|
|
|
2002-07-28 15:35:26 +00:00
|
|
|
case MKID_BE('DATA'):
|
2002-12-28 15:02:23 +00:00
|
|
|
size = READ_BE_UINT32(ptr); ptr += 4;
|
2002-07-19 17:00:27 +00:00
|
|
|
break;
|
|
|
|
|
2002-04-29 08:28:27 +00:00
|
|
|
default:
|
2003-06-13 18:09:18 +00:00
|
|
|
error("Unknown sound header %c%c%c%c",
|
|
|
|
(byte)(tag >> 24),
|
|
|
|
(byte)(tag >> 16),
|
|
|
|
(byte)(tag >> 8),
|
|
|
|
(byte)tag);
|
2002-05-01 12:57:12 +00:00
|
|
|
}
|
2002-04-29 08:28:27 +00:00
|
|
|
}
|
|
|
|
|
2002-07-28 15:35:26 +00:00
|
|
|
if (size < 0) {
|
|
|
|
warning("Decompression sound failed (no size field)");
|
2003-03-08 00:05:27 +00:00
|
|
|
goto bail;
|
2002-04-30 07:40:56 +00:00
|
|
|
}
|
2003-03-06 17:58:13 +00:00
|
|
|
|
2003-03-08 00:05:27 +00:00
|
|
|
final = (byte *)malloc(size);
|
2002-07-28 15:35:26 +00:00
|
|
|
memcpy(final, ptr, size);
|
2003-01-26 10:54:34 +00:00
|
|
|
|
|
|
|
if (_scumm->_actorToPrintStrFor != 0xFF && _scumm->_actorToPrintStrFor != 0) {
|
2003-05-25 00:30:48 +00:00
|
|
|
Actor *a = _scumm->derefActor(_scumm->_actorToPrintStrFor, "playBundleSound");
|
|
|
|
rate = (rate * a->talkFrequency) / 256;
|
2003-01-26 10:54:34 +00:00
|
|
|
}
|
|
|
|
|
2003-07-14 21:37:45 +00:00
|
|
|
// Stop any sound currently playing on the given handle
|
|
|
|
if (handle)
|
|
|
|
_scumm->_mixer->stopHandle(*handle);
|
|
|
|
|
2002-12-28 15:48:37 +00:00
|
|
|
if (bits == 8) {
|
2003-07-14 21:37:45 +00:00
|
|
|
_scumm->_mixer->playRaw(handle, final, size, rate, SoundMixer::FLAG_UNSIGNED | SoundMixer::FLAG_AUTOFREE);
|
|
|
|
} else if (bits == 16) {
|
|
|
|
_scumm->_mixer->playRaw(handle, final, size, rate, SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE);
|
2002-12-28 15:48:37 +00:00
|
|
|
} else {
|
|
|
|
warning("Sound::playBundleSound() to do more options to playRaw...");
|
|
|
|
}
|
2003-03-08 00:05:27 +00:00
|
|
|
|
|
|
|
bail:
|
2003-07-14 21:37:45 +00:00
|
|
|
free(orig_ptr);
|
2002-04-08 13:55:03 +00:00
|
|
|
}
|
|
|
|
|
2003-07-14 21:37:45 +00:00
|
|
|
void Sound::playSfxSound(void *sound, uint32 size, uint rate, bool isUnsigned, PlayingSoundHandle *handle) {
|
2002-04-21 21:58:21 +00:00
|
|
|
if (_soundsPaused)
|
2003-07-14 21:37:45 +00:00
|
|
|
return;
|
2002-08-03 11:57:10 +00:00
|
|
|
byte flags = SoundMixer::FLAG_AUTOFREE;
|
|
|
|
if (isUnsigned)
|
|
|
|
flags |= SoundMixer::FLAG_UNSIGNED;
|
2003-07-14 21:37:45 +00:00
|
|
|
_scumm->_mixer->playRaw(handle, sound, size, rate, flags);
|
2001-11-14 18:40:39 +00:00
|
|
|
}
|
|
|
|
|
2003-07-14 21:37:45 +00:00
|
|
|
void Sound::playSfxSound_MP3(void *sound, uint32 size, PlayingSoundHandle *handle) {
|
2002-10-27 01:12:10 +00:00
|
|
|
#ifdef USE_MAD
|
2003-07-14 21:37:45 +00:00
|
|
|
if (!_soundsPaused && !_scumm->_noDigitalSamples)
|
|
|
|
_scumm->_mixer->playMP3(handle, sound, size, SoundMixer::FLAG_AUTOFREE);
|
2002-04-16 18:33:04 +00:00
|
|
|
#endif
|
2002-04-15 20:22:47 +00:00
|
|
|
}
|
2002-04-17 20:23:45 +00:00
|
|
|
|
2002-10-27 11:41:08 +00:00
|
|
|
#ifdef USE_VORBIS
|
|
|
|
// Provide a virtual file to vorbisfile based on preloaded data
|
|
|
|
struct data_file_info {
|
|
|
|
char *data;
|
|
|
|
uint32 size;
|
|
|
|
int curr_pos;
|
|
|
|
};
|
|
|
|
|
|
|
|
static size_t read_data(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
data_file_info *f = (data_file_info *) datasource;
|
|
|
|
|
|
|
|
nmemb *= size;
|
|
|
|
if (f->curr_pos < 0)
|
|
|
|
return (size_t) -1;
|
|
|
|
if (f->curr_pos > (int) f->size)
|
|
|
|
nmemb = 0;
|
|
|
|
else if (f->curr_pos + nmemb > f->size)
|
|
|
|
nmemb = f->size - f->curr_pos;
|
|
|
|
|
|
|
|
memcpy(ptr, f->data + f->curr_pos, nmemb);
|
|
|
|
f->curr_pos += nmemb;
|
|
|
|
return nmemb / size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int seek_data(void *datasource, ogg_int64_t offset, int whence) {
|
|
|
|
data_file_info *f = (data_file_info *) datasource;
|
|
|
|
|
|
|
|
switch (whence) {
|
|
|
|
case SEEK_SET:
|
|
|
|
f->curr_pos = offset;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
f->curr_pos += offset;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
f->curr_pos = f->size + offset;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return f->curr_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int close_data(void *datasource) {
|
|
|
|
data_file_info *f = (data_file_info *) datasource;
|
|
|
|
|
|
|
|
free(f->data);
|
|
|
|
delete f;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long tell_data(void *datasource) {
|
|
|
|
data_file_info *f = (data_file_info *) datasource;
|
|
|
|
|
|
|
|
return f->curr_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ov_callbacks data_wrap = {
|
|
|
|
read_data, seek_data, close_data, tell_data
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2003-07-14 21:37:45 +00:00
|
|
|
void Sound::playSfxSound_Vorbis(void *sound, uint32 size, PlayingSoundHandle *handle) {
|
2002-10-27 11:41:08 +00:00
|
|
|
#ifdef USE_VORBIS
|
2003-07-14 21:37:45 +00:00
|
|
|
if (!_soundsPaused && !_scumm->_noDigitalSamples) {
|
|
|
|
OggVorbis_File *ov_file = new OggVorbis_File;
|
|
|
|
data_file_info *f = new data_file_info;
|
|
|
|
f->data = (char *) sound;
|
|
|
|
f->size = size;
|
|
|
|
f->curr_pos = 0;
|
|
|
|
|
|
|
|
if (ov_open_callbacks((void *) f, ov_file, NULL, 0, data_wrap) < 0) {
|
|
|
|
warning("Invalid file format");
|
|
|
|
delete ov_file;
|
|
|
|
delete f;
|
|
|
|
} else
|
|
|
|
_scumm->_mixer->playVorbis(handle, ov_file, 0, false);
|
2002-10-27 11:41:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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-03-06 17:58:13 +00:00
|
|
|
static void cd_timer_handler(void *ptr) {
|
2002-09-21 13:48:03 +00:00
|
|
|
Scumm *scumm = (Scumm *) ptr;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
if (_scumm->_gameId == GID_LOOM256)
|
|
|
|
timer_interval = 100;
|
|
|
|
else
|
|
|
|
timer_interval = 101;
|
|
|
|
|
|
|
|
_scumm->_timer->releaseProcedure(&cd_timer_handler);
|
2003-01-25 12:13:41 +00:00
|
|
|
_scumm->_timer->installProcedure(&cd_timer_handler, 1000 * timer_interval);
|
2002-09-21 13:48:03 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Sound::stopCDTimer() {
|
2002-09-21 13:48:03 +00:00
|
|
|
_scumm->_timer->releaseProcedure(&cd_timer_handler);
|
|
|
|
}
|
|
|
|
|
2003-06-30 22:25:08 +00:00
|
|
|
void Sound::playCDTrack(int track, int numLoops, int startFrame, int endFrame) {
|
|
|
|
if (playMP3CDTrack(track, numLoops, startFrame, endFrame) == -1)
|
|
|
|
_scumm->_system->play_cdrom(track, numLoops, startFrame, endFrame);
|
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() {
|
2002-09-21 13:48:03 +00:00
|
|
|
stopCDTimer();
|
2002-08-29 23:45:15 +00:00
|
|
|
if (stopMP3CD() == -1)
|
|
|
|
_scumm->_system->stop_cdrom();
|
|
|
|
}
|
|
|
|
|
2003-06-25 23:49:54 +00:00
|
|
|
int Sound::pollCD() const {
|
2002-08-29 23:45:15 +00:00
|
|
|
if (pollMP3CD())
|
|
|
|
return 1;
|
2002-10-28 12:56:42 +00:00
|
|
|
|
2002-08-29 23:45:15 +00:00
|
|
|
return _scumm->_system->poll_cdrom();
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void Sound::updateCD() {
|
2002-08-29 23:45:15 +00:00
|
|
|
if (updateMP3CD() == -1)
|
|
|
|
_scumm->_system->update_cdrom();
|
|
|
|
}
|
|
|
|
|
2002-08-14 20:43:56 +00:00
|
|
|
int Sound::getCachedTrack(int track) {
|
2002-04-17 20:23:45 +00:00
|
|
|
int i;
|
2002-11-19 01:52:22 +00:00
|
|
|
#if defined(USE_MAD) || defined(USE_VORBIS)
|
2002-04-17 20:23:45 +00:00
|
|
|
char track_name[1024];
|
2002-11-19 01:52:22 +00:00
|
|
|
File *file = new File();
|
|
|
|
#endif
|
2002-04-17 20:23:45 +00:00
|
|
|
int current_index;
|
|
|
|
|
|
|
|
// See if we find the track in the cache
|
2002-09-02 07:53:43 +00:00
|
|
|
for (i = 0; i < CACHE_TRACKS; i++)
|
2002-04-17 20:23:45 +00:00
|
|
|
if (_cached_tracks[i] == track) {
|
2002-10-27 01:12:10 +00:00
|
|
|
if (_track_info[i])
|
2002-04-17 20:23:45 +00:00
|
|
|
return i;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
current_index = _current_cache++;
|
|
|
|
_current_cache %= CACHE_TRACKS;
|
2002-07-27 13:12:23 +00:00
|
|
|
|
2002-04-17 20:23:45 +00:00
|
|
|
// Not found, see if it exists
|
2002-10-27 01:12:10 +00:00
|
|
|
|
|
|
|
// First, delete the previous track info object
|
|
|
|
delete _track_info[current_index];
|
|
|
|
_track_info[current_index] = NULL;
|
|
|
|
|
|
|
|
_cached_tracks[current_index] = track;
|
|
|
|
|
|
|
|
#ifdef USE_MAD
|
2002-09-15 19:28:34 +00:00
|
|
|
sprintf(track_name, "track%d.mp3", track);
|
|
|
|
file->open(track_name, _scumm->getGameDataPath());
|
2002-07-27 13:12:23 +00:00
|
|
|
|
2002-10-27 01:12:10 +00:00
|
|
|
if (file->isOpen()) {
|
|
|
|
_track_info[current_index] = new MP3TrackInfo(file);
|
|
|
|
if (_track_info[current_index]->error()) {
|
|
|
|
delete _track_info[current_index];
|
|
|
|
_track_info[current_index] = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return current_index;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_VORBIS
|
|
|
|
sprintf(track_name, "track%d.ogg", track);
|
|
|
|
file->open(track_name, _scumm->getGameDataPath());
|
|
|
|
|
|
|
|
if (file->isOpen()) {
|
|
|
|
_track_info[current_index] = new VorbisTrackInfo(file);
|
|
|
|
if (_track_info[current_index]->error()) {
|
|
|
|
delete _track_info[current_index];
|
|
|
|
_track_info[current_index] = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return current_index;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-10-28 12:56:42 +00:00
|
|
|
debug(2, "Track %d not available in compressed format", track);
|
2002-10-27 01:12:10 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-06-30 22:25:08 +00:00
|
|
|
int Sound::playMP3CDTrack(int track, int numLoops, int startFrame, int endFrame) {
|
2002-10-27 01:12:10 +00:00
|
|
|
int index;
|
2003-05-08 15:48:50 +00:00
|
|
|
_scumm->VAR(_scumm->VAR_MUSIC_TIMER) = 0;
|
2002-10-27 01:12:10 +00:00
|
|
|
|
|
|
|
if (_soundsPaused)
|
|
|
|
return 0;
|
|
|
|
|
2003-06-30 22:25:08 +00:00
|
|
|
if ((numLoops == 0) && (startFrame == 0)) {
|
2002-10-27 01:12:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
index = getCachedTrack(track);
|
|
|
|
if (index < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (_dig_cd_playing)
|
|
|
|
_scumm->_mixer->stop(_dig_cd_index);
|
2003-06-30 22:25:08 +00:00
|
|
|
_dig_cd_index = _track_info[index]->play(_scumm->_mixer, startFrame, endFrame);
|
2002-10-27 01:12:10 +00:00
|
|
|
_dig_cd_playing = true;
|
|
|
|
_dig_cd_track = track;
|
2003-06-30 22:25:08 +00:00
|
|
|
_dig_cd_num_loops = numLoops;
|
|
|
|
_dig_cd_start = startFrame;
|
|
|
|
_dig_cd_end = endFrame;
|
2002-10-27 01:12:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Sound::stopMP3CD() {
|
2003-06-26 23:04:41 +00:00
|
|
|
if (_dig_cd_playing) {
|
2002-10-27 01:12:10 +00:00
|
|
|
_scumm->_mixer->stop(_dig_cd_index);
|
|
|
|
_dig_cd_playing = false;
|
|
|
|
_dig_cd_track = 0;
|
|
|
|
_dig_cd_num_loops = 0;
|
|
|
|
_dig_cd_start = 0;
|
2003-06-30 22:25:08 +00:00
|
|
|
_dig_cd_end = 0;
|
2002-10-27 01:12:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-06-26 23:04:41 +00:00
|
|
|
int Sound::pollMP3CD() const {
|
|
|
|
if (_dig_cd_playing)
|
2002-10-27 01:12:10 +00:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Sound::updateMP3CD() {
|
|
|
|
if (_dig_cd_playing == false)
|
|
|
|
return -1;
|
2002-09-02 07:53:43 +00:00
|
|
|
|
2002-10-27 01:12:10 +00:00
|
|
|
if (_scumm->_mixer->_channels[_dig_cd_index] == NULL) {
|
|
|
|
warning("Error in MP3 decoding");
|
2002-04-17 20:23:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2002-09-02 07:53:43 +00:00
|
|
|
|
2003-06-22 01:55:53 +00:00
|
|
|
if (!_scumm->_mixer->isActiveChannel(_dig_cd_index)) {
|
2002-10-27 01:12:10 +00:00
|
|
|
if (_dig_cd_num_loops == -1 || --_dig_cd_num_loops > 0)
|
2003-06-30 22:25:08 +00:00
|
|
|
playMP3CDTrack(_dig_cd_track, _dig_cd_num_loops, _dig_cd_start, _dig_cd_end);
|
2002-10-27 01:12:10 +00:00
|
|
|
else
|
|
|
|
stopMP3CD();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_MAD
|
2003-06-15 00:54:14 +00:00
|
|
|
MP3TrackInfo::MP3TrackInfo(File *file) {
|
2002-10-27 01:12:10 +00:00
|
|
|
struct mad_stream stream;
|
|
|
|
struct mad_frame frame;
|
|
|
|
unsigned char buffer[8192];
|
|
|
|
unsigned int buflen = 0;
|
|
|
|
int count = 0;
|
|
|
|
|
2002-04-17 20:23:45 +00:00
|
|
|
// Check the format and bitrate
|
|
|
|
mad_stream_init(&stream);
|
|
|
|
mad_frame_init(&frame);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (buflen < sizeof(buffer)) {
|
2002-04-19 16:56:58 +00:00
|
|
|
int bytes;
|
2002-04-17 20:23:45 +00:00
|
|
|
|
2002-09-02 07:53:43 +00:00
|
|
|
bytes = file->read(buffer + buflen, sizeof(buffer) - buflen);
|
2002-04-17 20:23:45 +00:00
|
|
|
if (bytes <= 0) {
|
|
|
|
if (bytes == -1) {
|
2002-10-27 01:12:10 +00:00
|
|
|
warning("Invalid file format");
|
2002-04-26 17:11:05 +00:00
|
|
|
goto error;
|
2002-04-17 20:23:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
buflen += bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
mad_stream_buffer(&stream, buffer, buflen);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (mad_frame_decode(&frame, &stream) == -1) {
|
|
|
|
if (!MAD_RECOVERABLE(stream.error))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (stream.error != MAD_ERROR_BADCRC)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count++)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count || stream.error != MAD_ERROR_BUFLEN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
memmove(buffer, stream.next_frame,
|
2002-04-26 17:11:05 +00:00
|
|
|
buflen = &buffer[buflen] - stream.next_frame);
|
2002-04-17 20:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count)
|
2002-10-27 01:12:10 +00:00
|
|
|
memcpy(&_mad_header, &frame.header, sizeof(mad_header));
|
2002-04-17 20:23:45 +00:00
|
|
|
else {
|
2002-10-27 01:12:10 +00:00
|
|
|
warning("Invalid file format");
|
2002-04-26 17:11:05 +00:00
|
|
|
goto error;
|
2002-04-17 20:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mad_frame_finish(&frame);
|
|
|
|
mad_stream_finish(&stream);
|
|
|
|
// Get file size
|
2002-10-27 01:12:10 +00:00
|
|
|
_size = file->size();
|
|
|
|
_file = file;
|
|
|
|
_error_flag = false;
|
|
|
|
return;
|
2002-04-26 17:11:05 +00:00
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
error:
|
2002-04-26 17:11:05 +00:00
|
|
|
mad_frame_finish(&frame);
|
|
|
|
mad_stream_finish(&stream);
|
2002-10-27 01:12:10 +00:00
|
|
|
_error_flag = true;
|
2002-09-02 07:53:43 +00:00
|
|
|
delete file;
|
2002-04-17 20:23:45 +00:00
|
|
|
}
|
2002-04-22 11:36:41 +00:00
|
|
|
|
2003-06-30 22:25:08 +00:00
|
|
|
int MP3TrackInfo::play(SoundMixer *mixer, int startFrame, int endFrame) {
|
2002-05-03 21:37:49 +00:00
|
|
|
unsigned int offset;
|
2002-04-17 20:23:45 +00:00
|
|
|
mad_timer_t duration;
|
|
|
|
|
2002-05-03 21:37:49 +00:00
|
|
|
// Calc offset. As all bitrates are in kilobit per seconds, the division by 200 is always exact
|
2003-06-30 22:25:08 +00:00
|
|
|
offset = (startFrame * (_mad_header.bitrate / (8 * 25))) / 3;
|
2002-05-03 21:11:16 +00:00
|
|
|
|
2002-04-17 20:23:45 +00:00
|
|
|
// Calc delay
|
2003-06-30 22:25:08 +00:00
|
|
|
if (!endFrame) {
|
2002-10-27 01:12:10 +00:00
|
|
|
mad_timer_set(&duration, (_size * 8) / _mad_header.bitrate,
|
|
|
|
(_size * 8) % _mad_header.bitrate, _mad_header.bitrate);
|
2002-04-22 11:18:11 +00:00
|
|
|
} else {
|
2003-06-30 22:25:08 +00:00
|
|
|
mad_timer_set(&duration, endFrame / 75, endFrame % 75, 75);
|
2002-04-22 11:18:11 +00:00
|
|
|
}
|
|
|
|
|
2002-04-17 20:23:45 +00:00
|
|
|
// Go
|
2002-10-27 01:12:10 +00:00
|
|
|
_file->seek(offset, SEEK_SET);
|
|
|
|
|
|
|
|
return mixer->playMP3CDTrack(NULL, _file, duration);
|
2002-04-17 20:23:45 +00:00
|
|
|
}
|
|
|
|
|
2003-06-15 00:54:14 +00:00
|
|
|
MP3TrackInfo::~MP3TrackInfo() {
|
2002-10-27 01:12:10 +00:00
|
|
|
if (! _error_flag)
|
|
|
|
_file->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_VORBIS
|
|
|
|
// These are wrapper functions to allow using a File object to
|
|
|
|
// provide data to the OggVorbis_File object.
|
|
|
|
|
|
|
|
struct file_info {
|
|
|
|
File *file;
|
|
|
|
int start, curr_pos;
|
|
|
|
size_t len;
|
|
|
|
};
|
|
|
|
|
|
|
|
static size_t read_wrap(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
file_info *f = (file_info *) datasource;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
nmemb *= size;
|
|
|
|
if (f->curr_pos > (int) f->len)
|
|
|
|
nmemb = 0;
|
|
|
|
else if (nmemb > f->len - f->curr_pos)
|
|
|
|
nmemb = f->len - f->curr_pos;
|
|
|
|
result = f->file->read(ptr, nmemb);
|
|
|
|
if (result == -1) {
|
|
|
|
f->curr_pos = f->file->pos() - f->start;
|
|
|
|
return (size_t) -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
f->curr_pos += result;
|
|
|
|
return result / size;
|
2002-04-28 14:01:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-27 01:12:10 +00:00
|
|
|
static int seek_wrap(void *datasource, ogg_int64_t offset, int whence) {
|
|
|
|
file_info *f = (file_info *) datasource;
|
|
|
|
|
|
|
|
if (whence == SEEK_SET)
|
|
|
|
offset += f->start;
|
|
|
|
else if (whence == SEEK_END) {
|
|
|
|
offset += f->start + f->len;
|
|
|
|
whence = SEEK_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
f->file->seek(offset, whence);
|
|
|
|
f->curr_pos = f->file->pos() - f->start;
|
|
|
|
return f->curr_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int close_wrap(void *datasource) {
|
|
|
|
file_info *f = (file_info *) datasource;
|
|
|
|
|
|
|
|
f->file->close();
|
|
|
|
delete f;
|
2002-04-28 14:01:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-27 01:12:10 +00:00
|
|
|
static long tell_wrap(void *datasource) {
|
|
|
|
file_info *f = (file_info *) datasource;
|
2002-04-28 14:01:40 +00:00
|
|
|
|
2002-10-27 01:12:10 +00:00
|
|
|
return f->file->pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
static ov_callbacks File_wrap = {
|
|
|
|
read_wrap, seek_wrap, close_wrap, tell_wrap
|
|
|
|
};
|
|
|
|
|
2003-06-15 00:54:14 +00:00
|
|
|
VorbisTrackInfo::VorbisTrackInfo(File *file) {
|
2002-10-27 01:12:10 +00:00
|
|
|
file_info *f = new file_info;
|
|
|
|
|
|
|
|
f->file = file;
|
|
|
|
f->start = 0;
|
|
|
|
f->len = file->size();
|
|
|
|
f->curr_pos = file->pos();
|
|
|
|
|
|
|
|
if (ov_open_callbacks((void *) f, &_ov_file, NULL, 0, File_wrap) < 0) {
|
|
|
|
warning("Invalid file format");
|
|
|
|
_error_flag = true;
|
|
|
|
delete f;
|
|
|
|
delete file;
|
2002-04-28 14:01:40 +00:00
|
|
|
}
|
2002-10-27 01:12:10 +00:00
|
|
|
else {
|
|
|
|
_error_flag = false;
|
|
|
|
_file = file;
|
2002-04-28 14:01:40 +00:00
|
|
|
|
2002-10-27 01:12:10 +00:00
|
|
|
// Check the file format
|
|
|
|
if (ov_info(&_ov_file, -1)->rate != 22050)
|
|
|
|
warning("Vorbis code currently only supports files encoded at 22050 Hz");
|
2002-10-20 13:17:43 +00:00
|
|
|
}
|
2002-10-27 01:12:10 +00:00
|
|
|
}
|
2002-10-20 13:17:43 +00:00
|
|
|
|
2003-04-05 09:55:12 +00:00
|
|
|
#ifdef CHUNKSIZE
|
|
|
|
#define VORBIS_TREMOR
|
|
|
|
#endif
|
|
|
|
|
2003-06-30 22:25:08 +00:00
|
|
|
int VorbisTrackInfo::play(SoundMixer *mixer, int startFrame, int endFrame) {
|
2003-04-05 09:55:12 +00:00
|
|
|
#ifdef VORBIS_TREMOR
|
2003-06-30 22:25:08 +00:00
|
|
|
ov_time_seek(&_ov_file, (ogg_int64_t)(startFrame / 75.0 * 1000));
|
2003-04-05 09:55:12 +00:00
|
|
|
#else
|
2003-06-30 22:25:08 +00:00
|
|
|
ov_time_seek(&_ov_file, startFrame / 75.0);
|
2003-04-05 09:55:12 +00:00
|
|
|
#endif
|
2002-10-27 11:41:08 +00:00
|
|
|
return mixer->playVorbis(NULL, &_ov_file,
|
2003-06-30 22:25:08 +00:00
|
|
|
endFrame * ov_info(&_ov_file, -1)->rate / 75,
|
2002-10-27 11:41:08 +00:00
|
|
|
true);
|
2002-10-27 01:12:10 +00:00
|
|
|
}
|
|
|
|
|
2003-06-15 00:54:14 +00:00
|
|
|
VorbisTrackInfo::~VorbisTrackInfo() {
|
2002-10-27 01:12:10 +00:00
|
|
|
if (! _error_flag) {
|
|
|
|
ov_clear(&_ov_file);
|
|
|
|
delete _file;
|
|
|
|
}
|
2002-04-28 14:01:40 +00:00
|
|
|
}
|
2002-10-27 01:12:10 +00:00
|
|
|
|
|
|
|
#endif
|