private void DetectBeat() { DateTime now = DateTime.Now; double millis = now.Subtract(lastBeat).TotalMilliseconds; if (millis > BeatMinSpacingMillis) { BeatDetected?.Invoke(this, null); float bpm = (float)(60 / millis * 1000); bpmBuffer.Add(bpm); float avgBpm = 0; for (int i = 0; i < bpmBuffer.Count; i++) { avgBpm += bpmBuffer[i]; } avgBpm /= bpmBuffer.Count; BpmDetected?.Invoke(this, new BpmEventArgs(bpm, avgBpm)); lastBeat = now; } }
protected virtual void OnBeatDetected(TimeSpan e) { BeatDetected?.Invoke(this, e); }
protected void OnBeatDetected() { BeatDetected?.Invoke(this, new BeatDetectedEventArgs()); }