⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldcsub.c

📁 Reference Implementation of G.711 standard and other voice codecs
💻 C
📖 第 1 页 / 共 3 页
字号:
      stlpf[1] = stlpf[0];      stlpf[0] = tmp;    }    /* start correlation peak-picking in the decimated LPC residual domain. */    m1 = kpmin / 4;    m2 = kpmax / 4;    cormax = (double) -1e30;    i_1 = m2;    for (j = m1; j <= i_1; ++j)    {      tmp = 0.;      i_2 = npwsz / 4;      /* tmp = correlation in decimated domain */      for (n = 1; n <= i_2; ++n)      {	tmp += dec[n + 34] * dec[n - j + 34];      }      /* find maximum correlation and the corresponding lag. */      if (tmp > cormax)      {	cormax = tmp;	kmax = j;      }    }    /* shift decimated LPC residual buffer. */    i_1 = (npwsz - nfrsz) / 4;    for (n = -m2 + 1; n <= i_1; ++n)    {      dec[n + 34] = dec[n + 39];    }    /* start correlation peak-picking in undecimated domain */    m1 = (kmax << 2) - 3;    m2 = (kmax << 2) + 3;    /* check whether M1 out of range. */    if (m1 < kpmin)    {      m1 = kpmin;    }    /* check whether M2 out of range. */    if (m2 > kpmax)    {      m2 = kpmax;    }    /* correlation in undecimated domain. */    cormax = (double) -1e30;    i_1 = m2;    for (j = m1; j <= i_1; ++j)    {      tmp = (double) 0.;      i_2 = npwsz;      for (k = 1; k <= i_2; ++k)      {	tmp += d[k] * d[k - j + 139];      }      if (tmp > cormax)      {	/* find maximum correlation and */	cormax = tmp;	/* the corresponding lag. */	kp = j;      }    }    /* determine the range of search around */    m1 = kp1 - kpdlta;    /* the pitch period of previou frame. */    m2 = kp1 + kpdlta;    /* KP can't be a multiple pitch if true. */    if (kp < m2 + 1)    {      goto L115;    }    /* check whether M1 out of range. */    if (m1 < kpmin)    {      m1 = kpmin;    }    /* check whether M2 out of range. */    if (m2 > kpmax)    {      m2 = kpmax;    }    cmax = (double) -1e30;    i_1 = m2;    for (j = m1; j <= i_1; ++j)    {      tmp = (double) 0.;      i_2 = npwsz;      for (k = 1; k <= i_2; ++k)      {	/* correlation in undecimated domain. */	tmp += d[k + 139] * d[k - j + 139];      }      if (tmp > cmax)      {	/* find maximum correlation and the corresponding lag. */	cmax = tmp;	kptmp = j;      }    }    /* start computing the tap weights */    sum = tmp = (double) 0.;    i_1 = npwsz;    for (k = 1; k <= i_1; ++k)    {      sum += d[k - kp + 139] * d[k - kp + 139];      tmp += d[k - kptmp + 139] * d[k - kptmp + 139];    }    if (sum == 0.)    {      tap = 0.;    }    else    {      tap = cormax / sum;    }    if (tmp == 0.)    {      tap1 = 0.;    }    else    {      tap1 = cmax / tmp;    }    /* clamp TAP between 0 and 1 */    if (tap > 1.)    {      tap = 1.;    }    if (tap < 0.)    {      tap = 0.;    }    /* clamp TAP1 between 0 and 1 */    if (tap1 > 1.)    {      tap1 = 1.;    }    /* Replace KP with fundamental pitch if TAP1 is large enough. */    if (tap1 < 0.)    {      tap1 = 0.;    }    if (tap1 > tapth * tap)    {      kp = kptmp;    }L115:    /* update pitch period of previous frame */    kp1 = kp;    i_1 = npwsz - nfrsz;    /* shift the LPC residual buffer */    for (k = -kpmax + 1; k <= i_1; ++k)    {      d[k + 139] = d[k + nfrsz + 139];    }    /* Calculate the optimal tap weight of the single-tap pitch predictor of     * the decoded speech. */    sum = (double) 0.;    tmp = (double) 0.;    for (k = -npwsz + 1; k <= 0; ++k)    {      sum += sd[k - kp + 239] * sd[k - kp + 239];      tmp += sd[k + 239] * sd[k - kp + 239];    }    if (sum == 0.)    {      ptap = 0.;    }    else    {      /* Calculate the coefficient $b$ and the scaling factor $g sub l$ of       * the long-term postfilter. */      ptap = tmp / sum;    }    /* clamp PTAP at 1. */    if (ptap > 1.)    {      ptap = (double) 1.;    }    /* turn off pitch postfilter if PTAP smaller than threshold. */    if (ptap < ppfth)    {      ptap = (double) 0.;    }    b = ppfzcf * ptap;    gl = 1 / (b + 1);  }  /* Calculate the coefficients of the short-term postfilter. */  if (icount == 1)  {    for (i = 2; i <= 11; ++i)    {      /* scale denominator coeff. */      ap[i - 1] = sppcfv[i - 2] * apf[i - 1];      /* scale numerator coeff. */      az[i - 1] = spzcfv[i - 2] * apf[i - 1];    }    /* tilt compensation filter coeff. */    tiltz = tiltf * rc[0];  }  /* Perform filtering operation of the long-term postfilter. */  i_1 = idim;  for (k = 1; k <= i_1; ++k)  {    /* long-term postfiltering. */    temp[k - 1] = gl * (sd[k + 239] + b * sd[k - kp + 239]);  }  /* shift decoded speech buffer. */  for (k = -npwsz - kpmax + 1; k <= 0; ++k)  {    sd[k + 239] = sd[k + idim + 239];  }  /* Perform filtering operation of the short-term postfilter. */  i_1 = idim;  for (k = 1; k <= i_1; ++k)  {    tmp = temp[k - 1];    for (j = 10; j >= 2; --j)    {      /* All-zero part of the filter. */      temp[k - 1] += stpfir[j - 1] * az[j];      stpfir[j - 1] = stpfir[j - 2];    }    /* Last multiplier. */    temp[k - 1] += stpfir[0] * az[1];    stpfir[0] = tmp;    /* All-pole part of the filter. */    for (j = 10; j >= 2; --j)    {      temp[k - 1] -= stpiir[j - 1] * ap[j];      stpiir[j - 1] = stpiir[j - 2];    }    /* Last multiplier. */    temp[k - 1] -= stpiir[0] * ap[1];    /* Spectral tilt compensation filter. */    stpiir[0] = temp[k - 1];    temp[k - 1] += stpiir[1] * tiltz;  }  /* Calculate the sum of absolute values of the components of the */  /* decoded speech vector. */  sunfil = (double) 0.;  i_1 = idim;  for (k = 1; k <= i_1; ++k)  {    sunfil + = fabs(sd[k + 239]);  }  /* Calculate the sum of absolute values of the components of the */  /* short-term postfilter output vector. */  sumfil = (double) 0.;  i_1 = idim;  for (k = 1; k <= i_1; ++k)  {    sumfil += fabs(temp[k - 1]);  }  /* Calculate the overall scaling factor of the postfilter */  /* Lowpass filter the once-a-vector scaling factor and use the filtered */  /* scaling factor to scale the short-term postfilter output vector. */  scale = (double) 1.;  if (sumfil > 1.)  {    scale = sunfil / sumfil;  }  i_1 = idim;  for (k = 1; k <= i_1; ++k)  {    /* lowpass filtering */    scalfl = agcfac * scalfl + (1 - agcfac) * scale;    /* scale output. */    spf[k - 1] = scalfl * temp[k - 1];  }  /* Postprocessing */  /* ...transfer output vector */  for (k = 1; k <= 5; ++k)  {    sy[k - 1] = spf[k - 1];  }}/* ......................... End of pstflt() ......................... */int             durbin_(r, n, a, rc, ifail)  double         *r;  long           *n;  double         *a, *rc;  long           *ifail;{  /* System generated locals */  long            i_1, i_2;  /* Local variables */  static double   abuf[100];  static long     minc, i;  static double   alpha;  static long     n1, ib, mh;  static double   at;  static long     ip;  static double   sum;  *ifail = 0;  i_1 = *n + 1;  for (i = 0; i < i_1; ++i)  {    abuf[i] = a[i];  }  if (r[0] <= 0.)  {    *ifail = 1;    goto L99;  }  rc[0] = -(r[1] / r[0]);  a[0] = (double) 1.;  a[1] = rc[0];  alpha = r[0] + r[1] * rc[0];  if (alpha <= 0.)  {    *ifail = 2;    goto L99;  }  i_1 = *n;  for (minc = 2; minc <= i_1; ++minc)  {    sum = (double) 0.;    i_2 = minc;    for (ip = 1; ip <= i_2; ++ip)    {      n1 = minc - ip + 2;      sum += r[n1 - 1] * a[ip - 1];    }    rc[minc - 1] = -(sum / alpha);    mh = minc / 2 + 1;    i_2 = mh;    for (ip = 2; ip <= i_2; ++ip)    {      ib = minc - ip + 2;      at = a[ip - 1] + rc[minc - 1] * a[ib - 1];      a[ib - 1] += rc[minc - 1] * a[ip - 1];      a[ip - 1] = at;    }    a[minc] = rc[minc - 1];    alpha += rc[minc - 1] * sum;    if (alpha <= 0.)    {      *ifail = 2;      goto L99;    }  }  return 0;L99:  /* Keep wheighting filter coefficients in case of ill-conditioning */  i_1 = *n + 1;  for (i = 0; i < i_1; ++i)  {    a[i] = abuf[i];  }  return (*ifail);  /* Version: 03.10.91 / Ftj */}/* ........................ End of durbin() ............................. */void            hybws_(ws)  double         *ws;{  /* Initialized data */  static long     iws[105] = {1565, 3127, 4681, 6225, 7755, 9266, 10757, 12223,    13661, 15068, 16441, 17776, 19071, 20322, 21526, 22682, 23786, 24835, 25828,    26761, 27634, 28444, 29188, 29866, 30476, 31016, 31486, 31884, 32208, 32460,    32637, 32739, 32767, 32721, 32599, 32403, 32171, 31940, 31711, 31484, 31259,    31034, 30812, 30591, 30372, 30154, 29938, 29724, 29511, 29299, 29089, 28881,    28674, 28468, 28264, 28062, 27861, 27661, 27463, 27266, 27071, 26877, 26684,    26493, 26303, 26114, 25927, 25742, 25557, 25374, 25192, 25012, 24832, 24654,    24478, 24302, 24128, 23955, 23784, 23613, 23444, 23276, 23109, 22943, 22779,    22616, 22454, 22293, 22133, 21974, 21817, 21661, 21505, 21351, 21198, 21046,  20896, 20746, 20597, 20450, 20303, 20157, 20013, 19870, 19727};  /* System generated locals */  long            i_1, i_2;  /* Builtin functions */  long            s_rnge();  /* Local variables */  static long     i;  for (i = 0; i < 105; ++i)  {    ws[i] = iws[i] / (double) 32768.;  }  /* Version: 03.10.91 / Ftj */}/* ............................ End of hybws() .......................... */void            hybwg_(wg)  double         *wg;{  /* Version: 03.10.91 / Ftj */  /* Initialized data */  static long     iwg[34] = {3026, 6025, 8973, 11845, 14615, 17261, 19759, 22088,    24228, 26162, 27872, 29344, 30565, 31525, 32216, 32631, 32767, 32625, 32203,    31506, 30540, 29461, 28420, 27416, 26448, 25514, 24613, 23743, 22905, 22096,  21315, 20562, 19836, 19135};  /* Local variables */  static long     i;  for (i = 0; i < 34; ++i)    wg[i] = (double) iwg[i] / (double) 32768.;}/* .......................... End of hybwg() .............................. */void            hybwp_(wp)  double         *wp;{  /* Version: 03.10.91 / Ftj */  /* Initialized data */  static short    iwp[60] = {1957, 3908, 5845, 7760, 9648, 11502, 13314, 15079,    16790, 18441, 20026, 21540, 22976, 24331, 25599, 26775, 27856, 28837, 29715,    30487, 31150, 31702, 32141, 32464, 32672, 32763, 32738, 32595, 32336, 31961,    31472, 30931, 30400, 29878, 29365, 28860, 28364, 27877, 27398, 26927, 26465,    26010, 25563, 25124, 24693, 24268, 23851, 23442, 23039, 22643, 22254, 21872,  21496, 21127, 20764, 20407, 20057, 19712, 19373, 19041};  /* Local variables */  static int      i;  for (i = 0; i < 60; ++i)    wp[i] = (double) iwp[i] / (double) 32768.;}/* .......................... End of hybwp() ............................... */void            cbook_(y)  double         *y;{  /* Initialized data */  static short    iy[640] = {668, -2950, -1254, -1790, -2553, -5032, -4577, -1045,    2908, 3318, -2819, -2677, -948, -2825, -4450, -6679, -340, 1482, -1276, 1262,    -562, -6757, 1281, 179, -1274, -2512, -7130, -4925, 6913, 2411, -2478, -156,    4683, -3873, 0, -8208, 2140, -478, -2785, 533, 1889, 2759, 1381, -6955, -5913,    5082, -2460, -5778, 1797, 568, -2208, -3309, -4523, -6236, -7505, -2719,    4358, -2988, -1149, 2664, 1259, 995, 2711, -2464, -10390, 1722, -7569, -2742,    2171, -2329, 1032, 747, -858, -7946, -12843, 3106, 4856, -4193, -2541, 1035,    1862, -960, -6628, 410, 5882, -2493, -2628, -4000, -60, 7202, -2672, 1446,    1536, -3831, 1233, -5302, 6912, 1589, -4187, 3665, -3456, -8170, -7709, 1384,    4698, -4699, -6209, -11176, 8104, 16830, 930, 7004, 1269, -8977, 2567, 4649,    11804, 3441, -5657, 1199, 2542, -183, -8859, -7976, 3230, -2872, -2011,    -9713, -8385, 12983, 3086, 2140, -3680, -9643, -2896, -7609, 6515, -2283,    -2522, 6332, -3333, -5620, -9130, -11131, 5543, -407, -6721, -17466, -2889,    11568, 3692, 6796, -262, -10846, -1856, 7275, 13404, -2989, -10595, 4936,    244, -2219, 2656, 3776, -5412, -4043, -5934, 2131, 863, -2866, -3302, 1743,    -2006, -128, -2052, -6361, 3342, -1583, -21, 1142, -3837, -1831, 6397, 2545,    -2848, -9332, -6528, 5309, 1986, -2245, -4490, 748, 1935, -3027, -493, -9255,    5366, 3193, -4493, 1784, 4784, -370, 1866, 1057, -1889, 7342, -2690, -2577,    676, -611, -502, 2235, -1850, -1777, -2049, 1011, 3880, -2465, 2209, -152,    2592, 2829, 5588, 2839, -7306, -3049, -4918, 5955, 9201, -4447, 697, 3908,    5798, -4451, -4644, -2121, 5444, -2570, 321, -1202, 2846, -2086, 3532, 566,    -708, -4279, 950, 4980, 3749, 452, -2484, 3502, 1719, -170, 238, -3435, 263,    2114, -2005, 2361, -7338, -1208, 9347, -1216, -4013, -13498, -439, 8028,    -4232, 361, -3729, 5433, 2004, -4727, -1259, -3986, 7743, 8429, -3691, -987,    5198, -423, 1150, -1281, 816, 7409, 4109, -3949, 2690, 30, 1246, 3055, -35,    -1370, -246, -1489, 5635, -678, -2627, 3170, 4830, -4585, 2008, -1062, 799,    -129, 717, 4594, 14937, 10706, 417, 2759, 1850, -5057, -1153, -3887, 7361,    -5768, 4285, 666, 1443, -938, 20, -2119, -1697, -3712, -3402, -2212, 110,    2136, -2952, 12, -1568, -3500, -1855, -1315, -1731, 1160, -558, 1709, 88,    -4569, 194, -454, -2957, -2839, -1666, -273, 2084, -155, -189, -2376, 1663,    -1040, -2449, -2842, -1369, 636, -248, -2677, 1517, 79, -3013, -3669, -973,    1913, -2493, -5312, -749, 1271, -2903, -3324, -3756, -3690, -1829, -2913,    -1547, -2760, -1406, 1124, 1844, -1834, 456, 706, -4272, 467, -4256, -1909,    1521, 1134, -127, -994, -637, -1491, -6494, 873, -2045, -3828, -2792, -578,    2311, -1817, 2632, -3052, 1968, 641, 1194, 1893, 4107, 6342, -45, 1198, 2160,    -1449, 2203, -2004, 1713, 3518, 2652, 4251, 2936, -3968, 1280, 131, -1476,    2827, 8, -1928, 2658, 3513, 3199, -816, 2687, -1741, -1407, 2948, 4029, 394,    -253, 1298, 4286, 51, -4507, -32, -659, 3903, 5646, -5588, -2592, 5707, -606,    1234, -1607, -5187, 664, -525, 3620, -2192, -2527, 1707, 4297, -3251, -2283,    812, -2264, 5765, 528, -3287, 1352, 1672, 2735, 1241, -1103, -3273, -3407,    4033, 1648, -2965, -1174, 1444, 74, 918, 1999, 915, -1026, -2496, -1605, 2034,    2950, 229, -2168, 2037, 15, -1264, -208, -3552, 1530, 581, 1491, 962, -2613,    -2338, 3621, -1488, -2185, -1747, 81, 5538, 1432, -2257, -1019, 867, 214,    -2284, -1510, -1684, 2816, -229, 2551, -1389, 2707, 504, 479, 2783, -1009,    2517, -1487, -1596, 621, 1929, -148, 2206, -4288, 1292, -1401, -527, 1243,    -2731, 1909, 1280, 2149, -1501, 3688, 610, -4591, 3306, -3369, 1875, 3636,    -1217, 2574, 2513, 1449, -3074, -4979, 814, 1826, -2497, 4234, -4077, 1664,    -220, 3418, 1002, 1115, 781, 1658, 3919, 6130, 3140, 1148, 4065, 1516, 815,    199, 1191, 2489, 2561, 2421, 2443, 770, -5915, 5515, -368, -3199, 1190, 1047,    3742, 6927, -2089, 292, 3099, 4308, -758, -2455, 523, 3921, 4044, 1386, 85,    4367, 1006, -1252, -1466, -1383, 3852, 1579, -77, 2064, 868, 5109, 2919, -202,    359, -509, 3650, 3206, 2303, 1693, 1296, 2905, -3907, 229, -1196, -2332, 5977,    -3585, 805, 3825, -3138, 3746, -606, 53, -269, -3301, 606, 2018, -1316, 4064,  398};  /* Local variables */  int             i;  for (i = 0; i < 640; ++i)    y[i] = (double) iy[i] / (double) 2048.;}/* ........................... End of cbook() ........................... */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -