Pure C G.711 mu-law/a-law encoder/decoder and L16 linear PCM utilities with canonical ITU algorithms. No external dependencies, fully unit-tested off-platform.
/*
* es_codec โ G.711 mu-law / a-law + L16. Canonical ITU/Sun algorithms
* (public-domain lineage), reimplemented and unit-tested.
*
* Copyright (c) 2026 Varun Pratap Singh. MIT License.
*/
#include "es_codec.h"
#include <string.h>
#include <strings.h>
/* ---- G.711 mu-law ------------------------------------------------------- */
#define ULAW_BIAS 0x84
#define ULAW_CLIP 32635
/* exponent of the highest segment for a given (biased) magnitude high byte */
static const uint8_t ulaw_exp[256] = {
0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key