CsoundUnity 4.0.0-alpha.3
Loading...
Searching...
No Matches
Csound.Unity.CsoundUnityBridge Class Reference

The managed wrapper around one native Csound instance: it creates Csound, compiles the csd, and exposes the calls CsoundUnity needs — channels, score events, the spin and spout buffers, function tables and teardown. One bridge belongs to one CsoundUnity. More...

Inheritance diagram for Csound.Unity.CsoundUnityBridge:
Csound.Unity.CsoundWorker

Classes

class  OpcodeArgumentTypes
 Holds the output type string, input type string, and flags for a Csound opcode. More...
class  ChannelInfo
 Describes a single Csound software-bus channel: its name, data type, direction, and optional control hints. More...
class  ChannelHints
 This structure holds the parameter hints for control channels. More...

Public Types

enum  ChannelBehavior { None = 0 , Integer = 1 , Linear = 2 , Exponential = 3 }
 Defines the interpolation behavior of a Csound control channel. More...
enum  ChannelType {
  None = 0 , Control = 1 , Audio = 2 , String = 3 ,
  Pvs = 4 , Var = 5 , Array = 6
}
 Identifies the data type carried by a Csound software-bus channel. More...
enum  ChannelDirection { Input = 1 , Output = 2 }
 Flags indicating whether a Csound channel is readable (input), writable (output), or both. More...

Public Member Functions

CsoundArrayChannelStatus InitializeArrayChannel (string name, CsoundArrayChannelType type, params int[] sizes)
 Initialize an array channel, or validate an existing channel without resizing it. May allocate and briefly suspend Unity audio; never call from a performance callback. A subclass driving its own performance thread must stop that thread before initialization.
CsoundArrayChannelStatus GetArrayChannelInfo (string name, int[] sizes, out CsoundArrayChannelInfo info)
 Read array metadata and axis sizes into a reusable buffer; no channel is created.
CsoundArrayChannelStatus GetArrayChannel (string name, MYFLT[] destination, out int length)
 Copy a complete numeric array to a flat buffer; length reports required capacity on BufferTooSmall.
CsoundArrayChannelStatus GetArrayChannel (string name, MYFLT[] destination, int[] sizes, out CsoundArrayChannelInfo info)
 Read numeric values, axis sizes and matching metadata atomically; no partial copy occurs.
CsoundArrayChannelStatus SetArrayChannel (string name, MYFLT[] source)
 Write exactly the current number of numeric elements without creating or resizing the channel.
CsoundArrayChannelStatus GetAudioArrayChannel (string name, MYFLT[] destination, out int length)
 Read a[] blocks in element order, ksmps samples per element; length reports required samples.
CsoundArrayChannelStatus GetAudioArrayChannel (string name, MYFLT[] destination, int[] sizes, out CsoundArrayChannelInfo info)
 Read all audio blocks and their matching shape; no buffer changes on BufferTooSmall.
CsoundArrayChannelStatus SetAudioArrayChannel (string name, MYFLT[] source)
 Replace all a[] blocks; source must contain exactly ElementCount × ksmps samples.
 CsoundUnityBridge ()
 Default parameterless constructor. Creates an uninitialised bridge instance.
 CsoundUnityBridge (string csdFile, List< EnvironmentSettings > environmentSettings, float audioRate, float controlRate, int ksmps=0)
 The CsoundUnityBridge constructor sets up the Csound Global Environment Variables set by the user. Then it creates an instance of Csound and compiles the full csdFile passed as a string. Then it starts Csound.
void EnqueueMidiMessage (byte[] data)
 Enqueues a raw MIDI message to be delivered to Csound on the next ksmps cycle. Can be called from any thread.
int LoadPlugins (string dir)
 Loads all Csound plugins found in the specified directory. Not available on iOS; use the conditional compilation guard before calling.
int GetVersion ()
 Returns the Csound library version as an integer (e.g. 6180 for version 6.18.0). On WebGL, available after initialization completes.
virtual bool Destroy ()
 Frees the native Csound instance and its message buffer. Idempotent.
virtual bool Reset ()
 Returns the Csound instance to its pre-compilation state, keeping it alive and reusable: the orchestra and control channels are gone afterwards. Compile again before performing, and set the channel values again. Keeps the host sample rate, ksmps, audio IO and message buffer.
bool CompiledWithoutError ()
 Returns true if the CSD compiled without errors; equivalent to reading CompiledOk.
int CompileOrc (string orchStr)
 Compiles the given Csound orchestra string at runtime, adding new instruments and UDOs to the running instance.
int Start ()
 Starts a compiled orchestra after reset and enables audio callbacks. Call CompileOrc first. A running instance is left running without starting it twice.
int PerformKsmps ()
 Advances Csound by one ksmps block, filling the spout buffer, and caches the spout/spin pointers on the first successful call.
MYFLT Get0dbfs ()
 Returns the 0 dBFS value (full-scale amplitude) for this Csound instance, as set by the 0dbfs header statement.
long GetCurrentTimeSamples ()
 Returns the current performance position in samples from the start of the performance.
void SendScoreEvent (string scoreEvent)
 Sends a score event string to Csound (e.g. "i 1 0 1 0.5 440") for immediate processing.
void RewindScore ()
 Rewinds the score to the beginning, allowing the performance to repeat from time zero.
void CsoundSetScoreOffsetSeconds (MYFLT value)
 Sets the score time offset in seconds, causing performance to start from the given point in the score.
void SetChannel (string channel, MYFLT value)
 Sets the value of a named Csound control channel.
void SetStringChannel (string channel, string value)
 Sets the value of a named Csound string channel.
void SetAudioChannel (string name, MYFLT[] audio)
 Writes a ksmps-length audio buffer into the named Csound audio channel. Only the first ksmps samples are used; excess samples are ignored. A shorter array is padded with silence; an empty array clears the channel.
MYFLT[] GetAudioChannel (string name)
 Reads the named Csound audio channel into a newly allocated array of length ksmps. Use the zero-allocation overload on hot audio-thread paths to avoid GC pressure.
void GetAudioChannel (string name, MYFLT[] dest)
 Zero-allocation overload: reads the named audio channel directly into dest without any managed or native heap allocation. Use this on hot audio-thread paths to avoid GC pressure.
string GetStringChannel (string name)
 Reads the current value of the named Csound string channel.
int TableLength (int table)
 Returns the length of a function table (not including the guard point), or -1 if the table does not exist.
MYFLT GetTable (int table, int index)
 Returns the value of a slot in a function table. The table number and index are assumed to be valid.
void SetTable (int table, int index, MYFLT value)
 Sets the value of a slot in a function table. The table number and index are assumed to be valid.
void TableCopyOut (int table, out MYFLT[] dest)
 Copies the contents of a function table into a supplied array. The table number is assumed to be valid, and the destination will be resized to fit all table contents.
void TableCopyIn (int table, MYFLT[] source)
 Copies the contents of an array into a given function table. The table number is assumed to be valid, and the table must have sufficient space to receive all array contents.
int GetTable (out MYFLT[] tableValues, int numTable)
 Stores values of function table numTable in tableValues , and returns the table length (not including the guard point). If the table does not exist, tableValues is set to null and -1 is returned.
int GetTableArgs (out MYFLT[] args, int index)
 Stores the arguments used to generate function table index in args , and returns the number of arguments used. If the table does not exist, args is set to null and -1 is returned.
MYFLT GetSr ()
 Returns the audio sample rate (sr) of the current Csound instance.
MYFLT GetKr ()
 Returns the control rate (kr) of the current Csound instance.
uint GetKsmps ()
 Returns the number of samples per control period (ksmps). Returns the cached value when available (set after csoundStart) to avoid a P/Invoke on the hot path.
MYFLT GetSpoutSample (int frame, int channel)
 Get a sample from Csound's audio output buffer. Hot path — uses cached spout pointer and channel count; zero allocation. The pointer is fetched lazily because csoundGetSpout may return NULL before the first csoundPerformKsmps.
void AddSpinSample (int frame, int channel, MYFLT sample)
 Add a value to a sample in Csound's audio input buffer. Hot path — uses cached spin pointer and channel count; zero allocation.
void SetSpinSample (int frame, int channel, MYFLT sample)
 Set a sample in Csound's audio input buffer. Hot path — uses cached spin pointer and channel count; zero allocation.
void ClearSpin ()
 Clears the input buffer (spin).
MYFLT[] GetSpin ()
 Returns the Csound audio input working buffer (spin) as a MYFLT array. Enables external software to write audio into Csound before calling csoundPerformKsmps.
MYFLT[] GetSpout ()
 Returns the Csound audio output working buffer (spout) as a MYFLT array. Enables external software to read audio from Csound after calling csoundPerformKsmps.
MYFLT GetChannel (string channel)
 Returns the current value of the named Csound control channel. On WebGL returns the last-known cached value (0 until the first async read completes) and automatically schedules a non-blocking refresh via the callback-based overload.
uint GetNchnlsInput ()
 Get number of input channels.
uint GetNchnls ()
 Get number of output channels.
int GetCsoundMessageCount ()
 Returns the number of pending messages in Csound's message buffer.
string GetCsoundMessage ()
 Retrieves and removes the first pending message from Csound's message buffer.
IDictionary< string, ChannelInfo > GetChannelList ()
 Provides a dictionary of all currently defined channels resulting from compilation of an orchestra containing channel definitions. Entries, keyed by name, are polymorphically assigned to their correct data type: control, audio, string, pvc. Used internally to initialize channel contents.
string GetEnv (string key)
 Gets a string value from csound's environment values. Meaningful values include the contents of Windows' OS environment values such as SFDIR or SADIR for path name defaults.
int SetGlobalEnv (string name, string value)
 Set the global value of environment variable 'name' to 'value', or delete variable if 'value' is NULL. It is not safe to call this function while any Csound instances are active. See https://csound.com/docs/manual/CommandEnvironment.html for a list of the variables that can be used.
CsoundPvsChannelStatus InitializePvsChannel (string name, int fftSize, int overlap, int windowSize, int windowType=1, CsoundPvsFormat format=CsoundPvsFormat.AmplitudeFrequency)
 Create or verify a fixed-layout, non-sliding PVS channel. Setup only; may briefly suspend Unity audio.
CsoundPvsChannelStatus GetPvsChannelInfo (string name, out CsoundPvsChannelInfo info)
 Read PVS layout and frame counter without creating a channel.
CsoundPvsChannelStatus GetPvsChannel (string name, float[] destination, out CsoundPvsChannelInfo info)
 Read one complete N+2 float frame and matching metadata; unused trailing entries are unchanged.
CsoundPvsChannelStatus SetPvsChannel (string name, float[] source)
 Write exactly N+2 floats and advance the destination frame counter once on success.
CsoundPvsChannelStatus SetPvsChannel (string name, float[] source, CsoundPvsChannelInfo frame)
 Write a snapshot to a channel with the same layout, preserving the supplied frame counter.
CsoundArrayChannelStatus GetStringArrayChannel (string name, string[] destination, out int length)
 Read S[] values into a reusable container; changed strings allocate and unused trailing entries remain unchanged.
CsoundArrayChannelStatus GetStringArrayChannel (string name, string[] destination, int[] sizes, out CsoundArrayChannelInfo info)
 Read string data and matching axis sizes atomically; UTF-8 decoding happens outside the native lock.
CsoundArrayChannelStatus SetStringArrayChannel (string name, string[] source)
 Replace every S[] element; null becomes empty, embedded null characters are rejected. Not for audio callbacks.
void TableCopyOutAsync (int table, out MYFLT[] dest)
 Queues a table read. The returned array is filled during a later performance cycle.
CsoundTableCopySubmission TableCopyOutAsync (int table, out MYFLT[] dest, out CsoundTableCopyRequest request)
 Queues a table read and returns a request to poll. The destination is valid on success.
void TableCopyInAsync (int table, MYFLT[] source)
 Queues a copy of the source samples into the table, preserving any remaining entries.
CsoundTableCopySubmission TableCopyInAsync (int table, MYFLT[] source, out CsoundTableCopyRequest request)
 Queues a table write and returns a request to poll, or null if it could not be queued.

Static Public Member Functions

static string GetMessageText (IntPtr message)
 Converts a native char pointer returned by Csound into a managed string.

Public Attributes

IntPtr csound
 The raw Csound instance handle used for all native P/Invoke calls.
volatile bool Muted
 Mirrors the owning CsoundUnity.mute flag so that the audio paths which read spout without going through ProcessBlock — IAudioGenerator and RootOutput — can honour it. ProcessBlock checks mute directly and does not use this.
volatile bool Paused
 Mirrors the owning CsoundUnity.pauseProcessing flag, for the same reason as Muted. When set, those paths skip PerformKsmps entirely and output silence.
volatile int StartupFadeFrames
 Length of the startup fade in output frames, 0 when off. Pushed by CsoundUnity from its fadeInSeconds; lives here for the same reason OutputGain does, so the paths that read spout directly — IAudioGenerator and RootOutput — cannot end up fading differently from each other or from OnAudioFilterRead.
volatile float LoudThreshold = float.PositiveInfinity
 Sample value at which an audio path silences a sample and reports a runaway. Pushed by CsoundUnity from its loudWarningThreshold, and PositiveInfinity when that check is off, which still catches a sample that is not a number. Here for the same reason StartupFadeFrames is: so the paths that read spout directly guard the output the way OnAudioFilterRead does.
volatile float SpatialBlend
 How far the AudioSource is spatialized, 0 to 1, pushed by CsoundUnity every frame. The IAudioGenerator path needs it because Unity sums a generator's channels for a spatialized source, so a mono bed written into every channel has to be divided by what that costs.
volatile float LoudPeak
 The largest sample an audio path had to silence in its last block, 0 when nothing tripped and infinity when what tripped it was not a number. Written on the audio thread and cleared by its reader, so the warning is printed on the thread that is allowed to print.

Static Public Attributes

static int WebGLVariation = 3
 Which @csound/browser variation to create: 0 single threaded, 1 worker with a SharedArrayBuffer, 2 worker with a MessagePort. Anything higher clamps to the last. Read only in a WebGL player, and declared outside the guard so that code setting it compiles on every platform.
const int DestroyedSentinel = int.MinValue
 Returned by PerformKsmps when the instance has already been destroyed. Distinct from 0 (running) and from every positive value (score ended), so that a caller testing > 0 cannot mistake a freed instance for a finished score.

Protected Member Functions

 CsoundUnityBridge (float sampleRate, int ksmps)
 Records the host settings for a derived bridge that creates its own instance.

Static Protected Member Functions

static string UserOpcodeDir (List< EnvironmentSettings > environmentSettings)
 The plugin opcode folder the user asked for in the environment settings, or null when there is none for this platform. Csound takes the folder from the argument of csoundCreate, which wins over OPCODE7DIR64, so a setting that is only exported as an environment variable would be ignored.
static IntPtr CreateCsound (float sampleRate, int ksmps=0, string opcodeDir=null)
 Creates a Csound instance with the setup every path in the package needs: a message buffer, Csound's own audio I/O disabled, and the host's rates. The caller compiles the csd and calls csoundStart.

Package Functions

bool TryEnterAudio ()
 Claims this bridge for the duration of one audio callback. Returns false when the instance is being destroyed, reset or awaiting start, and the caller must produce silence without touching the bridge at all.
void ExitAudio ()
 Releases the claim taken by TryEnterAudio. Clears the claim id only if it is this thread's, so a second caller cannot erase the id of a thread that is still inside.
int StartWithSetup (Action prepareAudio)

Static Package Functions

static IDictionary< string, ChannelInfo > GetChannelList (IntPtr csoundHandle)
 Lists the channels allocated on a raw Csound handle. CsoundWorker.ScanCsdForChannels calls it for the temporary instance it manages, and GetChannelList() for this one.
static string CharPtr2String (IntPtr pString)
 Converts the char* for an ascii "c" string represented by the provided IntPtr into a managed string. Usually used for values returning a const char * from a csound routine. Using this method avoids pInvoke's default automatic attempted deletion of the returned char[] when string is expressly given as a marshalling type.

Properties

bool CompiledOk [get]
 Returns true while this instance holds a successfully compiled orchestra.
float OutputGain [get]
 Gain the audio paths that read spout directly should apply to their output: 0 while muted or paused, 1 otherwise. Exists so the two of them — IAudioGenerator and RootOutput — cannot drift apart on what "silent" means.

Detailed Description

The managed wrapper around one native Csound instance: it creates Csound, compiles the csd, and exposes the calls CsoundUnity needs — channels, score events, the spin and spout buffers, function tables and teardown. One bridge belongs to one CsoundUnity.

Member Enumeration Documentation

◆ ChannelBehavior

Defines the interpolation behavior of a Csound control channel.

Enumerator
None 

No specific interpolation behavior.

Integer 

The channel value is an integer.

Linear 

The channel value is interpolated linearly between min and max.

Exponential 

The channel value is interpolated exponentially between min and max.

◆ ChannelDirection

Flags indicating whether a Csound channel is readable (input), writable (output), or both.

Enumerator
Input 

The channel is written by the host and read by Csound.

Output 

The channel is written by Csound and read by the host.

◆ ChannelType

Identifies the data type carried by a Csound software-bus channel.

Enumerator
None 

No type; used only as an error return value.

Control 

k-rate (control) channel carrying a single floating-point value.

Audio 

a-rate (audio) channel carrying a ksmps-length sample buffer.

String 

String channel.

Pvs 

Phase vocoder streaming (pvs) channel.

Var 

Generic variable channel.

Array 

Array channel; element type and shape are separate metadata.

Constructor & Destructor Documentation

◆ CsoundUnityBridge() [1/3]

Csound.Unity.CsoundUnityBridge.CsoundUnityBridge ( )
inline

Default parameterless constructor. Creates an uninitialised bridge instance.

◆ CsoundUnityBridge() [2/3]

Csound.Unity.CsoundUnityBridge.CsoundUnityBridge ( float sampleRate,
int ksmps )
inlineprotected

Records the host settings for a derived bridge that creates its own instance.

Parameters
sampleRateThe host sample rate in Hz, captured by the caller.
ksmpsHost block size, or zero to use the orchestra's own ksmps.

◆ CsoundUnityBridge() [3/3]

Csound.Unity.CsoundUnityBridge.CsoundUnityBridge ( string csdFile,
List< EnvironmentSettings > environmentSettings,
float audioRate,
float controlRate,
int ksmps = 0 )
inline

The CsoundUnityBridge constructor sets up the Csound Global Environment Variables set by the user. Then it creates an instance of Csound and compiles the full csdFile passed as a string. Then it starts Csound.

Parameters
csdFileThe Csound (.csd) file content as a string
environmentSettingsA list of the Csound Environments settings defined by the user
audioRateSample rate in Hz, which overrides the csd's sr.
controlRateControl rate in Hz, which overrides the csd's kr.
ksmpsSamples per control period. 0 leaves the csd's own value.

Member Function Documentation

◆ AddSpinSample()

void Csound.Unity.CsoundUnityBridge.AddSpinSample ( int frame,
int channel,
MYFLT sample )
inline

Add a value to a sample in Csound's audio input buffer. Hot path — uses cached spin pointer and channel count; zero allocation.

Parameters
frameFrame inside the current block, 0 to ksmps - 1.
channelInput channel, 0-based.
sampleThe value to add to what is already there, in Csound units.

◆ CharPtr2String()

string Csound.Unity.CsoundUnityBridge.CharPtr2String ( IntPtr pString)
inlinestaticpackage

Converts the char* for an ascii "c" string represented by the provided IntPtr into a managed string. Usually used for values returning a const char * from a csound routine. Using this method avoids pInvoke's default automatic attempted deletion of the returned char[] when string is expressly given as a marshalling type.

◆ ClearSpin()

