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:44:38 +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:44:38 +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:44:38 +00:00
|
|
|
*/
|
|
|
|
|
2003-09-20 12:43:52 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2003-07-28 01:44:38 +00:00
|
|
|
// BROKEN SWORD 2
|
|
|
|
//
|
2003-09-20 12:43:52 +00:00
|
|
|
// SOUND.CPP Contains the sound engine, fx & music functions
|
|
|
|
// Some very 'sound' code in here ;)
|
2003-07-28 01:44:38 +00:00
|
|
|
//
|
|
|
|
// (16Dec96 JEL)
|
|
|
|
//
|
2003-09-20 12:43:52 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "common/file.h"
|
2010-11-19 17:03:07 +00:00
|
|
|
#include "common/memstream.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 "common/system.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.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
|
|
|
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/sword2.h"
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "sword2/defs.h"
|
2006-02-17 15:07:36 +00:00
|
|
|
#include "sword2/header.h"
|
2010-04-01 16:11:29 +00:00
|
|
|
#include "sword2/console.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/logic.h"
|
|
|
|
#include "sword2/resman.h"
|
2004-11-14 15:00:01 +00:00
|
|
|
#include "sword2/sound.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
|
|
|
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/decoders/wave.h"
|
2011-08-24 13:38:46 +00:00
|
|
|
#include "audio/decoders/xa.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2010-04-01 16:11:29 +00:00
|
|
|
#define Debug_Printf _vm->_debugger->DebugPrintf
|
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
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
|
|
|
Sound::Sound(Sword2Engine *vm) {
|
|
|
|
int i;
|
2004-05-01 10:42:23 +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
|
|
|
_vm = vm;
|
2004-05-01 10:42:23 +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
|
|
|
for (i = 0; i < FXQ_LENGTH; i++)
|
|
|
|
_fxQueue[i].resource = 0;
|
2004-05-01 10:42:23 +00:00
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
for (i = 0; i < MAXMUS; i++) {
|
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
|
|
|
_music[i] = NULL;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-02-21 08:35:18 +00:00
|
|
|
_musicFile[i].idxTab = NULL;
|
|
|
|
_musicFile[i].idxLen = 0;
|
|
|
|
_musicFile[i].fileSize = 0;
|
|
|
|
_musicFile[i].fileType = 0;
|
|
|
|
_musicFile[i].inUse = false;
|
|
|
|
|
|
|
|
_speechFile[i].idxTab = NULL;
|
|
|
|
_speechFile[i].idxLen = 0;
|
|
|
|
_speechFile[i].fileSize = 0;
|
|
|
|
_speechFile[i].fileType = 0;
|
|
|
|
_speechFile[i].inUse = false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
_speechPaused = false;
|
|
|
|
_musicPaused = false;
|
|
|
|
_fxPaused = false;
|
|
|
|
|
|
|
|
_speechMuted = false;
|
|
|
|
_musicMuted = false;
|
|
|
|
_fxMuted = false;
|
|
|
|
|
2005-03-03 08:34:01 +00:00
|
|
|
_reverseStereo = false;
|
|
|
|
|
2005-11-03 07:28:21 +00:00
|
|
|
_loopingMusicId = 0;
|
|
|
|
|
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
|
|
|
_mixBuffer = NULL;
|
|
|
|
_mixBufferLen = 0;
|
|
|
|
|
2010-04-12 09:14:17 +00:00
|
|
|
_vm->_mixer->playStream(Audio::Mixer::kMusicSoundType, &_mixerSoundHandle, this, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, true);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
Sound::~Sound() {
|
2007-02-20 18:50:17 +00:00
|
|
|
_vm->_mixer->stopHandle(_mixerSoundHandle);
|
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
|
|
|
|
2007-01-26 18:21:41 +00:00
|
|
|
clearFxQueue(true);
|
2005-02-08 08:32:50 +00:00
|
|
|
stopMusic(true);
|
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
|
|
|
stopSpeech();
|
|
|
|
|
|
|
|
free(_mixBuffer);
|
2005-02-08 08:32:50 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < MAXMUS; i++) {
|
2005-12-11 08:30:48 +00:00
|
|
|
if (_musicFile[i].file.isOpen())
|
|
|
|
_musicFile[i].file.close();
|
|
|
|
if (_speechFile[i].file.isOpen())
|
|
|
|
_speechFile[i].file.close();
|
|
|
|
|
|
|
|
free(_musicFile[i].idxTab);
|
|
|
|
free(_speechFile[i].idxTab);
|
2005-02-08 08:32:50 +00:00
|
|
|
}
|
2004-05-01 10:42:23 +00:00
|
|
|
}
|
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
void Sound::setReverseStereo(bool reverse) {
|
|
|
|
if (reverse != _reverseStereo) {
|
|
|
|
_reverseStereo = reverse;
|
|
|
|
|
|
|
|
for (int i = 0; i < FXQ_LENGTH; i++) {
|
|
|
|
if (!_fxQueue[i].resource)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
_fxQueue[i].pan = -_fxQueue[i].pan;
|
|
|
|
_vm->_mixer->setChannelBalance(_fxQueue[i].handle, _fxQueue[i].pan);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-01 10:42:23 +00:00
|
|
|
/**
|
2007-01-26 18:21:41 +00:00
|
|
|
* Stop all sounds, close their resources and clear the FX queue. This is used
|
|
|
|
* when going from one room to another, among other things.
|
2004-05-01 10:42:23 +00:00
|
|
|
*/
|
|
|
|
|
2007-01-26 18:21:41 +00:00
|
|
|
void Sound::clearFxQueue(bool killMovieSounds) {
|
2004-05-01 10:42:23 +00:00
|
|
|
for (int i = 0; i < FXQ_LENGTH; i++) {
|
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 (_fxQueue[i].resource) {
|
|
|
|
stopFx(i);
|
2004-05-01 10:42:23 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-26 18:21:41 +00:00
|
|
|
|
|
|
|
// We aren't just going to change rooms or anything like that, we are
|
|
|
|
// killing off resources (e.g. when restoring or restarting). We need
|
|
|
|
// to also kill any movie lead-in/out sounds.
|
|
|
|
|
|
|
|
if (killMovieSounds) {
|
|
|
|
_vm->_mixer->stopHandle(_leadInHandle);
|
|
|
|
_vm->_mixer->stopHandle(_leadOutHandle);
|
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-04-28 11:47:19 +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
|
|
|
* Process the FX queue. This function is called once every game cycle.
|
2004-04-28 11:47:19 +00:00
|
|
|
*/
|
2003-07-28 01:44:38 +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::processFxQueue() {
|
2003-11-03 07:47:42 +00:00
|
|
|
for (int i = 0; i < FXQ_LENGTH; i++) {
|
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 (!_fxQueue[i].resource)
|
2003-09-20 12:43:52 +00:00
|
|
|
continue;
|
2003-07-28 01:44:38 +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
|
|
|
switch (_fxQueue[i].type) {
|
2003-09-21 16:11:26 +00:00
|
|
|
case FX_RANDOM:
|
|
|
|
// 1 in 'delay' chance of this fx occurring
|
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 (_vm->_rnd.getRandomNumber(_fxQueue[i].delay) == 0)
|
|
|
|
playFx(&_fxQueue[i]);
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
case FX_SPOT:
|
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 (_fxQueue[i].delay)
|
|
|
|
_fxQueue[i].delay--;
|
2003-09-21 16:11:26 +00:00
|
|
|
else {
|
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
|
|
|
playFx(&_fxQueue[i]);
|
|
|
|
_fxQueue[i].type = FX_SPOT2;
|
2003-09-21 16:11:26 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-05-01 10:42:23 +00:00
|
|
|
case FX_LOOP:
|
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
|
|
|
playFx(&_fxQueue[i]);
|
|
|
|
_fxQueue[i].type = FX_LOOPING;
|
2004-05-01 10:42:23 +00:00
|
|
|
break;
|
2003-09-21 16:11:26 +00:00
|
|
|
case FX_SPOT2:
|
2004-05-01 10:42:23 +00:00
|
|
|
// Once the FX has finished remove it from the queue.
|
2005-03-12 18:56:09 +00:00
|
|
|
if (!_vm->_mixer->isSoundHandleActive(_fxQueue[i].handle)) {
|
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
|
|
|
_vm->_resman->closeResource(_fxQueue[i].resource);
|
|
|
|
_fxQueue[i].resource = 0;
|
2004-01-03 11:24:39 +00:00
|
|
|
}
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
2004-05-01 10:42:23 +00:00
|
|
|
case FX_LOOPING:
|
|
|
|
// Once the looped FX has started we can ignore it,
|
|
|
|
// but we can't close it since the WAV data is in use.
|
|
|
|
break;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-26 18:21:41 +00:00
|
|
|
/**
|
|
|
|
* This function is used by the cutscene player to play the movie lead-in/out.
|
|
|
|
* @param res The sound resource to play
|
|
|
|
* @param type Either kLeadInSound or kLeadOutSound
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Sound::playMovieSound(int32 res, int type) {
|
|
|
|
Audio::SoundHandle *handle;
|
|
|
|
|
|
|
|
if (type == kLeadInSound)
|
|
|
|
handle = &_leadInHandle;
|
|
|
|
else
|
|
|
|
handle = &_leadOutHandle;
|
|
|
|
|
|
|
|
if (_vm->_mixer->isSoundHandleActive(*handle)) {
|
|
|
|
_vm->_mixer->stopHandle(*handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *data = _vm->_resman->openResource(res);
|
2009-04-07 19:52:46 +00:00
|
|
|
uint32 len = _vm->_resman->fetchLen(res);
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2007-01-26 18:21:41 +00:00
|
|
|
assert(_vm->_resman->fetchType(data) == WAV_FILE);
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2010-05-15 08:38:19 +00:00
|
|
|
// We want to close the resource right away, so to be safe we make a
|
|
|
|
// private copy of the sound;
|
|
|
|
byte *soundData = (byte *)malloc(len);
|
|
|
|
|
|
|
|
if (soundData) {
|
|
|
|
memcpy(soundData, data, len);
|
|
|
|
|
|
|
|
Common::MemoryReadStream *stream = new Common::MemoryReadStream(soundData, len, DisposeAfterUse::YES);
|
|
|
|
|
|
|
|
// In PSX version we have nothing to skip here, as data starts
|
|
|
|
// right away.
|
|
|
|
if (!Sword2Engine::isPsx()) {
|
|
|
|
stream->seek(ResHeader::size());
|
|
|
|
}
|
|
|
|
|
|
|
|
Audio::RewindableAudioStream *input = 0;
|
|
|
|
|
|
|
|
if (Sword2Engine::isPsx()) {
|
2011-08-24 13:47:24 +00:00
|
|
|
input = Audio::makeXAStream(stream, 11025);
|
2010-05-15 08:38:19 +00:00
|
|
|
} else {
|
|
|
|
input = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
|
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_mixer->playStream(
|
|
|
|
Audio::Mixer::kMusicSoundType, handle, input,
|
|
|
|
-1, Audio::Mixer::kMaxChannelVolume, 0,
|
|
|
|
DisposeAfterUse::YES, false, isReverseStereo());
|
|
|
|
} else {
|
|
|
|
warning("Sound::playMovieSound: Could not allocate %d bytes\n", len);
|
2009-04-07 19:52:46 +00:00
|
|
|
}
|
2007-01-26 18:21:41 +00:00
|
|
|
|
2010-05-15 08:38:19 +00:00
|
|
|
_vm->_resman->closeResource(res);
|
2007-01-26 18:21:41 +00:00
|
|
|
}
|
|
|
|
|
2009-02-21 15:07:05 +00:00
|
|
|
void Sound::stopMovieSounds() {
|
|
|
|
if (_vm->_mixer->isSoundHandleActive(_leadInHandle)) {
|
|
|
|
_vm->_mixer->stopHandle(_leadInHandle);
|
|
|
|
}
|
|
|
|
if (_vm->_mixer->isSoundHandleActive(_leadOutHandle)) {
|
|
|
|
_vm->_mixer->stopHandle(_leadOutHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Queue a sound effect for playing later.
|
|
|
|
* @param res the sound resource number
|
|
|
|
* @param type the type of sound effect
|
|
|
|
* @param delay when to play the sound effect
|
|
|
|
* @param volume the sound effect volume (0 through 16)
|
|
|
|
* @param pan the sound effect panning (-16 through 16)
|
|
|
|
*/
|
2003-09-20 12:43:52 +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::queueFx(int32 res, int32 type, int32 delay, int32 volume, int32 pan) {
|
2003-11-08 15:47:51 +00:00
|
|
|
if (_vm->_wantSfxDebug) {
|
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
|
|
|
const char *typeStr;
|
2003-10-26 15:42:49 +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
|
|
|
switch (type) {
|
2003-09-21 16:11:26 +00:00
|
|
|
case FX_SPOT:
|
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
|
|
|
typeStr = "SPOT";
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
case FX_LOOP:
|
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
|
|
|
typeStr = "LOOPED";
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
case FX_RANDOM:
|
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
|
|
|
typeStr = "RANDOM";
|
2003-09-21 16:11:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
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
|
|
|
typeStr = "INVALID";
|
2004-01-03 11:24:39 +00:00
|
|
|
break;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2006-07-08 20:45:01 +00:00
|
|
|
debug(0, "SFX (sample=\"%s\", vol=%d, pan=%d, delay=%d, type=%s)", _vm->_resman->fetchName(res), volume, pan, delay, typeStr);
|
2004-05-01 10:42:23 +00:00
|
|
|
}
|
2003-07-28 01:44:38 +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
|
|
|
for (int i = 0; i < FXQ_LENGTH; i++) {
|
|
|
|
if (!_fxQueue[i].resource) {
|
|
|
|
byte *data = _vm->_resman->openResource(res);
|
2003-09-20 12:43:52 +00:00
|
|
|
|
2009-04-18 08:37:22 +00:00
|
|
|
// Check that we really have a WAV file here, alas this
|
|
|
|
// check is useless with psx demo game, because psx audio files
|
|
|
|
// are headerless and there is no way to check the type
|
|
|
|
if (!(Sword2Engine::isPsx() && (_vm->_features & GF_DEMO)))
|
|
|
|
assert(_vm->_resman->fetchType(data) == WAV_FILE);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
uint32 len = _vm->_resman->fetchLen(res);
|
|
|
|
|
|
|
|
// Skip the header if using PC version
|
|
|
|
if (!Sword2Engine::isPsx())
|
|
|
|
len -= ResHeader::size();
|
2003-07-28 01:44:38 +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 (type == FX_RANDOM) {
|
|
|
|
// For spot effects and loops the delay is the
|
|
|
|
// number of frames to wait. For random
|
|
|
|
// effects, however, it's the average number of
|
|
|
|
// seconds between playing the sound, so we
|
|
|
|
// have to multiply by the frame rate.
|
2007-01-03 07:56:24 +00:00
|
|
|
delay *= FRAMES_PER_SECOND;
|
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
|
|
|
}
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
volume = (volume * 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
|
|
|
pan = (pan * 127) / 16;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-02-19 14:02:16 +00:00
|
|
|
if (isReverseStereo())
|
|
|
|
pan = -pan;
|
|
|
|
|
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
|
|
|
_fxQueue[i].resource = res;
|
2009-04-07 19:52:46 +00:00
|
|
|
|
|
|
|
if (Sword2Engine::isPsx())
|
|
|
|
_fxQueue[i].data = data;
|
|
|
|
else
|
|
|
|
_fxQueue[i].data = data + ResHeader::size();
|
2009-05-24 15:17:42 +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
|
|
|
_fxQueue[i].len = len;
|
|
|
|
_fxQueue[i].delay = delay;
|
|
|
|
_fxQueue[i].volume = volume;
|
|
|
|
_fxQueue[i].pan = pan;
|
|
|
|
_fxQueue[i].type = type;
|
2003-07-28 01:44:38 +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
|
|
|
// Keep track of the index in the loop so that
|
|
|
|
// fnStopFx() can be used later to kill this sound.
|
|
|
|
// Mainly for FX_LOOP and FX_RANDOM.
|
2003-07-28 01:44:38 +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
|
|
|
_vm->_logic->writeVar(RESULT, i);
|
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;
|
|
|
|
}
|
|
|
|
}
|
2003-09-20 12:43:52 +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
|
|
|
warning("No free slot in FX queue");
|
2003-07-28 01:44:38 +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
|
|
|
int32 Sound::playFx(FxQueueEntry *fx) {
|
2005-05-10 23:48:48 +00:00
|
|
|
return playFx(&fx->handle, fx->data, fx->len, fx->volume, fx->pan, (fx->type == FX_LOOP), Audio::Mixer::kSFXSoundType);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-20 12:43:52 +00:00
|
|
|
|
2005-05-11 00:01:44 +00:00
|
|
|
int32 Sound::playFx(Audio::SoundHandle *handle, byte *data, uint32 len, uint8 vol, int8 pan, bool loop, Audio::Mixer::SoundType soundType) {
|
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 (_fxMuted)
|
|
|
|
return RD_OK;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2005-03-12 18:56:09 +00:00
|
|
|
if (_vm->_mixer->isSoundHandleActive(*handle))
|
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 RDERR_FXALREADYOPEN;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2009-04-07 19:52:46 +00:00
|
|
|
Common::MemoryReadStream *stream = new Common::MemoryReadStream(data, len);
|
2010-01-07 17:04:01 +00:00
|
|
|
Audio::RewindableAudioStream *input = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2010-01-07 17:04:01 +00:00
|
|
|
if (Sword2Engine::isPsx())
|
2011-08-24 13:47:24 +00:00
|
|
|
input = Audio::makeXAStream(stream, 11025);
|
2010-01-07 17:04:01 +00:00
|
|
|
else
|
2010-01-16 21:36:08 +00:00
|
|
|
input = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
|
2003-10-18 08:11:50 +00:00
|
|
|
|
2009-10-14 23:28:23 +00:00
|
|
|
assert(input);
|
2009-04-07 19:52:46 +00:00
|
|
|
|
2010-04-12 09:14:17 +00:00
|
|
|
_vm->_mixer->playStream(soundType, handle,
|
2010-01-08 16:27:29 +00:00
|
|
|
Audio::makeLoopingAudioStream(input, loop ? 0 : 1),
|
2010-01-08 22:09:43 +00:00
|
|
|
-1, vol, pan, DisposeAfterUse::YES, false, isReverseStereo());
|
2003-07-28 01:44:38 +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:44:38 +00:00
|
|
|
}
|
|
|
|
|
2004-04-28 11:47:19 +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
|
|
|
* This function closes a sound effect which has been previously opened for
|
|
|
|
* playing. Sound effects must be closed when they are finished with, otherwise
|
|
|
|
* you will run out of sound effect buffers.
|
|
|
|
* @param i the index of the sound to close
|
2004-04-28 11:47:19 +00:00
|
|
|
*/
|
2003-07-28 01:44:38 +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
|
|
|
int32 Sound::stopFx(int32 i) {
|
|
|
|
if (!_fxQueue[i].resource)
|
|
|
|
return RDERR_FXNOTOPEN;
|
2003-09-20 12:43:52 +00:00
|
|
|
|
2005-03-12 18:56:09 +00:00
|
|
|
_vm->_mixer->stopHandle(_fxQueue[i].handle);
|
2003-07-28 01:44:38 +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
|
|
|
_vm->_resman->closeResource(_fxQueue[i].resource);
|
|
|
|
_fxQueue[i].resource = 0;
|
|
|
|
return RD_OK;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2010-04-01 16:11:29 +00:00
|
|
|
void Sound::printFxQueue() {
|
|
|
|
int freeSlots = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < FXQ_LENGTH; i++) {
|
|
|
|
if (_fxQueue[i].resource) {
|
|
|
|
const char *type;
|
|
|
|
|
|
|
|
switch (_fxQueue[i].type) {
|
|
|
|
case FX_SPOT:
|
|
|
|
type = "SPOT";
|
|
|
|
break;
|
|
|
|
case FX_LOOP:
|
|
|
|
type = "LOOP";
|
|
|
|
break;
|
|
|
|
case FX_RANDOM:
|
|
|
|
type = "RANDOM";
|
|
|
|
break;
|
|
|
|
case FX_SPOT2:
|
|
|
|
type = "SPOT2";
|
|
|
|
break;
|
|
|
|
case FX_LOOPING:
|
|
|
|
type = "LOOPING";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = "UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug_Printf("%d: res: %d ('%s') %s (%d) delay: %d vol: %d pan: %d\n",
|
|
|
|
i, _fxQueue[i].resource,
|
|
|
|
_vm->_resman->fetchName(_fxQueue[i].resource),
|
|
|
|
type, _fxQueue[i].type, _fxQueue[i].delay,
|
|
|
|
_fxQueue[i].volume, _fxQueue[i].pan);
|
|
|
|
} else {
|
|
|
|
freeSlots++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Debug_Printf("Free slots: %d\n", freeSlots);
|
|
|
|
}
|
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
} // End of namespace Sword2
|