to get the event working, do this in your form...
Code:
' General Declarations...
Private WithEvents BEncoder As BladeEncoder
Private Sub Form_Load()
Set BEncoder = New BladeEncoder
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Set BEncoder = Nothing
End Sub
And to fix the problem with the second buffer not being correct you need to make the DirectX buffer a multiple of BEncoder.Samples and to make sure the buffer is aligned (divizible by 4)
Code:
Private Sub DirectXEvent8_DXCallback(ByVal eventid As Long)
Dim DataBuff() As Byte
ReDim DataBuff(HBuffer - 1)
Select Case eventid
Case StartEvent
gDSCB.ReadBuffer HBuffer, HBuffer, DataBuff(0), DSCBLOCK_DEFAULT
Case MidEvent
gDSCB.ReadBuffer 0, HBuffer, DataBuff(0), DSCBLOCK_DEFAULT
Case EndEvent
BEncoder.CloseStream
End Select
If eventid = StartEvent Or eventid = MidEvent Then
' write to file...
End If
End Sub
' when you initialize your DirectX sound do this
Private Sub Initialize()
... declarations.....
' you must call BEncoder.InitStream before this line
HBuffer = BEncoder.Samples * 8
HBuffer = HBuffer + (HBuffer Mod wFormat.nBlockAlign)
BufferSize = HBuffer * 2
With dscBuf
.fxFormat = wFormat
.lBufferBytes = BufferSize
.lFlags = DSCBCAPS_DEFAULT
End With
Set gDSCB = gDSC.CreateCaptureBuffer(dscBuf)
ReDim dsbpn(0 To 2) As DSBPOSITIONNOTIFY
StartEvent = gDX.CreateEvent(Me)
With dsbpn(0)
.hEventNotify = StartEvent
.lOffset = 1
End With
MidEvent = gDX.CreateEvent(Me)
With dsbpn(1)
.hEventNotify = MidEvent
.lOffset = HBuffer
End With
EndEvent = gDX.CreateEvent(Me)
With dsbpn(2)
.hEventNotify = EndEvent
.lOffset = DSBPN_OFFSETSTOP
End With
gDSCB.SetNotificationPositions 3, dsbpn()
gDSCB.Start DSCBSTART_LOOPING
End Sub