Has sound/music support changed again since 0.6.0?

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
Sslaxx
Citizen
Posts: 57
Joined: Sat Feb 14, 2009 8:54 pm
Location: Malvern, Worcs, UK
Contact:

Has sound/music support changed again since 0.6.0?

Post by Sslaxx »

I'm having an issue with some code. Not been updated since 0.6.0, seeing what if anything changed with 0.6.2. And I'm running into an issue where sound/music are cutting each other off. Not only that, but music appears to be cutting off randomly too.

Ubuntu 10.04, if that helps.

Anyone have any ideas? http://sslaxx.twu.net/EggTester.love if you want to take a look.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Has sound/music support changed again since 0.6.0?

Post by Jasoco »

Yeah. I get that too. I'm on OS X. Occasionally it'll just stop playing.

Also, I'm still bugged out that we can't call a Sound Effect twice and have it overlap. I need a function to let me call a sound file while it's already playing. Most games rely on layering the same sound over itself. I can't believe they changed that for 0.6.0. It worked perfectly in 0.5.0. I either need it back to what it was in 0.5.0 or a plugin library I can use that will let me do the same thing, i.e. call a sound effect multiple times even if it's still playing.

Examples where this is NEEDED:
Swinging my weapon rapidly
Tapping through the menus
More than one enemy is making the same sound at the same time
Rain
Etc...
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Has sound/music support changed again since 0.6.0?

Post by nevon »

Jasoco wrote:Also, I'm still bugged out that we can't call a Sound Effect twice and have it overlap. I need a function to let me call a sound file while it's already playing. Most games rely on layering the same sound over itself. I can't believe they changed that for 0.6.0. It worked perfectly in 0.5.0. I either need it back to what it was in 0.5.0 or a plugin library I can use that will let me do the same thing, i.e. call a sound effect multiple times even if it's still playing.

Examples where this is NEEDED:
Swinging my weapon rapidly
Tapping through the menus
More than one enemy is making the same sound at the same time
Rain
Etc...
You can still do that. Just load your sound effects as soundData, set up a sound queue, and whenever you need to play a sound effect, take that soundData and create a newSource that you add to your queue, then just play your newSource. Every loop you update your queue to check which sources have stopped playing and you remove them from the queue. It's a lot easier than it sounds (oh I made a funny!)

Bartbes wrote a soundmanager that I'm now using for everything. It's MIT licensed, so have fun. Just remember to load your sounds as soundData and your music as newSource.

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

function soundmanager:stop()
	--stop all currently playing music
	for i, v in ipairs(soundmanager.playlist) do
		love.audio.stop(v)
	end
end

--do the music magic
function soundmanager:playMusic(first, ...)
	soundmanager:stop()
	--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
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Has sound/music support changed again since 0.6.0?

Post by bartbes »

*cough* Obligation to reproduce the license *cough*

Code: Select all

Copyright (c) 2010 Bart van Strien and Tommy Brunn

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Has sound/music support changed again since 0.6.0?

Post by Jasoco »

Okay. So where's the documentation for it? I can't figure out how to actually use the code.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Has sound/music support changed again since 0.6.0?

Post by nevon »

Jasoco wrote:Okay. So where's the documentation for it? I can't figure out how to actually use the code.
There's no documentation since it's only been used "in-house" by me and Bartbes. It's simple enough though. Simply require it in your main.lua, then run soundmanager:update(dt) in your update loop.

soundmanager:playMusic(source1, source2, source3) to play a playlist.

soundmanager:play(soundData) plays a sound effect.

soundmanager:stop() stops all music.

soundmanager:shuffle() is supposed to be used inside playMusic(), to shuffle the tracks. So for example soundmanager:playMusic(soundmanager:shuffle(source1, source2, source3))
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Has sound/music support changed again since 0.6.0?

Post by Jasoco »

Thanks! I will implement it into my game and see how it goes! *crosses fingers*
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Has sound/music support changed again since 0.6.0?

