コード例 #1
0
        public override void Play()
        {
            if (_wav != null && _wav.State != SoundState.Stopped)
            {
                _wav.Stop();
            }

            var trackCount = _tracks.Length;

            switch (_variation)
            {
            case VariationType.Ordered:
                _wavIndex = (_wavIndex + 1) % trackCount;
                break;

            case VariationType.OrderedFromRandom:
                _wavIndex = (_wavIndex + 1) % trackCount;
                break;

            case VariationType.Random:
                _wavIndex = XactHelpers.Random.Next() % trackCount;
                break;

            case VariationType.RandomNoImmediateRepeats:
            {
                var last = _wavIndex;
                do
                {
                    _wavIndex = XactHelpers.Random.Next() % trackCount;
                }while (last == _wavIndex && trackCount > 1);
                break;
            }

            case VariationType.Shuffle:
                // TODO: Need some sort of deck implementation.
                _wavIndex = XactHelpers.Random.Next() % trackCount;
                break;
            }
            ;

            _wav = _soundBank.GetSoundEffectInstance(_waveBanks[_wavIndex], _tracks[_wavIndex]);
            if (_wav == null)
            {
                // We couldn't create a sound effect instance, most likely
                // because we've reached the sound pool limits.
                return;
            }

            _wav.Volume   = _volume;
            _wav.IsLooped = _isLooped && trackCount == 1;
            _wav.Play();
        }
コード例 #2
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();
            }
        }
コード例 #3
0
ファイル: XactSound.cs プロジェクト: Breadmouth/Gravitas
        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();
            }
        }
コード例 #4
0
        private void Play(bool pickNewWav)
        {
            var trackCount = _tracks.Length;

            // Do we need to pick a new wav to play first?
            if (pickNewWav)
            {
                switch (_variation)
                {
                case VariationType.Ordered:
                    _wavIndex = (_wavIndex + 1) % trackCount;
                    break;

                case VariationType.OrderedFromRandom:
                    _wavIndex = (_wavIndex + 1) % trackCount;
                    break;

                case VariationType.Random:
                    if (_weights == null || trackCount == 1)
                    {
                        _wavIndex = XactHelpers.Random.Next() % trackCount;
                    }
                    else
                    {
                        var sum = XactHelpers.Random.Next(_totalWeights);
                        for (var i = 0; i < trackCount; i++)
                        {
                            sum -= _weights[i];
                            if (sum <= 0)
                            {
                                _wavIndex = i;
                                break;
                            }
                        }
                    }
                    break;

                case VariationType.RandomNoImmediateRepeats:
                {
                    if (_weights == null || trackCount == 1)
                    {
                        _wavIndex = XactHelpers.Random.Next() % trackCount;
                    }
                    else
                    {
                        var last = _wavIndex;
                        var sum  = XactHelpers.Random.Next(_totalWeights);
                        for (var i = 0; i < trackCount; i++)
                        {
                            sum -= _weights[i];
                            if (sum <= 0)
                            {
                                _wavIndex = i;
                                break;
                            }
                        }

                        if (_wavIndex == last)
                        {
                            _wavIndex = (_wavIndex + 1) % trackCount;
                        }
                    }
                    break;
                }

                case VariationType.Shuffle:
                    // TODO: Need some sort of deck implementation.
                    _wavIndex = XactHelpers.Random.Next() % trackCount;
                    break;
                }
                ;
            }

            _wav = _soundBank.GetSoundEffectInstance(_waveBanks[_wavIndex], _tracks[_wavIndex]);
            if (_wav == null)
            {
                // We couldn't create a sound effect instance, most likely
                // because we've reached the sound pool limits.
                return;
            }

            // Set the volume.
            SetTrackVolume(_trackVolume);

            // Set the pitch.
            if (_pitchVar.HasValue)
            {
                _wav.Pitch = _pitchVar.Value.X + ((float)XactHelpers.Random.NextDouble() * _pitchVar.Value.Y);
            }
            else
            {
                _wav.Pitch = 0;
            }

            // This is a shortcut for infinite looping of a single track.
            _wav.IsLooped = _loopCount == 255 && trackCount == 1;
            _wav.Play();
        }
コード例 #5
0
ファイル: XactSound.cs プロジェクト: play3577/PixelVision8
        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();
            }
        }