I'm a bit confused about how to go about playing audio in Love. I'm told that using love.audio.newSource() shouldn't be called too often, as it loads and decodes the file each time. Now if I want to play a sound each time a collision happens between a bunch of boxes, I can't use one source, as I can't play multiple instances of one source at once.
I don't think I should construct a SoundData object once and then construct multiple sources off that each time a collision occurs, because the wiki says that converting a sound file into raw sound data is expensive.
So my last option is constructing a Decoder once and then constructing multiple sources off that. However it seems that a Decoder is only used as something to decode a sound file, so the decoding would still happen each I call newSource()? Is that correct? The documentation doesn't say anything about the performance implications of this.
Also as a side note, can someone explain to me the position, orientation and velocity functions of the love.audio module? The documentation is a bit sparse on these ones and I'm not really sure how to use it (for example, what on earth is a floatArray?).
Thanks guys!
How to go about audio
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: How to go about audio
I'm using setPosition here: https://bitbucket.org/dannyfritz/blind- ... .lua#cl-11
and setOrientation here: https://bitbucket.org/dannyfritz/blind- ... .lua#cl-65
Very simple program to look at. The float arrays are actually just (number, number, number) I believe since all Lua knows are doubles.
The arrays are (x,y,z) because all sound is done in 3D space, not 2D.
and setOrientation here: https://bitbucket.org/dannyfritz/blind- ... .lua#cl-65
Very simple program to look at. The float arrays are actually just (number, number, number) I believe since all Lua knows are doubles.
The arrays are (x,y,z) because all sound is done in 3D space, not 2D.
Re: How to go about audio
No, that's incorrect. If you create a Source from a SoundData, it'll just use the same SoundData as every other source spawned from it.BlackBulletIV wrote: I don't think I should construct a SoundData object once and then construct multiple sources off that each time a collision occurs, because the wiki says that converting a sound file into raw sound data is expensive.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: How to go about audio
Oh ok. But I'm still not sure how those functions effect the sound (I guess I'll to learn by trial and error).TechnoCat wrote:I'm using setPosition here: https://bitbucket.org/dannyfritz/blind- ... .lua#cl-11
and setOrientation here: https://bitbucket.org/dannyfritz/blind- ... .lua#cl-65
Very simple program to look at. The float arrays are actually just (number, number, number) I believe since all Lua knows are doubles.
The arrays are (x,y,z) because all sound is done in 3D space, not 2D.
What is incorrect? I realise that they'll share the same SoundData, that's the reason I thought this method may have a little bit of merit in it. Or are you saying that if they all share the same SoundData, I still won't be able to play multiple sounds over each other?thelinx wrote:No, that's incorrect. If you create a Source from a SoundData, it'll just use the same SoundData as every other source spawned from it.BlackBulletIV wrote: I don't think I should construct a SoundData object once and then construct multiple sources off that each time a collision occurs, because the wiki says that converting a sound file into raw sound data is expensive.
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: How to go about audio
thelinx is generally more knowledgeable than me when it comes to... Most things. But I believe that your approach is the correct one for sounds. At least that's how me and bartbes have been doing it. First you load your sound as sounddata, and when you want to play it, you create a newSource out of it.BlackBulletIV wrote:What is incorrect? I realise that they'll share the same SoundData, that's the reason I thought this method may have a little bit of merit in it. Or are you saying that if they all share the same SoundData, I still won't be able to play multiple sounds over each other?thelinx wrote:No, that's incorrect. If you create a Source from a SoundData, it'll just use the same SoundData as every other source spawned from it.BlackBulletIV wrote: I don't think I should construct a SoundData object once and then construct multiple sources off that each time a collision occurs, because the wiki says that converting a sound file into raw sound data is expensive.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: How to go about audio
That should mean you're right.
I shall explain why: SoundData is already decoded.
I shall explain why: SoundData is already decoded.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: How to go about audio
Oh so loading SoundData is not as bad as I thought. Well I'll do that then. I just found out that creating a new source from a file every time a collision occurs is bad news... Love started to freeze, and then crashed. Thanks guys!
Re: How to go about audio
Taehl and I wrote a sound module that works with sound a lot more sensibly than LOVE alone. It works completely with LOVE and requires no extra files or DLLs, just a Lua file and a require in your main file.
Go to http://love2d.org/forums/viewtopic.php?f=5&t=2334 for further information.
Go to http://love2d.org/forums/viewtopic.php?f=5&t=2334 for further information.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: How to go about audio
Yeah I've actually already got that and I've been digging around in the source code to see how it's done. One question about it, you seem to be creating a new source off a file every time someone plays a sound, isn't that expensive? I know when I did that for every time I had a physics collision with a velocity greater than 100 or something, Love crashed very quickly.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How to go about audio
I don't know about sources being expensive, but if you want to create lots of them, you could try keeping a pool of sources, and taking one out if the sound needs to be played, and putting it back in if the sound is done playing.BlackBulletIV wrote:Yeah I've actually already got that and I've been digging around in the source code to see how it's done. One question about it, you seem to be creating a new source off a file every time someone plays a sound, isn't that expensive? I know when I did that for every time I had a physics collision with a velocity greater than 100 or something, Love crashed very quickly.
Help us help you: attach a .love.
Who is online
Users browsing this forum: Amazon [Bot] and 4 guests