38 #include "asterisk/lock.h"
52 # if defined(_MSC_VER)
53 typedef __int64 sint64;
54 # elif defined(__GNUC__)
55 typedef long long sint64;
57 # error 64-bit integer type is not defined for your compiler/platform
61 #define BUFFER_SAMPLES 8096
98 static int qtab_721[7] = {-124, 80, 178, 246, 300, 349, 400};
103 static int _dqlntab[16] = {-2048, 4, 135, 213, 273, 323, 373, 425,
104 425, 373, 323, 273, 213, 135, 4, -2048};
107 static int _witab[16] = {-12, 18, 41, 64, 112, 198, 355, 1122,
108 1122, 355, 198, 112, 64, 41, 18, -12};
114 static int _fitab[16] = {0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00,
115 0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0};
129 state_ptr->
yl = 34816;
134 for (cnta = 0; cnta < 2; cnta++) {
135 state_ptr->
a[cnta] = 0;
136 state_ptr->
pk[cnta] = 0;
138 state_ptr->
sr[cnta] = 1;
140 state_ptr->
sr[cnta] = 32;
143 for (cnta = 0; cnta < 6; cnta++) {
144 state_ptr->
b[cnta] = 0;
146 state_ptr->
dq[cnta] = 1;
148 state_ptr->
dq[cnta] = 32;
166 for (i = 0; i < size && val >= *
table; ++i, ++
table)
183 for (sezi = 0, i = 0; i < 6; i++)
184 sezi += (sint64)state_ptr->
b[i] * state_ptr->
dq[i];
185 return (
int)(sezi >> 13) / 2 ;
196 return (
int)(((sint64)state_ptr->
a[1] * state_ptr->
sr[1] +
197 (sint64)state_ptr->
a[0] * state_ptr->
sr[0]) >> 13) / 2 ;
209 int anmag, anexp, anmant;
213 anmag = (an > 0) ? an : ((-an) & 0x1FFF);
214 anexp =
ilog2(anmag) - 5;
215 anmant = (anmag == 0) ? 32 :
216 (anexp >= 0) ? anmag >> anexp : anmag << -anexp;
217 wanexp = anexp + ((srn >> 6) & 0xF) - 13;
219 wanmant = (anmant * (srn & 077) + 0x30) >> 4;
220 retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) :
221 (wanmant >> -wanexp);
223 return (((an ^ srn) < 0) ? -retval : retval);
230 for (sezi = 0, i = 0; i < 6; i++)
231 sezi +=
fmult(state_ptr->
b[i] >> 2, state_ptr->
dq[i]);
237 return (
fmult(state_ptr->
a[1] >> 2, state_ptr->
sr[1]) +
238 fmult(state_ptr->
a[0] >> 2, state_ptr->
sr[0]));
255 if (state_ptr->
ap >= 256)
256 return (state_ptr->
yu);
258 y = state_ptr->
yl >> 6;
259 dif = state_ptr->
yu - y;
260 al = state_ptr->
ap >> 2;
262 y += (dif * al) >> 6;
264 y += (dif * al + 0x3F) >> 6;
300 mant = ((dqm << 7) >> exp) & 0x7F;
301 dl = (exp << 7) | mant;
315 i =
quan(dln, table, size);
317 return ((size << 1) + 1 - i);
319 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;
427 state_ptr->
yl += state_ptr->
yu + ((-state_ptr->
yl) >> 6);
442 pks1 = pk0 ^ state_ptr->
pk[0];
445 a2p = state_ptr->
a[1] - (state_ptr->
a[1] >> 7);
447 fa1 = (pks1) ? state_ptr->
a[0] : -state_ptr->
a[0];
455 if (pk0 ^ state_ptr->
pk[1])
459 else if (a2p >= 12416)
463 else if (a2p <= -12416)
465 else if (a2p >= 12160)
472 state_ptr->
a[1] = a2p;
476 state_ptr->
a[0] -= state_ptr->
a[0] >> 8;
479 state_ptr->
a[0] += 192;
481 state_ptr->
a[0] -= 192;
485 if (state_ptr->
a[0] < -a1ul)
486 state_ptr->
a[0] = -a1ul;
487 else if (state_ptr->
a[0] > a1ul)
488 state_ptr->
a[0] = a1ul;
491 for (cnt = 0; cnt < 6; cnt++) {
493 state_ptr->
b[cnt] -= state_ptr->
b[cnt] >> 9;
495 state_ptr->
b[cnt] -= state_ptr->
b[cnt] >> 8;
498 if ((dq ^ state_ptr->
dq[cnt]) >= 0)
499 state_ptr->
b[cnt] += 128;
501 state_ptr->
b[cnt] -= 128;
506 for (cnt = 5; cnt > 0; cnt--)
507 state_ptr->
dq[cnt] = state_ptr->
dq[cnt-1];
509 state_ptr->
dq[0] = dq;
513 state_ptr->
dq[0] = (dq >= 0) ? 0x20 : 0x20 - 0x400;
515 exp =
ilog2(mag) + 1;
516 state_ptr->
dq[0] = (dq >= 0) ?
517 (exp << 6) + ((mag << 6) >> exp) :
518 (exp << 6) + ((mag << 6) >> exp) - 0x400;
522 state_ptr->
sr[1] = state_ptr->
sr[0];
524 state_ptr->
sr[0] = sr;
528 state_ptr->
sr[0] = 0x20;
531 state_ptr->
sr[0] = (exp << 6) + ((sr << 6) >> exp);
532 }
else if (sr > -0x8000) {
534 exp =
ilog2(mag) + 1;
535 state_ptr->
sr[0] = (exp << 6) + ((mag << 6) >> exp) - 0x400;
537 state_ptr->
sr[0] = 0x20 - 0x400;
541 state_ptr->
pk[1] = state_ptr->
pk[0];
542 state_ptr->
pk[0] = pk0;
547 else if (a2p < -11776)
555 state_ptr->
dms += (fi - state_ptr->
dms) >> 5;
556 state_ptr->
dml += (((fi << 2) - state_ptr->
dml) >> 7);
561 state_ptr->
ap += (0x200 - state_ptr->
ap) >> 4;
562 else if (state_ptr->
td == 1)
563 state_ptr->
ap += (0x200 - state_ptr->
ap) >> 4;
564 else if (abs((state_ptr->
dms << 2) - state_ptr->
dml) >=
565 (state_ptr->
dml >> 3))
566 state_ptr->
ap += (0x200 - state_ptr->
ap) >> 4;
568 state_ptr->
ap += (-state_ptr->
ap) >> 4;
607 sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq;
608 dqsez = sr - se + sez;
611 update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
664 sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq;
665 dqsez = sr - se + sez;
668 update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
698 unsigned char *src = f->
data.
ptr;
702 for (i = 0; i < f->
datalen; i++) {
720 for (i = 0; i < f->
samples; i++) {
739 unsigned char *src = f->
data.
ptr;
743 for (i = 0; i < f->
datalen; i++) {
761 for (i = 0; i < f->
samples; i++) {
801 .
name =
"g726aal2tolin",
813 .
name =
"lintog726aal2",
int datalen
actual space used in outbuf
static int g726_encode(int sl, struct g726_state *state_ptr)
static void g726_init_state(struct g726_state *state_ptr)
Asterisk main include file. File version handling, generic pbx functions.
union ast_trans_pvt::@213 outbuf
Descriptor of a translator.
static void update(int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr)
Support for translation of data formats. translate.c.
static struct ast_frame * g726_sample(void)
Configuration File Parser.
static int step_size(struct g726_state *state_ptr)
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
static struct ast_frame * slin8_sample(void)
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 int load_module(void)
static struct ast_translator lintog726
static struct ast_translator lintog726aal2
static struct ast_translator g726aal2tolin
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.
log2comp.h - various base 2 log computation versions
#define ast_register_translator(t)
See __ast_register_translator()
#define AST_FORMAT_G726_AAL2
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given tranlator.
A set of macros to manage forward-linked lists.
static struct ast_translator g726tolin
static int lintog726_new(struct ast_trans_pvt *pvt)
init a new instance of g726_coder_pvt.
static int unload_module(void)
Default structure for translators, with the basic fields and buffers, all allocated as part of the sa...
static int quan(int val, int *table, int size)
if(yyss+yystacksize-1<=yyssp)
static int ilog2(int val)
static int reconstruct(int sign, int dqln, int y)
#define AST_FORMAT_SLINEAR
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 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 int predictor_pole(struct g726_state *state_ptr)
Data structure associated with a single frame of data.
static int fmult(int an, int srn)
static int g726_decode(int i, struct g726_state *state_ptr)
static int quantize(int d, int y, int *table, int size)
static int predictor_zero(struct g726_state *state_ptr)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
union ast_frame::@172 data
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.