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.
|
2003-07-28 01:47:41 +00:00
|
|
|
*
|
2007-05-31 20:28:29 +00:00
|
|
|
* Additional copyright for this file:
|
|
|
|
* Copyright (C) 1994-1998 Revolution Software Ltd.
|
|
|
|
*
|
2003-07-28 01:47:41 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-07-28 01:47:41 +00:00
|
|
|
*
|
2006-02-09 15:12:44 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-07-28 01:47:41 +00:00
|
|
|
*/
|
|
|
|
|
2004-08-28 14:50:44 +00:00
|
|
|
// One feature still missing is the original's DipMusic() function which, as
|
|
|
|
// far as I can understand, softened the music volume when someone was
|
|
|
|
// speaking, but only (?) if the music was playing loudly at the time.
|
2003-09-26 14:19:03 +00:00
|
|
|
//
|
2004-08-28 14:50:44 +00:00
|
|
|
// All things considered, I think this is more bother than it's worth.
|
2003-09-26 14:19:03 +00:00
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "common/file.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/system.h"
|
2006-02-17 15:07:36 +00:00
|
|
|
|
2010-01-26 22:48:45 +00:00
|
|
|
#include "sound/decoders/mp3.h"
|
|
|
|
#include "sound/decoders/vorbis.h"
|
|
|
|
#include "sound/decoders/flac.h"
|
|
|
|
#include "sound/decoders/wave.h"
|
|
|
|
#include "sound/decoders/vag.h"
|
2004-10-12 17:03:07 +00:00
|
|
|
#include "sound/rate.h"
|
2005-02-27 16:11:19 +00:00
|
|
|
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/sword2.h"
|
2005-02-27 16:11:19 +00:00
|
|
|
#include "sword2/defs.h"
|
2006-02-17 15:07:36 +00:00
|
|
|
#include "sword2/header.h"
|
2004-08-22 14:28:11 +00:00
|
|
|
#include "sword2/resman.h"
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
#include "sword2/sound.h"
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2009-10-18 19:41:59 +00:00
|
|
|
/**
|
|
|
|
* This class behaves like SeekableSubReadStream, except it remembers where the
|
|
|
|
* previous read() or seek() took it, so that it can continue from that point
|
|
|
|
* the next time. This is because we're frequently streaming two pieces of
|
|
|
|
* music from the same file.
|
|
|
|
*/
|
2009-02-20 22:43:13 +00:00
|
|
|
class SafeSubReadStream : public Common::SeekableSubReadStream {
|
|
|
|
protected:
|
|
|
|
uint32 _previousPos;
|
|
|
|
public:
|
2009-10-18 19:41:59 +00:00
|
|
|
SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end);
|
2009-02-20 22:43:13 +00:00
|
|
|
virtual uint32 read(void *dataPtr, uint32 dataSize);
|
|
|
|
virtual bool seek(int32 offset, int whence = SEEK_SET);
|
|
|
|
};
|
|
|
|
|
2009-10-18 19:41:59 +00:00
|
|
|
SafeSubReadStream::SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end)
|
2010-01-08 22:07:35 +00:00
|
|
|
: SeekableSubReadStream(parentStream, begin, end, DisposeAfterUse::NO) {
|
2009-02-20 22:43:13 +00:00
|
|
|
_previousPos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 SafeSubReadStream::read(void *dataPtr, uint32 dataSize) {
|
|
|
|
uint32 result;
|
|
|
|
SeekableSubReadStream::seek(_previousPos);
|
|
|
|
result = SeekableSubReadStream::read(dataPtr, dataSize);
|
|
|
|
_previousPos = pos();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SafeSubReadStream::seek(int32 offset, int whence) {
|
|
|
|
bool result = SeekableSubReadStream::seek(offset, whence);
|
|
|
|
_previousPos = pos();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-04-29 22:33:31 +00:00
|
|
|
static Audio::AudioStream *makeCLUStream(Common::File *fp, int size);
|
2009-04-07 19:52:46 +00:00
|
|
|
static Audio::AudioStream *makePSXCLUStream(Common::File *fp, int size);
|
2004-09-04 09:27:17 +00:00
|
|
|
|
2006-04-29 22:33:31 +00:00
|
|
|
static Audio::AudioStream *getAudioStream(SoundFileHandle *fh, const char *base, int cd, uint32 id, uint32 *numSamples) {
|
2008-07-18 04:16:00 +00:00
|
|
|
bool alreadyOpen;
|
2005-12-21 10:57:48 +00:00
|
|
|
|
2005-12-11 08:30:48 +00:00
|
|
|
if (!fh->file.isOpen()) {
|
2008-07-18 04:16:00 +00:00
|
|
|
alreadyOpen = false;
|
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
struct {
|
|
|
|
const char *ext;
|
|
|
|
int mode;
|
|
|
|
} file_types[] = {
|
2010-02-03 09:42:40 +00:00
|
|
|
#ifdef USE_FLAC
|
|
|
|
{ "clf", kFLACMode },
|
|
|
|
#endif
|
|
|
|
#ifdef USE_VORBIS
|
2005-02-21 08:35:18 +00:00
|
|
|
{ "clg", kVorbisMode },
|
2010-02-03 09:42:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_MAD
|
2007-02-24 23:40:28 +00:00
|
|
|
{ "cl3", kMP3Mode },
|
2010-02-03 09:42:40 +00:00
|
|
|
#endif
|
2005-02-21 08:35:18 +00:00
|
|
|
{ "clu", kCLUMode }
|
|
|
|
};
|
|
|
|
|
2005-11-19 05:00:56 +00:00
|
|
|
int soundMode = 0;
|
2005-02-21 08:35:18 +00:00
|
|
|
char filename[20];
|
|
|
|
|
|
|
|
for (int i = 0; i < ARRAYSIZE(file_types); i++) {
|
|
|
|
sprintf(filename, "%s%d.%s", base, cd, file_types[i].ext);
|
2008-07-18 04:16:00 +00:00
|
|
|
if (Common::File::exists(filename)) {
|
2005-02-21 08:35:18 +00:00
|
|
|
soundMode = file_types[i].mode;
|
|
|
|
break;
|
|
|
|
}
|
2004-09-04 09:27:17 +00:00
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
sprintf(filename, "%s.%s", base, file_types[i].ext);
|
2008-07-18 04:16:00 +00:00
|
|
|
if (Common::File::exists(filename)) {
|
2005-02-21 08:35:18 +00:00
|
|
|
soundMode = file_types[i].mode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-09-04 09:27:17 +00:00
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
if (soundMode == 0)
|
|
|
|
return NULL;
|
2004-09-04 09:27:17 +00:00
|
|
|
|
2005-12-11 08:30:48 +00:00
|
|
|
fh->file.open(filename);
|
2005-02-21 08:35:18 +00:00
|
|
|
fh->fileType = soundMode;
|
2005-12-11 08:30:48 +00:00
|
|
|
if (!fh->file.isOpen()) {
|
2007-02-17 20:38:27 +00:00
|
|
|
warning("BS2 getAudioStream: Failed opening file '%s'", filename);
|
2005-02-21 08:35:18 +00:00
|
|
|
return NULL;
|
2004-09-04 09:27:17 +00:00
|
|
|
}
|
2005-12-11 08:30:48 +00:00
|
|
|
if (fh->fileSize != fh->file.size()) {
|
2010-07-16 03:07:30 +00:00
|
|
|
free(fh->idxTab);
|
|
|
|
fh->idxTab = NULL;
|
2004-09-04 09:27:17 +00:00
|
|
|
}
|
2008-07-18 04:16:00 +00:00
|
|
|
} else
|
|
|
|
alreadyOpen = true;
|
2004-09-04 09:27:17 +00:00
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
uint32 entrySize = (fh->fileType == kCLUMode) ? 2 : 3;
|
2004-09-04 09:27:17 +00:00
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
if (!fh->idxTab) {
|
2005-12-11 08:30:48 +00:00
|
|
|
fh->file.seek(0);
|
|
|
|
fh->idxLen = fh->file.readUint32LE();
|
|
|
|
fh->file.seek(entrySize * 4);
|
2004-09-04 09:27:17 +00:00
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
fh->idxTab = (uint32*)malloc(fh->idxLen * 3 * sizeof(uint32));
|
|
|
|
for (uint32 cnt = 0; cnt < fh->idxLen; cnt++) {
|
2005-12-11 08:30:48 +00:00
|
|
|
fh->idxTab[cnt * 3 + 0] = fh->file.readUint32LE();
|
|
|
|
fh->idxTab[cnt * 3 + 1] = fh->file.readUint32LE();
|
2005-10-17 06:31:10 +00:00
|
|
|
if (fh->fileType == kCLUMode) {
|
2005-08-15 15:37:17 +00:00
|
|
|
fh->idxTab[cnt * 3 + 2] = fh->idxTab[cnt * 3 + 1];
|
2005-10-17 06:31:10 +00:00
|
|
|
fh->idxTab[cnt * 3 + 1]--;
|
|
|
|
} else
|
2005-12-11 08:30:48 +00:00
|
|
|
fh->idxTab[cnt * 3 + 2] = fh->file.readUint32LE();
|
2005-02-21 08:35:18 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-04 09:27:17 +00:00
|
|
|
|
2009-03-07 21:38:34 +00:00
|
|
|
// FIXME: In the forest maze on Zombie Island, the scripts will often
|
|
|
|
// try to play song 451, which doesn't exist. We could easily substitute
|
|
|
|
// another for it here, but which one? There are roughly 250 musical
|
|
|
|
// cues to choose from.
|
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
uint32 pos = fh->idxTab[id * 3 + 0];
|
|
|
|
uint32 len = fh->idxTab[id * 3 + 1];
|
|
|
|
uint32 enc_len = fh->idxTab[id * 3 + 2];
|
2004-09-04 09:27:17 +00:00
|
|
|
|
|
|
|
if (numSamples)
|
|
|
|
*numSamples = len;
|
|
|
|
|
|
|
|
if (!pos || !len) {
|
2008-07-18 04:16:00 +00:00
|
|
|
// We couldn't find the sound. Possibly as a result of a bad
|
|
|
|
// installation (e.g. using the music file from CD 2 as the
|
|
|
|
// first music file). Don't close the file if it was already
|
|
|
|
// open though, because something is playing from it.
|
|
|
|
warning("getAudioStream: Could not find %s ID %d! Possibly the wrong file", base, id);
|
|
|
|
if (!alreadyOpen)
|
|
|
|
fh->file.close();
|
2004-09-04 09:27:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-12-11 08:30:48 +00:00
|
|
|
fh->file.seek(pos, SEEK_SET);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
switch (fh->fileType) {
|
2004-09-04 09:27:17 +00:00
|
|
|
case kCLUMode:
|
2009-04-07 19:52:46 +00:00
|
|
|
if (Sword2Engine::isPsx())
|
|
|
|
return makePSXCLUStream(&fh->file, enc_len);
|
|
|
|
else
|
|
|
|
return makeCLUStream(&fh->file, enc_len);
|
2004-09-04 09:27:17 +00:00
|
|
|
#ifdef USE_MAD
|
2010-04-17 23:57:50 +00:00
|
|
|
case kMP3Mode: {
|
|
|
|
SafeSubReadStream *tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len);
|
2010-01-16 21:36:08 +00:00
|
|
|
return Audio::makeMP3Stream(tmp, DisposeAfterUse::YES);
|
2010-04-17 23:57:50 +00:00
|
|
|
}
|
2004-09-04 09:27:17 +00:00
|
|
|
#endif
|
2005-08-10 12:42:56 +00:00
|
|
|
#ifdef USE_VORBIS
|
2010-04-17 23:57:50 +00:00
|
|
|
case kVorbisMode: {
|
|
|
|
SafeSubReadStream *tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len);
|
2010-01-16 21:36:08 +00:00
|
|
|
return Audio::makeVorbisStream(tmp, DisposeAfterUse::YES);
|
2010-04-17 23:57:50 +00:00
|
|
|
}
|
2004-09-04 09:27:17 +00:00
|
|
|
#endif
|
|
|
|
#ifdef USE_FLAC
|
2010-04-17 23:57:50 +00:00
|
|
|
case kFLACMode: {
|
|
|
|
SafeSubReadStream *tmp = new SafeSubReadStream(&fh->file, pos, pos + enc_len);
|
2010-02-03 09:42:11 +00:00
|
|
|
return Audio::makeFLACStream(tmp, DisposeAfterUse::YES);
|
2010-04-17 23:57:50 +00:00
|
|
|
}
|
2004-09-04 09:27:17 +00:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-28 14:50:44 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2005-10-23 10:49:34 +00:00
|
|
|
// Custom AudioStream class to handle Broken Sword 2's audio compression.
|
2004-08-28 14:50:44 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-02-05 21:39:29 +00:00
|
|
|
#define GetCompressedShift(n) (((n) >> 4) & 0x0F)
|
|
|
|
#define GetCompressedSign(n) ((n) & 0x08)
|
|
|
|
#define GetCompressedAmplitude(n) ((n) & 0x07)
|
2003-07-29 12:34:46 +00:00
|
|
|
|
2005-05-10 22:56:25 +00:00
|
|
|
CLUInputStream::CLUInputStream(Common::File *file, int size)
|
2004-09-04 09:27:17 +00:00
|
|
|
: _file(file), _firstTime(true), _bufferEnd(_outbuf + BUFFER_SIZE) {
|
2004-08-25 06:55:15 +00:00
|
|
|
|
|
|
|
// Determine the end position.
|
2004-10-12 06:24:46 +00:00
|
|
|
_file_pos = _file->pos();
|
|
|
|
_end_pos = _file_pos + size;
|
2004-08-25 06:55:15 +00:00
|
|
|
|
|
|
|
// Read in initial data
|
|
|
|
refill();
|
|
|
|
}
|
|
|
|
|
|
|
|
CLUInputStream::~CLUInputStream() {
|
|
|
|
}
|
|
|
|
|
|
|
|
int CLUInputStream::readBuffer(int16 *buffer, const int numSamples) {
|
|
|
|
int samples = 0;
|
|
|
|
while (samples < numSamples && !eosIntern()) {
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
const int len = MIN(numSamples - samples, (int)(_bufferEnd - _pos));
|
2004-08-25 06:55:15 +00:00
|
|
|
memcpy(buffer, _pos, len * 2);
|
|
|
|
buffer += len;
|
|
|
|
_pos += len;
|
|
|
|
samples += len;
|
|
|
|
if (_pos >= _bufferEnd) {
|
|
|
|
refill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLUInputStream::refill() {
|
|
|
|
byte *in = _inbuf;
|
|
|
|
int16 *out = _outbuf;
|
2004-09-04 09:27:17 +00:00
|
|
|
|
|
|
|
_file->seek(_file_pos, SEEK_SET);
|
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
uint len_left = _file->read(in, MIN((uint32)BUFFER_SIZE, _end_pos - _file->pos()));
|
2004-08-25 06:55:15 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
_file_pos = _file->pos();
|
|
|
|
|
2004-08-25 06:55:15 +00:00
|
|
|
while (len_left > 0) {
|
|
|
|
uint16 sample;
|
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
if (_firstTime) {
|
|
|
|
_firstTime = false;
|
|
|
|
_prev = READ_LE_UINT16(in);
|
|
|
|
sample = _prev;
|
|
|
|
len_left -= 2;
|
|
|
|
in += 2;
|
|
|
|
} else {
|
|
|
|
uint16 delta = GetCompressedAmplitude(*in) << GetCompressedShift(*in);
|
|
|
|
if (GetCompressedSign(*in))
|
|
|
|
sample = _prev - delta;
|
|
|
|
else
|
|
|
|
sample = _prev + delta;
|
|
|
|
|
|
|
|
_prev = sample;
|
|
|
|
len_left--;
|
|
|
|
in++;
|
|
|
|
}
|
2004-08-25 06:55:15 +00:00
|
|
|
|
2008-02-05 21:39:29 +00:00
|
|
|
*out++ = (int16)sample;
|
2004-08-25 06:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_pos = _outbuf;
|
|
|
|
_bufferEnd = out;
|
|
|
|
}
|
|
|
|
|
2006-04-29 22:33:31 +00:00
|
|
|
Audio::AudioStream *makeCLUStream(Common::File *file, int size) {
|
2004-08-25 06:55:15 +00:00
|
|
|
return new CLUInputStream(file, size);
|
|
|
|
}
|
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
Audio::AudioStream *makePSXCLUStream(Common::File *file, int size) {
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
// Buffer audio file data, and ask MemoryReadStream to dispose of it
|
|
|
|
// when not needed anymore.
|
|
|
|
|
|
|
|
byte *buffer = (byte *)malloc(size);
|
|
|
|
file->read(buffer, size);
|
2010-01-28 09:38:21 +00:00
|
|
|
return Audio::makeVagStream(new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES));
|
2009-04-07 19:52:46 +00:00
|
|
|
}
|
|
|
|
|
2004-08-28 14:50:44 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2004-09-04 09:27:17 +00:00
|
|
|
// Another custom AudioStream class, to wrap around the various AudioStream
|
|
|
|
// classes used for music decompression, and to add looping, fading, etc.
|
2004-08-28 14:50:44 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2004-01-03 11:24:39 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
// The length of a fade-in/out, in milliseconds.
|
|
|
|
#define FADE_LENGTH 3000
|
2004-01-03 11:24:39 +00:00
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
MusicInputStream::MusicInputStream(int cd, SoundFileHandle *fh, uint32 musicId, bool looping) {
|
2005-02-08 08:32:50 +00:00
|
|
|
_cd = cd;
|
2005-02-21 08:35:18 +00:00
|
|
|
_fh = fh;
|
2005-02-08 08:32:50 +00:00
|
|
|
_musicId = musicId;
|
|
|
|
_looping = looping;
|
|
|
|
|
|
|
|
_bufferEnd = _buffer + BUFFER_SIZE;
|
|
|
|
_remove = false;
|
|
|
|
_fading = 0;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
_decoder = getAudioStream(_fh, "music", _cd, _musicId, &_numSamples);
|
2004-09-04 09:27:17 +00:00
|
|
|
if (_decoder) {
|
|
|
|
_samplesLeft = _numSamples;
|
|
|
|
_fadeSamples = (getRate() * FADE_LENGTH) / 1000;
|
|
|
|
fadeUp();
|
2004-07-17 14:00:07 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
// Read in initial data
|
|
|
|
refill();
|
|
|
|
}
|
|
|
|
}
|
2004-07-17 14:00:07 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
MusicInputStream::~MusicInputStream() {
|
|
|
|
delete _decoder;
|
2007-03-18 09:33:42 +00:00
|
|
|
_decoder = NULL;
|
2004-09-04 23:05:34 +00:00
|
|
|
}
|
2004-07-17 14:00:07 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
int MusicInputStream::readBuffer(int16 *buffer, const int numSamples) {
|
|
|
|
if (!_decoder)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int samples = 0;
|
|
|
|
while (samples < numSamples && !eosIntern()) {
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
const int len = MIN(numSamples - samples, (int)(_bufferEnd - _pos));
|
2004-09-04 09:27:17 +00:00
|
|
|
memcpy(buffer, _pos, len * 2);
|
|
|
|
buffer += len;
|
|
|
|
_pos += len;
|
|
|
|
samples += len;
|
|
|
|
if (_pos >= _bufferEnd) {
|
|
|
|
refill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return samples;
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
void MusicInputStream::refill() {
|
|
|
|
int16 *buf = _buffer;
|
|
|
|
uint32 numSamples = 0;
|
|
|
|
uint32 len_left;
|
|
|
|
bool endFade = false;
|
2004-08-25 06:55:15 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
len_left = BUFFER_SIZE;
|
2004-08-22 14:28:11 +00:00
|
|
|
|
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.
To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.
If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.
If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.
Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.
On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.
Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.
svn-id: r19366
2005-10-29 21:24:54 +00:00
|
|
|
if (_fading > 0 && (uint32)_fading < len_left)
|
2004-09-04 09:27:17 +00:00
|
|
|
len_left = _fading;
|
2004-08-22 14:28:11 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
if (_samplesLeft < len_left)
|
|
|
|
len_left = _samplesLeft;
|
2004-08-28 14:50:44 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
if (!_looping) {
|
2005-10-17 06:31:10 +00:00
|
|
|
// Non-looping music is faded out at the end. If this fade
|
2004-09-04 09:27:17 +00:00
|
|
|
// out would have started somewhere within the len_left samples
|
|
|
|
// to read, we only read up to that point. This way, we can
|
|
|
|
// treat this fade as any other.
|
2004-08-22 14:28:11 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
if (!_fading) {
|
|
|
|
uint32 currentlyAt = _numSamples - _samplesLeft;
|
|
|
|
uint32 fadeOutAt = _numSamples - _fadeSamples;
|
|
|
|
uint32 readTo = currentlyAt + len_left;
|
|
|
|
|
|
|
|
if (fadeOutAt == currentlyAt)
|
|
|
|
fadeDown();
|
|
|
|
else if (fadeOutAt > currentlyAt && fadeOutAt <= readTo) {
|
|
|
|
len_left = fadeOutAt - currentlyAt;
|
|
|
|
endFade = true;
|
|
|
|
}
|
|
|
|
}
|
2004-08-22 14:28:11 +00:00
|
|
|
}
|
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
int desired = len_left - numSamples;
|
|
|
|
int len = _decoder->readBuffer(buf, desired);
|
2004-08-28 14:50:44 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
// Shouldn't happen, but if it does it could cause an infinite loop.
|
|
|
|
// Of course there were bugs that caused it to happen several times
|
|
|
|
// during development. :-)
|
2004-08-28 14:50:44 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
if (len < desired) {
|
2005-10-16 13:31:57 +00:00
|
|
|
warning("Expected %d samples, but got %d", desired, len);
|
|
|
|
_samplesLeft = len;
|
2004-09-04 09:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buf += len;
|
|
|
|
numSamples += len;
|
|
|
|
len_left -= len;
|
|
|
|
_samplesLeft -= len;
|
|
|
|
|
|
|
|
int16 *ptr;
|
|
|
|
|
|
|
|
if (_fading > 0) {
|
|
|
|
// Fade down
|
|
|
|
for (ptr = _buffer; ptr < buf; ptr++) {
|
2004-09-04 09:46:47 +00:00
|
|
|
if (_fading > 0) {
|
|
|
|
_fading--;
|
|
|
|
*ptr = (*ptr * _fading) / _fadeSamples;
|
|
|
|
}
|
|
|
|
if (_fading == 0) {
|
2004-09-04 09:27:17 +00:00
|
|
|
_looping = false;
|
|
|
|
_remove = true;
|
2004-09-04 09:46:47 +00:00
|
|
|
*ptr = 0;
|
2004-09-04 09:27:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (_fading < 0) {
|
|
|
|
// Fade up
|
|
|
|
for (ptr = _buffer; ptr < buf; ptr++) {
|
|
|
|
_fading--;
|
|
|
|
*ptr = -(*ptr * _fading) / _fadeSamples;
|
|
|
|
if (_fading <= -_fadeSamples) {
|
|
|
|
_fading = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endFade)
|
|
|
|
fadeDown();
|
|
|
|
|
|
|
|
if (!_samplesLeft) {
|
|
|
|
if (_looping) {
|
|
|
|
delete _decoder;
|
2005-02-21 08:35:18 +00:00
|
|
|
_decoder = getAudioStream(_fh, "music", _cd, _musicId, &_numSamples);
|
2004-09-04 09:27:17 +00:00
|
|
|
_samplesLeft = _numSamples;
|
|
|
|
} else
|
|
|
|
_remove = true;
|
|
|
|
}
|
2004-08-28 14:50:44 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
_pos = _buffer;
|
|
|
|
_bufferEnd = buf;
|
2004-08-22 14:28:11 +00:00
|
|
|
}
|
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
void MusicInputStream::fadeUp() {
|
|
|
|
if (_fading > 0)
|
|
|
|
_fading = -_fading;
|
|
|
|
else if (_fading == 0)
|
|
|
|
_fading = -1;
|
|
|
|
}
|
2004-08-25 06:55:15 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
void MusicInputStream::fadeDown() {
|
|
|
|
if (_fading < 0)
|
|
|
|
_fading = -_fading;
|
|
|
|
else if (_fading == 0)
|
|
|
|
_fading = _fadeSamples;
|
|
|
|
}
|
2004-08-25 06:55:15 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
bool MusicInputStream::readyToRemove() {
|
|
|
|
return _remove;
|
|
|
|
}
|
2004-08-25 06:55:15 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
int32 MusicInputStream::getTimeRemaining() {
|
|
|
|
// This is far from exact, but it doesn't have to be.
|
|
|
|
return (_samplesLeft + BUFFER_SIZE) / getRate();
|
|
|
|
}
|
2004-08-25 06:55:15 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Main sound class
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-08-25 06:55:15 +00:00
|
|
|
|
2004-10-12 17:03:07 +00:00
|
|
|
// AudioStream API
|
|
|
|
|
|
|
|
int Sound::readBuffer(int16 *buffer, const int numSamples) {
|
2004-01-03 11:24:39 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
2004-12-11 00:37:05 +00:00
|
|
|
int i;
|
2004-01-03 11:24:39 +00:00
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
if (_musicPaused)
|
2004-10-12 17:03:07 +00:00
|
|
|
return 0;
|
2004-01-03 11:24:39 +00:00
|
|
|
|
2004-12-11 00:37:05 +00:00
|
|
|
for (i = 0; i < MAXMUS; i++) {
|
2004-09-04 09:27:17 +00:00
|
|
|
if (_music[i] && _music[i]->readyToRemove()) {
|
|
|
|
delete _music[i];
|
|
|
|
_music[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-06-12 09:53:45 +00:00
|
|
|
|
2004-10-12 17:03:07 +00:00
|
|
|
memset(buffer, 0, 2 * numSamples);
|
|
|
|
|
|
|
|
if (!_mixBuffer || numSamples > _mixBufferLen) {
|
|
|
|
if (_mixBuffer)
|
2005-05-12 13:12:15 +00:00
|
|
|
_mixBuffer = (int16 *)realloc(_mixBuffer, 2 * numSamples);
|
2004-10-12 17:03:07 +00:00
|
|
|
else
|
2005-05-12 13:12:15 +00:00
|
|
|
_mixBuffer = (int16 *)malloc(2 * numSamples);
|
2004-10-12 17:03:07 +00:00
|
|
|
|
|
|
|
_mixBufferLen = numSamples;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_mixBuffer)
|
|
|
|
return 0;
|
|
|
|
|
2004-12-11 00:37:05 +00:00
|
|
|
for (i = 0; i < MAXMUS; i++) {
|
2004-10-12 17:03:07 +00:00
|
|
|
if (!_music[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int len = _music[i]->readBuffer(_mixBuffer, numSamples);
|
|
|
|
|
|
|
|
if (!_musicMuted) {
|
|
|
|
for (int j = 0; j < len; j++) {
|
2005-05-11 00:01:44 +00:00
|
|
|
Audio::clampedAdd(buffer[j], _mixBuffer[j]);
|
2004-09-04 09:27:17 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-12 09:53:45 +00:00
|
|
|
}
|
|
|
|
|
2005-02-08 08:32:50 +00:00
|
|
|
bool inUse[MAXMUS];
|
|
|
|
|
|
|
|
for (i = 0; i < MAXMUS; i++)
|
|
|
|
inUse[i] = false;
|
|
|
|
|
|
|
|
for (i = 0; i < MAXMUS; i++) {
|
|
|
|
if (_music[i]) {
|
2005-12-21 10:57:48 +00:00
|
|
|
if (_music[i]->getCD() == 1)
|
2005-02-08 08:32:50 +00:00
|
|
|
inUse[0] = true;
|
|
|
|
else
|
|
|
|
inUse[1] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAXMUS; i++) {
|
2005-12-11 08:30:48 +00:00
|
|
|
if (!inUse[i] && !_musicFile[i].inUse && _musicFile[i].file.isOpen())
|
|
|
|
_musicFile[i].file.close();
|
2005-02-08 08:32:50 +00:00
|
|
|
}
|
2004-10-12 17:03:07 +00:00
|
|
|
|
|
|
|
return numSamples;
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
|
|
|
|
2005-02-08 08:32:50 +00:00
|
|
|
bool Sound::endOfData() const {
|
2007-03-18 09:33:42 +00:00
|
|
|
// The music never stops. It just goes quiet.
|
|
|
|
return false;
|
2005-02-08 08:32:50 +00:00
|
|
|
}
|
2004-10-12 17:03:07 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MUSIC
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops the music dead in its tracks. Any music that is currently being
|
|
|
|
* streamed is paused.
|
|
|
|
*/
|
2003-09-04 10:58:55 +00:00
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
void Sound::pauseMusic() {
|
2004-01-03 11:24:39 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
2003-08-31 10:38:32 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
_musicPaused = true;
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
2003-09-16 07:11:29 +00:00
|
|
|
|
2003-09-27 17:00:15 +00:00
|
|
|
/**
|
2004-01-03 11:24:39 +00:00
|
|
|
* Restarts the music from where it was stopped.
|
2003-09-27 17:00:15 +00:00
|
|
|
*/
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
void Sound::unpauseMusic() {
|
2004-01-03 11:24:39 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
2003-11-01 18:12:04 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
_musicPaused = false;
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
2003-11-01 18:12:04 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
/**
|
|
|
|
* Fades out and stops the music.
|
|
|
|
*/
|
2003-11-01 18:12:04 +00:00
|
|
|
|
2005-02-08 08:32:50 +00:00
|
|
|
void Sound::stopMusic(bool immediately) {
|
2004-01-03 11:24:39 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
_loopingMusicId = 0;
|
|
|
|
|
2005-02-08 08:32:50 +00:00
|
|
|
for (int i = 0; i < MAXMUS; i++) {
|
|
|
|
if (_music[i]) {
|
|
|
|
if (immediately) {
|
|
|
|
delete _music[i];
|
|
|
|
_music[i] = NULL;
|
|
|
|
} else
|
|
|
|
_music[i]->fadeDown();
|
|
|
|
}
|
|
|
|
}
|
2003-09-27 16:10:43 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
/**
|
|
|
|
* Streams music from a cluster file.
|
|
|
|
* @param musicId the id of the music to stream
|
2005-05-05 15:59:24 +00:00
|
|
|
* @param loop true if the music is to loop back to the start
|
2004-01-03 11:24:39 +00:00
|
|
|
* @return RD_OK or an error code
|
|
|
|
*/
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
int32 Sound::streamCompMusic(uint32 musicId, bool loop) {
|
2009-02-20 22:47:05 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2005-12-21 10:57:48 +00:00
|
|
|
int cd = _vm->_resman->getCD();
|
2005-02-07 10:51:48 +00:00
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
if (loop)
|
|
|
|
_loopingMusicId = musicId;
|
|
|
|
else
|
|
|
|
_loopingMusicId = 0;
|
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
int primary = -1;
|
|
|
|
int secondary = -1;
|
|
|
|
|
|
|
|
// If both music streams are active, one of them will have to go.
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
if (_music[0] && _music[1]) {
|
|
|
|
int32 fade0 = _music[0]->isFading();
|
|
|
|
int32 fade1 = _music[1]->isFading();
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
if (!fade0 && !fade1) {
|
|
|
|
// Neither is fading. This shouldn't happen, so just
|
|
|
|
// pick one and be done with it.
|
|
|
|
primary = 0;
|
|
|
|
} else if (fade0 && !fade1) {
|
2004-01-14 08:06:56 +00:00
|
|
|
// Stream 0 is fading, so pick that one.
|
2004-09-04 09:27:17 +00:00
|
|
|
primary = 0;
|
|
|
|
} else if (!fade0 && fade1) {
|
2004-01-14 08:06:56 +00:00
|
|
|
// Stream 1 is fading, so pick that one.
|
2004-09-04 09:27:17 +00:00
|
|
|
primary = 1;
|
2004-01-14 08:06:56 +00:00
|
|
|
} else {
|
|
|
|
// Both streams are fading. Pick the one that is
|
|
|
|
// closest to silent.
|
2004-09-04 09:27:17 +00:00
|
|
|
if (ABS(fade0) < ABS(fade1))
|
|
|
|
primary = 0;
|
2004-01-14 08:06:56 +00:00
|
|
|
else
|
2004-09-04 09:27:17 +00:00
|
|
|
primary = 1;
|
2004-01-14 08:06:56 +00:00
|
|
|
}
|
2003-09-03 18:59:02 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
delete _music[primary];
|
|
|
|
_music[primary] = NULL;
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
// Pick the available music stream. If no music is playing it doesn't
|
2004-09-04 09:27:17 +00:00
|
|
|
// matter which we use.
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
if (_music[0] || _music[1]) {
|
|
|
|
if (_music[0]) {
|
|
|
|
primary = 1;
|
|
|
|
secondary = 0;
|
2004-01-03 11:24:39 +00:00
|
|
|
} else {
|
2004-09-04 09:27:17 +00:00
|
|
|
primary = 0;
|
|
|
|
secondary = 1;
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
|
|
|
} else
|
2004-09-04 09:27:17 +00:00
|
|
|
primary = 0;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
// Don't start streaming if the volume is off.
|
2005-02-21 08:35:18 +00:00
|
|
|
if (isMusicMute()) {
|
2004-01-03 11:24:39 +00:00
|
|
|
return RD_OK;
|
2005-02-21 08:35:18 +00:00
|
|
|
}
|
2003-09-27 17:00:15 +00:00
|
|
|
|
2004-09-04 09:27:17 +00:00
|
|
|
if (secondary != -1)
|
|
|
|
_music[secondary]->fadeDown();
|
2005-02-21 08:35:18 +00:00
|
|
|
SoundFileHandle *fh = (cd == 1) ? &_musicFile[0] : &_musicFile[1];
|
|
|
|
fh->inUse = true;
|
2003-09-16 07:11:29 +00:00
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
MusicInputStream *tmp = new MusicInputStream(cd, fh, musicId, loop);
|
2005-02-08 08:32:50 +00:00
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
if (tmp->isReady()) {
|
|
|
|
_music[primary] = tmp;
|
|
|
|
fh->inUse = false;
|
|
|
|
return RD_OK;
|
|
|
|
} else {
|
|
|
|
fh->inUse = false;
|
|
|
|
delete tmp;
|
2004-08-27 08:31:33 +00:00
|
|
|
return RDERR_INVALIDFILENAME;
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the time left for the current music, in seconds.
|
|
|
|
*/
|
|
|
|
|
2005-05-02 05:41:01 +00:00
|
|
|
int32 Sound::musicTimeRemaining() {
|
2004-01-03 11:24:39 +00:00
|
|
|
Common::StackLock lock(_mutex);
|
|
|
|
|
|
|
|
for (int i = 0; i < MAXMUS; i++) {
|
2004-09-04 09:27:17 +00:00
|
|
|
if (_music[i] && _music[i]->isFading() <= 0)
|
|
|
|
return _music[i]->getTimeRemaining();
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// SPEECH
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mutes/Unmutes the speech.
|
|
|
|
* @param mute If mute is false, restore the volume to the last set master
|
|
|
|
* level. Otherwise the speech is muted (volume 0).
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Sound::muteSpeech(bool mute) {
|
|
|
|
_speechMuted = mute;
|
|
|
|
|
2005-03-12 18:56:09 +00:00
|
|
|
if (_vm->_mixer->isSoundHandleActive(_soundHandleSpeech)) {
|
2005-05-10 23:48:48 +00:00
|
|
|
uint volume = mute ? 0 : Audio::Mixer::kMaxChannelVolume;
|
2004-01-03 11:24:39 +00:00
|
|
|
|
|
|
|
_vm->_mixer->setChannelVolume(_soundHandleSpeech, volume);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops the speech dead in its tracks.
|
|
|
|
*/
|
|
|
|
|
2005-05-02 05:41:01 +00:00
|
|
|
void Sound::pauseSpeech() {
|
2007-07-21 14:39:12 +00:00
|
|
|
if (!_speechPaused) {
|
|
|
|
_speechPaused = true;
|
|
|
|
_vm->_mixer->pauseHandle(_soundHandleSpeech, true);
|
|
|
|
}
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restarts the speech from where it was stopped.
|
|
|
|
*/
|
|
|
|
|
2005-05-02 05:41:01 +00:00
|
|
|
void Sound::unpauseSpeech() {
|
2007-07-21 14:39:12 +00:00
|
|
|
if (_speechPaused) {
|
|
|
|
_speechPaused = false;
|
|
|
|
_vm->_mixer->pauseHandle(_soundHandleSpeech, false);
|
|
|
|
}
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops the speech from playing.
|
|
|
|
*/
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
int32 Sound::stopSpeech() {
|
2005-03-12 18:56:09 +00:00
|
|
|
if (_vm->_mixer->isSoundHandleActive(_soundHandleSpeech)) {
|
2004-01-03 11:24:39 +00:00
|
|
|
_vm->_mixer->stopHandle(_soundHandleSpeech);
|
|
|
|
return RD_OK;
|
|
|
|
}
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
return RDERR_SPEECHNOTPLAYING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Either RDSE_SAMPLEPLAYING or RDSE_SAMPLEFINISHED
|
|
|
|
*/
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
int32 Sound::getSpeechStatus() {
|
2005-03-12 18:56:09 +00:00
|
|
|
return _vm->_mixer->isSoundHandleActive(_soundHandleSpeech) ? RDSE_SAMPLEPLAYING : RDSE_SAMPLEFINISHED;
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns either RDSE_QUIET or RDSE_SPEAKING
|
|
|
|
*/
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
int32 Sound::amISpeaking() {
|
2005-03-12 18:56:09 +00:00
|
|
|
if (!_speechMuted && !_speechPaused && _vm->_mixer->isSoundHandleActive(_soundHandleSpeech))
|
2004-01-03 11:24:39 +00:00
|
|
|
return RDSE_SPEAKING;
|
|
|
|
|
|
|
|
return RDSE_QUIET;
|
|
|
|
}
|
|
|
|
|
2003-09-27 17:00:15 +00:00
|
|
|
/**
|
|
|
|
* This function loads, decompresses and plays a line of speech. An error
|
|
|
|
* occurs if speech is already playing.
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
* @param speechId the text line id used to reference the speech
|
2003-09-27 17:00:15 +00:00
|
|
|
* @param vol volume, 0 (minimum) to 16 (maximum)
|
|
|
|
* @param pan panning, -16 (full left) to 16 (full right)
|
|
|
|
*/
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
int32 Sound::playCompSpeech(uint32 speechId, uint8 vol, int8 pan) {
|
2004-01-03 11:24:39 +00:00
|
|
|
if (_speechMuted)
|
|
|
|
return RD_OK;
|
|
|
|
|
|
|
|
if (getSpeechStatus() == RDERR_SPEECHPLAYING)
|
|
|
|
return RDERR_SPEECHPLAYING;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2005-12-21 10:57:48 +00:00
|
|
|
int cd = _vm->_resman->getCD();
|
2005-02-21 08:35:18 +00:00
|
|
|
SoundFileHandle *fh = (cd == 1) ? &_speechFile[0] : &_speechFile[1];
|
2003-09-16 07:11:29 +00:00
|
|
|
|
2006-04-29 22:33:31 +00:00
|
|
|
Audio::AudioStream *input = getAudioStream(fh, "speech", cd, speechId, NULL);
|
2004-08-25 06:55:15 +00:00
|
|
|
|
|
|
|
if (!input)
|
|
|
|
return RDERR_INVALIDID;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
// Modify the volume according to the master volume
|
2003-09-21 14:26:25 +00:00
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
byte volume = _speechMuted ? 0 : vol * Audio::Mixer::kMaxChannelVolume / 16;
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
int8 p = (pan * 127) / 16;
|
|
|
|
|
|
|
|
if (isReverseStereo())
|
|
|
|
p = -p;
|
2003-08-30 18:06:08 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
// Start the speech playing
|
2010-04-12 09:14:17 +00:00
|
|
|
_vm->_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_soundHandleSpeech, input, -1, volume, p);
|
2003-09-16 07:11:29 +00:00
|
|
|
return RD_OK;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// SOUND EFFECTS
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2003-09-27 17:00:15 +00:00
|
|
|
/**
|
2004-01-03 11:24:39 +00:00
|
|
|
* Mutes/Unmutes the sound effects.
|
|
|
|
* @param mute If mute is false, restore the volume to the last set master
|
|
|
|
* level. Otherwise the sound effects are muted (volume 0).
|
2003-09-27 17:00:15 +00:00
|
|
|
*/
|
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
void Sound::muteFx(bool mute) {
|
|
|
|
_fxMuted = mute;
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
// Now update the volume of any fxs playing
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
for (int i = 0; i < FXQ_LENGTH; i++) {
|
|
|
|
if (_fxQueue[i].resource) {
|
|
|
|
_vm->_mixer->setChannelVolume(_fxQueue[i].handle, mute ? 0 : _fxQueue[i].volume);
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-27 17:00:15 +00:00
|
|
|
/**
|
|
|
|
* Sets the volume and pan of the sample which is currently playing
|
|
|
|
* @param id the id of the sample
|
|
|
|
* @param vol volume
|
|
|
|
* @param pan panning
|
|
|
|
*/
|
|
|
|
|
2005-05-05 15:59:24 +00:00
|
|
|
int32 Sound::setFxIdVolumePan(int32 id, int vol, int pan) {
|
|
|
|
if (!_fxQueue[id].resource)
|
2003-07-28 01:47:41 +00:00
|
|
|
return RDERR_FXNOTOPEN;
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
if (vol > 16)
|
|
|
|
vol = 16;
|
2004-01-03 11:24:39 +00:00
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
_fxQueue[id].volume = (vol * Audio::Mixer::kMaxChannelVolume) / 16;
|
2003-09-21 14:26:25 +00:00
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
if (pan != 255) {
|
|
|
|
if (isReverseStereo())
|
|
|
|
pan = -pan;
|
2005-05-05 15:59:24 +00:00
|
|
|
_fxQueue[id].pan = (pan * 127) / 16;
|
2005-02-19 14:02:16 +00:00
|
|
|
}
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2005-05-05 15:59:24 +00:00
|
|
|
if (!_fxMuted && _vm->_mixer->isSoundHandleActive(_fxQueue[id].handle)) {
|
|
|
|
_vm->_mixer->setChannelVolume(_fxQueue[id].handle, _fxQueue[id].volume);
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
if (pan != -1)
|
2005-05-05 15:59:24 +00:00
|
|
|
_vm->_mixer->setChannelBalance(_fxQueue[id].handle, _fxQueue[id].pan);
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
return RD_OK;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
void Sound::pauseFx() {
|
2007-07-21 14:39:12 +00:00
|
|
|
if (!_fxPaused) {
|
|
|
|
for (int i = 0; i < FXQ_LENGTH; i++) {
|
|
|
|
if (_fxQueue[i].resource)
|
|
|
|
_vm->_mixer->pauseHandle(_fxQueue[i].handle, true);
|
|
|
|
}
|
|
|
|
_fxPaused = true;
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Began what I hope is the final major restructuring of the BS2 engine.
In this first step, I have moved all opcode functions into functions.cpp,
instead of having them scattered all over the place.
To get things to compile again, I had to rewrite the overly complicated
sound effects handling. It's much simpler now.
The next step will be to move any non-trivial code out of the opcode
functions and into the appropriate object. This, I hope, will make it
easier to create well-separated objects, instead of the current mess.
I also want to tear down the artificial boundary between the main directory
and the "driver" directory. We already have a cross-platform layer; there's
no need to have yet another one. (Actually, the rewriting of the sound
effects code took one first step in this direction.)
At the final stage, I'd like to get rid of the "drivers" directory
completely, but I'll probably need some help with that if I want to
preserve the CVS history of the code.
Things will probably be a bit bumpy along the way, but I seem to have
reached a point of relative stability again, which is why I'm commiting
this now.
svn-id: r16668
2005-01-28 16:33:14 +00:00
|
|
|
void Sound::unpauseFx() {
|
2007-07-21 14:39:12 +00:00
|
|
|
if (_fxPaused) {
|
|
|
|
for (int i = 0; i < FXQ_LENGTH; i++)
|
|
|
|
if (_fxQueue[i].resource)
|
|
|
|
_vm->_mixer->pauseHandle(_fxQueue[i].handle, false);
|
|
|
|
_fxPaused = false;
|
|
|
|
}
|
2003-07-28 01:47:41 +00:00
|
|
|
}
|
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
} // End of namespace Sword2
|