Advertisement
Guest User

IMBE vocoder fixes for op25

a guest
Jun 12th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.53 KB | None | 0 0
  1. Index: blocks/src/lib/software_imbe_decoder.cc
  2. ===================================================================
  3. --- blocks/src/lib/software_imbe_decoder.cc (revision 301)
  4. +++ blocks/src/lib/software_imbe_decoder.cc (working copy)
  5. @@ -729,34 +729,11 @@
  6.     0.068775, 0.520336, 2.339119, -0.808328, 1.332154, 2.929768, -0.338316, 0.022767, -1.063795
  7.  };
  8.  
  9. -static const float Ui[129] = {
  10. -   460.246094, 90.698601, -140.362900, 3.415093, 99.369812, 445.443207, 522.042786, 252.818405, 125.521202, -119.443199, -342.607910, -393.066895, -494.564301, -284.859009, 351.480896, 660.536377,
  11. -   149.394104, -654.466980, -845.040527, -496.079102, -155.383499, 313.371399, 370.925110, -207.061905, -49.371632, 355.883392, -295.865509, -950.418823, -646.136597, 154.876801, 475.990295, 251.149902,
  12. -   275.690796, 176.195206, 39.321491, 323.984711, 3.765467, -740.295471, -684.010681, 22.967060, 532.828186, 327.829803, -17.576559, 36.373402, -144.939194, -400.725189, 59.048889, 408.261597,
  13. -   -3.164414, -207.470093, -76.218567, -8.249402, 56.827209, -221.976196, -346.998199, -139.244995, -582.422485, -1028.400024, -727.781982, -406.098907, -191.811295, 41.401581, -151.480103, -641.985779,
  14. -   -607.550781, -400.055786, -678.727417, -376.449890, 434.718109, 239.750504, -470.508392, -552.972717, -148.247299, 153.369507, 113.672798, 29.017599, 31.270840, -13.290440, -250.178604, -504.166809,
  15. -   -8.738471, 669.869019, 43.365711, -669.164429, -29.603149, 114.396599, -495.633301, -105.838203, 90.404091, -299.971100, 154.039200, 380.408691, 111.480400, 158.179993, -205.268204, -386.008087,
  16. -   -62.792370, -327.508087, -488.555298, 15.982190, 264.942902, 171.169998, 112.966904, -209.006302, -364.411591, 367.667999, 417.925293, -867.776184, -1286.915039, -779.282288, -557.706482, -184.866501,
  17. -   189.383804, 140.763107, 143.058304, 522.142395, 586.625122, -52.709290, 46.055168, 955.700806, 807.637085, -213.939499, -450.946411, 209.997101, 114.041298, -608.001221, -67.676140, 800.976929,
  18. -   918.058594
  19. -};
  20. -
  21. -static const float Uq[129] = {
  22. -   0.000000, 15.557470, -141.517395, 4.850000, 20.818390, -31.850750, 240.388107, 359.115509, 353.314514, -34.321480, -683.943787, -426.828705, 251.196106, 648.932800, 583.257080, -272.161804,
  23. -   -696.480774, -616.009888, -730.197388, -275.599213, -71.369781, -246.298599, 353.591187, 383.542999, -457.883911, -573.009827, 123.842796, 808.834473, 590.295227, -116.924400, 4.462234, 300.142792,
  24. -   -398.965790, -1374.654053, -1271.543945, -306.073090, 175.326508, 330.696106, 640.043701, 308.004608, -163.072403, 10.378300, -113.961601, -623.374390, -714.512207, -384.877991, 71.181877, 261.299896,
  25. -   129.764801, -8.331214, -68.725418, 88.997963, 276.388611, -133.622498, -673.724915, -355.871704, -137.479996, -829.466675, -936.803223, -471.582794, -615.728271, -670.887085, -713.287109, -1046.473022,
  26. -   -679.554688, -198.067902, -328.069305, -487.968994, -368.145203, 482.697296, 1213.579956, 528.013977, -148.013107, 88.007896, 349.561005, 483.642792, -11.267410, -765.563721, -95.221008, 1021.109985,
  27. -   810.747620, 291.417908, 516.477783, 771.458984, 430.919586, -105.049500, -259.056702, -412.976807, -776.695312, -506.850098, -208.051407, -624.956421, -280.915710, 302.574402, -349.600403, -520.683228,
  28. -   278.127899, 446.518799, 21.136551, -178.466400, 262.635498, 683.496704, 448.290802, 360.132202, 334.482605, -306.716003, -777.159912, -433.828796, 88.513657, 278.588989, 94.746696, -541.088989,
  29. -   -645.232483, 321.504211, 801.454773, 511.169189, 164.987106, -538.676819, -971.696228, -735.475586, -533.916626, -355.275909, -234.147903, -468.023285, -691.458313, -533.001770, -291.729004, -199.716904,
  30. -   0.000000
  31. -};
  32. -
  33.  software_imbe_decoder::software_imbe_decoder()
  34.  {
  35.     int i,j;
  36.     //initialize
  37. +   OldL = 0;
  38.     Old = 1; New = 0;
  39.     psi1 = 0.0;
  40.     for(i=0; i < 58; i++) {
  41. @@ -772,8 +749,17 @@
  42.     for(i=0; i < 256; i++) {
  43.        Olduw[i] = 0.0;
  44.     }
  45. +   u[0] = 3147;
  46. +   for(i=1; i < 211; i++) {
  47. +      u[i] = next_u(u[i-1]);
  48. +   }
  49.  }
  50.  
  51. +uint32_t
  52. +software_imbe_decoder::next_u(uint32_t u) {
  53. +   return (u * 171 + 11213) % 53125;
  54. +}
  55. +
  56.  software_imbe_decoder::~software_imbe_decoder()
  57.  {
  58.  }
  59. @@ -931,7 +917,7 @@
  60.  //         if(abs((int)sample) > 32767) {
  61.  //            sample = 32767 * (sample < 0) ? -1 : 1; // * sgn(sample)
  62.  //         }
  63. -         sample /= 16384.0; /* 32768.0 - but audio amplitude is not full range of int16  */
  64. +         sample /= 32768.0;
  65.           samples->push_back(sample);
  66.        }
  67.     }
  68. @@ -1285,6 +1271,14 @@
  69.  
  70.     int ell, bl, em, al, en;
  71.  
  72. +   // Generate the next 160 samples of white noise
  73. +   for (en = 0; en < 51; en++) {
  74. +      u[en] = u[en + 160];
  75. +   }
  76. +   for (; en < 211; en++) {
  77. +      u[en] = next_u(u[en-1]);
  78. +   }
  79. +
  80.     ell = 0; bl =(int) ceilf(128 / M_PI *(ell + .5) * w0);
  81.     for(em = 0; em <= bl - 1; em++) {
  82.        Uwi[em] = 0; Uwq[em] = 0;
  83. @@ -1300,17 +1294,28 @@
  84.           }
  85.        } else {
  86.           Luv = Luv + 1;
  87. +         for(em = al; em <= bl - 1; em++) {
  88. +            Uwi[em] = 0;
  89. +            Uwq[em] = 0;
  90. +            for (en = 0; en < 211; en++) {
  91. +               float exp = -0.0078125 * M_PI * em * (en - 105);
  92. +               Uwi[em] = Uwi[em] + u[en] * ws[en] * cos(exp);
  93. +               Uwq[em] = Uwq[em] + u[en] * ws[en] * sin(exp);
  94. +            }
  95. +         }
  96.           //precompute Tmp = <most of big hairy equation>
  97.           Tmp = 0;
  98.           // FOR en = al TO bl - 1
  99.           for(en = al; en <= bl - 1; en++) {
  100. -            Tmp += powf(Ui[en], 2) + pow(Uq[en], 2);
  101. +            Tmp += powf(Uwi[en], 2) + powf(Uwq[en], 2);
  102.           }
  103. -         Tmp = M[ell][New] / sqrt(Tmp /(bl - al)); //too loud with 146.6433 factor
  104. +         // 0.91652 is my best guess at what the unvoiced scaling
  105. +         // coefficient is supposed to be
  106. +         Tmp = 0.91652 * M[ell][New] / sqrt(Tmp /(bl - al));
  107.           //now do the rest of b.h.e.
  108.           for(em = al; em <= bl - 1; em++) {
  109. -            Uwi[em] =(Ui[em]) * Tmp;
  110. -            Uwq[em] =(Uq[em]) * Tmp;
  111. +            Uwi[em] =(Uwi[em]) * Tmp;
  112. +            Uwq[em] =(Uwq[em]) * Tmp;
  113.           }
  114.        }
  115.     }
  116. @@ -1370,7 +1375,7 @@
  117.     }
  118.     Tmp = Luv / L;
  119.     for(; ell <= MaxL; ell++) {
  120. -      phi[ell][ New] = psi1 * ell + Tmp * PhzNz[ell];
  121. +      phi[ell][ New] = psi1 * ell /* + Tmp * PhzNz[ell] */;
  122.     }
  123.  
  124.     for(en = 0; en <= 159; en++) {
  125. @@ -1394,10 +1399,8 @@
  126.        if(vee[ell][ New]) {
  127.           if ( vee[ell][ Old]) {
  128.              if(ell < 8 && fabsf(w0 - Oldw0) < .1 * w0) { // (fine transition)
  129. -               const double PI_SQUARED = M_PI * M_PI;
  130. -               const double INV_PI_SQUARED = 1.0 / PI_SQUARED;
  131.                 Dpl = phi[ell][ New] - phi[ell][ Old] -(Oldw0 + w0) * ell * 80;
  132. -               Dwl = .00625 * (Dpl - PI_SQUARED * floorf((Dpl + M_PI) * INV_PI_SQUARED));
  133. +               Dwl = .00625 * (Dpl - 2 * M_PI * floorf((Dpl + M_PI) / (2 * M_PI)));
  134.                 THa = (Oldw0 * (float)ell + Dwl);
  135.                 THb = (w0 - Oldw0) * ell * .003125;
  136.                 Mb = .00625 *(MNew - MOld);
  137. Index: blocks/src/lib/software_imbe_decoder.h
  138. ===================================================================
  139. --- blocks/src/lib/software_imbe_decoder.h  (revision 301)
  140. +++ blocks/src/lib/software_imbe_decoder.h  (working copy)
  141. @@ -68,6 +68,7 @@
  142.     float Olduw[256];
  143.     float psi1;
  144.     float phi[57][2];
  145. +   uint32_t u[211];   
  146.  
  147.     int Old;
  148.     int New;
  149. @@ -84,6 +85,7 @@
  150.  
  151.     uint32_t pngen15(uint32_t& pn);
  152.     uint32_t pngen23(uint32_t& pn);
  153. +   uint32_t next_u(uint32_t u);
  154.     void decode_audio(uint8_t *);
  155.     void decode_spectral_amplitudes(int, int );
  156.     void decode_vuv(int );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement