|
CsoundUnity 4.0.0-alpha.3
|
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...
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. | |
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.
Defines the interpolation behavior of a Csound control channel.
Identifies the data type carried by a Csound software-bus channel.
|
inline |
Default parameterless constructor. Creates an uninitialised bridge instance.
|
inlineprotected |
Records the host settings for a derived bridge that creates its own instance.
| sampleRate | The host sample rate in Hz, captured by the caller. |
| ksmps | Host block size, or zero to use the orchestra's own ksmps. |
|
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.
| csdFile | The Csound (.csd) file content as a string |
| environmentSettings | A list of the Csound Environments settings defined by the user |
| audioRate | Sample rate in Hz, which overrides the csd's sr. |
| controlRate | Control rate in Hz, which overrides the csd's kr. |
| ksmps | Samples per control period. 0 leaves the csd's own value. |
|
inline |
Add a value to a sample in Csound's audio input buffer. Hot path — uses cached spin pointer and channel count; zero allocation.
| frame | Frame inside the current block, 0 to ksmps - 1. |
| channel | Input channel, 0-based. |
| sample | The value to add to what is already there, in Csound units. |
|
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.
|
inline |
Clears the input buffer (spin).
|
inline |
Returns true if the CSD compiled without errors; equivalent to reading CompiledOk.
true when compilation succeeded.
|
inline |
Compiles the given Csound orchestra string at runtime, adding new instruments and UDOs to the running instance.
| orchStr | A 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.
|
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.
| sampleRate | Sample rate in Hz, which overrides the csd's sr. |
| ksmps | Samples per control period. 0 leaves the csd's own value. |
| opcodeDir | Directory to load plugin opcodes from, or null for the default. |
|
inline |
Sets the score time offset in seconds, causing performance to start from the given point in the score.
| value | Score offset in seconds. |
|
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.
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.
|
inline |
|
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.
|
inline |
Returns the 0 dBFS value (full-scale amplitude) for this Csound instance, as set by the 0dbfs header statement.
0 if this bridge has already been freed. Callers divide by this, so guard the divisor: 1 / 0 is Infinity, not silence.
|
inline |
Read numeric values, axis sizes and matching metadata atomically; no partial copy occurs.
| name | The channel name, as the orchestra declares it. |
| destination | Filled with the elements, in element order. |
| sizes | Filled with the size of each axis. |
| info | Filled with the metadata the values were read with. |
|
inline |
Copy a complete numeric array to a flat buffer; length reports required capacity on BufferTooSmall.
| name | The channel name, as the orchestra declares it. |
| destination | Filled with the elements, in element order. |
| length | How many elements were copied, or how many the buffer needs on BufferTooSmall. |
|
inline |
Read array metadata and axis sizes into a reusable buffer; no channel is created.
| name | The channel name, as the orchestra declares it. |
| sizes | Filled with the size of each axis. Reused between calls. |
| info | Filled with the element type, the axis count and the element count. |
|
inline |
Read all audio blocks and their matching shape; no buffer changes on BufferTooSmall.
| name | The channel name, as the orchestra declares it. |
| destination | Filled with the blocks, in element order, ksmps samples each. |
| sizes | Filled with the size of each axis. |
| info | Filled with the metadata the samples were read with. |
|
inline |
Read a[] blocks in element order, ksmps samples per element; length reports required samples.
| name | The channel name, as the orchestra declares it. |
| destination | Filled with the blocks, in element order, ksmps samples each. |
| length | How many samples were copied, or how many the buffer needs on BufferTooSmall. |
|
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.
| name | The name of the audio channel. |
|
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.
| name | The name of the audio channel. |
| dest | Buffer with room for at least ksmps samples. Null or empty arrays are ignored. |
| ArgumentException | A non-empty destination is shorter than ksmps. |
|
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.
| channel | The name of the control channel. |
|
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.
|
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.
| csoundHandle | The raw Csound instance pointer. |
|
inline |
Retrieves and removes the first pending message from Csound's message buffer.
|
inline |
Returns the number of pending messages in Csound's message buffer.
|
inline |
Returns the current performance position in samples from the start of the performance.
|
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.
| key | the name of the Environment Variable to get |
|
inline |
Returns the control rate (kr) of the current Csound instance.
|
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.
|
inlinestatic |
Converts a native char pointer returned by Csound into a managed string.
| message | An unmanaged pointer to a null-terminated ASCII string. |
|
inline |
Get number of output channels.
nchnls, or 0 once the instance is gone.
|
inline |
Get number of input channels.
nchnls_i, or 0 once the instance is gone.
|
inline |
Read one complete N+2 float frame and matching metadata; unused trailing entries are unchanged.
| name | The channel name, as the orchestra declares it. |
| destination | Filled with one frame of fftSize + 2 floats. |
| info | Filled with the layout and the counter of the frame that was read. |
|
inline |
Read PVS layout and frame counter without creating a channel.
| name | The channel name, as the orchestra declares it. |
| info | Filled with the layout and the frame counter. |
|
inline |
|
inline |
|
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.
| frame | Frame inside the current block, 0 to ksmps - 1. |
| channel | Output channel, 0-based. |
|
inline |
Returns the audio sample rate (sr) of the current Csound instance.
|
inline |
Read string data and matching axis sizes atomically; UTF-8 decoding happens outside the native lock.
| name | The channel name, as the orchestra declares it. |
| destination | Filled with the elements, in element order. Reused between calls. |
| sizes | Filled with the size of each axis. |
| info | Filled with the metadata the values were read with. |
|
inline |
Read S[] values into a reusable container; changed strings allocate and unused trailing entries remain unchanged.
| name | The channel name, as the orchestra declares it. |
| destination | Filled with the elements, in element order. Reused between calls. |
| length | How many elements were copied, or how many the buffer needs on BufferTooSmall. |
|
inline |
Reads the current value of the named Csound string channel.
| name | The name of the string channel. |
|
inline |
Returns the value of a slot in a function table. The table number and index are assumed to be valid.
| table | The function table number. |
| index | Zero-based index of the slot to read. |
|
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.
| tableValues | Output array populated with the table's values. |
| numTable | The function table number to read. |
|
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}.
| args | Output array populated with the GEN generator arguments. |
| index | The function table number. |
|
inline |
Returns the Csound library version as an integer (e.g. 6180 for version 6.18.0). On WebGL, available after initialization completes.
|
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.
| name | The channel name, as the orchestra declares it. |
| type | The element type the channel holds. |
| sizes | The size of each axis. One value for a vector, one per axis for an array. |
|
inline |
Create or verify a fixed-layout, non-sliding PVS channel. Setup only; may briefly suspend Unity audio.
| name | The channel name, as the orchestra declares it. |
| fftSize | The analysis size, which gives frames of fftSize + 2 floats. |
| overlap | The hop between frames, in samples. |
| windowSize | The analysis window length, in samples. |
| windowType | The window shape, as the pvs opcodes number them. |
| format | What a frame holds: amplitude and frequency, or amplitude and phase. |
|
inline |
Loads all Csound plugins found in the specified directory. Not available on iOS; use the conditional compilation guard before calling.
| dir | Path to the directory containing Csound plugin libraries. |
|
inline |
Advances Csound by one ksmps block, filling the spout buffer, and caches the spout/spin pointers on the first successful call.
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.
|
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.
Reimplemented in Csound.Unity.CsoundWorker.
|
inline |
Rewinds the score to the beginning, allowing the performance to repeat from time zero.
|
inline |
Sends a score event string to Csound (e.g. "i 1 0 1 0.5 440") for immediate processing.
| scoreEvent | A valid Csound score event string. |
|
inline |
Write exactly the current number of numeric elements without creating or resizing the channel.
| name | The channel name, as the orchestra declares it. |
| source | The elements to write. Its length must be the channel's element count. |
|
inline |
Replace all a[] blocks; source must contain exactly ElementCount × ksmps samples.
| name | The channel name, as the orchestra declares it. |
| source | The samples to write: exactly the element count times ksmps. |
|
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.
| name | The name of the audio channel. |
| audio | Non-null array of audio samples to write. |
| ArgumentNullException | audio is null. |
|
inline |
Sets the value of a named Csound control channel.
| channel | The name of the control channel. |
| value | The value to write to the channel. |
|
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.
| name | The name of the environment variable to set |
| value | The value to set, ie a path |
|
inline |
Write exactly N+2 floats and advance the destination frame counter once on success.
| name | The channel name, as the orchestra declares it. |
| source | One frame of exactly fftSize + 2 floats. |
|
inline |
Write a snapshot to a channel with the same layout, preserving the supplied frame counter.
| name | The channel name, as the orchestra declares it. |
| source | One frame of exactly fftSize + 2 floats. |
| frame | The layout and frame counter to write with, as a read returned them. |
|
inline |
Set a sample in Csound's audio input buffer. Hot path — uses cached spin pointer and channel count; zero allocation.
| frame | Frame inside the current block, 0 to ksmps - 1. |
| channel | Input channel, 0-based. |
| sample | The value to write, in Csound units. |
|
inline |
Replace every S[] element; null becomes empty, embedded null characters are rejected. Not for audio callbacks.
| name | The channel name, as the orchestra declares it. |
| source | The elements to write. Its length must be the channel's element count. |
|
inline |
Sets the value of a named Csound string channel.
| channel | The name of the string channel. |
| value | The string value to write to the channel. |
|
inline |
Sets the value of a slot in a function table. The table number and index are assumed to be valid.
| table | The function table number. |
| index | Zero-based index of the slot to write. |
| value | The value to store at the specified slot. |
|
inline |
Starts a compiled orchestra after reset and enables audio callbacks. Call CompileOrc first. A running instance is left running without starting it twice.
|
inlinepackage |
|
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.
| table | The function table number. |
| source | Array of values to copy into the table. |
|
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.
| table | The function table number to write. |
| source | The samples to copy in. A snapshot is taken at submission. |
|
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.
| table | The function table number to write. |
| source | The samples to copy in. A snapshot is taken at submission. |
| request | The request to poll, or null when the copy was not queued. |
|
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.
| table | The function table number. |
| dest | Output array populated with the table's values, or null if the table is empty or does not exist. |
|
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.
| table | The function table number to read. |
| dest | The array the copy will fill, sized for the table. |
|
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.
| table | The function table number to read. |
| dest | The array the copy will fill, sized for the table. |
| request | The request to poll, or null when the copy was not queued. |
|
inline |
Returns the length of a function table (not including the guard point), or -1 if the table does not exist.
| table | The function table number. |
|
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.
|
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.
| environmentSettings | The instance's environment settings. |
null when none is set for this platform.| IntPtr Csound.Unity.CsoundUnityBridge.csound |
The raw Csound instance handle used for all native P/Invoke calls.
|
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.
| 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.
| 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.
| 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.
| 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.
| 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.
| 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.
|
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.
|
get |
Returns true while this instance holds a successfully compiled orchestra.
|
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.