Clayton's patch for the legacy vocoder.

git-svn-id: http://op25.osmocom.org/svn/trunk@302 65a5c917-d112-43f1-993d-58c26a4786be
This commit is contained in:
stevie 2012-06-14 13:38:52 +00:00
parent da733ba270
commit 47eb8b0a01
2 changed files with 38 additions and 33 deletions

View File

@ -729,34 +729,11 @@ static const float PhzNz[57] = {
0.068775, 0.520336, 2.339119, -0.808328, 1.332154, 2.929768, -0.338316, 0.022767, -1.063795
};
static const float Ui[129] = {
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,
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,
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,
-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,
-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,
-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,
-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,
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,
918.058594
};
static const float Uq[129] = {
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,
-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,
-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,
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,
-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,
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,
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,
-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,
0.000000
};
software_imbe_decoder::software_imbe_decoder()
{
int i,j;
//initialize
OldL = 0;
Old = 1; New = 0;
psi1 = 0.0;
for(i=0; i < 58; i++) {
@ -772,6 +749,15 @@ software_imbe_decoder::software_imbe_decoder()
for(i=0; i < 256; i++) {
Olduw[i] = 0.0;
}
u[0] = 3147;
for(i=1; i < 211; i++) {
u[i] = next_u(u[i-1]);
}
}
uint32_t
software_imbe_decoder::next_u(uint32_t u) {
return (u * 171 + 11213) % 53125;
}
software_imbe_decoder::~software_imbe_decoder()
@ -931,7 +917,7 @@ software_imbe_decoder::decode_audio(uint8_t *A)
// if(abs((int)sample) > 32767) {
// sample = 32767 * (sample < 0) ? -1 : 1; // * sgn(sample)
// }
sample /= 16384.0; /* 32768.0 - but audio amplitude is not full range of int16 */
sample /= 32768.0;
samples->push_back(sample);
}
}
@ -1285,6 +1271,14 @@ software_imbe_decoder::synth_unvoiced()
int ell, bl, em, al, en;
// Generate the next 160 samples of white noise
for (en = 0; en < 51; en++) {
u[en] = u[en + 160];
}
for (; en < 211; en++) {
u[en] = next_u(u[en-1]);
}
ell = 0; bl =(int) ceilf(128 / M_PI *(ell + .5) * w0);
for(em = 0; em <= bl - 1; em++) {
Uwi[em] = 0; Uwq[em] = 0;
@ -1300,17 +1294,28 @@ software_imbe_decoder::synth_unvoiced()
}
} else {
Luv = Luv + 1;
for(em = al; em <= bl - 1; em++) {
Uwi[em] = 0;
Uwq[em] = 0;
for (en = 0; en < 211; en++) {
float exp = -0.0078125 * M_PI * em * (en - 105);
Uwi[em] = Uwi[em] + u[en] * ws[en] * cos(exp);
Uwq[em] = Uwq[em] + u[en] * ws[en] * sin(exp);
}
}
//precompute Tmp = <most of big hairy equation>
Tmp = 0;
// FOR en = al TO bl - 1
for(en = al; en <= bl - 1; en++) {
Tmp += powf(Ui[en], 2) + pow(Uq[en], 2);
Tmp += powf(Uwi[en], 2) + powf(Uwq[en], 2);
}
Tmp = M[ell][New] / sqrt(Tmp /(bl - al)); //too loud with 146.6433 factor
// 0.91652 is my best guess at what the unvoiced scaling
// coefficient is supposed to be
Tmp = 0.91652 * M[ell][New] / sqrt(Tmp /(bl - al));
//now do the rest of b.h.e.
for(em = al; em <= bl - 1; em++) {
Uwi[em] =(Ui[em]) * Tmp;
Uwq[em] =(Uq[em]) * Tmp;
Uwi[em] =(Uwi[em]) * Tmp;
Uwq[em] =(Uwq[em]) * Tmp;
}
}
}
@ -1370,7 +1375,7 @@ software_imbe_decoder::synth_voiced()
}
Tmp = Luv / L;
for(; ell <= MaxL; ell++) {
phi[ell][ New] = psi1 * ell + Tmp * PhzNz[ell];
phi[ell][ New] = psi1 * ell /* + Tmp * PhzNz[ell] */;
}
for(en = 0; en <= 159; en++) {
@ -1394,10 +1399,8 @@ software_imbe_decoder::synth_voiced()
if(vee[ell][ New]) {
if ( vee[ell][ Old]) {
if(ell < 8 && fabsf(w0 - Oldw0) < .1 * w0) { // (fine transition)
const double PI_SQUARED = M_PI * M_PI;
const double INV_PI_SQUARED = 1.0 / PI_SQUARED;
Dpl = phi[ell][ New] - phi[ell][ Old] -(Oldw0 + w0) * ell * 80;
Dwl = .00625 * (Dpl - PI_SQUARED * floorf((Dpl + M_PI) * INV_PI_SQUARED));
Dwl = .00625 * (Dpl - 2 * M_PI * floorf((Dpl + M_PI) / (2 * M_PI)));
THa = (Oldw0 * (float)ell + Dwl);
THb = (w0 - Oldw0) * ell * .003125;
Mb = .00625 *(MNew - MOld);

View File

@ -68,6 +68,7 @@ private:
float Olduw[256];
float psi1;
float phi[57][2];
uint32_t u[211];
int Old;
int New;
@ -84,6 +85,7 @@ private:
uint32_t pngen15(uint32_t& pn);
uint32_t pngen23(uint32_t& pn);
uint32_t next_t(uint32_t u);
void decode_audio(uint8_t *);
void decode_spectral_amplitudes(int, int );
void decode_vuv(int );