Exemplo n.º 1
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.º 2
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.º 3
0
        IMySourceVoice IMyAudio.GetSound(IMy3DSoundEmitter source, int sampleRate, int channels, MySoundDimensions dimension)
        {
            if (!m_canPlay)
            {
                return(null);
            }

            var waveFormat = new WaveFormat(sampleRate, channels);

            source.SourceChannels = channels;
            var sourceVoice = new MySourceVoice(m_audioEngine, waveFormat);

            float volume      = source.CustomVolume.HasValue ? source.CustomVolume.Value : 1;
            float maxDistance = source.CustomMaxDistance.HasValue ? source.CustomMaxDistance.Value : 0;

            sourceVoice.SetVolume(volume);

            if (dimension == MySoundDimensions.D3)
            {
                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);
                Update3DCuesState();
                Add3DCueToUpdateList(source);

                ++m_soundInstancesTotal3D;
            }

            return(sourceVoice);
        }
Exemplo n.º 4
0
 private void Add3DCueToUpdateList(IMy3DSoundEmitter source)
 {
     if (!m_3Dsounds.Contains(source))
     {
         m_3Dsounds.Add(source);
     }
 }
Exemplo n.º 5
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.º 6
0
        private void StopUpdating3DCue(IMy3DSoundEmitter source)
        {
            if (!m_canPlay)
            {
                return;
            }

            m_3Dsounds.Remove(source);
        }
Exemplo n.º 7
0
        internal MySourceVoice PlaySound(MyStringId cueId, IMy3DSoundEmitter source = null, MySoundDimensions type = MySoundDimensions.D2, bool skipIntro = false, bool skipToEnd = false)
        {
            var sound = GetSound(cueId, source, type);

            if (sound != null)
            {
                sound.Start(skipIntro, skipToEnd);
            }
            return(sound);
        }
Exemplo n.º 8
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.º 9
0
        internal MySourceVoice PlaySound(MyCueId cueId, IMy3DSoundEmitter source = null, MySoundDimensions type = MySoundDimensions.D2, bool skipIntro = false, bool skipToEnd = false)
        {
            int waveNumber = -1;
            var sound      = GetSound(cueId, out waveNumber, source, type);

            if (source != null)
            {
                source.LastPlayedWaveNumber = -1;
            }
            if (sound != null)
            {
                sound.Start(skipIntro, skipToEnd);
                if (source != null)
                {
                    source.LastPlayedWaveNumber = waveNumber;
                }
            }
            return(sound);
        }
