Esempio n. 1
0
        private async Task Activate()
        {
            var icbh = new ActivateAudioInterfaceCompletionHandler(
                ac2 =>
            {
                if (this.audioClientProperties != null)
                {
                    IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(this.audioClientProperties.Value));
                    Marshal.StructureToPtr(this.audioClientProperties.Value, p, false);
                    ac2.SetClientProperties(p);
                    Marshal.FreeHGlobal(p);
                    // TODO: consider whether we can marshal this without the need for AllocHGlobal
                }

                /*var wfx = new WaveFormat(44100, 16, 2);
                 * int hr = ac2.Initialize(AudioClientShareMode.Shared,
                 *         AudioClientStreamFlags.EventCallback | AudioClientStreamFlags.NoPersist,
                 *         10000000, 0, wfx, IntPtr.Zero);*/
            });
            var IID_IAudioClient2 = new Guid("726778CD-F60A-4eda-82DE-E47610CD78AA");
            IActivateAudioInterfaceAsyncOperation activationOperation;

            NativeMethods.ActivateAudioInterfaceAsync(device, IID_IAudioClient2, IntPtr.Zero, icbh, out activationOperation);
            var audioClient2 = await icbh;

            this.audioClient = new AudioClient((IAudioClient2)audioClient2);
        }
Esempio n. 2
0
 private async Task Activate()
 {
     var icbh = new ActivateAudioInterfaceCompletionHandler(
         ac2 =>
             {
                 /*var wfx = new WaveFormat(44100, 16, 2);
             int hr = ac2.Initialize(AudioClientShareMode.Shared,
                            AudioClientStreamFlags.EventCallback | AudioClientStreamFlags.NoPersist,
                            10000000, 0, wfx, IntPtr.Zero);*/
             });
     var IID_IAudioClient2 = new Guid("726778CD-F60A-4eda-82DE-E47610CD78AA");
     IActivateAudioInterfaceAsyncOperation activationOperation;
     NativeMethods.ActivateAudioInterfaceAsync(device, IID_IAudioClient2, IntPtr.Zero, icbh, out activationOperation);
     var audioClient2 = await icbh;
     this.audioClient = new AudioClient((IAudioClient) audioClient2);
 }
Esempio n. 3
0
        private async Task Activate()
        {
            var icbh = new ActivateAudioInterfaceCompletionHandler(
                ac2 =>
            {
                /*var wfx = new WaveFormat(44100, 16, 2);
                 * int hr = ac2.Initialize(AudioClientShareMode.Shared,
                 *         AudioClientStreamFlags.EventCallback | AudioClientStreamFlags.NoPersist,
                 *         10000000, 0, wfx, IntPtr.Zero);*/
            });
            var IID_IAudioClient2 = new Guid("726778CD-F60A-4eda-82DE-E47610CD78AA");
            IActivateAudioInterfaceAsyncOperation activationOperation;

            NativeMethods.ActivateAudioInterfaceAsync(device, IID_IAudioClient2, IntPtr.Zero, icbh, out activationOperation);
            var audioClient2 = await icbh;

            this.audioClient = new AudioClient((IAudioClient)audioClient2);
        }
Esempio n. 4
0
        /// <summary>
        /// Start Recording
        /// </summary>
        public async void StartRecording()
        {
            stop = false;

            var icbh = new ActivateAudioInterfaceCompletionHandler(ac2 => InitializeCaptureDevice((IAudioClient)ac2));
            
            IActivateAudioInterfaceAsyncOperation activationOperation;
            // must be called on UI thread
            NativeMethods.ActivateAudioInterfaceAsync(device, IID_IAudioClient2, IntPtr.Zero, icbh, out activationOperation);
            var audioClient2 = await icbh;
            await Task.Run(() => DoRecording(new AudioClient((IAudioClient)audioClient2)));
            
            Debug.WriteLine("Recording...");
        }
Esempio n. 5
0
        private async Task Activate()
        {
            var icbh = new ActivateAudioInterfaceCompletionHandler(
                ac2 =>
                {
                    if (this.audioClientProperties != null)
                    {
                        IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(this.audioClientProperties.Value));
                        Marshal.StructureToPtr(this.audioClientProperties.Value, p, false);
                        ac2.SetClientProperties(p);
                        // TODO: consider whether we can marshal this without the need for AllocHGlobal
                    }

                    /*var wfx = new WaveFormat(44100, 16, 2);
                int hr = ac2.Initialize(AudioClientShareMode.Shared,
                               AudioClientStreamFlags.EventCallback | AudioClientStreamFlags.NoPersist,
                               10000000, 0, wfx, IntPtr.Zero);*/
                });
            var IID_IAudioClient2 = new Guid("726778CD-F60A-4eda-82DE-E47610CD78AA");
            IActivateAudioInterfaceAsyncOperation activationOperation;
            NativeMethods.ActivateAudioInterfaceAsync(device, IID_IAudioClient2, IntPtr.Zero, icbh, out activationOperation);
            var audioClient2 = await icbh;
            this.audioClient = new AudioClient((IAudioClient)audioClient2);
        }