Beispiel #1
0
        public ISoundChannel Play(PlayArgs args)
        {
            if ((DateTime.Now - lastPlayback).TotalSeconds < InternalCooldown)
            {
                return(null);
            }

            SoundChannel channel;

            if (args.GetPosition == null || args.GetVelocity == null)       // 2d sound
            {
                if (Is3DSound)
                {
                    throw new Exception("Trying to play 3D-sound as a 2D-sound");
                }
                channel = PlayAnySound(args);
                if (args.FadeInTime > 0)
                {
                    channel.FadeInTime = args.FadeInTime;
                }
                channel.Paused = false;
            }
            else
            {
                if (!Is3DSound)
                {
                    throw new Exception("Trying to play 2D-sound as a 3D-sound");
                }
                if (args.FadeInTime > 0)
                {
                    throw new NotImplementedException("Hasn't been requested yet.");
                }
                else
                {
                    channel = PlayAnySound(args);
                    channel.ChannelGlue.Set3DAttributes(args.GetPosition.Invoke(), args.GetVelocity.Invoke());
                    if (args.Refreshes3DAttributes)
                    {
                        channel.GetObjectPosition = args.GetPosition;
                        channel.GetObjectVelocity = args.GetVelocity;
                    }
                    else
                    {
                        channel.SetConstantPosition(args.GetPosition.Invoke());
                    }
                    channel.Paused = false;
                }
            }
            lastPlayback = DateTime.Now;
            return(channel);
        }
Beispiel #2
0
        //public Vector2 _3DMinMaxDistance
        //{
        //    get { return minMaxDistance; }
        //    set { minMaxDistance = value; if (SoundGlue != null) SoundGlue._3DMinMaxDistance = new Vector2(value.X, value.Y); }
        //}
        //private Vector2 minMaxDistance;

        private SoundChannel PlayAnySound(PlayArgs args)
        {
            IChannelGlue channelGlue = SoundManager.Instance.SystemGlue.PlaySound(SoundGlue, true, args.Looping);

            var soundChannel = new SoundChannel(this, channelGlue)
            {
                Paused = true, WantsToPlaySound = SoundGlue, WantsToPlaySoundArgs = args
            };                                                                                                                                       // TODO: add args stuff

            if (Is3DSound)
            {
                soundChannel._3DPanLevel = SoundManager.Instance._3DPanLevel;
                //soundChannel._3DSpread = SoundManager.Instance._3DSpread;
            }
            return(soundChannel);
        }
