2002-11-29 22:09:52 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-05-05 00:42:37 +00:00
|
|
|
* Copyright (C) 2001 Ludvig Strigeus
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2001-2006 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.
|
2006-05-05 00:42:37 +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.
|
2006-05-05 00:42:37 +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
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
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/adpcm.h"
|
|
|
|
#include "sound/audiostream.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;
|
|
|
|
|
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);
|
2007-01-01 11:29:20 +00:00
|
|
|
void playSound(uint sound, Audio::SoundHandle *handle, byte flags, int vol = 0) {
|
|
|
|
playSound(sound, sound, handle, flags, vol);
|
2007-01-01 09:58:00 +00:00
|
|
|
}
|
2003-06-21 15:36:19 +00:00
|
|
|
virtual ~BaseSound();
|
2007-01-01 11:29:20 +00:00
|
|
|
virtual void playSound(uint sound, uint loopSound, 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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-01 05:44:34 +00:00
|
|
|
WavSound(Audio::Mixer *mixer, File *file, uint32 base = 0, bool bigEndian = false) : BaseSound(mixer, file, base, bigEndian) {};
|
2005-05-10 23:48:48 +00:00
|
|
|
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-01-01 11:29:20 +00:00
|
|
|
void playSound(uint sound, uint loopSound, 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 {
|
2003-06-15 11:48:04 +00:00
|
|
|
public:
|
2007-01-01 05:44:34 +00:00
|
|
|
VocSound(Audio::Mixer *mixer, File *file, uint32 base = 0, bool bigEndian = false) : BaseSound(mixer, file, base, bigEndian) {};
|
2007-01-01 09:58:00 +00:00
|
|
|
Audio::AudioStream *makeAudioStream(uint sound);
|
2007-01-01 11:29:20 +00:00
|
|
|
void playSound(uint sound, uint loopSound, 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-01-01 05:44:34 +00:00
|
|
|
RawSound(Audio::Mixer *mixer, File *file, uint32 base = 0, bool bigEndian = false) : BaseSound(mixer, file, base, bigEndian) {};
|
2007-01-01 11:29:20 +00:00
|
|
|
void playSound(uint sound, uint loopSound, 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
|
|
|
}
|
|
|
|
|
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);
|
2007-01-01 09:58:00 +00:00
|
|
|
return Audio::makeWAVStream(*_file);
|
|
|
|
}
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2007-01-01 11:29:20 +00:00
|
|
|
void WavSound::playSound(uint sound, uint loopSound, Audio::SoundHandle *handle, byte flags, int vol) {
|
|
|
|
convertVolume(vol);
|
|
|
|
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, new LoopingAudioStream(this, sound, loopSound, (flags & Audio::Mixer::FLAG_LOOP) != 0), sound, vol);
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2007-01-01 09:58:00 +00:00
|
|
|
Audio::AudioStream *VocSound::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);
|
2007-01-01 09:58:00 +00:00
|
|
|
return Audio::makeVOCStream(*_file);
|
|
|
|
}
|
2003-06-15 12:22:19 +00:00
|
|
|
|
2007-01-01 11:29:20 +00:00
|
|
|
void VocSound::playSound(uint sound, uint loopSound, Audio::SoundHandle *handle, byte flags, int vol) {
|
2007-01-01 09:58:00 +00:00
|
|
|
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, new LoopingAudioStream(this, sound, loopSound, (flags & Audio::Mixer::FLAG_LOOP) != 0), sound);
|
2003-06-15 12:22:19 +00:00
|
|
|
}
|
|
|
|
|
2007-01-01 11:29:20 +00:00
|
|
|
void RawSound::playSound(uint sound, uint loopSound, 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);
|
2006-10-14 05:47:18 +00:00
|
|
|
_mixer->playRaw(handle, buffer, size, 22050, flags | Audio::Mixer::FLAG_AUTOFREE, sound);
|
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) {};
|
2006-10-13 05:06:53 +00:00
|
|
|
Audio::AudioStream *makeAudioStream(uint sound);
|
2007-01-01 11:29:20 +00:00
|
|
|
void playSound(uint sound, uint loopSound, 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
|
|
|
|
2006-10-13 05:06:53 +00:00
|
|
|
return Audio::makeMP3Stream(_file, size);
|
|
|
|
}
|
|
|
|
|
2007-01-01 11:29:20 +00:00
|
|
|
void MP3Sound::playSound(uint sound, uint loopSound, Audio::SoundHandle *handle, byte flags, int vol) {
|
|
|
|
convertVolume(vol);
|
|
|
|
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, new LoopingAudioStream(this, sound, loopSound, (flags & Audio::Mixer::FLAG_LOOP) != 0), sound, 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:
|
2005-05-10 23:48:48 +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-01-01 11:29:20 +00:00
|
|
|
void playSound(uint sound, uint loopSound, 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])
|
|
|
|
i++;
|
|
|
|
|
2004-01-19 17:50:38 +00:00
|
|
|
uint32 size = _offsets[sound + i] - _offsets[sound];
|
2003-12-21 16:01:36 +00:00
|
|
|
|
2006-10-13 05:06:53 +00:00
|
|
|
return Audio::makeVorbisStream(_file, size);
|
|
|
|
}
|
|
|
|
|
2007-01-01 11:29:20 +00:00
|
|
|
void VorbisSound::playSound(uint sound, uint loopSound, Audio::SoundHandle *handle, byte flags, int vol) {
|
|
|
|
convertVolume(vol);
|
|
|
|
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, new LoopingAudioStream(this, sound, loopSound, (flags & Audio::Mixer::FLAG_LOOP) != 0), sound, 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:
|
2005-05-10 23:48:48 +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-01-01 11:29:20 +00:00
|
|
|
void playSound(uint sound, uint loopSound, 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])
|
|
|
|
i++;
|
|
|
|
|
|
|
|
uint32 size = _offsets[sound + i] - _offsets[sound];
|
|
|
|
|
2006-10-13 05:06:53 +00:00
|
|
|
return Audio::makeFlacStream(_file, size);
|
|
|
|
}
|
|
|
|
|
2007-01-01 11:29:20 +00:00
|
|
|
void FlacSound::playSound(uint sound, uint loopSound, Audio::SoundHandle *handle, byte flags, int vol) {
|
|
|
|
convertVolume(vol);
|
|
|
|
_mixer->playInputStream(Audio::Mixer::kSFXSoundType, handle, new LoopingAudioStream(this, sound, loopSound, (flags & Audio::Mixer::FLAG_LOOP) != 0), sound, 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
|
|
|
|
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
|
2002-11-29 22:09:52 +00:00
|
|
|
#ifdef USE_MAD
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasVoiceFile) {
|
|
|
|
sprintf(filename, "%s.mp3", gss->speech_filename);
|
|
|
|
file->open(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
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasVoiceFile) {
|
|
|
|
sprintf(filename, "%s.ogg", gss->speech_filename);
|
|
|
|
file->open(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) {
|
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
|
|
|
|
|
|
|
#ifdef USE_MAD
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasEffectsFile) {
|
|
|
|
sprintf(filename, "%s.mp3", gss->effects_filename);
|
|
|
|
file->open(filename);
|
2006-04-15 05:24:44 +00:00
|
|
|
if (file->isOpen()) {
|
|
|
|
_hasEffectsFile = true;
|
|
|
|
_effects = new MP3Sound(_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
|
|
|
|
#ifdef USE_FLAC
|
2006-04-20 02:23:17 +00:00
|
|
|
if (!_hasEffectsFile) {
|
2006-09-18 11:57:38 +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;
|
|
|
|
_effects = new FlacSound(_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();
|
|
|
|
|
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
|
|
|
|
2006-10-14 05:47:18 +00:00
|
|
|
if (_mixer->getSoundID(_voiceHandle) == (int)sound)
|
|
|
|
return;
|
|
|
|
|
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-01-01 11:29:20 +00:00
|
|
|
_voice->playSound(sound, sound + 1, &_voiceHandle, Audio::Mixer::FLAG_LOOP, -1500);
|
|
|
|
else
|
|
|
|
_voice->playSound(sound, sound, &_voiceHandle, Audio::Mixer::FLAG_LOOP);
|
2006-09-29 06:58:59 +00:00
|
|
|
} else if (_vm->getGameType() == GType_FF || _vm->getGameId() == GID_SIMON1CD32) {
|
2005-11-15 12:03:38 +00:00
|
|
|
_voice->playSound(sound, &_voiceHandle, 0);
|
|
|
|
} else {
|
|
|
|
_voice->playSound(sound, &_voiceHandle, 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);
|
2007-01-01 09:58:00 +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 {
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Elvira 1/2 and Waxworks specific
|
|
|
|
void Sound::playRawData(byte *soundData, uint sound, uint size) {
|
|
|
|
byte *buffer = (byte *)malloc(size);
|
|
|
|
memcpy(buffer, soundData, size);
|
|
|
|
|
2006-10-14 14:29:14 +00:00
|
|
|
if (_vm->getPlatform() == Common::kPlatformPC)
|
|
|
|
_mixer->playRaw(&_effectsHandle, buffer, size, 8000, Audio::Mixer::FLAG_UNSIGNED | Audio::Mixer::FLAG_AUTOFREE, sound);
|
|
|
|
else
|
|
|
|
_mixer->playRaw(&_effectsHandle, buffer, size, 8000, Audio::Mixer::FLAG_AUTOFREE, sound);
|
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-22 03:53:14 +00:00
|
|
|
byte *buffer, flags;
|
|
|
|
uint16 compType;
|
|
|
|
int blockAlign, rate;
|
2006-04-15 05:24:44 +00:00
|
|
|
|
|
|
|
int size = READ_LE_UINT32(soundData + 4);
|
|
|
|
Common::MemoryReadStream stream(soundData, size);
|
2006-08-27 05:02:48 +00:00
|
|
|
if (!Audio::loadWAVFromStream(stream, size, rate, flags, &compType, &blockAlign))
|
2006-04-15 05:24:44 +00:00
|
|
|
error("playSoundData: Not a valid WAV data");
|
|
|
|
|
2007-01-01 11:29:20 +00:00
|
|
|
convertVolume(vol);
|
|
|
|
convertPan(pan);
|
2006-04-23 15:42:02 +00:00
|
|
|
|
2006-04-17 12:05:45 +00:00
|
|
|
if (loop == true)
|
|
|
|
flags |= Audio::Mixer::FLAG_LOOP;
|
|
|
|
|
2006-04-22 03:53:14 +00:00
|
|
|
if (compType == 2) {
|
2006-04-29 22:33:31 +00:00
|
|
|
Audio::AudioStream *sndStream = Audio::makeADPCMStream(&stream, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
|
2006-04-22 03:53:14 +00:00
|
|
|
buffer = (byte *)malloc(size * 4);
|
|
|
|
size = sndStream->readBuffer((int16*)buffer, size * 2);
|
|
|
|
size *= 2; // 16bits.
|
|
|
|
delete sndStream;
|
|
|
|
} else {
|
|
|
|
buffer = (byte *)malloc(size);
|
|
|
|
memcpy(buffer, soundData + stream.pos(), size);
|
2006-04-15 05:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-01-01 11:29:20 +00:00
|
|
|
_mixer->playRaw(handle, buffer, size, rate, flags | Audio::Mixer::FLAG_AUTOFREE, sound, 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
|
|
|
|
#ifdef USE_MAD
|
|
|
|
if (!_hasVoiceFile) {
|
2006-04-20 02:23:17 +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;
|
|
|
|
_voice = new MP3Sound(_mixer, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef USE_VORBIS
|
|
|
|
if (!_hasVoiceFile) {
|
2006-04-20 02:23:17 +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;
|
|
|
|
_voice = new VorbisSound(_mixer, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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
|