Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

VB.NET - NAudio Buffer full TCP-Server

$
0
0

Hey, i have a problem with TCP-Server and the library "NAudio".
I can send the input from microphone with a TCP-Client but the TCP-Server cannot play, because fast cames the error: "buffer full".
I have searched but i didn't found a solution.

Can you help me?

My code:

TCP-Server:

Private Sub MainServer()
    TCP_Server.Start()
    Dim bytes(1024) As Byte
    Dim Received_Message As String = Nothing
    While True
        Dim client As TcpClient = TCP_Server.AcceptTcpClient()
        Dim MicrosoftADPCM_Codec As INetworkChatCodec = New MicrosoftADPCM()
        Dim stream As NetworkStream = client.GetStream

        waveOut = New WaveOut()
        waveProvider = New BufferedWaveProvider(MicrosoftADPCM_Codec.RecordFormat)
        waveOut.Init(waveProvider)
        waveOut.Play()

        Dim i As Int32 = stream.Read(bytes, 0, bytes.Length)
        While (i <> 0)

            Dim decoded As Byte() = MicrosoftADPCM_Codec.Decode(bytes, 0, i)
            waveProvider.AddSamples(decoded, 0, decoded.Length)

        End While
    End While
    TCP_Server.Stop()
End Sub

TCP-Client:

    Dim TCP_Client As New TcpClient("IP", "PORT")
    Dim stream As Stream = TCP_Client.GetStream

    Call_Stream = stream
    Dim MicrosoftADPCM_Codec As INetworkChatCodec = New MicrosoftADPCM()
    selectedCodec = MicrosoftADPCM_Codec
    waveIn = New WaveIn()
    waveIn.BufferMilliseconds = 50
    waveIn.DeviceNumber = comboBoxInputDevices.SelectedIndex
    waveIn.WaveFormat = MicrosoftADPCM_Codec.RecordFormat

    AddHandler waveIn.DataAvailable, AddressOf waveIn_DataAvailable
    waveIn.StartRecording()

waveIn_DataAvailable:

Private Sub waveIn_DataAvailable(sender As Object, e As WaveInEventArgs)
    Dim encoded As Byte() = selectedCodec.Encode(e.Buffer, 0, e.BytesRecorded)
    Call_Stream.Write(encoded, 0, encoded.Length)
End Sub

Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>