Esempio n. 1
0
        public void CanPlayWithStreamingSourceVoice()
        {
            for (int i = 0; i < 20; i++)
            {
                using (var masteringVoice = _xaudio2.CreateMasteringVoice())
                    using (var source = GlobalTestConfig.TestWav2S())
                        using (var pool = new StreamingSourceVoiceListener())
                            using (var streamingSourceVoice = new StreamingSourceVoice(_xaudio2, source))
                            {
                                var stoppedEvent = new ManualResetEvent(false);
                                streamingSourceVoice.Stopped += (s, e) =>
                                                                stoppedEvent.Set();

                                streamingSourceVoice.Start();

                                pool.Add(streamingSourceVoice);

                                Debug.WriteLine("All queued.");

                                stoppedEvent.WaitOne();

                                pool.Remove(streamingSourceVoice);
                            }

                Debug.WriteLine("All removed.");
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = CodecFactory.SupportedFilesFilterEn;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                using (var source = CodecFactory.Instance.GetCodec(openFileDialog.FileName))
                {
                    using (var xaudio2 = XAudio2.CreateXAudio2())
                        using (var masteringVoice = xaudio2.CreateMasteringVoice())
                            //ALWAYS create at least one masteringVoice.
                            using (var streamingSourceVoice = new StreamingSourceVoice(xaudio2, source))
                            {
                                StreamingSourceVoiceListener.Default.Add(streamingSourceVoice);
                                //add the streamingSourceVoice to the default sourcevoicelistener which processes the data requests.
                                streamingSourceVoice.Start();

                                Console.WriteLine("Press any key to exit.");
                                Console.ReadKey();

                                StreamingSourceVoiceListener.Default.Remove(streamingSourceVoice);
                                streamingSourceVoice.Stop();
                            }
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Resumes the sound.
 /// </summary>
 public void Resume()
 {
     _sourceVoice.Start();
     _playbackState = PlaybackState.Playing;
     if (PlaybackChanged != null)
     {
         PlaybackChanged(this, EventArgs.Empty);
     }
 }
Esempio n. 4
0
        public void OpenFile(string filename)
        {
            Stop();

            Vector3 center = new Vector3(0);

            _waveSource           = CodecFactory.Instance.GetCodec(filename).ToMono();
            _masteringVoice       = _xaudio2.CreateMasteringVoice(XAudio2.DefaultChannels, XAudio2.DefaultSampleRate);
            _streamingSourceVoice = StreamingSourceVoice.Create(_xaudio2, _waveSource, 150);

            object      defaultDevice = _xaudio2.DefaultDevice;
            ChannelMask channelMask;

            if (_xaudio2.Version == XAudio2Version.XAudio2_7)
            {
                var xaudio27      = (XAudio2_7)_xaudio2;
                var deviceDetails = xaudio27.GetDeviceDetails((int)defaultDevice);
                channelMask          = deviceDetails.OutputFormat.ChannelMask;
                _destinationChannels = deviceDetails.OutputFormat.Channels;
            }
            else
            {
                channelMask          = _masteringVoice.ChannelMask;
                _destinationChannels = _masteringVoice.VoiceDetails.InputChannels;
            }
            _sourceChannels = _waveSource.WaveFormat.Channels;

            _x3daudio = new X3DAudioCore(channelMask);

            _listener = new Listener()
            {
                Position    = center,
                OrientFront = new Vector3(0, 0, 1),
                OrientTop   = new Vector3(0, 1, 0),
                Velocity    = new Vector3(0, 0, 0)
            };


            _emitter = new Emitter()
            {
                ChannelCount        = _sourceChannels,
                CurveDistanceScaler = float.MinValue,
                OrientFront         = new Vector3(0, 0, 1),
                OrientTop           = new Vector3(0, 1, 0),
                Position            = new Vector3(0, 0, 0),
                Velocity            = new Vector3(0, 0, 0)
            };


            StreamingSourceVoiceListener.Default.Add(_streamingSourceVoice);
            _streamingSourceVoice.Start();

            _isPlaying = true;
        }
Esempio n. 5
0
 public void Play()
 {
     if (_streamingSourceVoice == null)
     {
         _streamingSourceVoice = new StreamingSourceVoice(_xaudio2, _source);
         StreamingSourceVoiceListener.Default.Add(_streamingSourceVoice);
     }
     if (_playbackState == PlaybackState.Paused)
     {
         Resume();
     }
     if (_playbackState != PlaybackState.Playing)
     {
         _streamingSourceVoice.Start();
     }
     _playbackState = PlaybackState.Playing;
 }