Skip to content

AudioAPI reference

Class MixerAudioDevice

Namespace: MicroEngine.Audio
Assembly: MicroEngine.Audio.dll
Guide: Audio

An IAudioDevice over the engine’s one mixer (AudioEngine) and a PCM sink: every backend device is one of these with its own sink, so voices, priorities, stealing, music and fades behave the same everywhere. Music decodes in managed code: WAV, OGG Vorbis (streamed, decoded ahead outside the simulation step), and formats a backend adds (AddDecoder).

C#
public class MixerAudioDevice : IAudioDevice, IDisposable

Inheritance

object ← MixerAudioDevice

Derived

CaptureAudioDevice

Implements

IAudioDevice, IDisposable

Remarks

Sound effects play on the “sfx” bus with priority 0, music on the “music” bus with the highest priority, so the voice limit (MaxVoices) never steals the music. Update ends a simulation step; Pump is the host frame’s audio work.

Constructors

MixerAudioDevice(IAudioSink, AudioEngineSettings?)

A device mixing into sink, which starts rendering now.

C#
public MixerAudioDevice(IAudioSink sink, AudioEngineSettings? settings = null)

Parameters

sink IAudioSink

settings AudioEngineSettings?

Properties

CurrentMusic

The music started last, until it is stopped or (when it does not loop) ends on the mixer’s timeline.

C#
public MusicHandle? CurrentMusic { get; }

Property Value

MusicHandle?

Engine

The mixer, for what IAudioDevice does not cover: buses, handles, priorities.

C#
public AudioEngine Engine { get; }

Property Value

AudioEngine

IsAvailable

True: the sink plays. A backend whose device could not open uses a SilentAudioDevice instead.

C#
public virtual bool IsAvailable { get; }

Property Value

bool

MusicFormats

The formats LoadMusicStream decodes, lower case: “wav”, “ogg” and any a backend added.

C#
public IReadOnlyList<string> MusicFormats { get; }

Property Value

IReadOnlyList<string>

Methods

AddDecoder(string, Func<byte[], IAudioStream>)

Adds a music format the device decodes (a backend’s native decoder, for example).

C#
protected void AddDecoder(string format, Func<byte[], IAudioStream> open)

Parameters

format string

The file extension without the dot.

open Func<byte[], IAudioStream>

Opens a stream over the file’s bytes; throws InvalidDataException for bytes it cannot decode.

Dispose()

Stops the sink and releases the streams.

C#
public void Dispose()

Dispose(bool)

Stops the mixer; a backend also closes its device here.

C#
protected virtual void Dispose(bool disposing)

Parameters

disposing bool

LoadMusic(string, AudioClip, bool)

Uploads decoded music and returns its handle.

C#
public MusicHandle LoadMusic(string name, AudioClip clip, bool loop = true)

Parameters

name string

Name reported by Name.

clip AudioClip

The music samples.

loop bool

Whether the music restarts when it reaches its end.

Returns

MusicHandle

LoadMusicStream(string, byte[], string, bool)

Loads music to stream: “wav” is decoded now; “ogg” and the formats a backend added are decoded while they play.

C#
public MusicHandle LoadMusicStream(string name, byte[] encoded, string format, bool loop = true)

Parameters

name string

encoded byte[]

format string

loop bool

Returns

MusicHandle

Exceptions

NotSupportedException

The format is not one of MusicFormats.

InvalidDataException

The bytes cannot be decoded as that format.

LoadSound(string, AudioClip)

Uploads a sound effect and returns its handle.

C#
public SoundHandle LoadSound(string name, AudioClip clip)

Parameters

name string

clip AudioClip

Returns

SoundHandle

PauseMusic(bool)

Pauses (true) or resumes (false) the current music.

C#
public void PauseMusic(bool paused)

Parameters

paused bool

Play(SoundHandle, float, float, float)

Plays a sound effect once, mixed with any sounds already playing.

C#
public virtual void Play(SoundHandle sound, float volume = 1, float pitch = 1, float pan = 0.5)

Parameters

sound SoundHandle

A handle from LoadSound.

volume float

Volume, 0..1.

pitch float

Playback speed factor; 1 is the original pitch.

pan float

Stereo position, 0 (left) to 1 (right); 0.5 is centred.

PlayMusic(MusicHandle, float)

Starts music from the beginning, replacing the music that was playing.

C#
public void PlayMusic(MusicHandle music, float volume = 1)

Parameters

music MusicHandle

volume float

Pump()

The host frame’s audio work: decodes streamed music ahead and pumps the sink.

C#
public virtual void Pump()

SetMusicVolume(float)

Sets the volume of the current music, 0..1.

C#
public void SetMusicVolume(float volume)

Parameters

volume float

StopMusic()

Stops the music immediately.

C#
public void StopMusic()

Update()

Ends a simulation step (the game calls it once per update through Update).

C#
public virtual void Update()