Exemplo n.º 10
0
        internal MySourceVoice GetSound(MyCueId cueId, out int waveNumber, IMy3DSoundEmitter source = null, MySoundDimensions type = MySoundDimensions.D2)
        {
			waveNumber = -1;
            //  If this computer can't play sound, we don't create cues
            if (cueId.Hash == MyStringHash.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;

			int waveNumberToIgnore = (source != null ? source.LastPlayedWaveNumber : -1);
			var sound = m_cueBank.GetVoice(cueId, out waveNumber, type, waveNumberToIgnore);
            var originalType = type;
            if (sound == null && source != null && source.Force3D)
            {
                originalType = type == MySoundDimensions.D3 ? MySoundDimensions.D2 : MySoundDimensions.D3;
                sound = m_cueBank.GetVoice(cueId, out waveNumber, originalType, waveNumberToIgnore);
            }
            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);

            float semitones = cue.Pitch;
            if (cue.PitchVariation != 0f)
                semitones += PitchVariation(cue);
            if (cue.DisablePitchEffects)
                semitones = 0f;
            if(semitones != 0f)
                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;
                sound.distanceToListener = m_x3dAudio.Apply3D(sound.Voice, m_listener, m_helperEmitter, source.SourceChannels, m_deviceDetails.OutputFormat.Channels, m_calculateFlags, maxDistance, sound.FrequencyRatio, sound.Silent, source.Realistic);

                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.º 11
0
        private void StopUpdating3DCue(IMy3DSoundEmitter source)
        {
            if (!m_canPlay)
                return;

            m_3Dsounds.Remove(source);
        }
Exemplo n.º 12
0
        public object CalculateDspSettingsDebug(IMy3DSoundEmitter source)
        {
            if (m_cueBank == null) 
                return null;

            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.º 13
0
 bool IMyAudio.SourceIsCloseEnoughToPlaySound(IMy3DSoundEmitter source, MyCueId cueId) { return false; }
Exemplo n.º 14
0
 IMySourceVoice IMyAudio.GetSound(IMy3DSoundEmitter source, int sampleRate, int channels, MySoundDimensions dimension)
 {
     return(null);
 }
Exemplo n.º 15
0
 IMySourceVoice IMyAudio.PlaySound(MyCueId cue, IMy3DSoundEmitter source, MySoundDimensions type, bool skipIntro, bool skipToEnd)
 {
     return(null);
 }
Exemplo n.º 16
0
 bool IMyAudio.SourceIsCloseEnoughToPlaySound(IMy3DSoundEmitter source, MyStringId cueEnum) { return false; }
Exemplo n.º 17
0
 bool IMyAudio.SourceIsCloseEnoughToPlaySound(IMy3DSoundEmitter source, MyCueId cueId)
 {
     return(false);
 }
Exemplo n.º 18
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.º 19
0
        private void Update3DCuePosition(IMy3DSoundEmitter source)
        {
            MySoundData cue = m_cueBank.GetCue(source.SoundId);
            if (cue == null)
                return;

            var sourceVoice = source.Sound as MySourceVoice;
            if (sourceVoice == null)
                return;

            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);
        }
Exemplo n.º 20
0
 IMySourceVoice IMyAudio.GetSound(MyStringId cueId, IMy3DSoundEmitter source, MySoundDimensions type)
 {
     return GetSound(cueId, source, type);
 }
Exemplo n.º 21
0
 internal MySourceVoice PlaySound(MyStringId cueId, IMy3DSoundEmitter source = null, MySoundDimensions type = MySoundDimensions.D2, bool skipIntro = false, bool skipToEnd = false)
 {
     var sound = GetSound(cueId, source, type);
     if(sound != null)
         sound.Start(skipIntro, skipToEnd);
     return sound;
 }
Exemplo n.º 22
0
        IMySourceVoice IMyAudio.GetSound(MyCueId cueId, IMy3DSoundEmitter source, MySoundDimensions type)
        {
			int waveNumber;
            return GetSound(cueId, out waveNumber, source, type);
        }
Exemplo n.º 23
0
        //  Adds new cue and starts playing it.
        //  Method returns reference to the cue, so that we can stop playing it.
        public static MySourceVoice PlayCue3D(IMy3DSoundEmitter source, MySoundCuesEnum cueEnum, bool addToUpdateList = true)
        {
            if (cueEnum == MySoundCuesEnum.None)
                return null;

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

            if (!MySandboxGame.IsGameReady)
                return null;

            if (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.
            MyObjectBuilder_CueDefinition cue = m_cueBank.GetCue(cueEnum);
            Debug.Assert(!cue.IsHudCue, "Hud cue can't be played as 3d sound!");

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

            if (!cue.Loopable)
            {
                float distanceToSound;
                if ((MySession.Player != null) && (MySession.Player.PlayerEntity != null) && (MySession.Player.PlayerEntity.Entity != null))
                    distanceToSound = Vector3.DistanceSquared(MySession.Player.PlayerEntity.Entity.GetPosition(), source.SourcePosition);
                else if (MySector.MainCamera != null)
                    distanceToSound = Vector3.DistanceSquared(MySector.MainCamera.Position, source.SourcePosition);
                else
                    return null;

                if (distanceToSound > cue.MaxDistance * cue.MaxDistance)
                    return null;
            }

            MySourceVoice sound = null;
            sound = TrySwitchToCue2D(source, cue);
            if (sound != null)
                return sound;

            sound = m_cueBank.GetVoice(cueEnum);
            if (sound == null)
                return null;

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

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

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

            //if (cue.UseOcclusion)
            //{
            //    //occlusions are disabled;
            //}

            //  Play the cue
            sound.Start();

            if (!m_listener.UpdateFromPlayer())
                m_listener.UpdateFromMainCamera();

            m_helperEmitter.UpdateValues(source.SourcePosition, source.DirForward, source.DirUp, source.Velocity, cue, m_deviceDetails.OutputFormat.Channels);
            m_x3dAudio.Apply3D(sound.Voice, m_listener, m_helperEmitter, cue.MaxDistance, sound.FrequencyRatio);

            Update3DCuesState();

            if (addToUpdateList)
                Add3DCueToUpdateList(source, cueEnum);

            ++m_soundInstancesTotal3D;

            return sound;
        }
Exemplo n.º 24
0
 IMySourceVoice IMyAudio.PlaySound(MyStringId cue, IMy3DSoundEmitter source, MySoundDimensions type, bool skipIntro, bool skipToEnd) { return null; }
Exemplo n.º 25
0
 IMySourceVoice IMyAudio.GetSound(MyCueId cue, IMy3DSoundEmitter source, MySoundDimensions type)
 {
     return(null);
 }
Exemplo n.º 26
0
        private static bool TrySwitchToIntroLoopPair2D(IMy3DSoundEmitter source, ref MySoundCuesEnum introCueEnum, ref MySoundCuesEnum loopCueEnum)
        {
            MyObjectBuilder_CueDefinition introCue = m_cueBank.GetCue(introCueEnum);
            MyObjectBuilder_CueDefinition loopCue = m_cueBank.GetCue(loopCueEnum);
            MyEntity entity = source.Entity;
            MyEntity owner = source.OwnedBy;
            MyEntity parent = (owner != null) ? owner.Parent : null;
            bool isControlledObject = (entity == MySession.ControlledObject) || (owner == MySession.ControlledObject) || (parent == MySession.ControlledObject);
            if ((MyGuiScreenTerminal.IsOpen && (MyGuiScreenTerminal.Interacted == entity)) || (isControlledObject && (introCue.Alternative2D != string.Empty) && (loopCue.Alternative2D != string.Empty)))
            {
                try
                {
                    MySoundCuesEnum introEnum = (MySoundCuesEnum)Enum.Parse(typeof(MySoundCuesEnum), introCue.Alternative2D);
                    MySoundCuesEnum loopEnum = (MySoundCuesEnum)Enum.Parse(typeof(MySoundCuesEnum), loopCue.Alternative2D);
                    introCueEnum = introEnum;
                    loopCueEnum = loopEnum;
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }

            return false;
        }
Exemplo n.º 27
0
        public static bool SourceIsCloseEnoughToPlaySound(IMy3DSoundEmitter source, MySoundCuesEnum cueEnum)
        {
            if (m_cueBank == null)
                return false;

            if (cueEnum == MySoundCuesEnum.None)
                return false;

            MyObjectBuilder_CueDefinition cue = m_cueBank.GetCue(cueEnum);
            if (cue == null)
                return false;

            float distanceToSound;
            if ((MySession.Player != null) && (MySession.Player.PlayerEntity != null) && (MySession.Player.PlayerEntity.Entity != null))
                distanceToSound = Vector3.DistanceSquared(MySession.Player.PlayerEntity.Entity.GetPosition(), source.SourcePosition);
            else if (MySector.MainCamera != null)
                distanceToSound = Vector3.DistanceSquared(MySector.MainCamera.Position, source.SourcePosition);
            else
                return false;

            return (distanceToSound <= cue.MaxDistance * cue.MaxDistance);
        }
Exemplo n.º 28
0
        private static void StopUpdating3DCue(IMy3DSoundEmitter source)
        {
            if (!m_canPlay)
                return;

            if (MyFakes.DEBUG_DRAW_AUDIO)
                MyHud.LocationMarkers.UnregisterMarker(source.Entity);

            m_3Dsounds.Remove(source);
        }
Exemplo n.º 29
0
        private static MySourceVoice TrySwitchToCue2D(IMy3DSoundEmitter source, MyObjectBuilder_CueDefinition cue3D)
        {
            MyEntity entity = source.Entity;
            MyEntity owner = source.OwnedBy;
            MyEntity parent = (owner != null) ? owner.Parent : null;
            bool isControlledObject = (entity == MySession.ControlledObject) || (owner == MySession.ControlledObject) || (parent == MySession.ControlledObject);
            if ((MyGuiScreenTerminal.IsOpen && (MyGuiScreenTerminal.Interacted == entity)) || (isControlledObject && (cue3D.Alternative2D != string.Empty)))
            {
                try
                {
                    MySoundCuesEnum cueEnum = (MySoundCuesEnum)Enum.Parse(typeof(MySoundCuesEnum), cue3D.Alternative2D);
                    MyObjectBuilder_CueDefinition cue2D = m_cueBank.GetCue(cueEnum);
                    float volume = cue2D.Volume;
                    if (cue2D.VolumeVariation != 0f)
                    {
                        float variation = VolumeVariation(cue2D);
                        volume = MathHelper.Clamp(volume + variation, 0f, 1f);
                    }

                    if (m_3Dsounds.Contains(source))
                        StopUpdating3DCue(source);

                    return PlayCue2DInternal(cueEnum, volume);
                }
                catch (Exception)
                {
                    return null;
                }
            }

            return null;
        }
Exemplo n.º 30
0
        public static MySourceVoice PlayIntroLoopPair3D(IMy3DSoundEmitter source, MySoundCuesEnum introCueEnum, MySoundCuesEnum loopCueEnum, bool addToUpdateList = true)
        {
            if ((introCueEnum == MySoundCuesEnum.None) || (loopCueEnum == MySoundCuesEnum.None))
                return null;

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

            if (!MySandboxGame.IsGameReady)
                return null;

            if (m_cueBank == null)
                return null;

            MyObjectBuilder_CueDefinition introCue = m_cueBank.GetCue(introCueEnum);
            MyObjectBuilder_CueDefinition loopCue = m_cueBank.GetCue(loopCueEnum);
            Debug.Assert(!introCue.IsHudCue && !loopCue.IsHudCue, "Hud cue can't be played as 3d sound!");
            Debug.Assert(!introCue.Loopable && loopCue.Loopable, "MyAudio.PlayIntroLoopPair3D is meant to play only pairs intro-loop");

            MySourceVoice voice = null;
            if (TrySwitchToIntroLoopPair2D(source, ref introCueEnum, ref loopCueEnum))
            {
                introCue = m_cueBank.GetCue(introCueEnum);
                loopCue = m_cueBank.GetCue(loopCueEnum);

                voice = m_cueBank.GetVoice(introCueEnum);
                if (voice != null)
                {
                    if (loopCue.PitchVariation != 0f)
                    {
                        float semitones = PitchVariation(loopCue);
                        voice.FrequencyRatio = SemitonesToFrequencyRatio(semitones);
                    }
                    else
                        voice.FrequencyRatio = 1f;

                    float volume2D = loopCue.Volume;
                    if (loopCue.VolumeVariation != 0f)
                    {
                        float variation = VolumeVariation(loopCue);
                        volume2D = MathHelper.Clamp(volume2D + variation, 0f, 1f);
                    }

                    voice.SetVolume(volume2D);
                    voice.Voice.SetFrequencyRatio(voice.FrequencyRatio);
                    voice.Voice.SetOutputVoices(m_gameAudioVoiceDesc);

                    MyInMemoryWave wave2D = m_cueBank.GetRandomWave(loopCue);
                    if (wave2D != null)
                    {
                        if (m_3Dsounds.Contains(source))
                            StopUpdating3DCue(source);

                        Debug.Assert(voice.Owner.WaveFormat.Encoding == wave2D.WaveFormat.Encoding, "Intro and loop cues must have the same encoding!");
                        Debug.Assert((voice.Owner.WaveFormat.Channels == 2) && (voice.Owner.WaveFormat.Channels == wave2D.WaveFormat.Channels), "Both intro and loop cues must have 2 channels");
                        if (voice.Owner.WaveFormat.Encoding == wave2D.WaveFormat.Encoding)
                        {
                            voice.SubmitSourceBuffer(loopCueEnum, wave2D.Buffer, wave2D.Stream.DecodedPacketsInfo, wave2D.WaveFormat.SampleRate);
                            voice.Start();
                            ++m_soundInstancesTotal2D;
                        }
                    }
                }
                return voice;
            }

            voice = m_cueBank.GetVoice(introCueEnum);
            if (voice == null)
                return null;

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

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

            voice.SetVolume(volume);
            voice.Voice.SetFrequencyRatio(voice.FrequencyRatio);
            voice.Voice.SetOutputVoices(m_gameAudioVoiceDesc);

            MyInMemoryWave wave3D = m_cueBank.GetRandomWave(loopCue);
            if (wave3D == null)
                return null;

            Debug.Assert(voice.Owner.WaveFormat.Encoding == wave3D.WaveFormat.Encoding, "Intro and loop cues must have the same encoding!");
            Debug.Assert((voice.Owner.WaveFormat.Channels == 1) && (voice.Owner.WaveFormat.Channels == wave3D.WaveFormat.Channels), "Both intro and loop cues must have 1 channel");
            if (voice.Owner.WaveFormat.Encoding != wave3D.WaveFormat.Encoding)
                return null;

            voice.SubmitSourceBuffer(loopCueEnum, wave3D.Buffer, wave3D.Stream.DecodedPacketsInfo, wave3D.WaveFormat.SampleRate);
            voice.Start();

            if (!m_listener.UpdateFromPlayer())
                m_listener.UpdateFromMainCamera();

            m_helperEmitter.UpdateValues(source.SourcePosition, source.DirForward, source.DirUp, source.Velocity, loopCue, m_deviceDetails.OutputFormat.Channels);
            m_x3dAudio.Apply3D(voice.Voice, m_listener, m_helperEmitter, introCue.MaxDistance, voice.FrequencyRatio);

            Update3DCuesState();

            if (addToUpdateList)
                Add3DCueToUpdateList(source, loopCueEnum);

            ++m_soundInstancesTotal3D;

            return voice;
        }
Exemplo n.º 31
0
 IMySourceVoice IMyAudio.PlaySound(MyStringId cueId, IMy3DSoundEmitter source, MySoundDimensions type, bool skipIntro, bool skipToEnd)
 {
     return(PlaySound(cueId, source, type, skipIntro, skipToEnd));
 }
Exemplo n.º 32
0
        private static void Update3DCuePosition(IMy3DSoundEmitter source)
        {
            //// Occlusions are disabled
            //if (!MyFakes.OPTIMIZATION_FOR_300_SMALLSHIPS)
            //{
            //    CalculateOcclusion(cue, position);
            //}

            MyObjectBuilder_CueDefinition cue = m_cueBank.GetCue(source.CueEnum);
            m_helperEmitter.UpdateValues(source.SourcePosition, source.DirForward, source.DirUp, source.Velocity, cue, m_deviceDetails.OutputFormat.Channels);
            m_x3dAudio.Apply3D(source.Sound.Voice, m_listener, m_helperEmitter, cue.MaxDistance, source.Sound.FrequencyRatio);
        }
Exemplo n.º 33
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.º 34
0
        IMySourceVoice IMyAudio.GetSound(MyCueId cueId, IMy3DSoundEmitter source, MySoundDimensions type)
        {
            int waveNumber;

            return(GetSound(cueId, out waveNumber, source, type));
        }
Exemplo n.º 35
0
 IMySourceVoice IMyAudio.GetSound(MyStringId cueId, IMy3DSoundEmitter source, MySoundDimensions type)
 {
     return(GetSound(cueId, source, type));
 }
Exemplo n.º 36
0
 bool IMyAudio.SourceIsCloseEnoughToPlaySound(IMy3DSoundEmitter source, MyStringId cueEnum)
 {
     return(false);
 }
Exemplo n.º 37
0
 private void Add3DCueToUpdateList(IMy3DSoundEmitter source)
 {
     if(!m_3Dsounds.Contains(source))
         m_3Dsounds.Add(source);
 }
Exemplo n.º 38
0
 object IMyAudio.CalculateDspSettingsDebug(IMy3DSoundEmitter source) { return null; }
Exemplo n.º 39
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.º 40
0
 IMySourceVoice IMyAudio.GetSound(MyCueId cue, IMy3DSoundEmitter source, MySoundDimensions type) { return null; }
Exemplo n.º 41
0
        internal MySourceVoice PlaySound(MyCueId cueId, IMy3DSoundEmitter source = null, MySoundDimensions type = MySoundDimensions.D2, bool skipIntro = false, bool skipToEnd = false)
        {
			int waveNumber = -1;
			var sound = GetSound(cueId, out waveNumber, source, type);
			if(source != null)
				source.LastPlayedWaveNumber = -1;
			if (sound != null)
			{
                sound.Start(skipIntro, skipToEnd);
				if (source != null)
					source.LastPlayedWaveNumber = waveNumber;
			}
            return sound;
        }
Exemplo n.º 42
0
 IMySourceVoice IMyAudio.GetSound(IMy3DSoundEmitter source, int sampleRate, int channels, MySoundDimensions dimension) { return null; }
Exemplo n.º 43
0
 IMySourceVoice IMyAudio.PlaySound(MyCueId cueId, IMy3DSoundEmitter source, MySoundDimensions type, bool skipIntro, bool skipToEnd)
 {
     return PlaySound(cueId, source, type, skipIntro, skipToEnd);
 }
Exemplo n.º 44
0
 object IMyAudio.CalculateDspSettingsDebug(IMy3DSoundEmitter source)
 {
     return(null);
 }
Exemplo n.º 45
0
        IMySourceVoice IMyAudio.GetSound(IMy3DSoundEmitter source, int sampleRate, int channels, MySoundDimensions dimension)
        {
            if (!m_canPlay)
                return null;

            var waveFormat = new WaveFormat(sampleRate, channels);
            source.SourceChannels = channels;
            var sourceVoice = new MySourceVoice(m_audioEngine, waveFormat);

            float volume = source.CustomVolume.HasValue ? source.CustomVolume.Value : 1;
            float maxDistance = source.CustomMaxDistance.HasValue ? source.CustomMaxDistance.Value : 0;

            sourceVoice.SetVolume(volume);

            if (dimension == MySoundDimensions.D3)
            {
                m_helperEmitter.UpdateValuesOmni(source.SourcePosition, source.Velocity, maxDistance, m_deviceDetails.OutputFormat.Channels, MyCurveType.Linear);
                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);
                Update3DCuesState();
                Add3DCueToUpdateList(source);

                ++m_soundInstancesTotal3D;
            }

            return sourceVoice;
        }
Exemplo n.º 46
0
 private static void Add3DCueToUpdateList(IMy3DSoundEmitter source, MySoundCuesEnum cueEnum)
 {
     m_3Dsounds.Add(source);
     MyHudEntityParams hudEntityParams = new MyHudEntityParams()
     {
         FlagsEnum = MyHudIndicatorFlagsEnum.SHOW_ALL,
         Text = new StringBuilder(cueEnum.ToString()),
     };
     if (MyFakes.DEBUG_DRAW_AUDIO)
         MyHud.LocationMarkers.RegisterMarker(m_3Dsounds[m_3Dsounds.Count - 1].Entity, hudEntityParams);
 }