diff --git a/src/bgm.emscripten.c b/src/bgm.emscripten.c index 44580d0..04a4dde 100644 --- a/src/bgm.emscripten.c +++ b/src/bgm.emscripten.c @@ -25,6 +25,7 @@ #include "bgm.h" #include "audio_meta.h" #include "system.h" +#include "music_private.h" bool musbgm_init(DRIFILETYPE type, int base_no) { if (type == DRIFILE_BGM) @@ -89,5 +90,5 @@ void musbgm_wait(int no, int timeout) { } void musbgm_reapply_valance(void) { - // not implemented + EM_ASM({ xsystem35.cdPlayer.setValance($0); }, prv.volval[BGM_VOLVAL_CH]); } diff --git a/src/midi.emscripten.c b/src/midi.emscripten.c index e100849..97fa38b 100644 --- a/src/midi.emscripten.c +++ b/src/midi.emscripten.c @@ -23,6 +23,7 @@ #include "portab.h" #include "midi.h" +#include "music_private.h" static bool midi_initialize(int subdev) { return true; @@ -82,6 +83,10 @@ EM_JS(bool, midi_fading, (void), { return xsystem35.midiPlayer.isFading(); }); +static void midi_reapply_valance(void) { + EM_ASM({ xsystem35.midiPlayer.setValance($0); }, prv.volval[BGM_VOLVAL_CH]); +} + mididevice_t midi_emscripten = { .init = midi_initialize, .exit = midi_exit, @@ -95,4 +100,5 @@ mididevice_t midi_emscripten = { .setflag = midi_setflag, .fadestart = midi_fadestart, .fading = midi_fading, + .reapply_volume = midi_reapply_valance, }; diff --git a/src/pcm.emscripten.c b/src/pcm.emscripten.c index e63fb18..62cffec 100644 --- a/src/pcm.emscripten.c +++ b/src/pcm.emscripten.c @@ -23,11 +23,25 @@ #include "portab.h" #include "music_pcm.h" +#include "music_private.h" +#include "nact.h" +#include "audio_meta.h" bool muspcm_init(int audio_buffer_size) { + wai_load(nact->files.wai); return true; } +// Volume-valancer channel for PCM file number `no`, based on the WAI file. +static int pcm_channel(int no) { + if (!wai_loaded()) + return SE_VOLVAL_CH; + int ch = wai_mixch(no); + if ((unsigned)ch >= 16) // guard against bad WAI data + ch = 0; + return ch; +} + void muspcm_exit(void) { // do nothing } @@ -36,20 +50,24 @@ EM_JS(void, muspcm_reset, (void), { xsystem35.audio.pcm_reset(); }); -EM_ASYNC_JS(bool, muspcm_load_no, (int slot, int no), { - return await xsystem35.audio.pcm_load(slot, no); +EM_ASYNC_JS(bool, pcm_load_no_js, (int slot, int no, int ch), { + return await xsystem35.audio.pcm_load(slot, no, ch); }); +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); + return await xsystem35.audio.pcm_load_bgm(slot, no, BGM_VOLVAL_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); + return await xsystem35.audio.pcm_load_data(slot, buf, len, SE_VOLVAL_CH); }); EM_ASYNC_JS(bool, muspcm_load_mixlr, (int slot, int noL, int noR), { - return await xsystem35.audio.pcm_load_mixlr(slot, noL, noR); + return await xsystem35.audio.pcm_load_mixlr(slot, noL, noR, SE_VOLVAL_CH); }); EM_JS(void, muspcm_unload, (int slot), { @@ -97,6 +115,10 @@ EM_ASYNC_JS(void, muspcm_waitend, (int slot), { await xsystem35.audio.pcm_waitend(slot); }); +EM_JS(void, pcm_set_valance, (const int *vols, int num), { + xsystem35.audio.setValance(HEAP32.subarray(vols >> 2, (vols >> 2) + num)); +}); + void muspcm_reapply_valance(void) { - // not implemented + pcm_set_valance(prv.volval, 16); }