brutal/samples/Hello/HelloFmod.cs
Rian Drake d1ce547eb2 samples: bump every package pin to the latest release
Fixes #38

Co-authored-by: LesoDeVaren <268139647+LesoDeVaren@users.noreply.github.com>
2026-11-03 11:43:45 +13:00

53 lines
1.5 KiB
C#

/*
* HelloFmod
*
* Starts FMOD, prints its version and plays a 440 Hz tone from FMOD's built-in oscillator.
*
* FMOD natives are not bundled: put your licensed FMOD 2.03 Core library (fmod.dll, libfmod.so
* or libfmod.dylib) on the library search path (PATH on Windows, LD_LIBRARY_PATH on Linux,
* DYLD_LIBRARY_PATH on macOS), or this throws DllNotFoundException.
*/
#:package Ahwoo.Brutal.Fmod@2026.10.4
#:package Ahwoo.Brutal.Core@2026.10.4
// RIAN: It needs to be stressed that we do not provide FMOD binaries, and you must obtain them from the official FMOD website.
using Brutal.FmodApi;
// The FMOD system owns everything else; closing and releasing it frees anything left behind.
var system = Fmod.SystemCreate(Fmod.VERSION);
system.Init(32, InitFlags.Normal, 0);
try
{
Run(system);
}
finally
{
system.Close();
system.Release();
}
static void Run(FmodSystem system)
{
system.GetVersion(out var version, out _);
Console.WriteLine($"FMOD version: {version >> 16:x}.{(version >> 8) & 0xff:x2}.{version & 0xff:x2}");
var dsp = system.CreateDspByType(DspType.Oscillator); // Generates a sine wave by default.
dsp.SetParameterFloat((int)DspOscillator.Rate, 440.0f);
var channel = system.PlayDsp(dsp, default, false);
channel.SetVolume(0.5f);
Console.WriteLine("Playing a 440 Hz tone...");
for (var i = 0; i < 100; i++)
{
system.Update();
Thread.Sleep(10);
}
// Channels and DSPs aren't IDisposable, so stop and release them by hand.
channel.Stop();
dsp.Release();
}