Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a TCP Audio Chat(Basic) ...
It works for about 1 second, then it say buffer full

I wish to use this as a tablet to front Door tablet Intercom

Server
C#
 WaveIn waveIn = new WaveIn();
// int deviceID = Cmb_InputDevices.SelectedIndex;
waveIn.BufferMilliseconds = 50;
waveIn.DeviceNumber = 0;


 waveIn.WaveFormat = new WaveFormat(44100, 1);//, WaveIn.GetCapabilities(deviceID).Channels); 


 // Lamewriter = new LameMP3FileWriter(Application.StartupPath + @"\128bits.mp3", waveIn.WaveFormat, LAMEPreset.ABR_128);


 waveIn.DataAvailable += WaveIn_DataAvailable;
waveIn.StartRecording();


private void WaveIn_DataAvailable(object sender, WaveInEventArgs e)
 {
 try
 {

byte[] decodedData = null;
 decodedData = G711.Encode_aLaw(e.Buffer, 0, e.Buffer.Length);
 Stream.Write(decodedData, 0, decodedData.Length); // NetworkStream
 }
 catch (Exception ex)
 {
 // MessageBox.Show(ex.ToString());
 }
 }
>

Client


C#
<
 WaveOut waveOut;
 WaveIn sourceStream;
 waveOut = null;

 sourceStream = null;
 waveOut = new WaveOut();


 sourceStream = new WaveIn();
 sourceStream.BufferMilliseconds = 50;
 sourceStream.DeviceNumber = 0;
 sourceStream.WaveFormat = new WaveFormat(44100, 1);//bitRate, bitDepth);


 waveProvider = new BufferedWaveProvider(sourceStream.WaveFormat);


 waveOut.Init(waveProvider);
 waveOut.Play();


 //  sourceStream.StartRecording();
            byte[] decodedData = null;//new byte[44100]; 
            byte[] bytes = new byte[1024];
            try
            {
                
                while(true)
                {
                    textBox1.AppendText(Encoding.ASCII.GetString(bytes, 0, bytes.Length));
                   stream.Read(bytes, 0, bytes.Length);
                    decodedData = G711.Decode_aLaw(bytes, 0, bytes.Length);


                    waveProvider.AddSamples(decodedData, 0, decodedData.Length);
                   // waveOut.Play();
                    
                }
            }catch(Exception ex) {    }


The problem is the buffer bytes ...

What I have tried:

I have tried many version of this including using

sourceStream.DataAvailable += SourceStream_DataAvailable;


No joy

I hope there a solution ...
Posted
Updated 7-Jan-20 20:09pm

1 solution

Based on the information you gave, it is hard to help. But anyway I see at least two problems:

1.) For audio streaming I would use UDP instead of TCP.

2.) Client

2.a) The while loop in your client is/can be a havy load for cpu, you should replace it by event based code. Means when something (but enough for decoding) arrives in the stream only then you should decode.

2.b) textBox1.AppendText, probably only for debugging. For debugging it should be enough only to show the length of the buffer and not the whole content.

I hope it helps a lttle bit.
 
Share this answer
 
Comments
dwk00 8-Jan-20 4:01am    
Thank you ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900