Files
sbox-public/engine/Sandbox.Engine/Systems/Audio/Processors/PitchProcessor.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

51 lines
1.1 KiB
C#

namespace Sandbox.Audio;
[Expose]
public sealed class PitchProcessor : AudioProcessor<PitchProcessor.State>
{
[Range( 0.5f, 2.0f )]
public float Pitch { get; set; }
public class State : ListenerState
{
internal CAudioProcessor _native;
internal PerChannel<float> PreviousInput;
internal PerChannel<float> PreviousOutput;
private float _pitch = 1.0f;
internal float Pitch
{
get => _pitch;
set
{
if ( _pitch == value ) return;
_pitch = value;
_native.SetControlParameter( "pitchScale", value );
}
}
public State()
{
_native = CAudioProcessor.CreatePitchShift( AudioEngine.ChannelCount );
}
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.Pitch = Pitch;
CurrentState.Process( input, output );
}
}