public long RunMeasurementRoutine() { Console.WriteLine($"We will take {c_sampleCount} samples to calculate the end-to-end system latency."); Console.WriteLine("Setting up audio devices..."); InterceptKeys.Instance.OnKey += OnKey; InterceptKeys.Start(); Thread.Sleep(1000); _capture.Initialize(); _capture.DataAvailable += OnData; _tracker.Start(); _capture.Start(); _output.Initialize(new SampleToIeeeFloat32(new MetronomeGenerator())); _output.Play(); _done.WaitOne(); float delta = 0; for (int i = 0; i < c_sampleCount; i++) { delta += _keyTicks[i] - _audioTicks[i]; } delta /= c_sampleCount; Console.WriteLine($"End-to-end latency: {delta / 10000}ms"); Thread.Sleep(5000); return((long)(delta)); }
public void Run() { _periodicThread = new Thread(PeriodicCancelThread); _periodicThread.Start(); _tracker.Start(); _capture.Start(); InterceptKeys.Instance.OnKey += OnKey; InterceptKeys.Start(); }
void OnKey(object sender, InterceptKeys.KeyOfInterest e) { _keyTicks.Add(_tracker.CurrentTime); if (_audioTicks.Count == _keyTicks.Count) { Console.WriteLine($"offset {(_keyTicks.Last()- _audioTicks.Last()) / 10000 }ms"); if (_audioTicks.Count >= c_sampleCount) { _capture.Stop(); InterceptKeys.Stop(); _output.Stop(); _capture.Dispose(); _output.Dispose(); _done.Set(); } } }
private void OnKey(object sender, InterceptKeys.KeyOfInterest e) { if (e == InterceptKeys.KeyOfInterest.BeatKey) OnBeatKey(); if (e == InterceptKeys.KeyOfInterest.EndKey) OnEndKey(); }