Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: Network Chat Multi-Client Program

$
0
0

Hello,

I've been working on expanding the Network Chat demo to allow multiple clients to connect to the host computer and voice chat. Seeing that I need to keep track of the clients and the audio data sent over, I created a Client struct that keeps track of who the client is and their BufferedWaveProvider object data.

For the host, I add their BufferedWaveProvider object to a MixingSampleProvider, which then I used that to create a IWaveProvider object. Finally, I used the IWaveProvider for my WaveOut object and use that to play audio.

For my Recieve method that I'm using to obtain audio data, I check to see whether or not the data came from the host or another client. If it's from the host, I just add the data to the host's BufferedWaveProvider object. Otherwise, I need to check to see if the client is connecting to the host IP for the first time. If it is, I create a new Client object with it's own BufferedWaveProvider object and add it to my MixingSampleProvider. Finally, I pull the correct Client object based on its IP address, add the data to its BufferedWaveProvider, and then update the BufferedWaveProvider so that it has the added sample data.

When I applied this logic to actual code and tested it, the audio from the host's mic works correctly. When a client connects to the host's IP from another computer, the audio gets choppy. I can hear what's being said from the client, but it's delayed by a few seconds.

Perhaps my logic isn't correct when trying to receive and play what's been sent over by clients. What could be causing the choppy audio?

Thanks


Viewing all articles
Browse latest Browse all 5831

Trending Articles



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