#include "asterisk.h"
#include <fcntl.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "asterisk/lock.h"
#include "asterisk/logger.h"
#include "asterisk/linkedlists.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/translate.h"
#include "asterisk/channel.h"
#include "asterisk/utils.h"
#include "log2comp.h"
#include "slin_g726_ex.h"
#include "g726_slin_ex.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 | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
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 struct ast_frame * | g726tolin_sample (void) |
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 struct ast_frame * | lintog726_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 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 struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "ITU G.726-32kbps G726 Transcoder" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, .reload = reload, } |
static int | _dqlntab [16] |
static int | _fitab [16] |
static int | _witab [16] |
static const struct ast_module_info * | ast_module_info = &__mod_info |
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} |
Definition in file codec_g726.c.
#define BUF_SHIFT 5 |
Definition at line 68 of file codec_g726.c.
#define BUFFER_SAMPLES 8096 |
Definition at line 67 of file codec_g726.c.
#define WANT_ASM |
Definition at line 51 of file codec_g726.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 897 of file codec_g726.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 897 of file codec_g726.c.
static int fmult | ( | int | an, | |
int | srn | |||
) | [static] |
Definition at line 214 of file codec_g726.c.
References ilog2().
Referenced by predictor_pole(), and predictor_zero().
00215 { 00216 int anmag, anexp, anmant; 00217 int wanexp, wanmant; 00218 int retval; 00219 00220 anmag = (an > 0) ? an : ((-an) & 0x1FFF); 00221 anexp = ilog2(anmag) - 5; 00222 anmant = (anmag == 0) ? 32 : 00223 (anexp >= 0) ? anmag >> anexp : anmag << -anexp; 00224 wanexp = anexp + ((srn >> 6) & 0xF) - 13; 00225 00226 wanmant = (anmant * (srn & 077) + 0x30) >> 4; 00227 retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) : 00228 (wanmant >> -wanexp); 00229 00230 return (((an ^ srn) < 0) ? -retval : retval); 00231 }
static int g726_decode | ( | int | i, | |
struct g726_state * | state_ptr | |||
) | [static] |
Definition at line 587 of file codec_g726.c.
References predictor_pole(), predictor_zero(), reconstruct(), step_size(), and update().
Referenced by g726aal2tolin_framein(), and g726tolin_framein().
00588 { 00589 int sezi, sez, se; /* ACCUM */ 00590 int y; /* MIX */ 00591 int sr; /* ADDB */ 00592 int dq; 00593 int dqsez; 00594 00595 i &= 0x0f; /* mask to get proper bits */ 00596 #ifdef NOT_BLI 00597 sezi = predictor_zero(state_ptr); 00598 sez = sezi; 00599 se = sezi + predictor_pole(state_ptr); /* estimated signal */ 00600 #else 00601 sezi = predictor_zero(state_ptr); 00602 sez = sezi >> 1; 00603 se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */ 00604 #endif 00605 00606 y = step_size(state_ptr); /* dynamic quantizer step size */ 00607 00608 dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized diff. */ 00609 00610 #ifdef NOT_BLI 00611 sr = se + dq; /* reconst. signal */ 00612 dqsez = dq + sez; /* pole prediction diff. */ 00613 #else 00614 sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */ 00615 dqsez = sr - se + sez; /* pole prediction diff. */ 00616 #endif 00617 00618 update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr); 00619 00620 #ifdef NOT_BLI 00621 return (sr >> 10); /* sr was 26-bit dynamic range */ 00622 #else 00623 return (sr << 2); /* sr was 14-bit dynamic range */ 00624 #endif 00625 }
static int g726_encode | ( | int | sl, | |
struct g726_state * | state_ptr | |||
) | [static] |
Definition at line 633 of file codec_g726.c.
References predictor_pole(), predictor_zero(), quantize(), reconstruct(), step_size(), and update().
Referenced by lintog726_framein(), and lintog726aal2_framein().
00634 { 00635 int sezi, se, sez; /* ACCUM */ 00636 int d; /* SUBTA */ 00637 int sr; /* ADDB */ 00638 int y; /* MIX */ 00639 int dqsez; /* ADDC */ 00640 int dq, i; 00641 00642 #ifdef NOT_BLI 00643 sl <<= 10; /* 26-bit dynamic range */ 00644 00645 sezi = predictor_zero(state_ptr); 00646 sez = sezi; 00647 se = sezi + predictor_pole(state_ptr); /* estimated signal */ 00648 #else 00649 sl >>= 2; /* 14-bit dynamic range */ 00650 00651 sezi = predictor_zero(state_ptr); 00652 sez = sezi >> 1; 00653 se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */ 00654 #endif 00655 00656 d = sl - se; /* estimation difference */ 00657 00658 /* quantize the prediction difference */ 00659 y = step_size(state_ptr); /* quantizer step size */ 00660 #ifdef NOT_BLI 00661 d /= 0x1000; 00662 #endif 00663 i = quantize(d, y, qtab_721, 7); /* i = G726 code */ 00664 00665 dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized est diff */ 00666 00667 #ifdef NOT_BLI 00668 sr = se + dq; /* reconst. signal */ 00669 dqsez = dq + sez; /* pole prediction diff. */ 00670 #else 00671 sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */ 00672 dqsez = sr - se + sez; /* pole prediction diff. */ 00673 #endif 00674 00675 update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr); 00676 00677 return (i); 00678 }
static void g726_init_state | ( | struct g726_state * | state_ptr | ) | [static] |
Definition at line 132 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().
00133 { 00134 int cnta; 00135 00136 state_ptr->yl = 34816; 00137 state_ptr->yu = 544; 00138 state_ptr->dms = 0; 00139 state_ptr->dml = 0; 00140 state_ptr->ap = 0; 00141 for (cnta = 0; cnta < 2; cnta++) { 00142 state_ptr->a[cnta] = 0; 00143 state_ptr->pk[cnta] = 0; 00144 #ifdef NOT_BLI 00145 state_ptr->sr[cnta] = 1; 00146 #else 00147 state_ptr->sr[cnta] = 32; 00148 #endif 00149 } 00150 for (cnta = 0; cnta < 6; cnta++) { 00151 state_ptr->b[cnta] = 0; 00152 #ifdef NOT_BLI 00153 state_ptr->dq[cnta] = 1; 00154 #else 00155 state_ptr->dq[cnta] = 32; 00156 #endif 00157 } 00158 state_ptr->td = 0; 00159 }
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 702 of file codec_g726.c.
References ast_trans_pvt::datalen, f, g726_coder_pvt::g726, g726_decode(), ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00703 { 00704 struct g726_coder_pvt *tmp = pvt->pvt; 00705 unsigned char *src = f->data; 00706 int16_t *dst = (int16_t *) pvt->outbuf + pvt->samples; 00707 unsigned int i; 00708 00709 for (i = 0; i < f->datalen; i++) { 00710 *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726); 00711 *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726); 00712 } 00713 00714 pvt->samples += f->samples; 00715 pvt->datalen += 2 * f->samples; /* 2 bytes/sample */ 00716 00717 return 0; 00718 }
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 743 of file codec_g726.c.
References ast_trans_pvt::datalen, f, g726_coder_pvt::g726, g726_decode(), ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00744 { 00745 struct g726_coder_pvt *tmp = pvt->pvt; 00746 unsigned char *src = f->data; 00747 int16_t *dst = (int16_t *) pvt->outbuf + pvt->samples; 00748 unsigned int i; 00749 00750 for (i = 0; i < f->datalen; i++) { 00751 *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726); 00752 *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726); 00753 } 00754 00755 pvt->samples += f->samples; 00756 pvt->datalen += 2 * f->samples; /* 2 bytes/sample */ 00757 00758 return 0; 00759 }
static struct ast_frame* g726tolin_sample | ( | void | ) | [static] |
Definition at line 783 of file codec_g726.c.
References AST_FORMAT_G726, AST_FRAME_VOICE, f, g726_slin_ex, and ast_frame::samples.
00784 { 00785 static struct ast_frame f = { 00786 .frametype = AST_FRAME_VOICE, 00787 .subclass = AST_FORMAT_G726, 00788 .datalen = sizeof(g726_slin_ex), 00789 .samples = sizeof(g726_slin_ex) * 2, /* 2 samples per byte */ 00790 .src = __PRETTY_FUNCTION__, 00791 .data = g726_slin_ex, 00792 }; 00793 00794 return &f; 00795 }
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 762 of file codec_g726.c.
References ast_trans_pvt::datalen, f, g726_coder_pvt::g726, g726_encode(), g726_coder_pvt::next_flag, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00763 { 00764 struct g726_coder_pvt *tmp = pvt->pvt; 00765 int16_t *src = f->data; 00766 unsigned int i; 00767 00768 for (i = 0; i < f->samples; i++) { 00769 unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */ 00770 00771 if (tmp->next_flag & 0x80) { /* merge with leftover sample */ 00772 pvt->outbuf[pvt->datalen++] = (d << 4) | (tmp->next_flag & 0xf); 00773 pvt->samples += 2; /* 2 samples per byte */ 00774 tmp->next_flag = 0; 00775 } else { 00776 tmp->next_flag = 0x80 | d; 00777 } 00778 } 00779 00780 return 0; 00781 }
static int lintog726_new | ( | struct ast_trans_pvt * | pvt | ) | [static] |
init a new instance of g726_coder_pvt.
Definition at line 692 of file codec_g726.c.
References g726_coder_pvt::g726, g726_init_state(), and ast_trans_pvt::pvt.
00693 { 00694 struct g726_coder_pvt *tmp = pvt->pvt; 00695 00696 g726_init_state(&tmp->g726); 00697 00698 return 0; 00699 }
static struct ast_frame* lintog726_sample | ( | void | ) | [static] |
Definition at line 797 of file codec_g726.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, f, ast_frame::samples, and slin_g726_ex.
00798 { 00799 static struct ast_frame f = { 00800 .frametype = AST_FRAME_VOICE, 00801 .subclass = AST_FORMAT_SLINEAR, 00802 .datalen = sizeof(slin_g726_ex), 00803 .samples = sizeof(slin_g726_ex) / 2, /* 1 sample per 2 bytes */ 00804 .src = __PRETTY_FUNCTION__, 00805 .data = slin_g726_ex, 00806 }; 00807 00808 return &f; 00809 }
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 721 of file codec_g726.c.
References ast_trans_pvt::datalen, f, g726_coder_pvt::g726, g726_encode(), g726_coder_pvt::next_flag, ast_trans_pvt::outbuf, ast_trans_pvt::pvt, and ast_trans_pvt::samples.
00722 { 00723 struct g726_coder_pvt *tmp = pvt->pvt; 00724 int16_t *src = f->data; 00725 unsigned int i; 00726 00727 for (i = 0; i < f->samples; i++) { 00728 unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */ 00729 00730 if (tmp->next_flag & 0x80) { /* merge with leftover sample */ 00731 pvt->outbuf[pvt->datalen++] = ((tmp->next_flag & 0xf)<< 4) | d; 00732 pvt->samples += 2; /* 2 samples per byte */ 00733 tmp->next_flag = 0; 00734 } else { 00735 tmp->next_flag = 0x80 | d; 00736 } 00737 } 00738 00739 return 0; 00740 }
static int load_module | ( | void | ) | [static] |
Definition at line 877 of file codec_g726.c.
References ast_register_translator, g726aal2tolin, g726tolin, lintog726, lintog726aal2, and unload_module().
00878 { 00879 int res = 0; 00880 00881 res |= ast_register_translator(&g726tolin); 00882 res |= ast_register_translator(&lintog726); 00883 00884 res |= ast_register_translator(&g726aal2tolin); 00885 res |= ast_register_translator(&lintog726aal2); 00886 00887 if (res) 00888 unload_module(); 00889 00890 return res; 00891 }
static int predictor_pole | ( | struct g726_state * | state_ptr | ) | [static] |
Definition at line 242 of file codec_g726.c.
References g726_state::a, fmult(), and g726_state::sr.
Referenced by g726_decode(), and g726_encode().
00243 { 00244 return (fmult(state_ptr->a[1] >> 2, state_ptr->sr[1]) + 00245 fmult(state_ptr->a[0] >> 2, state_ptr->sr[0])); 00246 }
static int predictor_zero | ( | struct g726_state * | state_ptr | ) | [static] |
Definition at line 233 of file codec_g726.c.
References g726_state::b, g726_state::dq, and fmult().
Referenced by g726_decode(), and g726_encode().
00234 { 00235 int i; 00236 int sezi; 00237 for (sezi = 0, i = 0; i < 6; i++) /* ACCUM */ 00238 sezi += fmult(state_ptr->b[i] >> 2, state_ptr->dq[i]); 00239 return sezi; 00240 }
static int quan | ( | int | val, | |
int * | table, | |||
int | size | |||
) | [static] |
Definition at line 169 of file codec_g726.c.
Referenced by quantize().
00170 { 00171 int i; 00172 00173 for (i = 0; i < size && val >= *table; ++i, ++table) 00174 ; 00175 return (i); 00176 }
static int quantize | ( | int | d, | |
int | y, | |||
int * | table, | |||
int | size | |||
) | [static] |
Definition at line 285 of file codec_g726.c.
References ilog2(), and quan().
Referenced by g726_encode().
00290 { 00291 int dqm; /* Magnitude of 'd' */ 00292 int exp; /* Integer part of base 2 log of 'd' */ 00293 int mant; /* Fractional part of base 2 log */ 00294 int dl; /* Log of magnitude of 'd' */ 00295 int dln; /* Step size scale factor normalized log */ 00296 int i; 00297 00298 /* 00299 * LOG 00300 * 00301 * Compute base 2 log of 'd', and store in 'dl'. 00302 */ 00303 dqm = abs(d); 00304 exp = ilog2(dqm); 00305 if (exp < 0) 00306 exp = 0; 00307 mant = ((dqm << 7) >> exp) & 0x7F; /* Fractional portion. */ 00308 dl = (exp << 7) | mant; 00309 00310 /* 00311 * SUBTB 00312 * 00313 * "Divide" by step size multiplier. 00314 */ 00315 dln = dl - (y >> 2); 00316 00317 /* 00318 * QUAN 00319 * 00320 * Obtain codword i for 'd'. 00321 */ 00322 i = quan(dln, table, size); 00323 if (d < 0) /* take 1's complement of i */ 00324 return ((size << 1) + 1 - i); 00325 else if (i == 0) /* take 1's complement of 0 */ 00326 return ((size << 1) + 1); /* new in 1988 */ 00327 else 00328 return (i); 00329 }
static int reconstruct | ( | int | sign, | |
int | dqln, | |||
int | y | |||
) | [static] |
Definition at line 338 of file codec_g726.c.
Referenced by bridge_p2p_rtp_write(), g726_decode(), and g726_encode().
00342 { 00343 int dql; /* Log of 'dq' magnitude */ 00344 int dex; /* Integer part of log */ 00345 int dqt; 00346 int dq; /* Reconstructed difference signal sample */ 00347 00348 dql = dqln + (y >> 2); /* ADDA */ 00349 00350 if (dql < 0) { 00351 #ifdef NOT_BLI 00352 return (sign) ? -1 : 1; 00353 #else 00354 return (sign) ? -0x8000 : 0; 00355 #endif 00356 } else { /* ANTILOG */ 00357 dex = (dql >> 7) & 15; 00358 dqt = 128 + (dql & 127); 00359 #ifdef NOT_BLI 00360 dq = ((dqt << 19) >> (14 - dex)); 00361 return (sign) ? -dq : dq; 00362 #else 00363 dq = (dqt << 7) >> (14 - dex); 00364 return (sign) ? (dq - 0x8000) : dq; 00365 #endif 00366 } 00367 }
static int reload | ( | void | ) | [static] |
static int step_size | ( | struct g726_state * | state_ptr | ) | [static] |
Definition at line 256 of file codec_g726.c.
References g726_state::ap, g726_state::yl, and g726_state::yu.
Referenced by g726_decode(), and g726_encode().
00257 { 00258 int y; 00259 int dif; 00260 int al; 00261 00262 if (state_ptr->ap >= 256) 00263 return (state_ptr->yu); 00264 else { 00265 y = state_ptr->yl >> 6; 00266 dif = state_ptr->yu - y; 00267 al = state_ptr->ap >> 2; 00268 if (dif > 0) 00269 y += (dif * al) >> 6; 00270 else if (dif < 0) 00271 y += (dif * al + 0x3F) >> 6; 00272 return (y); 00273 } 00274 }
static int unload_module | ( | void | ) | [static] |
Definition at line 864 of file codec_g726.c.
References ast_unregister_translator(), g726aal2tolin, g726tolin, lintog726, and lintog726aal2.
00865 { 00866 int res = 0; 00867 00868 res |= ast_unregister_translator(&g726tolin); 00869 res |= ast_unregister_translator(&lintog726); 00870 00871 res |= ast_unregister_translator(&g726aal2tolin); 00872 res |= ast_unregister_translator(&lintog726aal2); 00873 00874 return res; 00875 }
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 374 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 add_extensionstate_update(), check_extenstate_updates(), clear_extenstate_updates(), clearmarked_extenstate_updates(), g726_decode(), g726_encode(), markall_extenstate_updates(), unload_module(), and unmark_extenstate_update().
00383 { 00384 int cnt; 00385 int mag; /* Adaptive predictor, FLOAT A */ 00386 #ifndef NOT_BLI 00387 int exp; 00388 #endif 00389 int a2p=0; /* LIMC */ 00390 int a1ul; /* UPA1 */ 00391 int pks1; /* UPA2 */ 00392 int fa1; 00393 int tr; /* tone/transition detector */ 00394 int ylint, thr2, dqthr; 00395 int ylfrac, thr1; 00396 int pk0; 00397 00398 pk0 = (dqsez < 0) ? 1 : 0; /* needed in updating predictor poles */ 00399 00400 #ifdef NOT_BLI 00401 mag = abs(dq / 0x1000); /* prediction difference magnitude */ 00402 #else 00403 mag = dq & 0x7FFF; /* prediction difference magnitude */ 00404 #endif 00405 /* TRANS */ 00406 ylint = state_ptr->yl >> 15; /* exponent part of yl */ 00407 ylfrac = (state_ptr->yl >> 10) & 0x1F; /* fractional part of yl */ 00408 thr1 = (32 + ylfrac) << ylint; /* threshold */ 00409 thr2 = (ylint > 9) ? 31 << 10 : thr1; /* limit thr2 to 31 << 10 */ 00410 dqthr = (thr2 + (thr2 >> 1)) >> 1; /* dqthr = 0.75 * thr2 */ 00411 if (state_ptr->td == 0) /* signal supposed voice */ 00412 tr = 0; 00413 else if (mag <= dqthr) /* supposed data, but small mag */ 00414 tr = 0; /* treated as voice */ 00415 else /* signal is data (modem) */ 00416 tr = 1; 00417 00418 /* 00419 * Quantizer scale factor adaptation. 00420 */ 00421 00422 /* FUNCTW & FILTD & DELAY */ 00423 /* update non-steady state step size multiplier */ 00424 state_ptr->yu = y + ((wi - y) >> 5); 00425 00426 /* LIMB */ 00427 if (state_ptr->yu < 544) /* 544 <= yu <= 5120 */ 00428 state_ptr->yu = 544; 00429 else if (state_ptr->yu > 5120) 00430 state_ptr->yu = 5120; 00431 00432 /* FILTE & DELAY */ 00433 /* update steady state step size multiplier */ 00434 state_ptr->yl += state_ptr->yu + ((-state_ptr->yl) >> 6); 00435 00436 /* 00437 * Adaptive predictor coefficients. 00438 */ 00439 if (tr == 1) { /* reset a's and b's for modem signal */ 00440 state_ptr->a[0] = 0; 00441 state_ptr->a[1] = 0; 00442 state_ptr->b[0] = 0; 00443 state_ptr->b[1] = 0; 00444 state_ptr->b[2] = 0; 00445 state_ptr->b[3] = 0; 00446 state_ptr->b[4] = 0; 00447 state_ptr->b[5] = 0; 00448 } else { /* update a's and b's */ 00449 pks1 = pk0 ^ state_ptr->pk[0]; /* UPA2 */ 00450 00451 /* update predictor pole a[1] */ 00452 a2p = state_ptr->a[1] - (state_ptr->a[1] >> 7); 00453 if (dqsez != 0) { 00454 fa1 = (pks1) ? state_ptr->a[0] : -state_ptr->a[0]; 00455 if (fa1 < -8191) /* a2p = function of fa1 */ 00456 a2p -= 0x100; 00457 else if (fa1 > 8191) 00458 a2p += 0xFF; 00459 else 00460 a2p += fa1 >> 5; 00461 00462 if (pk0 ^ state_ptr->pk[1]) 00463 /* LIMC */ 00464 if (a2p <= -12160) 00465 a2p = -12288; 00466 else if (a2p >= 12416) 00467 a2p = 12288; 00468 else 00469 a2p -= 0x80; 00470 else if (a2p <= -12416) 00471 a2p = -12288; 00472 else if (a2p >= 12160) 00473 a2p = 12288; 00474 else 00475 a2p += 0x80; 00476 } 00477 00478 /* TRIGB & DELAY */ 00479 state_ptr->a[1] = a2p; 00480 00481 /* UPA1 */ 00482 /* update predictor pole a[0] */ 00483 state_ptr->a[0] -= state_ptr->a[0] >> 8; 00484 if (dqsez != 0) { 00485 if (pks1 == 0) 00486 state_ptr->a[0] += 192; 00487 else 00488 state_ptr->a[0] -= 192; 00489 } 00490 /* LIMD */ 00491 a1ul = 15360 - a2p; 00492 if (state_ptr->a[0] < -a1ul) 00493 state_ptr->a[0] = -a1ul; 00494 else if (state_ptr->a[0] > a1ul) 00495 state_ptr->a[0] = a1ul; 00496 00497 /* UPB : update predictor zeros b[6] */ 00498 for (cnt = 0; cnt < 6; cnt++) { 00499 if (code_size == 5) /* for 40Kbps G.723 */ 00500 state_ptr->b[cnt] -= state_ptr->b[cnt] >> 9; 00501 else /* for G.721 and 24Kbps G.723 */ 00502 state_ptr->b[cnt] -= state_ptr->b[cnt] >> 8; 00503 if (mag) 00504 { /* XOR */ 00505 if ((dq ^ state_ptr->dq[cnt]) >= 0) 00506 state_ptr->b[cnt] += 128; 00507 else 00508 state_ptr->b[cnt] -= 128; 00509 } 00510 } 00511 } 00512 00513 for (cnt = 5; cnt > 0; cnt--) 00514 state_ptr->dq[cnt] = state_ptr->dq[cnt-1]; 00515 #ifdef NOT_BLI 00516 state_ptr->dq[0] = dq; 00517 #else 00518 /* FLOAT A : convert dq[0] to 4-bit exp, 6-bit mantissa f.p. */ 00519 if (mag == 0) { 00520 state_ptr->dq[0] = (dq >= 0) ? 0x20 : 0x20 - 0x400; 00521 } else { 00522 exp = ilog2(mag) + 1; 00523 state_ptr->dq[0] = (dq >= 0) ? 00524 (exp << 6) + ((mag << 6) >> exp) : 00525 (exp << 6) + ((mag << 6) >> exp) - 0x400; 00526 } 00527 #endif 00528 00529 state_ptr->sr[1] = state_ptr->sr[0]; 00530 #ifdef NOT_BLI 00531 state_ptr->sr[0] = sr; 00532 #else 00533 /* FLOAT B : convert sr to 4-bit exp., 6-bit mantissa f.p. */ 00534 if (sr == 0) { 00535 state_ptr->sr[0] = 0x20; 00536 } else if (sr > 0) { 00537 exp = ilog2(sr) + 1; 00538 state_ptr->sr[0] = (exp << 6) + ((sr << 6) >> exp); 00539 } else if (sr > -0x8000) { 00540 mag = -sr; 00541 exp = ilog2(mag) + 1; 00542 state_ptr->sr[0] = (exp << 6) + ((mag << 6) >> exp) - 0x400; 00543 } else 00544 state_ptr->sr[0] = 0x20 - 0x400; 00545 #endif 00546 00547 /* DELAY A */ 00548 state_ptr->pk[1] = state_ptr->pk[0]; 00549 state_ptr->pk[0] = pk0; 00550 00551 /* TONE */ 00552 if (tr == 1) /* this sample has been treated as data */ 00553 state_ptr->td = 0; /* next one will be treated as voice */ 00554 else if (a2p < -11776) /* small sample-to-sample correlation */ 00555 state_ptr->td = 1; /* signal may be data */ 00556 else /* signal is voice */ 00557 state_ptr->td = 0; 00558 00559 /* 00560 * Adaptation speed control. 00561 */ 00562 state_ptr->dms += (fi - state_ptr->dms) >> 5; /* FILTA */ 00563 state_ptr->dml += (((fi << 2) - state_ptr->dml) >> 7); /* FILTB */ 00564 00565 if (tr == 1) 00566 state_ptr->ap = 256; 00567 else if (y < 1536) /* SUBTC */ 00568 state_ptr->ap += (0x200 - state_ptr->ap) >> 4; 00569 else if (state_ptr->td == 1) 00570 state_ptr->ap += (0x200 - state_ptr->ap) >> 4; 00571 else if (abs((state_ptr->dms << 2) - state_ptr->dml) >= 00572 (state_ptr->dml >> 3)) 00573 state_ptr->ap += (0x200 - state_ptr->ap) >> 4; 00574 else 00575 state_ptr->ap += (-state_ptr->ap) >> 4; 00576 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "ITU G.726-32kbps G726 Transcoder" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, .reload = reload, } [static] |
Definition at line 897 of file codec_g726.c.
int _dqlntab[16] [static] |
Initial value:
{-2048, 4, 135, 213, 273, 323, 373, 425, 425, 373, 323, 273, 213, 135, 4, -2048}
Definition at line 110 of file codec_g726.c.
int _fitab[16] [static] |
Initial value:
{0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00, 0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0}
Definition at line 121 of file codec_g726.c.
int _witab[16] [static] |
Initial value:
{-12, 18, 41, 64, 112, 198, 355, 1122, 1122, 355, 198, 112, 64, 41, 18, -12}
Definition at line 114 of file codec_g726.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 897 of file codec_g726.c.
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} [static] |
Definition at line 105 of file codec_g726.c.