2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
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.
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2002-11-29 22:09:52 +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.
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2002-11-29 22:09:52 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-11-29 22:09:52 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/file.h"
|
2010-11-19 17:03:07 +00:00
|
|
|
#include "common/memstream.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.h"
|
2003-09-10 12:31:20 +00:00
|
|
|
#include "common/util.h"
|
2004-11-27 15:58:18 +00:00
|
|
|
|
2006-09-29 08:14:27 +00:00
|
|
|
#include "agos/agos.h"
|
|
|
|
#include "agos/sound.h"
|
2004-11-27 15:58:18 +00:00
|
|
|
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/audiostream.h"
|
|
|
|
#include "audio/decoders/flac.h"
|
|
|
|
#include "audio/mixer.h"
|
|
|
|
#include "audio/decoders/mp3.h"
|
|
|
|
#include "audio/decoders/raw.h"
|
|
|
|
#include "audio/decoders/voc.h"
|
|
|
|
#include "audio/decoders/vorbis.h"
|
|
|
|
#include "audio/decoders/wave.h"
|
2002-11-29 22:09:52 +00:00
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
namespace AGOS {
|
2003-10-03 19:42:27 +00:00
|
|
|
|
2003-07-21 04:00:04 +00:00
|
|
|
#define SOUND_BIG_ENDIAN true
|
|
|
|
|
2010-01-26 22:51:40 +00:00
|
|
|
class BaseSound : Common::NonCopyable {
|
2003-06-15 11:48:04 +00:00
|
|
|
protected:
|
2010-11-01 16:00:17 +00:00
|
|
|
Common::File *_file;
|
2003-06-15 11:48:04 +00:00
|
|
|
uint32 *_offsets;
|
2005-05-10 23:48:48 +00:00
|
|
|
Audio::Mixer *_mixer;
|
2004-01-19 17:46:08 +00:00
|
|
|
bool _freeOffsets;
|
2010-01-23 00:04:01 +00:00
|
|
|
DisposeAfterUse::Flag _disposeFile;
|
2003-06-15 11:48:04 +00:00
|
|
|
|
|
|
|
public:
|
2010-11-01 16:00:17 +00:00
|
|
|
BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 base, bool bigEndian, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES);
|
|
|
|
BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 *offsets, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES);
|
2008-08-14 00:26:57 +00:00
|
|
|
virtual ~BaseSound();
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2010-01-23 00:01:00 +00:00
|
|
|
void playSound(uint sound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0) {
|
|
|
|
playSound(sound, sound, type, handle, loop, vol);
|
2007-01-01 09:58:00 +00:00
|
|
|
}
|
2010-01-23 00:01:00 +00:00
|
|
|
virtual void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0) = 0;
|
2010-01-23 00:02:59 +00:00
|
|
|
virtual Audio::AudioStream *makeAudioStream(uint sound) = 0;
|
2003-06-15 11:48:04 +00:00
|
|
|
};
|
|
|
|
|
2010-11-01 16:00:17 +00:00
|
|
|
BaseSound::BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 base, bool bigEndian, DisposeAfterUse::Flag disposeFileAfterUse)
|
2010-01-23 00:04:01 +00:00
|
|
|
: _mixer(mixer), _file(file), _disposeFile(disposeFileAfterUse) {
|
2010-01-22 23:56:59 +00:00
|
|
|
|
|
|
|
uint res = 0;
|
|
|
|
uint32 size;
|
|
|
|
|
|
|
|
_file->seek(base + sizeof(uint32), SEEK_SET);
|
|
|
|
if (bigEndian)
|
|
|
|
size = _file->readUint32BE();
|
|
|
|
else
|
|
|
|
size = _file->readUint32LE();
|
|
|
|
|
|
|
|
// The Feeble Files uses set amount of voice offsets
|
|
|
|
if (size == 0)
|
|
|
|
size = 40000;
|
|
|
|
|
|
|
|
res = size / sizeof(uint32);
|
|
|
|
|
|
|
|
_offsets = (uint32 *)malloc(size + sizeof(uint32));
|
|
|
|
_freeOffsets = true;
|
|
|
|
|
|
|
|
_file->seek(base, SEEK_SET);
|
|
|
|
|
|
|
|
for (uint i = 0; i < res; i++) {
|
|
|
|
if (bigEndian)
|
|
|
|
_offsets[i] = base + _file->readUint32BE();
|
|
|
|
else
|
|
|
|
_offsets[i] = base + _file->readUint32LE();
|
|
|
|
}
|
|
|
|
|
|
|
|
// only needed for mp3
|
|
|
|
_offsets[res] = _file->size();
|
|
|
|
}
|
|
|
|
|
2010-11-01 16:00:17 +00:00
|
|
|
BaseSound::BaseSound(Audio::Mixer *mixer, Common::File *file, uint32 *offsets, DisposeAfterUse::Flag disposeFileAfterUse)
|
2010-01-23 00:04:01 +00:00
|
|
|
: _mixer(mixer), _file(file), _disposeFile(disposeFileAfterUse) {
|
2010-01-23 00:02:59 +00:00
|
|
|
|
2010-01-22 23:56:59 +00:00
|
|
|
_offsets = offsets;
|
|
|
|
_freeOffsets = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseSound::~BaseSound() {
|
|
|
|
if (_freeOffsets)
|
|
|
|
free(_offsets);
|
2010-01-23 00:04:01 +00:00
|
|
|
if (_disposeFile == DisposeAfterUse::YES)
|
|
|
|
delete _file;
|
2010-01-22 23:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark -
|
|
|
|
|
2007-01-01 09:58:00 +00:00
|
|
|
class LoopingAudioStream : public Audio::AudioStream {
|
|
|
|
private:
|
|
|
|
BaseSound *_parent;
|
|
|
|
Audio::AudioStream *_stream;
|
|
|
|
bool _loop;
|
|
|
|
uint _sound;
|
|
|
|
uint _loopSound;
|
|
|
|
public:
|
|
|
|
LoopingAudioStream(BaseSound *parent, uint sound, uint loopSound, bool loop);
|
2007-06-03 15:55:07 +00:00
|
|
|
~LoopingAudioStream();
|
2007-01-01 09:58:00 +00:00
|
|
|
int readBuffer(int16 *buffer, const int numSamples);
|
|
|
|
bool isStereo() const { return _stream ? _stream->isStereo() : 0; }
|
|
|
|
bool endOfData() const;
|
|
|
|
int getRate() const { return _stream ? _stream->getRate() : 22050; }
|
|
|
|
};
|
|
|
|
|
|
|
|
LoopingAudioStream::LoopingAudioStream(BaseSound *parent, uint sound, uint loopSound, bool loop) {
|
|
|
|
_parent = parent;
|
|
|
|
_sound = sound;
|
|
|
|
_loop = loop;
|
|
|
|
_loopSound = loopSound;
|
|
|
|
|
|
|
|
_stream = _parent->makeAudioStream(sound);
|
|
|
|
}
|
|
|
|
|
2007-06-03 15:55:07 +00:00
|
|
|
LoopingAudioStream::~LoopingAudioStream() {
|
|
|
|
delete _stream;
|
|
|
|
}
|
|
|
|
|
2007-01-01 09:58:00 +00:00
|
|
|
int LoopingAudioStream::readBuffer(int16 *buffer, const int numSamples) {
|
|
|
|
if (!_loop) {
|
|
|
|
return _stream->readBuffer(buffer, numSamples);
|
|
|
|
}
|
|
|
|
|
|
|
|
int16 *buf = buffer;
|
|
|
|
int samplesLeft = numSamples;
|
|
|
|
|
|
|
|
while (samplesLeft > 0) {
|
|
|
|
int len = _stream->readBuffer(buf, samplesLeft);
|
|
|
|
if (len < samplesLeft) {
|
|
|
|
delete _stream;
|
|
|
|
_stream = _parent->makeAudioStream(_loopSound);
|
|
|
|
}
|
|
|
|
samplesLeft -= len;
|
|
|
|
buf += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return numSamples;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LoopingAudioStream::endOfData() const {
|
|
|
|
if (!_stream)
|
|
|
|
return true;
|
|
|
|
if (_loop)
|
|
|
|
return false;
|
|
|
|
return _stream->endOfData();
|
|
|
|
}
|
|
|
|
|
2010-01-22 23:56:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark -
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2010-01-22 23:56:59 +00:00
|
|
|
static void convertVolume(int &vol) {
|
2007-01-01 11:29:20 +00:00
|
|
|
// DirectSound was orginally used, which specifies volume
|
|
|
|
// and panning differently than ScummVM does, using a logarithmic scale
|
|
|
|
// rather than a linear one.
|
|
|
|
//
|
|
|
|
// Volume is a value between -10,000 and 0.
|
|
|
|
//
|
|
|
|
// In both cases, the -10,000 represents -100 dB. When panning, only
|
|
|
|
// one speaker's volume is affected - just like in ScummVM - with
|
|
|
|
// negative values affecting the left speaker, and positive values
|
|
|
|
// affecting the right speaker. Thus -10,000 means the left speaker is
|
|
|
|
// silent.
|
|
|
|
|
|
|
|
int v = CLIP(vol, -10000, 0);
|
|
|
|
if (v) {
|
|
|
|
vol = (int)((double)Audio::Mixer::kMaxChannelVolume * pow(10.0, (double)v / 2000.0) + 0.5);
|
|
|
|
} else {
|
|
|
|
vol = Audio::Mixer::kMaxChannelVolume;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-22 23:56:59 +00:00
|
|
|
static void convertPan(int &pan) {
|
2007-01-01 11:29:20 +00:00
|
|
|
// DirectSound was orginally used, which specifies volume
|
|
|
|
// and panning differently than ScummVM does, using a logarithmic scale
|
|
|
|
// rather than a linear one.
|
|
|
|
//
|
|
|
|
// Panning is a value between -10,000 and 10,000.
|
|
|
|
//
|
|
|
|
// In both cases, the -10,000 represents -100 dB. When panning, only
|
|
|
|
// one speaker's volume is affected - just like in ScummVM - with
|
|
|
|
// negative values affecting the left speaker, and positive values
|
|
|
|
// affecting the right speaker. Thus -10,000 means the left speaker is
|
|
|
|
// silent.
|
|
|
|
|
|
|
|
int p = CLIP(pan, -10000, 10000);
|
|
|
|
if (p < 0) {
|
|
|
|
pan = (int)(255.0 * pow(10.0, (double)p / 2000.0) + 127.5);
|
|
|
|
} else if (p > 0) {
|
|
|
|
pan = (int)(255.0 * pow(10.0, (double)p / -2000.0) - 127.5);
|
|
|
|
} else {
|
|
|
|
pan = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-22 23:56:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
class WavSound : public BaseSound {
|
|
|
|
public:
|
2010-11-01 16:00:17 +00:00
|
|
|
WavSound(Audio::Mixer *mixer, Common::File *file, uint32 base = 0, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES)
|
2010-01-23 00:04:01 +00:00
|
|
|
: BaseSound(mixer, file, base, false, disposeFileAfterUse) {}
|
2010-11-01 16:00:17 +00:00
|
|
|
WavSound(Audio::Mixer *mixer, Common::File *file, uint32 *offsets) : BaseSound(mixer, file, offsets) {}
|
2010-01-22 23:56:59 +00:00
|
|
|
Audio::AudioStream *makeAudioStream(uint sound);
|
2010-01-23 00:01:00 +00:00
|
|
|
void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0);
|
2010-01-22 23:56:59 +00:00
|
|
|
};
|
|
|
|
|
2007-01-01 09:58:00 +00:00
|
|
|
Audio::AudioStream *WavSound::makeAudioStream(uint sound) {
|
2003-06-15 12:22:19 +00:00
|
|
|
if (_offsets == NULL)
|
2007-01-01 09:58:00 +00:00
|
|
|
return NULL;
|
2003-06-15 12:22:19 +00:00
|
|
|
|
|
|
|
_file->seek(_offsets[sound], SEEK_SET);
|
2010-01-16 21:36:08 +00:00
|
|
|
return Audio::makeWAVStream(_file, DisposeAfterUse::NO);
|
2007-01-01 09:58:00 +00:00
|
|
|
}
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2010-01-23 00:01:00 +00:00
|
|
|
void WavSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol) {
|
2007-01-01 11:29:20 +00:00
|
|
|
convertVolume(vol);
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(type, handle, new LoopingAudioStream(this, sound, loopSound, loop), -1, vol);
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 23:56:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
class VocSound : public BaseSound {
|
2010-01-23 00:00:11 +00:00
|
|
|
const byte _flags;
|
2010-01-22 23:56:59 +00:00
|
|
|
public:
|
2010-11-01 16:00:17 +00:00
|
|
|
VocSound(Audio::Mixer *mixer, Common::File *file, bool isUnsigned, uint32 base = 0, bool bigEndian = false, DisposeAfterUse::Flag disposeFileAfterUse = DisposeAfterUse::YES)
|
2010-01-23 00:04:01 +00:00
|
|
|
: BaseSound(mixer, file, base, bigEndian, disposeFileAfterUse), _flags(isUnsigned ? Audio::FLAG_UNSIGNED : 0) {}
|
2010-01-22 23:56:59 +00:00
|
|
|
Audio::AudioStream *makeAudioStream(uint sound);
|
2010-01-23 00:01:00 +00:00
|
|
|
void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0);
|
2010-01-22 23:56:59 +00:00
|
|
|
};
|
|
|
|
|
2009-08-13 21:46:41 +00:00
|
|
|
Audio::AudioStream *VocSound::makeAudioStream(uint sound) {
|
2010-01-23 00:04:43 +00:00
|
|
|
assert(_offsets);
|
2003-06-15 12:22:19 +00:00
|
|
|
_file->seek(_offsets[sound], SEEK_SET);
|
2010-03-08 10:27:42 +00:00
|
|
|
return Audio::makeVOCStream(_file, _flags);
|
2009-08-13 21:46:41 +00:00
|
|
|
}
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2010-01-23 00:01:00 +00:00
|
|
|
void VocSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol) {
|
2009-08-13 21:46:41 +00:00
|
|
|
convertVolume(vol);
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(type, handle, new LoopingAudioStream(this, sound, loopSound, loop), -1, vol);
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 23:56:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark -
|
|
|
|
|
2010-01-23 03:09:29 +00:00
|
|
|
// This class is only used by speech in Simon1 Amiga CD32
|
2010-01-22 23:56:59 +00:00
|
|
|
class RawSound : public BaseSound {
|
2010-01-23 00:00:11 +00:00
|
|
|
const byte _flags;
|
2010-01-22 23:56:59 +00:00
|
|
|
public:
|
2010-11-01 16:00:17 +00:00
|
|
|
RawSound(Audio::Mixer *mixer, Common::File *file, bool isUnsigned)
|
2010-01-23 00:00:11 +00:00
|
|
|
: BaseSound(mixer, file, 0, SOUND_BIG_ENDIAN), _flags(isUnsigned ? Audio::FLAG_UNSIGNED : 0) {}
|
2010-01-23 00:02:59 +00:00
|
|
|
Audio::AudioStream *makeAudioStream(uint sound);
|
2010-01-23 00:01:00 +00:00
|
|
|
void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0);
|
2010-01-22 23:56:59 +00:00
|
|
|
};
|
|
|
|
|
2010-01-23 00:02:59 +00:00
|
|
|
Audio::AudioStream *RawSound::makeAudioStream(uint sound) {
|
2003-07-21 04:00:04 +00:00
|
|
|
if (_offsets == NULL)
|
2010-01-23 00:02:59 +00:00
|
|
|
return NULL;
|
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);
|
2006-10-05 00:16:50 +00:00
|
|
|
assert(buffer);
|
|
|
|
_file->read(buffer, size);
|
2010-01-19 22:19:43 +00:00
|
|
|
|
2010-01-30 15:26:54 +00:00
|
|
|
return Audio::makeRawStream(buffer, size, 22050, _flags);
|
2010-01-23 00:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RawSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol) {
|
2010-01-23 03:09:29 +00:00
|
|
|
// Sound looping and volume are ignored.
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(type, handle, makeAudioStream(sound));
|
2003-07-21 04:00:04 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 23:56:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark -
|
|
|
|
|
2010-01-23 00:04:43 +00:00
|
|
|
class CompressedSound : public BaseSound {
|
2003-06-24 21:52:52 +00:00
|
|
|
public:
|
2010-11-01 16:00:17 +00:00
|
|
|
CompressedSound(Audio::Mixer *mixer, Common::File *file, uint32 base) : BaseSound(mixer, file, base, false) {}
|
2003-06-24 21:52:52 +00:00
|
|
|
|
2010-11-19 17:03:07 +00:00
|
|
|
Common::SeekableReadStream *loadStream(uint sound) const {
|
2010-01-23 00:04:43 +00:00
|
|
|
if (_offsets == NULL)
|
|
|
|
return NULL;
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2010-01-23 00:04:43 +00:00
|
|
|
_file->seek(_offsets[sound], SEEK_SET);
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2010-01-23 00:04:43 +00:00
|
|
|
int i = 1;
|
|
|
|
while (_offsets[sound + i] == _offsets[sound])
|
|
|
|
i++;
|
2004-01-19 17:44:04 +00:00
|
|
|
|
2010-01-23 00:04:43 +00:00
|
|
|
uint32 size = _offsets[sound + i] - _offsets[sound];
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2010-01-23 00:04:43 +00:00
|
|
|
return _file->readStream(size);
|
|
|
|
}
|
2006-10-13 05:06:53 +00:00
|
|
|
|
2010-01-23 00:04:43 +00:00
|
|
|
void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, bool loop, int vol = 0) {
|
|
|
|
convertVolume(vol);
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(type, handle, new LoopingAudioStream(this, sound, loopSound, loop), -1, vol);
|
2010-01-23 00:04:43 +00:00
|
|
|
}
|
|
|
|
};
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2010-01-22 23:56:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark -
|
|
|
|
|
2010-01-23 00:04:43 +00:00
|
|
|
#ifdef USE_MAD
|
|
|
|
class MP3Sound : public CompressedSound {
|
2003-12-21 16:01:36 +00:00
|
|
|
public:
|
2010-11-01 16:00:17 +00:00
|
|
|
MP3Sound(Audio::Mixer *mixer, Common::File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {}
|
2010-01-23 00:04:43 +00:00
|
|
|
Audio::AudioStream *makeAudioStream(uint sound) {
|
2010-11-19 17:03:07 +00:00
|
|
|
Common::SeekableReadStream *tmp = loadStream(sound);
|
2010-01-23 00:04:43 +00:00
|
|
|
if (!tmp)
|
|
|
|
return NULL;
|
|
|
|
return Audio::makeMP3Stream(tmp, DisposeAfterUse::YES);
|
|
|
|
}
|
2003-12-21 16:01:36 +00:00
|
|
|
};
|
2010-01-23 00:04:43 +00:00
|
|
|
#endif
|
2003-12-21 16:01:36 +00:00
|
|
|
|
2010-01-23 00:04:43 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark -
|
2006-10-13 05:06:53 +00:00
|
|
|
|
2010-01-23 00:04:43 +00:00
|
|
|
#ifdef USE_VORBIS
|
|
|
|
class VorbisSound : public CompressedSound {
|
|
|
|
public:
|
2010-11-01 16:00:17 +00:00
|
|
|
VorbisSound(Audio::Mixer *mixer, Common::File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {}
|
2010-01-23 00:04:43 +00:00
|
|
|
Audio::AudioStream *makeAudioStream(uint sound) {
|
2010-11-19 17:03:07 +00:00
|
|
|
Common::SeekableReadStream *tmp = loadStream(sound);
|
2010-01-23 00:04:43 +00:00
|
|
|
if (!tmp)
|
|
|
|
return NULL;
|
|
|
|
return Audio::makeVorbisStream(tmp, DisposeAfterUse::YES);
|
|
|
|
}
|
|
|
|
};
|
2003-12-21 16:01:36 +00:00
|
|
|
#endif
|
|
|
|
|
2010-01-22 23:56:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark -
|
|
|
|
|
2004-02-22 14:11:16 +00:00
|
|
|
#ifdef USE_FLAC
|
2010-02-03 09:42:11 +00:00
|
|
|
class FLACSound : public CompressedSound {
|
2004-02-22 14:11:16 +00:00
|
|
|
public:
|
2010-11-01 16:00:17 +00:00
|
|
|
FLACSound(Audio::Mixer *mixer, Common::File *file, uint32 base = 0) : CompressedSound(mixer, file, base) {}
|
2010-01-23 00:04:43 +00:00
|
|
|
Audio::AudioStream *makeAudioStream(uint sound) {
|
2010-11-19 17:03:07 +00:00
|
|
|
Common::SeekableReadStream *tmp = loadStream(sound);
|
2010-01-23 00:04:43 +00:00
|
|
|
if (!tmp)
|
|
|
|
return NULL;
|
2010-02-03 09:42:11 +00:00
|
|
|
return Audio::makeFLACStream(tmp, DisposeAfterUse::YES);
|
2010-01-23 00:04:43 +00:00
|
|
|
}
|
2004-02-22 14:11:16 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2010-01-23 00:02:01 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark -
|
|
|
|
|
2010-11-01 16:00:17 +00:00
|
|
|
static CompressedSound *makeCompressedSound(Audio::Mixer *mixer, Common::File *file, const Common::String &basename) {
|
2010-01-23 00:02:01 +00:00
|
|
|
#ifdef USE_FLAC
|
|
|
|
file->open(basename + ".fla");
|
|
|
|
if (file->isOpen()) {
|
2010-02-03 09:42:11 +00:00
|
|
|
return new FLACSound(mixer, file);
|
2010-01-23 00:02:01 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_VORBIS
|
|
|
|
file->open(basename + ".ogg");
|
|
|
|
if (file->isOpen()) {
|
|
|
|
return new VorbisSound(mixer, file);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_MAD
|
|
|
|
file->open(basename + ".mp3");
|
|
|
|
if (file->isOpen()) {
|
|
|
|
return new MP3Sound(mixer, file);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-22 23:56:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#pragma mark -
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
Sound::Sound(AGOSEngine *vm, const GameSpecificSettings *gss, Audio::Mixer *mixer)
|
2005-11-12 06:01:24 +00:00
|
|
|
: _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;
|
2006-04-17 12:05:45 +00:00
|
|
|
_sfx5Paused = 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;
|
2006-04-17 12:05:45 +00:00
|
|
|
|
2005-05-08 12:33:25 +00:00
|
|
|
_ambientPlaying = 0;
|
2003-01-12 02:01:07 +00:00
|
|
|
|
2009-03-08 08:45:21 +00:00
|
|
|
_soundQueuePtr = 0;
|
|
|
|
_soundQueueNum = 0;
|
|
|
|
_soundQueueSize = 0;
|
|
|
|
_soundQueueFreq = 0;
|
|
|
|
|
2006-04-15 05:24:44 +00:00
|
|
|
if (_vm->getFeatures() & GF_TALKIE) {
|
|
|
|
loadVoiceFile(gss);
|
|
|
|
|
|
|
|
if (_vm->getGameType() == GType_SIMON1)
|
|
|
|
loadSfxFile(gss);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-17 12:05:45 +00:00
|
|
|
Sound::~Sound() {
|
|
|
|
delete _voice;
|
|
|
|
delete _effects;
|
|
|
|
|
|
|
|
free(_filenums);
|
|
|
|
free(_offsets);
|
|
|
|
}
|
|
|
|
|
2006-04-15 05:24:44 +00:00
|
|
|
void Sound::loadVoiceFile(const GameSpecificSettings *gss) {
|
|
|
|
// Game versions which use separate voice files
|
2006-09-29 00:50:22 +00:00
|
|
|
if (_vm->getGameType() == GType_FF || _vm->getGameId() == GID_SIMON1CD32)
|
2005-05-06 03:09:53 +00:00
|
|
|
return;
|
|
|
|
|
2010-01-23 00:00:11 +00:00
|
|
|
|
2006-04-20 02:23:17 +00:00
|
|
|
char filename[16];
|
2010-11-01 16:00:17 +00:00
|
|
|
Common::File *file = new Common::File();
|
2002-11-29 22:09:52 +00:00
|
|
|
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasVoiceFile) {
|
2010-01-23 00:02:01 +00:00
|
|
|
_voice = makeCompressedSound(_mixer, file, gss->speech_filename);
|
|
|
|
_hasVoiceFile = (_voice != 0);
|
2004-02-22 14:11:16 +00:00
|
|
|
}
|
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) {
|
2006-04-26 14:35:53 +00:00
|
|
|
int end = file->size();
|
2004-07-30 09:00:29 +00:00
|
|
|
_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
|
|
|
}
|
|
|
|
}
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasVoiceFile) {
|
|
|
|
sprintf(filename, "%s.wav", gss->speech_filename);
|
|
|
|
file->open(filename);
|
2005-05-08 02:50:43 +00:00
|
|
|
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
|
|
|
}
|
2010-01-23 00:00:11 +00:00
|
|
|
|
2010-01-23 03:02:56 +00:00
|
|
|
const bool dataIsUnsigned = true;
|
2010-01-23 00:00:11 +00:00
|
|
|
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasVoiceFile) {
|
|
|
|
sprintf(filename, "%s.voc", gss->speech_filename);
|
|
|
|
file->open(filename);
|
|
|
|
if (file->isOpen()) {
|
|
|
|
_hasVoiceFile = true;
|
2010-01-23 00:00:11 +00:00
|
|
|
_voice = new VocSound(_mixer, file, dataIsUnsigned);
|
2006-04-20 02:23:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!_hasVoiceFile) {
|
|
|
|
sprintf(filename, "%s", gss->speech_filename);
|
|
|
|
file->open(filename);
|
2005-05-08 02:50:43 +00:00
|
|
|
if (file->isOpen()) {
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasVoiceFile = true;
|
2006-09-29 00:50:22 +00:00
|
|
|
if (_vm->getGameType() == GType_PP)
|
|
|
|
_voice = new WavSound(_mixer, file);
|
|
|
|
else
|
2010-01-23 00:00:11 +00:00
|
|
|
_voice = new VocSound(_mixer, file, dataIsUnsigned);
|
2003-01-11 16:00:55 +00:00
|
|
|
}
|
2003-03-06 13:51:56 +00:00
|
|
|
}
|
2006-04-15 05:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::loadSfxFile(const GameSpecificSettings *gss) {
|
2006-04-20 02:23:17 +00:00
|
|
|
char filename[16];
|
2010-11-01 16:00:17 +00:00
|
|
|
Common::File *file = new Common::File();
|
2002-11-29 22:09:52 +00:00
|
|
|
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasEffectsFile) {
|
2010-01-23 00:02:01 +00:00
|
|
|
_effects = makeCompressedSound(_mixer, file, gss->effects_filename);
|
|
|
|
_hasEffectsFile = (_effects != 0);
|
2006-04-15 05:24:44 +00:00
|
|
|
}
|
2010-01-23 00:00:11 +00:00
|
|
|
|
2010-01-23 03:02:56 +00:00
|
|
|
const bool dataIsUnsigned = true;
|
2010-01-23 00:00:11 +00:00
|
|
|
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasEffectsFile) {
|
|
|
|
sprintf(filename, "%s.voc", gss->effects_filename);
|
|
|
|
file->open(filename);
|
|
|
|
if (file->isOpen()) {
|
|
|
|
_hasEffectsFile = true;
|
2010-01-23 00:00:11 +00:00
|
|
|
_effects = new VocSound(_mixer, file, dataIsUnsigned);
|
2006-04-20 02:23:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!_hasEffectsFile) {
|
|
|
|
sprintf(filename, "%s", gss->effects_filename);
|
|
|
|
file->open(filename);
|
2006-04-15 05:24:44 +00:00
|
|
|
if (file->isOpen()) {
|
|
|
|
_hasEffectsFile = true;
|
2010-01-23 00:00:11 +00:00
|
|
|
_effects = new VocSound(_mixer, file, dataIsUnsigned);
|
2003-01-11 16:00:55 +00:00
|
|
|
}
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-23 03:02:56 +00:00
|
|
|
// This method is only used by Simon1 Amiga CD32 & Windows
|
2010-01-22 23:58:24 +00:00
|
|
|
void Sound::readSfxFile(const Common::String &filename) {
|
2005-05-08 12:33:25 +00:00
|
|
|
if (_hasEffectsFile)
|
2005-05-08 05:23:31 +00:00
|
|
|
return;
|
|
|
|
|
2006-10-15 08:08:50 +00:00
|
|
|
_mixer->stopHandle(_effectsHandle);
|
2002-11-29 22:09:52 +00:00
|
|
|
|
2010-11-01 16:00:17 +00:00
|
|
|
Common::File *file = new Common::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) {
|
2010-01-22 23:58:24 +00:00
|
|
|
error("readSfxFile: Can't load sfx file %s", filename.c_str());
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2010-01-23 03:02:56 +00:00
|
|
|
const bool dataIsUnsigned = (_vm->getGameId() != GID_SIMON1CD32);
|
2010-01-23 00:00:11 +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) {
|
2010-01-23 00:00:11 +00:00
|
|
|
_effects = new VocSound(_mixer, file, dataIsUnsigned, 0, SOUND_BIG_ENDIAN);
|
2003-07-21 04:00:04 +00:00
|
|
|
} else
|
|
|
|
_effects = new WavSound(_mixer, file);
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 23:58:24 +00:00
|
|
|
// This method is only used by Simon2
|
2010-11-01 16:00:17 +00:00
|
|
|
void Sound::loadSfxTable(Common::File *gameFile, uint32 base) {
|
2002-11-29 22:09:52 +00:00
|
|
|
stopAll();
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2010-01-23 00:04:01 +00:00
|
|
|
delete _effects;
|
2010-01-23 03:02:56 +00:00
|
|
|
const bool dataIsUnsigned = true;
|
2005-11-12 06:01:24 +00:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformWindows)
|
2010-01-23 00:04:01 +00:00
|
|
|
_effects = new WavSound(_mixer, gameFile, base, DisposeAfterUse::NO);
|
2002-11-29 22:09:52 +00:00
|
|
|
else
|
2010-01-23 03:02:56 +00:00
|
|
|
_effects = new VocSound(_mixer, gameFile, dataIsUnsigned, base, false, DisposeAfterUse::NO);
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2010-01-23 03:02:56 +00:00
|
|
|
// This method is only used by Simon1 Amiga CD32
|
2010-01-22 23:58:24 +00:00
|
|
|
void Sound::readVoiceFile(const Common::String &filename) {
|
2006-10-15 08:08:50 +00:00
|
|
|
_mixer->stopHandle(_voiceHandle);
|
2003-07-21 04:00:04 +00:00
|
|
|
|
2010-11-01 16:00:17 +00:00
|
|
|
Common::File *file = new Common::File();
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(filename);
|
2003-07-21 04:00:04 +00:00
|
|
|
|
2006-08-27 05:02:48 +00:00
|
|
|
if (file->isOpen() == false)
|
2010-01-22 23:58:24 +00:00
|
|
|
error("readVoiceFile: Can't load voice file %s", filename.c_str());
|
2003-07-21 04:00:04 +00:00
|
|
|
|
2010-01-23 03:02:56 +00:00
|
|
|
const bool dataIsUnsigned = false;
|
2010-01-23 00:00:11 +00:00
|
|
|
|
2003-07-24 16:54:40 +00:00
|
|
|
delete _voice;
|
2010-01-23 00:00:11 +00:00
|
|
|
_voice = new RawSound(_mixer, file, dataIsUnsigned);
|
2003-07-21 04:00:04 +00:00
|
|
|
}
|
|
|
|
|
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]) {
|
2006-10-15 08:08:50 +00:00
|
|
|
_mixer->stopHandle(_voiceHandle);
|
2003-12-13 01:54:17 +00:00
|
|
|
|
|
|
|
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]);
|
2010-11-01 16:00:17 +00:00
|
|
|
Common::File *file = new Common::File();
|
2004-06-27 22:14:35 +00:00
|
|
|
file->open(filename);
|
2006-08-27 05:02:48 +00:00
|
|
|
if (file->isOpen() == false)
|
|
|
|
error("playVoice: Can't load voice file %s", filename);
|
|
|
|
|
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);
|
2006-09-29 06:58:59 +00:00
|
|
|
if (_vm->getGameType() == GType_PP) {
|
2007-01-01 09:58:00 +00:00
|
|
|
if (sound < 11)
|
2010-01-23 00:01:00 +00:00
|
|
|
_voice->playSound(sound, sound + 1, Audio::Mixer::kMusicSoundType, &_voiceHandle, true, -1500);
|
2007-01-01 11:29:20 +00:00
|
|
|
else
|
2010-01-23 00:01:00 +00:00
|
|
|
_voice->playSound(sound, sound, Audio::Mixer::kMusicSoundType, &_voiceHandle, true);
|
2006-09-29 06:58:59 +00:00
|
|
|
} else if (_vm->getGameType() == GType_FF || _vm->getGameId() == GID_SIMON1CD32) {
|
2010-01-23 00:01:00 +00:00
|
|
|
_voice->playSound(sound, Audio::Mixer::kSpeechSoundType, &_voiceHandle, false);
|
2005-11-15 12:03:38 +00:00
|
|
|
} else {
|
2010-01-23 00:01:00 +00:00
|
|
|
_voice->playSound(sound, Audio::Mixer::kSpeechSoundType, &_voiceHandle, false);
|
2005-11-15 12:03:38 +00:00
|
|
|
}
|
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;
|
|
|
|
|
2009-08-15 10:09:32 +00:00
|
|
|
if (_vm->getGameType() == GType_SIMON1)
|
|
|
|
_mixer->stopHandle(_effectsHandle);
|
2010-01-23 00:01:00 +00:00
|
|
|
_effects->playSound(sound, Audio::Mixer::kSFXSoundType, &_effectsHandle, false);
|
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);
|
2010-01-23 00:01:00 +00:00
|
|
|
_effects->playSound(sound, Audio::Mixer::kSFXSoundType, &_ambientHandle, true);
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2005-05-08 12:33:25 +00:00
|
|
|
bool Sound::hasVoice() const {
|
|
|
|
return _hasVoiceFile;
|
|
|
|
}
|
|
|
|
|
2009-03-08 08:45:21 +00:00
|
|
|
bool Sound::isSfxActive() const {
|
|
|
|
return _mixer->isSoundHandleActive(_effectsHandle);
|
|
|
|
}
|
|
|
|
|
2005-05-08 12:33:25 +00:00
|
|
|
bool Sound::isVoiceActive() const {
|
2006-04-17 12:05:45 +00:00
|
|
|
return _mixer->isSoundHandleActive(_voiceHandle);
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2006-09-29 06:58:59 +00:00
|
|
|
void Sound::stopAllSfx() {
|
|
|
|
_mixer->stopHandle(_ambientHandle);
|
|
|
|
_mixer->stopHandle(_effectsHandle);
|
|
|
|
_mixer->stopHandle(_sfx5Handle);
|
|
|
|
_ambientPlaying = 0;
|
|
|
|
}
|
|
|
|
|
2009-03-08 08:45:21 +00:00
|
|
|
void Sound::stopSfx() {
|
|
|
|
_mixer->stopHandle(_effectsHandle);
|
|
|
|
}
|
|
|
|
|
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;
|
2006-04-17 12:05:45 +00:00
|
|
|
_sfx5Paused = 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);
|
|
|
|
}
|
2006-10-14 01:15:28 +00:00
|
|
|
}
|
|
|
|
|
2009-03-08 08:45:21 +00:00
|
|
|
// Personal Nightmare specific
|
2009-05-04 09:17:31 +00:00
|
|
|
void Sound::handleSoundQueue() {
|
|
|
|
if (isSfxActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
_vm->_sampleEnd = 1;
|
|
|
|
|
|
|
|
if (_soundQueuePtr) {
|
2009-03-08 08:45:21 +00:00
|
|
|
playRawData(_soundQueuePtr, _soundQueueNum, _soundQueueSize, _soundQueueFreq);
|
|
|
|
|
|
|
|
_vm->_sampleWait = 1;
|
2009-05-04 09:17:31 +00:00
|
|
|
_vm->_sampleEnd = 0;
|
2009-03-08 08:45:21 +00:00
|
|
|
_soundQueuePtr = 0;
|
|
|
|
_soundQueueNum = 0;
|
|
|
|
_soundQueueSize = 0;
|
|
|
|
_soundQueueFreq = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::queueSound(byte *ptr, uint16 sound, uint32 size, uint16 freq) {
|
|
|
|
if (_effectsPaused)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Only a single sound can be queued
|
|
|
|
_soundQueuePtr = ptr;
|
|
|
|
_soundQueueNum = sound;
|
|
|
|
_soundQueueSize = size;
|
|
|
|
_soundQueueFreq = freq;
|
|
|
|
}
|
|
|
|
|
2006-10-14 01:15:28 +00:00
|
|
|
// Elvira 1/2 and Waxworks specific
|
2009-03-08 08:45:21 +00:00
|
|
|
void Sound::playRawData(byte *soundData, uint sound, uint size, uint freq) {
|
2007-06-06 23:48:07 +00:00
|
|
|
if (_effectsPaused)
|
|
|
|
return;
|
|
|
|
|
2006-10-14 01:15:28 +00:00
|
|
|
byte *buffer = (byte *)malloc(size);
|
|
|
|
memcpy(buffer, soundData, size);
|
|
|
|
|
2010-01-19 00:56:29 +00:00
|
|
|
byte flags = 0;
|
2006-10-14 14:29:14 +00:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformPC)
|
2010-01-19 22:30:33 +00:00
|
|
|
flags = Audio::FLAG_UNSIGNED;
|
2010-01-19 22:19:43 +00:00
|
|
|
|
2010-01-30 15:26:54 +00:00
|
|
|
Audio::AudioStream *stream = Audio::makeRawStream(buffer, size, freq, flags);
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_effectsHandle, stream);
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
2003-10-03 19:42:27 +00:00
|
|
|
|
2006-04-15 05:24:44 +00:00
|
|
|
// Feeble Files specific
|
2006-04-17 12:05:45 +00:00
|
|
|
void Sound::playAmbientData(byte *soundData, uint sound, uint pan, uint vol) {
|
|
|
|
if (sound == _ambientPlaying)
|
|
|
|
return;
|
2006-04-15 05:24:44 +00:00
|
|
|
|
2006-04-17 12:05:45 +00:00
|
|
|
_ambientPlaying = sound;
|
2006-04-15 05:24:44 +00:00
|
|
|
|
2006-04-17 12:05:45 +00:00
|
|
|
if (_ambientPaused)
|
|
|
|
return;
|
2006-04-15 05:24:44 +00:00
|
|
|
|
2006-04-17 12:05:45 +00:00
|
|
|
_mixer->stopHandle(_ambientHandle);
|
|
|
|
playSoundData(&_ambientHandle, soundData, sound, pan, vol, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::playSfxData(byte *soundData, uint sound, uint pan, uint vol) {
|
|
|
|
if (_effectsPaused)
|
|
|
|
return;
|
|
|
|
|
|
|
|
playSoundData(&_effectsHandle, soundData, sound, pan, vol, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::playSfx5Data(byte *soundData, uint sound, uint pan, uint vol) {
|
|
|
|
if (_sfx5Paused)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_mixer->stopHandle(_sfx5Handle);
|
|
|
|
playSoundData(&_sfx5Handle, soundData, sound, pan, vol, true);
|
|
|
|
}
|
|
|
|
|
2006-04-22 03:53:14 +00:00
|
|
|
void Sound::playVoiceData(byte *soundData, uint sound) {
|
|
|
|
_mixer->stopHandle(_voiceHandle);
|
|
|
|
playSoundData(&_voiceHandle, soundData, sound);
|
|
|
|
}
|
|
|
|
|
2006-04-23 15:42:02 +00:00
|
|
|
void Sound::playSoundData(Audio::SoundHandle *handle, byte *soundData, uint sound, int pan, int vol, bool loop) {
|
2010-09-26 12:28:26 +00:00
|
|
|
int size = READ_LE_UINT32(soundData + 4) + 8;
|
2010-11-19 17:03:07 +00:00
|
|
|
Common::SeekableReadStream *stream = new Common::MemoryReadStream(soundData, size);
|
2010-01-16 21:36:08 +00:00
|
|
|
Audio::RewindableAudioStream *sndStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
|
2006-04-15 05:24:44 +00:00
|
|
|
|
2007-01-01 11:29:20 +00:00
|
|
|
convertVolume(vol);
|
|
|
|
convertPan(pan);
|
2006-04-23 15:42:02 +00:00
|
|
|
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, Audio::makeLoopingAudioStream(sndStream, loop ? 0 : 1), -1, vol, pan);
|
2006-04-15 05:24:44 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 13:28:42 +00:00
|
|
|
void Sound::stopSfx5() {
|
|
|
|
_mixer->stopHandle(_sfx5Handle);
|
|
|
|
}
|
|
|
|
|
2006-04-20 02:23:17 +00:00
|
|
|
void Sound::switchVoiceFile(const GameSpecificSettings *gss, uint disc) {
|
2006-04-20 01:54:14 +00:00
|
|
|
if (_lastVoiceFile == disc)
|
|
|
|
return;
|
|
|
|
|
2006-10-15 08:08:50 +00:00
|
|
|
_mixer->stopHandle(_voiceHandle);
|
2006-04-20 01:54:14 +00:00
|
|
|
delete _voice;
|
|
|
|
|
|
|
|
_hasVoiceFile = false;
|
|
|
|
_lastVoiceFile = disc;
|
|
|
|
|
|
|
|
char filename[16];
|
2010-11-01 16:00:17 +00:00
|
|
|
Common::File *file = new Common::File();
|
2006-04-15 05:24:44 +00:00
|
|
|
|
2006-04-20 01:54:14 +00:00
|
|
|
if (!_hasVoiceFile) {
|
2010-01-23 00:02:01 +00:00
|
|
|
sprintf(filename, "%s%d", gss->speech_filename, disc);
|
|
|
|
_voice = makeCompressedSound(_mixer, file, filename);
|
|
|
|
_hasVoiceFile = (_voice != 0);
|
2006-04-20 01:54:14 +00:00
|
|
|
}
|
|
|
|
if (!_hasVoiceFile) {
|
2006-04-20 08:46:46 +00:00
|
|
|
sprintf(filename, "%s%d.wav", gss->speech_filename, disc);
|
2006-04-15 05:24:44 +00:00
|
|
|
file->open(filename);
|
|
|
|
if (file->isOpen() == false) {
|
2006-08-27 05:02:48 +00:00
|
|
|
error("switchVoiceFile: Can't load voice file %s", filename);
|
2006-04-15 05:24:44 +00:00
|
|
|
}
|
2006-04-20 01:54:14 +00:00
|
|
|
_hasVoiceFile = true;
|
2006-04-15 05:24:44 +00:00
|
|
|
_voice = new WavSound(_mixer, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
} // End of namespace AGOS
|