Skip to content

🚧 [WIP] FMOD web support (HTML5)#210

Draft
bitbrain wants to merge 13 commits into
masterfrom
web-support
Draft

🚧 [WIP] FMOD web support (HTML5)#210
bitbrain wants to merge 13 commits into
masterfrom
web-support

Conversation

@bitbrain

@bitbrain bitbrain commented Apr 6, 2024

Copy link
Copy Markdown
Contributor

Screenshot 2024-04-06 133323


Closes #50

This PR aims to add support for web support via wasm.

Todo

  • update SConstruct to consider web as a platform
  • make scons platform=web pass & build libGodotFmod.web.template_debug.wasm32.wasm correctly
  • Update documentation for how to build for web (requires Emscripten)
  • Update Github Action to build for web
  • Solve issue around bank file scanning (specifically file callback logic https://github.com/utopia-rise/fmod-gdextension/blob/master/src/callback/file_callbacks.cpp)
  • Solve Uncaught TypeError: Module.FMOD_JS_MixerFastpathFunction is not a function onmessage when trying to play sounds

Known issues

Comment thread SConstruct Outdated
@bitbrain

bitbrain commented Apr 11, 2024

Copy link
Copy Markdown
Contributor Author

This builds fine and GDExtension seems to load in Chrome (Firefox still does not work), but then it fails due to memory issues in the browser:

Screenshot 2024-04-11 062838
Screenshot 2024-04-11 063207

@2shady4u

Copy link
Copy Markdown
Contributor

Firefix also doesnt work for my SQLite plugin so I assume the issue with Firefox not working is on the side of godot-cpp itself.

@pmdevita

pmdevita commented Aug 10, 2024

Copy link
Copy Markdown
Contributor

Hey I've been trying to take a stab at this recently to see if I can help and learn a bit more about C++. What version of emscripten and FMOD are you compiling with? From what I understand, w32 is the recommended format to work with now, why are you using the bitcode binaries instead?

EDIT: This thread on the FMOD forums seems to indicate that statically linking to the wasm binary like the build currently does will cause linking errors, I'm seeing the same ones right now. We may need to include the binaries instead like we do for the other platforms.

@JalikMetagram

Copy link
Copy Markdown

Hello ! I worked on a little game project using FMOD with Godot using utopia's addon. If you need a tester for this PR with a small game using fmod to make a web export don't hesitate reaching out !

@plumocracy

Copy link
Copy Markdown

Hey! wanted to checkup on progress of this/if it's still being worked on. If not, I'd be glad to pick up the torch and get this finished up at least on the code side of things.

@CedNaru

CedNaru commented Sep 14, 2024

Copy link
Copy Markdown
Member

Feel free to try your hands on it. It hasn't been touched in months.

@bitbrain

Copy link
Copy Markdown
Contributor Author

I originally raised the PR for this but have not worked on it ever since due to hitting blockers. If anyhbody can figure out how to make it work that would be brilliant.

@plumocracy

Copy link
Copy Markdown

I originally raised the PR for this but have not worked on it ever since due to hitting blockers. If anyhbody can figure out how to make it work that would be brilliant.

Could I ask what issues you ran into other than the Memory stuff listed above? I'm going to take a crack at it soon.

@BigOrangeBoy

Copy link
Copy Markdown

I use GoDot and FMOD and I would pay someone to finish this

@Lvl50Hornist

Copy link
Copy Markdown

I would also pay for this to be completed. xD Someone, anyone take my money.

@pmdevita

pmdevita commented Dec 18, 2024

Copy link
Copy Markdown
Contributor

Opened a new thread on the forums, maybe this will help us get somewhere https://qa.fmod.com/t/emscripten-linking-errors/22429

EDIT: One of the FMOD devs said they are going to look into the situation, hopefully they will come up with some sort of solution for us

Just to add some extra info, this solution where we statically build the FMOD GDextension against the shared object library is actually against FMOD's EULA since we would technically be distributing a "tool for an end-user application". It seems a bit unfair that way, the only allowed option would be to compile FMOD into Godot, and all of that effort would be just for distributing Godot FMOD HTML5 games. I'm hoping we can dynamically link it like we do on the other platforms or (long shot but fingers crossed) they make some kind of exception in the EULA for us and other 3rd party engines.

@pmdevita

pmdevita commented Mar 8, 2025

Copy link
Copy Markdown
Contributor

Update, as of 2.02.27, FMOD has started compiling the HTML5 build with position independent code -fPIC enabled! Builds against w32 now compile with no errors!

However, FMOD still doesn't work on the web due to some runtime errors and I'm struggling to get a readable traceback from it. I don't have much experience in C++/emscripten to begin with so if anyone is interested in helping, please let me know!

@fkeyzuwu

fkeyzuwu commented May 6, 2025

Copy link
Copy Markdown

Update, as of 2.02.27, FMOD has started compiling the HTML5 build with position independent code -fPIC enabled! Builds against w32 now compile with no errors!

However, FMOD still doesn't work on the web due to some runtime errors and I'm struggling to get a readable traceback from it. I don't have much experience in C++/emscripten to begin with so if anyone is interested in helping, please let me know!

hey, any updates on this? ❤️
also might be related to this - godotengine/godot#105369

they say Godot officially supports version 3.1.62 of emscripten, maybe worth a shot to try that one?

@fakemaxwell

Copy link
Copy Markdown

Sorry to "any updates?" this, but wanted to check and see if this was something that is potentially possible, or if it's a lost cause. I wish I knew anything about how it all worked to pitch in, but unfortunately I don't have the skillset. Happy to pitch in some funds if somebody is available to head it up.

@pmdevita

Copy link
Copy Markdown
Contributor

Sorry for the delay, I got sort of discouraged at the time and just haven't circled back to yet in my side project rotation.

As far as the linked Godot issue, that was not an issue for me as I was building with Emscrypten 3.1 and (as far as I remember) I believe I was successful in building the web build for Godot, which I was attempting to do to enable extra debugging info.

When the build fails to launch in the browser, Godot suggests I compile with debug mode on, but I think after compiling both Godot and FMOD with debug enabled, I was still getting the exact same suggestion and the error message was no more usable. I'll try to take another crack at it soon.

@bitbrain

Copy link
Copy Markdown
Contributor Author

@pmdevita amazing, could you perhaps also share a branch of your progress? More eyes could then also take a look at it and we can figure this out together.

@pmdevita

Copy link
Copy Markdown
Contributor

This branch https://github.com/pmdevita/fmod-gdextension/tree/web-support is the closest thing online to what I have right now, you want to build against a recent FMOD >2.02.27, <2.03 and you compile against the w32 binaries. I think it should no longer require messing with the LINKFLAGS. I'll try to update my branch sometime soon with my local changes

@pmdevita

pmdevita commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Branch is now updated to master https://github.com/pmdevita/fmod-gdextension/tree/web-support-4.4

Rough instructions

  1. Be already familiar with building Godot or extensions (try building this for desktop if you haven't before)
  2. Install emscrypten emsdk 3.1+ (not 4!) and make sure you can run emcc from your terminal
  3. Clone the repo making sure the submodule godot-cpp inits (https://fmod-gdextension.readthedocs.io/en/latest/advanced/1-compiling/#compiling)
scons target=template_debug platform=web fmod_lib_dir=path/to/fmod threads=no verbose=yes

Path to FMOD is the path to the root directory of the unpacked HTML5 SDK. FMOD does not support threads in HTML5 (yet, hopefully).

If all goes well, it should build without error or warning, whereas previously it would complain a lot about -fPIC. Exporting from Godot and running it in the browser will give you this error

image

This is around where I got stumped, if I did somehow make it past this error (and I'm not sure I did) I was met with an equally as useless error about enabling verbose debugging or something. Does anyone know how to compile with -sAssertions? From my rough chaotic experience in building random C/C++ projects, I also wonder if this is a red herring too.

I think we should be building with env.Append(LIBS=[libfmodstudio]) but it fails with the error wasm-ld: error: unable to find library -lfmodstudioL_wasm. The SDK will also still "build" even without giving it the LINKFLAGS with the path to the studio binary but produces a much smaller (probably wrong) binary. I'm really not sure what of these flags was supposed to be set other than CPPPATH and LIBPATH.

FMOD has some docs on HTML5 here but they are inconsistent with what the SDK presents and are not very clear otherwise.

@sphynx-owner

sphynx-owner commented Dec 1, 2025

Copy link
Copy Markdown

Hello, I am investigating fmod with godot on the web, and naturally reached this pr. So if I understand, @pmdevita has the most progress, but work is generally stale. What is the feasibility of reaching something working? How much work would be needed? Is it just about figuring out the SConstruct? Would modification to source be required?

@bitbrain

bitbrain commented Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

@sphynx-owner I have attempted continuing the work myself but hit a brickwall again. Fixing the SConstruct is not a big deal, I am even able to run the game in the web. The only issue is that no audio plays because banks cannot be loaded. This is due to the custom bank loading logic this extension has: in order to load banks properly, we are running our own custom bank loader but that one won't work in the web. I had the idea to use preprocessor directives to do a cheeky if-else and disable any code that would be incompatible when building for web and using the native behaviour instead.

@sphynx-owner

Copy link
Copy Markdown

@bitbrain I appreciate your resopnse. In fact, this sounds very promising. I have a few questions then:

  1. why do we have custom bank loading logic?
  2. what could be the reason that it fails on the web build?

Also, perhaps unrelated, but I came across a quote from the FMod documentation:

Running FMOD as HTML5 on the web is made possible by having a web server host and deliver the JavaScript content to the client web browser.

Is this related to bank loading logic? does that mean that every game using fmod on the web will need a dedicated server for content streaming?

@sphynx-owner

Copy link
Copy Markdown

Where can I find your latest progress?

@pmdevita

pmdevita commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

@bitbrain Did you continue it from my work? How did you get it to not crash at launch? I figured we'd have to revisit the bank loading, I think your idea with the preprocessors makes sense. We're gonna need a web specific loader.

For @sphynx-owner I believe we have custom bank loading logic so that we can store banks in the Godot game bundle file.

@bitbrain

bitbrain commented Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

@sphynx-owner let me dig out the changes and push them here.

Did you continue it from my work?

@pmdevita yes :)

Screenshot_2025-10-07_211402

This is as far as I got: the demo project runs in the browser, but with no sound and a ton of console errors.

@sphynx-owner

Copy link
Copy Markdown

I see. Thank you for digging this out for me.

@sphynx-owner

sphynx-owner commented Dec 2, 2025

Copy link
Copy Markdown

I don't mean to rush, but do you have a PR that I can clone and have a look at myself @bitbrain? You might have pushed already and I just don't know where to look

@sphynx-owner

Copy link
Copy Markdown

I believe I got pretty close to having a compiled web bulid, but yet so far away. I got @pmdevita's branch, and followed his instructions, however I am getting this error when trying to compile. I am on windows so I am already shooting in the dark here:
image

@sphynx-owner

Copy link
Copy Markdown

Update: I got the latest fmod gdextension, and applied the same changes that @pmdevita had done in his fork
I am basically in the same state as described in his message, errors and everything, but with the latest gdextension version, fmod 2.03.06, and the latest version of emscripten. @bitbrain any updates? You said you had further progress using @pmdevita's work, I could try and pick up from where you left.

@bitbrain

bitbrain commented Dec 6, 2025

Copy link
Copy Markdown
Contributor Author

@sphynx-owner I pushed changes to this branch so it is up to date with master branch and scons platform=web now builds successfully. However, it still won't work when exporting a web build due to the issues discussed before.

The required structure in libs is:

libs/fmod/api <- probably should be renamed to `web` for consistency
    core/*
    fsbank/*
    studio/*

My toolchain:

$ scons --version
SCons by Steven Knight et al.:
        SCons: v4.10.0.b3e979a3e42c43b91f7624895910afb869a19806, Thu, 02 Oct 2025 10:16:02 -0700, by bdbaddog on M1Dog2021
        SCons path: ['C:\\Users\\mgonz\\scoop\\apps\\python\\current\\Lib\\site-packages\\SCons']
Copyright (c) 2001 - 2025 The SCons Foundation
$ emcc --version
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.17 (bb11bae9af3a6551132655a0908f86889d2d423b)
Copyright (C) 2025 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ --version
g++.exe (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@sphynx-owner

Copy link
Copy Markdown

@bitbrain thanks for the update. What FMOD version do I get? because 2.03.06 does not have the upstream directory anymore.

@sphynx-owner

Copy link
Copy Markdown

I would also like to clarify, you were able to run the game in the browser (albeit without sound banks loading). Were you doing that from the editor with the "run-in-browser" button?

@sphynx-owner

Copy link
Copy Markdown

My main concern right now is that I am not seeing any significant difference in your changes to those that @pmdevita did, yet you were able to enter the game without an -sAssertion error. This leads me to believe your success is due to toolchain specific setup.

@bitbrain

bitbrain commented Dec 6, 2025

Copy link
Copy Markdown
Contributor Author

@sphynx-owner I had to tweak it slightly, as without it, I got the same error as @pmdevita. Can you join the Discord server? We can debug the issues you are facing together in the #gdextension channel: https://discord.gg/nS34H6fY

@bitbrain

bitbrain commented Dec 7, 2025

Copy link
Copy Markdown
Contributor Author

Bank loading seems to work fine now. However, still no sound. The main issue right now is that gdextension .wasm is built as a side module because the main module is Godot itself, but FMOD's HTML5 setup assumes it is always run from a main module, so it leads to "visibility" problems of glue code. Raised the issue here to ask for assistance from the FMOD team on this matter.

@RafaelVidaurre

Copy link
Copy Markdown

I found a dirty workaround to get this working on @sphynx-owner 's branch here

Here's a copy-paste from the message I left on the Godot Fmod Discord:


Maybe this will shed some light onto whats going on with the banks, but I managed to get the HTML5 build to run by doing this:

  1. Served the bank files from an http server, such that paths are foobar.com/assets/* (e.g. with a local server http://localhost:<port>/assets
  2. On the index.html file, right before the game starts. I added explicit calls to load the current banks
Promise.all([
            engine.preloadFile('assets/Banks/Master.bank', 'assets/Banks/Master.bank'),
            engine.preloadFile('assets/Banks/Master.strings.bank', 'assets/Banks/Master.strings.bank'),
            engine.preloadFile('assets/Banks/Dialogue_CN.bank', 'assets/Banks/Dialogue_CN.bank'),
            engine.preloadFile('assets/Banks/Dialogue_EN.bank', 'assets/Banks/Dialogue_EN.bank'),
            engine.preloadFile('assets/Banks/Dialogue_JP.bank', 'assets/Banks/Dialogue_JP.bank'),
            engine.preloadFile('assets/Banks/Music.bank', 'assets/Banks/Music.bank'),
            engine.preloadFile('assets/Banks/SFX.bank', 'assets/Banks/SFX.bank'),
            engine.preloadFile('assets/Banks/Vehicles.bank', 'assets/Banks/Vehicles.bank'),
          ]).then(() => {
            engine
              .startGame({
                onProgress: function (current, total) {
                  if (current > 0 && total > 0) {
                    statusProgress.value = current;
                    statusProgress.max = total;
                  } else {
                    statusProgress.removeAttribute('value');
                    statusProgress.removeAttribute('max');
                  }
                },
              })
              .then(() => {
                setStatusMode('hidden');
              }, displayFailureNotice);
          });

This made the banks available to the game and it seems to function as intended

@esklarski

Copy link
Copy Markdown

Sphynx shared the build templates with me and I was able to get my project running -- in Firefox, on Fedora -- without the custom html shell stuff.

My only caveat seems to be that the FmodManager autoload needs to load first (ie at the top of the autoload list) or there is no sound. As long as it's first I get sound 🤷🏼

I made a modified html shell with the promise loading above, but after running the game I noticed I forgot to put in my banks yet all the sounds worked. I reverted to the default shell and it still works.

Ymmv.

The modified shell if anyone cares:
fmod_web_shell.html
Just add your banks to the promise near the bottom.

@ssebs

ssebs commented May 6, 2026

Copy link
Copy Markdown

Hi, I'm trying to follow along but I'm hitting some snags since I don't have experience with building GDExtensions.

From reading the comments here, it looks like you're able to build fmod from this PR, setup a web export that loads the .bank files, then use them in game?

Is anyone able to share the built .wasm files?

I tried checking out the latest branch & building https://github.com/pmdevita/fmod-gdextension/tree/web-support-4.4 , but I'm getting build errors.

$ scons --version
SCons by Steven Knight et al.:
        SCons: v4.5.2.120fd4f633e9ef3cafbc0fec35306d7555ffd1db, Tue, 21 Mar 2023 12:11:27 -0400, by bdbaddog on M1DOG2021
        SCons path: ['/usr/lib/python3/dist-packages/SCons']
Copyright (c) 2001 - 2023 The SCons Foundation

$ emcc --version
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.56 (cf90417346b78455089e64eb909d71d091ecc055)
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ --version
g++ (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ scons platform=web target=template_debug fmod_lib_dir=libs/fmod threads=no verbose=yes

. . .

In file included from src/core/fmod_sound.cpp:1:
src/core/fmod_sound.h:14:38: error: implicit instantiation of undefined template 'godot::Ref<godot::FmodSound>'
   14 |         inline static Ref<FmodSound> create_ref(FMOD::Channel* wrapped) {
      |                                      ^
godot-cpp/include/godot_cpp/templates/hashfuncs.hpp:313:7: note: template is declared here     
  313 | class Ref;
      |       ^
In file included from src/core/fmod_sound.cpp:1:
src/core/fmod_sound.h:15:28: error: implicit instantiation of undefined template 'godot::Ref<godot::FmodSound>'
   15 |             Ref<FmodSound> ref;
ate 'godot::Ref<godot::FmodParameterDescription>'
   26 |         inline static Ref<FmodParameterDescription> create_ref(const FMOD_STUDIO_PARAMETER_DESCRIPTION& wrapped) {
      |                                                     ^
godot-cpp/include/godot_cpp/templates/hashfuncs.hpp:313:7: note: template is declared here
  313 | class Ref;
      |       ^
In file included from src/studio/fmod_parameter_description.cpp:1:
src/studio/fmod_parameter_description.h:27:43: error: implicit instantiation of undefined template 'godot::Ref<godot::FmodParameterDescription>'
   27 |             Ref<FmodParameterDescription> ref;
      |                                           ^
godot-cpp/include/godot_cpp/templates/hashfuncs.hpp:313:7: note: template is declared here
  313 | class Ref;
      |       ^
In file included from src/core/fmod_file.cpp:1:
src/core/fmod_file.h:14:37: error: implicit instantiation of undefined template 'godot::Ref<godot::FmodFile>'
   14 |         inline static Ref<FmodFile> create_ref(FMOD::Sound* wrapped) {
      |                                     ^
godot-cpp/include/godot_cpp/templates/hashfuncs.hpp:313:7: note: template is declared here
  313 | class Ref;
      |       ^
In file included from src/core/fmod_file.cpp:1:
src/core/fmod_file.h:15:27: error: implicit instantiation of undefined template 'godot::Ref<godot::FmodFile>'
   15 |             Ref<FmodFile> ref;
      |                           ^
godot-cpp/include/godot_cpp/templates/hashfuncs.hpp:313:7: note: template is declared here
  313 | class Ref;
      |       ^
2 errors generated.
scons: *** [src/core/fmod_file.o] Error 1
In file included from src/studio/fmod_event_description.cpp:1:
In file included from src/studio/fmod_event_description.h:5:
src/studio/fmod_parameter_description.h:26:53: error: implicit instantiation of undefined template 'godot::Ref<godot::FmodParameterDescription>'
   26 |         inline static Ref<FmodParameterDescription> create_ref(const FMOD_STUDIO_PARAMETER_DESCRIPTION& wrapped) {
      |                                                     ^
godot-cpp/include/godot_cpp/templates/hashfuncs.hpp:313:7: note: template is declared here
  313 | class Ref;
      |       ^
In file included from src/studio/fmod_event_description.cpp:1:
In file included from src/studio/fmod_event_description.h:5:
src/studio/fmod_parameter_description.h:27:43: error: implicit instantiation of undefined template 'godot::Ref<godot::FmodParameterDescription>'
   27 |             Ref<FmodParameterDescription> ref;
      |                                           ^
godot-cpp/include/godot_cpp/templates/hashfuncs.hpp:313:7: note: template is declared here
  313 | class Ref;
      |       ^
2 errors generated.
scons: *** [src/studio/fmod_parameter_description.o] Error 1
2 errors generated.
scons: *** [src/studio/fmod_event_description.o] Error 1
scons: building terminated because of errors.

@sphynx-owner

sphynx-owner commented May 10, 2026

Copy link
Copy Markdown

@ssebs the working solution is on my branch, and it involves converting the gdextension into a godot module, and buliding it as part of the engine. In addition, some modification is done to the SCsub file on the godot source code side.

Long story short, it is not something you can currently build yourself, but I can give you the already exported build templates which you should be able to use to export your project (DOWNLOAD AT YOUR OWN RISK):

godot.web.template_debug.wasm32.nothreads.dlink.zip
godot.web.template_release.wasm32.nothreads.dlink.zip

You use them when exporting your project by enabling advanced options in the export preset editor and feeding the paths to these templates appropriately:
image

Edit: version is 4.6.2, and therading is disabled (default for web). You may need a custom shell for banks, but I am no longer sure. I cannot be much help beyond providing the templates sadly.

ssebs added a commit to ssebs/DankNooner that referenced this pull request May 11, 2026
@ssebs

ssebs commented May 11, 2026

Copy link
Copy Markdown

@sphynx-owner - Thank you for the explanation & building the template for me. I spent a couple hours trying to get this working, but ultimately I couldn't get it going.

I had Claude write a basic audio middleware for my project. I just need to tweak audio pitch & volume for my use-case.

Looking forward to seeing this once it's working!

Here's my code for posterity:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FMOD web support (HTML5)