forked from nikita/muzika-gromche
Apply audio offsets early to simplify math
This commit is contained in:
parent
e1f19b3919
commit
d13c617895
|
@ -431,6 +431,9 @@ namespace MuzikaGromche
|
||||||
set => _BeatsOffset = value;
|
set => _BeatsOffset = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Offset of beats, in seconds. Bigger offset => colors will change later.
|
||||||
|
public float Offset => BeatsOffset / Beats * LoadedLoop.length;
|
||||||
|
|
||||||
// Duration of color transition, measured in beats.
|
// Duration of color transition, measured in beats.
|
||||||
public float _ColorTransitionIn = 0.25f;
|
public float _ColorTransitionIn = 0.25f;
|
||||||
public float ColorTransitionIn
|
public float ColorTransitionIn
|
||||||
|
@ -469,27 +472,28 @@ namespace MuzikaGromche
|
||||||
// NOTE 2: There is a weird state when Jester has popped and chases a player:
|
// NOTE 2: There is a weird state when Jester has popped and chases a player:
|
||||||
// Start/farAudio isPlaying is true but stays exactly at zero time, so we need to ignore that.
|
// Start/farAudio isPlaying is true but stays exactly at zero time, so we need to ignore that.
|
||||||
|
|
||||||
var elapsed = start.isPlaying && start.time != 0f
|
float elapsed = 0f;
|
||||||
|
elapsed -= Config.AudioOffset.Value;
|
||||||
|
elapsed -= Offset;
|
||||||
|
|
||||||
|
elapsed += start.isPlaying && start.time != 0f
|
||||||
// [1] Start source is still playing
|
// [1] Start source is still playing
|
||||||
? start.time - WindUpTimer
|
? start.time - WindUpTimer
|
||||||
// [2] Start source has finished
|
// [2] Start source has finished
|
||||||
: loop.time + FixedLoopDelay;
|
: loop.time + FixedLoopDelay;
|
||||||
|
|
||||||
elapsed -= Config.AudioOffset.Value;
|
|
||||||
|
|
||||||
var normalized = Mod.Positive(elapsed / LoadedLoop.length, 1f);
|
var normalized = Mod.Positive(elapsed / LoadedLoop.length, 1f);
|
||||||
|
|
||||||
var beat = normalized * (float)Beats;
|
var beat = normalized * (float)Beats;
|
||||||
var offset = Mod.Positive(beat - BeatsOffset, (float)Beats);
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
var color = ColorAtBeat(beat);
|
var color = ColorAtBeat(beat);
|
||||||
Debug.LogFormat("MuzikaGromche t={0,10:N4} d={1,7:N4} Start[{2}{3,8:N4} ==0f? {4}] Loop[{5}{6,8:N4}] norm={7,6:N4} beat={8,7:N4} {9,7:N4} color={10}",
|
Debug.LogFormat("MuzikaGromche t={0,10:N4} d={1,7:N4} Start[{2}{3,8:N4} ==0f? {4}] Loop[{5}{6,8:N4}] norm={7,6:N4} beat={8,7:N4} color={9}",
|
||||||
Time.realtimeSinceStartup, Time.deltaTime,
|
Time.realtimeSinceStartup, Time.deltaTime,
|
||||||
(start.isPlaying ? '+' : ' '), start.time, (start.time == 0f ? 'Y' : 'n'),
|
(start.isPlaying ? '+' : ' '), start.time, (start.time == 0f ? 'Y' : 'n'),
|
||||||
(loop.isPlaying ? '+' : ' '), loop.time,
|
(loop.isPlaying ? '+' : ' '), loop.time,
|
||||||
normalized, beat, offset, color);
|
normalized, beat, color);
|
||||||
#endif
|
#endif
|
||||||
return offset;
|
return beat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Palette _Palette = Palette.DEFAULT;
|
public Palette _Palette = Palette.DEFAULT;
|
||||||
|
|
Loading…
Reference in New Issue