Exemplo n.º 1
0
        public bool SourceIsCloseEnoughToPlaySound(IMy3DSoundEmitter source, MyStringId cue)
        {
            if (m_cueBank == null || cue == MyStringId.NullOrEmpty)
            {
                return(false);
            }

            MySoundData cueDefinition = m_cueBank.GetCue(cue);

            if (cueDefinition == null)
            {
                return(false);
            }

            float distanceToSound = Vector3.DistanceSquared(new Vector3(m_listener.Position.X, m_listener.Position.Y, m_listener.Position.Z), source.SourcePosition);

            if (source.CustomMaxDistance > 0)
            {
                return(distanceToSound <= source.CustomMaxDistance * source.CustomMaxDistance);
            }
            else
            {
                return(distanceToSound <= cueDefinition.MaxDistance * cueDefinition.MaxDistance);
            }
        }
Exemplo n.º 2
0
        private MyCueId SelectCue(MySoundPair sound)
        {
            if (m_useRealisticByDefault)
            {
                if (m_lastSoundData == null)
                {
                    m_lastSoundData = MyAudio.Static.GetCue(sound.Realistic);
                }

                if (m_lastSoundData != null && m_lastSoundData.AlwaysUseOneMode)
                {
                    m_realistic = true;
                    return(sound.Realistic);
                }

                MyCockpit cockpit = MySession.Static.LocalCharacter != null ? MySession.Static.LocalCharacter.Parent as MyCockpit : null;
                bool      isLargePressurizedCockpit = (cockpit != null && cockpit.CubeGrid.GridSizeEnum == VRage.Game.MyCubeSize.Large && cockpit.BlockDefinition.IsPressurized);
                if (IsThereAir() || isLargePressurizedCockpit)
                {
                    m_realistic = false;
                    return(sound.Arcade);
                }
                else
                {
                    m_realistic = true;
                    return(sound.Realistic);
                }
            }
            else
            {
                m_realistic = false;
                return(sound.Arcade);
            }
        }
Exemplo n.º 3
0
        internal MyInMemoryWave GetWave(MySoundData cue, MySoundDimensions dim, int waveNumber, CuePart cuePart)
        {
            if (m_waveBank == null)
            {
                return(null);
            }
            foreach (var wave in cue.Waves)
            {
                if (wave.Type == dim)
                {
                    if (waveNumber == 0)
                    {
                        switch (cuePart)
                        {
                        case CuePart.Start:
                            return(m_waveBank.GetWave(wave.Start));

                        case CuePart.Loop:
                            return(m_waveBank.GetWave(wave.Loop));

                        case CuePart.End:
                            return(m_waveBank.GetWave(wave.End));
                        }
                    }
                    waveNumber--;
                }
            }
            return(null);
        }
Exemplo n.º 4
0
        private void Update3DCuePosition(IMy3DSoundEmitter source)
        {
            if (m_cueBank == null)
            {
                return;
            }

            MySoundData cue = m_cueBank.GetCue(source.SoundId);

            if (cue == null || source.Sound == null)// || !source.Sound.IsBuffered)
            {
                return;
            }

            var sourceVoice = source.Sound as MySourceVoice;

            if (sourceVoice == null)
            {
                return;
            }

            if (!sourceVoice.IsBuffered)
            {
                m_helperEmitter.UpdateValuesOmni(source.SourcePosition, source.Velocity, cue, m_deviceDetails.OutputFormat.Channels, source.CustomMaxDistance);
                float maxDistance = source.CustomMaxDistance.HasValue ? source.CustomMaxDistance.Value : cue.MaxDistance;
                sourceVoice.distanceToListener = m_x3dAudio.Apply3D(sourceVoice.Voice, m_listener, m_helperEmitter, source.SourceChannels, m_deviceDetails.OutputFormat.Channels, m_calculateFlags, maxDistance, source.Sound.FrequencyRatio, sourceVoice.Silent, !source.Realistic);
            }
            else
            {
                float maxDistance = source.CustomMaxDistance.Value;
                m_helperEmitter.UpdateValuesOmni(source.SourcePosition, source.Velocity, maxDistance, m_deviceDetails.OutputFormat.Channels, cue.VolumeCurve);
                sourceVoice.distanceToListener = m_x3dAudio.Apply3D(sourceVoice.Voice, m_listener, m_helperEmitter, source.SourceChannels, m_deviceDetails.OutputFormat.Channels, m_calculateFlags, maxDistance, sourceVoice.FrequencyRatio, sourceVoice.Silent, !source.Realistic);
            }
        }
