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);
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!