2
* Asterisk -- A telephony toolkit for Linux.
4
* u-Law to Signed linear conversion
6
* Copyright (C) 1999, Mark Spencer
8
* Mark Spencer <markster@linux-support.net>
10
* This program is free software, distributed under the terms of
11
* the GNU General Public License
14
#include <asterisk/alaw.h>
18
static inline unsigned char linear2alaw (short int linear)
23
static int seg_end[8] =
25
0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
31
/* Sign (7th) bit = 1 */
32
mask = AMI_MASK | 0x80;
41
/* Convert the scaled magnitude to segment number. */
42
for (seg = 0; seg < 8; seg++)
44
if (pcm_val <= seg_end[seg])
47
/* Combine the sign, segment, and quantization bits. */
48
return ((seg << 4) | ((pcm_val >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask;
50
/*- End of function --------------------------------------------------------*/
52
static inline short int alaw2linear (unsigned char alaw)
58
i = ((alaw & 0x0F) << 4);
59
seg = (((int) alaw & 0x70) >> 4);
61
i = (i + 0x100) << (seg - 1);
62
return (short int) ((alaw & 0x80) ? i : -i);
65
unsigned char __ast_lin2a[8192];
66
short __ast_alaw[256];
68
void ast_alaw_init(void)
72
* Set up mu-law conversion table
74
for(i = 0;i < 256;i++)
76
__ast_alaw[i] = alaw2linear(i);
78
/* set up the reverse (mu-law) conversion table */
79
for(i = -32768; i < 32768; i++)
81
__ast_lin2a[((unsigned short)i) >> 3] = linear2alaw(i);