Exemplo n.º 5
0
        public bool SourceIsCloseEnoughToPlaySound(Vector3 sourcePosition, MyCueId cueId, float?customMaxDistance = 0)
        {
            if (m_cueBank == null || cueId.Hash == MyStringHash.NullOrEmpty)
            {
                return(false);
            }

            MySoundData cueDefinition = m_cueBank.GetCue(cueId);

            if (cueDefinition == null)
            {
                return(false);
            }

            float distanceToSound = Vector3.DistanceSquared(new Vector3(m_listener.Position.X, m_listener.Position.Y, m_listener.Position.Z), sourcePosition);

            if (customMaxDistance > 0)
            {
                return(distanceToSound <= customMaxDistance * customMaxDistance);
            }
            else
            {
                return(distanceToSound <= cueDefinition.MaxDistance * cueDefinition.MaxDistance);
            }
        }
Exemplo n.º 6
0
        internal MyInMemoryWave GetRandomWave(MySoundData cue, MySoundDimensions type, out int waveNumber, out CuePart part, int tryIgnoreWaveNumber = -1)
        {
            int counter = 0;

            foreach (var w in cue.Waves)
            {
                if (w.Type == type)
                {
                    counter++;
                }
            }
            waveNumber = MyUtils.GetRandomInt(counter);
            if (counter > 2 && waveNumber == tryIgnoreWaveNumber)
            {
                waveNumber = (waveNumber + 1) % (counter);                      // TODO: Do this better
            }
            var wave = GetWave(cue, type, waveNumber, CuePart.Start);

            if (wave != null)
            {
                part = CuePart.Start;
            }
            else
            {
                wave = GetWave(cue, type, waveNumber, CuePart.Loop);
                part = CuePart.Loop;
            }
            return(wave);
        }
Exemplo 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;
        }
Exemplo n.º 8
0
        public static IMySourceVoice PlaySound(MyGuiSounds sound)
        {
            if (MyFakes.ENABLE_NEW_SOUNDS && MySession.Static != null && MySession.Static.Settings.RealisticSound && MySession.Static.LocalCharacter != null &&
                MySession.Static.LocalCharacter.OxygenComponent != null && MySession.Static.LocalCharacter.OxygenComponent.HelmetEnabled == false)
            {
                MySoundData soundData = MyAudio.Static.GetCue(m_sounds[sound].SoundId);
                if (soundData != null && soundData.CanBeSilencedByVoid)
                {
                    MyCockpit cockpit = MySession.Static.LocalCharacter.Parent as MyCockpit;
                    if ((cockpit == null || !cockpit.BlockDefinition.IsPressurized) && MySession.Static.LocalCharacter.EnvironmentOxygenLevel <= 0)
                    {
                        return(null);//disables hud sound when in realistic mode in space without helmet
                    }
                }
            }

            if (CheckForSynchronizedSounds(sound))
            {
                return(MyAudio.Static.PlaySound(m_sounds[sound].SoundId));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 9
0
        public MyInMemoryWave(MySoundData cue, string path, MyWaveBank owner, bool streamed = false)
        {
            using (var stream = MyFileSystem.OpenRead(path))
            {
                m_owner      = owner;
                m_path       = path;
                m_stream     = new SoundStream(stream);
                m_waveFormat = m_stream.Format;
                m_buffer     = new AudioBuffer
                {
                    Stream     = m_stream.ToDataStream(),
                    AudioBytes = (int)m_stream.Length,
                    Flags      = BufferFlags.None
                };

                if (cue.Loopable)
                {
                    m_buffer.LoopCount = AudioBuffer.LoopInfinite;
                }

                m_stream.Close();

                Streamed = streamed;
            }
        }
Exemplo n.º 10
0
        private static bool CheckForSynchronizedSounds(MyGuiSounds sound)
        {
            MySoundData soundData = MyAudio.Static.GetCue(m_sounds[sound].SoundId);

            if (soundData != null && soundData.PreventSynchronization >= 0)
            {
                int lastTime;
                int now = MyFpsManager.GetSessionTotalFrames();
                if (m_lastTimePlaying.TryGetValue(sound, out lastTime))
                {
                    if (Math.Abs(now - lastTime) <= soundData.PreventSynchronization)
                    {
                        return(false);
                    }
                    else
                    {
                        m_lastTimePlaying[sound] = now;
                    }
                }
                else
                {
                    m_lastTimePlaying.Add(sound, now);
                }
            }
            return(true);
        }
Exemplo n.º 11
0
        public void PlaySoundWithDistance(MyCueId soundId, bool stopPrevious = false, bool skipIntro = false, bool force2D = false, bool useDistanceCheck = true, bool alwaysHearOnRealistic = false)
        {
            m_lastSoundData = MyAudio.Static.GetCue(soundId);
            if (useDistanceCheck)
            {
                m_closeSoundCueId = soundId;
            }
            if (useDistanceCheck && ShouldPlay2D() == false && force2D == false)
            {
                soundId = CheckDistanceSounds(soundId);
            }
            bool usesDistanceSoundsCache = m_usesDistanceSounds;

            if (m_sound != null)
            {
                if (stopPrevious)
                {
                    StopSound(true);
                }
                else if (m_sound.IsLoopable)
                {
                    var sound = Sound;
                    StopSound(true);
                    m_soundsQueue.Add(sound.CueEnum);
                }
            }
            if (m_secondarySound != null)
            {
                m_secondarySound.Stop(true);
            }
            SoundId = soundId;
            PlaySoundInternal(skipIntro, force2D: force2D, alwaysHearOnRealistic: alwaysHearOnRealistic);
            m_usesDistanceSounds = usesDistanceSoundsCache;
        }
Exemplo n.º 12
0
 private MyCueId CheckDistanceSounds(MyCueId soundId)
 {
     if (soundId.IsNull == false)
     {
         MySoundData cueDefinition = MyAudio.Static.GetCue(soundId);
         if (cueDefinition != null && cueDefinition.DistantSounds != null && cueDefinition.DistantSounds.Count > 0)
         {
             float distanceToSoundSquered = Vector3.DistanceSquared(MySector.MainCamera.Position, this.SourcePosition);
             int   bestSoundIndex         = -1;
             usesDistanceSounds = true;
             for (int i = 0; i < cueDefinition.DistantSounds.Count; i++)
             {
                 if (distanceToSoundSquered > cueDefinition.DistantSounds[i].distance * cueDefinition.DistantSounds[i].distance)
                 {
                     bestSoundIndex = i;
                 }
                 else
                 {
                     break;
                 }
             }
             if (bestSoundIndex >= 0)
             {
                 soundId = new MyCueId(MyStringHash.GetOrCompute(cueDefinition.DistantSounds[bestSoundIndex].sound));
             }
         }
         else
         {
             usesDistanceSounds = false;
         }
     }
     return(soundId);
 }
Exemplo n.º 13
0
        private void Update3DCuePosition(IMy3DSoundEmitter source)
        {
            MySoundData cue = m_cueBank.GetCue(source.SoundId);

            if (cue == null && source.Sound == null && !source.Sound.IsBuffered)
            {
                return;
            }

            var sourceVoice = source.Sound as MySourceVoice;

            if (sourceVoice == null)
            {
                return;
            }

            if (!sourceVoice.IsBuffered)
            {
                m_helperEmitter.UpdateValuesOmni(source.SourcePosition, source.Velocity, cue, m_deviceDetails.OutputFormat.Channels, source.CustomMaxDistance);
                float maxDistance = source.CustomMaxDistance.HasValue ? source.CustomMaxDistance.Value : cue.MaxDistance;
                m_x3dAudio.Apply3D(sourceVoice.Voice, m_listener, m_helperEmitter, source.SourceChannels, m_deviceDetails.OutputFormat.Channels, m_calculateFlags, maxDistance, source.Sound.FrequencyRatio);
            }
            else
            {
                float maxDistance = source.CustomMaxDistance.Value;
                m_helperEmitter.UpdateValuesOmni(source.SourcePosition, source.Velocity, maxDistance, m_deviceDetails.OutputFormat.Channels, MyCurveType.Linear);
                m_x3dAudio.Apply3D(sourceVoice.Voice, m_listener, m_helperEmitter, source.SourceChannels, m_deviceDetails.OutputFormat.Channels, m_calculateFlags, maxDistance, sourceVoice.FrequencyRatio);
            }
        }
Exemplo n.º 14
0
        internal MyInMemoryWave GetRandomWave(MySoundData cue, MySoundDimensions type, out int waveNumber, out CuePart part)
        {
            int counter = 0;

            foreach (var w in cue.Waves)
            {
                if (w.Type == type)
                {
                    counter++;
                }
            }
            waveNumber = MyUtils.GetRandomInt(counter);
            var wave = GetWave(cue, type, waveNumber, CuePart.Start);

            if (wave != null)
            {
                part = CuePart.Start;
            }
            else
            {
                wave = GetWave(cue, type, waveNumber, CuePart.Loop);
                part = CuePart.Loop;
            }
            return(wave);
        }
Exemplo n.º 15
0
        public IMySourceVoice PlayTestSound(MyStringId cue)
        {
            if (cue == MyStringId.NullOrEmpty)
            {
                return(null);
            }

            MySoundData cueDefinition = m_cueBank.GetCue(cue);

            //  If this computer can't play sound, we don't create cues
            if (!m_canPlay)
            {
                return(null);
            }

            if (m_cueBank == null)
            {
                return(null);
            }

            MySourceVoice sound = m_cueBank.GetVoice(cue);

            if (sound == null)
            {
                sound = m_cueBank.GetVoice(cue, MySoundDimensions.D3);
            }
            if (sound == null)
            {
                return(null);
            }

            if (cueDefinition.PitchVariation != 0f)
            {
                float semitones = PitchVariation(cueDefinition);
                sound.FrequencyRatio = SemitonesToFrequencyRatio(semitones);
            }
            else
            {
                sound.FrequencyRatio = 1f;
            }

            float volume = cueDefinition.Volume;

            if (cueDefinition.VolumeVariation != 0f)
            {
                float variation = VolumeVariation(cueDefinition);
                volume = MathHelper.Clamp(volume + variation, 0f, 1f);
            }

            sound.SetVolume(volume);
            sound.SetOutputVoices(m_gameAudioVoiceDesc);

            //  Play the cue
            sound.Start(false);

            return(sound);
        }
Exemplo n.º 16
0
        void cuesCombo_OnSelect()
        {
            m_currentCueSelectedItem = (int)m_cuesCombo.GetSelectedKey();
            var cue = new MyCueId(MyStringHash.TryGet(m_cuesCombo.GetSelectedValue().ToString()));

            m_currentCue = MyAudio.Static.GetCue(cue);

            UpdateCueValues();
            //RecreateControls(false);
        }
Exemplo n.º 17
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_AudioDefinition;

            MyDebug.AssertDebug(ob != null);

            this.SoundData           = ob.SoundData;
            this.SoundData.SubtypeId = base.Id.SubtypeId;
        }
Exemplo n.º 18
0
        public MySoundData GetCue(MyCueId cueId)
        {
            //Debug.Assert(m_cues.ContainsKey(cue));
            if (!m_cues.ContainsKey(cueId) && cueId.Hash != MyStringHash.NullOrEmpty)
            {
                MyLog.Default.WriteLine("Cue was not found: " + cueId, LoggingOptions.AUDIO);
            }
            MySoundData result = null;

            m_cues.TryGetValue(cueId, out result);
            return(result);
        }
Exemplo n.º 19
0
        public object CalculateDspSettingsDebug(IMy3DSoundEmitter source)
        {
            MySoundData cue = m_cueBank.GetCue(source.SoundId);

            m_helperEmitter.UpdateValuesOmni(source.SourcePosition, source.Velocity, cue, m_deviceDetails.OutputFormat.Channels, source.CustomMaxDistance);
            DspSettingsRef result   = new DspSettingsRef(1, m_deviceDetails.OutputFormat.Channels);
            DspSettings    settings = result.DspSettings;

            unsafe
            {
                m_x3dAudio.Calculate(m_listener, m_helperEmitter, m_calculateFlags, &settings);
            }
            return(result);
        }
Exemplo n.º 20
0
        public bool IsLoopable(MyStringId cueId)
        {
            if (cueId == MyStringId.NullOrEmpty || m_cueBank == null)
            {
                return(false);
            }
            MySoundData cueDefinition = m_cueBank.GetCue(cueId);

            if (cueDefinition == null)
            {
                return(false);
            }

            return(cueDefinition.Loopable);
        }
        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);
            }
        }
