public void OneBufferIsPlayed()
        {
            XAudio2 obj    = XAudio2.Create();
            var     master = obj.CreateMasteringVoice();
            var     voice  = obj.CreateSourceVoice();

            int buffersStarted     = 0;
            int buffersEnded       = 0;
            var processingStartEvt = new ManualResetEvent(false);

            voice.VoiceProcessingPassStart += (bytes) => voice.SubmitSourceBuffer(new XAudio2Buffer(bytes));

            voice.BufferStart += (startObj) =>
            {
                ++buffersStarted;
            };

            voice.BufferEnd += (endObj) =>
            {
                ++buffersEnded;
                processingStartEvt.Set();
            };

            voice.Start();
            processingStartEvt.WaitOne(30000); // allow 30 secs for the event to occur
            voice.Stop();

            Assert.AreEqual(1, buffersStarted);
            Assert.AreEqual(1, buffersEnded);
        }
        public void CanStopVoice()
        {
            XAudio2 obj    = XAudio2.Create();
            var     master = obj.CreateMasteringVoice();
            var     voice  = obj.CreateSourceVoice();

            voice.Stop();
        }
Exemplo n.º 3
0
        public void CanCreateSourceVoice()
        {
            XAudio2 obj    = XAudio2.Create();
            var     master = obj.CreateMasteringVoice();
            var     voice  = obj.CreateSourceVoice();

            Assert.IsNotNull(voice);
        }
        public void CanGetState()
        {
            XAudio2 obj    = XAudio2.Create();
            var     master = obj.CreateMasteringVoice();
            var     voice  = obj.CreateSourceVoice();
            var     state  = voice.GetState(VoiceStateFlags.None);

            Assert.IsNotNull(state);
            Assert.AreEqual(0U, state.BuffersQueued);
            Assert.AreEqual(0U, state.SamplesPlayed);
        }
Exemplo n.º 5
0
        private void InitializeAudio()
        {
            audio          = XAudio2.Create();
            masteringVoice = audio.CreateMasteringVoice();

            WaveFormat fmt = new WaveFormat {
                ChannelCount = 1
            };

            voice = audio.CreateSourceVoice(fmt);

            voice.VoiceProcessingPassStart += voice_VoiceProcessingPassStart;
            voice.VoiceProcessingPassEnd   += voice_VoiceProcessingPassEnd;
            voice.BufferStart += voice_BufferStart;
            voice.BufferEnd   += voice_BufferEnd;

            Volume.Value = voice.Volume * 100;
        }
        public void StartingVoiceFiresVoiceProcessingPassStart()
        {
            XAudio2 obj    = XAudio2.Create();
            var     master = obj.CreateMasteringVoice();
            var     voice  = obj.CreateSourceVoice();

            uint bytesRequested = 0;
            var  evt            = new ManualResetEvent(false);

            voice.VoiceProcessingPassStart += (bytes) =>
            {
                bytesRequested = bytes;
                evt.Set();
            };

            voice.Start();
            evt.WaitOne(10000); // allow 10 secs for the event to occur
            voice.Stop();

            Assert.AreNotEqual(0, bytesRequested);
        }
Exemplo n.º 7
0
        public void CannotCreateSourceVoiceWithoutMasteringVoice()
        {
            XAudio2 obj = XAudio2.Create();

            Assert.ThrowsException <System.Exception>(() => obj.CreateSourceVoice());
        }