Files
osu-framework/osu.Framework/Audio/EzLatency/EzJudgeModule.cs
2026-01-16 12:28:33 +08:00

74 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using osu.Framework.Logging;
namespace osu.Framework.Audio.EzLatency
{
/// <summary>
/// EzJudgeModule 负责处理判定时间的计算和记录。
/// 主要职责包括基于输入事件计算判定时间,记录判定延迟,并为整体延迟分析提供数据。
/// </summary>
public static class EzJudgeModule
{
/// <summary>
/// EzOsuLatency 总开关 - 控制是否启用延迟测量
/// </summary>
public static bool Enabled { get; set; } = false;
private static readonly Stopwatch stopwatch = new Stopwatch();
// 存储判定时间
internal static double JudgeTime;
static EzJudgeModule()
{
stopwatch.Start();
}
/// <summary>
/// 记录判定时间戳T_judge
/// </summary>
/// <param name="timestamp">判定事件的时间戳</param>
public static void RecordTimestamp(DateTime timestamp)
{
if (Enabled)
{
JudgeTime = stopwatch.Elapsed.TotalMilliseconds;
// 不直接打印日志
}
}
/// <summary>
/// 运行判定延迟测试
/// </summary>
public static void RunTest()
{
if (Enabled)
Logger.Log("[EzJudge] Run judgement latency test", name: "audio", level: LogLevel.Debug);
}
/// <summary>
/// 设置判定缓冲区大小
/// </summary>
/// <param name="bufferSize">缓冲区大小</param>
public static void SetBufferSize(int bufferSize)
{
if (Enabled)
Logger.Log($"[EzJudge] Set buffer size: {bufferSize}", name: "audio", level: LogLevel.Debug);
}
/// <summary>
/// 设置采样率
/// </summary>
/// <param name="sampleRate">采样率</param>
public static void SetSampleRate(int sampleRate)
{
if (Enabled)
Logger.Log($"[EzJudge] Set sample rate: {sampleRate}", name: "audio", level: LogLevel.Debug);
}
}
}