summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author Justin Kerk <dopefishjustin@gmail.com>2014-07-22 04:51:52 +0000
committer Justin Kerk <dopefishjustin@gmail.com>2014-07-22 04:51:52 +0000
commitc4e9058ee26841baae4c0fd51e081949747d5f48 (patch)
tree51d9e35892c5931b099f9f30369cbe1cabe49cc8 /src
parentee2ad64677416ae895b69d65fc36e2abb142677e (diff)
[JSMESS] Add shim for Web Audio sound module [Katelyn Gadd, Justin Kerk]
Diffstat (limited to 'src')
-rw-r--r--src/osd/modules/sound/js_sound.c39
-rw-r--r--src/osd/modules/sound/js_sound.h31
-rw-r--r--src/osd/sdl/sdl.mak6
-rw-r--r--src/osd/sdl/sdlmain.c8
4 files changed, 84 insertions, 0 deletions
diff --git a/src/osd/modules/sound/js_sound.c b/src/osd/modules/sound/js_sound.c
new file mode 100644
index 00000000000..a2bc6086343
--- /dev/null
+++ b/src/osd/modules/sound/js_sound.c
@@ -0,0 +1,39 @@
+// license:BSD-3-Clause
+// copyright-holders:Miodrag Milanovic, Katelyn Gadd
+/***************************************************************************
+
+ js_sound.c
+
+ Shim for native JavaScript sound interface implementations (Emscripten only).
+
+*******************************************************************c********/
+
+
+#include "js_sound.h"
+#include "emscripten.h"
+
+//-------------------------------------------------
+// sound_js - constructor
+//-------------------------------------------------
+sound_js::sound_js(const osd_interface &osd)
+ : osd_sound_interface(osd)
+{
+}
+
+void sound_js::update_audio_stream(const INT16 *buffer, int samples_this_frame)
+{
+ EM_ASM_ARGS({
+ // Forward audio stream update on to JS backend implementation.
+ jsmess_update_audio_stream($0, $1);
+ }, (unsigned int)buffer, samples_this_frame);
+}
+
+void sound_js::set_mastervolume(int attenuation)
+{
+ EM_ASM_ARGS({
+ // Forward volume update on to JS backend implementation.
+ jsmess_set_mastervolume($0);
+ }, attenuation);
+}
+
+const osd_sound_type OSD_SOUND_JS = &osd_sound_creator<sound_js>;
diff --git a/src/osd/modules/sound/js_sound.h b/src/osd/modules/sound/js_sound.h
new file mode 100644
index 00000000000..ad0785fe960
--- /dev/null
+++ b/src/osd/modules/sound/js_sound.h
@@ -0,0 +1,31 @@
+// license:BSD-3-Clause
+// copyright-holders:Miodrag Milanovic, Katelyn Gadd
+/***************************************************************************
+
+ js_sound.h
+
+ Shim for native JavaScript sound interface implementations (Emscripten only).
+
+*******************************************************************c********/
+
+#pragma once
+
+#ifndef __SOUND_JS_H__
+#define __SOUND_JS_H__
+
+#include "osdepend.h"
+
+class sound_js : public osd_sound_interface
+{
+public:
+ // construction/destruction
+ sound_js(const osd_interface &osd);
+ virtual ~sound_js() { }
+
+ virtual void update_audio_stream(const INT16 *buffer, int samples_this_frame);
+ virtual void set_mastervolume(int attenuation);
+};
+
+extern const osd_sound_type OSD_SOUND_JS;
+
+#endif /* __SOUND_JS_H__ */
diff --git a/src/osd/sdl/sdl.mak b/src/osd/sdl/sdl.mak
index 43ee7e4afce..3e67d0cbe6f 100644
--- a/src/osd/sdl/sdl.mak
+++ b/src/osd/sdl/sdl.mak
@@ -417,6 +417,12 @@ endif
# add an ARCH define
DEFS += -DSDLMAME_ARCH="$(ARCHOPTS)" -DSYNC_IMPLEMENTATION=$(SYNC_IMPLEMENTATION)
+# Add JavaScript sound module for Emscripten compiles
+
+ifeq ($(TARGETOS),emscripten)
+OSDOBJS += $(OSDOBJ)/modules/sound/js_sound.o
+endif
+
#-------------------------------------------------
# Generic defines and additions
#-------------------------------------------------
diff --git a/src/osd/sdl/sdlmain.c b/src/osd/sdl/sdlmain.c
index 2cabef9012d..f4b52598c20 100644
--- a/src/osd/sdl/sdlmain.c
+++ b/src/osd/sdl/sdlmain.c
@@ -50,6 +50,9 @@
#include "osdsdl.h"
#include "sdlos.h"
#include "modules/sound/sdl_sound.h"
+#if defined(SDLMAME_EMSCRIPTEN)
+#include "modules/sound/js_sound.h"
+#endif
#if !defined(NO_DEBUGGER)
#include "modules/debugger/debugqt.h"
#endif
@@ -540,7 +543,12 @@ void sdl_osd_interface::video_register()
void sdl_osd_interface::sound_register()
{
sound_options_add("sdl", OSD_SOUND_SDL);
+#if defined(SDLMAME_EMSCRIPTEN)
+ sound_options_add("js", OSD_SOUND_JS);
+ sound_options_add("auto", OSD_SOUND_JS); // making JS audio default one
+#else
sound_options_add("auto", OSD_SOUND_SDL); // making SDL audio default one
+#endif
}
//============================================================