Beispiel #3
0
        //////////////////////////////////////////////////////////////////////////////////////////
        // Interval part /////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////////

        public void Play(PlayArgs args)
        {
            waiting = false;
            if (Is3DSound)
            {
                //Vector3 pos = GetPosition();
                //Vector3 vel = GetVelocity();
                //SoundChannel = (SoundChannel)Playable.Play(pos, vel);
                SoundChannel = (SoundChannel)Playable.Play(args);
            }
            else
            {
                if (fadingIn)
                {
                    fadingIn = false;       // reset so the remaining sounds won't fade in
                }
                else
                {
                    args.FadeInTime = 0;
                }
                SoundChannel = (SoundChannel)Playable.Play(args);
            }
        }
 public ISoundChannel PlayLoopedWithIntervals(float minWaitTime, float maxWaitTime, float initialCooldown, PlayArgs args)
 {
     return new DummyChannel();
 }
 public ISoundChannel Play(PlayArgs args)
 {
     return new DummyChannel();
 }
        //public ISoundChannel Play() { return availablePlayables[random.Next(availablePlayables.Count)].Play(); }
        //public ISoundChannel Play(float fadeTime) { return availablePlayables[random.Next(availablePlayables.Count)].Play(fadeTime); }
        //public ISoundChannel Play(Vector3 position, Vector3 velocity) { return availablePlayables[random.Next(availablePlayables.Count)].Play(position, velocity); }
        //public ISoundChannel Play(Func<Vector3> GetPosition, Func<Vector3> GetVelocity) { return availablePlayables[random.Next(availablePlayables.Count)].Play(GetPosition, GetVelocity); }
        //public ISoundChannel PlayLoopedWithIntervals(float minWaitTime, float maxWaitTime, float initialCooldown)
        //{
        //    var channel = new IntervalChannel
        //    {
        //        Playable = this,
        //        Is3DSound = false,
        //        MinWaitTime = minWaitTime,
        //        MaxWaitTime = maxWaitTime,
        //        _3DPanLevel = SoundManager.Instance._3DPanLevel,
        //        //_3DSpread = SoundManager.Instance._3DSpread,
        //    };
        //    channel.QueuePlayback(initialCooldown);
        //    return channel;
        //}
        public ISoundChannel PlayLoopedWithIntervals(float minWaitTime, float maxWaitTime, float initialCooldown, PlayArgs args)
        {
            bool is3DSound = true;
            if (args.GetPosition == null || args.GetVelocity == null)
                is3DSound = false;

            bool sampleIs3DSound = ((IInternalSoundResource)availablePlayables[0]).Is3DSound;
            if (is3DSound != sampleIs3DSound)
                throw new Exception(String.Format("Trying to play {0}D-sound as a {1}-sound", sampleIs3DSound ? 3 : 2, is3DSound ? 3 : 2));

            var channel = new IntervalChannel
            {
                Playable = this,
                Is3DSound = is3DSound,
                MinWaitTime = minWaitTime,
                MaxWaitTime = maxWaitTime
            };
            if (is3DSound)
            {
                channel._3DPanLevel = SoundManager.Instance._3DPanLevel;
                channel.GetPosition = args.GetPosition;
                channel.GetVelocity = args.GetVelocity;
            }
            if (args.FadeInTime > 0)
                channel.QueuePlayback(initialCooldown, args.FadeInTime);
            else
                channel.QueuePlayback(initialCooldown);
            return channel;
        }
 public ISoundChannel Play(PlayArgs args)
 {
     return availablePlayables[random.Next(availablePlayables.Count)].Play(args);
 }
        //public Vector2 _3DMinMaxDistance
        //{
        //    get { return minMaxDistance; }
        //    set { minMaxDistance = value; if (SoundGlue != null) SoundGlue._3DMinMaxDistance = new Vector2(value.X, value.Y); }
        //}
        //private Vector2 minMaxDistance;
        private SoundChannel PlayAnySound(PlayArgs args)
        {
            IChannelGlue channelGlue = SoundManager.Instance.SystemGlue.PlaySound(SoundGlue, true, args.Looping);

            var soundChannel = new SoundChannel(this, channelGlue) { Paused = true, WantsToPlaySound = SoundGlue, WantsToPlaySoundArgs = args };     // TODO: add args stuff

            if (Is3DSound)
            {
                soundChannel._3DPanLevel = SoundManager.Instance._3DPanLevel;
                //soundChannel._3DSpread = SoundManager.Instance._3DSpread;
            }
            return soundChannel;
        }
        public ISoundChannel Play(PlayArgs args)
        {
            if ((DateTime.Now - lastPlayback).TotalSeconds < InternalCooldown)
                return null;

            SoundChannel channel;
            if (args.GetPosition == null || args.GetVelocity == null)       // 2d sound
            {
                if (Is3DSound)
                    throw new Exception("Trying to play 3D-sound as a 2D-sound");
                channel = PlayAnySound(args);
                if (args.FadeInTime > 0)
                    channel.FadeInTime = args.FadeInTime;
                channel.Paused = false;
            }
            else
            {
                if (!Is3DSound)
                    throw new Exception("Trying to play 2D-sound as a 3D-sound");
                if (args.FadeInTime > 0)
                {
                    throw new NotImplementedException("Hasn't been requested yet.");
                }
                else
                {
                    channel = PlayAnySound(args);
                    channel.ChannelGlue.Set3DAttributes(args.GetPosition.Invoke(), args.GetVelocity.Invoke());
                    if (args.Refreshes3DAttributes)
                    {
                        channel.GetObjectPosition = args.GetPosition;
                        channel.GetObjectVelocity = args.GetVelocity;
                    }
                    else
                        channel.SetConstantPosition(args.GetPosition.Invoke());
                    channel.Paused = false;
                }
            }
            lastPlayback = DateTime.Now;
            return channel;
        }
 //////////////////////////////////////////////////////////////////////////////////////////
 // Interval part /////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////
 public void Play(PlayArgs args)
 {
     waiting = false;
     if (Is3DSound)
     {
         //Vector3 pos = GetPosition();
         //Vector3 vel = GetVelocity();
         //SoundChannel = (SoundChannel)Playable.Play(pos, vel);
         SoundChannel = (SoundChannel)Playable.Play(args);
     }
     else
     {
         if (fadingIn)
             fadingIn = false;       // reset so the remaining sounds won't fade in
         else
             args.FadeInTime = 0;
         SoundChannel = (SoundChannel)Playable.Play(args);
     }
 }
