Table of Contents

Interface ISunVoxLib

Namespace
SunSharp.Native
Assembly
SunSharp.dll

Friendlier interface for SunVox native library functions.

public interface ISunVoxLib

Methods

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

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

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

Parameters

outputBuffer short[]

Output buffer to write audio data to.

outputChannels AudioChannels

Number of channels the library was initialized with.

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[], AudioChannels, int, uint)

Get the next piece of audio from the Output module.

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

Parameters

outputBuffer short[]

Output buffer to write audio data to.

channels AudioChannels

Number of channels the library was initialized with.

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[], AudioChannels, float[], AudioChannels, int, uint)

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

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

Parameters

outputBuffer short[]

Output buffer to write audio data to.

outputChannels AudioChannels

Number of channels the library was initialized with.

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[], AudioChannels, short[], AudioChannels, int, uint)

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

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

Parameters

outputBuffer float[]

Output buffer to write audio data to.

outputChannels AudioChannels

Number of channels the library was initialized with.

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[], AudioChannels, int, uint)

Get the next piece of audio from the Output module.

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

Parameters

outputBuffer float[]

Output buffer to write audio data to.

channels AudioChannels

Number of channels the library was initialized with.

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[], AudioChannels, float[], AudioChannels, int, uint)

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

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

Parameters

outputBuffer float[]

Output buffer to write audio data to.

outputChannels AudioChannels

Number of channels the library was initialized with.

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.

ClonePattern(int, int, int, int)

Clone a pattern.

int ClonePattern(int slotId, int originalPatternId, int x, int y)

Parameters

slotId int

Slot number (0 to 15).

originalPatternId int

Pattern to clone.

x int

Line number on which the pattern starts (horizontal).

y int

Vertical position on the timeline.

Returns

int

The number of the newly created pattern.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

CloseSlot(int)

Close the slot and free its resources.

