winmm wavein callback

  • Thread starter Thread starter -tE
  • Start date Start date
T

-tE

Guest
I am starting on an audio in component. I believe I will nee to get a callback from the waveopen function. But currently I am not. I get a NO_ERR message from the wavestart.

Any ideas?

Declare Function waveInOpen Lib "winmm.dll" (ByRef lphWaveIn As Integer, ByVal uDeviceID As UInteger, ByRef lpFormat As WAVEFORMATEXTENSIBLE, ByVal dwCallback As WaveInCallBack, ByVal dwInstance As UInteger, ByVal dwFlags As UInteger) As Integer

Declare Function waveInStart Lib "winmm.dll" (ByVal hWaveIn As Integer) As Integer
Declare Function waveInStop Lib "winmm.dll" (ByVal hWaveIn As Integer) As Integer
Declare Function waveInAddBuffer Lib "winmm.dll" (ByVal hWaveIn As Integer, ByRef lpWaveInHdr As WAVEHDR, ByVal uSize As Integer) As Integer
Declare Function waveInReset Lib "winmm.dll" (ByVal hWaveIn As Integer) As Integer
Declare Function waveInPrepareHeader Lib "winmm.dll" (ByVal hwi As Integer, ByRef pwh As WAVEHDR, ByVal cbwh As UInteger) As Integer
Declare Function waveInGetErrorText Lib "winmm.dll" Alias "waveInGetErrorTextA" (ByVal errorIN As Integer, ByVal lpText As String, ByVal uSize As UInteger) As Integer
Declare Function waveInClose Lib "winmm.dll" (ByVal hwi As Integer) As Integer
Declare Function waveInUnprepareHeader Lib "winmm.dll" (ByVal hwi As Integer, ByRef pwh As WAVEHDR, ByVal cbwh As UInteger) As Integer
Declare Function waveInClose Lib "winmm.dll" (ByVal hwi As IntPtr) As Integer

Public Delegate Function WaveInCallback(ByVal hwi As Integer, ByVal uMsg As UInteger, ByVal dwInstance As Integer, ByVal dwParam1 As Integer, ByVal dwParam2 As Integer) As Integer

Public CALLBACK_FUNCTION As Integer = &H30000


Dim WFE As AudioProfile.WAVEFORMATEXTENSIBLE
Dim WH As AudioProfile.WAVEHDR
Dim RAMBufferPtr As String = "BOGUSNAME"
Dim RAMBufferSize As Integer = 32767
Dim BufferWaveInIntptr As New List(Of IntPtr)

Dim result As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim N As String = "012390"

Dim P As AudioProfile.Pointers
P.waveIntPtr = CType(N, IntPtr)

BufferWaveInIntptr.Add(P.waveIntPtr)

WFE.wFormatTag = 1
WFE.nChannels = 2
WFE.dwBitsPerSample = 24
WFE.nSamplesPerSec = 48000
WFE.nBlockAlign = CUShort(CShort(WFE.nChannels * WFE.dwBitsPerSample / 8))
WFE.nAvgBytesPerSec = WFE.nSamplesPerSec * WFE.nBlockAlign
WFE.cbSize = 0

RAMBufferPtr = Marshal.AllocHGlobal(RAMBufferSize)
WH.lpData = CType(RAMBufferPtr, IntPtr)
WH.dwBufferLength = RAMBufferSize
WH.dwBytesRecorded = 0
WH.dwFlags = 0
WH.dwLoops = 0
waveInOpen(BufferWaveInIntptr(0), 0, WFE, myCallBackFunction, 0, CALLBACK_FUNCTION)

waveInPrepareHeader(BufferWaveInIntptr(0), WH, CUInt(Marshal.SizeOf(WH)))
waveInAddBuffer(BufferWaveInIntptr(0), WH, Marshal.SizeOf(WH))


result = CUInt(AudioProfile.waveInStart(BufferWaveInIntptr(0)))




End Sub


Private Const BUFFER_SIZE As Int32 = 128
Private RawWaveData(BUFFER_SIZE) As Byte

Public Delegate Sub DisplayDataDelegate(dwParam1)

Private myCallBackFunction As New AudioProfile.WaveInCallBack(AddressOf MyWaveCallBackProcedure)

Private Function MyWaveCallBackProcedure(ByVal hwi As IntPtr, ByVal uMsg As Int32, ByVal dwInstance As Int32, ByVal dwParam1 As Int32, ByVal dwParam2 As Int32) As Int32

Marshal.Copy(WH.lpData, RawWaveData, 0, WH.dwBytesRecorded)

End Function



Thanks for helping!!

Continue reading...
 
Back
Top