jarikomppa / soloud

Free, easy, portable audio engine for games
http://soloud-audio.com
Other
1.69k stars 270 forks source link

mod-support and openmpt #357

Open konsumer opened 1 year ago

konsumer commented 1 year ago

I would really like mod-support with soloud, in a couple places that would benefit from static compilation, I think:

Expected behavior:

I am hoping to compile soloud + openmpt directly from C/C++ files, that can be used in nim or wasm. The FAQ mentions an old modplug version with looser licensing, but the code seems to do a dynamic DLL openmpt-load, now.

Actual behavior:

I got it building great for nim, and the wrapper works well for libretro, but I am using src/audiosource/openmpt/soloud_openmpt_dll.c to stub the openmpt functions, and without the DLL it will not work.

Similar, for wasm, I can remove the DLL stub, and end up with this when I compile soloud:

  "_openmpt_module_create_from_memory", referenced from:
      SoLoud::OpenmptInstance::OpenmptInstance(SoLoud::Openmpt*) in soloud_openmpt.cpp.o
      SoLoud::Openmpt::loadFile(SoLoud::File*) in soloud_openmpt.cpp.o
  "_openmpt_module_destroy", referenced from:
      SoLoud::OpenmptInstance::~OpenmptInstance() in soloud_openmpt.cpp.o
      SoLoud::Openmpt::loadFile(SoLoud::File*) in soloud_openmpt.cpp.o
  "_openmpt_module_read_float_stereo", referenced from:
      SoLoud::OpenmptInstance::getAudio(float*, unsigned int, unsigned int) in soloud_openmpt.cpp.o
  "_openmpt_module_set_repeat_count", referenced from:
      SoLoud::OpenmptInstance::OpenmptInstance(SoLoud::Openmpt*) in soloud_openmpt.cpp.o

If I include soloud/src/audiosource/openmpt/soloud_openmpt_dll.c, it builds, but wasm cannot dynamically load a DLL, so this will not work when I try to compile the library for wasm. I would really like to be able to just inline those functions from openmpt.

I can build openmpt on it's own as a DLL (running make in openmpt dir) but get a lot of errors when I try to inline all of it's C code. If this path makes sense, then I will keep at it, but it's a lot of errors like reference to 'BasicPathString' is ambiguous, so I am probably including the wrong openmpt C files. I could really use some help with that part, as I am not very strong with C/C++, especially around dep-management & tooling.

Steps to reproduce the problem:

git clone --recursive git@github.com:konsumer/soloud-web.git
cd soloud-web

cmake -B build
cmake --build build

This will build, but it currently uses soloud_openmpt_dll.c, which will try to dynamically load the openmpt dll. Even though it has web in the name, the output of that is a plain native dll. My plan is to use emcmake once I can compile a standalone DLL.

SoLoud version, operating system, backend used, any other potentially useful information:

I am using github-latest versions of soloud/openmpt:

I am on OSX Ventura 13.2.1 on arm64 & x86_64 chip (have built on 2 different macs.) My primary dev-machine is x86_64.

konsumer commented 1 year ago

I have tried a lot of stuff, so my repro is maybe not as simple as it could be, but I am happy to do the leg-work to setup any combo that is helpful for troublshooting.