Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions | Variables
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
 

Macros

#define BUF_SHIFT   5
 
#define BUFFER_SAMPLES   8096 /* size for the translation buffers */
 
#define WANT_ASM
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (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. More...
 
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. More...
 
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 More...
 
static int lintog726_new (struct ast_trans_pvt *pvt)
 init a new instance of g726_coder_pvt. More...
 
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 More...
 
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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 const 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.

Macro Definition Documentation

◆ BUF_SHIFT

#define BUF_SHIFT   5

Definition at line 60 of file codec_g726.c.

◆ BUFFER_SAMPLES

#define BUFFER_SAMPLES   8096 /* size for the translation buffers */

Definition at line 59 of file codec_g726.c.

◆ WANT_ASM

#define WANT_ASM

Definition at line 43 of file codec_g726.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 903 of file codec_g726.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 903 of file codec_g726.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 903 of file codec_g726.c.

◆ fmult()

static int fmult ( int  an,
int  srn 
)
static

Definition at line 205 of file codec_g726.c.

References ilog2(), and retval.

Referenced by predictor_pole(), and predictor_zero().

206 {
207  int anmag, anexp, anmant;
208  int wanexp, wanmant;
209  int retval;
210 
211  anmag = (an > 0) ? an : ((-an) & 0x1FFF);
212  anexp = ilog2(anmag) - 5;
213  anmant = (anmag == 0) ? 32 :
214  (anexp >= 0) ? anmag >> anexp : anmag << -anexp;
215  wanexp = anexp + ((srn >> 6) & 0xF) - 13;
216 
217  wanmant = (anmant * (srn & 077) + 0x30) >> 4;
218  retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) :
219  (wanmant >> -wanexp);
220 
221  return (((an ^ srn) < 0) ? -retval : retval);
222 }
static int ilog2(int val)
Definition: log2comp.h:67
static ENTRY retval
Definition: hsearch.c:50

◆ g726_decode()

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

Definition at line 588 of file codec_g726.c.

References _dqlntab, _fitab, _witab, g726_state::dq, predictor_pole(), predictor_zero(), reconstruct(), g726_state::sr, step_size(), and update().

Referenced by g726aal2tolin_framein(), and g726tolin_framein().

589 {
590  int sezi, sez, se; /* ACCUM */
591  int y; /* MIX */
592  int sr; /* ADDB */
593  int dq;
594  int dqsez;
595 
596  i &= 0x0f; /* mask to get proper bits */
597 #ifdef NOT_BLI
598  sezi = predictor_zero(state_ptr);
599  sez = sezi;
600  se = sezi + predictor_pole(state_ptr); /* estimated signal */
601 #else
602  sezi = predictor_zero(state_ptr);
603  sez = sezi >> 1;
604  se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */
605 #endif
606 
607  y = step_size(state_ptr); /* dynamic quantizer step size */
608 
609  dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized diff. */
610 
611 #ifdef NOT_BLI
612  sr = se + dq; /* reconst. signal */
613  dqsez = dq + sez; /* pole prediction diff. */
614 #else
615  sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */
616  dqsez = sr - se + sez; /* pole prediction diff. */
617 #endif
618 
619  update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
620 
621 #ifdef NOT_BLI
622  return (sr >> 10); /* sr was 26-bit dynamic range */
623 #else
624  return (sr << 2); /* sr was 14-bit dynamic range */
625 #endif
626 }
static int _witab[16]
Definition: codec_g726.c:105
static void update(int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr)
Definition: codec_g726.c:367
static int step_size(struct g726_state *state_ptr)
Definition: codec_g726.c:247
static int _fitab[16]
Definition: codec_g726.c:112
static int _dqlntab[16]
Definition: codec_g726.c:101
static int reconstruct(int sign, int dqln, int y)
Definition: codec_g726.c:331
static int predictor_pole(struct g726_state *state_ptr)
Definition: codec_g726.c:233
static int predictor_zero(struct g726_state *state_ptr)
Definition: codec_g726.c:224

◆ g726_encode()

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

Definition at line 634 of file codec_g726.c.

References _dqlntab, _fitab, _witab, d, g726_state::dq, predictor_pole(), predictor_zero(), qtab_721, quantize(), reconstruct(), g726_state::sr, step_size(), and update().

