#include <stdlib.h>
#include <stdio.h>

/*--------------------------------------------------------------------------*/
/* The following routine was extracted from posting by Brian Foley.         */
/* Brian Foley		email: bfoley@greatlakes.Central.Sun.COM            */
/* Systems Engineer	smail:	1000 Town Center                            */
/* Sun Microsystems		Suite 1700                                  */
/* GreatLakes Region		Southfield, MI 48075   (313) 352-7070       */
/*--------------------------------------------------------------------------*/

int ulaw2linear(unsigned char ulawbyte)
{
	static int exp_lut[8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 };
	       int sign, exponent, mantissa, sample;

	ulawbyte	= ~ulawbyte;
	sign		=  ulawbyte & 0x80;
	exponent	= (ulawbyte >> 4) & 0x07;
	mantissa	=  ulawbyte & 0x0F;
	sample		= exp_lut[exponent] + (mantissa << (exponent + 3));
	if ( sign ) sample = -sample;
	return sample;
}

main()
{
int i;

	printf("/*\n"
		" * u-law to linear conversion table\n"
		" * generated "__TIME__", "__DATE__"\n"
		" * by D. Champion's gentab\n"
		" * using B. Foley's ulaw2linear()\n"
		" * and a custom formatting routine\n"
		" *\n"
		" * use this table in place of ulaw2linear()\n"
		" * to speed up processing\n"
		" */\n\n");
	printf("signed long ulaw_tab[] = {\n\t");

	for (i=0; i<256; i++) {
		printf("0x%08x, ", ulaw2linear(i));
		if ( i%4 == 3 ) printf("\n\t");
	}

	printf("0x00000000\n};\n");

	exit(0);
}
