How to go about audio

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.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

How to go about audio

Post by BlackBulletIV »

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!
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: How to go about audio

Post by TechnoCat »

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.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: How to go about audio

Post by thelinx »

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.
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.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: How to go about audio

Post by BlackBulletIV »

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.
Oh ok. But I'm still not sure how those functions effect the sound (I guess I'll to learn by trial and error).
thelinx wrote:
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.
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.
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?
User avatar
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

Post by nevon »

BlackBulletIV wrote:
thelinx wrote:
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.
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.
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 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: How to go about audio

Post by bartbes »

That should mean you're right. :P

I shall explain why: SoundData is already decoded.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: How to go about audio

Post by BlackBulletIV »

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!
User avatar
Ensayia
Party member
Posts: 399
Joined: Sat Jun 12, 2010 7:57 pm

Re: How to go about audio

Post by Ensayia »

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.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: How to go about audio

Post by BlackBulletIV »

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

Re: How to go about audio

Post by Robin »

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.
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.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 4 guests