Ejemplo n.º 1
0
        public static PlayingSound PlaySound3DToChannel(AudioEngine.SoundEffect sound, float x, float y, float z, SoundTrackChannel channel, WaitHandle waitHandle = null)
        {
            PlayingSound s = new PlayingSound(sound.CreateInstance(), channel, waitHandle);

            s.Instance.SetPosition(false, new Math.Vector3(x, y, z));
            s.Play();
            _playingSounds.Add(s);

            return(s);

            /*AudioSource source = getFreeSource(null);
             * if (source != null)
             * {
             *  source.IsLooping
             *
             *  Al.alSourcei(source, Al.AL_BUFFER, sound.Buffer);
             *  Al.alSource3f(source, Al.AL_POSITION, x, y, z);
             *  Al.alSourcei(source, Al.AL_SOURCE_RELATIVE, Al.AL_FALSE);
             *  Al.alSourcef(source, Al.AL_MAX_DISTANCE, sound.DefaultMaxDistance);
             *  Al.alSourcef(source, Al.AL_REFERENCE_DISTANCE, sound.DefaultMinDistance);
             *  Al.alSourcePlay(source);
             *
             *  _channelSounds[channel].Add(source);// BUG: this should be adding this sound to a collection!
             *
             *  return new PlayingSound(source, false);
             * }
             *
             * return new PlayingSound();*/
        }
Ejemplo n.º 2
0
        public static PlayingSound PlaySound2DToChannel(AudioEngine.SoundEffect sound, SoundTrackChannel channel, WaitHandle waitHandle = null)
        {
            PlayingSound s = new PlayingSound(sound.CreateInstance(), channel, waitHandle);

            s.Instance.SetPosition(true, Math.Vector3.Zero);
            s.Play();
            _playingSounds.Add(s);

            return(s);
        }
Ejemplo n.º 3
0
        public void Step(int currentTime)
        {
            if (_waiting)
            {
                if (_timeToFinishWait > currentTime)
                {
                    _waiting = false;
                    _currentNodeIndex++;
                }
            }
            else if (_playingSound != null)
            {
                if (_playingSound.Instance.State == AudioEngine.SoundState.Stopped)
                {
                    _playingSound.Release();
                    _playingSound = null;
                }
            }
            else
            {
                // move to the next enabled node
                if (findNextEnabledNode(_currentNodeIndex, out _currentNodeIndex) == false)
                {
                    _playing = false;
                    return;
                }

                if (_nodes[_currentNodeIndex].RepeatEnabled)
                {
                    _nodes[_currentNodeIndex].Repeat--;

                    if (_nodes[_currentNodeIndex].Repeat < 1)
                    {
                        _nodes[_currentNodeIndex].Enabled = false;
                    }
                }

                if (Utils.RollFloatingDie() < _nodes[_currentNodeIndex].Random)
                {
                    if (_nodes[_currentNodeIndex].Type == SoundTrackNodeType.Wait)
                    {
                        SoundTrackWaitNode node = (SoundTrackWaitNode)_nodes[_currentNodeIndex];

                        _waiting = true;

                        if (node.MaxWait == node.MinWait)
                        {
                            _timeToFinishWait = currentTime + node.MinWait;
                        }
                        else
                        {
                            _timeToFinishWait = currentTime + Utils.PickRandomNumber(node.MinWait, node.MaxWait);
                        }
                    }
                    else if (_nodes[_currentNodeIndex].Type == SoundTrackNodeType.Sound)
                    {
                        SoundTrackSoundNode node = (SoundTrackSoundNode)_nodes[_currentNodeIndex];

                        // TODO: set up the 3D position, fade in/out, etc
                        if (node.Sound != null)
                        {
                            if (node.Is3D)
                            {
                                _playingSound = SoundManager.PlaySound3DToChannel(node.Sound, node.Z, node.Y, node.X, _channel);
                            }
                            else
                            {
                                _playingSound = SoundManager.PlaySound2DToChannel(node.Sound, _channel);
                            }
                        }
                    }
                    else if (_nodes[_currentNodeIndex].Type == SoundTrackNodeType.Prs)
                    {
                        int prsCount = countPrs(_currentNodeIndex);

                        int prsToPlay = Utils.PickRandomNumber(0, prsCount);

                        SoundTrackSoundNode node = (SoundTrackSoundNode)_nodes[_currentNodeIndex + prsToPlay];

                        // TODO: set up the 3D position, fade in/out, etc
                        if (node.Sound != null)
                        {
                            if (node.Is3D)
                            {
                                _playingSound = SoundManager.PlaySound3DToChannel(node.Sound, node.X, node.Y, node.Z, _channel);
                            }
                            else
                            {
                                _playingSound = SoundManager.PlaySound2DToChannel(node.Sound, _channel);
                            }
                        }

                        // move to the last PRS node
                        _currentNodeIndex += prsCount - 1;
                    }
                }
            }
        }