This project has moved. For the latest updates, please go here.

Network chat between regular C# and Raspberry Pi 2 using NAudio

Dec 13, 2015 at 11:47 PM

I am having problems attempting to create network chat between a regular C# console app using naudio and a raspberry pi 2 using the NAudio universal library. Right now I am just trying to get it to go from the Raspberry pi to the C# console app.

I believe my issue is in my limited understanding of which codecs are actually the same between the two. My network communication is successful however I hear only static for a few seconds then a buffer overflow error.

The following is my code on the RPi:
        public void record()

            if (recorder == null)
                recorder = new WasapiCaptureRT();
                recorder.DataAvailable += RecorderOnDataAvailable;

            if (reader != null)
                reader = null;

        private async void RecorderOnDataAvailable(object sender, WaveInEventArgs waveInEventArgs)
            if (reader == null)
                recordStream = new MemoryStream();
                reader = new RawSourceWaveStream(recordStream, recorder.WaveFormat);

                await writer.StoreAsync();
And on the C# app:
     public void test()
            udpListener = new UdpClient(listenPort);
            IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
            var _format = WaveFormat.CreateIeeeFloatWaveFormat(44100,1);

            waveOut = new WaveOut();
            waveProvider = new BufferedWaveProvider(_format);
            waveProvider.BufferDuration = new TimeSpan(1,0,0);
            connected = true;
            var state = new ListenerThreadState { EndPoint = groupEP };
            ThreadPool.QueueUserWorkItem(ListenerThread, state);

        private void ListenerThread(object state)
            var listenerThreadState = (ListenerThreadState)state;
            var endPoint = listenerThreadState.EndPoint;
                while (connected)
                    byte[] b = udpListener.Receive(ref endPoint);
                    waveProvider.AddSamples(b, 0, b.Length);

            catch (SocketException)
                // usually not a problem - just means we have disconnected
Any help would be appreciated!

Jan 3, 2016 at 8:23 PM
first, you're likely capturing stereo audio, so the volume of data sent will be very high. I'd also try to find ways to reduce the volume of audio being sent. IEEE float at 44.1kHz is not very efficient.

Why not start by capturing the audio to a WAV file, and saving a few seconds. This might highlight any mismatches of WaveFormat.