Song Rewinder v2.0

Show off your games, demos and other (playable) creations.
Post Reply
Connorses
Citizen
Posts: 63
Joined: Fri Sep 06, 2013 7:02 am

Song Rewinder v2.0

Post by Connorses »

This is basically a prank, it's a simple script that has a chance to rewind a song to one of the listed times, whenever it reaches one of the times in the list.

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
Attachments
SongRewinder_v2.0.zip
(33.5 MiB) Downloaded 156 times
Connorses
Citizen
Posts: 63
Joined: Fri Sep 06, 2013 7:02 am

Re: Song Rewinder v2.0

Post by Connorses »

My friend made excellent use for this as background music for his stream while he's in between playing games.
I just had to share.
https://clips.twitch.tv/GleamingBlatant ... 2J9R2yd0is
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 9 guests