Esempio n. 1
0
        /// <summary>
        /// Calculates DSP settings for the specified listener and emitter.
        /// </summary>
        /// <param name="listener">The listener.</param>
        /// <param name="emitter">The emitter.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="sourceChannelCount">The source channel count.</param>
        /// <param name="destinationChannelCount">The destination channel count.</param>
        /// <returns>DSP settings</returns>
        /// <msdn-id>ee419052</msdn-id>
        /// <unmanaged>void X3DAudioCalculate([In] const X3DAUDIOHANDLE* Instance,[In] const X3DAUDIO_LISTENER* pListener,[In] const X3DAUDIO_EMITTER* pEmitter,[In] X3DAudioCalculateFlags Flags,[In] void* pDSPSettings)</unmanaged>
        /// <unmanaged-short>X3DAudioCalculate</unmanaged-short>
        public DspSettings Calculate(Listener listener, Emitter emitter, CalculateFlags flags, int sourceChannelCount, int destinationChannelCount)
        {
            var settings = new DspSettings(sourceChannelCount, destinationChannelCount);

            Calculate(listener, emitter, flags, settings);
            return(settings);
        }
Esempio n. 2
0
        /// <summary>
        /// Calculates dsp settings for the specified listener and emitter.
        /// </summary>
        /// <param name="listener">The listener.</param>
        /// <param name="emitter">The emitter.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="sourceChannelCount">The source channel count.</param>
        /// <param name="destinationChannelCount">The destination channel count.</param>
        /// <returns>Dsp settings</returns>
        public DspSettings Calculate(Listener listener, Emitter emitter, CalculateFlags flags, int sourceChannelCount, int destinationChannelCount)
        {
            var settings = new DspSettings
            {
                SourceChannelCount = sourceChannelCount,
                DestinationChannelCount = destinationChannelCount
            };

            X3DAudioCalculate(ref handle, listener, emitter, flags, settings);

            return settings;
        }
Esempio n. 3
0
        internal void Apply3DImpl(AudioListener listener, AudioEmitter emitter)
        {
            //////////////////////////////////////////////////////////////
            // 1. First let's calculate the parameters to set to the voice
            var inputChannels = soundEffect.WaveFormat.Channels;
            var outputChannels = MasterVoice.VoiceDetails.InputChannelCount;

            if (inputChannels != 1 || outputChannels != 2)
                throw new AudioSystemInternalException("Error in Apply3DImpl only mono sounds are supposed to be localizable");

            var list = new Listener
                {
                    Position = listener.Position.ToSharpDX(), 
                    Velocity = listener.Velocity.ToSharpDX(),
                    OrientFront = listener.Forward.ToSharpDX(),
                    OrientTop = listener.Up.ToSharpDX()
                };
            var emit = new Emitter
                {
                    Position = emitter.Position.ToSharpDX(),
                    Velocity = emitter.Velocity.ToSharpDX(),
                    DopplerScaler = emitter.DopplerScale,
                    CurveDistanceScaler = emitter.DistanceScale,
                    ChannelRadius = 0f, // Multi-channels localizable sound are considered as source of multiple sounds coming from the same location.
                    ChannelCount = inputChannels
                };
            
            var dspSettings = new DspSettings(inputChannels, outputChannels);

            AudioEngine.X3DAudio.Calculate(list, emit, CalculateFlags.Matrix | CalculateFlags.LpfDirect, dspSettings);

            /////////////////////////////////////////////////////////////
            // 2. Now let's set the voice parameters to simulate a 3D voice.

            // 2.1 The Doppler effect due to the difference of speed between the emitter and listener
            ComputeDopplerFactor(listener, emitter);
            UpdatePitch();

            // 2.2 The channel attenuations due to the source localization.
            localizationChannelVolumes = new[] { dspSettings.MatrixCoefficients[0], dspSettings.MatrixCoefficients[1] };    // only mono sound can be localized so matrix should be 2*1
            UpdateStereoVolumes();
        }
Esempio n. 4
0
        /// <summary>
        /// Calculates DSP settings for the specified listener and emitter. See remarks.
        /// </summary>
        /// <param name="listener">The listener.</param>
        /// <param name="emitter">The emitter.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="settings">The settings.</param>
        /// <remarks>The source and destination channel count must be set on <see cref="DspSettings" /> before calling this method.</remarks>
        /// <msdn-id>ee419052</msdn-id>	
        /// <unmanaged>void X3DAudioCalculate([In] const X3DAUDIOHANDLE* Instance,[In] const X3DAUDIO_LISTENER* pListener,[In] const X3DAUDIO_EMITTER* pEmitter,[In] X3DAudioCalculateFlags Flags,[In] void* pDSPSettings)</unmanaged>	
        /// <unmanaged-short>X3DAudioCalculate</unmanaged-short>	
        public unsafe void Calculate(Listener listener, Emitter emitter, CalculateFlags flags, DspSettings settings)
        {
            if (settings == null) throw new ArgumentNullException("settings");

            DspSettings.__Native settingsNative;
            settingsNative.SrcChannelCount = settings.SourceChannelCount;
            settingsNative.DstChannelCount = settings.DestinationChannelCount;

            fixed (void* pMatrix = settings.MatrixCoefficients)
            fixed (void* pDelays = settings.DelayTimes)
            {
                settingsNative.MatrixCoefficientsPointer = (IntPtr)pMatrix;
                settingsNative.DelayTimesPointer = (IntPtr)pDelays;
                
                X3DAudioCalculate(ref handle, listener, emitter, flags, new IntPtr(&settingsNative));
            }

            settings.__MarshalFrom(ref settingsNative);
        }
Esempio n. 5
0
 /// <summary>
 /// Calculates DSP settings for the specified listener and emitter.
 /// </summary>
 /// <param name="listener">The listener.</param>
 /// <param name="emitter">The emitter.</param>
 /// <param name="flags">The flags.</param>
 /// <param name="sourceChannelCount">The source channel count.</param>
 /// <param name="destinationChannelCount">The destination channel count.</param>
 /// <returns>DSP settings</returns>
 /// <msdn-id>ee419052</msdn-id>	
 /// <unmanaged>void X3DAudioCalculate([In] const X3DAUDIOHANDLE* Instance,[In] const X3DAUDIO_LISTENER* pListener,[In] const X3DAUDIO_EMITTER* pEmitter,[In] X3DAudioCalculateFlags Flags,[In] void* pDSPSettings)</unmanaged>	
 /// <unmanaged-short>X3DAudioCalculate</unmanaged-short>	
 public DspSettings Calculate(Listener listener, Emitter emitter, CalculateFlags flags, int sourceChannelCount, int destinationChannelCount)
 {
     var settings = new DspSettings(sourceChannelCount, destinationChannelCount);
     Calculate(listener, emitter, flags, settings);
     return settings;
 }
Esempio n. 6
0
        /// <summary>
        /// Calculates DSP settings for the specified listener and emitter. See remarks.
        /// </summary>
        /// <param name="listener">The listener.</param>
        /// <param name="emitter">The emitter.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="settings">The settings.</param>
        /// <remarks>The source and destination channel count must be set on <see cref="DspSettings" /> before calling this method.</remarks>
        /// <msdn-id>ee419052</msdn-id>	
        /// <unmanaged>void X3DAudioCalculate([In] const X3DAUDIOHANDLE* Instance,[In] const X3DAUDIO_LISTENER* pListener,[In] const X3DAUDIO_EMITTER* pEmitter,[In] X3DAudioCalculateFlags Flags,[In] void* pDSPSettings)</unmanaged>	
        /// <unmanaged-short>X3DAudioCalculate</unmanaged-short>	
        public unsafe void Calculate(Listener listener, Emitter emitter, CalculateFlags flags, DspSettings settings)
        {
            if (settings == null) throw new ArgumentNullException("settings");

            DspSettings.__Native settingsNative;
            settingsNative.SrcChannelCount = settings.SourceChannelCount;
            settingsNative.DstChannelCount = settings.DestinationChannelCount;

            fixed (void* pMatrix = settings.MatrixCoefficients)
            fixed (void* pDelays = settings.DelayTimes)
            {
                settingsNative.MatrixCoefficientsPointer = (IntPtr)pMatrix;
                settingsNative.DelayTimesPointer = (IntPtr)pDelays;
                
                calculateDelegate(ref handle, listener, emitter, flags, new IntPtr(&settingsNative));
            }

            settings.__MarshalFrom(ref settingsNative);
        }
 public MyX3DAudio(WaveFormatExtensible format)
 {
     m_x3dAudio = new X3DAudio(format.ChannelMask);
     m_dsp = new DspSettings(1, format.Channels);
 }
Esempio n. 8
0
 public MyX3DAudio(AudioEngine engine)
 {
     m_x3dAudio = new X3DAudio(engine.FinalMixFormat.ChannelMask);
     m_dsp = new DspSettings(1, engine.FinalMixFormat.Channels);
 }