Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="listener"></param>
        /// <param name="emitter"></param>
        public void Apply3D(AudioListener listener, AudioEmitter emitter)
        {
            // If we have no voice then nothing to do.
            if (_voice == null)
            {
                return;
            }

            // Convert from XNA Emitter to a SharpDX Emitter
            var e = emitter.ToEmitter();

            // Apply overall Doppler and distance scale :
            e.DopplerScaler       *= device.DopplerScale;
            e.CurveDistanceScaler *= device.DistanceScale;

            // Convert from XNA Listener to a SharpDX Listener
            var l = listener.ToListener();

            // Number of channels in the sound being played.
            // Not actually sure if XNA supported 3D attenuation of sterio sounds, but X3DAudio does.
            var srcChannelCount = 1;//_effect._format.Channels;

            // Number of output channels.
            var dstChannelCount = device.MasterVoice.VoiceDetails.InputChannelCount;

            var flags = CalculateFlags.Matrix | CalculateFlags.Doppler /*| CalculateFlags.Reverb | CalculateFlags.LpfDirect*/;

            // XNA supports distance attenuation and doppler.
            var dspSettings = device.Device3D.Calculate(l, e, flags, srcChannelCount, dstChannelCount);

            // Apply Volume settings (from distance attenuation) ...
            _voice.SetOutputMatrix(device.MasterVoice, srcChannelCount, dstChannelCount, dspSettings.MatrixCoefficients, 0);

            //	USE: VoiceFlags.UseFilter !!!
            //	_voice.SetFilterParameters( ... );

            // Apply Pitch settings (from doppler) ...
            _voice.SetFrequencyRatio(dspSettings.DopplerFactor);
        }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="listener"></param>
		/// <param name="emitter"></param>
		public void Apply3D (AudioListener listener, AudioEmitter emitter)
        {
            // If we have no voice then nothing to do.
            if (_voice == null)
                return;

            // Convert from XNA Emitter to a SharpDX Emitter
            var e = emitter.ToEmitter();

			// Apply overall Doppler and distance scale :
			e.DopplerScaler	*= device.DopplerScale;
			e.CurveDistanceScaler *= device.DistanceScale;

            // Convert from XNA Listener to a SharpDX Listener
            var l = listener.ToListener();                        
            
            // Number of channels in the sound being played.
            // Not actually sure if XNA supported 3D attenuation of sterio sounds, but X3DAudio does.
            var srcChannelCount = 1;//_effect._format.Channels;            

            // Number of output channels.
            var dstChannelCount = device.MasterVoice.VoiceDetails.InputChannelCount;

			var flags =  CalculateFlags.Matrix | CalculateFlags.Doppler /*| CalculateFlags.Reverb | CalculateFlags.LpfDirect*/;

            // XNA supports distance attenuation and doppler.            
            var dspSettings = device.Device3D.Calculate(l, e, flags, srcChannelCount, dstChannelCount);

            // Apply Volume settings (from distance attenuation) ...
            _voice.SetOutputMatrix(device.MasterVoice, srcChannelCount, dstChannelCount, dspSettings.MatrixCoefficients, 0);

			//	USE: VoiceFlags.UseFilter !!!
			//	_voice.SetFilterParameters( ... );

            // Apply Pitch settings (from doppler) ...
            _voice.SetFrequencyRatio(dspSettings.DopplerFactor);
        }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="listeners"></param>
		/// <param name="emitter"></param>
		public void Apply3D (AudioListener[] listeners,AudioEmitter emitter)
		{
            foreach ( var l in listeners )
                Apply3D(l, emitter);            
		}