Initial import of Rhyculator
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
commit
728bb0c657
315 files changed
+96030
No files matched your search
@@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
// 延遲校正的計算(純函式,方便測試)
|
||||
public static class CalibrationMath
|
||||
{
|
||||
// 點擊時間對最近一拍的偏差;超出半拍或屬於暖身拍則回傳 false
|
||||
public static bool TryBeatDelta(double tapTime, double firstBeat, double interval, int beatCount, int warmupBeats, out double delta)
|
||||
{
|
||||
delta = 0;
|
||||
int i = (int)System.Math.Round((tapTime - firstBeat) / interval);
|
||||
if (i < warmupBeats || i >= beatCount) return false;
|
||||
delta = tapTime - (firstBeat + i * interval);
|
||||
return System.Math.Abs(delta) < interval / 2;
|
||||
}
|
||||
|
||||
// 中位數(比平均值不受誤觸影響)
|
||||
public static double Median(List<double> values)
|
||||
{
|
||||
if (values == null || values.Count == 0) return 0;
|
||||
var sorted = new List<double>(values);
|
||||
sorted.Sort();
|
||||
int n = sorted.Count;
|
||||
return n % 2 == 1 ? sorted[n / 2] : (sorted[n / 2 - 1] + sorted[n / 2]) / 2;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user