PageRenderTime 61ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/NAudio/Wave/WaveInputs/WasapiLoopbackCapture.cs

http://naudio.codeplex.com
C# | 58 lines | 32 code | 5 blank | 21 comment | 0 complexity | 35b9e026dce386cbf048418a7628baf2 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using NAudio.CoreAudioApi;
  5. namespace NAudio.Wave
  6. {
  7. /// <summary>
  8. /// WASAPI Loopback Capture
  9. /// based on a contribution from "Pygmy" - http://naudio.codeplex.com/discussions/203605
  10. /// </summary>
  11. public class WasapiLoopbackCapture : WasapiCapture
  12. {
  13. /// <summary>
  14. /// Initialises a new instance of the WASAPI capture class
  15. /// </summary>
  16. public WasapiLoopbackCapture() :
  17. this(GetDefaultLoopbackCaptureDevice())
  18. {
  19. }
  20. /// <summary>
  21. /// Initialises a new instance of the WASAPI capture class
  22. /// </summary>
  23. /// <param name="captureDevice">Capture device to use</param>
  24. public WasapiLoopbackCapture(MMDevice captureDevice) :
  25. base(captureDevice)
  26. {
  27. }
  28. /// <summary>
  29. /// Gets the default audio loopback capture device
  30. /// </summary>
  31. /// <returns>The default audio loopback capture device</returns>
  32. public static MMDevice GetDefaultLoopbackCaptureDevice()
  33. {
  34. MMDeviceEnumerator devices = new MMDeviceEnumerator();
  35. return devices.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
  36. }
  37. /// <summary>
  38. /// Recording wave format
  39. /// </summary>
  40. public override WaveFormat WaveFormat
  41. {
  42. get { return base.WaveFormat; }
  43. set { throw new InvalidOperationException("WaveFormat cannot be set for WASAPI Loopback Capture"); }
  44. }
  45. /// <summary>
  46. /// Specify loopback
  47. /// </summary>
  48. protected override AudioClientStreamFlags GetAudioClientStreamFlags()
  49. {
  50. return AudioClientStreamFlags.Loopback;
  51. }
  52. }
  53. }