Audio source for local audio capture device (i.e. a microphone).

This audio source captures audio data obtained from a local audio capture device such as the microphone. The audio is captured using DirectSound through SlimDX.

For instructions on how to list capture devices, please see the AudioDeviceCollection documentation page.

Inheritance: IAudioSource, IDisposable
        /// <summary>
        ///   Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// 
        /// <param name="disposing"><c>true</c> to release both managed
        /// and unmanaged resources; <c>false</c> to release only unmanaged
        /// resources.</param>
        ///
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                // free managed resources
                if (clickCapture != null)
                {
                    clickCapture.Dispose();
                    clickCapture = null;
                }

                if (cursorCapture != null)
                {
                    cursorCapture.Dispose();
                    cursorCapture = null;
                }

                if (keyCapture != null)
                {
                    keyCapture.Dispose();
                    keyCapture = null;
                }

                if (audioDevice != null)
                {
                    audioDevice.Dispose();
                    audioDevice = null;
                }

                if (videoWriter != null)
                {
                    videoWriter.Dispose();
                    videoWriter = null;
                }
            }
        }
        /// <summary>
        ///   Starts recording. Only works if the player has
        ///   already been started and is grabbing frames.
        /// </summary>
        /// 
        public void StartRecording()
        {
            if (IsRecording || !IsPlaying) return;

            Rectangle area = CaptureRegion;
            string fileName = newFileName();

            int height = area.Height;
            int width = area.Width;
            int framerate = 1000 / screenStream.FrameInterval;
            int videoBitRate = 10 * 1000 * 1000;
            int audioBitRate = 320 * 1000;

            OutputPath = Path.Combine(main.CurrentDirectory, fileName);
            RecordingStartTime = DateTime.MinValue;
            videoWriter = new VideoFileWriter();

            if (CaptureAudioDevice != null)
            {
                audioDevice = new AudioCaptureDevice(CaptureAudioDevice.Guid);
                audioDevice.Format = SampleFormat.Format16Bit;
                audioDevice.SampleRate = Settings.Default.SampleRate;
                audioDevice.DesiredFrameSize = 4096;
                audioDevice.NewFrame += audioDevice_NewFrame;
                audioDevice.Start();

                videoWriter.Open(OutputPath, width, height, framerate, VideoCodec.H264, videoBitRate,
                    AudioCodec.MP3, audioBitRate, audioDevice.SampleRate, 1);
            }
            else
            {
                videoWriter.Open(OutputPath, width, height, framerate, VideoCodec.H264, videoBitRate);
            }

            HasRecorded = false;
            IsRecording = true;
        }
        /// <summary>
        ///   Stops recording.
        /// </summary>
        /// 
        public void StopRecording()
        {
            if (!IsRecording) return;

            lock (syncObj)
            {
                if (videoWriter != null)
                {
                    videoWriter.Close();
                    videoWriter.Dispose();
                    videoWriter = null;
                }

                if (audioDevice != null)
                {
                    audioDevice.Stop();
                    audioDevice.Dispose();
                    audioDevice = null;
                }

                IsRecording = false;
                HasRecorded = true;
            }
        }
        /// <summary>
        ///   Starts recording. Only works if the player has
        ///   already been started and is grabbing frames.
        /// </summary>
        /// 
        public void StartRecording()
        {
            if (IsRecording || !IsPlaying) 
                return;

            Rectangle area = CaptureRegion;
            string fileName = newFileName();

            int height = area.Height;
            int width = area.Width;
            int framerate = 1000 / screenStream.FrameInterval;
            int videoBitRate = 1200 * 1000;
            int audioBitRate = 320 * 1000;

            OutputPath = Path.Combine(main.CurrentDirectory, fileName);
            RecordingStartTime = DateTime.MinValue;
            videoWriter = new VideoFileWriter();

            // Create audio devices which have been checked
            var audioDevices = new List<AudioCaptureDevice>();
            foreach (var audioViewModel in AudioCaptureDevices)
            {
                if (!audioViewModel.Checked) 
                    continue;

                var device = new AudioCaptureDevice(audioViewModel.DeviceInfo);
                device.AudioSourceError += device_AudioSourceError;
                device.Format = SampleFormat.Format16Bit;
                device.SampleRate = Settings.Default.SampleRate;
                device.DesiredFrameSize = 2 * 4098;
                device.Start();

                audioDevices.Add(device);
            }

            if (audioDevices.Count > 0) // Check if we need to record audio
            {
                audioDevice = new AudioSourceMixer(audioDevices);
                audioDevice.AudioSourceError += device_AudioSourceError;
                audioDevice.NewFrame += audioDevice_NewFrame;
                audioDevice.Start();

                videoWriter.Open(OutputPath, width, height, framerate, VideoCodec.H264, videoBitRate,
                    AudioCodec.MP3, audioBitRate, audioDevice.SampleRate, audioDevice.Channels);
            }
            else
            {
                videoWriter.Open(OutputPath, width, height, framerate, VideoCodec.H264, videoBitRate);
            }

            HasRecorded = false;
            IsRecording = true;
        }