refactor: WaitForAlignment coroutine use BeatClock.cs insted of calculate independently.

This commit is contained in:
2026-04-21 15:01:55 +08:00
parent 15f220a4c7
commit e46c324ac5
4 changed files with 30 additions and 36 deletions
@@ -197,34 +197,8 @@ namespace OCES.Audio
if (mode == AlignMode.Immediate || container.Bpm <= 0f)
yield break;
double now = AudioSettings.dspTime;
double elapsed = now - this.m_playStartTime;
double secondsPerBeat = 60.0 / container.Bpm;
switch (mode)
{
case AlignMode.Beat:
{
double beatsElapsed = elapsed / secondsPerBeat;
double nextBeat = Math.Ceiling(beatsElapsed);
double waitSeconds = (nextBeat - beatsElapsed) * secondsPerBeat;
if (waitSeconds > 0.001)
yield return new WaitForSeconds((float)waitSeconds);
break;
}
case AlignMode.Bar:
{
int beatsPerBar = MusicContainerConfig.GetBeatsPerBar(container.TimeSig);
double secondsPerBar = secondsPerBeat * beatsPerBar;
double barsElapsed = elapsed / secondsPerBar;
double nextBar = Math.Ceiling(barsElapsed);
double waitSeconds = (nextBar - barsElapsed) * secondsPerBar;
if (waitSeconds > 0.001)
yield return new WaitForSeconds((float)waitSeconds);
break;
}
}
double target = this.m_beatClock.GetNextDspTime(mode);
yield return new WaitUntil(() => AudioSettings.dspTime >= target);
}
// ─────────────────────────────────────────────