Also make sure you're
interpolating the audio time value. (interpolating values you get from the Source:tell function).
These two functions may prove useful:
Code: Select all
--Taken from beatfever source code
function playInterpolated() --Runs the music, but enables interpolated timer reporting. Used ingame as an interpolated timer.
previousFrameTime = love.timer.getTime()*1000
lastReportedPlaytime = 0
songTime = 0
songPlay:play()
end
function getInterpolatedTimer()
songTime = songTime + (love.timer.getTime()*1000) - previousFrameTime
previousFrameTime = love.timer.getTime()*1000
if songPlay:tell("seconds")*1000 ~= lastReportedPlaytime then --Updates music time, but with easing
songTime = (songTime + (songPlay:tell("seconds")*1000))/2
lastReportedPlaytime = songPlay:tell("seconds")*1000
eased = true
end
return songTime
--for more info about this, take a look
--https://www.reddit.com/r/gamedev/comments/13y26t/how_do_rhythm_games_stay_in_sync_with_the_music/
end
Now you said you need to work with the beat to beat calculation.. hmm
First, i'd get the current milliseconds between every beat of the song (you can calculate this based on the BPM).
Then, starting from 0 i'd generate a list with every beat time in milliseconds..
Code: Select all
Say we have 300 milliseconds per beat for a given song. The list on it's first position would be 300, on the second position 600, on the third position 900... and so on until the BPM changes or the music reaches it's end.
Finally, to figure out how far are we from the next beat, we just get the
((time from the next beat)-(time from last beat))/(milliseconds per beat). And concatenate this with the current index of the beat on the table, hence, resulting in something like 3.4 or something of the sort.
@edit
I'm stupid, so the function was very very wrong. But it's fixed now!
![Razz :P](./images/smilies/ms-razz.png)