aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2011-06-19 21:14:49 +1000
committerPaul Gilbert2011-06-19 21:14:49 +1000
commit9dddf76aa79751bf232d5dcd6a85248cf725a723 (patch)
tree47a1365b1075ebcf8db4a3015b67f71666080bd9 /engines
parent48e5bd36e9722d87787d077e34ca28a454cc14f1 (diff)
parentcc63cbcf5fe466ff72e84d1eeb34f0afd61b5714 (diff)
downloadscummvm-rg350-9dddf76aa79751bf232d5dcd6a85248cf725a723.tar.gz
scummvm-rg350-9dddf76aa79751bf232d5dcd6a85248cf725a723.tar.bz2
scummvm-rg350-9dddf76aa79751bf232d5dcd6a85248cf725a723.zip
Merge remote branch 'remotes/dreammaster/tsage_sound'
Conflicts: engines/tsage/ringworld_scenes1.cpp engines/tsage/ringworld_scenes5.cpp engines/tsage/tsage.h
Diffstat (limited to 'engines')
-rw-r--r--engines/tsage/converse.cpp2
-rw-r--r--engines/tsage/converse.h3
-rw-r--r--engines/tsage/core.cpp53
-rw-r--r--engines/tsage/core.h69
-rw-r--r--engines/tsage/events.cpp5
-rw-r--r--engines/tsage/globals.cpp2
-rw-r--r--engines/tsage/globals.h3
-rw-r--r--engines/tsage/resources.cpp4
-rw-r--r--engines/tsage/ringworld_demo.cpp2
-rw-r--r--engines/tsage/ringworld_demo.h3
-rw-r--r--engines/tsage/ringworld_logic.cpp2
-rw-r--r--engines/tsage/ringworld_scenes1.cpp148
-rw-r--r--engines/tsage/ringworld_scenes1.h21
-rw-r--r--engines/tsage/ringworld_scenes10.cpp43
-rw-r--r--engines/tsage/ringworld_scenes10.h8
-rw-r--r--engines/tsage/ringworld_scenes2.cpp37
-rw-r--r--engines/tsage/ringworld_scenes2.h4
-rw-r--r--engines/tsage/ringworld_scenes3.cpp252
-rw-r--r--engines/tsage/ringworld_scenes3.h20
-rw-r--r--engines/tsage/ringworld_scenes4.cpp8
-rw-r--r--engines/tsage/ringworld_scenes4.h2
-rw-r--r--engines/tsage/ringworld_scenes5.cpp90
-rw-r--r--engines/tsage/ringworld_scenes5.h10
-rw-r--r--engines/tsage/ringworld_scenes6.cpp36
-rw-r--r--engines/tsage/ringworld_scenes6.h8
-rw-r--r--engines/tsage/ringworld_scenes8.cpp49
-rw-r--r--engines/tsage/ringworld_scenes8.h14
-rw-r--r--engines/tsage/sound.cpp2594
-rw-r--r--engines/tsage/sound.h392
-rw-r--r--engines/tsage/tsage.cpp11
-rw-r--r--engines/tsage/tsage.h5
31 files changed, 3391 insertions, 509 deletions
diff --git a/engines/tsage/converse.cpp b/engines/tsage/converse.cpp
index 5fa36142e7..b475310533 100644
--- a/engines/tsage/converse.cpp
+++ b/engines/tsage/converse.cpp
@@ -231,7 +231,7 @@ void SequenceManager::signal() {
case 26:
v1 = getNextValue();
v2 = getNextValue();
- _soundHandler.startSound(v1, v2 ? this : NULL, 127);
+ _soundHandler.play(v1, v2 ? this : NULL, 127);
break;
case 27: {
v1 = getNextValue();
diff --git a/engines/tsage/converse.h b/engines/tsage/converse.h
index 6876fa41cb..13c490e995 100644
--- a/engines/tsage/converse.h
+++ b/engines/tsage/converse.h
@@ -25,6 +25,7 @@
#include "tsage/core.h"
#include "tsage/dialogs.h"
+#include "tsage/sound.h"
namespace tSage {
@@ -50,7 +51,7 @@ public:
int _objectIndex;
SceneObject *_sceneObject;
SceneObject *_objectList[6];
- SoundHandler _soundHandler;
+ ASound _soundHandler;
public:
SequenceManager();
diff --git a/engines/tsage/core.cpp b/engines/tsage/core.cpp
index ed2b03ebc4..4603379c78 100644
--- a/engines/tsage/core.cpp
+++ b/engines/tsage/core.cpp
@@ -31,6 +31,7 @@
#include "tsage/scenes.h"
#include "tsage/staticres.h"
#include "tsage/globals.h"
+#include "tsage/sound.h"
namespace tSage {
@@ -2961,55 +2962,6 @@ int SceneRegions::indexOf(const Common::Point &pt) {
/*--------------------------------------------------------------------------*/
-SoundHandler::SoundHandler() {
- _action = NULL;
- _field280 = -1;
- if (_globals)
- _globals->_sceneListeners.push_back(this);
-}
-
-SoundHandler::~SoundHandler() {
- if (_globals)
- _globals->_sceneListeners.remove(this);
-}
-
-void SoundHandler::dispatch() {
- EventHandler::dispatch();
- int v = _sound.proc12();
-
- if (v != -1) {
- _field280 = v;
- _sound.proc2(-1);
-
- if (_action)
- _action->signal();
- }
-
- if (_field280 != -1) {
- // FIXME: Hardcoded to only flag a sound ended if an action has been set
- if (_action) {
-// if (!_sound.proc3()) {
- _field280 = -1;
- if (_action) {
- _action->signal();
- _action = NULL;
- }
- }
- }
-}
-
-void SoundHandler::startSound(int soundNum, Action *action, int volume) {
- _action = action;
- _field280 = 0;
- setVolume(volume);
- _sound.startSound(soundNum);
-
- warning("TODO: SoundHandler::startSound");
-}
-
-
-/*--------------------------------------------------------------------------*/
-
void SceneItemList::addItems(SceneItem *first, ...) {
va_list va;
va_start(va, first);
@@ -3490,8 +3442,9 @@ void SceneHandler::postInit(SceneObjectList *OwnerList) {
_globals->_scenePalette.loadPalette(0);
_globals->_scenePalette.refresh();
- // TODO: Bunch of other scene related setup goes here
_globals->_soundManager.postInit();
+ _globals->_soundManager.buildDriverList(true);
+ _globals->_soundManager.installConfigDrivers();
_globals->_game->start();
}
diff --git a/engines/tsage/core.h b/engines/tsage/core.h
index 92907addbc..b86e2f63fe 100644
--- a/engines/tsage/core.h
+++ b/engines/tsage/core.h
@@ -33,7 +33,6 @@
#include "tsage/graphics.h"
#include "tsage/resources.h"
#include "tsage/saveload.h"
-#include "tsage/sound.h"
namespace tSage {
@@ -719,74 +718,6 @@ public:
/*--------------------------------------------------------------------------*/
-class GameSoundHandler {
-public:
- void proc1() {
- warning("TODO: GameSoundHandler::proc1");
- }
- void proc5(int v) {
- warning("TODO: GameSoundHandler::proc5");
- }
- void proc11(int v1, int v2, int v3, int v4) {
- warning("TODO: GameSoundHandler::proc11");
- }
- int proc12() {
- // TODO
- return -1;
- }
- void proc2(int v) {
- // TODO
- }
- int proc3() {
- return 0;
- }
- void setVolume(int volume) {
- warning("TODO GameSoundHandler::setVolume");
- }
- void startSound(int soundNum) {
- warning("TODO GameSoundHandler::startSound");
- }
-};
-
-class SoundHandler : public EventHandler {
-public:
- GameSoundHandler _sound;
- Action *_action;
- int _field280;
-public:
- SoundHandler();
- ~SoundHandler();
-
- void startSound(int soundNum, Action *action = NULL, int volume = 127);
- void proc1(Action *action) {
- proc11(0, 5, 10, 1, action);
- }
- void proc2(int v) {
- warning("TODO: SoundHandler::proc2");
- }
- void proc3() {
- warning("TODO: SoundHandler::proc5");
- }
- void proc4() {
- _sound.proc1();
- }
- void proc5(int v) {
- _sound.proc5(v);
- }
- void proc11(int v1, int v2, int v3, int v4, Action *action) {
- if (action)
- _action = action;
-
- _sound.proc11(v1, v2, v3, v4);
- }
- void setVolume(int volume) { _sound.setVolume(volume); }
-
- virtual Common::String getClassName() { return "SoundHandler"; }
- virtual void dispatch();
-};
-
-/*--------------------------------------------------------------------------*/
-
class SceneItemList : public SynchronizedList<SceneItem *> {
public:
void addItems(SceneItem *first, ...);
diff --git a/engines/tsage/events.cpp b/engines/tsage/events.cpp
index 9df2a7ccd6..50077fecaf 100644
--- a/engines/tsage/events.cpp
+++ b/engines/tsage/events.cpp
@@ -48,7 +48,9 @@ bool EventsClass::pollEvent() {
_priorFrameTime = milli;
++_frameNumber;
+ // Update screen and allow the sound manager to process pending sounds
g_system->updateScreen();
+ SoundManager::_sfSoundServer();
}
if (!g_system->getEventManager()->pollEvent(_event)) return false;
@@ -297,6 +299,9 @@ void EventsClass::delay(int numFrames) {
++_frameNumber;
_priorFrameTime = g_system->getMillis();
+
+ // Allow pending sounds to be processed
+ SoundManager::_sfSoundServer();
}
g_system->updateScreen();
diff --git a/engines/tsage/globals.cpp b/engines/tsage/globals.cpp
index 863f1458b1..b0f6db53c6 100644
--- a/engines/tsage/globals.cpp
+++ b/engines/tsage/globals.cpp
@@ -117,9 +117,9 @@ Globals::Globals() : _dialogCenter(160, 140), _gfxManagerInstance(_screenSurface
}
Globals::~Globals() {
- _globals = NULL;
delete _inventory;
delete _game;
+ _globals = NULL;
}
void Globals::reset() {
diff --git a/engines/tsage/globals.h b/engines/tsage/globals.h
index 8212387ed1..3635fcc3fa 100644
--- a/engines/tsage/globals.h
+++ b/engines/tsage/globals.h
@@ -28,6 +28,7 @@
#include "tsage/dialogs.h"
#include "tsage/scenes.h"
#include "tsage/events.h"
+#include "tsage/sound.h"
#include "tsage/saveload.h"
namespace tSage {
@@ -58,7 +59,7 @@ public:
SynchronizedList<EventHandler *> _sceneListeners;
bool _flags[256];
Player _player;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
InvObjectList *_inventory;
Region _paneRegions[2];
int _paneRefreshFlag[2];
diff --git a/engines/tsage/resources.cpp b/engines/tsage/resources.cpp
index 676d319ba9..d24c564a1f 100644
--- a/engines/tsage/resources.cpp
+++ b/engines/tsage/resources.cpp
@@ -66,7 +66,9 @@ uint16 MemoryManager::allocate(uint32 size) {
byte *MemoryManager::allocate2(uint32 size) {
uint32 idx = allocate(size);
- return lock(idx);
+ byte *result = lock(idx);
+ Common::set_to(result, result + size, 0);
+ return result;
}
byte *MemoryManager::lock(uint32 handle) {
diff --git a/engines/tsage/ringworld_demo.cpp b/engines/tsage/ringworld_demo.cpp
index de8dbf8c12..4f905d5bec 100644
--- a/engines/tsage/ringworld_demo.cpp
+++ b/engines/tsage/ringworld_demo.cpp
@@ -101,7 +101,7 @@ void RingworldDemoScene::postInit(SceneObjectList *OwnerList) {
}
void RingworldDemoScene::signal() {
- _soundHandler.startSound(4);
+ _soundHandler.play(4);
_actor1.postInit();
_actor2.postInit();
_actor3.postInit();
diff --git a/engines/tsage/ringworld_demo.h b/engines/tsage/ringworld_demo.h
index 7492c1e871..3e7431e107 100644
--- a/engines/tsage/ringworld_demo.h
+++ b/engines/tsage/ringworld_demo.h
@@ -28,6 +28,7 @@
#include "tsage/core.h"
#include "tsage/scenes.h"
#include "tsage/globals.h"
+#include "tsage/sound.h"
namespace tSage {
@@ -46,7 +47,7 @@ public:
SequenceManager _sequenceManager;
SceneObject _actor1, _actor2, _actor3;
SceneObject _actor4, _actor5, _actor6;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
virtual void postInit(SceneObjectList *OwnerList = NULL);
virtual void process(Event &event);
diff --git a/engines/tsage/ringworld_logic.cpp b/engines/tsage/ringworld_logic.cpp
index 95c9da9fe7..4c60e5fea9 100644
--- a/engines/tsage/ringworld_logic.cpp
+++ b/engines/tsage/ringworld_logic.cpp
@@ -1346,7 +1346,7 @@ void RingworldGame::start() {
void RingworldGame::restart() {
_globals->_scenePalette.clearListeners();
- _globals->_soundHandler.proc3();
+ _globals->_soundHandler.stop();
// Reset the flags
_globals->reset();
diff --git a/engines/tsage/ringworld_scenes1.cpp b/engines/tsage/ringworld_scenes1.cpp
index 6960788db3..9f8aedbfc1 100644
--- a/engines/tsage/ringworld_scenes1.cpp
+++ b/engines/tsage/ringworld_scenes1.cpp
@@ -98,7 +98,7 @@ void Scene10::Action1::signal() {
scene->_object4.animate(ANIM_MODE_6, this);
break;
case 10:
- _globals->_soundHandler.proc1(this);
+ _globals->_soundHandler.fadeOut(this);
break;
case 11:
_globals->_scenePalette.clearListeners();
@@ -185,7 +185,7 @@ void Scene10::postInit(SceneObjectList *OwnerList) {
_globals->_sceneOffset.x = (_globals->_sceneManager._scene->_sceneBounds.left / 160) * 160;
setAction(&_action1);
- _globals->_soundHandler.startSound(5);
+ _globals->_soundHandler.play(5);
}
void Scene10::stripCallback(int v) {
@@ -232,7 +232,7 @@ void Scene15::Action1::signal() {
Common::Point pt(160, 100);
NpcMover *mover = new NpcMover();
scene->_object1.addMover(mover, &pt, this);
- scene->_soundHandler.startSound(7);
+ scene->_soundHandler.play(7);
break;
}
case 3:
@@ -256,7 +256,7 @@ void Scene15::postInit(SceneObjectList *OwnerList) {
loadScene(15);
Scene::postInit();
setZoomPercents(0, 100, 200, 100);
- _globals->_soundHandler.startSound(6);
+ _globals->_soundHandler.play(6);
setAction(&_action1);
}
@@ -276,7 +276,7 @@ void Scene20::Action1::signal() {
scene->_stripManager.start(20, this);
break;
case 2:
- _globals->_soundHandler.proc1(this);
+ _globals->_soundHandler.fadeOut(this);
break;
case 3:
_globals->_sceneManager._fadeMode = FADEMODE_GRADUAL;
@@ -341,8 +341,8 @@ void Scene20::Action2::signal() {
break;
}
case 8:
- scene->_sound.proc4();
- scene->_sound.proc1(this);
+ scene->_sound.release();
+ scene->_sound.fadeOut(this);
break;
case 9:
SceneItem::display(0, 0, LIST_END);
@@ -400,8 +400,8 @@ void Scene20::Action3::signal() {
break;
}
case 6:
- scene->_sound.startSound(60, this, 127);
- _globals->_soundHandler.proc4();
+ scene->_sound.play(60, this, 127);
+ _globals->_soundHandler.release();
break;
case 7:
_globals->_sceneManager._fadeMode = FADEMODE_GRADUAL;
@@ -450,7 +450,7 @@ void Scene20::Action4::signal() {
break;
}
case 4: {
- scene->_sound.startSound(28);
+ scene->_sound.play(28);
scene->_sceneObject4.postInit();
scene->_sceneObject4.setVisage(21);
scene->_sceneObject4.setStrip(3);
@@ -463,7 +463,7 @@ void Scene20::Action4::signal() {
break;
}
case 5: {
- scene->_sound.startSound(42);
+ scene->_sound.play(42);
scene->_sceneObject4.remove();
scene->_SceneObjectExt.setVisage(21);
scene->_SceneObjectExt.setStrip(1);
@@ -487,7 +487,7 @@ void Scene20::Action4::signal() {
break;
}
case 6: {
- scene->_sound.startSound(42);
+ scene->_sound.play(42);
scene->_SceneObjectExt.setStrip(2);
scene->_SceneObjectExt.animate(ANIM_MODE_2, NULL);
@@ -506,7 +506,7 @@ void Scene20::Action4::signal() {
case 7:
_globals->_player.setStrip(2);
_globals->_player.animate(ANIM_MODE_2, NULL);
- scene->_sound.startSound(77, this, 127);
+ scene->_sound.play(77, this, 127);
break;
case 8:
_globals->_game->endGame(20, 0);
@@ -549,15 +549,15 @@ void Scene20::postInit(SceneObjectList *OwnerList) {
_SceneObjectExt._moveDiff = Common::Point(10, 10);
_sceneObject3._moveDiff = Common::Point(10, 10);
- _globals->_soundHandler.startSound(20);
- _sound.startSound(21);
- _sound.proc5(1);
+ _globals->_soundHandler.play(20);
+ _sound.play(21);
+ _sound.holdAt(true);
setAction(&_action2);
_sceneBounds = Rect(320, 0, 640, 200);
} else if (_globals->_sceneManager._previousScene == 60) {
// Evasion
- _sound.startSound(30);
+ _sound.play(30);
_globals->_player.postInit();
_globals->_player.setVisage(20);
_globals->_player.setPosition(Common::Point(588, 79));
@@ -605,7 +605,7 @@ void Scene20::postInit(SceneObjectList *OwnerList) {
_speakerGameText.setTextPos(Common::Point(350, 20));
_speakerGameText._textWidth = 260;
- _globals->_soundHandler.startSound(8);
+ _globals->_soundHandler.play(8);
_sceneBounds = Rect(320, 0, 640, 200);
}
@@ -669,7 +669,7 @@ void Scene30::BeamAction::signal() {
case 2:
// Hide the beam and lower the player's hand
- scene->_sound.startSound(10, NULL, 127);
+ scene->_sound.play(10, NULL, 127);
_globals->_player.animate(ANIM_MODE_6, this);
scene->_beam.remove();
break;
@@ -693,14 +693,14 @@ void Scene30::BeamAction::signal() {
case 4:
// Open the door
- scene->_sound.startSound(11, NULL, 127);
+ scene->_sound.play(11, NULL, 127);
scene->_door.animate(ANIM_MODE_5, this);
break;
case 5:
// Run the Kzin's talk sequence
- scene->_sound.startSound(13, NULL, 127);
- _globals->_soundHandler.startSound(12, NULL, 127);
+ scene->_sound.play(13, NULL, 127);
+ _globals->_soundHandler.play(12, NULL, 127);
scene->_stripManager.start((scene->_sceneMode == 0) ? 30 : 37, this);
break;
@@ -732,7 +732,7 @@ void Scene30::KzinAction::signal() {
setDelay(1200);
break;
case 1:
- _globals->_soundHandler.proc2(0);
+ _globals->_soundHandler.fadeOut(NULL);
_globals->_player.disableControl();
setAction(&scene->_sequenceManager, _globals->_sceneManager._scene, 31, &scene->_kzin, &scene->_door, NULL);
break;
@@ -772,12 +772,12 @@ void Scene30::RingAction::signal() {
}
case 3:
- scene->_sound.startSound(11, NULL, 127);
+ scene->_sound.play(11, NULL, 127);
scene->_door.animate(ANIM_MODE_6, this);
break;
case 4: {
- scene->_sound.startSound(13, NULL, 127);
+ scene->_sound.play(13, NULL, 127);
NpcMover *kzinMover = new NpcMover();
Common::Point pt(354, 5);
scene->_kzin.addMover(kzinMover, &pt, this);
@@ -955,7 +955,7 @@ void Scene40::Action1::signal() {
scene->_doorway.setVisage(46);
scene->_doorway.setPosition(Common::Point(305, 61));
scene->_doorway.animate(ANIM_MODE_5, this);
- scene->_soundHandler.startSound(25);
+ scene->_soundHandler.play(25);
break;
case 3:
scene->_doorway.hide();
@@ -976,7 +976,7 @@ void Scene40::Action1::signal() {
scene->_assassin.setFrame(1);
scene->_assassin.setPosition(Common::Point(13, 171));
scene->_assassin.animate(ANIM_MODE_5, this);
- scene->_soundHandler.startSound(25);
+ scene->_soundHandler.play(25);
break;
case 5:
scene->_doorway.show();
@@ -1011,7 +1011,7 @@ void Scene40::Action1::signal() {
break;
}
case 10: {
- scene->_soundHandler.startSound(27);
+ scene->_soundHandler.play(27);
Common::Point pt(223, 184);
NpcMover *mover = new NpcMover();
scene->_dyingKzin.addMover(mover, &pt, this);
@@ -1024,7 +1024,7 @@ void Scene40::Action1::signal() {
break;
}
case 12: {
- _globals->_soundHandler.startSound(26);
+ _globals->_soundHandler.play(26);
_globals->_player._uiEnabled = true;
scene->_assassin.setVisage(42);
scene->_assassin.setPosition(Common::Point(4, 191));
@@ -1043,7 +1043,7 @@ void Scene40::Action1::signal() {
scene->_assassin.setStrip(1);
scene->_assassin.setFrame(1);
scene->_assassin.animate(ANIM_MODE_5, this);
- scene->_soundHandler.startSound(28);
+ scene->_soundHandler.play(28);
break;
case 15:
_globals->_player.disableControl();
@@ -1057,7 +1057,7 @@ void Scene40::Action1::signal() {
_globals->_player.animate(ANIM_MODE_5, this);
break;
case 16:
- _globals->_soundHandler.startSound(77, this);
+ _globals->_soundHandler.play(77, this);
break;
case 17:
_globals->_game->endGame(40, 20);
@@ -1083,7 +1083,7 @@ void Scene40::Action2::signal() {
_globals->_player.animate(ANIM_MODE_5, this);
break;
case 2: {
- scene->_soundHandler.startSound(28);
+ scene->_soundHandler.play(28);
scene->_doorway.postInit();
scene->_doorway.setVisage(16);
scene->_doorway.setStrip2(6);
@@ -1103,7 +1103,7 @@ void Scene40::Action2::signal() {
scene->_assassin.setVisage(44);
scene->_assassin._frame = 1;
scene->_assassin.animate(ANIM_MODE_5, this);
- scene->_soundHandler.startSound(29);
+ scene->_soundHandler.play(29);
RING_INVENTORY._infoDisk._sceneNumber = 40;
break;
case 4:
@@ -1234,11 +1234,11 @@ void Scene40::Action6::signal() {
scene->_doorway.setVisage(46);
scene->_doorway.setPosition(Common::Point(305, 61));
scene->_doorway.animate(ANIM_MODE_5, this);
- scene->_soundHandler.startSound(25);
+ scene->_soundHandler.play(25);
break;
}
case 1:
- scene->_soundHandler.startSound(28);
+ scene->_soundHandler.play(28);
scene->_doorway.setPosition(Common::Point(148, 74));
scene->_doorway.setFrame(1);
scene->_doorway.setStrip(2);
@@ -1270,7 +1270,7 @@ void Scene40::Action7::signal() {
scene->_object7.setFrame(15);
}
scene->_object7.animate(ANIM_MODE_5, this);
- scene->_soundHandler.startSound(25);
+ scene->_soundHandler.play(25);
break;
case 2:
scene->_object7.remove();
@@ -1322,7 +1322,7 @@ void Scene40::Action8::signal() {
_globals->_player.animate(ANIM_MODE_5, this);
break;
case 3:
- _globals->_soundHandler.startSound(77, this);
+ _globals->_soundHandler.play(77, this);
break;
case 4:
_globals->_game->endGame(40, 45);
@@ -1480,7 +1480,7 @@ void Scene40::postInit(SceneObjectList *OwnerList) {
_globals->_player.disableControl();
if (_globals->_sceneManager._previousScene == 20) {
- _globals->_soundHandler.startSound(24);
+ _globals->_soundHandler.play(24);
_globals->_player.setVisage(43);
_object1.postInit();
@@ -1872,7 +1872,7 @@ void Scene60::Action1::signal() {
scene->_floppyDrive.setPosition(Common::Point(136, 65));
scene->_floppyDrive.animate(ANIM_MODE_5, this);
- scene->_soundHandler1.startSound(35);
+ scene->_soundHandler1.play(35);
break;
case 2:
scene->_redLights.postInit();
@@ -1893,13 +1893,13 @@ void Scene60::Action1::signal() {
scene->_message._numFrames = 5;
_globals->_sceneItems.push_front(&scene->_message);
- scene->_soundHandler2.startSound(38);
+ scene->_soundHandler2.play(38);
}
_globals->_events.setCursor(CURSOR_USE);
break;
case 3:
- scene->_soundHandler2.startSound(37);
+ scene->_soundHandler2.play(37);
scene->loadScene(65);
scene->_message.remove();
@@ -1968,8 +1968,8 @@ void Scene60::Action1::signal() {
scene->_floppyDrive.setFrame(scene->_floppyDrive.getFrameCount());
scene->_floppyDrive.animate(ANIM_MODE_6, this);
- scene->_soundHandler1.startSound(35);
- scene->_soundHandler3.proc3();
+ scene->_soundHandler1.play(35);
+ scene->_soundHandler3.stop();
scene->_masterButton.setFrame(1);
scene->_masterButton._state = 0;
@@ -2019,7 +2019,7 @@ void Scene60::PrevObject::doAction(int action) {
animate(ANIM_MODE_8, 1, NULL);
if (scene->_action1.getActionIndex() > 5) {
- scene->_soundHandler3.startSound(36);
+ scene->_soundHandler3.play(36);
scene->_action1.setActionIndex(scene->_action1.getActionIndex() - 2);
scene->_action1.setDelay(1);
}
@@ -2037,7 +2037,7 @@ void Scene60::NextObject::doAction(int action) {
animate(ANIM_MODE_8, 1, NULL);
if (scene->_action1.getActionIndex() < 8) {
- scene->_soundHandler3.startSound(36);
+ scene->_soundHandler3.play(36);
scene->_action1.setDelay(1);
}
} else {
@@ -2051,7 +2051,7 @@ void Scene60::ExitObject::doAction(int action) {
if (action == CURSOR_LOOK) {
SceneItem::display2(60, 18);
} else if (action == CURSOR_USE) {
- scene->_soundHandler3.startSound(36);
+ scene->_soundHandler3.play(36);
animate(ANIM_MODE_8, 1, NULL);
scene->_nextButton.remove();
scene->_prevButton.remove();
@@ -2132,8 +2132,8 @@ void Scene60::ControlObject::doAction(int action) {
if (_animateMode == ANIM_MODE_NONE)
SceneItem::display2(60, 14);
else if (!scene->_slaveButton._state) {
- _globals->_soundHandler.startSound(40);
- _globals->_soundHandler.proc5(1);
+ _globals->_soundHandler.play(40);
+ _globals->_soundHandler.holdAt(true);
_globals->_sceneManager.changeScene(20);
} else {
scene->_sceneMode = 15;
@@ -2153,14 +2153,14 @@ void Scene60::SlaveObject::doAction(int action) {
if (scene->_masterButton._state)
scene->_sceneMode = 19;
else if (_state) {
- scene->_soundHandler3.proc3();
+ scene->_soundHandler3.stop();
animate(ANIM_MODE_6, NULL);
_globals->clearFlag(102);
_globals->clearFlag(!_globals->_stripNum ? 117 : 120);
_state = 0;
scene->_sceneMode = 9998;
} else {
- scene->_soundHandler3.startSound(39);
+ scene->_soundHandler3.play(39);
_globals->setFlag(102);
_globals->setFlag(!_globals->_stripNum ? 117 : 120);
animate(ANIM_MODE_5, NULL);
@@ -2185,14 +2185,14 @@ void Scene60::MasterObject::doAction(int action) {
else if (scene->_slaveButton._state)
scene->_sceneMode = 20;
else if (_state) {
- scene->_soundHandler3.proc3();
+ scene->_soundHandler3.stop();
animate(ANIM_MODE_6, NULL);
_state = 0;
_globals->clearFlag(103);
_globals->clearFlag(!_globals->_stripNum ? 116 : 119);
scene->_sceneMode = 9998;
} else {
- scene->_soundHandler3.startSound(39);
+ scene->_soundHandler3.play(39);
animate(ANIM_MODE_5, NULL);
_state = 1;
_globals->setFlag(103);
@@ -2347,7 +2347,7 @@ void Scene60::postInit(SceneObjectList *OwnerList) {
_redLights.setPosition(Common::Point(199, 186));
_redLights.animate(ANIM_MODE_8, 0, NULL);
- _soundHandler1.startSound(35);
+ _soundHandler1.play(35);
if (!_globals->getFlag(83)) {
_message.postInit();
@@ -2359,7 +2359,7 @@ void Scene60::postInit(SceneObjectList *OwnerList) {
_message._numFrames = 5;
_globals->_sceneItems.push_front(&_message);
- _soundHandler2.startSound(38);
+ _soundHandler2.play(38);
}
}
} else {
@@ -2382,7 +2382,7 @@ void Scene60::postInit(SceneObjectList *OwnerList) {
_redLights.animate(ANIM_MODE_8, 0, NULL);
_redLights._numFrames = 5;
- _soundHandler1.startSound(35);
+ _soundHandler1.play(35);
if (!_globals->getFlag(83)) {
_message.postInit();
@@ -2394,7 +2394,7 @@ void Scene60::postInit(SceneObjectList *OwnerList) {
_message._numFrames = 5;
_globals->_sceneItems.push_front(&_message);
- _soundHandler2.startSound(38);
+ _soundHandler2.play(38);
}
}
}
@@ -2462,7 +2462,7 @@ void Scene90::Action1::signal() {
setDelay(2);
break;
case 5:
- scene->_soundHandler2.startSound(58);
+ scene->_soundHandler2.play(58);
if (scene->_stripManager._field2E8 == 220)
scene->_stripManager.start(91, this, scene);
@@ -2477,7 +2477,7 @@ void Scene90::Action1::signal() {
break;
case 7:
scene->_object2.animate(ANIM_MODE_NONE);
- _globals->_soundHandler.startSound(56);
+ _globals->_soundHandler.play(56);
scene->_object3.animate(ANIM_MODE_5, this);
break;
case 8: {
@@ -2507,8 +2507,8 @@ void Scene90::Action1::signal() {
break;
}
case 11:
- _globals->_soundHandler.startSound(57);
- _globals->_soundHandler.startSound(68);
+ _globals->_soundHandler.play(57);
+ _globals->_soundHandler.play(68);
scene->_object3.animate(ANIM_MODE_6, NULL);
SceneItem::display(90, _globals->getFlag(104) ? 15 : 14,
@@ -2556,8 +2556,8 @@ void Scene90::Object2::doAction(int action) {
scene->_object6.hide();
scene->_sceneMode = 91;
- scene->_soundHandler1.startSound(59);
- scene->_soundHandler1.proc5(1);
+ scene->_soundHandler1.play(59);
+ scene->_soundHandler1.holdAt(true);
scene->setAction(&scene->_sequenceManager, scene, 91, this, &scene->_object6, NULL);
break;
case CURSOR_LOOK:
@@ -2653,9 +2653,9 @@ void Scene90::postInit(SceneObjectList *OwnerList) {
_globals->_sceneItems.push_back(&_object3);
_globals->_player.disableControl();
- _globals->_soundHandler.startSound(55);
- _soundHandler1.startSound(52);
- _soundHandler1.proc5(1);
+ _globals->_soundHandler.play(55);
+ _soundHandler1.play(52);
+ _soundHandler1.holdAt(true);
setAction(&_action1);
@@ -2670,7 +2670,7 @@ void Scene90::signal() {
switch (_sceneMode) {
case 91:
_sceneMode = 92;
- _globals->_soundHandler.startSound(77, this);
+ _globals->_soundHandler.play(77, this);
break;
case 92:
_globals->_scenePalette.clearListeners();
@@ -2713,7 +2713,7 @@ void Scene95::Action1::signal() {
setDelay(60);
break;
case 2: {
- scene->_soundHandler.startSound(66);
+ scene->_soundHandler.play(66);
scene->_object3._numFrames = 5;
scene->_object3.animate(ANIM_MODE_5, NULL);
SceneItem::display(0, 0);
@@ -2728,7 +2728,7 @@ void Scene95::Action1::signal() {
break;
}
case 3: {
- scene->_soundHandler.startSound(21);
+ scene->_soundHandler.play(21);
Common::Point pt1(235, 72);
PlayerMover *mover1 = new PlayerMover();
@@ -2768,7 +2768,7 @@ void Scene95::Action1::signal() {
scene->_object1.setVisage(91);
scene->_object1.setPosition(Common::Point(-22, 220));
- scene->_soundHandler.startSound(21);
+ scene->_soundHandler.play(21);
Common::Point pt1(5, 198);
NpcMover *mover1 = new NpcMover();
@@ -2826,7 +2826,7 @@ void Scene95::postInit(SceneObjectList *OwnerList) {
_object3.setVisage(96);
_object3.setPosition(Common::Point(29, 198));
- _soundHandler.startSound(67);
+ _soundHandler.play(67);
setAction(&_action1);
}
@@ -3000,21 +3000,21 @@ void Scene6100::Action5::dispatch() {
(tempSet.sqrt(zeroSet) < 150.0)) {
switch (scene->_hitCount++) {
case 0:
- scene->_soundHandler.startSound(233);
+ scene->_soundHandler.play(233);
scene->showMessage(NULL, 0, NULL);
if (!_globals->getFlag(76))
scene->_probe.setAction(&scene->_action1);
break;
case 1:
- scene->_soundHandler.startSound(233);
+ scene->_soundHandler.play(233);
scene->showMessage(NULL, 0, NULL);
if (!_globals->getFlag(76))
scene->_probe.setAction(&scene->_action2);
break;
case 2:
- scene->_soundHandler.startSound(234);
+ scene->_soundHandler.play(234);
scene->showMessage(NULL, 0, NULL);
if (!_globals->getFlag(76))
@@ -3243,7 +3243,7 @@ void Scene6100::postInit(SceneObjectList *OwnerList) {
if (!_globals->getFlag(76))
_probe.setAction(&_action4);
- _globals->_soundHandler.startSound(231);
+ _globals->_soundHandler.play(231);
}
void Scene6100::remove() {
diff --git a/engines/tsage/ringworld_scenes1.h b/engines/tsage/ringworld_scenes1.h
index abd765473c..712a16c612 100644
--- a/engines/tsage/ringworld_scenes1.h
+++ b/engines/tsage/ringworld_scenes1.h
@@ -30,6 +30,7 @@
#include "tsage/core.h"
#include "tsage/scenes.h"
#include "tsage/globals.h"
+#include "tsage/sound.h"
namespace tSage {
@@ -65,7 +66,7 @@ class Scene15 : public Scene {
public:
Action1 _action1;
SceneObject _object1;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
virtual void postInit(SceneObjectList *OwnerList = NULL);
};
@@ -97,7 +98,7 @@ public:
Action3 _action3;
Action4 _action4;
SceneObject _sceneObject1, _SceneObjectExt, _sceneObject3, _sceneObject4, _sceneObject5;
- SoundHandler _sound;
+ ASound _sound;
public:
Scene20();
virtual ~Scene20() {}
@@ -143,7 +144,7 @@ class Scene30 : public Scene {
};
public:
- SoundHandler _sound;
+ ASound _sound;
DisplayHotspot _groundHotspot, _wallsHotspot, _courtyardHotspot, _treeHotspot;
BeamObject _beam;
DoorObject _door;
@@ -232,7 +233,7 @@ public:
SpeakerQText _speakerQText;
SpeakerSText _speakerSText;
SpeakerGameText _speakerGameText;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
Action1 _action1;
Action2 _action2;
Action3 _action3;
@@ -387,9 +388,9 @@ public:
SceneObject _redLights;
Item1 _item1;
Item _item2, _item3, _item4, _item5, _item6;
- SoundHandler _soundHandler1;
- SoundHandler _soundHandler2;
- SoundHandler _soundHandler3;
+ ASound _soundHandler1;
+ ASound _soundHandler2;
+ ASound _soundHandler3;
Scene60();
virtual void postInit(SceneObjectList *OwnerList = NULL);
@@ -423,7 +424,7 @@ public:
DisplayObject _object3, _object4, _object5;
SceneObject _object6;
DisplayHotspot _item1, _item2, _item3;
- SoundHandler _soundHandler1, _soundHandler2;
+ ASound _soundHandler1, _soundHandler2;
Scene90();
@@ -441,7 +442,7 @@ class Scene95 : public Scene {
public:
Action1 _action1;
SceneObject _object1, _object2, _object3;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
Scene95();
virtual void postInit(SceneObjectList *OwnerList);
@@ -505,7 +506,7 @@ public:
Action5 _action5;
GetBoxAction _getBoxAction;
Action7 _action7;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
Speaker _speaker1;
SpeakerQR _speakerQR;
SpeakerSL _speakerSL;
diff --git a/engines/tsage/ringworld_scenes10.cpp b/engines/tsage/ringworld_scenes10.cpp
index 0b4186531d..ba4060548e 100644
--- a/engines/tsage/ringworld_scenes10.cpp
+++ b/engines/tsage/ringworld_scenes10.cpp
@@ -151,7 +151,7 @@ void Scene9100::postInit(SceneObjectList *OwnerList) {
_sceneHotspot5.setup(69, 36, 121, 272, 9100, 45, 46);
_sceneHotspot6.setup(127, 0, 200, 52, 9100, 47, 48);
- _globals->_soundHandler.startSound(251);
+ _globals->_soundHandler.play(251);
if (_globals->_sceneManager._previousScene == 9150) {
if (_globals->getFlag(20)) {
_globals->_player.disableControl();
@@ -236,7 +236,7 @@ void Scene9150::dispatch() {
} else {
_globals->_player.disableControl();
if (_globals->getFlag(11)) {
- _globals->_soundHandler.startSound(286);
+ _globals->_soundHandler.play(286);
_sceneMode = 9153;
} else {
_sceneMode = 9156;
@@ -270,7 +270,7 @@ void Scene9150::postInit(SceneObjectList *OwnerList) {
_sceneHotspot8.setup(133, 584, 142, 640, 9150, 57, -1);
_sceneHotspot10.setup(83, 304, 103, 323, 9150, 58, 59);
- _globals->_soundHandler.startSound(285);
+ _globals->_soundHandler.play(285);
_globals->_player.disableControl();
if (_globals->getFlag(20)) {
@@ -402,7 +402,8 @@ void Scene9200::postInit(SceneObjectList *OwnerList) {
_object1.animate(ANIM_MODE_2, NULL);
_object1.setPosition(Common::Point(132, 114));
_object1.fixPriority(140);
- _soundHandler.startSound(297);
+ _soundHandler.play(297);
+
_stripManager.addSpeaker(&_speakerQText);
_stripManager.addSpeaker(&_speakerGR);
_stripManager.addSpeaker(&_speakerGText);
@@ -479,7 +480,7 @@ void Scene9300::signal() {
_globals->setFlag(84);
// No break on purpose
case 9303:
- _globals->_soundHandler.startSound(295);
+ _globals->_soundHandler.play(295);
_globals->_sceneManager.changeScene(9350);
break;
case 9302:
@@ -509,7 +510,7 @@ void Scene9300::postInit(SceneObjectList *OwnerList) {
_globals->_player.changeZoom(-1);
_object1.postInit();
_object2.postInit();
- _globals->_soundHandler.startSound(289);
+ _globals->_soundHandler.play(289);
_hotspot1.setup(35, 142, 76, 212, 9300, 0, 1);
_hotspot2.setup(28, 90, 81, 143, 9300, 2, 3);
@@ -764,7 +765,7 @@ void Scene9400::signal() {
void Scene9400::dispatch() {
if ((_object1._animateMode == 2) && (_object1._strip == 1) && (_object1._frame == 4)){
if (_field1032 == 0) {
- _soundHandler.startSound(296);
+ _soundHandler.play(296);
_field1032 = 1;
}
} else {
@@ -1083,7 +1084,7 @@ void Scene9500::signal() {
switch (_sceneMode) {
case 9503:
_globals->_sceneManager.changeScene(9200);
- _globals->_soundHandler.startSound(295);
+ _globals->_soundHandler.play(295);
break;
case 9504:
_globals->_sceneManager.changeScene(9850);
@@ -1141,7 +1142,7 @@ void Scene9500::postInit(SceneObjectList *OwnerList) {
setZoomPercents(110, 75, 200, 150);
_globals->_player.postInit();
- _globals->_soundHandler.startSound(305);
+ _globals->_soundHandler.play(305);
_candle.postInit();
_candle.setVisage(9500);
@@ -1249,7 +1250,7 @@ void Scene9700::signal() {
_globals->_events.setCursor(CURSOR_USE);
break;
case 9704:
- _globals->_soundHandler.startSound(323);
+ _globals->_soundHandler.play(323);
_globals->_sceneManager.changeScene(9750);
break;
}
@@ -1308,7 +1309,7 @@ void Scene9700::postInit(SceneObjectList *OwnerList) {
void Scene9750::signal() {
switch (_sceneMode ++) {
case 9751:
- _globals->_soundHandler.proc1(this);
+ _globals->_soundHandler.fadeOut(this);
break;
case 9752:
_globals->_sceneManager.changeScene(2100);
@@ -1440,7 +1441,7 @@ void Scene9850::Hotspot17::doAction(int action) {
SceneItem::display(9850, 32, SET_Y, 20, SET_WIDTH, 200, SET_EXT_BGCOLOR, 7, LIST_END);
} else {
if (action == CURSOR_USE)
- scene->_soundHandler.startSound(306);
+ scene->_soundHandler.play(306);
NamedHotspot::doAction(action);
}
}
@@ -1452,7 +1453,7 @@ void Scene9850::Hotspot18::doAction(int action) {
SceneItem::display(9850, 32, SET_Y, 20, SET_WIDTH, 200, SET_EXT_BGCOLOR, 7, LIST_END);
} else {
if (action == CURSOR_USE)
- scene->_soundHandler.startSound(306);
+ scene->_soundHandler.play(306);
NamedHotspot::doAction(action);
}
}
@@ -1464,7 +1465,7 @@ void Scene9850::Hotspot19::doAction(int action) {
SceneItem::display(9850, 31, SET_Y, 20, SET_WIDTH, 200, SET_EXT_BGCOLOR, 7, LIST_END);
} else {
if (action == CURSOR_USE)
- scene->_soundHandler.startSound(313);
+ scene->_soundHandler.play(313);
NamedHotspot::doAction(action);
}
}
@@ -1653,7 +1654,7 @@ void Scene9900::strAction1::signal() {
switch (_actionIndex++) {
case 0:
- scene->_soundHandler.startSound(351);
+ scene->_soundHandler.play(351);
_object9.postInit();
_object9.setVisage(18);
_object9._frame = 1;
@@ -1673,7 +1674,7 @@ void Scene9900::strAction1::signal() {
_globals->_scenePalette.addFader(&mask2[0], 1, 5, this);
break;
case 3:
- _globals->_soundHandler.startSound(377);
+ _globals->_soundHandler.play(377);
setDelay(120);
break;
case 4:
@@ -1854,7 +1855,7 @@ void Scene9900::signal() {
switch (_sceneMode){
case 150:
- _globals->_soundHandler.startSound(380);
+ _globals->_soundHandler.play(380);
_object8.postInit();
_object8.setVisage(2002);
_object8.setStrip(1);
@@ -1887,7 +1888,7 @@ void Scene9900::signal() {
setAction(&_sequenceManager, this, 9902, &_object1, &_object2, &_object3, &_object4, &_object5, &_object6);
break;
case 9904:
- _globals->_soundHandler.startSound(390);
+ _globals->_soundHandler.play(390);
_sceneMode = 9912;
setAction(&_strAction2, this);
break;
@@ -1918,7 +1919,7 @@ void Scene9900::signal() {
setAction(&_sequenceManager, this, 9904, &_object1, &_object2, &_object3, &_object4, &_object5, &_object6);
break;
case 9909:
- _globals->_soundHandler.startSound(375);
+ _globals->_soundHandler.play(375);
_globals->_player.disableControl();
_sceneMode = 9907;
setAction(&_sequenceManager, this, 9907, &_object1, &_object2, &_object3, &_object4, &_object5, &_object6);
@@ -1929,7 +1930,7 @@ void Scene9900::signal() {
setAction(&_sequenceManager, this, 9911, &_object1, &_object2, &_object3, &_object4, &_object5, &_object6);
break;
case 9911:
- _globals->_soundHandler.startSound(367);
+ _globals->_soundHandler.play(367);
_globals->_player.disableControl();
_sceneMode = 9909;
setAction(&_sequenceManager, this, 9909, &_object1, &_object2, &_object3, &_object4, &_object5, &_object6);
@@ -2080,7 +2081,7 @@ void Scene9999::postInit(SceneObjectList *OwnerList) {
else
_globals->_stripNum = 2121;
- _globals->_soundHandler.startSound(118);
+ _globals->_soundHandler.play(118);
}
diff --git a/engines/tsage/ringworld_scenes10.h b/engines/tsage/ringworld_scenes10.h
index aa41555718..33b16d0014 100644
--- a/engines/tsage/ringworld_scenes10.h
+++ b/engines/tsage/ringworld_scenes10.h
@@ -129,7 +129,7 @@ public:
SpeakerGText _speakerGText;
SpeakerGR _speakerGR;
SpeakerQText _speakerQText;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SceneHotspot1 _hotspot1;
NamedHotspot _hotspot2;
NamedHotspot _hotspot3;
@@ -230,7 +230,7 @@ public:
NamedHotspot _hotspot4;
NamedHotspot _hotspot5;
NamedHotspot _hotspot6;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
int _field1032;
SceneHotspot7 _hotspot7;
SceneHotspot8 _hotspot8;
@@ -424,7 +424,7 @@ public:
SceneObject _objLever;
Object6 _objScimitar;
Object7 _objSword;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
NamedHotspot _hotspot1;
NamedHotspot _hotspot2;
NamedHotspot _hotspot3;
@@ -482,7 +482,7 @@ class Scene9900 : public Scene {
};
public:
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SequenceManager _sequenceManager;
SceneObject _object1;
SceneObject _object2;
diff --git a/engines/tsage/ringworld_scenes2.cpp b/engines/tsage/ringworld_scenes2.cpp
index 4378eac724..0154123c3d 100644
--- a/engines/tsage/ringworld_scenes2.cpp
+++ b/engines/tsage/ringworld_scenes2.cpp
@@ -117,6 +117,7 @@ void Scene1000::Action3::signal() {
// First time being played, so show the introduction
ConfMan.setBool(SEEN_INTRO, true);
ConfMan.flushToDisk();
+
setDelay(1);
} else {
// Prompt user for whether to start play or watch introduction
@@ -124,7 +125,7 @@ void Scene1000::Action3::signal() {
if (MessageDialog::show2(WATCH_INTRO_MSG, START_PLAY_BTN_STRING, INTRODUCTION_BTN_STRING) == 0) {
_actionIndex = 20;
- _globals->_soundHandler.proc1(this);
+ _globals->_soundHandler.fadeOut(this);
} else {
setDelay(1);
}
@@ -214,7 +215,7 @@ void Scene1000::Action3::signal() {
case 18:
zoom(false);
_globals->_scenePalette.clearListeners();
- _globals->_soundHandler.proc1(this);
+ _globals->_soundHandler.fadeOut(this);
break;
case 19:
_globals->_sceneManager.changeScene(10);
@@ -267,7 +268,7 @@ void Scene1000::postInit(SceneObjectList *OwnerList) {
_globals->_sceneManager._scene->_sceneBounds.contain(_globals->_sceneManager._scene->_backgroundBounds);
_globals->_sceneOffset.x = (_globals->_sceneManager._scene->_sceneBounds.left / 160) * 160;
- _globals->_soundHandler.startSound(114);
+ _globals->_soundHandler.play(114);
} else if (_globals->_sceneManager._previousScene == 2222) {
setZoomPercents(150, 10, 180, 100);
_object1.postInit();
@@ -283,7 +284,7 @@ void Scene1000::postInit(SceneObjectList *OwnerList) {
setAction(&_action1);
} else {
- _globals->_soundHandler.startSound(4);
+ _globals->_soundHandler.play(4);
setZoomPercents(0, 10, 30, 100);
_object3.postInit();
_object3.setVisage(1050);
@@ -429,7 +430,7 @@ void Scene1001::Action1::signal() {
setDelay(10);
break;
case 16: {
- scene->_soundHandler1.startSound(90);
+ scene->_soundHandler1.play(90);
scene->_object6.postInit();
scene->_object6.setVisage(16);
@@ -446,7 +447,7 @@ void Scene1001::Action1::signal() {
break;
}
case 17: {
- scene->_soundHandler1.startSound(90);
+ scene->_soundHandler1.play(90);
scene->_object6.remove();
scene->_object7.postInit();
@@ -475,7 +476,7 @@ void Scene1001::Action1::signal() {
setDelay(30);
break;
case 19: {
- _globals->_soundHandler.startSound(91);
+ _globals->_soundHandler.play(91);
byte adjustData[4] = {0xff, 0xff, 0xff, 0};
_globals->_scenePalette.fade(adjustData, false, 0);
@@ -496,7 +497,7 @@ void Scene1001::Action1::signal() {
scene->_object1.animate(ANIM_MODE_5, this);
break;
case 22:
- _globals->_soundHandler.startSound(92);
+ _globals->_soundHandler.play(92);
scene->_stripManager.start(111, this);
break;
case 23:
@@ -526,7 +527,7 @@ void Scene1001::postInit(SceneObjectList *OwnerList) {
_object3.setStrip2(4);
_object3.setPosition(Common::Point(61, 177));
- _globals->_soundHandler.startSound(85);
+ _globals->_soundHandler.play(85);
setAction(&_action1);
}
@@ -647,7 +648,7 @@ void Scene1250::postInit(SceneObjectList *OwnerList) {
setAction(&_action4);
} else {
setAction(&_action3);
- _globals->_soundHandler.startSound(114);
+ _globals->_soundHandler.play(114);
}
}
@@ -734,7 +735,7 @@ void Scene1400::Action1::signal() {
_globals->_sceneManager._scrollerRect = Rect(40, 20, 280, 180);
_globals->_sceneManager._fadeMode = FADEMODE_GRADUAL;
_globals->_stripNum = 1500;
- _globals->_soundHandler.proc3();
+ _globals->_soundHandler.stop();
_globals->_sceneManager.changeScene(1500);
break;
@@ -779,7 +780,7 @@ void Scene1400::postInit(SceneObjectList *OwnerList) {
_globals->_sceneOffset.y = (_globals->_sceneManager._scene->_sceneBounds.top / 100) * 100;
setAction(&_action1);
- _globals->_soundHandler.startSound(118);
+ _globals->_soundHandler.play(118);
}
/*--------------------------------------------------------------------------
@@ -842,7 +843,7 @@ void Scene1500::Action1::signal() {
setDelay(30);
break;
case 6:
- scene->_soundHandler.startSound(123);
+ scene->_soundHandler.play(123);
scene->_object1.setStrip2(4);
scene->_object1.setFrame(1);
scene->_object1.animate(ANIM_MODE_5, this);
@@ -850,13 +851,13 @@ void Scene1500::Action1::signal() {
case 7:
scene->_object1.setStrip2(5);
scene->_object1.animate(ANIM_MODE_2, NULL);
- scene->_soundHandler.startSound(124, this);
+ scene->_soundHandler.play(124, this);
break;
case 8:
- _globals->_soundHandler.startSound(126, this);
+ _globals->_soundHandler.play(126, this);
break;
case 9:
- _globals->_soundHandler.startSound(127);
+ _globals->_soundHandler.play(127);
_globals->_sceneManager.changeScene(2000);
break;
}
@@ -893,7 +894,7 @@ void Scene1500::Action2::signal() {
break;
}
case 3:
- scene->_soundHandler.proc4();
+ scene->_soundHandler.release();
_globals->_stripNum = 1505;
_globals->_sceneManager.changeScene(2400);
break;
@@ -907,7 +908,7 @@ void Scene1500::postInit(SceneObjectList *OwnerList) {
Scene::postInit();
if ((_globals->_stripNum == 1500) || ((_globals->_stripNum != 1504) && (_globals->_stripNum != 2751))) {
- _globals->_soundHandler.startSound(120);
+ _globals->_soundHandler.play(120);
setZoomPercents(105, 20, 145, 100);
setAction(&_action1);
diff --git a/engines/tsage/ringworld_scenes2.h b/engines/tsage/ringworld_scenes2.h
index 7731b45ae8..93a8f04fd4 100644
--- a/engines/tsage/ringworld_scenes2.h
+++ b/engines/tsage/ringworld_scenes2.h
@@ -72,7 +72,7 @@ public:
Action1 _action1;
SceneObject _object1, _object2, _object3, _object4;
SceneObject _object5, _object6, _object7;
- SoundHandler _soundHandler1, _soundHandler2;
+ ASound _soundHandler1, _soundHandler2;
virtual void postInit(SceneObjectList *OwnerList = NULL);
};
@@ -134,7 +134,7 @@ public:
virtual void signal();
};
public:
- SoundHandler _soundHandler;
+ ASound _soundHandler;
Action1 _action1;
Action2 _action2;
SceneObject _object1, _object2, _object3;
diff --git a/engines/tsage/ringworld_scenes3.cpp b/engines/tsage/ringworld_scenes3.cpp
index a19f15eca6..5d2732d36c 100644
--- a/engines/tsage/ringworld_scenes3.cpp
+++ b/engines/tsage/ringworld_scenes3.cpp
@@ -129,11 +129,11 @@ void Scene2000::Action6::signal() {
setDelay(130);
break;
case 1:
- scene->_soundHandler2.startSound(79);
+ scene->_soundHandler2.play(79);
scene->_stripManager.start(2000, this);
break;
case 2:
- _globals->_soundHandler.startSound(81);
+ _globals->_soundHandler.play(81);
scene->_object6.postInit();
scene->_object6.setVisage(2003);
scene->_object6.setAction(NULL);
@@ -148,7 +148,7 @@ void Scene2000::Action6::signal() {
scene->_object6.animate(ANIM_MODE_6, this);
break;
case 5:
- _globals->_soundHandler.startSound(80);
+ _globals->_soundHandler.play(80);
scene->_object6.remove();
_globals->_sceneManager.changeScene(1001);
break;
@@ -308,12 +308,12 @@ void Scene2000::Action14::signal() {
setDelay(60);
break;
case 3:
- _globals->_soundHandler.startSound(99);
+ _globals->_soundHandler.play(99);
scene->_object8.show();
scene->_object8.animate(ANIM_MODE_5, this);
break;
case 4:
- _globals->_soundHandler.startSound(12);
+ _globals->_soundHandler.play(12);
scene->_object8.setStrip(2);
scene->_object8.setFrame(1);
scene->_object9.show();
@@ -324,7 +324,7 @@ void Scene2000::Action14::signal() {
scene->_stripManager.start(2001, this, scene);
break;
case 6:
- _globals->_soundHandler.proc1(0/* was false */);
+ _globals->_soundHandler.fadeOut(0/* was false */);
scene->_object8.setStrip(1);
scene->_object8.setFrame(scene->_object8.getFrameCount());
scene->_object8.animate(ANIM_MODE_6, this);
@@ -333,7 +333,7 @@ void Scene2000::Action14::signal() {
scene->_object10.remove();
break;
case 7:
- _globals->_soundHandler.startSound(111);
+ _globals->_soundHandler.play(111);
scene->_object8.remove();
setDelay(5);
break;
@@ -425,11 +425,11 @@ void Scene2000::postInit(SceneObjectList *OwnerList) {
setAction(&_action13);
break;
case 2200:
- _globals->_soundHandler.startSound(111);
+ _globals->_soundHandler.play(111);
setAction(&_action14);
break;
case 2222:
- _globals->_soundHandler.startSound(115);
+ _globals->_soundHandler.play(115);
setAction(&_action8);
break;
case 3500:
@@ -437,12 +437,12 @@ void Scene2000::postInit(SceneObjectList *OwnerList) {
break;
default:
_object6.remove();
- _globals->_soundHandler.startSound(80);
+ _globals->_soundHandler.play(80);
setAction(&_action6);
break;
}
- _soundHandler1.startSound(78);
+ _soundHandler1.play(78);
_globals->_sceneManager._scene->_sceneBounds.contain(_globals->_sceneManager._scene->_backgroundBounds);
_globals->_sceneOffset.x = (_globals->_sceneManager._scene->_sceneBounds.left / 160) * 160;
}
@@ -502,7 +502,7 @@ void Scene2100::Action1::signal() {
break;
}
case 2:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_5, this);
break;
case 3: {
@@ -551,7 +551,7 @@ void Scene2100::Action1::signal() {
}
}
- scene->_soundHandler.startSound(161);
+ scene->_soundHandler.play(161);
scene->_area1.restore();
scene->_area2.restore();
scene->_area3.restore();
@@ -560,7 +560,7 @@ void Scene2100::Action1::signal() {
if (_state == 2100) {
setDelay(1);
} else {
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_6, this);
}
break;
@@ -576,7 +576,7 @@ void Scene2100::Action1::signal() {
break;
case 7:
_globals->_player.fixPriority(-1);
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_6, this);
break;
case 8:
@@ -776,17 +776,17 @@ void Scene2100::Action9::signal() {
scene->_stripManager.start(6050, this);
break;
case 2:
- scene->_soundHandler.startSound(99);
+ scene->_soundHandler.play(99);
scene->_object4.show();
scene->_object4.animate(ANIM_MODE_5, this);
break;
case 3:
- scene->_soundHandler.startSound(12);
+ scene->_soundHandler.play(12);
scene->_object4.setStrip(2);
scene->_stripManager.start(6051, this, scene);
break;
case 4:
- scene->_soundHandler.proc1(0/* was false */);
+ scene->_soundHandler.fadeOut(0/* was false */);
scene->_object4.setStrip(1);
scene->_object4.setFrame(scene->_object4.getFrameCount());
scene->_object4.animate(ANIM_MODE_6, this);
@@ -847,7 +847,7 @@ void Scene2100::Action10::signal() {
break;
}
case 5:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_5, this);
break;
case 6: {
@@ -880,7 +880,7 @@ void Scene2100::Action10::signal() {
setDelay(45);
break;
case 9:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_6, this);
break;
case 10:
@@ -924,7 +924,7 @@ void Scene2100::Action11::signal() {
break;
}
case 3:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_5, this);
break;
case 4: {
@@ -945,7 +945,7 @@ void Scene2100::Action11::signal() {
setDelay(45);
break;
case 6:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_6, this);
break;
case 7:
@@ -970,7 +970,7 @@ void Scene2100::Action12::signal() {
scene->_stripManager.start(6000, this);
break;
case 2:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_5, this);
break;
case 3: {
@@ -984,7 +984,7 @@ void Scene2100::Action12::signal() {
break;
}
case 4: {
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_6, NULL);
_globals->_player.fixPriority(-1);
@@ -1096,7 +1096,7 @@ void Scene2100::Action14::signal() {
scene->_stripManager.start(6008, this);
break;
case 4:
- scene->_soundHandler.startSound(99);
+ scene->_soundHandler.play(99);
scene->_object4.show();
scene->_object4.animate(ANIM_MODE_5, this);
break;
@@ -1105,7 +1105,7 @@ void Scene2100::Action14::signal() {
scene->_stripManager.start(6009, this, scene);
break;
case 6:
- scene->_soundHandler.proc1(0/* was false */);
+ scene->_soundHandler.fadeOut(0/* was false */);
scene->_object4.setStrip(1);
scene->_object4.setFrame(scene->_object4.getFrameCount());
scene->_object4.animate(ANIM_MODE_6, this);
@@ -1136,7 +1136,7 @@ void Scene2100::Action14::signal() {
break;
}
case 10:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_5, this);
break;
case 11: {
@@ -1151,7 +1151,7 @@ void Scene2100::Action14::signal() {
break;
case 13:
scene->_object3.fixPriority(1);
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_6, this);
break;
case 14:
@@ -1180,7 +1180,7 @@ void Scene2100::Action15::signal() {
scene->_object3.fixPriority(1);
scene->_object3.changeZoom(-1);
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_5, this);
break;
case 2: {
@@ -1191,7 +1191,7 @@ void Scene2100::Action15::signal() {
break;
}
case 3: {
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_6, this);
Common::Point pt(272, 140);
@@ -1251,7 +1251,7 @@ void Scene2100::Action16::signal() {
break;
}
case 5:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_5, this);
break;
case 6: {
@@ -1266,7 +1266,7 @@ void Scene2100::Action16::signal() {
setDelay(45);
break;
case 8:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_object1.animate(ANIM_MODE_6, this);
break;
case 9:
@@ -1295,17 +1295,17 @@ void Scene2100::Action17::signal() {
scene->_stripManager.start(7070, this);
break;
case 4:
- scene->_soundHandler.startSound(99);
+ scene->_soundHandler.play(99);
scene->_object4.show();
scene->_object4.animate(ANIM_MODE_5, this);
break;
case 5:
- scene->_soundHandler.startSound(12);
+ scene->_soundHandler.play(12);
scene->_object4.setStrip(2);
scene->_stripManager.start(7071, this, scene);
break;
case 6:
- scene->_soundHandler.proc1(NULL);
+ scene->_soundHandler.fadeOut(NULL);
scene->_object4.setStrip(1);
scene->_object4.setFrame(scene->_object4.getFrameCount());
scene->_object4.animate(ANIM_MODE_6, this);
@@ -1690,8 +1690,8 @@ void Scene2100::postInit(SceneObjectList *OwnerList) {
switch (_globals->_sceneManager._previousScene) {
case 2120:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
_object1.fixPriority(-1);
_globals->_player.fixPriority(-1);
_globals->_player.setPosition(Common::Point(80, 66));
@@ -1759,8 +1759,8 @@ void Scene2100::postInit(SceneObjectList *OwnerList) {
}
break;
case 3700:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
Scene::setZoomPercents(80, 75, 100, 90);
if (_globals->_sceneObjects->contains(&_object2))
@@ -1778,8 +1778,8 @@ void Scene2100::postInit(SceneObjectList *OwnerList) {
setAction(&_sequenceManager, this, 2105, &_object3, NULL);
break;
case 4250:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
_globals->clearFlag(43);
_globals->_player.setVisage(2104);
@@ -1797,8 +1797,8 @@ void Scene2100::postInit(SceneObjectList *OwnerList) {
setAction(&_sequenceManager, this, 2107, &_object4, NULL);
break;
case 5000:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
if (_globals->_sceneObjects->contains(&_object2))
_object2.remove();
@@ -1814,8 +1814,8 @@ void Scene2100::postInit(SceneObjectList *OwnerList) {
setAction(&_action5);
break;
case 5100:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
_globals->_player.setVisage(2104);
_globals->_player.setFrame(1);
_globals->_player.setPosition(Common::Point(65, 149));
@@ -1833,8 +1833,8 @@ void Scene2100::postInit(SceneObjectList *OwnerList) {
setAction(&_action9);
break;
case 7000:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
if (RING_INVENTORY._stasisBox2._sceneNumber == 1) {
_globals->_player.fixPriority(1);
@@ -1861,8 +1861,8 @@ void Scene2100::postInit(SceneObjectList *OwnerList) {
}
break;
case 7600:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
if (_globals->_sceneObjects->contains(&_object2))
_object2.remove();
@@ -1873,8 +1873,8 @@ void Scene2100::postInit(SceneObjectList *OwnerList) {
setAction(&_action8);
break;
case 8100:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
_globals->_player.setVisage(2104);
_globals->_player.setFrame(1);
@@ -1886,8 +1886,8 @@ void Scene2100::postInit(SceneObjectList *OwnerList) {
setAction(&_sequenceManager, this, 2106, NULL);
break;
case 9750:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
_globals->_player.setVisage(2104);
_globals->_player.setFrame(1);
@@ -1904,8 +1904,8 @@ void Scene2100::postInit(SceneObjectList *OwnerList) {
setAction(&_sequenceManager, this, 2103, &_object4, NULL);
break;
default:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
_globals->_player._uiEnabled = true;
break;
@@ -2074,7 +2074,7 @@ void Scene2120::Action1::dispatch() {
_actionIndex = !_entries[scene->_subjectIndex]._visage ? 4 : 3;
setDelay(30);
- scene->_soundHandler.startSound(159);
+ scene->_soundHandler.play(159);
}
// Next Page button handling
@@ -2105,7 +2105,7 @@ void Scene2120::Action1::dispatch() {
setDelay(30);
}
- scene->_soundHandler.startSound(159);
+ scene->_soundHandler.play(159);
}
// Previous Page button handling
@@ -2132,7 +2132,7 @@ void Scene2120::Action1::dispatch() {
break;
}
- scene->_soundHandler.startSound(159);
+ scene->_soundHandler.play(159);
}
// Exit button handling
@@ -2162,7 +2162,7 @@ void Scene2120::Action1::dispatch() {
setDelay(1);
}
- scene->_soundHandler.startSound(159);
+ scene->_soundHandler.play(159);
}
}
@@ -2232,7 +2232,7 @@ void Scene2150::Action1::signal() {
break;
}
case 1:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_hotspot1.animate(ANIM_MODE_5, this);
break;
case 2: {
@@ -2282,7 +2282,7 @@ void Scene2150::Action1::signal() {
}
}
- scene->_soundHandler.startSound(161);
+ scene->_soundHandler.play(161);
scene->_area1.restore();
scene->_area2.restore();
scene->_area3.restore();
@@ -2291,7 +2291,7 @@ void Scene2150::Action1::signal() {
if (_state == 2150) {
setDelay(1);
} else {
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_hotspot1.animate(ANIM_MODE_6, this);
}
break;
@@ -2306,7 +2306,7 @@ void Scene2150::Action1::signal() {
}
break;
case 6:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_hotspot1.animate(ANIM_MODE_6, this);
break;
case 7:
@@ -2333,10 +2333,10 @@ void Scene2150::Action2::signal() {
_globals->_player.setStrip(8);
_globals->_player.animate(ANIM_MODE_8, 1, this);
- scene->_soundHandler.startSound(163);
+ scene->_soundHandler.play(163);
break;
case 2:
- scene->_soundHandler.startSound(164);
+ scene->_soundHandler.play(164);
scene->_hotspot10.animate(ANIM_MODE_5, this);
break;
case 3:
@@ -2361,7 +2361,7 @@ void Scene2150::Action2::signal() {
_globals->_player.animate(ANIM_MODE_5, this);
break;
case 5:
- scene->_soundHandler.startSound(164);
+ scene->_soundHandler.play(164);
scene->_hotspot10.animate(ANIM_MODE_6, NULL);
scene->_hotspot14.remove();
@@ -2559,8 +2559,8 @@ void Scene2150::postInit(SceneObjectList *OwnerList) {
switch (_globals->_sceneManager._previousScene) {
case 2120:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
_globals->_player.setPosition(Common::Point(108, 99));
break;
case 2200:
@@ -2709,7 +2709,7 @@ void Scene2200::Action3::signal() {
switch (_actionIndex++) {
case 0: {
- scene->_soundHandler2.startSound(103);
+ scene->_soundHandler2.play(103);
scene->_hotspot4.setStrip(4);
scene->_hotspot4.animate(ANIM_MODE_NONE, NULL);
@@ -2726,7 +2726,7 @@ void Scene2200::Action3::signal() {
break;
}
case 1:
- scene->_soundHandler2.startSound(104);
+ scene->_soundHandler2.play(104);
scene->_hotspot4.setStrip(2);
scene->_hotspot4.setFrame(2);
setDelay(120);
@@ -2882,7 +2882,7 @@ void Scene2200::Hotspot9::doAction(int action) {
break;
case OBJECT_INFODISK:
if (_globals->_sceneManager._previousScene == 2310) {
- scene->_soundHandler2.startSound(35);
+ scene->_soundHandler2.play(35);
_globals->_player.disableControl();
scene->setAction(&scene->_action3);
}
@@ -2943,8 +2943,8 @@ void Scene2200::postInit(SceneObjectList *OwnerList) {
_hotspot8.remove();
break;
case 4000:
- _globals->_soundHandler.startSound(100);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(100);
+ _globals->_soundHandler.holdAt(true);
_globals->_player.remove();
_hotspot5.remove();
_hotspot8.remove();
@@ -2984,9 +2984,9 @@ void Scene2200::postInit(SceneObjectList *OwnerList) {
_hotspot4.fixPriority(255);
_globals->_sceneItems.push_back(&_hotspot4);
- _soundHandler1.startSound(101);
- _soundHandler2.startSound(100);
- _globals->_soundHandler.proc5(true);
+ _soundHandler1.play(101);
+ _soundHandler2.play(100);
+ _globals->_soundHandler.holdAt(true);
_globals->_sceneItems.push_back(&_hotspot5);
setAction(&_action2);
@@ -3139,7 +3139,7 @@ void Scene2222::postInit(SceneObjectList *OwnerList) {
setAction(&_action1);
}
- _soundHandler.startSound(116);
+ _soundHandler.play(116);
_globals->_sceneManager._scene->_sceneBounds.center(_hotspot1._position);
_globals->_sceneManager._scene->_sceneBounds.contain(_globals->_sceneManager._scene->_backgroundBounds);
@@ -3225,7 +3225,7 @@ void Scene2230::Action2::signal() {
_globals->_player.animate(ANIM_MODE_5, this);
break;
case 3:
- scene->_soundHandler.startSound(157);
+ scene->_soundHandler.play(157);
_globals->_player._moveDiff = Common::Point(1, 1);
_globals->_player.setAction(&scene->_action4);
_globals->_player._uiEnabled = true;
@@ -3249,7 +3249,7 @@ void Scene2230::Action3::signal() {
NpcMover *mover = new NpcMover();
_globals->_player.addMover(mover, &pt, this);
- scene->_soundHandler.proc3();
+ scene->_soundHandler.stop();
break;
}
case 1:
@@ -3368,7 +3368,7 @@ void Scene2230::Action7::signal() {
break;
}
case 2: {
- scene->_soundHandler.startSound(158);
+ scene->_soundHandler.play(158);
scene->_hotspot8.setStrip2(2);
Common::Point pt(scene->_hotspot8._position.x, 97);
@@ -3451,7 +3451,7 @@ void Scene2230::Action8::signal() {
scene->_hotspot2.animate(ANIM_MODE_6, this);
break;
case 4: {
- scene->_soundHandler.startSound(158);
+ scene->_soundHandler.play(158);
scene->_hotspot2.remove();
scene->_hotspot8._frame = 1;
@@ -3774,7 +3774,7 @@ void Scene2280::Action1::signal() {
break;
}
case 1:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_hotspot16.animate(ANIM_MODE_5, this);
break;
case 2: {
@@ -3789,7 +3789,7 @@ void Scene2280::Action1::signal() {
break;
case 4:
_globals->_player.fixPriority(1);
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_hotspot16.animate(ANIM_MODE_6, this);
break;
case 5:
@@ -3810,7 +3810,7 @@ void Scene2280::Action2::signal() {
break;
}
case 1:
- scene->_soundHandler.startSound(265);
+ scene->_soundHandler.play(265);
_globals->_player.setVisage(2162);
_globals->_player._frame = 1;
@@ -3830,7 +3830,7 @@ void Scene2280::Action2::signal() {
scene->_hotspot12.remove();
break;
case 4:
- scene->_soundHandler.startSound(266);
+ scene->_soundHandler.play(266);
_globals->_player.setVisage(2170);
_globals->_player._frame = 1;
_globals->_player._strip = 4;
@@ -3858,7 +3858,7 @@ void Scene2280::Action3::signal() {
break;
}
case 1:
- scene->_soundHandler.startSound(265);
+ scene->_soundHandler.play(265);
_globals->_player.setVisage(2162);
_globals->_player._frame = 6;
@@ -4338,8 +4338,8 @@ void Scene2280::postInit(SceneObjectList *OwnerList) {
_sceneMode = 2281;
setAction(&_sequenceManager, this, 2281, &_globals->_player, &_hotspot16, NULL);
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
}
_globals->_sceneItems.addItems(&_hotspot13, &_hotspot11, &_hotspot9, &_hotspot14, &_hotspot7,
@@ -4390,7 +4390,7 @@ void Scene2300::Action1::signal() {
}
case 2: {
scene->_hotspot8.setAction(&scene->_action4);
- scene->_soundHandler2.startSound(21);
+ scene->_soundHandler2.play(21);
Common::Point pt1(95, scene->_hotspot5._position.y);
NpcMover *mover1 = new NpcMover();
@@ -4428,7 +4428,7 @@ void Scene2300::Action1::signal() {
break;
}
case 6:
- scene->_soundHandler1.startSound(28);
+ scene->_soundHandler1.play(28);
_globals->_player.disableControl();
scene->_hotspot2.setVisage(40);
@@ -4442,7 +4442,7 @@ void Scene2300::Action1::signal() {
_globals->_player.animate(ANIM_MODE_5, this);
break;
case 7:
- _globals->_soundHandler.startSound(77, this);
+ _globals->_soundHandler.play(77, this);
break;
case 8:
_globals->_game->endGame(2300, 0);
@@ -4470,7 +4470,7 @@ void Scene2300::Action1::signal() {
_globals->_player.animate(ANIM_MODE_5, this);
break;
case 11:
- scene->_soundHandler1.startSound(28);
+ scene->_soundHandler1.play(28);
scene->_hotspot5._strip = 2;
scene->_hotspot6._strip = 2;
@@ -4487,7 +4487,7 @@ void Scene2300::Action1::signal() {
_globals->_player.animate(ANIM_MODE_6, this);
break;
case 12:
- scene->_soundHandler1.startSound(77);
+ scene->_soundHandler1.play(77);
_globals->_player.setVisage(0);
_globals->_player.animate(ANIM_MODE_1, NULL);
_globals->_player.setStrip(4);
@@ -4565,8 +4565,8 @@ void Scene2300::Action2::signal() {
scene->_hotspot2.setFrame(1);
scene->_hotspot2.animate(ANIM_MODE_5, this);
- scene->_soundHandler1.startSound(28);
- scene->_soundHandler2.startSound(97);
+ scene->_soundHandler1.play(28);
+ scene->_soundHandler2.play(97);
break;
case 7:
scene->_hotspot7._strip = 2;
@@ -4610,8 +4610,8 @@ void Scene2300::Action3::signal() {
_globals->_player.animate(ANIM_MODE_5, this);
break;
case 3:
- scene->_soundHandler1.startSound(97);
- scene->_soundHandler2.startSound(28);
+ scene->_soundHandler1.play(97);
+ scene->_soundHandler2.play(28);
scene->_hotspot7._strip = 2;
scene->_hotspot7._frame = 1;
@@ -4623,7 +4623,7 @@ void Scene2300::Action3::signal() {
_globals->_player.animate(ANIM_MODE_6, NULL);
break;
case 4:
- scene->_soundHandler2.startSound(97);
+ scene->_soundHandler2.play(97);
_globals->_player.setVisage(0);
_globals->_player.animate(ANIM_MODE_1, NULL);
_globals->_player.setStrip(1);
@@ -4645,7 +4645,7 @@ void Scene2300::Action4::signal() {
switch (_actionIndex++) {
case 0:
scene->_hotspot8.animate(ANIM_MODE_5, this);
- scene->_soundHandler1.startSound(11);
+ scene->_soundHandler1.play(11);
break;
case 1:
scene->_hotspot9.postInit();
@@ -4655,7 +4655,7 @@ void Scene2300::Action4::signal() {
scene->_hotspot9.setPosition(Common::Point(273, 199));
scene->_hotspot9.fixPriority(19);
scene->_hotspot9.animate(ANIM_MODE_5, this);
- scene->_soundHandler1.startSound(11);
+ scene->_soundHandler1.play(11);
break;
case 2:
scene->_hotspot8.remove();
@@ -4666,10 +4666,10 @@ void Scene2300::Action4::signal() {
scene->_hotspot10.setFrame(4);
scene->_hotspot10.setPosition(Common::Point(292, 113));
scene->_hotspot10.animate(ANIM_MODE_5, this);
- scene->_soundHandler1.startSound(11);
+ scene->_soundHandler1.play(11);
break;
case 3:
- scene->_soundHandler1.startSound(13);
+ scene->_soundHandler1.play(13);
remove();
break;
}
@@ -4747,7 +4747,7 @@ void Scene2300::postInit(SceneObjectList *OwnerList) {
_hotspot8.setVisage(2301);
_hotspot8.setPosition(Common::Point(288, 74));
- _globals->_soundHandler.startSound(96);
+ _globals->_soundHandler.play(96);
if (_globals->_sceneManager._previousScene == 2000) {
_hotspot8.remove();
@@ -4778,8 +4778,8 @@ void Scene2300::postInit(SceneObjectList *OwnerList) {
_hotspot7.setPosition(Common::Point(229, 125));
_hotspot7._numFrames = 5;
- _soundHandler1.startSound(95);
- _soundHandler2.startSound(96);
+ _soundHandler1.play(95);
+ _soundHandler2.play(96);
_globals->_sceneItems.push_back(&_hotspot7);
setAction(&_action2);
@@ -5062,7 +5062,7 @@ void Scene2320::Action2::signal() {
switch (_actionIndex++) {
case 0: {
- scene->_soundHandler.startSound(253);
+ scene->_soundHandler.play(253);
scene->_hotspot13.fixPriority(99);
Common::Point pt(scene->_hotspot13._position.x, 200);
@@ -5088,7 +5088,7 @@ void Scene2320::Action3::signal() {
break;
}
case 1:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_hotspot6.animate(ANIM_MODE_5, this);
break;
case 2: {
@@ -5137,7 +5137,7 @@ void Scene2320::Action3::signal() {
}
}
- scene->_soundHandler.startSound(161);
+ scene->_soundHandler.play(161);
scene->_area1.restore();
scene->_area2.restore();
scene->_area3.restore();
@@ -5146,7 +5146,7 @@ void Scene2320::Action3::signal() {
if (_state == 2320) {
setDelay(10);
} else {
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_hotspot6.animate(ANIM_MODE_6, this);
}
break;
@@ -5162,7 +5162,7 @@ void Scene2320::Action3::signal() {
break;
}
case 6:
- scene->_soundHandler.startSound(162);
+ scene->_soundHandler.play(162);
scene->_hotspot6.animate(ANIM_MODE_6, this);
break;
case 7:
@@ -5250,8 +5250,8 @@ void Scene2320::Action4::signal() {
break;
case 10:
if (_globals->getFlag(109)) {
- _globals->_soundHandler.startSound(40);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(40);
+ _globals->_soundHandler.holdAt(true);
Common::Point pt(303, 240);
NpcMover *mover = new NpcMover();
@@ -5311,7 +5311,7 @@ void Scene2320::Action4::signal() {
}
case 19: {
scene->_hotspot16.remove();
- scene->_soundHandler.startSound(253);
+ scene->_soundHandler.play(253);
scene->_hotspot13.show();
Common::Point pt(319, 157);
@@ -5462,7 +5462,7 @@ void Scene2320::Action7::signal() {
setDelay(30);
break;
case 1:
- _globals->_soundHandler.startSound(162);
+ _globals->_soundHandler.play(162);
scene->_hotspot6.animate(ANIM_MODE_5, this);
break;
case 2:
@@ -5889,8 +5889,8 @@ void Scene2320::postInit(SceneObjectList *OwnerList) {
switch (_globals->_sceneManager._previousScene) {
case 2120:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
_globals->_player.fixPriority(-1);
_globals->_player.setPosition(Common::Point(389, 72));
@@ -5907,8 +5907,8 @@ void Scene2320::postInit(SceneObjectList *OwnerList) {
case 4250:
case 5000:
case 7000:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
if ((_globals->_sceneManager._previousScene == 7000) && !_globals->getFlag(80))
_globals->setFlag(36);
@@ -5924,8 +5924,8 @@ void Scene2320::postInit(SceneObjectList *OwnerList) {
setAction(&_action6);
break;
case 6100:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
_hotspot8.postInit();
_hotspot8.setVisage(2345);
@@ -5936,9 +5936,9 @@ void Scene2320::postInit(SceneObjectList *OwnerList) {
setAction(&_sequenceManager1, this, 2325, &_globals->_player, &_hotspot6, &_hotspot8, &_hotspot7, NULL);
break;
case 7600:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
- _soundHandler.startSound(21);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
+ _soundHandler.play(21);
_globals->_player.setVisage(2323);
_globals->_player.setStrip(2);
@@ -5995,8 +5995,8 @@ void Scene2320::postInit(SceneObjectList *OwnerList) {
setAction(&_sequenceManager1, this, 2325, &_globals->_player, &_hotspot6, &_hotspot8, &_hotspot7, NULL);
break;
default:
- _globals->_soundHandler.startSound(160);
- _globals->_soundHandler.proc5(true);
+ _globals->_soundHandler.play(160);
+ _globals->_soundHandler.holdAt(true);
_sceneMode = 2321;
_globals->_player.setStrip(3);
@@ -6127,7 +6127,7 @@ void Scene2400::postInit(SceneObjectList *OwnerList) {
_globals->_sceneManager._scene->_sceneBounds.contain(_globals->_sceneManager._scene->_backgroundBounds);
_globals->_sceneOffset.x = (_globals->_sceneManager._scene->_sceneBounds.left / 160) * 160;
- _globals->_soundHandler.startSound(153);
+ _globals->_soundHandler.play(153);
}
} // End of namespace tSage
diff --git a/engines/tsage/ringworld_scenes3.h b/engines/tsage/ringworld_scenes3.h
index cc237a1f91..711360c190 100644
--- a/engines/tsage/ringworld_scenes3.h
+++ b/engines/tsage/ringworld_scenes3.h
@@ -114,7 +114,7 @@ public:
Action14 _action14;
SceneObject _object1, _object2, _object3, _object4, _object5;
SceneObject _object6, _object7, _object8, _object9, _object10;
- SoundHandler _soundHandler1, _soundHandler2;
+ ASound _soundHandler1, _soundHandler2;
virtual void postInit(SceneObjectList *OwnerList = NULL);
virtual void stripCallback(int v);
@@ -232,7 +232,7 @@ class Scene2100 : public Scene {
};
public:
SequenceManager _sequenceManager;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SpeakerMText _speakerMText;
SpeakerMR _speakerMR;
SpeakerQL _speakerQL;
@@ -311,7 +311,7 @@ class Scene2120 : public Scene {
};
public:
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SceneObject _topicArrowHotspot, _arrowHotspot, _visageHotspot;
SceneObject _subjectButton, _nextPageButton, _previousPageButton, _exitButton;
Action1 _action1;
@@ -359,7 +359,7 @@ class Scene2150 : public Scene {
virtual void doAction(int action);
};
public:
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SequenceManager _sequenceManager;
SpeakerGameText _speakerGameText;
@@ -440,7 +440,7 @@ public:
DisplayHotspot _hotspot10;
SceneObject _hotspot2, _hotspot4;
SceneObject _hotspot6, _hotspot7, _hotspot8;
- SoundHandler _soundHandler1, _soundHandler2;
+ ASound _soundHandler1, _soundHandler2;
Scene2200();
virtual void postInit(SceneObjectList *OwnerList = NULL);
@@ -462,7 +462,7 @@ class Scene2222 : public Scene {
};
public:
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SpeakerSText _speakerSText;
SpeakerMText _speakerMText;
SpeakerQText _speakerQText;
@@ -552,7 +552,7 @@ class Scene2230 : public Scene {
virtual void doAction(int action);
};
public:
- SoundHandler _soundHandler;
+ ASound _soundHandler;
Action1 _action1;
Action2 _action2;
Action3 _action3;
@@ -652,7 +652,7 @@ class Scene2280 : public Scene {
};
public:
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SequenceManager _sequenceManager;
Rect _exitRect;
Action1 _action1;
@@ -712,7 +712,7 @@ class Scene2300 : public Scene {
virtual void doAction(int action);
};
public:
- SoundHandler _soundHandler1, _soundHandler2;
+ ASound _soundHandler1, _soundHandler2;
SpeakerSL _speakerSL;
SpeakerMText _speakerMText;
SpeakerQText _speakerQText;
@@ -834,7 +834,7 @@ class Scene2320 : public Scene {
virtual void doAction(int action);
};
public:
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SequenceManager _sequenceManager1, _sequenceManager2;
SpeakerMText _speakerMText;
SpeakerMR _speakerMR;
diff --git a/engines/tsage/ringworld_scenes4.cpp b/engines/tsage/ringworld_scenes4.cpp
index 883da9b5b1..838769e4af 100644
--- a/engines/tsage/ringworld_scenes4.cpp
+++ b/engines/tsage/ringworld_scenes4.cpp
@@ -178,7 +178,7 @@ void Scene3700::Action1::signal() {
setDelay(90);
break;
case 3:
- scene->_soundHandler.startSound(196);
+ scene->_soundHandler.play(196);
scene->_viewer.hide();
scene->_hotspot1.postInit();
@@ -190,7 +190,7 @@ void Scene3700::Action1::signal() {
setDelay(90);
break;
case 4:
- scene->_soundHandler.startSound(197);
+ scene->_soundHandler.play(197);
scene->_hotspot1.hide();
scene->_hotspot2.postInit();
@@ -202,7 +202,7 @@ void Scene3700::Action1::signal() {
setDelay(30);
break;
case 5:
- scene->_soundHandler.startSound(198);
+ scene->_soundHandler.play(198);
scene->_hotspot2.hide();
scene->_hotspot1.show();
setDelay(90);
@@ -244,7 +244,7 @@ void Scene3700::postInit(tSage::SceneObjectList *OwnerList) {
_viewer.setPosition(Common::Point(195, 83));
setAction(&_action1);
- _globals->_soundHandler.startSound(195);
+ _globals->_soundHandler.play(195);
}
} // End of namespace tSage
diff --git a/engines/tsage/ringworld_scenes4.h b/engines/tsage/ringworld_scenes4.h
index 389c67b83a..0b575d02d3 100644
--- a/engines/tsage/ringworld_scenes4.h
+++ b/engines/tsage/ringworld_scenes4.h
@@ -82,7 +82,7 @@ public:
SpeakerSText _speakerSText;
SpeakerMText _speakerMText;
SpeakerMR _speakerMR;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
virtual void postInit(SceneObjectList *OwnerList = NULL);
};
diff --git a/engines/tsage/ringworld_scenes5.cpp b/engines/tsage/ringworld_scenes5.cpp
index 8b95e40abe..c884f9f6e4 100644
--- a/engines/tsage/ringworld_scenes5.cpp
+++ b/engines/tsage/ringworld_scenes5.cpp
@@ -102,7 +102,7 @@ void Scene4000::Action1::signal() {
ADD_MOVER_NULL(scene->_hotspot5, -40, 86);
break;
case 5:
- _globals->_soundHandler.startSound(155);
+ _globals->_soundHandler.play(155);
_globals->setFlag(43);
_globals->setFlag(114);
scene->_stripManager.start(4430, this);
@@ -354,14 +354,14 @@ void Scene4000::Action8::signal() {
setDelay(60);
break;
case 3:
- _globals->_soundHandler.startSound(170);
+ _globals->_soundHandler.play(170);
scene->_smoke2.setVisage(4000);
scene->_smoke2.setStrip(6);
scene->_smoke2.animate(ANIM_MODE_2, NULL);
setDelay(60);
break;
case 4:
- _globals->_soundHandler.startSound(77, this);
+ _globals->_soundHandler.play(77, this);
break;
case 5:
_globals->_game->endGame(4000, 15);
@@ -429,7 +429,7 @@ void Scene4000::Action11::signal() {
scene->_olo.animate(ANIM_MODE_1, NULL);
break;
case 5:
- scene->_soundHandler1.proc3();
+ scene->_soundHandler1.stop();
scene->_forceField.remove();
ADD_MOVER(_globals->_player, 340, 163);
@@ -494,12 +494,12 @@ void Scene4000::Action13::signal() {
setDelay(3);
break;
case 1:
- scene->_soundHandler2.startSound(151);
- scene->_soundHandler2.proc5(true);
+ scene->_soundHandler2.play(151);
+ scene->_soundHandler2.holdAt(true);
ADD_MOVER(scene->_lander, -30, 70);
break;
case 2:
- scene->_soundHandler2.proc4();
+ scene->_soundHandler2.release();
_globals->_sceneManager.changeScene(4010);
break;
}
@@ -867,7 +867,7 @@ void Scene4000::postInit(SceneObjectList *OwnerList) {
_theTech.setPosition(Common::Point(281, 176));
if (_globals->getFlag(34)) {
- _soundHandler1.startSound(156);
+ _soundHandler1.play(156);
_forceField.postInit();
_forceField.setVisage(4000);
@@ -900,7 +900,7 @@ void Scene4000::postInit(SceneObjectList *OwnerList) {
switch (_globals->_sceneManager._previousScene) {
case 2320:
- _globals->_soundHandler.startSound(155);
+ _globals->_soundHandler.play(155);
if (RING_INVENTORY._ale._sceneNumber == 1) {
_guardRock.postInit();
@@ -962,7 +962,7 @@ void Scene4000::postInit(SceneObjectList *OwnerList) {
}
if (_globals->_stripNum == 4025) {
- _soundHandler1.startSound(182);
+ _soundHandler1.play(182);
_forceField.remove();
_hotspot5.postInit();
@@ -1043,7 +1043,7 @@ void Scene4000::postInit(SceneObjectList *OwnerList) {
break;
case 4050:
- _globals->_soundHandler.startSound(155);
+ _globals->_soundHandler.play(155);
_globals->_player.disableControl();
if (_globals->_stripNum == 4050) {
@@ -1080,7 +1080,7 @@ void Scene4000::postInit(SceneObjectList *OwnerList) {
break;
default:
- _globals->_soundHandler.startSound(155);
+ _globals->_soundHandler.play(155);
_lander.postInit();
_lander.setVisage(4002);
@@ -1104,7 +1104,7 @@ void Scene4000::postInit(SceneObjectList *OwnerList) {
RING_INVENTORY._ladder._sceneNumber = 4100;
RING_INVENTORY._rope._sceneNumber = 4150;
- _soundHandler1.startSound(156);
+ _soundHandler1.play(156);
_forceField.postInit();
_forceField.setVisage(4000);
@@ -1243,8 +1243,8 @@ void Scene4000::dispatch() {
if ((RING_INVENTORY._peg._sceneNumber == 1) && _globals->getFlag(34) &&
_globals->getFlag(37) && !_globals->getFlag(40)) {
_globals->_player.disableControl();
- _soundHandler1.startSound(177);
- _globals->_soundHandler.startSound(178);
+ _soundHandler1.play(177);
+ _globals->_soundHandler.play(178);
setAction(&_action1);
}
@@ -1892,7 +1892,7 @@ void Scene4045::postInit(SceneObjectList *OwnerList) {
_olloFace.fixPriority(152);
if(_globals->_sceneManager._previousScene == 4050) {
- _globals->_soundHandler.startSound(155);
+ _globals->_soundHandler.play(155);
_globals->_player.setPosition(Common::Point(72, 128));
_globals->_player.enableControl();
@@ -2273,7 +2273,7 @@ void Scene4050::postInit(SceneObjectList *OwnerList) {
_globals->_player.setStrip(2);
setAction(&_action2);
- _globals->_soundHandler.startSound(175);
+ _globals->_soundHandler.play(175);
} else {
// Without the rope
_globals->_player.setVisage(5315);
@@ -2284,7 +2284,7 @@ void Scene4050::postInit(SceneObjectList *OwnerList) {
_globals->_player.animate(ANIM_MODE_2, NULL);
setAction(&_action4);
- _globals->_soundHandler.startSound(176);
+ _globals->_soundHandler.play(176);
}
break;
case 4045:
@@ -2298,7 +2298,7 @@ void Scene4050::postInit(SceneObjectList *OwnerList) {
_globals->_player.setObjectWrapper(new SceneObjectWrapper());
_globals->_player.setPosition(Common::Point(193, 193));
- _globals->_soundHandler.startSound(175);
+ _globals->_soundHandler.play(175);
break;
default:
break;
@@ -2717,7 +2717,7 @@ void Scene4100::postInit(SceneObjectList *OwnerList) {
&_hotspot11, &_hotspot9, &_hotspot7, &_hotspot10, &_hotspot8, &_hotspot14, NULL);
if (_globals->_sceneManager._previousScene == 4150) {
- _globals->_soundHandler.startSound(155);
+ _globals->_soundHandler.play(155);
if (!_globals->getFlag(42)) {
_hotspot1.setVisage(4104);
@@ -3095,8 +3095,8 @@ void Scene4150::postInit(SceneObjectList *OwnerList) {
&_hotspot10, &_hotspot9, &_hotspot8, &_hotspot7, &_hotspot6, &_hotspot2,
&_hotspot5, NULL);
- _globals->_soundHandler.startSound(165);
- _soundHandler.startSound(311);
+ _globals->_soundHandler.play(165);
+ _soundHandler.play(311);
}
void Scene4150::signal() {
@@ -3110,8 +3110,8 @@ void Scene4150::dispatch() {
Scene::dispatch();
if (!_action && (_globals->_player._position.x >= 316)) {
- _globals->_soundHandler.proc1(NULL);
- _soundHandler.proc1(NULL);
+ _globals->_soundHandler.fadeOut(NULL);
+ _soundHandler.fadeOut(NULL);
_globals->_player.disableControl();
_sceneMode = 4152;
setAction(&_sequenceManager, this, 4152, &_globals->_player, NULL);
@@ -3414,7 +3414,7 @@ void Scene4250::Hotspot6::doAction(int action) {
SceneItem::display2(4250, (RING_INVENTORY._helmet._sceneNumber == 4250) ? 20 : 3);
break;
case OBJECT_HELMET:
- _globals->_soundHandler.startSound(354);
+ _globals->_soundHandler.play(354);
_globals->_player.disableControl();
RING_INVENTORY._helmet._sceneNumber = 4250;
@@ -3443,7 +3443,7 @@ void Scene4250::Hotspot6::doAction(int action) {
break;
case OBJECT_NULLIFIER:
if (RING_INVENTORY._helmet._sceneNumber == 4250) {
- _globals->_soundHandler.startSound(353);
+ _globals->_soundHandler.play(353);
_globals->_player.disableControl();
RING_INVENTORY._helmet._sceneNumber = 1;
@@ -3650,7 +3650,7 @@ void Scene4250::postInit(tSage::SceneObjectList *OwnerList) {
_hotspot7.setBounds(Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
_globals->_sceneItems.push_back(&_hotspot7);
- _globals->_soundHandler.startSound(185);
+ _globals->_soundHandler.play(185);
}
void Scene4250::signal() {
@@ -3683,7 +3683,7 @@ void Scene4250::signal() {
_globals->_player.enableControl();
break;
case 4259:
- _globals->_soundHandler.startSound(360);
+ _globals->_soundHandler.play(360);
_globals->_sceneManager.changeScene(9900);
break;
case 4261:
@@ -3751,36 +3751,36 @@ void Scene4300::Action1::signal() {
_globals->setFlag(56);
_globals->_scenePalette.addRotation(240, 254, -1);
scene->_hotspot7.animate(ANIM_MODE_6, this);
- _globals->_soundHandler.startSound(164);
+ _globals->_soundHandler.play(164);
break;
case 1:
- _globals->_soundHandler.startSound(340);
- scene->_soundHandler1.startSound(341);
+ _globals->_soundHandler.play(340);
+ scene->_soundHandler1.play(341);
scene->_hotspot1.remove();
setDelay(3);
break;
case 2:
- scene->_soundHandler1.startSound(341);
+ scene->_soundHandler1.play(341);
scene->_hotspot2.remove();
setDelay(6);
break;
case 3:
- scene->_soundHandler1.startSound(341);
+ scene->_soundHandler1.play(341);
scene->_hotspot3.remove();
setDelay(6);
break;
case 4:
- scene->_soundHandler1.startSound(341);
+ scene->_soundHandler1.play(341);
scene->_hotspot4.remove();
setDelay(12);
break;
case 5:
- scene->_soundHandler1.startSound(341);
+ scene->_soundHandler1.play(341);
scene->_hotspot5.remove();
setDelay(12);
break;
case 6:
- scene->_soundHandler1.startSound(341);
+ scene->_soundHandler1.play(341);
scene->_hotspot6.remove();
setDelay(60);
break;
@@ -3793,7 +3793,7 @@ void Scene4300::Action1::signal() {
scene->_stripManager.start(8015, this, scene);
break;
case 9:
- _globals->_soundHandler.startSound(350);
+ _globals->_soundHandler.play(350);
_globals->_sceneManager._fadeMode = FADEMODE_GRADUAL;
_globals->_events.setCursor(CURSOR_USE);
_globals->_player.enableControl();
@@ -3916,7 +3916,7 @@ void Scene4300::Hotspot10::doAction(int action) {
void Scene4300::Hotspot15::signal() {
Scene4300 *scene = (Scene4300 *)_globals->_sceneManager._scene;
- scene->_soundHandler2.startSound(345);
+ scene->_soundHandler2.play(345);
_strip = (_globals->_randomSource.getRandomNumber(6) < 2) ? 2 : 1;
if ((RING_INVENTORY._stasisBox2._sceneNumber == 4300) ||
@@ -3982,7 +3982,7 @@ void Scene4300::Hotspot17::doAction(int action) {
SceneItem::display2(4300, 26);
break;
case OBJECT_STASIS_BOX2:
- scene->_soundHandler1.startSound(352);
+ scene->_soundHandler1.play(352);
_globals->_events.setCursor(CURSOR_USE);
scene->_sceneMode = 4303;
@@ -4241,11 +4241,11 @@ void Scene4301::Action1::signal() {
switch (_actionIndex++) {
case 0:
- scene->_soundHandler.startSound(164);
+ scene->_soundHandler.play(164);
scene->_hotspot1.animate(ANIM_MODE_5, this);
break;
case 1:
- _globals->_soundHandler.startSound(335);
+ _globals->_soundHandler.play(335);
_globals->_events.setCursor(CURSOR_USE);
scene->_hotspot2.postInit();
@@ -4270,7 +4270,7 @@ void Scene4301::Action1::signal() {
case 10:
// Puzzle: Wrong code
_globals->_events.setCursor(CURSOR_NONE);
- scene->_soundHandler.startSound(337);
+ scene->_soundHandler.play(337);
if (scene->_hotspot3._flags & OBJFLAG_HIDE)
scene->_hotspot3.show();
else
@@ -4285,7 +4285,7 @@ void Scene4301::Action1::signal() {
for (_state = 0; _state < 6; ++_state)
_buttonList[_state].remove();
- scene->_soundHandler.startSound(338);
+ scene->_soundHandler.play(338);
scene->_hotspot3.hide();
_actionIndex = 2;
@@ -4295,7 +4295,7 @@ void Scene4301::Action1::signal() {
case 20:
// Puzzle: Correct code
_globals->_player.disableControl();
- scene->_soundHandler.startSound(339);
+ scene->_soundHandler.play(339);
scene->_hotspot3._frame = 3;
if (scene->_hotspot3._flags & OBJFLAG_HIDE)
scene->_hotspot3.show();
@@ -4329,7 +4329,7 @@ void Scene4301::Action1::process(Event &event) {
if ((event.eventType == EVENT_BUTTON_DOWN) && buttonsRect.contains(event.mousePos)) {
event.handled = true;
- scene->_soundHandler.startSound(336);
+ scene->_soundHandler.play(336);
int buttonIndex = ((event.mousePos.y - buttonsRect.top) / 33) * 3 +
((event.mousePos.x - buttonsRect.left) / 33);
diff --git a/engines/tsage/ringworld_scenes5.h b/engines/tsage/ringworld_scenes5.h
index a2991c7283..c3ae9f4aa9 100644
--- a/engines/tsage/ringworld_scenes5.h
+++ b/engines/tsage/ringworld_scenes5.h
@@ -134,7 +134,7 @@ class Scene4000 : public Scene {
};
public:
SequenceManager _sequenceManager1, _sequenceManager2, _sequenceManager3;
- SoundHandler _soundHandler1, _soundHandler2;
+ ASound _soundHandler1, _soundHandler2;
SpeakerQR _speakerQR;
SpeakerML _speakerML;
SpeakerMR _speakerMR;
@@ -471,7 +471,7 @@ class Scene4150 : public Scene {
public:
SequenceManager _sequenceManager;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SpeakerQText _speakerQText;
SpeakerQR _speakerQR;
SpeakerCDL _speakerCDL;
@@ -541,7 +541,7 @@ class Scene4250 : public Scene {
public:
SequenceManager _sequenceManager;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SpeakerSR _speakerSR;
SpeakerSL _speakerSL;
SpeakerSText _speakerSText;
@@ -613,7 +613,7 @@ class Scene4300 : public Scene {
virtual void doAction(int action);
};
public:
- SoundHandler _soundHandler1, _soundHandler2;
+ ASound _soundHandler1, _soundHandler2;
SequenceManager _sequenceManager;
GfxButton _gfxButton;
SpeakerQText _speakerQText;
@@ -672,7 +672,7 @@ class Scene4301 : public Scene {
public:
Common::List<int> _list1;
SequenceManager _sequenceManager;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
Action1 _action1;
SceneObject _hotspot1, _hotspot2, _hotspot3;
Hotspot4 _hotspot4;
diff --git a/engines/tsage/ringworld_scenes6.cpp b/engines/tsage/ringworld_scenes6.cpp
index 9e5766d656..68c184196c 100644
--- a/engines/tsage/ringworld_scenes6.cpp
+++ b/engines/tsage/ringworld_scenes6.cpp
@@ -41,8 +41,8 @@ void Scene5000::Action1::signal() {
setDelay(10);
break;
case 1:
- scene->_soundHandler.startSound(190);
- scene->_soundHandler.proc5(true);
+ scene->_soundHandler.play(190);
+ scene->_soundHandler.holdAt(true);
ADD_MOVER(scene->_hotspot1, 283, 12);
break;
case 2:
@@ -55,7 +55,7 @@ void Scene5000::Action1::signal() {
setDelay(15);
break;
case 4:
- scene->_soundHandler.proc4();
+ scene->_soundHandler.release();
ADD_MOVER(scene->_hotspot1, 233, 80);
break;
case 5:
@@ -561,7 +561,7 @@ void Scene5000::postInit(SceneObjectList *OwnerList) {
break;
}
- _globals->_soundHandler.startSound(190);
+ _globals->_soundHandler.play(190);
}
void Scene5000::signal() {
@@ -639,7 +639,7 @@ void Scene5100::Action1::signal() {
}
break;
case 4:
- scene->_soundHandler.startSound(206);
+ scene->_soundHandler.play(206);
scene->_hotspot5.postInit();
scene->_hotspot5.setVisage(5362);
@@ -740,7 +740,7 @@ void Scene5100::Action3::signal() {
_globals->_player.animate(ANIM_MODE_5, this);
break;
case 2:
- scene->_soundHandler.startSound(28);
+ scene->_soundHandler.play(28);
if (static_cast<SceneObject *>(_owner)->_position.x < _globals->_player._position.x) {
scene->_hotspot2.setVisage(5130);
scene->_hotspot2._strip = 1;
@@ -786,7 +786,7 @@ void Scene5100::Action4::signal() {
switch (_actionIndex++) {
case 0: {
_globals->_player.disableControl();
- scene->_soundHandler.startSound(208);
+ scene->_soundHandler.play(208);
SceneItem::display2(5100, 15);
ObjectMover3 *mover = new ObjectMover3();
@@ -1289,7 +1289,7 @@ void Scene5100::postInit(SceneObjectList *OwnerList) {
_globals->_sceneManager._scene->_sceneBounds.center(_globals->_player._position);
loadScene(5100);
- _globals->_soundHandler.startSound(205);
+ _globals->_soundHandler.play(205);
}
void Scene5100::signal() {
@@ -1385,7 +1385,7 @@ void Scene5100::dispatch() {
_globals->_player.disableControl();
_globals->_player.addMover(NULL);
- _soundHandler.startSound(207);
+ _soundHandler.play(207);
_sceneMode = 5103;
setAction(&_sequenceManager, this, (_globals->_player._position.x >= 966) ? 5104 : 5103,
&_globals->_player, &_hotspot15, NULL);
@@ -1396,7 +1396,7 @@ void Scene5100::dispatch() {
(_globals->_sceneManager._previousScene != 5200) && (_sceneMode != 5150)) {
setAction(NULL);
_sceneMode = 5150;
- _soundHandler.startSound(208);
+ _soundHandler.play(208);
if (RING_INVENTORY._vial._sceneNumber == 5100) {
_globals->_player.addMover(NULL);
@@ -1471,7 +1471,7 @@ void Scene5200::Action2::signal() {
_globals->_player.animate(ANIM_MODE_4, 3, 1, this);
break;
case 2:
- scene->_soundHandler.proc3();
+ scene->_soundHandler.stop();
scene->_hotspot14.remove();
RING_INVENTORY._stasisBox._sceneNumber = 1;
@@ -1486,7 +1486,7 @@ void Scene5200::Action2::signal() {
ADD_MOVER(scene->_hotspot8, 141, 77);
break;
case 4:
- scene->_soundHandler.startSound(303);
+ scene->_soundHandler.play(303);
scene->_hotspot8._strip = 2;
scene->_hotspot8._frame = 1;
@@ -1523,7 +1523,7 @@ void Scene5200::Action4::signal() {
setDelay(120);
break;
case 1:
- _globals->_soundHandler.startSound(209);
+ _globals->_soundHandler.play(209);
scene->_stripManager.start(5202, this, scene);
break;
case 2:
@@ -1622,8 +1622,8 @@ void Scene5200::postInit(SceneObjectList *OwnerList) {
_speakerQText._textPos.x = 20;
if (RING_INVENTORY._stasisBox._sceneNumber == 5200) {
- _soundHandler.startSound(216);
- _soundHandler.proc5(true);
+ _soundHandler.play(216);
+ _soundHandler.holdAt(true);
_hotspot14.postInit();
_hotspot14.setVisage(5202);
@@ -1643,7 +1643,7 @@ void Scene5200::postInit(SceneObjectList *OwnerList) {
// Happens when the player enters the throne room via the secret passage,
// after talking with the bat. No NPCs are around and the player can
// obtain the stasis box.
- _globals->_soundHandler.startSound(205);
+ _globals->_soundHandler.play(205);
_globals->_player.disableControl();
_globals->_player.postInit();
@@ -2131,7 +2131,7 @@ void Scene5300::postInit(SceneObjectList *OwnerList) {
_hotspot8._sceneRegionId = 8;
_globals->_sceneItems.addItems(&_hotspot8, &_hotspot2, &_hotspot6, &_hotspot3, &_hotspot7, NULL);
- _globals->_soundHandler.startSound(212);
+ _globals->_soundHandler.play(212);
}
void Scene5300::signal() {
@@ -2141,7 +2141,7 @@ void Scene5300::signal() {
_globals->_sceneManager.changeScene(5100);
break;
case 5307:
- _soundHandler.proc1(NULL);
+ _soundHandler.fadeOut(NULL);
// No break on purpose
case 5302:
case 5308:
diff --git a/engines/tsage/ringworld_scenes6.h b/engines/tsage/ringworld_scenes6.h
index 6ac73d4bff..2e99f5ab87 100644
--- a/engines/tsage/ringworld_scenes6.h
+++ b/engines/tsage/ringworld_scenes6.h
@@ -75,7 +75,7 @@ class Scene5000 : public Scene {
};
public:
SequenceManager _sequenceManager;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SpeakerSText _speakerSText;
SpeakerQText _speakerQText;
Action1 _action1;
@@ -163,7 +163,7 @@ class Scene5100 : public Scene {
};
public:
SequenceManager _sequenceManager;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SpeakerMText _speakerMText;
SpeakerQText _speakerQText;
SpeakerSText _speakerSText;
@@ -226,7 +226,7 @@ class Scene5200 : public Scene {
virtual void doAction(int action);
};
public:
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SpeakerFLL _speakerFLL;
SpeakerFLText _speakerFLText;
SpeakerQL _speakerQL;
@@ -291,7 +291,7 @@ class Scene5300 : public Scene {
virtual void doAction(int action);
};
public:
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SequenceManager _sequenceManager;
SpeakerQR _speakerQR;
SpeakerQL _speakerQL;
diff --git a/engines/tsage/ringworld_scenes8.cpp b/engines/tsage/ringworld_scenes8.cpp
index 934c7494fa..2b329b958a 100644
--- a/engines/tsage/ringworld_scenes8.cpp
+++ b/engines/tsage/ringworld_scenes8.cpp
@@ -60,7 +60,7 @@ void Scene7000::Action1::signal() {
setAction(&scene->_action6, this);
break;
case 2:
- scene->_soundHandler.startSound(252);
+ scene->_soundHandler.play(252);
scene->_object8.remove();
scene->_object1.postInit();
scene->_object1.setVisage(7003);
@@ -184,7 +184,7 @@ void Scene7000::Action4::signal() {
setDelay(300);
break;
case 2:
- _globals->_soundHandler.startSound(252);
+ _globals->_soundHandler.play(252);
scene->_object1.show();
scene->_object1.setStrip(3);
scene->_object1.setFrame(1);
@@ -214,7 +214,7 @@ void Scene7000::Action5::signal() {
}
case 1:
_globals->_player.checkAngle(&scene->_object1);
- _globals->_soundHandler.startSound(252);
+ _globals->_soundHandler.play(252);
scene->_object1.setStrip(2);
scene->_stripManager.start(7015, this);
break;
@@ -546,7 +546,7 @@ void Scene7000::postInit(SceneObjectList *OwnerList) {
_object1.animate(ANIM_MODE_8, 0, NULL);
_globals->_sceneItems.push_back(&_object1);
}
- _soundHandler.startSound(251);
+ _soundHandler.play(251);
if (_globals->_sceneManager._previousScene == 2100) {
if (_globals->getFlag(72)) {
_globals->_player.postInit();
@@ -565,7 +565,7 @@ void Scene7000::postInit(SceneObjectList *OwnerList) {
setAction(&_action1);
}
} else {
- _globals->_soundHandler.startSound(250);
+ _globals->_soundHandler.play(250);
_globals->setFlag(72);
_object3.postInit();
@@ -611,9 +611,9 @@ void Scene7000::postInit(SceneObjectList *OwnerList) {
_object3.setVisage(5001);
_object3.setStrip2(1);
_object3.setPosition(Common::Point(307, 0));
- _soundHandler.startSound(151);
- _soundHandler.proc5(1);
- _globals->_soundHandler.startSound(250);
+ _soundHandler.play(151);
+ _soundHandler.holdAt(true);
+ _globals->_soundHandler.play(250);
setAction(&_action3);
}
@@ -1135,9 +1135,9 @@ void Scene7100::postInit(SceneObjectList *OwnerList) {
_object1.setPosition(Common::Point(100, 100));
setAction(&_action11);
- _soundHandler1.startSound(270);
- _soundHandler2.startSound(275);
- _globals->_soundHandler.startSound(270);
+ _soundHandler1.play(270);
+ _soundHandler2.play(275);
+ _globals->_soundHandler.play(270);
}
/*--------------------------------------------------------------------------
* Scene 7200 - Underwater: Entering the cave
@@ -1302,7 +1302,7 @@ void Scene7200::postInit(SceneObjectList *OwnerList) {
_swimmer.setPosition(Common::Point(-8, 16));
setAction(&_action1);
- _soundHandler.startSound(271);
+ _soundHandler.play(271);
}
/*--------------------------------------------------------------------------
@@ -1344,7 +1344,7 @@ void Scene7300::Action1::signal() {
break;
case 7:
setDelay(3);
- _globals->_soundHandler.proc1(NULL);
+ _globals->_soundHandler.fadeOut(NULL);
break;
case 8:
_globals->_sceneManager.changeScene(2280);
@@ -1497,7 +1497,7 @@ void Scene7300::postInit(SceneObjectList *OwnerList) {
_object8._numFrames = 2;
setAction(&_action1);
- _globals->_soundHandler.startSound(272);
+ _globals->_soundHandler.play(272);
}
/*--------------------------------------------------------------------------
@@ -1601,8 +1601,8 @@ void Scene7600::postInit(SceneObjectList *OwnerList) {
}
_sceneBounds.center(_globals->_player._position.x, _globals->_player._position.y);
loadScene(7600);
- _soundHandler2.startSound(255);
- _soundHandler1.startSound(251);
+ _soundHandler2.play(255);
+ _soundHandler1.play(251);
}
/*--------------------------------------------------------------------------
@@ -1665,7 +1665,7 @@ void Scene7700::Action3::signal() {
setDelay(60);
// No break on purpose!
case 2:
- scene->_soundHandler.startSound(260);
+ scene->_soundHandler.play(260);
scene->_object8.setVisage(7703);
scene->_object8.setPosition(Common::Point(177, 97));
scene->_object8.setStrip2(3);
@@ -1874,7 +1874,7 @@ void Scene7700::SceneHotspot8::doAction(int action) {
break;
case CURSOR_USE:
scene->_sceneMode = 7709;
- scene->_soundHandler.startSound(259);
+ scene->_soundHandler.play(259);
scene->_object15.setFrame(scene->_object15.getFrameCount());
scene->_object15.animate(ANIM_MODE_6, scene);
if ((scene->_field977 == 2) && (scene->_field97B == 0)) {
@@ -1900,7 +1900,7 @@ void Scene7700::SceneHotspot9::doAction(int action) {
break;
case CURSOR_USE:
scene->_sceneMode = 7709;
- scene->_soundHandler.startSound(259);
+ scene->_soundHandler.play(259);
scene->_object15.setFrame(1);
scene->_object15.animate(ANIM_MODE_5, scene);
if (scene->_field977 > 2) {
@@ -2034,7 +2034,7 @@ void Scene7700::Object7::doAction(int action) {
break;
case OBJECT_STUNNER:
if (!_globals->getFlag(78)) {
- _globals->_soundHandler.proc3();
+ _globals->_soundHandler.stop();
_globals->setFlag(78);
setAction(NULL);
_globals->_player.disableControl();
@@ -2124,7 +2124,8 @@ void Scene7700::Object9::doAction(int action) {
_globals->_sceneItems.push_front(&scene->_object10);
scene->_object10.fixPriority(240);
}
- scene->_soundHandler.startSound(262);
+
+ scene->_soundHandler.play(262);
scene->_object14.animate(ANIM_MODE_5, NULL);
}
_globals->_events.setCursor(CURSOR_WALK);
@@ -2222,7 +2223,7 @@ void Scene7700::signal() {
}
break;
case 7702:
- _soundHandler.proc1(0);
+ _soundHandler.fadeOut(0);
_globals->_sceneManager.changeScene(7600);
break;
case 7703:
@@ -2233,7 +2234,7 @@ void Scene7700::signal() {
_globals->_player.enableControl();
break;
case 7704:
- _globals->_soundHandler.startSound(256);
+ _globals->_soundHandler.play(256);
_prof.setStrip2(4);
_prof.setFrame2(1);
_prof.setPosition(Common::Point(159, 87));
@@ -2520,7 +2521,7 @@ void Scene7700::postInit(SceneObjectList *OwnerList) {
_sceneMode = 7701;
setAction(&_sequenceManager, this, 7701, &_globals->_player, NULL);
- _soundHandler.startSound(256);
+ _soundHandler.play(256);
}
Scene7700::Scene7700() {
diff --git a/engines/tsage/ringworld_scenes8.h b/engines/tsage/ringworld_scenes8.h
index 8b183e895f..fe9560d9d8 100644
--- a/engines/tsage/ringworld_scenes8.h
+++ b/engines/tsage/ringworld_scenes8.h
@@ -94,7 +94,7 @@ class Scene7000 : public Scene {
};
public:
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SequenceManager _sequenceManager;
SpeakerSKText _speakerSKText;
SpeakerSKL _speakerSKL;
@@ -165,8 +165,8 @@ class Scene7100 : public Scene {
};
public:
- SoundHandler _soundHandler1;
- SoundHandler _soundHandler2;
+ ASound _soundHandler1;
+ ASound _soundHandler2;
SceneObject _object1;
SceneObject _object2;
SceneObject _object3;
@@ -230,7 +230,7 @@ public:
SceneObject _object7;
SceneObject _object8;
SceneObject _object9;
- SoundHandler _soundHandler;
+ ASound _soundHandler;
virtual void postInit(SceneObjectList *OwnerList = NULL);
};
@@ -296,8 +296,8 @@ public:
SceneObject _object4;
SceneObject _object5;
SceneObject _object6;
- SoundHandler _soundHandler1;
- SoundHandler _soundHandler2;
+ ASound _soundHandler1;
+ ASound _soundHandler2;
virtual void postInit(SceneObjectList *OwnerList = NULL);
};
@@ -409,7 +409,7 @@ class Scene7700 : public Scene {
virtual void doAction(int action);
};
public:
- SoundHandler _soundHandler;
+ ASound _soundHandler;
SequenceManager _sequenceManager;
GfxButton _gfxButton;
SpeakerEText _speakerEText;
diff --git a/engines/tsage/sound.cpp b/engines/tsage/sound.cpp
index defec1cebd..4494656d46 100644
--- a/engines/tsage/sound.cpp
+++ b/engines/tsage/sound.cpp
@@ -20,21 +20,471 @@
*
*/
+#include "common/config-manager.h"
#include "tsage/core.h"
#include "tsage/globals.h"
#include "tsage/debugger.h"
#include "tsage/graphics.h"
+#include "tsage/tsage.h"
namespace tSage {
+static SoundManager *_soundManager = NULL;
+
+/*--------------------------------------------------------------------------*/
+
+SoundManager::SoundManager() {
+ _soundManager = this;
+ __sndmgrReady = false;
+ _ourSndResVersion = 0x102;
+ _ourDrvResVersion = 0x10A;
+
+ for (int i = 0; i < SOUND_ARR_SIZE; ++i)
+ _voiceTypeStructPtrs[i] = NULL;
+
+ _groupsAvail = 0;
+ _masterVol = 127;
+ _serverSuspendedCount = 0;
+ _serverDisabledCount = 0;
+ _suspendedCount = 0;
+ _driversDetected = false;
+ _needToRethink = false;
+
+ _soTimeIndexFlag = false;
+}
+
+SoundManager::~SoundManager() {
+ if (__sndmgrReady) {
+ for (Common::List<Sound *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i)
+ (*i)->stop();
+ for (Common::List<SoundDriver *>::iterator i = _installedDrivers.begin(); i != _installedDrivers.end(); ) {
+ SoundDriver *driver = *i;
+ ++i;
+ delete driver;
+ }
+ _sfTerminate();
+ }
+
+ _soundManager = NULL;
+}
+
void SoundManager::postInit() {
- _saver->addSaveNotifier(&SoundManager::saveNotifier);
- _saver->addLoadNotifier(&SoundManager::loadNotifier);
- _saver->addListener(this);
+ if (!__sndmgrReady) {
+ _saver->addSaveNotifier(&SoundManager::saveNotifier);
+ _saver->addLoadNotifier(&SoundManager::loadNotifier);
+ _saver->addListener(this);
+ __sndmgrReady = true;
+ }
+}
+
+/**
+ * Loops through all the loaded sounds, and stops any that have been flagged for stopping
+ */
+void SoundManager::dispatch() {
+ Common::List<Sound *>::iterator i = _soundList.begin();
+ while (i != _soundList.end()) {
+ Sound *sound = *i;
+ ++i;
+
+ // If the sound is flagged for stopping, then stop it
+ if (sound->_stoppedAsynchronously) {
+ sound->stop();
+ }
+ }
+}
+
+void SoundManager::syncSounds() {
+ bool mute = false;
+ if (ConfMan.hasKey("mute"))
+ mute = ConfMan.getBool("mute");
+
+ bool music_mute = mute;
+ bool sfx_mute = mute;
+
+ if (!mute) {
+ music_mute = ConfMan.getBool("music_mute");
+ sfx_mute = ConfMan.getBool("sfx_mute");
+ }
+
+ // Get the new music and sfx volumes
+ int musicVolume = music_mute ? 0 : MIN(255, ConfMan.getInt("music_volume"));
+ int sfxVolume = sfx_mute ? 0 : MIN(255, ConfMan.getInt("sfx_volume"));
+
+ warning("Set volume music=%d sfx=%d", musicVolume, sfxVolume);
+ this->setMasterVol(musicVolume / 2);
+}
+
+Common::List<SoundDriverEntry> &SoundManager::buildDriverList(bool detectFlag) {
+ assert(__sndmgrReady);
+ _availableDrivers.clear();
+
+ // Build up a list of available drivers. Currently we only implement an Adlib driver
+ SoundDriverEntry sd;
+ sd.driverNum = ADLIB_DRIVER_NUM;
+ sd.status = detectFlag ? SNDSTATUS_DETECTED : SNDSTATUS_SKIPPED;
+ sd.field2 = 0;
+ sd.field6 = 15000;
+ sd.shortDescription = "Adlib or SoundBlaster";
+ sd.longDescription = "3812fm";
+ _availableDrivers.push_back(sd);
+
+ _driversDetected = true;
+ return _availableDrivers;
+}
+
+void SoundManager::installConfigDrivers() {
+ installDriver(ADLIB_DRIVER_NUM);
+}
+
+Common::List<SoundDriverEntry> &SoundManager::getDriverList(bool detectFlag) {
+ if (detectFlag)
+ return _availableDrivers;
+ else
+ return buildDriverList(false);
+}
+
+void SoundManager::dumpDriverList() {
+ _availableDrivers.clear();
+}
+
+void SoundManager::disableSoundServer() {
+ ++_serverDisabledCount;
+}
+
+void SoundManager::enableSoundServer() {
+ if (_serverDisabledCount > 0)
+ --_serverDisabledCount;
+}
+
+void SoundManager::suspendSoundServer() {
+ ++_serverSuspendedCount;
+}
+
+void SoundManager::restartSoundServer() {
+ if (_serverSuspendedCount > 0)
+ --_serverSuspendedCount;
+}
+
+/**
+ * Install the specified driver number
+ */
+void SoundManager::installDriver(int driverNum) {
+ // If driver is already installed, no need to install it
+ if (isInstalled(driverNum))
+ return;
+
+ // Instantiate the sound driver
+ SoundDriver *driver = instantiateDriver(driverNum);
+ if (!driver)
+ return;
+
+ assert((_ourDrvResVersion >= driver->_minVersion) && (_ourDrvResVersion <= driver->_maxVersion));
+
+ // Mute any loaded sounds
+ disableSoundServer();
+ for (Common::List<Sound *>::iterator i = _playList.begin(); i != _playList.end(); ++i)
+ (*i)->mute(true);
+
+ // Install the driver
+ if (!_sfInstallDriver(driver))
+ error("Sound driver initialization failed");
+
+ switch (driverNum) {
+ case ROLAND_DRIVER_NUM:
+ case ADLIB_DRIVER_NUM: {
+ // Handle loading bank infomation
+ byte *bankData = _resourceManager->getResource(RES_BANK, driverNum, 0, true);
+ if (bankData) {
+ // Install the patch bank data
+ _sfInstallPatchBank(driver, bankData);
+ DEALLOCATE(bankData);
+ } else {
+ // Could not locate patch bank data, so unload the driver
+ _sfUnInstallDriver(driver);
+
+ // Unmute currently active sounds
+ for (Common::List<Sound *>::iterator i = _playList.begin(); i != _playList.end(); ++i)
+ (*i)->mute(false);
+
+ enableSoundServer();
+ }
+ break;
+ }
+ }
+}
+
+/**
+ * Instantiate a driver class for the specified driver number
+ */
+SoundDriver *SoundManager::instantiateDriver(int driverNum) {
+ assert(driverNum == ADLIB_DRIVER_NUM);
+ return new AdlibSoundDriver();
+}
+
+/**
+ * Uninstall the specified driver
+ */
+void SoundManager::unInstallDriver(int driverNum) {
+ Common::List<SoundDriver *>::const_iterator i;
+ for (i = _installedDrivers.begin(); i != _installedDrivers.end(); ++i) {
+ if ((*i)->_driverResID == driverNum) {
+ // Found driver to remove
+
+ // Mute any loaded sounds
+ disableSoundServer();
+ for (Common::List<Sound *>::iterator i = _playList.begin(); i != _playList.end(); ++i)
+ (*i)->mute(true);
+
+ // Uninstall the driver
+ _sfUnInstallDriver(*i);
+
+ // Re-orient all the loaded sounds
+ for (Common::List<Sound *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i)
+ (*i)->orientAfterDriverChange();
+
+ // Unmute currently active sounds
+ for (Common::List<Sound *>::iterator i = _playList.begin(); i != _playList.end(); ++i)
+ (*i)->mute(false);
+
+ enableSoundServer();
+ }
+ }
+}
+
+/**
+ * Returns true if a specified driver number is currently installed
+ */
+bool SoundManager::isInstalled(int driverNum) const {
+ Common::List<SoundDriver *>::const_iterator i;
+ for (i = _installedDrivers.begin(); i != _installedDrivers.end(); ++i) {
+ if ((*i)->_driverResID == driverNum)
+ return true;
+ }
+
+ return false;
+}
+
+void SoundManager::setMasterVol(int volume) {
+ _sfSetMasterVol(volume);
+}
+
+int SoundManager::getMasterVol() const {
+ return _masterVol;
+}
+
+void SoundManager::loadSound(int soundNum, bool showErrors) {
+ // This method preloaded the data associated with a given sound, so is now redundant
+}
+
+void SoundManager::unloadSound(int soundNum) {
+ // This method signalled the resource manager to unload the data for a sound, and is now redundant
}
+int SoundManager::determineGroup(const byte *soundData) {
+ return _sfDetermineGroup(soundData);
+}
+
+void SoundManager::checkResVersion(const byte *soundData) {
+ int maxVersion = READ_LE_UINT16(soundData + 4);
+ int minVersion = READ_LE_UINT16(soundData + 6);
+
+ if (_soundManager->_ourSndResVersion < minVersion)
+ error("Attempt to play/prime sound resource that is too new");
+ if (_soundManager->_ourSndResVersion > maxVersion)
+ error("Attempt to play/prime sound resource that is too old");
+}
+
+int SoundManager::extractPriority(const byte *soundData) {
+ return READ_LE_UINT16(soundData + 12);
+}
+
+int SoundManager::extractLoop(const byte *soundData) {
+ return READ_LE_UINT16(soundData + 14);
+}
+
+void SoundManager::extractTrackInfo(trackInfoStruct *trackInfo, const byte *soundData, int groupNum) {
+ _sfExtractTrackInfo(trackInfo, soundData, groupNum);
+}
+
+void SoundManager::addToSoundList(Sound *sound) {
+ if (!contains(_soundList, sound))
+ _soundList.push_back(sound);
+}
+
+void SoundManager::removeFromSoundList(Sound *sound) {
+ _soundList.remove(sound);
+}
+
+void SoundManager::addToPlayList(Sound *sound) {
+ _sfAddToPlayList(sound);
+}
+
+void SoundManager::removeFromPlayList(Sound *sound) {
+ _sfRemoveFromPlayList(sound);
+}
+
+bool SoundManager::isOnPlayList(Sound *sound) {
+ return _sfIsOnPlayList(sound);
+}
+
+void SoundManager::updateSoundVol(Sound *sound) {
+ _sfUpdateVolume(sound);
+}
+
+void SoundManager::updateSoundPri(Sound *sound) {
+ _sfUpdatePriority(sound);
+}
+
+void SoundManager::updateSoundLoop(Sound *sound) {
+ _sfUpdateLoop(sound);
+}
+
+void SoundManager::rethinkVoiceTypes() {
+ _sfRethinkVoiceTypes();
+}
+
+void SoundManager::_sfSoundServer() {
+ if (!sfManager()._serverDisabledCount && !sfManager()._serverSuspendedCount)
+ return;
+
+ if (sfManager()._needToRethink) {
+ _sfRethinkVoiceTypes();
+ sfManager()._needToRethink = false;
+ } else {
+ _sfDereferenceAll();
+ }
+
+ // Handle any fading if necessary
+ do {
+ _sfProcessFading();
+ } while (sfManager()._serverSuspendedCount > 0);
+
+ // Poll all sound drivers in case they need it
+ for (Common::List<SoundDriver *>::iterator i = sfManager()._installedDrivers.begin();
+ i != sfManager()._installedDrivers.end(); ++i) {
+ (*i)->poll();
+ }
+}
+
+void SoundManager::_sfProcessFading() {
+ // Loop through processing active sounds
+ bool removeFlag = false;
+ Common::List<Sound *>::iterator i = sfManager()._playList.begin();
+ while (i != sfManager()._playList.end()) {
+ Sound *s = *i;
+ ++i;
+
+ if (!s->_pausedCount)
+ removeFlag = s->_soServiceTracks();
+ if (removeFlag) {
+ _sfDoRemoveFromPlayList(s);
+ s->_stoppedAsynchronously = true;
+ sfManager()._needToRethink = true;
+ }
+
+ if (s->_fadeDest != -1) {
+ if (s->_fadeCounter != 0)
+ --s->_fadeCounter;
+ else {
+ if (s->_volume >= s->_fadeDest) {
+ if ((s->_fadeDest - s->_volume) > s->_fadeSteps)
+ s->_volume += s->_fadeSteps;
+ else
+ s->_volume = s->_fadeDest;
+ } else {
+ if (s->_fadeDest > s->_fadeSteps)
+ s->_volume -= s->_fadeSteps;
+ else
+ s->_volume = s->_fadeDest;
+ }
+
+ _sfDoUpdateVolume(s);
+ if (s->_volume != s->_fadeDest)
+ s->_fadeCounter = s->_fadeTicks;
+ else {
+ s->_fadeDest = -1;
+ if (s->_stopAfterFadeFlag) {
+ _sfDoRemoveFromPlayList(s);
+ s->_stoppedAsynchronously = true;
+ sfManager()._needToRethink = true;
+ }
+ }
+ }
+ }
+ }
+
+ // Loop through the voiceType list
+ for (int voiceIndex = 0; voiceIndex < SOUND_ARR_SIZE; ++voiceIndex) {
+ VoiceTypeStruct *vtStruct = sfManager()._voiceTypeStructPtrs[voiceIndex];
+ if (!vtStruct)
+ continue;
+
+ if (vtStruct->_voiceType == VOICETYPE_1) {
+ for (uint idx = 0; idx < vtStruct->_entries.size(); ++idx) {
+ if (vtStruct->_entries[idx]._type1._field6 >= -1)
+ ++vtStruct->_entries[idx]._type1._field6;
+ }
+ }
+ }
+}
+
+void SoundManager::_sfUpdateVoiceStructs() {
+ for (int voiceIndex = 0; voiceIndex < SOUND_ARR_SIZE; ++voiceIndex) {
+ VoiceTypeStruct *vs = sfManager()._voiceTypeStructPtrs[voiceIndex];
+ if (!vs)
+ continue;
+
+ if (vs->_voiceType == VOICETYPE_0) {
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntry &vse = vs->_entries[idx];
+
+ vse._type0._sound = vse._type0._sound2;
+ vse._type0._channelNum = vse._type0._channelNum2;
+ vse._type0._priority = vse._type0._priority2;
+ vse._type0._fieldA = vse._type0._field12;
+ }
+ } else {
+ vs->_field3 = vs->_numVoices;
+
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntry &vse = vs->_entries[idx];
+
+ vse._type1._sound = vse._type1._sound2;
+ vse._type1._channelNum = vse._type1._channelNum2;
+ vse._type1._priority = vse._type1._priority2;
+ }
+ }
+ }
+}
+
+void SoundManager::_sfUpdateVoiceStructs2() {
+ for (int voiceIndex = 0; voiceIndex < SOUND_ARR_SIZE; ++voiceIndex) {
+ VoiceTypeStruct *vtStruct = sfManager()._voiceTypeStructPtrs[voiceIndex];
+ if (!vtStruct)
+ continue;
+
+ for (uint idx = 0; idx < vtStruct->_entries.size(); ++idx) {
+
+ if (vtStruct->_voiceType == VOICETYPE_0) {
+ VoiceStructEntryType0 &vse = vtStruct->_entries[idx]._type0;
+ vse._sound2 = vse._sound;
+ vse._channelNum2 = vse._channelNum;
+ vse._priority2 = vse._priority;
+ vse._field12 = vse._fieldA;
+ } else {
+ VoiceStructEntryType1 &vse = vtStruct->_entries[idx]._type1;
+ vse._sound2 = vse._sound;
+ vse._channelNum2 = vse._channelNum;
+ vse._priority2 = vse._priority;
+ }
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+
void SoundManager::saveNotifier(bool postFlag) {
- _globals->_soundManager.saveNotifierProc(postFlag);
+ _soundManager->saveNotifierProc(postFlag);
}
void SoundManager::saveNotifierProc(bool postFlag) {
@@ -42,7 +492,7 @@ void SoundManager::saveNotifierProc(bool postFlag) {
}
void SoundManager::loadNotifier(bool postFlag) {
- _globals->_soundManager.loadNotifierProc(postFlag);
+ _soundManager->loadNotifierProc(postFlag);
}
void SoundManager::loadNotifierProc(bool postFlag) {
@@ -51,7 +501,2139 @@ void SoundManager::loadNotifierProc(bool postFlag) {
void SoundManager::listenerSynchronize(Serializer &s) {
s.validate("SoundManager");
- warning("TODO: SoundManager listenerSynchronize");
+ warning("TODO: SoundManager listenerSynchronise");
+}
+
+/*--------------------------------------------------------------------------*/
+
+SoundManager &SoundManager::sfManager() {
+ assert(_soundManager);
+ return *_soundManager;
+}
+
+int SoundManager::_sfDetermineGroup(const byte *soundData) {
+ const byte *p = soundData + READ_LE_UINT16(soundData + 8);
+ uint32 v;
+ while ((v = READ_LE_UINT32(p)) != 0) {
+ if ((v & _soundManager->_groupsAvail) == v)
+ return v;
+
+ p += 6 + (READ_LE_UINT16(p + 4) * 4);
+ }
+
+ return 0;
+}
+
+void SoundManager::_sfAddToPlayList(Sound *sound) {
+ ++sfManager()._serverSuspendedCount;
+ _sfDoAddToPlayList(sound);
+ sound->_stoppedAsynchronously = false;
+ _sfRethinkVoiceTypes();
+ --sfManager()._serverSuspendedCount;
+}
+
+void SoundManager::_sfRemoveFromPlayList(Sound *sound) {
+ ++sfManager()._serverSuspendedCount;
+ if (_sfDoRemoveFromPlayList(sound))
+ _sfRethinkVoiceTypes();
+ --sfManager()._serverSuspendedCount;
+}
+
+bool SoundManager::_sfIsOnPlayList(Sound *sound) {
+ ++_soundManager->_serverSuspendedCount;
+ bool result = contains(_soundManager->_playList, sound);
+ --_soundManager->_serverSuspendedCount;
+
+ return result;
+}
+
+void SoundManager::_sfRethinkSoundDrivers() {
+ // Free any existing entries
+ for (int idx = 0; idx < SOUND_ARR_SIZE; ++idx) {
+ if (sfManager()._voiceTypeStructPtrs[idx]) {
+ delete sfManager()._voiceTypeStructPtrs[idx];
+ sfManager()._voiceTypeStructPtrs[idx] = NULL;
+ }
+ }
+
+ for (int idx = 0; idx < SOUND_ARR_SIZE; ++idx) {
+ byte flag = 0xff;
+ int total = 0;
+
+ // Loop through the sound drivers
+ for (Common::List<SoundDriver *>::iterator i = sfManager()._installedDrivers.begin();
+ i != sfManager()._installedDrivers.end(); ++i) {
+ // Process the group data for each sound driver
+ SoundDriver *driver = *i;
+ const byte *groupData = driver->_groupOffset->pData;
+
+ while (*groupData != 0xff) {
+ byte byteVal = *groupData++;
+
+ if (byteVal == idx) {
+ byte byteVal2 = *groupData++;
+ if (flag == 0xff)
+ flag = byteVal2;
+ else {
+ assert(flag == byteVal2);
+ }
+
+ if (!flag) {
+ while (*groupData++ != 0xff)
+ ++total;
+ } else {
+ total += *groupData;
+ groupData += 2;
+ }
+ } else if (*groupData++ == 0) {
+ while (*groupData != 0xff)
+ ++groupData;
+ ++groupData;
+ } else {
+ groupData += 2;
+ }
+ }
+ }
+
+ if (total) {
+ VoiceTypeStruct *vs = new VoiceTypeStruct();
+ sfManager()._voiceTypeStructPtrs[idx] = vs;
+
+ if (!flag) {
+ vs->_voiceType = VOICETYPE_0;
+ } else {
+ vs->_voiceType = VOICETYPE_1;
+ }
+
+ vs->_total = vs->_numVoices = total;
+ vs->_field3 = 0;
+
+ for (Common::List<SoundDriver *>::iterator i = sfManager()._installedDrivers.begin();
+ i != sfManager()._installedDrivers.end(); ++i) {
+ // Process the group data for each sound driver
+ SoundDriver *driver = *i;
+ const byte *groupData = driver->_groupOffset->pData;
+
+ while (*groupData != 0xff) {
+ byte byteVal = *groupData++;
+
+ if (byteVal == idx) {
+ ++groupData;
+
+ if (!flag) {
+ while ((byteVal = *groupData++) != 0xff) {
+ VoiceStructEntry ve;
+ memset(&ve, 0, sizeof(VoiceStructEntry));
+
+ ve._field1 = (byteVal & 0x80) ? 0 : 1;
+ ve._driver = driver;
+ ve._type0._sound = NULL;
+ ve._type0._channelNum = 0;
+ ve._type0._priority = 0;
+ ve._type0._fieldA = 0;
+
+ vs->_entries.push_back(ve);
+ }
+ } else {
+ byteVal = *groupData;
+ groupData += 2;
+
+ for (int idx = 0; idx < byteVal; ++idx) {
+ VoiceStructEntry ve;
+ memset(&ve, 0, sizeof(VoiceStructEntry));
+
+ ve._voiceNum = idx;
+ ve._driver = driver;
+ ve._type1._field4 = -1;
+ ve._type1._field5 = 0;
+ ve._type1._field6 = 0;
+ ve._type1._sound = NULL;
+ ve._type1._channelNum = 0;
+ ve._type1._priority = 0;
+
+ vs->_entries.push_back(ve);
+ }
+ }
+ } else {
+ if (*groupData++ != 0) {
+ while (*groupData != 0xff)
+ ++groupData;
+ } else {
+ groupData += 2;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+void SoundManager::_sfRethinkVoiceTypes() {
+ ++sfManager()._serverSuspendedCount;
+ _sfDereferenceAll();
+
+ // Pre-processing
+ for (int voiceIndex = 0; voiceIndex < SOUND_ARR_SIZE; ++voiceIndex) {
+ VoiceTypeStruct *vs = sfManager()._voiceTypeStructPtrs[voiceIndex];
+ if (!vs)
+ continue;
+
+ if (vs->_voiceType == VOICETYPE_0) {
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntry &vse = vs->_entries[idx];
+ vse._type0._sound3 = vse._type0._sound;
+ vse._type0._channelNum3 = vse._type0._channelNum;
+ vse._type0._priority3 = vse._type0._priority;
+ vse._type0._field1A = vse._type0._fieldA;
+ vse._type0._sound = NULL;
+ vse._type0._channelNum = 0;
+ vse._type0._priority = 0;
+ vse._type0._fieldA = 0;
+ vse._type0._sound2 = NULL;
+ vse._type0._channelNum2 = 0;
+ vse._type0._priority2 = 0;
+ vse._type0._field12 = 0;
+ }
+ } else {
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntry &vse = vs->_entries[idx];
+ vse._type1._sound3 = vse._type1._sound;
+ vse._type1._channelNum3 = vse._type1._channelNum;
+ vse._type1._priority3 = vse._type1._priority;
+ vse._type1._sound = NULL;
+ vse._type1._channelNum = 0;
+ vse._type1._priority = 0;
+ vse._type1._sound2 = NULL;
+ vse._type1._channelNum2 = 0;
+ vse._type1._priority2 = 0;
+ }
+
+ // Reset the number of voices available
+ vs->_numVoices = vs->_total;
+ }
+ }
+
+ // Main processing loop
+ int priorityOffset = 0;
+ for (Common::List<Sound *>::iterator i = sfManager()._playList.begin(); i != sfManager()._playList.end(); ++i, priorityOffset += 16) {
+ Sound *sound = *i;
+ if ((sound->_mutedCount != 0) || (sound->_pausedCount != 0))
+ continue;
+
+ _sfUpdateVoiceStructs();
+ Common::set_to(sound->_chWork, sound->_chWork + SOUND_ARR_SIZE, false);
+
+ for (;;) {
+ // Scan for sub priority
+ int foundIndex = -1, foundPriority = 0;
+ for (int idx = 0; idx < SOUND_ARR_SIZE; ++idx) {
+ if (!(sound->_chFlags[idx] & 0x8000) & !sound->_chWork[idx]) {
+ int subPriority = sound->_chSubPriority[idx];
+ if (subPriority)
+ subPriority = 16 - subPriority + priorityOffset;
+
+ if (foundIndex != -1) {
+ if (subPriority < foundPriority) {
+ foundIndex = idx;
+ foundPriority = subPriority;
+ }
+ } else {
+ foundIndex = idx;
+ foundPriority = subPriority;
+ }
+ }
+ }
+ if (foundIndex == -1)
+ break;
+
+ int chNumVoices = sound->_chNumVoices[foundIndex];
+ sound->_chWork[foundIndex] = true;
+
+ VoiceTypeStruct *vtStruct = sfManager()._voiceTypeStructPtrs[sound->_chVoiceType[foundIndex]];
+ if (!vtStruct) {
+ if (foundPriority)
+ continue;
+
+ _sfUpdateVoiceStructs2();
+ break;
+ }
+
+ if (vtStruct->_voiceType != VOICETYPE_0) {
+ // Type 1
+ int numVoices = vtStruct->_numVoices;
+
+ if (numVoices >= chNumVoices) {
+ int channelCount = chNumVoices, idx = 0;
+ while (channelCount > 0) {
+ if (!vtStruct->_entries[idx]._type1._sound2) {
+ vtStruct->_entries[idx]._type1._sound2 = sound;
+ vtStruct->_entries[idx]._type1._channelNum2 = foundIndex;
+ vtStruct->_entries[idx]._type1._priority2 = foundPriority;
+ --channelCount;
+ }
+ ++idx;
+ }
+
+ vtStruct->_numVoices -= chNumVoices;
+ continue;
+ } else if (!foundPriority) {
+ do {
+ int maxPriority = 0;
+ for (uint idx = 0; idx < vtStruct->_entries.size(); ++idx)
+ maxPriority = MAX(maxPriority, vtStruct->_entries[idx]._type1._priority2);
+
+ if (!maxPriority) {
+ _sfUpdateVoiceStructs2();
+ break;
+ }
+
+ for (uint idx = 0; idx < vtStruct->_entries.size(); ++idx) {
+ if (vtStruct->_entries[idx]._type1._priority2 == maxPriority) {
+ vtStruct->_entries[idx]._type1._sound2 = NULL;
+ vtStruct->_entries[idx]._type1._channelNum2 = 0;
+ vtStruct->_entries[idx]._type1._priority2 = 0;
+ ++numVoices;
+ }
+ }
+ } while (chNumVoices > numVoices);
+
+ int voicesCtr = chNumVoices;
+ for (uint idx = 0; (idx < vtStruct->_entries.size()) && (voicesCtr > 0); ++idx) {
+ if (!vtStruct->_entries[idx]._type1._sound2) {
+ vtStruct->_entries[idx]._type1._sound2 = sound;
+ vtStruct->_entries[idx]._type1._channelNum2 = foundIndex;
+ vtStruct->_entries[idx]._type1._priority2 = foundPriority;
+ --voicesCtr;
+ }
+ }
+
+ numVoices -= chNumVoices;
+ vtStruct->_numVoices = numVoices;
+ continue;
+ } else if (!numVoices) {
+ break;
+ }
+ continue;
+ } else {
+ // Type 0
+ if (sound->_isEmpty) {
+ uint idx = 0;
+ while ((idx < vtStruct->_entries.size()) &&
+ (vtStruct->_entries[idx]._voiceNum == foundIndex))
+ ++idx;
+ if (idx == vtStruct->_entries.size())
+ continue;
+ }
+
+ int flagsVal = sound->_chFlags[foundIndex] & 3;
+ if (flagsVal != 1) {
+ // All modes except mode 1 (loc_23EDF)
+ int entryIndex = -1, maxVoiceNum = 0;
+
+ for (uint idx = 0; idx < vtStruct->_entries.size(); ++idx) {
+ if (!vtStruct->_entries[idx]._type0._sound2 && (vtStruct->_entries[idx]._field1 != 0) &&
+ (vtStruct->_entries[idx]._voiceNum > maxVoiceNum)) {
+ maxVoiceNum = vtStruct->_entries[idx]._voiceNum;
+ entryIndex = idx;
+ }
+ }
+
+ if (entryIndex != -1) {
+ vtStruct->_entries[entryIndex]._type0._sound2 = sound;
+ vtStruct->_entries[entryIndex]._type0._channelNum2 = foundIndex;
+ vtStruct->_entries[entryIndex]._type0._priority2 = foundPriority;
+ vtStruct->_entries[entryIndex]._type0._field12 = 0;
+ continue;
+ }
+
+ if (foundPriority != 0)
+ continue;
+
+ int maxPriority = 0;
+ entryIndex = -1;
+ for (uint idx = 0; idx < vtStruct->_entries.size(); ++idx) {
+ if ((vtStruct->_entries[idx]._field1 != 0) &&
+ (vtStruct->_entries[idx]._type0._priority2 > maxVoiceNum)) {
+ maxPriority = vtStruct->_entries[idx]._type0._priority2;
+ entryIndex = idx;
+ }
+ }
+
+ if (entryIndex != -1) {
+ vtStruct->_entries[entryIndex]._type0._sound2 = sound;
+ vtStruct->_entries[entryIndex]._type0._channelNum2 = foundIndex;
+ vtStruct->_entries[entryIndex]._type0._priority2 = foundPriority;
+ vtStruct->_entries[entryIndex]._type0._field12 = 0;
+ continue;
+ }
+
+ _sfUpdateVoiceStructs2();
+ break;
+ } else {
+ // Channel mode 1 handling (loc_23FAC)
+
+ bool foundMatch = false;
+ int entryIndex = -1;
+ for (uint idx = 0; idx < vtStruct->_entries.size(); ++idx) {
+ if (vtStruct->_entries[idx]._voiceNum == foundIndex) {
+ foundIndex = true;
+ if (!vtStruct->_entries[idx]._type0._sound2) {
+ entryIndex = idx;
+ break;
+ }
+ }
+ }
+
+ if (entryIndex != -1) {
+ vtStruct->_entries[entryIndex]._type0._sound2 = sound;
+ vtStruct->_entries[entryIndex]._type0._channelNum2 = foundIndex;
+ vtStruct->_entries[entryIndex]._type0._priority2 = foundPriority;
+ vtStruct->_entries[entryIndex]._type0._field12 = 0;
+ continue;
+ }
+
+ if (!foundMatch) {
+ if (foundPriority)
+ continue;
+ if (entryIndex == -1) {
+ _sfUpdateVoiceStructs2();
+ break;
+ }
+ }
+
+ // Find the entry with the highest priority
+ int maxPriority = 0;
+ foundMatch = false;
+ entryIndex = -1;
+ for (uint idx = 0; idx < vtStruct->_entries.size(); ++idx) {
+ if (vtStruct->_entries[idx]._voiceNum != foundIndex)
+ continue;
+ if (!vtStruct->_entries[idx]._type0._field12) {
+ foundMatch = true;
+ break;
+ }
+
+ if (vtStruct->_entries[idx]._type0._priority2 > maxPriority) {
+ maxPriority = vtStruct->_entries[idx]._type0._priority2;
+ entryIndex = -1;
+ }
+ }
+
+ if (!foundMatch) {
+ if (foundPriority)
+ continue;
+
+ if (entryIndex != -1) {
+ vtStruct->_entries[entryIndex]._type0._sound2 = sound;
+ vtStruct->_entries[entryIndex]._type0._channelNum2 = foundIndex;
+ vtStruct->_entries[entryIndex]._type0._priority2 = foundPriority;
+ vtStruct->_entries[entryIndex]._type0._field12 = 1;
+ continue;
+ }
+
+ _sfUpdateVoiceStructs2();
+ break;
+ }
+
+ // Found a match (loc_24061)
+ maxPriority = 0;
+ int maxVoiceNum = 0;
+ int priorityIndex = -1, voiceIndex = -1;
+
+ for (uint idx = 0; idx < vtStruct->_entries.size(); ++idx) {
+ if (vtStruct->_entries[idx]._field1) {
+ if (!vtStruct->_entries[idx]._type0._sound2) {
+ if (vtStruct->_entries[idx]._voiceNum > maxVoiceNum) {
+ maxVoiceNum = vtStruct->_entries[idx]._voiceNum;
+ voiceIndex = idx;
+ }
+ } else {
+ if (vtStruct->_entries[idx]._type0._priority2 > maxPriority) {
+ maxPriority = vtStruct->_entries[idx]._type0._priority2;
+ priorityIndex = idx;
+ }
+ }
+ }
+ }
+
+ if (voiceIndex != -1) {
+ VoiceStructEntryType0 &vteSrc = vtStruct->_entries[foundIndex]._type0;
+ VoiceStructEntryType0 &vteDest = vtStruct->_entries[voiceIndex]._type0;
+
+ vteDest._sound2 = vteSrc._sound2;
+ vteDest._channelNum2 = vteSrc._channelNum2;
+ vteDest._priority2 = vteSrc._priority2;
+
+ vteSrc._sound2 = sound;
+ vteSrc._channelNum2 = foundIndex;
+ vteSrc._priority2 = foundPriority;
+ vteSrc._field12 = 1;
+ continue;
+ }
+
+ if (!foundPriority)
+ continue;
+ if (priorityIndex == -1) {
+ _sfUpdateVoiceStructs2();
+ break;
+ }
+
+ VoiceStructEntryType0 &vteSrc = vtStruct->_entries[foundIndex]._type0;
+ VoiceStructEntryType0 &vteDest = vtStruct->_entries[priorityIndex]._type0;
+
+ if (priorityIndex != foundIndex) {
+ vteDest._sound2 = vteSrc._sound2;
+ vteDest._channelNum2 = vteSrc._channelNum2;
+ vteDest._priority2 = vteSrc._priority2;
+ vteDest._field12 = vteSrc._field12;
+ }
+
+ vteSrc._sound2 = sound;
+ vteSrc._channelNum2 = foundIndex;
+ vteSrc._priority2 = foundPriority;
+ vteSrc._field12 = 1;
+ continue;
+ }
+ }
+ }
+ }
+
+ // Post-processing
+ for (int voiceIndex = 0; voiceIndex < SOUND_ARR_SIZE; ++voiceIndex) {
+ VoiceTypeStruct *vs = sfManager()._voiceTypeStructPtrs[voiceIndex];
+ if (!vs)
+ continue;
+
+ if (vs->_voiceType == VOICETYPE_0) {
+ // Type 0
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntryType0 &vse = vs->_entries[idx]._type0;
+ SoundDriver *driver = vs->_entries[idx]._driver;
+ assert(driver);
+
+ if (vse._field12) {
+ int total = 0;
+ vse._sound = vse._sound2;
+ if (vse._sound3 != vse._sound)
+ ++total;
+
+ vse._channelNum = vse._channelNum2;
+ if (vse._channelNum3 != vse._channelNum)
+ ++total;
+
+ vse._priority = vse._priority2;
+ vse._fieldA = 1;
+ vse._sound2 = NULL;
+
+ if (total) {
+ driver->proc24(vse._channelNum, idx, vse._sound, 123, 0);
+ driver->proc24(vse._channelNum, idx, vse._sound, 1, vse._sound->_chModulation[vse._channelNum]);
+ driver->proc24(vse._channelNum, idx, vse._sound, 7,
+ vse._sound->_chVolume[vse._channelNum] * vse._sound->_volume / 127);
+ driver->proc24(vse._channelNum, idx, vse._sound, 10, vse._sound->_chPan[vse._channelNum]);
+ driver->proc24(vse._channelNum, idx, vse._sound, 64, vse._sound->_chDamper[vse._channelNum]);
+
+ driver->setProgram(vse._channelNum, vse._sound->_chProgram[vse._channelNum]);
+ driver->setPitchBlend(vse._channelNum, vse._sound->_chPitchBlend[vse._channelNum]);
+
+ vse._sound3 = NULL;
+ }
+ } else {
+ vse._sound = NULL;
+ vse._channelNum = 0;
+ vse._priority = 0;
+ vse._fieldA = 0;
+ }
+ }
+
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntryType0 &vse = vs->_entries[idx]._type0;
+ Sound *sound = vse._sound2;
+ int channelNum = vse._channelNum2;
+
+ if (!sound)
+ continue;
+
+ for (uint entryIndex = 0; entryIndex < vs->_entries.size(); ++entryIndex) {
+ if ((vs->_entries[entryIndex]._type0._sound3 != sound) ||
+ (vs->_entries[entryIndex]._type0._channelNum3 != channelNum)) {
+ // Found match
+ vs->_entries[entryIndex]._type0._sound = sound;
+ vs->_entries[entryIndex]._type0._channelNum = channelNum;
+ vs->_entries[entryIndex]._type0._priority = vse._priority2;
+ vs->_entries[entryIndex]._type0._fieldA = 0;
+ vse._sound2 = NULL;
+ break;
+ }
+ }
+ }
+
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntryType0 &vse = vs->_entries[idx]._type0;
+ Sound *sound = vse._sound2;
+ if (!sound)
+ continue;
+
+ int voiceNum = 0, foundIndex = -1;
+ for (uint entryIndex = 0; entryIndex < vs->_entries.size(); ++entryIndex) {
+ if ((vs->_entries[entryIndex]._field1) && !vs->_entries[entryIndex]._type0._sound) {
+ int tempVoice = vs->_entries[entryIndex]._voiceNum;
+
+ if (voiceNum <= tempVoice) {
+ voiceNum = tempVoice;
+ foundIndex = entryIndex;
+ }
+ }
+ }
+ assert(foundIndex != -1);
+
+ VoiceStructEntryType0 &vseFound = vs->_entries[foundIndex]._type0;
+
+ vseFound._sound = vse._sound2;
+ vseFound._channelNum = vse._channelNum2;
+ vseFound._priority = vse._priority2;
+ vseFound._fieldA = 0;
+
+ SoundDriver *driver = vs->_entries[foundIndex]._driver;
+ assert(driver);
+
+ driver->proc24(vseFound._channelNum, voiceIndex, vseFound._sound, 123, 0);
+ driver->proc24(vseFound._channelNum, voiceIndex, vseFound._sound,
+ 1, vseFound._sound->_chModulation[vseFound._channelNum]);
+ driver->proc24(vseFound._channelNum, voiceIndex, vseFound._sound,
+ 7, vseFound._sound->_chVolume[vseFound._channelNum] * vseFound._sound->_volume / 127);
+ driver->proc24(vseFound._channelNum, voiceIndex, vseFound._sound,
+ 10, vseFound._sound->_chPan[vseFound._channelNum]);
+ driver->setProgram(vseFound._channelNum, vseFound._sound->_chProgram[vseFound._channelNum]);
+ driver->setPitchBlend(vseFound._channelNum, vseFound._sound->_chPitchBlend[vseFound._channelNum]);
+ }
+
+ // Final loop
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntryType0 &vse = vs->_entries[idx]._type0;
+
+ if (!vse._sound && (vse._sound3)) {
+ SoundDriver *driver = vs->_entries[idx]._driver;
+ assert(driver);
+ driver->proc24(vs->_entries[idx]._voiceNum, voiceIndex, vse._sound3, 123, 0);
+ }
+ }
+
+ } else {
+ // Type 1
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntry &vse = vs->_entries[idx];
+ vse._type1._sound = NULL;
+ vse._type1._channelNum = 0;
+ vse._type1._priority = 0;
+ }
+
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntryType1 &vse = vs->_entries[idx]._type1;
+ Sound *sound = vse._sound2;
+ int channelNum = vse._channelNum2;
+
+ if (!sound)
+ continue;
+
+ for (uint entryIndex = 0; entryIndex < vs->_entries.size(); ++entryIndex) {
+ VoiceStructEntryType1 &vse2 = vs->_entries[entryIndex]._type1;
+ if (!vse2._sound && (vse2._sound3 == sound) && (vse2._channelNum3 == channelNum)) {
+ vse2._sound = sound;
+ vse2._channelNum = channelNum;
+ vse._channelNum = vse2._channelNum2;
+ vse._priority = vse2._priority2;
+ vse._sound2 = NULL;
+ break;
+ }
+ }
+ }
+
+ uint idx2 = 0;
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntryType1 &vse = vs->_entries[idx]._type1;
+ Sound *sound = vse._sound2;
+ if (!sound)
+ continue;
+
+ while (vs->_entries[idx2]._type1._sound)
+ ++idx2;
+
+ VoiceStructEntryType1 &vse2 = vs->_entries[idx2]._type1;
+ vse2._sound = vse._sound2;
+ vse2._channelNum = vse._channelNum2;
+ vse2._priority = vse._priority2;
+ vse._field4 = -1;
+ vse2._field5 = 0;
+ vse2._field6 = 0;
+
+ SoundDriver *driver = vs->_entries[idx2]._driver;
+ assert(driver);
+
+ driver->updateVoice(vs->_entries[idx2]._voiceNum);
+ driver->proc38(vs->_entries[idx2]._voiceNum, 1, vse2._sound->_chModulation[vse2._channelNum]);
+ driver->proc38(vs->_entries[idx2]._voiceNum, 7,
+ vse2._sound->_chVolume[vse2._channelNum] * vse2._sound->_volume / 127);
+ driver->proc38(vs->_entries[idx2]._voiceNum, 10, vse2._sound->_chPan[vse2._channelNum]);
+ driver->setPitch(vs->_entries[idx2]._voiceNum, vse2._sound->_chPitchBlend[vse2._channelNum]);
+ }
+
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntryType1 &vse = vs->_entries[idx]._type1;
+
+ if (!vse._sound && (vse._sound3)) {
+ vse._field4 = -1;
+ vse._field5 = 0;
+ vse._field6 = 0;
+
+ SoundDriver *driver = vs->_entries[idx]._driver;
+ assert(driver);
+ driver->updateVoice(voiceIndex);
+ }
+ }
+ }
+ }
+
+ --sfManager()._serverSuspendedCount;
+}
+
+void SoundManager::_sfUpdateVolume(Sound *sound) {
+ _sfDereferenceAll();
+ _sfDoUpdateVolume(sound);
+}
+
+void SoundManager::_sfDereferenceAll() {
+ // Orignal used handles for both the driver list and voiceStructPtrs list. This method then refreshed
+ // pointer lists based on the handles. Since in ScummVM we're just using pointers directly, this
+ // method doesn't need any implementation
+}
+
+void SoundManager::_sfUpdatePriority(Sound *sound) {
+ ++_soundManager->_serverSuspendedCount;
+
+ int tempPriority = (sound->_fixedPriority == 255) ? sound->_sndResPriority : sound->_priority;
+ if (sound->_priority != tempPriority) {
+ sound->_priority = tempPriority;
+ if (_sfDoRemoveFromPlayList(sound)) {
+ _sfDoAddToPlayList(sound);
+ _sfRethinkVoiceTypes();
+ }
+ }
+
+ --_soundManager->_serverSuspendedCount;
+}
+
+void SoundManager::_sfUpdateLoop(Sound *sound) {
+ if (sound->_fixedLoop)
+ sound->_loop = sound->_sndResLoop;
+ else
+ sound->_loop = sound->_fixedLoop;
+}
+
+void SoundManager::_sfSetMasterVol(int volume) {
+ if (volume > 127)
+ volume = 127;
+
+ if (volume != _soundManager->_masterVol) {
+ _soundManager->_masterVol = volume;
+
+ for (Common::List<SoundDriver *>::iterator i = _soundManager->_installedDrivers.begin();
+ i != _soundManager->_installedDrivers.end(); ++i) {
+ (*i)->setMasterVolume(volume);
+ }
+ }
+}
+
+void SoundManager::_sfExtractTrackInfo(trackInfoStruct *trackInfo, const byte *soundData, int groupNum) {
+ trackInfo->_numTracks = 0;
+
+ const byte *p = soundData + READ_LE_UINT16(soundData + 8);
+ uint32 v;
+ while ((v = READ_LE_UINT32(p)) != 0) {
+ if ((v == 0x80000000) || (v == (uint)groupNum)) {
+ // Found group to process
+ int count = READ_LE_UINT16(p + 4);
+ p += 6;
+
+ for (int idx = 0; idx < count; ++idx) {
+ if (trackInfo->_numTracks == 16) {
+ trackInfo->_numTracks = -1;
+ return;
+ }
+
+ trackInfo->_chunks[trackInfo->_numTracks] = READ_LE_UINT16(p);
+ trackInfo->_voiceTypes[trackInfo->_numTracks] = READ_LE_UINT16(p + 2);
+ ++trackInfo->_numTracks;
+ p += 4;
+ }
+ } else {
+ // Not correct group, so move to next one
+ p += 6 + (READ_LE_UINT16(p + 4) * 4);
+ }
+ }
+}
+
+void SoundManager::_sfTerminate() {
+
+}
+
+void SoundManager::_sfExtractGroupMask() {
+ uint32 mask = 0;
+
+ for (Common::List<SoundDriver *>::iterator i = sfManager()._installedDrivers.begin();
+ i != sfManager()._installedDrivers.end(); ++i)
+ mask |= (*i)->_groupMask;
+
+ _soundManager->_groupsAvail = mask;
+}
+
+bool SoundManager::_sfInstallDriver(SoundDriver *driver) {
+ if (!driver->open())
+ return false;
+
+ sfManager()._installedDrivers.push_back(driver);
+ driver->_groupOffset = driver->getGroupData();
+ driver->_groupMask = READ_LE_UINT32(driver->_groupOffset);
+
+ _sfExtractGroupMask();
+ _sfRethinkSoundDrivers();
+ driver->setMasterVolume(sfManager()._masterVol);
+
+ return true;
+}
+
+void SoundManager::_sfUnInstallDriver(SoundDriver *driver) {
+ sfManager()._installedDrivers.remove(driver);
+ delete driver;
+
+ _sfExtractGroupMask();
+ _sfRethinkSoundDrivers();
+}
+
+void SoundManager::_sfInstallPatchBank(SoundDriver *driver, const byte *bankData) {
+ driver->installPatch(bankData, _vm->_memoryManager.getSize(bankData));
+}
+
+/**
+ * Adds the specified sound in the playing sound list, inserting in order of priority
+ */
+void SoundManager::_sfDoAddToPlayList(Sound *sound) {
+ ++sfManager()._serverSuspendedCount;
+
+ Common::List<Sound *>::iterator i = sfManager()._playList.begin();
+ while ((i != sfManager()._playList.end()) && (sound->_priority > (*i)->_priority))
+ ++i;
+
+ sfManager()._playList.insert(i, sound);
+ --sfManager()._serverSuspendedCount;
+}
+
+/**
+ * Removes the specified sound from the play list
+ */
+bool SoundManager::_sfDoRemoveFromPlayList(Sound *sound) {
+ ++sfManager()._serverSuspendedCount;
+
+ bool result = false;
+ for (Common::List<Sound *>::iterator i = sfManager()._playList.begin(); i != sfManager()._playList.end(); ++i) {
+ if (*i == sound) {
+ result = true;
+ sfManager()._playList.erase(i);
+ break;
+ }
+ }
+
+ --sfManager()._serverSuspendedCount;
+ return result;
+}
+
+void SoundManager::_sfDoUpdateVolume(Sound *sound) {
+ ++_soundManager->_serverSuspendedCount;
+
+ for (int voiceIndex = 0; voiceIndex < SOUND_ARR_SIZE; ++voiceIndex) {
+ VoiceTypeStruct *vs = sfManager()._voiceTypeStructPtrs[voiceIndex];
+ if (!vs)
+ continue;
+
+ for (uint idx = 0; idx < vs->_entries.size(); ++idx) {
+ VoiceStructEntry &vse = vs->_entries[idx];
+ SoundDriver *driver = vse._driver;
+
+ if (vs->_voiceType == VOICETYPE_0) {
+ if (!vse._type0._sound) {
+ int vol = sound->_volume * sound->_chVolume[vse._type0._channelNum] / 127;
+ driver->proc24(voiceIndex, vse._voiceNum, sound, 7, vol);
+ }
+ } else {
+ if (!vse._type1._sound) {
+ int vol = sound->_volume * sound->_chVolume[vse._type1._channelNum] / 127;
+ driver->setVolume1(voiceIndex, vse._voiceNum, 7, vol);
+ }
+ }
+ }
+ }
+
+ --_soundManager->_serverSuspendedCount;
+}
+
+/*--------------------------------------------------------------------------*/
+
+Sound::Sound() {
+ _stoppedAsynchronously = false;
+ _soundResID = 0;
+ _group = 0;
+ _sndResPriority = 0;
+ _fixedPriority = -1;
+ _sndResLoop = true;
+ _fixedLoop = true;
+ _priority = 0;
+ _volume = 127;
+ _loop = false;
+ _pausedCount = 0;
+ _mutedCount = 0;
+ _hold = 0xff;
+ _cueValue = -1;
+ _fadeDest = -1;
+ _fadeSteps = 0;
+ _fadeTicks = 0;
+ _fadeCounter = 0;
+ _stopAfterFadeFlag = false;
+ _timer = 0;
+ _loopTimer = 0;
+ _trackInfo._numTracks = 0;
+ _primed = false;
+ _isEmpty = false;
+ _remoteReceiver = NULL;
+
+
+ memset(_chProgram, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_chModulation, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_chVolume, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_chPan, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_chDamper, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_chPitchBlend, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_chVoiceType, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_chNumVoices, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_chSubPriority, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_chFlags, 0, SOUND_ARR_SIZE * sizeof(int));
+ Common::set_to(_chWork, _chWork + SOUND_ARR_SIZE, false);
+ memset(_channelData, 0, SOUND_ARR_SIZE * sizeof(byte *));
+ memset(_trkChannel, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_trkState, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_trkLoopState, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_trkIndex, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_trkLoopIndex, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_trkRest, 0, SOUND_ARR_SIZE * sizeof(int));
+ memset(_trkLoopRest, 0, SOUND_ARR_SIZE * sizeof(int));
+}
+
+Sound::~Sound() {
+ stop();
+}
+
+void Sound::play(int soundNum) {
+ prime(soundNum);
+ _soundManager->addToPlayList(this);
+}
+
+void Sound::stop() {
+ _unPrime();
+}
+
+void Sound::prime(int soundResID) {
+ if (_soundResID != -1) {
+ stop();
+ _prime(soundResID, false);
+ }
+}
+
+void Sound::unPrime() {
+ stop();
+}
+
+void Sound::_prime(int soundResID, bool queueFlag) {
+ if (_primed)
+ unPrime();
+
+ if (_soundResID != -1) {
+ // Sound number specified
+ _isEmpty = false;
+ _remoteReceiver = NULL;
+ byte *soundData = _resourceManager->getResource(RES_SOUND, soundResID, 0);
+ _soundManager->checkResVersion(soundData);
+ _group = _soundManager->determineGroup(soundData);
+ _sndResPriority = _soundManager->extractPriority(soundData);
+ _sndResLoop = _soundManager->extractLoop(soundData);
+ _soundManager->extractTrackInfo(&_trackInfo, soundData, _group);
+
+ for (int idx = 0; idx < _trackInfo._numTracks; ++idx) {
+ _channelData[idx] = _resourceManager->getResource(RES_SOUND, soundResID, _trackInfo._chunks[idx]);
+ }
+
+ DEALLOCATE(soundData);
+ } else {
+ // No sound specified
+ _isEmpty = true;
+ _group = 0;
+ _sndResPriority = 0;
+ _sndResLoop = 0;
+ _trackInfo._numTracks = 0;
+ _channelData[0] = ALLOCATE(200);
+ _remoteReceiver = ALLOCATE(200);
+ }
+
+ _soPrimeSound(queueFlag);
+ if (queueFlag)
+ _soundManager->addToSoundList(this);
+
+ _primed = true;
+}
+
+void Sound::_unPrime() {
+ if (_primed) {
+ if (_isEmpty) {
+ DEALLOCATE(_channelData[0]);
+ DEALLOCATE(_remoteReceiver);
+ _remoteReceiver = NULL;
+ } else {
+ for (int idx = 0; idx < _trackInfo._numTracks; ++idx) {
+ DEALLOCATE(_channelData[idx]);
+ }
+ }
+
+ _trackInfo._numTracks = 0;
+ if (_soundManager)
+ _soundManager->removeFromSoundList(this);
+
+ _primed = false;
+ _stoppedAsynchronously = false;
+ }
+}
+
+void Sound::orientAfterDriverChange() {
+ if (!_isEmpty) {
+ int timeIndex = getTimeIndex();
+
+ for (int idx = 0; idx < _trackInfo._numTracks; ++idx)
+ DEALLOCATE(_channelData[idx]);
+
+ _trackInfo._numTracks = 0;
+ _primed = false;
+ _prime(_soundResID, true);
+ setTimeIndex(timeIndex);
+ }
+}
+
+void Sound::orientAfterRestore() {
+ if (_isEmpty) {
+ int timeIndex = getTimeIndex();
+ _primed = false;
+ _prime(_soundResID, true);
+ setTimeIndex(timeIndex);
+ }
+}
+
+void Sound::go() {
+ if (!_primed)
+ error("Attempt to execute Sound::go() on an unprimed Sound");
+
+ _soundManager->addToPlayList(this);
+}
+
+void Sound::halt(void) {
+ _soundManager->removeFromPlayList(this);
+}
+
+int Sound::getSoundNum() const {
+ return _soundResID;
+}
+
+bool Sound::isPlaying() {
+ return _soundManager->isOnPlayList(this);
+}
+
+bool Sound::isPrimed() const {
+ return _primed;
+}
+
+bool Sound::isPaused() const {
+ return _pausedCount != 0;
+}
+
+bool Sound::isMuted() const {
+ return _mutedCount != 0;
+}
+
+void Sound::pause(bool flag) {
+ _soundManager->suspendSoundServer();
+
+ if (flag)
+ ++_pausedCount;
+ else if (_pausedCount > 0)
+ --_pausedCount;
+
+ _soundManager->rethinkVoiceTypes();
+ _soundManager->restartSoundServer();
+}
+
+void Sound::mute(bool flag) {
+ _soundManager->suspendSoundServer();
+
+ if (flag)
+ ++_mutedCount;
+ else if (_mutedCount > 0)
+ --_mutedCount;
+
+ _soundManager->rethinkVoiceTypes();
+ _soundManager->restartSoundServer();
+}
+
+void Sound::fade(int fadeDest, int fadeTicks, int fadeSteps, bool stopAfterFadeFlag) {
+ _soundManager->suspendSoundServer();
+
+ if (fadeDest > 127)
+ fadeDest = 127;
+ if (fadeTicks > 127)
+ fadeTicks = 127;
+ if (fadeSteps > 255)
+ fadeSteps = 255;
+
+ _fadeDest = fadeDest;
+ _fadeTicks = fadeTicks;
+ _fadeSteps = fadeSteps;
+ _fadeCounter = 0;
+ _stopAfterFadeFlag = stopAfterFadeFlag;
+
+ _soundManager->restartSoundServer();
+}
+
+void Sound::setTimeIndex(uint32 timeIndex) {
+ if (_primed) {
+ mute(true);
+ _soSetTimeIndex(timeIndex);
+ mute(false);
+ }
+}
+
+uint32 Sound::getTimeIndex() const {
+ return _timer;
+}
+
+int Sound::getCueValue() const {
+ return _cueValue;
+}
+
+void Sound::setCueValue(int cueValue) {
+ _cueValue = cueValue;
+}
+
+void Sound::setVol(int volume) {
+ if (volume > 127)
+ volume = 127;
+
+ if (_volume != volume) {
+ _volume = volume;
+ if (isPlaying())
+ _soundManager->updateSoundVol(this);
+ }
+}
+
+int Sound::getVol() const {
+ return _volume;
+}
+
+void Sound::setPri(int priority) {
+ if (priority > 127)
+ priority = 127;
+ _fixedPriority = priority;
+ _soundManager->updateSoundPri(this);
+}
+
+void Sound::setLoop(bool flag) {
+ _fixedLoop = flag;
+ _soundManager->updateSoundLoop(this);
+}
+
+int Sound::getPri() const {
+ return _priority;
+}
+
+bool Sound::getLoop() {
+ return _loop;
+}
+
+void Sound::holdAt(int amount) {
+ if (amount > 127)
+ amount = 127;
+ _hold = amount;
+}
+
+void Sound::release() {
+ _hold = -1;
+}
+
+void Sound::_soPrimeSound(bool queueFlag) {
+ if (!queueFlag) {
+ _priority = (_fixedPriority != -1) ? _fixedPriority : _sndResPriority;
+ _loop = !_fixedLoop ? _fixedLoop : _sndResLoop;
+ _pausedCount = 0;
+ _mutedCount = 0;
+ _hold = -1;
+ _cueValue = -1;
+ _fadeDest = -1;
+ _fadeSteps = 0;
+ _fadeTicks = 0;
+ _fadeCounter = 0;
+ _stopAfterFadeFlag = false;
+ }
+
+ _timer = 0;
+ _loopTimer = 0;
+ _soPrimeChannelData();
+}
+
+void Sound::_soSetTimeIndex(uint timeIndex) {
+ ++_soundManager->_serverDisabledCount;
+
+ if (timeIndex != _timer) {
+ _soundManager->_soTimeIndexFlag = true;
+ _timer = 0;
+ _loopTimer = 0;
+ _soPrimeChannelData();
+
+ while (timeIndex > 0) {
+ if (_soServiceTracks()) {
+ SoundManager::_sfDoRemoveFromPlayList(this);
+ _stoppedAsynchronously = true;
+ _soundManager->_needToRethink = true;
+ break;
+ }
+ }
+
+ _soundManager->_soTimeIndexFlag = false;
+ }
+
+ --_soundManager->_serverDisabledCount;
+}
+
+bool Sound::_soServiceTracks() {
+ if (_isEmpty) {
+ _soRemoteReceive();
+ return false;
+ }
+
+ bool flag = true;
+ for (int trackCtr = 0; trackCtr < _trackInfo._numTracks; ++trackCtr) {
+ int mode = *_channelData[trackCtr];
+
+ if (mode == 0) {
+ _soServiceTrackType0(trackCtr, _channelData[trackCtr]);
+ } else if (mode == 1) {
+ _soServiceTrackType1(trackCtr, _channelData[trackCtr]);
+ } else {
+ error("Unknown sound mode encountered");
+ }
+
+ if (_trkState[trackCtr])
+ flag = false;
+ }
+
+ ++_timer;
+ if (!flag)
+ return false;
+ else if ((_loop > 0) && (--_loop == 0))
+ return true;
+ else {
+ for (int trackCtr = 0; trackCtr < _trackInfo._numTracks; ++trackCtr) {
+ _trkState[trackCtr] = _trkLoopState[trackCtr];
+ _trkRest[trackCtr] = _trkLoopRest[trackCtr];
+ _trkIndex[trackCtr] = _trkLoopIndex[trackCtr];
+ }
+
+ _timer = _loopTimer;
+ return false;
+ }
+}
+
+void Sound::_soPrimeChannelData() {
+ if (_isEmpty) {
+ for (int idx = 0; idx < 16; ++idx) {
+ _chProgram[idx] = 0;
+ _chModulation[idx] = 0;
+ _chVolume[idx] = 127;
+ _chPan[idx] = 64;
+ _chDamper[idx] = 0;
+ _chVoiceType[idx] = VOICETYPE_0;
+ _chNumVoices[idx] = 0;
+ _chSubPriority[idx] = 0;
+ _chPitchBlend[idx] = 0x2000;
+ _chFlags[idx] = 1;
+ }
+
+ _trkChannel[0] = 0;
+ _trkState[0] = 1;
+ _trkLoopState[0] = 1;
+ _trkIndex[0] = 0;
+ _trkLoopIndex[0] = 0;
+ } else {
+ for (int idx = 0; idx < SOUND_ARR_SIZE; ++idx)
+ _chFlags[idx] = 0x8000;
+
+ for (int idx = 0; idx < _trackInfo._numTracks; ++idx) {
+ byte *d = _channelData[idx];
+ int mode = *d;
+ int channelNum = (int8)*(d + 1);
+
+ _trkChannel[idx] = channelNum;
+ assert((channelNum >= -1) && (channelNum < 16));
+
+ if (channelNum >= 0) {
+ _chProgram[channelNum] = *(d + 10);
+ _chModulation[channelNum] = 0;
+ _chVolume[channelNum] = *(d + 11);
+ _chPan[channelNum] = *(d + 12);
+ _chDamper[channelNum] = 0;
+ _chVoiceType[channelNum] = _trackInfo._voiceTypes[idx];
+ _chNumVoices[channelNum] = *(d + 6);
+ _chSubPriority[channelNum] = *(d + 7);
+ _chPitchBlend[channelNum] = 0x2000;
+ _chFlags[channelNum] = READ_LE_UINT16(d + 8);
+ }
+
+ if (mode == 0) {
+ _trkState[idx] = 1;
+ _trkLoopState[idx] = 1;
+ _trkIndex[idx] = 14;
+ _trkLoopIndex[idx] = 14;
+ _trkRest[idx] = 0;
+ _trkLoopRest[idx] = 0;
+ } else if (mode == 1) {
+ _trkState[idx] = 1;
+ _trkLoopState[idx] = 1;
+ _trkIndex[idx] = 0;
+ _trkLoopIndex[idx] = 0;
+ _trkRest[idx] = 0;
+ _trkLoopRest[idx] = 0;
+ } else {
+ error("Unknown sound mode encountered");
+ }
+ }
+ }
+}
+
+void Sound::_soRemoteReceive() {
+ error("_soRemoteReceive not implemented");
+}
+
+void Sound::_soServiceTrackType0(int trackIndex, const byte *channelData) {
+ if (_trkRest[trackIndex]) {
+ --_trkRest[trackIndex];
+ return;
+ }
+ if (!_trkState[trackIndex])
+ return;
+
+ int channelNum = _trkChannel[trackIndex];
+ assert((channelNum >= 0) && (channelNum < SOUND_ARR_SIZE));
+ int chFlags = (channelNum == -1) ? 0 : _chFlags[channelNum];
+ int voiceNum = -1;
+ SoundDriver *driver = NULL;
+
+ VoiceTypeStruct *vtStruct;
+ VoiceType voiceType = VOICETYPE_0, chVoiceType = VOICETYPE_0;
+
+ if ((channelNum == -1) || _soundManager->_soTimeIndexFlag) {
+ vtStruct = NULL;
+ voiceType = VOICETYPE_0;
+ } else {
+ chVoiceType = (VoiceType)_chVoiceType[channelNum];
+ vtStruct = _soundManager->_voiceTypeStructPtrs[(int)chVoiceType];
+
+ if (vtStruct) {
+ voiceType = vtStruct->_voiceType;
+ if (voiceType == VOICETYPE_0) {
+ for (uint idx = 0; idx < vtStruct->_entries.size(); ++idx) {
+ if (!vtStruct->_entries[idx]._type0._sound &&
+ (vtStruct->_entries[idx]._type0._channelNum != channelNum)) {
+ voiceNum = vtStruct->_entries[idx]._voiceNum;
+ driver = vtStruct->_entries[idx]._driver;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ const byte *pData = channelData + _trkIndex[trackIndex];
+
+ for (;;) {
+ byte v = *pData++;
+ if (!(v & 0x80)) {
+ // Area #1
+ if (!_soundManager->_soTimeIndexFlag) {
+ // Only do processing if fast forwarding to a given time index
+ if (channelNum != -1) {
+ if (voiceType == VOICETYPE_1) {
+ _soUpdateDamper(vtStruct, channelNum, chVoiceType, v);
+ } else if (voiceNum != -1) {
+ assert(driver);
+ driver->proc18(voiceNum, chVoiceType);
+ }
+ }
+ }
+ } else if (!(v & 0x40)) {
+ // Area #2
+ if (!_soundManager->_soTimeIndexFlag) {
+ // Only do processing if fast forwarding to a given time index
+ byte b = *pData++;
+ v <<= 1;
+ if (b & 0x80)
+ v |= 1;
+
+ b &= 0x7f;
+
+ if (channelNum != -1) {
+ if (voiceType == VOICETYPE_1) {
+ // TODO: sub_25E32/sub_25DD8
+ if (chFlags & 0x10)
+ _soProc42(vtStruct, channelNum, chVoiceType, v);
+ else
+ _soProc32(vtStruct, channelNum, chVoiceType, v, b);
+ } else if (voiceNum != -1) {
+ assert(driver);
+ driver->proc20(voiceNum, chVoiceType);
+ }
+ }
+ } else {
+ ++pData;
+ }
+ } else if (!(v & 0x20)) {
+ // Area #3
+ v &= 0x1f;
+
+ // Gather up an extended number
+ int trkRest = v;
+ while ((*pData & 0xE0) == 0xC0) {
+ byte b = *pData++;
+ trkRest = (trkRest << 5) | (b & 0x1f);
+ }
+
+ _trkRest[trackIndex] = trkRest - 1;
+ _trkIndex[trackIndex] = pData - channelData;
+ return;
+ } else if (!(v & 0x10)) {
+ // Area #4
+ v = (v & 0xf) << 1;
+
+ byte b = *pData++;
+ if (b & 0x80)
+ v |= 1;
+ b &= 0x7f;
+
+ assert(v < 4);
+ int cmdList[32] = { 1, 7, 10, 64 };
+ int cmdVal = cmdList[v];
+
+ if (channelNum == -1) {
+ if (_soDoUpdateTracks(cmdVal, b))
+ return;
+ } else {
+ _soDoTrackCommand(_trkChannel[trackIndex], cmdVal, b);
+
+ if (!_soundManager->_soTimeIndexFlag) {
+ if (cmdVal == 7)
+ b = static_cast<byte>(_volume * (int)b / 127);
+
+ if (voiceType != VOICETYPE_0) {
+ _soProc38(vtStruct, channelNum, chVoiceType, cmdVal, b);
+ } else if (voiceNum != -1) {
+ assert(driver);
+ driver->proc24(voiceNum, chVoiceType, this, cmdVal, b);
+ }
+ }
+ }
+ } else if (!(v & 0x8)) {
+ // Area #5
+ if (!_soundManager->_soTimeIndexFlag) {
+ // Only do processing if fast forwarding to a given time index
+ int cx = READ_LE_UINT16(pData);
+ pData += 2;
+
+ if (channelNum != -1) {
+ assert(driver);
+ driver->proc22(voiceNum, chVoiceType, cx);
+ }
+ } else {
+ pData += 2;
+ }
+ } else if (!(v & 0x4)) {
+ // Area #6
+ int cmd = *pData++;
+ int value = *pData++;
+
+ if (channelNum != -1) {
+ _soDoTrackCommand(_trkChannel[trackIndex], cmd, value);
+
+ if (!_soundManager->_soTimeIndexFlag) {
+ if (voiceType != VOICETYPE_0) {
+ _soProc38(vtStruct, channelNum, chVoiceType, cmd, value);
+ } else if (voiceNum != -1) {
+ assert(driver);
+ driver->proc24(voiceNum, chVoiceType, this, cmd, value);
+ }
+ }
+ } else if (_soDoUpdateTracks(cmd, value)) {
+ return;
+ }
+ } else if (!(v & 0x2)) {
+ // Area #7
+ if (!_soundManager->_soTimeIndexFlag) {
+ int pitchBlend = READ_BE_UINT16(pData);
+ pData += 2;
+
+ if (channelNum != -1) {
+ int channel = _trkChannel[trackIndex];
+ _chPitchBlend[channel] = pitchBlend;
+
+ if (voiceType != VOICETYPE_0) {
+ _soProc40(vtStruct, channelNum, pitchBlend);
+ } else if (voiceNum != -1) {
+ assert(driver);
+ driver->setPitchBlend(channel, pitchBlend);
+ }
+ }
+ } else {
+ pData += 2;
+ }
+ } else if (!(v & 0x1)) {
+ // Area #8
+ int program = *pData++;
+
+ if (channelNum != -1) {
+ int channel = _trkChannel[trackIndex];
+ _chProgram[channel] = program;
+
+ if (!_soundManager->_soTimeIndexFlag) {
+ if ((voiceType == VOICETYPE_0) && (voiceNum != -1)) {
+ assert(driver);
+ driver->setProgram(voiceNum, program);
+ }
+ }
+ } else {
+ _soSetTrackPos(trackIndex, pData - channelData, program);
+ }
+
+ } else {
+ // Area #9
+ byte b = *pData++;
+
+ if (b & 0x80) {
+ _trkState[trackIndex] = 0;
+ _trkIndex[trackIndex] = pData - channelData;
+ return;
+ }
+
+ if (!_soundManager->_soTimeIndexFlag) {
+ if ((channelNum != -1) && (voiceType == VOICETYPE_0) && (voiceNum != -1)) {
+ assert(driver);
+ driver->setVolume1(voiceNum, chVoiceType, 0, b);
+ }
+
+ }
+ }
+ }
+}
+
+void Sound::_soUpdateDamper(VoiceTypeStruct *voiceType, int channelNum, VoiceType mode, int v0) {
+ bool hasDamper = _chDamper[channelNum] != 0;
+
+ for (uint idx = 0; idx < voiceType->_entries.size(); ++idx) {
+ VoiceStructEntryType1 &vte = voiceType->_entries[idx]._type1;
+
+ if ((vte._field4 == v0) && (vte._channelNum == channelNum) && (vte._sound == this)) {
+ if (hasDamper)
+ vte._field5 = 1;
+ else {
+ SoundDriver *driver = voiceType->_entries[idx]._driver;
+ assert(driver);
+
+ vte._field4 = -1;
+ vte._field5 = 0;
+ driver->updateVoice(voiceType->_entries[idx]._voiceNum);
+ }
+ return;
+ }
+ }
+}
+
+void Sound::_soProc32(VoiceTypeStruct *vtStruct, int channelNum, VoiceType voiceType, int v0, int v1) {
+ int entryIndex = _soFindSound(vtStruct, channelNum);
+ if (entryIndex != -1) {
+ SoundDriver *driver = vtStruct->_entries[entryIndex]._driver;
+ assert(driver);
+
+ vtStruct->_entries[entryIndex]._type1._field6 = 0;
+ vtStruct->_entries[entryIndex]._type1._field4 = v0;
+ vtStruct->_entries[entryIndex]._type1._field5 = 0;
+
+ driver->proc32(vtStruct->_entries[entryIndex]._voiceNum, _chProgram[channelNum], v0, v1);
+ }
+}
+
+void Sound::_soProc42(VoiceTypeStruct *vtStruct, int channelNum, VoiceType voiceType, int v0) {
+ for (int trackCtr = 0; trackCtr < _trackInfo._numTracks; ++trackCtr) {
+ const byte *instrument = _channelData[trackCtr];
+ if ((*(instrument + 13) == v0) && (*instrument == 1)) {
+ int entryIndex = _soFindSound(vtStruct, channelNum);
+
+ if (entryIndex != -1) {
+ SoundDriver *driver = vtStruct->_entries[entryIndex]._driver;
+ assert(driver);
+
+ vtStruct->_entries[entryIndex]._type1._field6 = 0;
+ vtStruct->_entries[entryIndex]._type1._field4 = v0;
+ vtStruct->_entries[entryIndex]._type1._field5 = 0;
+
+ driver->proc32(vtStruct->_entries[entryIndex]._voiceNum, -1, v0, 0x7F);
+ driver->proc42(vtStruct->_entries[entryIndex]._voiceNum, voiceType, 0);
+ }
+ break;
+ }
+ }
+}
+
+void Sound::_soProc38(VoiceTypeStruct *vtStruct, int channelNum, VoiceType voiceType, int cmd, int value) {
+ if (cmd == 64) {
+ if (value == 0) {
+ for (uint entryIndex = 0; entryIndex < vtStruct->_entries.size(); ++entryIndex) {
+ VoiceStructEntryType1 &vte = vtStruct->_entries[entryIndex]._type1;
+
+ if ((vte._sound == this) && (vte._channelNum == channelNum) && (vte._field5 != 0)) {
+ SoundDriver *driver = vtStruct->_entries[entryIndex]._driver;
+ assert(driver);
+
+ vte._field4 = -1;
+ vte._field5 = 0;
+ driver->updateVoice(vtStruct->_entries[entryIndex]._voiceNum);
+ }
+ }
+ }
+ } else if (cmd == 75) {
+ _soundManager->_needToRethink = true;
+ } else {
+ for (uint entryIndex = 0; entryIndex < vtStruct->_entries.size(); ++entryIndex) {
+ VoiceStructEntry &vte = vtStruct->_entries[entryIndex];
+
+ if ((vte._type1._sound == this) && (vte._type1._channelNum == channelNum)) {
+ SoundDriver *driver = vte._driver;
+ assert(driver);
+
+ driver->proc38(vte._voiceNum, cmd, value);
+ }
+ }
+ }
+}
+
+void Sound::_soProc40(VoiceTypeStruct *vtStruct, int channelNum, int pitchBlend) {
+ for (uint entryIndex = 0; entryIndex < vtStruct->_entries.size(); ++entryIndex) {
+ VoiceStructEntryType1 &vte = vtStruct->_entries[entryIndex]._type1;
+
+ if ((vte._sound == this) && (vte._channelNum == channelNum)) {
+ SoundDriver *driver = vtStruct->_entries[entryIndex]._driver;
+ assert(driver);
+
+ driver->setPitch(vtStruct->_entries[entryIndex]._voiceNum, pitchBlend);
+ }
+ }
+}
+
+void Sound::_soDoTrackCommand(int channelNum, int command, int value) {
+ switch (command) {
+ case 1:
+ _chModulation[channelNum] = value;
+ break;
+ case 7:
+ _chVolume[channelNum] = value;
+ break;
+ case 10:
+ _chPan[channelNum] = value;
+ break;
+ case 64:
+ _chDamper[channelNum] = value;
+ break;
+ case 75:
+ _chNumVoices[channelNum] = value;
+ break;
+ }
+}
+
+bool Sound::_soDoUpdateTracks(int command, int value) {
+ if ((command == 76) || (_hold != value))
+ return false;
+
+ for (int trackIndex = 0; trackIndex < _trackInfo._numTracks; ++trackIndex) {
+ _trkState[trackIndex] = _trkLoopState[trackIndex];
+ _trkRest[trackIndex] = _trkLoopRest[trackIndex];
+ _trkIndex[trackIndex] = _trkLoopIndex[trackIndex];
+ }
+
+ _timer = _loopTimer;
+ return true;
+}
+
+void Sound::_soSetTrackPos(int trackIndex, int trackPos, int cueValue) {
+ _trkIndex[trackIndex] = trackPos;
+ if (cueValue == 127) {
+ if (!_soundManager->_soTimeIndexFlag)
+ _cueValue = cueValue;
+ } else {
+ for (int idx = 0; idx < _trackInfo._numTracks; ++idx) {
+ _trkLoopState[idx] = _trkState[idx];
+ _trkLoopRest[idx] = _trkRest[idx];
+ _trkLoopIndex[idx] = _trkIndex[idx];
+ }
+
+ _loopTimer = _timer;
+ }
+}
+
+void Sound::_soServiceTrackType1(int trackIndex, const byte *channelData) {
+ if (_soundManager->_soTimeIndexFlag || !_trkState[trackIndex])
+ return;
+
+ int channel = _trkChannel[trackIndex];
+ if (channel == -1)
+ _trkState[trackIndex] = 0;
+ else {
+ int voiceType = _chVoiceType[channel];
+ VoiceTypeStruct *vtStruct = _soundManager->_voiceTypeStructPtrs[voiceType];
+
+ if (!vtStruct)
+ _trkState[trackIndex] = 0;
+ else {
+ if (vtStruct->_voiceType != VOICETYPE_0) {
+ if (_trkState[trackIndex] == 1) {
+ int entryIndex = _soFindSound(vtStruct, *(channelData + 1));
+ if (entryIndex != -1) {
+ SoundDriver *driver = vtStruct->_entries[entryIndex]._driver;
+ assert(driver);
+
+ vtStruct->_entries[entryIndex]._type1._field6 = 0;
+ vtStruct->_entries[entryIndex]._type1._field4 = *(channelData + 1);
+ vtStruct->_entries[entryIndex]._type1._field5 = 0;
+
+ driver->proc32(vtStruct->_entries[entryIndex]._voiceNum, -1, *(channelData + 1), 0x7f);
+ }
+ } else {
+
+ }
+ }
+ }
+ }
+}
+
+int Sound::_soFindSound(VoiceTypeStruct *vtStruct, int channelNum) {
+ int entryIndex = -1, entry2Index = -1;
+ int v6 = 0, v8 = 0;
+
+ for (uint idx = 0; idx < vtStruct->_entries.size(); ++idx) {
+ VoiceStructEntryType1 &vte = vtStruct->_entries[idx]._type1;
+ if ((vte._channelNum == channelNum) && (vte._sound == this)) {
+ int v = vte._field6;
+ if (vte._field4 != -1) {
+ if (v8 <= v) {
+ v8 = v;
+ entry2Index = idx;
+ }
+ } else {
+ if (v6 <= v) {
+ v6 = v;
+ entryIndex = idx;
+ }
+ }
+ }
+ }
+
+ if (entryIndex != -1)
+ return entryIndex;
+ else if ((entryIndex == -1) && (entry2Index == -1))
+ return -1;
+ else {
+ SoundDriver *driver = vtStruct->_entries[entry2Index]._driver;
+ assert(driver);
+ driver->updateVoice(vtStruct->_entries[entry2Index]._voiceNum);
+
+ return entry2Index;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+
+ASound::ASound(): EventHandler() {
+ _action = NULL;
+ _cueValue = -1;
+}
+
+void ASound::synchronize(Serializer &s) {
+ EventHandler::synchronize(s);
+
+ SYNC_POINTER(_action);
+ s.syncAsByte(_cueValue);
+}
+
+void ASound::dispatch() {
+ EventHandler::dispatch();
+
+ int cueValue = _sound.getCueValue();
+ if (cueValue != -1) {
+ _cueValue = cueValue;
+ _sound.setCueValue(-1);
+
+ if (_action)
+ _action->signal();
+ }
+
+ if (_cueValue != -1) {
+ if (!_sound.isPrimed()) {
+ _cueValue = -1;
+ if (_action) {
+ _action->signal();
+ _action = NULL;
+ }
+ }
+ }
+}
+
+void ASound::play(int soundNum, Action *action, int volume) {
+ _action = action;
+ _cueValue = 0;
+
+ setVol(volume);
+ _sound.play(soundNum);
+}
+
+void ASound::stop() {
+ _sound.stop();
+ _action = NULL;
+}
+
+void ASound::prime(int soundResID, Action *action) {
+ _action = action;
+ _cueValue = 0;
+ _sound.prime(soundResID);
+}
+
+void ASound::unPrime() {
+ _sound.unPrime();
+ _action = NULL;
+}
+
+void ASound::fade(int v1, int v2, int v3, int v4, Action *action) {
+ if (action)
+ _action = action;
+
+ _sound.fade(v1, v2, v3, v4);
+}
+
+
+/*--------------------------------------------------------------------------*/
+
+SoundDriver::SoundDriver() {
+ _driverResID = 0;
+ _minVersion = _maxVersion = 0;
+ _groupMask = 0;
+}
+
+/*--------------------------------------------------------------------------*/
+
+const byte adlib_group_data[] = { 1, 1, 9, 1, 0xff };
+
+const byte v440B0[9] = { 0, 1, 2, 6, 7, 8, 12, 13, 14 };
+
+const byte v440B9[9] = { 3, 4, 5, 9, 10, 11, 15, 16, 17 };
+
+const byte v440C2[18] = {
+ 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 16, 17, 18, 19, 20, 21
+};
+
+const byte v44134[64] = {
+ 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
+ 33, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
+ 46, 47, 47, 48, 49, 50, 50, 51, 52, 52, 53, 54, 54, 55,
+ 56, 56, 57, 57, 58, 58, 59, 59, 59, 60, 60, 60, 61, 61,
+ 61, 62, 62, 62, 62, 63, 63, 63
+};
+
+const int v440D4[48] = {
+ 343, 348, 353, 358, 363, 369, 374, 379, 385, 391, 396,
+ 402, 408, 414, 420, 426, 432, 438, 445, 451, 458, 465,
+ 471, 478, 485, 492, 499, 507, 514, 521, 529, 537, 544,
+ 552, 560, 569, 577, 585, 594, 602, 611, 620, 629, 638,
+ 647, 657, 666, 676
+};
+
+AdlibSoundDriver::AdlibSoundDriver(): SoundDriver() {
+ _minVersion = 0x102;
+ _maxVersion = 0x10A;
+ _masterVolume = 0;
+
+ _groupData.groupMask = 9;
+ _groupData.v1 = 0x46;
+ _groupData.v2 = 0;
+ _groupData.pData = &adlib_group_data[0];
+
+ _mixer = _vm->_mixer;
+ _sampleRate = _mixer->getOutputRate();
+ _opl = makeAdLibOPL(_sampleRate);
+
+ Common::set_to(_channelVoiced, _channelVoiced + ADLIB_CHANNEL_COUNT, false);
+ memset(_channelVolume, 0, ADLIB_CHANNEL_COUNT * sizeof(int));
+ memset(_v4405E, 0, ADLIB_CHANNEL_COUNT * sizeof(int));
+ memset(_v44067, 0, ADLIB_CHANNEL_COUNT * sizeof(int));
+ memset(_v44070, 0, ADLIB_CHANNEL_COUNT * sizeof(int));
+ memset(_v44079, 0, ADLIB_CHANNEL_COUNT * sizeof(int));
+ memset(_v44082, 0, ADLIB_CHANNEL_COUNT * sizeof(int));
+ _v44082[ADLIB_CHANNEL_COUNT] = 0x90;
+ Common::set_to(_pitchBlend, _pitchBlend + ADLIB_CHANNEL_COUNT, 0x2000);
+ memset(_v4409E, 0, ADLIB_CHANNEL_COUNT * sizeof(int));
+ _patchData = NULL;
+}
+
+AdlibSoundDriver::~AdlibSoundDriver() {
+ DEALLOCATE(_patchData);
+ OPLDestroy(_opl);
+}
+
+bool AdlibSoundDriver::open() {
+ write(1, 0x20);
+ if (!reset())
+ return false;
+
+ write(8, 0);
+ for (int idx = 0x20; idx < 0xF6; ++idx)
+ write(idx, 0);
+
+ write(0xBD, 0);
+ return true;
+}
+
+void AdlibSoundDriver::close() {
+ for (int idx = 0xB0; idx < 0xB8; ++idx)
+ write(idx, _portContents[idx] & 0xDF);
+ for (int idx = 0x40; idx < 0x55; ++idx)
+ write(idx, 0x3F);
+ reset();
+}
+
+bool AdlibSoundDriver::reset() {
+ write(1, 0x20);
+ write(4, 0x80);
+
+ write(2, 1);
+ write(4, 1);
+
+ return true;
+}
+
+const GroupData *AdlibSoundDriver::getGroupData() {
+ return &_groupData;
+}
+
+void AdlibSoundDriver::installPatch(const byte *data, int size) {
+ byte *patchData = ALLOCATE(size);
+ Common::copy(data, data + size, patchData);
+ _patchData = patchData;
+}
+
+int AdlibSoundDriver::setMasterVolume(int volume) {
+ int oldVolume = _masterVolume;
+ _masterVolume = volume;
+
+ for (int channelNum = 0; channelNum < ADLIB_CHANNEL_COUNT; ++channelNum)
+ updateChannelVolume(channelNum);
+
+ return oldVolume;
+}
+
+void AdlibSoundDriver::proc32(int channel, int program, int v0, int v1) {
+ if (program == -1)
+ return;
+
+ int offset = READ_LE_UINT16(_patchData + program * 2);
+ if (offset) {
+ const byte *dataP = _patchData + offset;
+
+ for (int offset = 2, id = 0; id != READ_LE_UINT16(dataP); offset += 30, ++id) {
+ if ((dataP[offset] <= v0) && (dataP[offset + 1] >= v0)) {
+ if (dataP[offset + 2] != 0xff)
+ v0 = dataP[offset + 2];
+
+ _v4409E[channel] = dataP + offset - _patchData;
+
+ // Set sustain/release
+ int portNum = v440C2[v440B0[channel]] + 0x80;
+ write(portNum, (_portContents[portNum] & 0xF0) | 0xF);
+
+ portNum = v440C2[v440B9[channel]] + 0x80;
+ write(portNum, (_portContents[portNum] & 0xF0) | 0xF);
+
+ if (_channelVoiced[channel])
+ clearVoice(channel);
+
+ _v44067[channel] = v0;
+ _v4405E[channel] = v1;
+
+ updateChannel(channel);
+ setFrequency(channel);
+ updateChannelVolume(channel);
+ setVoice(channel);
+ break;
+ }
+ }
+ }
+}
+
+void AdlibSoundDriver::updateVoice(int channel) {
+ if (_channelVoiced[channel])
+ clearVoice(channel);
+}
+
+void AdlibSoundDriver::proc38(int channel, int cmd, int value) {
+ if (cmd == 7) {
+ // Set channel volume
+ _channelVolume[channel] = value;
+ updateChannelVolume(channel);
+ }
+}
+
+void AdlibSoundDriver::setPitch(int channel, int pitchBlend) {
+ _pitchBlend[channel] = pitchBlend;
+ setFrequency(channel);
+}
+
+void AdlibSoundDriver::write(byte reg, byte value) {
+ _portContents[reg] = value;
+ OPLWriteReg(_opl, reg, value);
+}
+
+void AdlibSoundDriver::updateChannelVolume(int channelNum) {
+ int volume = (_masterVolume * _channelVolume[channelNum] / 127 * _v4405E[channelNum] / 127) / 2;
+ int level2 = 63 - v44134[volume * _v44079[channelNum] / 63];
+ int level1 = !_v44082[channelNum] ? 63 - _v44070[channelNum] :
+ 63 - v44134[volume * _v44070[channelNum] / 63];
+
+ int portNum = v440C2[v440B0[channelNum]] + 0x40;
+ write(portNum, (_portContents[portNum] & 0x80) | level1);
+
+ portNum = v440C2[v440B9[channelNum]] + 0x40;
+ write(portNum, (_portContents[portNum] & 0x80) | level2);
+}
+
+void AdlibSoundDriver::setVoice(int channel) {
+ int portNum = 0xB0 + channel;
+ write(portNum, _portContents[portNum] | 0x20);
+ _channelVoiced[channel] = true;
+}
+
+void AdlibSoundDriver::clearVoice(int channel) {
+ write(0xB0 + channel, _portContents[0xB0 + channel] & ~0x20);
+ _channelVoiced[channel] = false;
+}
+
+void AdlibSoundDriver::updateChannel(int channel) {
+ const byte *dataP = _patchData + _v4409E[channel];
+ int portOffset = v440C2[v440B0[channel]];
+
+ int portNum = portOffset + 0x20;
+ int portValue = 0;
+ if (*(dataP + 4))
+ portValue |= 0x80;
+ if (*(dataP + 5))
+ portValue |= 0x40;
+ if (*(dataP + 8))
+ portValue |= 0x20;
+ if (*(dataP + 6))
+ portValue |= 0x10;
+ portValue |= *(dataP + 7);
+ write(portNum, portValue);
+
+ portValue = (_portContents[0x40 + portOffset] & 0x3F) | (*(dataP + 9) << 6);
+ write(0x40 + portOffset, portValue);
+
+ _v44070[channel] = 63 - *(dataP + 10);
+ write(0x60 + portOffset, *(dataP + 12) | (*(dataP + 11) << 4));
+ write(0x80 + portOffset, *(dataP + 14) | (*(dataP + 13) << 4));
+ write(0xE0 + portOffset, (_portContents[0xE0 + portOffset] & 0xFC) | *(dataP + 15));
+
+ portOffset = v440C2[v440B9[channel]];
+ portNum = portOffset + 0x20;
+ portValue = 0;
+ if (*(dataP + 17))
+ portValue |= 0x80;
+ if (*(dataP + 18))
+ portValue |= 0x40;
+ if (*(dataP + 21))
+ portValue |= 0x20;
+ if (*(dataP + 19))
+ portValue |= 0x10;
+ portValue |= *(dataP + 20);
+ write(portNum, portValue);
+
+ write(0x40 + portOffset, (_portContents[0x40 + portOffset] & 0x3f) | (*(dataP + 22) << 6));
+ _v44079[channel] = 0x3F - *(dataP + 23);
+ write(0x60 + portOffset, *(dataP + 25) | (*(dataP + 24) << 4));
+ write(0x80 + portOffset, *(dataP + 27) | (*(dataP + 26) << 4));
+ write(0xE0 + portOffset, (_portContents[0xE0 + portOffset] & 0xFC) | *(dataP + 28));
+
+ write(0xC0 + channel, (_portContents[0xC0 + channel] & 0xF0)
+ | (*(dataP + 16) << 1) | *(dataP + 3));
+
+ _v44082[channel] = *(dataP + 3);
+}
+
+void AdlibSoundDriver::setFrequency(int channel) {
+ int offset, ch;
+
+ int v = _pitchBlend[channel];
+ if (v == 0x2000) {
+ offset = 0;
+ ch = _v44067[channel];
+ } else if (v > 0x2000) {
+ ch = _v44067[channel];
+ v -= 0x2000;
+ if (v == 0x1fff)
+ v = 0x2000;
+
+ offset = (v / 170) & 3;
+ ch += (v / 170) >> 2;
+
+ if (ch >= 128)
+ ch = 127;
+ } else {
+ ch = _v44067[channel];
+ int tempVal = (0x2000 - v) / 170;
+ int tempVal2 = 4 - (tempVal & 3);
+
+ if (tempVal2 == 4)
+ offset = 0;
+ else {
+ offset = tempVal2;
+ --ch;
+ }
+
+ ch -= tempVal >> 2;
+ if (ch < 0)
+ ch = 0;
+ }
+
+ int var2 = ch / 12;
+ if (var2)
+ --var2;
+
+ int dataWord = v440D4[((ch % 12) << 2) + offset];
+ write(0xA0 + channel, dataWord & 0xff);
+ write(0xB0 + channel, (_portContents[0xB0 + channel] & 0xE0) |
+ ((dataWord >> 8) & 3) | (var2 << 2));
}
} // End of namespace tSage
diff --git a/engines/tsage/sound.h b/engines/tsage/sound.h
index 03ae77b703..4bef27d2c9 100644
--- a/engines/tsage/sound.h
+++ b/engines/tsage/sound.h
@@ -24,21 +24,409 @@
#define TSAGE_SOUND_H
#include "common/scummsys.h"
+#include "audio/audiostream.h"
+#include "audio/fmopl.h"
+#include "audio/mixer.h"
+#include "common/list.h"
#include "tsage/saveload.h"
+#include "tsage/core.h"
namespace tSage {
+class Sound;
+
+#define SOUND_ARR_SIZE 16
+#define ROLAND_DRIVER_NUM 2
+#define ADLIB_DRIVER_NUM 3
+
+struct trackInfoStruct {
+ int _numTracks;
+ int _chunks[SOUND_ARR_SIZE];
+ int _voiceTypes[SOUND_ARR_SIZE];
+};
+
+enum SoundDriverStatus {SNDSTATUS_FAILED = 0, SNDSTATUS_DETECTED = 1, SNDSTATUS_SKIPPED = 2};
+enum VoiceType {VOICETYPE_0 = 0, VOICETYPE_1 = 1};
+
+class SoundDriverEntry {
+public:
+ int driverNum;
+ SoundDriverStatus status;
+ int field2, field6;
+ Common::String shortDescription;
+ Common::String longDescription;
+};
+
+struct GroupData {
+ uint32 groupMask;
+ byte v1;
+ byte v2;
+ const byte *pData;
+};
+
+class SoundDriver {
+public:
+ Common::String _shortDescription, _longDescription;
+ int _minVersion, _maxVersion;
+ // The following fields were originally held in separate arrays in the SoundManager class
+ uint32 _groupMask;
+ const GroupData *_groupOffset;
+ int _driverResID;
+public:
+ SoundDriver();
+
+ const Common::String &getShortDriverDescription() { return _shortDescription; }
+ const Common::String &getLongDriverDescription() { return _longDescription; }
+
+ virtual bool open() { return true; } // Method #0
+ virtual void close() {} // Method #1
+ virtual bool reset() { return true; } // Method #2
+ virtual const GroupData *getGroupData() { return NULL; } // Method #3
+ virtual void installPatch(const byte *data, int size) {} // Method #4
+ virtual void poll() {} // Method #5
+ virtual void proc12() {} // Method #6
+ virtual int setMasterVolume(int volume) { return 0; } // Method #7
+ virtual void proc16() {} // Method #8
+ virtual void proc18(int al, VoiceType voiceType) {} // Method #9
+ virtual void proc20(int al, VoiceType voiceType) {} // Method #10
+ virtual void proc22(int al, VoiceType voiceType, int v3) {} // Method #11
+ virtual void proc24(int channel, int voiceIndex, Sound *sound, int v1, int v2) {}
+ virtual void setProgram(int channel, int program) {} // Method #13
+ virtual void setVolume1(int channel, int v2, int v3, int volume) {}
+ virtual void setPitchBlend(int channel, int pitchBlend) {} // Method #15
+ virtual void proc32(int channel, int program, int v0, int v1) {}// Method #16
+ virtual void updateVoice(int channel) {} // Method #17
+ virtual void proc36() {} // Method #18
+ virtual void proc38(int channel, int cmd, int value) {} // Method #19
+ virtual void setPitch(int channel, int pitchBlend) {} // Method #20
+ virtual void proc42(int channel, int v0, int v1) {} // Method #21
+};
+
+struct VoiceStructEntryType0 {
+ Sound *_sound;
+ int _channelNum;
+ int _priority;
+ int _fieldA;
+ Sound *_sound2;
+ int _channelNum2;
+ int _priority2;
+ int _field12;
+ Sound *_sound3;
+ int _channelNum3;
+ int _priority3;
+ int _field1A;
+ int _field1B;
+};
+
+struct VoiceStructEntryType1 {
+ int _field4;
+ int _field5;
+ int _field6;
+ Sound *_sound;
+ int _channelNum;
+ int _priority;
+ Sound *_sound2;
+ int _channelNum2;
+ int _priority2;
+ Sound *_sound3;
+ int _channelNum3;
+ int _priority3;
+};
+
+struct VoiceStructEntry {
+ int _voiceNum;
+ int _field1;
+ SoundDriver *_driver;
+
+ VoiceStructEntryType0 _type0;
+ VoiceStructEntryType1 _type1;
+};
+
+class VoiceTypeStruct {
+public:
+ VoiceType _voiceType;
+ int _total;
+ int _numVoices;
+ int _field3;
+
+ Common::Array<VoiceStructEntry> _entries;
+};
+
class SoundManager : public SaveListener {
+private:
+ SoundDriver *instantiateDriver(int driverNum);
+public:
+ bool __sndmgrReady;
+ int _ourSndResVersion, _ourDrvResVersion;
+ Common::List<Sound *> _playList;
+ Common::List<SoundDriver *> _installedDrivers;
+ VoiceTypeStruct *_voiceTypeStructPtrs[SOUND_ARR_SIZE];
+ uint32 _groupsAvail;
+ int _masterVol;
+ int _serverDisabledCount;
+ int _serverSuspendedCount;
+ int _suspendedCount;
+ bool _driversDetected;
+ Common::List<Sound *> _soundList;
+ Common::List<SoundDriverEntry> _availableDrivers;
+ bool _needToRethink;
+ // Misc flags
+ bool _soTimeIndexFlag;
public:
- void dispatch() {}
+ SoundManager();
+ ~SoundManager();
+
+ void dispatch();
virtual void listenerSynchronize(Serializer &s);
virtual void postInit();
+ void syncSounds();
- void proc2() {}
static void saveNotifier(bool postFlag);
void saveNotifierProc(bool postFlag);
static void loadNotifier(bool postFlag);
void loadNotifierProc(bool postFlag);
+
+ void installConfigDrivers();
+ Common::List<SoundDriverEntry> &buildDriverList(bool detectFlag);
+ Common::List<SoundDriverEntry> &getDriverList(bool detectFlag);
+ void dumpDriverList();
+ void installDriver(int driverNum);
+ bool isInstalled(int driverNum) const;
+ void unInstallDriver(int driverNum);
+ void disableSoundServer();
+ void enableSoundServer();
+ void suspendSoundServer();
+ void restartSoundServer();
+ void checkResVersion(const byte *soundData);
+ int determineGroup(const byte *soundData);
+ int extractPriority(const byte *soundData);
+ int extractLoop(const byte *soundData);
+ bool isOnPlayList(Sound *sound);
+ void extractTrackInfo(trackInfoStruct *trackInfo, const byte *soundData, int groupNum);
+ void addToSoundList(Sound *sound);
+ void removeFromSoundList(Sound *sound);
+ void addToPlayList(Sound *sound);
+ void removeFromPlayList(Sound *sound);
+ void rethinkVoiceTypes();
+ void updateSoundVol(Sound *sound);
+ void updateSoundPri(Sound *sound);
+ void updateSoundLoop(Sound *sound);
+ void setMasterVol(int volume);
+ int getMasterVol() const;
+ void loadSound(int soundNum, bool showErrors);
+ void unloadSound(int soundNum);
+
+ // _sf methods
+ static SoundManager &sfManager();
+ static void _sfTerminate();
+ static int _sfDetermineGroup(const byte *soundData);
+ static void _sfAddToPlayList(Sound *sound);
+ static void _sfRemoveFromPlayList(Sound *sound);
+ static bool _sfIsOnPlayList(Sound *sound);
+ static void _sfRethinkSoundDrivers();
+ static void _sfRethinkVoiceTypes();
+ static void _sfUpdateVolume(Sound *sound);
+ static void _sfDereferenceAll();
+ static void _sfUpdatePriority(Sound *sound);
+ static void _sfUpdateLoop(Sound *sound);
+ static void _sfSetMasterVol(int volume);
+ static void _sfExtractTrackInfo(trackInfoStruct *trackInfo, const byte *soundData, int groupNum);
+ static void _sfExtractGroupMask();
+ static bool _sfInstallDriver(SoundDriver *driver);
+ static void _sfUnInstallDriver(SoundDriver *driver);
+ static void _sfInstallPatchBank(SoundDriver *driver, const byte *bankData);
+ static void _sfDoAddToPlayList(Sound *sound);
+ static bool _sfDoRemoveFromPlayList(Sound *sound);
+ static void _sfDoUpdateVolume(Sound *sound);
+ static void _sfSoundServer();
+ static void _sfProcessFading();
+ static void _sfUpdateVoiceStructs();
+ static void _sfUpdateVoiceStructs2();
+};
+
+class Sound: public EventHandler {
+private:
+ void _prime(int soundResID, bool queueFlag);
+ void _unPrime();
+ void orientAfterRestore();
+public:
+ bool _stoppedAsynchronously;
+ int _soundResID;
+ int _group;
+ int _sndResPriority;
+ int _fixedPriority;
+ bool _sndResLoop;
+ bool _fixedLoop;
+ int _priority;
+ int _volume;
+ int _loop;
+ int _pausedCount;
+ int _mutedCount;
+ int _hold;
+ int _cueValue;
+ int _fadeDest;
+ int _fadeSteps;
+ int _fadeTicks;
+ int _fadeCounter;
+ bool _stopAfterFadeFlag;
+ uint _timer;
+ int _loopTimer;
+ int _chProgram[SOUND_ARR_SIZE];
+ int _chModulation[SOUND_ARR_SIZE];
+ int _chVolume[SOUND_ARR_SIZE];
+ int _chPan[SOUND_ARR_SIZE];
+ int _chDamper[SOUND_ARR_SIZE];
+ int _chPitchBlend[SOUND_ARR_SIZE];
+ int _chVoiceType[SOUND_ARR_SIZE];
+ int _chNumVoices[SOUND_ARR_SIZE];
+ int _chSubPriority[SOUND_ARR_SIZE];
+ int _chFlags[SOUND_ARR_SIZE];
+ bool _chWork[SOUND_ARR_SIZE];
+ trackInfoStruct _trackInfo;
+ byte *_channelData[SOUND_ARR_SIZE];
+ int _trkChannel[SOUND_ARR_SIZE];
+ int _trkState[SOUND_ARR_SIZE];
+ int _trkLoopState[SOUND_ARR_SIZE];
+ int _trkIndex[SOUND_ARR_SIZE];
+ int _trkLoopIndex[SOUND_ARR_SIZE];
+ int _trkRest[SOUND_ARR_SIZE];
+ int _trkLoopRest[SOUND_ARR_SIZE];
+
+ bool _primed;
+ bool _isEmpty;
+ byte *_remoteReceiver;
+public:
+ Sound();
+ ~Sound();
+
+ void play(int soundResID);
+ void stop();
+ void prime(int soundResID);
+ void unPrime();
+ void go();
+ void halt(void);
+ bool isPlaying();
+ int getSoundNum() const;
+ bool isPrimed() const;
+ bool isPaused() const;
+ bool isMuted() const;
+ void pause(bool flag);
+ void mute(bool flag);
+ void fade(int fadeDest, int fadeTicks, int fadeSteps, bool stopAfterFadeFlag);
+ void setTimeIndex(uint32 timeIndex);
+ uint32 getTimeIndex() const;
+ int getCueValue() const;
+ void setCueValue(int cueValue);
+ void setVol(int volume);
+ int getVol() const;
+ void setPri(int priority);
+ void setLoop(bool flag);
+ int getPri() const;
+ bool getLoop();
+ void holdAt(int amount);
+ void release();
+ void orientAfterDriverChange();
+
+ // _so methods
+ void _soPrimeSound(bool queueFlag);
+ void _soSetTimeIndex(uint timeIndex);
+ bool _soServiceTracks();
+ void _soPrimeChannelData();
+ void _soRemoteReceive();
+ void _soServiceTrackType0(int trackIndex, const byte *channelData);
+ void _soUpdateDamper(VoiceTypeStruct *voiceType, int channelNum, VoiceType mode, int v0);
+ void _soProc32(VoiceTypeStruct *vtStruct, int channelNum, VoiceType voiceType, int v0, int v1);
+ void _soProc42(VoiceTypeStruct *vtStruct, int channelNum, VoiceType voiceType, int v0);
+ void _soProc38(VoiceTypeStruct *vtStruct, int channelNum, VoiceType voiceType, int cmd, int value);
+ void _soProc40(VoiceTypeStruct *vtStruct, int channelNum, int pitchBlend);
+ void _soDoTrackCommand(int channelNum, int command, int value);
+ bool _soDoUpdateTracks(int command, int value);
+ void _soSetTrackPos(int trackIndex, int trackPos, int cueValue);
+
+ void _soServiceTrackType1(int trackIndex, const byte *channelData);
+ int _soFindSound(VoiceTypeStruct *vtStruct, int channelNum);
+};
+
+class ASound: public EventHandler {
+public:
+ Sound _sound;
+ Action *_action;
+ int _cueValue;
+
+ ASound();
+ virtual void synchronize(Serializer &s);
+ virtual void dispatch();
+
+ void play(int soundNum, Action *action = NULL, int volume = 127);
+ void stop();
+ void prime(int soundNum, Action *action = NULL);
+ void unPrime();
+ void go() { _sound.go(); }
+ void hault(void) { _sound.halt(); }
+ bool isPlaying() { return _sound.isPlaying(); }
+ int getSoundNum() const { return _sound.getSoundNum(); }
+ bool isPaused() const { return _sound.isPaused(); }
+ bool isMuted() const { return _sound.isMuted(); }
+ void pause(bool flag) { _sound.pause(flag); }
+ void mute(bool flag) { _sound.mute(flag); }
+ void fadeIn() { fade(127, 5, 10, 0, NULL); }
+ void fadeOut(Action *action) { fade(0, 5, 10, 1, action); }
+ void fade(int v1, int v2, int v3, int v4, Action *action);
+ void setTimeIndex(uint32 timeIndex) { _sound.setTimeIndex(timeIndex); }
+ uint32 getTimeIndex() const { return _sound.getTimeIndex(); }
+ void setPri(int v) { _sound.setPri(v); }
+ void setLoop(bool flag) { _sound.setLoop(flag); }
+ int getPri() const { return _sound.getPri(); }
+ bool getLoop() { return _sound.getLoop(); }
+ void setVol(int volume) { _sound.setVol(volume); }
+ int getVol() const { return _sound.getVol(); }
+ void holdAt(int v) { _sound.holdAt(v); }
+ void release() { _sound.release(); }
+};
+
+#define ADLIB_CHANNEL_COUNT 9
+
+class AdlibSoundDriver: public SoundDriver {
+private:
+ GroupData _groupData;
+ Audio::Mixer *_mixer;
+ FM_OPL *_opl;
+ int _sampleRate;
+ byte _portContents[256];
+ const byte *_patchData;
+ int _masterVolume;
+
+ bool _channelVoiced[ADLIB_CHANNEL_COUNT];
+ int _channelVolume[ADLIB_CHANNEL_COUNT];
+ int _v4405E[ADLIB_CHANNEL_COUNT];
+ int _v44067[ADLIB_CHANNEL_COUNT];
+ int _v44070[ADLIB_CHANNEL_COUNT];
+ int _v44079[ADLIB_CHANNEL_COUNT];
+ int _v44082[ADLIB_CHANNEL_COUNT + 1];
+ int _pitchBlend[ADLIB_CHANNEL_COUNT];
+ int _v4409E[ADLIB_CHANNEL_COUNT];
+
+
+ void write(byte reg, byte value);
+ void updateChannelVolume(int channel);
+ void setVoice(int channel);
+ void clearVoice(int channel);
+ void updateChannel(int channel);
+ void setFrequency(int channel);
+public:
+ AdlibSoundDriver();
+ ~AdlibSoundDriver();
+
+ virtual bool open();
+ virtual void close();
+ virtual bool reset();
+ virtual const GroupData *getGroupData();
+ virtual void installPatch(const byte *data, int size);
+ virtual int setMasterVolume(int volume);
+ virtual void proc32(int channel, int program, int v0, int v1);
+ virtual void updateVoice(int channel);
+ virtual void proc38(int channel, int cmd, int value);
+ virtual void setPitch(int channel, int pitchBlend);
};
} // End of namespace tSage
diff --git a/engines/tsage/tsage.cpp b/engines/tsage/tsage.cpp
index 50ce0ce4be..41f3d58897 100644
--- a/engines/tsage/tsage.cpp
+++ b/engines/tsage/tsage.cpp
@@ -81,12 +81,17 @@ void TSageEngine::initialize() {
_globals = new Globals();
_globals->gfxManager().setDefaults();
+
+ // Setup sound settings
+ syncSoundSettings();
}
void TSageEngine::deinitialize() {
delete _globals;
delete _resourceManager;
delete _saver;
+ _resourceManager = NULL;
+ _saver = NULL;
}
Common::Error TSageEngine::run() {
@@ -136,4 +141,10 @@ Common::String TSageEngine::generateSaveName(int slot) {
return Common::String::format("%s.%03d", _targetName.c_str(), slot);
}
+void TSageEngine::syncSoundSettings() {
+ Engine::syncSoundSettings();
+
+ _globals->_soundManager.syncSounds();
+}
+
} // End of namespace tSage
diff --git a/engines/tsage/tsage.h b/engines/tsage/tsage.h
index 5db45f24ab..f004c7f625 100644
--- a/engines/tsage/tsage.h
+++ b/engines/tsage/tsage.h
@@ -51,7 +51,9 @@ enum {
};
enum {
- kRingDebugScripts = 1 << 0
+ kRingDebugScripts = 1 << 0,
+ ktSageSound = 1 << 1,
+ ktSageCore = 1 << 2
};
struct tSageGameDescription;
@@ -83,6 +85,7 @@ public:
virtual bool canSaveGameStateCurrently();
virtual Common::Error loadGameState(int slot);
virtual Common::Error saveGameState(int slot, const Common::String &desc);
+ virtual void syncSoundSettings();
Common::String generateSaveName(int slot);
void initialize();