void ResumeCue(IMySourceVoice cue)
 {
     if ((cue != null) && cue.IsPaused)
     {
         cue.Resume();
     }
 }
        public void Update(bool force=false)
        {
            if (!Sandbox.Game.World.MySession.Static.Settings.RealisticSound)
                return;
            if (CurrentState == State.NoBreath)
            {
                if (m_sound != null)
                {
                    m_sound.Stop();
                    m_sound = null;
                }
                return;
            }

            if (force || m_lastChange < MySandboxGame.Static.UpdateTime)
            {
                if (m_healthOverride > MySandboxGame.Static.UpdateTime || CurrentState == State.Heated)
                {//State.Heated
                    if (m_sound == null || m_sound.CueEnum != BREATH_HEAVY.SoundId)
                    {
                        PlaySound(BREATH_HEAVY.SoundId);
                    }
                }
                else
                {//State.Calm:
                    if (m_sound == null || m_sound.CueEnum != BREATH_CALM.SoundId)
                    {
                        PlaySound(BREATH_CALM.SoundId);
                    }
                }
            }
        }
 void PauseCue(IMySourceVoice cue)
 {
     if ((cue != null) && cue.IsPlaying)
     {
         cue.Pause();
     }
 }
        public void Update(bool force = false)
        {
            if (!Sandbox.Game.World.MySession.Static.Settings.RealisticSound)
            {
                return;
            }
            if (CurrentState == State.NoBreath)
            {
                if (m_sound != null)
                {
                    m_sound.Stop();
                    m_sound = null;
                }
                return;
            }

            if (force || m_lastChange < MySandboxGame.Static.UpdateTime)
            {
                if (m_healthOverride > MySandboxGame.Static.UpdateTime || CurrentState == State.Heated)
                {//State.Heated
                    if (m_sound == null || m_sound.CueEnum != BREATH_HEAVY.SoundId)
                    {
                        PlaySound(BREATH_HEAVY.SoundId);
                    }
                }
                else
                {//State.Calm:
                    if (m_sound == null || m_sound.CueEnum != BREATH_CALM.SoundId)
                    {
                        PlaySound(BREATH_CALM.SoundId);
                    }
                }
            }
        }
 void PlayZoomingRelSound()
 {
     if ((m_zoomRelCue == null) || !m_zoomRelCue.IsPlaying)
     {
         m_zoomRelCue = MyAudio.Static.PlaySound(ZOOM_SOUND.SoundId);
     }
 }
Esempio n. 6
0
        public void Update()
        {
            bool validSoundIsPlaying = m_sound != null && m_sound.IsPlaying;

            if (!CanHearSound())
            {
                if (validSoundIsPlaying)
                {
                    StopSound(true, false);
                    m_sound = null;
                }
                return;
            }
            else if (!validSoundIsPlaying && Loop)
            {
                PlaySoundInternal(true);
            }
            else if (validSoundIsPlaying && Loop && m_playing2D != ShouldPlay2D())
            {
                StopSound(true, false);
                PlaySoundInternal(true);
            }
            else if (validSoundIsPlaying && Loop && m_playing2D == false && usesDistanceSounds)
            {
                MyCueId newSound = CheckDistanceSounds(closeSound);
                if (MyStringHash.Comparer.Equals(newSound.Hash, SoundId.Hash) == false)
                {
                    PlaySound(newSound, true, useDistanceCheck: false);
                }
            }
        }
Esempio n. 7
0
        public void PlaySoundWithDistance(MyCueId soundId, bool stopPrevious = false, bool skipIntro = false, bool force2D = false, bool useDistanceCheck = true, bool alwaysHearOnRealistic = false, bool skipToEnd = false, bool?force3D = new bool?())
        {
            this.m_lastSoundData = MyAudio.Static.GetCue(soundId);
            if (useDistanceCheck)
            {
                this.m_closeSoundCueId = soundId;
                MyCueId id1 = this.CheckDistanceSounds(soundId);
                soundId = id1;
            }
            bool usesDistanceSounds = this.m_usesDistanceSounds;

            if (this.Sound != null)
            {
                if (stopPrevious)
                {
                    this.StopSound(true, true);
                }
                else if (this.Loop)
                {
                    IMySourceVoice sound = this.Sound;
                    this.StopSound(true, true);
                    this.m_soundsQueue.Add(sound.CueEnum);
                }
            }
            if (this.m_secondarySound != null)
            {
                this.m_secondarySound.Stop(true);
            }
            this.SoundId = soundId;
            bool flag2 = force2D;

            this.PlaySoundInternal(skipIntro | skipToEnd, skipToEnd, flag2, alwaysHearOnRealistic, force3D);
            this.m_usesDistanceSounds = usesDistanceSounds;
        }
Esempio n. 8
0
 private void PlaySoundInternal(bool skipIntro = false, bool skipToEnd = false)
 {
     m_playing2D = ShouldPlay2D() && !Force3D;
     Loop        = MyAudio.Static.IsLoopable(SoundId) && !skipToEnd;
     if (m_playing2D)
     {
         Sound = MyAudio.Static.PlaySound(SoundId, this, MySoundDimensions.D2, skipIntro, skipToEnd);
     }
     else if (CanHearSound()) //Start 3D sound only if can be heard
     {
         Sound = MyAudio.Static.PlaySound(SoundId, this, MySoundDimensions.D3, skipIntro, skipToEnd);
     }
     if (Sound != null)
     {
         Sound.StoppedPlaying = OnStopPlaying;
         if (EmitterMethods[MethodsEnum.ImplicitEffect].Count > 0)
         {
             var effectId = ((Func <MyStringId>)EmitterMethods[MethodsEnum.ImplicitEffect][0])();
             if (effectId != MyStringId.NullOrEmpty)
             {
                 var effect = MyAudio.Static.ApplyEffect(Sound, effectId);
                 if (effect != null)
                 {
                     Sound = effect.OutputSound;
                 }
             }
         }
     }
     else
     {
         OnStopPlaying();
     }
 }
Esempio n. 9
0
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            if (MySandboxGame.IsDedicated)
            {
                m_hudWarnings.Clear();
                m_soundQueue.Clear();
                return;
            }

            m_updateCounter++;
            if (m_updateCounter % FRAMES_BETWEEN_UPDATE == 0)
            {
                foreach (var warningGroup in m_hudWarnings)
                {
                    warningGroup.Update();
                }
                if (m_soundQueue.Count > 0 && MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastSoundPlayed > 5000)
                {
                    m_lastSoundPlayed = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                    m_sound           = MyGuiAudio.PlaySound(m_soundQueue[0]);
                    m_soundQueue.RemoveAt(0);
                }
            }
        }
Esempio n. 10
0
        public void Update()
        {
            bool validSoundIsPlaying = m_sound != null && m_sound.IsPlaying;

            if (!CanHearSound())
            {
                if (validSoundIsPlaying)
                {
                    StopSound(true, false);
                    m_sound = null;
                }
                return;
            }
            else if (!validSoundIsPlaying && Loop)
            {
                PlaySound(m_closeSoundSoundPair, true, true);
            }
            else if (validSoundIsPlaying && Loop && m_playing2D != ShouldPlay2D() && ((Force2D == true && m_playing2D == false) || (Force3D == true && m_playing2D == true)))
            {
                StopSound(true, false);
                PlaySound(m_closeSoundSoundPair, true, true);
            }
            else if (validSoundIsPlaying && Loop && m_playing2D == false && m_usesDistanceSounds)
            {
                MyCueId oldSecondary = (m_secondaryEnabled ? m_secondaryCueEnum : myEmptyCueId);
                MyCueId newSound     = CheckDistanceSounds(m_closeSoundCueId);
                if (newSound != m_cueEnum || oldSecondary != m_secondaryCueEnum)
                {
                    PlaySoundWithDistance(newSound, true, true, useDistanceCheck: false);
                }
                else if (m_secondaryEnabled)
                {
                    if (Sound != null)
                    {
                        Sound.SetVolume(RealisticVolumeChange * m_baseVolume * (1f - m_secondaryVolumeRatio));
                    }
                    if (m_secondarySound != null)
                    {
                        m_secondarySound.SetVolume(RealisticVolumeChange * m_secondaryBaseVolume * m_secondaryVolumeRatio);
                    }
                }
            }
            if (validSoundIsPlaying && Loop)
            {
                //arcade/real sound change
                MyCueId newCueId = SelectCue(m_soundPair);
                if (newCueId.Equals(m_cueEnum) == false)
                {
                    PlaySoundWithDistance(newCueId, true, true);
                }

                //active filter changed
                MyStringHash newEffect = SelectEffect();
                if (m_activeEffect != newEffect)
                {
                    PlaySoundWithDistance(newCueId, true, true);
                }
            }
        }
Esempio n. 11
0
 public void Cleanup()
 {
     if (Sound != null)
     {
         Sound.Cleanup();
         Sound = null;
     }
 }
Esempio n. 12
0
 public static void RemoveSound(MyGuiSounds cueEnum)
 {
     if (m_sound != null && m_sound.CueEnum == MyGuiAudio.GetCue(cueEnum) && m_sound.IsPlaying == false)
     {
         m_sound.Stop();
         m_sound = null;
     }
     m_soundQueue.RemoveAll(new System.Predicate <MyGuiSounds>((cue) => { return(cue == cueEnum); }));
 }
Esempio n. 13
0
 public void Unload()
 {
     if (this.m_musicSourceVoice != null)
     {
         this.m_musicSourceVoice.Stop(false);
         this.m_musicSourceVoice = null;
     }
     this.Active = false;
     this.ClearMusicCues();
 }
Esempio n. 14
0
 public void Unload()
 {
     if (m_musicSourceVoice != null)
     {
         m_musicSourceVoice.Stop();
         m_musicSourceVoice = null;
     }
     Active = false;
     ClearMusicCues();
 }
Esempio n. 15
0
        public static void PreloadSound(MySoundPair soundId)
        {
            IMySourceVoice voice = MyAudio.Static.GetSound(soundId.SoundId, null, MySoundDimensions.D2);

            if (voice != null)
            {
                voice.Start(false, false);
                voice.Stop(true);
            }
        }
 public MyEffectInstance CreateEffect(IMySourceVoice input, MyStringHash effect, MySourceVoice[] cues = null, float? duration = null)
 {
     if(!m_effects.ContainsKey(effect))
     {
         Debug.Fail(string.Format("Effect not found: {0}", effect.ToString()));
         return null;
     }
     var instance = new MyEffectInstance(m_effects[effect], input, cues, duration, m_engine);
     m_activeEffects.Add(instance);
     return instance;
 }
