Skip to main content

Posts

Showing posts with the label audio codecs

Extracting Opus from a pcap file into an audible wav

From time to time I need to verify that the audio inside a trace is as expected. Not much in terms of quality, but more often content and duration. A few years ago I wrote a small program to transform a pcap into a wav file - the codec in use was SILK. These days I'm dealing with Opus , and I have to say things are greatly simplified, in particular if you consider opus-tools , a set of utilities to handle opus files and traces. One of those tools, opusrtp , can do live captures and write the interpreted payload into a .opus file. Still, what I needed was to achieve the same result but from a pcap already existing, i.e. "offline". So I come up with a small - quite shamlessly copy&pasted - patch to opusrtc, which is now in this fork . Once you have a pcap with an RTP stream with opus (say in input.pcap ) you can retrieve the .opus equivalent (in rtpdump.opus ) with: ./opusrtp --extract input.pcap Then you can generate an audible wav file with: ./opusd...

How to compute or validate the network bandwidth when using Speex

This is a quite simple computation or validation of the network bandwidth, but can be tricky if you don't take into account the "quality" parameter used in Speex . Speex is designed to change bitrate depending on the desired quality, and there are 10 different levels of quality per type (narrowband (8 KHz), wideband (16 KHz), ultra-wideband (32 KHz)). All you have to do is take the expected encoding bitrate for that quality ( e.g. 28 Kbps for wideband at quality 8/10 ), compute the payload per frame, optionally sum the payload when you have more than 1 frame per packet, add the overhead of IP, UDP and RTP, then recompute the overall bitrate. Each Speex frame has 20 msec duration. The payload for Speex wideband at quality 8 (28 kbps) is: P = (28*10^3 kbps * 20*10^-3 msec/frame) = 70 B/frame Consider 1 frame per packet and add the overhead from IP, UDP and RTP: Ptot = 70 B + 40 B = 110 B/packet Compute the final network bandwidth: BW = (110 B)*8 / (20 * 10^...

A gentle introduction to G.729

G.729 is an 8 Kpbs audio codec, standardized by ITU , and called also CS-ACELP: Coding of Speech using Coniugate-Structure Algebraic-Code-Excited Linear Prediction , as that’s the algorithm used for audio compression. It has two extended versions: G.729A (optimized algorithm, slightly lower quality) and G.729B (extended features, higher quality), and it's popular in the VoIP world because combines very low bitrate with good quality (but alas is not royalty-free). G.729A takes as input frames of voice of 10 msec of duration, sampled at 8KHz and with each sample having 16 bit : This gives a frame size of 80 samples: 8000 sample/sec * 10 * 10e-3 sec/frame = 80 samples/frame The output is 8 Kbps, so each encoded frame is represented by 10 Bytes: 8000 bit/sec * 10 * 10e-3 sec/frame = 80 bit/frame = 10 Bytes/frame Quality Considering its bit rate, G.729 has an excellent perceived quality ( MOS ). Under normal network conditions G.729A has MOS 4.04 (while G.711 u-law, 64 kbps, has 4.4...