Page 1 of 1
[SOLVED] Streaming sound crashes. (+loading screen)
Posted: Fri Aug 31, 2012 1:10 pm
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
.
Re: Streaming sound crashes.
Posted: Sun Sep 02, 2012 1:16 pm
by vt007
[updted]
Re: Streaming sound crashes.
Posted: Sun Sep 02, 2012 1:43 pm
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.
Re: Streaming sound crashes.
Posted: Sun Sep 02, 2012 1:57 pm
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"...
Re: Streaming sound crashes.
Posted: Sun Sep 02, 2012 2:24 pm
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.
Re: Streaming sound crashes.
Posted: Sun Sep 02, 2012 2:31 pm
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.
Re: Streaming sound crashes.
Posted: Sun Sep 02, 2012 4:11 pm
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
Re: [SOLVED] Streaming sound crashes. (+loading screen)
Posted: Sun Sep 02, 2012 4:37 pm
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?
Re: [SOLVED] Streaming sound crashes. (+loading screen)
Posted: Sun Sep 02, 2012 6:33 pm
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.