Example #1
0
 /// <summary>
 /// Initializes the engine callback.
 /// </summary>
 private void InitializeEngineCallback()
 {
     //register an object for receiving engine callbacks
     if (_engineCallback == null)
     {
         _engineCallback = new XAudio2EngineCallback();
         RegisterForCallbacks(_engineCallback);
     }
 }
Example #2
0
        public void CanRegisterEngineCallback()
        {
            const int lengthInSeconds = 2;
            bool b0 = false, b1 = false;

            XAudio2EngineCallback engineCallback = new XAudio2EngineCallback();
            engineCallback.ProcessingPassStart += (s, e) =>
                b0 = true;
            engineCallback.ProcessingPassEnd += (s, e) =>
                b1 = true;

            _xaudio2.RegisterForCallbacks(engineCallback);

            using (var masteringVoice = _xaudio2.CreateMasteringVoice())
            using (var sourceVoice = _xaudio2.CreateSourceVoice(_source.WaveFormat))
            {
                byte[] rawBuffer = new byte[_source.WaveFormat.BytesPerSecond * lengthInSeconds];
                int read = _source.Read(rawBuffer, 0, rawBuffer.Length);

                var buffer = new XAudio2Buffer(read);
                using (var stream = buffer.GetStream())
                {
                    stream.Write(rawBuffer, 0, read);
                }

                sourceVoice.SubmitSourceBuffer(buffer);
                sourceVoice.Start();

                Thread.Sleep((lengthInSeconds * 1000 + 500) / 2);

                Assert.IsTrue(b0 || b1);

                Console.WriteLine("Unregistered");
                _xaudio2.UnregisterForCallbacks(engineCallback);
                b0 = b1 = false;

                Thread.Sleep((lengthInSeconds * 1000 + 500) / 4);

                Assert.IsFalse(b0 && b1);

                Console.WriteLine("Register");
                _xaudio2.RegisterForCallbacks(engineCallback);

                Thread.Sleep((lengthInSeconds * 1000 + 500) / 4);

                Assert.IsTrue(b0 || b1);
            }

            _xaudio2.UnregisterForCallbacks(engineCallback);
        }
Example #3
0
 /// <summary>
 /// Initializes the engine callback.
 /// </summary>
 private void InitializeEngineCallback()
 {
     //register an object for receiving engine callbacks
     if (_engineCallback == null)
     {
         _engineCallback = new XAudio2EngineCallback();
         RegisterForCallbacks(_engineCallback);
     }
 }