void Csound.Unity.CsoundUnityBridge.ClearSpin ( )
inline

Clears the input buffer (spin).

◆ CompiledWithoutError()

bool Csound.Unity.CsoundUnityBridge.CompiledWithoutError ( )
inline

Returns true if the CSD compiled without errors; equivalent to reading CompiledOk.

Returns
true when compilation succeeded.

◆ CompileOrc()

int Csound.Unity.CsoundUnityBridge.CompileOrc ( string orchStr)
inline

Compiles the given Csound orchestra string at runtime, adding new instruments and UDOs to the running instance.

Parameters
orchStrA valid Csound orchestra string to compile.

After reset, compilation leaves audio suspended until an explicit Start. On a running engine, updates the orchestra without stopping its performance.

Returns
Zero on success, or a non-zero error code on failure.

◆ CreateCsound()

IntPtr Csound.Unity.CsoundUnityBridge.CreateCsound ( float sampleRate,
int ksmps = 0,
string opcodeDir = null )
inlinestaticprotected

Creates a Csound instance with the setup every path in the package needs: a message buffer, Csound's own audio I/O disabled, and the host's rates. The caller compiles the csd and calls csoundStart.

Parameters
sampleRateSample rate in Hz, which overrides the csd's sr.
ksmpsSamples per control period. 0 leaves the csd's own value.
opcodeDirDirectory to load plugin opcodes from, or null for the default.
Returns
The Csound handle, or IntPtr.Zero when creation failed.

◆ CsoundSetScoreOffsetSeconds()

void Csound.Unity.CsoundUnityBridge.CsoundSetScoreOffsetSeconds ( MYFLT value)
inline

Sets the score time offset in seconds, causing performance to start from the given point in the score.

Parameters
valueScore offset in seconds.

◆ Destroy()

virtual bool Csound.Unity.CsoundUnityBridge.Destroy ( )
inlinevirtual

Frees the native Csound instance and its message buffer. Idempotent.

Safe to call from any thread but the audio one, at any time: before anything is freed, CloseToAudioThread shuts the bridge to new audio-thread callers and waits for the ones already inside. That wait is capped — see its doc for what crossing the cap means. A call from the audio thread itself is refused below, with an error. A subclass that drives Csound from a thread of its own has to join it before calling this — see CsoundWorker.

The handle and the cached pointers are cleared before anything is freed, so that a caller that got in anyway hits the == IntPtr.Zero checks in the hot path rather than reading released memory. Keep both: the handshake stops new callers, the nulls cover the one already inside.

Returns
true when the instance is gone — freed here, or already freed by an earlier call. false when called from an audio callback or an array-channel operation did not finish within the teardown wait. Keep the bridge reference and retry from the main thread: the native instance is retained rather than freed beneath an active caller.

Reimplemented in Csound.Unity.CsoundWorker.

◆ EnqueueMidiMessage()

void Csound.Unity.CsoundUnityBridge.EnqueueMidiMessage ( byte[] data)
inline

Enqueues a raw MIDI message to be delivered to Csound on the next ksmps cycle. Can be called from any thread.

Parameters
data1–3 MIDI bytes (status [, data1 [, data2]])

◆ ExitAudio()

void Csound.Unity.CsoundUnityBridge.ExitAudio ( )
inlinepackage

Releases the claim taken by TryEnterAudio. Clears the claim id only if it is this thread's, so a second caller cannot erase the id of a thread that is still inside.

◆ Get0dbfs()

MYFLT Csound.Unity.CsoundUnityBridge.Get0dbfs ( )
inline

Returns the 0 dBFS value (full-scale amplitude) for this Csound instance, as set by the 0dbfs header statement.

Returns
The 0 dBFS amplitude value, or 0 if this bridge has already been freed. Callers divide by this, so guard the divisor: 1 / 0 is Infinity, not silence.

◆ GetArrayChannel() [1/2]

CsoundArrayChannelStatus Csound.Unity.CsoundUnityBridge.GetArrayChannel ( string name,
MYFLT[] destination,
int[] sizes,
out CsoundArrayChannelInfo info )
inline

Read numeric values, axis sizes and matching metadata atomically; no partial copy occurs.

Parameters
nameThe channel name, as the orchestra declares it.
destinationFilled with the elements, in element order.
sizesFilled with the size of each axis.
infoFilled with the metadata the values were read with.
Returns
What happened, including why nothing was copied.

◆ GetArrayChannel() [2/2]

CsoundArrayChannelStatus Csound.Unity.CsoundUnityBridge.GetArrayChannel ( string name,
MYFLT[] destination,
out int length )
inline

Copy a complete numeric array to a flat buffer; length reports required capacity on BufferTooSmall.

Parameters
nameThe channel name, as the orchestra declares it.
destinationFilled with the elements, in element order.
lengthHow many elements were copied, or how many the buffer needs on BufferTooSmall.
Returns
What happened, including why nothing was copied.

◆ GetArrayChannelInfo()

CsoundArrayChannelStatus Csound.Unity.CsoundUnityBridge.GetArrayChannelInfo ( string name,
int[] sizes,
out CsoundArrayChannelInfo info )
inline

Read array metadata and axis sizes into a reusable buffer; no channel is created.

Parameters
nameThe channel name, as the orchestra declares it.
sizesFilled with the size of each axis. Reused between calls.
infoFilled with the element type, the axis count and the element count.
Returns
What happened, including why nothing was copied.

◆ GetAudioArrayChannel() [1/2]

CsoundArrayChannelStatus Csound.Unity.CsoundUnityBridge.GetAudioArrayChannel ( string name,
MYFLT[] destination,
int[] sizes,
out CsoundArrayChannelInfo info )
inline

Read all audio blocks and their matching shape; no buffer changes on BufferTooSmall.

Parameters
nameThe channel name, as the orchestra declares it.
destinationFilled with the blocks, in element order, ksmps samples each.
sizesFilled with the size of each axis.
infoFilled with the metadata the samples were read with.
Returns
What happened, including why nothing was copied.

◆ GetAudioArrayChannel() [2/2]

CsoundArrayChannelStatus Csound.Unity.CsoundUnityBridge.GetAudioArrayChannel ( string name,
MYFLT[] destination,
out int length )
inline

Read a[] blocks in element order, ksmps samples per element; length reports required samples.

Parameters
nameThe channel name, as the orchestra declares it.
destinationFilled with the blocks, in element order, ksmps samples each.
lengthHow many samples were copied, or how many the buffer needs on BufferTooSmall.
Returns
What happened, including why nothing was copied.

◆ GetAudioChannel() [1/2]

MYFLT[] Csound.Unity.CsoundUnityBridge.GetAudioChannel ( string name)
inline

