aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorJaromir Wysoglad2019-06-03 10:56:24 +0200
committerThierry Crozat2019-07-28 15:09:14 +0100
commit63ca424ac30e8651969983507edd30dc43dc1d35 (patch)
treec7bb62706b6e9052676a81cb1214b78ed06b4a88 /engines
parentb9c528425ae154660e2c2c3041b5dc285a1621e0 (diff)
downloadscummvm-rg350-63ca424ac30e8651969983507edd30dc43dc1d35.tar.gz
scummvm-rg350-63ca424ac30e8651969983507edd30dc43dc1d35.tar.bz2
scummvm-rg350-63ca424ac30e8651969983507edd30dc43dc1d35.zip
SUPERNOVA2: Add sound to all rooms currently coded
Diffstat (limited to 'engines')
-rw-r--r--engines/supernova2/module.mk1
-rw-r--r--engines/supernova2/resman.cpp60
-rw-r--r--engines/supernova2/resman.h16
-rw-r--r--engines/supernova2/rooms.cpp5
-rw-r--r--engines/supernova2/sound.cpp65
-rw-r--r--engines/supernova2/sound.h65
-rw-r--r--engines/supernova2/state.cpp21
-rw-r--r--engines/supernova2/state.h3
-rw-r--r--engines/supernova2/supernova2.cpp22
-rw-r--r--engines/supernova2/supernova2.h7
10 files changed, 219 insertions, 46 deletions
diff --git a/engines/supernova2/module.mk b/engines/supernova2/module.mk
index f62af5f1a7..7135c9c7a5 100644
--- a/engines/supernova2/module.mk
+++ b/engines/supernova2/module.mk
@@ -8,6 +8,7 @@ MODULE_OBJS := \
rooms.o \
screen.o \
console.o \
+ sound.o \
supernova2.o
MODULE_DIRS += \
diff --git a/engines/supernova2/resman.cpp b/engines/supernova2/resman.cpp
index a47a155b2f..ac060ac0c8 100644
--- a/engines/supernova2/resman.cpp
+++ b/engines/supernova2/resman.cpp
@@ -42,30 +42,20 @@ struct AudioInfo {
int _offsetEnd;
};
-//static Common::MemoryReadStream *convertToMod(const char *filename, int version = 1);
-
-/*static const AudioInfo audioInfo[kAudioNumSamples] = {
- {44, 0, -1},
- {45, 0, -1},
- {46, 0, 2510},
- {46, 2510, 4020},
- {46, 4020, -1},
- {47, 0, 24010},
- {47, 24010, -1},
- {48, 0, 2510},
- {48, 2510, 10520},
- {48, 10520, 13530},
- {48, 13530, -1},
- {50, 0, 12786},
- {50, 12786, -1},
- {51, 0, -1},
+static Common::MemoryReadStream *convertToMod(const char *filename, int version = 2);
+
+static const AudioInfo audioInfo[kAudioNumSamples] = {
+ {55, 18230, -1},
+ {47, 0, 16010},
+ {47, 16010, -1},
+ {49, 8010, -1},
+ {49, 0, 8010},
+ {52, 0, -1},
{53, 0, -1},
- {54, 0, 8010},
- {54, 8010, 24020},
- {54, 24020, 30030},
- {54, 30030, 31040},
- {54, 31040, -1}
-};*/
+ {54, 0, -1},
+ {55, 0, -1},
+ {56, 0, -1},
+};
static const byte mouseNormal[64] = {
0xff,0x3f,0xff,0x1f,0xff,0x0f,0xff,0x07,
@@ -94,12 +84,11 @@ static const byte mouseWait[64] = {
ResourceManager::ResourceManager()
: _audioRate(11931) {
- //initSoundFiles();
+ initSoundFiles();
initGraphics();
}
-//TODO
-/*void ResourceManager::initSoundFiles() {
+void ResourceManager::initSoundFiles() {
// Sound
// Note:
// - samples start with a header of 6 bytes: 01 SS SS 00 AD 00
@@ -109,7 +98,7 @@ ResourceManager::ResourceManager()
Common::File file;
for (int i = 0; i < kAudioNumSamples; ++i) {
- if (!file.open(Common::String::format("msn_data.%03d", audioInfo[i]._filenumber))) {
+ if (!file.open(Common::String::format("ms2_data.%03d", audioInfo[i]._filenumber))) {
error("File %s could not be read!", file.getName());
}
@@ -132,9 +121,9 @@ ResourceManager::ResourceManager()
streamFlag, DisposeAfterUse::YES));
}
- _musicIntroBuffer.reset(convertToMod("msn_data.052"));
- _musicOutroBuffer.reset(convertToMod("msn_data.049"));
-}*/
+ _musicIntroBuffer.reset(convertToMod("ms2_data.052"));
+ _musicOutroBuffer.reset(convertToMod("ms2_data.049"));
+}
void ResourceManager::initGraphics() {
Screen::initPalette();
@@ -170,8 +159,7 @@ void ResourceManager::initImages() {
}
}
-//TODO
-/*Audio::SeekableAudioStream *ResourceManager::getSoundStream(AudioId index) {
+Audio::SeekableAudioStream *ResourceManager::getSoundStream(AudioId index) {
Audio::SeekableAudioStream *stream = _soundSamples[index].get();
stream->rewind();
@@ -189,7 +177,7 @@ Audio::AudioStream *ResourceManager::getSoundStream(MusicId index) {
default:
error("Invalid music constant in playAudio()");
}
-}*/
+}
const MS2Image *ResourceManager::getImage(int filenumber) const {
if (filenumber < 47)
@@ -209,10 +197,8 @@ const byte *ResourceManager::getImage(CursorId id) const {
}
}
-//TODO
-/*
static Common::MemoryReadStream *convertToMod(const char *filename, int version) {
- // MSN format
+ // MS2 format
struct {
uint16 seg;
uint16 start;
@@ -396,6 +382,6 @@ static Common::MemoryReadStream *convertToMod(const char *filename, int version)
return new Common::MemoryReadStream(buffer.getData(), buffer.size(), DisposeAfterUse::YES);
}
-*/
+
}
diff --git a/engines/supernova2/resman.h b/engines/supernova2/resman.h
index 72b7d78bfd..16e237eadb 100644
--- a/engines/supernova2/resman.h
+++ b/engines/supernova2/resman.h
@@ -27,7 +27,7 @@
#include "common/ptr.h"
#include "supernova2/graphics.h"
-//#include "supernova/sound.h"
+#include "supernova2/sound.h"
namespace Common {
@@ -49,8 +49,8 @@ public:
public:
ResourceManager();
- //Audio::SeekableAudioStream *getSoundStream(AudioId index);
- //Audio::AudioStream *getSoundStream(MusicId index);
+ Audio::SeekableAudioStream *getSoundStream(AudioId index);
+ Audio::AudioStream *getSoundStream(MusicId index);
const MS2Image *getImage(int filenumber) const;
const byte *getImage(CursorId id) const;
@@ -61,11 +61,11 @@ private:
void initImages();
private:
- //Common::ScopedPtr<Audio::SeekableAudioStream> _soundSamples[kAudioNumSamples];
- //Common::ScopedPtr<Common::MemoryReadStream> _musicIntroBuffer;
- //Common::ScopedPtr<Common::MemoryReadStream> _musicOutroBuffer;
- //Common::ScopedPtr<Audio::AudioStream> _musicIntro;
- //Common::ScopedPtr<Audio::AudioStream> _musicOutro;
+ Common::ScopedPtr<Audio::SeekableAudioStream> _soundSamples[kAudioNumSamples];
+ Common::ScopedPtr<Common::MemoryReadStream> _musicIntroBuffer;
+ Common::ScopedPtr<Common::MemoryReadStream> _musicOutroBuffer;
+ Common::ScopedPtr<Audio::AudioStream> _musicIntro;
+ Common::ScopedPtr<Audio::AudioStream> _musicOutro;
int _audioRate;
MS2Image _images[kNumImageFiles];
byte _cursorNormal[256];
diff --git a/engines/supernova2/rooms.cpp b/engines/supernova2/rooms.cpp
index 1969d8439f..a95c522428 100644
--- a/engines/supernova2/rooms.cpp
+++ b/engines/supernova2/rooms.cpp
@@ -258,6 +258,7 @@ void Intro::titleScreen() {
const Common::String title1 = "V1.02";
_vm->_screen->renderText(title1, 295, 190, 3);
+ _vm->playSound(kMusicIntro);
Marquee marquee(_vm->_screen, Marquee::kMarqueeIntro, _introText.c_str());
while (!_vm->shouldQuit()) {
_gm->updateEvents();
@@ -267,6 +268,7 @@ void Intro::titleScreen() {
g_system->updateScreen();
g_system->delayMillis(_vm->_delay);
}
+ _vm->stopSound();
_vm->paletteFadeOut();
CursorMan.showMouse(true);
}
@@ -408,8 +410,10 @@ bool Intro::tvDialogue() {
_gm->wait(3);
_vm->renderImage(i);
}
+ _vm->playSound(kAudioIntroDing);
_gm->wait(30);
_vm->renderImage(11);
+ _vm->playSound(kAudioIntroDing);
_gm->wait(60);
_vm->_system->fillScreen(kColorBlack);
@@ -673,6 +677,7 @@ bool Street::interact(Action verb, Object &obj1, Object &obj2) {
else {
_vm->renderMessage(kStringSawPole);
_gm->takeObject(*getObject(3));
+ _vm->playSound(kAudioSuccess);
}
}
else if (verb == ACTION_WALK && obj1._id == REAR_STREET) {
diff --git a/engines/supernova2/sound.cpp b/engines/supernova2/sound.cpp
new file mode 100644
index 0000000000..f08158a879
--- /dev/null
+++ b/engines/supernova2/sound.cpp
@@ -0,0 +1,65 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+*/
+
+#include "audio/audiostream.h"
+#include "audio/mixer.h"
+#include "audio/decoders/raw.h"
+#include "audio/mods/protracker.h"
+#include "common/system.h"
+
+#include "supernova2/resman.h"
+#include "supernova2/sound.h"
+#include "supernova2/supernova2.h"
+
+namespace Supernova2 {
+
+Sound::Sound(Audio::Mixer *mixer, ResourceManager *resMan)
+ : _mixer(mixer)
+ , _resMan(resMan) {
+}
+
+void Sound::play(AudioId index) {
+ Audio::AudioStream *stream = _resMan->getSoundStream(index);
+
+ stop();
+ _mixer->playStream(Audio::Mixer::kPlainSoundType, &_soundHandle, stream,
+ -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
+}
+
+void Sound::play(MusicId index) {
+ Audio::AudioStream *stream = _resMan->getSoundStream(index);
+
+ stop();
+ _mixer->playStream(Audio::Mixer::kMusicSoundType, &_soundHandle, stream,
+ -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO);
+}
+
+bool Sound::isPlaying() {
+ return _mixer->isSoundHandleActive(_soundHandle);
+}
+
+void Sound::stop() {
+ if (_mixer->isSoundHandleActive(_soundHandle))
+ _mixer->stopHandle(_soundHandle);
+}
+
+}
diff --git a/engines/supernova2/sound.h b/engines/supernova2/sound.h
new file mode 100644
index 0000000000..30c05eea2c
--- /dev/null
+++ b/engines/supernova2/sound.h
@@ -0,0 +1,65 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef SUPERNOVA2_SOUND_H
+#define SUPERNOVA2_SOUND_H
+
+#include "audio/mixer.h"
+
+namespace Supernova2 {
+
+class Supernova2Engine;
+class ResourceManager;
+
+enum AudioId {
+ kAudioIntroDing,
+ kAudioSuccess,
+ kAudioTaxiOpen,
+ kAudioTaxiLeaving,
+ kAudioTaxiArriving,
+ kAudioNumSamples = 10 //TODO find out how many samples there are
+};
+
+enum MusicId {
+ kMusicIntro = 52,
+ kMusicOutro = 56
+};
+
+class Sound {
+public:
+
+public:
+ Sound(Audio::Mixer *mixer, ResourceManager *resMan);
+
+ void play(AudioId index);
+ void play(MusicId index);
+ void stop();
+ bool isPlaying();
+private:
+ Audio::Mixer *_mixer;
+ ResourceManager *_resMan;
+ Audio::SoundHandle _soundHandle;
+};
+
+}
+
+#endif
diff --git a/engines/supernova2/state.cpp b/engines/supernova2/state.cpp
index 766529a0ed..d179011b37 100644
--- a/engines/supernova2/state.cpp
+++ b/engines/supernova2/state.cpp
@@ -972,6 +972,18 @@ void GameManager::handleTime() {
_oldTime = newTime;
}
+void GameManager::pauseTimer(bool pause) {
+ if (pause == _timerPaused)
+ return;
+
+ if (pause) {
+ _timerPaused = true;
+ } else {
+ _oldTime = g_system->getMillis();
+ _timerPaused = false;
+ }
+}
+
int GameManager::invertSection(int section) {
if (section < 128)
section += 128;
@@ -990,6 +1002,7 @@ bool GameManager::genericInteract(Action verb, Object &obj1, Object &obj2) {
takeObject(*_rooms[TAXISTAND]->getObject(4));
takeObject(*_rooms[TAXISTAND]->getObject(5));
takeMoney(1);
+ _vm->playSound(kAudioSuccess);
}
} else if (verb == ACTION_PRESS && obj1._id == TRANSMITTER) {
if (_currentRoom == _rooms[TAXISTAND]) {
@@ -997,6 +1010,7 @@ bool GameManager::genericInteract(Action verb, Object &obj1, Object &obj2) {
_vm->renderImage(5);
wait(3);
_vm->renderImage(6);
+ _vm->playSound(kAudioTaxiOpen);
_currentRoom->getObject(0)->_type = EXIT;
drawMapExits();
}
@@ -1064,6 +1078,7 @@ bool GameManager::genericInteract(Action verb, Object &obj1, Object &obj2) {
case 2:
_vm->renderMessage(kStringTransferCD);
_state._admission = 2;
+ _vm->playSound(kAudioSuccess);
break;
default:
_vm->renderMessage(kStringCDNotInserted);
@@ -1258,6 +1273,9 @@ void GameManager::taxiPayment(int price, int destination) {
Common::String t = _vm->getGameString(kStringTaxiAccelerating);
_vm->renderMessage(t);
+ _vm->playSound(kAudioTaxiLeaving);
+ while(_vm->_sound->isPlaying())
+ wait(1);
waitOnInput((t.size() + 20) * _vm->_textSpeed / 10);
_vm->removeMessage();
@@ -1267,6 +1285,9 @@ void GameManager::taxiPayment(int price, int destination) {
Common::String t2 = _vm->getGameString(kString5MinutesLater);
_vm->renderMessage(t2);
+ _vm->playSound(kAudioTaxiArriving);
+ while(_vm->_sound->isPlaying())
+ wait(1);
waitOnInput((t2.size() + 20) * _vm->_textSpeed / 10);
_vm->removeMessage();
diff --git a/engines/supernova2/state.h b/engines/supernova2/state.h
index a355fac075..c69aebce0a 100644
--- a/engines/supernova2/state.h
+++ b/engines/supernova2/state.h
@@ -27,7 +27,7 @@
#include "common/rect.h"
#include "common/keyboard.h"
#include "supernova2/rooms.h"
-//#include "supernova2/sound.h"
+#include "supernova2/sound.h"
namespace Supernova2 {
@@ -181,6 +181,7 @@ public:
void resetInputState();
void handleInput();
void handleTime();
+ void pauseTimer(bool pause);
void setAnimationTimer(int ticks);
int dialog(int num, byte rowLength[6], StringId text[6], int number);
void sentence(int number, bool brightness);
diff --git a/engines/supernova2/supernova2.cpp b/engines/supernova2/supernova2.cpp
index 5572ac2d56..683d711cbe 100644
--- a/engines/supernova2/supernova2.cpp
+++ b/engines/supernova2/supernova2.cpp
@@ -42,6 +42,7 @@
#include "gui/saveload.h"
#include "supernova2/resman.h"
+#include "supernova2/sound.h"
#include "supernova2/screen.h"
#include "supernova2/supernova2.h"
#include "supernova2/state.h"
@@ -77,6 +78,7 @@ Supernova2Engine::Supernova2Engine(OSystem *syst)
: Engine(syst)
, _console(nullptr)
, _gm(nullptr)
+ , _sound(nullptr)
, _resMan(nullptr)
, _screen(nullptr)
, _allowLoadGame(true)
@@ -99,6 +101,7 @@ Supernova2Engine::~Supernova2Engine() {
delete _resMan;
delete _screen;
delete _sleepAutoSave;
+ delete _sound;
}
Common::Error Supernova2Engine::run() {
@@ -130,6 +133,7 @@ void Supernova2Engine::init() {
error("Failed reading game strings");
_resMan = new ResourceManager();
+ _sound = new Sound(_mixer, _resMan);
_gm = new GameManager(this);
_screen = new Screen(this, _resMan);
_console = new Console(this, _gm);
@@ -156,6 +160,12 @@ bool Supernova2Engine::hasFeature(EngineFeature f) const {
}
}
+void Supernova2Engine::pauseEngineIntern(bool pause) {
+ _mixer->pauseAll(pause);
+ _gm->pauseTimer(pause);
+}
+
+
Common::Error Supernova2Engine::loadGameStrings() {
Common::String cur_lang = ConfMan.get("language");
Common::String string_id("TEXT");
@@ -225,6 +235,14 @@ void Supernova2Engine::setGameString(int idx, const Common::String &string) {
_gameStrings[idx] = string;
}
+void Supernova2Engine::playSound(AudioId sample) {
+ _sound->play(sample);
+}
+
+void Supernova2Engine::playSound(MusicId index) {
+ _sound->play(index);
+}
+
void Supernova2Engine::renderImage(int section) {
if (section > 128)
_gm->_currentRoom->setSectionVisible(section - 128, false);
@@ -611,4 +629,8 @@ void Supernova2Engine::errorTempSave(bool saving) {
error("Unrecoverable error");
}
+void Supernova2Engine::stopSound() {
+ _sound->stop();
+}
+
}
diff --git a/engines/supernova2/supernova2.h b/engines/supernova2/supernova2.h
index 4fa80b5067..0e1b0c0e66 100644
--- a/engines/supernova2/supernova2.h
+++ b/engines/supernova2/supernova2.h
@@ -34,6 +34,7 @@
#include "supernova2/graphics.h"
#include "supernova2/ms2_def.h"
#include "supernova2/rooms.h"
+#include "supernova2/sound.h"
#include "supernova2/imageid.h"
namespace Common {
@@ -50,6 +51,7 @@ namespace Supernova2 {
class GuiElement;
class ResourceManager;
+class Sound;
class console;
class GameManager;
class Screen;
@@ -65,9 +67,11 @@ public:
virtual Common::Error saveGameState(int slot, const Common::String &desc);
virtual bool canSaveGameStateCurrently();
virtual bool hasFeature(EngineFeature f) const;
+ virtual void pauseEngineIntern(bool pause);
GameManager *_gm;
Console *_console;
+ Sound *_sound;
ResourceManager *_resMan;
Screen *_screen;
bool _allowLoadGame;
@@ -93,6 +97,8 @@ public:
void setGameString(int idx, const Common::String &string);
// forwarding calls
+ void playSound(AudioId sample);
+ void playSound(MusicId index);
void paletteFadeIn();
void paletteFadeOut();
void paletteBrightness();
@@ -120,6 +126,7 @@ public:
void renderBox(int x, int y, int width, int height, byte color);
void renderBox(const GuiElement &guiElement);
void setColor63(byte value);
+ void stopSound();
};
}