Exemplo n.º 22
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);
 }
Exemplo n.º 23
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_AudioDefinition;

            MyDebug.AssertDebug(ob != null);

            this.SoundData           = ob.SoundData;
            this.SoundData.SubtypeId = base.Id.SubtypeId;

            if (this.SoundData.Loopable)
            {
                bool hasLoop = true;
                for (int i = 0; i < this.SoundData.Waves.Count; i++)
                {
                    hasLoop &= this.SoundData.Waves[i].Loop != null;
                }
                //MyDebug.AssertDebug(hasLoop, String.Format("Sound '{0}' has <Loopable> tag set to TRUE, but is missing a <Loop> in <Wave>, please fix the .sbc", this.SoundData.SubtypeId));
            }
        }
Exemplo n.º 24
0
 private void PlayMusic(MyCueId cue, MyStringHash effect, int effectDuration = 0x7d0, MyCueId[] cueIds = null, bool play = true)
 {
     if (MyAudio.Static != null)
     {
         if (play)
         {
             this.m_musicSourceVoice = MyAudio.Static.PlayMusicCue(cue, true);
         }
         if (this.m_musicSourceVoice != null)
         {
             if (effect != MyStringHash.NullOrEmpty)
             {
                 this.m_musicSourceVoice = MyAudio.Static.ApplyEffect(this.m_musicSourceVoice, effect, cueIds, new float?((float)effectDuration), true).OutputSound;
             }
             if (this.m_musicSourceVoice != null)
             {
                 this.m_musicSourceVoice.StoppedPlaying = (Action)Delegate.Combine(this.m_musicSourceVoice.StoppedPlaying, new Action(this.MusicStopped));
             }
         }
         this.m_lastMusicData = MyAudio.Static.GetCue(cue);
     }
 }
