Beispiel #1
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);
        }
Beispiel #2
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);
        }