Jump to content
CrazyM

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

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.

Share this post


Link to post

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

Share this post


Link to post

In C++ you can do

 

emitter->EmitSound(snd);
Source* s = emitter->activesources.front();

 

with emitter being an Entity and snd a Sound.

Surely this isn't the cleanest way. I agree, it would be nice to have the actual Source returned by the Emit-Call.

Share this post


Link to post

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.

Share this post


Link to post

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()

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...