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
-
objectSunVox
- Implements
Properties
Channels
Number of channels SunVox was initialized with on startup.
public AudioChannels Channels { get; }
Property Value
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
NeedsUserCallback
public bool NeedsUserCallback { get; }
Property Value
- bool
OutputType
public OutputType? OutputType { get; }
Property Value
SampleRate
public int SampleRate { get; }
Property Value
- int
SingleThreaded
public bool SingleThreaded { get; }
Property Value
- bool
Slots
public Slots Slots { get; }
Property Value
Version
public SunVoxVersion Version { get; }
Property Value
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
outputBuffershort[]Output buffer to write audio data to.
inputBuffershort[]Input buffer. Stereo data must be interleaved.
inputChannelsAudioChannelsNumber of input channels.
latencyintAudio latency in frames.
outTimeuintBuffer 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.
Calls sv_audio_callback2(IntPtr, int, int, uint, int, int, IntPtr).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
outputBufferorinputBufferis 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
outputBuffershort[]Output buffer to write audio data to.
latencyintAudio latency in frames.
outTimeuintBuffer 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
outputBufferis 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
outputBuffershort[]Output buffer to write audio data to.
inputBufferfloat[]Input buffer. Stereo data must be interleaved.
inputChannelsAudioChannelsNumber of input channels.
latencyintAudio latency in frames.
outTimeuintBuffer 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.
Calls sv_audio_callback2(IntPtr, int, int, uint, int, int, IntPtr).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
outputBufferorinputBufferis 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
outputBufferfloat[]Output buffer to write audio data to.
inputBuffershort[]Input buffer. Stereo data must be interleaved.
inputChannelsAudioChannelsNumber of input channels.
latencyintAudio latency in frames.
outTimeuintBuffer 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.
Calls sv_audio_callback2(IntPtr, int, int, uint, int, int, IntPtr).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
outputBufferorinputBufferis 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
outputBufferfloat[]Output buffer to write audio data to.
latencyintAudio latency in frames.
outTimeuintBuffer 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
outputBufferis 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
outputBufferfloat[]Output buffer to write audio data to.
inputBufferfloat[]Input buffer. Stereo data must be interleaved.
inputChannelsAudioChannelsNumber of input channels.
latencyintAudio latency in frames.
outTimeuintBuffer 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.
Calls sv_audio_callback2(IntPtr, int, int, uint, int, int, IntPtr).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
outputBufferorinputBufferis 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
lengthint
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
Calls sv_get_ticks_per_second().
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
Calls sv_update_input().
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
libraryISunVoxLibCchannelsAudioChannelsbufferSizeuint?Leave null for the value to be assigned by the engine.
deviceInstringLeave null for the value to be assigned by the engine.
deviceOutstringLeave null for the value to be assigned by the engine.
driverstringLeave null for the value to be assigned by the engine.
noDebugOutputboolLimit information sent to Standard Output.
Returns
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
libraryISunVoxLibCsampleRateintoutputTypeOutputTypechannelsAudioChannelssingleThreadedboolUse to promise that audio callback and other methods will be called from one thread.
noDebugOutputboolLimit information sent to Standard Output.
Returns
Exceptions
- ArgumentException