📄 g727.c
字号:
{ Int16 ome = 15360; Int16 a1ul = (ome + 65536UL - a2p) & 65535; Int16 a1ll = (a2p + 65536UL - ome) & 65535; return (32768 <= a1t && a1t <= a1ll) ? a1ll : ((a1ul <= a1t && a1t <= 32767) ? a1ul : a1t);}Int16g727_aprsc_trigb(Int8 tr, Int16 anp){ Int16 anr; if (tr == 0) anr = anp; else if (tr == 1) anr = 0; else assert(0); return anr;}Int16g727_upa1(g727_aprsc_state *st, Int8 pk0, Int8 sigpk){ Int8 pks = pk0 ^ st->pk1; Int16 uga1; Int8 a1s; Int16 ula1; Int16 ua1; if (pks == 0 && sigpk == 0) uga1 = 192; else if (pks == 1 && sigpk == 0) uga1 = 65344; else if (sigpk == 1) uga1 = 0; else assert(0); a1s = st->a1 >> 15; if (a1s == 0) ula1 = (65536 - (st->a1 >> 8)) & 65535; else if (a1s == 1) ula1 = (65536 - ((st->a1 >> 8) + 65280UL)) & 65535; else assert(0); ua1 = (uga1 + ula1) & 65535; return (st->a1 + ua1) & 65535;}Int16g727_upa2(g727_aprsc_state *st, Int8 pk0, Int8 sigpk){ Int8 pks1 = pk0 ^ st->pk1; Int8 pks2 = pk0 ^ st->pk2; Int32 uga2a; Int8 a1s; Int32 fa1; Int32 fa; Int32 uga2b; Int8 uga2s; Int16 uga2; Int8 a2s; Int16 ula2; Int16 ua2; if (pks2 == 0) uga2a = 16384; else if (pks2 == 1) uga2a = 114688; else assert(0); a1s = st->a1 >> 15; if (a1s == 0) fa1 = (st->a1 <= 8191) ? ((Int32)st->a1 << 2) : (8191U << 2); else if (a1s == 1) fa1 = (st->a1 >= 57345) ? (((Int32)st->a1 << 2) & 131071) : (24577UL << 2); else assert(0); if (pks1 == 1) fa = fa1; else if (pks1 == 0) fa = (131072 - fa1) & 131071; else assert(0); uga2b = (uga2a + fa) & 131071; uga2s = uga2b >> 16; if (uga2s == 0 && sigpk == 0) uga2 = uga2b >> 7; else if (uga2s == 1 && sigpk == 0) uga2 = (uga2b >> 7) + 64512; else if (sigpk == 1) uga2 = 0; else assert(0); a2s = st->a2 >> 15; if (a2s == 0) ula2 = (65536 - (st->a2 >> 7)) & 65535; else if (a2s == 1) ula2 = (65536 - ((st->a2 >> 7) + 65024)) & 65535; else assert(0); ua2 = (uga2 + ula2) & 65535; return (st->a2 + ua2) & 65535;}Int16g727_upb(Int8 un, Int16 bn, Int16 dq){ Int16 dqmag = dq & 16383; Int16 ugbn; Int8 bns; Int16 ulbn; Int16 ubn; if (un == 0 && dqmag != 0) ugbn = 128; else if (un == 1 && dqmag != 0) ugbn = 65408; else if (dqmag == 0) ugbn = 0; else assert(0); bns = bn >> 15; if (bns == 0) ulbn = (65536 - (bn >> 8)) & 65535; else if (bns == 1) ulbn = (65536 - ((bn >> 8) + 65280)) & 65535; else assert(0); ubn = (ugbn + ulbn) & 65535; return (bn + ubn) & 65535;}Int8g727_xor(Int16 dqn, Int16 dq){ Int8 dqs = dq >> 14; Int8 dqns = dqn >> 10; return dqs ^ dqns;}/*---------- Reconstructed signal calculator ----------*//*---------- Feed-Forward Path (G.727 6.2.8) ----------*/Int16g727_get_srff(Int16 dqff, Int16 se){ return g727_addb(dqff, se);}/*---------- Tone and Transition Detector (G.727 6.2.9) ----------*/voidg727_ttd_reset(g727_ttd_state *st){ st->td = 0;}Int8g727_get_tr(g727_ttd_state *st, Int32 yl, Int16 dq){ return g727_trans(st, yl, dq);}Int8g727_get_tdp(Int16 a2p){ return g727_tone(a2p);}voidg727_ttd_transit(g727_ttd_state *st, Int8 tr, Int8 tdp){ st->td = g727_ttd_trigb(tr, tdp);}Int8g727_tone(Int16 a2p){ return (32768 <= a2p && a2p < 53760) ? 1 : 0;}Int8g727_trans(g727_ttd_state *st, Int32 yl, Int16 dq){ Int16 dqmag = dq & 16383; Int8 ylint = yl >> 15; Int8 ylfrac = (yl >> 10) & 31; Int32 thr1 = (32 + ylfrac) << ylint; Int32 thr2 = (ylint > 8) ? (31 << 9) : thr1; Int32 dqthr = (thr2 + (thr2 >> 1)) >> 1; return (dqmag > dqthr && st->td == 1) ? 1 : 0;}Int8g727_ttd_trigb(Int8 tr, Int8 tdp){ Int8 tdr; if (tr == 0) tdr = tdp; else if (tr == 1) tdr = 0; else assert(0); return tdr;}/*---------- Output PCM Format Conversion and Synchronous -----------*//*---------- Coding Adjustment (G.727 6.2.9) ------------------------*/Int8g727_get_sd(Int16 sr, Int16 se, Int8 in, Int16 y, short law, short rate){ Int8 sp = g727_compress(sr, law); Int16 dl; Int8 ds; g727_log(&dl, &ds, g727_subta(g727_expand(sp, law), se)); return g727_sync(in, sp, g727_subtb(dl, y), law, ds, rate);}Int8g727_compress(Int16 sr, short law){ Int8 is = sr >> 15; Int16 im; Int16 imag; Int16 sp; if (is == 0) im = sr; else if (is == 1) im = (65536 - sr) & 32767; else assert(0); if (law == 0) imag = im; else if (is == 0) imag = im >> 1; else if (is == 1) imag = (im + 1) >> 1; else assert(0); if (law == 1) { /* A law */ if (imag == 0) sp = 0; else { if (is == 1) imag -= 1; if (4095 < imag) sp = 0x7f; /* Absolute maximum of PCM signal. */ else if (2047 < imag) sp = 0x70 | ((imag >> 7) & 0xf); else if (1023 < imag) sp = 0x60 | ((imag >> 6) & 0xf); else if (511 < imag) sp = 0x50 | ((imag >> 5) & 0xf); else if (255 < imag) sp = 0x40 | ((imag >> 4) & 0xf); else if (127 < imag) sp = 0x30 | ((imag >> 3) & 0xf); else if (63 < imag) sp = 0x20 | ((imag >> 2) & 0xf); else if (31 < imag) sp = 0x10 | ((imag >> 1) & 0xf); else sp = (imag >> 1) & 0xf; } } else { /* U law */ imag += 33; if (8191 < imag) sp = 0x7f; /* Absolute maximum of PCM signal. */ else if (4095 < imag) sp = 0x70 | ((imag >> 8) & 0xf); else if (2047 < imag) sp = 0x60 | ((imag >> 7) & 0xf); else if (1023 < imag) sp = 0x50 | ((imag >> 6) & 0xf); else if (511 < imag) sp = 0x40 | ((imag >> 5) & 0xf); else if (255 < imag) sp = 0x30 | ((imag >> 4) & 0xf); else if (127 < imag) sp = 0x20 | ((imag >> 3) & 0xf); else if (63 < imag) sp = 0x10 | ((imag >> 2) & 0xf); else sp = (imag >> 1) & 0xf; } sp |= is << 7; return sp;}Int8g727_sync(Int8 in, Int8 sp, Int16 dlnx, short law, Int8 ds, short rate){ Int8 is; Int8 im; Int8 id; Int8 sd; switch (rate) { case 5: is = in >> 4; if (is == 0) im = in + 16; else if (is == 1) im = in & 15; else assert(0); if (4096 <= dlnx) assert(0); else if (4089 <= dlnx) id = 18; else if (3961 <= dlnx) id = 17; else if (2048 <= dlnx) id = 16; else if (439 <= dlnx) id = 31; else if (405 <= dlnx) id = 30; else if (380 <= dlnx) id = 29; else if (356 <= dlnx) id = 28; else if (333 <= dlnx) id = 27; else if (310 <= dlnx) id = 26; else if (286 <= dlnx) id = 25; else if (261 <= dlnx) id = 24; else if (233 <= dlnx) id = 23; else if (202 <= dlnx) id = 22; else if (166 <= dlnx) id = 21; else if (123 <= dlnx) id = 20; else if (69 <= dlnx) id = 19; else id = 18; id = (ds == 1) ? ((~id) & 0x1f) : id; break; case 4: is = in >> 3; if (is == 0) im = in + 8; else if (is == 1) im = in & 7; else assert(0); if (4096 <= dlnx) assert(0); else if (4089 <= dlnx) id = 9; else if (2048 <= dlnx) id = 8; else if (405 <= dlnx) id = 15; else if (356 <= dlnx) id = 14; else if (310 <= dlnx) id = 13; else if (261 <= dlnx) id = 12; else if (202 <= dlnx) id = 11; else if (123 <= dlnx) id = 10; else id = 9; id = (ds == 1) ? ((~id) & 0xf) : id; break; case 3: is = in >> 2; if (is == 0) im = in + 4; else if (is == 1) im = in & 3; else assert(0); if (4096 <= dlnx) assert(0); else if (2048 <= dlnx) id = 4; else if (356 <= dlnx) id = 7; else if (261 <= dlnx) id = 6; else if (123 <= dlnx) id = 5; else id = 4; id = (ds == 1) ? ((~id) & 0x7) : id; break; case 2: is = in >> 1; if (is == 0) im = in + 2; else if (is == 1) im = in & 1; else assert(0); if (4096 <= dlnx) assert(0); else if (2048 <= dlnx) id = 2; else if (261 <= dlnx) id = 3; else id = 2; id = (ds == 1) ? ((~id) & 0x3) : id; break; default: assert(0); } if (id < im) { if (0xff < sp) assert(0); else if (0x80 < sp) sd = sp - 1; else if (sp == 0x80) sd = (law == 0) ? 1 : 0; else if (sp == 0x7f) sd = 0x7f; else sd = sp + 1; } else if (id > im) { if (0xff < sp) assert(0); else if (sp == 0xff) sd = sp; else if (0x7f < sp) sd = sp + 1; else if (0 < sp) sd = sp - 1; else sd = (law == 0) ? 0x81 : 0x80; } else sd = sp; return (law == 1) ? (0xd5 ^ sd) : (0xff ^ sd);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -