I'm developing a little game in my past-time, and I had an idea which involved modulating the pitch of a sound file every time it finishes playing according to a certain scheme. I do this by checking it each update loop, and if it's playing I check to see if it's still playing. If not - I go on to the next bit.
I initialize it like so:
Code: Select all
self.source = love.audio.newSource(filename, "static")
self.source:setLooping(false)
Later on, I check to see what needs to be done:
Code: Select all
if self.source:isStopped() then
-- Now we know that it has stopped playing.
-- So I'll go on to the next bit, change the pitch and play the sound again.
end
So my main question is how do I know when a sound has finished playing? And secondly, what else might I be doing wrong?
EDIT:
I spent a while tinkering and it just occurred to me that that this is a format issue. I converted the wav to an ogg, and it now detects when it stopped. However, I am now experiencing an issue where the number of times it plays the sound is inconsistent when it is very clear it should only play an X number of times.
How accurate (in terms of time) is :isStopped if I call it every time from the update loop?