Referenced by lintog726_framein(), and lintog726aal2_framein().

635 {
636  int sezi, se, sez; /* ACCUM */
637  int d; /* SUBTA */
638  int sr; /* ADDB */
639  int y; /* MIX */
640  int dqsez; /* ADDC */
641  int dq, i;
642 
643 #ifdef NOT_BLI
644  sl <<= 10; /* 26-bit dynamic range */
645 
646  sezi = predictor_zero(state_ptr);
647  sez = sezi;
648  se = sezi + predictor_pole(state_ptr); /* estimated signal */
649 #else
650  sl >>= 2; /* 14-bit dynamic range */
651 
652  sezi = predictor_zero(state_ptr);
653  sez = sezi >> 1;
654  se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */
655 #endif
656 
657  d = sl - se; /* estimation difference */
658 
659  /* quantize the prediction difference */
660  y = step_size(state_ptr); /* quantizer step size */
661 #ifdef NOT_BLI
662  d /= 0x1000;
663 #endif
664  i = quantize(d, y, qtab_721, 7); /* i = G726 code */
665 
666  dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized est diff */
667 
668 #ifdef NOT_BLI
669  sr = se + dq; /* reconst. signal */
670  dqsez = dq + sez; /* pole prediction diff. */
671 #else
672  sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */
673  dqsez = sr - se + sez; /* pole prediction diff. */
674 #endif
675 
676  update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
677 
678  return i;
679 }
static int qtab_721[7]
Definition: codec_g726.c:96
static int _witab[16]
Definition: codec_g726.c:105
static void update(int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr)
Definition: codec_g726.c:367
static struct test_val d
static int step_size(struct g726_state *state_ptr)
Definition: codec_g726.c:247
static int _fitab[16]
Definition: codec_g726.c:112
static int _dqlntab[16]
Definition: codec_g726.c:101
static int reconstruct(int sign, int dqln, int y)
Definition: codec_g726.c:331
static int predictor_pole(struct g726_state *state_ptr)
Definition: codec_g726.c:233
static int quantize(int d, int y, int *table, int size)
Definition: codec_g726.c:276
static int predictor_zero(struct g726_state *state_ptr)
Definition: codec_g726.c:224

◆ g726_init_state()

static void g726_init_state ( struct g726_state state_ptr)
static

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

124 {
125  int cnta;
126 
127  state_ptr->yl = 34816;
128  state_ptr->yu = 544;
129  state_ptr->dms = 0;
130  state_ptr->dml = 0;
131  state_ptr->ap = 0;
132  for (cnta = 0; cnta < 2; cnta++) {
133  state_ptr->a[cnta] = 0;
134  state_ptr->pk[cnta] = 0;
135 #ifdef NOT_BLI
136  state_ptr->sr[cnta] = 1;
137 #else
138  state_ptr->sr[cnta] = 32;
139 #endif
140  }
141  for (cnta = 0; cnta < 6; cnta++) {
142  state_ptr->b[cnta] = 0;
143 #ifdef NOT_BLI
144  state_ptr->dq[cnta] = 1;
145 #else
146  state_ptr->dq[cnta] = 32;
147 #endif
148  }
149  state_ptr->td = 0;
150 }
int b[6]
Definition: codec_g726.c:83
int a[2]
Definition: codec_g726.c:81
int dq[6]
Definition: codec_g726.c:87
int sr[2]
Definition: codec_g726.c:90
int pk[2]
Definition: codec_g726.c:85

◆ g726aal2tolin_framein()

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

References ast_frame::data, ast_frame::datalen, ast_trans_pvt::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().

704 {
705  struct g726_coder_pvt *tmp = pvt->pvt;
706  unsigned char *src = f->data.ptr;
707  int16_t *dst = pvt->outbuf.i16 + pvt->samples;
708  unsigned int i;
709 
710  for (i = 0; i < f->datalen; i++) {
711  *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726);
712  *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726);
713  }
714 
715  pvt->samples += f->samples;
716  pvt->datalen += 2 * f->samples; /* 2 bytes/sample */
717 
718  return 0;
719 }
int datalen
actual space used in outbuf
Definition: translate.h:218
short int16_t
Definition: db.h:59
static int tmp()
Definition: bt_open.c:389
struct g726_state g726
Definition: codec_g726.c:689
void * pvt
Definition: translate.h:219
int16_t * i16
Definition: translate.h:223
union ast_trans_pvt::@327 outbuf
static int g726_decode(int i, struct g726_state *state_ptr)
Definition: codec_g726.c:588
union ast_frame::@263 data

