|
@@ -7,10 +7,12 @@ var playing = false
|
|
const COMPENSATE_FRAMES = 2
|
|
const COMPENSATE_FRAMES = 2
|
|
const COMPENSATE_HZ = 60.0
|
|
const COMPENSATE_HZ = 60.0
|
|
|
|
|
|
-const SYNC_SOURCE_SYSTEM_CLOCK = 0
|
|
|
|
-const SYNC_SOURCE_SOUND_CLOCK = 1
|
|
|
|
|
|
+enum SyncSource {
|
|
|
|
+ SYSTEM_CLOCK,
|
|
|
|
+ SOUND_CLOCK,
|
|
|
|
+}
|
|
|
|
|
|
-var sync_source = SYNC_SOURCE_SYSTEM_CLOCK
|
|
|
|
|
|
+var sync_source = SyncSource.SYSTEM_CLOCK
|
|
|
|
|
|
# Used by system clock.
|
|
# Used by system clock.
|
|
var time_begin
|
|
var time_begin
|
|
@@ -25,16 +27,16 @@ func strsec(secs):
|
|
|
|
|
|
|
|
|
|
func _process(_delta):
|
|
func _process(_delta):
|
|
- if (!playing or !$Player.playing):
|
|
|
|
|
|
+ if !playing or !$Player.playing:
|
|
return
|
|
return
|
|
|
|
|
|
var time = 0.0
|
|
var time = 0.0
|
|
- if (sync_source == SYNC_SOURCE_SYSTEM_CLOCK):
|
|
|
|
|
|
+ if sync_source == SyncSource.SYSTEM_CLOCK:
|
|
# Obtain from ticks.
|
|
# Obtain from ticks.
|
|
time = (OS.get_ticks_usec() - time_begin) / 1000000.0
|
|
time = (OS.get_ticks_usec() - time_begin) / 1000000.0
|
|
# Compensate.
|
|
# Compensate.
|
|
time -= time_delay
|
|
time -= time_delay
|
|
- elif (sync_source == SYNC_SOURCE_SOUND_CLOCK):
|
|
|
|
|
|
+ elif sync_source == SyncSource.SOUND_CLOCK:
|
|
time = $Player.get_playback_position() + AudioServer.get_time_since_last_mix() - AudioServer.get_output_latency() + (1 / COMPENSATE_HZ) * COMPENSATE_FRAMES
|
|
time = $Player.get_playback_position() + AudioServer.get_time_since_last_mix() - AudioServer.get_output_latency() + (1 / COMPENSATE_HZ) * COMPENSATE_FRAMES
|
|
|
|
|
|
var beat = int(time * BPM / 60.0)
|
|
var beat = int(time * BPM / 60.0)
|
|
@@ -44,7 +46,7 @@ func _process(_delta):
|
|
|
|
|
|
|
|
|
|
func _on_PlaySystem_pressed():
|
|
func _on_PlaySystem_pressed():
|
|
- sync_source = SYNC_SOURCE_SYSTEM_CLOCK
|
|
|
|
|
|
+ sync_source = SyncSource.SYSTEM_CLOCK
|
|
time_begin = OS.get_ticks_usec()
|
|
time_begin = OS.get_ticks_usec()
|
|
time_delay = AudioServer.get_time_to_next_mix() + AudioServer.get_output_latency()
|
|
time_delay = AudioServer.get_time_to_next_mix() + AudioServer.get_output_latency()
|
|
playing = true
|
|
playing = true
|
|
@@ -52,6 +54,6 @@ func _on_PlaySystem_pressed():
|
|
|
|
|
|
|
|
|
|
func _on_PlaySound_pressed():
|
|
func _on_PlaySound_pressed():
|
|
- sync_source = SYNC_SOURCE_SOUND_CLOCK
|
|
|
|
|
|
+ sync_source = SyncSource.SOUND_CLOCK
|
|
playing = true
|
|
playing = true
|
|
$Player.play()
|
|
$Player.play()
|