Exemplo n.º 25
0
        private MyCueId SelectCue(MySoundPair sound)
        {
            int isPressurized;

            if (!this.m_useRealisticByDefault)
            {
                this.m_realistic = false;
                return(sound.Arcade);
            }
            if (this.m_lastSoundData == null)
            {
                this.m_lastSoundData = MyAudio.Static.GetCue(sound.Realistic);
            }
            if ((this.m_lastSoundData != null) && this.m_lastSoundData.AlwaysUseOneMode)
            {
                this.m_realistic = true;
                return(sound.Realistic);
            }
            MyCockpit cockpit = (MySession.Static.LocalCharacter != null) ? (MySession.Static.LocalCharacter.Parent as MyCockpit) : null;

            if ((cockpit == null) || (cockpit.CubeGrid.GridSizeEnum != MyCubeSize.Large))
            {
                isPressurized = 0;
            }
            else
            {
                isPressurized = (int)cockpit.BlockDefinition.IsPressurized;
            }
            bool flag = (bool)isPressurized;

            if (this.IsThereAir() | flag)
            {
                this.m_realistic = false;
                return(sound.Arcade);
            }
            this.m_realistic = true;
            return(sound.Realistic);
        }
Exemplo n.º 26
0
        internal MySourceVoice GetSound(MyStringId cueId, IMy3DSoundEmitter source = null, MySoundDimensions type = MySoundDimensions.D2)
        {
            //  If this computer can't play sound, we don't create cues
            if (cueId == MyStringId.NullOrEmpty || !m_canPlay || m_cueBank == null)
            {
                return(null);
            }

            //  If this is one-time cue, we check if it is close enough to hear it and if not, we don't even play - this is for optimization only.
            //  We must add loopable cues always, because if source of cue comes near the camera, we need to update the position, but of course we can do that only if we have reference to it.
            MySoundData cue = m_cueBank.GetCue(cueId);

            if ((SoloCue != null) && (SoloCue != cue))
            {
                return(null);
            }

            var sound        = m_cueBank.GetVoice(cueId, type);
            var originalType = type;

            if (sound == null && source != null && source.Force3D)
            {
                originalType = type == MySoundDimensions.D3 ? MySoundDimensions.D2 : MySoundDimensions.D3;
                sound        = m_cueBank.GetVoice(cueId, originalType);
            }
            if (sound == null)
            {
                return(null);
            }

            float volume = cue.Volume;

            if (source != null && source.CustomVolume.HasValue)
            {
                volume = source.CustomVolume.Value;
            }
            if (cue.VolumeVariation != 0f)
            {
                float variation = VolumeVariation(cue);
                volume = MathHelper.Clamp(volume + variation, 0f, 1f);
            }
            sound.SetVolume(volume);
            var wave = m_cueBank.GetWave(m_sounds.ItemAt(0), MySoundDimensions.D2, 0, MyCueBank.CuePart.Start);

            if (cue.PitchVariation != 0f)
            {
                float semitones = PitchVariation(cue);
                sound.FrequencyRatio = SemitonesToFrequencyRatio(semitones);
            }
            else
            {
                sound.FrequencyRatio = 1f;
            }

            if (cue.IsHudCue)
            {
                sound.Voice.SetOutputVoices(m_hudAudioVoiceDesc);
            }
            else
            {
                sound.Voice.SetOutputVoices(m_gameAudioVoiceDesc);
            }

            if (type == MySoundDimensions.D3)
            {
                m_helperEmitter.UpdateValuesOmni(source.SourcePosition, source.Velocity, cue, m_deviceDetails.OutputFormat.Channels, source.CustomMaxDistance);
                float maxDistance = source.CustomMaxDistance.HasValue ? source.CustomMaxDistance.Value : cue.MaxDistance;

                source.SourceChannels = 1;
                if (originalType == MySoundDimensions.D2)
                {
                    source.SourceChannels = 2;
                }
                m_x3dAudio.Apply3D(sound.Voice, m_listener, m_helperEmitter, source.SourceChannels, m_deviceDetails.OutputFormat.Channels, m_calculateFlags, maxDistance, sound.FrequencyRatio);

                Update3DCuesState();

                // why was this only for loops?
                //if (sound.IsLoopable)
                Add3DCueToUpdateList(source);

                ++m_soundInstancesTotal3D;
            }
            else
            {
                if (m_3Dsounds.Contains(source))
                {
                    StopUpdating3DCue(source);
                }
                ++m_soundInstancesTotal2D;
            }
            return(sound);
        }
