Represnts audio emitter, the entity that emit sound in physical world.
            /// <summary>
            /// 
            /// </summary>
            /// <param name="instance"></param>
            /// <param name="position"></param>
            /// <param name="soundPath"></param>
            public SoundStage( SfxInstance instance, Vector3 position, float radius, string soundPath, bool looped, bool local )
                : base(instance)
            {
                var sound	=	instance.sfxSystem.LoadSound( soundPath );

                if (sound==null) {
                    return;
                }

                emitter	=	SfxInstance.sw.AllocEmitter();
                emitter.Position		=	position;
                emitter.DistanceScale	=	radius;
                emitter.DopplerScale	=	1;
                emitter.VolumeCurve		=	null;
                emitter.LocalSound		=	local;

                emitter.PlaySound( sound, looped ? PlayOptions.Looped : PlayOptions.None );
            }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="listener"></param>
        /// <param name="emitter"></param>
        public void Apply3D(AudioListener listener, AudioEmitter emitter, int operationSet)
        {
            // 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, operationSet);

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

            // Apply Pitch settings (from doppler) ...
            _voice.SetFrequencyRatio(dspSettings.DopplerFactor, operationSet);
        }
Ejemplo n.º 3
0
		/// <summary>
		/// 
		/// </summary>
		/// <returns>True if the emitter is successfully found and removed; otherwise, false</returns>
		public bool FreeEmitter ( AudioEmitter emitter )
		{
			emitter.StopSound(true);
			return emitters.Remove(emitter);
		}
Ejemplo n.º 4
0
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public AudioEmitter AllocEmitter ()
		{
			var emitter = new AudioEmitter();
			emitters.Add(emitter);
			return emitter;
		}
Ejemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <returns>True if the emitter is successfully found and removed; otherwise, false</returns>
 public bool FreeEmitter(AudioEmitter emitter)
 {
     emitter.StopSound(true);
     return(emitters.Remove(emitter));
 }
Ejemplo n.º 6
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="listener"></param>
		/// <param name="emitter"></param>
		public void Apply3D (AudioListener listener, AudioEmitter emitter, int operationSet)
        {
            // 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, operationSet);

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

            // Apply Pitch settings (from doppler) ...
            _voice.SetFrequencyRatio(dspSettings.DopplerFactor, operationSet);
        }
Ejemplo n.º 7
0
		//public void Apply2D ( int operationSet )
		//{
		//	_voice.SetFrequencyRatio(dspSettings.DopplerFactor, operationSet);
		//}



		/// <summary>
		/// 
		/// </summary>
		/// <param name="listeners"></param>
		/// <param name="emitter"></param>
		public void Apply3D (AudioListener[] listeners,AudioEmitter emitter, int operationSet)
		{
            foreach ( var l in listeners )
                Apply3D(l, emitter, operationSet);            
		}