35 lines
1 KiB
Text
35 lines
1 KiB
Text
integer tempo = 120, -- beats per minute (max 800)
|
|
measure = 4, -- beats per bar
|
|
runsecs = 5 -- total run time (rounded up to whole bars)
|
|
|
|
integer low_freq = #200, low_duration = 20,
|
|
high_freq = #400, high_duration = 20
|
|
|
|
atom k32=0, xBeep
|
|
atom t0 = time(), count = 0
|
|
atom duration = 60/tempo,
|
|
next = time()+duration
|
|
|
|
while time()<t0+runsecs do
|
|
for j=1 to measure do
|
|
if platform()=WINDOWS then
|
|
if k32=0 then
|
|
k32 = open_dll("kernel32.dll")
|
|
xBeep = define_c_proc(k32, "Beep", {C_INT,C_INT})
|
|
end if
|
|
if j=1 then
|
|
c_proc(xBeep,{high_freq,high_duration})
|
|
if count=0 then t0 = time() end if
|
|
else
|
|
c_proc(xBeep,{low_freq,low_duration})
|
|
end if
|
|
else
|
|
puts(1,7)
|
|
end if
|
|
count += 1
|
|
puts(1,iff(j=1?"\nH":"L"))
|
|
sleep(next-time())
|
|
next += duration
|
|
end for
|
|
end while
|
|
printf(1,"\naverage %f bpm\n",{count*60/(time()-t0)})
|