Hi glad to hear from you.
I downloaded this version: fmodstudioapi20100win-installer.exe
The reason is that I tried to use music/sounds developed with a Fmod editor using that version some years ago.
I took the .dll files from the directories you get through the shortcuts that were installed in the windows start menu.
C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\examples\bin
C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\studio\examples\bin
A little about the background to all this. I am a pensioner trying to help my son with a game he developed as part of his examination work when he got an exam in games, specialization music.
And he suggested we should take it up and make the game better but we should this time use godot instead of Unity and he want to use Fmod (he has created the music and effects using Fmod)
I looked at it and since the .dlls can be wrapped so they can be called from C# code I said it looked as if we would be able to use Fmod.
I have started sketching a class to be used - where I am running into these problems. Here it is:
(Note FMODUseError is an exception I have created).
using System;
using System.Runtime.InteropServices;
using Godot;
namespace SBS_Utilities
{
public static class FMODGodot
{
private const string FMOD_STUDIO_DLL = "fmodstudio.dll";
private const string FMOD_CORE_DLL = "fmod.dll";
private static IntPtr coreSystem;
private static IntPtr studioSystem;
public static void InitializeFMOD()
{
try
{
// Step 1: Create Core System
GD.Print("Creating FMOD Core system...");
int result = FMOD_System_Create(out coreSystem);
if (result != 0)
{
throw new FMODUseError(nameof(InitializeFMOD), result, "FMOD Core system creation failed");
}
// Step 2: Initialize Core System
GD.Print("Initializing FMOD Core system...");
result = FMOD_System_Init(coreSystem, 512, FMOD_INIT.NORMAL, IntPtr.Zero);
if (result != 0)
{
throw new FMODUseError(nameof(InitializeFMOD), result, "FMOD Core system initialization failed");
}
GD.Print("FMOD Core system initialized successfully.");
// Step 3: Create Studio System (linked to Core System)
GD.Print("Creating FMOD Studio system...");
result = FMOD_Studio_System_Create(out studioSystem);
if (result != 0)
{
throw new FMODUseError(nameof(InitializeFMOD), result, "FMOD Studio system creation failed");
}
// Step 4: Initialize Studio System
GD.Print("Initializing FMOD Studio system...");
result = FMOD_Studio_System_Initialize(studioSystem, 512, FMOD_STUDIO_INIT.NORMAL, FMOD_INIT.NORMAL, IntPtr.Zero);
if (result != 0)
{
throw new FMODUseError(nameof(InitializeFMOD), result, "FMOD Studio system initialization failed");
}
GD.Print("FMOD Studio system initialized successfully.");
// Step 5: Load banks
GD.Print("Loading banks.");
LoadBank(@"F:\FmodBanks\Master.bank");
LoadBank(@"F:\FmodBanks\Master.strings.bank");
}
catch (Exception ex)
{
GD.PrintErr($"Error during FMOD initialization: {ex.Message}");
throw;
}
}
private static void LoadBank(string bankPath)
{
try
{
if (studioSystem == IntPtr.Zero)
{
throw new FMODUseError(nameof(LoadBank), -1, "FMOD Studio system is not initialized. Cannot load bank.");
}
string absolutePath = ProjectSettings.GlobalizePath(bankPath);
if (!System.IO.File.Exists(absolutePath))
{
throw new FMODUseError(nameof(LoadBank), -1, $"Bank file not found: {absolutePath}");
}
GD.Print($"Loading bank: {absolutePath}");
IntPtr bank;
int result = FMOD_Studio_System_LoadBankFile(studioSystem, absolutePath, out bank);
if (result != 0)
{
throw new FMODUseError(nameof(LoadBank), result, $"Failed to load bank {absolutePath}");
}
GD.Print($"Loaded bank {absolutePath} successfully.");
}
catch (Exception ex)
{
GD.PrintErr($"Error during loading bank {bankPath}: {ex.Message}");
throw;
}
}
public static void ReleaseFMOD()
{
try
{
if (studioSystem != IntPtr.Zero)
{
GD.Print("Releasing FMOD Studio system...");
int result = FMOD_Studio_System_Release(studioSystem);
if (result != 0)
{
throw new FMODUseError(nameof(ReleaseFMOD), result, "FMOD Studio system release failed");
}
studioSystem = IntPtr.Zero;
GD.Print("FMOD Studio system released successfully.");
}
if (coreSystem != IntPtr.Zero)
{
GD.Print("Releasing FMOD Core system...");
int result = FMOD_System_Release(coreSystem);
if (result != 0)
{
throw new FMODUseError(nameof(ReleaseFMOD), result, "FMOD Core system release failed");
}
coreSystem = IntPtr.Zero;
GD.Print("FMOD Core system released successfully.");
}
}
catch (Exception ex)
{
GD.PrintErr($"Error during FMOD release: {ex.Message}");
throw;
}
}
public static void PlayEvent(string eventPath)
{
try
{
GD.Print($"Playing event: {eventPath}");
IntPtr eventInstance;
int result = FMOD_Studio_System_GetEvent(studioSystem, eventPath, out eventInstance);
if (result != 0)
{
throw new FMODUseError(nameof(PlayEvent), result, $"Failed to get event {eventPath}");
}
result = FMOD_Studio_EventInstance_Start(eventInstance);
if (result != 0)
{
throw new FMODUseError(nameof(PlayEvent), result, $"Failed to start event {eventPath}");
}
GD.Print($"Started event {eventPath} successfully.");
}
catch (Exception ex)
{
GD.PrintErr($"Error during playing event {eventPath}: {ex.Message}");
throw;
}
}
// FMOD imports
[DllImport(FMOD_CORE_DLL)]
private static extern int FMOD_System_Create(out IntPtr system); // Example for Core API usage
[DllImport(FMOD_CORE_DLL)]
private static extern int FMOD_System_Init(IntPtr system, int maxchannels, FMOD_INIT flags, IntPtr extradriverdata);
[DllImport(FMOD_CORE_DLL)]
private static extern int FMOD_System_Release(IntPtr system);
[DllImport(FMOD_STUDIO_DLL)]
private static extern int FMOD_Studio_System_Create(out IntPtr system);
[DllImport(FMOD_STUDIO_DLL)]
private static extern int FMOD_Studio_System_Initialize(IntPtr system, int maxchannels, FMOD_STUDIO_INIT studioFlags, FMOD_INIT flags, IntPtr extradriverdata);
[DllImport(FMOD_STUDIO_DLL)]
private static extern int FMOD_Studio_System_LoadBankFile(IntPtr system, string path, out IntPtr bank);
[DllImport(FMOD_STUDIO_DLL)]
private static extern int FMOD_Studio_System_Release(IntPtr system);
[DllImport(FMOD_STUDIO_DLL)]
private static extern int FMOD_Studio_System_GetEvent(IntPtr system, string path, out IntPtr eventInstance);
[DllImport(FMOD_STUDIO_DLL)]
private static extern int FMOD_Studio_EventInstance_Start(IntPtr eventInstance);
}
[Flags]
public enum FMOD_STUDIO_INIT : uint
{
NORMAL = 0x00000000,
LIVEUPDATE = 0x00000001,
ALLOW_MISSING_PLUGINS = 0x00000002,
SYNCHRONOUS_UPDATE = 0x00000004,
DEFERRED_CALLBACKS = 0x00000008,
LOAD_FROM_UPDATE = 0x00000010,
MEMORY_TRACKING = 0x00000020
}
[Flags]
public enum FMOD_INIT : uint
{
NORMAL = 0x00000000,
STREAM_FROM_UPDATE = 0x00000001,
MIX_FROM_UPDATE = 0x00000002,
RIGHTHANDED_3D = 0x00000004,
CHANNEL_LOWPASS = 0x00000100,
CHANNEL_DISTANCEFILTER = 0x00000200,
PROFILE_ENABLE = 0x00010000,
VOL0_BECOMES_VIRTUAL = 0x00020000,
GEOMETRY_USECLOSEST = 0x00040000,
PREFER_DOLBY_DOWNMIX = 0x00080000,
THREAD_UNSAFE = 0x00100000,
PROFILE_METER_ALL = 0x00200000,
DISABLE_SRS_HIGH_PASS_FILTER = 0x00400000
}
}