feat: music callback
This commit is contained in:
@@ -28,7 +28,7 @@ namespace OCES.Audio
|
||||
|
||||
public void Restart(MusicContainer container, float inheritedBpm, double dspTime)
|
||||
{
|
||||
Debug.Log($"[BeatClock] Restart called, container={container.Id}, bpm={container.Bpm}, inherited={inheritedBpm}");
|
||||
//Debug.Log($"[BeatClock] Restart called, container={container.Id}, bpm={container.Bpm}, inherited={inheritedBpm}");
|
||||
|
||||
StopAll();
|
||||
this.m_blendError = this.m_stopped = false;
|
||||
@@ -69,21 +69,15 @@ namespace OCES.Audio
|
||||
while (true)
|
||||
{
|
||||
double nextTime = this.m_startDspTime + index * this.m_secondsPerBeat;
|
||||
if (index == 0)
|
||||
{
|
||||
Debug.Log($"[BeatClock] BeatCoroutine waiting, nextTime={nextTime}, now={AudioSettings.dspTime}");
|
||||
}
|
||||
yield return new WaitUntil(() => AudioSettings.dspTime >= nextTime - 0.02);
|
||||
|
||||
while (AudioSettings.dspTime < nextTime)
|
||||
yield return null;
|
||||
|
||||
if (this.m_blendError || this.m_stopped){
|
||||
Debug.Log($"[BeatClock] Coroutine exiting early, blendError={m_blendError}, stopped={m_stopped}");
|
||||
yield break;
|
||||
}
|
||||
this.m_onBeat?.Invoke(this.m_containerId);
|
||||
Debug.Log($"[Beat] index={index}, nextTime={nextTime:F4}, actualDspTime={AudioSettings.dspTime:F4}, diff={(AudioSettings.dspTime - nextTime)*1000:F1}ms");
|
||||
index++;
|
||||
}
|
||||
}
|
||||
@@ -99,7 +93,6 @@ namespace OCES.Audio
|
||||
while (AudioSettings.dspTime < nextTime)
|
||||
yield return null;
|
||||
if (this.m_blendError || this.m_stopped){
|
||||
Debug.Log($"[BeatClock] Coroutine exiting early, blendError={m_blendError}, stopped={m_stopped}");
|
||||
yield break;
|
||||
}
|
||||
this.m_onBar?.Invoke(this.m_containerId);
|
||||
@@ -118,7 +111,6 @@ namespace OCES.Audio
|
||||
while (AudioSettings.dspTime < nextTime)
|
||||
yield return null;
|
||||
if (this.m_blendError || this.m_stopped){
|
||||
Debug.Log($"[BeatClock] Coroutine exiting early, blendError={m_blendError}, stopped={m_stopped}");
|
||||
yield break;
|
||||
}
|
||||
this.m_onGrid?.Invoke(this.m_containerId);
|
||||
|
||||
Reference in New Issue
Block a user