For example, if I have an animation that plays a sound repeatedly (a ball bounces around), what do I do to make the sounds mix in a proper way?
Do I need to creat a new source every time from the same sound data?
Correct way to play sounds?
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: Correct way to play sounds?
You don't need to. Create the source once. and then use source controls.
Dunno for sure if you're looking for that, but if you are continuously sending playing calls to a source, and you are not sure whether or not the source is actually being played, then you can rewrite love.audio.play in a manner it always rewinds the source before playing it.
Dunno for sure if you're looking for that, but if you are continuously sending playing calls to a source, and you are not sure whether or not the source is actually being played, then you can rewrite love.audio.play in a manner it always rewinds the source before playing it.
Code: Select all
local old_love_audio_play = love.audio.play
function love.audio.play(source)
if not source:isStopped() then
source:rewind()
else
old_love_audio_play(source)
end
end
Re: Correct way to play sounds?
Perhaps I didn't say it clearly. What I want to do is to have multiple sounds playing at the same time, so I don't want the first one to stop nor want to wait for it to stop.
The idea I had in mind was like this:
------------------------
Edit*
I tried the method I mentioned just now. It seemed to work well on this pc (no lags I could tell).
But I'm not sure if creating sound source is an acceptable way.
The idea I had in mind was like this:
Code: Select all
local sdping = love.sound.newSoundData("ping.wav")
function playSound(sd)
love.audio.newSource(sd, "static"):play()
end
playSound(sdping)
------------------------
Edit*
I tried the method I mentioned just now. It seemed to work well on this pc (no lags I could tell).
But I'm not sure if creating sound source is an acceptable way.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Correct way to play sounds?
That is, in fact, the proper (and only) way to play a single sound multiple times simultaneously.utunnels wrote:But I'm not sure if creating sound source is an acceptable way.
Help us help you: attach a .love.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Correct way to play sounds?
And, I think LÖVE should provide a way to do that by default, since this question has been asked again and again.Robin wrote:That is, in fact, the proper (and only) way to play a single sound multiple times simultaneously.
Don't want to repeat myself too much: LÖVE needs a first-class "Sound" entity that acts as a "Source manager". When a Sound is played, a new (or existing in the Sound's pool) Source should be returned by love.play. This is too basic to need external libraries.
When I write def I mean function.
- dreadkillz
- Party member
- Posts: 223
- Joined: Sun Mar 04, 2012 2:04 pm
- Location: USA
Re: Correct way to play sounds?
The way sound is handled isn't very intuitive if you're new. It's not like an image object where you can just draw as many copies of an image as you want. I too share the same sentiment as kikito.
Re: Correct way to play sounds?
It shouldn't be hard to write a a wrapper in lua.
Another thing I'm concerning is the unlimited new sound source may cause booms. It works well on my pc, but lags and booms on android if too many sounds are created. Though android version is not an official release, perhaps it is still necessary to have some limit.
For example, have a pool with limited size, when a new source is played, check the pool, if it is full, find a source which is already stopped or has lower priority, replace it with the new source.
Another thing I'm concerning is the unlimited new sound source may cause booms. It works well on my pc, but lags and booms on android if too many sounds are created. Though android version is not an official release, perhaps it is still necessary to have some limit.
For example, have a pool with limited size, when a new source is played, check the pool, if it is full, find a source which is already stopped or has lower priority, replace it with the new source.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Correct way to play sounds?
I didn't say "it is hard to write a wrapper in Lua". I said "it should be done by LÖVE". The fact that is (allegedly) simple to do doesn't mean that it should be done by default. It's not a matter of difficulty, it's a matter of convenience and expectatives.utunnels wrote:It shouldn't be hard to write a a wrapper in lua.
It shouldn't be hard to write a wrapper in Lua (see? )utunnels wrote:Another thing I'm concerning is the unlimited new sound source may cause booms. It works well on my pc, but lags and booms on android if too many sounds are created. Though android version is not an official release, perhaps it is still necessary to have some limit.
Now, seriously. As you say the Android version is even less official than LÖVE. If worst comes to worst, the android version could add a limit for Android.
I was thinking about having an optional `sources` param at the end of love.audio.newSound, maybe default to 4. Or a constant in love.audio (love.audio.setSourcePoolSize(...)). I'm open to anything on that regard.utunnels wrote:For example, have a pool with limited size, when a new source is played, check the pool, if it is full, find a source which is already stopped or has lower priority, replace it with the new source.
When I write def I mean function.
Re: Correct way to play sounds?
I think that's overkill, and it will just add to the confusion (we already have enough sound-related classes as it is). A much simpler solution would be to just allow love.audio.play() to take either a Source or a SoundData as the parameter.kikito wrote:Don't want to repeat myself too much: LÖVE needs a first-class "Sound" entity that acts as a "Source manager".
Who is online
Users browsing this forum: No registered users and 6 guests