47 #ifndef G711_NEW_ALGORITHM 54 static int exp_lut[256] = {
55 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
56 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
57 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
58 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
59 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
60 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
61 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
62 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
63 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
64 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
65 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
66 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
67 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
68 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
69 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
70 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 };
71 int sign, exponent, mantissa;
72 unsigned char ulawbyte;
75 sign = (sample >> 8) & 0x80;
82 sample = sample +
BIAS;
83 exponent = exp_lut[(sample >> 7) & 0xFF];
84 mantissa = (sample >> (exponent + 3)) & 0x0F;
85 ulawbyte = ~(sign | (exponent << 4) | mantissa);
100 static unsigned char linear2ulaw(
short sample,
int full_coding)
102 static const unsigned exp_lut[256] = {
103 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
104 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
105 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
106 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
107 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
108 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
109 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
110 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
111 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
112 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
113 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
114 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
115 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
116 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
117 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
118 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 };
119 unsigned sign, exponent, mantissa, mag;
120 unsigned char ulawbyte;
123 ast_ulaw_get_sign_mag(sample, &sign, &mag);
127 sign = (sample >> 8) & 0x80;
135 exponent = exp_lut[(mag >> 7) & 0xFF];
136 mantissa = (mag >> (exponent + 3)) & 0x0F;
140 ulawbyte = ~(sign | (exponent << 4) | mantissa);
147 ulawbyte = (exponent << 4) | mantissa;
153 static inline short ulaw2linear(
unsigned char ulawbyte)
155 unsigned exponent, mantissa;
157 static const short etab[]={0,132,396,924,1980,4092,8316,16764};
159 ulawbyte = ~ulawbyte;
160 exponent = (ulawbyte & 0x70) >> 4;
161 mantissa = ulawbyte & 0x0f;
162 sample = mantissa << (exponent + 3);
163 sample += etab[exponent];
180 #ifndef G711_NEW_ALGORITHM 181 for (i = 0;i < 256;i++) {
183 static const short etab[]={0,132,396,924,1980,4092,8316,16764};
188 y = f * (1 << (e + 3));
190 if (mu & 0x80) y = -y;
194 for (i = -32768; i < 32768; i++) {
199 for (i = 0; i < 256; i++) {
208 #ifdef TEST_CODING_TABLES 209 for (i = -32768; i < 32768; ++i) {
210 #ifndef G711_NEW_ALGORITHM 215 short d1 = ulaw2linear(e1);
217 short d2 = ulaw2linear(e2);
220 if (e1 != e2 || d1 != d3 || d2 != d3) {
221 ast_log(
LOG_WARNING,
"u-Law coding tables test failed on %d: e1=%u, e2=%u, d1=%d, d2=%d\n",
222 i, (
unsigned)e1, (
unsigned)e2, (
int)d1, (
int)d2);
228 #ifdef TEST_TANDEM_TRANSCODING 230 for (i = -32768; i < 32768; ++i) {
238 if (i < 0 && e1 == 0x7f && e2 == 0xff && e3 == 0xff)
241 if (e1 != e2 || e2 != e3 || d1 != d2 || d2 != d3) {
242 ast_log(
LOG_WARNING,
"u-Law tandem transcoding test failed on %d: e1=%u, e2=%u, d1=%d, d2=%d, d3=%d\n",
243 i, (
unsigned)e1, (
unsigned)e2, (
int)d1, (
int)d2, (
int)d3);
Asterisk main include file. File version handling, generic pbx functions.
static unsigned char linear2ulaw(short sample)
u-Law to Signed linear conversion
void ast_ulaw_init(void)
Set up mu-law conversion table.
unsigned char __ast_lin2mu[16384]
converts signed linear to mulaw
Support for logging to various files, console and syslog Configuration in file logger.conf.
#define AST_ULAW_TAB_SIZE