2
votes

I'm writing a UDP local area network video chat system and have got the video and audio streams working. However I'm experiencing a little latency (about half a second) in the audio and was wondering what codecs would provide the least latency. I'm using NAudio (http://naudio.codeplex.com/) which provides me access to the following codecs for streaming;

  • Speex Narrow Band (VBR)
  • Speex Wide Band (16kHz)(VBR)
  • Speex Ultra Wide Band (32kHz)(VBR)
  • DSP Group TrueSpeech (8.5kbps)
  • GSM 6.10 (13kbps)
  • Microsoft ADPCM (32.8kbps)
  • G.711 a-law (64kbps)
  • G.722 16kHz (64kbps)
  • G.711 mu-law (64kbps)
  • PCM 8kHz 16 bit uncompressed (128kbps)

I've tried them out and I'm not noticing much difference. Is there any others that I should download and try to reduce latency? I'm only going to be sending voice over the connection but I'm not really worried about quality or background noises too much.

UPDATE

I'm sending the audio in blocks like so;

        waveIn = new WaveIn();
        waveIn.BufferMilliseconds = 50;
        waveIn.DeviceNumber = inputDeviceNumber;
        waveIn.WaveFormat = codec.RecordFormat;
        waveIn.DataAvailable += waveIn_DataAvailable;

void waveIn_DataAvailable(object sender, WaveInEventArgs e)
    {
        if (connected)
        {
            byte[] encoded = codec.Encode(e.Buffer, 0, e.BytesRecorded);
            udpSender.Send(encoded, encoded.Length);
        }
    }
2
Sometimes latency is out of your hands. I can run the same equipment, running low latency drivers but different progs and the difference is amazing. Some programs have latency buffers. I guess you'd have to write your own. I would say 1/2 second is pretty long. In pro-audio you deal with ms. I can't understand why if you're communicating why noise and quality are not important. - ChiefTwoPencils
Oh yeah. I noticed naudio has an ASIO option. Are you using it (i.e., does your hardware support it?) ? - ChiefTwoPencils
I'm running from an i5 MS Surface to a Windows 7 i7 laptop, but I know the bottleneck is probably elsewhere. What I meant was I'd be willing to take a hit on my background noise/quality in order to reduce the latency. I have just installed ASIO4All in both systems but I'm unfamiliar with it. Does it aid with encoding/decoding? - windowsgm
Music is a hobby for me, I don't program for it. I'm coming from experience of using audio progs. What it's good for is low latency audio production. Edit: I think what you could do is treat the devices themselves as streams. So it would be like an IO connection where the audio was being "recorded" at the receiver if that makes sense. - ChiefTwoPencils
Nope, over a router. From research I'm guessing you need a fairly heavy duty soundcard to use ASIO, not just ASIO4All. - windowsgm

2 Answers

1
votes

Your latency issue is probably not coming from the codec you pick but from your audio API choice. WinMM and DirectSound APIs are quite old and as pointed at by Mark Heath, the creator of the NAudio Libray :

WinMM - these are the APIs that have been around for ages (e.g. the waveOut... and waveIn... functions). Their main limitation is poor latency (its hard to go much below 50ms without dropouts).

DirectSound - has its uses, particularly for game development, but it appears Microsoft is phasing this out too.

What's up with WASAPI? - Mark Heath

If you use Window 7 or higher version, I recommand you tu use WASAPI instead. This API is already included in NAudio like WinMM and DirectSound and it will help you to achieve low latency audio transmission.

Also, Asio4All can be a very good solution too. However, in my experience, Asio4All will not fit if you want to redirect specific audio stream to specific output devices on your system programmatically (in your code each devices appears like one and you configure the audio stream repartition later in the Asio4All GUI).

You will find a interesting recap here : NAudio Output Devices - Mark Heath

0
votes

Oddly enough the latency was appearing on the client side. After trying various combinations of settings I eventually decided to give DirectSoundOut ago instead of WaveOut. I was shocked to find that the latency shot way down. Guess I'll be using that in the future.

        dso= new DirectSoundOut();         //Direct Sound Removed nearly all latency
        //WaveOut waveOut = new WaveOut();
        waveProvider = new BufferedWaveProvider(codec.RecordFormat);

        //WaveOut.Init(waveProvider);
        //WaveOut.Play();
        dso.Init(waveProvider);
        dso.Play();