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

Cannot get DataFlow for new devices without full enumeration #139

Closed mikepelley closed 8 years ago

mikepelley commented 8 years ago

MMDevice does not have a DataFlow property, but I can enumerate Render and Capture separately and save DataFlow with the device. However, it seems I cannot get the DataFlow for new devices reported by MMNotificationClient.DeviceAdded without re-enumerating all devices.

Ideally MMDevice would have a DataFlow parameter, although perhaps I've misunderstood something. Perhaps there's a way to use QueryInterface to do this? It seems I'd need to leverage IMMEndpoint, but I don't think that's been wrapped by CSCore.

filoe commented 8 years ago

I've added the MMEndpoint class. Example usage:

var device = MMDeviceEnumerator.DefaultAudioEndpoint(DataFlow.Render, Role.Console);
Console.WriteLine(device.QueryInterface<MMEndpoint>().DataFlow);
Console.WriteLine(new MMEndpoint(device).DataFlow);
filoe commented 8 years ago

In addition, I've added the DataFlow property to the MMDevice class:

var device = MMDeviceEnumerator.DefaultAudioEndpoint(DataFlow.Render, Role.Console);
Console.WriteLine(device.DataFlow);
mikepelley commented 8 years ago

So fast! Thanks very much - this will be much cleaner. One note: while testing I noticed MMEndpoint.cs is missing from the CSCore project.

filoe commented 8 years ago

I've added the missing file to the project. See https://github.com/filoe/cscore/commit/298c3ea82067ecdcec7cb8946f1db27ea580ce86