|
CsoundUnity 4.0.0-alpha.3
|
Runs Csound inside a scene: compiles a .csd, performs it while the scene plays, and exposes its channels to the rest of the game.
More...
Public Types | |
| enum | EnvType { SFDIR , SSDIR , SADIR , SFOUTYP , INCDIR , OPCODE7DIR , OPCODE7DIR64 , SNAPDIR , CSOUND7RC , CSSTRNGS , CS_LANG , RAWWAVE_PATH , CSNOSTOP , MFDIR , CS_OMIT_LIBS , CS_USER_PLUGINDIR , CS_UDO_DIR } |
| The enum representing the Csound Environment Variables. More... | |
| enum | DiscreteChannelMode { SnapAtEnd , SnapAtMidpoint , SnapAtStart } |
| Controls how discrete channels (button, checkbox, combobox) are handled during MorphToPreset. More... | |
| enum | DiscreteBlendMode { Ignore , NearestCorner } |
| Controls how discrete channels (button, checkbox, combobox) are handled during BlendPresets. More... | |
Public Member Functions | |
| CsoundArrayChannelStatus | InitializeArrayChannel (string name, CsoundArrayChannelType type, params int[] sizes) |
| Create an i[], k[], S[] or a[] channel, or verify an existing channel's exact type and shape. Initialization may allocate and briefly suspend Unity audio processing; call during setup, never from an audio callback. Existing channels are not resized. | |
| CsoundArrayChannelStatus | GetArrayChannelInfo (string name, int[] sizes, out CsoundArrayChannelInfo info) |
| Read array metadata and axis sizes without creating a channel or allocating a buffer. | |
| CsoundArrayChannelStatus | GetArrayChannel (string name, MYFLT[] destination, out int length) |
| Copy a numeric array into a reusable flat buffer; unused trailing entries are unchanged. | |
| CsoundArrayChannelStatus | GetArrayChannel (string name, MYFLT[] destination, int[] sizes, out CsoundArrayChannelInfo info) |
| Copy numeric data and its axis sizes under one channel lock, including when producers resize. | |
| CsoundArrayChannelStatus | SetArrayChannel (string name, MYFLT[] source) |
| Replace all numeric elements of the channel's current shape; source length must match exactly. | |
| CsoundArrayChannelStatus | GetAudioArrayChannel (string name, MYFLT[] destination, out int length) |
| Copy an audio array into a reusable flat buffer; unused trailing entries are unchanged. | |
| CsoundArrayChannelStatus | GetAudioArrayChannel (string name, MYFLT[] destination, int[] sizes, out CsoundArrayChannelInfo info) |
| Copy audio blocks and their axis sizes under one channel lock, including when producers resize. | |
| CsoundArrayChannelStatus | SetAudioArrayChannel (string name, MYFLT[] source) |
| Replace all audio samples of the channel's current shape; source length must match exactly. | |
| CsoundArrayChannelStatus | GetStringArrayChannel (string name, string[] destination, out int length) |
| Read a complete string array into a reusable container. Changed strings allocate; unchanged values retain their references. Runs outside audio callbacks and does not create a channel. | |
| CsoundArrayChannelStatus | GetStringArrayChannel (string name, string[] destination, int[] sizes, out CsoundArrayChannelInfo info) |
| Read UTF-8 string values and their matching shape atomically; decode outside the native spin lock. | |
| CsoundArrayChannelStatus | SetStringArrayChannel (string name, string[] source) |
| Replace all S[] elements from UTF-8 text without resizing the channel. Null elements become empty strings; embedded null characters are rejected. Native buffers may grow. Not audio-thread safe. | |
| AudioRouteResult | AddAudioInputRoute (CsoundUnity source, string sourceChannelName, int destSpinChannel=0, float level=1f, bool forceConnection=false) |
| Adds a new audio input route to this instance at runtime. | |
| void | RemoveAudioInputRoute (int index) |
| Removes the audio input route at index in audioInputRoutes. | |
| void | RemoveAudioInputRoute (CsoundUnity source) |
| Removes all audio input routes whose source is source . | |
| void | RemoveAudioInputRoute (CsoundUnity source, string sourceChannelName, int destSpinChannel) |
| Removes the specific audio input route that matches all three key fields. | |
| void | RemoveAllAudioInputRoutes () |
| Removes all audio input routes from this instance. | |
| bool | WouldCreateCircle (CsoundUnity newSource) |
Returns true if routing audio from newSource into this instance would create a circular dependency in the audio graph. | |
| void | SetChannel (string channel, MYFLT val) |
| Sets a Csound channel. Used in connection with a chnget opcode in your Csound instrument. | |
| void | SetChannel (CsoundChannelController channelController) |
| Sets a Csound channel. Useful for setting presets at runtime. Used in connection with a chnget opcode in your Csound instrument. | |
| void | SetChannels (List< CsoundChannelController > channelControllers, bool excludeButtons=true) |
| Sets a list of Csound channels. | |
| void | SetStringChannel (string channel, string val) |
| Sets a string channel in Csound. Used in connection with a chnget opcode in your Csound instrument. | |
| MYFLT | GetChannel (string channel) |
| Gets a Csound channel. Used in connection with a chnset opcode in your Csound instrument, or set with SetChannel. | |
| void | GetChannel (string channel, Action< MYFLT > callback) |
| Reads a Csound control channel and delivers the result via callback . On non-WebGL platforms the callback is invoked synchronously before this method returns. On WebGL the read is dispatched to the AudioWorklet thread; the callback fires on the main thread once the value is available (typically within the same or the next frame). | |
| CsoundChannelController | GetChannelController (string channel) |
| Returns the serialized CsoundChannelController for the named channel, as parsed from the CSD file by ParseCsdFile. | |
| string | GetStringChannel (string name) |
| Get a Csound string channel. Used in connection with a chnset opcode in your Csound instrument, or set with SetStringChannel. | |
| IDictionary< string, CsoundUnityBridge.ChannelInfo > | GetChannelList () |
| Blocking method to get a list of the channels from Csound, not from the serialized list of this instance. 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. | |
| MYFLT[] | GetAudioChannel (string channel) |
| Gets a Csound Audio channel. Used in connection with a chnset opcode in your Csound instrument. | |
| void | GetAudioChannel (string channel, MYFLT[] dest) |
Zero-allocation overload: reads the named audio channel directly into dest without any managed or native heap allocation. Prefer this on hot audio-thread paths (e.g. inside OnAudioFilterRead or a ksmps callback) to avoid GC pressure and the periodic audio dropouts it causes. | |
| void | AddAudioChannel (string channel) |
| Add an audio channel to the list that can be used in CsoundUnityChild. | |
| void | RemoveAudioChannel (string channel) |
| Removes an audio channel from the list that can be used in CsoundUnityChild. | |
| double | GetAudioChannelSample (string channel, int sample) |
| Returns a sample from a CsoundUnity audio channel This is useful if you want to update an AudioSource using the OnAudioFilterRead callback Internally it uses the namedAudioChannelDataDict buffer, that is usually used to update CsoundUnityChild scripts Using this together with AddAudioChannel(string) and RemoveAudioChannel(string) allows you to create new audio channels at runtime. | |
| void | ResetDspLoadStatistics () |
| Requests a statistics reset at the next measured DSP block. Call from the main thread. Measurement must be enabled for the reset to take effect. | |
| delegate void | CsoundInitialized () |
| The delegate of the event OnCsoundInitialized. | |
| delegate void | ChannelsUpdated () |
| The delegate of the event OnChannelsUpdated. | |
| void | NotifyChannelsUpdated () |
| Raises OnChannelsUpdated. Call it after writing several channels yourself with SetChannel(string, MYFLT), so the UI components re-read them. | |
| delegate void | CsoundStopped () |
| The delegate of the event OnCsoundStopped. | |
| delegate void | CsoundPerformKsmps () |
| The delegate of the event OnCsoundPerformKsmps. | |
| delegate void | CsoundPerformanceFinishedDelegate () |
| The delegate of the event OnCsoundPerformanceFinished. | |
| void | Initialize () |
| Initializes CsoundUnity manually. Only works if initializeOnAwake is false, or after a Stop. Silently returns if already initialized or initializing. | |
| void | Stop () |
| Stops and disposes the current Csound instance. After this, Initialize or Restart can be called to start again. | |
| void | Restart () |
| Stops the current Csound instance and reinitializes it from scratch. | |
| int | GetVersion () |
| Returns the Csound version number times 1000 (5.00.0 = 5000). | |
| int | LoadPlugins (string dir) |
| Loads all plugins from a given directory. | |
| bool | CompiledWithoutError () |
| Returns true if the csd file was compiled without errors. | |
| void | SetInputSample (int frame, int channel, MYFLT sample) |
| Set a sample in Csound's input buffer, overwriting any existing value. | |
| void | AddInputSample (int frame, int channel, MYFLT sample) |
| Adds the indicated sample into the audio input working buffer (spin); this only ever makes sense before calling PerformKsmps(). The frame and channel must be in bounds relative to ksmps and nchnls. NB: the spin buffer needs to be cleared at every k-cycle by calling ClearSpin(). | |
| void | ClearSpin () |
| Clears the input buffer (spin). | |
| MYFLT | GetOutputSample (int frame, int channel) |
| Get a sample from Csound's audio output buffer. | |
| MYFLT[] | GetSpin () |
| Get Csound's audio input buffer. | |
| MYFLT[] | GetSpout () |
| Get Csound's audio output buffer. | |
| string | GetEnv (EnvType envType) |
| Get Environment path. | |
| 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. | |
| uint | GetNchnlsInputs () |
| Get the number of input channels. | |
| uint | GetNchnls () |
| Get the number of output channels. | |
| MYFLT | Get0dbfs () |
Get the 0 dBFS amplitude reference value as set by the 0dbfs statement in the orchestra. | |
| long | GetCurrentTimeSamples () |
| Returns the current performance time in samples. | |
| bool | CsoundReset () |
| Returns the Csound instance to its pre-compilation state, keeping it alive and reusable: the orchestra and the control channels are gone afterwards. Compile again before performing, and set the channel values again. The engine settings are re-armed here, so the instance keeps the host sample rate, ksmps and audio IO it was created with. | |
| AudioChannelReader | GetAudioChannelReader (string channelName) |
| Returns a reader for the audio this instance publishes on a named audio channel: one finished block at a time, readable from any thread. | |
| GeneratorInstance | CreateInstance (ControlContext context, AudioFormat? nestedFormat=null, ProcessorInstance.CreationParameters creationParameters=default) |
Called by Unity when AudioSource.generator = this is set (or when a scene with a serialized generator reference is loaded). Creates the unmanaged CsoundRealtime and CsoundControl structs and hands them to Unity via context.AllocateGenerator. | |
| void | SetCsd (string guid) |
| Sets the CSD from a project asset, identified by its AssetDatabase GUID. | |
| bool | LoadCsdFromString (string csdContent, bool startNow=true) |
Loads a CSD from a raw string at runtime, without requiring a .csd asset. | |
| bool | LoadCsdFromPath (string path, bool startNow=true) |
| Reads a CSD from a file and loads it, the runtime counterpart of assigning a csd asset. Equivalent to reading the file yourself and calling LoadCsdFromString. | |
| void | LoadCsdFromPath (string path, Action< bool > onLoaded, bool startNow=true) |
Reads a CSD with UnityWebRequest and loads it, then reports the outcome to onLoaded . Works for the cases the synchronous overload refuses: StreamingAssets on any platform, and http/https URLs. | |
| int | CompileOrc (string orcStr) |
| Parse, and compile the given orchestra from an ASCII string, also evaluating any global space code (i-time only) this can be called during performance to compile a new orchestra. This sample shows how to use CompileOrc. | |
| int | CsoundStart () |
| Starts the compiled orchestra after CsoundReset and enables performance. Call CompileOrc first. Starting an already running instance is a no-op. | |
| void | SendScoreEvent (string scoreEvent) |
| Send a score event to Csound in the form of "i1 0 10 .... | |
| void | RewindScore () |
| Rewinds a compiled Csound score to the time specified with SetScoreOffsetSeconds(). | |
| void | SetScoreOffsetSeconds (MYFLT value) |
| Csound score events prior to the specified time are not performed, and performance begins immediately at the specified time (real-time events will continue to be performed as they are received). Can be used by external software, such as a VST host, to begin score performance midway through a Csound score, for example to repeat a loop in a sequencer, or to synchronize other events with the Csound score. | |
| MYFLT | GetSr () |
| Get the current sample rate. | |
| MYFLT | GetKr () |
| Get the current control rate. | |
| int | PerformKsmps () |
| Process a ksmps-sized block of samples. | |
| uint | GetKsmps () |
| Get the number of audio sample frames per control sample. | |
| void | SavePresetAsScriptableObject (string presetName, string path=null) |
| Save a CsoundUnityPreset of this CsoundUnity instance at the specified path, using the specified presetName. The current csoundFileName and list of CsoundChannelControllers will be saved in the preset. If no presetName is given, a default one will be used. | |
| void | SavePresetAsJSON (string presetName, string path=null, bool overwriteIfExisting=false) |
| Save a preset as JSON using CsoundChannelControllers and CsoundFileName from this CsoundUnity instance. See SavePresetAsJSON(CsoundUnityPreset, string, bool). | |
| void | SaveGlobalPreset (string presetName, string path=null, bool overwriteIfExisting=false) |
| Save a serialized copy of this CsoundUnity instance. Similar behaviour as saving a Unity Preset from the inspector of the CsoundUnity component, but this can be used at runtime. | |
| void | ConvertPresetToScriptableObject (string path, string destination) |
| Convert a JSON preset into a Scriptable Object preset to be written at the specified path. If path is empty the converted preset will be saved inside the Assets folder. | |
| CsoundUnityPreset | SetPreset (string presetName, string presetData) |
| Set a CsoundUnityPreset to this CsoundUnity instance using a presetName and presetData. The set preset will be returned. | |
| CsoundUnityPreset | SetPreset (string presetData) |
| Set a CsoundUnityPreset to this CsoundUnity instance using presetData. | |
| void | SetPreset (CsoundUnityPreset preset) |
| Set a CsoundUnityPreset to this CsoundUnity instance. | |
| CsoundUnity | SetGlobalPreset (string presetName, string presetData) |
| Set a global preset to this CsoundUnity instance using a presetName and presetData. | |
| void | LoadPreset (string path, Action< CsoundUnityPreset > onPresetLoaded=null) |
| Loads a preset from a JSON file. The JSON file should represent a CsoundUnityPreset. | |
| void | LoadGlobalPreset (string path) |
| Load a global preset on this CsoundUnity instance from a JSON file found at path. The JSON file should represent a Global Preset, ie a complete CsoundUnity instance. | |
| Coroutine | MorphToPreset (CsoundUnityPreset preset, float duration, AnimationCurve curve=null, Action onComplete=null, DiscreteChannelMode discreteMode=DiscreteChannelMode.SnapAtEnd) |
| Smoothly interpolates all continuous channels — the sliders, plus both axes of an xypad, hrange or vrange — from their current values to the target preset's values over the given duration. An optional AnimationCurve controls easing; pass null for linear interpolation. The returned Coroutine can be passed to StopMorph to cancel mid-way. If duration is zero or negative, the preset is applied immediately. | |
| void | StopMorph () |
| Stops an in-progress morph started by MorphToPreset. Channel values remain at whatever point the morph reached when stopped. | |
| void | BlendPresets (CsoundUnityPreset a, CsoundUnityPreset b, CsoundUnityPreset c, CsoundUnityPreset d, Vector2 position, DiscreteBlendMode discreteMode=DiscreteBlendMode.Ignore) |
| Bilinear blend of four presets placed at the corners of a unit square. | |
| bool | CopyChannelsToClipboard () |
Puts this instance's control channels on the system clipboard, as the same JSON a CsoundUnityPreset is saved in — so a clipboard snapshot and a saved .json preset are interchangeable, and channels can be pasted into a chat window as readily as back into an inspector. | |
| bool | PasteChannelsFromClipboard () |
| Applies channels held on the clipboard in the CsoundUnityPreset JSON format. | |
| CsoundPvsChannelStatus | InitializePvsChannel (string name, int fftSize, int overlap, int windowSize, int windowType=1, CsoundPvsFormat format=CsoundPvsFormat.AmplitudeFrequency) |
| Create or verify a fixed-layout PVS channel during setup. May allocate and 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 a complete N+2 float frame and matching metadata; neither partial copies nor channel creation occur. | |
| CsoundPvsChannelStatus | SetPvsChannel (string name, float[] source) |
| Write exactly N+2 floats and increment the frame counter on success. Use once per new spectral frame. | |
| CsoundPvsChannelStatus | SetPvsChannel (string name, float[] source, CsoundPvsChannelInfo frame) |
| Write a snapshot with matching FFT/hop/window/format, preserving its frame counter. | |
| int | CreateFloatTable (int tableNumber, float[] samples) |
| Creates a table with the supplied float samples. Can be called during performance. | |
| int | CreateTable (int tableNumber, MYFLT[] samples) |
| Creates a table with the supplied samples. Can be called during performance. | |
| int | CreateTableInstrument (int tableNumber, int tableLength) |
| Creates an empty table, to be filled with samples later. Please note that trying to read the samples from an empty folder will produce a crash. Can be called during performance. | |
| int | GetTableLength (int table) |
| Returns the length of a function table (not including the guard point), or -1 if the table does not exist. | |
| MYFLT | GetTableSample (int tableNumber, int index) |
| Retrieves a single sample from a Csound function table. | |
| int | GetTable (out MYFLT[] tableValues, int numTable) |
| Stores values to 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 'tableNum' in args, and returns the number of arguments used. If the table does not exist, args is set to NULL and -1 is returned. NB: the argument list starts with the GEN number and is followed by its parameters. eg. f 1 0 1024 10 1 0.5 yields the list {10.0,1.0,0.5}. | |
| 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 | CopyTableOut (int table, out MYFLT[] dest) |
| Copy the contents of a function table into a supplied array dest The table number is assumed to be valid, and the destination needs to have sufficient space to receive all the function table contents. | |
| void | CopyTableOutAsync (int table, out MYFLT[] dest) |
| Queues a read into an array filled during a later performance cycle. | |
| CsoundTableCopySubmission | CopyTableOutAsync (int table, out MYFLT[] dest, out CsoundTableCopyRequest request) |
| Queues a table read and returns the destination and a request to poll on the calling thread. | |
| void | CopyFloatTableIn (int table, float[] source) |
| Same as CopyTableIn but passing a float array. | |
| void | CopyTableIn (int table, MYFLT[] source) |
| Copy the contents of a supplied array into a function table The table number is assumed to be valid, and the destination needs to have sufficient space to receive all the function table contents. | |
| void | CopyTableInAsync (int table, MYFLT[] source) |
| Queues a snapshot of the source for a later performance cycle. | |
| CsoundTableCopySubmission | CopyTableInAsync (int table, MYFLT[] source, out CsoundTableCopyRequest request) |
| Queues a table write and returns a request to poll on the calling thread. | |
| void | SendMidiNoteOn (int channel, int note, int velocity) |
Sends a MIDI Note On message to Csound. The CSD must have a MIDI device option (e.g. <CsOptions> -M0 </CsOptions>) for Csound to process MIDI events. | |
| void | SendMidiNoteOff (int channel, int note, int velocity=0) |
| Sends a MIDI Note Off message to Csound. | |
| void | SendMidiControlChange (int channel, int controller, int value) |
| Sends a MIDI Control Change message to Csound. | |
| void | SendMidiProgramChange (int channel, int program) |
| Sends a MIDI Program Change message to Csound. | |
| void | SendMidiMessage (byte[] data) |
| Sends a raw MIDI message (1–3 bytes) directly to Csound. Use this for any MIDI message type not covered by the helper methods above. | |
Static Public Member Functions | |
| static int | ParseCsdFileForNchnls (string filename) |
Reads the CSD file and returns the value of nchnls (output channels) declared in the orchestra header. Correctly ignores nchnls_i (input channels). Returns 0 when the directive is absent — in that case Csound defaults to 1, but callers should treat 0 as "unknown / not specified". | |
| static int | ParseCsdStringForNchnls (string csdContent) |
| String equivalent of ParseCsdFileForNchnls, used when only the CSD content is available (no file path), e.g. from LoadCsdFromString. | |
| static int | ParseCsdFileForKsmps (string filename) |
Parses ksmps from the global header of the CSD's <CsInstruments> section. Returns the explicit ksmps value if declared; otherwise computes round(sr / kr) if both are present; otherwise returns 0 (not specified). Only scans lines before the first instr declaration. | |
| static int | ParseCsdStringForKsmps (string csdContent) |
| String equivalent of ParseCsdFileForKsmps, used when only the CSD content is available (no file path), e.g. from LoadCsdFromString. | |
| static List< string > | ParseCsdFileForAudioChannels (string filename) |
Parses the CSD file and returns the names of all audio-rate channels declared via chnset avar, "channel name" (channels driven by a- or ga-rate variables with literal string names). | |
| static List< string > | ParseCsdStringForUnsupportedWidgets (string csdContent) |
| Cabbage widget names that appear in a csd but that the parser does not build a channel for, so the inspector and the UI generator can say so instead of silently showing less than the csd declares. | |
| static List< string > | ParseCsdStringForAudioChannels (string csdContent) |
Parses a CSD string (already in memory) for named audio channels written with chnset. Runtime equivalent of ParseCsdFileForAudioChannels used when only the CSD content is available (no file path), e.g. during Init on first play after a fresh package import where the inspector was never opened to trigger SetCsd. | |
| static List< CsoundChannelController > | ParseCsdFile (string filename) |
| Parses the CSD file's Cabbage widget section and returns a list of CsoundChannelController objects describing every slider, button, checkbox, combobox, xypad, and similar widget found. | |
| static List< CsoundChannelController > | ParseCsdString (string csdContent) |
| String equivalent of ParseCsdFile — parses the Cabbage widget section from CSD text already in memory (no file path), e.g. from LoadCsdFromString. | |
| static CsoundUnityPreset | CreatePreset (string presetName, string csoundFileName, List< CsoundChannelController > channels) |
| Create a CsoundUnityPreset from a presetName, csoundFileName and a list of CsoundChannelControllers. | |
| static CsoundUnityPreset | CreatePreset (string presetName, string presetData) |
| Create a CsoundUnityPreset from a presetName and presetData. | |
| static void | WritePreset (CsoundUnityPreset preset, string path) |
| Write a CsoundUnityPreset at the specified path inside the Assets folder. You can pass a full path, the Assets folder path will be extracted. Subfolders in the preset name are created as needed; the stored name is the file's leaf name. Overwriting an existing asset preserves its GUID and references. | |
| static void | SavePresetAsJSON (CsoundUnityPreset preset, string path=null, bool overwriteIfExisting=false) |
| Save the specified CsoundUnityPreset as JSON, at the specified path. If a file exists at the specified path, it will be overwritten if overwriteIfExisting is true. | |
| static void | SavePresetAsJSON (List< CsoundChannelController > channels, string csoundFileName, string presetName, string path=null, bool overwriteIfExisting=false) |
| Save a preset as JSON from a list of CsoundChannelController, specifying the related CsoundFileName and the presetName. See SavePresetAsJSON(CsoundUnityPreset, string, bool). | |
| static List< CsoundUnityPreset > | ParseSnap (string csdPath, string snapPath) |
Parses a Cabbage .snaps file and returns a list of CsoundUnityPreset objects, one per snapshot entry, with channel metadata filled in from the companion CSD. | |
Public Attributes | |
| bool | logCsoundOutput = false |
| If true, all Csound output messages will be sent to the Unity output console. Note that this can slow down performance if there is a lot of information being printed. | |
| bool | initializeOnAwake = true |
| If true CsoundUnity will initialize automatically in Awake. Set to false to initialize manually by calling Initialize. | |
| bool | mute = false |
| Silences this instance's audio output. Csound keeps performing: the score advances, so unmuting drops back in on the beat rather than resuming where it left off, and input (audio input routes, native audio input, clip audio) keeps flowing in. | |
| bool | pauseProcessing = false |
| Suspends this instance: the output is silenced and Csound stops performing, so no DSP work is done at all. The score is frozen, so clearing the flag resumes from exactly where it stopped. | |
| bool | processClipAudio |
| If true Csound uses as an input the AudioClip attached to this AudioSource. If false, no processing occurs on the attached AudioClip. | |
| bool | loudVolumeWarning = true |
| If true it will print warnings in the console when the output volume is too high, and clamp every sample louder than loudWarningThreshold to it. | |
| float | loudWarningThreshold = 10f |
| The ceiling: a sample louder than this is clamped to it, and the console names the level it reached. 1 is full scale, so the default of 10 only catches real runaways. | |
| bool | overrideSamplingRate = false |
| If true you can override the default Csound control rate with a custom value. The default value is AudioSettings.outputSampleRate. Ksmps will be calculated by Csound so there's no need to set it in your csd. | |
| int | audioRate = 44100 |
The audio sample rate (sr) passed to Csound on initialization. Defaults to AudioSettings.outputSampleRate unless overrideSamplingRate is true. | |
| int | controlRate = 44100 |
The Csound control rate (kr) computed as audioRate / ksmps. Updated automatically whenever audioRate or ksmps changes. | |
| int | ksmps = 32 |
| Intended ksmps value. Stored so that when the audio device changes (sr changes) the control rate is recomputed as kr = sr / ksmps rather than being rounded from the old kr, which would yield a different ksmps. | |
| bool | updateOutputBuffer = false |
When true, the full Csound output buffer (all nchnls channels) is copied into OutputBuffer each DSP block, making it available to visualisers and external audio routing. Off by default to avoid the per-block copy overhead. | |
| float | fadeInSeconds = 0f |
| Ramps the output up from silence over this many seconds when Csound starts, masking the transient of chained sources that have not filled their buffers yet. 0 disables it, which is the default: playback starts at full level. | |
| List< AudioInputRoute > | audioInputRoutes = new List<AudioInputRoute>() |
Audio-rate input routes: each entry reads a named audio channel from another CsoundUnity instance and injects it into this instance's spin buffer before every PerformKsmps call. | |
| volatile INativeAudioInputProvider | nativeAudioInputProvider |
Optional native audio input provider (e.g. CsoundUnityNativeAudioInput). When set, INativeAudioInputProvider.FillSpinBuffer is called once per ksmps boundary on the audio thread, before PerformKsmps. Assign on the main thread; reads on the audio thread are safe due to the volatile qualifier. | |
| bool | muteAudioInputRoutes = false |
| When true, all Audio Input Routes are silenced without removing them. | |
| readonly Dictionary< string, MYFLT[]> | namedAudioChannelDataDict = new Dictionary<string, MYFLT[]>() |
| Named audio channels produced by this instance, shown in the CsoundUnityChild inspector. | |
| string | csoundScore |
| the score to send via editor | |
| List< EnvironmentSettings > | environmentSettings = new List<EnvironmentSettings>() |
| The list of the Environment Settings that will be set on start, using csoundSetGlobalEnv. Each setting can be used to specify the path of an environment variable. These settings will be applied to this CsoundUnity instance when the CsoundUnityBridge is created. | |
| List< string > | webGLAssetsList |
| List of asset paths that will be loaded asynchronously by the WebGL Csound bridge before performance begins (e.g. sample files that must be available in the virtual file system). | |
Static Public Attributes | |
| const string | packageName = "com.csound.csoundunity" |
| The name of this package. | |
| const string | packageVersion = "4.0.0-alpha.3" |
| The version of this package. | |
Package Functions | |
| CsoundSharedBuffer | GetPublishedAudioChannel (string channelName) |
Returns the published snapshot buffer for channelName , or null if this instance has never published that channel. | |
| bool | TryApplyPreset (CsoundUnityPreset preset) |
Static Package Functions | |
| static bool | IsButtonChannel (CsoundChannelController ch) |
A button channel carries an impulse, not a state: the csd zeroes it with its own chnset, which the serialised copy never sees, so a click leaves 1 in the list for good. Everything that pours serialised values back into Csound skips these. A checkbox is excluded: that one does hold a state worth restoring. | |
| static bool | IsRestorable (CsoundChannelController ch) |
Whether the clipboard can carry and restore this channel. It needs a name — the csd's form, and any widget without one, is in the list but is not a channel — and a button is excluded because a momentary trigger has no value worth putting back. | |
| static bool | CsdRequestsMidi (string csd) |
Whether a csd asks Csound for a MIDI device. Comments are stripped before looking: a line that merely mentions -M, as a comment explaining it does, is not an option. | |
Static Package Attributes | |
| const string | GLOBAL_TAG = "(GLOBAL)" |
Properties | |
| string | csoundFileGUID [get] |
| the unique guid of the csd file | |
| string | csoundFileName [get] |
| The file CsoundUnity will try to load. You can only load one file with each instance of CsoundUnity, but you can use as many instruments within that file as you wish.You may also create as many of CsoundUnity objects as you wish. | |
| string | csoundString [get] |
| a string to hold all the csoundFile content | |
| float | LoudLimit [get] |
The sample value the audio paths silence a sample at. PositiveInfinity when the check is off, so a sample that is not a number is caught either way: on RootOutput one of those does not stay inside this instance, it goes into Unity's main output. | |
| string | samplingRateSettingsInfo [get] |
Returns a human-readable summary of the current sampling-rate settings in the form "sr: X, kr: Y, ksmps: Z". Used by the inspector. | |
| List< CsoundChannelController > | channels [get] |
| list to hold channel data | |
| List< string > | availableAudioChannels [get] |
| list to hold available audioChannels names | |
| List< string > | unsupportedWidgets [get] |
| Cabbage widgets present in the current csd that the parser does not build a channel for. Empty when everything in the csd is supported. | |
| bool | IsInitialized [get] |
| Is Csound initialized? | |
| bool | IsWaitingForUserGesture [get] |
| True while a browser is withholding audio until the page gets a real click, tap or key press. Always false off WebGL, so a scene can read it without a platform check. | |
| bool | MeasureDspLoad [get, set] |
| Turns the DSP load measurement on and off. It costs a little time on the audio thread, so it is off unless something is reading it. | |
| float | DspLoad = 0f [get] |
| Exponentially smoothed DSP load: fraction of the DSP time budget used by this instance. 0 = idle, 1 = full budget consumed, >1 = overload. Only meaningful when MeasureDspLoad is true. | |
| double | DspPeakBlockMilliseconds [get] |
| Highest measured DSP block duration in milliseconds since the last reset. Covers the same Csound work as DspLoad; excludes other Unity audio sources. Stays zero until measurement is enabled with MeasureDspLoad; retains its value while measurement is off. | |
| long | DspMeasuredBlocks [get] |
| Number of DSP blocks measured since the last reset. Stays zero until measurement is enabled with MeasureDspLoad; retains its value while measurement is off. | |
| long | DspOverBudgetBlocks [get] |
| Measured blocks whose Csound work exceeded the block's audio time budget. This is a timing counter, not a count reported by the audio device. Stays zero until measurement is enabled with MeasureDspLoad; retains its value while measurement is off. | |
| bool | PerformanceFinished [get] |
| True when Csound's score has ended naturally (all score events have been performed). This is set on the audio thread; for main-thread notification subscribe to OnCsoundPerformanceFinished. | |
| CsoundUnityPreset | CurrentPreset [get] |
The preset currently applied to this instance, or null if none is. | |
| string | CurrentPresetName [get] |
| The name of the current preset, or empty if none is set. | |
| float[] | OutputBuffer [get] |
| The most recently completed DSP output buffer. Contains interleaved samples for all Csound output channels when updateOutputBuffer is true; otherwise the array holds the single-channel Unity output. | |
| int | OutputChannels [get] |
Number of audio channels interleaved in OutputBuffer (equals Csound's nchnls when updateOutputBuffer is true), or 1 before the first block has been published. | |
| int | StartupFadeFrames [get] |
| Length of the startup fade in output frames, or 0 when fadeInSeconds leaves it off. Plain arithmetic over a sample rate cached on the main thread, so the audio paths can ask for it without calling into Unity. | |
| float | LastLoudPeak [get] |
| The last peak an audio path had to clamp, and when it happened. The inspector shows them while it is going on: the console can be cleared, filtered, or simply not watched, and the clamp itself sounds like a loud mix rather than like a fault. | |
| float | LastLoudTime = float.NegativeInfinity [get] |
| bool | HasCompiled [get] |
true when a CSD was assigned and compiled successfully. | |
| static bool | ApplicationIsQuitting [get] |
The static half of IsShuttingDown, for the other components in the package: they make the same main-thread AudioSource calls and need them kept away from FMOD teardown, and this is the part that holds whether or not OnApplicationQuit reached them. | |
| bool | isFinite [get] |
| Csound runs indefinitely — not finite. | |
| bool | isRealtime [get] |
| Csound must run at the system audio rate. | |
| DiscreteTime? | length [get] |
| Infinite generator — length is unknown. | |
| bool | WebGLSpatialization [get, set] |
| Whether the position is sent to the csd on WebGL. | |
Events | |
| CsoundInitialized | OnCsoundInitialized |
| An event that will be executed when Csound is initialized. | |
| ChannelsUpdated | OnChannelsUpdated |
| Raised after a batch of channels has been written from outside the UI — applying a preset, most of the time. | |
| CsoundStopped | OnCsoundStopped |
| An event that will be executed when Csound is stopped via Stop. | |
| CsoundPerformKsmps | OnCsoundPerformKsmps |
An event fired on the audio thread after every PerformKsmps call. Keep the handler extremely lightweight to avoid audio dropouts. | |
| CsoundPerformanceFinishedDelegate | OnCsoundPerformanceFinished |
| An event fired on the main thread when Csound performance ends naturally (score complete). CsoundUnity will call Stop immediately after firing this event. | |
Runs Csound inside a scene: compiles a .csd, performs it while the scene plays, and exposes its channels to the rest of the game.
Sending MIDI to Csound from C#. The receiving side of the same subsystem is in this folder too: CsoundUnityMidiInput and the per-platform receivers beside it.
IAudioGenerator and RootOutput implementations for CsoundUnity (Unity 6+).
Add it to a GameObject and assign a CSD. An AudioSource is required and added automatically: the audio Csound produces is handed to it, so the mixer, effects and 3D positioning apply as they would to a clip.
Compilation is asynchronous. Check IsInitialized, or subscribe to OnCsoundInitialized, before reading or writing channels.
Several instances can coexist in one scene, each compiling its own CSD, and the named audio channels of one can be routed into the input of another.
This file is a partial extension of CsoundUnity. Depending on CsoundUnity._audioPath:
GeneratorInstance pipeline and routed through an AudioSource and the AudioMixer. RootOutputInstance pipeline and mixed additively into the main output, bypassing the AudioMixer entirely. No AudioSource is required. In both cases the same CsoundUnityBridge is reused, so all existing CsoundUnity API calls continue to work unchanged.
Controls how discrete channels (button, checkbox, combobox) are handled during BlendPresets.
| Enumerator | |
|---|---|
| Ignore | Discrete channels are not modified during the blend. Default. |
| NearestCorner | Discrete channels take the value from whichever corner currently has the highest weight. |
Controls how discrete channels (button, checkbox, combobox) are handled during MorphToPreset.
| Enumerator | |
|---|---|
| SnapAtEnd | Discrete channels are applied only at the very end, together with SetPreset. Default. |
| SnapAtMidpoint | Discrete channels snap to the target value when the interpolation parameter crosses 0.5. |
| SnapAtStart | Discrete channels are set to the target value immediately when the morph begins. |
The enum representing the Csound Environment Variables.
| Enumerator | |
|---|---|
| SFDIR | Default directory for sound files. Used if no full path is given for sound files. |
| SSDIR | Default directory for input (source) audio and MIDI files. Used if no full path is given for sound files. May be used in conjunction with SFDIR to set separate input and output directories. Please note that MIDI files as well as audio files are also sought inside SSDIR. |
| SADIR | Default directory for analysis files. Used if no full path is given for analysis files. |
| SFOUTYP | Sets the default output file type. Currently only 'WAV', 'AIFF' and 'IRCAM' are valid. This flag is checked by the csound executable and the utilities and is used if no file output type is specified. |
| INCDIR | Include directory. Specifies the location of files used by |
| OPCODE7DIR | Defines the location of csound opcode plugins for the single precision float (32-bit) version. |
| OPCODE7DIR64 | Defines the location of csound opcode plugins for the double precision float (64-bit) version. |
| SNAPDIR | Is used by the FLTK widget opcodes when loading and saving snapshots. |
| CSOUND7RC | Points at a Csound configuration file holding command line flags. Only the csound executable reads it, so a host that embeds the library, as CsoundUnity does, is not affected by this setting. |
| CSSTRNGS | In Csound 5.00 and later versions, the localisation of messages is controlled by two environment variables CSSTRNGS and CS_LANG, both of which are optional. CSSTRNGS points to a directory containing .xmg files. |
| CS_LANG | Selects a language for csound messages. |
| RAWWAVE_PATH | Is used by the STK opcodes to find the raw wave files. Only relevant if you are using STK wrapper opcodes like STKBowed or STKBrass. |
| CSNOSTOP | If this environment variable is set to "yes", then any graph displays are closed automatically at the end of performance (meaning that you possibly will not see much of them in the case of a short non-realtime render). Otherwise, you need to click "Quit" in the FLTK display window to exit, allowing for viewing the graphs even after the end of score is reached. |
| MFDIR | Default directory for MIDI files. Used if no full path is given for MIDI files. Please note that MIDI files are sought in SSDIR and SFDIR as well. |
| CS_OMIT_LIBS | Allows defining a list of plugin libraries that should be skipped. Libraries can be separated with commas, and don't require the "lib" prefix. Csound reads this one straight from the process environment, which this setting does not write to. |
| CS_USER_PLUGINDIR | Where Csound looks for the user's own plugin opcodes, separately from the opcode directory the package sets for itself. This is the place to put your own opcodes without touching what CsoundUnity ships. |
| CS_UDO_DIR | Where Csound looks for User Defined Opcodes ( |
|
inline |
Add an audio channel to the list that can be used in CsoundUnityChild.
| channel | The channel to be added |
|
inline |
Adds a new audio input route to this instance at runtime.
The route injects audio from source 's named channel sourceChannelName into Csound's spin buffer at destSpinChannel before every PerformKsmps.
If adding the route would create a circular dependency (e.g. A→B→A), the method logs a warning and returns false without modifying the list.
| source | The CsoundUnity instance to read audio from. |
| sourceChannelName | Named audio channel on the source (e.g. "audioL" or "main_out_0"). |
| destSpinChannel | Spin buffer channel index on this instance (default 0). |
| level | Volume multiplier applied to the source signal (0–2, default 1). |
| forceConnection | When true the route is added even if the source is not initialised yet. |
true; route added anyway. null; route was NOT added.
|
inline |
Adds the indicated sample into the audio input working buffer (spin); this only ever makes sense before calling PerformKsmps(). The frame and channel must be in bounds relative to ksmps and nchnls. NB: the spin buffer needs to be cleared at every k-cycle by calling ClearSpin().
| frame | Frame index within the current ksmps block (0-based). |
| channel | Input channel index (0-based). |
| sample | The sample value to add. |
|
inline |
Bilinear blend of four presets placed at the corners of a unit square.
Corner mapping: a = (0,0), b = (1,0), c = (0,1), d = (1,1).
Continuous channels are interpolated bilinearly — the sliders, plus both axes of an xypad, hrange or vrange. Discrete channels (button, checkbox, combobox) follow discreteMode .
Call this every frame (e.g. from CsoundUnityVectorMorph) to drive real-time vector synthesis.
| a | Preset at corner (0,0). |
| b | Preset at corner (1,0). |
| c | Preset at corner (0,1). |
| d | Preset at corner (1,1). |
| position | Normalised 2-D blend position, clamped to [0,1] on each axis. |
| discreteMode | How button/checkbox/combobox channels are resolved during the blend. |
| delegate void Csound.Unity.CsoundUnity.ChannelsUpdated | ( | ) |
The delegate of the event OnChannelsUpdated.
|
inline |
Clears the input buffer (spin).
|
inline |
Returns true if the csd file was compiled without errors.
true when Csound compilation succeeded; otherwise false.
|
inline |
Parse, and compile the given orchestra from an ASCII string, also evaluating any global space code (i-time only) this can be called during performance to compile a new orchestra. This sample shows how to use CompileOrc.
| orcStr | The orchestra string to compile. |
After CsoundReset, compilation keeps audio suspended until CsoundStart is called explicitly.
|
inline |
Convert a JSON preset into a Scriptable Object preset to be written at the specified path. If path is empty the converted preset will be saved inside the Assets folder.
| path | Path to the source JSON preset file. |
| destination | Target directory inside the Assets folder where the ScriptableObject will be written. |
|
inline |
Puts this instance's control channels on the system clipboard, as the same JSON a CsoundUnityPreset is saved in — so a clipboard snapshot and a saved .json preset are interchangeable, and channels can be pasted into a chat window as readily as back into an inspector.
For the quick pass a preset asset is too heavy for: try a change, dislike it, paste the old values back. Works in play mode.
true when something was copied.
|
inline |
Same as CopyTableIn but passing a float array.
| table | The function table number to write to. |
| source | Float array whose values will be copied into the table. |
|
inline |
Copy the contents of a supplied array into a function table The table number is assumed to be valid, and the destination needs to have sufficient space to receive all the function table contents.
| table | the number of the table |
| source | the supplied array |
|
inline |
Queues a snapshot of the source for a later performance cycle.
| 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 on the calling thread.
A null request means the write was not queued.
| 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 |
Copy the contents of a function table into a supplied array dest The table number is assumed to be valid, and the destination needs to have sufficient space to receive all the function table contents.
| table | The function table number to read from. |
| dest | Output array that receives the table contents. |
|
inline |
Queues a read into an array filled during a later performance cycle.
Use the overload with a request to determine when the array is ready.
| 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 the destination and a request to poll on the calling thread.
A null request means the read was not queued. Only read the destination after CsoundTableCopyRequest.Succeeded is true.
| 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 |
Creates a table with the supplied float samples. Can be called during performance.
| tableNumber | The Csound function table number to create. |
| samples | Float array of samples to populate the table with. |
|
inline |
Called by Unity when AudioSource.generator = this is set (or when a scene with a serialized generator reference is loaded). Creates the unmanaged CsoundRealtime and CsoundControl structs and hands them to Unity via context.AllocateGenerator.
| context | The control thread context Unity passes in. |
| nestedFormat | The format of a nested graph, or null for the output's own. |
| creationParameters | What Unity asks the instance to be created with. |
|
inlinestatic |
Create a CsoundUnityPreset from a presetName, csoundFileName and a list of CsoundChannelControllers.
| presetName | Name of the preset (defaults to "CsoundUnityPreset" if empty). |
| csoundFileName | Name of the CSD file this preset is associated with. |
| channels | Channel controllers whose values will be deep-copied into the preset. |
|
inlinestatic |
Create a CsoundUnityPreset from a presetName and presetData.
PresetData should be a CsoundUnityPreset in the JSON format.
It will use the presetName parameter if not empty, if presetName is empty it will use preset.presetName, if also preset.presetName is empty it will use "CsoundUnityPreset" as a default name.
| presetName | Name override; if empty the name embedded in presetData is used. |
| presetData | JSON string representing a CsoundUnityPreset. |
null if the JSON could not be parsed.
|
inline |
Creates a table with the supplied samples. Can be called during performance.
| tableNumber | The Csound function table number to create. |
| samples | MYFLT array of samples to populate the table with. |
|
inline |
Creates an empty table, to be filled with samples later. Please note that trying to read the samples from an empty folder will produce a crash. Can be called during performance.
| tableNumber | The number of the newly created table |
| tableLength | The length of the table in samples |
AudioSettings.outputSampleRate
|
inlinestaticpackage |
Whether a csd asks Csound for a MIDI device. Comments are stripped before looking: a line that merely mentions -M, as a comment explaining it does, is not an option.
| csd | The whole csd, as text. |
| delegate void Csound.Unity.CsoundUnity.CsoundInitialized | ( | ) |
The delegate of the event OnCsoundInitialized.
| delegate void Csound.Unity.CsoundUnity.CsoundPerformanceFinishedDelegate | ( | ) |
The delegate of the event OnCsoundPerformanceFinished.
| delegate void Csound.Unity.CsoundUnity.CsoundPerformKsmps | ( | ) |
The delegate of the event OnCsoundPerformKsmps.
|
inline |
Returns the Csound instance to its pre-compilation state, keeping it alive and reusable: the orchestra and the control channels are gone afterwards. Compile again before performing, and set the channel values again. The engine settings are re-armed here, so the instance keeps the host sample rate, ksmps and audio IO it was created with.
Prefer Restart, which stops the audio path and builds a fresh instance: it is the path everything in the package takes, and the one the samples use. This is the lower-level door, for a scene that wants to keep the same instance and compile something else into it. To reuse this instance, wait for the new orchestra, compile it with CompileOrc, then call CsoundStart explicitly. Compilation alone does not resume audio. Send score events and set the channel values again. Register new named audio channels with AddAudioChannel(string); the new orchestra is not automatically parsed for them. Expect a gap between reset and the new performance. Unavailable on WebGL.
|
inline |
Starts the compiled orchestra after CsoundReset and enables performance. Call CompileOrc first. Starting an already running instance is a no-op.
Stop disposes the instance. Use Initialize or Restart after Stop, rather than CsoundStart.
| delegate void Csound.Unity.CsoundUnity.CsoundStopped | ( | ) |
The delegate of the event OnCsoundStopped.
|
inline |
Get the 0 dBFS amplitude reference value as set by the 0dbfs statement in the orchestra.
|
inline |
Copy numeric data and its axis sizes under one channel lock, including when producers resize.
| name | The channel name. |
| destination | Destination for the whole current array. |
| sizes | Destination for the current axis sizes. |
| info | Metadata corresponding to this copy, or required capacity on BufferTooSmall. |
|
inline |
Copy a numeric array into a reusable flat buffer; unused trailing entries are unchanged.
| name | The channel name. |
| destination | Destination for the whole current array. |
| length | Number of elements copied, or required when BufferTooSmall is returned. |
|
inline |
Read array metadata and axis sizes without creating a channel or allocating a buffer.
| name | The channel name. |
| sizes | Destination for axis sizes; unused trailing entries are unchanged. |
| info | Current metadata, also returned when a supplied buffer is too small. |
|
inline |
Copy audio blocks and their axis sizes under one channel lock, including when producers resize.
| name | The channel name. |
| destination | Destination for ElementCount × ksmps samples. |
| sizes | Destination for the current axis sizes. |
| info | Metadata corresponding to this copy, or required capacity on BufferTooSmall. |
|
inline |
Copy an audio array into a reusable flat buffer; unused trailing entries are unchanged.
| name | The channel name. |
| destination | Destination for ElementCount × ksmps samples. |
| length | Number of samples copied, or required when BufferTooSmall is returned. |
|
inline |
Gets a Csound Audio channel. Used in connection with a chnset opcode in your Csound instrument.
| channel | Name of the Csound audio channel to read. |
null if not initialized.
|
inline |
Zero-allocation overload: reads the named audio channel directly into dest without any managed or native heap allocation. Prefer this on hot audio-thread paths (e.g. inside OnAudioFilterRead or a ksmps callback) to avoid GC pressure and the periodic audio dropouts it causes.
| channel | Name of the Csound audio channel to read. |
| dest | Pre-allocated destination array (at least ksmps long). Null or empty arrays are ignored. |
| ArgumentException | A non-empty destination is shorter than ksmps. |
|
inline |
Returns a reader for the audio this instance publishes on a named audio channel: one finished block at a time, readable from any thread.
| channelName | A channel the CSD writes with chnset, or one of the automatic output channels main_out_0, main_out_1, … |
null for an empty name. Call it once and keep the reader: each one carries its own position in the stream, so two readers on the same channel both receive every block. This is the supported way to take audio out of a channel. Reading namedAudioChannelDataDict instead reaches the live working array, which another thread may be half-way through writing.
|
inline |
Returns a sample from a CsoundUnity audio channel This is useful if you want to update an AudioSource using the OnAudioFilterRead callback Internally it uses the namedAudioChannelDataDict buffer, that is usually used to update CsoundUnityChild scripts Using this together with AddAudioChannel(string) and RemoveAudioChannel(string) allows you to create new audio channels at runtime.
| channel | An existing audio channel buffer |
| sample | Zero-based sample index within the channel buffer. |
Reads the live working buffer, which the audio thread is writing into. Called from the main thread it may therefore return a sample from a block that is only half produced, and it will keep returning the last block written if the instance stops updating it (muted, paused, or finished). Fine for metering and visualisation, where an occasional wrong sample does not matter; not a safe way to move audio between instances. Use GetAudioChannelReader, which delivers finished blocks and is what audio input routing and CsoundUnityChild read.
|
inline |
Gets a Csound channel. Used in connection with a chnset opcode in your Csound instrument, or set with SetChannel.
| channel | Name of the Csound channel to read. |
|
inline |
Reads a Csound control channel and delivers the result via callback . On non-WebGL platforms the callback is invoked synchronously before this method returns. On WebGL the read is dispatched to the AudioWorklet thread; the callback fires on the main thread once the value is available (typically within the same or the next frame).
| channel | Name of the control channel to read. |
| callback | Called with the value. |
|
inline |
Returns the serialized CsoundChannelController for the named channel, as parsed from the CSD file by ParseCsdFile.
| channel | The channel name to look up. |
null if not found.
|
inline |
Blocking method to get a list of the channels from Csound, not from the serialized list of this instance. 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.
ChannelInfo, or null if not initialized.
|
inline |
Returns the current performance time in samples.
|
inline |
Get Environment path.
| envType | the type of the environment to get |
|
inline |
Get the current control rate.
|
inline |
Get the number of audio sample frames per control sample.
|
inline |
Get the number of output channels.
nchnls, or 0 if not initialized.
|
inline |
Get the number of input channels.
nchnls_i, or 0 if not initialized.
|
inline |
Get a sample from Csound's audio output buffer.
| frame | Frame index within the current ksmps block (0-based). |
| channel | Output channel index (0-based). |
|
inlinepackage |
Returns the published snapshot buffer for channelName , or null if this instance has never published that channel.
|
inline |
Read a complete N+2 float frame and matching metadata; neither partial copies nor channel creation occur.
| name | The channel name. |
| destination | Reusable float buffer, independent of native audio precision; unused tails are unchanged. |
| info | Matching metadata, also returned on BufferTooSmall so FrameLength reports required capacity. |
|
inline |
Read PVS layout and frame counter without creating a channel.
| name | The channel name. |
| info | Current FFT/hop/window/format and frame counter. |
|
inline |
Get Csound's audio input buffer.
null if not initialized.
|
inline |
Get Csound's audio output buffer.
null if not initialized.
|
inline |
Get the current sample rate.
|
inline |
Read UTF-8 string values and their matching shape atomically; decode outside the native spin lock.
| name | The channel name. |
| destination | Destination for all current string elements. |
| sizes | Destination for current axis sizes. |
| info | Metadata corresponding to the snapshot, or required capacity on BufferTooSmall. |
|
inline |
Read a complete string array into a reusable container. Changed strings allocate; unchanged values retain their references. Runs outside audio callbacks and does not create a channel.
| name | The channel name. |
| destination | Destination for all current elements; unused trailing entries are unchanged. |
| length | Elements copied, or required capacity on BufferTooSmall. |
|
inline |
Get a Csound string channel. Used in connection with a chnset opcode in your Csound instrument, or set with SetStringChannel.
| name | Name of the Csound string channel to read. |
null if the component is not initialized. An initialized component returns an empty string if the read is unavailable, including on WebGL or while another operation holds the bridge's channel gate.
|
inline |
Stores values to 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 filled with the table contents. |
| numTable | The function table number to read. |
|
inline |
Stores the arguments used to generate function table 'tableNum' in args, and returns the number of arguments used. If the table does not exist, args is set to NULL and -1 is returned. NB: the argument list starts with the GEN number and is followed by its parameters. eg. f 1 0 1024 10 1 0.5 yields the list {10.0,1.0,0.5}.
| args | Output array filled with the GEN number followed by its parameters. |
| index | The function table number to query. |
|
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 to query. |
|
inline |
Retrieves a single sample from a Csound function table.
| tableNumber | The function table number. |
| index | Zero-based sample index within the table. |
|
inline |
Returns the Csound version number times 1000 (5.00.0 = 5000).
|
inline |
Initializes CsoundUnity manually. Only works if initializeOnAwake is false, or after a Stop. Silently returns if already initialized or initializing.
|
inline |
Create an i[], k[], S[] or a[] channel, or verify an existing channel's exact type and shape. Initialization may allocate and briefly suspend Unity audio processing; call during setup, never from an audio callback. Existing channels are not resized.
| name | The channel name. |
| type | Init, Control, String or Audio elements. |
| sizes | One nonnegative size per axis. |
|
inline |
Create or verify a fixed-layout PVS channel during setup. May allocate and briefly suspend Unity audio.
| name | A nonempty UTF-8 channel name. |
| fftSize | Even FFT size N. |
| overlap | Analysis hop in audio samples; at least global ksmps and greater than 10. |
| windowSize | Analysis window size in samples. |
| windowType | Built-in Csound window code (0-9); defaults to Hann. |
| format | Meaning of each float pair. |
|
inlinestaticpackage |
A button channel carries an impulse, not a state: the csd zeroes it with its own chnset, which the serialised copy never sees, so a click leaves 1 in the list for good. Everything that pours serialised values back into Csound skips these. A checkbox is excluded: that one does hold a state worth restoring.
| ch | The channel controller to test. |
true for a button-type channel.
|
inlinestaticpackage |
Whether the clipboard can carry and restore this channel. It needs a name — the csd's form, and any widget without one, is in the list but is not a channel — and a button is excluded because a momentary trigger has no value worth putting back.
Copy and paste share this so the two report the same number, instead of one counting controllers and the other counting what it managed to apply.
|
inline |
Reads a CSD with UnityWebRequest and loads it, then reports the outcome to onLoaded . Works for the cases the synchronous overload refuses: StreamingAssets on any platform, and http/https URLs.
The component must be active and enabled, since the read runs as a coroutine.
| path | Path or URL to the .csd file. |
| onLoaded | Called with true when Csound ends up running the CSD, false when the read failed, the CSD did not compile, or startNow is false. |
| startNow | Passed through to LoadCsdFromString. |
|
inline |
Reads a CSD from a file and loads it, the runtime counterpart of assigning a csd asset. Equivalent to reading the file yourself and calling LoadCsdFromString.
Use this for real filesystem paths — Application.persistentDataPath, an absolute path, anything the user picked. For a URL, or for StreamingAssets on Android and WebGL where the folder lives inside the compressed application package and cannot be read as a file, use the overload that takes a callback: this one refuses with an explicit error rather than failing quietly.
| path | Path to the .csd file. |
| startNow | Passed through to LoadCsdFromString. |
true when Csound is running the CSD from the file by the time this returns. false when the file could not be read, when it did not compile, or when startNow is false. Every case logs its reason.
|
inline |
Loads a CSD from a raw string at runtime, without requiring a .csd asset.
This is the runtime counterpart of SetCsd (which is editor-only and works via an asset GUID). Use it for dynamically generated or downloaded CSDs. The Csound bridge compiles directly from the stored string, so no file is needed.
Channel controllers, named audio channels, nchnls and ksmps are parsed from the string exactly as SetCsd parses them from a file.
Startup behaviour when startNow is true:
Awake has run it will not run again, so there is nobody else left to compile the string. If Awake has not run yet (audioSource not resolved), only the fields are populated; initialization is deferred to Awake or a later Initialize call, because Init depends on Awake-time state (DSP buffer size, AudioSource).
| csdContent | The full CSD text to load. |
| startNow | When true, (re)initialize Csound after loading; when false, only store and parse the CSD (call Initialize yourself). |
true when Csound is running the new CSD by the time this returns. false otherwise, which is not always a failure: it is also what you get when startNow is false, or when Awake has not run yet and the CSD was only stored. A compile error also lands here, and is logged.
|
inline |
Load a global preset on this CsoundUnity instance from a JSON file found at path. The JSON file should represent a Global Preset, ie a complete CsoundUnity instance.
This also sets the global preset, overriding the current content of this CsoundUnity instance.
This could have unintended consequences in certain situations. You could need to disable this CsoundUnity GameObject and enable it again to restore the Csound internal state.
| path | The path must point to an existing JSON file |
|
inline |
Loads all plugins from a given directory.
| dir | Path to the directory containing Csound plugin libraries. |
|
inline |
Loads a preset from a JSON file. The JSON file should represent a CsoundUnityPreset.
This doesn't set the preset.
You should use the Action to get the reference of the loaded preset. This is needed because of the async nature of this method, that uses a WebRequest on Android and iOS.
Example of usage:
| path | The path must point to an existing JSON file |
| onPresetLoaded | Called with the loaded preset, or with null when the file could not be read. |
|
inline |
Smoothly interpolates all continuous channels — the sliders, plus both axes of an xypad, hrange or vrange — from their current values to the target preset's values over the given duration. An optional AnimationCurve controls easing; pass null for linear interpolation. The returned Coroutine can be passed to StopMorph to cancel mid-way. If duration is zero or negative, the preset is applied immediately.
| preset | The target preset to morph towards. |
| duration | Duration of the morph in seconds. Zero or negative applies the preset instantly. |
| curve | Optional easing curve evaluated over [0,1]; null = linear. |
| onComplete | Optional callback invoked when the morph finishes. |
| discreteMode | Controls when button/checkbox/combobox channels are snapped to their target values. |
null when the preset was applied instantly.
|
inline |
Raises OnChannelsUpdated. Call it after writing several channels yourself with SetChannel(string, MYFLT), so the UI components re-read them.
Applying a preset or pasting channels does this already. It is a separate call rather than something SetChannel does on its own because a single write happens on every frame a slider moves, and firing there would have every widget re-read on every frame.
|
inlinestatic |
Parses the CSD file's Cabbage widget section and returns a list of CsoundChannelController objects describing every slider, button, checkbox, combobox, xypad, and similar widget found.
| filename | Full path to the CSD file. |
null if the file does not exist or is empty.
|
inlinestatic |
Parses the CSD file and returns the names of all audio-rate channels declared via chnset avar, "channel name" (channels driven by a- or ga-rate variables with literal string names).
| filename | Full path to the CSD file. |
null if the file does not exist or is empty.
|
inlinestatic |
Parses ksmps from the global header of the CSD's <CsInstruments> section. Returns the explicit ksmps value if declared; otherwise computes round(sr / kr) if both are present; otherwise returns 0 (not specified). Only scans lines before the first instr declaration.
| filename | Full path to the CSD file. |
|
inlinestatic |
Reads the CSD file and returns the value of nchnls (output channels) declared in the orchestra header. Correctly ignores nchnls_i (input channels). Returns 0 when the directive is absent — in that case Csound defaults to 1, but callers should treat 0 as "unknown / not specified".
| filename | Full path to the CSD file. |
nchnls value, or 0 if not found.
|
inlinestatic |
String equivalent of ParseCsdFile — parses the Cabbage widget section from CSD text already in memory (no file path), e.g. from LoadCsdFromString.
| csdContent | The full CSD text. |
null if the content is empty.
|
inlinestatic |
Parses a CSD string (already in memory) for named audio channels written with chnset. Runtime equivalent of ParseCsdFileForAudioChannels used when only the CSD content is available (no file path), e.g. during Init on first play after a fresh package import where the inspector was never opened to trigger SetCsd.
| csdContent | The full CSD text. |
|
inlinestatic |
String equivalent of ParseCsdFileForKsmps, used when only the CSD content is available (no file path), e.g. from LoadCsdFromString.
| csdContent | The full CSD text. |
|
inlinestatic |
String equivalent of ParseCsdFileForNchnls, used when only the CSD content is available (no file path), e.g. from LoadCsdFromString.
| csdContent | The full CSD text. |
nchnls value, or 0 if not found.
|
inlinestatic |
Cabbage widget names that appear in a csd but that the parser does not build a channel for, so the inspector and the UI generator can say so instead of silently showing less than the csd declares.
A line counts as a widget when it carries a bounds( attribute. keyboard is deliberately not reported: CsoundUnityKeyboard exists, it is simply built in the scene rather than read from the csd.
| csdContent | The full CSD text. |
|
inlinestatic |
Parses a Cabbage .snaps file and returns a list of CsoundUnityPreset objects, one per snapshot entry, with channel metadata filled in from the companion CSD.
| csdPath | Full path to the CSD file used as the reference for channel types and ranges. |
| snapPath | Full path to the Cabbage .snaps file to parse. |
| FormatException | A channel entry has an invalid numeric value. |
|
inline |
Applies channels held on the clipboard in the CsoundUnityPreset JSON format.
Unlike SetPreset(CsoundUnityPreset) this does not refuse when the clipboard came from another csd. Refusing would defeat the purpose — the clipboard is for moving values by hand, between instances and between csds that share channel names — so the channels this csd declares are applied and the rest are reported.
true when at least one channel was applied.
|
inline |
Process a ksmps-sized block of samples.
> 0, not != 0.
|
inline |
Removes all audio input routes from this instance.
|
inline |
Removes an audio channel from the list that can be used in CsoundUnityChild.
| channel | The channel to be removed |
|
inline |
Removes all audio input routes whose source is source .
| source | The instance whose routes into this one are removed. |
|
inline |
Removes the specific audio input route that matches all three key fields.
| source | The instance the route comes from. |
| sourceChannelName | The named audio channel the route reads. |
| destSpinChannel | The spin channel the route writes into. |
|
inline |
Removes the audio input route at index in audioInputRoutes.
| index | Index of the route in audioInputRoutes. |
|
inline |
Requests a statistics reset at the next measured DSP block. Call from the main thread. Measurement must be enabled for the reset to take effect.
|
inline |
Stops the current Csound instance and reinitializes it from scratch.
|
inline |
Rewinds a compiled Csound score to the time specified with SetScoreOffsetSeconds().
|
inline |
Save a serialized copy of this CsoundUnity instance. Similar behaviour as saving a Unity Preset from the inspector of the CsoundUnity component, but this can be used at runtime.
| presetName | Name for the global preset file. |
| path | Target directory; defaults to Application.persistentDataPath if null. |
| overwriteIfExisting | When false, a counter suffix is appended to avoid overwriting existing files. |
|
inlinestatic |
Save the specified CsoundUnityPreset as JSON, at the specified path. If a file exists at the specified path, it will be overwritten if overwriteIfExisting is true.
| preset | The preset to serialize to JSON. |
| path | Target directory path; defaults to Application.persistentDataPath if null. |
| overwriteIfExisting | When false, a counter suffix is appended to avoid overwriting existing files. |
|
inlinestatic |
Save a preset as JSON from a list of CsoundChannelController, specifying the related CsoundFileName and the presetName. See SavePresetAsJSON(CsoundUnityPreset, string, bool).
| channels | Channel controllers to store in the preset. |
| csoundFileName | Name of the CSD file this preset is associated with. |
| presetName | Name for the preset. |
| path | Target directory; defaults to Application.persistentDataPath if null. |
| overwriteIfExisting | When false, a counter suffix is appended to avoid overwriting existing files. |
|
inline |
Save a preset as JSON using CsoundChannelControllers and CsoundFileName from this CsoundUnity instance. See SavePresetAsJSON(CsoundUnityPreset, string, bool).
| presetName | Name for the preset. |
| path | Target directory; defaults to Application.persistentDataPath if null. |
| overwriteIfExisting | When false, a counter suffix is appended to avoid overwriting existing files. |
|
inline |
Save a CsoundUnityPreset of this CsoundUnity instance at the specified path, using the specified presetName. The current csoundFileName and list of CsoundChannelControllers will be saved in the preset. If no presetName is given, a default one will be used.
| presetName | Name for the preset (defaults to "CsoundUnityPreset" if empty). |
| path | Target directory path inside the Assets folder; defaults to Assets root if null. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Send a score event to Csound in the form of "i1 0 10 ....
| scoreEvent | the score string to send |
|
inline |
Replace all numeric elements of the channel's current shape; source length must match exactly.
| name | The channel name. |
| source | Flat i[] or k[] values, in Csound array order. |
|
inline |
Replace all audio samples of the channel's current shape; source length must match exactly.
| name | The channel name. |
| source | Flat a[] blocks: all ksmps samples of element 0, then element 1, and so on. |
|
inline |
Sets a Csound channel. Useful for setting presets at runtime. Used in connection with a chnget opcode in your Csound instrument.
Only the value is taken from channelController . The widget definition — type, range, skew, increment, options, bounds — belongs to the csd.
| channelController | The channel controller to take the value from. |
|
inline |
Sets a Csound channel. Used in connection with a chnget opcode in your Csound instrument.
val is the value as Csound holds it, so a combobox takes the 1-based Cabbage index. The serialized channel is updated through CsoundChannelController.SetFromCsoundValue.
| channel | Name of the Csound channel. |
| val | Value to assign to the channel, in Csound's terms. |
|
inline |
Sets a list of Csound channels.
| channelControllers | The list of channel controllers to apply. |
| excludeButtons | When true (default), button-type channels are skipped. |
|
inline |
Sets the CSD from a project asset, identified by its AssetDatabase GUID.
Editor only, and inherently so: a GUID is an AssetDatabase concept and there is no AssetDatabase in a build. The runtime equivalent is LoadCsdFromString(string, bool) — read the CSD text however suits the platform (a TextAsset, StreamingAssets, the network) and hand it the string.
| guid | the guid of the csd file asset |
|
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 |
Set a global preset to this CsoundUnity instance using a presetName and presetData.
Preset data should represent a CsoundUnity instance in JSON format.
This overrides the current content of this CsoundUnity instance.
This could have unintended consequences in certain situations. You could need to disable this CsoundUnity GameObject and enable it again to restore the Csound internal state.
This updated CsoundUnity instance will be returned.
| presetName | Name to assign (overrides the name embedded in the JSON). |
| presetData | JSON string of a full CsoundUnity instance serialization. |
|
inline |
Set a sample in Csound's input buffer, overwriting any existing value.
| frame | Frame index within the current ksmps block (0-based). |
| channel | Input channel index (0-based). |
| sample | The sample value to write. |
|
inline |
Set a CsoundUnityPreset to this CsoundUnity instance.
If the preset csoundFileName is different from this CsoundUnity instance csoundFileName the preset will not be set and an error will be logged.
| preset | The preset to apply to this instance. |
|
inline |
Set a CsoundUnityPreset to this CsoundUnity instance using presetData.
The set preset will be returned. The name of the preset will be the one found inside presetData, if not empty. Otherwise a default presetName will be used.
Preset data should represent a CsoundUnityPreset in JSON format.
If the preset csoundFileName is different from this CsoundUnity instance csoundFileName the preset will not be set and an error will be logged.
| presetData | JSON string representing a CsoundUnityPreset. |
null if loading or applying it failed.
|
inline |
Set a CsoundUnityPreset to this CsoundUnity instance using a presetName and presetData. The set preset will be returned.
Preset data should represent a CsoundUnityPreset in JSON format.
If the preset csoundFileName is different from this CsoundUnity instance csoundFileName the preset will not be set and an error will be logged.
| presetName | Name to assign to the preset (overrides the name in the JSON). |
| presetData | JSON string representing a CsoundUnityPreset. |
null if loading or applying it failed.
|
inline |
Write exactly N+2 floats and increment the frame counter on success. Use once per new spectral frame.
| name | The channel name. |
| source | Exactly N+2 floats in the destination's pair format. |
|
inline |
Write a snapshot with matching FFT/hop/window/format, preserving its frame counter.
| name | The channel name. |
| source | Exactly frame.FrameLength floats. |
| frame | Snapshot metadata from a compatible source channel, including its frame counter. |
|
inline |
Csound score events prior to the specified time are not performed, and performance begins immediately at the specified time (real-time events will continue to be performed as they are received). Can be used by external software, such as a VST host, to begin score performance midway through a Csound score, for example to repeat a loop in a sequencer, or to synchronize other events with the Csound score.
| value | Time offset in seconds from the start of the score. |
|
inline |
Replace all S[] elements from UTF-8 text without resizing the channel. Null elements become empty strings; embedded null characters are rejected. Native buffers may grow. Not audio-thread safe.
| name | The channel name. |
| source | Exactly one value per current element. |
|
inline |
Sets a string channel in Csound. Used in connection with a chnget opcode in your Csound instrument.
| channel | Name of the Csound string channel. |
| val | String value to assign. |
|
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 slot index to write. |
| value | The value to write into the slot. |
|
inline |
Stops and disposes the current Csound instance. After this, Initialize or Restart can be called to start again.
|
inline |
Stops an in-progress morph started by MorphToPreset. Channel values remain at whatever point the morph reached when stopped.
|
inlinepackage |
|
inline |
Returns true if routing audio from newSource into this instance would create a circular dependency in the audio graph.
The algorithm performs a BFS starting from this node and follows outgoing edges — i.e. it finds every instance X that lists any already-reachable node as one of its audioInputRoutes sources, then checks whether X equals newSource .
Because audioInputRoutes only stores incoming edges, the search must inspect all live CsoundUnity instances in the scene.
| newSource | The instance that would become a source for this one. |
|
inlinestatic |
Write a CsoundUnityPreset at the specified path inside the Assets folder. You can pass a full path, the Assets folder path will be extracted. Subfolders in the preset name are created as needed; the stored name is the file's leaf name. Overwriting an existing asset preserves its GUID and references.
| preset | The preset ScriptableObject to write. |
| path | Target directory path; the Assets sub-path will be extracted automatically. |
| List<AudioInputRoute> Csound.Unity.CsoundUnity.audioInputRoutes = new List<AudioInputRoute>() |
Audio-rate input routes: each entry reads a named audio channel from another CsoundUnity instance and injects it into this instance's spin buffer before every PerformKsmps call.
| int Csound.Unity.CsoundUnity.audioRate = 44100 |
The audio sample rate (sr) passed to Csound on initialization. Defaults to AudioSettings.outputSampleRate unless overrideSamplingRate is true.
| int Csound.Unity.CsoundUnity.controlRate = 44100 |
| string Csound.Unity.CsoundUnity.csoundScore |
the score to send via editor
| List<EnvironmentSettings> Csound.Unity.CsoundUnity.environmentSettings = new List<EnvironmentSettings>() |
The list of the Environment Settings that will be set on start, using csoundSetGlobalEnv. Each setting can be used to specify the path of an environment variable. These settings will be applied to this CsoundUnity instance when the CsoundUnityBridge is created.
| float Csound.Unity.CsoundUnity.fadeInSeconds = 0f |
Ramps the output up from silence over this many seconds when Csound starts, masking the transient of chained sources that have not filled their buffers yet. 0 disables it, which is the default: playback starts at full level.
In seconds rather than samples so it means the same thing at any output sample rate, and honoured by all three audio paths. Applies from the next Init().
|
staticpackage |
| bool Csound.Unity.CsoundUnity.initializeOnAwake = true |
If true CsoundUnity will initialize automatically in Awake. Set to false to initialize manually by calling Initialize.
| int Csound.Unity.CsoundUnity.ksmps = 32 |
Intended ksmps value. Stored so that when the audio device changes (sr changes) the control rate is recomputed as kr = sr / ksmps rather than being rounded from the old kr, which would yield a different ksmps.
| bool Csound.Unity.CsoundUnity.logCsoundOutput = false |
If true, all Csound output messages will be sent to the Unity output console. Note that this can slow down performance if there is a lot of information being printed.
| bool Csound.Unity.CsoundUnity.loudVolumeWarning = true |
If true it will print warnings in the console when the output volume is too high, and clamp every sample louder than loudWarningThreshold to it.
| float Csound.Unity.CsoundUnity.loudWarningThreshold = 10f |
The ceiling: a sample louder than this is clamped to it, and the console names the level it reached. 1 is full scale, so the default of 10 only catches real runaways.
| bool Csound.Unity.CsoundUnity.mute = false |
Silences this instance's audio output. Csound keeps performing: the score advances, so unmuting drops back in on the beat rather than resuming where it left off, and input (audio input routes, native audio input, clip audio) keeps flowing in.
Instances routed from this one receive silence while it is muted — they do not keep hearing the last block it produced. To stop the DSP work as well, and pick up exactly where it stopped, use pauseProcessing instead.
Not to be confused with AudioSource.mute, which silences this instance's own monitoring but leaves it feeding its routed destinations at full level (and has no effect at all on the RootOutput audio path, which bypasses the AudioSource).
| bool Csound.Unity.CsoundUnity.muteAudioInputRoutes = false |
When true, all Audio Input Routes are silenced without removing them.
| readonly Dictionary<string, MYFLT[]> Csound.Unity.CsoundUnity.namedAudioChannelDataDict = new Dictionary<string, MYFLT[]>() |
Named audio channels produced by this instance, shown in the CsoundUnityChild inspector.
These are the live working arrays, filled sample by sample by the audio thread while a block is being produced. Reading them from another thread — the main thread, or another instance's audio callback — can therefore observe a half-written block, and carries no memory barrier, so on 32-bit ARM a MYFLT can be read torn. Both are audible as intermittent clicks.
Audio input routing does not read this: it reads the completed snapshots published at the end of each block. Anything else that needs this data across threads should do the same, through GetAudioChannelReader, rather than reading here directly.
| volatile INativeAudioInputProvider Csound.Unity.CsoundUnity.nativeAudioInputProvider |
Optional native audio input provider (e.g. CsoundUnityNativeAudioInput). When set, INativeAudioInputProvider.FillSpinBuffer is called once per ksmps boundary on the audio thread, before PerformKsmps. Assign on the main thread; reads on the audio thread are safe due to the volatile qualifier.
| bool Csound.Unity.CsoundUnity.overrideSamplingRate = false |
If true you can override the default Csound control rate with a custom value. The default value is AudioSettings.outputSampleRate. Ksmps will be calculated by Csound so there's no need to set it in your csd.
|
static |
The name of this package.
|
static |
The version of this package.
| bool Csound.Unity.CsoundUnity.pauseProcessing = false |
Suspends this instance: the output is silenced and Csound stops performing, so no DSP work is done at all. The score is frozen, so clearing the flag resumes from exactly where it stopped.
Unlike disabling the GameObject or calling Stop, nothing is torn down: the Csound instance, its state and its channel values are all preserved, and resuming is immediate. Instances routed from this one receive silence while it is paused.
Use mute instead when the instance should stay in time.
| bool Csound.Unity.CsoundUnity.processClipAudio |
If true Csound uses as an input the AudioClip attached to this AudioSource. If false, no processing occurs on the attached AudioClip.
Clip audio keeps reaching Csound while the instance is muted — muting silences the output, not the input, so effects fed by the clip stay warm. It stops under pauseProcessing, where nothing would consume it.
| bool Csound.Unity.CsoundUnity.updateOutputBuffer = false |
When true, the full Csound output buffer (all nchnls channels) is copied into OutputBuffer each DSP block, making it available to visualisers and external audio routing. Off by default to avoid the per-block copy overhead.
| List<string> Csound.Unity.CsoundUnity.webGLAssetsList |
List of asset paths that will be loaded asynchronously by the WebGL Csound bridge before performance begins (e.g. sample files that must be available in the virtual file system).
|
staticgetpackage |
The static half of IsShuttingDown, for the other components in the package: they make the same main-thread AudioSource calls and need them kept away from FMOD teardown, and this is the part that holds whether or not OnApplicationQuit reached them.
|
get |
list to hold available audioChannels names
|
get |
list to hold channel data
|
get |
the unique guid of the csd file
|
get |
The file CsoundUnity will try to load. You can only load one file with each instance of CsoundUnity, but you can use as many instruments within that file as you wish.You may also create as many of CsoundUnity objects as you wish.
|
get |
a string to hold all the csoundFile content
|
get |
The preset currently applied to this instance, or null if none is.
Set it in the inspector to have it applied when Csound starts. A preset built at runtime from JSON lives here too, but only until the next reload: Unity serialises a reference to an asset, and one of those has no asset behind it.
|
get |
The name of the current preset, or empty if none is set.
Kept apart from CurrentPreset because the two can disagree: a global preset is a snapshot of the whole component rather than a CsoundUnityPreset, so it can only leave a name behind.
|
get |
Exponentially smoothed DSP load: fraction of the DSP time budget used by this instance. 0 = idle, 1 = full budget consumed, >1 = overload. Only meaningful when MeasureDspLoad is true.
|
get |
Number of DSP blocks measured since the last reset. Stays zero until measurement is enabled with MeasureDspLoad; retains its value while measurement is off.
|
get |
Measured blocks whose Csound work exceeded the block's audio time budget. This is a timing counter, not a count reported by the audio device. Stays zero until measurement is enabled with MeasureDspLoad; retains its value while measurement is off.
|
get |
Highest measured DSP block duration in milliseconds since the last reset. Covers the same Csound work as DspLoad; excludes other Unity audio sources. Stays zero until measurement is enabled with MeasureDspLoad; retains its value while measurement is off.
|
get |
true when a CSD was assigned and compiled successfully.
Unlike IsInitialized, which is true even when no CSD is assigned, HasCompiled is false when CsoundUnity was started without a CSD, when compilation failed, and after a CsoundReset until the next successful compilation.
|
get |
Csound runs indefinitely — not finite.
|
get |
Is Csound initialized?
|
get |
Csound must run at the system audio rate.
|
get |
True while a browser is withholding audio until the page gets a real click, tap or key press. Always false off WebGL, so a scene can read it without a platform check.
This is the difference IsInitialized cannot express: not initialized yet lasts a few frames on every platform, while this lasts until the page is clicked, and it is the only one of the two a "click to start" notice should follow. The gesture itself needs no handling — the browser delivers it, Csound starts, and OnCsoundInitialized fires as usual.
|
getpackage |
The last peak an audio path had to clamp, and when it happened. The inspector shows them while it is going on: the console can be cleared, filtered, or simply not watched, and the clamp itself sounds like a loud mix rather than like a fault.
|
getpackage |
|
get |
Infinite generator — length is unknown.
|
getpackage |
The sample value the audio paths silence a sample at. PositiveInfinity when the check is off, so a sample that is not a number is caught either way: on RootOutput one of those does not stay inside this instance, it goes into Unity's main output.
|
getset |
Turns the DSP load measurement on and off. It costs a little time on the audio thread, so it is off unless something is reading it.
|
get |
The most recently completed DSP output buffer. Contains interleaved samples for all Csound output channels when updateOutputBuffer is true; otherwise the array holds the single-channel Unity output.
Reading this property pulls the latest block published by the audio thread, so the returned array is always a complete block and never one being rewritten underneath the caller. When no new block has been produced since the last read the previous contents are returned unchanged, so polling faster than the DSP rate is free. Read it from the main thread.
|
get |
Number of audio channels interleaved in OutputBuffer (equals Csound's nchnls when updateOutputBuffer is true), or 1 before the first block has been published.
Read straight from the published block rather than cached when the buffer is fetched, so that reading this before OutputBuffer cannot hand back a stale count.
|
get |
True when Csound's score has ended naturally (all score events have been performed). This is set on the audio thread; for main-thread notification subscribe to OnCsoundPerformanceFinished.
|
get |
Returns a human-readable summary of the current sampling-rate settings in the form "sr: X, kr: Y, ksmps: Z". Used by the inspector.
|
getpackage |
Length of the startup fade in output frames, or 0 when fadeInSeconds leaves it off. Plain arithmetic over a sample rate cached on the main thread, so the audio paths can ask for it without calling into Unity.
|
get |
Cabbage widgets present in the current csd that the parser does not build a channel for. Empty when everything in the csd is supported.
|
getset |
Whether the position is sent to the csd on WebGL.
| ChannelsUpdated Csound.Unity.CsoundUnity.OnChannelsUpdated |
Raised after a batch of channels has been written from outside the UI — applying a preset, most of the time.
The UI components drive their channels but do not watch them, so without this a preset applied while the scene runs changed the sound and left every control where it was. They subscribe here and re-read, the same way they already do for OnCsoundInitialized.
| CsoundInitialized Csound.Unity.CsoundUnity.OnCsoundInitialized |
An event that will be executed when Csound is initialized.
| CsoundPerformanceFinishedDelegate Csound.Unity.CsoundUnity.OnCsoundPerformanceFinished |
An event fired on the main thread when Csound performance ends naturally (score complete). CsoundUnity will call Stop immediately after firing this event.
| CsoundPerformKsmps Csound.Unity.CsoundUnity.OnCsoundPerformKsmps |
An event fired on the audio thread after every PerformKsmps call. Keep the handler extremely lightweight to avoid audio dropouts.
Fires while the instance is muted, since muting silences the output but Csound keeps performing; it does not fire while pauseProcessing is set, because then there is no PerformKsmps to report.
| CsoundStopped Csound.Unity.CsoundUnity.OnCsoundStopped |
An event that will be executed when Csound is stopped via Stop.