Skip to content

Instantly share code, notes, and snippets.

@wldevries
Created August 7, 2014 11:52
Show Gist options
  • Select an option

  • Save wldevries/af40cd1aba180ca60359 to your computer and use it in GitHub Desktop.

Select an option

Save wldevries/af40cd1aba180ca60359 to your computer and use it in GitHub Desktop.
FMOD C# wrapper usage
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class FmodProxy: IDisposable
{
FMOD.Studio.System system;
private bool disposed;
public FmodProxy()
{
}
public void Initialize()
{
new Thread(FmodEventLoop).Start();
}
public void Dispose()
{
this.disposed = true;
}
private void FmodEventLoop()
{
c(FMOD.Studio.System.create(out system));
c(system.initialize(24, FMOD.Studio.INITFLAGS.NORMAL, FMOD.INITFLAGS.NORMAL, IntPtr.Zero));
Console.WriteLine("system valid: " + system.isValid());
FMOD.Studio.Bank bank;
c(system.loadBankFile(@"Audio\Weapons.bank", FMOD.Studio.LOAD_BANK_FLAGS.NORMAL, out bank));
c(bank.loadSampleData());
FMOD.Studio.LOADING_STATE loadingState;
c(bank.getLoadingState(out loadingState));
Console.WriteLine("bank loading state: " + loadingState);
Console.WriteLine("bank valid: " + bank.isValid());
PrintPaths(bank);
var eventD = GetEventDescription(@"event:/Explosions/Single Explosion");
PlayEventDescription(eventD);
while (!disposed)
{
c(system.update());
}
}
private void PlayEventDescription(FMOD.Studio.EventDescription eventD)
{
FMOD.Studio.EventInstance instance;
c(eventD.createInstance(out instance));
c(instance.start());
}
private static void PrintPaths(FMOD.Studio.Bank bank)
{
FMOD.Studio.EventDescription[] eventDescriptions;
c(bank.getEventList(out eventDescriptions));
foreach(var ed in eventDescriptions)
{
Console.WriteLine("event description valid: " + ed.isValid());
c(ed.loadSampleData());
string path;
c(ed.getPath(out path));
Console.WriteLine(path);
}
}
private FMOD.Studio.EventDescription GetEventDescription(string path)
{
FMOD.Studio.EventDescription eventDescription;
FMOD.GUID guid;
c(system.lookupID(path, out guid));
c(system.getEvent(guid, FMOD.Studio.LOADING_MODE.BEGIN_NOW, out eventDescription));
return eventDescription;
}
private static void c(FMOD.RESULT result)
{
if (result != FMOD.RESULT.OK)
Console.WriteLine(result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment