Wed Jan 8 2020 09:50:10

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
 

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)
 
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 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 , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload, }
 
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.

Macro Definition Documentation

#define BUF_SHIFT   5

Definition at line 62 of file codec_g726.c.

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

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

static void __unreg_module ( void  )
static

Definition at line 864 of file codec_g726.c.

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().

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

581 {
582  int sezi, sez, se; /* ACCUM */
583  int y; /* MIX */
584  int sr; /* ADDB */
585  int dq;
586  int dqsez;
587 
588  i &= 0x0f; /* mask to get proper bits */
589 #ifdef NOT_BLI
590  sezi = predictor_zero(state_ptr);
591  sez = sezi;
592  se = sezi + predictor_pole(state_ptr); /* estimated signal */
593 #else
594  sezi = predictor_zero(state_ptr);
595  sez = sezi >> 1;
596  se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */
597 #endif
598 
599  y = step_size(state_ptr); /* dynamic quantizer step size */
600 
601  dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized diff. */
602 
603 #ifdef NOT_BLI
604  sr = se + dq; /* reconst. signal */
605  dqsez = dq + sez; /* pole prediction diff. */
606 #else
607  sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */
608  dqsez = sr - se + sez; /* pole prediction diff. */
609 #endif
610 
611  update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
612 
613 #ifdef NOT_BLI
614  return (sr >> 10); /* sr was 26-bit dynamic range */
615 #else
616  return (sr << 2); /* sr was 14-bit dynamic range */
617 #endif
618 }
static int _witab[16]
Definition: codec_g726.c:107
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:249
static int _fitab[16]
Definition: codec_g726.c:114
static int _dqlntab[16]
Definition: codec_g726.c:103
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:235
static int predictor_zero(struct g726_state *state_ptr)
Definition: codec_g726.c:226
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().

627 {
628  int sezi, se, sez; /* ACCUM */
629  int d; /* SUBTA */
630  int sr; /* ADDB */
631  int y; /* MIX */
632  int dqsez; /* ADDC */
633  int dq, i;
634 
635 #ifdef NOT_BLI
636  sl <<= 10; /* 26-bit dynamic range */
637 
638  sezi = predictor_zero(state_ptr);
639  sez = sezi;
640  se = sezi + predictor_pole(state_ptr); /* estimated signal */
641 #else
642  sl >>= 2; /* 14-bit dynamic range */
643 
644  sezi = predictor_zero(state_ptr);
645  sez = sezi >> 1;
646  se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */
647 #endif
648 
649  d = sl - se; /* estimation difference */
650 
651  /* quantize the prediction difference */
652  y = step_size(state_ptr); /* quantizer step size */
653 #ifdef NOT_BLI
654  d /= 0x1000;
655 #endif
656  i = quantize(d, y, qtab_721, 7); /* i = G726 code */
657 
658  dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized est diff */
659 
660 #ifdef NOT_BLI
661  sr = se + dq; /* reconst. signal */
662  dqsez = dq + sez; /* pole prediction diff. */
663 #else
664  sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */
665  dqsez = sr - se + sez; /* pole prediction diff. */
666 #endif
667 
668  update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr);
669 
670  return (i);
671 }
static int qtab_721[7]
Definition: codec_g726.c:98
static int _witab[16]
Definition: codec_g726.c:107
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:249
static int _fitab[16]
Definition: codec_g726.c:114
static int _dqlntab[16]
Definition: codec_g726.c:103
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:235
static int quantize(int d, int y, int *table, int size)
Definition: codec_g726.c:278
static int predictor_zero(struct g726_state *state_ptr)
Definition: codec_g726.c:226
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().

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

696 {
697  struct g726_coder_pvt *tmp = pvt->pvt;
698  unsigned char *src = f->data.ptr;
699  int16_t *dst = pvt->outbuf.i16 + pvt->samples;
700  unsigned int i;
701 
702  for (i = 0; i < f->datalen; i++) {
703  *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726);
704  *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726);
705  }
706 
707  pvt->samples += f->samples;
708  pvt->datalen += 2 * f->samples; /* 2 bytes/sample */
709 
710  return 0;
711 }
int datalen
actual space used in outbuf
Definition: translate.h:140
union ast_trans_pvt::@213 outbuf
void * ptr
Definition: frame.h:160
struct g726_state g726
Definition: codec_g726.c:681
void * pvt
Definition: translate.h:141
int16_t * i16
Definition: translate.h:145
int datalen
Definition: frame.h:148
static int g726_decode(int i, struct g726_state *state_ptr)
Definition: codec_g726.c:580
union ast_frame::@172 data
int samples
Definition: frame.h:150
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_trans_pvt::samples, and ast_frame::samples.

737 {
738  struct g726_coder_pvt *tmp = pvt->pvt;
739  unsigned char *src = f->data.ptr;
740  int16_t *dst = pvt->outbuf.i16 + pvt->samples;
741  unsigned int i;
742 
743  for (i = 0; i < f->datalen; i++) {
744  *dst++ = g726_decode(src[i] & 0x0f, &tmp->g726);
745  *dst++ = g726_decode((src[i] >> 4) & 0xf, &tmp->g726);
746  }
747 
748  pvt->samples += f->samples;
749  pvt->datalen += 2 * f->samples; /* 2 bytes/sample */
750 
751  return 0;
752 }
int datalen
actual space used in outbuf
Definition: translate.h:140
union ast_trans_pvt::@213 outbuf
void * ptr
Definition: frame.h:160
struct g726_state g726
Definition: codec_g726.c:681
void * pvt
Definition: translate.h:141
int16_t * i16
Definition: translate.h:145
int datalen
Definition: frame.h:148
static int g726_decode(int i, struct g726_state *state_ptr)
Definition: codec_g726.c:580
union ast_frame::@172 data
int samples
Definition: frame.h:150
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.

756 {
757  struct g726_coder_pvt *tmp = pvt->pvt;
758  int16_t *src = f->data.ptr;
759  unsigned int i;
760 
761  for (i = 0; i < f->samples; i++) {
762  unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */
763 
764  if (tmp->next_flag & 0x80) { /* merge with leftover sample */
765  pvt->outbuf.c[pvt->datalen++] = (d << 4) | (tmp->next_flag & 0xf);
766  pvt->samples += 2; /* 2 samples per byte */
767  tmp->next_flag = 0;
768  } else {
769  tmp->next_flag = 0x80 | d;
770  }
771  }
772 
773  return 0;
774 }
int datalen
actual space used in outbuf
Definition: translate.h:140
static int g726_encode(int sl, struct g726_state *state_ptr)
Definition: codec_g726.c:626
unsigned char next_flag
Definition: codec_g726.c:680
union ast_trans_pvt::@213 outbuf
void * ptr
Definition: frame.h:160
struct g726_state g726
Definition: codec_g726.c:681
void * pvt
Definition: translate.h:141
union ast_frame::@172 data
int samples
Definition: frame.h:150
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.

686 {
687  struct g726_coder_pvt *tmp = pvt->pvt;
688 
689  g726_init_state(&tmp->g726);
690 
691  return 0;
692 }
static void g726_init_state(struct g726_state *state_ptr)
Definition: codec_g726.c:125
struct g726_state g726
Definition: codec_g726.c:681
void * pvt
Definition: translate.h:141
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.

715 {
716  struct g726_coder_pvt *tmp = pvt->pvt;
717  int16_t *src = f->data.ptr;
718  unsigned int i;
719 
720  for (i = 0; i < f->samples; i++) {
721  unsigned char d = g726_encode(src[i], &tmp->g726); /* this sample */
722 
723  if (tmp->next_flag & 0x80) { /* merge with leftover sample */
724  pvt->outbuf.c[pvt->datalen++] = ((tmp->next_flag & 0xf)<< 4) | d;
725  pvt->samples += 2; /* 2 samples per byte */
726  tmp->next_flag = 0;
727  } else {
728  tmp->next_flag = 0x80 | d;
729  }
730  }
731 
732  return 0;
733 }
int datalen
actual space used in outbuf
Definition: translate.h:140
static int g726_encode(int sl, struct g726_state *state_ptr)
Definition: codec_g726.c:626
unsigned char next_flag
Definition: codec_g726.c:680
union ast_trans_pvt::@213 outbuf
void * ptr
Definition: frame.h:160
struct g726_state g726
Definition: codec_g726.c:681
void * pvt
Definition: translate.h:141
union ast_frame::@172 data
int samples
Definition: frame.h:150
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().