Exemplo n.º 27
0
 private float PitchVariation(MySoundData cue)
 {
     return(MyUtils.GetRandomFloat(-1f, 1f) * cue.PitchVariation / 100f);
 }
Exemplo n.º 28
0
 private float VolumeVariation(MySoundData cue)
 {
     return(MyUtils.GetRandomFloat(-1f, 1f) * cue.VolumeVariation * 0.07f);
 }
Exemplo n.º 29
0
        public void FindAndPlayStateSound()
        {
            if (m_character.Breath != null)
            {
                m_character.Breath.Update();
            }

            var cueEnum = SelectSound();

            UpdateBreath();

            var  primaryEmitter          = m_soundEmitters[(int)MySoundEmitterEnum.PrimaryState];
            var  walkEmitter             = m_soundEmitters[(int)MySoundEmitterEnum.WalkState];
            bool sameSoundAlreadyPlaying = (cueEnum.Equals(primaryEmitter.SoundPair) && primaryEmitter.IsPlaying);

            if (primaryEmitter.Sound != null)
            {
                MySoundData cue = MyAudio.Static.GetCue(cueEnum.SoundId);
                if (cue != null)
                {
                    float definedVolume = cue.Volume;
                    float scaledVolume  = definedVolume * MathHelper.Clamp(m_character.Physics.LinearVelocity.Length() / 7.5f, 0.6f, 1);
                    primaryEmitter.Sound.SetVolume(scaledVolume);
                }
            }

            if (!sameSoundAlreadyPlaying && (m_isWalking == false || m_character.Definition.LoopingFootsteps))
            {
                if (cueEnum != EmptySoundPair && cueEnum == CharacterSounds[(int)CharacterSoundsEnum.JETPACK_RUN_SOUND])
                {
                    if (m_jetpackSustainTimer >= JETPACK_TIME_BETWEEN_SOUNDS)
                    {
                        if (primaryEmitter.Loop)
                        {
                            primaryEmitter.StopSound(true);
                        }
                        primaryEmitter.PlaySound(cueEnum, false, false);
                    }
                }
                else if (!primaryEmitter.SoundId.IsNull && primaryEmitter.SoundId == CharacterSounds[(int)CharacterSoundsEnum.JETPACK_RUN_SOUND].SoundId)
                {
                    if (m_jetpackSustainTimer <= 0f || cueEnum != CharacterSounds[(int)CharacterSoundsEnum.JETPACK_IDLE_SOUND])
                    {
                        primaryEmitter.StopSound(false);
                        primaryEmitter.PlaySound(CharacterSounds[(int)CharacterSoundsEnum.JETPACK_IDLE_SOUND], false, true);
                    }
                }
                else if (cueEnum == EmptySoundPair)
                {
                    foreach (var soundEmitter in m_soundEmitters)
                    {
                        if (soundEmitter.Loop)
                        {
                            soundEmitter.StopSound(false);
                        }
                    }
                }
                else if (cueEnum == m_lastPrimarySound && (cueEnum == CharacterSounds[(int)CharacterSoundsEnum.CROUCH_DOWN_SOUND] || cueEnum == CharacterSounds[(int)CharacterSoundsEnum.CROUCH_UP_SOUND]))
                {
                    //do nothing
                }
                else
                {
                    if (primaryEmitter.Loop)
                    {
                        primaryEmitter.StopSound(false);
                    }
                    primaryEmitter.PlaySound(cueEnum, true, false);
                }
            }
            else if (!m_character.Definition.LoopingFootsteps && walkEmitter != null && cueEnum != null)
            {
                IKFeetStepSounds(walkEmitter, cueEnum);
            }
            m_lastPrimarySound = cueEnum;
        }
Exemplo n.º 30
0
        /// <summary>
        /// Updates values of omnidirectional emitter.
        /// Omnidirectional means it's same for all directions. There's no Cone and Front/Top vectors are not used.
        /// </summary>
        internal static void UpdateValuesOmni(this Emitter emitter, Vector3 position, Vector3 velocity, MySoundData cue, int channelsCount, float?customMaxDistance)
        {
            emitter.Position = new SharpDX.Vector3(position.X, position.Y, position.Z);
            emitter.Velocity = new SharpDX.Vector3(velocity.X, velocity.Y, velocity.Z);

            float maxDistance = customMaxDistance.HasValue ? customMaxDistance.Value : cue.MaxDistance;

            emitter.DopplerScaler       = 1f;
            emitter.CurveDistanceScaler = maxDistance;
            emitter.VolumeCurve         = MyDistanceCurves.Curves[(int)cue.VolumeCurve];

            emitter.InnerRadius      = (channelsCount > 2) ? maxDistance : 0f;
            emitter.InnerRadiusAngle = (channelsCount > 2) ? 0.5f * SharpDX.AngleSingle.RightAngle.Radians : 0f;
        }