◆ g726tolin_framein()

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

References ast_frame::data, ast_frame::datalen, ast_trans_pvt::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().

745 {
746  struct g726_coder_pvt *tmp = pvt->pvt;
747  unsigned char *src = f->data.ptr;
748  int16_t *dst = pvt->outbuf.i16 + pvt->samples;
749  unsigned int i;
750 
751  for (i = 0; i < f->datalen; i++) {
752  *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726);
753  *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726);
754  }
755 
756  pvt->samples += f->samples;
757  pvt->datalen += 2 * f->samples; /* 2 bytes/sample */
758 
759  return 0;
760 }
int datalen
actual space used in outbuf
Definition: translate.h:218
short int16_t
Definition: db.h:59
static int tmp()
Definition: bt_open.c:389
struct g726_state g726
Definition: codec_g726.c:689
void * pvt
Definition: translate.h:219
int16_t * i16
Definition: translate.h:223
union ast_trans_pvt::@327 outbuf
static int g726_decode(int i, struct g726_state *state_ptr)
Definition: codec_g726.c:588
union ast_frame::@263 data

◆ lintog726_framein()

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

764 {
765  struct g726_coder_pvt *tmp = pvt->pvt;
766  int16_t *src = f->data.ptr;
767  unsigned int i;
768 
769  for (i = 0; i < f->samples; i++) {
770  unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */
771 
772  if (tmp->next_flag & 0x80) { /* merge with leftover sample */
773  pvt->outbuf.c[pvt->datalen++] = (d << 4) | (tmp->next_flag & 0xf);
774  pvt->samples += 2; /* 2 samples per byte */
775  tmp->next_flag = 0;
776  } else {
777  tmp->next_flag = 0x80 | d;
778  }
779  }
780 
781  return 0;
782 }
int datalen
actual space used in outbuf
Definition: translate.h:218
static int g726_encode(int sl, struct g726_state *state_ptr)
Definition: codec_g726.c:634
unsigned char next_flag
Definition: codec_g726.c:688
short int16_t
Definition: db.h:59
static struct test_val d
static int tmp()
Definition: bt_open.c:389
struct g726_state g726
Definition: codec_g726.c:689
void * pvt
Definition: translate.h:219
union ast_trans_pvt::@327 outbuf
union ast_frame::@263 data

◆ lintog726_new()

static int lintog726_new ( struct ast_trans_pvt pvt)
static

init a new instance of g726_coder_pvt.

Definition at line 693 of file codec_g726.c.

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

694 {
695  struct g726_coder_pvt *tmp = pvt->pvt;
696 
697  g726_init_state(&tmp->g726);
698 
699  return 0;
700 }
static void g726_init_state(struct g726_state *state_ptr)
Definition: codec_g726.c:123
static int tmp()
Definition: bt_open.c:389
struct g726_state g726
Definition: codec_g726.c:689
void * pvt
Definition: translate.h:219

◆ lintog726aal2_framein()

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

723 {
724  struct g726_coder_pvt *tmp = pvt->pvt;
725  int16_t *src = f->data.ptr;
726  unsigned int i;
727 
728  for (i = 0; i < f->samples; i++) {
729  unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */
730 
731  if (tmp->next_flag & 0x80) { /* merge with leftover sample */
732  pvt->outbuf.c[pvt->datalen++] = ((tmp->next_flag & 0xf)<< 4) | d;
733  pvt->samples += 2; /* 2 samples per byte */
734  tmp->next_flag = 0;
735  } else {
736  tmp->next_flag = 0x80 | d;
737  }
738  }
739 
740  return 0;
741 }
int datalen
actual space used in outbuf
Definition: translate.h:218
static int g726_encode(int sl, struct g726_state *state_ptr)
Definition: codec_g726.c:634
unsigned char next_flag
Definition: codec_g726.c:688
short int16_t
Definition: db.h:59
static struct test_val d
static int tmp()
Definition: bt_open.c:389
struct g726_state g726
Definition: codec_g726.c:689
void * pvt
Definition: translate.h:219
union ast_trans_pvt::@327 outbuf
union ast_frame::@263 data