Esempio n. 17
0
 private void PlaySound(MyStringId soundId)
 {
     if (m_sound != null && m_sound.IsPlaying)
     {
         var effect = MyAudio.Static.ApplyEffect(m_sound, MyStringId.GetOrCompute("CrossFade"), new MyStringId[] { soundId }, 2000);
         m_sound = effect.OutputSound;
     }
     else
     {
         m_sound = MyAudio.Static.PlaySound(soundId, null, MySoundDimensions.D2);
     }
 }
Esempio n. 18
0
        public MyEffectInstance CreateEffect(IMySourceVoice input, MyStringId effect, MySourceVoice[] cues = null, float?duration = null)
        {
            if (!m_effects.ContainsKey(effect))
            {
                Debug.Fail(string.Format("Effect not found: {0}", effect.ToString()));
                return(null);
            }
            var instance = new MyEffectInstance(m_effects[effect], input, cues, duration, m_engine);

            m_activeEffects.Add(instance);
            return(instance);
        }
Esempio n. 19
0
 public void Cleanup()
 {
     if (Sound != null)
     {
         Sound.Cleanup();
         Sound = null;
     }
     if (m_secondarySound != null)
     {
         m_secondarySound.Cleanup();
         m_secondarySound = null;
     }
 }
Esempio n. 20
0
 public void Cleanup()
 {
     if (this.Sound != null)
     {
         this.Sound.Cleanup();
         this.Sound = null;
     }
     if (this.m_secondarySound != null)
     {
         this.m_secondarySound.Cleanup();
         this.m_secondarySound = null;
     }
 }
 void QuestInfo_ValueChanged()
 {
     Position = m_position + this.Size / 2;
     RecreateControls();
     if (QuestInfo.HighlightChanges)
     {
         m_currentFrame = 0;
         if (m_currentSoundID == null && MyAudio.Static != null)
             m_currentSoundID = MyAudio.Static.PlaySound(m_highlightSound.SoundId);
     }
     else
     {
         m_currentFrame = float.MaxValue;
     }
 }
Esempio n. 22
0
 public override void Draw(float transitionAlpha, float backgroundTransitionAlpha)
 {
     if (m_currentFrame < NUMER_OF_PERIODS * ANIMATION_PERIOD && QuestInfo.HighlightChanges)
     {
         float ratio    = (float)(2 * Math.PI * (m_currentFrame / ANIMATION_PERIOD));
         float visValue = ((float)Math.Cos(ratio) + 1.5f) * 0.5f;
         backgroundTransitionAlpha = MathHelper.Clamp(visValue, 0, 1);
         m_currentFrame++;
     }
     else if (m_currentFrame == NUMER_OF_PERIODS * ANIMATION_PERIOD && m_currentSoundID != null)
     {
         m_currentSoundID.Stop();
         m_currentSoundID = null;
     }
     base.Draw(transitionAlpha, backgroundTransitionAlpha);
 }
Esempio n. 23
0
 public static void EnqueueSound(MyGuiSounds sound)
 {
     if (!MyGuiAudio.HudWarnings)
     {
         return;
     }
     if ((m_sound == null || !m_sound.IsPlaying) && MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastSoundPlayed > 5000)
     {
         m_sound           = MyGuiAudio.PlaySound(sound);
         m_lastSoundPlayed = MySandboxGame.TotalGamePlayTimeInMilliseconds;
     }
     else
     {
         m_soundQueue.Add(sound);
     }
 }
        private void PlaySound(MyCueId sound)
        {
            if (m_sound == null || !m_sound.IsPlaying)
            {
                m_sound = MyAudio.Static.PlaySound(sound);
                if (!sound.IsNull)
                {
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeIn, null);
                }
                if (m_effect != null)
                {
                    m_sound = m_effect.OutputSound;
                }
            }
            else if (m_effect != null && m_effect.Finished && sound.IsNull)
            {
                m_sound.Stop(true);
            }
            else if (m_sound.CueEnum != sound)
            {
                if (m_effect != null && !m_effect.Finished)
                {
                    //m_effect.SetPositionRelative(1f);
                    m_effect.AutoUpdate = true;
                }
                if (sound.IsNull)
                {
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeOut, null, 5000f);
                }
                else
                {
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_crossFade, new MyCueId[] { sound }, 5000f);
                }

                if (m_effect != null && !m_effect.Finished)
                {
                    m_effect.AutoUpdate = true;
                    m_sound             = m_effect.OutputSound;
                }
            }
            if (m_sound != null)
            {
                MySoundData data = MyAudio.Static.GetCue(sound);
                m_volumeOriginal = data != null ? data.Volume :1f;
                m_sound.SetVolume(m_volumeOriginal * m_volumeModifier * VolumeModifierGlobal);
            }
        }
Esempio n. 25
0
 private void PlayMusic(MyCueId cue, MyStringHash effect, int effectDuration = 2000, MyCueId[] cueIds = null, bool play = true)
 {
     if (play)
     {
         m_musicSourceVoice = MyAudio.Static.PlayMusicCue(cue);
     }
     if (m_musicSourceVoice != null)
     {
         if (effect != MyStringHash.NullOrEmpty)
         {
             var effectSourceVoice = MyAudio.Static.ApplyEffect(m_musicSourceVoice, effect, cueIds, effectDuration);
             m_musicSourceVoice = effectSourceVoice.OutputSound;
         }
         m_musicSourceVoice.StoppedPlaying += MusicStopped;
     }
     m_lastMusicData = MyAudio.Static.GetCue(cue);
 }
