filoe / cscore

An advanced audio library, written in C#. Provides tons of features. From playing/recording audio to decoding/encoding audio streams/files to processing audio data in realtime (e.g. applying custom effects during playback, create visualizations,...). The possibilities are nearly unlimited.
Other
2.19k stars 454 forks source link

CoreAudioApiException when Initializing after using GetDefaultAudioEndpoint #203

Open christopher-bonitz opened 7 years ago

christopher-bonitz commented 7 years ago

I've debugged this as far as I can without pulling the source.

My goal is to record a small sound file using the microphone, inside an existing WPF application. There exists two active recording devices, one of them is both communication device and multimedia device. It is not chosen per default, so I'm trying to select it manually.

This is the (somewhat simple) code that should do the trick.

WasapiLoopbackCapture wasapiCapture = new WasapiLoopbackCapture();
wasapiCapture.Device = new MMDeviceEnumerator().GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications);
wasapiCapture.Initialize();

But alas, no success. Message: IAudioClient::Initialize caused an error: 0x88890003, "Unknown HRESULT".

Relevant stacktrace

   at CSCore.SoundIn.WasapiCapture.InitializeInternal()
   at CSCore.SoundIn.WasapiCapture.Initialize()

Bonus info: The device property of WasapiLoopbackCapture is set correctly, it is the initialization that seems to have a problem here.

I've taken a peak at the source, no dice I'm afraid.

christopher-bonitz commented 7 years ago

Darn it.

Figured out what went wrong, I built my code from the example in cscore/Samples/RecordToWma/Program.cs This uses the WasapiLoopbackCapture, but in my case that didn't work.

Don't think this is a bug then, but a clarification in the sample would be nice. :)

filoe commented 7 years ago

Glad to hear that. I ll take a look at the sample.

filoe commented 6 years ago

I'm sorry for coming back to this so late. What should be clarified?