/* For further information see John C. Bellamy's Digital Telephony, 1982, John Wiley & Sons, pps 98-111 and 472-476.  */
static 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.  */
static 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;
	}
	if (pcm_val > 0x7FFF)
		pcm_val = 0x7FFF;
	seg = val_seg(pcm_val);
	uval = (seg << 4) | ((pcm_val >> (seg + 3)) & 0xF);
	return uval ^ mask;
}