summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/sound/js_sound.c
blob: f3e11785633a48f5795f2259a5d05b9e052a7ec6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// license:BSD-3-Clause
// copyright-holders:Miodrag Milanovic, Katelyn Gadd
/***************************************************************************

    js_sound.c

    Shim for native JavaScript sound interface implementations (Emscripten only).

*******************************************************************c********/

#include "sound_module.h"
#include "modules/osdmodule.h"

#if (defined(SDLMAME_EMSCRIPTEN))

#include "emscripten.h"

class sound_js : public osd_module, public sound_module
{
public:

    sound_js()
    : osd_module(OSD_SOUND_PROVIDER, "js"), sound_module()
    {
    }
    virtual ~sound_js() { }

    virtual int init();
    virtual void exit();

    // sound_module

    virtual void update_audio_stream(bool is_throttled, const INT16 *buffer, int samples_this_frame)
    {
        EM_ASM_ARGS({
        // Forward audio stream update on to JS backend implementation.
        jsmess_update_audio_stream($1, $2);
        }, (unsigned int)buffer, samples_this_frame);
    }
    virtual void set_mastervolume(int attenuation)
    {
        EM_ASM_ARGS({
        // Forward volume update on to JS backend implementation.
        jsmess_set_mastervolume($0);
        }, attenuation);
    }

};

#else /* SDLMAME_UNIX */
    MODULE_NOT_SUPPORTED(sound_js, OSD_SOUND_PROVIDER, "js")
#endif

MODULE_DEFINITION(SOUND_JS, sound_js)