void mbe_synthesizeSpeechf (float *aout_buf, mbe_parms * cur_mp, mbe_parms * prev_mp, int uvquality) { int i, l, n, maxl; float *Ss, loguvquality; float C1, C2, C3, C4; //float deltaphil, deltawl, thetaln, aln; int numUv; float cw0, pw0, cw0l, pw0l; float uvsine, uvrand, uvthreshold, uvthresholdf; float uvstep, uvoffset; float qfactor; float rphase[64], rphase2[64]; const int N = 160; uvthresholdf = (float) 2700; uvthreshold = ((uvthresholdf * M_PI) / (float) 4000); // voiced/unvoiced/gain settings uvsine = (float) 1.3591409 *M_E; uvrand = (float) 2.0; if ((uvquality < 1) || (uvquality > 64)) { printf ("\nmbelib: Error - uvquality must be within the range 1 - 64, setting to default value of 3\n"); uvquality = 3; } // calculate loguvquality if (uvquality == 1) { loguvquality = (float) 1 / M_E; } else { loguvquality = log ((float) uvquality) / (float) uvquality; } // calculate unvoiced step and offset values uvstep = (float) 1.0 / (float) uvquality; qfactor = loguvquality; uvoffset = (uvstep * (float) (uvquality - 1)) / (float) 2; // count number of unvoiced bands numUv = 0; for (l = 1; l <= cur_mp->L; l++) { if (cur_mp->Vl[l] == 0) { numUv++; } } cw0 = cur_mp->w0; pw0 = prev_mp->w0; // init aout_buf Ss = aout_buf; for (n = 0; n < N; n++) { *Ss = (float) 0; Ss++; } // eq 128 and 129 if (cur_mp->L > prev_mp->L) { maxl = cur_mp->L; for (l = prev_mp->L + 1; l <= maxl; l++) { prev_mp->Ml[l] = (float) 0; prev_mp->Vl[l] = 1; } } else { maxl = prev_mp->L; for (l = cur_mp->L + 1; l <= maxl; l++) { cur_mp->Ml[l] = (float) 0; cur_mp->Vl[l] = 1; } } // update phil from eq 139,140 for (l = 1; l <= 56; l++) { cur_mp->PSIl[l] = prev_mp->PSIl[l] + ((pw0 + cw0) * ((float) (l * N) / (float) 2)); if (l <= (int) (cur_mp->L / 4)) { cur_mp->PHIl[l] = cur_mp->PSIl[l]; } else { cur_mp->PHIl[l] = cur_mp->PSIl[l] + ((numUv * mbe_rand_phase()) / cur_mp->L); } } for (l = 1; l <= maxl; l++) { cw0l = (cw0 * (float) l); pw0l = (pw0 * (float) l); if ((cur_mp->Vl[l] == 0) && (prev_mp->Vl[l] == 1)) { Ss = aout_buf; // init random phase for (i = 0; i < uvquality; i++) { rphase[i] = mbe_rand_phase(); } for (n = 0; n < N; n++) { C1 = 0; // eq 131 C1 = Ws[n + N] * prev_mp->Ml[l] * cosf ((pw0l * (float) n) + prev_mp->PHIl[l]); C3 = 0; // unvoiced multisine mix for (i = 0; i < uvquality; i++) { C3 = C3 + cosf ((cw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) + rphase[i]); if (cw0l > uvthreshold) { C3 = C3 + ((cw0l - uvthreshold) * uvrand * mbe_rand()); } } C3 = C3 * uvsine * Ws[n] * cur_mp->Ml[l] * qfactor; *Ss = *Ss + C1 + C3; Ss++; } } else if ((cur_mp->Vl[l] == 1) && (prev_mp->Vl[l] == 0)) { Ss = aout_buf; // init random phase for (i = 0; i < uvquality; i++) { rphase[i] = mbe_rand_phase(); } for (n = 0; n < N; n++) { C1 = 0; // eq 132 C1 = Ws[n] * cur_mp->Ml[l] * cosf ((cw0l * (float) (n - N)) + cur_mp->PHIl[l]); C3 = 0; // unvoiced multisine mix for (i = 0; i < uvquality; i++) { C3 = C3 + cosf ((pw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) + rphase[i]); if (pw0l > uvthreshold) { C3 = C3 + ((pw0l - uvthreshold) * uvrand * mbe_rand()); } } C3 = C3 * uvsine * Ws[n + N] * prev_mp->Ml[l] * qfactor; *Ss = *Ss + C1 + C3; Ss++; } } // else if (((cur_mp->Vl[l] == 1) || (prev_mp->Vl[l] == 1)) && ((l >= 8) || (fabsf (cw0 - pw0) >= ((float) 0.1 * cw0)))) else if ((cur_mp->Vl[l] == 1) || (prev_mp->Vl[l] == 1)) { Ss = aout_buf; for (n = 0; n < N; n++) { C1 = 0; // eq 133-1 C1 = Ws[n + N] * prev_mp->Ml[l] * cosf ((pw0l * (float) n) + prev_mp->PHIl[l]); C2 = 0; // eq 133-2 C2 = Ws[n] * cur_mp->Ml[l] * cosf ((cw0l * (float) (n - N)) + cur_mp->PHIl[l]); *Ss = *Ss + C1 + C2; Ss++; } } /* // expensive and unnecessary? else if ((cur_mp->Vl[l] == 1) || (prev_mp->Vl[l] == 1)) { Ss = aout_buf; // eq 137 deltaphil = cur_mp->PHIl[l] - prev_mp->PHIl[l] - (((pw0 + cw0) * (float) (l * N)) / (float) 2); // eq 138 deltawl = ((float) 1 / (float) N) * (deltaphil - ((float) 2 * M_PI * (int) ((deltaphil + M_PI) / (M_PI * (float) 2)))); for (n = 0; n < N; n++) { // eq 136 thetaln = prev_mp->PHIl[l] + ((pw0l + deltawl) * (float) n) + (((cw0 - pw0) * ((float) (l * n * n)) / (float) (2 * N))); // eq 135 aln = prev_mp->Ml[l] + (((float) n / (float) N) * (cur_mp->Ml[l] - prev_mp->Ml[l])); // eq 134 *Ss = *Ss + (aln * cosf (thetaln)); Ss++; } } */ else { Ss = aout_buf; // init random phase for (i = 0; i < uvquality; i++) { rphase[i] = mbe_rand_phase(); } // init random phase for (i = 0; i < uvquality; i++) { rphase2[i] = mbe_rand_phase(); } for (n = 0; n < N; n++) { C3 = 0; // unvoiced multisine mix for (i = 0; i < uvquality; i++) { C3 = C3 + cosf ((pw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) + rphase[i]); if (pw0l > uvthreshold) { C3 = C3 + ((pw0l - uvthreshold) * uvrand * mbe_rand()); } } C3 = C3 * uvsine * Ws[n + N] * prev_mp->Ml[l] * qfactor; C4 = 0; // unvoiced multisine mix for (i = 0; i < uvquality; i++) { C4 = C4 + cosf ((cw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) + rphase2[i]); if (cw0l > uvthreshold) { C4 = C4 + ((cw0l - uvthreshold) * uvrand * mbe_rand()); } } C4 = C4 * uvsine * Ws[n] * cur_mp->Ml[l] * qfactor; *Ss = *Ss + C3 + C4; Ss++; } } } }
void mbe_synthesizeSpeechf (float *aout_buf, mbe_parms * cur_mp, mbe_parms * prev_mp, int uvquality) { int i, l, n, maxl; float *Ss, loguvquality; float C1, C2, C3, C4; float deltaphil, deltawl, thetaln, aln; int numUv; float cw0, pw0, cw0l, pw0l; float uvsine, uvthreshold, uvthresholdf; float uvstep, uvoffset; float qfactor; float rphase[64], rphase2[64]; const int N = 160; uvthresholdf = 2700.0f; uvthreshold = (uvthresholdf / 4000.0f); // voiced/unvoiced/gain settings uvsine = 1.3591409f *M_E; if ((uvquality < 1) || (uvquality > 64)) { #ifdef MBE_DEBUG printf ("\nmbelib: Error - uvquality must be within the range 1 - 64\n"); #endif uvquality = 3; } // calculate loguvquality if (uvquality == 1) { loguvquality = (float) 1 / M_E; } else { loguvquality = AmbeLog2f[uvquality] / ((float) uvquality * (float)M_LOG2E); } // calculate unvoiced step and offset values uvstep = 1.0f / (float) uvquality; qfactor = loguvquality; uvoffset = (uvstep * (float) (uvquality - 1)) * 0.5f; // count number of unvoiced bands numUv = 0; for (l = 1; l <= cur_mp->L; l++) { if (cur_mp->Vl[l] == 0) { numUv++; } } cw0 = cur_mp->w0; pw0 = prev_mp->w0; // init aout_buf Ss = aout_buf; for (n = 0; n < N; n++) { *Ss = 0.0f; Ss++; } // eq 128 and 129 if (cur_mp->L > prev_mp->L) { maxl = cur_mp->L; for (l = prev_mp->L + 1; l <= maxl; l++) { prev_mp->Ml[l] = 0.0f; prev_mp->Vl[l] = 1; } } else { maxl = prev_mp->L; for (l = cur_mp->L + 1; l <= maxl; l++) { cur_mp->Ml[l] = 0.0f; cur_mp->Vl[l] = 1; } } // update phil from eq 139,140 for (l = 1; l <= 56; l++) { cur_mp->PSIl[l] = prev_mp->PSIl[l] + ((float)M_PI * (pw0 + cw0) * ((float) (l * N) * 0.5f)); if (l <= (int) (cur_mp->L / 4)) { cur_mp->PHIl[l] = cur_mp->PSIl[l]; } else { cur_mp->PHIl[l] = cur_mp->PSIl[l] + ((numUv * mbe_rand_phase()) / cur_mp->L); } } for (l = 1; l <= maxl; l++) { cw0l = (cw0 * (float) l); pw0l = (pw0 * (float) l); if ((cur_mp->Vl[l] == 0) && (prev_mp->Vl[l] == 1)) { Ss = aout_buf; // init random phase for (i = 0; i < uvquality; i++) { rphase[i] = mbe_rand_phase(); } for (n = 0; n < N; n++) { C1 = 0; // eq 131 C1 = Ws[n + N] * prev_mp->Ml[l] * mbe_cosf (((float)M_PI * pw0l * (float) n) + prev_mp->PHIl[l]); C3 = 0; // unvoiced multisine mix for (i = 0; i < uvquality; i++) { // float tmp; // tmp = (mbe_cosf((float)M_PI * cw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) * // mbe_cosf(rphase[i])) + // (mbe_cosf((float)M_PI * (0.5f - (cw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset))) * // mbe_sinf(rphase[i])); C3 = C3 + mbe_cosf (((float)M_PI * cw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) + rphase[i]); if (cw0l > uvthreshold) { C3 = C3 + ((float)M_PI * (cw0l - uvthreshold) * 2.0f * mbe_rand()); } } C3 = C3 * uvsine * Ws[n] * cur_mp->Ml[l] * qfactor; *Ss += C1 + C3; Ss++; } } else if ((cur_mp->Vl[l] == 1) && (prev_mp->Vl[l] == 0)) { Ss = aout_buf; // init random phase for (i = 0; i < uvquality; i++) { rphase[i] = mbe_rand_phase(); } for (n = 0; n < N; n++) { C1 = 0; // eq 132 C1 = Ws[n] * cur_mp->Ml[l] * mbe_cosf (((float)M_PI * cw0l * (float) (n - N)) + cur_mp->PHIl[l]); C3 = 0; // unvoiced multisine mix for (i = 0; i < uvquality; i++) { C3 = C3 + mbe_cosf (((float)M_PI * pw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) + rphase[i]); if (pw0l > uvthreshold) { C3 = C3 + ((float)M_PI * (pw0l - uvthreshold) * 2.0f * mbe_rand()); } } C3 = C3 * uvsine * Ws[n + N] * prev_mp->Ml[l] * qfactor; *Ss += C1 + C3; Ss++; } // } else if (((cur_mp->Vl[l] == 1) || (prev_mp->Vl[l] == 1)) && ((l >= 8) || (fabsf (cw0 - pw0) >= ((float) 0.1 * cw0)))) { } else if ((cur_mp->Vl[l] == 1) || (prev_mp->Vl[l] == 1)) { Ss = aout_buf; for (n = 0; n < N; n++) { C1 = 0; // eq 133-1 C1 = Ws[n + N] * prev_mp->Ml[l] * mbe_cosf (((float)M_PI * pw0l * (float) n) + prev_mp->PHIl[l]); C2 = 0; // eq 133-2 C2 = Ws[n] * cur_mp->Ml[l] * mbe_cosf (((float)M_PI * cw0l * (float) (n - N)) + cur_mp->PHIl[l]); *Ss += C1 + C2; Ss++; } } /* // expensive and unnecessary? else if ((cur_mp->Vl[l] == 1) || (prev_mp->Vl[l] == 1)) { // eq 137 // eq 138 // eq 136 // eq 135 // eq 134 } */ else { Ss = aout_buf; // init random phase for (i = 0; i < uvquality; i++) { float f = (float)((int16_t)lfg_rand() * 3.051757e-5f); //rphase[i] = mbe_rand_phase(); rphase[i] = f; } // init random phase for (i = 0; i < uvquality; i++) { float f = (float)((int16_t)lfg_rand() * 3.051757e-5f); //rphase2[i] = mbe_rand_phase(); rphase2[i] = f; } for (n = 0; n < N; n++) { C3 = 0; // unvoiced multisine mix for (i = 0; i < uvquality; i++) { C3 = C3 + mbe_cosf (((float)M_PI * pw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) + rphase[i]); if (pw0l > uvthreshold) { C3 = C3 + ((float)M_PI * (pw0l - uvthreshold) * 2.0f * mbe_rand()); } } C3 = C3 * uvsine * Ws[n + N] * prev_mp->Ml[l] * qfactor; C4 = 0; // unvoiced multisine mix for (i = 0; i < uvquality; i++) { C4 = C4 + mbe_cosf (((float)M_PI * cw0 * (float) n * ((float) l + ((float) i * uvstep) - uvoffset)) + rphase2[i]); if (cw0l > uvthreshold) { C4 = C4 + ((float)M_PI * (cw0l - uvthreshold) * 2.0f * mbe_rand()); } } C4 = C4 * uvsine * Ws[n] * cur_mp->Ml[l] * qfactor; *Ss += C3 + C4; Ss++; } } } }