Imports Microsoft.DirectX.DirectSound
Public Class project1
Private Const SAMPLES As Integer = 8
Private Shared SAMPLE_FORMAT_ARRAY As Integer() = {SAMPLES, 2, 1}
Public Shared audioDevices As CaptureDevicesCollection
Private Shared m_deviceNames As StringCollection
Private deviceIndex As Integer = -1
Private buffer As Microsoft.DirectX.DirectSound.CaptureBuffer
Private liveVolumeThread As System.Threading.Thread
Private m_frameDelay As Integer = 20
Private Range_Division As Integer = 10
Public Sub Start()
Dim audioDevices As New CaptureDevicesCollection
deviceIndex = ComboBox1.SelectedIndex
If deviceIndex <> -1 Then
' initialize the capture buffer and start the animation thread
Dim cap As New Capture(audioDevices(deviceIndex).DriverGuid)
Dim desc As New CaptureBufferDescription()
Dim wf As New WaveFormat()
wf.BitsPerSample = 16
wf.SamplesPerSecond = 44100
wf.Channels = 2
wf.BlockAlign = CShort(wf.Channels * wf.BitsPerSample / 8)
wf.AverageBytesPerSecond = wf.BlockAlign * wf.SamplesPerSecond
wf.FormatTag = WaveFormatTag.Pcm
desc.Format = wf
desc.BufferBytes = SAMPLES * wf.BlockAlign
buffer = New Microsoft.DirectX.DirectSound.CaptureBuffer(desc, cap)
buffer.Start(True)
liveVolumeThread = New Thread(AddressOf updateProgress)
Control.CheckForIllegalCrossThreadCalls = False
liveVolumeThread.Priority = ThreadPriority.Lowest
liveVolumeThread.Start()
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim audioDevices As New CaptureDevicesCollection
Dim x As Integer = 1
While x < audioDevices.Count
ComboBox1.Items.Add(audioDevices.Item(x).Description)
x = x + 1
End While
ComboBox1.SelectedIndex = 0
Start()
End Sub
End Class
Dim devices As List(Of DeviceInformation) = DirectSoundCapture.GetDevices()
Dim devices As New CaptureDevicesCollection()
Dim inputDevices As New List(Of InputDevice)(devices.Count)
For Each info As DeviceInformation In devices
Console.WriteLine("InputDevice ModuleName:")
Console.WriteLine(info.ModuleName)
Console.WriteLine("InputDevice Description:")
Console.WriteLine(info.Description)
Console.WriteLine("InputDevice DriverGuid:")
Console.WriteLine(info.DriverGuid)
Try
inputDevices.Add(New InputDevice(info))
Catch ex As Exception
Console.WriteLine("InputDevice FAILED:")
Console.WriteLine(ex.Message)
Console.WriteLine(ex.StackTrace)
Continue Try
End Try
Next
m_CachedInputDevices = inputDevices
Console.WriteLine(">>> InputDevices: " + inputDevices.Count)