codec_g726.c - translate between signed linear and ITU G.726-32kbps (both RFC3551 and AAL2 codeword packing) More...
#include "asterisk.h"#include "asterisk/lock.h"#include "asterisk/linkedlists.h"#include "asterisk/module.h"#include "asterisk/config.h"#include "asterisk/translate.h"#include "asterisk/utils.h"#include "log2comp.h"#include "asterisk/slin.h"#include "ex_g726.h"
Go to the source code of this file.
Data Structures | |
| struct | g726_coder_pvt |
| struct | g726_state |
Defines | |
| #define | BUF_SHIFT 5 |
| #define | BUFFER_SAMPLES 8096 |
| #define | WANT_ASM |
Functions | |
| AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,"ITU G.726-32kbps G726 Transcoder",.load=load_module,.unload=unload_module,.reload=reload,) | |
| static int | fmult (int an, int srn) |
| static int | g726_decode (int i, struct g726_state *state_ptr) |
| static int | g726_encode (int sl, struct g726_state *state_ptr) |
| static void | g726_init_state (struct g726_state *state_ptr) |
| 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 | 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 | lintog726_new (struct ast_trans_pvt *pvt) |
| init a new instance of g726_coder_pvt. | |
| 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 int | predictor_pole (struct g726_state *state_ptr) |
| static int | predictor_zero (struct g726_state *state_ptr) |
| static int | quan (int val, int *table, int size) |
| static int | quantize (int d, int y, int *table, int size) |
| static int | reconstruct (int sign, int dqln, int y) |
| static int | reload (void) |
| static int | step_size (struct g726_state *state_ptr) |
| static int | unload_module (void) |
| static void | update (int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr) |
Variables | |
| static int | _dqlntab [16] |
| static int | _fitab [16] |
| static int | _witab [16] |
| static struct ast_translator | g726aal2tolin |
| static struct ast_translator | g726tolin |
| static struct ast_translator | lintog726 |
| static struct ast_translator | lintog726aal2 |
| static int | qtab_721 [7] = {-124, 80, 178, 246, 300, 349, 400} |
codec_g726.c - translate between signed linear and ITU G.726-32kbps (both RFC3551 and AAL2 codeword packing)
Definition in file codec_g726.c.
| #define BUF_SHIFT 5 |
Definition at line 58 of file codec_g726.c.
| #define BUFFER_SAMPLES 8096 |
Definition at line 57 of file codec_g726.c.
| #define WANT_ASM |
Definition at line 41 of file codec_g726.c.
| AST_MODULE_INFO | ( | ASTERISK_GPL_KEY | , | |
| AST_MODFLAG_DEFAULT | , | |||
| "ITU G.726-32kbps G726 Transcoder" | , | |||
| . | load = load_module, |
|||
| . | unload = unload_module, |
|||
| . | reload = reload | |||
| ) |
| static int fmult | ( | int | an, | |
| int | srn | |||
| ) | [static] |
Definition at line 203 of file codec_g726.c.
References ilog2().
Referenced by predictor_pole(), and predictor_zero().
00204 { 00205 int anmag, anexp, anmant; 00206 int wanexp, wanmant; 00207 int retval; 00208 00209 anmag = (an > 0) ? an : ((-an) & 0x1FFF); 00210 anexp = ilog2(anmag) - 5; 00211 anmant = (anmag == 0) ? 32 : 00212 (anexp >= 0) ? anmag >> anexp : anmag << -anexp; 00213 wanexp = anexp + ((srn >> 6) & 0xF) - 13; 00214 00215 wanmant = (anmant * (srn & 077) + 0x30) >> 4; 00216 retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) : 00217 (wanmant >> -wanexp); 00218 00219 return (((an ^ srn) < 0) ? -retval : retval); 00220 }
| static int g726_decode | ( | int | i, | |
| struct g726_state * | state_ptr | |||
| ) | [static] |
Definition at line 576 of file codec_g726.c.
References predictor_pole(), predictor_zero(), reconstruct(), step_size(), and update().
Referenced by g726aal2tolin_framein(), and g726tolin_framein().
00577 { 00578 int sezi, sez, se; /* ACCUM */ 00579 int y; /* MIX */ 00580 int sr; /* ADDB */ 00581 int dq; 00582 int dqsez; 00583 00584 i &= 0x0f; /* mask to get proper bits */ 00585 #ifdef NOT_BLI 00586 sezi = predictor_zero(state_ptr); 00587 sez = sezi; 00588 se = sezi + predictor_pole(state_ptr); /* estimated signal */ 00589 #else 00590 sezi = predictor_zero(state_ptr); 00591 sez = sezi >> 1; 00592 se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */ 00593 #endif 00594 00595 y = step_size(state_ptr); /* dynamic quantizer step size */ 00596 00597 dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized diff. */ 00598 00599 #ifdef NOT_BLI 00600 sr = se + dq; /* reconst. signal */ 00601 dqsez = dq + sez; /* pole prediction diff. */ 00602 #else 00603 sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */ 00604 dqsez = sr - se + sez; /* pole prediction diff. */ 00605 #endif 00606 00607 update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr); 00608 00609 #ifdef NOT_BLI 00610 return (sr >> 10); /* sr was 26-bit dynamic range */ 00611 #else 00612 return (sr << 2); /* sr was 14-bit dynamic range */ 00613 #endif 00614 }
| static int g726_encode | ( | int | sl, | |
| struct g726_state * | state_ptr | |||
| ) | [static] |
Definition at line 622 of file codec_g726.c.
References predictor_pole(), predictor_zero(), quantize(), reconstruct(), step_size(), and update().
Referenced by lintog726_framein(), and lintog726aal2_framein().
00623 { 00624 int sezi, se, sez; /* ACCUM */ 00625 int d; /* SUBTA */ 00626 int sr; /* ADDB */ 00627 int y; /* MIX */ 00628 int dqsez; /* ADDC */ 00629 int dq, i; 00630 00631 #ifdef NOT_BLI 00632 sl <<= 10; /* 26-bit dynamic range */ 00633 00634 sezi = predictor_zero(state_ptr); 00635 sez = sezi; 00636 se = sezi + predictor_pole(state_ptr); /* estimated signal */ 00637 #else 00638 sl >>= 2; /* 14-bit dynamic range */ 00639 00640 sezi = predictor_zero(state_ptr); 00641 sez = sezi >> 1; 00642 se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */ 00643 #endif 00644 00645 d = sl - se; /* estimation difference */ 00646 00647 /* quantize the prediction difference */ 00648 y = step_size(state_ptr); /* quantizer step size */ 00649 #ifdef NOT_BLI 00650 d /= 0x1000; 00651 #endif 00652 i = quantize(d, y, qtab_721, 7); /* i = G726 code */ 00653 00654 dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized est diff */ 00655 00656 #ifdef NOT_BLI 00657 sr = se + dq; /* reconst. signal */ 00658 dqsez = dq + sez; /* pole prediction diff. */ 00659 #else 00660 sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */ 00661 dqsez = sr - se + sez; /* pole prediction diff. */ 00662 #endif 00663 00664 update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr); 00665 00666 return (i); 00667 }
| static void g726_init_state | ( | struct g726_state * | state_ptr | ) | [static] |
Definition at line 121 of file codec_g726.c.
References g726_state::a, g726_state::ap, g726_state::b, g726_state::dml, g726_state::dms, g726_state::dq, g726_state::pk, g726_state::sr, g726_state::td, g726_state::yl, and g726_state::yu.
Referenced by lintog726_new().
00122 { 00123 int cnta; 00124 00125 state_ptr->yl = 34816; 00126 state_ptr->yu = 544; 00127 state_ptr->dms = 0; 00128 state_ptr->dml = 0; 00129 state_ptr->ap = 0; 00130 for (cnta = 0; cnta < 2; cnta++) { 00131 state_ptr->a[cnta] = 0; 00132 state_ptr->pk[cnta] = 0; 00133 #ifdef NOT_BLI 00134 state_ptr->sr[cnta] = 1; 00135 #else 00136 state_ptr->sr[cnta] = 32; 00137 #endif 00138 } 00139 for (cnta = 0; cnta < 6; cnta++) { 00140 state_ptr->b[cnta] = 0; 00141 #ifdef NOT_BLI 00142 state_ptr->dq[cnta] = 1; 00143 #else 00144 state_ptr->dq[cnta] = 32; 00145 #endif 00146 } 00147 state_ptr->td = 0; 00148 }
| static int g726aal2tolin_framein | ( | struct ast_trans_pvt * | pvt, | |
| struct ast_frame * | f | |||
| ) | [static] |
decode packed 4-bit G726 values (AAL2 packing) and store in buffer.
Definition at line 691 of file codec_g726.c.
References ast_frame::data, ast_trans_pvt::datalen, ast_frame::datalen, g726_coder_pvt::g726, g726_decode(), ast_trans_pvt::i16, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, ast_frame::samples, and ast_trans_pvt::samples.
00692 { 00693 struct g726_coder_pvt *tmp = pvt->pvt; 00694 unsigned char *src = f->data.ptr; 00695 int16_t *dst = pvt->outbuf.i16 + pvt->samples; 00696 unsigned int i; 00697 00698 for (i = 0; i < f->datalen; i++) { 00699 *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726); 00700 *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726); 00701 } 00702 00703 pvt->samples += f->samples; 00704 pvt->datalen += 2 * f->samples; /* 2 bytes/sample */ 00705 00706 return 0; 00707 }
| static int g726tolin_framein | ( | struct ast_trans_pvt * | pvt, | |
| struct ast_frame * | f | |||
| ) | [static] |
decode packed 4-bit G726 values (RFC3551 packing) and store in buffer.
Definition at line 732 of file codec_g726.c.
References ast_frame::data, ast_trans_pvt::datalen, ast_frame::datalen, g726_coder_pvt::g726, g726_decode(), ast_trans_pvt::i16, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, ast_frame::samples, and ast_trans_pvt::samples.
00733 { 00734 struct g726_coder_pvt *tmp = pvt->pvt; 00735 unsigned char *src = f->data.ptr; 00736 int16_t *dst = pvt->outbuf.i16 + pvt->samples; 00737 unsigned int i; 00738 00739 for (i = 0; i < f->datalen; i++) { 00740 *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726); 00741 *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726); 00742 } 00743 00744 pvt->samples += f->samples; 00745 pvt->datalen += 2 * f->samples; /* 2 bytes/sample */ 00746 00747 return 0; 00748 }
| static int lintog726_framein | ( | struct ast_trans_pvt * | pvt, | |
| struct ast_frame * | f | |||
| ) | [static] |
compress and store data (4-bit G726 samples, RFC3551 packing) in outbuf
Definition at line 751 of file codec_g726.c.
References ast_trans_pvt::c, ast_frame::data, ast_trans_pvt::datalen, g726_coder_pvt::g726, g726_encode(), g726_coder_pvt::next_flag, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, ast_trans_pvt::samples, and ast_frame::samples.
00752 { 00753 struct g726_coder_pvt *tmp = pvt->pvt; 00754 int16_t *src = f->data.ptr; 00755 unsigned int i; 00756 00757 for (i = 0; i < f->samples; i++) { 00758 unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */ 00759 00760 if (tmp->next_flag & 0x80) { /* merge with leftover sample */ 00761 pvt->outbuf.c[pvt->datalen++] = (d << 4) | (tmp->next_flag & 0xf); 00762 pvt->samples += 2; /* 2 samples per byte */ 00763 tmp->next_flag = 0; 00764 } else { 00765 tmp->next_flag = 0x80 | d; 00766 } 00767 } 00768 00769 return 0; 00770 }
| static int lintog726_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
init a new instance of g726_coder_pvt.
Definition at line 681 of file codec_g726.c.
References g726_coder_pvt::g726, g726_init_state(), and ast_trans_pvt::pvt.
00682 { 00683 struct g726_coder_pvt *tmp = pvt->pvt; 00684 00685 g726_init_state(&tmp->g726); 00686 00687 return 0; 00688 }
| static int lintog726aal2_framein | ( | struct ast_trans_pvt * | pvt, | |
| struct ast_frame * | f | |||
| ) | [static] |
compress and store data (4-bit G726 samples, AAL2 packing) in outbuf
Definition at line 710 of file codec_g726.c.
References ast_trans_pvt::c, ast_frame::data, ast_trans_pvt::datalen, g726_coder_pvt::g726, g726_encode(), g726_coder_pvt::next_flag, ast_trans_pvt::outbuf, ast_frame::ptr, ast_trans_pvt::pvt, ast_trans_pvt::samples, and ast_frame::samples.
00711 { 00712 struct g726_coder_pvt *tmp = pvt->pvt; 00713 int16_t *src = f->data.ptr; 00714 unsigned int i; 00715 00716 for (i = 0; i < f->samples; i++) { 00717 unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */ 00718 00719 if (tmp->next_flag & 0x80) { /* merge with leftover sample */ 00720 pvt->outbuf.c[pvt->datalen++] = ((tmp->next_flag & 0xf)<< 4) | d; 00721 pvt->samples += 2; /* 2 samples per byte */ 00722 tmp->next_flag = 0; 00723 } else { 00724 tmp->next_flag = 0x80 | d; 00725 } 00726 } 00727 00728 return 0; 00729 }
| static int load_module | ( | void | ) | [static] |
Definition at line 838 of file codec_g726.c.
References AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, and unload_module.
00839 { 00840 int res = 0; 00841 00842 res |= ast_register_translator(&g726tolin); 00843 res |= ast_register_translator(&lintog726); 00844 00845 res |= ast_register_translator(&g726aal2tolin); 00846 res |= ast_register_translator(&lintog726aal2); 00847 00848 if (res) { 00849 unload_module(); 00850 return AST_MODULE_LOAD_FAILURE; 00851 } 00852 00853 return AST_MODULE_LOAD_SUCCESS; 00854 }
| static int predictor_pole | ( | struct g726_state * | state_ptr | ) | [static] |
Definition at line 231 of file codec_g726.c.
References g726_state::a, fmult(), and g726_state::sr.
Referenced by g726_decode(), and g726_encode().
| static int predictor_zero | ( | struct g726_state * | state_ptr | ) | [static] |
Definition at line 222 of file codec_g726.c.
References g726_state::b, g726_state::dq, and fmult().
Referenced by g726_decode(), and g726_encode().
| static int quan | ( | int | val, | |
| int * | table, | |||
| int | size | |||
| ) | [static] |
Definition at line 158 of file codec_g726.c.
Referenced by quantize().
| static int quantize | ( | int | d, | |
| int | y, | |||
| int * | table, | |||
| int | size | |||
| ) | [static] |
Definition at line 274 of file codec_g726.c.
References ilog2(), and quan().
Referenced by g726_encode().
00279 { 00280 int dqm; /* Magnitude of 'd' */ 00281 int exp; /* Integer part of base 2 log of 'd' */ 00282 int mant; /* Fractional part of base 2 log */ 00283 int dl; /* Log of magnitude of 'd' */ 00284 int dln; /* Step size scale factor normalized log */ 00285 int i; 00286 00287 /* 00288 * LOG 00289 * 00290 * Compute base 2 log of 'd', and store in 'dl'. 00291 */ 00292 dqm = abs(d); 00293 exp = ilog2(dqm); 00294 if (exp < 0) 00295 exp = 0; 00296 mant = ((dqm << 7) >> exp) & 0x7F; /* Fractional portion. */ 00297 dl = (exp << 7) | mant; 00298 00299 /* 00300 * SUBTB 00301 * 00302 * "Divide" by step size multiplier. 00303 */ 00304 dln = dl - (y >> 2); 00305 00306 /* 00307 * QUAN 00308 * 00309 * Obtain codword i for 'd'. 00310 */ 00311 i = quan(dln, table, size); 00312 if (d < 0) /* take 1's complement of i */ 00313 return ((size << 1) + 1 - i); 00314 else if (i == 0) /* take 1's complement of 0 */ 00315 return ((size << 1) + 1); /* new in 1988 */ 00316 else 00317 return (i); 00318 }
| static int reconstruct | ( | int | sign, | |
| int | dqln, | |||
| int | y | |||
| ) | [static] |
Definition at line 327 of file codec_g726.c.
Referenced by bridge_p2p_rtp_write(), g726_decode(), and g726_encode().
00331 { 00332 int dql; /* Log of 'dq' magnitude */ 00333 int dex; /* Integer part of log */ 00334 int dqt; 00335 int dq; /* Reconstructed difference signal sample */ 00336 00337 dql = dqln + (y >> 2); /* ADDA */ 00338 00339 if (dql < 0) { 00340 #ifdef NOT_BLI 00341 return (sign) ? -1 : 1; 00342 #else 00343 return (sign) ? -0x8000 : 0; 00344 #endif 00345 } else { /* ANTILOG */ 00346 dex = (dql >> 7) & 15; 00347 dqt = 128 + (dql & 127); 00348 #ifdef NOT_BLI 00349 dq = ((dqt << 19) >> (14 - dex)); 00350 return (sign) ? -dq : dq; 00351 #else 00352 dq = (dqt << 7) >> (14 - dex); 00353 return (sign) ? (dq - 0x8000) : dq; 00354 #endif 00355 } 00356 }
| static int reload | ( | void | ) | [static] |
Definition at line 820 of file codec_g726.c.
References AST_MODULE_LOAD_SUCCESS.
00821 { 00822 return AST_MODULE_LOAD_SUCCESS; 00823 }
| static int step_size | ( | struct g726_state * | state_ptr | ) | [static] |
Definition at line 245 of file codec_g726.c.
References g726_state::ap, g726_state::yl, and g726_state::yu.
Referenced by g726_decode(), and g726_encode().
00246 { 00247 int y; 00248 int dif; 00249 int al; 00250 00251 if (state_ptr->ap >= 256) 00252 return (state_ptr->yu); 00253 else { 00254 y = state_ptr->yl >> 6; 00255 dif = state_ptr->yu - y; 00256 al = state_ptr->ap >> 2; 00257 if (dif > 0) 00258 y += (dif * al) >> 6; 00259 else if (dif < 0) 00260 y += (dif * al + 0x3F) >> 6; 00261 return (y); 00262 } 00263 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 825 of file codec_g726.c.
References ast_unregister_translator().
00826 { 00827 int res = 0; 00828 00829 res |= ast_unregister_translator(&g726tolin); 00830 res |= ast_unregister_translator(&lintog726); 00831 00832 res |= ast_unregister_translator(&g726aal2tolin); 00833 res |= ast_unregister_translator(&lintog726aal2); 00834 00835 return res; 00836 }
| static void update | ( | int | code_size, | |
| int | y, | |||
| int | wi, | |||
| int | fi, | |||
| int | dq, | |||
| int | sr, | |||
| int | dqsez, | |||
| struct g726_state * | state_ptr | |||
| ) | [static] |
Definition at line 363 of file codec_g726.c.
References g726_state::a, g726_state::ap, g726_state::b, g726_state::dml, g726_state::dms, g726_state::dq, ilog2(), g726_state::pk, g726_state::sr, g726_state::td, g726_state::yl, and g726_state::yu.
Referenced by config_device(), config_line(), g726_decode(), and g726_encode().
00372 { 00373 int cnt; 00374 int mag; /* Adaptive predictor, FLOAT A */ 00375 #ifndef NOT_BLI 00376 int exp; 00377 #endif 00378 int a2p=0; /* LIMC */ 00379 int a1ul; /* UPA1 */ 00380 int pks1; /* UPA2 */ 00381 int fa1; 00382 int tr; /* tone/transition detector */ 00383 int ylint, thr2, dqthr; 00384 int ylfrac, thr1; 00385 int pk0; 00386 00387 pk0 = (dqsez < 0) ? 1 : 0; /* needed in updating predictor poles */ 00388 00389 #ifdef NOT_BLI 00390 mag = abs(dq / 0x1000); /* prediction difference magnitude */ 00391 #else 00392 mag = dq & 0x7FFF; /* prediction difference magnitude */ 00393 #endif 00394 /* TRANS */ 00395 ylint = state_ptr->yl >> 15; /* exponent part of yl */ 00396 ylfrac = (state_ptr->yl >> 10) & 0x1F; /* fractional part of yl */ 00397 thr1 = (32 + ylfrac) << ylint; /* threshold */ 00398 thr2 = (ylint > 9) ? 31 << 10 : thr1; /* limit thr2 to 31 << 10 */ 00399 dqthr = (thr2 + (thr2 >> 1)) >> 1; /* dqthr = 0.75 * thr2 */ 00400 if (state_ptr->td == 0) /* signal supposed voice */ 00401 tr = 0; 00402 else if (mag <= dqthr) /* supposed data, but small mag */ 00403 tr = 0; /* treated as voice */ 00404 else /* signal is data (modem) */ 00405 tr = 1; 00406 00407 /* 00408 * Quantizer scale factor adaptation. 00409 */ 00410 00411 /* FUNCTW & FILTD & DELAY */ 00412 /* update non-steady state step size multiplier */ 00413 state_ptr->yu = y + ((wi - y) >> 5); 00414 00415 /* LIMB */ 00416 if (state_ptr->yu < 544) /* 544 <= yu <= 5120 */ 00417 state_ptr->yu = 544; 00418 else if (state_ptr->yu > 5120) 00419 state_ptr->yu = 5120; 00420 00421 /* FILTE & DELAY */ 00422 /* update steady state step size multiplier */ 00423 state_ptr->yl += state_ptr->yu + ((-state_ptr->yl) >> 6); 00424 00425 /* 00426 * Adaptive predictor coefficients. 00427 */ 00428 if (tr == 1) { /* reset a's and b's for modem signal */ 00429 state_ptr->a[0] = 0; 00430 state_ptr->a[1] = 0; 00431 state_ptr->b[0] = 0; 00432 state_ptr->b[1] = 0; 00433 state_ptr->b[2] = 0; 00434 state_ptr->b[3] = 0; 00435 state_ptr->b[4] = 0; 00436 state_ptr->b[5] = 0; 00437 } else { /* update a's and b's */ 00438 pks1 = pk0 ^ state_ptr->pk[0]; /* UPA2 */ 00439 00440 /* update predictor pole a[1] */ 00441 a2p = state_ptr->a[1] - (state_ptr->a[1] >> 7); 00442 if (dqsez != 0) { 00443 fa1 = (pks1) ? state_ptr->a[0] : -state_ptr->a[0]; 00444 if (fa1 < -8191) /* a2p = function of fa1 */ 00445 a2p -= 0x100; 00446 else if (fa1 > 8191) 00447 a2p += 0xFF; 00448 else 00449 a2p += fa1 >> 5; 00450 00451 if (pk0 ^ state_ptr->pk[1]) 00452 /* LIMC */ 00453 if (a2p <= -12160) 00454 a2p = -12288; 00455 else if (a2p >= 12416) 00456 a2p = 12288; 00457 else 00458 a2p -= 0x80; 00459 else if (a2p <= -12416) 00460 a2p = -12288; 00461 else if (a2p >= 12160) 00462 a2p = 12288; 00463 else 00464 a2p += 0x80; 00465 } 00466 00467 /* TRIGB & DELAY */ 00468 state_ptr->a[1] = a2p; 00469 00470 /* UPA1 */ 00471 /* update predictor pole a[0] */ 00472 state_ptr->a[0] -= state_ptr->a[0] >> 8; 00473 if (dqsez != 0) { 00474 if (pks1 == 0) 00475 state_ptr->a[0] += 192; 00476 else 00477 state_ptr->a[0] -= 192; 00478 } 00479 /* LIMD */ 00480 a1ul = 15360 - a2p; 00481 if (state_ptr->a[0] < -a1ul) 00482 state_ptr->a[0] = -a1ul; 00483 else if (state_ptr->a[0] > a1ul) 00484 state_ptr->a[0] = a1ul; 00485 00486 /* UPB : update predictor zeros b[6] */ 00487 for (cnt = 0; cnt < 6; cnt++) { 00488 if (code_size == 5) /* for 40Kbps G.723 */ 00489 state_ptr->b[cnt] -= state_ptr->b[cnt] >> 9; 00490 else /* for G.721 and 24Kbps G.723 */ 00491 state_ptr->b[cnt] -= state_ptr->b[cnt] >> 8; 00492 if (mag) 00493 { /* XOR */ 00494 if ((dq ^ state_ptr->dq[cnt]) >= 0) 00495 state_ptr->b[cnt] += 128; 00496 else 00497 state_ptr->b[cnt] -= 128; 00498 } 00499 } 00500 } 00501 00502 for (cnt = 5; cnt > 0; cnt--) 00503 state_ptr->dq[cnt] = state_ptr->dq[cnt-1]; 00504 #ifdef NOT_BLI 00505 state_ptr->dq[0] = dq; 00506 #else 00507 /* FLOAT A : convert dq[0] to 4-bit exp, 6-bit mantissa f.p. */ 00508 if (mag == 0) { 00509 state_ptr->dq[0] = (dq >= 0) ? 0x20 : 0x20 - 0x400; 00510 } else { 00511 exp = ilog2(mag) + 1; 00512 state_ptr->dq[0] = (dq >= 0) ? 00513 (exp << 6) + ((mag << 6) >> exp) : 00514 (exp << 6) + ((mag << 6) >> exp) - 0x400; 00515 } 00516 #endif 00517 00518 state_ptr->sr[1] = state_ptr->sr[0]; 00519 #ifdef NOT_BLI 00520 state_ptr->sr[0] = sr; 00521 #else 00522 /* FLOAT B : convert sr to 4-bit exp., 6-bit mantissa f.p. */ 00523 if (sr == 0) { 00524 state_ptr->sr[0] = 0x20; 00525 } else if (sr > 0) { 00526 exp = ilog2(sr) + 1; 00527 state_ptr->sr[0] = (exp << 6) + ((sr << 6) >> exp); 00528 } else if (sr > -0x8000) { 00529 mag = -sr; 00530 exp = ilog2(mag) + 1; 00531 state_ptr->sr[0] = (exp << 6) + ((mag << 6) >> exp) - 0x400; 00532 } else 00533 state_ptr->sr[0] = 0x20 - 0x400; 00534 #endif 00535 00536 /* DELAY A */ 00537 state_ptr->pk[1] = state_ptr->pk[0]; 00538 state_ptr->pk[0] = pk0; 00539 00540 /* TONE */ 00541 if (tr == 1) /* this sample has been treated as data */ 00542 state_ptr->td = 0; /* next one will be treated as voice */ 00543 else if (a2p < -11776) /* small sample-to-sample correlation */ 00544 state_ptr->td = 1; /* signal may be data */ 00545 else /* signal is voice */ 00546 state_ptr->td = 0; 00547 00548 /* 00549 * Adaptation speed control. 00550 */ 00551 state_ptr->dms += (fi - state_ptr->dms) >> 5; /* FILTA */ 00552 state_ptr->dml += (((fi << 2) - state_ptr->dml) >> 7); /* FILTB */ 00553 00554 if (tr == 1) 00555 state_ptr->ap = 256; 00556 else if (y < 1536) /* SUBTC */ 00557 state_ptr->ap += (0x200 - state_ptr->ap) >> 4; 00558 else if (state_ptr->td == 1) 00559 state_ptr->ap += (0x200 - state_ptr->ap) >> 4; 00560 else if (abs((state_ptr->dms << 2) - state_ptr->dml) >= 00561 (state_ptr->dml >> 3)) 00562 state_ptr->ap += (0x200 - state_ptr->ap) >> 4; 00563 else 00564 state_ptr->ap += (-state_ptr->ap) >> 4; 00565 }
int _dqlntab[16] [static] |
{-2048, 4, 135, 213, 273, 323, 373, 425,
425, 373, 323, 273, 213, 135, 4, -2048}
Definition at line 99 of file codec_g726.c.
int _fitab[16] [static] |
{0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00,
0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0}
Definition at line 110 of file codec_g726.c.
int _witab[16] [static] |
{-12, 18, 41, 64, 112, 198, 355, 1122,
1122, 355, 198, 112, 64, 41, 18, -12}
Definition at line 103 of file codec_g726.c.
struct ast_translator g726aal2tolin [static] |
Definition at line 796 of file codec_g726.c.
struct ast_translator g726tolin [static] |
Definition at line 772 of file codec_g726.c.
struct ast_translator lintog726 [static] |
Definition at line 784 of file codec_g726.c.
struct ast_translator lintog726aal2 [static] |
Definition at line 808 of file codec_g726.c.
int qtab_721[7] = {-124, 80, 178, 246, 300, 349, 400} [static] |
Definition at line 94 of file codec_g726.c.
1.6.1