Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Out of Index" error with USB devices when try get volume peak. #208

Closed
andernunes opened this issue Jul 6, 2017 · 5 comments
Closed

"Out of Index" error with USB devices when try get volume peak. #208

andernunes opened this issue Jul 6, 2017 · 5 comments

Comments

@andernunes
Copy link

I'm tryin get the peaks of volume from USB devices with WASAPI but i het a overflow error:
"Exception thrown: 'System.IndexOutOfRangeException' in NAudio.dll"

With others devices no problem. Only with USB like UB222 and Wireless Headphones.

err

I need the values to test a custom VU Meter with customized handles.

(Sorry my bad english)

@markheath
Copy link
Contributor

markheath commented Jul 22, 2017

is index >= Count? This method should probably throw an ArgumentOutOfRangeException before getting the peak values. Perhaps its mono?

@andernunes
Copy link
Author

Hi markheath!
No, its stereo.
I try increase and decrease the index value, write a count test to jump the error but i don't had sucess.
The error happen only when i use a USB device, like UC202 (Behringer) or a Headphone Wireless with dongle USB.
If i use a pci or pci-x soundcard, works fine.

@markheath
Copy link
Contributor

hmm, may just be a quirk of the drivers for those devices.

@andernunes
Copy link
Author

Hi markeath!
Sorry for this (don't report anymore about the issue).
Thank you. (Here, in Brazil, we say: Antes tarde do que nunca. LOL)

@andernunes
Copy link
Author

SOLVED
The error happens because the index of listed devices for Peaks is different from listed devices on WaveDevices.
I have created a function that associate the index of soundcard in WASAPI

Private Function getwasapi_dev(ByVal n As Integer, tipo As DataFlow) As Integer
        Try
            Dim caps As String = Nothing
            Dim entradas_d(32) As String
            If tipo = DataFlow.Capture Then
                caps = WaveIn.GetCapabilities(n).ProductName
            ElseIf tipo = DataFlow.Render Then
                caps = WaveOut.GetCapabilities(n).ProductName
            End If
            Dim c As Integer = 0
            Dim enumerator As MMDeviceEnumerator = New MMDeviceEnumerator()
            For Each device As MMDevice In enumerator.EnumerateAudioEndPoints(tipo, DeviceState.Active)
                If caps = Microsoft.VisualBasic.Left(device.FriendlyName, 31) Then
                    Debug.Print(n & ": " & caps & " - " & c & ": " & Microsoft.VisualBasic.Left(device.FriendlyName, 31))
                    Return c
                End If
                c += 1
            Next
        Catch ex As Exception
        End Try
        Return -1
End Function

Again: Thank you so much for your knowledgment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants