Exemplo n.º 1
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();
                    }
                }
            }
        }
Exemplo n.º 2
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 = new StreamingSourceVoice(_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;
        }
Exemplo n.º 3
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.");
            }
        }