NAudio sound via microphone

1.2k Views Asked by At

My application uses microphone to talk between machines. I am having a problem when two people talk, there is a constant 'hiss' noise with the voice. Need help please

  {
        waveOutDevice = new DirectSoundOut();
        wavFormat = new WaveFormat(sampleRates, numberChannels);
        // Create two buffers to represent left & right output
        waveProvider[0] = new BufferedWaveProvider(wavFormat);
        waveProvider[1] = new BufferedWaveProvider(wavFormat);
        waveProvider[0].BufferDuration = new TimeSpan(0, 0, 0, 0, 100);
        waveProvider[1].BufferDuration = new TimeSpan(0, 0, 0, 0, 100);
        waveProvider[0].DiscardOnBufferOverflow = true;
        waveProvider[1].DiscardOnBufferOverflow = true;


        IEnumerable<IWaveProvider> providers = from w in waveProvider select w;


        // channels of a stereo setup. 
        outputWaveProvider = new MultiplexingWaveProvider(providers,2);
        outputWaveProvider.ConnectInputToOutput(0, 0);
        outputWaveProvider.ConnectInputToOutput(1, 1);
        waveOutDevice.Init(outputWaveProvider);
        waveOutDevice.Play();

        waveInStream = new WaveIn();
        waveInStream.WaveFormat = wavFormat;
        waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);
        waveInStream.StartRecording();
        waveInStream.RecordingStopped += new EventHandler<StoppedEventArgs>(this.OnRecordingStopped);
   }

    void waveInStream_DataAvailable(object sender, WaveInEventArgs e)
    {
        writer.WriteData(e.Buffer, 0, e.BytesRecorded);
        writer.Flush();
    }

    public void OnRecordingStopped(object sender, StoppedEventArgs e)
    {
        if (this.writer != null)
        {
            waveInStream.StopRecording();
            writer.Close();
            writer = null;
        }
    }

If I try and give high BufferDuration then the noise is almost nil but lag increases. Please help

1

There are 1 best solutions below

5
On

The buffer duration should not affect latency, and should be left at a higher value. Reduce latency by changing the latency of the output device.