aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/pink/objects/actions/action_play_with_sfx.cpp23
-rw-r--r--engines/pink/objects/actions/action_play_with_sfx.h10
-rw-r--r--engines/pink/objects/actions/action_sound.cpp29
-rw-r--r--engines/pink/objects/actions/action_sound.h9
-rw-r--r--engines/pink/objects/actions/action_talk.cpp11
-rw-r--r--engines/pink/objects/actions/action_talk.h2
-rw-r--r--engines/pink/objects/pages/page.cpp4
-rw-r--r--engines/pink/objects/pages/page.h2
-rw-r--r--engines/pink/objects/sequences/sequence.cpp12
-rw-r--r--engines/pink/objects/sequences/sequence.h3
-rw-r--r--engines/pink/resource_mgr.cpp6
-rw-r--r--engines/pink/resource_mgr.h5
-rw-r--r--engines/pink/sound.cpp42
-rw-r--r--engines/pink/sound.h29
14 files changed, 55 insertions, 132 deletions
diff --git a/engines/pink/objects/actions/action_play_with_sfx.cpp b/engines/pink/objects/actions/action_play_with_sfx.cpp
index 056ce6e9b3..3805b8fe3c 100644
--- a/engines/pink/objects/actions/action_play_with_sfx.cpp
+++ b/engines/pink/objects/actions/action_play_with_sfx.cpp
@@ -78,13 +78,6 @@ void ActionPlayWithSfx::updateSound() {
}
}
-ActionSfx::ActionSfx()
- : _sound(nullptr) {}
-
-ActionSfx::~ActionSfx() {
- end();
-}
-
void ActionSfx::deserialize(Pink::Archive &archive) {
_frame = archive.readDWORD();
_volume = archive.readDWORD();
@@ -97,20 +90,8 @@ void ActionSfx::toConsole() {
}
void ActionSfx::play(Page *page) {
- if (!_sound)
- _sound = page->loadSound(_sfxName);
-
- if (!_sound->isPlaying())
- _sound->play(Audio::Mixer::kSFXSoundType, _volume, 0);
-}
-
-void ActionSfx::end() {
- delete _sound;
- _sound = nullptr;
-}
-
-uint32 ActionSfx::getFrame() {
- return _frame;
+ if (!_sound.isPlaying())
+ _sound.play(page->getResourceStream(_sfxName), Audio::Mixer::kSFXSoundType, _volume);
}
} // End of namespace Pink
diff --git a/engines/pink/objects/actions/action_play_with_sfx.h b/engines/pink/objects/actions/action_play_with_sfx.h
index 7e8b0c8ed2..16a3cada99 100644
--- a/engines/pink/objects/actions/action_play_with_sfx.h
+++ b/engines/pink/objects/actions/action_play_with_sfx.h
@@ -24,6 +24,7 @@
#define PINK_ACTION_PLAY_WITH_SFX_H
#include "pink/objects/actions/action_play.h"
+#include "pink/sound.h"
namespace Pink {
@@ -49,26 +50,21 @@ private:
uint32 _isLoop;
};
-class Sound;
class Page;
class ActionSfx : public Object {
public:
- ActionSfx();
- ~ActionSfx() override;
-
void deserialize(Archive &archive) override;
void toConsole() override;
void play(Page *page);
- void end();
- uint32 getFrame();
+ uint32 getFrame() { return _frame; }
private:
- Sound *_sound;
Common::String _sfxName;
+ Sound _sound;
uint32 _volume;
uint32 _frame;
};
diff --git a/engines/pink/objects/actions/action_sound.cpp b/engines/pink/objects/actions/action_sound.cpp
index d63d57c7f3..e67717f04a 100644
--- a/engines/pink/objects/actions/action_sound.cpp
+++ b/engines/pink/objects/actions/action_sound.cpp
@@ -31,10 +31,7 @@
namespace Pink {
-ActionSound::ActionSound()
- : _sound(nullptr) {}
-
-ActionSound::~ActionSound(){
+ActionSound::~ActionSound() {
end();
}
@@ -52,16 +49,12 @@ void ActionSound::toConsole() {
}
void ActionSound::start() {
- assert(!_sound);
- _sound = _actor->getPage()->loadSound(_fileName);
-
- Audio::Mixer::SoundType soundType = _isBackground ? Audio::Mixer::kMusicSoundType
- : Audio::Mixer::kSpeechSoundType;
+ Audio::Mixer::SoundType soundType = _isBackground ? Audio::Mixer::kMusicSoundType : Audio::Mixer::kSFXSoundType;
Director *director = _actor->getPage()->getGame()->getDirector();
director->addSound(this);
- _sound->play(soundType, _volume, _isLoop);
+ _sound.play(_actor->getPage()->getResourceStream(_fileName), soundType, _volume, _isLoop);
if (_isLoop)
_actor->endAction();
@@ -69,25 +62,21 @@ void ActionSound::start() {
}
void ActionSound::end() {
- if (_sound) {
- debug("ActionSound %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
+ _sound.stop();
+ debug("ActionSound %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());
- Director *director = _actor->getPage()->getGame()->getDirector();
- director->removeSound(this);
+ Director *director = _actor->getPage()->getGame()->getDirector();
+ director->removeSound(this);
- delete _sound;
- _sound = nullptr;
- }
}
void ActionSound::update() {
- if (!_sound->isPlaying())
+ if (!_sound.isPlaying())
_actor->endAction();
}
void ActionSound::pause(bool paused) {
- if (_sound)
- _sound->pause(paused);
+ _sound.pause(paused);
}
} // End of namespace Pink
diff --git a/engines/pink/objects/actions/action_sound.h b/engines/pink/objects/actions/action_sound.h
index c614951557..e502f34293 100644
--- a/engines/pink/objects/actions/action_sound.h
+++ b/engines/pink/objects/actions/action_sound.h
@@ -24,16 +24,13 @@
#define PINK_ACTION_SOUND_H
#include "pink/objects/actions/action.h"
+#include "pink/sound.h"
namespace Pink {
-class Sound;
-
class ActionSound : public Action {
public:
- ActionSound();
- ~ActionSound();
-
+ ~ActionSound() override;
void deserialize(Archive &archive) override;
void toConsole() override;
@@ -46,8 +43,8 @@ public:
void pause(bool paused) override;
private:
- Sound *_sound;
Common::String _fileName;
+ Sound _sound;
uint32 _volume;
bool _isLoop;
bool _isBackground;
diff --git a/engines/pink/objects/actions/action_talk.cpp b/engines/pink/objects/actions/action_talk.cpp
index c142dca0e6..f46afb312c 100644
--- a/engines/pink/objects/actions/action_talk.cpp
+++ b/engines/pink/objects/actions/action_talk.cpp
@@ -42,7 +42,7 @@ void ActionTalk::toConsole() {
void ActionTalk::update() {
ActionLoop::update();
- if (!_sound->isPlaying()) {
+ if (!_sound.isPlaying()) {
_decoder->stop();
_actor->endAction();
}
@@ -50,20 +50,17 @@ void ActionTalk::update() {
void ActionTalk::end() {
ActionPlay::end();
- delete _sound;
- _sound = nullptr;
+ _sound.stop();
}
void ActionTalk::pause(bool paused) {
ActionCEL::pause(paused);
- if (_sound)
- _sound->pause(paused);
+ _sound.pause(paused);
}
void ActionTalk::onStart() {
ActionPlay::onStart();
- _sound = _actor->getPage()->loadSound(_vox);
- _sound->play(Audio::Mixer::kSpeechSoundType, 100, 0);
+ _sound.play(_actor->getPage()->getResourceStream(_vox), Audio::Mixer::kSpeechSoundType);
}
} // End of namespace Pink
diff --git a/engines/pink/objects/actions/action_talk.h b/engines/pink/objects/actions/action_talk.h
index 672e0249a6..f29dc0f5fc 100644
--- a/engines/pink/objects/actions/action_talk.h
+++ b/engines/pink/objects/actions/action_talk.h
@@ -45,7 +45,7 @@ protected:
void onStart() override;
private:
- Sound *_sound;
+ Sound _sound;
Common::String _vox;
};
diff --git a/engines/pink/objects/pages/page.cpp b/engines/pink/objects/pages/page.cpp
index 2266cd5a2a..bb93d17f93 100644
--- a/engines/pink/objects/pages/page.cpp
+++ b/engines/pink/objects/pages/page.cpp
@@ -47,10 +47,6 @@ Actor *Page::findActor(const Common::String &name) {
return nullptr;
}
-Sound *Page::loadSound(Common::String &fileName) {
- return _resMgr.loadSound(fileName);
-}
-
CelDecoder *Page::loadCel(Common::String &fileName) {
return _resMgr.loadCEL(fileName);
diff --git a/engines/pink/objects/pages/page.h b/engines/pink/objects/pages/page.h
index 0ed16db2c8..9ccfe20166 100644
--- a/engines/pink/objects/pages/page.h
+++ b/engines/pink/objects/pages/page.h
@@ -46,7 +46,7 @@ public:
Actor *findActor(const Common::String &name);
LeadActor *getLeadActor();
- Sound *loadSound(Common::String &fileName);
+ Common::SafeSeekableSubReadStream *getResourceStream(const Common::String &fileName) { return _resMgr.getResourceStream(fileName); }
CelDecoder *loadCel(Common::String &fileName);
virtual void clear();
diff --git a/engines/pink/objects/sequences/sequence.cpp b/engines/pink/objects/sequences/sequence.cpp
index 8e2f38c549..e7d5783050 100644
--- a/engines/pink/objects/sequences/sequence.cpp
+++ b/engines/pink/objects/sequences/sequence.cpp
@@ -160,27 +160,25 @@ void SequenceAudio::start(int unk) {
}
void SequenceAudio::end() {
- delete _sound;
- _sound = nullptr;
+ _sound.stop();
Sequence::end();
}
void SequenceAudio::update() {
- if (!_sound->isPlaying())
+ if (!_sound.isPlaying())
end();
- else if (_sample <= _sound->getCurrentSample())
+ else if (_sample <= _sound.getCurrentSample())
start(0);
}
void SequenceAudio::init(int unk) {
_sample = 0;
- _sound = _sequencer->_page->loadSound(_soundName);
- _sound->play(Audio::Mixer::kMusicSoundType, 100, 0);
+ _sound.play(_sequencer->_page->getResourceStream(_soundName), Audio::Mixer::kMusicSoundType);
Sequence::init(unk);
}
void SequenceAudio::restart() {
- _sound->play(Audio::Mixer::kMusicSoundType, 100, 0);
+ _sound.play(_sequencer->_page->getResourceStream(_soundName), Audio::Mixer::kMusicSoundType);
Sequence::restart();
}
diff --git a/engines/pink/objects/sequences/sequence.h b/engines/pink/objects/sequences/sequence.h
index 34863256f2..93dcb25d26 100644
--- a/engines/pink/objects/sequences/sequence.h
+++ b/engines/pink/objects/sequences/sequence.h
@@ -23,6 +23,7 @@
#ifndef PINK_SEQUENCE_H
#define PINK_SEQUENCE_H
+#include "pink/sound.h"
#include "pink/objects/object.h"
namespace Pink {
@@ -79,7 +80,7 @@ public:
private:
Common::String _soundName;
- Sound *_sound;
+ Sound _sound;
uint _sample;
};
diff --git a/engines/pink/resource_mgr.cpp b/engines/pink/resource_mgr.cpp
index 98792d23f7..ebaf219ddc 100644
--- a/engines/pink/resource_mgr.cpp
+++ b/engines/pink/resource_mgr.cpp
@@ -59,10 +59,6 @@ CelDecoder *ResourceMgr::loadCEL(Common::String &name) {
return decoder;
}
-Sound *ResourceMgr::loadSound(Common::String &name) {
- return new Sound(_game->_mixer, getResourceStream(name));
-}
-
Common::String ResourceMgr::loadText(Common::String &name) {
Common::SeekableReadStream *stream = getResourceStream(name);
char *txt = new char[stream->size()];
@@ -79,7 +75,7 @@ PinkEngine *ResourceMgr::getGame() const {
return _game;
}
-Common::SafeSeekableSubReadStream *ResourceMgr::getResourceStream(Common::String &name) {
+Common::SafeSeekableSubReadStream *ResourceMgr::getResourceStream(const Common::String &name) {
Common::SeekableReadStream *stream;
ResourceDescription *desc = (ResourceDescription*) bsearch(name.c_str(), _resDescTable, _resCount, sizeof(ResourceDescription), resDescComp);
diff --git a/engines/pink/resource_mgr.h b/engines/pink/resource_mgr.h
index 4b050eb3ae..0cdf2ae8ba 100644
--- a/engines/pink/resource_mgr.h
+++ b/engines/pink/resource_mgr.h
@@ -50,15 +50,14 @@ public:
void clear();
+ Common::SafeSeekableSubReadStream *getResourceStream(const Common::String &name);
+
CelDecoder *loadCEL(Common::String &name);
- Sound *loadSound(Common::String &name);
Common::String loadText(Common::String &name);
PinkEngine *getGame() const;
private:
- Common::SafeSeekableSubReadStream *getResourceStream(Common::String &name);
-
PinkEngine *_game;
ResourceDescription *_resDescTable;
uint32 _resCount;
diff --git a/engines/pink/sound.cpp b/engines/pink/sound.cpp
index 333093e063..81463b29bf 100644
--- a/engines/pink/sound.cpp
+++ b/engines/pink/sound.cpp
@@ -30,44 +30,22 @@
namespace Pink {
-Sound::Sound(Audio::Mixer *mixer, Common::SafeSeekableSubReadStream *stream)
- : _mixer(mixer), _fileStream(stream) {}
-
-Sound::~Sound() {
- _mixer->stopHandle(_handle);
- delete _fileStream;
-}
-
-bool Sound::isPlaying() {
- return _mixer->isSoundHandleActive(_handle);
-}
-
-void Sound::pause(bool paused) {
- _mixer->pauseHandle(_handle, paused);
-}
-
-void Sound::play(Audio::Mixer::SoundType type, int volume, bool isLoop) {
+void Sound::play(Common::SafeSeekableSubReadStream *stream, Audio::Mixer::SoundType type, byte volume, int8 balance, bool isLoop) {
// Vox files in pink have wave format.
// RIFF (little-endian) data, WAVE audio, Microsoft PCM, 8 bit, mono 22050 Hz
- _mixer->stopHandle(_handle);
- _fileStream->seek(0);
- Audio::AudioStream *audioStream ;
- Audio::SeekableAudioStream *wavStream = Audio::makeWAVStream(_fileStream, DisposeAfterUse::NO);
- if (isLoop) {
+ volume = ((int) volume * 255) / 100;
+ Audio::Mixer *mixer = g_system->getMixer();
+ mixer->stopHandle(_handle);
+
+ Audio::AudioStream *audioStream;
+ Audio::SeekableAudioStream *wavStream = Audio::makeWAVStream(stream, DisposeAfterUse::NO);
+ if (isLoop)
audioStream = Audio::makeLoopingAudioStream(wavStream, 0, 0, 0);
- } else
+ else
audioStream = wavStream;
- _mixer->playStream(type, &_handle , audioStream, -1 , 50, 0, DisposeAfterUse::YES);
-}
-
-void Sound::setBalance(int8 balance) {
- _mixer->setChannelBalance(_handle, balance);
-}
-
-uint32 Sound::getCurrentSample() {
- return _mixer->getSoundElapsedTime(_handle) * kSampleRate / 1000;
+ mixer->playStream(type, &_handle , audioStream, -1, volume, balance, DisposeAfterUse::YES);
}
} // End of namespace Pink
diff --git a/engines/pink/sound.h b/engines/pink/sound.h
index a5e7cca6ed..f18fb9fe21 100644
--- a/engines/pink/sound.h
+++ b/engines/pink/sound.h
@@ -25,35 +25,30 @@
#include "audio/mixer.h"
-#include "common/stream.h"
-#include "common/substream.h"
+#include "common/system.h"
-namespace Pink {
+namespace Common {
+ class SafeSeekableSubReadStream;
+}
-/*TODO
- from disasm foreground 100 %, background 80 %
- dont know how to properly do it
- may be use ConfMan
-*/
+namespace Pink {
class Sound {
public:
- Sound(Audio::Mixer *mixer, Common::SafeSeekableSubReadStream *stream);
- ~Sound();
+ ~Sound() { stop(); }
+
+ void play(Common::SafeSeekableSubReadStream *stream, Audio::Mixer::SoundType type, byte volume = 100, int8 balance = 0, bool isLoop = false);
- void play(Audio::Mixer::SoundType type, int volume, bool isLoop);
+ bool isPlaying() { return g_system->getMixer()->isSoundHandleActive(_handle); }
- bool isPlaying();
+ void stop() { g_system->getMixer()->stopHandle(_handle); }
- void pause(bool paused);
+ void pause(bool paused) { g_system->getMixer()->pauseHandle(_handle, paused); }
- uint32 getCurrentSample();
- void setBalance(int8 balance);
+ uint32 getCurrentSample() { return g_system->getMixer()->getSoundElapsedTime(_handle) * 22050 / 1000; }
private:
- Audio::Mixer *_mixer;
Audio::SoundHandle _handle;
- Common::SafeSeekableSubReadStream *_fileStream;
};
} // End of namespace Pink