2009-10-11 22:30:40 +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.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2009-10-30 05:21:44 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2009-10-11 22:30:40 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-07-01 07:10:40 +00:00
|
|
|
#include "common/archive.h"
|
2009-10-12 22:27:23 +00:00
|
|
|
#include "common/config-manager.h"
|
2009-10-11 22:30:40 +00:00
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/file.h"
|
|
|
|
#include "common/str.h"
|
2010-11-19 17:03:07 +00:00
|
|
|
#include "common/substream.h"
|
|
|
|
#include "common/memstream.h"
|
2010-07-01 07:10:40 +00:00
|
|
|
#include "common/unzip.h"
|
2009-10-11 22:30:40 +00:00
|
|
|
|
|
|
|
#include "draci/sound.h"
|
|
|
|
#include "draci/draci.h"
|
2009-10-29 15:26:48 +00:00
|
|
|
#include "draci/game.h"
|
2009-10-11 22:30:40 +00:00
|
|
|
|
2009-10-12 22:27:23 +00:00
|
|
|
#include "sound/audiostream.h"
|
|
|
|
#include "sound/mixer.h"
|
2010-01-26 22:48:45 +00:00
|
|
|
#include "sound/decoders/raw.h"
|
2010-07-01 07:10:40 +00:00
|
|
|
#include "sound/decoders/mp3.h"
|
|
|
|
#include "sound/decoders/vorbis.h"
|
|
|
|
#include "sound/decoders/flac.h"
|
2009-10-12 22:27:23 +00:00
|
|
|
|
2009-10-11 22:30:40 +00:00
|
|
|
namespace Draci {
|
|
|
|
|
2010-07-01 07:10:40 +00:00
|
|
|
void LegacySoundArchive::openArchive(const char *path) {
|
2009-10-11 22:30:40 +00:00
|
|
|
// Close previously opened archive (if any)
|
|
|
|
closeArchive();
|
|
|
|
|
2010-07-03 03:48:26 +00:00
|
|
|
debugCN(1, kDraciArchiverDebugLevel, "Loading samples %s: ", path);
|
2009-10-11 22:30:40 +00:00
|
|
|
|
|
|
|
_f = new Common::File();
|
|
|
|
_f->open(path);
|
|
|
|
if (_f->isOpen()) {
|
2010-07-03 03:48:26 +00:00
|
|
|
debugC(1, kDraciArchiverDebugLevel, "Success");
|
2009-10-11 22:30:40 +00:00
|
|
|
} else {
|
2010-07-03 03:48:26 +00:00
|
|
|
debugC(1, kDraciArchiverDebugLevel, "Error");
|
2009-10-13 05:38:45 +00:00
|
|
|
delete _f;
|
|
|
|
_f = NULL;
|
2009-10-11 22:30:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save path for reading in files later on
|
|
|
|
_path = path;
|
|
|
|
|
|
|
|
// Read archive header
|
2010-07-03 03:48:26 +00:00
|
|
|
debugC(1, kDraciArchiverDebugLevel, "Loading header");
|
2009-10-11 22:30:40 +00:00
|
|
|
|
|
|
|
uint totalLength = _f->readUint32LE();
|
|
|
|
const uint kMaxSamples = 4095; // The no-sound file is exactly 16K bytes long, so don't fail on short reads
|
|
|
|
uint sampleStarts[kMaxSamples];
|
|
|
|
for (uint i = 0; i < kMaxSamples; ++i) {
|
|
|
|
sampleStarts[i] = _f->readUint32LE();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill the sample table
|
|
|
|
for (_sampleCount = 0; _sampleCount < kMaxSamples - 1; ++_sampleCount) {
|
|
|
|
int length = sampleStarts[_sampleCount + 1] - sampleStarts[_sampleCount];
|
|
|
|
if (length <= 0 && sampleStarts[_sampleCount] >= totalLength) // heuristics to detect the last sample
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (_sampleCount > 0) {
|
2010-07-03 03:48:26 +00:00
|
|
|
debugC(1, kDraciArchiverDebugLevel, "Archive info: %d samples, %d total length",
|
2009-10-11 22:30:40 +00:00
|
|
|
_sampleCount, totalLength);
|
|
|
|
_samples = new SoundSample[_sampleCount];
|
|
|
|
for (uint i = 0; i < _sampleCount; ++i) {
|
|
|
|
_samples[i]._offset = sampleStarts[i];
|
|
|
|
_samples[i]._length = sampleStarts[i+1] - sampleStarts[i];
|
2009-10-11 23:01:59 +00:00
|
|
|
_samples[i]._frequency = 0; // set in getSample()
|
2009-10-11 22:30:40 +00:00
|
|
|
}
|
|
|
|
if (_samples[_sampleCount-1]._offset + _samples[_sampleCount-1]._length != totalLength &&
|
|
|
|
_samples[_sampleCount-1]._offset + _samples[_sampleCount-1]._length - _samples[0]._offset != totalLength) {
|
|
|
|
// WORKAROUND: the stored length is stored with the header for sounds and without the hader for dubbing. Crazy.
|
2010-07-03 03:48:26 +00:00
|
|
|
debugC(1, kDraciArchiverDebugLevel, "Broken sound archive: %d != %d",
|
2009-10-11 22:30:40 +00:00
|
|
|
_samples[_sampleCount-1]._offset + _samples[_sampleCount-1]._length,
|
|
|
|
totalLength);
|
|
|
|
closeArchive();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2010-07-03 03:48:26 +00:00
|
|
|
debugC(1, kDraciArchiverDebugLevel, "Archive info: empty");
|
2009-10-11 22:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Indicate that the archive has been successfully opened
|
|
|
|
_opened = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-06-30 08:27:09 +00:00
|
|
|
* @brief LegacySoundArchive close method
|
2009-10-11 22:30:40 +00:00
|
|
|
*
|
|
|
|
* Closes the currently opened archive. It can be called explicitly to
|
|
|
|
* free up memory.
|
|
|
|
*/
|
2010-06-30 08:27:09 +00:00
|
|
|
void LegacySoundArchive::closeArchive() {
|
2009-10-11 22:30:40 +00:00
|
|
|
clearCache();
|
|
|
|
delete _f;
|
|
|
|
_f = NULL;
|
|
|
|
delete[] _samples;
|
|
|
|
_samples = NULL;
|
|
|
|
_sampleCount = 0;
|
|
|
|
_path = "";
|
|
|
|
_opened = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the cache of the open files inside the archive without closing it.
|
|
|
|
* If the files are subsequently accessed, they are read from the disk.
|
|
|
|
*/
|
2010-06-30 08:27:09 +00:00
|
|
|
void LegacySoundArchive::clearCache() {
|
2009-10-11 22:30:40 +00:00
|
|
|
// Delete all cached data
|
|
|
|
for (uint i = 0; i < _sampleCount; ++i) {
|
|
|
|
_samples[i].close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief On-demand sound sample loader
|
|
|
|
* @param i Index of file inside an archive
|
|
|
|
* @return Pointer to a SoundSample coresponding to the opened file or NULL (on failure)
|
|
|
|
*
|
|
|
|
* Loads individual samples from an archive to memory on demand.
|
|
|
|
*/
|
2010-06-30 08:27:09 +00:00
|
|
|
SoundSample *LegacySoundArchive::getSample(int i, uint freq) {
|
2009-10-11 22:30:40 +00:00
|
|
|
// Check whether requested file exists
|
2009-10-12 22:27:23 +00:00
|
|
|
if (i < 0 || i >= (int) _sampleCount) {
|
2009-10-11 22:30:40 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
debugCN(2, kDraciArchiverDebugLevel, "Accessing sample %d from archive %s... ",
|
2010-07-01 07:10:40 +00:00
|
|
|
i, _path);
|
2009-10-11 22:30:40 +00:00
|
|
|
|
|
|
|
// Check if file has already been opened and return that
|
|
|
|
if (_samples[i]._data) {
|
2010-07-01 07:10:40 +00:00
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Cached");
|
2009-10-11 23:01:59 +00:00
|
|
|
} else {
|
2010-07-01 07:10:40 +00:00
|
|
|
// It would be nice to unify the approach with ZipSoundArchive
|
|
|
|
// and allocate a MemoryReadStream with buffer stored inside it
|
|
|
|
// that playSoundBuffer() would just play. Unfortunately,
|
|
|
|
// streams are not thread-safe and the same sample couldn't
|
|
|
|
// thus be played more than once at the same time (this holds
|
|
|
|
// even if we create a SeekableSubReadStream from it as this
|
|
|
|
// just uses the parent). The only thread-safe solution is to
|
|
|
|
// share a read-only buffer and allocate separate
|
|
|
|
// MemoryReadStream's on top of it.
|
|
|
|
_samples[i]._data = new byte[_samples[i]._length];
|
|
|
|
_samples[i]._format = RAW;
|
|
|
|
|
2009-10-11 23:01:59 +00:00
|
|
|
// Read in the file (without the file header)
|
|
|
|
_f->seek(_samples[i]._offset);
|
|
|
|
_f->read(_samples[i]._data, _samples[i]._length);
|
2009-10-11 22:30:40 +00:00
|
|
|
|
2010-07-03 03:48:26 +00:00
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Read sample %d from archive %s",
|
2010-07-01 07:10:40 +00:00
|
|
|
i, _path);
|
2009-10-11 23:01:59 +00:00
|
|
|
}
|
2009-10-12 22:27:23 +00:00
|
|
|
_samples[i]._frequency = freq ? freq : _defaultFreq;
|
2009-10-11 22:30:40 +00:00
|
|
|
|
|
|
|
return _samples + i;
|
|
|
|
}
|
|
|
|
|
2010-07-01 07:10:40 +00:00
|
|
|
void ZipSoundArchive::openArchive(const char *path, const char *extension, SoundFormat format, int raw_frequency) {
|
|
|
|
closeArchive();
|
2010-07-01 17:16:06 +00:00
|
|
|
if ((format == RAW || format == RAW80) && !raw_frequency) {
|
2010-07-01 17:06:14 +00:00
|
|
|
error("openArchive() expects frequency for RAW data");
|
|
|
|
return;
|
|
|
|
}
|
2010-07-01 07:10:40 +00:00
|
|
|
|
2010-07-03 03:48:26 +00:00
|
|
|
debugCN(1, kDraciArchiverDebugLevel, "Trying to open ZIP archive %s: ", path);
|
2010-07-01 07:10:40 +00:00
|
|
|
_archive = Common::makeZipArchive(path);
|
|
|
|
_path = path;
|
|
|
|
_extension = extension;
|
|
|
|
_format = format;
|
|
|
|
_defaultFreq = raw_frequency;
|
|
|
|
|
|
|
|
if (_archive) {
|
|
|
|
Common::ArchiveMemberList files;
|
|
|
|
_archive->listMembers(files);
|
|
|
|
_sampleCount = files.size();
|
2010-07-03 03:48:26 +00:00
|
|
|
debugC(1, kDraciArchiverDebugLevel, "Capacity %d", _sampleCount);
|
|
|
|
} else {
|
|
|
|
debugC(1, kDraciArchiverDebugLevel, "Failed");
|
2010-07-01 07:10:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZipSoundArchive::closeArchive() {
|
|
|
|
clearCache();
|
|
|
|
delete _archive;
|
|
|
|
_archive = NULL;
|
|
|
|
_path = _extension = NULL;
|
|
|
|
_sampleCount = _defaultFreq = 0;
|
|
|
|
_format = RAW;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZipSoundArchive::clearCache() {
|
|
|
|
// Just deallocate the link-list of (very short) headers for each
|
|
|
|
// dubbed sentence played in the current location. If the callers have
|
|
|
|
// not called .close() on any of the items, call them now.
|
|
|
|
for (Common::List<SoundSample>::iterator it = _cache.begin(); it != _cache.end(); ++it) {
|
|
|
|
it->close();
|
|
|
|
}
|
|
|
|
_cache.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
SoundSample *ZipSoundArchive::getSample(int i, uint freq) {
|
|
|
|
if (i < 0 || i >= (int) _sampleCount) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
debugCN(2, kDraciArchiverDebugLevel, "Accessing sample %d.%s from archive %s (format %d@%d, capacity %d): ",
|
|
|
|
i, _extension, _path, static_cast<int> (_format), _defaultFreq, _sampleCount);
|
|
|
|
if (freq != 0 && (_format != RAW && _format != RAW80)) {
|
|
|
|
error("Cannot resample a sound in compressed format");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We cannot really cache anything, because createReadStreamForMember()
|
|
|
|
// returns the data as a ReadStream, which is not thread-safe. We thus
|
|
|
|
// read it again each time even if it has possibly been already cached
|
|
|
|
// a while ago. This is not such a problem for dubbing as for regular
|
|
|
|
// sound samples.
|
|
|
|
SoundSample sample;
|
|
|
|
sample._frequency = freq ? freq : _defaultFreq;
|
|
|
|
sample._format = _format;
|
|
|
|
// Read in the file (without the file header)
|
|
|
|
char file_name[20];
|
|
|
|
sprintf(file_name, "%d.%s", i+1, _extension);
|
|
|
|
sample._stream = _archive->createReadStreamForMember(file_name);
|
|
|
|
if (!sample._stream) {
|
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Doesn't exist");
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
debugC(2, kDraciArchiverDebugLevel, "Read");
|
|
|
|
_cache.push_back(sample);
|
|
|
|
// Return a pointer that we own and which we will deallocate
|
|
|
|
// including its contents.
|
|
|
|
return &_cache.back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-13 05:38:45 +00:00
|
|
|
Sound::Sound(Audio::Mixer *mixer) : _mixer(mixer), _muteSound(false), _muteVoice(false),
|
2009-10-29 15:26:48 +00:00
|
|
|
_showSubtitles(true), _talkSpeed(kStandardSpeed) {
|
2009-10-12 22:27:23 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
_handles[i].type = kFreeHandle;
|
|
|
|
|
|
|
|
setVolume();
|
|
|
|
}
|
|
|
|
|
|
|
|
SndHandle *Sound::getHandle() {
|
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++) {
|
|
|
|
if (_handles[i].type != kFreeHandle && !_mixer->isSoundHandleActive(_handles[i].handle)) {
|
|
|
|
debugC(5, kDraciSoundDebugLevel, "Handle %d has finished playing", i);
|
|
|
|
_handles[i].type = kFreeHandle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++) {
|
2009-11-28 00:07:22 +00:00
|
|
|
if (_handles[i].type == kFreeHandle) {
|
|
|
|
debugC(5, kDraciSoundDebugLevel, "Allocated handle %d", i);
|
2009-10-12 22:27:23 +00:00
|
|
|
return &_handles[i];
|
2009-11-28 00:07:22 +00:00
|
|
|
}
|
2009-10-12 22:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error("Sound::getHandle(): Too many sound handles");
|
|
|
|
|
|
|
|
return NULL; // for compilers that don't support NORETURN
|
|
|
|
}
|
|
|
|
|
2010-07-03 05:05:28 +00:00
|
|
|
uint Sound::playSoundBuffer(Audio::SoundHandle *handle, const SoundSample &buffer, int volume,
|
2009-10-12 22:27:23 +00:00
|
|
|
sndHandleType handleType, bool loop) {
|
2010-07-01 07:10:40 +00:00
|
|
|
if (!buffer._stream && !buffer._data) {
|
|
|
|
warning("Empty stream");
|
2010-07-03 05:05:28 +00:00
|
|
|
return 0;
|
2010-07-01 07:10:40 +00:00
|
|
|
}
|
|
|
|
// Create a new SeekableReadStream which will be automatically disposed
|
|
|
|
// after the sample stops playing. Do not dispose the original
|
|
|
|
// data/stream though.
|
|
|
|
// Beware that if the sample comes from an archive (i.e., is stored in
|
|
|
|
// buffer._stream), then you must NOT play it more than once at the
|
|
|
|
// same time, because streams are not thread-safe. Playing it
|
|
|
|
// repeatedly is OK. Currently this is ensured by that archives are
|
|
|
|
// only used for dubbing, which is only played from one place in
|
|
|
|
// script.cpp, which blocks until the dubbed sentence has finished
|
|
|
|
// playing.
|
2010-11-19 17:03:07 +00:00
|
|
|
Common::SeekableReadStream *stream;
|
2010-07-01 17:06:14 +00:00
|
|
|
const int skip = buffer._format == RAW80 ? 80 : 0;
|
2010-07-01 07:10:40 +00:00
|
|
|
if (buffer._stream) {
|
2010-07-01 17:06:14 +00:00
|
|
|
stream = new Common::SeekableSubReadStream(
|
|
|
|
buffer._stream, skip, buffer._stream->size() /* end */, DisposeAfterUse::NO);
|
2010-07-01 07:10:40 +00:00
|
|
|
} else {
|
2010-07-01 17:06:14 +00:00
|
|
|
stream = new Common::MemoryReadStream(
|
|
|
|
buffer._data + skip, buffer._length - skip /* length */, DisposeAfterUse::NO);
|
2010-07-01 07:10:40 +00:00
|
|
|
}
|
2009-10-12 22:27:23 +00:00
|
|
|
|
2010-07-01 07:10:40 +00:00
|
|
|
Audio::SeekableAudioStream *reader = NULL;
|
|
|
|
switch (buffer._format) {
|
|
|
|
case RAW:
|
2010-07-01 17:06:14 +00:00
|
|
|
case RAW80:
|
2010-07-01 07:10:40 +00:00
|
|
|
reader = Audio::makeRawStream(stream, buffer._frequency, Audio::FLAG_UNSIGNED, DisposeAfterUse::YES);
|
|
|
|
break;
|
|
|
|
#ifdef USE_MAD
|
|
|
|
case MP3:
|
|
|
|
reader = Audio::makeMP3Stream(stream, DisposeAfterUse::YES);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef USE_VORBIS
|
|
|
|
case OGG:
|
|
|
|
reader = Audio::makeVorbisStream(stream, DisposeAfterUse::YES);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef USE_FLAC
|
|
|
|
case FLAC:
|
|
|
|
reader = Audio::makeFLACStream(stream, DisposeAfterUse::YES);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
error("Unsupported compression format %d", static_cast<int> (buffer._format));
|
|
|
|
delete stream;
|
2010-07-03 05:05:28 +00:00
|
|
|
return 0;
|
2010-07-01 07:10:40 +00:00
|
|
|
}
|
2009-10-12 22:27:23 +00:00
|
|
|
|
2010-07-03 05:05:28 +00:00
|
|
|
const uint length = reader->getLength().msecs();
|
2010-01-25 01:39:44 +00:00
|
|
|
const Audio::Mixer::SoundType soundType = (handleType == kVoiceHandle) ?
|
2009-10-12 22:27:23 +00:00
|
|
|
Audio::Mixer::kSpeechSoundType : Audio::Mixer::kSFXSoundType;
|
2010-07-01 07:10:40 +00:00
|
|
|
Audio::AudioStream *audio_stream = Audio::makeLoopingAudioStream(reader, loop ? 0 : 1);
|
|
|
|
_mixer->playStream(soundType, handle, audio_stream, -1, volume);
|
2010-07-03 05:05:28 +00:00
|
|
|
return length;
|
2009-10-12 22:27:23 +00:00
|
|
|
}
|
|
|
|
|
2010-07-03 05:05:28 +00:00
|
|
|
uint Sound::playSound(const SoundSample *buffer, int volume, bool loop) {
|
2009-10-13 05:38:45 +00:00
|
|
|
if (!buffer || _muteSound)
|
2010-07-03 05:05:28 +00:00
|
|
|
return 0;
|
2009-10-12 22:27:23 +00:00
|
|
|
SndHandle *handle = getHandle();
|
|
|
|
|
|
|
|
handle->type = kEffectHandle;
|
2010-07-03 05:05:28 +00:00
|
|
|
return playSoundBuffer(&handle->handle, *buffer, 2 * volume, handle->type, loop);
|
2009-10-12 22:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::pauseSound() {
|
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
if (_handles[i].type == kEffectHandle)
|
|
|
|
_mixer->pauseHandle(_handles[i].handle, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::resumeSound() {
|
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
if (_handles[i].type == kEffectHandle)
|
|
|
|
_mixer->pauseHandle(_handles[i].handle, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::stopSound() {
|
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
if (_handles[i].type == kEffectHandle) {
|
|
|
|
_mixer->stopHandle(_handles[i].handle);
|
2009-11-28 00:07:22 +00:00
|
|
|
debugC(5, kDraciSoundDebugLevel, "Stopping effect handle %d", i);
|
2009-10-12 22:27:23 +00:00
|
|
|
_handles[i].type = kFreeHandle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-03 05:05:28 +00:00
|
|
|
uint Sound::playVoice(const SoundSample *buffer) {
|
2009-10-13 05:38:45 +00:00
|
|
|
if (!buffer || _muteVoice)
|
2010-07-03 05:05:28 +00:00
|
|
|
return 0;
|
2009-10-12 22:27:23 +00:00
|
|
|
SndHandle *handle = getHandle();
|
|
|
|
|
|
|
|
handle->type = kVoiceHandle;
|
2010-07-03 05:05:28 +00:00
|
|
|
return playSoundBuffer(&handle->handle, *buffer, Audio::Mixer::kMaxChannelVolume, handle->type, false);
|
2009-10-12 22:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sound::pauseVoice() {
|
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
if (_handles[i].type == kVoiceHandle)
|
|
|
|
_mixer->pauseHandle(_handles[i].handle, true);
|
|
|
|
}
|
2009-10-11 22:30:40 +00:00
|
|
|
|
2009-10-12 22:27:23 +00:00
|
|
|
void Sound::resumeVoice() {
|
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
if (_handles[i].type == kVoiceHandle)
|
|
|
|
_mixer->pauseHandle(_handles[i].handle, false);
|
|
|
|
}
|
2009-10-11 22:30:40 +00:00
|
|
|
|
2009-10-12 22:27:23 +00:00
|
|
|
void Sound::stopVoice() {
|
|
|
|
for (int i = 0; i < SOUND_HANDLES; i++)
|
|
|
|
if (_handles[i].type == kVoiceHandle) {
|
|
|
|
_mixer->stopHandle(_handles[i].handle);
|
2009-11-28 00:07:22 +00:00
|
|
|
debugC(5, kDraciSoundDebugLevel, "Stopping voice handle %d", i);
|
2009-10-12 22:27:23 +00:00
|
|
|
_handles[i].type = kFreeHandle;
|
|
|
|
}
|
|
|
|
}
|
2009-10-11 22:30:40 +00:00
|
|
|
|
2009-10-12 22:27:23 +00:00
|
|
|
void Sound::setVolume() {
|
2010-10-23 15:46:50 +00:00
|
|
|
if (_mixer->isReady()) {
|
|
|
|
_muteSound = ConfMan.getBool("sfx_mute");
|
|
|
|
_muteVoice = ConfMan.getBool("speech_mute");
|
|
|
|
} else {
|
|
|
|
_muteSound = _muteVoice = true;
|
|
|
|
}
|
2009-11-12 22:52:00 +00:00
|
|
|
if (ConfMan.getBool("mute")) {
|
2010-10-23 15:46:50 +00:00
|
|
|
_muteSound = _muteVoice = true;
|
2009-11-12 22:52:00 +00:00
|
|
|
}
|
2009-10-13 05:38:45 +00:00
|
|
|
_showSubtitles = ConfMan.getBool("subtitles");
|
|
|
|
_talkSpeed = ConfMan.getInt("talkspeed");
|
2009-10-12 22:27:23 +00:00
|
|
|
const int soundVolume = ConfMan.getInt("sfx_volume");
|
|
|
|
const int speechVolume = ConfMan.getInt("speech_volume");
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, soundVolume);
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, speechVolume);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Draci
|