internal MySourceVoice GetVoice(MyCueId cueId, MyInMemoryWave wave, CuePart part = CuePart.Start)
        {
            MyWaveFormat myWaveFormat = new MyWaveFormat()
            {
                Encoding   = wave.WaveFormat.Encoding,
                Channels   = wave.WaveFormat.Channels,
                SampleRate = wave.WaveFormat.SampleRate,
                WaveFormat = wave.WaveFormat
            };

            MySourceVoice voice = m_voicePools[myWaveFormat].NextAvailable();

            if (voice == null)
            {
                return(null);
            }
            voice.Flush();
            voice.SubmitSourceBuffer(cueId, wave, part);

            if (m_applyReverb)
            {
                voice.Voice.SetEffectChain(m_effectDescriptor);
                voice.Voice.EnableEffect(0);
            }
            else
            {
                voice.Voice.SetEffectChain(null);
            }
            return(voice);
        }
Exemple #2
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);
            }
        }
 private void AddMusicCue(MyStringId musicTransition, MyStringId category, MyCueId cueId)
 {
     if (!m_musicTransitionCues.ContainsKey(musicTransition))
     {
         m_musicTransitionCues[musicTransition] = new Dictionary <MyStringId, MyCueId>(MyStringId.Comparer);
     }
     m_musicTransitionCues[musicTransition].Add(category, cueId);
 }
Exemple #4
0
        internal MySourceVoice PlaySound(MyCueId 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);
        }
        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);
        }
Exemple #6
0
        public void Flush()
        {
            m_cueId = new MyCueId(MyStringHash.NullOrEmpty);
            m_voice.Stop();
            m_voice.FlushSourceBuffers();
            DisposeWaves();

            m_isPlaying         = false;
            m_isPaused          = false;
            m_isLoopable        = false;
            m_currentDescriptor = null;
        }
 private void InitCues(ListReader <MySoundData> cues)
 {
     foreach (var cue in cues)
     {
         Debug.Assert(m_cues.Where((v) => v.Value.SubtypeId == cue.SubtypeId).Count() == 0, "Cue with this name was already added.");
         var id = new MyCueId(cue.SubtypeId);
         m_cues[id] = cue;
         if (cue.Category == MUSIC_CATEGORY)
         {
             AddMusicCue(cue.MusicTrack.TransitionCategory, cue.MusicTrack.MusicCategory, id);
         }
     }
 }
Exemple #8
0
 public void Flush()
 {
     m_cueId = new MyCueId(MyStringHash.NullOrEmpty);
     m_voice.Stop();
     m_voice.FlushSourceBuffers();
     for (int i = 0; i < m_loopBuffers.Length; i++)
     {
         m_loopBuffers[i] = null;
     }
     m_isPlaying         = false;
     m_isPaused          = false;
     m_isLoopable        = false;
     m_currentDescriptor = null;
 }
Exemple #9
0
        public bool IsLoopable(MyCueId cueId)
        {
            if (cueId.Hash == MyStringHash.NullOrEmpty || m_cueBank == null)
            {
                return(false);
            }
            MySoundData cueDefinition = m_cueBank.GetCue(cueId);

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

            return(cueDefinition.Loopable);
        }
Exemple #10
0
        private void AddMusicCue(MyStringId musicTransition, MyStringId category, MyCueId cueId)
        {
            if (!m_musicTransitionCues.ContainsKey(musicTransition))
            {
                m_musicTransitionCues[musicTransition] = new Dictionary <MyStringId, MyCueId>(MyStringId.Comparer);
            }
            if (m_musicTransitionCues[musicTransition].ContainsKey(category) == false)
            {
                m_musicTransitionCues[musicTransition].Add(category, cueId);
            }

            if (m_musicTracks.ContainsKey(category) == false)
            {
                m_musicTracks.Add(category, new List <MyCueId>());
            }
            m_musicTracks[category].Add(cueId);
        }
Exemple #11
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);
        }
Exemple #12
0
 IMySourceVoice IMyAudio.PlaySound(MyCueId cue, IMy3DSoundEmitter source, MySoundDimensions type, bool skipIntro, bool skipToEnd)
 {
     return(null);
 }
Exemple #13
0
 bool IMyAudio.IsLoopable(MyCueId cueId)
 {
     return(false);
 }
Exemple #14
0
 bool IMyAudio.SourceIsCloseEnoughToPlaySound(Vector3 position, MyCueId cueId, float?customMaxDistance)
 {
     return(false);
 }