Esempio n. 26
0
 public void PlaySound(byte[] buffer, int size, int sampleRate, float volume = 1, float maxDistance = 0, MySoundDimensions dimension = MySoundDimensions.D3)
 {
     CustomMaxDistance = maxDistance;
     CustomVolume      = volume;
     if (Sound == null)
     {
         Sound = MyAudio.Static.GetSound(this, sampleRate, 1, dimension);
     }
     if (Sound != null)
     {
         Sound.SubmitBuffer(buffer, size);
         if (!Sound.IsPlaying)
         {
             Sound.StartBuffered();
         }
     }
 }
Esempio n. 27
0
        public IMyAudioEffect ApplyEffect(IMySourceVoice input, MyStringId effect, MyStringId[] cues = null, float?duration = null)
        {
            if (m_effectBank == null)
            {
                return(null);
            }
            List <MySourceVoice> voices = new List <MySourceVoice>();

            if (cues != null)
            {
                foreach (var cue in cues)
                {
                    voices.Add(GetSound(cue));
                }
            }
            return(m_effectBank.CreateEffect(input, effect, voices.ToArray(), duration));
        }
        private void PlaySound(MyCueId soundId, bool useCrossfade)
        {
            if (m_sound != null && m_sound.IsPlaying && useCrossfade)
            {
                var effect = MyAudio.Static.ApplyEffect(m_sound, MyStringHash.GetOrCompute("CrossFade"), new MyCueId[] { soundId }, 2000);
                m_sound = effect.OutputSound;
            }
            else
            {
                if (m_sound != null)
                {
                    m_sound.Stop(true);
                }

                m_sound = MyAudio.Static.PlaySound(soundId, null, MySoundDimensions.D2);
            }
        }
Esempio n. 29
0
 void QuestInfo_ValueChanged()
 {
     Position = m_position + this.Size / 2;
     RecreateControls();
     if (QuestInfo.HighlightChanges)
     {
         m_currentFrame = 0;
         if (m_currentSoundID == null && MyAudio.Static != null)
         {
             m_currentSoundID = MyAudio.Static.PlaySound(m_highlightSound);
         }
     }
     else
     {
         m_currentFrame = float.MaxValue;
     }
 }
Esempio n. 30
0
 private void PlaySound(MyCueId soundId, bool useCrossfade)
 {
     if (((this.m_sound != null) && this.m_sound.IsPlaying) & useCrossfade)
     {
         MyCueId[]      cueIds = new MyCueId[] { soundId };
         IMyAudioEffect effect = MyAudio.Static.ApplyEffect(this.m_sound, MyStringHash.GetOrCompute("CrossFade"), cueIds, new float?((float)0x7d0), false);
         this.m_sound = effect.OutputSound;
     }
     else
     {
         if (this.m_sound != null)
         {
             this.m_sound.Stop(true);
         }
         this.m_sound = MyAudio.Static.PlaySound(soundId, null, MySoundDimensions.D2, false, false);
     }
 }
 public static void EnqueueSound(MyGuiSounds sound)
 {
     if (!MyGuiAudio.HudWarnings)
     {
         return;
     }
     if ((_mSound == null || !_mSound.IsPlaying) &&
         MySandboxGame.TotalGamePlayTimeInMilliseconds - _mLastSoundPlayed > 5000)
     {
         _mSound           = MyGuiAudio.PlaySound(sound);
         _mLastSoundPlayed = MySandboxGame.TotalGamePlayTimeInMilliseconds;
     }
     else
     {
         M_SOUND_QUEUE.Add(sound);
     }
 }
Esempio n. 32
0
        public IMyAudioEffect ApplyEffect(IMySourceVoice input, MyStringHash effect, MyCueId[] cueIds = null, float?duration = null)
        {
            if (m_effectBank == null)
            {
                return(null);
            }
            int waveNumber;
            List <MySourceVoice> voices = new List <MySourceVoice>();

            if (cueIds != null)
            {
                foreach (var cueId in cueIds)
                {
                    voices.Add(GetSound(cueId, out waveNumber));
                }
            }
            return(m_effectBank.CreateEffect(input, effect, voices.ToArray(), duration));
        }
 private void VisibilityChanged(object sender, bool isVisible)
 {
     if (Visible)
     {
         Position = m_position + this.Size / 2;
         RecreateControls();
         m_currentFrame = 0;
     }
     else
     {
         m_currentFrame = float.MaxValue;
         if (m_currentSoundID != null)
         {
             m_currentSoundID.Stop();
             m_currentSoundID = null;
         }
     }
 }
        private void VisibilityChanged(object sender, bool isVisible)
        {
            if (Visible)
            {
                Position = m_position + this.Size / 2;
                RecreateControls();
                m_currentFrame = 0;
                if (m_currentSoundID == null)
                    m_currentSoundID = MyAudio.Static.PlaySound(m_highlightSound.SoundId);
            }
            else
            {
                m_currentFrame = float.MaxValue;
                if (m_currentSoundID != null)
                {
                    m_currentSoundID.Stop();
                    m_currentSoundID = null;
                }

            }
        }
