refactor: WaitForAlignment coroutine use BeatClock.cs insted of calculate independently.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user