Reads the named Csound audio channel into a newly allocated array of length ksmps. Use the zero-allocation overload on hot audio-thread paths to avoid GC pressure.

Parameters
nameThe name of the audio channel.
Returns
A new MYFLT array containing the channel's current audio data.

◆ GetAudioChannel() [2/2]

void Csound.Unity.CsoundUnityBridge.GetAudioChannel ( string name,
MYFLT[] dest )
inline

Zero-allocation overload: reads the named audio channel directly into dest without any managed or native heap allocation. Use this on hot audio-thread paths to avoid GC pressure.

Parameters
nameThe name of the audio channel.
destBuffer with room for at least ksmps samples. Null or empty arrays are ignored.
Exceptions
ArgumentExceptionA non-empty destination is shorter than ksmps.

◆ GetChannel()

MYFLT Csound.Unity.CsoundUnityBridge.GetChannel ( string channel)
inline

Returns the current value of the named Csound control channel. On WebGL returns the last-known cached value (0 until the first async read completes) and automatically schedules a non-blocking refresh via the callback-based overload.

Parameters
channelThe name of the control channel.
Returns
The channel's current floating-point value.

◆ GetChannelList() [1/2]

IDictionary< string, ChannelInfo > Csound.Unity.CsoundUnityBridge.GetChannelList ( )
inline

Provides a dictionary of all currently defined channels resulting from compilation of an orchestra containing channel definitions. Entries, keyed by name, are polymorphically assigned to their correct data type: control, audio, string, pvc. Used internally to initialize channel contents.

Returns
a dictionary of all currently defined channels keyed by their name to its ChannelInfo

◆ GetChannelList() [2/2]

IDictionary< string, ChannelInfo > Csound.Unity.CsoundUnityBridge.GetChannelList ( IntPtr csoundHandle)
inlinestaticpackage

Lists the channels allocated on a raw Csound handle. CsoundWorker.ScanCsdForChannels calls it for the temporary instance it manages, and GetChannelList() for this one.

Parameters
csoundHandleThe raw Csound instance pointer.
Returns
A sorted dictionary of all currently defined channels keyed by name.

◆ GetCsoundMessage()

string Csound.Unity.CsoundUnityBridge.GetCsoundMessage ( )
inline

Retrieves and removes the first pending message from Csound's message buffer.

Returns
The message text, or an empty string if the buffer is empty.

◆ GetCsoundMessageCount()

int Csound.Unity.CsoundUnityBridge.GetCsoundMessageCount ( )
inline

Returns the number of pending messages in Csound's message buffer.

Returns
Number of unread messages.

◆ GetCurrentTimeSamples()

long Csound.Unity.CsoundUnityBridge.GetCurrentTimeSamples ( )
inline

Returns the current performance position in samples from the start of the performance.

Returns
Number of samples elapsed since the performance began.

◆ GetEnv()

string Csound.Unity.CsoundUnityBridge.GetEnv ( string key)
inline

Gets a string value from csound's environment values. Meaningful values include the contents of Windows' OS environment values such as SFDIR or SADIR for path name defaults.

Parameters
keythe name of the Environment Variable to get
Returns
the corresponding value or an empty string if no such key exists

◆ GetKr()

MYFLT Csound.Unity.CsoundUnityBridge.GetKr ( )
inline

Returns the control rate (kr) of the current Csound instance.

Returns
Control rate in Hz.

◆ GetKsmps()

uint Csound.Unity.CsoundUnityBridge.GetKsmps ( )
inline

Returns the number of samples per control period (ksmps). Returns the cached value when available (set after csoundStart) to avoid a P/Invoke on the hot path.

Returns
Samples per control block.

◆ GetMessageText()

string Csound.Unity.CsoundUnityBridge.GetMessageText ( IntPtr message)
inlinestatic

Converts a native char pointer returned by Csound into a managed string.

Parameters
messageAn unmanaged pointer to a null-terminated ASCII string.
Returns
The corresponding managed string, or an empty string for a null pointer.

◆ GetNchnls()

uint Csound.Unity.CsoundUnityBridge.GetNchnls ( )
inline

Get number of output channels.

Returns
The csd's nchnls, or 0 once the instance is gone.

◆ GetNchnlsInput()

uint Csound.Unity.CsoundUnityBridge.GetNchnlsInput ( )
inline

Get number of input channels.

Returns
The csd's nchnls_i, or 0 once the instance is gone.

◆ GetPvsChannel()

CsoundPvsChannelStatus Csound.Unity.CsoundUnityBridge.GetPvsChannel ( string name,
float[] destination,
out CsoundPvsChannelInfo info )
inline

Read one complete N+2 float frame and matching metadata; unused trailing entries are unchanged.

Parameters
nameThe channel name, as the orchestra declares it.
destinationFilled with one frame of fftSize + 2 floats.
infoFilled with the layout and the counter of the frame that was read.
Returns
What happened, including why nothing was copied.

◆ GetPvsChannelInfo()

CsoundPvsChannelStatus Csound.Unity.CsoundUnityBridge.GetPvsChannelInfo ( string name,
out CsoundPvsChannelInfo info )
inline

Read PVS layout and frame counter without creating a channel.

Parameters
nameThe channel name, as the orchestra declares it.
infoFilled with the layout and the frame counter.
Returns
What happened, including why nothing was copied.

◆ GetSpin()

MYFLT[] Csound.Unity.CsoundUnityBridge.GetSpin ( )
inline

Returns the Csound audio input working buffer (spin) as a MYFLT array. Enables external software to write audio into Csound before calling csoundPerformKsmps.

Returns
a MYFLT array representing the Csound audio input buffer

◆ GetSpout()

MYFLT[] Csound.Unity.CsoundUnityBridge.GetSpout ( )
inline

Returns the Csound audio output working buffer (spout) as a MYFLT array. Enables external software to read audio from Csound after calling csoundPerformKsmps.

Returns
a MYFLT array representing the Csound audio output buffer

◆ GetSpoutSample()

MYFLT Csound.Unity.CsoundUnityBridge.GetSpoutSample ( int frame,
int channel )
inline

Get a sample from Csound's audio output buffer. Hot path — uses cached spout pointer and channel count; zero allocation. The pointer is fetched lazily because csoundGetSpout may return NULL before the first csoundPerformKsmps.

Parameters
frameFrame inside the current block, 0 to ksmps - 1.
channelOutput channel, 0-based.
Returns
The sample in Csound units, or 0 while no output buffer is available yet.

◆ GetSr()

MYFLT Csound.Unity.CsoundUnityBridge.GetSr ( )
inline

Returns the audio sample rate (sr) of the current Csound instance.

Returns
Sample rate in Hz.

◆ GetStringArrayChannel() [1/2]

