Thu Sep 7 01:03:26 2017

Asterisk developer's documentation


codec_g726.c File Reference

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}

Detailed Description

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 Documentation

#define BUF_SHIFT   5

Definition at line 62 of file codec_g726.c.

#define BUFFER_SAMPLES   8096

Definition at line 61 of file codec_g726.c.

#define WANT_ASM

Definition at line 45 of file codec_g726.c.


Function Documentation

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 207 of file codec_g726.c.

References ilog2().

Referenced by predictor_pole(), and predictor_zero().

00208 {
00209    int      anmag, anexp, anmant;
00210    int      wanexp, wanmant;
00211    int      retval;
00212 
00213    anmag = (an > 0) ? an : ((-an) & 0x1FFF);
00214    anexp = ilog2(anmag) - 5;
00215    anmant = (anmag == 0) ? 32 :
00216        (anexp >= 0) ? anmag >> anexp : anmag << -anexp;
00217    wanexp = anexp + ((srn >> 6) & 0xF) - 13;
00218 
00219    wanmant = (anmant * (srn & 077) + 0x30) >> 4;
00220    retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) :
00221        (wanmant >> -wanexp);
00222 
00223    return (((an ^ srn) < 0) ? -retval : retval);
00224 }

static int g726_decode ( int  i,
struct g726_state state_ptr 
) [static]

Definition at line 580 of file codec_g726.c.

References predictor_pole(), predictor_zero(), reconstruct(), step_size(), and update().

Referenced by g726aal2tolin_framein(), and g726tolin_framein().

00581 {
00582    int      sezi, sez, se; /* ACCUM */
00583    int      y;       /* MIX */
00584    int      sr;         /* ADDB */
00585    int      dq;
00586    int      dqsez;
00587 
00588    i &= 0x0f;        /* mask to get proper bits */
00589 #ifdef NOT_BLI
00590    sezi = predictor_zero(state_ptr);
00591    sez = sezi;
00592    se = sezi + predictor_pole(state_ptr); /* estimated signal */
00593 #else
00594    sezi = predictor_zero(state_ptr);
00595    sez = sezi >> 1;
00596    se = (sezi + predictor_pole(state_ptr)) >> 1;   /* estimated signal */
00597 #endif
00598 
00599    y = step_size(state_ptr);  /* dynamic quantizer step size */
00600 
00601    dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized diff. */
00602 
00603 #ifdef NOT_BLI
00604    sr = se + dq;           /* reconst. signal */
00605    dqsez = dq + sez;       /* pole prediction diff. */
00606 #else
00607    sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq;   /* reconst. signal */
00608    dqsez = sr - se + sez;     /* pole prediction diff. */
00609 #endif
00610 
00611    update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
00612 
00613 #ifdef NOT_BLI
00614    return (sr >> 10);   /* sr was 26-bit dynamic range */
00615 #else
00616    return (sr << 2); /* sr was 14-bit dynamic range */
00617 #endif
00618 }

static int g726_encode ( int  sl,
struct g726_state state_ptr 
) [static]

Definition at line 626 of file codec_g726.c.

References predictor_pole(), predictor_zero(), quantize(), reconstruct(), step_size(), and update().

Referenced by lintog726_framein(), and lintog726aal2_framein().

