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.17k stars 450 forks source link

XAudio 2.8 missing GetDeviceCount and GetDeviceDetails with proposed solution #19

Closed avandun closed 8 years ago

avandun commented 8 years ago

For XAudio 2.8 the functions GetDeviceCount and GetDeviceDetails are not available anymore. This is also in the CSCore lib. I have checked for other solutions to query the devices but haven't found one in the lib. A solution is proposed here: http://blogs.msdn.com/b/chuckw/archive/2012/04/02/xaudio2-and-windows-8-consumer-preview.aspx It's a pity that my C++ skill are too rusty to fix it myself. This would enhance the CScore lib and make it possible to query the devices in 2.8 version. Hope to see it soon.

filoe commented 8 years ago

XAudio 2.8 uses the deviceid of an mmdevice. Use the MMDeviceEnumerator to enumerate devices.

avandun commented 8 years ago

Hi, the devices I have are: devices

and this is the code:

                List<MMDevice> _devices = new List<MMDevice>();
                using (var mmdeviceEnumerator = new MMDeviceEnumerator())
                {
                    using (
                        var mmdeviceCollection = mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
                    {
                        foreach (var device in mmdeviceCollection)
                        {
                            _devices.Add(device);
                        }
                    }
                }

                using (var xaudio2 = XAudio2.CreateXAudio2())
                using (var masteringVoice = xaudio2.CreateMasteringVoice(0 ,0,_devices[0].DeviceID))

this results in an exception although the device exists and has a com handler. exception

so what's the mistake I made ?

avandun commented 8 years ago

Maybe a hint which can help in finding the bug. bug addition

filoe commented 8 years ago

I am currently not able to take a look at the code, but which version of XAudio causes this bug. Note that XAudio2.7 (on Windows XP, Vista, 7) uses the an index instead of the MMDeviceID. For XAudio2_7 you have to use the XAudio2_7.GetDeviceCount() Method an the GetDeviceDetails Method instead of the MMDeviceModel.

filoe commented 8 years ago

Should be fixed with the provided example.