2002-11-29 22:09:52 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2005-01-01 16:09:25 +00:00
|
|
|
* Copyright (C) 2001-2005 The ScummVM project
|
2002-11-29 22:09:52 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* 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.
|
2002-11-29 22:09:52 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2004-11-27 15:58:18 +00:00
|
|
|
|
2002-11-29 22:09:52 +00:00
|
|
|
#include "common/file.h"
|
2003-09-10 12:31:20 +00:00
|
|
|
#include "common/util.h"
|
2004-11-27 15:58:18 +00:00
|
|
|
|
2005-11-12 06:01:24 +00:00
|
|
|
#include "simon/simon.h"
|
2003-09-07 20:30:02 +00:00
|
|
|
#include "simon/sound.h"
|
2004-11-27 15:58:18 +00:00
|
|
|
|
|
|
|
#include "sound/flac.h"
|
|
|
|
#include "sound/mp3.h"
|
2003-09-07 20:30:02 +00:00
|
|
|
#include "sound/voc.h"
|
2004-11-27 15:58:18 +00:00
|
|
|
#include "sound/vorbis.h"
|
2005-01-09 15:57:38 +00:00
|
|
|
#include "sound/wave.h"
|
2002-11-29 22:09:52 +00:00
|
|
|
|
2005-05-10 22:56:25 +00:00
|
|
|
using Common::File;
|
|
|
|
|
2003-10-03 19:42:27 +00:00
|
|
|
namespace Simon {
|
|
|
|
|
2003-07-21 04:00:04 +00:00
|
|
|
#define SOUND_BIG_ENDIAN true
|
|
|
|
|
2003-06-15 12:22:19 +00:00
|
|
|
class BaseSound {
|
2003-06-15 11:48:04 +00:00
|
|
|
protected:
|
|
|
|
File *_file;
|
|
|
|
uint32 *_offsets;
|
2005-05-10 23:48:48 +00:00
|
|
|
Audio::Mixer *_mixer;
|
2004-01-19 17:46:08 +00:00
|
|
|
bool _freeOffsets;
|
2003-06-15 11:48:04 +00:00
|
|
|
|
|
|
|
public:
|
2005-05-10 23:48:48 +00:00
|
|
|
BaseSound(Audio::Mixer *mixer, File *file, uint32 base = 0, bool bigendian = false);
|
|
|
|
BaseSound(Audio::Mixer *mixer, File *file, uint32 *offsets, bool bigendian = false);
|
2003-06-21 15:36:19 +00:00
|
|
|
virtual ~BaseSound();
|
2005-05-11 00:01:44 +00:00
|
|
|
virtual void playSound(uint sound, Audio::SoundHandle *handle, byte flags) = 0;
|
2003-06-15 11:48:04 +00:00
|
|
|
};
|
|
|
|
|
2003-06-15 12:22:19 +00:00
|
|
|
class WavSound : public BaseSound {
|
2003-06-15 11:48:04 +00:00
|
|
|
public:
|
2005-05-10 23:48:48 +00:00
|
|
|
WavSound(Audio::Mixer *mixer, File *file, uint32 base = 0, bool bigendian = false) : BaseSound(mixer, file, base, bigendian) {};
|
|
|
|
WavSound(Audio::Mixer *mixer, File *file, uint32 *offsets) : BaseSound(mixer, file, offsets) {};
|
2005-05-11 00:01:44 +00:00
|
|
|
void playSound(uint sound, Audio::SoundHandle *handle, byte flags);
|
2003-06-15 11:48:04 +00:00
|
|
|
};
|
|
|
|
|
2003-06-15 12:22:19 +00:00
|
|
|
class VocSound : public BaseSound {
|
2003-06-15 11:48:04 +00:00
|
|
|
public:
|
2005-05-10 23:48:48 +00:00
|
|
|
VocSound(Audio::Mixer *mixer, File *file, uint32 base = 0, bool bigendian = false) : BaseSound(mixer, file, base, bigendian) {};
|
2005-05-11 00:01:44 +00:00
|
|
|
void playSound(uint sound, Audio::SoundHandle *handle, byte flags);
|
2003-07-21 04:00:04 +00:00
|
|
|
};
|
|
|
|
class RawSound : public BaseSound {
|
|
|
|
public:
|
2005-05-10 23:48:48 +00:00
|
|
|
RawSound(Audio::Mixer *mixer, File *file, uint32 base = 0, bool bigendian = false) : BaseSound(mixer, file, base, bigendian) {};
|
2005-05-11 00:01:44 +00:00
|
|
|
void playSound(uint sound, Audio::SoundHandle *handle, byte flags);
|
2003-06-15 11:48:04 +00:00
|
|
|
};
|
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
BaseSound::BaseSound(Audio::Mixer *mixer, File *file, uint32 base, bool bigendian) {
|
2003-06-15 12:22:19 +00:00
|
|
|
_mixer = mixer;
|
|
|
|
_file = file;
|
|
|
|
|
|
|
|
uint res = 0;
|
|
|
|
uint32 size;
|
|
|
|
|
|
|
|
_file->seek(base + sizeof(uint32), SEEK_SET);
|
2003-07-21 04:00:04 +00:00
|
|
|
if (bigendian)
|
|
|
|
size = _file->readUint32BE();
|
|
|
|
else
|
|
|
|
size = _file->readUint32LE();
|
2003-06-15 12:22:19 +00:00
|
|
|
|
|
|
|
res = size / sizeof(uint32);
|
|
|
|
|
|
|
|
_offsets = (uint32 *)malloc(size + sizeof(uint32));
|
2004-01-19 17:46:08 +00:00
|
|
|
_freeOffsets = true;
|
2003-06-15 12:22:19 +00:00
|
|
|
|
|
|
|
_file->seek(base, SEEK_SET);
|
|
|
|
|
|
|
|
if (_file->read(_offsets, size) != size)
|
|
|
|
error("Can't read offsets");
|
|
|
|
|
|
|
|
for (uint i = 0; i < res; i++) {
|
|
|
|
#if defined(SCUMM_BIG_ENDIAN)
|
2003-07-21 04:00:04 +00:00
|
|
|
if (!(bigendian))
|
2003-06-15 12:22:19 +00:00
|
|
|
_offsets[i] = FROM_LE_32(_offsets[i]);
|
|
|
|
#endif
|
2003-07-21 04:00:04 +00:00
|
|
|
if (bigendian)
|
|
|
|
_offsets[i] = TO_BE_32(_offsets[i]);
|
2003-06-15 12:22:19 +00:00
|
|
|
_offsets[i] += base;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only needed for mp3
|
|
|
|
_file->seek(0, SEEK_END);
|
|
|
|
_offsets[res] = _file->pos();
|
|
|
|
}
|
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
BaseSound::BaseSound(Audio::Mixer *mixer, File *file, uint32 *offsets, bool bigendian) {
|
2003-06-15 12:22:19 +00:00
|
|
|
_mixer = mixer;
|
|
|
|
_file = file;
|
|
|
|
_offsets = offsets;
|
2004-01-19 17:46:08 +00:00
|
|
|
_freeOffsets = false;
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2003-06-21 15:36:19 +00:00
|
|
|
BaseSound::~BaseSound() {
|
2004-01-19 17:46:08 +00:00
|
|
|
if (_freeOffsets)
|
|
|
|
free(_offsets);
|
2003-06-21 15:36:19 +00:00
|
|
|
delete _file;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-11 00:01:44 +00:00
|
|
|
void WavSound::playSound(uint sound, Audio::SoundHandle *handle, byte flags) {
|
2003-06-15 12:22:19 +00:00
|
|
|
if (_offsets == NULL)
|
2003-12-21 00:05:00 +00:00
|
|
|
return;
|
2003-06-15 12:22:19 +00:00
|
|
|
|
|
|
|
_file->seek(_offsets[sound], SEEK_SET);
|
|
|
|
|
2005-01-14 00:38:54 +00:00
|
|
|
// Try to load the WAVE data into an audio stream
|
|
|
|
AudioStream *stream = makeWAVStream(*_file);
|
|
|
|
if (!stream) {
|
|
|
|
error("playWav(%d): can't read WAVE header", sound);
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, stream);
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 00:01:44 +00:00
|
|
|
void VocSound::playSound(uint sound, Audio::SoundHandle *handle, byte flags) {
|
2003-06-15 12:22:19 +00:00
|
|
|
if (_offsets == NULL)
|
2003-12-21 00:05:00 +00:00
|
|
|
return;
|
2003-06-15 12:22:19 +00:00
|
|
|
|
|
|
|
_file->seek(_offsets[sound], SEEK_SET);
|
|
|
|
|
2003-12-27 14:11:03 +00:00
|
|
|
int size, samples_per_sec;
|
2004-12-11 23:34:34 +00:00
|
|
|
byte *buffer = loadVOCFromStream(*_file, size, samples_per_sec);
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
_mixer->playRaw(handle, buffer, size, samples_per_sec, flags | Audio::Mixer::FLAG_AUTOFREE);
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 00:01:44 +00:00
|
|
|
void RawSound::playSound(uint sound, Audio::SoundHandle *handle, byte flags) {
|
2003-07-21 04:00:04 +00:00
|
|
|
if (_offsets == NULL)
|
2003-12-21 00:05:00 +00:00
|
|
|
return;
|
2003-07-21 04:00:04 +00:00
|
|
|
|
|
|
|
_file->seek(_offsets[sound], SEEK_SET);
|
2003-12-27 14:11:03 +00:00
|
|
|
|
2003-07-21 04:00:04 +00:00
|
|
|
uint size = _file->readUint32BE();
|
|
|
|
byte *buffer = (byte *)malloc(size);
|
|
|
|
_file->read(buffer, size);
|
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
_mixer->playRaw(handle, buffer, size, 22050, flags | Audio::Mixer::FLAG_AUTOFREE);
|
2003-07-21 04:00:04 +00:00
|
|
|
}
|
|
|
|
|
2003-06-15 12:22:19 +00:00
|
|
|
#ifdef USE_MAD
|
2003-06-24 21:52:52 +00:00
|
|
|
class MP3Sound : public BaseSound {
|
|
|
|
public:
|
2005-05-10 23:48:48 +00:00
|
|
|
MP3Sound(Audio::Mixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {};
|
2005-05-11 00:01:44 +00:00
|
|
|
void playSound(uint sound, Audio::SoundHandle *handle, byte flags);
|
2003-06-24 21:52:52 +00:00
|
|
|
};
|
|
|
|
|
2005-05-11 00:01:44 +00:00
|
|
|
void MP3Sound::playSound(uint sound, Audio::SoundHandle *handle, byte flags)
|
2003-06-15 12:22:19 +00:00
|
|
|
{
|
|
|
|
if (_offsets == NULL)
|
2003-12-21 00:05:00 +00:00
|
|
|
return;
|
2003-06-15 12:22:19 +00:00
|
|
|
|
|
|
|
_file->seek(_offsets[sound], SEEK_SET);
|
|
|
|
|
2004-01-19 17:44:04 +00:00
|
|
|
int i = 1;
|
|
|
|
while (_offsets[sound + i] == _offsets[sound])
|
|
|
|
i++;
|
|
|
|
|
|
|
|
uint32 size = _offsets[sound + i] - _offsets[sound];
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, makeMP3Stream(_file, size));
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-08-10 12:42:56 +00:00
|
|
|
#ifdef USE_VORBIS
|
2003-12-21 16:01:36 +00:00
|
|
|
class VorbisSound : public BaseSound {
|
|
|
|
public:
|
2005-05-10 23:48:48 +00:00
|
|
|
VorbisSound(Audio::Mixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {};
|
2005-05-11 00:01:44 +00:00
|
|
|
void playSound(uint sound, Audio::SoundHandle *handle, byte flags);
|
2003-12-21 16:01:36 +00:00
|
|
|
};
|
|
|
|
|
2005-05-11 00:01:44 +00:00
|
|
|
void VorbisSound::playSound(uint sound, Audio::SoundHandle *handle, byte flags)
|
2003-12-21 16:01:36 +00:00
|
|
|
{
|
|
|
|
if (_offsets == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_file->seek(_offsets[sound], SEEK_SET);
|
|
|
|
|
2004-01-19 17:44:04 +00:00
|
|
|
int i = 1;
|
|
|
|
while (_offsets[sound + i] == _offsets[sound])
|
|
|
|
i++;
|
|
|
|
|
2004-01-19 17:50:38 +00:00
|
|
|
uint32 size = _offsets[sound + i] - _offsets[sound];
|
2003-12-21 16:01:36 +00:00
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, makeVorbisStream(_file, size));
|
2003-12-21 16:01:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-02-22 14:11:16 +00:00
|
|
|
#ifdef USE_FLAC
|
|
|
|
class FlacSound : public BaseSound {
|
|
|
|
public:
|
2005-05-10 23:48:48 +00:00
|
|
|
FlacSound(Audio::Mixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {};
|
2005-05-11 00:01:44 +00:00
|
|
|
void playSound(uint sound, Audio::SoundHandle *handle, byte flags);
|
2004-02-22 14:11:16 +00:00
|
|
|
};
|
|
|
|
|
2005-05-11 00:01:44 +00:00
|
|
|
void FlacSound::playSound(uint sound, Audio::SoundHandle *handle, byte flags)
|
2004-02-22 14:11:16 +00:00
|
|
|
{
|
|
|
|
if (_offsets == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_file->seek(_offsets[sound], SEEK_SET);
|
|
|
|
|
|
|
|
int i = 1;
|
|
|
|
while (_offsets[sound + i] == _offsets[sound])
|
|
|
|
i++;
|
|
|
|
|
|
|
|
uint32 size = _offsets[sound + i] - _offsets[sound];
|
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, makeFlacStream(_file, size));
|
2004-02-22 14:11:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-11-12 06:01:24 +00:00
|
|
|
Sound::Sound(SimonEngine *vm, const GameSpecificSettings *gss, Audio::Mixer *mixer)
|
|
|
|
: _vm(vm), _mixer(mixer) {
|
2003-05-20 15:17:21 +00:00
|
|
|
_voice = 0;
|
|
|
|
_effects = 0;
|
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
_effectsPaused = false;
|
|
|
|
_ambientPaused = false;
|
2002-11-29 22:09:52 +00:00
|
|
|
|
2003-05-20 15:17:21 +00:00
|
|
|
_filenums = 0;
|
2005-05-08 12:33:25 +00:00
|
|
|
_lastVoiceFile = 0;
|
2003-05-20 15:17:21 +00:00
|
|
|
_offsets = 0;
|
|
|
|
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasEffectsFile = false;
|
|
|
|
_hasVoiceFile = false;
|
|
|
|
_ambientPlaying = 0;
|
2003-01-12 02:01:07 +00:00
|
|
|
|
2005-11-12 06:01:24 +00:00
|
|
|
// SIMON1CD32 uses separate speech files
|
|
|
|
if (!(_vm->getFeatures() & GF_TALKIE) || (_vm->getGameId() == GID_SIMON1CD32))
|
2005-05-06 03:09:53 +00:00
|
|
|
return;
|
|
|
|
|
2003-06-14 15:19:41 +00:00
|
|
|
File *file = new File();
|
2002-11-29 22:09:52 +00:00
|
|
|
|
2004-02-22 14:11:16 +00:00
|
|
|
#ifdef USE_FLAC
|
2005-08-30 12:30:11 +00:00
|
|
|
if (!_hasVoiceFile && gss->flac_filename && gss->flac_filename[0]) {
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(gss->flac_filename);
|
2004-02-22 14:11:16 +00:00
|
|
|
if (file->isOpen()) {
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasVoiceFile = true;
|
2004-02-22 14:11:16 +00:00
|
|
|
_voice = new FlacSound(_mixer, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2002-11-29 22:09:52 +00:00
|
|
|
#ifdef USE_MAD
|
2005-08-30 12:30:11 +00:00
|
|
|
if (!_hasVoiceFile && gss->mp3_filename && gss->mp3_filename[0]) {
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(gss->mp3_filename);
|
2003-12-21 16:01:36 +00:00
|
|
|
if (file->isOpen()) {
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasVoiceFile = true;
|
2003-12-21 16:01:36 +00:00
|
|
|
_voice = new MP3Sound(_mixer, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2005-08-10 12:42:56 +00:00
|
|
|
#ifdef USE_VORBIS
|
2005-08-30 12:30:11 +00:00
|
|
|
if (!_hasVoiceFile && gss->vorbis_filename && gss->vorbis_filename[0]) {
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(gss->vorbis_filename);
|
2003-12-21 16:01:36 +00:00
|
|
|
if (file->isOpen()) {
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasVoiceFile = true;
|
2003-12-21 16:01:36 +00:00
|
|
|
_voice = new VorbisSound(_mixer, file);
|
|
|
|
}
|
2003-11-29 11:56:24 +00:00
|
|
|
}
|
2002-11-29 22:09:52 +00:00
|
|
|
#endif
|
2005-11-12 06:01:24 +00:00
|
|
|
if (!_hasVoiceFile && _vm->getGameType() == GType_SIMON2) {
|
2003-03-06 13:51:56 +00:00
|
|
|
// for simon2 mac/amiga, only read index file
|
2004-07-30 09:00:29 +00:00
|
|
|
file->open("voices.idx");
|
|
|
|
if (file->isOpen() == true) {
|
|
|
|
file->seek(0, SEEK_END);
|
|
|
|
int end = file->pos();
|
|
|
|
file->seek(0, SEEK_SET);
|
|
|
|
_filenums = (uint16 *)malloc((end / 6 + 1) * 2);
|
|
|
|
_offsets = (uint32 *)malloc((end / 6 + 1) * 4);
|
|
|
|
|
|
|
|
for (int i = 1; i <= end / 6; i++) {
|
|
|
|
_filenums[i] = file->readUint16BE();
|
|
|
|
_offsets[i] = file->readUint32BE();
|
2005-05-08 02:50:43 +00:00
|
|
|
}
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasVoiceFile = true;
|
2005-05-06 03:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-30 12:30:11 +00:00
|
|
|
if (!_hasVoiceFile && gss->wav_filename && gss->wav_filename[0]) {
|
2005-05-08 02:50:43 +00:00
|
|
|
file->open(gss->wav_filename);
|
|
|
|
if (file->isOpen()) {
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasVoiceFile = true;
|
2005-05-08 02:50:43 +00:00
|
|
|
_voice = new WavSound(_mixer, file);
|
|
|
|
}
|
2005-05-06 03:09:53 +00:00
|
|
|
}
|
2005-08-30 12:30:11 +00:00
|
|
|
if (!_hasVoiceFile && gss->voc_filename && gss->voc_filename[0]) {
|
2005-05-08 02:50:43 +00:00
|
|
|
file->open(gss->voc_filename);
|
|
|
|
if (file->isOpen()) {
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasVoiceFile = true;
|
2005-05-08 02:50:43 +00:00
|
|
|
_voice = new VocSound(_mixer, file);
|
2003-01-11 16:00:55 +00:00
|
|
|
}
|
2003-03-06 13:51:56 +00:00
|
|
|
}
|
2002-11-29 22:09:52 +00:00
|
|
|
|
2005-11-12 06:01:24 +00:00
|
|
|
if ((_vm->getGameType() == GType_SIMON1) && (_vm->getFeatures() & GF_TALKIE)) {
|
2003-06-20 12:25:37 +00:00
|
|
|
file = new File();
|
2002-11-29 22:09:52 +00:00
|
|
|
#ifdef USE_MAD
|
2005-08-30 12:30:11 +00:00
|
|
|
if (!_hasEffectsFile && gss->mp3_effects_filename && gss->mp3_effects_filename[0]) {
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(gss->mp3_effects_filename);
|
2003-12-21 16:01:36 +00:00
|
|
|
if (file->isOpen()) {
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasEffectsFile = true;
|
2003-12-21 16:01:36 +00:00
|
|
|
_effects = new MP3Sound(_mixer, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2005-08-10 12:42:56 +00:00
|
|
|
#ifdef USE_VORBIS
|
2005-08-30 12:30:11 +00:00
|
|
|
if (!_hasEffectsFile && gss->vorbis_effects_filename && gss->vorbis_effects_filename[0]) {
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(gss->vorbis_effects_filename);
|
2003-12-21 16:01:36 +00:00
|
|
|
if (file->isOpen()) {
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasEffectsFile = true;
|
2003-12-21 16:01:36 +00:00
|
|
|
_effects = new VorbisSound(_mixer, file);
|
|
|
|
}
|
2003-11-29 11:56:24 +00:00
|
|
|
}
|
2004-02-22 14:11:16 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_FLAC
|
2005-08-30 12:30:11 +00:00
|
|
|
if (!_hasEffectsFile && gss->flac_effects_filename && gss->flac_effects_filename[0]) {
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(gss->flac_effects_filename);
|
2004-02-22 14:11:16 +00:00
|
|
|
if (file->isOpen()) {
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasEffectsFile = true;
|
2004-02-22 14:11:16 +00:00
|
|
|
_effects = new FlacSound(_mixer, file);
|
|
|
|
}
|
|
|
|
}
|
2003-01-11 16:00:55 +00:00
|
|
|
#endif
|
2005-08-30 12:30:11 +00:00
|
|
|
if (!_hasEffectsFile && gss->voc_effects_filename && gss->voc_effects_filename[0]) {
|
2005-05-08 04:54:08 +00:00
|
|
|
file->open(gss->voc_effects_filename);
|
|
|
|
if (file->isOpen()) {
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasEffectsFile = true;
|
2003-06-20 12:25:37 +00:00
|
|
|
_effects = new VocSound(_mixer, file);
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
2003-01-11 16:00:55 +00:00
|
|
|
}
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-03 01:28:00 +00:00
|
|
|
Sound::~Sound() {
|
2003-06-21 15:36:19 +00:00
|
|
|
delete _voice;
|
|
|
|
delete _effects;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-21 15:36:19 +00:00
|
|
|
free(_filenums);
|
|
|
|
free(_offsets);
|
|
|
|
}
|
|
|
|
|
2004-06-27 22:14:35 +00:00
|
|
|
void Sound::readSfxFile(const char *filename) {
|
2005-05-08 12:33:25 +00:00
|
|
|
if (_hasEffectsFile)
|
2005-05-08 05:23:31 +00:00
|
|
|
return;
|
|
|
|
|
2002-11-29 22:09:52 +00:00
|
|
|
stopAll();
|
|
|
|
|
2003-06-14 15:19:41 +00:00
|
|
|
File *file = new File();
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(filename);
|
2002-11-29 22:09:52 +00:00
|
|
|
|
2003-06-14 15:19:41 +00:00
|
|
|
if (file->isOpen() == false) {
|
2002-12-10 09:50:22 +00:00
|
|
|
char *filename2;
|
2003-03-25 12:25:06 +00:00
|
|
|
filename2 = (char *)malloc(strlen(filename) + 2);
|
2002-12-08 23:06:11 +00:00
|
|
|
strcpy(filename2, filename);
|
|
|
|
strcat(filename2, ".");
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(filename2);
|
2002-12-10 09:50:22 +00:00
|
|
|
free(filename2);
|
2003-06-14 15:19:41 +00:00
|
|
|
if (file->isOpen() == false) {
|
2002-12-08 23:06:11 +00:00
|
|
|
if (atoi(filename + 6) != 1 && atoi(filename + 6) != 30)
|
2003-10-23 04:49:04 +00:00
|
|
|
warning("readSfxFile: Can't load sfx file %s", filename);
|
2002-12-08 23:06:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2003-07-24 16:54:40 +00:00
|
|
|
delete _effects;
|
2005-11-12 06:01:24 +00:00
|
|
|
if (_vm->getGameId() == GID_SIMON1CD32) {
|
2003-07-21 04:00:04 +00:00
|
|
|
_effects = new VocSound(_mixer, file, 0, SOUND_BIG_ENDIAN);
|
|
|
|
} else
|
|
|
|
_effects = new WavSound(_mixer, file);
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 01:28:00 +00:00
|
|
|
void Sound::loadSfxTable(File *gameFile, uint32 base) {
|
2002-11-29 22:09:52 +00:00
|
|
|
stopAll();
|
|
|
|
|
2005-11-12 06:01:24 +00:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformWindows)
|
2002-11-29 22:09:52 +00:00
|
|
|
_effects = new WavSound(_mixer, gameFile, base);
|
|
|
|
else
|
|
|
|
_effects = new VocSound(_mixer, gameFile, base);
|
|
|
|
}
|
|
|
|
|
2004-06-27 22:14:35 +00:00
|
|
|
void Sound::readVoiceFile(const char *filename) {
|
2003-07-21 04:00:04 +00:00
|
|
|
stopAll();
|
|
|
|
|
|
|
|
File *file = new File();
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(filename);
|
2003-07-21 04:00:04 +00:00
|
|
|
|
|
|
|
if (file->isOpen() == false) {
|
|
|
|
char *filename2;
|
|
|
|
filename2 = (char *)malloc(strlen(filename) + 2);
|
|
|
|
strcpy(filename2, filename);
|
|
|
|
strcat(filename2, ".");
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(filename2);
|
2003-07-21 04:00:04 +00:00
|
|
|
free(filename2);
|
|
|
|
if (file->isOpen() == false) {
|
|
|
|
warning("readVoiceFile: Can't load voice file %s", filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-24 16:54:40 +00:00
|
|
|
delete _voice;
|
2003-07-21 04:00:04 +00:00
|
|
|
_voice = new RawSound(_mixer, file, 0, SOUND_BIG_ENDIAN);
|
|
|
|
}
|
|
|
|
|
2004-01-03 01:28:00 +00:00
|
|
|
void Sound::playVoice(uint sound) {
|
2004-07-30 09:00:29 +00:00
|
|
|
if (_filenums) {
|
2005-05-08 12:33:25 +00:00
|
|
|
if (_lastVoiceFile != _filenums[sound]) {
|
2003-12-13 01:54:17 +00:00
|
|
|
stopAll();
|
|
|
|
|
|
|
|
char filename[16];
|
2005-05-08 12:33:25 +00:00
|
|
|
_lastVoiceFile = _filenums[sound];
|
2003-12-13 01:54:17 +00:00
|
|
|
sprintf(filename, "voices%d.dat", _filenums[sound]);
|
|
|
|
File *file = new File();
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(filename);
|
2003-12-13 01:54:17 +00:00
|
|
|
if (file->isOpen() == false) {
|
|
|
|
warning("playVoice: Can't load voice file %s", filename);
|
|
|
|
return;
|
2005-07-30 21:11:48 +00:00
|
|
|
}
|
2004-01-19 17:46:08 +00:00
|
|
|
delete _voice;
|
2003-12-13 01:54:17 +00:00
|
|
|
_voice = new WavSound(_mixer, file, _offsets);
|
|
|
|
}
|
2003-01-11 16:00:55 +00:00
|
|
|
}
|
|
|
|
|
2002-11-29 22:09:52 +00:00
|
|
|
if (!_voice)
|
|
|
|
return;
|
2003-07-21 04:00:04 +00:00
|
|
|
|
2005-05-08 12:33:25 +00:00
|
|
|
_mixer->stopHandle(_voiceHandle);
|
2005-11-12 06:01:24 +00:00
|
|
|
_voice->playSound(sound, &_voiceHandle, (_vm->getGameId() == GID_SIMON1CD32) ? 0 : Audio::Mixer::FLAG_UNSIGNED);
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 01:28:00 +00:00
|
|
|
void Sound::playEffects(uint sound) {
|
2002-11-29 22:09:52 +00:00
|
|
|
if (!_effects)
|
|
|
|
return;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_effectsPaused)
|
2002-11-29 22:09:52 +00:00
|
|
|
return;
|
|
|
|
|
2005-11-12 06:01:24 +00:00
|
|
|
_effects->playSound(sound, &_effectsHandle, (_vm->getGameId() == GID_SIMON1CD32) ? 0 : Audio::Mixer::FLAG_UNSIGNED);
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 01:28:00 +00:00
|
|
|
void Sound::playAmbient(uint sound) {
|
2002-11-29 22:09:52 +00:00
|
|
|
if (!_effects)
|
|
|
|
return;
|
|
|
|
|
2005-05-08 12:33:25 +00:00
|
|
|
if (sound == _ambientPlaying)
|
2002-11-29 22:09:52 +00:00
|
|
|
return;
|
|
|
|
|
2005-05-08 12:33:25 +00:00
|
|
|
_ambientPlaying = sound;
|
2002-11-29 22:09:52 +00:00
|
|
|
|
2005-05-06 11:37:33 +00:00
|
|
|
if (_ambientPaused)
|
2002-11-29 22:09:52 +00:00
|
|
|
return;
|
|
|
|
|
2005-05-08 12:33:25 +00:00
|
|
|
_mixer->stopHandle(_ambientHandle);
|
2005-05-10 23:48:48 +00:00
|
|
|
_effects->playSound(sound, &_ambientHandle, Audio::Mixer::FLAG_LOOP|Audio::Mixer::FLAG_UNSIGNED);
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2005-05-08 12:33:25 +00:00
|
|
|
bool Sound::hasVoice() const {
|
|
|
|
return _hasVoiceFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sound::isVoiceActive() const {
|
|
|
|
return _mixer->isSoundHandleActive(_voiceHandle) ;
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 01:28:00 +00:00
|
|
|
void Sound::stopVoice() {
|
2005-05-08 12:33:25 +00:00
|
|
|
_mixer->stopHandle(_voiceHandle);
|
2002-12-07 17:35:34 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 01:28:00 +00:00
|
|
|
void Sound::stopAll() {
|
2002-11-29 22:09:52 +00:00
|
|
|
_mixer->stopAll();
|
2005-05-08 12:33:25 +00:00
|
|
|
_ambientPlaying = 0;
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 01:28:00 +00:00
|
|
|
void Sound::effectsPause(bool b) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_effectsPaused = b;
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 01:28:00 +00:00
|
|
|
void Sound::ambientPause(bool b) {
|
2005-05-06 11:37:33 +00:00
|
|
|
_ambientPaused = b;
|
2002-11-29 22:09:52 +00:00
|
|
|
|
2005-05-08 12:33:25 +00:00
|
|
|
if (_ambientPaused && _ambientPlaying) {
|
|
|
|
_mixer->stopHandle(_ambientHandle);
|
|
|
|
} else if (_ambientPlaying) {
|
|
|
|
uint tmp = _ambientPlaying;
|
|
|
|
_ambientPlaying = 0;
|
2002-11-29 22:09:52 +00:00
|
|
|
playAmbient(tmp);
|
|
|
|
}
|
|
|
|
}
|
2003-10-03 19:42:27 +00:00
|
|
|
|
|
|
|
} // End of namespace Simon
|