view miscutil/pcm16-to-alaw.c @ 231:67cbfa0aeb1c

pcm16-to-ulaw: fix usage message
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 May 2023 18:08:12 +0000
parents dc52c3857bf7
children
line wrap: on
line source

/*
 * This program reads a 16-bit PCM recording in raw format (robe by default,
 * or LE with -l option) and converts it to 8-bit PCM in European A-law
 * encoding.  It is based on toast_alaw.c from libgsm/toast package by
 * Jutta Degener and Carsten Bormann, Technische Universitaet Berlin.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

#define	S2A(x)	(s2a[ ((unsigned short)(x)) >> 4 ])

static unsigned char s2a[] = {
	213,212,215,214,209,208,211,210,221,220,223,222,217,216,219,218,
	197,196,199,198,193,192,195,194,205,204,207,206,201,200,203,202,
	245,245,244,244,247,247,246,246,241,241,240,240,243,243,242,242,
	253,253,252,252,255,255,254,254,249,249,248,248,251,251,250,250,
	229,229,229,229,228,228,228,228,231,231,231,231,230,230,230,230,
	225,225,225,225,224,224,224,224,227,227,227,227,226,226,226,226,
	237,237,237,237,236,236,236,236,239,239,239,239,238,238,238,238,
	233,233,233,233,232,232,232,232,235,235,235,235,234,234,234,234,
	149,149,149,149,149,149,149,149,148,148,148,148,148,148,148,148,
	151,151,151,151,151,151,151,151,150,150,150,150,150,150,150,150,
	145,145,145,145,145,145,145,145,144,144,144,144,144,144,144,144,
	147,147,147,147,147,147,147,147,146,146,146,146,146,146,146,146,
	157,157,157,157,157,157,157,157,156,156,156,156,156,156,156,156,
	159,159,159,159,159,159,159,159,158,158,158,158,158,158,158,158,
	153,153,153,153,153,153,153,153,152,152,152,152,152,152,152,152,
	155,155,155,155,155,155,155,155,154,154,154,154,154,154,154,154,
	133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,133,
	132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,132,
	135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,135,
	134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,134,
	129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,129,
	128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,
	131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,131,
	130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,130,
	141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,141,
	140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,140,
	143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,143,
	142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,142,
	137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,137,
	136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,136,
	139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,139,
	138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,138,
	181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,
	181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,181,
	180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,
	180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,180,
	183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,
	183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,183,
	182,182,182,182,182,182,182,182,182,182,182,182,182,182,182,182,
	182,182,182,182,182,182,182,182,182,182,182,182,182,182,182,182,
	177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,
	177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,177,
	176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,
	176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,176,
	179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,
	179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,179,
	178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,
	178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,
	189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,
	189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,189,
	188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,
	188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,188,
	191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,
	191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,191,
	190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,
	190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,190,
	185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,
	185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,185,
	184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,
	184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,184,
	187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,
	187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,187,
	186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,
	186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,186,
	165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,
	165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,
	165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,
	165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,165,
	164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,
	164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,
	164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,
	164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,164,
	167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,
	167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,
	167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,
	167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,167,
	166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,
	166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,
	166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,
	166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,166,
	161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,
	161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,
	161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,
	161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,161,
	160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,
	160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,
	160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,
	160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,160,
	163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,
	163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,
	163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,
	163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,163,
	162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,
	162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,
	162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,
	162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,162,
	173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,
	173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,
	173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,
	173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,173,
	172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,
	172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,
	172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,
	172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,172,
	175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
	175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
	175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
	175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
	174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,
	174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,
	174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,
	174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,174,
	169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,
	169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,
	169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,
	169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,169,
	168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,
	168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,
	168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,
	168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,168,
	171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,
	171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,
	171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,
	171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,171,
	170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,
	170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,
	170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,
	170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,170,
	 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
	 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
	 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
	 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
	 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
	 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
	 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
	 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
	 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
	 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
	 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
	 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
	 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
	 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
	 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
	 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
	 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
	 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
	 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
	 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
	 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
	 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
	 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
	 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
	 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
	 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
	 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
	 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
	 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
	 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
	 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
	 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
	 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
	 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
	 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
	 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34,
	 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
	 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
	 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
	 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
	 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
	 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
	 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
	 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
	 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
	 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
	 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
	 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
	 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
	 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
	 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
	 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
	 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
	 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
	 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
	 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39,
	 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
	 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
	 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
	 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
	 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
	 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
	 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
	 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
	 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
	 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 58,
	 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
	 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
	 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
	 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56,
	 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57,
	 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57, 57,
	 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
	 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
	 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
	 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
	 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
	 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,
	 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
	 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
	 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
	 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
	 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
	 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51,
	 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
	 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
	 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
	 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
	 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
	 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54,
	 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
	 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55,
	 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
	 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
	 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,
	 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,
	 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
	 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
	  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
	  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
	 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
	 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
	 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
	 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
	  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,
	  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,
	  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
	  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
	  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,
	  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,  7,
	  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,
	 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
	 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25,
	 30, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31,
	 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29,
	 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19,
	 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17,
	 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
	 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21,
	106,106,106,106,107,107,107,107,104,104,104,104,105,105,105,105,
	110,110,110,110,111,111,111,111,108,108,108,108,109,109,109,109,
	 98, 98, 98, 98, 99, 99, 99, 99, 96, 96, 96, 96, 97, 97, 97, 97,
	102,102,102,102,103,103,103,103,100,100,100,100,101,101,101,101,
	122,122,123,123,120,120,121,121,126,126,127,127,124,124,125,125,
	114,114,115,115,112,112,113,113,118,118,119,119,116,116,117,117,
	 74, 75, 72, 73, 78, 79, 76, 77, 66, 67, 64, 65, 70, 71, 68, 69,
	 90, 91, 88, 89, 94, 95, 92, 93, 82, 83, 80, 81, 86, 87, 84, 85
};

main(argc, argv)
	char **argv;
{
	int little_endian;
	char *infname, *outfname;
	FILE *inf, *outf;
	uint8_t inb[2];
	uint16_t ins;
	int cc;

	if (argc == 3 && argv[1][0] != '-') {
		little_endian = 0;
		infname = argv[1];
		outfname = argv[2];
	} else if (argc == 4 && !strcmp(argv[1], "-l")) {
		little_endian = 1;
		infname = argv[2];
		outfname = argv[3];
	} else {
		fprintf(stderr, "usage: %s [-l] input.pcm16 output.alaw\n",
			argv[0]);
		exit(1);
	}
	inf = fopen(infname, "r");
	if (!inf) {
		perror(infname);
		exit(1);
	}
	outf = fopen(outfname, "w");
	if (!outf) {
		perror(outfname);
		exit(1);
	}
	for (;;) {
		cc = fread(inb, 1, 2, inf);
		if (cc <= 0)
			break;
		if (cc & 1) {
			fprintf(stderr, "error: %s has odd number of bytes\n",
				infname);
			exit(1);
		}
		if (little_endian)
			ins = ((uint16_t) inb[1] << 8) | ((uint16_t) inb[0]);
		else
			ins = ((uint16_t) inb[0] << 8) | ((uint16_t) inb[1]);
		putc(S2A(ins), outf);
	}
	fclose(outf);
	exit(0);
}