Asterisk - The Open Source Telephony Project GIT-master-d856a3e
Macros | Functions | Variables
ulaw.h File Reference

u-Law to Signed linear conversion More...

This graph shows which files directly or indirectly include this file:

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

◆ AST_LIN2MU

#define AST_LIN2MU (   a)    (__ast_lin2mu[((unsigned short)(a)) >> 2])

Definition at line 49 of file ulaw.h.

◆ AST_MULAW

#define AST_MULAW (   a)    (__ast_mulaw[(a)])

Definition at line 85 of file ulaw.h.

◆ AST_ULAW_BIT_LOSS

#define AST_ULAW_BIT_LOSS   3

Definition at line 32 of file ulaw.h.

◆ AST_ULAW_SIGN_BIT

#define AST_ULAW_SIGN_BIT   0x80

Definition at line 35 of file ulaw.h.

◆ AST_ULAW_STEP

#define AST_ULAW_STEP   (1 << AST_ULAW_BIT_LOSS)

Definition at line 33 of file ulaw.h.

◆ AST_ULAW_TAB_SIZE

#define AST_ULAW_TAB_SIZE   (32768 / AST_ULAW_STEP + 1)

Definition at line 34 of file ulaw.h.

Function Documentation

◆ ast_ulaw_init()

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 173 of file ulaw.c.

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

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

Referenced by asterisk_daemon().

Variable Documentation

◆ __ast_lin2mu

unsigned char __ast_lin2mu[16384]
extern

converts signed linear to mulaw

Definition at line 49 of file ulaw.c.

Referenced by ast_ulaw_init().

◆ __ast_mulaw

short __ast_mulaw[256]
extern

help

Definition at line 50 of file ulaw.c.

Referenced by ast_ulaw_init().