Skip to content
shmellyorc edited this page Sep 13, 2026 · 5 revisions

Audio

VOID's game-facing audio API is built around Sound, SoundInstance, and SoundHelper.

Internally, playback is handled by Silk.NET.OpenAL. Encoded files are decoded to PCM through NAudio.SoundFile before OpenAL receives them.

SDL audio is not used.

Load a Sound

var explosion =
    AssetManager.Instance.Load<Sound>("Audio/explosion.wav");

var music =
    AssetManager.Instance.Load<Sound>("Audio/music.ogg");

Supported Asset Extensions

VOID currently registers these sound extensions:

.ogg .wav .flac .mp3 .aiff .au .raw .paf .svx .nist .voc
.ircam .w64 .mat4 .mat5 .pvf .htk .sds .avr .sd2 .caf .wve
.mpc2k .rf64

Actual decoding depends on the bundled decoder's support for the file contents.

Sound Priority

var explosion =
    AssetManager.Instance.LoadSound(
        "Audio/explosion.wav",
        SoundPriority.High);

Priorities are:

  • Low
  • Normal
  • High
  • Critical

The pool uses priority when deciding which active voice can be reused.

Create and Play an Instance

Define categories however you like:

public enum SoundCategory
{
    SFX,
    Music,
    UI,
    Ambient
}

Then create an instance:

var instance =
    explosion.CreateInstance(SoundCategory.SFX);

instance.Volume = 0.8f;
instance.Pan = -0.5f;
instance.Pitch = 1.2f;
instance.Looping = false;

instance.Play();

Playback Control

instance.Play();
instance.Pause();
instance.Stop();

Status helpers:

bool playing = instance.IsPlaying;
bool paused = instance.IsPaused;
bool stopped = instance.IsStopped;
bool complete = instance.IsComplete;

IsComplete is useful when you specifically need to know that an instance has finished/stopped and its completion state has been recorded.

Playback Properties

float volume = instance.Volume;      // 0..1
float pan = instance.Pan;            // -1..1
float pitch = instance.Pitch;
float playTime = instance.PlayTime;
float duration = instance.Duration;
float progress = instance.Progress;  // 0..1
int loops = instance.LoopCount;

The public pitch property accepts a wide range, while the OpenAL backend clamps the value used for portable playback behavior.

Events

instance.SoundCompleted += (sender, e) =>
{
    Console.WriteLine(
        $"Completed after {e.LoopCount} loops");
};

instance.SoundLooped += (sender, e) =>
{
    Console.WriteLine(
        $"Loop #{e.LoopCount}");
};

instance.SoundStopped += (sender, e) =>
{
    Console.WriteLine(
        $"Stopped. Playing before stop: {e.WasPlaying}, " +
        $"paused before stop: {e.WasPaused}");
};

instance.SoundError += (sender, e) =>
{
    Console.WriteLine(e.ErrorMessage);
};

SoundStoppedEventArgs.WasPlaying and WasPaused describe the instance state captured immediately before Stop() changed it.

Master and Category Volume

SoundHelper.MasterVolume = 0.8f;

SoundHelper.SetCategoryVolume(
    SoundCategory.SFX,
    0.9f);

SoundHelper.SetCategoryVolume(
    SoundCategory.Music,
    0.5f);

Read a category volume:

float musicVolume =
    SoundHelper.GetCategoryVolume(
        SoundCategory.Music);

Pooled One-Shots

SoundHelper.PlayPooled(
    explosion,
    volume: 0.8f,
    pan: 0f,
    pitch: 1f,
    category: SoundCategory.SFX);

Pitch variation:

SoundHelper.PlayPooledWithVariation(
    explosion,
    variation: 0.15f,
    volume: 0.8f,
    pan: 0f,
    category: SoundCategory.SFX);

Sound Groups

SoundHelper.RegisterSoundGroup(
    "footsteps",
    footstep1,
    footstep2,
    footstep3);

Play a random member:

SoundHelper.PlayFromGroup(
    "footsteps",
    0.7f,
    0f,
    1f,
    SoundCategory.SFX,
    true);

Pool Information

int active = SoundHelper.ActiveSoundCount;
int available = SoundHelper.AvailableSoundCount;
int total = SoundHelper.TotalSoundCount;
bool exhausted = SoundHelper.IsPoolExhausted;

Configure the maximum pool size at startup:

GameSettings.Instance.SetAudioLimit(128);

Batch Operations

SoundHelper.StopAll();
SoundHelper.PauseAll();
SoundHelper.ResumeAll();

For additional shortcuts see SoundHelper and Sound Extensions.


Back to Home

Clone this wiki locally