2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief u-Law to Signed linear conversion
23 * \author Mark Spencer <markster@digium.com>
28 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
30 #include "asterisk/alaw.h"
34 static inline unsigned char linear2alaw (short int linear
)
39 static int seg_end
[8] =
41 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
47 /* Sign (7th) bit = 1 */
48 mask
= AMI_MASK
| 0x80;
57 /* Convert the scaled magnitude to segment number. */
58 for (seg
= 0; seg
< 8; seg
++)
60 if (pcm_val
<= seg_end
[seg
])
63 /* Combine the sign, segment, and quantization bits. */
64 return ((seg
<< 4) | ((pcm_val
>> ((seg
) ? (seg
+ 3) : 4)) & 0x0F)) ^ mask
;
66 /*- End of function --------------------------------------------------------*/
68 static inline short int alaw2linear (unsigned char alaw
)
74 i
= ((alaw
& 0x0F) << 4);
75 seg
= (((int) alaw
& 0x70) >> 4);
77 i
= (i
+ 0x100) << (seg
- 1);
78 return (short int) ((alaw
& 0x80) ? i
: -i
);
81 unsigned char __ast_lin2a
[8192];
82 short __ast_alaw
[256];
84 void ast_alaw_init(void)
88 * Set up mu-law conversion table
90 for(i
= 0;i
< 256;i
++)
92 __ast_alaw
[i
] = alaw2linear(i
);
94 /* set up the reverse (mu-law) conversion table */
95 for(i
= -32768; i
< 32768; i
++)
97 __ast_lin2a
[((unsigned short)i
) >> 3] = linear2alaw(i
);