Helmholtz testing (no decay bug)
This commit is contained in:
30
Program.cs
30
Program.cs
@@ -17,7 +17,7 @@ public class Program
|
||||
private const double DrawFrequency = 60.0;
|
||||
|
||||
// Playback speed
|
||||
private static double _desiredSpeed = 0.01;
|
||||
private static double _desiredSpeed = 0.001;
|
||||
private static double _currentDisplaySpeed = _desiredSpeed;
|
||||
private const double MinSpeed = 0.0001;
|
||||
private const double MaxSpeed = 1.0;
|
||||
@@ -38,11 +38,11 @@ public class Program
|
||||
private static Text? _overlayText;
|
||||
|
||||
// Throttle control
|
||||
private static double _throttleTarget = 1.0; // 0‑1, set by arrow keys
|
||||
private static double _throttleCurrent = 0.0; // actual current fraction (lerped)
|
||||
private const double ThrottleLerpRate = 10.0; // times per second (speed of movement)
|
||||
private static float _throttleTarget = 1.0f; // 0‑1, set by arrow keys
|
||||
private static float _throttleCurrent = 0.0f; // actual current fraction (lerped)
|
||||
private const float ThrottleLerpRate = 10.0f; // times per second (speed of movement)
|
||||
private static bool _wKeyHeld = false;
|
||||
private static double _lastThrottleUpdateTime;
|
||||
private static float _lastThrottleUpdateTime;
|
||||
|
||||
private const int TargetMaxFill = (int)(SampleRate * 0.2);
|
||||
|
||||
@@ -50,11 +50,11 @@ public class Program
|
||||
{
|
||||
var window = CreateWindow();
|
||||
LoadFont();
|
||||
_scenario = new Inline4Scenario();
|
||||
_scenario = new HelmholtzScenario();
|
||||
_scenario.Initialize(SampleRate);
|
||||
_lastThrottleUpdateTime = 0.0;
|
||||
_lastThrottleUpdateTime = 0.0f;
|
||||
|
||||
_simRingBuffer = new SimulationRingBuffer(131072);
|
||||
_simRingBuffer = new SimulationRingBuffer(8192);
|
||||
_soundEngine = new SoundEngine(_simRingBuffer) { Volume = 100 };
|
||||
_soundEngine.Start();
|
||||
|
||||
@@ -77,19 +77,19 @@ public class Program
|
||||
_soundEngine.Speed = _currentDisplaySpeed;
|
||||
|
||||
// ---- Throttle update ----
|
||||
double dtThrottle = now - _lastThrottleUpdateTime;
|
||||
_lastThrottleUpdateTime = now;
|
||||
float dtThrottle = (float)now - _lastThrottleUpdateTime;
|
||||
_lastThrottleUpdateTime = (float)now;
|
||||
|
||||
double throttleDesiredFraction = _wKeyHeld ? _throttleTarget : 0.0;
|
||||
float throttleDesiredFraction = _wKeyHeld ? _throttleTarget : 0.0f;
|
||||
|
||||
// Snap to zero instantly when target is zero (key released)
|
||||
if (throttleDesiredFraction == 0.0)
|
||||
{
|
||||
_throttleCurrent = 0.0;
|
||||
_throttleCurrent = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
double smoothing = 1.0 - Math.Exp(-ThrottleLerpRate * dtThrottle);
|
||||
float smoothing = 1.0f - MathF.Exp(-ThrottleLerpRate * dtThrottle);
|
||||
_throttleCurrent += (throttleDesiredFraction - _throttleCurrent) * smoothing;
|
||||
}
|
||||
|
||||
@@ -199,11 +199,11 @@ public class Program
|
||||
break;
|
||||
|
||||
case Keyboard.Key.Up:
|
||||
_throttleTarget = Math.Min(1.0, _throttleTarget + 0.05);
|
||||
_throttleTarget = MathF.Min(1.0f, _throttleTarget + 0.05f);
|
||||
break;
|
||||
|
||||
case Keyboard.Key.Down:
|
||||
_throttleTarget = Math.Max(0.0, _throttleTarget - 0.05);
|
||||
_throttleTarget = MathF.Max(0.0f, _throttleTarget - 0.05f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user