[SOLVED] Streaming sound crashes. (+loading screen)

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.
Post Reply
vt007
Prole
Posts: 14
Joined: Sun Oct 30, 2011 4:01 am

[SOLVED] Streaming sound crashes. (+loading screen)

Post by vt007 »

PROBLEM:
-when using streaming, sound gets all "clicky" and prog crashes.

QUESTION:
-how do i get rid of the sound bug and crashes when using streaming.

INFO:
-all drivers up to date (x86 w8RP 8400build, but had the same pb under w7)
-under love 0.8.0
-audio file is an.ogg (212kb .. 18sec) (not ticking under VLC)
-code exemple:

Code: Select all

function musicLoad()

	s = love.audio.newSource("music/music .ogg") 
	s :setVolume(0.5)
	s:setLooping(true)

end
then i call it as this

Code: Select all

function love.update(dt)
     if player >= 450 then
			love.audio.play(s)
		else
			love.audio.stop(s)
		end
end
and it crashes

thank you for your time ^^
.
Last edited by vt007 on Sun Sep 02, 2012 4:12 pm, edited 2 times in total.
vt007
Prole
Posts: 14
Joined: Sun Oct 30, 2011 4:01 am

Re: Streaming sound crashes.

Post by vt007 »

[updted]
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Streaming sound crashes.

Post by bartbes »

I am not sure what that "player" variable is, but nevertheless calling love.audio.play and love.audio.stop this often extremely hampers audio playback, and it wouldn't surprise me if this is what's leading to your crashes.
vt007
Prole
Posts: 14
Joined: Sun Oct 30, 2011 4:01 am

Re: Streaming sound crashes.

Post by vt007 »

player is just a .png pic that moves with direction keys...

i see what you mean, no streaming for sound effects... got it. ^^

so how can i get a loading screen then before jumping into the game? because there is a white screen while all the music is loading into the memory when you're using "static"...
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: Streaming sound crashes.

Post by Santos »

A simple way to have a loading screen is like this:

Code: Select all

function love.load()
	loadingStage = 'start'	
end

function love.update()
	if loadingStage == 'start' then
		loadingStage = 'loading'
		return
	elseif loadingStage == 'loading' then
		loadImages()
		loadingStage = 'done'
	end

	-- Game stuff here!
end

function love.draw()
	if loadingStage == 'loading' then
		drawLoadingScreen()
		return
	end

	-- Game stuff here!
end
Here's how this works:

Note: In the default love.run, love.update is run before love.draw.
  • First love.load runs, and loadingStage is set to 'start'.
  • Then love.update runs, and loadingStage is set to 'loading' and the rest of love.update is skipped using return.
  • Then love.draw runs, and the loading screen is drawn, and the rest of love.draw is skipped using return.
  • Then love.update runs, and the images are loaded, and loadingStage is set to 'done'.
  • The rest of love.update is run, then love.draw and love.update run normally!
For a more advanced solution (if you wanted an animated loading screen for example), you might want to try something like love-loader.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Streaming sound crashes.

Post by bartbes »

My gripes with doing this in love.update is that this unnecessarily bothers the audio thread (which is busy trying to send you smooth audio), since generally a sound hasn't ended before love.update runs the next time. If you want a looping sound (looks like it), you can use Source:setLooping. In any case, I would advice you to only call play or stop (or any of the source functions, for that matter) when you actually want to change something. When you want to start playing, not when you want to continue playing, etc.
vt007
Prole
Posts: 14
Joined: Sun Oct 30, 2011 4:01 am

Re: Streaming sound crashes.

Post by vt007 »

@Santos
very clean exemple, thank you ^^ so i guess i can use it for sound too by placing loadSound() near loadImages()?

@bartbes
i guess i should handle the sound like a particle system(which im more familiar with) ^^ thanks
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: [SOLVED] Streaming sound crashes. (+loading screen)

Post by Santos »

I'm glad I could help! ^^ Yep, you could load sound there too. :)

So for continuing sound, would it be better to do something like this?

Code: Select all

function love.load()
	s = love.audio.newSource("music/music.ogg")
end

function love.update(dt)
	if player >= 450 then
		playAudio()
	else
		stopAudio()
	end
end

function playAudio()
	if s:isStopped() then
		s:play()
	end
end

function stopAudio()
	if not s:isStopped() then
		s:stop()
	end
end
Or is LÖVE doing this internally?
vt007
Prole
Posts: 14
Joined: Sun Oct 30, 2011 4:01 am

Re: [SOLVED] Streaming sound crashes. (+loading screen)

Post by vt007 »

yes well its what i was thinking, if its working for particle system like this:

Code: Select all

function love.update(dt)
   if player >= 450 then
      p:start()
   else
      p:stop()
   end
end
then it should for the sound... ^^

but still its a good question.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 1 guest