CsoundUnityChild is a component that can output AudioChannels found in the csd of the associated CsoundUnity gameObject.
More...
|
| GameObject | csoundUnityGameObject |
| | The gameObject with the CsoundUnity component to load Audio Channels from.
|
| AudioChannels | AudioChannelsSetting = AudioChannels.MONO |
| | Defines if this CsoundUnityChild will use one (MONO) or two (STEREO) channels. MONO reaches every output channel, the way a mono orchestra does on the parent; STEREO maps its two channels to the first two outputs and leaves the rest silent.
|
| float | fadeInSeconds = 0f |
| | Ramps the output up from silence over this many seconds when the component starts producing, masking the transient of joining a parent that is already running. 0 disables it, which is the default: the component starts at full level.
|
| int[] | selectedAudioChannelIndexByChannel |
| | An array containing the selected audiochannel indexes by channel: MONO = 0, STEREO = 1.
|
| List< string > | availableAudioChannels |
| | A list to hold available audioChannels names.
|
| List< MYFLT[]> | namedAudioChannelData = new List<MYFLT[]>() |
| | A list to hold the current audio buffer data for each channel.
|
|
| void | SyncNamedAudioChannelData (float[][] snapshots, int channelCount, int frames) |
| | Copies the blocks this component is about to play into namedAudioChannelData, which is public API and keeps holding the parent's channel data as it always has — Csound units, before this component normalises it.
|
| float[] | GetOutputScratch (int samples) |
| | Scratch buffer for a path that has to build its interleaved output before it can publish it. Grows on demand and is reused, so it allocates on the first block and on a block size change, never in steady state. Audio thread only.
|
| void | PublishOutput (float[] interleaved, int samples, int channels) |
| | Publishes the finished output block for OutputBuffer.
|
|
| static int | PullPublishedChannels (CsoundUnity parent, string[] names, float[][] snapshots, int[] cursors, int[] staleCounts) |
| | Pulls one complete published block per channel from the parent, into snapshots , and answers the longest block any channel had.
|
|
| const int | MaxStaleBlocks = 2 |
| | Consecutive blocks a channel may reuse its snapshot before being treated as silent. One miss is normal — the parent publishes once per DSP buffer and the two callbacks are not ordered — so the tolerance only has to catch a parent that has stopped publishing altogether.
|
|
| float[] | OutputBuffer [get] |
| | The most recently completed block this component put out, interleaved across the AudioSource's output channels.
|
| int | OutputChannels [get] |
| | Number of channels interleaved in OutputBuffer, or 1 before the first block has been published. This is the AudioSource's output channel count, which is not AudioChannelsSetting: a MONO component still puts out stereo, the same signal on both. Read from the published block rather than cached, so reading it before OutputBuffer cannot hand back a stale count.
|
| int | StartupFadeFrames [get] |
| | Length of the start fade in output frames, or 0 when it is off. Read by both audio paths, so it is plain arithmetic over the cached sample rate rather than a Unity call, and it is recomputed per block so toggling the fade takes effect on the next one.
|
| float | SpatialBlend [get] |
| | How far this component's AudioSource is spatialized, as the audio thread may read it. The IAudioGenerator path needs it to know what a MONO bed costs there.
|
| bool | isFinite [get] |
| | Not finite.
|
| bool | isRealtime [get] |
| | Realtime.
|
| DiscreteTime? | length [get] |
| | Infinite.
|
CsoundUnityChild is a component that can output AudioChannels found in the csd of the associated CsoundUnity gameObject.
IAudioGenerator implementation for CsoundUnityChild (Unity 6+).
When CsoundUnityChild._audioPath is set to AudioPath.IAudioGenerator this partial class:
-
Bypasses the classic dummy-clip × named-channel multiplication in
OnAudioFilterRead.
-
Drives the
AudioSource via a CsoundChildRealtime / CsoundChildControl pair that pulls completed blocks from the parent's publishers.
-
Registers a CsoundChildEntry in CsoundChildRegistry holding the parent instance, so the unmanaged struct can reach it by integer index on the audio thread.
The entry deliberately does not hold the parent's namedAudioChannelDataDict: those are live working arrays written on the parent's own audio callback, which Unity does not order against this child's. See the remarks on CsoundChildEntry.Parent.
The parent CsoundUnity must be running, so that it publishes a snapshot of each named channel at the end of every DSP period.
◆ AudioChannels
How many output channels a CsoundUnityChild reads from its parent.
| Enumerator |
|---|
| MONO | One channel, which reaches every speaker, like a mono orchestra does.
|
| STEREO | Two channels, sent to the first two outputs as they are.
|
◆ CreateInstance()
| GeneratorInstance Csound.Unity.CsoundUnityChild.CreateInstance |
( |
ControlContext | context, |
|
|
AudioFormat? | nestedFormat = null, |
|
|
ProcessorInstance.CreationParameters | creationParameters = default ) |
|
inline |
Called by Unity when AudioSource.generator = this is set. Creates the unmanaged CsoundChildRealtime / CsoundChildControl pair.
- Parameters
-
| 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. |
- Returns
- The generator instance Unity will drive.
◆ GetOutputScratch()
| float[] Csound.Unity.CsoundUnityChild.GetOutputScratch |
( |
int | samples | ) |
|
|
inlinepackage |
Scratch buffer for a path that has to build its interleaved output before it can publish it. Grows on demand and is reused, so it allocates on the first block and on a block size change, never in steady state. Audio thread only.
◆ Init()
Initializes this CsoundUnityChild instance setting the CsoundUnity reference and the audioChannels settings.
- Parameters
-
| csound | The parent instance to read the audio channels from. |
| audioChannels | Whether to read one channel or two. |
◆ PublishOutput()
| void Csound.Unity.CsoundUnityChild.PublishOutput |
( |
float[] | interleaved, |
|
|
int | samples, |
|
|
int | channels ) |
|
inlinepackage |
Publishes the finished output block for OutputBuffer.
Deliberately the samples the component actually emits, not the channel data it started from: whatever the path applies on the way out — the 0dbfs normalisation, the mono gain, the IAudioGenerator startup fade — is already in them. Publishing the source data instead made the monitor useless on a csd that leaves 0dbfs at its 32768 default, since the view is drawn in Unity's ±1 range and everything sat pinned at full scale.
- Parameters
-
| interleaved | Interleaved output samples. |
| samples | Total samples to publish (frames × channels ). |
| channels | Interleaved channel count. |
◆ PullPublishedChannels()
| int Csound.Unity.CsoundUnityChild.PullPublishedChannels |
( |
CsoundUnity | parent, |
|
|
string[] | names, |
|
|
float | snapshots[][], |
|
|
int[] | cursors, |
|
|
int[] | staleCounts ) |
|
inlinestaticpackage |
Pulls one complete published block per channel from the parent, into snapshots , and answers the longest block any channel had.
Never reads the parent's live arrays: those are written sample by sample on the parent's own audio callback, which is not ordered against the caller's. A channel that has nothing to give — no name, no publisher, an empty block — is marked stale rather than zeroed, so the caller can tell "nothing new this block", which is normal, from "the parent has
stopped", which is not: MaxStaleBlocks is where one becomes the other.
Shared by this component's two audio paths, which hold the same state in different places: fields here, the registry entry there.
◆ SetAudioChannel()
| void Csound.Unity.CsoundUnityChild.SetAudioChannel |
( |
int | channel, |
|
|
int | audioChannel ) |
|
inline |
◆ SyncNamedAudioChannelData()
| void Csound.Unity.CsoundUnityChild.SyncNamedAudioChannelData |
( |
float | snapshots[][], |
|
|
int | channelCount, |
|
|
int | frames ) |
|
inlinepackage |
Copies the blocks this component is about to play into namedAudioChannelData, which is public API and keeps holding the parent's channel data as it always has — Csound units, before this component normalises it.
Called from the audio thread by both paths — ProcessBlock and CsoundChildGeneratorInstance.Process. Anything an observer is meant to see has to go through here and through PublishOutput, or it works on one path and silently does nothing on the other: the inspector monitor drew nothing at all under IAudioGenerator for exactly that reason, because this lived inside ProcessBlock, which that path never runs.
- Parameters
-
| snapshots | Per-channel blocks, indexed by output channel. |
| channelCount | Channels to take from snapshots . |
| frames | Samples per channel actually published this block. Passed in rather than taken from the arrays: a snapshot array is grown to fit, never shrunk, so after the DSP buffer size drops its tail still holds the previous block and Length would over-report. |
◆ AudioChannelsSetting
Defines if this CsoundUnityChild will use one (MONO) or two (STEREO) channels. MONO reaches every output channel, the way a mono orchestra does on the parent; STEREO maps its two channels to the first two outputs and leaves the rest silent.
◆ availableAudioChannels
| List<string> Csound.Unity.CsoundUnityChild.availableAudioChannels |
A list to hold available audioChannels names.
◆ csoundUnityGameObject
| GameObject Csound.Unity.CsoundUnityChild.csoundUnityGameObject |
The gameObject with the CsoundUnity component to load Audio Channels from.
◆ fadeInSeconds
| float Csound.Unity.CsoundUnityChild.fadeInSeconds = 0f |
Ramps the output up from silence over this many seconds when the component starts producing, masking the transient of joining a parent that is already running. 0 disables it, which is the default: the component starts at full level.
In seconds rather than samples so it means the same thing at any output sample rate. Applies from the next start.
◆ MaxStaleBlocks
| const int Csound.Unity.CsoundUnityChild.MaxStaleBlocks = 2 |
|
staticpackage |
Consecutive blocks a channel may reuse its snapshot before being treated as silent. One miss is normal — the parent publishes once per DSP buffer and the two callbacks are not ordered — so the tolerance only has to catch a parent that has stopped publishing altogether.
◆ namedAudioChannelData
| List<MYFLT[]> Csound.Unity.CsoundUnityChild.namedAudioChannelData = new List<MYFLT[]>() |
A list to hold the current audio buffer data for each channel.
These are this instance's own buffers, refilled from the parent's published snapshots once per audio block — not references into the parent's live working arrays.
◆ selectedAudioChannelIndexByChannel
| int [] Csound.Unity.CsoundUnityChild.selectedAudioChannelIndexByChannel |
An array containing the selected audiochannel indexes by channel: MONO = 0, STEREO = 1.
◆ isFinite
| bool Csound.Unity.CsoundUnityChild.isFinite |
|
get |
◆ isRealtime
| bool Csound.Unity.CsoundUnityChild.isRealtime |
|
get |
◆ length
| DiscreteTime? Csound.Unity.CsoundUnityChild.length |
|
get |
◆ OutputBuffer
| float [] Csound.Unity.CsoundUnityChild.OutputBuffer |
|
get |
The most recently completed block this component put out, interleaved across the AudioSource's output channels.
These are the samples as they leave, in Unity's ±1 range, with the 0dbfs normalisation and the startup fade already applied, so a MONO component hands back the same signal on every output channel. Reading this property pulls the latest published block, so it is always complete; when nothing new has been produced the previous contents are returned unchanged, making it free to poll faster than the DSP rate. Read it from the main thread.
This is what a visualiser wants. namedAudioChannelData holds the other end of the same block — the parent's channel data, per channel and still in Csound units, so a csd that leaves 0dbfs at its 32768 default fills it with values three orders of magnitude outside what a ±1 view can draw. It is also written on the audio thread with no synchronisation, so a main-thread reader can catch it half rewritten. Nothing audible depends on it — the audio path never reads it back.
◆ OutputChannels
| int Csound.Unity.CsoundUnityChild.OutputChannels |
|
get |
Number of channels interleaved in OutputBuffer, or 1 before the first block has been published. This is the AudioSource's output channel count, which is not AudioChannelsSetting: a MONO component still puts out stereo, the same signal on both. Read from the published block rather than cached, so reading it before OutputBuffer cannot hand back a stale count.
◆ SpatialBlend
| float Csound.Unity.CsoundUnityChild.SpatialBlend |
|
getpackage |
How far this component's AudioSource is spatialized, as the audio thread may read it. The IAudioGenerator path needs it to know what a MONO bed costs there.
◆ StartupFadeFrames
| int Csound.Unity.CsoundUnityChild.StartupFadeFrames |
|
getpackage |
Length of the start fade in output frames, or 0 when it is off. Read by both audio paths, so it is plain arithmetic over the cached sample rate rather than a Unity call, and it is recomputed per block so toggling the fade takes effect on the next one.
The documentation for this class was generated from the following files: