copying data from WAVEHDR structure

i try to copy the recorded data from the WAVEHDR structure (WaveInHdr(k)) into a byte array (bytarray) to send it over internet using winsock (sckSend). The sound is recorded properly, but when i use CopyMemory there will only weired noise played back. Seems that the byte array which is played back/transmitted is not related to the source data block.
What might be wrong?

Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Long, ByVal Length As Long)

Code in event procedure:
dim lRecBytes as long
dim bytarray() as byte

waveInStop(hWaveIn) 'stop recording
lRecBytes = WaveInHdr(k).dwBytesRecorded
ReDim bytarray(lRecBytes) As Byte 'initialize size of array

'copy data into array
Call CopyMemory(bytarray(0), WaveInHdr(k).lpData, lRecBytes)
'send data via winsock using UDP
frmMain.sckSend.SendData bytarray

the recorded sound is played back properly when using this code after recording:

WaveOutHdr(k).lpData = WaveInHdr(k).lpData
WaveOutHdr(k).dwBufferLength = WaveInHdr(k).dwBufferLength
'play buffer
RetVal = waveOutWrite(ByVal hWaveOut, WaveOutHdr(k), ByVal Len(WaveOutHdr(k)))

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!