00627 {
00628    int      sezi, se, sez;    /* ACCUM */
00629    int      d;       /* SUBTA */
00630    int      sr;         /* ADDB */
00631    int      y;       /* MIX */
00632    int      dqsez;         /* ADDC */
00633    int      dq, i;
00634 
00635 #ifdef NOT_BLI
00636    sl <<= 10;        /* 26-bit dynamic range */
00637 
00638    sezi = predictor_zero(state_ptr);
00639    sez = sezi;
00640    se = sezi + predictor_pole(state_ptr); /* estimated signal */
00641 #else
00642    sl >>= 2;         /* 14-bit dynamic range */
00643 
00644    sezi = predictor_zero(state_ptr);
00645    sez = sezi >> 1;
00646    se = (sezi + predictor_pole(state_ptr)) >> 1;   /* estimated signal */
00647 #endif
00648 
00649    d = sl - se;            /* estimation difference */
00650 
00651    /* quantize the prediction difference */
00652    y = step_size(state_ptr);     /* quantizer step size */
00653 #ifdef NOT_BLI
00654    d /= 0x1000;
00655 #endif
00656    i = quantize(d, y, qtab_721, 7); /* i = G726 code */
00657 
00658    dq = reconstruct(i & 8, _dqlntab[i], y);  /* quantized est diff */
00659 
00660 #ifdef NOT_BLI
00661    sr = se + dq;           /* reconst. signal */
00662    dqsez = dq + sez;       /* pole prediction diff. */
00663 #else
00664    sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq;   /* reconst. signal */
00665    dqsez = sr - se + sez;        /* pole prediction diff. */
00666 #endif
00667 
00668    update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
00669 
00670    return (i);
00671 }

static void g726_init_state ( struct g726_state state_ptr  )  [static]

Definition at line 125 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().

00126 {
00127    int      cnta;
00128 
00129    state_ptr->yl = 34816;
00130    state_ptr->yu = 544;
00131    state_ptr->dms = 0;
00132    state_ptr->dml = 0;
00133    state_ptr->ap = 0;
00134    for (cnta = 0; cnta < 2; cnta++) {
00135       state_ptr->a[cnta] = 0;
00136       state_ptr->pk[cnta] = 0;
00137 #ifdef NOT_BLI
00138       state_ptr->sr[cnta] = 1;
00139 #else
00140       state_ptr->sr[cnta] = 32;
00141 #endif
00142    }
00143    for (cnta = 0; cnta < 6; cnta++) {
00144       state_ptr->b[cnta] = 0;
00145 #ifdef NOT_BLI
00146       state_ptr->dq[cnta] = 1;
00147 #else
00148       state_ptr->dq[cnta] = 32;
00149 #endif
00150    }
00151    state_ptr->td = 0;
00152 }

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 695 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.

00696 {
00697    struct g726_coder_pvt *tmp = pvt->pvt;
00698    unsigned char *src = f->data.ptr;
00699    int16_t *dst = pvt->outbuf.i16 + pvt->samples;
00700    unsigned int i;
00701 
00702    for (i = 0; i < f->datalen; i++) {
00703       *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726);
00704       *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726);
00705    }
00706 
00707    pvt->samples += f->samples;
00708    pvt->datalen += 2 * f->samples; /* 2 bytes/sample */
00709 
00710    return 0;
00711 }

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 736 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.

00737 {
00738    struct g726_coder_pvt *tmp = pvt->pvt;
00739    unsigned char *src = f->data.ptr;
00740    int16_t *dst = pvt->outbuf.i16 + pvt->samples;
00741    unsigned int i;
00742 
00743    for (i = 0; i < f->datalen; i++) {
00744       *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726);
00745       *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726);
00746    }
00747 
00748    pvt->samples += f->samples;
00749    pvt->datalen += 2 * f->samples; /* 2 bytes/sample */
00750 
00751    return 0;
00752 }

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 755 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.

00756 {
00757    struct g726_coder_pvt *tmp = pvt->pvt;
00758    int16_t *src = f->data.ptr;
00759    unsigned int i;
00760 
00761    for (i = 0; i < f->samples; i++) {
00762       unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */
00763 
00764       if (tmp->next_flag & 0x80) {  /* merge with leftover sample */
00765          pvt->outbuf.c[pvt->datalen++] = (d << 4) | (tmp->next_flag & 0xf);
00766          pvt->samples += 2;   /* 2 samples per byte */
00767          tmp->next_flag = 0;
00768       } else {
00769          tmp->next_flag = 0x80 | d;
00770       }
00771    }
00772 
00773    return 0;
00774 }

static int lintog726_new ( struct ast_trans_pvt pvt  )  [static]

init a new instance of g726_coder_pvt.

Definition at line 685 of file codec_g726.c.

References g726_coder_pvt::g726, g726_init_state(), and ast_trans_pvt::pvt.

