aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2019-03-02 20:43:19 -0800
committerPaul Gilbert2019-03-02 20:43:19 -0800
commit4c708dc97f5c515ba01aee0d5610489fa43fa1f9 (patch)
tree92267e11f516f4a6725546b0ad525d38abfb6986 /engines
parent8393faf036e07f8844ee01e94173da5cdcbb7f77 (diff)
downloadscummvm-rg350-4c708dc97f5c515ba01aee0d5610489fa43fa1f9.tar.gz
scummvm-rg350-4c708dc97f5c515ba01aee0d5610489fa43fa1f9.tar.bz2
scummvm-rg350-4c708dc97f5c515ba01aee0d5610489fa43fa1f9.zip
GLK: FROTZ: Implement os_beep method
I instantiate a PCSpeaker instance in the main engine just for beeps, because I don't know any simpler way. But hey, it works.
Diffstat (limited to 'engines')
-rw-r--r--engines/glk/frotz/glk_interface.cpp1
-rw-r--r--engines/glk/glk.cpp8
-rw-r--r--engines/glk/glk.h7
-rw-r--r--engines/glk/module.mk1
-rw-r--r--engines/glk/pc_speaker.cpp52
-rw-r--r--engines/glk/pc_speaker.h50
6 files changed, 118 insertions, 1 deletions
diff --git a/engines/glk/frotz/glk_interface.cpp b/engines/glk/frotz/glk_interface.cpp
index 7e14e403c0..69b1dc5882 100644
--- a/engines/glk/frotz/glk_interface.cpp
+++ b/engines/glk/frotz/glk_interface.cpp
@@ -322,6 +322,7 @@ void GlkInterface::os_stop_sample(int a) {
}
void GlkInterface::os_beep(int volume) {
+ beep();
}
bool GlkInterface::os_picture_data(int picture, uint *height, uint *width) {
diff --git a/engines/glk/glk.cpp b/engines/glk/glk.cpp
index f39ef6a98a..13f185d586 100644
--- a/engines/glk/glk.cpp
+++ b/engines/glk/glk.cpp
@@ -48,7 +48,7 @@ GlkEngine::GlkEngine(OSystem *syst, const GlkGameDescription &gameDesc) :
_clipboard(nullptr), _conf(nullptr), _events(nullptr), _pictures(nullptr),
_screen(nullptr), _selection(nullptr), _sounds(nullptr), _windows(nullptr),
_copySelect(false), _terminated(false), gli_unregister_obj(nullptr),
- gli_register_arr(nullptr), gli_unregister_arr(nullptr) {
+ _pcSpeaker(nullptr), gli_register_arr(nullptr), gli_unregister_arr(nullptr) {
g_vm = this;
}
@@ -57,6 +57,7 @@ GlkEngine::~GlkEngine() {
delete _clipboard;
delete _conf;
delete _events;
+ delete _pcSpeaker;
delete _pictures;
delete _screen;
delete _selection;
@@ -79,6 +80,7 @@ void GlkEngine::initialize() {
_screen->initialize();
_clipboard = new Clipboard();
_events = new Events();
+ _pcSpeaker = new PCSpeaker(_mixer);
_pictures = new Pictures();
_selection = new Selection();
_sounds = new Sounds();
@@ -199,4 +201,8 @@ Common::Error GlkEngine::saveGameState(int slot, const Common::String &desc) {
return result;
}
+void GlkEngine::beep() {
+ _pcSpeaker->speakerOn(50, 50);
+}
+
} // End of namespace Glk
diff --git a/engines/glk/glk.h b/engines/glk/glk.h
index 17ee3568aa..9064105aa7 100644
--- a/engines/glk/glk.h
+++ b/engines/glk/glk.h
@@ -30,6 +30,7 @@
#include "engines/engine.h"
#include "glk/glk_types.h"
#include "glk/streams.h"
+#include "glk/pc_speaker.h"
namespace Glk {
@@ -77,6 +78,7 @@ protected:
Common::RandomSource _random;
int _loadSaveSlot;
Common::File _gameFile;
+ PCSpeaker *_pcSpeaker;
// Engine APIs
virtual Common::Error run();
@@ -213,6 +215,11 @@ public:
* Save the game to the passed file
*/
virtual Common::Error saveGameData(strid_t file, const Common::String &desc) = 0;
+
+ /**
+ * Generate a beep
+ */
+ void beep();
};
extern GlkEngine *g_vm;
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index a51fb7e413..a38750e201 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -8,6 +8,7 @@ MODULE_OBJS := \
fonts.o \
glk.o \
glk_api.o \
+ pc_speaker.o \
picture.o \
raw_decoder.o \
screen.o \
diff --git a/engines/glk/pc_speaker.cpp b/engines/glk/pc_speaker.cpp
new file mode 100644
index 0000000000..cbfce3e089
--- /dev/null
+++ b/engines/glk/pc_speaker.cpp
@@ -0,0 +1,52 @@
+/* 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/softsynth/pcspk.h"
+#include "glk/pc_speaker.h"
+
+namespace Glk {
+
+PCSpeaker::PCSpeaker(Audio::Mixer *mixer) : _mixer(mixer) {
+ _stream = new Audio::PCSpeaker(_mixer->getOutputRate());
+ _mixer->playStream(Audio::Mixer::kSFXSoundType,
+ &_handle, _stream, -1, 50, 0, DisposeAfterUse::NO, true);
+}
+
+PCSpeaker::~PCSpeaker() {
+ _mixer->stopHandle(_handle);
+ delete _stream;
+}
+
+void PCSpeaker::speakerOn(int16 frequency, int32 length) {
+ _stream->play(Audio::PCSpeaker::kWaveFormSquare, frequency, length);
+}
+
+void PCSpeaker::speakerOff() {
+ _stream->stop();
+}
+
+void PCSpeaker::onUpdate(uint32 millis) {
+ if (_stream->isPlaying())
+ _stream->stop(millis);
+}
+
+} // End of namespace Glk
diff --git a/engines/glk/pc_speaker.h b/engines/glk/pc_speaker.h
new file mode 100644
index 0000000000..8c3d1adea2
--- /dev/null
+++ b/engines/glk/pc_speaker.h
@@ -0,0 +1,50 @@
+/* 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 GLK_PC_SPEAKER_H
+#define GLK_PC_SPEAKER_H
+
+#include "audio/mixer.h"
+
+namespace Audio {
+class PCSpeaker;
+}
+
+namespace Glk {
+
+class PCSpeaker {
+private:
+ Audio::Mixer *_mixer;
+ Audio::PCSpeaker *_stream;
+ Audio::SoundHandle _handle;
+public:
+ PCSpeaker(Audio::Mixer *mixer);
+ ~PCSpeaker();
+
+ void speakerOn(int16 frequency, int32 length = -1);
+ void speakerOff();
+ void onUpdate(uint32 millis);
+};
+
+} // End of namespace Glk
+
+#endif