aboutsummaryrefslogtreecommitdiff
path: root/engines/pegasus
diff options
context:
space:
mode:
Diffstat (limited to 'engines/pegasus')
-rwxr-xr-xengines/pegasus/sound.cpp49
-rwxr-xr-xengines/pegasus/sound.h23
2 files changed, 60 insertions, 12 deletions
diff --git a/engines/pegasus/sound.cpp b/engines/pegasus/sound.cpp
index 847106aa4d..3fd7a2a867 100755
--- a/engines/pegasus/sound.cpp
+++ b/engines/pegasus/sound.cpp
@@ -116,17 +116,6 @@ void Sound::playSoundSegment(uint32 start, uint32 end) {
g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_handle, subStream, -1, _volume, 0, DisposeAfterUse::YES);
}
-void Sound::loopSoundSegment(uint32 start, uint32 end) {
- if (!isSoundLoaded())
- return;
-
- stopSound();
-
- Audio::AudioStream *subLoopStream = new Audio::SubLoopingAudioStream(_stream, 0, Audio::Timestamp(0, start, 600), Audio::Timestamp(0, end, 600), DisposeAfterUse::NO);
-
- g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_handle, subLoopStream, -1, _volume, 0, DisposeAfterUse::YES);
-}
-
void Sound::stopSound() {
g_system->getMixer()->stopHandle(_handle);
}
@@ -147,4 +136,42 @@ bool Sound::isSoundLoaded() const {
return _stream != 0;
}
+SoundTimeBase::SoundTimeBase() {
+ setScale(600);
+ _startScale = 600;
+ _stopScale = 600;
+ _setToStart = false;
+}
+
+void SoundTimeBase::playSoundSegment(uint32 startTime, uint32 endTime) {
+ _startTime = startTime;
+ _stopTime = endTime;
+ _setToStart = true;
+ _time = Common::Rational(startTime, getScale());
+ setRate(1);
+ Sound::playSoundSegment(startTime, endTime);
+}
+
+void SoundTimeBase::updateTime() {
+ if (_setToStart) {
+ if (isPlaying()) {
+ // Not at the end, let's get the time
+ uint numFrames = g_system->getMixer()->getSoundElapsedTime(_handle) * 600 / 1000;
+
+ // WORKAROUND: Our mixer is woefully inaccurate and quite often returns
+ // times that exceed the actual length of the clip. We'll just fake times
+ // that are under the final time to ensure any trigger for the end time is
+ // only sent when the sound has actually stopped.
+ if (numFrames >= (_stopTime - _startTime))
+ numFrames = _stopTime - _startTime - 1;
+
+ _time = Common::Rational(_startTime + numFrames, getScale());
+ } else {
+ // Assume we reached the end
+ _setToStart = false;
+ _time = Common::Rational(_stopTime, getScale());
+ }
+ }
+}
+
} // End of namespace Pegasus
diff --git a/engines/pegasus/sound.h b/engines/pegasus/sound.h
index f66c3f4250..f6e175dd73 100755
--- a/engines/pegasus/sound.h
+++ b/engines/pegasus/sound.h
@@ -28,6 +28,7 @@
#include "audio/mixer.h"
#include "common/str.h"
+#include "pegasus/timers.h"
namespace Audio {
class SeekableAudioStream;
@@ -67,7 +68,6 @@ public:
void playSound();
void loopSound();
void playSoundSegment(uint32 start, uint32 end);
- void loopSoundSegment(uint32 start, uint32 end);
void stopSound();
void setVolume(const uint16 volume);
bool isPlaying();
@@ -82,6 +82,27 @@ protected:
SoundFader *_fader;
};
+// TODO: Make this class follow TimeBase better
+// Right now it's just a loose wrapper to plug callbacks
+// into sounds. Since this is only used for spot sounds,
+// I'm not too worried about it right now as its usage
+// is very limited.
+// At the very least, the regular TimeBase functions for
+// setting/getting should be neutered.
+class SoundTimeBase : public Sound, public TimeBase {
+public:
+ SoundTimeBase();
+ ~SoundTimeBase() {}
+
+ void playSoundSegment(uint32 start, uint32 end);
+
+protected:
+ void updateTime();
+
+private:
+ bool _setToStart;
+};
+
} // End of namespace Pegasus
#endif