CsoundArrayChannelStatus Csound.Unity.CsoundUnityBridge.GetStringArrayChannel ( string name,
string[] destination,
int[] sizes,
out CsoundArrayChannelInfo info )
inline

Read string data and matching axis sizes atomically; UTF-8 decoding happens outside the native lock.

Parameters
nameThe channel name, as the orchestra declares it.
destinationFilled with the elements, in element order. Reused between calls.
sizesFilled with the size of each axis.
infoFilled with the metadata the values were read with.
Returns
What happened, including why nothing was copied.

◆ GetStringArrayChannel() [2/2]

CsoundArrayChannelStatus Csound.Unity.CsoundUnityBridge.GetStringArrayChannel ( string name,
string[] destination,
out int length )
inline

Read S[] values into a reusable container; changed strings allocate and unused trailing entries remain unchanged.

Parameters
nameThe channel name, as the orchestra declares it.
destinationFilled with the elements, in element order. Reused between calls.
lengthHow many elements were copied, or how many the buffer needs on BufferTooSmall.
Returns
What happened, including why nothing was copied.

◆ GetStringChannel()

string Csound.Unity.CsoundUnityBridge.GetStringChannel ( string name)
inline

Reads the current value of the named Csound string channel.

Parameters
nameThe name of the string channel.
Returns
The channel's current string value, or an empty string on WebGL, if the channel or instance is unavailable, or if another operation holds the bridge's channel gate. A failed read and a valid empty value have the same result.

◆ GetTable() [1/2]

MYFLT Csound.Unity.CsoundUnityBridge.GetTable ( int table,
int index )
inline

Returns the value of a slot in a function table. The table number and index are assumed to be valid.

Parameters
tableThe function table number.
indexZero-based index of the slot to read.
Returns
The value at the specified slot, or 0 if the table or index is out of range.

◆ GetTable() [2/2]

int Csound.Unity.CsoundUnityBridge.GetTable ( out MYFLT[] tableValues,
int numTable )
inline

Stores values of function table numTable in tableValues , and returns the table length (not including the guard point). If the table does not exist, tableValues is set to null and -1 is returned.

Parameters
tableValuesOutput array populated with the table's values.
numTableThe function table number to read.
Returns
The length of the table, or -1 if the table does not exist.

◆ GetTableArgs()

int Csound.Unity.CsoundUnityBridge.GetTableArgs ( out MYFLT[] args,
int index )
inline

Stores the arguments used to generate function table index in args , and returns the number of arguments used. If the table does not exist, args is set to null and -1 is returned.

The argument list starts with the GEN number followed by its parameters; e.g. f 1 0 1024 10 1 0.5 yields {10.0, 1.0, 0.5}.

Parameters
argsOutput array populated with the GEN generator arguments.
indexThe function table number.
Returns
The number of arguments, or -1 if the table does not exist.

◆ GetVersion()

int Csound.Unity.CsoundUnityBridge.GetVersion ( )
inline

Returns the Csound library version as an integer (e.g. 6180 for version 6.18.0). On WebGL, available after initialization completes.

Returns
Csound version number.

◆ InitializeArrayChannel()

CsoundArrayChannelStatus Csound.Unity.CsoundUnityBridge.InitializeArrayChannel ( string name,
CsoundArrayChannelType type,
params int[] sizes )
inline

Initialize an array channel, or validate an existing channel without resizing it. May allocate and briefly suspend Unity audio; never call from a performance callback. A subclass driving its own performance thread must stop that thread before initialization.

Parameters
nameThe channel name, as the orchestra declares it.
typeThe element type the channel holds.
sizesThe size of each axis. One value for a vector, one per axis for an array.
Returns
What happened, including why nothing was copied.

◆ InitializePvsChannel()

CsoundPvsChannelStatus Csound.Unity.CsoundUnityBridge.InitializePvsChannel ( string name,
int fftSize,
int overlap,
int windowSize,
int windowType = 1,
CsoundPvsFormat format = CsoundPvsFormat::AmplitudeFrequency )
inline

Create or verify a fixed-layout, non-sliding PVS channel. Setup only; may briefly suspend Unity audio.

Parameters
nameThe channel name, as the orchestra declares it.
fftSizeThe analysis size, which gives frames of fftSize + 2 floats.
overlapThe hop between frames, in samples.
windowSizeThe analysis window length, in samples.
windowTypeThe window shape, as the pvs opcodes number them.
formatWhat a frame holds: amplitude and frequency, or amplitude and phase.
Returns
What happened, including why nothing was copied.

◆ LoadPlugins()

int Csound.Unity.CsoundUnityBridge.LoadPlugins ( string dir)
inline

Loads all Csound plugins found in the specified directory. Not available on iOS; use the conditional compilation guard before calling.

Parameters
dirPath to the directory containing Csound plugin libraries.
Returns
Zero on success, or a non-zero error code on failure.

◆ PerformKsmps()

int Csound.Unity.CsoundUnityBridge.PerformKsmps ( )
inline

Advances Csound by one ksmps block, filling the spout buffer, and caches the spout/spin pointers on the first successful call.

Returns

Zero while the performance is ongoing, a positive value when the score has ended, or DestroyedSentinel when this bridge has already been freed. Test for score end with > 0, never != 0 — the latter reads a freed instance as a finished score, which latches performanceFinished and, with domain reload disabled, carries into the next Play session.

> 0 loses nothing: csound.h documents csoundPerformKsmps as returning "false during performance, and true when performance is finished" and defines no negative error return, so there is no error code for this to swallow. CsoundWorker exits its loop on any nonzero value, including the destroyed-instance sentinel.

◆ Reset()

virtual bool Csound.Unity.CsoundUnityBridge.Reset ( )
inlinevirtual

Returns the Csound instance to its pre-compilation state, keeping it alive and reusable: the orchestra and control channels are gone afterwards. Compile again before performing, and set the channel values again. Keeps the host sample rate, ksmps, audio IO and message buffer.

Audio callbacks are suspended during reset and remain silent while waiting for a new orchestra. Call CompileOrc to compile it, then Start to start performance explicitly. Compilation alone does not resume audio. Expect a gap in audio. A subclass that drives Csound from a thread of its own has to stop that thread first: the audio-thread handshake does not see it, the way Destroy joins before freeing.

Returns
True when reset succeeded; false if the instance is unavailable, the call comes from its audio callback, or the callback could not be suspended within 200 ms. A refused reset preserves engine state, but waiting for a callback can silence audio for up to 200 ms. Unavailable on WebGL.

Reimplemented in Csound.Unity.CsoundWorker.

◆ RewindScore()

void Csound.Unity.CsoundUnityBridge.RewindScore ( )
inline

Rewinds the score to the beginning, allowing the performance to repeat from time zero.

◆ SendScoreEvent()

void Csound.Unity.CsoundUnityBridge.SendScoreEvent ( string scoreEvent)
inline

Sends a score event string to Csound (e.g. "i 1 0 1 0.5 440") for immediate processing.

Parameters
scoreEventA valid Csound score event string.

◆ SetArrayChannel()

CsoundArrayChannelStatus Csound.Unity.CsoundUnityBridge.SetArrayChannel ( string name,
MYFLT[] source )
inline

Write exactly the current number of numeric elements without creating or resizing the channel.

Parameters
nameThe channel name, as the orchestra declares it.
sourceThe elements to write. Its length must be the channel's element count.
Returns
What happened, including why nothing was copied.

◆ SetAudioArrayChannel()

CsoundArrayChannelStatus Csound.Unity.CsoundUnityBridge.SetAudioArrayChannel ( string name,
MYFLT[] source )
inline

Replace all a[] blocks; source must contain exactly ElementCount × ksmps samples.

Parameters
nameThe channel name, as the orchestra declares it.
sourceThe samples to write: exactly the element count times ksmps.
Returns
What happened, including why nothing was copied.

◆ SetAudioChannel()

void Csound.Unity.CsoundUnityBridge.SetAudioChannel ( string name,
MYFLT[] audio )
inline

Writes a ksmps-length audio buffer into the named Csound audio channel. Only the first ksmps samples are used; excess samples are ignored. A shorter array is padded with silence; an empty array clears the channel.

Parameters
nameThe name of the audio channel.
audioNon-null array of audio samples to write.
Exceptions
ArgumentNullExceptionaudio is null.

◆ SetChannel()

void Csound.Unity.CsoundUnityBridge.SetChannel ( string channel,
MYFLT value )
inline

Sets the value of a named Csound control channel.

Parameters
channelThe name of the control channel.
valueThe value to write to the channel.

◆ SetGlobalEnv()

int Csound.Unity.CsoundUnityBridge.SetGlobalEnv ( string name,
string value )
inline

Set the global value of environment variable 'name' to 'value', or delete variable if 'value' is NULL. It is not safe to call this function while any Csound instances are active. See https://csound.com/docs/manual/CommandEnvironment.html for a list of the variables that can be used.

Parameters
nameThe name of the environment variable to set
valueThe value to set, ie a path
Returns
Returns zero on success.

◆ SetPvsChannel() [1/2]

CsoundPvsChannelStatus Csound.Unity.CsoundUnityBridge.SetPvsChannel ( string name,
float[] source )
inline

Write exactly N+2 floats and advance the destination frame counter once on success.

Parameters
nameThe channel name, as the orchestra declares it.
sourceOne frame of exactly fftSize + 2 floats.
Returns
What happened, including why nothing was copied.

◆ SetPvsChannel() [2/2]

CsoundPvsChannelStatus Csound.Unity.CsoundUnityBridge.SetPvsChannel ( string name,
float[] source,
CsoundPvsChannelInfo frame )
inline

Write a snapshot to a channel with the same layout, preserving the supplied frame counter.

Parameters
nameThe channel name, as the orchestra declares it.
sourceOne frame of exactly fftSize + 2 floats.
frameThe layout and frame counter to write with, as a read returned them.
Returns
What happened, including why nothing was copied.

◆ SetSpinSample()

void Csound.Unity.CsoundUnityBridge.SetSpinSample ( int frame,
int channel,
MYFLT sample )
inline

Set a sample in Csound's audio input buffer. Hot path — uses cached spin pointer and channel count; zero allocation.

Parameters
frameFrame inside the current block, 0 to ksmps - 1.
channelInput channel, 0-based.
sampleThe value to write, in Csound units.

◆ SetStringArrayChannel()

CsoundArrayChannelStatus Csound.Unity.CsoundUnityBridge.SetStringArrayChannel ( string name,
string[] source )
inline

Replace every S[] element; null becomes empty, embedded null characters are rejected. Not for audio callbacks.

Parameters
nameThe channel name, as the orchestra declares it.
sourceThe elements to write. Its length must be the channel's element count.
Returns
What happened, including why nothing was copied.

◆ SetStringChannel()

void Csound.Unity.CsoundUnityBridge.SetStringChannel ( string channel,
string value )
inline

Sets the value of a named Csound string channel.

Parameters
channelThe name of the string channel.
valueThe string value to write to the channel.

◆ SetTable()

void Csound.Unity.CsoundUnityBridge.SetTable ( int table,
int index,
MYFLT value )
inline

Sets the value of a slot in a function table. The table number and index are assumed to be valid.

Parameters
tableThe function table number.
indexZero-based index of the slot to write.
valueThe value to store at the specified slot.

◆ Start()

int Csound.Unity.CsoundUnityBridge.Start ( )
inline

Starts a compiled orchestra after reset and enables audio callbacks. Call CompileOrc first. A running instance is left running without starting it twice.

Returns
Zero on success or when already running; nonzero when starting fails or the instance is unavailable, suspended, uncompiled, or this call is from its audio callback. Unavailable on WebGL.

◆ StartWithSetup()

int Csound.Unity.CsoundUnityBridge.StartWithSetup ( Action prepareAudio)
inlinepackage

◆ TableCopyIn()

void Csound.Unity.CsoundUnityBridge.TableCopyIn ( int table,
MYFLT[] source )
inline

Copies the contents of an array into a given function table. The table number is assumed to be valid, and the table must have sufficient space to receive all array contents.

Parameters
tableThe function table number.
sourceArray of values to copy into the table.

◆ TableCopyInAsync() [1/2]

void Csound.Unity.CsoundUnityBridge.TableCopyInAsync ( int table,
MYFLT[] source )
inline

Queues a copy of the source samples into the table, preserving any remaining entries.

Call from a control thread. Uses a snapshot of the source taken at submission. Write buffers are reused between requests and retained until reset or destruction. Use the overload with a request to check completion. Unavailable on WebGL.

Parameters
tableThe function table number to write.
sourceThe samples to copy in. A snapshot is taken at submission.

◆ TableCopyInAsync() [2/2]

CsoundTableCopySubmission Csound.Unity.CsoundUnityBridge.TableCopyInAsync ( int table,
MYFLT[] source,
out CsoundTableCopyRequest request )
inline

Queues a table write and returns a request to poll, or null if it could not be queued.

The write fails if the table is missing or too short when the copy runs. Keep the table structure stable during submission and avoid replacing it on another thread during the performance cycle.

Parameters
tableThe function table number to write.
sourceThe samples to copy in. A snapshot is taken at submission.
requestThe request to poll, or null when the copy was not queued.
Returns
Whether the copy was queued, and why it was not.

◆ TableCopyOut()

