GLK: Sound volume and pausing methods

This commit is contained in:
Paul Gilbert 2018-12-08 20:22:31 -08:00
parent 34d01af004
commit 867adc6dca
3 changed files with 61 additions and 7 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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;