FMOD for Haxe
This library provides FMOD Studio and FMOD Core support for Haxe
Setup instructions, guides, and the API reference live on the documentation site.
Having problems or want to chat? Join the Haxe Discord, then follow the haxe-fmod thread.
Features
- The FMOD Studio API and FMOD Core API at runtime, with some known limitations
- Events, buses, VCAs, snapshots, banks, global and labeled parameters, and more
- Typed callbacks with payloads (beats, timeline markers, etc.)
- Live Update for mixing sounds while playtesting
- Helper class to map FMOD Studio calls/events to game code
- Generated constants for every event, bus, VCA, snapshot, and parameter in your banks
- TODO markers for sound effects you plan to add later
- fmod.com extension (beta) to integrate Haxe examples into the official FMOD docs
If this library does not support something you need, open an Issue.
Supported Platforms
Built and tested on Haxe 4.3.6 and FMOD Engine 2.03.12
| Platform | Architecture | HaxeFlixel | Heaps | Kha |
|---|---|---|---|---|
| HTML5 | All | WebAssembly | WebAssembly | WebAssembly |
| Windows | x86_64 | C++, HashLink | HashLink | Kore C++, Kore HL/C |
| Linux | x86_64 | C++, HashLink | HashLink | Kore C++, Kore HL/C |
| macOS | ARM64 (Apple Silicon) | C++, HashLink | HashLink through HL/C | Kore C++, Kore HL/C |
Getting Started
The Getting Started section on the docs site is a complete guide to setting up this library in your Haxe project.
Using the Library in Code
The FmodManager class is the primary way to interact with FMOD in your game. The FmodEvents constants used below are generated from your banks (see Generating constants). Every call and its description is in the FmodManager API reference.
public function StartLevel():Void {
// One background song at a time, additional transition functions available when using this to manage game music
FmodManager.PlaySong(FmodEvents.MusicMainLevel);
}
public function JumpPressed():Void {
// Fire-and-forget playback
FmodManager.PlayOneShot(FmodEvents.SFXJump);
}
var engine:FmodEvent;
public function StartEngine():Void {
// Handle-based playback for events you control after starting
engine = FmodManager.PlayEvent(FmodEvents.SFXEngine);
engine.setParameter("RPM", 0.2);
}
public function OnBeat():Void {
// Typed callbacks with payloads
FmodManager.OnSongEvent(data -> switch (data) {
case TimelineBeat(beat): pulseUI(beat.bar, beat.beat); // your own function
default:
});
}
FmodManager covers most common cases, but deeper layers are available for more explicit control:
// Example of reaching beyond FmodManager: everything FMOD Studio exposes is reachable
import haxefmod.studio.StudioSystem;
var music = StudioSystem.getBus("bus:/Music");
music.setVolume(0.5);
var description = StudioSystem.getEvent("event:/Ambience/Forest");
trace(description.getParameterDescriptionCount());
Generating Constants From Your Banks
The export script turns every event, bus, VCA, snapshot, and parameter in your FMOD Studio project into a Haxe constant. Once installed, Ctrl+B in FMOD Studio writes the constants to your project and builds your banks.
Generating constants in the docs covers the details of the setup and what gets generated.
FmodManager.PlaySong(FmodEvents.MusicLetsGo);
FmodManager.PlaySong("event:/Music/LetsGo"); // the same call using the explicit path string
FMOD Studio Live Update
One of the most powerful features of the FMOD ecosystem. Mix your sounds in real-time by binding FMOD Studio to a running instance of your game.
Live Update only works on HashLink and C++ builds. HTML5 builds do not support it. The FMOD team says this is a limitation of running games inside web browsers and they do not have plans to support it.
Live Update in the docs covers turning it on and off.
Tracking Sound Work With TODOs
If your code is ready for a sound effect that doesn't exist yet, leave an intelligent marker as a placeholder.
FmodManager.Todo("door creak when the vault opens");haxelib run haxefmod todoslists every remaining marker with its file and line.- Builds with
-D haxefmod_todo_beepplay a short placeholder blip so you hear the sounds that are still missing while playtesting.
More details can be found in the docs here.
fmod.com Extension (beta)
Experimental feature: The code snippets are occasionally incorrect, but this will still provide value if you are a docs-first developer
This modifies the code examples in the official fmod.com documentation to natively include Haxe
Migrating From Previous haxe-fmod Versions?
See MIGRATION.md for the complete mapping.
License
Special Thanks
This entire project was started as an expansion of Aaron Shea's faxe.
Feature Requests and Contact
For feature requests or problems with the library, do one or both of the following:
-
Join the Haxe Discord, then ask any questions you have in the haxe-fmod thread. Responses are quick.
-
Open an Issue here on GitHub.