Esempio n. 35
0
        public MyEffectInstance(MyAudioEffect effect, IMySourceVoice input, MySourceVoice[] cues, float? duration, XAudio2 engine)
        {
            m_engine = engine;
            m_effect = effect;
            var inputSound = input as MySourceVoice;
            if (inputSound != null && inputSound.IsValid && inputSound.Voice != null && inputSound.Voice.IsValid())
            {
                Debug.Assert(!inputSound.Voice.IsDisposed);
                var sd = new SoundData()
                {
                    Sound = inputSound,
                    Pivot = 0,
                    CurrentEffect = 0,
                    OrigVolume = inputSound.Volume,
                    OrigFrequency = inputSound.FrequencyRatio,
                };
                //FilterParameters fp = new FilterParameters();
                m_sounds.Add(sd);
            }

            foreach(var sound in cues)
            {
                Debug.Assert(!sound.Voice.IsDisposed);
                sound.Start(false); //jn:todo effect command to start sound
                m_sounds.Add(new SoundData()
                {
                    Sound = sound,
                    Pivot = 0,
                    CurrentEffect = 0,
                    OrigVolume = sound.Volume,
                    OrigFrequency = sound.FrequencyRatio,
                });
            }
            if(OutputSound != null)
                OutputSound.StoppedPlaying += EffectFinished;

            ComputeDurationAndScale(duration);
            Update(0);
        }
 void OnPlaySelected(MyGuiControlButton button)
 {
     if ((m_sound != null) && (m_sound.IsPlaying))
         m_sound.Stop(true);
     var cue = new MyCueId(MyStringHash.TryGet(m_cuesCombo.GetSelectedValue().ToString()));
     m_sound = MyAudio.Static.PlaySound(cue);
     var effect = MyStringHash.TryGet(m_effects.GetSelectedValue().ToString());
     if(effect != MyStringHash.NullOrEmpty)
     {
         foreach(var box in m_cues)
         {
             var effCue = new MyCueId(MyStringHash.TryGet(box.GetSelectedValue().ToString()));
             m_cueCache.Add(effCue);
         }
         var eff = MyAudio.Static.ApplyEffect(m_sound, effect, m_cueCache.ToArray());
         m_sound = eff.OutputSound;
         m_cueCache.Clear();
     }
 }
 public void StopSound(bool forced, bool cleanUp = true)
 {
     if (m_sound != null)
     {
         m_sound.Stop(forced);
         if (Loop && !forced)
             PlaySoundInternal(true, true);
         if (m_soundsQueue.Count == 0)
         {
             m_sound = null;
             if (cleanUp)
             {
                 Loop = false;
                 SoundId = MyStringId.NullOrEmpty;
             }
         }
         else
         {
             if (cleanUp)
             {
                 SoundId = m_soundsQueue[0];
                 PlaySoundInternal(true);
                 m_soundsQueue.RemoveAt(0);
             }
         }
     }
     else
     {
         if (cleanUp)
         {
             Loop = false;
             SoundId = MyStringId.NullOrEmpty;
         }
     }
 }
Esempio n. 38
0
 private void PlayMusic(MyCueId cue, MyStringHash effect, int effectDuration = 2000, MyCueId[] cueIds = null, bool play = true)
 {
     if (MyAudio.Static == null)
         return;
     if(play)
         m_musicSourceVoice = MyAudio.Static.PlayMusicCue(cue, true);
     if (m_musicSourceVoice != null)
     {
         if (effect != MyStringHash.NullOrEmpty)
         {
             m_musicSourceVoice = MyAudio.Static.ApplyEffect(m_musicSourceVoice, effect, cueIds, effectDuration, true).OutputSound;
         }
         if (m_musicSourceVoice != null)
             m_musicSourceVoice.StoppedPlaying += MusicStopped;
     }
     m_lastMusicData = MyAudio.Static.GetCue(cue);
 }
 private void PlaySoundInternal(bool skipIntro = false, bool skipToEnd = false)
 {
     m_playing2D = ShouldPlay2D() && !Force3D;
     Loop = MyAudio.Static.IsLoopable(SoundId) && !skipToEnd;
     if (m_playing2D)
         Sound = MyAudio.Static.PlaySound(SoundId, this, MySoundDimensions.D2, skipIntro, skipToEnd);
     else if (CanHearSound()) //Start 3D sound only if can be heard
         Sound = MyAudio.Static.PlaySound(SoundId, this, MySoundDimensions.D3, skipIntro, skipToEnd);
     if (Sound != null)
     {
         Sound.StoppedPlaying = OnStopPlaying;
         if (EmitterMethods[MethodsEnum.ImplicitEffect].Count > 0)
         {
             var effectId = ((Func<MyStringId>)EmitterMethods[MethodsEnum.ImplicitEffect][0])();
             if (effectId != MyStringId.NullOrEmpty)
             {
                 var effect = MyAudio.Static.ApplyEffect(Sound, effectId);
                 if (effect != null)
                     Sound = effect.OutputSound;
             }
         }
     }
     else
         OnStopPlaying();
 }
 void ResumeCue(IMySourceVoice cue)
 {
     if ((cue != null) && cue.IsPaused)
     {
         cue.Resume();
     }
 }
