/NAudio/Wave/WaveInputs/WasapiLoopbackCapture.cs
C# | 58 lines | 32 code | 5 blank | 21 comment | 0 complexity | 35b9e026dce386cbf048418a7628baf2 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
- using System;
- using System.Collections.Generic;
- using System.Text;
- using NAudio.CoreAudioApi;
-
- namespace NAudio.Wave
- {
- /// <summary>
- /// WASAPI Loopback Capture
- /// based on a contribution from "Pygmy" - http://naudio.codeplex.com/discussions/203605
- /// </summary>
- public class WasapiLoopbackCapture : WasapiCapture
- {
- /// <summary>
- /// Initialises a new instance of the WASAPI capture class
- /// </summary>
- public WasapiLoopbackCapture() :
- this(GetDefaultLoopbackCaptureDevice())
- {
- }
-
- /// <summary>
- /// Initialises a new instance of the WASAPI capture class
- /// </summary>
- /// <param name="captureDevice">Capture device to use</param>
- public WasapiLoopbackCapture(MMDevice captureDevice) :
- base(captureDevice)
- {
- }
-
- /// <summary>
- /// Gets the default audio loopback capture device
- /// </summary>
- /// <returns>The default audio loopback capture device</returns>
- public static MMDevice GetDefaultLoopbackCaptureDevice()
- {
- MMDeviceEnumerator devices = new MMDeviceEnumerator();
- return devices.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
- }
-
- /// <summary>
- /// Recording wave format
- /// </summary>
- public override WaveFormat WaveFormat
- {
- get { return base.WaveFormat; }
- set { throw new InvalidOperationException("WaveFormat cannot be set for WASAPI Loopback Capture"); }
- }
-
- /// <summary>
- /// Specify loopback
- /// </summary>
- protected override AudioClientStreamFlags GetAudioClientStreamFlags()
- {
- return AudioClientStreamFlags.Loopback;
- }
- }
- }