Hello, it is a simple example:
Code:
Option Explicit
' Sorry my English.
Private Declare Sub memcpy Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
' This is a capture object.
Dim WithEvents recorder As clsTrickSound
' Temporary stereo buffer which will obtain the sound data.
Dim tempBuffer(1, 4096) As Integer
Private Sub Form_Load()
Me.ScaleMode = vbPixels
' Create a new recorder object
Set recorder = New clsTrickSound
' Handle errors from this object
On Error GoTo ErrorCapturing
' Initialize a capture sound
' Set the number of channels (mono/stereo), sample rate, bits per sample and size of internal capture buffer
' Don't need set the size internal buffer too small, because it will cause clicking sounds and noises.
' For capturing the sound we using a default capture device.
recorder.InitCapture UBound(tempBuffer, 1) + 1, 44100, 16, UBound(tempBuffer, 2) + 1
' Ok, the capture is success, start it.
recorder.StartProcess
Exit Sub
ErrorCapturing:
MsgBox "Error", vbCritical
Unload Me
End Sub
' // This events calling when a part of recorded sound is ready.
Private Sub recorder_NewData(ByVal DataPtr As Long, ByVal CountBytes As Long)
' Copy data to temporary buffer
memcpy tempBuffer(0, 0), ByVal DataPtr, CountBytes
' Just we draw this data on the form.
Dim dx As Single, dy As Single, oy1 As Long, oy2 As Long, i As Long, di As Long, o As Long
dx = Me.ScaleWidth / UBound(tempBuffer, 2)
dy = Me.ScaleHeight / 131072
oy1 = Me.ScaleHeight / 4
oy2 = oy1 + Me.ScaleHeight / 2
Me.cls
For i = 1 To Me.ScaleWidth
di = Int(i / dx)
' Both channels
Me.Line (i - 1, tempBuffer(0, o) * dy + oy1)-(i, tempBuffer(0, di) * dy + oy1)
Me.Line (i - 1, tempBuffer(1, o) * dy + oy2)-(i, tempBuffer(1, di) * dy + oy2)
o = di
Next
End Sub
ADDED: You also can use DirectSound to capture sound. Here is example.