Files
sbox-public/engine/Sandbox.Engine/Systems/Audio/Processors/DelayProcessor.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

68 lines
1.3 KiB
C#

namespace Sandbox.Audio;
[Expose]
public sealed class DelayProcessor : AudioProcessor<DelayProcessor.State>
{
[Range( 0, 1 )]
public float Delay { get; set; }
[Range( 0, 1 )]
public float Volume { get; set; }
public class State : ListenerState
{
internal CAudioProcessor _native;
private float _delay;
internal float Delay
{
get => _delay;
set
{
if ( value > 3.0f )
value = 3.0f;
if ( _delay == value ) return;
_delay = value;
_native.SetControlParameter( "delay", value * 1000.0f );
}
}
private float _volume;
internal float Volume
{
get => _volume;
set
{
if ( _volume == value ) return;
_volume = value;
_native.SetControlParameter( "gain", _volume.Remap( 0, 1, -20, 0 ) );
}
}
public State()
{
_native = CAudioProcessor.CreateDelay( AudioEngine.ChannelCount );
Delay = 0.2f;
Volume = 0.5f;
}
protected override void OnDestroy()
{
MainThread.QueueDispose( _native );
_native = default;
}
internal void Process( MultiChannelBuffer input, MultiChannelBuffer output )
{
_native.Process( input._native, output._native, Math.Min( input.ChannelCount, output.ChannelCount ) );
}
}
internal override void Process( MultiChannelBuffer input, MultiChannelBuffer output )
{
CurrentState.Process( input, output );
}
}