Table of Contents

Class SunVox

Namespace
SunSharp
Assembly
SunSharp.dll

Supports all classes in the .NET class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all .NET classes; it is the root of the type hierarchy.

public sealed class SunVox : ISunVox
Inheritance
object
SunVox
Implements

Properties

Channels

Number of channels SunVox was initialized with on startup.

public AudioChannels Channels { get; }

Property Value

AudioChannels

Deinitialized

public bool Deinitialized { get; }

Property Value

bool

Library

The underlying library interface. Direct use may break existing abstractions.

public SunVoxLib Library { get; }

Property Value

SunVoxLib

NeedsUserCallback

public bool NeedsUserCallback { get; }

Property Value

bool

OutputType

public OutputType? OutputType { get; }

Property Value

OutputType?

SampleRate

public int SampleRate { get; }

Property Value

int

SingleThreaded

public bool SingleThreaded { get; }

Property Value

bool

Slots

public Slots Slots { get; }

Property Value

Slots

Version

public SunVoxVersion Version { get; }

Property Value

SunVoxVersion

Methods

AudioCallback(short[], short[], AudioChannels, int, uint)

Send audio to the Input module and get the next piece of audio from the Output module.

public bool AudioCallback(short[] outputBuffer, short[] inputBuffer, AudioChannels inputChannels, int latency, uint outTime)

Parameters

outputBuffer short[]

Output buffer to write audio data to.

inputBuffer short[]

Input buffer. Stereo data must be interleaved.

inputChannels AudioChannels

Number of input channels.

latency int

Audio latency in frames.

outTime uint

Buffer output time in system ticks. See GetTicks().

Returns

bool

true if buffer contains any non-0 samples.

Remarks

Exceptions

ArgumentException

Thrown when buffer sizes are invalid for the channel count or not equal length.

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if outputBuffer or inputBuffer is null.

AudioCallback(short[], int, uint)

Get the next piece of audio from the Output module.

public bool AudioCallback(short[] outputBuffer, int latency, uint outTime)

Parameters

outputBuffer short[]

Output buffer to write audio data to.

latency int

Audio latency in frames.

outTime uint

Buffer output time in system ticks. See GetTicks().

Returns

bool

true if buffer contains any non-0 samples.

Remarks

UserAudioCallback must be set in Initialize(int, string?, AudioChannels, SunVoxInitOptions) to use this function.

Make sure to call the correct overload for the buffer data type.

Calls sv_audio_callback(IntPtr, int, int, uint).

Exceptions

ArgumentException

Thrown when buffer size is invalid for the channel count.

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if outputBuffer is null.

AudioCallback(short[], float[], AudioChannels, int, uint)

Send audio to the Input module and get the next piece of audio from the Output module.

public bool AudioCallback(short[] outputBuffer, float[] inputBuffer, AudioChannels inputChannels, int latency, uint outTime)

Parameters

outputBuffer short[]

Output buffer to write audio data to.

inputBuffer float[]

Input buffer. Stereo data must be interleaved.

inputChannels AudioChannels

Number of input channels.

latency int

Audio latency in frames.

outTime uint

Buffer output time in system ticks. See GetTicks().

Returns

bool

true if buffer contains any non-0 samples.

Remarks

Exceptions

ArgumentException

Thrown when buffer sizes are invalid for the channel count or not equal length.

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if outputBuffer or inputBuffer is null.

AudioCallback(float[], short[], AudioChannels, int, uint)

Send audio to the Input module and get the next piece of audio from the Output module.

public bool AudioCallback(float[] outputBuffer, short[] inputBuffer, AudioChannels inputChannels, int latency, uint outTime)

Parameters

outputBuffer float[]

Output buffer to write audio data to.

inputBuffer short[]

Input buffer. Stereo data must be interleaved.

inputChannels AudioChannels

Number of input channels.

latency int

Audio latency in frames.

outTime uint

Buffer output time in system ticks. See GetTicks().

Returns

bool

true if buffer contains any non-0 samples.

Remarks

Exceptions

ArgumentException

Thrown when buffer sizes are invalid for the channel count or not equal length.

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if outputBuffer or inputBuffer is null.

AudioCallback(float[], int, uint)

Get the next piece of audio from the Output module.

public bool AudioCallback(float[] outputBuffer, int latency, uint outTime)

Parameters

outputBuffer float[]

Output buffer to write audio data to.

latency int

Audio latency in frames.

outTime uint

Buffer output time in system ticks. See GetTicks().

Returns

bool

true if buffer contains any non-0 samples.

Remarks

UserAudioCallback must be set in Initialize(int, string?, AudioChannels, SunVoxInitOptions) to use this function.

Make sure to call the correct overload for the buffer data type.

Calls sv_audio_callback(IntPtr, int, int, uint).

Exceptions

ArgumentException

Thrown when buffer size is invalid for the channel count.

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if outputBuffer is null.

AudioCallback(float[], float[], AudioChannels, int, uint)

Send audio to the Input module and get the next piece of audio from the Output module.

public bool AudioCallback(float[] outputBuffer, float[] inputBuffer, AudioChannels inputChannels, int latency, uint outTime)

Parameters

outputBuffer float[]

Output buffer to write audio data to.

inputBuffer float[]

Input buffer. Stereo data must be interleaved.

inputChannels AudioChannels

Number of input channels.

latency int

Audio latency in frames.

outTime uint

Buffer output time in system ticks. See GetTicks().

Returns

bool

true if buffer contains any non-0 samples.

Remarks

Exceptions

ArgumentException

Thrown when buffer sizes are invalid for the channel count or not equal length.

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if outputBuffer or inputBuffer is null.

Dispose()

Use to deinitialize the library and free resources.

public void Dispose()

~SunVox()

protected ~SunVox()

GetLog(int)

Get the latest log messages from the SunVox engine.

public string? GetLog(int length)

Parameters

length int

Returns

string

Log messages, or null if unavailable.

Remarks

Log messages are typically written when a call to another function fails.

Calls sv_get_log(int).

GetTicks()

Get the current system tick counter.

public uint GetTicks()

Returns

uint

Remarks

SunVox engine uses system-provided time space, measured in system ticks (don't confuse it with the project ticks). System ticks are used for timing in functions like AudioCallback(float[], AudioChannels, int, uint) and SetEventTiming(int, int).

Calls sv_get_ticks().

GetTicksPerSecond()

Get the number of system ticks per second.

public uint GetTicksPerSecond()

Returns

uint

Remarks

UpdateInputDevices()

Handle input ON/OFF requests to enable/disable sound card input ports (e.g., after Input module creation). Call from the main thread only, where the SunVox sound stream is not locked.

public void UpdateInputDevices()

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

WithOwnAudioStream(ISunVoxLibC, AudioChannels, uint?, string?, string?, string?, bool)

Create an instance of the engine with own audio stream and threading.

public static SunVox WithOwnAudioStream(ISunVoxLibC library, AudioChannels channels = AudioChannels.Stereo, uint? bufferSize = null, string? deviceIn = null, string? deviceOut = null, string? driver = null, bool noDebugOutput = true)

Parameters

library ISunVoxLibC
channels AudioChannels
bufferSize uint?

Leave null for the value to be assigned by the engine.

deviceIn string

Leave null for the value to be assigned by the engine.

deviceOut string

Leave null for the value to be assigned by the engine.

driver string

Leave null for the value to be assigned by the engine.

noDebugOutput bool

Limit information sent to Standard Output.

Returns

SunVox

WithUserManagedAudio(ISunVoxLibC, int, OutputType, AudioChannels, bool, bool)

Create an instance of the engine with the intent of using AudioCallback.

public static SunVox WithUserManagedAudio(ISunVoxLibC library, int sampleRate, OutputType outputType, AudioChannels channels = AudioChannels.Stereo, bool singleThreaded = false, bool noDebugOutput = true)

Parameters

library ISunVoxLibC
sampleRate int
outputType OutputType
channels AudioChannels
singleThreaded bool

Use to promise that audio callback and other methods will be called from one thread.

noDebugOutput bool

Limit information sent to Standard Output.

Returns

SunVox

Exceptions

ArgumentException