[JSMESS] Add shim for Web Audio sound module [Katelyn Gadd, Justin Kerk]

This commit is contained in:
Justin Kerk 2014-07-22 04:51:52 +00:00
parent ee2ad64677
commit c4e9058ee2
5 changed files with 86 additions and 0 deletions

2
.gitattributes vendored
View File

@ -9303,6 +9303,8 @@ src/osd/modules/debugger/qt/debugqtwindow.c svneol=native#text/plain
src/osd/modules/debugger/qt/debugqtwindow.h svneol=native#text/plain
src/osd/modules/sound/direct_sound.c svneol=native#text/plain
src/osd/modules/sound/direct_sound.h svneol=native#text/plain
src/osd/modules/sound/js_sound.c svneol=native#text/plain
src/osd/modules/sound/js_sound.h svneol=native#text/plain
src/osd/modules/sound/none.c svneol=native#text/plain
src/osd/modules/sound/none.h svneol=native#text/plain
src/osd/modules/sound/sdl_sound.c svneol=native#text/plain

View File

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

View File

@ -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__ */

View File

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

View File

@ -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
}
//============================================================