34 #include "asterisk/alaw.h"
37 #ifndef G711_NEW_ALGORITHM
45 static int seg_end[8] =
47 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF
61 for (seg = 0; seg < 8; seg++) {
62 if (pcm_val <= seg_end[seg]) {
67 return ((seg << 4) | ((pcm_val >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask;
70 static unsigned char linear2alaw(
short sample,
int full_coding)
72 static const unsigned exp_lut[128] = {
89 unsigned sign, exponent, mantissa, mag;
90 unsigned char alawbyte;
92 ast_alaw_get_sign_mag(sample, &sign, &mag);
96 exponent = exp_lut[(mag >> 8) & 0x7f];
97 mantissa = (mag >> (exponent + 3)) & 0x0f;
103 alawbyte = (
unsigned char)(sign | (exponent << 4) | mantissa);
107 alawbyte = (exponent << 4) | mantissa;
113 #ifndef G711_NEW_ALGORITHM
120 i = ((alaw & 0x0F) << 4) + 8 ;
121 seg = (((int) alaw & 0x70) >> 4);
123 i = (i + 0x100) << (seg - 1);
125 return (
short int) ((alaw & 0x80) ? i : -i);
128 static inline short alaw2linear(
unsigned char alawbyte)
130 unsigned exponent, mantissa;
134 exponent = (alawbyte & 0x70) >> 4;
135 mantissa = alawbyte & 0x0f;
136 sample = (mantissa << 4) + 8 ;
138 sample = (sample + 0x100) << (exponent - 1);
139 if (!(alawbyte & 0x80))
147 #ifndef G711_NEW_ALGORITHM
160 #ifndef G711_NEW_ALGORITHM
161 for (i = 0; i < 256; i++) {
165 for (i = -32768; i < 32768; i++) {
166 __ast_lin2a[((
unsigned short)i) >> 3] =
linear2alaw(i);
169 for (i = 0; i < 256; i++) {
178 #ifdef TEST_CODING_TABLES
179 for (i = -32768; i < 32768; ++i) {
180 #ifndef G711_NEW_ALGORITHM
190 if (e1 != e2 || d1 != d3 || d2 != d3) {
191 ast_log(
LOG_WARNING,
"a-Law coding tables test failed on %d: e1=%u, e2=%u, d1=%d, d2=%d\n",
192 i, (
unsigned)e1, (
unsigned)e2, (
int)d1, (
int)d2);
198 #ifdef TEST_TANDEM_TRANSCODING
200 for (i = -32768; i < 32768; ++i) {
208 if (e1 != e2 || e2 != e3 || d1 != d2 || d2 != d3) {
209 ast_log(
LOG_WARNING,
"a-Law tandem transcoding test failed on %d: e1=%u, e2=%u, d1=%d, d2=%d, d3=%d\n",
210 i, (
unsigned)e1, (
unsigned)e2, (
int)d1, (
int)d2, (
int)d3);
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
void ast_alaw_init(void)
To init the alaw to slinear conversion stuff, this needs to be run.
static short int alaw2linear(unsigned char alaw)
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...
#define AST_ALAW_TAB_SIZE
Support for logging to various files, console and syslog Configuration in file logger.conf.
static unsigned char linear2alaw(short int linear)
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.