public void Play()
{
var category = _soundBank.AudioEngine.Categories[_categoryID];
var curInstances = category.GetPlayingInstanceCount();
if (curInstances >= category.maxInstances)
{
var prevSound = category.GetOldestInstance();
if (prevSound != null)
{
prevSound.SetFade(0.0f, category.fadeOut);
prevSound.Stop(AudioStopOptions.Immediate);
SetFade(category.fadeIn, 0.0f);
}
}
if (_complexSound)
{
foreach (XactClip clip in _soundClips)
{
clip.Play();
}
}
else
{
if (_wave != null && _wave.State != SoundState.Stopped && _wave.IsLooped)
{
_wave.Stop();
}
else
{
_wave = _soundBank.GetSoundEffectInstance(_waveBankIndex, _trackIndex);
}
if (_wave == null)
{
// We couldn't create a sound effect instance, most likely
// because we've reached the sound pool limits.
return;
}
_wave.Play();
}
}