Repository navigation
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.
var explosion =
AssetManager.Instance.Load<Sound>("Audio/explosion.wav");
var music =
AssetManager.Instance.Load<Sound>("Audio/music.ogg");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.
var explosion =
AssetManager.Instance.LoadSound(
"Audio/explosion.wav",
SoundPriority.High);Priorities are:
LowNormalHighCritical
The pool uses priority when deciding which active voice can be reused.
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();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.
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.
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.
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);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);SoundHelper.RegisterSoundGroup(
"footsteps",
footstep1,
footstep2,
footstep3);Play a random member:
SoundHelper.PlayFromGroup(
"footsteps",
0.7f,
0f,
1f,
SoundCategory.SFX,
true);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);SoundHelper.StopAll();
SoundHelper.PauseAll();
SoundHelper.ResumeAll();For additional shortcuts see SoundHelper and Sound Extensions.
Home · Getting Started · Rendering · Custom Renderers · GitHub · Report an Issue
Built with VOID Engine · MIT License
- Coroutines
- State Machine
- Save System
- Pathfinding
- Logging
- Beacon Manager
- Beacon Event System
- Discoverable System
- Instance Helper
- BeaconManager Extensions
- BeaconHandle Extensions
- Enum Extensions
- String Extensions
- Int Extensions
- Float Extensions
- IEnumerable Extensions
- Random Extensions
- Sound Extensions
- Font Extensions