◆ load_module()

static int load_module ( void  )
static

Definition at line 881 of file codec_g726.c.

References AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ast_register_translator, ASTERISK_GPL_KEY, and unload_module().

882 {
883  int res = 0;
884 
887 
890 
891  if (res) {
892  unload_module();
894  }
895 
897 }
static struct ast_translator lintog726
Definition: codec_g726.c:805
static struct ast_translator lintog726aal2
Definition: codec_g726.c:847
static struct ast_translator g726aal2tolin
Definition: codec_g726.c:826
#define ast_register_translator(t)
See __ast_register_translator()
Definition: translate.h:257
static struct ast_translator g726tolin
Definition: codec_g726.c:784
static int unload_module(void)
Definition: codec_g726.c:868
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78

◆ predictor_pole()

static int predictor_pole ( struct g726_state state_ptr)
static

Definition at line 233 of file codec_g726.c.

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

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

234 {
235  return (fmult(state_ptr->a[1] >> 2, state_ptr->sr[1]) +
236  fmult(state_ptr->a[0] >> 2, state_ptr->sr[0]));
237 }
int a[2]
Definition: codec_g726.c:81
int sr[2]
Definition: codec_g726.c:90
static int fmult(int an, int srn)
Definition: codec_g726.c:205

◆ predictor_zero()

static int predictor_zero ( struct g726_state state_ptr)
static

Definition at line 224 of file codec_g726.c.

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

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

225 {
226  int i;
227  int sezi;
228  for (sezi = 0, i = 0; i < 6; i++) /* ACCUM */
229  sezi += fmult(state_ptr->b[i] >> 2, state_ptr->dq[i]);
230  return sezi;
231 }
int b[6]
Definition: codec_g726.c:83
int dq[6]
Definition: codec_g726.c:87
static int fmult(int an, int srn)
Definition: codec_g726.c:205

◆ quan()

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

Definition at line 160 of file codec_g726.c.

References g726_state::a, g726_state::b, g726_state::dq, predictor_pole(), predictor_zero(), g726_state::sr, and table.

Referenced by quantize().

161 {
162  int i;
163 
164  for (i = 0; i < size && val >= *table; ++i, ++table)
165  ;
166  return i;
167 }
static char * table
Definition: cdr_odbc.c:58

◆ quantize()

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

Definition at line 276 of file codec_g726.c.

References abs, ilog2(), and quan().

Referenced by g726_encode().

281 {
282  int dqm; /* Magnitude of 'd' */
283  int exp; /* Integer part of base 2 log of 'd' */
284  int mant; /* Fractional part of base 2 log */
285  int dl; /* Log of magnitude of 'd' */
286  int dln; /* Step size scale factor normalized log */
287  int i;
288 
289  /*
290  * LOG
291  *
292  * Compute base 2 log of 'd', and store in 'dl'.
293  */
294  dqm = abs(d);
295  exp = ilog2(dqm);
296  if (exp < 0) {
297  exp = 0;
298  }
299  mant = ((dqm << 7) >> exp) & 0x7F; /* Fractional portion. */
300  dl = (exp << 7) | mant;
301 
302  /*
303  * SUBTB
304  *
305  * "Divide" by step size multiplier.
306  */
307  dln = dl - (y >> 2);
308 
309  /*
310  * QUAN
311  *
312  * Obtain codword i for 'd'.
313  */
314  i = quan(dln, table, size);
315  if (d < 0) { /* take 1's complement of i */
316  return ((size << 1) + 1 - i);
317  } else if (i == 0) { /* take 1's complement of 0 */
318  return ((size << 1) + 1); /* new in 1988 */
319  } else {
320  return i;
321  }
322 }
static struct test_val d
static char * table
Definition: cdr_odbc.c:58
static int quan(int val, int *table, int size)
Definition: codec_g726.c:160
static int ilog2(int val)
Definition: log2comp.h:67
#define abs(x)
Definition: f2c.h:195

◆ reconstruct()

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

Definition at line 331 of file codec_g726.c.

