I tried to make it easy to understand, so that if folks want to play around with it they can. I figure it might be interesting for a game, since you could make songs that loop in unpredictable ways. I recommend using Audacity to select sections of a song and get the times at the start/end of the selection.
A friend of mine took interest in this old project. I looked at the code because he wanted to tweak some things. The code was so bad that I rewrote most of it.
THE CODE:
Code: Select all
--Song Rewinder v2.0
--by Connorses
source = love.audio.newSource("song.wav", "static")
times = {
1.46,
6.914,
7.872,
15.317,
18.902,
22.521,
26.198,
29.840,
32.594,
34.288,
37.124,
44.477,
51.830,
57.340
}
love.window.setTitle("\"Let the bodies hit the") --random window titles
rewindTime = 1; --Our place in the times array
love.audio.play(source)--This hack was a mistake.
function love.load()
whale = love.graphics.newImage("whale record.png")
love.graphics.setBackgroundColor(224, 244, 252)
end
function love.update()
index = source:tell()
if rewindTime <= #times and index >= times[rewindTime] then
rollDice();
end
end
function love.draw()
love.graphics.draw(whale, 400,300, math.sin(index)/10, 1, 1, (500/2), (400/2))
end
function rollDice()
--If we roll a certain percentage chance, rewind the song to the previous time entry
if (rewindTime > 1 and love.math.random(100) < 66) then
--Also, for every consecutive roll of a certain percentage, set the rewind 1 more entry back.
while (rewindTime > 2 and love.math.random(100) < 17) do
rewindTime = rewindTime - 1;
end
--Set the time to rewindTime - 1 (since we are waiting to reach rewindTime to roll dice again, we rewind to an entry before it.)
source:seek( times[rewindTime-1], "seconds" );
else
--Finally, if we fail the roll to rewind at all we wait for the next entry.
rewindTime = rewindTime + 1;
end
end