Пример #1
0
 public WaveManager()
 {
     xAudio = new XAudio2();
     var mastering = new MasteringVoice(xAudio);
     mastering.SetVolume(1, 0);
     xAudio.StartEngine();
 }
Пример #2
0
        internal static void InitializeSoundEffect()
        {
            try
            {
                if (Device == null)
                {
#if !WINRT && DEBUG
                    try
                    {
                        //Fails if the XAudio2 SDK is not installed
                        Device = new XAudio2(XAudio2Flags.DebugEngine, ProcessorSpecifier.DefaultProcessor);
                        Device.StartEngine();
                    }
                    catch
#endif
                    {
                        Device = new XAudio2(XAudio2Flags.None, ProcessorSpecifier.DefaultProcessor);
                        Device.StartEngine();
                    }
                }

                // Just use the default device.
#if WINRT
                string deviceId = null;
#else
                const int deviceId = 0;
#endif

                if (MasterVoice == null)
                {
                    // Let windows autodetect number of channels and sample rate.
                    MasterVoice = new MasteringVoice(Device, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate, deviceId);
                    MasterVoice.SetVolume(_masterVolume, 0);
                }

                // The autodetected value of MasterVoice.ChannelMask corresponds to the speaker layout.
#if WINRT
                Speakers = (Speakers)MasterVoice.ChannelMask;
#else
                var deviceDetails = Device.GetDeviceDetails(deviceId);
                Speakers = deviceDetails.OutputFormat.ChannelMask;
#endif
            }
            catch
            {
                // Release the device and null it as
                // we have no audio support.
                if (Device != null)
                {
                    Device.Dispose();
                    Device = null;
                }

                MasterVoice = null;
            }
        }
Пример #3
0
        public XAudio2Mixer()
        {
            _xAudio = new XAudio2();
            _xAudio.StartEngine();
            _masteringVoice = new MasteringVoice(_xAudio);
            _buffers = new XAudioBuffer[NumBuffers];

            for (var i = 0; i < NumBuffers; i++)
            {
                _buffers[i] = new XAudioBuffer(BufferSize);
            }
        }
Пример #4
0
		/// <summary>
		/// 
		/// </summary>
        public override void Initialize()
        {
            try
            {
                if (Device == null) {
                    Device = new XAudio2(XAudio2Flags.None, ProcessorSpecifier.DefaultProcessor);
                    Device.StartEngine();
                }

				var DeviceFormat = Device.GetDeviceDetails(0).OutputFormat;

                // Just use the default device.
                const int deviceId = 0;

                if (MasterVoice == null) {
                    // Let windows autodetect number of channels and sample rate.
                    MasterVoice = new MasteringVoice(Device, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate, deviceId);
                    MasterVoice.SetVolume(_masterVolume, 0);
                }

                // The autodetected value of MasterVoice.ChannelMask corresponds to the speaker layout.
                var deviceDetails = Device.GetDeviceDetails(deviceId);
                Speakers = deviceDetails.OutputFormat.ChannelMask;

				var dev3d = Device3D;

				Log.Debug("Audio devices :");
				for ( int devId = 0; devId < Device.DeviceCount; devId++ ) {
					var device = Device.GetDeviceDetails( devId );

					Log.Debug( "[{1}] {0}", device.DisplayName, devId );
					Log.Debug( "    role : {0}", device.Role );
					Log.Debug( "    id   : {0}", device.DeviceID );
				}
            }
            catch
            {
                // Release the device and null it as
                // we have no audio support.
                if (Device != null)
                {
                    Device.Dispose();
                    Device = null;
                }

                MasterVoice = null;
            }


			soundWorld	=	new SoundWorld(Game);
        }
        internal static void InitializeSoundEffect()
        {
            try
            {
                if (Device == null)
                {
                    {
                        Device = new XAudio2(XAudio2Flags.None, ProcessorSpecifier.DefaultProcessor);
                        Device.StartEngine();
                    }
                }

                // Just use the default device.
                //string deviceId = null;

                if (MasterVoice == null)
                {
                    // Let windows autodetect number of channels and sample rate.
                    MasterVoice = new MasteringVoice(Device, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate);
                }

                // The autodetected value of MasterVoice.ChannelMask corresponds to the speaker layout.
                //Speakers = (Speakers)MasterVoice.ChannelMask;
                Speakers = SharpDX.Multimedia.Speakers.Stereo;
            }
            catch
            {
                // Release the device and null it as
                // we have no audio support.
                if (Device != null)
                {
                    Device.Dispose();
                    Device = null;
                }

                MasterVoice = null;
            }
        }
Пример #6
0
        private void InitializeXAudio2()
        {
            // This is mandatory when using any of SharpDX.MediaFoundation classes
            MediaManager.Startup();

            // Starts The XAudio2 engine
            xaudio2 = new XAudio2();
            xaudio2.StartEngine();
            masteringVoice = new MasteringVoice(xaudio2);
        }
Пример #7
0
        public static void Main(string[] args)
        {
            xaudio2 = new XAudio2();
            xaudio2.StartEngine();
            var masteringVoice = new MasteringVoice(xaudio2);

            if (!string.IsNullOrEmpty(Properties.Settings.Default.BackgroundMusicPath) &&
                Directory.Exists(Properties.Settings.Default.BackgroundMusicPath))
            {
                var musicFiles = Directory.GetFiles(Properties.Settings.Default.BackgroundMusicPath, "*.wav");
                if(musicFiles.Length > 0)
                    backgroundPlayer = new TrackPlayer(xaudio2, musicFiles);
            }

            var listener = new UdpClient(10009);
            listener.BeginReceive(new AsyncCallback(ReceiveCallback), listener);

            effectManager = new EffectManager(xaudio2, 4, Properties.Settings.Default.FXPath);

            // Wait until its done
            int count = 1;
            while (true)
            {
                Thread.Sleep(10);

                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey();
                    if (key.Key == ConsoleKey.Escape)
                        break;

                    switch (key.Key)
                    {
                        case ConsoleKey.A:
                            effectManager.Play("Scream.wav");
                            break;
                        case ConsoleKey.B:
                            effectManager.Play("Violin screech.wav");
                            break;
                        case ConsoleKey.N:
                            if(backgroundPlayer != null)
                                backgroundPlayer.NextTrack();
                            break;
                        case ConsoleKey.V:
                            if (key.Modifiers.HasFlag(ConsoleModifiers.Shift))
                                backgroundVolume -= 0.1f;
                            else
                                backgroundVolume += 0.1f;

                            if (backgroundVolume < 0f)
                                backgroundVolume = 0f;
                            if (backgroundVolume > 1f)
                                backgroundVolume = 1f;
                            break;
                    }
                }

                var muteMusic = effectManager.AreAnyPlaying && autoMuteBackground ? 0.2f : 0f;
                if (backgroundPlayer != null)
                    backgroundPlayer.Volume = backgroundVolume - muteMusic;

                if (count % 50 == 0)
                {
                    Console.Write(".");
                    Console.Out.Flush();
                }

                Thread.Sleep(10);
                count++;
            }

            listener.Close();

            if (backgroundPlayer != null)
                backgroundPlayer.Stop();
            if (trackPlayer != null)
                trackPlayer.Stop();

            effectManager.Dispose();

            Thread.Sleep(500);

            masteringVoice.Dispose();
            xaudio2.StopEngine();
            xaudio2.Dispose();
        }
Пример #8
0
        static SoundEffect()
        {
            // This cannot fail.
            Device = new XAudio2();

            try
            {
                Device.StartEngine();

                // Let windows autodetect number of channels and sample rate.
                MasterVoice = new MasteringVoice(Device, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate);            
                MasterVoice.SetVolume(_masterVolume, 0);

                // The autodetected value of MasterVoice.ChannelMask corresponds to the speaker layout.
                Speakers = (Speakers)MasterVoice.ChannelMask;
            }
            catch
            {
                // Release the device and null it as
                // we have no audio support.
                Device.Dispose();
                Device = null;
                MasterVoice = null;
            }

        }