コード例 #1
0
ファイル: ERPTier.cpp プロジェクト: Crisil/praat
static PointProcess TextGrid_getStartingPoints_multiNumeric (TextGrid me, uint16_t number) {
	try {
		autoPointProcess thee = NULL;
		int numberOfBits = my numberOfTiers();
		for (int ibit = 0; ibit < numberOfBits; ibit ++) {
			(void) TextGrid_checkSpecifiedTierIsIntervalTier (me, ibit + 1);
			if (number & (1 << ibit)) {
				autoPointProcess bitEvents = TextGrid_getStartingPoints (me, ibit + 1, kMelder_string_EQUAL_TO, L"1");
				if (thee.peek()) {
					autoPointProcess intersection = PointProcesses_intersection (thee.peek(), bitEvents.peek());
					thee.reset (intersection.transfer());
				} else {
					thee.reset (bitEvents.transfer());
				}
			}
		}
		for (int ibit = 0; ibit < numberOfBits; ibit ++) {
			autoPointProcess bitEvents = TextGrid_getStartingPoints (me, ibit + 1, kMelder_string_EQUAL_TO, L"1");
			if (! (number & (1 << ibit))) {
				if (thee.peek()) {
					autoPointProcess difference = PointProcesses_difference (thee.peek(), bitEvents.peek());
					thee.reset (difference.transfer());
				} else {
					thee.reset (PointProcess_create (my xmin, my xmax, 10));
				}
			}
		}
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, ": starting points not converted to PointProcess.");
	}
}
コード例 #2
0
PointProcess PitchTier_to_PointProcess (PitchTier me) {
	try {
		autoPointProcess thee = PointProcess_create (my xmin, my xmax, 1000);
		double area = 0.5;   // imagine an event half a period before the beginning
		long size = my points -> size;
		if (size == 0) return thee.transfer();
		for (long interval = 0; interval <= size; interval ++) {
			double t1 = interval == 0 ? my xmin : ((RealPoint) my points -> item [interval]) -> number;
			Melder_assert (NUMdefined (t1));
			double t2 = interval == size ? my xmax : ((RealPoint) my points -> item [interval + 1]) -> number;
			Melder_assert (NUMdefined (t2));
			double f1 = ((RealPoint) my points -> item [interval == 0 ? 1 : interval]) -> value;
			Melder_assert (NUMdefined (f1));
			double f2 = ((RealPoint) my points -> item [interval == size ? size : interval + 1]) -> value;
			Melder_assert (NUMdefined (f2));
			area += (t2 - t1) * 0.5 * (f1 + f2);
			while (area >= 1.0) {
				double slope = (f2 - f1) / (t2 - t1), discriminant;
				area -= 1.0;
				discriminant = f2 * f2 - 2.0 * area * slope;
				if (discriminant < 0.0) discriminant = 0.0;   // catch rounding errors
				PointProcess_addPoint (thee.peek(), t2 - 2.0 * area / (f2 + sqrt (discriminant)));
			}
		}
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, ": not converted to PointProcess.");
	}
}
コード例 #3
0
ファイル: ERPTier.cpp プロジェクト: nullpunktTUD/praat
static autoPointProcess TextGrid_getStartingPoints_multiNumeric (TextGrid me, uint16_t number) {
	try {
		autoPointProcess thee;
		int numberOfBits = my tiers->size;
		for (int ibit = 0; ibit < numberOfBits; ibit ++) {
			(void) TextGrid_checkSpecifiedTierIsIntervalTier (me, ibit + 1);
			if (number & (1 << ibit)) {
				autoPointProcess bitEvents = TextGrid_getStartingPoints (me, ibit + 1, kMelder_string_EQUAL_TO, U"1");
				if (thee) {
					thee = PointProcesses_intersection (thee.get(), bitEvents.get());
				} else {
					thee = bitEvents.move();
				}
			}
		}
		for (int ibit = 0; ibit < numberOfBits; ibit ++) {
			autoPointProcess bitEvents = TextGrid_getStartingPoints (me, ibit + 1, kMelder_string_EQUAL_TO, U"1");
			if (! (number & (1 << ibit))) {
				if (thee) {
					thee = PointProcesses_difference (thee.get(), bitEvents.get());
				} else {
					thee = PointProcess_create (my xmin, my xmax, 10);
				}
			}
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": starting points not converted to PointProcess.");
	}
}
コード例 #4
0
PointProcess Sound_Pitch_to_PointProcess_peaks (Sound sound, Pitch pitch, int includeMaxima, int includeMinima) {
	PointProcess point = PointProcess_create (sound -> xmin, sound -> xmax, 10);
	double t = pitch -> xmin;
	double addedRight = -1e300;
	/*
	 * Cycle over all voiced intervals.
	 */

	for (;;) {
		double tleft, tright, tmiddle, f0middle, tmax, tsave;
		if (! Pitch_getVoicedIntervalAfter (pitch, t, & tleft, & tright)) break;
		/*
		 * Go to the middle of the voiced interval.
		 */
		tmiddle = (tleft + tright) / 2;
		if (! Melder_progress1 ((tmiddle - sound -> xmin) / (sound -> xmax - sound -> xmin), L"Sound & Pitch to PointProcess"))
			goto end;
		f0middle = Pitch_getValueAtTime (pitch, tmiddle, kPitch_unit_HERTZ, Pitch_LINEAR);

		/*
		 * Our first point is near this middle.
		 */
		Melder_assert (NUMdefined (f0middle));
		tmax = Sound_findExtremum (sound, tmiddle - 0.5 / f0middle, tmiddle + 0.5 / f0middle, includeMaxima, includeMinima);
		Melder_assert (NUMdefined (tmax));
		if (! PointProcess_addPoint (point, tmax)) goto end;

		tsave = tmax;
		for (;;) {
			double f0 = Pitch_getValueAtTime (pitch, tmax, kPitch_unit_HERTZ, Pitch_LINEAR);
			if (f0 == NUMundefined) break;
			tmax = Sound_findExtremum (sound, tmax - 1.25 / f0, tmax - 0.8 / f0, includeMaxima, includeMinima);
			if (tmax < tleft) {
				if (tmax - addedRight > 0.8 / f0)
					if (! PointProcess_addPoint (point, tmax)) goto end;
				break;
			}
			if (tmax - addedRight > 0.8 / f0)   /* Do not fill in a short originally unvoiced interval twice. */
				if (! PointProcess_addPoint (point, tmax)) goto end;
		}
		tmax = tsave;
		for (;;) {
			double f0 = Pitch_getValueAtTime (pitch, tmax, kPitch_unit_HERTZ, Pitch_LINEAR);
			if (f0 == NUMundefined) break;
			tmax = Sound_findExtremum (sound, tmax + 0.8 / f0, tmax + 1.25 / f0, includeMaxima, includeMinima);
			if (tmax > tright) {
				if (! PointProcess_addPoint (point, tmax)) goto end;
				addedRight = tmax;
				break;
			}
			if (! PointProcess_addPoint (point, tmax)) goto end;
			addedRight = tmax;
		}
		t = tright;
	}
end:
	Melder_progress1 (1.0, NULL);
	iferror forget (point);
	return point;
}
コード例 #5
0
autoPointProcess Matrix_to_PointProcess (Matrix me) {
	try {
		autoPointProcess thee = PointProcess_create (my z [1] [1], my z [1] [my nx], my nx);
		for (long i = 1; i <= my nx; i ++) {
			PointProcess_addPoint (thee.peek(), my z [1] [i]);
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": not converted to PointProcess.");
	}
}
コード例 #6
0
ファイル: AnyTier.cpp プロジェクト: alekstorm/tala
PointProcess AnyTier_downto_PointProcess (I) {
	iam (AnyTier);
	long numberOfPoints = my points -> size;
	AnyPoint *points = (AnyPoint *) my points -> item;
	PointProcess thee = PointProcess_create (my xmin, my xmax, numberOfPoints);
	if (! thee) return NULL;
	/* OPTIMIZATION, bypassing PointProcess_addTime: */
	for (long i = 1; i <= numberOfPoints; i ++)
		thy t [i] = points [i] -> time;
	thy nt = numberOfPoints;
	return thee;
}
コード例 #7
0
ファイル: AnyTier.cpp プロジェクト: READSEARCH/praat
autoPointProcess AnyTier_downto_PointProcess (AnyTier me) {
	try {
		long numberOfPoints = my points.size;
		autoPointProcess thee = PointProcess_create (my xmin, my xmax, numberOfPoints);
		/* OPTIMIZATION, bypassing PointProcess_addTime: */
		for (long i = 1; i <= numberOfPoints; i ++)
			thy t [i] = my points.at [i] -> number;
		thy nt = numberOfPoints;
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": not converted to PointProcess.");
	}
}
コード例 #8
0
ファイル: PointProcess.cpp プロジェクト: READSEARCH/praat
autoPointProcess PointProcess_createPoissonProcess (double startingTime, double finishingTime, double density) {
	try {
		long nt = NUMrandomPoisson ((finishingTime - startingTime) * density);
		autoPointProcess me = PointProcess_create (startingTime, finishingTime, nt);
		my nt = nt;
		for (long i = 1; i <= nt; i ++)
			my t [i] = NUMrandomUniform (startingTime, finishingTime);
		NUMsort_d (my nt, my t);
		return me;
	} catch (MelderError) {
		Melder_throw (U"PointProcess (Poisson process) not created.");
	}
}
コード例 #9
0
ファイル: AnyTier.cpp プロジェクト: eginhard/praat
PointProcess AnyTier_downto_PointProcess (I) {
	iam (AnyTier);
	try {
		long numberOfPoints = my points -> size;
		AnyPoint *points = (AnyPoint *) my points -> item;
		autoPointProcess thee = PointProcess_create (my xmin, my xmax, numberOfPoints);
		/* OPTIMIZATION, bypassing PointProcess_addTime: */
		for (long i = 1; i <= numberOfPoints; i ++)
			thy t [i] = points [i] -> number;
		thy nt = numberOfPoints;
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, U": not converted to PointProcess.");
	}
}
コード例 #10
0
PointProcess PitchTier_Point_to_PointProcess (PitchTier me, PointProcess vuv, double maxT) {
	try {
		autoPointProcess fullPoint = PitchTier_to_PointProcess (me);
		autoPointProcess thee = PointProcess_create (my xmin, my xmax, fullPoint -> maxnt);
		/*
		 * Copy only voiced parts to result.
		 */
		for (long i = 1; i <= fullPoint -> nt; i ++) {
			double t = fullPoint -> t [i];
			if (PointProcess_isVoiced_t (vuv, t, maxT)) {
				PointProcess_addPoint (thee.peek(), t);
			}
		}
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, " & ", vuv, ": not converted to PointProcess.");
	}
}
コード例 #11
0
PointProcess Sound_Pitch_to_PointProcess_cc (Sound sound, Pitch pitch) {
	PointProcess point = PointProcess_create (sound -> xmin, sound -> xmax, 10);
	double t = pitch -> xmin;
	double addedRight = -1e300;
	double globalPeak = Vector_getAbsoluteExtremum (sound, sound -> xmin, sound -> xmax, 0), peak;
	
	/*
	 * Cycle over all voiced intervals.
	 */
	for (;;) {
		double tleft, tright, tmiddle, f0middle, tmax, tsave;
		if (! Pitch_getVoicedIntervalAfter (pitch, t, & tleft, & tright)) break;
		/*
		 * Go to the middle of the voice stretch.
		 */
		tmiddle = (tleft + tright) / 2;
		if (! Melder_progress1 ((tmiddle - sound -> xmin) / (sound -> xmax - sound -> xmin), L"Sound & Pitch to PointProcess"))
			goto end;
		f0middle = Pitch_getValueAtTime (pitch, tmiddle, kPitch_unit_HERTZ, Pitch_LINEAR);

		/*
		 * Our first point is near this middle.
		 */
		if (f0middle == NUMundefined) {
			Melder_fatal ("Sound_Pitch_to_PointProcess_cc: tleft %ls, tright %ls, f0middle %ls",
				Melder_double (tleft), Melder_double (tright), Melder_double (f0middle));
		}
		tmax = Sound_findExtremum (sound, tmiddle - 0.5 / f0middle, tmiddle + 0.5 / f0middle, TRUE, TRUE);
		Melder_assert (NUMdefined (tmax));
		if (! PointProcess_addPoint (point, tmax)) goto end;

		tsave = tmax;
		for (;;) {
			double f0 = Pitch_getValueAtTime (pitch, tmax, kPitch_unit_HERTZ, Pitch_LINEAR), correlation;
			if (f0 == NUMundefined) break;
			correlation = Sound_findMaximumCorrelation (sound, tmax, 1.0 / f0, tmax - 1.25 / f0, tmax - 0.8 / f0, & tmax, & peak);
			if (correlation == -1) /*break*/ tmax -= 1.0 / f0;   /* This one period will drop out. */
			if (tmax < tleft) {
				if (correlation > 0.7 && peak > 0.023333 * globalPeak && tmax - addedRight > 0.8 / f0)
					if (! PointProcess_addPoint (point, tmax)) goto end;
				break;
			}
			if (correlation > 0.3 && (peak == 0.0 || peak > 0.01 * globalPeak)) {
				if (tmax - addedRight > 0.8 / f0)   /* Do not fill in a short originally unvoiced interval twice. */
					if (! PointProcess_addPoint (point, tmax)) goto end;
			}
		}
		tmax = tsave;
		for (;;) {
			double f0 = Pitch_getValueAtTime (pitch, tmax, kPitch_unit_HERTZ, Pitch_LINEAR), correlation;
			if (f0 == NUMundefined) break;
			correlation = Sound_findMaximumCorrelation (sound, tmax, 1.0 / f0, tmax + 0.8 / f0, tmax + 1.25 / f0, & tmax, & peak);
			if (correlation == -1) /*break*/ tmax += 1.0 / f0;
			if (tmax > tright) {
				if (correlation > 0.7 && peak > 0.023333 * globalPeak) {
					if (! PointProcess_addPoint (point, tmax)) goto end;
					addedRight = tmax;
				}
				break;
			}
			if (correlation > 0.3 && (peak == 0.0 || peak > 0.01 * globalPeak)) {
				if (! PointProcess_addPoint (point, tmax)) goto end;
				addedRight = tmax;
			}
		}
		t = tright;
	}
end:
	Melder_progress1 (1.0, NULL);
	iferror forget (point);
	return point;
}