Gun sounds

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
veethree
Inner party member
Posts: 820
Joined: Sat Dec 10, 2011 7:18 pm

Gun sounds

Post by veethree »

Hey guys. So i need some help with gun sounds.I have a gun sound that plays every time the gun is shot, Problem is if you shoot rapidly it doesn't play the sound every time you shoot, I figured that's because it's only capable of playing the same sound once any given time and wont play it again until it's done playing the first one until the very end. So is there any good way to get around that? Thanks in advance.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Gun sounds

Post by nevon »

Save the sound as sound data, create a sound queue and every time you need to play the sound, create a new source from the sounddata and add it to the queue. Once it's finished playing, remove it from the queue.
User avatar
baconhawka7x
Party member
Posts: 484
Joined: Mon Nov 21, 2011 7:05 am
Contact:

Re: Gun sounds

Post by baconhawka7x »

What I do is, just before playing the sound, I stop the one before it...'

Code: Select all

love.audio.stop(gunsound)
love.audio.play(gunsound)
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Gun sounds

Post by Nixola »

There's a lib meant to solve ths problem, but I can't remember its name...
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
veethree
Inner party member
Posts: 820
Joined: Sat Dec 10, 2011 7:18 pm

Re: Gun sounds

Post by veethree »

baconhawka7x wrote:What I do is, just before playing the sound, I stop the one before it...'

Code: Select all

love.audio.stop(gunsound)
love.audio.play(gunsound)
How did i not think of that shit...it's so simple..lol
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Gun sounds

Post by coffee »

Nixola wrote:There's a lib meant to solve ths problem, but I can't remember its name...
Perhaps https://love2d.org/wiki/Minimalist_Sound_Manager?

EDITED: OMG 666 Posts! KARMA 13! Perfect combo!
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Gun sounds

Post by nevon »

Nixola wrote:There's a lib meant to solve ths problem, but I can't remember its name...
I think you're referring to TESound. There's also mine and bartbes' soundmanager.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Gun sounds

Post by coffee »

I think you're referring to TESound.
Which concerning managing/queue sounds don't seem to do much more than minimalistic
There's also mine and bartbes' soundmanager.
That appear require an account to even check it.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Gun sounds

Post by nevon »

coffee wrote:
There's also mine and bartbes' soundmanager.
That appear require an account to even check it.
What the...? That's the OSS fork. Why the heck is that private...?

Anyway, here's the soundmanager:

Code: Select all

soundmanager = {}
soundmanager.queue = {}
soundmanager.playlist = {}
soundmanager.currentsong = -1

local function shuffle(a, b)
	return math.random(1, 2) == 1
end

--do the magic
function soundmanager:play(sndData)
	--make a source out of the sound data
	local src = love.audio.newSource(sndData, "static")
	--put it in the queue
	table.insert(self.queue, src)
	--and play it
	love.audio.play(src)
end

--do the music magic
function soundmanager:playMusic(first, ...)
	--stop all currently playing music
	for i, v in ipairs(self.playlist) do
		love.audio.stop(v)
	end
	--decide if we were passed a table or a vararg,
	--and assemble the playlist
	if type(first) == "table" then
		self.playlist = first
	else
		self.playlist = {first, ...}
	end
	self.currentsong = 1
	--play
	love.audio.play(self.playlist[1])
end

--do some shufflin'
function soundmanager:shuffle(first, ...)
	local playlist
	if type(first) == "table" then
		playlist = first
	else
		playlist = {first, ...}
	end
	table.sort(playlist, shuffle)
	return unpack(playlist)
end

--update
function soundmanager:update(dt)
	--check which sounds in the queue have finished, and remove them
	local removelist = {}
	for i, v in ipairs(self.queue) do
		if v:isStopped() then
			table.insert(removelist, i)
		end
	end
	--we can't remove them in the loop, so use another loop
	for i, v in ipairs(removelist) do
		table.remove(self.queue, v-i+1)
	end
	--advance the playlist if necessary
	if self.currentsong ~= -1 and self.playlist and self.playlist[self.currentsong]:isStopped() then
		self.currentsong = self.currentsong + 1
		if self.currentsong > #self.playlist then
			self.currentsong = 1
		end
		love.audio.play(self.playlist[self.currentsong])
	end
end
Note that it also lets you play music playlists. It doesn't just do sound effects. But you can easily rip out the music bit if you don't need it.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Gun sounds

Post by coffee »

nevon wrote: What the...? That's the OSS fork. Why the heck is that private...?

Anyway, here's the soundmanager:
Thanks nevon, why you and bartbes (if you don't mind) don't add it to lib section? More choices is always better.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], L41A and 34 guests