mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-20 04:10:00 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
51 lines
1.1 KiB
C#
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 );
|
|
}
|
|
}
|