Regarding windows API waveInAddBuffer

Hi,

I am developing a application in Visual Studio 2005 using visual basic which detects while we speak in microphone. I serached in the net and found there are number of API's available for working with sound. In which i found we will be filling a buffer using the APIwaveInAddBuffer. But when i tried it the function is successfull and i received a 0 as return value. But the buffer is not filled. I don't know where i was wrong. I have copied the code down. Please let me know if any one have experienced this error.

Dim InData(511)AsByte

Dim MyGCAs GCHandle = GCHandle.Alloc(InData, GCHandleType.Pinned)

Dim AddofLongValueAs IntPtr = MyGC.AddrOfPinnedObject()

Wave.lpData =CType(AddofLongValue,Integer)

ret = waveInPrepareHeader(DevHandle, Wave, Marshal.SizeOf(Wave))

ret = waveInAddBuffer(DevHandle, Wave, Marshal.SizeOf(Wave))

Thanks,

Ganesh

[1369 byte] By [Ganeshsethuraman] at [2008-1-10]
# 1
You're forgetting to set Wave.dwBufferLength. Your buffer is also quite small; at 511 bytes, you'd get well less than a second of sound.
nobugz at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
Where's the rest of your code to initialize wave in and the wave header? Where do you check for WHDR_DONE? Where are your function declarations? You need to post a little more code. At least the check for WHDR_DONE. The change of the IntPtr to Integer doesn't look right, but I can't tell without the declarations.
JohnWein at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

Hi All,

Thanks for your replies.

Now i am able to detect the voice from microphone and able to propagate the same in a progress bar. I have added one delay of 50ms in the code and the buffer gets filled successfully. I have added the code down,

Dim Wave As WaveHdr

Dim ret As Integer

Dim i As Integer

Dim lTotalLeftSq, lTotalRightSq As Integer

Dim iLeftVal, iRightVal As Short

Dim fRMSLeft, fRMSRight As Single

Dim fdBLeft, fdbRight As Single

Dim MyGC As GCHandle = GCHandle.Alloc(InData, GCHandleType.Pinned)

Dim AddofLongValue As IntPtr = MyGC.AddrOfPinnedObject()

Wave.lpData = CType(AddofLongValue, Integer) 'InData(0)

Wave.dwBufferLength = 512

Do

ret = waveInPrepareHeader(DevHandle, Wave, Marshal.SizeOf(Wave))

ret = waveInAddBuffer(DevHandle, Wave, Marshal.SizeOf(Wave))

Do

lngTempTime = timeGetTime

Do Until timeGetTime > lngTempTime + 50

Loop

Loop Until ((Wave.dwFlags And WHDR_DONE) = WHDR_DONE) Or DevHandle = 0

Loop While DevHandle <> 0

Thanks,

Ganesh

Ganeshsethuraman at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...