00686 {
00687    struct g726_coder_pvt *tmp = pvt->pvt;
00688 
00689    g726_init_state(&tmp->g726);
00690 
00691    return 0;
00692 }

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 714 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.

00715 {
00716    struct g726_coder_pvt *tmp = pvt->pvt;
00717    int16_t *src = f->data.ptr;
00718    unsigned int i;
00719 
00720    for (i = 0; i < f->samples; i++) {
00721       unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */
00722 
00723       if (tmp->next_flag & 0x80) {  /* merge with leftover sample */
00724          pvt->outbuf.c[pvt->datalen++] = ((tmp->next_flag & 0xf)<< 4) | d;
00725          pvt->samples += 2;   /* 2 samples per byte */
00726          tmp->next_flag = 0;
00727       } else {
00728          tmp->next_flag = 0x80 | d;
00729       }
00730    }
00731 
00732    return 0;
00733 }

static int load_module ( void   )  [static]

Definition at line 842 of file codec_g726.c.

References AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, and unload_module.

00843 {
00844    int res = 0;
00845 
00846    res |= ast_register_translator(&g726tolin);
00847    res |= ast_register_translator(&lintog726);
00848 
00849    res |= ast_register_translator(&g726aal2tolin);
00850    res |= ast_register_translator(&lintog726aal2);
00851 
00852    if (res) {
00853       unload_module();
00854       return AST_MODULE_LOAD_FAILURE;
00855    }  
00856 
00857    return AST_MODULE_LOAD_SUCCESS;
00858 }

static int predictor_pole ( struct g726_state state_ptr  )  [static]

Definition at line 235 of file codec_g726.c.

References g726_state::a, fmult(), and g726_state::sr.

Referenced by g726_decode(), and g726_encode().

00236 {
00237    return (fmult(state_ptr->a[1] >> 2, state_ptr->sr[1]) +
00238          fmult(state_ptr->a[0] >> 2, state_ptr->sr[0]));
00239 }

static int predictor_zero ( struct g726_state state_ptr  )  [static]

Definition at line 226 of file codec_g726.c.

References g726_state::b, g726_state::dq, and fmult().

Referenced by g726_decode(), and g726_encode().

00227 {
00228    int      i;
00229    int      sezi;
00230    for (sezi = 0, i = 0; i < 6; i++)         /* ACCUM */
00231       sezi += fmult(state_ptr->b[i] >> 2, state_ptr->dq[i]);
00232    return sezi;
00233 }

static int quan ( int  val,
int *  table,
int  size 
) [static]

Definition at line 162 of file codec_g726.c.

Referenced by quantize().

00163 {
00164    int      i;
00165 
00166    for (i = 0; i < size && val >= *table; ++i, ++table)
00167       ;
00168    return (i);
00169 }

static int quantize ( int  d,
int  y,
int *  table,
int  size 
) [static]

Definition at line 278 of file codec_g726.c.

References ilog2(), and quan().

Referenced by g726_encode().

00283 {
00284    int      dqm;  /* Magnitude of 'd' */
00285    int      exp;  /* Integer part of base 2 log of 'd' */
00286    int      mant; /* Fractional part of base 2 log */
00287    int      dl;      /* Log of magnitude of 'd' */
00288    int      dln;  /* Step size scale factor normalized log */
00289    int      i;
00290 
00291    /*
00292     * LOG
00293     *
00294     * Compute base 2 log of 'd', and store in 'dl'.
00295     */
00296    dqm = abs(d);
00297    exp = ilog2(dqm);
00298    if (exp < 0)
00299       exp = 0;
00300    mant = ((dqm << 7) >> exp) & 0x7F;  /* Fractional portion. */
00301    dl = (exp << 7) | mant;
00302 
00303    /*
00304     * SUBTB
00305     *
00306     * "Divide" by step size multiplier.
00307     */
00308    dln = dl - (y >> 2);
00309 
00310    /*
00311     * QUAN
00312     *
00313     * Obtain codword i for 'd'.
00314     */
00315    i = quan(dln, table, size);
00316    if (d < 0)        /* take 1's complement of i */
00317       return ((size << 1) + 1 - i);
00318    else if (i == 0)     /* take 1's complement of 0 */
00319       return ((size << 1) + 1); /* new in 1988 */
00320    else
00321       return (i);
00322 }

