Issue: Two problems with SoundEffects

Jul 29, 2009 at 2:21 AM

The first issue I have is that the sound effect just isn't playing. I have it added to the Silverlight project ast a wma file with the type set to "Content" but when the .Play method is getting called no sound effect plays. The sound effect works fine in XNA.

The second issue is there is no overload for the "Play" method for a SoundEffect that matches the method signature for the Play method in XNA causing me to have to write code like this:

    _menuHover.Play(1f, -1f, 0f, false);
    _menuHover.Play(.5f, -1f, 0f);
Thanks, I am using the 2.0 framework but I plan on using the 3 stuff soon so  it is no problem if these fixes are all made to the 3.0 stuff.

Aug 2, 2009 at 10:19 PM
Edited Aug 2, 2009 at 11:02 PM

I found that the sound wasn't working because I load the same effect in more than one game component (although these game components aren't both open at the same time). The first time I load my sound effect the variable "StreamResourceInfo info;" in the SoundEffect class is set correctly. After that, it is added to the static variable "Dictionary<string, byte[]> soundBuffers = new Dictionary<string, byte[]>();" variable correctly as well. The next time I load the sound effect (in a different game component) the dictionary still has the effect so it skips loading it, which doesn't populate the "StreamResourceInfo info;" variable. The problem is that the Play method does *not* play from the dictionary, but from the info variable. Since info is null, my effect does not play.

I solved it modifying as little code as possible, from:

static Dictionary<string, byte[]> soundBuffers = new Dictionary<string, byte[]>();


Dictionary<string, byte[]> soundBuffers = new Dictionary<string, byte[]>();

on line 20 of SilverArcade.SilverSprite.Audio.SoundEffect. Although not using the info variable for anything after the effect has been loaded and added to the soundBuffer dictionary object could be a potential fix as well.

The overload problem was of course a lot more straight forward, I just added this to the same SoundEffect class:


public SoundEffectInstance Play(float volume, float pitch, float pan)
    var effect = Play(volume);

    return effect;

Which brings up an interesting observation, I didn't see it noted in any of the documentation or discussions but it looks as though pitch, pan and loop aren't honored in the Play methods that accept those parameters. Just an FYI if it was overlooked accidentally.

As always thanks for such a great tool to the game developer community!


Aug 7, 2009 at 1:02 AM

Thanks for posting these fixes, we'll get them incorporated as soon as possible. You're right, we don't implement everything in audio right now, probably our weakest part. Some of it is limitations in Silverlight but we need to revisit these now that Silverlight 3 is out and see if there is anything we can improve.