From 9f8c2af8421f5f2432007265fb79eca8abeedade Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sun, 19 Jul 2026 07:20:53 +0900 Subject: [PATCH] Emscripten: Fix ReferenceError for SE_VOLVAL_CH EM_ASYNC_JS stringifies its function body without expanding macros. Pass the BGM and sound-effect channel values through C wrapper functions so the generated JavaScript receives numeric channel arguments. --- src/pcm.emscripten.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/pcm.emscripten.c b/src/pcm.emscripten.c index 62cffec..5a6c4a5 100644 --- a/src/pcm.emscripten.c +++ b/src/pcm.emscripten.c @@ -58,18 +58,30 @@ bool muspcm_load_no(int slot, int no) { return pcm_load_no_js(slot, no, pcm_channel(no)); } -EM_ASYNC_JS(bool, muspcm_load_bgm, (int slot, int no), { - return await xsystem35.audio.pcm_load_bgm(slot, no, BGM_VOLVAL_CH); +EM_ASYNC_JS(bool, pcm_load_bgm_js, (int slot, int no, int ch), { + return await xsystem35.audio.pcm_load_bgm(slot, no, ch); }); -EM_ASYNC_JS(bool, muspcm_load_data, (int slot, uint8_t *buf, uint32_t len), { - return await xsystem35.audio.pcm_load_data(slot, buf, len, SE_VOLVAL_CH); +bool muspcm_load_bgm(int slot, int no) { + return pcm_load_bgm_js(slot, no, BGM_VOLVAL_CH); +} + +EM_ASYNC_JS(bool, pcm_load_data_js, (int slot, uint8_t *buf, uint32_t len, int ch), { + return await xsystem35.audio.pcm_load_data(slot, buf, len, ch); }); -EM_ASYNC_JS(bool, muspcm_load_mixlr, (int slot, int noL, int noR), { - return await xsystem35.audio.pcm_load_mixlr(slot, noL, noR, SE_VOLVAL_CH); +bool muspcm_load_data(int slot, uint8_t *buf, uint32_t len) { + return pcm_load_data_js(slot, buf, len, SE_VOLVAL_CH); +} + +EM_ASYNC_JS(bool, pcm_load_mixlr_js, (int slot, int noL, int noR, int ch), { + return await xsystem35.audio.pcm_load_mixlr(slot, noL, noR, ch); }); +bool muspcm_load_mixlr(int slot, int noL, int noR) { + return pcm_load_mixlr_js(slot, noL, noR, SE_VOLVAL_CH); +} + EM_JS(void, muspcm_unload, (int slot), { xsystem35.audio.pcm_unload(slot); });