views:

19

answers:

1

I'm trying to understand the threading and queuing model when used SoundEffect.Play() so that I can play notes with accurate timing.

Is the sound played back synchronously on the UI thread? Or is a background thread used to play the samples at the correct time?

I've read that I need to call FrameworkDispatcher.Update() for the sounds to play, but what is this doing?

Is there a queue for the sounds? What if I call play on a SoundEffect that is already playing. Will another instance be started in parallel, or will the current stop first?

As for sequencing sounds I assume the best approach is to use a background thread and Thread.Sleep() to make sure I wake up at the correct time to play the next "note". Or is there a better way to handle this?

A: 

SoundEffects play Asynchronously. That's why you can have lots of them playing at once.

Assuming that you're creating an app in Silverlight, FrameworkDispatcher.Update() must be called (typically 20 times a second) because SoundEffect is from the XNA framework and is expecting an underlying game loop as part of it's execution model. Repeated calls to FrameworkDispatcher.Update() simulate this.

Setting up calls to this in an ApplicationLifeObject is the way this is most typically done.

In terms of sequencing sounds, I'd use a timer and trigger new sounds to play that way rather than have lots of calls to Thread.Sleep.

Matt Lacey