#include "asterisk.h"
#include "asterisk/alaw.h"
Go to the source code of this file.
Defines | |
#define | AMI_MASK 0x55 |
Functions | |
static short int | alaw2linear (unsigned char alaw) |
void | ast_alaw_init (void) |
static unsigned char | linear2alaw (short int linear) |
Variables | |
short | __ast_alaw [256] |
unsigned char | __ast_lin2a [8192] |
Definition in file alaw.c.
#define AMI_MASK 0x55 |
static short int alaw2linear | ( | unsigned char | alaw | ) | [inline, static] |
Definition at line 68 of file alaw.c.
References AMI_MASK.
Referenced by ast_alaw_init().
00069 { 00070 int i; 00071 int seg; 00072 00073 alaw ^= AMI_MASK; 00074 i = ((alaw & 0x0F) << 4) + 8 /* rounding error */; 00075 seg = (((int) alaw & 0x70) >> 4); 00076 if (seg) 00077 i = (i + 0x100) << (seg - 1); 00078 return (short int) ((alaw & 0x80) ? i : -i); 00079 }
void ast_alaw_init | ( | void | ) |
To init the ulaw to slinear conversion stuff, this needs to be run.
Definition at line 84 of file alaw.c.
References alaw2linear(), and linear2alaw().
Referenced by main().
00085 { 00086 int i; 00087 /* 00088 * Set up mu-law conversion table 00089 */ 00090 for(i = 0;i < 256;i++) 00091 { 00092 __ast_alaw[i] = alaw2linear(i); 00093 } 00094 /* set up the reverse (mu-law) conversion table */ 00095 for(i = -32768; i < 32768; i++) 00096 { 00097 __ast_lin2a[((unsigned short)i) >> 3] = linear2alaw(i); 00098 } 00099 00100 }
static unsigned char linear2alaw | ( | short int | linear | ) | [inline, static] |
Definition at line 34 of file alaw.c.
References AMI_MASK.
Referenced by ast_alaw_init().
00035 { 00036 int mask; 00037 int seg; 00038 int pcm_val; 00039 static int seg_end[8] = 00040 { 00041 0xFF, 0x1FF, 0x3FF, 0x7FF, 0xFFF, 0x1FFF, 0x3FFF, 0x7FFF 00042 }; 00043 00044 pcm_val = linear; 00045 if (pcm_val >= 0) 00046 { 00047 /* Sign (7th) bit = 1 */ 00048 mask = AMI_MASK | 0x80; 00049 } 00050 else 00051 { 00052 /* Sign bit = 0 */ 00053 mask = AMI_MASK; 00054 pcm_val = -pcm_val; 00055 } 00056 00057 /* Convert the scaled magnitude to segment number. */ 00058 for (seg = 0; seg < 8; seg++) 00059 { 00060 if (pcm_val <= seg_end[seg]) 00061 break; 00062 } 00063 /* Combine the sign, segment, and quantization bits. */ 00064 return ((seg << 4) | ((pcm_val >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask; 00065 }
short __ast_alaw[256] |
unsigned char __ast_lin2a[8192] |