i omitted code that is not yet reached when executing.
The crash location is in the sub "Create3DListener(...)"
I just can't figure out why it crashes.
Any help you can give would be greatly appreciated.
I'm having trouble finding ANY vb.net SlimDX audio examples and am trying to learn by looking at DX Audio examples in C's.
Sub New(), imports, and class values...
Code:
Imports System
Imports System.Text
Imports System.Windows.Forms
Imports System.Collections.Generic
Imports Microsoft.VisualBasic
Imports SlimDX
Imports SlimDX.Multimedia
Imports SlimDX.DirectSound
Imports System.Threading
Imports System.IO
'Namespace Play3DSound
Public Class SoundLibrary
Public listenerParameters As Buffer3DSettings
Public Shared AmUpdating As Boolean = False
Public Shared AmReady As Boolean = False
Public Structure ThreeDAlgos
Public Const Defalt As String = "Default 3D Algorithm"
Public Const Low As String = "Low 3D Algorithm"
Public Const Full As String = "Full 3D Algorithm"
Public Const NoVirt As String = "No Virtualization Algorithm"
End Structure
Private Structure SoundListDefinition
Dim Description As String
Dim Buffer As SecondarySoundBuffer
Dim SoundData As Byte()
Dim Format As WaveFormat
Dim Desc As SoundBufferDescription
Dim Frequency As Short
End Structure
Private Device As New DirectSound
Private SoundList As New List(Of SoundListDefinition)
Private Buffer As PrimarySoundBuffer
Private Desc As SoundBufferDescription
Friend applicationBuffer As SecondarySoundBuffer
Friend MyListener As SoundListener3D
Friend Sub New()
PushIntoChat("INITILIZING SOUND...")
SetUpHardware()
AddToDebug("Sub LoadingSoundFiles...")
Dim CurrentLine As String
Dim WavSoundsList As System.IO.TextReader = New StreamReader(MyPath + "\bin\Sounds\SoundList.txt")
Dim Doit As Boolean = True
Dim Channels As Short = 1
Dim Frequency As Integer
Dim BitRate As Integer
Dim FileName As String = "FILENAME NOT GIVEN"
Dim Description As String = "NO DESCRIPTION SET"
Try
While Doit = True
ReReadLine:
CurrentLine = WavSoundsList.ReadLine()
AddToDebug("JUST READ:" & CurrentLine)
[.... irrelevant code removed for forum space....]
End Sub
Sub SetupHardware()
Code:
Private Sub SetUpHardware() 'ByVal parent As Control, ByVal level As CooperativeLevel)
Device = New DirectSound()
Device.SetCooperativeLevel(Form1.Handle, CooperativeLevel.Priority)
SetPrimaryBuffer(1, 44100, 8) 'CHANNELS, FREQUENCY,BITRATE
MyListener = Create3DListener(1, 1, 1) 'INGAME CAMERA
End Sub
The crash line is here when the listener is set up with Listener = New SoundListener3D(Buffer)
Sub Create3DListener(...)
Code:
Private Function Create3DListener(ByVal x As Single, ByVal y As Single, ByVal z As Single) As SoundListener3D
Dim GivenVector As Vector3
Dim listener As SoundListener3D
Dim description As New SoundBufferDescription
'Dim MyListenerSettings As New settings
'description.Flags = BufferFlags.PrimaryBuffer And BufferFlags.Control3D And BufferFlags.GlobalFocus
listener = New SoundListener3D(Buffer) <-----CRASHES HERE <-------
GivenVector = New Vector3(x, y, z)
listener.Position = GivenVector
Return (listener)
End Function
Sub SetPrimaryBuffer(....)
Code:
Private Sub SetPrimaryBuffer(ByVal channels As Short, ByVal frequency As Integer, ByVal bitRate As Short)
Desc = New SoundBufferDescription
Dim format As New WaveFormatExtensible()
Try
With format
.FormatTag = WaveFormatTag.Pcm
.Channels = 1
.SamplesPerSecond = frequency
.BitsPerSample = bitRate
.BlockAlignment = CShort(Fix(bitRate \ 8 * channels))
.AverageBytesPerSecond = frequency * format.BlockAlignment
End With
Desc.Flags = BufferFlags.PrimaryBuffer
Device.SetCooperativeLevel(Form1.Handle, CooperativeLevel.Priority)
Buffer = New PrimarySoundBuffer(Device, Desc)
Buffer.Format = format
Catch ex As Exception
Debug.Print(ex.ToString)
Debug.Print(ex.Message)
Debug.Print(" ")
End Try
End Sub