mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-09-29 02:18:09 +03:00
emscripten: FM sound support
This commit is contained in:
+4
-1
@@ -19,16 +19,19 @@ if (ANDROID)
|
||||
target_link_libraries(system3 PRIVATE SDL2 SDL2_ttf)
|
||||
|
||||
elseif (EMSCRIPTEN)
|
||||
add_subdirectory(../deps/fmgen fmgen)
|
||||
add_executable(system3)
|
||||
|
||||
target_sources(system3 PRIVATE
|
||||
emscripten/nact_emscripten.cpp
|
||||
emscripten/mako.cpp
|
||||
fm/makofm.cpp
|
||||
fm/mako_fmgen.cpp
|
||||
)
|
||||
set(LIBS "SHELL:-s USE_SDL=2" "SHELL:-s USE_SDL_TTF=2")
|
||||
target_compile_options(system3 PRIVATE ${LIBS})
|
||||
target_link_options(system3 PRIVATE ${LIBS})
|
||||
target_link_libraries(system3 PRIVATE idbfs.js)
|
||||
target_link_libraries(system3 PRIVATE idbfs.js fmgen)
|
||||
|
||||
# Without optimizations, Asyncify generates very large code.
|
||||
list(APPEND CMAKE_EXE_LINKER_FLAGS_DEBUG "-O1")
|
||||
|
||||
@@ -7,8 +7,18 @@
|
||||
#include <emscripten.h>
|
||||
#include "mako.h"
|
||||
#include "mako_midi.h"
|
||||
#include "fm/mako_fmgen.h"
|
||||
#include "dri.h"
|
||||
|
||||
namespace {
|
||||
|
||||
std::unique_ptr<MakoFMgen> fm;
|
||||
uint8* fmdata;
|
||||
|
||||
} // namespace
|
||||
|
||||
MAKO::MAKO(NACT* parent, const MAKOConfig& config) :
|
||||
use_fm(config.use_fm),
|
||||
current_music(0),
|
||||
next_loop(0),
|
||||
nact(parent)
|
||||
@@ -29,6 +39,16 @@ void MAKO::play_music(int page)
|
||||
if (track) {
|
||||
EM_ASM_ARGS({ xsystem35.cdPlayer.play($0, $1); },
|
||||
cd_track[page] + 1, next_loop ? 0 : 1);
|
||||
} else if (use_fm) {
|
||||
DRI dri;
|
||||
int size;
|
||||
uint8* data = dri.load(amus, page, &size);
|
||||
if (!data)
|
||||
return;
|
||||
fm = std::make_unique<MakoFMgen>(data);
|
||||
free(fmdata);
|
||||
fmdata = data;
|
||||
EM_ASM({ xsystem35.audio.enable_audio_hook(); });
|
||||
} else {
|
||||
auto midi = std::make_unique<MAKOMidi>(nact, amus);
|
||||
if (!midi->load_mml(page)) {
|
||||
@@ -56,6 +76,9 @@ void MAKO::stop_music()
|
||||
xsystem35.midiPlayer.stop();
|
||||
});
|
||||
|
||||
fm = nullptr;
|
||||
free(fmdata);
|
||||
fmdata = nullptr;
|
||||
current_music = 0;
|
||||
}
|
||||
|
||||
@@ -81,3 +104,15 @@ bool MAKO::check_pcm()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
bool audio_callback(Uint8 *stream, int len) {
|
||||
if (!fm)
|
||||
return false;
|
||||
fm->Process(reinterpret_cast<int16*>(stream), len);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user