Hi All,
I have been struggling with this for weeks now and I just can't get my
head around it. I am trying to convert this procedure to VB.NET. In
particular I am having problems with the CopyMemory and ZeroMemory
calls. I have been messing around with the Marshal class but just
can't seem to get it to work. Can anybody help me with this please and
also if possible tell me what they did so I can learn from it.
Many Thanks,
Declare Sub FillMemory Lib "kernel32.d ll" Alias "RtlFillMem ory" (ByRef
Destination As Object, ByVal length As Integer, ByVal Fill As Byte)
Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMem ory" (ByRef
hpvDest As Object, ByRef hpvSource As Object, ByVal cbCopy As Integer)
Declare Sub ZeroMemory Lib "kernel32.d ll" Alias "RtlZeroMem ory"
(ByRef Destination As Object, ByVal length As Integer)
<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi)> Structure
WAVEHDR
Dim lpData As Integer
Dim dwBufferLength As Integer
Dim dwBytesRecorded As Integer
Dim dwUser As Integer
Dim dwFlags As Integer
Dim dwLoops As Integer
Dim lpNext As Integer
Dim Reserved As Integer
End Structure
Public g_PhoneOutHdr(N UM_BUFFERS) As WAVEHDR
Public Sub PlayWaveChunk(B yRef NumChunksToPlay As Short, ByRef
StartingBuffer As Integer, ByRef hOutputDevice As Integer, ByRef
FileAsInput As Boolean)
Dim i As Short
For i = 1 To NumChunksToPlay
'we DO have a full buffer left
ReDim SpeakerArray(BU FFER_SIZE - 1)
If (MessagePlaying Position + BUFFER_SIZE <=
(TotalFileLengt h + 1)) Then
'lets see if we are using input from a file or from
SAPI memory stream
If FileAsInput Then
'we are using wave input from a file, lets load the
data into an array
FileGet(fFile, SpeakerArray,
MessagePlayingP osition)
'lets copy the array bytes to our wave output
buffer area
CopyMemory(g_Ph oneOutHdr(Start ingBuffer).lpDa ta,
SpeakerArray(0) , BUFFER_SIZE)
Else
'we are using wave input that has been generated
via SAPI internally
CopyMemory(g_Ph oneOutHdr(Start ingBuffer).lpDa ta,
MemStream(Messa gePlayingPositi on), BUFFER_SIZE)
End If
g_PhoneOutHdr(S tartingBuffer). dwBufferLength =
BUFFER_SIZE
'lets check to see if we are done, this would be very
rare to finish exactly
'on a buffer boundry. usually we will have one last
chunk to play that will be
'smaller than our buffer size.
If MessagePlayingP osition + BUFFER_SIZE =
(TotalFileLengt h + 1) Then
'we will use this to determine when we are finished
playing
g_PhoneOutHdr(S tartingBuffer). dwUser =
EndofWaveFile
If FileAsInput Then
FileClose(fFile )
End If
i = NumChunksToPlay + 1
Else
g_PhoneOutHdr(S tartingBuffer). dwUser =
StartingBuffer
End If
play_audio_buff er(g_PhoneOutHd r(StartingBuffe r),
hOutputDevice)
MessagePlayingP osition = MessagePlayingP osition +
BUFFER_SIZE
'lets set the wave playing progress bar value
fmain.DefInstan ce.pbPlayingWav e.Value =
MessagePlayingP osition
StartingBuffer = StartingBuffer + 1
If StartingBuffer > NUM_BUFFERS - 1 Then
StartingBuffer = 0
End If
Else
'*** this section handles the last buffer chunk that is
smaller than our
'buffer size
If MessagePlayingP osition < TotalFileLength + 1 Then
'we've got one last chunk of data to play
g_PhoneOutHdr(S tartingBuffer). dwUser =
EndofWaveFile
If FileAsInput Then
'we do NOT have a full buffer of data left to
play
ReDim SpeakerArray((T otalFileLength -
MessagePlayingP osition) - 1)
FileGet(fFile, SpeakerArray,
MessagePlayingP osition)
ZeroMemory(g_Ph oneOutHdr(Start ingBuffer).lpDa ta, BUFFER_SIZE)
CopyMemory(g_Ph oneOutHdr(Start ingBuffer).lpDa ta, SpeakerArray(0) ,
TotalFileLength - MessagePlayingP osition)
Else
ZeroMemory(g_Ph oneOutHdr(Start ingBuffer).lpDa ta, BUFFER_SIZE)
CopyMemory(g_Ph oneOutHdr(Start ingBuffer).lpDa ta,
MemStream(Messa gePlayingPositi on), TotalFileLength -
MessagePlayingP osition)
End If
g_PhoneOutHdr(S tartingBuffer). dwBufferLength =
BUFFER_SIZE
play_audio_buff er(g_PhoneOutHd r(StartingBuffe r),
hOutputDevice)
MessagePlayingP osition = MessagePlayingP osition +
BUFFER_SIZE
If FileAsInput Then
FileClose(fFile )
End If
i = NumChunksToPlay + 1
End If
End If
Next i
End Sub
I have been struggling with this for weeks now and I just can't get my
head around it. I am trying to convert this procedure to VB.NET. In
particular I am having problems with the CopyMemory and ZeroMemory
calls. I have been messing around with the Marshal class but just
can't seem to get it to work. Can anybody help me with this please and
also if possible tell me what they did so I can learn from it.
Many Thanks,
Declare Sub FillMemory Lib "kernel32.d ll" Alias "RtlFillMem ory" (ByRef
Destination As Object, ByVal length As Integer, ByVal Fill As Byte)
Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMem ory" (ByRef
hpvDest As Object, ByRef hpvSource As Object, ByVal cbCopy As Integer)
Declare Sub ZeroMemory Lib "kernel32.d ll" Alias "RtlZeroMem ory"
(ByRef Destination As Object, ByVal length As Integer)
<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi)> Structure
WAVEHDR
Dim lpData As Integer
Dim dwBufferLength As Integer
Dim dwBytesRecorded As Integer
Dim dwUser As Integer
Dim dwFlags As Integer
Dim dwLoops As Integer
Dim lpNext As Integer
Dim Reserved As Integer
End Structure
Public g_PhoneOutHdr(N UM_BUFFERS) As WAVEHDR
Public Sub PlayWaveChunk(B yRef NumChunksToPlay As Short, ByRef
StartingBuffer As Integer, ByRef hOutputDevice As Integer, ByRef
FileAsInput As Boolean)
Dim i As Short
For i = 1 To NumChunksToPlay
'we DO have a full buffer left
ReDim SpeakerArray(BU FFER_SIZE - 1)
If (MessagePlaying Position + BUFFER_SIZE <=
(TotalFileLengt h + 1)) Then
'lets see if we are using input from a file or from
SAPI memory stream
If FileAsInput Then
'we are using wave input from a file, lets load the
data into an array
FileGet(fFile, SpeakerArray,
MessagePlayingP osition)
'lets copy the array bytes to our wave output
buffer area
CopyMemory(g_Ph oneOutHdr(Start ingBuffer).lpDa ta,
SpeakerArray(0) , BUFFER_SIZE)
Else
'we are using wave input that has been generated
via SAPI internally
CopyMemory(g_Ph oneOutHdr(Start ingBuffer).lpDa ta,
MemStream(Messa gePlayingPositi on), BUFFER_SIZE)
End If
g_PhoneOutHdr(S tartingBuffer). dwBufferLength =
BUFFER_SIZE
'lets check to see if we are done, this would be very
rare to finish exactly
'on a buffer boundry. usually we will have one last
chunk to play that will be
'smaller than our buffer size.
If MessagePlayingP osition + BUFFER_SIZE =
(TotalFileLengt h + 1) Then
'we will use this to determine when we are finished
playing
g_PhoneOutHdr(S tartingBuffer). dwUser =
EndofWaveFile
If FileAsInput Then
FileClose(fFile )
End If
i = NumChunksToPlay + 1
Else
g_PhoneOutHdr(S tartingBuffer). dwUser =
StartingBuffer
End If
play_audio_buff er(g_PhoneOutHd r(StartingBuffe r),
hOutputDevice)
MessagePlayingP osition = MessagePlayingP osition +
BUFFER_SIZE
'lets set the wave playing progress bar value
fmain.DefInstan ce.pbPlayingWav e.Value =
MessagePlayingP osition
StartingBuffer = StartingBuffer + 1
If StartingBuffer > NUM_BUFFERS - 1 Then
StartingBuffer = 0
End If
Else
'*** this section handles the last buffer chunk that is
smaller than our
'buffer size
If MessagePlayingP osition < TotalFileLength + 1 Then
'we've got one last chunk of data to play
g_PhoneOutHdr(S tartingBuffer). dwUser =
EndofWaveFile
If FileAsInput Then
'we do NOT have a full buffer of data left to
play
ReDim SpeakerArray((T otalFileLength -
MessagePlayingP osition) - 1)
FileGet(fFile, SpeakerArray,
MessagePlayingP osition)
ZeroMemory(g_Ph oneOutHdr(Start ingBuffer).lpDa ta, BUFFER_SIZE)
CopyMemory(g_Ph oneOutHdr(Start ingBuffer).lpDa ta, SpeakerArray(0) ,
TotalFileLength - MessagePlayingP osition)
Else
ZeroMemory(g_Ph oneOutHdr(Start ingBuffer).lpDa ta, BUFFER_SIZE)
CopyMemory(g_Ph oneOutHdr(Start ingBuffer).lpDa ta,
MemStream(Messa gePlayingPositi on), TotalFileLength -
MessagePlayingP osition)
End If
g_PhoneOutHdr(S tartingBuffer). dwBufferLength =
BUFFER_SIZE
play_audio_buff er(g_PhoneOutHd r(StartingBuffe r),
hOutputDevice)
MessagePlayingP osition = MessagePlayingP osition +
BUFFER_SIZE
If FileAsInput Then
FileClose(fFile )
End If
i = NumChunksToPlay + 1
End If
End If
Next i
End Sub