morphx666/CoreAudio

[Samples] Error running the samples

LiorBanai opened this issue · 7 comments

Hi,
There is an error when running the netcore CoreAudioForms.Core.Sample
System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'

in:
v = (int)(device.AudioMeterInformation.PeakValues[1] * 100);

That would indicate that the default audio output is mono (one channel)... what sound card are you using?

I guess the code could be enhanced to check whether the device supports two-channel audio.

I'll check. I also had Invalid cast exception of a device.

Hi @morphx666
the error I'm getting is
System.InvalidCastException: 'Unable to cast COM object of type 'System.__ComObject' to interface type 'CoreAudio.Interfaces.IMMDevice'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{D666063F-1587-4E43-81F1-B948E807363F}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).'

the code is

        devEnum = new MMDeviceEnumerator(Guid.Empty);
        defaultDevice = devEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
        defaultDevice?.AudioEndpointVolume?.VolumeStepUp(); // here is the exception

Hi @LiorBanai, I just tested it myself and it worked.

So... what happens if you query the StepInformation of AudioEndpointVolume?

AudioEndpointVolumeStepInformation si = defaultDevice.AudioEndpointVolume.StepInformation;

Also, I think it would be helpful to have some information regarding your setup: Windows version and the sound card brand and model.

sure I'll collect it this week. Thanks for your help.
I think the issue is reproducible if you create the objects on one thread but access it in another
(access defaultDevice?.AudioEndpointVolume?.VolumeStepUp(); in different thread).

@LiorBanai, accessing the device through a separate thread doesn't seem to have any negative effects.

Actually, the CoreAudioForms.Core.Sample sample works by running a task to update the UI.
But, just to be sure, I added some code to access the VolumeStepUp method and it worked just fine.

image

The issue is not reproduceble on my end so I'm closing the issue. Thanks for you help