static int reconstruct ( int  sign,
int  dqln,
int  y 
) [static]

Definition at line 331 of file codec_g726.c.

Referenced by bridge_p2p_rtp_write(), g726_decode(), and g726_encode().

00335 {
00336    int      dql;  /* Log of 'dq' magnitude */
00337    int      dex;  /* Integer part of log */
00338    int      dqt;
00339    int      dq;   /* Reconstructed difference signal sample */
00340 
00341    dql = dqln + (y >> 2);  /* ADDA */
00342 
00343    if (dql < 0) {
00344 #ifdef NOT_BLI
00345       return (sign) ? -1 : 1;
00346 #else
00347       return (sign) ? -0x8000 : 0;
00348 #endif
00349    } else {    /* ANTILOG */
00350       dex = (dql >> 7) & 15;
00351       dqt = 128 + (dql & 127);
00352 #ifdef NOT_BLI
00353       dq = ((dqt << 19) >> (14 - dex));
00354       return (sign) ? -dq : dq;
00355 #else
00356       dq = (dqt << 7) >> (14 - dex);
00357       return (sign) ? (dq - 0x8000) : dq;
00358 #endif
00359    }
00360 }

static int reload ( void   )  [static]

Definition at line 824 of file codec_g726.c.

References AST_MODULE_LOAD_SUCCESS.

00825 {
00826    return AST_MODULE_LOAD_SUCCESS;
00827 }

static int step_size ( struct g726_state state_ptr  )  [static]

Definition at line 249 of file codec_g726.c.

References g726_state::ap, g726_state::yl, and g726_state::yu.

Referenced by g726_decode(), g726_encode(), and smb_pitch_shift().

00250 {
00251    int      y;
00252    int      dif;
00253    int      al;
00254 
00255    if (state_ptr->ap >= 256)
00256       return (state_ptr->yu);
00257    else {
00258       y = state_ptr->yl >> 6;
00259       dif = state_ptr->yu - y;
00260       al = state_ptr->ap >> 2;
00261       if (dif > 0)
00262          y += (dif * al) >> 6;
00263       else if (dif < 0)
00264          y += (dif * al + 0x3F) >> 6;
00265       return (y);
00266    }
00267 }

static int unload_module ( void   )  [static]

Definition at line 829 of file codec_g726.c.

References ast_unregister_translator().

00830 {
00831    int res = 0;
00832 
00833    res |= ast_unregister_translator(&g726tolin);
00834    res |= ast_unregister_translator(&lintog726);
00835 
00836    res |= ast_unregister_translator(&g726aal2tolin);
00837    res |= ast_unregister_translator(&lintog726aal2);
00838 
00839    return res;
00840 }

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 367 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(), connectedline_write(), g726_decode(), g726_encode(), load_pktccops_config(), and redirecting_write().

