35 #ifndef G711_NEW_ALGORITHM 43 static int seg_end[8] =
45 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
59 for (seg = 0; seg < 8; seg++) {
60 if (pcm_val <= seg_end[seg]) {
65 return ((seg << 4) | ((pcm_val >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask;
68 static unsigned char linear2alaw(
short sample,
int full_coding)
70 static const unsigned exp_lut[128] = {
87 unsigned sign, exponent, mantissa, mag;
88 unsigned char alawbyte;
90 ast_alaw_get_sign_mag(sample, &sign, &mag);
94 exponent = exp_lut[(mag >> 8) & 0x7f];
95 mantissa = (mag >> (exponent + 3)) & 0x0f;
101 alawbyte = (
unsigned char)(sign | (exponent << 4) | mantissa);
105 alawbyte = (exponent << 4) | mantissa;
111 #ifndef G711_NEW_ALGORITHM 118 i = ((alaw & 0x0F) << 4) + 8 ;
119 seg = (((int) alaw & 0x70) >> 4);
121 i = (i + 0x100) << (seg - 1);
123 return (
short int) ((alaw & 0x80) ? i : -i);
126 static inline short alaw2linear(
unsigned char alawbyte)
128 unsigned exponent, mantissa;
132 exponent = (alawbyte & 0x70) >> 4;
133 mantissa = alawbyte & 0x0f;
134 sample = (mantissa << 4) + 8 ;
136 sample = (sample + 0x100) << (exponent - 1);
137 if (!(alawbyte & 0x80))
145 #ifndef G711_NEW_ALGORITHM 158 #ifndef G711_NEW_ALGORITHM 159 for (i = 0; i < 256; i++) {
163 for (i = -32768; i < 32768; i++) {
167 for (i = 0; i < 256; i++) {
176 #ifdef TEST_CODING_TABLES 177 for (i = -32768; i < 32768; ++i) {
178 #ifndef G711_NEW_ALGORITHM 188 if (e1 != e2 || d1 != d3 || d2 != d3) {
189 ast_log(
LOG_WARNING,
"a-Law coding tables test failed on %d: e1=%u, e2=%u, d1=%d, d2=%d\n",
190 i, (
unsigned)e1, (
unsigned)e2, (
int)d1, (
int)d2);
196 #ifdef TEST_TANDEM_TRANSCODING 198 for (i = -32768; i < 32768; ++i) {
206 if (e1 != e2 || e2 != e3 || d1 != d2 || d2 != d3) {
207 ast_log(
LOG_WARNING,
"a-Law tandem transcoding test failed on %d: e1=%u, e2=%u, d1=%d, d2=%d, d3=%d\n",
208 i, (
unsigned)e1, (
unsigned)e2, (
int)d1, (
int)d2, (
int)d3);
A-Law to Signed linear conversion.
Asterisk main include file. File version handling, generic pbx functions.
unsigned char __ast_lin2a[8192]
converts signed linear to alaw
#define AST_ALAW_AMI_MASK
static struct ast_codec alaw
static short int alaw2linear(unsigned char alaw)
#define AST_ALAW_TAB_SIZE
Support for logging to various files, console and syslog Configuration in file logger.conf.
void ast_alaw_init(void)
To init the alaw to slinear conversion stuff, this needs to be run.
static unsigned char linear2alaw(short int linear)