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 :)