/* For further information see John C. Bellamy's Digital Telephony, 1982, John Wiley & Sons, pps 98-111 and 472-476.  */
unsigned char linear2ulaw(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 linear2ulaw(int pcm_val)
{
	int		mask;
	int		seg;
	unsigned char	uval;
	if (pcm_val < 0) {
		pcm_val = BIAS - pcm_val;
		mask = 0x7F;
	} else {
		pcm_val += BIAS;
		mask = 0xFF;
	}
	seg = search(pcm_val, seg_end, 8);
	if (seg >= 8)
		return (0x7F ^ mask);
	else {
		uval = (seg << 4) | ((pcm_val >> (seg + 3)) & 0xF);
		return (uval ^ mask);
	}
}