00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _ASTERISK_ALAW_H
00024 #define _ASTERISK_ALAW_H
00025
00026
00027
00028
00029
00030 void ast_alaw_init(void);
00031
00032 #define AST_ALAW_BIT_LOSS 4
00033 #define AST_ALAW_STEP (1 << AST_ALAW_BIT_LOSS)
00034 #define AST_ALAW_TAB_SIZE (32768 / AST_ALAW_STEP + 1)
00035 #define AST_ALAW_SIGN_BIT 0x80
00036 #define AST_ALAW_AMI_MASK 0x55
00037
00038
00039
00040 #ifndef G711_NEW_ALGORITHM
00041 extern unsigned char __ast_lin2a[8192];
00042 #else
00043 extern unsigned char __ast_lin2a[AST_ALAW_TAB_SIZE];
00044 #endif
00045
00046
00047 extern short __ast_alaw[256];
00048
00049 #ifndef G711_NEW_ALGORITHM
00050 #define AST_LIN2A(a) (__ast_lin2a[((unsigned short)(a)) >> 3])
00051 #else
00052 #define AST_LIN2A_LOOKUP(mag) \
00053 __ast_lin2a[(mag) >> AST_ALAW_BIT_LOSS]
00054
00055
00056 static inline void ast_alaw_get_sign_mag(short sample, unsigned *sign, unsigned *mag)
00057 {
00058
00059
00060
00061 *sign = ((unsigned short)sample >> 8) & AST_ALAW_SIGN_BIT;
00062 #if defined(G711_REDUCED_BRANCHING)
00063 {
00064 unsigned dual_mag = (-sample << 16) | (unsigned short)sample;
00065 *mag = (dual_mag >> (*sign >> 3)) & 0xffffU;
00066 }
00067 #else
00068 if (sample < 0)
00069 *mag = -sample;
00070 else
00071 *mag = sample;
00072 #endif
00073 *sign ^= AST_ALAW_SIGN_BIT;
00074 }
00075
00076 static inline unsigned char AST_LIN2A(short sample)
00077 {
00078 unsigned mag, sign;
00079 ast_alaw_get_sign_mag(sample, &sign, &mag);
00080 return (sign | AST_LIN2A_LOOKUP(mag)) ^ AST_ALAW_AMI_MASK;
00081 }
00082 #endif
00083
00084 #define AST_ALAW(a) (__ast_alaw[(int)(a)])
00085
00086 #endif