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
|
|
|
*
|
2006-05-05 00:42:37 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
2002-11-29 22:09:52 +00:00
|
|
|
*/
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
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
|
|
|
|
2006-09-29 08:14:27 +00:00
|
|
|
#include "agos/agos.h"
|
|
|
|
#include "agos/sound.h"
|
2004-11-27 15:58:18 +00:00
|
|
|
|
2006-04-22 03:53:14 +00:00
|
|
|
#include "sound/audiostream.h"
|
2004-11-27 15:58:18 +00:00
|
|
|
#include "sound/flac.h"
|
2007-06-10 01:08:15 +00:00
|
|
|
#include "sound/mixer.h"
|
2004-11-27 15:58:18 +00:00
|
|
|
#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;
|
|
|
|
|
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
|
|
|
|
|
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:
|
2007-01-01 05:44:34 +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);
|
2008-08-14 00:26:57 +00:00
|
|
|
virtual ~BaseSound();
|
|
|
|
void close();
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2007-06-10 01:08:15 +00:00
|
|
|
void playSound(uint sound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol = 0) {
|
|
|
|
playSound(sound, sound, type, handle, flags, vol);
|
2007-01-01 09:58:00 +00:00
|
|
|
}
|
2007-06-10 01:08:15 +00:00
|
|
|
virtual void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol = 0) = 0;
|
2006-10-13 05:06:53 +00:00
|
|
|
virtual Audio::AudioStream *makeAudioStream(uint sound) { return NULL; }
|
2003-06-15 11:48:04 +00:00
|
|
|
};
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2003-06-15 12:22:19 +00:00
|
|
|
class WavSound : public BaseSound {
|
2003-06-15 11:48:04 +00:00
|
|
|
public:
|
2007-04-26 19:08:53 +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) {}
|
2007-01-01 09:58:00 +00:00
|
|
|
Audio::AudioStream *makeAudioStream(uint sound);
|
2007-06-10 01:08:15 +00:00
|
|
|
void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol = 0);
|
2003-06-15 11:48:04 +00:00
|
|
|
};
|
|
|
|
|
2003-06-15 12:22:19 +00:00
|
|
|
class VocSound : public BaseSound {
|
2009-08-13 21:46:41 +00:00
|
|
|
byte _flags;
|
2003-06-15 11:48:04 +00:00
|
|
|
public:
|
2009-08-13 21:46:41 +00:00
|
|
|
VocSound(Audio::Mixer *mixer, File *file, uint32 base = 0, bool bigEndian = false) : BaseSound(mixer, file, base, bigEndian), _flags(0) {}
|
|
|
|
Audio::AudioStream *makeAudioStream(uint sound);
|
2007-06-10 01:08:15 +00:00
|
|
|
void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol = 0);
|
2003-07-21 04:00:04 +00:00
|
|
|
};
|
2007-01-01 09:58:00 +00:00
|
|
|
|
2003-07-21 04:00:04 +00:00
|
|
|
class RawSound : public BaseSound {
|
|
|
|
public:
|
2007-04-26 19:08:53 +00:00
|
|
|
RawSound(Audio::Mixer *mixer, File *file, uint32 base = 0, bool bigEndian = false) : BaseSound(mixer, file, base, bigEndian) {}
|
2007-06-10 01:08:15 +00:00
|
|
|
void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol = 0);
|
2003-06-15 11:48:04 +00:00
|
|
|
};
|
|
|
|
|
2007-01-01 05:44:34 +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);
|
2007-01-01 05:44:34 +00:00
|
|
|
if (bigEndian)
|
2003-07-21 04:00:04 +00:00
|
|
|
size = _file->readUint32BE();
|
|
|
|
else
|
|
|
|
size = _file->readUint32LE();
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2005-11-15 12:03:38 +00:00
|
|
|
// The Feeble Files uses set amount of voice offsets
|
|
|
|
if (size == 0)
|
|
|
|
size = 40000;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
for (uint i = 0; i < res; i++) {
|
2007-01-01 05:44:34 +00:00
|
|
|
if (bigEndian)
|
|
|
|
_offsets[i] = base + _file->readUint32BE();
|
|
|
|
else
|
|
|
|
_offsets[i] = base + _file->readUint32LE();
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// only needed for mp3
|
2006-04-26 14:35:53 +00:00
|
|
|
_offsets[res] = _file->size();
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2007-01-01 05:44:34 +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
|
|
|
}
|
|
|
|
|
2008-08-14 00:26:57 +00:00
|
|
|
void BaseSound::close() {
|
|
|
|
if (_freeOffsets) {
|
|
|
|
free(_offsets);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2007-01-01 11:29:20 +00:00
|
|
|
void convertVolume(int &vol) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void convertPan(int &pan) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2007-06-10 01:08:15 +00:00
|
|
|
void WavSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol) {
|
2007-01-01 11:29:20 +00:00
|
|
|
convertVolume(vol);
|
2007-06-10 01:08:15 +00:00
|
|
|
_mixer->playInputStream(type, handle, new LoopingAudioStream(this, sound, loopSound, (flags & Audio::Mixer::FLAG_LOOP) != 0), -1, vol);
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2009-08-13 21:46:41 +00:00
|
|
|
Audio::AudioStream *VocSound::makeAudioStream(uint sound) {
|
2003-06-15 12:22:19 +00:00
|
|
|
_file->seek(_offsets[sound], SEEK_SET);
|
2009-08-13 21:46:41 +00:00
|
|
|
return Audio::makeVOCStream(*_file, _flags);
|
|
|
|
}
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2009-08-13 21:46:41 +00:00
|
|
|
void VocSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol) {
|
|
|
|
convertVolume(vol);
|
|
|
|
_flags = flags;
|
|
|
|
_mixer->playInputStream(type, handle, new LoopingAudioStream(this, sound, loopSound, (flags & Audio::Mixer::FLAG_LOOP) != 0), -1, vol);
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2007-06-10 01:08:15 +00:00
|
|
|
void RawSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol) {
|
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);
|
2006-10-05 00:16:50 +00:00
|
|
|
assert(buffer);
|
|
|
|
_file->read(buffer, size);
|
2010-01-19 00:56:29 +00:00
|
|
|
_mixer->playRaw(type, handle, buffer, size, DisposeAfterUse::YES, 22050, flags);
|
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:
|
2007-04-26 19:08:53 +00:00
|
|
|
MP3Sound(Audio::Mixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {}
|
2006-10-13 05:06:53 +00:00
|
|
|
Audio::AudioStream *makeAudioStream(uint sound);
|
2007-06-10 01:08:15 +00:00
|
|
|
void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol = 0);
|
2003-06-24 21:52:52 +00:00
|
|
|
};
|
|
|
|
|
2006-10-13 05:06:53 +00:00
|
|
|
Audio::AudioStream *MP3Sound::makeAudioStream(uint sound) {
|
2003-06-15 12:22:19 +00:00
|
|
|
if (_offsets == NULL)
|
2006-10-13 05:06:53 +00:00
|
|
|
return NULL;
|
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])
|
2006-12-20 20:10:37 +00:00
|
|
|
i++;
|
2004-01-19 17:44:04 +00:00
|
|
|
|
|
|
|
uint32 size = _offsets[sound + i] - _offsets[sound];
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2007-07-15 19:24:00 +00:00
|
|
|
Common::MemoryReadStream *tmp = _file->readStream(size);
|
|
|
|
assert(tmp);
|
2010-01-16 21:36:08 +00:00
|
|
|
return Audio::makeMP3Stream(tmp, DisposeAfterUse::YES);
|
2006-10-13 05:06:53 +00:00
|
|
|
}
|
|
|
|
|
2007-06-10 01:08:15 +00:00
|
|
|
void MP3Sound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol) {
|
2007-01-01 11:29:20 +00:00
|
|
|
convertVolume(vol);
|
2007-06-10 01:08:15 +00:00
|
|
|
_mixer->playInputStream(type, handle, new LoopingAudioStream(this, sound, loopSound, (flags & Audio::Mixer::FLAG_LOOP) != 0), -1, vol);
|
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:
|
2007-04-26 19:08:53 +00:00
|
|
|
VorbisSound(Audio::Mixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {}
|
2006-10-13 05:06:53 +00:00
|
|
|
Audio::AudioStream *makeAudioStream(uint sound);
|
2007-06-10 01:08:15 +00:00
|
|
|
void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol = 0);
|
2003-12-21 16:01:36 +00:00
|
|
|
};
|
|
|
|
|
2006-10-13 05:06:53 +00:00
|
|
|
Audio::AudioStream *VorbisSound::makeAudioStream(uint sound) {
|
2003-12-21 16:01:36 +00:00
|
|
|
if (_offsets == NULL)
|
2006-10-13 05:06:53 +00:00
|
|
|
return NULL;
|
2003-12-21 16:01:36 +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])
|
2007-02-17 00:54:32 +00:00
|
|
|
i++;
|
2004-01-19 17:44:04 +00:00
|
|
|
|
2004-01-19 17:50:38 +00:00
|
|
|
uint32 size = _offsets[sound + i] - _offsets[sound];
|
2003-12-21 16:01:36 +00:00
|
|
|
|
2007-07-15 19:24:00 +00:00
|
|
|
Common::MemoryReadStream *tmp = _file->readStream(size);
|
|
|
|
assert(tmp);
|
2010-01-16 21:36:08 +00:00
|
|
|
return Audio::makeVorbisStream(tmp, DisposeAfterUse::YES);
|
2006-10-13 05:06:53 +00:00
|
|
|
}
|
|
|
|
|
2007-06-10 01:08:15 +00:00
|
|
|
void VorbisSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol) {
|
2007-01-01 11:29:20 +00:00
|
|
|
convertVolume(vol);
|
2007-06-10 01:08:15 +00:00
|
|
|
_mixer->playInputStream(type, handle, new LoopingAudioStream(this, sound, loopSound, (flags & Audio::Mixer::FLAG_LOOP) != 0), -1, vol);
|
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:
|
2007-04-26 19:08:53 +00:00
|
|
|
FlacSound(Audio::Mixer *mixer, File *file, uint32 base = 0) : BaseSound(mixer, file, base) {}
|
2006-10-13 05:06:53 +00:00
|
|
|
Audio::AudioStream *makeAudioStream(uint sound);
|
2007-06-10 01:08:15 +00:00
|
|
|
void playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol = 0);
|
2004-02-22 14:11:16 +00:00
|
|
|
};
|
|
|
|
|
2006-10-13 05:06:53 +00:00
|
|
|
Audio::AudioStream *FlacSound::makeAudioStream(uint sound) {
|
2004-02-22 14:11:16 +00:00
|
|
|
if (_offsets == NULL)
|
2006-10-13 05:06:53 +00:00
|
|
|
return NULL;
|
2004-02-22 14:11:16 +00:00
|
|
|
|
|
|
|
_file->seek(_offsets[sound], SEEK_SET);
|
|
|
|
|
|
|
|
int i = 1;
|
|
|
|
while (_offsets[sound + i] == _offsets[sound])
|
2007-02-17 00:54:32 +00:00
|
|
|
i++;
|
2004-02-22 14:11:16 +00:00
|
|
|
|
|
|
|
uint32 size = _offsets[sound + i] - _offsets[sound];
|
|
|
|
|
2007-07-15 19:24:00 +00:00
|
|
|
Common::MemoryReadStream *tmp = _file->readStream(size);
|
|
|
|
assert(tmp);
|
2010-01-16 21:36:08 +00:00
|
|
|
return Audio::makeFlacStream(tmp, DisposeAfterUse::YES);
|
2006-10-13 05:06:53 +00:00
|
|
|
}
|
|
|
|
|
2007-06-10 01:08:15 +00:00
|
|
|
void FlacSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol) {
|
2007-01-01 11:29:20 +00:00
|
|
|
convertVolume(vol);
|
2007-06-10 01:08:15 +00:00
|
|
|
_mixer->playInputStream(type, handle, new LoopingAudioStream(this, sound, loopSound, (flags & Audio::Mixer::FLAG_LOOP) != 0), -1, vol);
|
2004-02-22 14:11:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
|
2006-04-20 02:23:17 +00:00
|
|
|
char filename[16];
|
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
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasVoiceFile) {
|
2006-05-06 06:25:15 +00:00
|
|
|
sprintf(filename, "%s.fla", gss->speech_filename);
|
2006-04-20 02:23:17 +00:00
|
|
|
file->open(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
|
2007-02-24 23:40:28 +00:00
|
|
|
#ifdef USE_VORBIS
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasVoiceFile) {
|
2007-02-24 23:40:28 +00:00
|
|
|
sprintf(filename, "%s.ogg", gss->speech_filename);
|
2006-04-20 02:23:17 +00:00
|
|
|
file->open(filename);
|
2003-12-21 16:01:36 +00:00
|
|
|
if (file->isOpen()) {
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasVoiceFile = true;
|
2007-02-24 23:40:28 +00:00
|
|
|
_voice = new VorbisSound(_mixer, file);
|
2003-12-21 16:01:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2007-02-24 23:40:28 +00:00
|
|
|
#ifdef USE_MAD
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasVoiceFile) {
|
2007-02-24 23:40:28 +00:00
|
|
|
sprintf(filename, "%s.mp3", gss->speech_filename);
|
2006-04-20 02:23:17 +00:00
|
|
|
file->open(filename);
|
2003-12-21 16:01:36 +00:00
|
|
|
if (file->isOpen()) {
|
2005-05-08 12:33:25 +00:00
|
|
|
_hasVoiceFile = true;
|
2007-02-24 23:40:28 +00:00
|
|
|
_voice = new MP3Sound(_mixer, file);
|
2003-12-21 16:01:36 +00:00
|
|
|
}
|
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) {
|
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
|
|
|
}
|
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;
|
|
|
|
_voice = new VocSound(_mixer, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
_voice = new VocSound(_mixer, file);
|
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];
|
2006-04-15 05:24:44 +00:00
|
|
|
File *file = new File();
|
2002-11-29 22:09:52 +00:00
|
|
|
|
2007-02-24 23:40:28 +00:00
|
|
|
#ifdef USE_FLAC
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasEffectsFile) {
|
2007-02-24 23:40:28 +00:00
|
|
|
sprintf(filename, "%s.fla", gss->effects_filename);
|
2006-04-20 02:23:17 +00:00
|
|
|
file->open(filename);
|
2006-04-15 05:24:44 +00:00
|
|
|
if (file->isOpen()) {
|
|
|
|
_hasEffectsFile = true;
|
2007-02-24 23:40:28 +00:00
|
|
|
_effects = new FlacSound(_mixer, file);
|
2003-12-21 16:01:36 +00:00
|
|
|
}
|
2006-04-15 05:24:44 +00:00
|
|
|
}
|
2003-12-21 16:01:36 +00:00
|
|
|
#endif
|
2005-08-10 12:42:56 +00:00
|
|
|
#ifdef USE_VORBIS
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasEffectsFile) {
|
|
|
|
sprintf(filename, "%s.ogg", gss->effects_filename);
|
|
|
|
file->open(filename);
|
2006-04-15 05:24:44 +00:00
|
|
|
if (file->isOpen()) {
|
|
|
|
_hasEffectsFile = true;
|
|
|
|
_effects = new VorbisSound(_mixer, file);
|
2003-11-29 11:56:24 +00:00
|
|
|
}
|
2006-04-15 05:24:44 +00:00
|
|
|
}
|
2004-02-22 14:11:16 +00:00
|
|
|
#endif
|
2007-02-24 23:40:28 +00:00
|
|
|
#ifdef USE_MAD
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasEffectsFile) {
|
2007-02-24 23:40:28 +00:00
|
|
|
sprintf(filename, "%s.mp3", gss->effects_filename);
|
2006-04-20 02:23:17 +00:00
|
|
|
file->open(filename);
|
2006-04-15 05:24:44 +00:00
|
|
|
if (file->isOpen()) {
|
|
|
|
_hasEffectsFile = true;
|
2007-02-24 23:40:28 +00:00
|
|
|
_effects = new MP3Sound(_mixer, file);
|
2004-02-22 14:11:16 +00:00
|
|
|
}
|
2006-04-15 05:24:44 +00:00
|
|
|
}
|
2003-01-11 16:00:55 +00:00
|
|
|
#endif
|
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;
|
|
|
|
_effects = new VocSound(_mixer, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!_hasEffectsFile) {
|
|
|
|
sprintf(filename, "%s", gss->effects_filename);
|
|
|
|
file->open(filename);
|
2006-04-15 05:24:44 +00:00
|
|
|
if (file->isOpen()) {
|
|
|
|
_hasEffectsFile = true;
|
|
|
|
_effects = new VocSound(_mixer, file);
|
2003-01-11 16:00:55 +00:00
|
|
|
}
|
2002-11-29 22:09:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2006-10-15 08:08:50 +00:00
|
|
|
_mixer->stopHandle(_effectsHandle);
|
2002-11-29 22:09:52 +00:00
|
|
|
|
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) {
|
2006-09-16 22:35:21 +00:00
|
|
|
error("readSfxFile: Can't load sfx file %s", filename);
|
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();
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-08-14 00:26:57 +00:00
|
|
|
if (_effects)
|
|
|
|
_effects->close();
|
2002-11-29 22:09:52 +00:00
|
|
|
|
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) {
|
2006-10-15 08:08:50 +00:00
|
|
|
_mixer->stopHandle(_voiceHandle);
|
2003-07-21 04:00:04 +00:00
|
|
|
|
|
|
|
File *file = new 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)
|
|
|
|
error("readVoiceFile: Can't load voice file %s", filename);
|
2003-07-21 04:00:04 +00:00
|
|
|
|
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]) {
|
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]);
|
|
|
|
File *file = new 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)
|
2007-06-10 01:08:15 +00:00
|
|
|
_voice->playSound(sound, sound + 1, Audio::Mixer::kMusicSoundType, &_voiceHandle, Audio::Mixer::FLAG_LOOP, -1500);
|
2007-01-01 11:29:20 +00:00
|
|
|
else
|
2007-06-10 01:08:15 +00:00
|
|
|
_voice->playSound(sound, sound, Audio::Mixer::kMusicSoundType, &_voiceHandle, Audio::Mixer::FLAG_LOOP);
|
2006-09-29 06:58:59 +00:00
|
|
|
} else if (_vm->getGameType() == GType_FF || _vm->getGameId() == GID_SIMON1CD32) {
|
2007-06-10 01:08:15 +00:00
|
|
|
_voice->playSound(sound, Audio::Mixer::kSpeechSoundType, &_voiceHandle, 0);
|
2005-11-15 12:03:38 +00:00
|
|
|
} else {
|
2007-06-10 01:08:15 +00:00
|
|
|
_voice->playSound(sound, Audio::Mixer::kSpeechSoundType, &_voiceHandle, Audio::Mixer::FLAG_UNSIGNED);
|
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);
|
2007-06-10 01:08:15 +00:00
|
|
|
_effects->playSound(sound, Audio::Mixer::kSFXSoundType, &_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);
|
2007-06-10 01:08:15 +00:00
|
|
|
_effects->playSound(sound, Audio::Mixer::kSFXSoundType, &_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;
|
|
|
|
}
|
|
|
|
|
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 00:56:29 +00:00
|
|
|
flags = Audio::Mixer::FLAG_UNSIGNED;
|
|
|
|
_mixer->playRaw(Audio::Mixer::kSFXSoundType, &_effectsHandle, buffer, size, DisposeAfterUse::YES, freq, flags);
|
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) {
|
2006-04-15 05:24:44 +00:00
|
|
|
int size = READ_LE_UINT32(soundData + 4);
|
2009-12-28 15:53:13 +00:00
|
|
|
Common::MemoryReadStream *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-01-08 16:27:29 +00:00
|
|
|
_mixer->playInputStream(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];
|
|
|
|
File *file = new File();
|
2006-04-15 05:24:44 +00:00
|
|
|
|
2006-04-20 01:54:14 +00:00
|
|
|
#ifdef USE_FLAC
|
|
|
|
if (!_hasVoiceFile) {
|
2006-05-06 06:25:15 +00:00
|
|
|
sprintf(filename, "%s%d.fla", gss->speech_filename, disc);
|
2006-04-20 01:54:14 +00:00
|
|
|
file->open(filename);
|
|
|
|
if (file->isOpen()) {
|
|
|
|
_hasVoiceFile = true;
|
|
|
|
_voice = new FlacSound(_mixer, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2007-02-24 23:40:28 +00:00
|
|
|
#ifdef USE_VORBIS
|
2006-04-20 01:54:14 +00:00
|
|
|
if (!_hasVoiceFile) {
|
2007-02-24 23:40:28 +00:00
|
|
|
sprintf(filename, "%s%d.ogg", gss->speech_filename, disc);
|
2006-04-20 01:54:14 +00:00
|
|
|
file->open(filename);
|
|
|
|
if (file->isOpen()) {
|
|
|
|
_hasVoiceFile = true;
|
2007-02-24 23:40:28 +00:00
|
|
|
_voice = new VorbisSound(_mixer, file);
|
2006-04-20 01:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2007-02-24 23:40:28 +00:00
|
|
|
#ifdef USE_MAD
|
2006-04-20 01:54:14 +00:00
|
|
|
if (!_hasVoiceFile) {
|
2007-02-24 23:40:28 +00:00
|
|
|
sprintf(filename, "%s%d.mp3", gss->speech_filename, disc);
|
2006-04-20 01:54:14 +00:00
|
|
|
file->open(filename);
|
|
|
|
if (file->isOpen()) {
|
|
|
|
_hasVoiceFile = true;
|
2007-02-24 23:40:28 +00:00
|
|
|
_voice = new MP3Sound(_mixer, file);
|
2006-04-20 01:54:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
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
|