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"

Include dependency graph for codec_g726.c:

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 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 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 , .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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
static int _dqlntab [16]
static int _fitab [16]
static int _witab [16]
static struct ast_module_infoast_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}


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

static void __reg_module ( void   )  [static]

Definition at line 905 of file codec_g726.c.

static void __unreg_module ( void   )  [static]

Definition at line 905 of file codec_g726.c.

static int fmult ( int  an,
int  srn 
) [static]

Definition at line 207 of file codec_g726.c.

References ilog2(), and retval.

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

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

Referenced by g726aal2tolin_framein(), and g726tolin_framein().

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

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

Definition at line 636 of file codec_g726.c.

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

Referenced by lintog726_framein(), and lintog726aal2_framein().

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

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 705 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, ast_trans_pvt::samples, and tmp().

00706 {
00707    struct g726_coder_pvt *tmp = pvt->pvt;
00708    unsigned char *src = f->data.ptr;
00709    int16_t *dst = pvt->outbuf.i16 + pvt->samples;
00710    unsigned int i;
00711 
00712    for (i = 0; i < f->datalen; i++) {
00713       *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726);
00714       *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726);
00715    }
00716 
00717    pvt->samples += f->samples;
00718    pvt->datalen += 2 * f->samples; /* 2 bytes/sample */
00719 
00720    return 0;
00721 }

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 746 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, ast_trans_pvt::samples, and tmp().

00747 {
00748    struct g726_coder_pvt *tmp = pvt->pvt;
00749    unsigned char *src = f->data.ptr;
00750    int16_t *dst = pvt->outbuf.i16 + pvt->samples;
00751    unsigned int i;
00752 
00753    for (i = 0; i < f->datalen; i++) {
00754       *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726);
00755       *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726);
00756    }
00757 
00758    pvt->samples += f->samples;
00759    pvt->datalen += 2 * f->samples; /* 2 bytes/sample */
00760 
00761    return 0;
00762 }

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

References ast_trans_pvt::c, d, 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, ast_frame::samples, and tmp().

00766 {
00767    struct g726_coder_pvt *tmp = pvt->pvt;
00768    int16_t *src = f->data.ptr;
00769    unsigned int i;
00770 
00771    for (i = 0; i < f->samples; i++) {
00772       unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */
00773 
00774       if (tmp->next_flag & 0x80) {  /* merge with leftover sample */
00775          pvt->outbuf.c[pvt->datalen++] = (d << 4) | (tmp->next_flag & 0xf);
00776          pvt->samples += 2;   /* 2 samples per byte */
00777          tmp->next_flag = 0;
00778       } else {
00779          tmp->next_flag = 0x80 | d;
00780       }
00781    }
00782 
00783    return 0;
00784 }

static int lintog726_new ( struct ast_trans_pvt pvt  )  [static]

init a new instance of g726_coder_pvt.

Definition at line 695 of file codec_g726.c.

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

00696 {
00697    struct g726_coder_pvt *tmp = pvt->pvt;
00698 
00699    g726_init_state(&tmp->g726);
00700 
00701    return 0;
00702 }

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

References ast_trans_pvt::c, d, 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, ast_frame::samples, and tmp().

00725 {
00726    struct g726_coder_pvt *tmp = pvt->pvt;
00727    int16_t *src = f->data.ptr;
00728    unsigned int i;
00729 
00730    for (i = 0; i < f->samples; i++) {
00731       unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */
00732 
00733       if (tmp->next_flag & 0x80) {  /* merge with leftover sample */
00734          pvt->outbuf.c[pvt->datalen++] = ((tmp->next_flag & 0xf)<< 4) | d;
00735          pvt->samples += 2;   /* 2 samples per byte */
00736          tmp->next_flag = 0;
00737       } else {
00738          tmp->next_flag = 0x80 | d;
00739       }
00740    }
00741 
00742    return 0;
00743 }

static int load_module ( void   )  [static]

Definition at line 883 of file codec_g726.c.

References AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_translator, and unload_module.

00884 {
00885    int res = 0;
00886 
00887    res |= ast_register_translator(&g726tolin);
00888    res |= ast_register_translator(&lintog726);
00889 
00890    res |= ast_register_translator(&g726aal2tolin);
00891    res |= ast_register_translator(&lintog726aal2);
00892 
00893    if (res) {
00894       unload_module();
00895       return AST_MODULE_LOAD_FAILURE;
00896    }  
00897 
00898    return AST_MODULE_LOAD_SUCCESS;
00899 }

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 abs, 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    }
00301    mant = ((dqm << 7) >> exp) & 0x7F;  /* Fractional portion. */
00302    dl = (exp << 7) | mant;
00303 
00304    /*
00305     * SUBTB
00306     *
00307     * "Divide" by step size multiplier.
00308     */
00309    dln = dl - (y >> 2);
00310 
00311    /*
00312     * QUAN
00313     *
00314     * Obtain codword i for 'd'.
00315     */
00316    i = quan(dln, table, size);
00317    if (d < 0) {         /* take 1's complement of i */
00318       return ((size << 1) + 1 - i);
00319    } else if (i == 0) {    /* take 1's complement of 0 */
00320       return ((size << 1) + 1); /* new in 1988 */
00321    } else {
00322       return i;
00323    }
00324 }

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

Definition at line 333 of file codec_g726.c.

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

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

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

static int unload_module ( void   )  [static]

Definition at line 870 of file codec_g726.c.

References ast_unregister_translator().

00871 {
00872    int res = 0;
00873 
00874    res |= ast_unregister_translator(&g726tolin);
00875    res |= ast_unregister_translator(&lintog726);
00876 
00877    res |= ast_unregister_translator(&g726aal2tolin);
00878    res |= ast_unregister_translator(&lintog726aal2);
00879 
00880    return res;
00881 }

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

References g726_state::a, abs, 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 AST_TEST_DEFINE(), bridge_snapshot_update(), cache_update(), caching_topic_exec(), cel_snapshot_update_cb(), channel_snapshot_update(), config_device(), config_line(), connectedline_write(), find_route(), g726_decode(), g726_encode(), handle_bridge_enter_message(), handle_bridge_leave_message(), handle_channel_cache_message(), init_start_time(), load_pktccops_config(), redirecting_write(), stasis_cache_update_dtor(), sub_bridge_update_handler(), sub_channel_update_handler(), sub_endpoint_update_handler(), update_contact_status(), update_create(), and updates().

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


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, } [static]

Definition at line 905 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 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.

Definition at line 905 of file codec_g726.c.

struct ast_translator g726aal2tolin [static]

Definition at line 828 of file codec_g726.c.

struct ast_translator g726tolin [static]

Definition at line 786 of file codec_g726.c.

struct ast_translator lintog726 [static]

Definition at line 807 of file codec_g726.c.

struct ast_translator lintog726aal2 [static]

Definition at line 849 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 Thu Apr 16 06:30:15 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6