34 #include "asterisk/ulaw.h"
49 #ifndef G711_NEW_ALGORITHM
56 static int exp_lut[256] = {
57 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
58 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
59 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
60 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
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 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
64 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
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 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
72 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 };
73 int sign, exponent, mantissa;
74 unsigned char ulawbyte;
77 sign = (sample >> 8) & 0x80;
84 sample = sample +
BIAS;
85 exponent = exp_lut[(sample >> 7) & 0xFF];
86 mantissa = (sample >> (exponent + 3)) & 0x0F;
87 ulawbyte = ~(sign | (exponent << 4) | mantissa);
100 short __ast_mulaw[256];
102 static unsigned char linear2ulaw(
short sample,
int full_coding)
104 static const unsigned exp_lut[256] = {
105 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
106 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
107 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
108 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
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 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
112 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
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 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
120 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 };
121 unsigned sign, exponent, mantissa, mag;
122 unsigned char ulawbyte;
125 ast_ulaw_get_sign_mag(sample, &sign, &mag);
129 sign = (sample >> 8) & 0x80;
137 exponent = exp_lut[(mag >> 7) & 0xFF];
138 mantissa = (mag >> (exponent + 3)) & 0x0F;
142 ulawbyte = ~(sign | (exponent << 4) | mantissa);
149 ulawbyte = (exponent << 4) | mantissa;
155 static inline short ulaw2linear(
unsigned char ulawbyte)
157 unsigned exponent, mantissa;
159 static const short etab[]={0,132,396,924,1980,4092,8316,16764};
161 ulawbyte = ~ulawbyte;
162 exponent = (ulawbyte & 0x70) >> 4;
163 mantissa = ulawbyte & 0x0f;
164 sample = mantissa << (exponent + 3);
165 sample += etab[exponent];
182 #ifndef G711_NEW_ALGORITHM
183 for (i = 0;i < 256;i++) {
185 static const short etab[]={0,132,396,924,1980,4092,8316,16764};
190 y = f * (1 << (e + 3));
192 if (mu & 0x80) y = -y;
196 for (i = -32768; i < 32768; i++) {
197 __ast_lin2mu[((
unsigned short)i) >> 2] =
linear2ulaw(i);
201 for (i = 0; i < 256; i++) {
202 __ast_mulaw[i] = ulaw2linear(i);
210 #ifdef TEST_CODING_TABLES
211 for (i = -32768; i < 32768; ++i) {
212 #ifndef G711_NEW_ALGORITHM
217 short d1 = ulaw2linear(e1);
219 short d2 = ulaw2linear(e2);
222 if (e1 != e2 || d1 != d3 || d2 != d3) {
223 ast_log(
LOG_WARNING,
"u-Law coding tables test failed on %d: e1=%u, e2=%u, d1=%d, d2=%d\n",
224 i, (
unsigned)e1, (
unsigned)e2, (
int)d1, (
int)d2);
230 #ifdef TEST_TANDEM_TRANSCODING
232 for (i = -32768; i < 32768; ++i) {
240 if (i < 0 && e1 == 0x7f && e2 == 0xff && e3 == 0xff)
243 if (e1 != e2 || e2 != e3 || d1 != d2 || d2 != d3) {
244 ast_log(
LOG_WARNING,
"u-Law tandem transcoding test failed on %d: e1=%u, e2=%u, d1=%d, d2=%d, d3=%d\n",
245 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)
void ast_ulaw_init(void)
Set up mu-law conversion table.
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
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
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.