Esempio n. 41
0
        public IMyAudioEffect ApplyEffect(IMySourceVoice input, MyStringHash effect, MyCueId[] cueIds = null, float? duration = null, bool musicEffect = false)
        {
            if (m_effectBank == null)
                return null;
			int waveNumber;
            List<MySourceVoice> voices = new List<MySourceVoice>();
            if (cueIds != null)
            {
                foreach (var cueId in cueIds)
                {
                    var sound = GetSound(cueId, out waveNumber);
                    System.Diagnostics.Debug.Assert(sound != null, "Missing sound " + cueId);
                    if (sound != null)
                        voices.Add(sound);
                }
            }
            IMyAudioEffect result = m_effectBank.CreateEffect(input, effect, voices.ToArray(), duration);
            if (musicEffect && result.OutputSound is MySourceVoice)
                (result.OutputSound as MySourceVoice).SetOutputVoices(m_musicAudioVoiceDesc);
            return result;
        }
 public static void EnqueueSound(MyGuiSounds sound)
 {
     if (!MyGuiAudio.HudWarnings)
         return;
     if ((m_sound == null || !m_sound.IsPlaying) && MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastSoundPlayed > 5000)
     {
         m_sound = MyGuiAudio.PlaySound(sound);
         m_lastSoundPlayed = MySandboxGame.TotalGamePlayTimeInMilliseconds;
     }
     else
         m_soundQueue.Add(sound);
 }
 public void PlaySound(byte[] buffer, int size, int sampleRate, float volume = 1, float maxDistance = 0, MySoundDimensions dimension = MySoundDimensions.D3)
 {
     CustomMaxDistance = maxDistance;
     CustomVolume = volume;
     if (Sound == null)
         Sound = MyAudio.Static.GetSound(this, sampleRate, 1, dimension);
     if (Sound != null)
     {
         Sound.SubmitBuffer(buffer, size);
         if (!Sound.IsPlaying)
             Sound.StartBuffered();
     }
 }
        public void Update()
        {
            bool validSoundIsPlaying = m_sound != null && m_sound.IsPlaying;
            if (!CanHearSound())
            {
                if (validSoundIsPlaying)
                {
                    StopSound(true, false);
                    m_sound = null;
                }
                return;
            }
            else if (!validSoundIsPlaying && Loop)
            {
                PlaySound(m_closeSoundSoundPair,true,true);
            }
            else if (validSoundIsPlaying && Loop && m_playing2D != ShouldPlay2D() && ((Force2D == true && m_playing2D == false) || (Force3D == true && m_playing2D == true)))
            {
                StopSound(true, false);
                PlaySound(m_closeSoundSoundPair, true, true);
            }
            else if (validSoundIsPlaying && Loop && m_playing2D == false && m_usesDistanceSounds)
            {
                MyCueId oldSecondary = (m_secondaryEnabled ? m_secondaryCueEnum : myEmptyCueId);
                MyCueId newSound = CheckDistanceSounds(m_closeSoundCueId);
                if (newSound != m_cueEnum || oldSecondary != m_secondaryCueEnum)
                {
                    PlaySoundWithDistance(newSound, true, true, useDistanceCheck: false);
                }
                else if (m_secondaryEnabled)
                {
                    if(Sound != null)
                        Sound.SetVolume(RealisticVolumeChange * m_baseVolume * (1f - m_secondaryVolumeRatio));
                    if(m_secondarySound != null)
                        m_secondarySound.SetVolume(RealisticVolumeChange * m_secondaryBaseVolume * m_secondaryVolumeRatio);
                }
            }
            if (validSoundIsPlaying && Loop)
            {
                //arcade/real sound change
                MyCueId newCueId = SelectCue(m_soundPair);
                if (newCueId.Equals(m_cueEnum) == false)
                    PlaySoundWithDistance(newCueId, true, true);

                //active filter changed
                MyStringHash newEffect = SelectEffect();
                if(m_activeEffect != newEffect)
                    PlaySoundWithDistance(newCueId, true, true);
            }
        }
 private void PlaySound(MyStringId soundId)
 {
     if (m_sound != null && m_sound.IsPlaying)
     {
         var effect = MyAudio.Static.ApplyEffect(m_sound, MyStringId.GetOrCompute("CrossFade"), new MyStringId[] { soundId }, 2000);
         m_sound = effect.OutputSound;
     }
     else
         m_sound = MyAudio.Static.PlaySound(soundId, null, MySoundDimensions.D2);
 }
 private void PlaySoundInternal(bool skipIntro = false, bool skipToEnd = false, bool force2D = false, bool alwaysHearOnRealistic = false)
 {
     Force2D = force2D;
     m_alwaysHearOnRealistic = alwaysHearOnRealistic;
     m_playing2D = (ShouldPlay2D() && !Force3D) || force2D || Force2D;
     Loop = MyAudio.Static.IsLoopable(SoundId) && !skipToEnd;
     if (!SoundId.IsNull)
     {
         if (Loop && MySession.Static.ElapsedPlayTime.TotalSeconds < 6)
             skipIntro = true;
         if (m_playing2D && CheckForSynchronizedSounds())
             Sound = MyAudio.Static.PlaySound(SoundId, this, MySoundDimensions.D2, skipIntro, skipToEnd);
         else if (CanHearSound() && CheckForSynchronizedSounds()) //Start 3D sound only if can be heard
             Sound = MyAudio.Static.PlaySound(SoundId, this, MySoundDimensions.D3, skipIntro, skipToEnd);
     }
     if (Sound != null && Sound.IsPlaying)
     {
         if (MyMusicController.Static != null && m_lastSoundData != null && m_lastSoundData.DynamicMusicCategory != MyStringId.NullOrEmpty && m_lastSoundData.DynamicMusicAmount > 0)
             MyMusicController.Static.IncreaseCategory(m_lastSoundData.DynamicMusicCategory, m_lastSoundData.DynamicMusicAmount);
         m_baseVolume = Sound.Volume;
         Sound.SetVolume(Sound.Volume * RealisticVolumeChange);
         if (m_secondaryEnabled && m_secondaryCueEnum != null)
         {
             m_secondarySound = MyAudio.Static.PlaySound(m_secondaryCueEnum, this, MySoundDimensions.D3, skipIntro, skipToEnd);
             if (Sound == null)
                 return;
             if (m_secondarySound != null)
             {
                 m_secondaryBaseVolume = m_secondarySound.Volume;
                 Sound.SetVolume(RealisticVolumeChange * m_baseVolume * (1f - m_secondaryVolumeRatio));
                 m_secondarySound.SetVolume(RealisticVolumeChange * m_secondaryBaseVolume * m_secondaryVolumeRatio);
                 m_secondarySound.VolumeMultiplier = m_volumeMultiplier;
             }
         }
         Sound.VolumeMultiplier = m_volumeMultiplier;
         Sound.StoppedPlaying = OnStopPlaying;
         if (EmitterMethods[MethodsEnum.ImplicitEffect].Count > 0)
         {
             m_activeEffect = MyStringHash.NullOrEmpty;
             var effectId = ((Func<MyStringHash>)EmitterMethods[MethodsEnum.ImplicitEffect][0])();
             if (effectId != MyStringHash.NullOrEmpty)
             {
                 var effect = MyAudio.Static.ApplyEffect(Sound, effectId);
                 if (effect != null)
                 {
                     Sound = effect.OutputSound;
                     m_activeEffect = effectId;
                 }
             }
         }
     }
     else
         OnStopPlaying();
 }
 public void Cleanup()
 {
     if (Sound != null)
     {
         Sound.Cleanup();
         Sound = null;
     }
     if (m_secondarySound != null)
     {
         m_secondarySound.Cleanup();
         m_secondarySound = null;
     }
 }