void Csound.Unity.CsoundUnityBridge.TableCopyOut ( int table,
out MYFLT[] dest )
inline

Copies the contents of a function table into a supplied array. The table number is assumed to be valid, and the destination will be resized to fit all table contents.

Parameters
tableThe function table number.
destOutput array populated with the table's values, or null if the table is empty or does not exist.

◆ TableCopyOutAsync() [1/2]

void Csound.Unity.CsoundUnityBridge.TableCopyOutAsync ( int table,
out MYFLT[] dest )
inline

Queues a table read. The returned array is filled during a later performance cycle.

Call from a control thread. Use the overload with a request to check completion. Returns null if the table is unavailable or the queue is full. On WebGL it returns an empty array.

Parameters
tableThe function table number to read.
destThe array the copy will fill, sized for the table.

◆ TableCopyOutAsync() [2/2]

CsoundTableCopySubmission Csound.Unity.CsoundUnityBridge.TableCopyOutAsync ( int table,
out MYFLT[] dest,
out CsoundTableCopyRequest request )
inline

Queues a table read and returns a request to poll. The destination is valid on success.

A read fails if the table is missing or changes size before the copy runs. Keep the table structure stable during submission and avoid replacing it on another thread during the performance cycle. A null request means the copy could not be queued.

Parameters
tableThe function table number to read.
destThe array the copy will fill, sized for the table.
requestThe request to poll, or null when the copy was not queued.
Returns
Whether the copy was queued, and why it was not.

◆ TableLength()

int Csound.Unity.CsoundUnityBridge.TableLength ( int table)
inline

Returns the length of a function table (not including the guard point), or -1 if the table does not exist.

Parameters
tableThe function table number.
Returns
The table length, or -1 if the table does not exist.

◆ TryEnterAudio()

bool Csound.Unity.CsoundUnityBridge.TryEnterAudio ( )
inlinepackage

Claims this bridge for the duration of one audio callback. Returns false when the instance is being destroyed, reset or awaiting start, and the caller must produce silence without touching the bridge at all.

Every audio-thread entry point pairs this with ExitAudio in a finally: CsoundUnity.OnAudioFilterRead, CsoundRealtime.Process and CsoundRootRealtime.EndProcessing. It is claimed once per DSP block, not per sample, so the cost is volatile flag reads and two interlocked operations per block.

The flag is checked twice on purpose. The first check is the cheap common case. The second closes the window where the destroy set _closing between that check and the increment: without it the destroy could see a count of zero, start freeing, and only then have this caller appear.

◆ UserOpcodeDir()

string Csound.Unity.CsoundUnityBridge.UserOpcodeDir ( List< EnvironmentSettings > environmentSettings)
inlinestaticprotected

The plugin opcode folder the user asked for in the environment settings, or null when there is none for this platform. Csound takes the folder from the argument of csoundCreate, which wins over OPCODE7DIR64, so a setting that is only exported as an environment variable would be ignored.

Parameters
environmentSettingsThe instance's environment settings.
Returns
The folder, or null when none is set for this platform.

Member Data Documentation

◆ csound

IntPtr Csound.Unity.CsoundUnityBridge.csound

The raw Csound instance handle used for all native P/Invoke calls.

◆ DestroyedSentinel

const int Csound.Unity.CsoundUnityBridge.DestroyedSentinel = int.MinValue
static

Returned by PerformKsmps when the instance has already been destroyed. Distinct from 0 (running) and from every positive value (score ended), so that a caller testing > 0 cannot mistake a freed instance for a finished score.

◆ LoudPeak

volatile float Csound.Unity.CsoundUnityBridge.LoudPeak

The largest sample an audio path had to silence in its last block, 0 when nothing tripped and infinity when what tripped it was not a number. Written on the audio thread and cleared by its reader, so the warning is printed on the thread that is allowed to print.

◆ LoudThreshold

volatile float Csound.Unity.CsoundUnityBridge.LoudThreshold = float.PositiveInfinity

Sample value at which an audio path silences a sample and reports a runaway. Pushed by CsoundUnity from its loudWarningThreshold, and PositiveInfinity when that check is off, which still catches a sample that is not a number. Here for the same reason StartupFadeFrames is: so the paths that read spout directly guard the output the way OnAudioFilterRead does.

◆ Muted

volatile bool Csound.Unity.CsoundUnityBridge.Muted

Mirrors the owning CsoundUnity.mute flag so that the audio paths which read spout without going through ProcessBlock — IAudioGenerator and RootOutput — can honour it. ProcessBlock checks mute directly and does not use this.

Written from the audio thread once per ksmps and read on the same thread.

◆ Paused

volatile bool Csound.Unity.CsoundUnityBridge.Paused

Mirrors the owning CsoundUnity.pauseProcessing flag, for the same reason as Muted. When set, those paths skip PerformKsmps entirely and output silence.

They must nonetheless keep invoking the spin-fill callback that refreshes this flag: it is the only thing that can clear it again, so skipping it would make the pause impossible to lift.

◆ SpatialBlend

volatile float Csound.Unity.CsoundUnityBridge.SpatialBlend

How far the AudioSource is spatialized, 0 to 1, pushed by CsoundUnity every frame. The IAudioGenerator path needs it because Unity sums a generator's channels for a spatialized source, so a mono bed written into every channel has to be divided by what that costs.

◆ StartupFadeFrames

volatile int Csound.Unity.CsoundUnityBridge.StartupFadeFrames

Length of the startup fade in output frames, 0 when off. Pushed by CsoundUnity from its fadeInSeconds; lives here for the same reason OutputGain does, so the paths that read spout directly — IAudioGenerator and RootOutput — cannot end up fading differently from each other or from OnAudioFilterRead.

◆ WebGLVariation

int Csound.Unity.CsoundUnityBridge.WebGLVariation = 3
static

Which @csound/browser variation to create: 0 single threaded, 1 worker with a SharedArrayBuffer, 2 worker with a MessagePort. Anything higher clamps to the last. Read only in a WebGL player, and declared outside the guard so that code setting it compiles on every platform.

They differ in how the host reaches Csound, not only in how audio is carried: in the worker variations a channel write is a request posted to the worker, in the single threaded one it is a direct call. Set before the first instance is created.

Property Documentation

◆ CompiledOk

bool Csound.Unity.CsoundUnityBridge.CompiledOk
get

Returns true while this instance holds a successfully compiled orchestra.

◆ OutputGain

float Csound.Unity.CsoundUnityBridge.OutputGain
get

Gain the audio paths that read spout directly should apply to their output: 0 while muted or paused, 1 otherwise. Exists so the two of them — IAudioGenerator and RootOutput — cannot drift apart on what "silent" means.


The documentation for this class was generated from the following files: