void TextGrid_Pitch_draw (TextGrid grid, Pitch pitch, Graphics g, long tierNumber, double tmin, double tmax, double fmin, double fmax, double fontSize, int useTextStyles, int horizontalAlignment, int garnish, int speckle, int unit) { try { TextGrid_checkSpecifiedTierNumberWithinRange (grid, tierNumber); double oldFontSize = Graphics_inqFontSize (g); Pitch_draw (pitch, g, tmin, tmax, fmin, fmax, garnish, speckle, unit); if (tmax <= tmin) tmin = grid -> xmin, tmax = grid -> xmax; autoPitchTier pitchTier = Pitch_to_PitchTier (pitch); if (Function_isUnitLogarithmic (pitch, Pitch_LEVEL_FREQUENCY, unit)) { fmin = Function_convertStandardToSpecialUnit (pitch, fmin, Pitch_LEVEL_FREQUENCY, unit); fmax = Function_convertStandardToSpecialUnit (pitch, fmax, Pitch_LEVEL_FREQUENCY, unit); } Graphics_setTextAlignment (g, horizontalAlignment, Graphics_BOTTOM); Graphics_setInner (g); Graphics_setFontSize (g, fontSize); Graphics_setPercentSignIsItalic (g, useTextStyles); Graphics_setNumberSignIsBold (g, useTextStyles); Graphics_setCircumflexIsSuperscript (g, useTextStyles); Graphics_setUnderscoreIsSubscript (g, useTextStyles); Function anyTier = (Function) grid -> tiers -> item [tierNumber]; if (anyTier -> classInfo == classIntervalTier) { IntervalTier tier = (IntervalTier) anyTier; for (long i = 1; i <= tier -> intervals -> size; i ++) { TextInterval interval = (TextInterval) tier -> intervals -> item [i]; double tleft = interval -> xmin, tright = interval -> xmax, tmid, f0; if (! interval -> text || ! interval -> text [0]) continue; if (tleft < pitch -> xmin) tleft = pitch -> xmin; if (tright > pitch -> xmax) tright = pitch -> xmax; tmid = (tleft + tright) / 2; if (tmid < tmin || tmid > tmax) continue; f0 = Function_convertStandardToSpecialUnit (pitch, RealTier_getValueAtTime (pitchTier.peek(), tmid), Pitch_LEVEL_FREQUENCY, unit); if (f0 < fmin || f0 > fmax) continue; Graphics_text (g, horizontalAlignment == Graphics_LEFT ? tleft : horizontalAlignment == Graphics_RIGHT ? tright : tmid, f0, interval -> text); } } else { TextTier tier = (TextTier) anyTier; for (long i = 1; i <= tier -> points -> size; i ++) { TextPoint point = (TextPoint) tier -> points -> item [i]; double t = point -> number, f0; if (! point -> mark || ! point -> mark [0]) continue; if (t < tmin || t > tmax) continue; f0 = Function_convertStandardToSpecialUnit (pitch, RealTier_getValueAtTime (pitchTier.peek(), t), Pitch_LEVEL_FREQUENCY, unit); if (f0 < fmin || f0 > fmax) continue; Graphics_text (g, t, f0, point -> mark); } } Graphics_setPercentSignIsItalic (g, TRUE); Graphics_setNumberSignIsBold (g, TRUE); Graphics_setCircumflexIsSuperscript (g, TRUE); Graphics_setUnderscoreIsSubscript (g, TRUE); Graphics_setFontSize (g, oldFontSize); Graphics_unsetInner (g); } catch (MelderError) { Melder_throw (grid, " & ", pitch, ": not drawn."); } }
autoPitchTier Pitch_AnyTier_to_PitchTier (Pitch pitch, AnyTier tier, int checkMethod) { try { SortedSetOfDouble points = tier -> points; if (checkMethod == 2) { autoPitchTier temp = Pitch_to_PitchTier (pitch); autoPitchTier thee = PitchTier_AnyTier_to_PitchTier (temp.peek(), tier); return thee.transfer(); } /* * Result's domain is a union of both domains. */ autoPitchTier thee = PitchTier_create ( pitch -> xmin < tier -> xmin ? pitch -> xmin : tier -> xmin, pitch -> xmax > tier -> xmax ? pitch -> xmax : tier -> xmax); /* * Copy pitch's frequencies at tier's points to the resulting PitchTier. */ for (long ipoint = 1; ipoint <= points -> size; ipoint ++) { AnyPoint point = (AnyPoint) points -> item [ipoint]; double time = point -> number; double frequency = Pitch_getValueAtTime (pitch, time, kPitch_unit_HERTZ, Pitch_LINEAR); if (frequency == NUMundefined && checkMethod) Melder_throw (U"No periodicity at time ", time, U" seconds."); RealTier_addPoint (thee.peek(), time, frequency); } return thee; } catch (MelderError) { Melder_throw (pitch, U" & ", tier, U": not converted to PitchTier."); } }
PitchTier Pitch_PointProcess_to_PitchTier (Pitch me, PointProcess pp) { try { autoPitchTier temp = Pitch_to_PitchTier (me); autoPitchTier thee = PitchTier_PointProcess_to_PitchTier (temp.peek(), pp); return thee.transfer(); } catch (MelderError) { Melder_throw (me, " & ", pp, ": not converted to PitchTier."); } }
PointProcess Pitch_to_PointProcess (Pitch pitch) { PitchTier pitchTier = NULL; PointProcess point = NULL; pitchTier = Pitch_to_PitchTier (pitch); cherror point = PitchTier_Pitch_to_PointProcess (pitchTier, pitch); cherror end: forget (pitchTier); iferror forget (point); return point; }
autoManipulation Sound_Pitch_to_Manipulation (Sound sound, Pitch pitch) { try { autoManipulation me = Manipulation_create (sound -> xmin, sound -> xmax); my sound = Sound_convertToMono (sound); Vector_subtractMean (my sound.get()); my pulses = Sound_Pitch_to_PointProcess_cc (my sound.get(), pitch); my pitch = Pitch_to_PitchTier (pitch); return me; } catch (MelderError) { Melder_throw (sound, U" & ", pitch, U": not converted to Manipulation."); } }
autoManipulation Sound_to_Manipulation (Sound me, double timeStep, double minimumPitch, double maximumPitch) { try { autoManipulation thee = Manipulation_create (my xmin, my xmax); thy sound = Sound_convertToMono (me); Vector_subtractMean (thy sound.get()); autoPitch pitch = Sound_to_Pitch (thy sound.get(), timeStep, minimumPitch, maximumPitch); thy pulses = Sound_Pitch_to_PointProcess_cc (thy sound.get(), pitch.get()); thy pitch = Pitch_to_PitchTier (pitch.get()); /* (DurationTier has been done at creation time) */ return thee; } catch (MelderError) { Melder_throw (me, U": not converted to Manipulation."); } }
Sound Sound_lengthen_overlapAdd (Sound me, double fmin, double fmax, double factor) { try { if (my ny > 1) Melder_throw (U"Overlap-add works only on mono sounds."); autoSound sound = Data_copy (me); Vector_subtractMean (sound.peek()); autoPitch pitch = Sound_to_Pitch (sound.peek(), 0.8 / fmin, fmin, fmax); autoPointProcess pulses = Sound_Pitch_to_PointProcess_cc (sound.peek(), pitch.peek()); autoPitchTier pitchTier = Pitch_to_PitchTier (pitch.peek()); autoDurationTier duration = DurationTier_create (my xmin, my xmax); RealTier_addPoint (duration.peek(), 0.5 * (my xmin + my xmax), factor); autoSound thee = Sound_Point_Pitch_Duration_to_Sound (sound.peek(), pulses.peek(), pitchTier.peek(), duration.peek(), 1.5 / fmin); return thee.transfer(); } catch (MelderError) { Melder_throw (me, U": not lengthened."); } }