843 {
844  int res = 0;
845 
848 
851 
852  if (res) {
853  unload_module();
855  }
856 
858 }
static struct ast_translator lintog726
Definition: codec_g726.c:788
static struct ast_translator lintog726aal2
Definition: codec_g726.c:812
static struct ast_translator g726aal2tolin
Definition: codec_g726.c:800
#define ast_register_translator(t)
See __ast_register_translator()
Definition: translate.h:170
static struct ast_translator g726tolin
Definition: codec_g726.c:776
static int unload_module(void)
Definition: codec_g726.c:829
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().

236 {
237  return (fmult(state_ptr->a[1] >> 2, state_ptr->sr[1]) +
238  fmult(state_ptr->a[0] >> 2, state_ptr->sr[0]));
239 }
int a[2]
Definition: codec_g726.c:83
int sr[2]
Definition: codec_g726.c:92
static int fmult(int an, int srn)
Definition: codec_g726.c:207
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().

227 {
228  int i;
229  int sezi;
230  for (sezi = 0, i = 0; i < 6; i++) /* ACCUM */
231  sezi += fmult(state_ptr->b[i] >> 2, state_ptr->dq[i]);
232  return sezi;
233 }
int b[6]
Definition: codec_g726.c:85
int dq[6]
Definition: codec_g726.c:89
static int fmult(int an, int srn)
Definition: codec_g726.c:207
static int quan ( int  val,
int *  table,
int  size 
)
static

Definition at line 162 of file codec_g726.c.

References table.

Referenced by quantize().

163 {
164  int i;
165 
166  for (i = 0; i < size && val >= *table; ++i, ++table)
167  ;
168  return (i);
169 }
static char * table
Definition: cdr_odbc.c:50
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().

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

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 }
static int reload ( void  )
static

Definition at line 824 of file codec_g726.c.

References AST_MODULE_LOAD_SUCCESS.

825 {
827 }
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().

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

Definition at line 829 of file codec_g726.c.

References ast_unregister_translator().

Referenced by load_module().

