#include <fcntl.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "asterisk.h"
#include "asterisk/lock.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/translate.h"
#include "asterisk/channel.h"
#include "log2comp.h"
#include "slin_g726_ex.h"
#include "g726_slin_ex.h"
Go to the source code of this file.
Data Structures | |
struct | g726_decoder_pvt |
struct | g726_encoder_pvt |
struct | g726_state |
Defines | |
#define | BUF_SHIFT 5 |
#define | BUFFER_SIZE 8096 |
#define | WANT_ASM |
Functions | |
AST_MUTEX_DEFINE_STATIC (localuser_lock) | |
char * | description (void) |
Provides a description of the module. | |
static int | fmult (int an, int srn) |
static int | g726_decode (int i, struct g726_state *state_ptr) |
static void | g726_destroy (struct ast_translator_pvt *pvt) |
static int | g726_encode (int sl, struct g726_state *state_ptr) |
static void | g726_init_state (struct g726_state *state_ptr) |
static int | g726tolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f) |
static struct ast_frame * | g726tolin_frameout (struct ast_translator_pvt *pvt) |
static struct ast_translator_pvt * | g726tolin_new (void) |
static struct ast_frame * | g726tolin_sample (void) |
char * | key () |
Returns the ASTERISK_GPL_KEY. | |
static int | lintog726_framein (struct ast_translator_pvt *pvt, struct ast_frame *f) |
static struct ast_frame * | lintog726_frameout (struct ast_translator_pvt *pvt) |
static struct ast_translator_pvt * | lintog726_new (void) |
static struct ast_frame * | lintog726_sample (void) |
int | load_module (void) |
Initialize the module. | |
static void | parse_config (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) |
int | reload (void) |
Reload stuff. | |
static int | step_size (struct g726_state *state_ptr) |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
static void | update (int code_size, int y, int wi, int fi, int dq, int sr, int dqsez, struct g726_state *state_ptr) |
int | usecount (void) |
Provides a usecount. | |
Variables | |
static int | _dqlntab [16] |
static int | _fitab [16] |
static int | _witab [16] |
static struct ast_translator | g726tolin |
static struct ast_translator | lintog726 |
static int | localusecnt = 0 |
static int | qtab_721 [7] = {-124, 80, 178, 246, 300, 349, 400} |
static char * | tdesc = "ITU G.726-32kbps G726 Transcoder" |
static int | useplc = 0 |
Definition in file codec_g726.c.
|
Definition at line 66 of file codec_g726.c. |
|
Definition at line 65 of file codec_g726.c. |
|
Definition at line 49 of file codec_g726.c. |
|
|
|
Provides a description of the module.
Definition at line 1075 of file codec_g726.c. References tdesc. 01076 { 01077 return tdesc; 01078 }
|
|
Definition at line 229 of file codec_g726.c. References ilog2(). Referenced by predictor_pole(), and predictor_zero(). 00230 { 00231 int anmag, anexp, anmant; 00232 int wanexp, wanmant; 00233 int retval; 00234 00235 anmag = (an > 0) ? an : ((-an) & 0x1FFF); 00236 anexp = ilog2(anmag) - 5; 00237 anmant = (anmag == 0) ? 32 : 00238 (anexp >= 0) ? anmag >> anexp : anmag << -anexp; 00239 wanexp = anexp + ((srn >> 6) & 0xF) - 13; 00240 00241 wanmant = (anmant * (srn & 077) + 0x30) >> 4; 00242 retval = (wanexp >= 0) ? ((wanmant << wanexp) & 0x7FFF) : 00243 (wanmant >> -wanexp); 00244 00245 return (((an ^ srn) < 0) ? -retval : retval); 00246 }
|
|
Definition at line 602 of file codec_g726.c. References _dqlntab, _fitab, _witab, predictor_pole(), predictor_zero(), reconstruct(), step_size(), and update(). 00603 { 00604 int sezi, sez, se; /* ACCUM */ 00605 int y; /* MIX */ 00606 int sr; /* ADDB */ 00607 int dq; 00608 int dqsez; 00609 00610 i &= 0x0f; /* mask to get proper bits */ 00611 #ifdef NOT_BLI 00612 sezi = predictor_zero(state_ptr); 00613 sez = sezi; 00614 se = sezi + predictor_pole(state_ptr); /* estimated signal */ 00615 #else 00616 sezi = predictor_zero(state_ptr); 00617 sez = sezi >> 1; 00618 se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */ 00619 #endif 00620 00621 y = step_size(state_ptr); /* dynamic quantizer step size */ 00622 00623 dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized diff. */ 00624 00625 #ifdef NOT_BLI 00626 sr = se + dq; /* reconst. signal */ 00627 dqsez = dq + sez; /* pole prediction diff. */ 00628 #else 00629 sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */ 00630 dqsez = sr - se + sez; /* pole prediction diff. */ 00631 #endif 00632 00633 update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr); 00634 00635 #ifdef NOT_BLI 00636 return (sr >> 10); /* sr was 26-bit dynamic range */ 00637 #else 00638 return (sr << 2); /* sr was 14-bit dynamic range */ 00639 #endif 00640 }
|
|
Definition at line 977 of file codec_g726.c. References ast_update_use_count(), free, and localusecnt. 00978 { 00979 free (pvt); 00980 localusecnt--; 00981 ast_update_use_count (); 00982 }
|
|
Definition at line 648 of file codec_g726.c. References _dqlntab, _fitab, _witab, predictor_pole(), predictor_zero(), qtab_721, quantize(), reconstruct(), step_size(), and update(). 00649 { 00650 int sezi, se, sez; /* ACCUM */ 00651 int d; /* SUBTA */ 00652 int sr; /* ADDB */ 00653 int y; /* MIX */ 00654 int dqsez; /* ADDC */ 00655 int dq, i; 00656 00657 #ifdef NOT_BLI 00658 sl <<= 10; /* 26-bit dynamic range */ 00659 00660 sezi = predictor_zero(state_ptr); 00661 sez = sezi; 00662 se = sezi + predictor_pole(state_ptr); /* estimated signal */ 00663 #else 00664 sl >>= 2; /* 14-bit dynamic range */ 00665 00666 sezi = predictor_zero(state_ptr); 00667 sez = sezi >> 1; 00668 se = (sezi + predictor_pole(state_ptr)) >> 1; /* estimated signal */ 00669 #endif 00670 00671 d = sl - se; /* estimation difference */ 00672 00673 /* quantize the prediction difference */ 00674 y = step_size(state_ptr); /* quantizer step size */ 00675 #ifdef NOT_BLI 00676 d /= 0x1000; 00677 #endif 00678 i = quantize(d, y, qtab_721, 7); /* i = G726 code */ 00679 00680 dq = reconstruct(i & 8, _dqlntab[i], y); /* quantized est diff */ 00681 00682 #ifdef NOT_BLI 00683 sr = se + dq; /* reconst. signal */ 00684 dqsez = dq + sez; /* pole prediction diff. */ 00685 #else 00686 sr = (dq < 0) ? se - (dq & 0x3FFF) : se + dq; /* reconst. signal */ 00687 dqsez = sr - se + sez; /* pole prediction diff. */ 00688 #endif 00689 00690 update(4, y, _witab[i] << 5, _fitab[i], dq, sr, dqsez, state_ptr); 00691 00692 return (i); 00693 }
|
|
Definition at line 145 of file codec_g726.c. References g726_state::a, g726_state::ap, g726_state::dml, g726_state::dms, g726_state::pk, g726_state::sr, g726_state::yl, and g726_state::yu. Referenced by g726tolin_new(), and lintog726_new(). 00146 { 00147 int cnta; 00148 00149 state_ptr->yl = 34816; 00150 state_ptr->yu = 544; 00151 state_ptr->dms = 0; 00152 state_ptr->dml = 0; 00153 state_ptr->ap = 0; 00154 for (cnta = 0; cnta < 2; cnta++) 00155 { 00156 state_ptr->a[cnta] = 0; 00157 state_ptr->pk[cnta] = 0; 00158 #ifdef NOT_BLI 00159 state_ptr->sr[cnta] = 1; 00160 #else 00161 state_ptr->sr[cnta] = 32; 00162 #endif 00163 } 00164 for (cnta = 0; cnta < 6; cnta++) 00165 { 00166 state_ptr->b[cnta] = 0; 00167 #ifdef NOT_BLI 00168 state_ptr->dq[cnta] = 1; 00169 #else 00170 state_ptr->dq[cnta] = 32; 00171 #endif 00172 } 00173 state_ptr->td = 0; 00174 }
|
|
Definition at line 791 of file codec_g726.c. References ast_log(), BUFFER_SIZE, ast_frame::data, ast_frame::datalen, g726_decoder_pvt::f, LOG_WARNING, g726_decoder_pvt::outbuf, g726_decoder_pvt::plc, plc_fillin(), g726_decoder_pvt::tail, and useplc. 00792 { 00793 struct g726_decoder_pvt *tmp = (struct g726_decoder_pvt *) pvt; 00794 unsigned char *b; 00795 int x; 00796 00797 if(f->datalen == 0) { /* perform PLC with nominal framesize of 20ms/160 samples */ 00798 if((tmp->tail + 160) > BUFFER_SIZE) { 00799 ast_log(LOG_WARNING, "Out of buffer space\n"); 00800 return -1; 00801 } 00802 if(useplc) { 00803 plc_fillin(&tmp->plc, tmp->outbuf+tmp->tail, 160); 00804 tmp->tail += 160; 00805 } 00806 return 0; 00807 } 00808 00809 b = f->data; 00810 for (x=0;x<f->datalen;x++) { 00811 if (tmp->tail >= BUFFER_SIZE) { 00812 ast_log(LOG_WARNING, "Out of buffer space!\n"); 00813 return -1; 00814 } 00815 tmp->outbuf[tmp->tail++] = g726_decode((b[x] >> 4) & 0xf, &tmp->g726); 00816 if (tmp->tail >= BUFFER_SIZE) { 00817 ast_log(LOG_WARNING, "Out of buffer space!\n"); 00818 return -1; 00819 } 00820 tmp->outbuf[tmp->tail++] = g726_decode(b[x] & 0x0f, &tmp->g726); 00821 } 00822 00823 if(useplc) plc_rx(&tmp->plc, tmp->outbuf+tmp->tail-f->datalen*2, f->datalen*2); 00824 00825 return 0; 00826 }
|
|
Definition at line 841 of file codec_g726.c. References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_frame::data, ast_frame::datalen, g726_decoder_pvt::f, ast_frame::frametype, ast_frame::mallocd, ast_frame::offset, g726_decoder_pvt::outbuf, ast_frame::samples, ast_frame::src, ast_frame::subclass, and g726_decoder_pvt::tail. 00842 { 00843 struct g726_decoder_pvt *tmp = (struct g726_decoder_pvt *) pvt; 00844 00845 if (!tmp->tail) 00846 return NULL; 00847 00848 tmp->f.frametype = AST_FRAME_VOICE; 00849 tmp->f.subclass = AST_FORMAT_SLINEAR; 00850 tmp->f.datalen = tmp->tail * 2; 00851 tmp->f.samples = tmp->tail; 00852 tmp->f.mallocd = 0; 00853 tmp->f.offset = AST_FRIENDLY_OFFSET; 00854 tmp->f.src = __PRETTY_FUNCTION__; 00855 tmp->f.data = tmp->outbuf; 00856 tmp->tail = 0; 00857 return &tmp->f; 00858 }
|
|
Definition at line 735 of file codec_g726.c. References ast_update_use_count(), g726_init_state(), localusecnt, malloc, and plc_init(). 00736 { 00737 struct g726_decoder_pvt *tmp; 00738 tmp = malloc (sizeof (struct g726_decoder_pvt)); 00739 if (tmp) 00740 { 00741 memset(tmp, 0, sizeof(*tmp)); 00742 tmp->tail = 0; 00743 plc_init(&tmp->plc); 00744 localusecnt++; 00745 g726_init_state(&tmp->g726); 00746 ast_update_use_count (); 00747 } 00748 return (struct ast_translator_pvt *) tmp; 00749 }
|
|
Definition at line 931 of file codec_g726.c. References AST_FORMAT_G726, AST_FRAME_VOICE, ast_frame::data, ast_frame::datalen, ast_frame::frametype, g726_slin_ex, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, ast_frame::src, and ast_frame::subclass. 00932 { 00933 static struct ast_frame f; 00934 f.frametype = AST_FRAME_VOICE; 00935 f.subclass = AST_FORMAT_G726; 00936 f.datalen = sizeof (g726_slin_ex); 00937 f.samples = sizeof(g726_slin_ex) * 2; 00938 f.mallocd = 0; 00939 f.offset = 0; 00940 f.src = __PRETTY_FUNCTION__; 00941 f.data = g726_slin_ex; 00942 return &f; 00943 }
|
|
Returns the ASTERISK_GPL_KEY. This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:
char *key(void) { return ASTERISK_GPL_KEY; }
Definition at line 1089 of file codec_g726.c. References ASTERISK_GPL_KEY. 01090 { 01091 return ASTERISK_GPL_KEY; 01092 }
|
|
Definition at line 872 of file codec_g726.c. References ast_log(), BUFFER_SIZE, ast_frame::data, ast_frame::datalen, g726_encoder_pvt::f, LOG_WARNING, g726_encoder_pvt::next_flag, s, and g726_encoder_pvt::tail. 00873 { 00874 struct g726_encoder_pvt *tmp = (struct g726_encoder_pvt *) pvt; 00875 short *s = f->data; 00876 int samples = f->datalen / 2; 00877 int x; 00878 for (x=0;x<samples;x++) { 00879 if (tmp->next_flag & 0x80) { 00880 if (tmp->tail >= BUFFER_SIZE) { 00881 ast_log(LOG_WARNING, "Out of buffer space\n"); 00882 return -1; 00883 } 00884 tmp->outbuf[tmp->tail++] = ((tmp->next_flag & 0xf)<< 4) | g726_encode(s[x], &tmp->g726); 00885 tmp->next_flag = 0; 00886 } else { 00887 tmp->next_flag = 0x80 | g726_encode(s[x], &tmp->g726); 00888 } 00889 } 00890 return 0; 00891 }
|
|
Definition at line 906 of file codec_g726.c. References AST_FORMAT_G726, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_frame::data, ast_frame::datalen, g726_encoder_pvt::f, ast_frame::frametype, ast_frame::mallocd, ast_frame::offset, g726_encoder_pvt::outbuf, ast_frame::samples, ast_frame::src, ast_frame::subclass, and g726_encoder_pvt::tail. 00907 { 00908 struct g726_encoder_pvt *tmp = (struct g726_encoder_pvt *) pvt; 00909 00910 if (!tmp->tail) 00911 return NULL; 00912 tmp->f.frametype = AST_FRAME_VOICE; 00913 tmp->f.subclass = AST_FORMAT_G726; 00914 tmp->f.samples = tmp->tail * 2; 00915 tmp->f.mallocd = 0; 00916 tmp->f.offset = AST_FRIENDLY_OFFSET; 00917 tmp->f.src = __PRETTY_FUNCTION__; 00918 tmp->f.data = tmp->outbuf; 00919 tmp->f.datalen = tmp->tail; 00920 00921 tmp->tail = 0; 00922 return &tmp->f; 00923 }
|
|
Definition at line 763 of file codec_g726.c. References ast_update_use_count(), g726_init_state(), localusecnt, and malloc. 00764 { 00765 struct g726_encoder_pvt *tmp; 00766 tmp = malloc (sizeof (struct g726_encoder_pvt)); 00767 if (tmp) 00768 { 00769 memset(tmp, 0, sizeof(*tmp)); 00770 localusecnt++; 00771 tmp->tail = 0; 00772 g726_init_state(&tmp->g726); 00773 ast_update_use_count (); 00774 } 00775 return (struct ast_translator_pvt *) tmp; 00776 }
|
|
Definition at line 950 of file codec_g726.c. References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_frame::data, ast_frame::datalen, ast_frame::frametype, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, slin_g726_ex, ast_frame::src, and ast_frame::subclass. 00951 { 00952 static struct ast_frame f; 00953 f.frametype = AST_FRAME_VOICE; 00954 f.subclass = AST_FORMAT_SLINEAR; 00955 f.datalen = sizeof (slin_g726_ex); 00956 /* Assume 8000 Hz */ 00957 f.samples = sizeof (slin_g726_ex) / 2; 00958 f.mallocd = 0; 00959 f.offset = 0; 00960 f.src = __PRETTY_FUNCTION__; 00961 f.data = slin_g726_ex; 00962 return &f; 00963 }
|
|
Initialize the module. Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.
Definition at line 1058 of file codec_g726.c. References ast_register_translator(), ast_unregister_translator(), g726tolin, lintog726, and parse_config(). 01059 { 01060 int res; 01061 parse_config(); 01062 res = ast_register_translator (&g726tolin); 01063 if (!res) 01064 res = ast_register_translator (&lintog726); 01065 else 01066 ast_unregister_translator (&g726tolin); 01067 return res; 01068 }
|
|
Definition at line 1017 of file codec_g726.c. References ast_config_destroy(), ast_config_load(), ast_true(), ast_variable_browse(), ast_verbose(), cfg, option_verbose, useplc, var, and VERBOSE_PREFIX_3. 01018 { 01019 struct ast_config *cfg; 01020 struct ast_variable *var; 01021 if ((cfg = ast_config_load("codecs.conf"))) { 01022 if ((var = ast_variable_browse(cfg, "plc"))) { 01023 while (var) { 01024 if (!strcasecmp(var->name, "genericplc")) { 01025 useplc = ast_true(var->value) ? 1 : 0; 01026 if (option_verbose > 2) 01027 ast_verbose(VERBOSE_PREFIX_3 "codec_g726: %susing generic PLC\n", useplc ? "" : "not "); 01028 } 01029 var = var->next; 01030 } 01031 } 01032 ast_config_destroy(cfg); 01033 } 01034 }
|
|
Definition at line 257 of file codec_g726.c. References g726_state::a, fmult(), and g726_state::sr. Referenced by g726_decode(), and g726_encode(). 00258 { 00259 return (fmult(state_ptr->a[1] >> 2, state_ptr->sr[1]) + 00260 fmult(state_ptr->a[0] >> 2, state_ptr->sr[0])); 00261 }
|
|
Definition at line 248 of file codec_g726.c. References g726_state::b, g726_state::dq, and fmult(). Referenced by g726_decode(), and g726_encode(). 00249 { 00250 int i; 00251 int sezi; 00252 for (sezi = 0, i = 0; i < 6; i++) /* ACCUM */ 00253 sezi += fmult(state_ptr->b[i] >> 2, state_ptr->dq[i]); 00254 return sezi; 00255 }
|
|
Definition at line 184 of file codec_g726.c. Referenced by quantize(). 00185 { 00186 int i; 00187 00188 for (i = 0; i < size && val >= *table; ++i, ++table) 00189 ; 00190 return (i); 00191 }
|
|
Definition at line 300 of file codec_g726.c. References ilog2(), and quan(). Referenced by g726_encode(). 00305 { 00306 int dqm; /* Magnitude of 'd' */ 00307 int exp; /* Integer part of base 2 log of 'd' */ 00308 int mant; /* Fractional part of base 2 log */ 00309 int dl; /* Log of magnitude of 'd' */ 00310 int dln; /* Step size scale factor normalized log */ 00311 int i; 00312 00313 /* 00314 * LOG 00315 * 00316 * Compute base 2 log of 'd', and store in 'dl'. 00317 */ 00318 dqm = abs(d); 00319 exp = ilog2(dqm); 00320 if (exp < 0) 00321 exp = 0; 00322 mant = ((dqm << 7) >> exp) & 0x7F; /* Fractional portion. */ 00323 dl = (exp << 7) | mant; 00324 00325 /* 00326 * SUBTB 00327 * 00328 * "Divide" by step size multiplier. 00329 */ 00330 dln = dl - (y >> 2); 00331 00332 /* 00333 * QUAN 00334 * 00335 * Obtain codword i for 'd'. 00336 */ 00337 i = quan(dln, table, size); 00338 if (d < 0) /* take 1's complement of i */ 00339 return ((size << 1) + 1 - i); 00340 else if (i == 0) /* take 1's complement of 0 */ 00341 return ((size << 1) + 1); /* new in 1988 */ 00342 else 00343 return (i); 00344 }
|
|
Definition at line 353 of file codec_g726.c. Referenced by g726_decode(), and g726_encode(). 00357 { 00358 int dql; /* Log of 'dq' magnitude */ 00359 int dex; /* Integer part of log */ 00360 int dqt; 00361 int dq; /* Reconstructed difference signal sample */ 00362 00363 dql = dqln + (y >> 2); /* ADDA */ 00364 00365 if (dql < 0) { 00366 #ifdef NOT_BLI 00367 return (sign) ? -1 : 1; 00368 #else 00369 return (sign) ? -0x8000 : 0; 00370 #endif 00371 } else { /* ANTILOG */ 00372 dex = (dql >> 7) & 15; 00373 dqt = 128 + (dql & 127); 00374 #ifdef NOT_BLI 00375 dq = ((dqt << 19) >> (14 - dex)); 00376 return (sign) ? -dq : dq; 00377 #else 00378 dq = (dqt << 7) >> (14 - dex); 00379 return (sign) ? (dq - 0x8000) : dq; 00380 #endif 00381 } 00382 }
|
|
Reload stuff. This function is where any reload routines take place. Re-read config files, change signalling, whatever is appropriate on a reload.
Definition at line 1037 of file codec_g726.c. References parse_config(). 01038 { 01039 parse_config(); 01040 return 0; 01041 }
|
|
Definition at line 271 of file codec_g726.c. References g726_state::ap, g726_state::yl, and g726_state::yu. Referenced by g726_decode(), and g726_encode(). 00272 { 00273 int y; 00274 int dif; 00275 int al; 00276 00277 if (state_ptr->ap >= 256) 00278 return (state_ptr->yu); 00279 else { 00280 y = state_ptr->yl >> 6; 00281 dif = state_ptr->yu - y; 00282 al = state_ptr->ap >> 2; 00283 if (dif > 0) 00284 y += (dif * al) >> 6; 00285 else if (dif < 0) 00286 y += (dif * al + 0x3F) >> 6; 00287 return (y); 00288 } 00289 }
|
|
Cleanup all module structures, sockets, etc. This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).
Definition at line 1044 of file codec_g726.c. References ast_mutex_lock(), ast_mutex_unlock(), ast_unregister_translator(), g726tolin, lintog726, and localusecnt. 01045 { 01046 int res; 01047 ast_mutex_lock (&localuser_lock); 01048 res = ast_unregister_translator (&lintog726); 01049 if (!res) 01050 res = ast_unregister_translator (&g726tolin); 01051 if (localusecnt) 01052 res = -1; 01053 ast_mutex_unlock (&localuser_lock); 01054 return res; 01055 }
|
|
Definition at line 389 of file codec_g726.c. References g726_state::a, g726_state::b, g726_state::dq, g726_state::pk, g726_state::td, g726_state::yl, and g726_state::yu. Referenced by g726_decode(), and g726_encode(). 00398 { 00399 int cnt; 00400 int mag; /* Adaptive predictor, FLOAT A */ 00401 #ifndef NOT_BLI 00402 int exp; 00403 #endif 00404 int a2p=0; /* LIMC */ 00405 int a1ul; /* UPA1 */ 00406 int pks1; /* UPA2 */ 00407 int fa1; 00408 int tr; /* tone/transition detector */ 00409 int ylint, thr2, dqthr; 00410 int ylfrac, thr1; 00411 int pk0; 00412 00413 pk0 = (dqsez < 0) ? 1 : 0; /* needed in updating predictor poles */ 00414 00415 #ifdef NOT_BLI 00416 mag = abs(dq / 0x1000); /* prediction difference magnitude */ 00417 #else 00418 mag = dq & 0x7FFF; /* prediction difference magnitude */ 00419 #endif 00420 /* TRANS */ 00421 ylint = state_ptr->yl >> 15; /* exponent part of yl */ 00422 ylfrac = (state_ptr->yl >> 10) & 0x1F; /* fractional part of yl */ 00423 thr1 = (32 + ylfrac) << ylint; /* threshold */ 00424 thr2 = (ylint > 9) ? 31 << 10 : thr1; /* limit thr2 to 31 << 10 */ 00425 dqthr = (thr2 + (thr2 >> 1)) >> 1; /* dqthr = 0.75 * thr2 */ 00426 if (state_ptr->td == 0) /* signal supposed voice */ 00427 tr = 0; 00428 else if (mag <= dqthr) /* supposed data, but small mag */ 00429 tr = 0; /* treated as voice */ 00430 else /* signal is data (modem) */ 00431 tr = 1; 00432 00433 /* 00434 * Quantizer scale factor adaptation. 00435 */ 00436 00437 /* FUNCTW & FILTD & DELAY */ 00438 /* update non-steady state step size multiplier */ 00439 state_ptr->yu = y + ((wi - y) >> 5); 00440 00441 /* LIMB */ 00442 if (state_ptr->yu < 544) /* 544 <= yu <= 5120 */ 00443 state_ptr->yu = 544; 00444 else if (state_ptr->yu > 5120) 00445 state_ptr->yu = 5120; 00446 00447 /* FILTE & DELAY */ 00448 /* update steady state step size multiplier */ 00449 state_ptr->yl += state_ptr->yu + ((-state_ptr->yl) >> 6); 00450 00451 /* 00452 * Adaptive predictor coefficients. 00453 */ 00454 if (tr == 1) { /* reset a's and b's for modem signal */ 00455 state_ptr->a[0] = 0; 00456 state_ptr->a[1] = 0; 00457 state_ptr->b[0] = 0; 00458 state_ptr->b[1] = 0; 00459 state_ptr->b[2] = 0; 00460 state_ptr->b[3] = 0; 00461 state_ptr->b[4] = 0; 00462 state_ptr->b[5] = 0; 00463 } else { /* update a's and b's */ 00464 pks1 = pk0 ^ state_ptr->pk[0]; /* UPA2 */ 00465 00466 /* update predictor pole a[1] */ 00467 a2p = state_ptr->a[1] - (state_ptr->a[1] >> 7); 00468 if (dqsez != 0) { 00469 fa1 = (pks1) ? state_ptr->a[0] : -state_ptr->a[0]; 00470 if (fa1 < -8191) /* a2p = function of fa1 */ 00471 a2p -= 0x100; 00472 else if (fa1 > 8191) 00473 a2p += 0xFF; 00474 else 00475 a2p += fa1 >> 5; 00476 00477 if (pk0 ^ state_ptr->pk[1]) 00478 /* LIMC */ 00479 if (a2p <= -12160) 00480 a2p = -12288; 00481 else if (a2p >= 12416) 00482 a2p = 12288; 00483 else 00484 a2p -= 0x80; 00485 else if (a2p <= -12416) 00486 a2p = -12288; 00487 else if (a2p >= 12160) 00488 a2p = 12288; 00489 else 00490 a2p += 0x80; 00491 } 00492 00493 /* TRIGB & DELAY */ 00494 state_ptr->a[1] = a2p; 00495 00496 /* UPA1 */ 00497 /* update predictor pole a[0] */ 00498 state_ptr->a[0] -= state_ptr->a[0] >> 8; 00499 if (dqsez != 0) { 00500 if (pks1 == 0) 00501 state_ptr->a[0] += 192; 00502 else 00503 state_ptr->a[0] -= 192; 00504 } 00505 /* LIMD */ 00506 a1ul = 15360 - a2p; 00507 if (state_ptr->a[0] < -a1ul) 00508 state_ptr->a[0] = -a1ul; 00509 else if (state_ptr->a[0] > a1ul) 00510 state_ptr->a[0] = a1ul; 00511 00512 /* UPB : update predictor zeros b[6] */ 00513 for (cnt = 0; cnt < 6; cnt++) { 00514 if (code_size == 5) /* for 40Kbps G.723 */ 00515 state_ptr->b[cnt] -= state_ptr->b[cnt] >> 9; 00516 else /* for G.721 and 24Kbps G.723 */ 00517 state_ptr->b[cnt] -= state_ptr->b[cnt] >> 8; 00518 if (mag) 00519 { /* XOR */ 00520 if ((dq ^ state_ptr->dq[cnt]) >= 0) 00521 state_ptr->b[cnt] += 128; 00522 else 00523 state_ptr->b[cnt] -= 128; 00524 } 00525 } 00526 } 00527 00528 for (cnt = 5; cnt > 0; cnt--) 00529 state_ptr->dq[cnt] = state_ptr->dq[cnt-1]; 00530 #ifdef NOT_BLI 00531 state_ptr->dq[0] = dq; 00532 #else 00533 /* FLOAT A : convert dq[0] to 4-bit exp, 6-bit mantissa f.p. */ 00534 if (mag == 0) { 00535 state_ptr->dq[0] = (dq >= 0) ? 0x20 : 0x20 - 0x400; 00536 } else { 00537 exp = ilog2(mag) + 1; 00538 state_ptr->dq[0] = (dq >= 0) ? 00539 (exp << 6) + ((mag << 6) >> exp) : 00540 (exp << 6) + ((mag << 6) >> exp) - 0x400; 00541 } 00542 #endif 00543 00544 state_ptr->sr[1] = state_ptr->sr[0]; 00545 #ifdef NOT_BLI 00546 state_ptr->sr[0] = sr; 00547 #else 00548 /* FLOAT B : convert sr to 4-bit exp., 6-bit mantissa f.p. */ 00549 if (sr == 0) { 00550 state_ptr->sr[0] = 0x20; 00551 } else if (sr > 0) { 00552 exp = ilog2(sr) + 1; 00553 state_ptr->sr[0] = (exp << 6) + ((sr << 6) >> exp); 00554 } else if (sr > -0x8000) { 00555 mag = -sr; 00556 exp = ilog2(mag) + 1; 00557 state_ptr->sr[0] = (exp << 6) + ((mag << 6) >> exp) - 0x400; 00558 } else 00559 state_ptr->sr[0] = 0x20 - 0x400; 00560 #endif 00561 00562 /* DELAY A */ 00563 state_ptr->pk[1] = state_ptr->pk[0]; 00564 state_ptr->pk[0] = pk0; 00565 00566 /* TONE */ 00567 if (tr == 1) /* this sample has been treated as data */ 00568 state_ptr->td = 0; /* next one will be treated as voice */ 00569 else if (a2p < -11776) /* small sample-to-sample correlation */ 00570 state_ptr->td = 1; /* signal may be data */ 00571 else /* signal is voice */ 00572 state_ptr->td = 0; 00573 00574 /* 00575 * Adaptation speed control. 00576 */ 00577 state_ptr->dms += (fi - state_ptr->dms) >> 5; /* FILTA */ 00578 state_ptr->dml += (((fi << 2) - state_ptr->dml) >> 7); /* FILTB */ 00579 00580 if (tr == 1) 00581 state_ptr->ap = 256; 00582 else if (y < 1536) /* SUBTC */ 00583 state_ptr->ap += (0x200 - state_ptr->ap) >> 4; 00584 else if (state_ptr->td == 1) 00585 state_ptr->ap += (0x200 - state_ptr->ap) >> 4; 00586 else if (abs((state_ptr->dms << 2) - state_ptr->dml) >= 00587 (state_ptr->dml >> 3)) 00588 state_ptr->ap += (0x200 - state_ptr->ap) >> 4; 00589 else 00590 state_ptr->ap += (-state_ptr->ap) >> 4; 00591 }
|
|
Provides a usecount. This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.
Definition at line 1081 of file codec_g726.c. References STANDARD_USECOUNT. 01082 { 01083 int res; 01084 STANDARD_USECOUNT (res); 01085 return res; 01086 }
|
|
Initial value: {-2048, 4, 135, 213, 273, 323, 373, 425, 425, 373, 323, 273, 213, 135, 4, -2048} Definition at line 119 of file codec_g726.c. Referenced by g726_decode(), and g726_encode(). |
|
Initial value: {0, 0, 0, 0x200, 0x200, 0x200, 0x600, 0xE00, 0xE00, 0x600, 0x200, 0x200, 0x200, 0, 0, 0} Definition at line 130 of file codec_g726.c. Referenced by g726_decode(), and g726_encode(). |
|
Initial value: {-12, 18, 41, 64, 112, 198, 355, 1122, 1122, 355, 198, 112, 64, 41, 18, -12} Definition at line 123 of file codec_g726.c. Referenced by g726_decode(), and g726_encode(). |
|
Definition at line 988 of file codec_g726.c. Referenced by load_module(), and unload_module(). |
|
Definition at line 1004 of file codec_g726.c. Referenced by load_module(), and unload_module(). |
|
Definition at line 69 of file codec_g726.c. |
|
Definition at line 114 of file codec_g726.c. Referenced by g726_encode(). |
|
Definition at line 71 of file codec_g726.c. |
|
Definition at line 73 of file codec_g726.c. |