DEV Community

Justin Smith
Justin Smith

Posted on

Estimating VoIP call quality (MOS-CQE) from latency, jitter buffer, and packet loss in JavaScript

When a VoIP call sounds robotic or people keep talking over each other, network graphs usually give you four numbers: one-way delay (ms), jitter buffer size (ms), packet loss (%), and the codec in use. Turning those four numbers into a single 1–5 call quality estimate is what the ITU-T G.107 E-model was built to do.

Here is how the narrowband E-model calculates the transmission rating factor (R) and MOS-CQE (Conversational Quality Estimated) in about 25 lines of JavaScript, and why a codec that saves bandwidth can degrade much faster once packet loss appears.

How the narrowband E-model combines impairments

In its simplified narrowband form, the E-model starts from a baseline rating of 93.2 and subtracts two main network impairments:

  1. Delay impairment (Idd): Computed from total one-way mouth-to-ear delay Ta = networkDelayMs + jitterBufferMs + codecOverheadMs. Up to Ta = 100 ms, pure delay impairment is 0. Above 100 ms, it rises nonlinearly.
  2. Effective equipment impairment (Ie,eff): Combines the codec's baseline compression loss (Ie) with random packet loss (Ppl), weighted by the codec's packet-loss robustness factor (Bpl): Ie,eff = Ie + (95 - Ie) * (Ppl / (Ppl + Bpl))

From R = 93.2 - Idd - Ie,eff, a standard polynomial maps R (0–100) onto the 1.00–4.50 MOS-CQE scale.

The function

const CODECS = {
  g711:  { Ie: 0,  Bpl: 25.1, overhead: 20 }, // G.711 PCMU/PCMA (64 kbps, with PLC)
  g729a: { Ie: 11, Bpl: 19.0, overhead: 35 }, // G.729A CS-ACELP (8 kbps)
};

function delayImpairment(Ta) {
  if (Ta <= 100) return 0;
  const X = Math.log2(Ta / 100);
  return 25 * (
    Math.pow(1 + Math.pow(X, 6), 1 / 6) -
    3 * Math.pow(1 + Math.pow(X / 3, 6), 1 / 6) +
    2
  );
}

function estimateMos({ networkDelayMs, jitterBufferMs, packetLossPct, codec = "g711" }) {
  const { Ie, Bpl, overhead } = CODECS[codec];
  const Ta = networkDelayMs + jitterBufferMs + overhead;
  const Idd = delayImpairment(Ta);
  const IeEff = packetLossPct === 0
    ? Ie
    : Ie + (95 - Ie) * (packetLossPct / (packetLossPct + Bpl));

  const R = Math.max(0, Math.min(100, 93.2 - Idd - IeEff));
  const mos = R <= 0 ? 1 : R >= 100 ? 4.5 : 1 + 0.035 * R + R * (R - 60) * (100 - R) * 7e-6;

  return {
    Ta,
    Idd: +Idd.toFixed(2),
    IeEff: +IeEff.toFixed(2),
    R: +R.toFixed(1),
    mos: +mos.toFixed(2),
  };
}
Enter fullscreen mode Exit fullscreen mode

Comparing G.711 and G.729A across network conditions

Let's run five network scenarios through estimateMos:

const scenarios = [
  { name: "Clean fiber (G.711)",            networkDelayMs: 25,  jitterBufferMs: 30, packetLossPct: 0, codec: "g711"  },
  { name: "Clean fiber (G.729A)",           networkDelayMs: 25,  jitterBufferMs: 30, packetLossPct: 0, codec: "g729a" },
  { name: "2% packet loss (G.711)",         networkDelayMs: 40,  jitterBufferMs: 40, packetLossPct: 2, codec: "g711"  },
  { name: "2% packet loss (G.729A)",        networkDelayMs: 40,  jitterBufferMs: 40, packetLossPct: 2, codec: "g729a" },
  { name: "High latency + 3% loss (G.711)", networkDelayMs: 160, jitterBufferMs: 60, packetLossPct: 3, codec: "g711"  },
];

for (const s of scenarios) {
  console.log(s.name, estimateMos(s));
}
Enter fullscreen mode Exit fullscreen mode

Here is what the model outputs:

Scenario Mouth-to-ear Ta Delay (Idd) Codec + loss (Ie,eff) R-factor Estimated MOS-CQE
Clean fiber (G.711, 0% loss) 75 ms 0.00 0.00 93.2 4.41
Clean fiber (G.729A, 0% loss) 90 ms 0.00 11.00 82.2 4.10
2% packet loss (G.711) 100 ms 0.00 7.01 86.2 4.23
2% packet loss (G.729A) 115 ms 0.00 19.00 74.2 3.79
High latency + 3% loss (G.711) 240 ms 7.69 10.14 75.4 3.84

Two practical takeaways jump out of the numbers:

  1. Packet loss hurts far more than moderate latency. Going from 0% to 2% packet loss on G.711 drops R by 7 points (93.2 -> 86.2), while increasing total one-way delay from 20 ms all the way to 100 ms costs 0 points of Idd.
  2. Low-bitrate compression (G.729A) starts with an 11-point handicap (Ie = 11) and lower loss robustness (Bpl = 19.0). At 2% packet loss, G.711 still sits comfortably at 4.23 MOS-CQE, while G.729A drops to 3.79. Unless your WAN link is genuinely bandwidth-constrained (around 30 kbps per call on G.729 vs ~90 kbps per call with headers on G.711), G.711 leaves much more headroom for real-world network jitter and loss.

Watch out for two common input mistakes

  • Passing ping RTT directly as networkDelayMs: ping reports round-trip time, whereas Ta in the E-model is one-way delay (RTT / 2 is a rough approximation). Also make sure your delay measurement doesn't already include endpoint playout buffering, or you will count jitterBufferMs twice.
  • Calling the output "measured MOS": The E-model computes MOS-CQE (estimated from network parameters), not MOS-LQO (PESQ/POLQA audio signal comparison) or MOS-LQS (human listening panels under ITU-T P.800).

If you would rather not run code

We built two free browser calculators around these formulas—no login or email required, and shareable via URL parameters:

  • MOS Score Calculator: plug in one-way network delay, jitter buffer size, codec, and packet loss to see the full step-by-step Ta, Idd, Ie,eff, R-factor, and MOS-CQE breakdown.
  • SIP Trunk Bandwidth Calculator: size concurrent SIP channels (using Erlang B at P.01 / P.005 / P.001) and calculate required voice bandwidth across G.711, G.729, and Opus.

For a deeper dive into jitter buffers, DSCP QoS tagging, and troubleshooting choppy audio, see our VoIP call quality guide or explore all of our calculators on the EaseDial free tools hub.

Disclosure: I work with the team at EaseDial, which publishes the calculators and guide linked above.

Top comments (0)