A ProcessorInstance that processes audio data.
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 IControl<T0> and
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.
Additional resources: IAudioEffect, ControlContext.AllocateEffect
The following example implements a gain effect and exposes it as a component you can add
to the GameObject of an <see cref="AudioSource" />.
[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;
}
}
| Method | Description |
|---|---|
| Configure | Manually reconfigure this EffectInstance with the given AudioConfiguration. |
| Equals | Checks if this instance equals another. |
| GetHashCode | Retrieves a hash code based on this instance. |
| Process | Manually process this particular EffectInstance. |
| Operator | Description |
|---|---|
| operator != | Checks if two instances are not equal. |
| operator == | Checks if two instances are equal. |
| ProcessorInstance | Convert this EffectInstance to its more general ProcessorInstance representation. |