/* For further information see John C. Bellamy's Digital Telephony, 1982, John Wiley & Sons, pps 98-111 and 472-476.  */
unsigned char linear2alaw(int pcm_val)
/* For further information see John C. Bellamy's Digital Telephony, 1982, John Wiley & Sons, pps 98-111 and 472-476.  */
unsigned char linear2alaw(int pcm_val)
{
	int		mask;
	int		seg;
	unsigned char	aval;
	if (pcm_val >= 0) {
		mask = 0xD5;
	} else {
		mask = 0x55;
		pcm_val = -pcm_val - 8;
	}
	seg = search(pcm_val, seg_end, 8);
	if (seg >= 8)
		return (0x7F ^ mask);
	else {
		aval = seg << SEG_SHIFT;
		if (seg < 2)
			aval |= (pcm_val >> 4) & QUANT_MASK;
		else
			aval |= (pcm_val >> (seg + 3)) & QUANT_MASK;
		return (aval ^ mask);
	}
}