Example #1
0
        static public SharpDX.X3DAudio.Listener ToListener(this Audio.AudioListener listener)
        {
            // Pulling out Vector properties for efficiency.
            var pos     = listener.Position;
            var vel     = listener.Velocity;
            var forward = listener.Forward;
            var up      = listener.Up;

            // From MSDN:
            //  X3DAudio uses a left-handed Cartesian coordinate system,
            //  with values on the x-axis increasing from left to right, on the y-axis from bottom to top,
            //  and on the z-axis from near to far.
            //  Azimuths are measured clockwise from a given reference direction.
            //
            // From MSDN:
            //  The XNA Framework uses a right-handed coordinate system,
            //  with the positive z-axis pointing toward the observer when the positive x-axis is pointing to the right,
            //  and the positive y-axis is pointing up.
            //
            // Programmer Notes:
            //  According to this description the z-axis (forward vector) is inverted between these two coordinate systems.
            //  Therefore, we need to negate the z component of any position/velocity values, and negate any forward vectors.

            forward *= -1.0f;
            pos.Z   *= -1.0f;
            vel.Z   *= -1.0f;

            return(new SharpDX.X3DAudio.Listener()
            {
                Position = Convert(pos),
                Velocity = Convert(vel),
                OrientFront = Convert(forward),
                OrientTop = Convert(up),
            });
        }
Example #2
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		protected override void Update ( GameTime gameTime )
		{
			var ds = GetService<DebugStrings>();

			var dr = GetService<DebugRender>();
			var cam = GetService<Camera>();

			dr.View			=	cam.GetViewMatrix( StereoEye.Mono );
			dr.Projection	=	cam.GetProjectionMatrix( StereoEye.Mono );;
			dr.DrawGrid(20);
			dr.DrawRing( Vector3.Zero, 15, Color.Orange, 64 );

			angle	+= 0.1f;

			if (emitter!=null) {
				emitter.DopplerScale	=	1;
				emitter.Position		=	GetPosition(angle);
				emitter.Velocity		=	(GetPosition(angle) - GetPosition(angle-0.1f)) * (1/gameTime.ElapsedSec);
				emitter.DistanceScale	=	2;
				//emitter.VolumeCurve		=	Enumerable.Range(0, 11).Select( i => new CurvePoint{ Distance = i, DspSetting = (float)Math.Pow((10-i)/10.0f,2) } ).ToArray();
				dr.DrawPoint( GetPosition(angle), 0.5f, Color.Yellow );
				dr.DrawRing( GetPosition(angle), 10, Color.Orange, 64 );
			}

			//AudioDevice.SetupListener( cam.GetCameraMatrix( stereoEye ).TranslationVector, cam.GetCameraMatrix( stereoEye ).Forward, cam.GetCameraMatrix( stereoEye ).Up, cam.FreeCameraVelocity );*/
			listener	=	cam.Listener;

			if (soundInstance!=null) {
				soundInstance.Apply3D( listener, emitter );
			}

			base.Update(gameTime);

			ds.Add( Color.Orange, "FPS {0}", gameTime.Fps );
			ds.Add( "F1   - show developer console" );
			ds.Add( "F2   - toggle vsync" );
			ds.Add( "F5   - build content and reload textures" );
			ds.Add( "F12  - make screenshot" );
			ds.Add( "ESC  - exit" );
			ds.Add("");


			ds.Add("B - break glass");
			ds.Add("P - play 3D sound");
			ds.Add("O - pause/unpause 3D sound");
			ds.Add("I - stop");
			ds.Add("U - immediate stop");
			ds.Add(Color.Orange, "See Camera config for controls");
		}
Example #3
0
 /// <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);
 }
Example #4
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);
        }