double VocalTract_and_LPC_Frame_getMatchingLength (VocalTract me, LPC_Frame thee, double glottalDamping, bool radiationDamping, bool internalDamping) { try { // match the average distance between the first two formants in the VocaTract and the LPC spectrum long numberOfFrequencies = 1000; double maximumFrequency = 5000.0; autoSpectrum vts = VocalTract_to_Spectrum (me, numberOfFrequencies, maximumFrequency, glottalDamping, radiationDamping, internalDamping); double samplingFrequency = 1000.0 * my nx; autoSpectrum lps = Spectrum_create (0.5 * samplingFrequency, numberOfFrequencies); LPC_Frame_into_Spectrum (thee, lps.peek(), 0, 50); autoSpectrumTier vtst = Spectrum_to_SpectrumTier_peaks (vts.peek()); autoSpectrumTier lpst = Spectrum_to_SpectrumTier_peaks (lps.peek()); double vt_f1 = vtst -> points.at [1] -> number, vt_f2 = vtst -> points.at [2] -> number; double lp_f1 = lpst -> points.at [1] -> number, lp_f2 = lpst -> points.at [2] -> number; double df1 = lp_f1 - vt_f1, df2 = lp_f2 - vt_f2, df = 0.5 * (df1 + df2); double dl = - df / lp_f2; return my dx * my nx * (1 + dl); } catch (MelderError) { Melder_throw (U"Length could not be determined from VocalTract and LPC_Frame."); } }
Spectrum LPC_to_Spectrum (LPC me, double t, double dfMin, double bandwidthReduction, double deEmphasisFrequency) { try { double samplingFrequency = 1.0 / my samplingPeriod; long nfft = 2, index = Sampled_xToNearestIndex (me, t); if (index < 1) { index = 1; } if (index > my nx) { index = my nx; } if (dfMin <= 0) { nfft = 512; dfMin = samplingFrequency / nfft; } while (samplingFrequency / nfft > dfMin || nfft <= my d_frames[index].nCoefficients) { nfft *= 2; } autoSpectrum thee = Spectrum_create (samplingFrequency / 2, nfft / 2 + 1); LPC_Frame_into_Spectrum (& my d_frames[index], thee.peek(), bandwidthReduction, deEmphasisFrequency); return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": no Spectrum created."); } }