51typedef __int64 sint64;
52# elif defined(__GNUC__)
53typedef long long sint64;
55# error 64-bit integer type is not defined for your compiler/platform
59#define BUFFER_SAMPLES 8096
96static int qtab_721[7] = {-124, 80, 178, 246, 300, 349, 400};
101static int _dqlntab[16] = {-2048, 4, 135, 213, 273, 323, 373, 425,
102 425, 373, 323, 273, 213, 135, 4, -2048};
105static int _witab[16] = {-12, 18, 41, 64, 112, 198, 355, 1122,
106 1122, 355, 198, 112, 64, 41, 18, -12};
112static int _fitab[16] = {0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00,
113 0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0};
127 state_ptr->
yl = 34816;
132 for (cnta = 0; cnta < 2; cnta++) {
133 state_ptr->
a[cnta] = 0;
134 state_ptr->
pk[cnta] = 0;
136 state_ptr->
sr[cnta] = 1;
138 state_ptr->
sr[cnta] = 32;
141 for (cnta = 0; cnta < 6; cnta++) {
142 state_ptr->
b[cnta] = 0;
144 state_ptr->
dq[cnta] = 1;
146 state_ptr->
dq[cnta] = 32;
164 for (i = 0; i < size && val >= *
table; ++i, ++
table)
181 for (sezi = 0, i = 0; i < 6; i++)
182 sezi += (sint64)state_ptr->
b[i] * state_ptr->
dq[i];
183 return (
int)(sezi >> 13) / 2 ;
194 return (
int)(((sint64)state_ptr->
a[1] * state_ptr->
sr[1] +
195 (sint64)state_ptr->
a[0] * state_ptr->
sr[0]) >> 13) / 2 ;
207 int anmag, anexp, anmant;
211 anmag = (an > 0) ? an : ((-an) & 0x1FFF);
212 anexp =
ilog2(anmag) - 5;
213 anmant = (anmag == 0) ? 32 :
214 (anexp >= 0) ? anmag >> anexp : anmag << -anexp;
215 wanexp = anexp + ((srn >> 6) & 0xF) - 13;
217 wanmant = (anmant * (srn & 077) + 0x30) >> 4;
218 retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) :
219 (wanmant >> -wanexp);
228 for (sezi = 0, i = 0; i < 6; i++)
229 sezi +=
fmult(state_ptr->
b[i] >> 2, state_ptr->
dq[i]);
235 return (
fmult(state_ptr->
a[1] >> 2, state_ptr->
sr[1]) +
236 fmult(state_ptr->
a[0] >> 2, state_ptr->
sr[0]));
251 if (state_ptr->
ap >= 256) {
252 return state_ptr->
yu;
255 y = state_ptr->
yl >> 6;
256 dif = state_ptr->
yu - y;
257 al = state_ptr->
ap >> 2;
260 y += (dif * al) >> 6;
261 }
else if (dif < 0) {
262 y += (dif * al + 0x3F) >> 6;
299 mant = ((dqm << 7) >> exp) & 0x7F;
300 dl = (exp << 7) | mant;
316 return ((size << 1) + 1 - i);
318 return ((size << 1) + 1);
341 dql = dqln + (y >> 2);
345 return (sign) ? -1 : 1;
347 return (sign) ? -0x8000 : 0;
350 dex = (dql >> 7) & 15;
351 dqt = 128 + (dql & 127);
353 dq = ((dqt << 19) >> (14 - dex));
354 return (sign) ? -dq : dq;
356 dq = (dqt << 7) >> (14 - dex);
357 return (sign) ? (dq - 0x8000) : dq;
387 int ylint, thr2, dqthr;
391 pk0 = (dqsez < 0) ? 1 : 0;
394 mag =
abs(dq / 0x1000);
399 ylint = state_ptr->
yl >> 15;
400 ylfrac = (state_ptr->
yl >> 10) & 0x1F;
401 thr1 = (32 + ylfrac) << ylint;
402 thr2 = (ylint > 9) ? 31 << 10 : thr1;
403 dqthr = (thr2 + (thr2 >> 1)) >> 1;
404 if (state_ptr->
td == 0) {
406 }
else if (mag <= dqthr) {
417 state_ptr->
yu = y + ((wi - y) >> 5);
420 if (state_ptr->
yu < 544) {
422 }
else if (state_ptr->
yu > 5120) {
423 state_ptr->
yu = 5120;
428 state_ptr->
yl += state_ptr->
yu + ((-state_ptr->
yl) >> 6);
443 pks1 = pk0 ^ state_ptr->
pk[0];
446 a2p = state_ptr->
a[1] - (state_ptr->
a[1] >> 7);
448 fa1 = (pks1) ? state_ptr->
a[0] : -state_ptr->
a[0];
451 }
else if (fa1 > 8191) {
457 if (pk0 ^ state_ptr->
pk[1]) {
461 }
else if (a2p >= 12416) {
466 }
else if (a2p <= -12416) {
468 }
else if (a2p >= 12160) {
476 state_ptr->
a[1] = a2p;
480 state_ptr->
a[0] -= state_ptr->
a[0] >> 8;
483 state_ptr->
a[0] += 192;
485 state_ptr->
a[0] -= 192;
489 if (state_ptr->
a[0] < -a1ul) {
490 state_ptr->
a[0] = -a1ul;
491 }
else if (state_ptr->
a[0] > a1ul) {
492 state_ptr->
a[0] = a1ul;
496 for (cnt = 0; cnt < 6; cnt++) {
497 if (code_size == 5) {
498 state_ptr->
b[cnt] -= state_ptr->
b[cnt] >> 9;
500 state_ptr->
b[cnt] -= state_ptr->
b[cnt] >> 8;
503 if ((dq ^ state_ptr->
dq[cnt]) >= 0) {
504 state_ptr->
b[cnt] += 128;
506 state_ptr->
b[cnt] -= 128;
512 for (cnt = 5; cnt > 0; cnt--)
513 state_ptr->
dq[cnt] = state_ptr->
dq[cnt-1];
515 state_ptr->
dq[0] = dq;
519 state_ptr->
dq[0] = (dq >= 0) ? 0x20 : 0x20 - 0x400;
521 exp =
ilog2(mag) + 1;
522 state_ptr->
dq[0] = (dq >= 0) ?
523 (exp << 6) + ((mag << 6) >> exp) :
524 (exp << 6) + ((mag << 6) >> exp) - 0x400;
528 state_ptr->
sr[1] = state_ptr->
sr[0];
530 state_ptr->
sr[0] = sr;
534 state_ptr->
sr[0] = 0x20;
537 state_ptr->
sr[0] = (exp << 6) + ((sr << 6) >> exp);
538 }
else if (sr > -0x8000) {
540 exp =
ilog2(mag) + 1;
541 state_ptr->
sr[0] = (exp << 6) + ((mag << 6) >> exp) - 0x400;
543 state_ptr->
sr[0] = 0x20 - 0x400;
547 state_ptr->
pk[1] = state_ptr->
pk[0];
548 state_ptr->
pk[0] = pk0;
553 }
else if (a2p < -11776) {
562 state_ptr->
dms += (fi - state_ptr->
dms) >> 5;
563 state_ptr->
dml += (((fi << 2) - state_ptr->
dml) >> 7);
567 }
else if (y < 1536) {
568 state_ptr->
ap += (0x200 - state_ptr->
ap) >> 4;
569 }
else if (state_ptr->
td == 1) {
570 state_ptr->
ap += (0x200 - state_ptr->
ap) >> 4;
571 }
else if (
abs((state_ptr->
dms << 2) - state_ptr->
dml) >=
572 (state_ptr->
dml >> 3)) {
573 state_ptr->
ap += (0x200 - state_ptr->
ap) >> 4;
575 state_ptr->
ap += (-state_ptr->
ap) >> 4;
615 sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq;
616 dqsez = sr - se + sez;
672 sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq;
673 dqsez = sr - se + sez;
706 unsigned char *src = f->
data.
ptr;
710 for (i = 0; i < f->
datalen; i++) {
728 for (i = 0; i < f->
samples; i++) {
731 if (
tmp->next_flag & 0x80) {
736 tmp->next_flag = 0x80 |
d;
747 unsigned char *src = f->
data.
ptr;
751 for (i = 0; i < f->
datalen; i++) {
769 for (i = 0; i < f->
samples; i++) {
772 if (
tmp->next_flag & 0x80) {
777 tmp->next_flag = 0x80 |
d;
827 .
name =
"g726aal2tolin",
848 .
name =
"lintog726aal2",
859 .format =
"g726aal2",
Asterisk main include file. File version handling, generic pbx functions.
static int step_size(struct g726_state *state_ptr)
static int predictor_zero(struct g726_state *state_ptr)
static int fmult(int an, int srn)
static int g726tolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
decode packed 4-bit G726 values (RFC3551 packing) and store in buffer.
static struct ast_translator lintog726aal2
static int quan(int val, int *table, int size)
static void g726_init_state(struct g726_state *state_ptr)
static int lintog726aal2_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
compress and store data (4-bit G726 samples, AAL2 packing) in outbuf
static struct ast_translator g726tolin
static struct ast_translator lintog726
static void update(int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr)
static int lintog726_new(struct ast_trans_pvt *pvt)
init a new instance of g726_coder_pvt.
static int quantize(int d, int y, int *table, int size)
static struct ast_translator g726aal2tolin
static int predictor_pole(struct g726_state *state_ptr)
static int reconstruct(int sign, int dqln, int y)
static int g726aal2tolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
decode packed 4-bit G726 values (AAL2 packing) and store in buffer.
static int load_module(void)
static int unload_module(void)
static int g726_decode(int i, struct g726_state *state_ptr)
static int g726_encode(int sl, struct g726_state *state_ptr)
static int lintog726_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
compress and store data (4-bit G726 samples, RFC3551 packing) in outbuf
static struct ast_frame * g726_sample(void)
Configuration File Parser.
A set of macros to manage forward-linked lists.
Asterisk locking-related definitions:
log2comp.h - various base 2 log computation versions
static int ilog2(int val)
Asterisk module definitions.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
static struct ast_frame * slin8_sample(void)
Data structure associated with a single frame of data.
union ast_frame::@226 data
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
int datalen
actual space used in outbuf
union ast_trans_pvt::@287 outbuf
Descriptor of a translator.
Support for translation of data formats. translate.c.
#define ast_register_translator(t)
See __ast_register_translator()
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given translator.