Wed Jan 8 2020 09:49:52

Asterisk developer's documentation


alaw.h File Reference

A-Law to Signed linear conversion. More...

Go to the source code of this file.

Macros

#define AST_ALAW(a)   (__ast_alaw[(int)(a)])
 
#define AST_ALAW_AMI_MASK   0x55
 
#define AST_ALAW_BIT_LOSS   4
 
#define AST_ALAW_SIGN_BIT   0x80
 
#define AST_ALAW_STEP   (1 << AST_ALAW_BIT_LOSS)
 
#define AST_ALAW_TAB_SIZE   (32768 / AST_ALAW_STEP + 1)
 
#define AST_LIN2A(a)   (__ast_lin2a[((unsigned short)(a)) >> 3])
 

Functions

void ast_alaw_init (void)
 To init the alaw to slinear conversion stuff, this needs to be run. More...
 

Variables

short __ast_alaw [256]
 
unsigned char __ast_lin2a [8192]
 converts signed linear to alaw More...
 

Detailed Description

A-Law to Signed linear conversion.

Definition in file alaw.h.

Macro Definition Documentation

#define AST_ALAW (   a)    (__ast_alaw[(int)(a)])
#define AST_ALAW_AMI_MASK   0x55

Definition at line 36 of file alaw.h.

#define AST_ALAW_BIT_LOSS   4

Definition at line 32 of file alaw.h.

#define AST_ALAW_SIGN_BIT   0x80

Definition at line 35 of file alaw.h.

#define AST_ALAW_STEP   (1 << AST_ALAW_BIT_LOSS)

Definition at line 33 of file alaw.h.

Referenced by ast_alaw_init().

#define AST_ALAW_TAB_SIZE   (32768 / AST_ALAW_STEP + 1)

Definition at line 34 of file alaw.h.

#define AST_LIN2A (   a)    (__ast_lin2a[((unsigned short)(a)) >> 3])

Function Documentation

void ast_alaw_init ( void  )

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

Definition at line 154 of file alaw.c.

References alaw2linear(), AST_ALAW, AST_ALAW_STEP, AST_LIN2A, ast_log(), linear2alaw(), LOG_NOTICE, and LOG_WARNING.

Referenced by main().

155 {
156  int i;
157  /*
158  * Set up mu-law conversion table
159  */
160 #ifndef G711_NEW_ALGORITHM
161  for (i = 0; i < 256; i++) {
162  __ast_alaw[i] = alaw2linear(i);
163  }
164  /* set up the reverse (mu-law) conversion table */
165  for (i = -32768; i < 32768; i++) {
166  __ast_lin2a[((unsigned short)i) >> 3] = linear2alaw(i);
167  }
168 #else
169  for (i = 0; i < 256; i++) {
170  __ast_alaw[i] = alaw2linear(i);
171  }
172  /* set up the reverse (a-law) conversion table */
173  for (i = 0; i <= 32768; i += AST_ALAW_STEP) {
174  AST_LIN2A_LOOKUP(i) = linear2alaw(i, 0 /* half-cooked */);
175  }
176 #endif
177 
178 #ifdef TEST_CODING_TABLES
179  for (i = -32768; i < 32768; ++i) {
180 #ifndef G711_NEW_ALGORITHM
181  unsigned char e1 = linear2alaw(i);
182 #else
183  unsigned char e1 = linear2alaw(i, 1);
184 #endif
185  short d1 = alaw2linear(e1);
186  unsigned char e2 = AST_LIN2A(i);
187  short d2 = alaw2linear(e2);
188  short d3 = AST_ALAW(e1);
189 
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);
193  }
194  }
195  ast_log(LOG_NOTICE, "a-Law coding tables test complete.\n");
196 #endif /* TEST_CODING_TABLES */
197 
198 #ifdef TEST_TANDEM_TRANSCODING
199  /* tandem transcoding test */
200  for (i = -32768; i < 32768; ++i) {
201  unsigned char e1 = AST_LIN2A(i);
202  short d1 = AST_ALAW(e1);
203  unsigned char e2 = AST_LIN2A(d1);
204  short d2 = AST_ALAW(e2);
205  unsigned char e3 = AST_LIN2A(d2);
206  short d3 = AST_ALAW(e3);
207 
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);
211  }
212  }
213  ast_log(LOG_NOTICE, "a-Law tandem transcoding test complete.\n");
214 #endif /* TEST_TANDEM_TRANSCODING */
215 
216 }
#define LOG_WARNING
Definition: logger.h:144
#define AST_ALAW(a)
Definition: alaw.h:84
short __ast_alaw[256]
Definition: alaw.c:152
unsigned char __ast_lin2a[8192]
converts signed linear to alaw
Definition: alaw.c:148
#define AST_ALAW_STEP
Definition: alaw.h:33
static short int alaw2linear(unsigned char alaw)
Definition: alaw.c:114
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
static unsigned char linear2alaw(short int linear)
Definition: alaw.c:40
#define AST_LIN2A(a)
Definition: alaw.h:50

Variable Documentation

short __ast_alaw[256]

help

Definition at line 152 of file alaw.c.

unsigned char __ast_lin2a[8192]

converts signed linear to alaw

Definition at line 148 of file alaw.c.