Exemplo n.º 1
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.º 2
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.º 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);
                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;
        }