1

Is there any way to play audio directly into a capture device in C#? In my project I will have to feed later on a virtual capture driver with audio so I can use it in other programs and play the wanted audio anywhere else, but Im not sure it is possible in C#, I tried to do this with NAudio (which is truly amazing):

    var enumerator = new MMDeviceEnumerator();
    MMDevice captureDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Multimedia);
    WasapiOut wasapiOut = new WasapiOut(captureDevice, AudioClientShareMode.Shared, false, 0);

But ultimately it just throws a COMException with the code 0x88890003 which translates to the error "The AUDCLNT_STREAMFLAGS_LOOPBACK flag is set but the endpoint device is a capture device, not a rendering device". So in the end is there any possible solution or do I have to turn to another language like C++?

Saliom
  • 109
  • 2
  • 10

1 Answers1

1

You cannot push audio to the device which generates audio on its own, "capture device".

Loopback mode means that you can have a copy of audio stream from a rendering device, but this does not work the other way.

The way things can work more or less as you assumed is when you have a special (and custom or third party, since no stock implementation of the kind exists) implementation of audio capture device, designed to generate audio supplied by external application such as your pushing the payload audio data via an API.

Switching to C++ will be of no help with this challenge.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Interesting, so the virtual audio capture driver has to be the one in charge of getting its own data If I got it right. Could you please guide me to some links where I could find more informations about the process of pushing payload data locally that could be read by others applications (like the custom driver in this scenario)? – Saliom May 31 '21 at 09:58
  • 1
    I am afraid the closest sample is generic audio device driver from DDK. One workaround some use is to use third party virtual audio software, which creates a pair of virtual devices, capture and playback. You would "play" into latter and the driver would duplicated the data on the former showing as coming from capture device. – Roman R. May 31 '21 at 11:00
  • Unfortunately I can't use third party drivers in this project, especially if they're not open source, I'll have to build one from scratch :D – Saliom Jun 01 '21 at 10:14