Beispiel #11
0
 public ISoundChannel PlayLoopedWithIntervals(float minWaitTime, float maxWaitTime, float initialCooldown, PlayArgs args)
 {
     return(new DummyChannel());
 }
Beispiel #12
0
 public ISoundChannel Play(PlayArgs args)
 {
     return(new DummyChannel());
 }
Beispiel #13
0
        //public ISoundChannel Play() { return availablePlayables[random.Next(availablePlayables.Count)].Play(); }
        //public ISoundChannel Play(float fadeTime) { return availablePlayables[random.Next(availablePlayables.Count)].Play(fadeTime); }
        //public ISoundChannel Play(Vector3 position, Vector3 velocity) { return availablePlayables[random.Next(availablePlayables.Count)].Play(position, velocity); }
        //public ISoundChannel Play(Func<Vector3> GetPosition, Func<Vector3> GetVelocity) { return availablePlayables[random.Next(availablePlayables.Count)].Play(GetPosition, GetVelocity); }
        //public ISoundChannel PlayLoopedWithIntervals(float minWaitTime, float maxWaitTime, float initialCooldown)
        //{
        //    var channel = new IntervalChannel
        //    {
        //        Playable = this,
        //        Is3DSound = false,
        //        MinWaitTime = minWaitTime,
        //        MaxWaitTime = maxWaitTime,
        //        _3DPanLevel = SoundManager.Instance._3DPanLevel,
        //        //_3DSpread = SoundManager.Instance._3DSpread,
        //    };
        //    channel.QueuePlayback(initialCooldown);
        //    return channel;
        //}
        public ISoundChannel PlayLoopedWithIntervals(float minWaitTime, float maxWaitTime, float initialCooldown, PlayArgs args)
        {
            bool is3DSound = true;

            if (args.GetPosition == null || args.GetVelocity == null)
            {
                is3DSound = false;
            }

            bool sampleIs3DSound = ((IInternalSoundResource)availablePlayables[0]).Is3DSound;

            if (is3DSound != sampleIs3DSound)
            {
                throw new Exception(String.Format("Trying to play {0}D-sound as a {1}-sound", sampleIs3DSound ? 3 : 2, is3DSound ? 3 : 2));
            }

            var channel = new IntervalChannel
            {
                Playable    = this,
                Is3DSound   = is3DSound,
                MinWaitTime = minWaitTime,
                MaxWaitTime = maxWaitTime
            };

            if (is3DSound)
            {
                channel._3DPanLevel = SoundManager.Instance._3DPanLevel;
                channel.GetPosition = args.GetPosition;
                channel.GetVelocity = args.GetVelocity;
            }
            if (args.FadeInTime > 0)
            {
                channel.QueuePlayback(initialCooldown, args.FadeInTime);
            }
            else
            {
                channel.QueuePlayback(initialCooldown);
            }
            return(channel);
        }
Beispiel #14
0
 public ISoundChannel Play(PlayArgs args)
 {
     return(availablePlayables[random.Next(availablePlayables.Count)].Play(args));
 }