Confused about sound and :isStopped()

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
adiron
Prole
Posts: 4
Joined: Sun Aug 18, 2013 7:31 am

Confused about sound and :isStopped()

Post by adiron »

Hi guys

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)
And later :play() it.

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
Unfortunately, :isStopped() always returns false no matter what, long after the sound has ended.

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?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Confused about sound and :isStopped()

Post by Robin »

Could you upload your .love? That way we can have a better grasp of what you're doing, and hopefully how to fix it.
Help us help you: attach a .love.
adiron
Prole
Posts: 4
Joined: Sun Aug 18, 2013 7:31 am

Re: Confused about sound and :isStopped()

Post by adiron »

Yes, I'll prepare a .love this evening.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Confused about sound and :isStopped()

Post by Boolsheet »

The current WAVE decoder LÖVE uses has issues and appends a few seconds of silence at the end. You're better off with ogg vorbis.
How accurate (in terms of time) is :isStopped if I call it every time from the update loop?
How many times per second can you execute the update loop?

The function itself also takes some time to execute, but that's just some microseconds. The value itself comes directly from OpenAL which means that this is most likely the point where it stopped pushing data to the audio backend. This audio system will have some latency as it is still pushing its buffers to the speakers, but that should be below 100 ms. Hopefully.
Shallow indentations.
adiron
Prole
Posts: 4
Joined: Sun Aug 18, 2013 7:31 am

Re: Confused about sound and :isStopped()

Post by adiron »

Hello again.

Ok, so this is what I have. The idea is a system that "reads" text and makes it sound sort of like speech as sometimes done in RPGs. It's very rudimentary and not fine tuned at all (Blabber:set_pitch is really just a placeholder for the real thing) which is why it sounds so terrible.

You will notice that the number of times it plays the sound is inconsistent. That's my main problem.

Another thing I noticed is that changing the pitch of a file changes its playing speed. Is there a way to only shift pitches? If you have any other suggestions for the code in general, do let me know.

I have included LCS in this .love file because it's a dependency of mine in the original code. Anything else is my code, so if you intend to use it for your own stuff, please ask for permission first :P

Anyway, thanks for the help.
Attachments
blabbertest.love
(35.61 KiB) Downloaded 103 times
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Confused about sound and :isStopped()

Post by Boolsheet »

adiron wrote:You will notice that the number of times it plays the sound is inconsistent. That's my main problem.
That indeed seems to be an issue in the LÖVE code. slime just pushed a fix for an issue that may be related to this. I don't know of a workaround for 0.8.0. Very annoying.
adiron wrote:Another thing I noticed is that changing the pitch of a file changes its playing speed. Is there a way to only shift pitches? If you have any other suggestions for the code in general, do let me know.
No, there's no setting for that. LÖVE uses OpenAL which has the pitch thing already built in. I think this is part of the specification because they already needed a resampler and adding this was not much additional work. Maybe it should get renamed speed in LÖVE, similar to Audacity's way of naming the three different things (speed, tempo, pitch). Adding tempo and pitch will require a lot of additional code (for proper quality).

You could create the 26 (or whatever) different sounds yourself and just play them in the order you want. Instead of relying on Source:isStopped, you could use a timer.

Note that with your current pitch calculation, Q and l (lower case L) will give you a pitch of 0 which is not valid.
Shallow indentations.
adiron
Prole
Posts: 4
Joined: Sun Aug 18, 2013 7:31 am

Re: Confused about sound and :isStopped()

Post by adiron »

Thank you for you help. I'll see what I can do and report back. As for the pitch algorithm itself, it obviously needs some work :P
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests