Last active
May 23, 2023 20:17
-
-
Save KokoseiJ/7dd3a125c65b174fa8fdb4f3910d2c97 to your computer and use it in GitHub Desktop.
Test BPM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
target_str = sys.argv[-1] if len(sys.argv) > 1 else input("target bpm: ") | |
target = float(target_str) | |
spb = 1 / target * 60 | |
input("Waiting for start...") | |
next_ = time.perf_counter() | |
while True: | |
next_ += spb | |
print(next_, end="\n\n") | |
time.sleep(next_ - time.perf_counter()) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
seconds_per_beat = avg(input_diffs) | |
beats_per_second = 1/seconds_per_beat | |
beats_per_minute = beats_per_second * 60 | |
''' | |
import time | |
avg = 0 | |
trials = 0 | |
prev = 0 | |
restart_threshold = 1.5 | |
while True: | |
input() | |
now = time.perf_counter() | |
if prev == 0 or now - prev >= restart_threshold: | |
prev = now | |
avg = 0 | |
trials = 0 | |
print("start") | |
continue | |
avg = (avg * trials + now - prev)/(trials + 1) | |
trials += 1 | |
prev = now | |
bpm = 1 / avg * 60 | |
print(bpm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment