Jump to content

Entity:EmitSound() loop, stop, and restart?


CrazyM
 Share

Recommended Posts

Doe anyone know if you can stop a looping Entity:EmitSound() method without releasing the entity, then start the sound again back in loop mode?

 

It looks like EmitSound automatically creates a Source and the entity manages it. Is there some way to get reference to this Source to call Source:Stop()?

 

EDIT:

Nevermind, I'll just create and manage the Source manually.

Link to comment
Share on other sites

In LE2's lua, the source was the entity emitting the sound as the command would return a TSource

source = box:EmitSound(sound,5,1)

unfortunately, it appears that no longer works...

 

sounds like a good thing to bring up in the suggestions... or at least a need for an entity:GetSource() command

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

The reason for this design is returning a source would require the user to release it. This would likely cause more problems then it solves.

 

What about a new overload that accepts a source as an argument? This would allow you to retain control of the source and remain simple to use. The only thing this adds is that the source will automatically have its position updated when the entity moves.

  • Upvote 3

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

What about a new overload that accepts a source as an argument? This would allow you to retain control of the source and remain simple to use. The only thing this adds is that the source will automatically have its position updated when the entity moves.

so something like static Model* Load(const std::string& path, int flags=0, const uint64_t fileid=0, Source *source=null)? or would it be easier to have something like entity:SetSource() / entity:GetSource()? granted your way would solve the problem as long as all the available model entities have this overload... and it would basically remove the need for EmitSound()

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

The reason for this design is returning a source would require the user to release it.

 

If there was only a pointer returned, that would not be the case.

IMHO the most logical way to do that would be:

A pointer to the created source is returned but the refcounter is not increased.

If the user wants to keep the reference, he can increase its refcounter (src->AddRef()), so it would not be automatically removed, when it finished playing (the refcount would only be decreased by 1 (Currently it isn't even possible to keep the reference any further due to the bug I reported here: http://www.leadwerks.com/werkspace/topic/10804-finished-sound-sources-are-released-every-frame/)). If the user does not add a reference, the source will be removed once it finished and the user might end up with a corrupt reference, but that would be the user's own fault.

  • Upvote 1
Link to comment
Share on other sites

Wow, active discussion in my absence...LOL! I don't find the manually managed source route a bad option and am somewhat ambivalent. It would be nice to simply get a reference from EmitSound and have it's position updates already handled, but it's not really a big deal either way (to me anyway) now that I understand how it works.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...