[MDX, DirectSound]"Value does not fall within the expected range" if Control3D = 1

Started by
0 comments, last by CadeF 18 years, 1 month ago
I've got normal sound working, so now I'm trying to convert it to 3D sound. The following code works

 Dim DSDevice As DirectSound.Device
    Dim BufferDesc As DirectSound.BufferDescription

    Private Structure udt_SoundPool
        Dim SoundName As String
        Dim Buf As DirectSound.SecondaryBuffer
        Dim Sound3DBuf As DirectSound.Buffer3D
    End Structure

    Dim DSSoundPool() As udt_SoundPool
    Dim DSSoundPoolCount As Integer = 0
    Dim pBuf As DirectSound.Buffer

    Public Function DSInit(ByVal frmHandle As System.IntPtr) As Boolean
        Try
            DSDevice = New DirectSound.Device
            DSDevice.SetCooperativeLevel(frmHandle, CooperativeLevel.Priority)

            BufferDesc = New BufferDescription
            With BufferDesc
                .ControlVolume = True
                .ControlFrequency = True

            End With

            Return True
        Catch ex As System.Exception
            MsgBox(ex.Message & vbCrLf & ex.Source & vbCrLf & ex.StackTrace, MsgBoxStyle.Information, "")
        End Try
        Return False
    End Function

    Public Sub DSAddSound(ByVal FName As String)
        ReDim Preserve DSSoundPool(DSSoundPoolCount)

        With DSSoundPool(DSSoundPoolCount)
            .Buf = New SecondaryBuffer(FName, BufferDesc, DSDevice)
            .SoundName = FName

        End With

        DSSoundPoolCount += 1
    End Sub

But the following code crashes

Dim DSDevice As DirectSound.Device
    Dim BufferDesc As DirectSound.BufferDescription

    Private Structure udt_SoundPool
        Dim SoundName As String
        Dim Buf As DirectSound.SecondaryBuffer
        Dim Sound3DBuf As DirectSound.Buffer3D
    End Structure

    Dim DSSoundPool() As udt_SoundPool
    Dim DSSoundPoolCount As Integer = 0
    Dim pBuf As DirectSound.Buffer

    Public Function DSInit(ByVal frmHandle As System.IntPtr) As Boolean
        Try
            DSDevice = New DirectSound.Device
            DSDevice.SetCooperativeLevel(frmHandle, CooperativeLevel.Priority)

            BufferDesc = New BufferDescription
            With BufferDesc
                .Control3D = True
                .ControlVolume = True
                .ControlFrequency = True

                .Guid3DAlgorithm = DSoundHelper.Guid3DAlgorithmDefault
            End With

            Return True
        Catch ex As System.Exception
            MsgBox(ex.Message & vbCrLf & ex.Source & vbCrLf & ex.StackTrace, MsgBoxStyle.Information, "")
        End Try
        Return False
    End Function

    Public Sub DSAddSound(ByVal FName As String)
        ReDim Preserve DSSoundPool(DSSoundPoolCount)

        With DSSoundPool(DSSoundPoolCount)
            .Buf = New SecondaryBuffer(FName, BufferDesc, DSDevice)
            .SoundName = FName

            .Sound3DBuf = New Buffer3D(.Buf)
            .Sound3DBuf.Mode = Mode3D.HeadRelative
        End With

        DSSoundPoolCount += 1
    End Sub

It crashes on .Buf = New SecondaryBuffer(FName, BufferDesc, DSDevice) With the error message, "Value does not fall within the expected range" I'm using this tutorial Thanks :)
Advertisement
I've tried using the code directly from the tutorial

Dim dsound As New DirectSound.Device
dsound = New DirectSound.Device
dsound.SetCooperativeLevel(Me.Handle, DirectSound.CooperativeLevel.Priority)
Dim d As DirectSound.BufferDescription = New DirectSound.BufferDescription
d.Control3D = True
d.Guid3DAlgorithm = DirectSound.DSoundHelper.Guid3DAlgorithmHrtfFull
Dim sound As DirectSound.SecondaryBuffer = New DirectSound.SecondaryBuffer(cSound, d, dsound)
Dim sound3d As DirectSound.Buffer3D = New DirectSound.Buffer3D(sound)
sound3d.Mode = DirectSound.Mode3D.HeadRelative

It still crashes on creating a SecondaryBuffer, with the same error. It runs fine if d.Control3D = False and d.Gui3DAlgorithm set to nothing. The tutorial runs perfectly, without me changing anything. What am I doing wrong?

This topic is closed to new replies.

Advertisement