ulaw.h
Go to the documentation of this file.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_ULAW_H
00024 #define _ASTERISK_ULAW_H
00025
00026
00027
00028
00029
00030 void ast_ulaw_init(void);
00031
00032 #define AST_ULAW_BIT_LOSS 3
00033 #define AST_ULAW_STEP (1 << AST_ULAW_BIT_LOSS)
00034 #define AST_ULAW_TAB_SIZE (32768 / AST_ULAW_STEP + 1)
00035 #define AST_ULAW_SIGN_BIT 0x80
00036
00037
00038 #ifndef G711_NEW_ALGORITHM
00039 extern unsigned char __ast_lin2mu[16384];
00040 #else
00041 extern unsigned char __ast_lin2mu[AST_ULAW_TAB_SIZE];
00042 #endif
00043
00044
00045 extern short __ast_mulaw[256];
00046
00047 #ifndef G711_NEW_ALGORITHM
00048
00049 #define AST_LIN2MU(a) (__ast_lin2mu[((unsigned short)(a)) >> 2])
00050
00051 #else
00052
00053 #define AST_LIN2MU_LOOKUP(mag) \
00054 __ast_lin2mu[((mag) + AST_ULAW_STEP / 2) >> AST_ULAW_BIT_LOSS]
00055
00056
00057
00058 static inline void ast_ulaw_get_sign_mag(short sample, unsigned *sign, unsigned *mag)
00059 {
00060
00061
00062
00063 *sign = ((unsigned short)sample >> 8) & AST_ULAW_SIGN_BIT;
00064 #if defined(G711_REDUCED_BRANCHING)
00065 {
00066 unsigned dual_mag = (-sample << 16) | (unsigned short)sample;
00067 *mag = (dual_mag >> (*sign >> 3)) & 0xffffU;
00068 }
00069 #else
00070 if (sample < 0)
00071 *mag = -sample;
00072 else
00073 *mag = sample;
00074 #endif
00075 }
00076
00077 static inline unsigned char AST_LIN2MU(short sample)
00078 {
00079 unsigned mag, sign;
00080 ast_ulaw_get_sign_mag(sample, &sign, &mag);
00081 return ~(sign | AST_LIN2MU_LOOKUP(mag));
00082 }
00083 #endif
00084
00085 #define AST_MULAW(a) (__ast_mulaw[(a)])
00086
00087 #endif