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

The small decisions the three audio paths must make identically: which Csound channel feeds a Unity output channel, how far the startup fade has got, and what to divide a sample by. More...

Static Package Functions

static int BedChannel (int outputChannel, int nchnls)
 The Csound channel that feeds one of Unity's output channels, or -1 when the orchestra has nothing for it. A mono orchestra is one signal, so it plays from every speaker; a wider one maps one to one, and the speakers past nchnls stay silent.
static float NextFade (int fadeFrames, ref int fadeIndex)
 The gain of the startup fade for this frame, advancing fadeIndex while the ramp lasts. 1 once it is over, and 1 throughout when fadeFrames is 0, which is the default.
static int OutputChannelCount ()
 How many channels Unity's output has, which is what a carrier clip has to cover and what a mono bed is spread over.
static float BlendOutput (float bed, float mix, float blend, int carrierChannels)
 What one output channel carries, from the channel-per-speaker bed and from the whole source summed into one signal, according to how far the AudioSource is spatialized.
static float SpreadDivisor (int sourceChannels, int outputChannels, float blend)
 What to divide a bed by on the paths Unity pans itself, where the same signal in several channels is not free: Unity maps a generator's channels one to one when nothing is spatialized, and sums them when something is, so a mono bed written into every channel comes out multiplied by the width of the output.
static float GuardSample (float value, float limit, ref float peak)
 One output sample, bounded. limit is the ceiling: a sample louder than it comes out clamped to it, with its real magnitude recorded in peak , and a sample that is not a number comes out as silence. The same comparison catches both, because nothing compares true against NaN. On RootOutput this matters beyond the instance: what it writes goes into Unity's main output.
static float Inv0dbfs (double zerodbfs)
 The reciprocal of Csound's 0dbfs, which every path multiplies its samples by. Guards the divisor and not the result: a destroyed bridge answers 0, and 1/0 is Infinity, which would turn a block of audio into NaN rather than into silence.

Detailed Description

The small decisions the three audio paths must make identically: which Csound channel feeds a Unity output channel, how far the startup fade has got, and what to divide a sample by.

Member Function Documentation

◆ BedChannel()

int Csound.Unity.AudioPathShared.BedChannel ( int outputChannel,
int nchnls )
inlinestaticpackage

The Csound channel that feeds one of Unity's output channels, or -1 when the orchestra has nothing for it. A mono orchestra is one signal, so it plays from every speaker; a wider one maps one to one, and the speakers past nchnls stay silent.

◆ BlendOutput()

float Csound.Unity.AudioPathShared.BlendOutput ( float bed,
float mix,
float blend,
int carrierChannels )
inlinestaticpackage

What one output channel carries, from the channel-per-speaker bed and from the whole source summed into one signal, according to how far the AudioSource is spatialized.

A position in the scene has one signal at it, not a channel per speaker, so a spatialized instance puts mix in every channel and lets Unity's panner place it. The carrier clip is all ones, so what the filter receives is the gain Unity wants applied: 1 per channel when nothing is spatialized, and the panner's gain times carrierChannels when everything is, because the panner sums the carrier's channels into the point. Dividing by that same interpolation is what keeps the level steady across the blend, and it is a plain scaling, so volume, mute and distance survive it. Exact at both ends of the blend, approximate in between.

◆ GuardSample()

float Csound.Unity.AudioPathShared.GuardSample ( float value,
float limit,
ref float peak )
inlinestaticpackage

One output sample, bounded. limit is the ceiling: a sample louder than it comes out clamped to it, with its real magnitude recorded in peak , and a sample that is not a number comes out as silence. The same comparison catches both, because nothing compares true against NaN. On RootOutput this matters beyond the instance: what it writes goes into Unity's main output.

Clamped rather than silenced, so a runaway is a clipped version of itself instead of a waveform full of holes, and nothing louder than the ceiling leaves the component: at the default of 10 that still means ten times full scale, which is why the ceiling is the user's to set.

The reporting is left to the caller's main thread. An orchestra that runs away does so on every block, and the audio thread is no place to be building console messages.

◆ Inv0dbfs()

float Csound.Unity.AudioPathShared.Inv0dbfs ( double zerodbfs)
inlinestaticpackage

The reciprocal of Csound's 0dbfs, which every path multiplies its samples by. Guards the divisor and not the result: a destroyed bridge answers 0, and 1/0 is Infinity, which would turn a block of audio into NaN rather than into silence.

◆ NextFade()

float Csound.Unity.AudioPathShared.NextFade ( int fadeFrames,
ref int fadeIndex )
inlinestaticpackage

The gain of the startup fade for this frame, advancing fadeIndex while the ramp lasts. 1 once it is over, and 1 throughout when fadeFrames is 0, which is the default.

◆ OutputChannelCount()

int Csound.Unity.AudioPathShared.OutputChannelCount ( )
inlinestaticpackage

How many channels Unity's output has, which is what a carrier clip has to cover and what a mono bed is spread over.

◆ SpreadDivisor()

float Csound.Unity.AudioPathShared.SpreadDivisor ( int sourceChannels,
int outputChannels,
float blend )
inlinestaticpackage

What to divide a bed by on the paths Unity pans itself, where the same signal in several channels is not free: Unity maps a generator's channels one to one when nothing is spatialized, and sums them when something is, so a mono bed written into every channel comes out multiplied by the width of the output.

1 when there is no duplication to pay for, which is every source with more than one channel, and when nothing is spatialized. RootOutput passes 0 for the blend: it writes to the main output and has no panner to sum anything.


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