Wed Jan 8 2020 09:50:21

Asterisk developer's documentation


ulaw.h File Reference

u-Law to Signed linear conversion More...

Go to the source code of this file.

Macros

#define AST_LIN2MU(a)   (__ast_lin2mu[((unsigned short)(a)) >> 2])
 
#define AST_MULAW(a)   (__ast_mulaw[(a)])
 
#define AST_ULAW_BIT_LOSS   3
 
#define AST_ULAW_SIGN_BIT   0x80
 
#define AST_ULAW_STEP   (1 << AST_ULAW_BIT_LOSS)
 
#define AST_ULAW_TAB_SIZE   (32768 / AST_ULAW_STEP + 1)
 

Functions

void ast_ulaw_init (void)
 Set up mu-law conversion table. More...
 

Variables

unsigned char __ast_lin2mu [16384]
 converts signed linear to mulaw More...
 
short __ast_mulaw [256]
 

Detailed Description

u-Law to Signed linear conversion

Definition in file ulaw.h.

Macro Definition Documentation

#define AST_LIN2MU (   a)    (__ast_lin2mu[((unsigned short)(a)) >> 2])
#define AST_MULAW (   a)    (__ast_mulaw[(a)])
#define AST_ULAW_BIT_LOSS   3

Definition at line 32 of file ulaw.h.

#define AST_ULAW_SIGN_BIT   0x80

Definition at line 35 of file ulaw.h.

#define AST_ULAW_STEP   (1 << AST_ULAW_BIT_LOSS)

Definition at line 33 of file ulaw.h.

Referenced by ast_ulaw_init().

#define AST_ULAW_TAB_SIZE   (32768 / AST_ULAW_STEP + 1)

Definition at line 34 of file ulaw.h.

Function Documentation

void ast_ulaw_init ( void  )

Set up mu-law conversion table.

To init the ulaw to slinear conversion stuff, this needs to be run.

Definition at line 175 of file ulaw.c.

References AST_LIN2MU, ast_log(), AST_MULAW, AST_ULAW_STEP, f, linear2ulaw(), LOG_NOTICE, and LOG_WARNING.

Referenced by load_module(), and main().

176 {
177  int i;
178 
179  /*
180  * Set up mu-law conversion table
181  */
182 #ifndef G711_NEW_ALGORITHM
183  for (i = 0;i < 256;i++) {
184  short mu,e,f,y;
185  static const short etab[]={0,132,396,924,1980,4092,8316,16764};
186 
187  mu = 255-i;
188  e = (mu & 0x70)/16;
189  f = mu & 0x0f;
190  y = f * (1 << (e + 3));
191  y += etab[e];
192  if (mu & 0x80) y = -y;
193  __ast_mulaw[i] = y;
194  }
195  /* set up the reverse (mu-law) conversion table */
196  for (i = -32768; i < 32768; i++) {
197  __ast_lin2mu[((unsigned short)i) >> 2] = linear2ulaw(i);
198  }
199 #else
200 
201  for (i = 0; i < 256; i++) {
202  __ast_mulaw[i] = ulaw2linear(i);
203  }
204  /* set up the reverse (mu-law) conversion table */
205  for (i = 0; i <= 32768; i += AST_ULAW_STEP) {
206  AST_LIN2MU_LOOKUP(i) = linear2ulaw(i, 0 /* half-cooked */);
207  }
208 #endif
209 
210 #ifdef TEST_CODING_TABLES
211  for (i = -32768; i < 32768; ++i) {
212 #ifndef G711_NEW_ALGORITHM
213  unsigned char e1 = linear2ulaw(i);
214 #else
215  unsigned char e1 = linear2ulaw(i, 1);
216 #endif
217  short d1 = ulaw2linear(e1);
218  unsigned char e2 = AST_LIN2MU(i);
219  short d2 = ulaw2linear(e2);
220  short d3 = AST_MULAW(e1);
221 
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);
225  }
226  }
227  ast_log(LOG_NOTICE, "u-Law coding table test complete.\n");
228 #endif /* TEST_CODING_TABLES */
229 
230 #ifdef TEST_TANDEM_TRANSCODING
231  /* tandem transcoding test */
232  for (i = -32768; i < 32768; ++i) {
233  unsigned char e1 = AST_LIN2MU(i);
234  short d1 = AST_MULAW(e1);
235  unsigned char e2 = AST_LIN2MU(d1);
236  short d2 = AST_MULAW(e2);
237  unsigned char e3 = AST_LIN2MU(d2);
238  short d3 = AST_MULAW(e3);
239 
240  if (i < 0 && e1 == 0x7f && e2 == 0xff && e3 == 0xff)
241  continue; /* known and normal negative 0 case */
242 
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);
246  }
247  }
248  ast_log(LOG_NOTICE, "u-Law tandem transcoding test complete.\n");
249 #endif /* TEST_TANDEM_TRANSCODING */
250 }
static unsigned char linear2ulaw(short sample)
Definition: ulaw.c:54
#define LOG_WARNING
Definition: logger.h:144
short __ast_mulaw[256]
Definition: ulaw.c:52
#define AST_MULAW(a)
Definition: ulaw.h:85
#define AST_ULAW_STEP
Definition: ulaw.h:33
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...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
unsigned char __ast_lin2mu[16384]
converts signed linear to mulaw
Definition: ulaw.c:51
static struct ast_format f[]
Definition: format_g726.c:181
#define AST_LIN2MU(a)
Definition: ulaw.h:49

Variable Documentation

unsigned char __ast_lin2mu[16384]

converts signed linear to mulaw

Definition at line 51 of file ulaw.c.

short __ast_mulaw[256]

help

Definition at line 52 of file ulaw.c.