📄 g727.c
字号:
g727_asc_transit(&st->asc, ic, y, tr, tdp, cbits); g727_aprsc_transit(&st->aprsc, dqfb, tr, srfb, a2p, pk0, sigpk); g727_ttd_transit(&st->ttd, tr, tdp); return sd;}/* ..................... End of G727_decode_sample() ..................... *//* ********************************************************************** * * ******** PRIVATE FUNCTIONS - DO NOT GO BEYOND THIS POINT ... ********* * * ********************************************************************** *//*---------- Input PCM format conversion and difference ----------*//*---------- signal computation (G.727 6.2.1) --------------------*/Int16g727_get_d(Int8 s, Int16 se, short law){ Int8 sp = (law == 1) ? (0xd5 ^ s) : (0xff ^ s); return g727_subta(g727_expand(sp, law), se);}Int16g727_expand(Int8 sp, short law){ Int16 ss = 0x21 | ((sp & 0xf) << 1); Int8 sss; Int16 ssq; Int16 sl; if (law == 1) { if ((sp & 0x70) == 0) ss ^= 0x20; else ss <<= ((sp & 0x70) >> 4) - 1; ss |= (sp & 0x80) << 5; } else if (law == 0) { ss <<= (sp & 0x70) >> 4; ss -= 33; ss |= (sp & 0x80) << 6; } else assert(0); if (law == 0) { sss = ss >> 13; ssq = ss & 8191; } else { Int16 ssm; sss = ss >> 12; ssm = ss & 4095; ssq = ssm << 1; } if (sss == 0) sl = ssq; else if (sss == 1) sl = (16384 - ssq) & 16383; else assert(0); return sl;}Int16g727_subta(Int16 sl, Int16 se){ Int8 sls = sl >> 13; Int16 sli; Int8 ses; Int16 sei; if (sls == 0) sli = sl; else if (sls == 1) sli = 49152 + sl; else assert(0); ses = se >> 14; if (ses == 0) sei = se; else if (ses == 1) sei = 32768 + se; else assert(0); return (sli + 65536UL - sei) & 65535;}/*---------- Adaptive quantizer (G.727 6.2.2) ----------*/Int8g727_get_in(Int16 d, Int16 y, short rate){ Int16 dl; Int8 ds; g727_log(&dl, &ds, d); return g727_quan(g727_subtb(dl, y), ds, rate);}voidg727_log(Int16 *dl, Int8 *ds, Int16 d){ Int16 dqm; Int8 exp; Int8 mant; *ds = d >> 15; if (*ds == 0) dqm = d; else if (*ds == 1) dqm = (65536 - d) & 32767; else assert(0); if (16384 <= dqm) exp = 14; else if (8192 <= dqm) exp = 13; else if (4096 <= dqm) exp = 12; else if (2048 <= dqm) exp = 11; else if (1024 <= dqm) exp = 10; else if (512 <= dqm) exp = 9; else if (256 <= dqm) exp = 8; else if (128 <= dqm) exp = 7; else if (64 <= dqm) exp = 6; else if (32 <= dqm) exp = 5; else if (16 <= dqm) exp = 4; else if (8 <= dqm) exp = 3; else if (4 <= dqm) exp = 2; else if (2 <= dqm) exp = 1; else exp = 0; mant = (((Int32)dqm << 7) >> exp) & 127; *dl = ((Int16)exp << 7) + mant;}Int8g727_quan(Int16 dln, Int8 ds, short rate){ Int8 in; switch (rate) { case 5: if (4096 <= dln) assert(0); else if (4089 <= dln) in = 2; else if (3961 <= dln) in = 1; else if (2048 <= dln) in = 0; else if (439 <= dln) in = 15; else if (405 <= dln) in = 14; else if (380 <= dln) in = 13; else if (356 <= dln) in = 12; else if (333 <= dln) in = 11; else if (310 <= dln) in = 10; else if (286 <= dln) in = 9; else if (261 <= dln) in = 8; else if (233 <= dln) in = 7; else if (202 <= dln) in = 6; else if (166 <= dln) in = 5; else if (123 <= dln) in = 4; else if (69 <= dln) in = 3; else in = 2; in = (ds == 1) ? ((~in) & 0x1f) : in; break; case 4: if (4096 <= dln) assert(0); else if (4089 <= dln) in = 1; else if (2048 <= dln) in = 0; else if (405 <= dln) in = 7; else if (356 <= dln) in = 6; else if (310 <= dln) in = 5; else if (261 <= dln) in = 4; else if (202 <= dln) in = 3; else if (123 <= dln) in = 2; else in = 1; in = (ds == 1) ? ((~in) & 0xf) : in; break; case 3: if (4096 <= dln) assert(0); else if (2048 <= dln) in = 0; else if (356 <= dln) in = 3; else if (261 <= dln) in = 2; else if (123 <= dln) in = 1; else in = 0; in = (ds == 1) ? ((~in) & 0x7) : in; break; case 2: if (4096 <= dln) assert(0); else if (2048 <= dln) in = 0; else if (261 <= dln) in = 1; else in = 0; in = (ds == 1) ? ((~in) & 0x3) : in; break; default: assert(0); } return in;}Int16g727_subtb(Int16 dl, Int16 y){ return (dl + 4096 - (y >> 2)) & 4095;}/*---------- Bit masking (G.727 6.2.3) ----------*/Int8g727_get_ic(Int8 in, short enh){ return in >> enh;}/*---------- Inverse Adaptive Quantizer (G.727 6.2.4) ----------*/Int16g727_get_dq(Int16 y, Int8 in, short rate){ Int16 dqln; Int8 dqs; g727_reconst(&dqln, &dqs, in, rate); return g727_antilog(g727_adda(dqln, y), dqs);}Int16g727_antilog(Int16 dql, Int8 dqs){ Int8 ds = dql >> 11; Int8 dex = (dql >> 7) & 15; Int8 dmn = dql & 127; Int8 dqt = (1 << 7) + dmn; Int16 dqmag; if (ds == 0) dqmag = (dqt << 7) >> (14 - dex); else if (ds == 1) dqmag = 0; else assert(0); return (dqs << 14) + dqmag;}Int16g727_adda(Int16 dqln, Int16 y){ return (dqln + (y >> 2)) & 4095;}voidg727_reconst(Int16 *dqln, Int8 *dqs, Int8 in, short rate){ switch (rate) { case 5: *dqs = in >> 4; *dqln = g727_dqlnTable40[in]; break; case 4: *dqs = in >> 3; *dqln = g727_dqlnTable32[in]; break; case 3: *dqs = in >> 2; *dqln = g727_dqlnTable24[in]; break; case 2: *dqs = in >> 1; *dqln = g727_dqlnTable16[in]; break; default: assert(0); }}/*---------- Quantizer Scale Factor Adaptation (G.727 6.2.5) ----------*/voidg727_qsfa_reset(g727_qsfa_state *st){ st->yl = 34816; st->yu = 544;}Int16g727_get_y(g727_qsfa_state *st, Int8 al){ return g727_mix(st, al);}Int32g727_get_yl(g727_qsfa_state *st){ return st->yl;}voidg727_qsfa_transit(g727_qsfa_state *st, Int8 in, Int16 y, short rate){ Int16 yup = g727_limb(g727_filtd(g727_functw(in, rate), y)); Int32 ylp = g727_filte(st, yup); st->yu = yup; st->yl = ylp;}Int16g727_filtd(Int16 wi, Int16 y){ Int32 dif = (((Int32)wi << 5) + 131072 - y) & 131071; Int8 difs = dif >> 16; Int16 difsx; if (difs == 0) difsx = dif >> 5; else if (difs == 1) difsx = (dif >> 5) + 4096; else assert(0); return (y + difsx) & 8191;}Int32g727_filte(g727_qsfa_state *st, Int16 yup){ Int16 dif = (yup + ((1048576 - st->yl) >> 6)) & 16383; Int8 difs = dif >> 13; Int32 difsx; if (difs == 0) difsx = dif; else if (difs == 1) difsx = dif + 507904; else assert(0); return (st->yl + difsx) & 524287;}Int16g727_functw(Int8 in, short rate){ Int8 is; Int8 im; Int16 wi; switch (rate) { case 4: is = in >> 3; if (is == 0) im = in & 7; else if (is == 1) im = (15 - in) & 7; else assert(0); wi = g727_wiTable32[im]; break; case 3: is = in >> 2; if (is == 0) im = in & 3; else if (is == 1) im = (7 - in) & 3; else assert(0); wi = g727_wiTable24[im]; break; case 2: is = in >> 1; if (is == 0) im = in & 1; else if (is == 1) im = (3 - in) & 1; else assert(0); wi = g727_wiTable16[im]; break; default: assert(0); } return wi;}Int16g727_limb(Int16 yut){ Int8 geul = ((yut + 11264) & 16383) >> 13; Int8 gell = ((yut + 15840) & 16383) >> 13; Int16 yup; if (gell == 1) yup = 544; else if (geul == 0) yup = 5120; else yup = yut; return yup;}Int16g727_mix(g727_qsfa_state *st, Int8 al){ Int16 dif = (st->yu + 16384 - (st->yl >> 6)) & 16383; Int8 difs = dif >> 13; Int16 difm; Int16 prodm; Int16 prod; if (difs == 0) difm = dif; else if (difs == 1) difm = (16384 - dif) & 8191;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -