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
@@ -26,7 +26,7 @@ namespace OCES.Audio
this.m_onGrid = onGrid;
}
public void Restart(MusicContainer container, float inheritedBpm, double dspTime)
internal void Restart(MusicContainer container, float inheritedBpm, double dspTime)
{
//Debug.Log($"[BeatClock] Restart called, container={container.Id}, bpm={container.Bpm}, inherited={inheritedBpm}");
@@ -63,6 +63,26 @@ namespace OCES.Audio
this.m_beatCoroutine = this.m_barCoroutine = this.m_gridCoroutine = null;
}
internal double GetNextDspTime(AlignMode mode)
{
double now = AudioSettings.dspTime;
if (this.m_blendError || this.m_stopped)
{
return now;
}
double elapsed = now - this.m_startDspTime;
double period = mode switch
{
AlignMode.Beat => this.m_secondsPerBeat,
AlignMode.Bar => this.m_secondsPerBeat * this.m_beatsPerBar,
_ => this.m_secondsPerBeat,
};
long next = (long)(elapsed / period) + 1L;
return this.m_startDspTime + next * period;
}
IEnumerator BeatCoroutine()
{
double elapsed = AudioSettings.dspTime - this.m_startDspTime;