Beispiel #1
0
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.");
	}
}
Beispiel #2
0
void Spectrum_getNearestMaximum (Spectrum me, double frequency, double *frequencyOfMaximum, double *heightOfMaximum) {
	try {
		autoSpectrumTier thee = Spectrum_to_SpectrumTier_peaks (me);
		long index = AnyTier_timeToNearestIndex (thee.peek(), frequency);
		if (index == 0)
			Melder_throw ("No peak.");
		RealPoint point = (RealPoint) thy points -> item [index];
		*frequencyOfMaximum = point -> number;
		*heightOfMaximum = point -> value;
	} catch (MelderError) {
		Melder_throw (me, ": no nearest maximum found.");
	}
}