References g726_state::dq.

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

335 {
336  int dql; /* Log of 'dq' magnitude */
337  int dex; /* Integer part of log */
338  int dqt;
339  int dq; /* Reconstructed difference signal sample */
340 
341  dql = dqln + (y >> 2); /* ADDA */
342 
343  if (dql < 0) {
344 #ifdef NOT_BLI
345  return (sign) ? -1 : 1;
346 #else
347  return (sign) ? -0x8000 : 0;
348 #endif
349  } else { /* ANTILOG */
350  dex = (dql >> 7) & 15;
351  dqt = 128 + (dql & 127);
352 #ifdef NOT_BLI
353  dq = ((dqt << 19) >> (14 - dex));
354  return (sign) ? -dq : dq;
355 #else
356  dq = (dqt << 7) >> (14 - dex);
357  return (sign) ? (dq - 0x8000) : dq;
358 #endif
359  }
360 }

◆ step_size()

static int step_size ( struct g726_state state_ptr)
static

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

248 {
249  int y, dif, al;
250 
251  if (state_ptr->ap >= 256) {
252  return state_ptr->yu;
253  }
254 
255  y = state_ptr->yl >> 6;
256  dif = state_ptr->yu - y;
257  al = state_ptr->ap >> 2;
258 
259  if (dif > 0) {
260  y += (dif * al) >> 6;
261  } else if (dif < 0) {
262  y += (dif * al + 0x3F) >> 6;
263  }
264  return y;
265 }

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 868 of file codec_g726.c.

References ast_unregister_translator().

Referenced by load_module().

869 {
870  int res = 0;
871 
874 
877 
878  return res;
879 }
static struct ast_translator lintog726
Definition: codec_g726.c:805
static struct ast_translator lintog726aal2
Definition: codec_g726.c:847
static struct ast_translator g726aal2tolin
Definition: codec_g726.c:826
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given tranlator.
Definition: translate.c:1333
static struct ast_translator g726tolin
Definition: codec_g726.c:784

◆ update()

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, abs, g726_state::ap, g726_state::b, g726_state::dml, g726_state::dms, g726_state::dq, if(), ilog2(), g726_state::pk, g726_state::sr, g726_state::td, g726_state::yl, and g726_state::yu.

Referenced by ast_bridge_publish_state(), ast_channel_publish_final_snapshot(), ast_channel_publish_snapshot(), AST_TEST_DEFINE(), bridge_publish_state_from_blob(), bridge_snapshot_update(), bridge_snapshot_update_create(), bridge_snapshot_update_dtor(), bridge_topics_destroy(), cache_update(), cache_update_cb(), caching_topic_exec(), cel_snapshot_update_cb(), channel_snapshot_update(), channel_snapshot_update_create(), channel_snapshot_update_dtor(), config_device(), config_line(), connectedline_write(), endpoint_cache_clear(), find_route(), g726_decode(), g726_encode(), handle_bridge_enter_message(), handle_bridge_leave_message(), handle_channel_snapshot_update_message(), load_module(), load_pktccops_config(), redirecting_write(), stasis_cache_update_dtor(), sub_bridge_update_handler(), sub_channel_update_handler(), sub_endpoint_update_handler(), unload_module(), update_create(), and updates().

376 {
377  int cnt;
378  int mag; /* Adaptive predictor, FLOAT A */
379 #ifndef NOT_BLI
380  int exp;
381 #endif
382  int a2p=0; /* LIMC */
383  int a1ul; /* UPA1 */
384  int pks1; /* UPA2 */
385  int fa1;
386  int tr; /* tone/transition detector */
387  int ylint, thr2, dqthr;
388  int ylfrac, thr1;
389  int pk0;
390 
391  pk0 = (dqsez < 0) ? 1 : 0; /* needed in updating predictor poles */
392 
393 #ifdef NOT_BLI
394  mag = abs(dq / 0x1000); /* prediction difference magnitude */
395 #else
396  mag = dq & 0x7FFF; /* prediction difference magnitude */
397 #endif
398  /* TRANS */
399  ylint = state_ptr->yl >> 15; /* exponent part of yl */
400  ylfrac = (state_ptr->yl >> 10) & 0x1F; /* fractional part of yl */
401  thr1 = (32 + ylfrac) << ylint; /* threshold */
402  thr2 = (ylint > 9) ? 31 << 10 : thr1; /* limit thr2 to 31 << 10 */
403  dqthr = (thr2 + (thr2 >> 1)) >> 1; /* dqthr = 0.75 * thr2 */
404  if (state_ptr->td == 0) { /* signal supposed voice */
405  tr = 0;
406  } else if (mag <= dqthr) { /* supposed data, but small mag */
407  tr = 0; /* treated as voice */
408  } else { /* signal is data (modem) */
409  tr = 1;
410  }
411  /*
412  * Quantizer scale factor adaptation.
413  */
414 
415  /* FUNCTW & FILTD & DELAY */
416  /* update non-steady state step size multiplier */
417  state_ptr->yu = y + ((wi - y) >> 5);
418 
419  /* LIMB */
420  if (state_ptr->yu < 544) { /* 544 <= yu <= 5120 */
421  state_ptr->yu = 544;
422  } else if (state_ptr->yu > 5120) {
423  state_ptr->yu = 5120;
424  }
425 
426  /* FILTE & DELAY */
427  /* update steady state step size multiplier */
428  state_ptr->yl += state_ptr->yu + ((-state_ptr->yl) >> 6);
429 
430  /*
431  * Adaptive predictor coefficients.
432  */
433  if (tr == 1) { /* reset a's and b's for modem signal */
434  state_ptr->a[0] = 0;
435  state_ptr->a[1] = 0;
436  state_ptr->b[0] = 0;
437  state_ptr->b[1] = 0;
438  state_ptr->b[2] = 0;
439  state_ptr->b[3] = 0;
440  state_ptr->b[4] = 0;
441  state_ptr->b[5] = 0;
442  } else { /* update a's and b's */
443  pks1 = pk0 ^ state_ptr->pk[0]; /* UPA2 */
444 
445  /* update predictor pole a[1] */
446  a2p = state_ptr->a[1] - (state_ptr->a[1] >> 7);
447  if (dqsez != 0) {
448  fa1 = (pks1) ? state_ptr->a[0] : -state_ptr->a[0];
449  if (fa1 < -8191) { /* a2p = function of fa1 */
450  a2p -= 0x100;
451  } else if (fa1 > 8191) {
452  a2p += 0xFF;
453  } else {
454  a2p += fa1 >> 5;
455  }
456 
457  if (pk0 ^ state_ptr->pk[1]) {
458  /* LIMC */
459  if (a2p <= -12160) {
460  a2p = -12288;
461  } else if (a2p >= 12416) {
462  a2p = 12288;
463  } else {
464  a2p -= 0x80;
465  }
466  } else if (a2p <= -12416) {
467  a2p = -12288;
468  } else if (a2p >= 12160) {
469  a2p = 12288;
470  } else {
471  a2p += 0x80;
472  }
473  }
474 
475  /* TRIGB & DELAY */
476  state_ptr->a[1] = a2p;
477 
478  /* UPA1 */
479  /* update predictor pole a[0] */
480  state_ptr->a[0] -= state_ptr->a[0] >> 8;
481  if (dqsez != 0) {
482  if (pks1 == 0)
483  state_ptr->a[0] += 192;
484  else
485  state_ptr->a[0] -= 192;
486  }
487  /* LIMD */
488  a1ul = 15360 - a2p;
489  if (state_ptr->a[0] < -a1ul) {
490  state_ptr->a[0] = -a1ul;
491  } else if (state_ptr->a[0] > a1ul) {
492  state_ptr->a[0] = a1ul;
493  }
494 
495  /* UPB : update predictor zeros b[6] */
496  for (cnt = 0; cnt < 6; cnt++) {
497  if (code_size == 5) { /* for 40Kbps G.723 */
498  state_ptr->b[cnt] -= state_ptr->b[cnt] >> 9;
499  } else { /* for G.721 and 24Kbps G.723 */
500  state_ptr->b[cnt] -= state_ptr->b[cnt] >> 8;
501  }
502  if (mag) { /* XOR */
503  if ((dq ^ state_ptr->dq[cnt]) >= 0) {
504  state_ptr->b[cnt] += 128;
505  } else {
506  state_ptr->b[cnt] -= 128;
507  }
508  }
509  }
510  }
511 
512  for (cnt = 5; cnt > 0; cnt--)
513  state_ptr->dq[cnt] = state_ptr->dq[cnt-1];
514 #ifdef NOT_BLI
515  state_ptr->dq[0] = dq;
516 #else
517  /* FLOAT A : convert dq[0] to 4-bit exp, 6-bit mantissa f.p. */
518  if (mag == 0) {
519  state_ptr->dq[0] = (dq >= 0) ? 0x20 : 0x20 - 0x400;
520  } else {
521  exp = ilog2(mag) + 1;
522  state_ptr->dq[0] = (dq >= 0) ?
523  (exp << 6) + ((mag << 6) >> exp) :
524  (exp << 6) + ((mag << 6) >> exp) - 0x400;
525  }
526 #endif
527 
528  state_ptr->sr[1] = state_ptr->sr[0];
529 #ifdef NOT_BLI
530  state_ptr->sr[0] = sr;
531 #else
532  /* FLOAT B : convert sr to 4-bit exp., 6-bit mantissa f.p. */
533  if (sr == 0) {
534  state_ptr->sr[0] = 0x20;
535  } else if (sr > 0) {
536  exp = ilog2(sr) + 1;
537  state_ptr->sr[0] = (exp << 6) + ((sr << 6) >> exp);
538  } else if (sr > -0x8000) {
539  mag = -sr;
540  exp = ilog2(mag) + 1;
541  state_ptr->sr[0] = (exp << 6) + ((mag << 6) >> exp) - 0x400;
542  } else
543  state_ptr->sr[0] = 0x20 - 0x400;
544 #endif
545 
546  /* DELAY A */
547  state_ptr->pk[1] = state_ptr->pk[0];
548  state_ptr->pk[0] = pk0;
549 
550  /* TONE */
551  if (tr == 1) { /* this sample has been treated as data */
552  state_ptr->td = 0; /* next one will be treated as voice */
553  } else if (a2p < -11776) { /* small sample-to-sample correlation */
554  state_ptr->td = 1; /* signal may be data */
555  } else { /* signal is voice */
556  state_ptr->td = 0;
557  }
558 
559  /*
560  * Adaptation speed control.
561  */
562  state_ptr->dms += (fi - state_ptr->dms) >> 5; /* FILTA */
563  state_ptr->dml += (((fi << 2) - state_ptr->dml) >> 7); /* FILTB */
564 
565  if (tr == 1) {
566  state_ptr->ap = 256;
567  } else if (y < 1536) { /* SUBTC */
568  state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
569  } else if (state_ptr->td == 1) {
570  state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
571  } else if (abs((state_ptr->dms << 2) - state_ptr->dml) >=
572  (state_ptr->dml >> 3)) {
573  state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
574  } else {
575  state_ptr->ap += (-state_ptr->ap) >> 4;
576  }
577 }
int b[6]
Definition: codec_g726.c:83
int a[2]
Definition: codec_g726.c:81
int dq[6]
Definition: codec_g726.c:87
if(!yyg->yy_init)
Definition: ast_expr2f.c:868
int sr[2]
Definition: codec_g726.c:90
static int ilog2(int val)
Definition: log2comp.h:67
#define abs(x)
Definition: f2c.h:195
int pk[2]
Definition: codec_g726.c:85

Variable Documentation

◆ __mod_info

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
static

Definition at line 903 of file codec_g726.c.

◆ _dqlntab

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

Referenced by g726_decode(), and g726_encode().

◆ _fitab

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

Referenced by g726_decode(), and g726_encode().

◆ _witab

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

Referenced by g726_decode(), and g726_encode().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 903 of file codec_g726.c.

◆ g726aal2tolin

struct ast_translator g726aal2tolin
static

Definition at line 826 of file codec_g726.c.

◆ g726tolin

struct ast_translator g726tolin
static

Definition at line 784 of file codec_g726.c.

◆ lintog726

struct ast_translator lintog726
static

Definition at line 805 of file codec_g726.c.

◆ lintog726aal2

struct ast_translator lintog726aal2
static

Definition at line 847 of file codec_g726.c.

◆ qtab_721

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

Definition at line 96 of file codec_g726.c.

Referenced by g726_encode().