CsoundUnity 4.0.0-alpha.3
Loading...
Searching...
No Matches
Csound.Unity.CsoundRootRealtime Struct Reference

Realtime struct for the AudioPath.RootOutput path (Unity 6+). More...

Inheritance diagram for Csound.Unity.CsoundRootRealtime:

Public Member Functions

JobHandle EarlyProcessing (in RealtimeContext context, ProcessorInstance.Pipe pipe)
 Stage 1: intentionally empty.
void Process (in RealtimeContext context, ProcessorInstance.Pipe pipe, JobHandle input)
 Stage 2: no-op. PerformKsmps is a P/Invoke call and cannot run inside a Burst job; all Csound work happens in EndProcessing.
void EndProcessing (in RealtimeContext context, ProcessorInstance.Pipe pipe, ChannelBuffer output)
 Stage 3: run the PerformKsmps loop and copy spout samples into output . Content written here is additively mixed into Unity's main audio output: no AudioMixer, and the AudioSource is not read.
void Update (ProcessorInstance.UpdatedDataContext context, ProcessorInstance.Pipe pipe)
 No-op — no pipe messages in Phase 1.
void RemovedFromProcessing ()
 No-op — cleanup is handled by CsoundRootControl.Dispose.

Package Attributes

int InstanceId
 Index into CsoundBridgeRegistry.

Detailed Description

Realtime struct for the AudioPath.RootOutput path (Unity 6+).

Implements RootOutputInstance.IRealtime, writing Csound output directly into Unity's main audio output — bypassing the AudioMixer entirely. No AudioSource is required; audio is mixed additively into the final hardware output.

Processing is split across three stages per mix frame:

  • EarlyProcessing — no-op; see remarks on EarlyProcessing for why the spin buffer is not filled here.
  • Process — no-op; PerformKsmps cannot run inside a Burst job because it is a P/Invoke call.
  • EndProcessing — fills Csound's spin buffer (NativeAudioInput, audio input routes) immediately before each PerformKsmps call, runs the PerformKsmps loop, and copies the spout into the ChannelBuffer that Unity mixes to hardware.

The struct is unmanaged and stored in Unity's audio memory, so _ksmpsIndex and _startupFadeIndex persist correctly across consecutive callbacks — exactly as in CsoundRealtime on the IAudioGenerator path.

Member Function Documentation

◆ EarlyProcessing()

JobHandle Csound.Unity.CsoundRootRealtime.EarlyProcessing ( in RealtimeContext context,
ProcessorInstance.Pipe pipe )
inline

Stage 1: intentionally empty.

_ksmpsIndex always resets to 0 right after a PerformKsmps call, so the first real ksmps boundary in a fresh buffer lands at f == ksmps, never at f == 0. Calling the spin-fill callback here with a hardcoded offset of 0 does not correspond to where EndProcessing actually performs, and would fire a second time when the real boundary is reached — double-invoking OnSpinFillCallback per buffer. Since that callback drives CsoundUnityNativeAudioInput.FillSpinBuffer, which does a consuming read from the native ring buffer, the duplicate call drains one extra ksmps block of input per DSP buffer, starving the ring buffer over time (audible as input drop-outs when combining NativeAudioInput with RootOutput). The spin-fill is done once, at the correct offset, inside EndProcessing — exactly as CsoundRealtime does on the IAudioGenerator path, which has no EarlyProcessing equivalent at all.

Parameters
contextThe audio thread context for this block.
pipeThe pipe that carries messages between the control and audio sides.
Returns
The job this stage runs as.

◆ EndProcessing()

void Csound.Unity.CsoundRootRealtime.EndProcessing ( in RealtimeContext context,
ProcessorInstance.Pipe pipe,
ChannelBuffer output )
inline

Stage 3: run the PerformKsmps loop and copy spout samples into output . Content written here is additively mixed into Unity's main audio output: no AudioMixer, and the AudioSource is not read.

output belongs to this instance alone — Unity's docs call it the buffer you "return the main result of your computation to the system in", sized from the format this instance was given in Configure, and the system is what renders every RootOutputInstance into the final mix. So plain assignment is right and output.Clear() on an early return silences only this instance, never a sibling. Worth stating because the additive mixing invites the opposite reading, under which both would be bugs.

The corollary is a real one for users: this path bypasses the AudioMixer, so nothing attenuates it before the sum. Several loud RootOutput instances at once will clip where the same material through an AudioSource would not.

Parameters
contextThe audio thread context for this block.
pipeThe pipe that carries messages between the control and audio sides.
outputThe main output this adds into.

◆ Process()

void Csound.Unity.CsoundRootRealtime.Process ( in RealtimeContext context,
ProcessorInstance.Pipe pipe,
JobHandle input )
inline

Stage 2: no-op. PerformKsmps is a P/Invoke call and cannot run inside a Burst job; all Csound work happens in EndProcessing.

Parameters
contextThe audio thread context for this block.
pipeThe pipe that carries messages between the control and audio sides.
inputThe job to wait on before this one runs.

◆ RemovedFromProcessing()

void Csound.Unity.CsoundRootRealtime.RemovedFromProcessing ( )
inline

No-op — cleanup is handled by CsoundRootControl.Dispose.

◆ Update()

void Csound.Unity.CsoundRootRealtime.Update ( ProcessorInstance.UpdatedDataContext context,
ProcessorInstance.Pipe pipe )
inline

No-op — no pipe messages in Phase 1.

Parameters
contextThe context Unity passes when it hands over updated data.
pipeThe pipe that carries messages between the control and audio sides.

Member Data Documentation

◆ InstanceId

int Csound.Unity.CsoundRootRealtime.InstanceId
package

Index into CsoundBridgeRegistry.


The documentation for this struct was generated from the following file: