aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/glk/glk_api.cpp24
-rw-r--r--engines/glk/sound.cpp25
-rw-r--r--engines/glk/sound.h19
3 files changed, 61 insertions, 7 deletions
diff --git a/engines/glk/glk_api.cpp b/engines/glk/glk_api.cpp
index 08dce8cd12..f638ea3a0d 100644
--- a/engines/glk/glk_api.cpp
+++ b/engines/glk/glk_api.cpp
@@ -1022,7 +1022,11 @@ void GlkAPI::glk_schannel_stop(schanid_t chan) {
}
void GlkAPI::glk_schannel_set_volume(schanid_t chan, glui32 vol) {
- // TODO
+ if (chan) {
+ chan->setVolume(vol);
+ } else {
+ warning("schannel_set_volume: invalid ref");
+ }
}
void GlkAPI::glk_sound_load_hint(glui32 snd, glui32 flag) {
@@ -1041,16 +1045,28 @@ glui32 GlkAPI::glk_schannel_play_multi(schanid_t *chanarray, glui32 chancount,
}
void GlkAPI::glk_schannel_pause(schanid_t chan) {
- // TODO
+ if (chan) {
+ chan->pause();
+ } else {
+ warning("schannel_pause: invalid ref");
+ }
}
void GlkAPI::glk_schannel_unpause(schanid_t chan) {
- // TODO
+ if (chan) {
+ chan->unpause();
+ } else {
+ warning("schannel_unpause: invalid ref");
+ }
}
void GlkAPI::glk_schannel_set_volume_ext(schanid_t chan, glui32 vol,
glui32 duration, glui32 notify) {
- // TODO
+ if (chan) {
+ chan->setVolume(vol, duration, notify);
+ } else {
+ warning("schannel_set_volume_ext: invalid ref");
+ }
}
void GlkAPI::glk_set_hyperlink(glui32 linkval) {
diff --git a/engines/glk/sound.cpp b/engines/glk/sound.cpp
index 02fb7f9253..0e3fbf48ee 100644
--- a/engines/glk/sound.cpp
+++ b/engines/glk/sound.cpp
@@ -144,10 +144,29 @@ void SoundChannel::stop() {
}
void SoundChannel::poll() {
- if (!g_vm->_mixer->isSoundHandleActive(_handle) && _notify != 0)
- g_vm->_events->store(evtype_SoundNotify, 0,
- _soundNum, _notify);
+ if (!g_vm->_mixer->isSoundHandleActive(_handle) && _notify != 0) {
+ glui32 notify = _notify;
+ _notify = 0;
+ g_vm->_events->store(evtype_SoundNotify, nullptr, _soundNum, notify);
+ }
+}
+
+void SoundChannel::setVolume(uint volume, uint duration, uint notify) {
+ uint newVol = volume * 255 / 0x10000;
+ g_vm->_mixer->setChannelVolume(_handle, newVol);
+
+ if (notify) {
+ warning("TODO: Gradual volume change");
+ g_vm->_events->store(evtype_VolumeNotify, nullptr, 0, notify);
+ }
+}
+
+void SoundChannel::pause() {
+ g_vm->_mixer->pauseHandle(_handle, true);
+}
+void SoundChannel::unpause() {
+ g_vm->_mixer->pauseHandle(_handle, false);
}
} // End of namespace Glk
diff --git a/engines/glk/sound.h b/engines/glk/sound.h
index 514a5f6ad2..9635302b8d 100644
--- a/engines/glk/sound.h
+++ b/engines/glk/sound.h
@@ -68,6 +68,25 @@ public:
* Poll for whether a playing sound was finished
*/
void poll();
+
+ /**
+ * Change the volume
+ * @param volume Volume from 0 (silence) to 0x10000 (full volume)
+ * @param duration Optional duration for a gradual volume change
+ * @param notify If non-zero, triggers a evtype_VolumeNotify when
+ * the volume change duration finishes
+ */
+ void setVolume(uint volume, uint duration = 0, uint notify = 0);
+
+ /**
+ * Pause playback
+ */
+ void pause();
+
+ /**
+ * Unpause playback
+ */
+ void unpause();
};
typedef SoundChannel *schanid_t;