Sub AudioStream_RecordBuffer(Data() As Byte)
If sendingAudio = False Then Return 'Why bother if were not going to send the audio
If Data.Length < 1 Then Return 'Sanity check
audioList.Add(Data) 'Buffer the incoming data
If audioListProcessing = True Then Return 'Quit if we are currently processing the audio list
audioListProcessing = True 'Flag audio processing and
'Adjust to the maximum amount of data To sent via UDP. Please note
' that the actuall UDP packet will be larger (data, plus UDP header, plus any
' encapsulations)
Dim maxSizeToSent As Int = 1000
Dim dataLength As Int
Dim packetsToSent As Int
Dim offset As Int
Dim x As Int
Do While audioListProcessing ' let us process some audio
Dim audioData() As Byte = audioList.Get(audioListPtr)
dataLength = audioData.Length
packetsToSent = (dataLength/maxSizeToSent)+1
offset = 0
'Sent all but the last packet with the For Loop. Loop Is skipped If only one packet
' needs To be sent.
For x = 1 To packetsToSent - 1
Dim packet As UDPPacket
packet.Initialize2(audioData, offset, maxSizeToSent, genaudioip, genaudioport)
UDPSck.Send(packet)
offset = offset + maxSizeToSent
Next
'Sent the last Or only packet
Dim packet As UDPPacket
packet.Initialize2(audioData, offset, dataLength - offset, genaudioip, genaudioport)
UDPSck.Send(packet)
audioList.Set(audioListPtr, Null) 'Done with the data
audioListPtr = audioListPtr + 1 'Increment the list pointer
If audioListPtr = audioList.Size Then 'If we reached the end of the audio list
audioListProcessing = False ' then we are done processing the audio list
End If
Loop
End Sub