Source and SoundData

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
MachineCode
Citizen
Posts: 70
Joined: Fri Jun 20, 2014 1:33 pm

Source and SoundData

Post by MachineCode »

I have a question about the audio system. What I want to do is make a SoundData buffer of a fixed length and then synthesize samples into that using some algorithms. This needs to be wrapped into a Source so it can be played or looped.

If I modify the SoundData with SoundData:setSample, will this change what gets played the next time? There does not seem to be an update for Source to reflect changes in the SoundData buffer.

Do I need to create a new Source from the SoundData to effect the changes? If so, how much overhead is that likely to create? The wiki has a warning about repeatedly calling newSource, but does that apply when using in memory SoundData buffers (as opposed to reading files or activating decoders)?
User avatar
pgimeno
Party member
Posts: 3551
Joined: Sun Oct 18, 2015 2:58 pm

Re: Source and SoundData

Post by pgimeno »

I suggest you take a look at this library which is already doing that: https://github.com/nucular/sfxrlua
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Source and SoundData

Post by zorg »

Unfortunately, even if you modify the SoundData object, it won't have any effect on an already playing source unless you load it into the Source again.
But, i did experiment with realtime sound generation myself, and currently, lpghatguy's QueuableSource module would be something you should try in my opinion :3

I also linked my own thing so you can see how i got it to work, it's p. ugly though, and probably unoptimized, but at least it mostly works!
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
MachineCode
Citizen
Posts: 70
Joined: Fri Jun 20, 2014 1:33 pm

Re: Source and SoundData

Post by MachineCode »

OK thanks for that. I will take a look at your project - it looks like you went down a similar track, but it does not look simple.

The problems I see are first, that after modifying the SoundData, you need to create a new Sound object and discard the old one - which is probably quite expensive if done often.

The second one is that there is no built in way to queue a second Sound to play after the first. That means that trying to set up ping-pong sound buffers in a loop is not going to be viable. Playing or looping a segment of a Sound doesn't seem to be available, although it should be possible.

I need to do some more reading.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Source and SoundData

Post by zorg »

You're welcome. :3

Technically, it's enough to modify the SoundData, and queue that up with the QSource, if using that; but it could be done faster of course, using pure FFI arrays.

Also, OpenAL does have a built-in way to queue data constantly, though löve itself doesn't (expose it nor implements it in any way), at the moment.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Source and SoundData

Post by bobbyjones »

zorg wrote:You're welcome. :3

Technically, it's enough to modify the SoundData, and queue that up with the QSource, if using that; but it could be done faster of course, using pure FFI arrays.

Also, OpenAL does have a built-in way to queue data constantly, though löve itself doesn't (expose it nor implements it in any way), at the moment.
Yeah that's the reason we can't have Issue #1 solved already.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 58 guests