Post by nevon »

Jasoco wrote:Thanks! I will implement it into my game and see how it goes! *crosses fingers*
Just remember that sound effects (anything that isn't music, basically) should be soundData, and music should be newSource. I always tend to mess that up (before I had bartbes' awesome resource loader, that is :awesome: )
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Has sound/music support changed again since 0.6.0?

Post by Jasoco »

Can't get it to work. I am doing it wrong.

I have this code that I run at startup:

Code: Select all

	sfx = {}
	sfx[1] = love.audio.newSource("game/audio/sfx/menu_cursor.ogg", "static")
	sfx[2] = love.audio.newSource("game/audio/sfx/menu_select.ogg", "static")
	sfx[10] = love.audio.newSource("game/audio/sfx/player_sword1.ogg", "static")
	sfx[14] = love.audio.newSource("game/audio/sfx/player_push.ogg", "static")
	sfx[15] = love.audio.newSource("game/audio/sfx/player_shield_reflect.ogg", "static")
	sfx[17] = love.audio.newSource("game/audio/sfx/player_lowhealth.ogg", "static")
	sfx[18] = love.audio.newSource("game/audio/sfx/player_hurt.ogg", "static")
	sfx[19] = love.audio.newSource("game/audio/sfx/player_die.ogg", "static")
	sfx[50] = love.audio.newSource("game/audio/sfx/get_money.ogg", "static")
	sfx[51] = love.audio.newSource("game/audio/sfx/get_item.ogg", "static")
	sfx[52] = love.audio.newSource("game/audio/sfx/get_health.ogg", "static")
	sfx[53] = love.audio.newSource("game/audio/sfx/get_key.ogg", "static")
	sfx[57] = love.audio.newSource("game/audio/sfx/get_chest.ogg", "static")
	sfx[59] = love.audio.newSource("game/audio/sfx/get_money_fanfare.ogg", "static")
	sfx[80] = love.audio.newSource("game/audio/sfx/door_open.ogg", "static")
	sfx[81] = love.audio.newSource("game/audio/sfx/door_close.ogg", "static")
	sfx[82] = love.audio.newSource("game/audio/sfx/stairs_up.ogg", "static")
	sfx[83] = love.audio.newSource("game/audio/sfx/stairs_down.ogg", "static")
	sfx[90] = love.audio.newSource("game/audio/sfx/bomb_drop.ogg", "static")
	sfx[91] = love.audio.newSource("game/audio/sfx/bomb_blow.ogg", "static")
	sfx[100] = love.audio.newSource("game/audio/sfx/enemy_hit.ogg", "static")
	sfx[101] = love.audio.newSource("game/audio/sfx/enemy_die.ogg", "static")
	sfx[500] = love.audio.newSource("game/audio/sfx/shatter.ogg", "static")
	sfx[501] = love.audio.newSource("game/audio/sfx/arrow_shoot.ogg", "static")
	sfx[502] = love.audio.newSource("game/audio/sfx/arrow_hit.ogg", "static")
	sfx[700] = love.audio.newSource("game/audio/sfx/thunder.ogg", "static")
	sfx[800] = love.audio.newSource("game/audio/sfx/rain_outside.ogg", "static")
	sfx[997] = love.audio.newSource("game/audio/sfx/text_letter.ogg", "static")
	sfx[998] = love.audio.newSource("game/audio/sfx/text_done.ogg", "static")
	sfx[999] = love.audio.newSource("game/audio/sfx/exitgame.ogg", "static")
	sfx[1000] = love.audio.newSource("game/audio/sfx/Der Kleber Sting.ogg", "static")
I changed it to love.audio.soundData and it won't work. I even changed it to love.audio.newSoundData and it still won't work.

Can you walk me through it? I get an error right at that first line before soundmanager:update is even called.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Has sound/music support changed again since 0.6.0?

Post by bartbes »

love.sound.newSoundData.
Post Reply

Who is online

Users browsing this forum: No registered users and 129 guests