Example #1
0
        public void Play(float volume, AudioEngine engine)
        {
            _cueVolume = volume;
            var category = engine.Categories[_categoryID];

            UpdateCategoryVolume(category._volume[0]);

            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.Pitch  = _pitch + _cuePitch;
                _wave.Volume = _volume * _cueVolume * category._volume[0];
                _wave.PlatformSetReverbMix(_useReverb ? _cueReverbMix : 0.0f);
                _wave.Play();
            }
        }
Example #2
0
        /// <summary>
        /// Returns a pooled SoundEffectInstance if one is available, or allocates a new
        /// SoundEffectInstance if the pool is empty.
        /// </summary>
        /// <returns>The SoundEffectInstance.</returns>
        internal static SoundEffectInstance GetInstance(bool forXAct)
        {
            SoundEffectInstance inst = null;
            var count = _pooledInstances.Count;

            if (count > 0)
            {
                // Grab the item at the end of the list so the remove doesn't copy all
                // the list items down one slot.
                inst = _pooledInstances[count - 1];
                _pooledInstances.RemoveAt(count - 1);

                // Reset used instance to the "default" state.
                inst._isPooled = true;
                inst._isXAct   = forXAct;
                inst.Volume    = 1.0f;
                inst.Pan       = 0.0f;
                inst.Pitch     = 0.0f;
                inst.IsLooped  = false;
                inst.PlatformSetReverbMix(0);
                inst.PlatformClearFilter();
            }
            else
            {
                inst           = new SoundEffectInstance();
                inst._isPooled = true;
                inst._isXAct   = forXAct;
            }

            return(inst);
        }
Example #3
0
        internal void UpdateState(AudioEngine engine, float volume, float pitch, float reverbMix, float?filterFrequency, float?filterQFactor)
        {
            _cueVolume = volume;
            var finalVolume = _volume * _cueVolume * engine.Categories[_categoryID]._volume[0];

            _cueReverbMix       = reverbMix;
            _cueFilterFrequency = filterFrequency;
            _cueFilterQFactor   = filterQFactor;

            _cuePitch = pitch;
            var finalPitch = _pitch + _cuePitch;

            if (_complexSound)
            {
                foreach (var clip in _soundClips)
                {
                    clip.UpdateState(finalVolume, finalPitch, _useReverb ? _cueReverbMix : 0.0f, _cueFilterFrequency, _cueFilterQFactor);
                }
            }
            else if (_wave != null)
            {
                _wave.PlatformSetReverbMix(_useReverb ? _cueReverbMix : 0.0f);
                _wave.Pitch  = finalPitch;
                _wave.Volume = finalVolume;
            }
        }
        private void UpdateState()
        {
            _wav.Volume = _trackVolume * _clipVolume;
            _wav.Pitch  = _trackPitch + _clipPitch;

            if (_clip.UseReverb)
            {
                _wav.PlatformSetReverbMix(_clipReverbMix);
            }
            if (_clip.FilterEnabled)
            {
                _wav.PlatformSetFilter(_clip.FilterMode, _trackFilterQFactor, _trackFilterFrequency);
            }
        }
Example #5
0
        public void Play(float volume, AudioEngine engine)
        {
            _cueVolume = volume;
            var category = engine.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);
                }
            }

            float finalVolume = _volume * _cueVolume * category._volume[0];
            float finalPitch  = _pitch + _cuePitch;
            float finalMix    = _useReverb ? _cueReverbMix : 0.0f;

            if (_complexSound)
            {
                foreach (XactClip clip in _soundClips)
                {
                    clip.UpdateState(finalVolume, finalPitch, finalMix, _cueFilterFrequency, _cueFilterQFactor);
                    clip.Play();
                }
            }
            else
            {
                if (_wave != null)
                {
                    if (_streaming)
                    {
                        _wave.Dispose();
                    }
                    else
                    {
                        _wave._isXAct = false;
                    }
                    _wave = null;
                }

                _wave = _soundBank.GetSoundEffectInstance(_waveBankIndex, _trackIndex, out _streaming);

                if (_wave == null)
                {
                    // We couldn't create a sound effect instance, most likely
                    // because we've reached the sound pool limits.
                    return;
                }

                _wave.Pitch  = finalPitch;
                _wave.Volume = finalVolume;
                _wave.PlatformSetReverbMix(finalMix);
                _wave.Play();
            }
        }