mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-09-10 12:02:53 +02:00
Use embedded GMGSx.sf2 as soundfont in libretro builds
This commit is contained in:
parent
b1133b78f7
commit
66720a5bc0
6 changed files with 78 additions and 5 deletions
|
@ -44,9 +44,9 @@ namespace mkxp_sandbox {
|
|||
|
||||
SANDBOX_AWAIT_AND_SET(filename, rb_string_value_cstr, (VALUE *)(**sb() + argv));
|
||||
if (argc >= 2) {
|
||||
SANDBOX_AWAIT_AND_SET(volume, rb_ll2inum, ((VALUE *)(**sb() + argv))[1]);
|
||||
SANDBOX_AWAIT_AND_SET(volume, rb_num2int, ((VALUE *)(**sb() + argv))[1]);
|
||||
if (argc >= 3) {
|
||||
SANDBOX_AWAIT_AND_SET(pitch, rb_ll2inum, ((VALUE *)(**sb() + argv))[2]);
|
||||
SANDBOX_AWAIT_AND_SET(pitch, rb_num2int, ((VALUE *)(**sb() + argv))[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -259,6 +259,7 @@ if get_option('retro') == true
|
|||
'binding-sandbox/sandbox.cpp',
|
||||
'binding-sandbox/wasi.cpp',
|
||||
'binding/module_rpg.cpp',
|
||||
join_paths(retro_phase1, 'GMGSx.sf2.c'),
|
||||
join_paths(retro_phase1, 'wasm2c/wasm-rt-impl.c'),
|
||||
join_paths(retro_phase1, 'wasm2c/wasm-rt-mem-impl.c'),
|
||||
join_paths(retro_phase1, 'mkxp-sandbox-bindgen.cpp'),
|
||||
|
|
BIN
retro/GMGSx.sf2
Normal file
BIN
retro/GMGSx.sf2
Normal file
Binary file not shown.
|
@ -52,7 +52,7 @@ ruby-dist: $(OUTDIR)/mkxp-retro-dist.zip.c $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-
|
|||
|
||||
ruby-bindings: $(OUTDIR)/mkxp-sandbox-bindgen.cpp $(OUTDIR)/mkxp-sandbox-bindgen.h
|
||||
|
||||
deps: $(OUTDIR)/libretro.h $(OUTDIR)/wasm2c/wasm-rt.h $(OUTDIR)/wasm2c/wasm-rt-impl.c $(OUTDIR)/wasm2c/wasm-rt-mem-impl.c $(OUTDIR)/sdl/include/SDL.h
|
||||
deps: $(OUTDIR)/GMGSx.sf2.c $(OUTDIR)/libretro.h $(OUTDIR)/wasm2c/wasm-rt.h $(OUTDIR)/wasm2c/wasm-rt-impl.c $(OUTDIR)/wasm2c/wasm-rt-mem-impl.c $(OUTDIR)/sdl/include/SDL.h
|
||||
|
||||
clean: clean-ruby-dist clean-ruby-bindings clean-deps
|
||||
rm -rf $(LIBDIR)/*
|
||||
|
@ -69,11 +69,16 @@ clean-ruby-bindings:
|
|||
rm -f $(LIBDIR)/tags
|
||||
|
||||
clean-deps:
|
||||
rm -f $(OUTDIR)/GMGSx.sf2.c
|
||||
rm -f $(OUTDIR)/libretro.h
|
||||
rm -rf $(OUTDIR)/wasm2c
|
||||
rm -rf $(OUTDIR)/sdl
|
||||
rm -rf $(DOWNLOADS)/wabt
|
||||
|
||||
$(OUTDIR)/GMGSx.sf2.c: GMGSx.sf2
|
||||
mkdir -p $(OUTDIR)
|
||||
$(XXD) -i GMGSx.sf2 $(OUTDIR)/GMGSx.sf2.c
|
||||
|
||||
$(OUTDIR)/libretro.h:
|
||||
mkdir -p $(OUTDIR)
|
||||
$(CURL) -s -L -o $(OUTDIR)/libretro.h https://raw.githubusercontent.com/libretro/libretro-common/$(LIBRETRO_REF)/include/libretro.h
|
||||
|
|
|
@ -164,12 +164,14 @@ private:
|
|||
{
|
||||
fluid_synth_t *syn = fluid.new_synth(flSettings);
|
||||
|
||||
#ifndef MKXPZ_RETRO
|
||||
#ifdef MKXPZ_RETRO
|
||||
fluid.synth_sfload(syn, "/GMGSx.sf2", 1);
|
||||
#else
|
||||
if (!soundFont.empty())
|
||||
fluid.synth_sfload(syn, soundFont.c_str(), 1);
|
||||
else
|
||||
#endif // MKXPZ_RETRO
|
||||
Debug() << "Warning: No soundfont specified, sound might be mute";
|
||||
#endif // MKXPZ_RETRO
|
||||
|
||||
Synth synth;
|
||||
synth.inUse = usedNow;
|
||||
|
|
65
src/core.cpp
65
src/core.cpp
|
@ -19,6 +19,7 @@
|
|||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstdarg>
|
||||
|
@ -26,6 +27,8 @@
|
|||
#include <boost/optional.hpp>
|
||||
#include <AL/alc.h>
|
||||
#include <AL/alext.h>
|
||||
#include <fluidlite.h>
|
||||
#include <fluidsynth_priv.h>
|
||||
#include "../binding-sandbox/sandbox.h"
|
||||
#include "../binding-sandbox/binding-sandbox.h"
|
||||
#include "../binding-sandbox/core.h"
|
||||
|
@ -49,6 +52,9 @@ static inline void *malloc_align(size_t alignment, size_t size) {
|
|||
}
|
||||
#endif
|
||||
|
||||
extern unsigned char GMGSx_sf2[];
|
||||
extern unsigned int GMGSx_sf2_len;
|
||||
|
||||
static size_t frame_number = 0;
|
||||
static ALCdevice *al_device = NULL;
|
||||
static ALCcontext *al_context = NULL;
|
||||
|
@ -62,6 +68,21 @@ static void fallback_log(enum retro_log_level level, const char *fmt, ...) {
|
|||
va_end(va);
|
||||
}
|
||||
|
||||
static void fluid_log(int level, char *message, void *data) {
|
||||
switch (level) {
|
||||
case FLUID_PANIC:
|
||||
log_printf(RETRO_LOG_ERROR, "fluidsynth: panic: %s\n", message);
|
||||
case FLUID_ERR:
|
||||
log_printf(RETRO_LOG_ERROR, "fluidsynth: error: %s\n", message);
|
||||
case FLUID_WARN:
|
||||
log_printf(RETRO_LOG_WARN, "fluidsynth: warning: %s\n", message);
|
||||
case FLUID_INFO:
|
||||
log_printf(RETRO_LOG_INFO, "fluidsynth: %s\n", message);
|
||||
case FLUID_DBG:
|
||||
log_printf(RETRO_LOG_DEBUG, "fluidsynth: debug: %s\n", message);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t *frame_buf;
|
||||
boost::optional<struct sandbox> mkxp_retro::sandbox;
|
||||
boost::optional<Audio> mkxp_retro::audio;
|
||||
|
@ -141,6 +162,50 @@ static bool init_sandbox() {
|
|||
return false;
|
||||
}
|
||||
|
||||
fluid_set_log_function(FLUID_PANIC, fluid_log, NULL);
|
||||
fluid_set_log_function(FLUID_ERR, fluid_log, NULL);
|
||||
fluid_set_log_function(FLUID_WARN, fluid_log, NULL);
|
||||
fluid_set_log_function(FLUID_INFO, fluid_log, NULL);
|
||||
fluid_set_log_function(FLUID_DBG, fluid_log, NULL);
|
||||
|
||||
static fluid_fileapi_t fluid_fileapi = {
|
||||
.free = [](fluid_fileapi_t *f) {
|
||||
return 0;
|
||||
},
|
||||
.fopen = [](fluid_fileapi_t *f, const char *filename) {
|
||||
assert(std::strcmp(filename, "/GMGSx.sf2") == 0);
|
||||
return std::calloc(1, sizeof(long));
|
||||
},
|
||||
.fread = [](void *buf, int count, void *handle) {
|
||||
assert(*(long *)handle + count < GMGSx_sf2_len);
|
||||
std::memcpy(buf, GMGSx_sf2 + *(long *)handle, count);
|
||||
*(long *)handle += count;
|
||||
return (int)FLUID_OK;
|
||||
},
|
||||
.fseek = [](void *handle, long offset, int origin) {
|
||||
switch (origin) {
|
||||
case SEEK_CUR:
|
||||
*(long *)handle += offset;
|
||||
break;
|
||||
case SEEK_END:
|
||||
*(long *)handle = GMGSx_sf2_len + offset;
|
||||
break;
|
||||
default:
|
||||
*(long *)handle = offset;
|
||||
break;
|
||||
}
|
||||
return (int)FLUID_OK;
|
||||
},
|
||||
.fclose = [](void *handle) {
|
||||
std::free(handle);
|
||||
return (int)FLUID_OK;
|
||||
},
|
||||
.ftell = [](void *handle) {
|
||||
return *(long *)handle;
|
||||
},
|
||||
};
|
||||
fluid_set_default_fileapi(&fluid_fileapi);
|
||||
|
||||
audio.emplace();
|
||||
fs.emplace((const char *)NULL, false);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue