From 627f4ba84658833d43350bb1d0843e95e85d17bc Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 4 Aug 2019 09:12:43 +0900 Subject: [PATCH] Introduce pcm.emscripten.c --- CMakeLists.txt | 1 + emscripten/library.js | 48 ----------------------- src/pcm.emscripten.c | 88 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 48 deletions(-) create mode 100644 src/pcm.emscripten.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d59a0c3..d980198 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,6 +130,7 @@ endif() if (EMSCRIPTEN) list(APPEND SRC_AUDIO) + list(APPEND SRC_AUDIO pcm.emscripten.c) list(APPEND SUMMARY_AUDIO "Emscripten") elseif (SDL2MIXER_FOUND) list(APPEND SRC_AUDIO pcm.sdlmixer.c) diff --git a/emscripten/library.js b/emscripten/library.js index 5b60b9b..a6fe241 100644 --- a/emscripten/library.js +++ b/emscripten/library.js @@ -11,52 +11,4 @@ mergeInto(LibraryManager.library, { xsystem35.load_mincho_font().then(wakeUp); }); }, - muspcm_init: function(audio_buffer_size) { - return 0; // OK - }, - muspcm_exit: function() { - return 0; // OK - }, - muspcm_load_no: function(slot, no) { // async - return xsystem35.audio.pcm_load(slot, no); - }, - muspcm_load_mixlr: function(slot, noL, noR) { // async - return xsystem35.audio.pcm_load_mixlr(slot, noL, noR); - }, - muspcm_unload: function(slot) { - return xsystem35.audio.pcm_unload(slot); - }, - muspcm_start: function(slot, loop) { - return xsystem35.audio.pcm_start(slot, loop); - }, - muspcm_stop: function(slot) { - return xsystem35.audio.pcm_stop(slot); - }, - muspcm_fadeout: function(slot, msec) { - return xsystem35.audio.pcm_fadeout(slot, msec); - }, - muspcm_pause: function(slot) { - console.log('muspcm_pause: not implemented'); - return -1; // NG - }, - muspcm_unpause: function(slot) { - console.log('muspcm_unpause: not implemented'); - return -1; // NG - }, - muspcm_getpos: function(slot) { - return xsystem35.audio.pcm_getpos(slot); - }, - muspcm_setvol: function(dev, slot, lv) { - return xsystem35.audio.pcm_setvol(slot, lv); - }, - muspcm_getwavelen: function(slot) { - var len = xsystem35.audio.pcm_getwavelen(slot); - return len > 65535 ? 65535 : len; - }, - muspcm_isplaying: function(slot) { - return xsystem35.audio.pcm_isplaying(slot); - }, - muspcm_waitend: function(slot) { // async - return xsystem35.audio.pcm_waitend(slot); - } }); diff --git a/src/pcm.emscripten.c b/src/pcm.emscripten.c new file mode 100644 index 0000000..5c1790c --- /dev/null +++ b/src/pcm.emscripten.c @@ -0,0 +1,88 @@ +/* + * pcm.emscripten.c PCM audio for emscripten + * + * Copyright (C) 2019 + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * +*/ + +#include + +#include "portab.h" +#include "music_pcm.h" + +EM_JS(int, muspcm_init, (int audio_buffer_size), { + return xsystem35.Status.OK; +}); + +EM_JS(int, muspcm_exit, (void), { + return xsystem35.Status.OK; +}); + +EM_JS(int, muspcm_load_no, (int slot, int no), { // async + return xsystem35.audio.pcm_load(slot, no); +}); + +EM_JS(int, muspcm_load_mixlr, (int slot, int noL, int noR), { // async + return xsystem35.audio.pcm_load_mixlr(slot, noL, noR); +}); + +EM_JS(int, muspcm_unload, (int slot), { + return xsystem35.audio.pcm_unload(slot); +}); + +EM_JS(int, muspcm_start, (int slot, int loop), { + return xsystem35.audio.pcm_start(slot, loop); +}); + +EM_JS(int, muspcm_stop, (int slot), { + return xsystem35.audio.pcm_stop(slot); +}); + +EM_JS(int, muspcm_fadeout, (int slot, int msec), { + return xsystem35.audio.pcm_fadeout(slot, msec); +}); + +EM_JS(int, muspcm_pause, (int slot), { + console.log('muspcm_pause: not implemented'); + return xsystem35.Status.NG; +}); + +EM_JS(int, muspcm_unpause, (int slot), { + console.log('muspcm_unpause: not implemented'); + return xsystem35.Status.NG; +}); + +EM_JS(int, muspcm_getpos, (int slot), { + return xsystem35.audio.pcm_getpos(slot); +}); + +EM_JS(int, muspcm_setvol, (int dev, int slot, int lv), { + return xsystem35.audio.pcm_setvol(slot, lv); +}); + +EM_JS(int, muspcm_getwavelen, (int slot), { + var len = xsystem35.audio.pcm_getwavelen(slot); + return len > 65535 ? 65535 : len; +}); + +EM_JS(boolean, muspcm_isplaying, (int slot), { + return xsystem35.audio.pcm_isplaying(slot); +}); + +EM_JS(int, muspcm_waitend, (int slot), { // async + return xsystem35.audio.pcm_waitend(slot); +});