void CloseSlot(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ConnectModules(int, int, int)

Connect the source module to the destination module.

void ConnectModules(int slotId, int source, int destination)

Parameters

slotId int

slot number (0 to 15).

source int

Source module number (0-based).

destination int

Destination module number (0-based).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

CreateModule(int, SynthModuleType, string?, int, int, int)

Create a new module.

int CreateModule(int slotId, SynthModuleType type, string? name = null, int x = 0, int y = 0, int z = 0)

Parameters

slotId int

slot number (0 to 15).

type SynthModuleType

Type of module to create.

name string

Name of the module.

x int

X coordinate (0 to 1024, center: 512).

y int

Y coordinate (0 to 1024, center: 512).

z int

Layer number (0 to 7).

Returns

int

The identifier of the newly created module (0-based).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if type is null.

ArgumentOutOfRangeException

Thrown when the module type is not valid.

CreateModule(int, string, string?, int, int, int)

Create a new module.

int CreateModule(int slotId, string type, string? name = null, int x = 0, int y = 0, int z = 0)

Parameters

slotId int

slot number (0 to 15).

type string

Type of module to create.

name string

Name of the module.

x int

X coordinate (0 to 1024, center: 512).

y int

Y coordinate (0 to 1024, center: 512).

z int

Layer number (0 to 7).

Returns

int

The identifier of the newly created module (0-based).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if type is null.

CreatePattern(int, int, int, int, int, int, string?)

Create a new pattern.

int CreatePattern(int slotId, int x, int y, int tracks, int lines, int iconSeed = 0, string? name = null)

Parameters

slotId int

Slot number (0 to 15).

x int

Line number on which the pattern starts.

y int

Y coordinate on timeline.

tracks int

Number of tracks.

lines int

Number of lines.

iconSeed int

Icon seed for pattern appearance.

name string

Pattern name.

Returns

int

The number of the newly created pattern.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

Deinitialize()

Deinitialize the SunVox engine and free all resources.

void Deinitialize()

Remarks

Calls sv_deinit().

Exceptions

SunVoxException

Thrown when the operation fails, or when already deinitialized.

DisconnectModules(int, int, int)

Disconnect the source module from the destination module.

void DisconnectModules(int slotId, int source, int destination)

Parameters

slotId int

slot number (0 to 15).

source int

Source module number (0-based).

destination int

Destination module number (0-based).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

FindModule(int, string)

Find a module by name.

int? FindModule(int slotId, string name)

Parameters

slotId int

slot number (0 to 15).

name string

Module name to search for.

Returns

int?

module number (0-based) if found.

Remarks

Exceptions

SunVoxException

Thrown when an error occurs during the search.

ArgumentNullException

Thrown if name is null.

FindPattern(int, string)

Find a pattern by name.

int? FindPattern(int slotId, string name)

Parameters

slotId int

Slot number (0 to 15).

name string

Pattern name to search for.

Returns

int?

Pattern number if found.

Remarks

Exceptions

SunVoxException

Thrown when an error occurs during the search.

ArgumentNullException

Thrown if name is null.

GetAutomaticStop(int)

Get the autostop mode. When false, the project loops endlessly.

bool GetAutomaticStop(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Returns

bool

true if automatic stop is enabled.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetCurrentLine(int)

Get the current line number on the timeline.

int GetCurrentLine(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Returns

int

Current line number (playback position).

Remarks

GetCurrentLineWithTenthPart(int)

Get the current line number in fixed point format. The value contains the tenth part of the line for higher precision.

int GetCurrentLineWithTenthPart(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Returns

int

Current line number in fixed point format.

Remarks

GetCurrentSignalLevel(int, AudioChannel)

Get the current signal level from the Output module.

int GetCurrentSignalLevel(int slotId, AudioChannel channel)

Parameters

slotId int

Slot number (0 to 15).

channel AudioChannel

Audio channel.

Returns

int

Signal level (0 to 255).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetLog(int)

Get the latest log messages from the SunVox engine.

string? GetLog(int size)

Parameters

size int

Maximum number of characters to read.

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).

GetModuleColor(int, int)

Get the module color.

(byte r, byte g, byte b) GetModuleColor(int slotId, int moduleId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

Returns

(byte R, byte G, byte B)

RGB color tuple (r, g, b).

Remarks

GetModuleControllerCount(int, int)

Get the number of controllers in the module.

int GetModuleControllerCount(int slotId, int moduleId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

Returns

int

Number of controllers.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetModuleControllerGroup(int, int, int)

Get the controller group number.

int GetModuleControllerGroup(int slotId, int moduleId, int controllerId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

controllerId int

controller number (0-based).

Returns

int

Controller group number.

Remarks

GetModuleControllerMaxValue(int, int, int, ValueScalingMode)

Get the controller maximum value.

int GetModuleControllerMaxValue(int slotId, int moduleId, int controllerId, ValueScalingMode scalingMode)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

controllerId int

Controller number (0-based).

scalingMode ValueScalingMode

Value scaling mode.

Returns

int

Maximum controller value.

Remarks

GetModuleControllerMinValue(int, int, int, ValueScalingMode)

Get the controller minimum value.

int GetModuleControllerMinValue(int slotId, int moduleId, int controllerId, ValueScalingMode scalingMode)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

controllerId int

Controller number (0-based).

scalingMode ValueScalingMode

Value scaling mode.

Returns

int

Minimum controller value.

Remarks

GetModuleControllerName(int, int, int)

Get the controller name.

string? GetModuleControllerName(int slotId, int moduleId, int controllerId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

controllerId int

Controller number (0-based).

Returns

string

Controller name, or null if unavailable.

Remarks

GetModuleControllerOffset(int, int, int)

Get the controller display value offset.

int GetModuleControllerOffset(int slotId, int moduleId, int controllerId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

controllerId int

Controller number (0-based).

Returns

int

Display value offset.

Remarks

GetModuleControllerType(int, int, int)

Get the controller type.

ControllerType GetModuleControllerType(int slotId, int moduleId, int controllerId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

controllerId int

Controller number (0-based).

Returns

ControllerType

Controller type.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetModuleControllerValue(int, int, int, ValueScalingMode)

Get the controller value.

int GetModuleControllerValue(int slotId, int moduleId, int controllerId, ValueScalingMode scalingMode)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

controllerId int

Controller number (0-based).

scalingMode ValueScalingMode

Value scaling mode.

Returns

int

Controller value.

Remarks

GetModuleExists(int, int)

Check if a module exists.

bool GetModuleExists(int slotId, int moduleId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

Returns

bool

true if module exists.

Remarks

GetModuleFineTune(int, int)

Get the module fine tune and relative note values.

FineTunePair GetModuleFineTune(int slotId, int moduleId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

Returns

FineTunePair

Fine tune pair containing fine tune value and relative note.

Remarks

GetModuleFlags(int, int)

Get the module flags.

ModuleFlags GetModuleFlags(int slotId, int moduleId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

Returns

ModuleFlags

Module flags indicating existence, type, state, and connections.

Remarks

GetModuleInputs(int, int)

Get the array of input module numbers connected to this module.

int[] GetModuleInputs(int slotId, int moduleId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

Returns

int[]

Array of connected input module numbers.

Remarks

GetModuleName(int, int)

Get the module name.

string? GetModuleName(int slotId, int moduleId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

Returns

string

Module name, or null if unavailable.

Remarks

GetModuleOutputs(int, int)

Get the array of output module numbers connected from this module.

int[] GetModuleOutputs(int slotId, int moduleId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

Returns

int[]

Array of connected output module numbers.

Remarks

GetModulePosition(int, int)

Get the module position on the canvas.

(int x, int y) GetModulePosition(int slotId, int moduleId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

Returns

(int x, int y)

Tuple containing X and Y coordinates.

Remarks

GetModuleType(int, int)

Get the module type string.

string? GetModuleType(int slotId, int moduleId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

Returns

string

Module type string, or null if unavailable.

Remarks

GetPatternData(int, int)

Get the pattern data (all events).

(PatternEvent[] data, int tracks, int lines)? GetPatternData(int slotId, int patternId)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

Returns

(PatternEvent[] data, int tracks, int lines)?

Tuple containing event data array, number of tracks, and number of lines if pattern exists.

Remarks

GetPatternEventValue(int, int, int, int, Column)

Get a specific column value from a pattern event.

int GetPatternEventValue(int slotId, int patternId, int track, int line, Column column)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

track int

Track number.

line int

Line number.

column Column

Column to read.

Returns

int

Column value.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetPatternExists(int, int)

Check if a pattern exists.

bool GetPatternExists(int slotId, int patternId)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

Returns

bool

true if pattern exists; false otherwise.

Remarks

GetPatternLines(int, int)

Get the number of lines in the pattern. Can be used to check if a pattern exists (lines > 0).

int GetPatternLines(int slotId, int patternId)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

Returns

int

Number of lines.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetPatternMuted(int, int)

Get the pattern mute state.

bool GetPatternMuted(int slotId, int patternId)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

Returns

bool

true if pattern is muted; false otherwise.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetPatternName(int, int)

Get the pattern name.

string? GetPatternName(int slotId, int patternId)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

Returns

string

Pattern name, or null if unavailable.

Remarks

GetPatternPosition(int, int)

Get the pattern position on the timeline.

(int x, int y) GetPatternPosition(int slotId, int patternId)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

Returns

(int x, int y)

Tuple containing X and Y coordinates.

Remarks

GetPatternTracks(int, int)

Get the number of tracks in the pattern.

int GetPatternTracks(int slotId, int patternId)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

Returns

int

Number of tracks.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetPatternX(int, int)

Get the pattern X coordinate on the timeline.

int GetPatternX(int slotId, int patternId)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

Returns

int

X coordinate.

Remarks

GetPatternY(int, int)

Get the pattern Y coordinate on the timeline.

int GetPatternY(int slotId, int patternId)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

Returns

int

Y coordinate.

Remarks

GetSampleRate()

Get the current sampling rate (may differ from the value specified in Initialize(int, string?, AudioChannels, SunVoxInitOptions)).

int GetSampleRate()

Returns

int

Current sample rate in Hz.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetSongBaseVersion(int)

Get the SunVox version used to create this project.

SunVoxVersion GetSongBaseVersion(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Returns

SunVoxVersion

SunVox version used to create the project.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetSongBpm(int)

Get the project BPM (Beats Per Minute).

int GetSongBpm(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Returns

int

Remarks

The value can be set using pattern effects.

Calls sv_get_song_bpm(int).

Exceptions

SunVoxException

Thrown when the operation fails.

See Also

GetSongLengthInFrames(int)

Get the project length in frames.

uint GetSongLengthInFrames(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Returns

uint

Remarks

A frame is a pair of samples for stereo audio, or a single sample for mono audio.

Calls sv_get_song_length_frames(int).

GetSongLengthInLines(int)

Get the project length in lines.

uint GetSongLengthInLines(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Returns

uint

Remarks

GetSongName(int)

Get the project name.

string? GetSongName(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Returns

string

Project name, or null if unavailable.

Remarks

GetSongTpl(int)

Get the project TPL (Ticks Per Line).

int GetSongTpl(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Returns

int

Remarks

The value can be set using pattern effects.

Calls sv_get_song_tpl(int).

Exceptions

SunVoxException

Thrown when the operation fails.

GetTicks()

Get the current system tick counter.

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.

uint GetTicksPerSecond()

Returns

uint

Remarks

GetTimeMapFrames(int, int, int)

Get the project time map.

uint[] GetTimeMapFrames(int slotId, int startLine, int length)

Parameters

slotId int

Slot number (0 to 15).

startLine int

First line to read (usually 0).

length int

Number of lines to read.

Returns

uint[]

Array with frame counts for each line.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetTimeMapSpeed(int, int, int)

Get the project time map.

Speed[] GetTimeMapSpeed(int slotId, int startLine, int length)

Parameters

slotId int

Slot number (0 to 15).

startLine int

First line to read (usually 0).

length int

Number of lines to read.

Returns

Speed[]

Array with information about speed for each line.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetUpperModuleCount(int)

Get the upper limit of module count (one more than the highest module number).

int GetUpperModuleCount(int slotId)

Parameters

slotId int

slot number (0 to 15).

Returns

int

Upper limit of module count.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

GetUpperPatternCount(int)

Get the upper limit of pattern count (one more than the highest pattern number).

int GetUpperPatternCount(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Returns

int

Upper limit of pattern count.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

Initialize(int, string?, AudioChannels, SunVoxInitOptions)

Initialize the SunVox engine.

SunVoxVersion Initialize(int sampleRate, string? config = null, AudioChannels channels = AudioChannels.Stereo, SunVoxInitOptions options = SunVoxInitOptions.None)

Parameters

sampleRate int

Desired sample rate (Hz); minimum 44100. The actual rate may differ if offline mode is not set.

config string

Configuration string in pipe-separated format (e.g., "param1=value1|param2=value2"). Use null for automatic configuration.

channels AudioChannels

Number of audio channels.

options SunVoxInitOptions

Initialization flags.

Returns

SunVoxVersion

Remarks

Exceptions

SunVoxException

Thrown when initialization fails, or when already initialized.

IsPlaying(int)

Check if the project is currently playing.

bool IsPlaying(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Returns

bool

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

Load(int, byte[])

Load a SunVox project from memory.

void Load(int slotId, byte[] data)

Parameters

slotId int

Slot number (0 to 15).

data byte[]

Byte array with project data.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

Load(int, string)

Load a SunVox project from file.

void Load(int slotId, string path)

Parameters

slotId int

Slot number (0 to 15).

path string

File path (relative or absolute).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if path is null.

LoadIntoMetaModule(int, int, byte[])

Load a file into a MetaModule from memory. Supported file formats: sunvox, mod, xm, midi.

void LoadIntoMetaModule(int slotId, int moduleId, byte[] data)

Parameters

slotId int

slot number (0 to 15).

moduleId int

Metamodule number (0-based).

data byte[]

Byte array with project data.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if data is null.

LoadIntoMetaModule(int, int, string)

Load a file into a MetaModule. Supported file formats: sunvox, mod, xm, midi.

void LoadIntoMetaModule(int slotId, int moduleId, string path)

Parameters

slotId int

slot number (0 to 15).

moduleId int

Metamodule number (0-based).

path string

File path (relative or absolute).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if path is null.

LoadIntoVorbisPlayer(int, int, byte[])

Load a file into a Vorbis Player module from memory. Supported file formats: ogg.

void LoadIntoVorbisPlayer(int slotId, int moduleId, byte[] data)

Parameters

slotId int

slot number (0 to 15).

moduleId int

Vorbis Player module number (0-based).

data byte[]

Byte array with audio file data.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if data is null.

LoadIntoVorbisPlayer(int, int, string)

Load a file into a Vorbis Player module. Supported file formats: ogg.

void LoadIntoVorbisPlayer(int slotId, int moduleId, string path)

Parameters

slotId int

slot number (0 to 15).

moduleId int

Vorbis Player module number (0-based).

path string

File path (relative or absolute).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if path is null.

LoadModule(int, byte[], int, int, int)

Load a module or sample from memory. Supported file formats: sunsynth, xi, wav, aiff.

int LoadModule(int slotId, byte[] data, int x = 0, int y = 0, int z = 0)

Parameters

slotId int

slot number (0 to 15).

data byte[]

Byte array with module data.

x int

X coordinate (0 to 1024, center: 512).

y int

Y coordinate (0 to 1024, center: 512).

z int

Layer number (0 to 7).

Returns

int

The number of the loaded module.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if data is null.

LoadModule(int, string, int, int, int)

Load a module or sample from file. Supported file formats: sunsynth, xi, wav, aiff.

int LoadModule(int slotId, string path, int x = 0, int y = 0, int z = 0)

Parameters

slotId int

slot number (0 to 15).

path string

File path (relative or absolute).

x int

X coordinate (0 to 1024, center: 512).

y int

Y coordinate (0 to 1024, center: 512).

z int

Layer number (0 to 7).

Returns

int

The number of the loaded module.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if path is null.

LoadSamplerSample(int, int, byte[], int?)

Load a sample into a Sampler module from memory. Supported file formats: xi, wav, aiff. Set sampleSlot to null to apply the sample to all sample slots.

void LoadSamplerSample(int slotId, int moduleId, byte[] data, int? sampleSlot = null)

Parameters

slotId int

slot number (0 to 15).

moduleId int

Sampler module number (0-based).

data byte[]

Byte array with sample data.

sampleSlot int?

Sample slot number (-1 for auto/all slots).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if data is null.

LoadSamplerSample(int, int, string, int?)

Load a sample into a Sampler module. Supported file formats: xi, wav, aiff. Set sampleSlot to null to apply the sample to all sample slots.

void LoadSamplerSample(int slotId, int moduleId, string path, int? sampleSlot = null)

Parameters

slotId int

slot number (0 to 15).

moduleId int

Sampler module number (0-based).

path string

File path (relative or absolute).

sampleSlot int?

Sample slot number (-1 for auto/all slots).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if path is null.

LockSlot(int)

Lock the slot for thread-safe access. Use when reading/modifying SunVox data from different threads on the same slot. Some functions require lock/unlock. Remember to call UnlockSlot(int)!

void LockSlot(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Remarks

The library uses a recursive mutex, so the same thread may call LockSlot(int) multiple times without deadlocking itself.

Calls sv_lock_slot(int).

Exceptions

SunVoxException

Thrown when the operation fails.

OpenSlot(int)

Open a slot.

void OpenSlot(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

PauseAudioStream(int)

Pause the audio stream from a slot.

void PauseAudioStream(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ReadModuleCurve(int, int, int, float[])

Read data from a module curve.

int ReadModuleCurve(int slotId, int moduleId, int curveId, float[] data)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

curveId int

Curve number.

data float[]

Array to receive curveId data.

Returns

int

Number of values read.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if data is null.

ReadModuleScope(int, int, AudioChannel, short[])

Read oscilloscope data from a module.

int ReadModuleScope(int slotId, int moduleId, AudioChannel channel, short[] buffer)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

channel AudioChannel

Audio channel.

buffer short[]

Buffer to receive scope data.

Returns

int

Number of samples read.

Remarks

Exceptions

ArgumentNullException

Thrown if buffer is null.

ReadPatternData(int, int, PatternEvent[], int, int, int, int, int, int, int?, int?)

Read a section or all of the pattern data into a buffer.

int ReadPatternData(int slotId, int patternId, PatternEvent[] buffer, int bufferTracks, int bufferLines, int bufferOffsetTracks = 0, int bufferOffsetLines = 0, int readOffsetTracks = 0, int readOffsetLines = 0, int? maxTracks = null, int? maxLines = null)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

buffer PatternEvent[]

Buffer to receive pattern data.

bufferTracks int

Width of the buffer.

bufferLines int

Height of the buffer.

bufferOffsetTracks int

Number of tracks in the buffer to skip.

bufferOffsetLines int

Number of lines in the buffer to skip.

readOffsetTracks int

Number of tracks in the pattern to skip.

readOffsetLines int

Number of lines in the pattern to skip.

maxTracks int?

Maximum number of tracks to read.

maxLines int?

Maximum number of lines to read.

Returns

int

Number of events read.

Remarks

Exceptions

ArgumentOutOfRangeException

Thrown if any offset or size parameter is negative.

ArgumentException

Thrown if buffer length doesn't match bufferTracks * bufferLines.

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if buffer is null.

RemoveModule(int, int)

Remove (delete) a module.

void RemoveModule(int slotId, int moduleId)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

RemovePattern(int, int)

Delete a pattern.

void RemovePattern(int slotId, int patternId)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

Remarks

Deleting the original pattern also deletes all its clones.

Requires LockSlot(int) / UnlockSlot(int).

Calls sv_remove_pattern(int, int).

Exceptions

SunVoxException

Thrown when the operation fails.

ResetEventTiming(int)

Reset the timestamp of events sent by SendEvent(int, int, PatternEvent). If timestamp is zero: event is heard as quickly as possible.

void ResetEventTiming(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ResumeAudioStream(int)

Resume the audio stream from a slot.

void ResumeAudioStream(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ResumeStreamOnSyncEffect(int)

Wait for sync (pattern effect 0x33 in any slot) and resume the audio stream.

void ResumeStreamOnSyncEffect(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

Rewind(int, int)

Jump to the specified line on the timeline.

void Rewind(int slotId, int line)

Parameters

slotId int

Slot number (0 to 15).

line int

Line number on the timeline.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SaveToFile(int, string)

Save the SunVox project to a file.

void SaveToFile(int slotId, string path)

Parameters

slotId int

Slot number (0 to 15).

path string

File path where the project will be saved.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if path is null.

SendEvent(int, int, PatternEvent)

Send an event to the SunVox engine. Sends the specified pattern event to the given track. The event will be processed according to the last set timing.

void SendEvent(int slotId, int track, PatternEvent data)

Parameters

slotId int

Slot number (0 to 15).

track int

Track number within the virtual pattern.

data PatternEvent

Pattern event data.

Remarks

See Also

SendEvent(int, int, int, int, int, int, int)

Send an event to the SunVox engine. Sends the specified pattern event to the given track. The event will be processed according to the last set timing.

void SendEvent(int slotId, int track, int nn = 0, int vv = 0, int mm = 0, int ccee = 0, int xxyy = 0)

Parameters

slotId int

Slot number (0 to 15).

track int

Track number within the virtual pattern.

nn int

Note.

vv int

Velocity.

mm int

Module.

ccee int

Controller and effect.

xxyy int

Value.

Remarks

Consider using PatternEvent and the overload that accepts it for better readability.

Calls sv_send_event(int, int, int, int, int, int, int).

Exceptions

SunVoxException

Thrown when the operation fails.

SetAutomaticStop(int, bool)

Set autostop mode. When OFF, the project loops endlessly.

void SetAutomaticStop(int slotId, bool enable)

Parameters

slotId int

Slot number (0 to 15).

enable bool

true - stop at the end.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SetEventTiming(int, int)

Set the timestamp of events sent by SendEvent(int, int, PatternEvent). Every event has a timestamp (when it was generated, e.g., key press time). If nonzero: event is heard at timestamp + sound latency * 2.

void SetEventTiming(int slotId, int timestamp)

Parameters

slotId int

Slot number (0 to 15).

timestamp int

Timestamp (in system ticks) for future events. If not zero, must be ≥ previous value for same slot. See GetTicks() and GetTicksPerSecond().

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SetModuleColor(int, int, byte, byte, byte)

Set the module color.

void SetModuleColor(int slotId, int moduleId, byte r, byte g, byte b)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

r byte

Red component (0 to 255).

g byte

Green component (0 to 255).

b byte

Blue component (0 to 255).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SetModuleControllerValue(int, int, int, int, ValueScalingMode)

Set a controller value. Note: SendEvent(int, int, PatternEvent) will be used internally, which may introduce latency.

void SetModuleControllerValue(int slotId, int moduleId, int controllerId, int value, ValueScalingMode scalingMode)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

controllerId int

controller number (0-based).

value int

Controller value.

scalingMode ValueScalingMode

Value scaling mode.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SetModuleFineTune(int, int, int)

Set the module fine tune value.

void SetModuleFineTune(int slotId, int moduleId, int fineTune)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

fineTune int

Fine tune value (-256 to 256, 1/256 of a semitone).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SetModuleName(int, int, string)

Set the module name.

void SetModuleName(int slotId, int moduleId, string name)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

name string

New module name.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if name is null.

SetModulePosition(int, int, int, int)

Set the module position.

void SetModulePosition(int slotId, int moduleId, int x, int y)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

x int

X coordinate (center: 512, working area: 0 to 1024).

y int

Y coordinate (center: 512, working area: 0 to 1024).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SetModuleRelativeNote(int, int, int)

Set the module relative note value.

void SetModuleRelativeNote(int slotId, int moduleId, int relativeNote)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

relativeNote int

Relative note in semitones.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SetPatternData(int, int, PatternEvent[], int, int)

Set the pattern data (all events). Resizes the pattern and sets all event data.

void SetPatternData(int slotId, int patternId, PatternEvent[] data, int tracks, int lines)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

data PatternEvent[]

Event data array (length must equal tracks * lines).

tracks int

Number of tracks.

lines int

Number of lines.

Remarks

Exceptions

ArgumentOutOfRangeException

Thrown if tracks or lines are negative.

ArgumentException

Thrown if data length doesn't match tracks * lines.

SunVoxException

Thrown when the operation fails or pattern doesn't exist.

ArgumentNullException

Thrown if data is null.

SetPatternEvent(int, int, int, int, PatternEvent)

Set a pattern event at a specific location.

void SetPatternEvent(int slotId, int patternId, int track, int line, PatternEvent ev)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

track int

Track number.

line int

Line number.

ev PatternEvent

Pattern event data.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SetPatternEvent(int, int, int, int, int, int, int, int, int)

Set a pattern event at a specific location.

void SetPatternEvent(int slotId, int patternId, int track, int line, int nn, int vv, int mm, int ccee, int xxyy)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

track int

Track number.

line int

Line number.

nn int

Note: 0 - nothing; 1 to 127 - note; 128 - note off; 129+ - see NOTECMD_*.

vv int

Velocity: 1 to 129; 0 - default.

mm int

Module: 0 (empty) or module number + 1 (1 to 65535).

ccee int

Controller/effect: 0xCCEE. CC - controller (1 to 255); EE - effect.

xxyy int

Value: 0xXXYY. Controller value (0 to 32768) or effect parameter (0 to 65535).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SetPatternMuted(int, int, bool)

Set the pattern mute state.

void SetPatternMuted(int slotId, int patternId, bool muted)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

muted bool

true to mute; false to unmute.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SetPatternName(int, int, string)

Set the pattern name.

void SetPatternName(int slotId, int patternId, string name)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

name string

New pattern name.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if name is null.

SetPatternPosition(int, int, int, int)

Set the pattern position on the timeline.

void SetPatternPosition(int slotId, int patternId, int x, int y)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

x int

Line number on which the pattern starts.

y int

Y coordinate on timeline.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SetPatternSize(int, int, int?, int?)

Set the pattern size (number of tracks and/or lines).

void SetPatternSize(int slotId, int patternId, int? tracks = null, int? lines = null)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

tracks int?

Number of tracks (null to keep current).

lines int?

Number of lines (null to keep current).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

SetSongName(int, string)

Set the project name.

void SetSongName(int slotId, string value)

Parameters

slotId int

Slot number (0 to 15).

value string

New project name.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

StartPlayback(int)

Play from the current position.

void StartPlayback(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Remarks

Calls sv_play(int).

Exceptions

SunVoxException

Thrown when the operation fails.

StartPlaybackFromBeginning(int)

Play from the beginning (line 0).

void StartPlaybackFromBeginning(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

StopPlayback(int)

Stop playing. First call stops playback. The sound engine continues working (e.g., reverb tail may be heard). Second call resets all activity and enters standby mode.

void StopPlayback(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Remarks

Calls sv_stop(int).

Exceptions

SunVoxException

Thrown when the operation fails.

UnlockSlot(int)

Unlock the slot. Must be called after LockSlot(int).

void UnlockSlot(int slotId)

Parameters

slotId int

Slot number (0 to 15).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

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.

void UpdateInputDevices()

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

Volume(int, int)

Set the project volume.

int Volume(int slotId, int volume)

Parameters

slotId int

Slot number (0 to 15).

volume int

Volume: 0 (min) to 256 (max/100%). Negative values are ignored.

Returns

int

Previous volume (0 to 256).

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

WriteModuleCurve(int, int, int, float[])

Write data to a module curve.

int WriteModuleCurve(int slotId, int moduleId, int curveId, float[] data)

Parameters

slotId int

slot number (0 to 15).

moduleId int

module number (0-based).

curveId int

Curve number.

data float[]

Array containing curveId data to write.

Returns

int

Number of values written.

Remarks

Exceptions

SunVoxException

Thrown when the operation fails.

ArgumentNullException

Thrown if data is null.

WritePatternData(int, int, PatternEvent[], int, int, int, int, int, int, int?, int?)

Write a section or all of a buffer into the pattern data.

int WritePatternData(int slotId, int patternId, PatternEvent[] buffer, int bufferTracks, int bufferLines, int bufferOffsetTracks = 0, int bufferOffsetLines = 0, int writeOffsetTracks = 0, int writeOffsetLines = 0, int? maxTracks = null, int? maxLines = null)

Parameters

slotId int

Slot number (0 to 15).

patternId int

Pattern number.

buffer PatternEvent[]

Buffer containing pattern data to write.

bufferTracks int

Width of the buffer.

bufferLines int

Height of the buffer.

bufferOffsetTracks int

Number of tracks in the buffer to skip.

bufferOffsetLines int

Number of lines in the buffer to skip.

writeOffsetTracks int

Number of tracks in the pattern to skip.

writeOffsetLines int

Number of lines in the pattern to skip.

maxTracks int?

Maximum number of tracks to write.

maxLines int?

Maximum number of lines to write.

Returns

int

Number of events written.

Remarks

Exceptions

ArgumentOutOfRangeException

Thrown if any offset or size parameter is negative.

ArgumentException

Thrown if buffer length doesn't match bufferTracks * bufferLines.

ArgumentNullException

Thrown if buffer is null.