00376 {
00377    int      cnt;
00378    int      mag;     /* Adaptive predictor, FLOAT A */
00379 #ifndef NOT_BLI
00380    int      exp;
00381 #endif
00382    int      a2p=0;      /* LIMC */
00383    int      a1ul;    /* UPA1 */
00384    int      pks1;    /* UPA2 */
00385    int      fa1;
00386    int      tr;         /* tone/transition detector */
00387    int      ylint, thr2, dqthr;
00388    int      ylfrac, thr1;
00389    int      pk0;
00390 
00391    pk0 = (dqsez < 0) ? 1 : 0; /* needed in updating predictor poles */
00392 
00393 #ifdef NOT_BLI
00394    mag = abs(dq / 0x1000); /* prediction difference magnitude */
00395 #else
00396    mag = dq & 0x7FFF;      /* prediction difference magnitude */
00397 #endif
00398    /* TRANS */
00399    ylint = state_ptr->yl >> 15;  /* exponent part of yl */
00400    ylfrac = (state_ptr->yl >> 10) & 0x1F; /* fractional part of yl */
00401    thr1 = (32 + ylfrac) << ylint;      /* threshold */
00402    thr2 = (ylint > 9) ? 31 << 10 : thr1;  /* limit thr2 to 31 << 10 */
00403    dqthr = (thr2 + (thr2 >> 1)) >> 1;  /* dqthr = 0.75 * thr2 */
00404    if (state_ptr->td == 0)    /* signal supposed voice */
00405       tr = 0;
00406    else if (mag <= dqthr)     /* supposed data, but small mag */
00407       tr = 0;        /* treated as voice */
00408    else           /* signal is data (modem) */
00409       tr = 1;
00410 
00411    /*
00412     * Quantizer scale factor adaptation.
00413     */
00414 
00415    /* FUNCTW & FILTD & DELAY */
00416    /* update non-steady state step size multiplier */
00417    state_ptr->yu = y + ((wi - y) >> 5);
00418 
00419    /* LIMB */
00420    if (state_ptr->yu < 544)   /* 544 <= yu <= 5120 */
00421       state_ptr->yu = 544;
00422    else if (state_ptr->yu > 5120)
00423       state_ptr->yu = 5120;
00424 
00425    /* FILTE & DELAY */
00426    /* update steady state step size multiplier */
00427    state_ptr->yl += state_ptr->yu + ((-state_ptr->yl) >> 6);
00428 
00429    /*
00430     * Adaptive predictor coefficients.
00431     */
00432    if (tr == 1) {       /* reset a's and b's for modem signal */
00433       state_ptr->a[0] = 0;
00434       state_ptr->a[1] = 0;
00435       state_ptr->b[0] = 0;
00436       state_ptr->b[1] = 0;
00437       state_ptr->b[2] = 0;
00438       state_ptr->b[3] = 0;
00439       state_ptr->b[4] = 0;
00440       state_ptr->b[5] = 0;
00441    } else {       /* update a's and b's */
00442       pks1 = pk0 ^ state_ptr->pk[0];      /* UPA2 */
00443 
00444       /* update predictor pole a[1] */
00445       a2p = state_ptr->a[1] - (state_ptr->a[1] >> 7);
00446       if (dqsez != 0) {
00447          fa1 = (pks1) ? state_ptr->a[0] : -state_ptr->a[0];
00448          if (fa1 < -8191)  /* a2p = function of fa1 */
00449             a2p -= 0x100;
00450          else if (fa1 > 8191)
00451             a2p += 0xFF;
00452          else
00453             a2p += fa1 >> 5;
00454 
00455          if (pk0 ^ state_ptr->pk[1])
00456             /* LIMC */
00457             if (a2p <= -12160)
00458                a2p = -12288;
00459             else if (a2p >= 12416)
00460                a2p = 12288;
00461             else
00462                a2p -= 0x80;
00463          else if (a2p <= -12416)
00464             a2p = -12288;
00465          else if (a2p >= 12160)
00466             a2p = 12288;
00467          else
00468             a2p += 0x80;
00469       }
00470 
00471       /* TRIGB & DELAY */
00472       state_ptr->a[1] = a2p;
00473 
00474       /* UPA1 */
00475       /* update predictor pole a[0] */
00476       state_ptr->a[0] -= state_ptr->a[0] >> 8;
00477       if (dqsez != 0) {
00478          if (pks1 == 0)
00479             state_ptr->a[0] += 192;
00480          else
00481             state_ptr->a[0] -= 192;
00482       }
00483       /* LIMD */
00484       a1ul = 15360 - a2p;
00485       if (state_ptr->a[0] < -a1ul)
00486          state_ptr->a[0] = -a1ul;
00487       else if (state_ptr->a[0] > a1ul)
00488          state_ptr->a[0] = a1ul;
00489 
00490       /* UPB : update predictor zeros b[6] */
00491       for (cnt = 0; cnt < 6; cnt++) {
00492          if (code_size == 5)     /* for 40Kbps G.723 */
00493             state_ptr->b[cnt] -= state_ptr->b[cnt] >> 9;
00494          else        /* for G.721 and 24Kbps G.723 */
00495             state_ptr->b[cnt] -= state_ptr->b[cnt] >> 8;
00496          if (mag)
00497          {  /* XOR */
00498             if ((dq ^ state_ptr->dq[cnt]) >= 0)
00499                state_ptr->b[cnt] += 128;
00500             else
00501                state_ptr->b[cnt] -= 128;
00502          }
00503       }
00504    }
00505 
00506    for (cnt = 5; cnt > 0; cnt--)
00507       state_ptr->dq[cnt] = state_ptr->dq[cnt-1];
00508 #ifdef NOT_BLI
00509    state_ptr->dq[0] = dq;
00510 #else
00511    /* FLOAT A : convert dq[0] to 4-bit exp, 6-bit mantissa f.p. */
00512    if (mag == 0) {
00513       state_ptr->dq[0] = (dq >= 0) ? 0x20 : 0x20 - 0x400;
00514    } else {
00515       exp = ilog2(mag) + 1;
00516       state_ptr->dq[0] = (dq >= 0) ?
00517           (exp << 6) + ((mag << 6) >> exp) :
00518           (exp << 6) + ((mag << 6) >> exp) - 0x400;
00519    }
00520 #endif
00521 
00522    state_ptr->sr[1] = state_ptr->sr[0];
00523 #ifdef NOT_BLI
00524    state_ptr->sr[0] = sr;
00525 #else
00526    /* FLOAT B : convert sr to 4-bit exp., 6-bit mantissa f.p. */
00527    if (sr == 0) {
00528       state_ptr->sr[0] = 0x20;
00529    } else if (sr > 0) {
00530       exp = ilog2(sr) + 1;
00531       state_ptr->sr[0] = (exp << 6) + ((sr << 6) >> exp);
00532    } else if (sr > -0x8000) {
00533       mag = -sr;
00534       exp = ilog2(mag) + 1;
00535       state_ptr->sr[0] =  (exp << 6) + ((mag << 6) >> exp) - 0x400;
00536    } else
00537       state_ptr->sr[0] = 0x20 - 0x400;
00538 #endif
00539 
00540    /* DELAY A */
00541    state_ptr->pk[1] = state_ptr->pk[0];
00542    state_ptr->pk[0] = pk0;
00543 
00544    /* TONE */
00545    if (tr == 1)      /* this sample has been treated as data */
00546       state_ptr->td = 0;   /* next one will be treated as voice */
00547    else if (a2p < -11776)  /* small sample-to-sample correlation */
00548       state_ptr->td = 1;   /* signal may be data */
00549    else           /* signal is voice */
00550       state_ptr->td = 0;
00551 
00552    /*
00553     * Adaptation speed control.
00554     */
00555    state_ptr->dms += (fi - state_ptr->dms) >> 5;      /* FILTA */
00556    state_ptr->dml += (((fi << 2) - state_ptr->dml) >> 7);   /* FILTB */
00557 
00558    if (tr == 1)
00559       state_ptr->ap = 256;
00560    else if (y < 1536)               /* SUBTC */
00561       state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
00562    else if (state_ptr->td == 1)
00563       state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
00564    else if (abs((state_ptr->dms << 2) - state_ptr->dml) >=
00565        (state_ptr->dml >> 3))
00566       state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
00567    else
00568       state_ptr->ap += (-state_ptr->ap) >> 4;
00569 }


Variable Documentation

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 103 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 114 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 107 of file codec_g726.c.

struct ast_translator g726aal2tolin [static]

Definition at line 800 of file codec_g726.c.

struct ast_translator g726tolin [static]

Definition at line 776 of file codec_g726.c.

struct ast_translator lintog726 [static]

Definition at line 788 of file codec_g726.c.

struct ast_translator lintog726aal2 [static]

Definition at line 812 of file codec_g726.c.

int qtab_721[7] = {-124, 80, 178, 246, 300, 349, 400} [static]

Definition at line 98 of file codec_g726.c.


Generated on 7 Sep 2017 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1