Esempio n. 48
0
 IMyAudioEffect IMyAudio.ApplyEffect(IMySourceVoice input, MyStringHash effect, MyCueId[] cueIds, float? duration) { return null; }
 public void Update()
 {
     if (!CanHearSound())
     {
         if (m_sound != null && m_sound.IsPlaying)
         {
             StopSound(true, false);
             m_sound = null;
         }
         return;
     }
     else if ((m_sound == null || !m_sound.IsPlaying) && Loop)
         PlaySoundInternal(true);
     else if (m_sound != null && m_sound.IsPlaying && Loop && m_playing2D != ShouldPlay2D())
     {
         StopSound(true, false);
         PlaySoundInternal(true);
     }
 }
 public static void RemoveSound(MyGuiSounds cueEnum)
 {
     if (m_sound != null && m_sound.CueEnum == MyGuiAudio.GetCue(cueEnum) && m_sound.IsPlaying == false)
     {
         m_sound.Stop();
         m_sound = null;
     }
     m_soundQueue.RemoveAll(new System.Predicate<MyGuiSounds>((cue) => { return cue == cueEnum; }));
 }
 public void Cleanup()
 {
     if (Sound != null)
     {
         Sound.Cleanup();
         Sound = null;
     }
 }
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            if (MySandboxGame.IsDedicated)
            {
                m_hudWarnings.Clear();
                m_soundQueue.Clear();
                return;
            }

            m_updateCounter++;
            if (m_updateCounter % FRAMES_BETWEEN_UPDATE == 0)
            {
                foreach (var warningGroup in m_hudWarnings)
                    warningGroup.Update();
                if (m_soundQueue.Count > 0 && MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastSoundPlayed > 5000)
                {
                    m_lastSoundPlayed = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                    m_sound = MyGuiAudio.PlaySound(m_soundQueue[0]);
                    m_soundQueue.RemoveAt(0);
                }
            }
        }
 void PauseCue(IMySourceVoice cue)
 {
     if ((cue != null) && cue.IsPlaying)
     {
         cue.Pause();
     }
 }
Esempio n. 54
0
        private void PlaySound(MyCueId soundId, bool useCrossfade)
        {
            if (m_sound != null && m_sound.IsPlaying && useCrossfade)
            {
                var effect = MyAudio.Static.ApplyEffect(m_sound, MyStringHash.GetOrCompute("CrossFade"), new MyCueId[] { soundId }, 2000);
                m_sound = effect.OutputSound;
            }
            else
            {
                if (m_sound != null)
                {
                    m_sound.Stop(true);
                }

                m_sound = MyAudio.Static.PlaySound(soundId, null, MySoundDimensions.D2);
            }
        }
 void PlayZoomingRelSound()
 {
     if ((m_zoomRelCue == null) || !m_zoomRelCue.IsPlaying)
     {
         m_zoomRelCue = MyAudio.Static.PlaySound(ZOOM_SOUND.SoundId);
     }
 }
 public void Update()
 {
     bool validSoundIsPlaying = m_sound != null && m_sound.IsPlaying;
     if (!CanHearSound())
     {
         if (validSoundIsPlaying)
         {
             StopSound(true, false);
             m_sound = null;
         }
         return;
     }
     else if (!validSoundIsPlaying && Loop)
     {
         PlaySoundInternal(true);
     }
     else if (validSoundIsPlaying && Loop && m_playing2D != ShouldPlay2D())
     {
         StopSound(true, false);
         PlaySoundInternal(true);
     }
     else if (validSoundIsPlaying && Loop && m_playing2D == false && usesDistanceSounds)
     {
         MyCueId newSound = CheckDistanceSounds(closeSound);
         if (MyStringHash.Comparer.Equals(newSound.Hash, SoundId.Hash) == false)
         {
             PlaySound(newSound, true, useDistanceCheck: false);
         }
     }
 }
