Friday, June 19, 2009

Turn up the Buffers a Notch (or two)

I've had an interesting chat with a customer yesterday about audio quality... or the lack thereof. He was pretty displeased with what AGEphone Mobile 2 had to offer in that department and after hearing a sample that he recorded on his answering machine and sent in I could see his point: His voice was distorted to the point of being unintelligible and so we started going through possible causes -

1. High CPU time consumption: This is the less likely reason as AGEphone Mobile 2 has been found to perform well even on older WM5 devices with 200 MHz CPUs. We also have fixed a bug in the past that could cause CPU spikes on some devices and so the only possible cause is 3rd party software so completely hammering the device that it chokes all other programs. If you suspect any such program on your device, Task Manager is a great program to make sure.

2. Network issues: Here we're talking about a large field that ranges from insufficient connections over network congestion to mobile providers purposely slowing down VoIP traffic. Our mobile softphone needs at least a standard 3G connection that offers 128 kbit/s up- and downstream with G.711 and 64 kbit/s for GSM-FR. While both codecs theoretically need less bandwidth (64 + 13 kbit/s respectively), the packet overhead (plus 21 kbit/s) and a certain security margin need to be accounted for. Thus there is absolutely no chance for you to run AGEphone Mobile 2 over GPRS. And if you say "But I am using EDGE!" now, that one is also less than ideal because even if the bandwidth is sufficient, the latency introduced (around 500 ms) is way too high to have satisfactory calls without constantly cutting each other off.

3. Settings: And here namely the buffer settings. Even if your connection is sufficient, different devices and networks call for different buffer settings. Raising either the incoming or outgoing buffer can fix stuttering and noise in the respective direction.

As it turned out our customer was using a SE Xperia X1 with CPU monitoring over his home WiFi that supplies way more than the required bandwidth. We could thus rule out point 1. and 2. and I advised him to raise his outgoing buffer.

In order to do that he had to open the AGEphone Mobile 2 settings and go to "3. Audio" where we have the "Playback Buffer" (incoming) and "Record Buffer" (outgoing) values. Raising the latter to 100 ms made the sound intelligible and going up further to 180 ms fixed the sound quality issues completely.

Some of you may need different values -- I myself have set the values to 120 and 60 ms respectively which gives me more than adequate quality. Sometimes you may have to raise the incoming or "Playback Buffer" if the sound you hear is skippy or distorted. The "Playback Buffer" goes up in larger steps as the maximum values needed can be considerably higher than for the "Record Buffer".

Setting the buffers is always a tradeoff between latency and audio quality. If you set them too high the delay between you and whomever you are talking to could become too high to have a good conversation. You generally want to keep the delay below 500 ms, a figure that adds up when you combine:

Connection Latency (CL) + Buffer (B) + Distance (D)

If you are using WiFi, connection latency is probably a minor factor, but if you use a mobile broadband provider you can add 100 - 300 ms depending on which mobile broadband technology you use (3G or 3.5G) and how far you are from the next cell tower. The buffer is a combination of the incoming and outgoing value to which you have to add the distance between you and the callee. Let's assume I place a call from Japan to Germany over my HSD(U)PA (3.5G) enabled device:

CL 110 ms + B (120 + 60 ms) + D 210 ms = 500 ms

The call should be reasonably fluent without any walkie-talkie effect. If you don't usually place your calls to the other end of the world and / or if you are using WiFi you should be able to get much better values which leave some more room for higher buffer settings if required. With this knowledge in hand, just experiment a bit for yourself to find the optimum buffer values for your everyday use!

No comments: