Beispiel #1
0
        public void CanCreateMasteringVoiceWithSampleRate()
        {
            XAudio2 obj   = XAudio2.Create();
            var     voice = obj.CreateMasteringVoice(2, 48000);

            Assert.IsNotNull(voice);
        }
Beispiel #2
0
        public void CanCreateMasteringVoiceWithChannelCount()
        {
            XAudio2 obj   = XAudio2.Create();
            var     voice = obj.CreateMasteringVoice(2);

            Assert.IsNotNull(voice);
        }
        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);
        }
Beispiel #4
0
        public void CannotCreateMasteringVoiceWithBadDeviceId()
        {
            XAudio2 obj = XAudio2.Create();

            var id = "Not A Valid Device Id";

            Assert.ThrowsException <COMException>(() => obj.CreateMasteringVoice(2, 48000, id));
        }
        public void CanGetInputSampleRate()
        {
            XAudio2 obj     = XAudio2.Create();
            var     voice   = obj.CreateMasteringVoice(2, 44100);
            var     details = voice.GetVoiceDetails();

            Assert.AreEqual(44100U, details.InputSampleRate);
        }
Beispiel #6
0
        public void CanGetVoiceDetails()
        {
            XAudio2 obj     = XAudio2.Create();
            var     voice   = obj.CreateMasteringVoice();
            var     details = voice.GetVoiceDetails();

            Assert.IsNotNull(details);
        }
        public void CanStopVoice()
        {
            XAudio2 obj    = XAudio2.Create();
            var     master = obj.CreateMasteringVoice();
            var     voice  = obj.CreateSourceVoice();

            voice.Stop();
        }
Beispiel #8
0
        public void CanCreateSourceVoice()
        {
            XAudio2 obj    = XAudio2.Create();
            var     master = obj.CreateMasteringVoice();
            var     voice  = obj.CreateSourceVoice();

            Assert.IsNotNull(voice);
        }
        public void CanGetCreationFlags()
        {
            XAudio2 obj     = XAudio2.Create();
            var     voice   = obj.CreateMasteringVoice();
            var     details = voice.GetVoiceDetails();

            Assert.AreEqual(0U, details.CreationFlags);
        }
Beispiel #10
0
        public void CanGetVolume()
        {
            XAudio2 obj    = XAudio2.Create();
            var     voice  = obj.CreateMasteringVoice();
            var     volume = voice.Volume;

            Assert.AreEqual(1.0f, volume);
        }
        public void CanGetInputChannels()
        {
            XAudio2 obj     = XAudio2.Create();
            var     voice   = obj.CreateMasteringVoice(2);
            var     details = voice.GetVoiceDetails();

            Assert.AreEqual(2U, details.InputChannels);
        }
Beispiel #12
0
        public void CanCreateMasteringVoiceWithDeviceId()
        {
            XAudio2 obj = XAudio2.Create();

            var id    = MediaDevice.GetDefaultAudioRenderId(AudioDeviceRole.Default);
            var voice = obj.CreateMasteringVoice(2, 48000, id);

            Assert.IsNotNull(voice);
        }
Beispiel #13
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;
        }
        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);
        }
        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);
        }
Beispiel #17
0
        public void CannotCreateMasteringVoiceWithBadChannelCount()
        {
            XAudio2 obj = XAudio2.Create();

            Assert.ThrowsException <System.Exception>(() => obj.CreateMasteringVoice(0xffffffff));
        }
Beispiel #18
0
        public void CannotCreateMasteringVoiceWithBadSampleRate()
        {
            XAudio2 obj = XAudio2.Create();

            Assert.ThrowsException <System.Exception>(() => obj.CreateMasteringVoice(2, 99));
        }