Esempio n. 57
0
 public void Unload()
 {
     if(m_musicSourceVoice != null)
     {
         m_musicSourceVoice.Stop();
         m_musicSourceVoice = null;
     }
     Active = false;
     ClearMusicCues();
 }
        private void PlaySound(MyCueId sound)
        {
            if (m_sound == null || !m_sound.IsPlaying)
            {
                m_sound = MyAudio.Static.PlaySound(sound);
                if (!sound.IsNull)
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeIn, null);
                if (m_effect != null)
                    m_sound = m_effect.OutputSound;
            }
            else if (m_effect != null && m_effect.Finished && sound.IsNull)
                m_sound.Stop(true);
            else if (m_sound.CueEnum != sound)
            {
                if (m_effect != null && !m_effect.Finished)
                {
                    //m_effect.SetPositionRelative(1f);
                    m_effect.AutoUpdate = true;
                }
                if (sound.IsNull)
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_fadeOut, null, 5000f);
                else
                    m_effect = MyAudio.Static.ApplyEffect(m_sound, m_crossFade, new MyCueId[] { sound }, 5000f);

                if (m_effect != null && !m_effect.Finished)
                {
                    m_effect.AutoUpdate = true;
                    m_sound = m_effect.OutputSound;
                }
            }
            if (m_sound != null)
            {
                MySoundData data = MyAudio.Static.GetCue(sound);
                m_volumeOriginal = data != null ? data.Volume :1f;
                m_sound.SetVolume(m_volumeOriginal * m_volumeModifier * VolumeModifierGlobal);
            }
        }
 public void StopSound(bool forced, bool cleanUp = true)
 {
     m_usesDistanceSounds = false;
     if (m_sound != null)
     {
         m_sound.Stop(forced);
         if (Loop && !forced)
             PlaySoundInternal(true, true);
         if (m_soundsQueue.Count == 0)
         {
             m_sound = null;
             if (cleanUp)
             {
                 Loop = false;
                 SoundId = myEmptyCueId;
             }
         }
         else
         {
             if (cleanUp)
             {
                 SoundId = m_soundsQueue[0];
                 PlaySoundInternal(true);
                 m_soundsQueue.RemoveAt(0);
             }
         }
     }
     else
     {
         if (cleanUp)
         {
             Loop = false;
             SoundId = myEmptyCueId;
         }
     }
     if (m_secondarySound != null)
     {
         m_secondarySound.Stop(true);
     }
 }
Esempio n. 60
0
        public void Update(bool force=false)
        {
            if (MySession.Static == null || MySession.Static.LocalCharacter != m_character)
                return;

            if (CurrentState == State.Heated)
                m_staminaDepletion = Math.Min(m_staminaDepletion + STAMINA_AMOUNT_RUN, STAMINA_AMOUNT_MAX);
            else if (CurrentState == State.VeryHeated)
                m_staminaDepletion = Math.Min(m_staminaDepletion + STAMINA_AMOUNT_SPRINT, STAMINA_AMOUNT_MAX);
            else
                m_staminaDepletion = Math.Max(m_staminaDepletion - MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS, 0f);

            if (CurrentState == State.NoBreath)
            {
                if (m_sound != null)
                {
                    m_sound.Stop();
                    m_sound = null;
                }
                return;
            }
            float health = m_character.StatComp.Health.Value;
            if (CurrentState == State.Choking)
            {
                if (health >= CHOKE_TRESHOLD_LOW && (m_sound == null || m_sound.CueEnum != OXYGEN_CHOKE_NORMAL.SoundId))
                    PlaySound(OXYGEN_CHOKE_NORMAL.SoundId, false);
                else if (health >= CHOKE_TRESHOLD_CRITICAL && health < CHOKE_TRESHOLD_LOW && (m_sound == null || m_sound.CueEnum != OXYGEN_CHOKE_LOW.SoundId))
                    PlaySound(OXYGEN_CHOKE_LOW.SoundId, false);
                else if (health > 0f && health < CHOKE_TRESHOLD_CRITICAL && (m_sound == null || m_sound.CueEnum != OXYGEN_CHOKE_CRITICAL.SoundId))
                    PlaySound(OXYGEN_CHOKE_CRITICAL.SoundId, false);
                return;
            }

            if (CurrentState == State.Calm || CurrentState == State.Heated || CurrentState == State.VeryHeated)
            {
                if (m_staminaDepletion < STAMINA_RECOVERY_CALM_TO_ZERO && health > 20f)
                {
                    if (!BREATH_CALM.SoundId.IsNull && (m_sound == null || m_sound.CueEnum != BREATH_CALM.SoundId))
                        PlaySound(BREATH_CALM.SoundId, true);
                }
                else
                {
                    if (!BREATH_HEAVY.SoundId.IsNull && (m_sound == null || m_sound.CueEnum != BREATH_HEAVY.SoundId))
                        PlaySound(BREATH_HEAVY.SoundId, true);
                }
            }
        }