Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


EffectInstance

A ProcessorInstance that processes audio data.
Read time 3 minutesLast updated 2 days ago

Definition

public struct EffectInstance : IEquatable<EffectInstance>

Remarks

An EffectInstance reads audio from an input buffer, transforms it, and writes the result to an output buffer. You can define the EffectInstance through implementing the EffectInstance.IControl<TProcessor> and EffectInstance.IRealtime interfaces, which defines the control and real-time thread behavior respectively.
To use an effect in a scene, implement IAudioEffect on a MonoBehaviour and add the component to the same GameObject as an AudioSource. The AudioSource auto-discovers IAudioEffect components on its GameObject, and instantiates and manages their EffectInstances for you.
It is also possible to create your own effects through code using ControlContext.AllocateEffect, for example to run an effect nested inside another processor. Interacting with an instantiated effect depends on the ownership of the EffectInstance: If the effect has been created from an AudioSource, you would interact with it through the instance obtained from AudioSource.GetEffectInstance.
The following example implements a gain effect and exposes it as a component you can add to the GameObject of an AudioSource.

Examples

[BurstCompile(CompileSynchronously = true)]struct Realtime : EffectInstance.IRealtime{ // Fixed attenuation applied to every sample. private const float k_Gain = 0.5f; // Called when the real-time side of the graph updates (e.g., new control data available). // Keep this method allocation-free and exception-free. public void Update(UpdatedDataContext context, Pipe pipe) { } public EffectInstance.Result Process( in RealtimeContext context, ChannelBuffer inputBuffer, ChannelBuffer outputBuffer, EffectInstance.Arguments args) { // Scale every input sample and write it to the output buffer. // Always write every output sample: the output buffer starts undefined. for (int frame = 0; frame < inputBuffer.frameCount; frame++) { for (int ch = 0; ch < inputBuffer.channelCount; ch++) outputBuffer[ch, frame] = inputBuffer[ch, frame] * k_Gain; } return default; }}

Methods

Method

Description

ConfigureManually reconfigure this EffectInstance with the given AudioConfiguration.
EqualsChecks if this instance equals a given object.
GetHashCodeRetrieves a hash code based on this instance.
ProcessManually process this particular EffectInstance.

Operators

Operator

Description

operator ==Checks if two instances are equal.
ProcessorInstanceConvert this EffectInstance to its more general ProcessorInstance representation.
operator !=Checks if two instances are not equal.

Structs

Struct

Description

EffectInstance.ArgumentsAdditional arguments passed to the EffectInstance.IRealtime.Process method.
EffectInstance.CreationParametersAdditional parameters and initialization state for creating an EffectInstance.
EffectInstance.ResultThe result returned from an EffectInstance.IRealtime.Process call.
EffectInstance.SetupPer-instance setup an effect reports back from EffectInstance.IControl<TProcessor>.Configure.
EffectInstance.SidechainPlaceholder for future sidechain wiring and layout information.

Interfaces

Interface

Description

EffectInstance.ICapabilitiesStatic capabilities an effect declares up front.
EffectInstance.IControl<TProcessor>The control interface an implementation of an EffectInstance must implement on a struct to be fully formed.
EffectInstance.IRealtimeThe processing interface an implementation of an EffectInstance must implement on a struct to be fully formed.