Ripple - audio library with tags and music-timed events

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Ripple - audio library with tags and music-timed events

Post by Tesselode »

Hey all,

I've been working on an audio library called Ripple. It has tags and nice features for music. Example:

Code: Select all

ripple = require 'ripple'

tags = {
  sfx = ripple.newTag(),
  music = ripple.newTag(),
  master = ripple.newTag(),
}

sounds = {
  shoot = ripple.newSound('shoot.ogg', {
    tags = {tags.sfx, tags.master},
  }),
}

music = {
  gameplay = ripple.newSound('gameplay.ogg', {
    bpm = 130,
    length = '32m',
    loop = true,
    tags = {tags.music, tags.master},
  })
}
music.gameplay.every['1b'] = function() background:flashOnBeat() end

tags.master:setVolume(.8)
music.gameplay:play()

function player:shoot()
  sounds.shoot:play {pitch = .5*love.math.random() + .5}
end

function love.update(dt)
  for _, m in pairs(music) do
    m:update(dt)
  end
end
I'm lazy and don't feel like writing much right now, so

GitHub
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Ripple - audio library with tags and music-timed events

Post by zorg »

Nice to have something other than TESound! :3

My suggestion would be to allow setting the Time Signature (Or at least, how many beats are in a measure, though supporting specifying the note type per beat would be neat too.)

Also, do note that the temporal granularity of love.update may not be fast enough for this lib to work precisely enough, but that's the users' responsibility, not yours, but a notice wouldn't hurt in my opinion.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Re: Ripple - audio library with tags and music-timed events

Post by Tesselode »

zorg wrote:My suggestion would be to allow setting the Time Signature (Or at least, how many beats are in a measure, though supporting specifying the note type per beat would be neat too.)
Can you think of a specific instance where this would be useful? Or would it just be to make it more intuitive to work with songs of different time signatures? Either way, I think it's a good idea.
zorg wrote:Also, do note that the temporal granularity of love.update may not be fast enough for this lib to work precisely enough, but that's the users' responsibility, not yours, but a notice wouldn't hurt in my opinion.
Yeah, I've definitely had some timing issues with looping and chaining pieces of music. I really wish LOVE had some way of working with audio more precisely, but I imagine I would have this issue with virtually any game engine. Do you think modifying love.run to get rid of the pause between frames would help?
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Ripple - audio library with tags and music-timed events

Post by zorg »

Tesselode wrote:Can you think of a specific instance where this would be useful? Or would it just be to make it more intuitive to work with songs of different time signatures? Either way, I think it's a good idea.
Well, you did mention 8th notes as .5b or half-beat time intervals, that suggests to me common time, or 4/4. Just a thought, it's not necessary but yeah, intuition. Especially, if someone wants to create a game like Crypt of the Necrodancer or something, and wants to use music with weirder beats. :3
Tesselode wrote:Yeah, I've definitely had some timing issues with looping and chaining pieces of music. I really wish LOVE had some way of working with audio more precisely, but I imagine I would have this issue with virtually any game engine. Do you think modifying love.run to get rid of the pause between frames would help?
Thing is, i'd say yes, but this is a library. You can't really ask the ones creating their game to conform to your own specs like that, only to notify them through notices that this should be called more than the probable vsync=true option would allow. (Note that this shouldn't be THAT big of an issue, unless the songs are in the 300+BPM range, or you'd set the beats to 16th or even shorter notes (like 1024th notes :D))

That said, this is my current love.run that i use in my music generation related test projects:

Code: Select all

love.run = function()
	if love.math then
		love.math.setRandomSeed(os.time())
	end
 
	if love.load then love.load(arg) end
 
	-- We don't want the first frame's dt to include time taken by love.load.
	if love.timer then love.timer.step() end

	local dt = 0.0    -- delta time
 
	local tr = 1/100  -- tick rate
	local fr = 1/75   -- frame rate

	local da = 0.0    -- draw accumulator
	local ua = 0.0    -- update accumulator
 
	-- Main loop time.
	while true do
		-- Process events.
		if love.event then
			love.event.pump()
			for name, a,b,c,d,e,f in love.event.poll() do
				if name == "quit" then
					if not love.quit or not love.quit() then
						return a
					end
				end
				love.handlers[name](a,b,c,d,e,f)
			end
		end
 
		-- Update dt, as we'll be passing it to update
		if love.timer then
			love.timer.step()
			dt = love.timer.getDelta()
			da = da + dt
			ua = ua + dt
		end
 
		-- Call audio
		if love.atomic then love.atomic(dt) end

		-- Call update
		if ua > tr then
			if love.update then
				love.update(tr) -- will pass 0 if love.timer is disabled
			end
			ua = ua % tr
		end
 
		-- Call draw
		if da > fr then
			if love.graphics and love.graphics.isActive() then
				love.graphics.clear(love.graphics.getBackgroundColor())
				love.graphics.origin()
				if love.draw then love.draw() end -- no interpolation
				love.graphics.present()
			end
			da = da % fr
		end
 
		-- Optimal sleep time, anything higher does not go below 0.40 % cpu
		-- utilization; 0.001 results in 0.72 %, so this is an improvement.
		if love.timer then love.timer.sleep(0.002) end
	end
end
[/size]
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 87 guests