Exemple #15
0
 IMySourceVoice IMyAudio.PlayMusicCue(MyCueId musicCue)
 {
     return(null);
 }
Exemple #16
0
        IMySourceVoice IMyAudio.GetSound(MyCueId cueId, IMy3DSoundEmitter source, MySoundDimensions type)
        {
            int waveNumber;

            return(GetSound(cueId, out waveNumber, source, type));
        }
Exemple #17
0
 MySoundData IMyAudio.GetCue(MyCueId cueId)
 {
     return(m_cueBank.GetCue(cueId));
 }
Exemple #18
0
 IMySourceVoice IMyAudio.PlayMusicCue(MyCueId musicCue, bool overrideMusicAllowed)
 {
     return(null);
 }
Exemple #19
0
 MySoundData IMyAudio.GetCue(MyCueId cueId)
 {
     return(m_canPlay ? m_cueBank.GetCue(cueId) : null);
 }
Exemple #20
0
 internal void SubmitSourceBuffer(MyCueId cueId, MyInMemoryWave wave, MyCueBank.CuePart part)
 {
     m_loopBuffers[(int)part] = wave;
     m_cueId       = cueId;
     m_isLoopable |= (wave.Buffer.LoopCount > 0);
 }
        internal MySourceVoice GetVoice(MyCueId cueId, out int waveNumber, MySoundDimensions type = MySoundDimensions.D2, int tryIgnoreWaveNumber = -1)
        {
            waveNumber = -1;
            MySoundData cue = GetCue(cueId);

            if ((cue == null) || (cue.Waves == null) || (cue.Waves.Count == 0))
            {
                return(null);
            }

            CuePart        part;
            MyInMemoryWave wave = GetRandomWave(cue, type, out waveNumber, out part, tryIgnoreWaveNumber);

            if (wave == null && type == MySoundDimensions.D2)
            {
                type = MySoundDimensions.D3;
                wave = GetRandomWave(cue, type, out waveNumber, out part, tryIgnoreWaveNumber);
            }
            if (wave == null)
            {
                return(null);
            }

            MySourceVoice voice = GetVoice(cueId, wave, part);

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

            if (cue.Loopable)
            {
                wave = GetWave(cue, type, waveNumber, CuePart.Loop);
                if (wave != null)
                {
                    Debug.Assert(voice.Owner.WaveFormat.Encoding == wave.WaveFormat.Encoding);
                    if (voice.Owner.WaveFormat.Encoding == wave.WaveFormat.Encoding)
                    {
                        voice.SubmitSourceBuffer(cueId, wave, CuePart.Loop);
                    }
                    else
                    {
                        MyLog.Default.WriteLine(string.Format("Inconsistent encodings: '{0}', got '{1}', expected '{2}', part = '{3}'", cueId, wave.WaveFormat.Encoding, voice.Owner.WaveFormat.Encoding, CuePart.Loop));
                    }
                }
                wave = GetWave(cue, type, waveNumber, CuePart.End);
                if (wave != null)
                {
                    Debug.Assert(voice.Owner.WaveFormat.Encoding == wave.WaveFormat.Encoding);
                    if (voice.Owner.WaveFormat.Encoding == wave.WaveFormat.Encoding)
                    {
                        voice.SubmitSourceBuffer(cueId, wave, CuePart.End);
                    }
                    else
                    {
                        MyLog.Default.WriteLine(string.Format("Inconsistent encodings: '{0}', got '{1}', expected '{2}', part = '{3}'", cueId, wave.WaveFormat.Encoding, voice.Owner.WaveFormat.Encoding, CuePart.End));
                    }
                }
            }

#if DEBUG
            if (voice.CueEnum.IsNull == false)
            {
                AddVoiceForDebug(voice);
            }
#endif

            return(voice);
        }
Exemple #22
0
 IMySourceVoice IMyAudio.GetSound(MyCueId cue, IMy3DSoundEmitter source, MySoundDimensions type)
 {
     return(null);
 }
Exemple #23
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);
        }
Exemple #24
0
 MySoundData IMyAudio.GetCue(MyCueId cue)
 {
     return(null);
 }
Exemple #25
0
 bool IMyAudio.SourceIsCloseEnoughToPlaySound(IMy3DSoundEmitter source, MyCueId cueId)
 {
     return(false);
 }