830 {
831  int res = 0;
832 
835 
838 
839  return res;
840 }
static struct ast_translator lintog726
Definition: codec_g726.c:788
static struct ast_translator lintog726aal2
Definition: codec_g726.c:812
static struct ast_translator g726aal2tolin
Definition: codec_g726.c:800
int ast_unregister_translator(struct ast_translator *t)
Unregister a translator Unregisters the given tranlator.
Definition: translate.c:942
static struct ast_translator g726tolin
Definition: codec_g726.c:776
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, if(), 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().

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  /* FILTE & DELAY */
426  /* update steady state step size multiplier */
427  state_ptr->yl += state_ptr->yu + ((-state_ptr->yl) >> 6);
428 
429  /*
430  * Adaptive predictor coefficients.
431  */
432  if (tr == 1) { /* reset a's and b's for modem signal */
433  state_ptr->a[0] = 0;
434  state_ptr->a[1] = 0;
435  state_ptr->b[0] = 0;
436  state_ptr->b[1] = 0;
437  state_ptr->b[2] = 0;
438  state_ptr->b[3] = 0;
439  state_ptr->b[4] = 0;
440  state_ptr->b[5] = 0;
441  } else { /* update a's and b's */
442  pks1 = pk0 ^ state_ptr->pk[0]; /* UPA2 */
443 
444  /* update predictor pole a[1] */
445  a2p = state_ptr->a[1] - (state_ptr->a[1] >> 7);
446  if (dqsez != 0) {
447  fa1 = (pks1) ? state_ptr->a[0] : -state_ptr->a[0];
448  if (fa1 < -8191) /* a2p = function of fa1 */
449  a2p -= 0x100;
450  else if (fa1 > 8191)
451  a2p += 0xFF;
452  else
453  a2p += fa1 >> 5;
454 
455  if (pk0 ^ state_ptr->pk[1])
456  /* LIMC */
457  if (a2p <= -12160)
458  a2p = -12288;
459  else if (a2p >= 12416)
460  a2p = 12288;
461  else
462  a2p -= 0x80;
463  else if (a2p <= -12416)
464  a2p = -12288;
465  else if (a2p >= 12160)
466  a2p = 12288;
467  else
468  a2p += 0x80;
469  }
470 
471  /* TRIGB & DELAY */
472  state_ptr->a[1] = a2p;
473 
474  /* UPA1 */
475  /* update predictor pole a[0] */
476  state_ptr->a[0] -= state_ptr->a[0] >> 8;
477  if (dqsez != 0) {
478  if (pks1 == 0)
479  state_ptr->a[0] += 192;
480  else
481  state_ptr->a[0] -= 192;
482  }
483  /* LIMD */
484  a1ul = 15360 - a2p;
485  if (state_ptr->a[0] < -a1ul)
486  state_ptr->a[0] = -a1ul;
487  else if (state_ptr->a[0] > a1ul)
488  state_ptr->a[0] = a1ul;
489 
490  /* UPB : update predictor zeros b[6] */
491  for (cnt = 0; cnt < 6; cnt++) {
492  if (code_size == 5) /* for 40Kbps G.723 */
493  state_ptr->b[cnt] -= state_ptr->b[cnt] >> 9;
494  else /* for G.721 and 24Kbps G.723 */
495  state_ptr->b[cnt] -= state_ptr->b[cnt] >> 8;
496  if (mag)
497  { /* XOR */
498  if ((dq ^ state_ptr->dq[cnt]) >= 0)
499  state_ptr->b[cnt] += 128;
500  else
501  state_ptr->b[cnt] -= 128;
502  }
503  }
504  }
505 
506  for (cnt = 5; cnt > 0; cnt--)
507  state_ptr->dq[cnt] = state_ptr->dq[cnt-1];
508 #ifdef NOT_BLI
509  state_ptr->dq[0] = dq;
510 #else
511  /* FLOAT A : convert dq[0] to 4-bit exp, 6-bit mantissa f.p. */
512  if (mag == 0) {
513  state_ptr->dq[0] = (dq >= 0) ? 0x20 : 0x20 - 0x400;
514  } else {
515  exp = ilog2(mag) + 1;
516  state_ptr->dq[0] = (dq >= 0) ?
517  (exp << 6) + ((mag << 6) >> exp) :
518  (exp << 6) + ((mag << 6) >> exp) - 0x400;
519  }
520 #endif
521 
522  state_ptr->sr[1] = state_ptr->sr[0];
523 #ifdef NOT_BLI
524  state_ptr->sr[0] = sr;
525 #else
526  /* FLOAT B : convert sr to 4-bit exp., 6-bit mantissa f.p. */
527  if (sr == 0) {
528  state_ptr->sr[0] = 0x20;
529  } else if (sr > 0) {
530  exp = ilog2(sr) + 1;
531  state_ptr->sr[0] = (exp << 6) + ((sr << 6) >> exp);
532  } else if (sr > -0x8000) {
533  mag = -sr;
534  exp = ilog2(mag) + 1;
535  state_ptr->sr[0] = (exp << 6) + ((mag << 6) >> exp) - 0x400;
536  } else
537  state_ptr->sr[0] = 0x20 - 0x400;
538 #endif
539 
540  /* DELAY A */
541  state_ptr->pk[1] = state_ptr->pk[0];
542  state_ptr->pk[0] = pk0;
543 
544  /* TONE */
545  if (tr == 1) /* this sample has been treated as data */
546  state_ptr->td = 0; /* next one will be treated as voice */
547  else if (a2p < -11776) /* small sample-to-sample correlation */
548  state_ptr->td = 1; /* signal may be data */
549  else /* signal is voice */
550  state_ptr->td = 0;
551 
552  /*
553  * Adaptation speed control.
554  */
555  state_ptr->dms += (fi - state_ptr->dms) >> 5; /* FILTA */
556  state_ptr->dml += (((fi << 2) - state_ptr->dml) >> 7); /* FILTB */
557 
558  if (tr == 1)
559  state_ptr->ap = 256;
560  else if (y < 1536) /* SUBTC */
561  state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
562  else if (state_ptr->td == 1)
563  state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
564  else if (abs((state_ptr->dms << 2) - state_ptr->dml) >=
565  (state_ptr->dml >> 3))
566  state_ptr->ap += (0x200 - state_ptr->ap) >> 4;
567  else
568  state_ptr->ap += (-state_ptr->ap) >> 4;
569 }
int b[6]
Definition: codec_g726.c:85
int a[2]
Definition: codec_g726.c:83
int dq[6]
Definition: codec_g726.c:89
int sr[2]
Definition: codec_g726.c:92
if(yyss+yystacksize-1<=yyssp)
Definition: ast_expr2.c:1874
static int ilog2(int val)
Definition: log2comp.h:67
int pk[2]
Definition: codec_g726.c:87

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .reload = reload, }
static

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