Sign in to follow this  

DynamicSoundEffectInstance.BufferNeeded event not firing

This topic is 438 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I start create my Speaker and feed it data it seems to only play the first buffer. The method that feeds in buffers first checks needbuffers flag and just returns and does nothing if it's false. My setneedbuffers event handler is never called (I set a break point in it) and needbuffers flag never gets set back to true.

 

If I pause execution and check the state of DynSoundInst it's still set to "playing". DynamicSoundEffectInstance is suposed to stop playback if its starved of data, but that's not the case here.

    public class Speaker_XNA : Speaker
    {
        DynamicSoundEffectInstance DynSoundInst;
        bool needbuffers = true;
        short bitspersample;

        public Speaker_XNA(short BitsPerSample, short Channels, int SamplesPerSecond)
        {
            FrameworkDispatcher.Update();
            DynSoundInst = new DynamicSoundEffectInstance(SamplesPerSecond, (AudioChannels)Channels);
            bitspersample = BitsPerSample;
            DynSoundInst.BufferNeeded += setneedbuffers;

        }
        private void setneedbuffers(object sender, EventArgs e)
        {
            needbuffers = true;
        }
...
}

Share this post


Link to post
Share on other sites

I have ran into the same problem with MonoGame recently: the BufferNeeded event is not firing. I took a look at the current MG sourcecode but unfortunately I haven't been able to track down the cause yet.

The only thing I found related to your question was an issue related to FNA:

 

https://github.com/flibitijibibo/FNA-MGHistory/issues/320

 

According to this DynamicSoundEffenctInstance never changes its state back to SoundState.Stopped unless Stop() is called. 

If it runs out of data, it will be still playing if it is fed with buffers again, however I wasn't able to do it without the BufferNeeded event. The PendingBufferCount property could be used but I would prefer to avoid polling it continuously.

 

Have you found the casue? Anyone else has any ideas?

Share this post


Link to post
Share on other sites

This topic is 438 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this