The code appears to work most of the time but I am having problems understanding what is going on especially where the MidB function is being used on an array
waveChunkSize has a constant value of 3200. This is the maximum length of a wave segment that is sent from other app
MAXTCP has a constant value of 32. This is the maximum number of clients allowed at same time
waveChunkSize has a constant value of 3200. This is the maximum length of a wave segment that is sent from other app
MAXTCP has a constant value of 32. This is the maximum number of clients allowed at same time
Code:
Private Sub ServerSocket_DataArrival(Index As Integer, ByVal BytesTotal As Long)
' Incomming Buffer On...
Dim rc As Long ' Return Code Variable
Dim WaveData() As Byte ' Byte array of wave data
Static ExBytes(MAXTCP) As Long ' Extra bytes in frame buffer
Static ExData(MAXTCP) As Variant ' Extra bytes from frame buffer
If ServerSocket(Index).BytesReceived > 0 Then ' Validate that bytes where actually received
Do While ServerSocket(Index).BytesReceived > 0 ' While data available...
If ExBytes(Index) = 0 Then ' Was there leftover data from last time
If wStream.waveChunkSize <= ServerSocket(Index).BytesReceived Then ' Can we get an entire wave buffer of data
ServerSocket(Index).GetData WaveData, vbByte + vbArray, wStream.waveChunkSize ' Get 1 wave buffer of data
wStream.SaveStreamBuffer Index, WaveData ' Save wave data to buffer
wStream.AddStreamToQueue Index ' Queue current stream for playback
Else
ExBytes(Index) = ServerSocket(Index).BytesReceived ' Save Extra bytes
ServerSocket(Index).GetData ExData(Index), vbByte + vbArray, ExBytes(Index) ' Get Extra data
End If
Else
ServerSocket(Index).GetData WaveData, vbByte + vbArray, wStream.waveChunkSize - ExBytes(Index) ' Get leftover bits
ExData(Index) = MidB(ExData(Index), 1) & MidB(WaveData, 1) ' Sync wave bits...
wStream.SaveStreamBuffer Index, ExData(Index) ' Save the current wave data to the wave buffer
wStream.AddStreamToQueue Index ' Queue the current wave stream
ExBytes(Index) = 0 ' Clear Extra byte count
ExData(Index) = "" ' Clear Extra data buffer
End If
Loop ' Look for next Data Chunk
If Not wStream.Playing And wStream.PlayDeviceFree And Not wStream.Recording And wStream.RecDeviceFree Then ' Check Audio Device Status
StartPlayBack ' Start PlayBack...
End If
End If
End Sub