PitchTier PitchTier_normalizePitchRange (PitchTier me, double pitchMin_ref_Hz, double pitchMax_ref_Hz, double pitchMin_Hz, double pitchMax_Hz, int pitchUnit) { try { double fminr = HertzToSpecial (pitchMin_ref_Hz, pitchUnit); double fmaxr = HertzToSpecial (pitchMax_ref_Hz, pitchUnit); double fmin = HertzToSpecial (pitchMin_Hz, pitchUnit); double fmax = HertzToSpecial (pitchMax_Hz, pitchUnit); if (fminr == NUMundefined || fmaxr == NUMundefined || fmin == NUMundefined || fmax == NUMundefined) { Melder_throw ("The conversion of a pitch value is not defined. "); } double ranger = fmaxr - fminr, range = fmax - fmin; if (ranger < 0.01 || range < 0.01) { Melder_throw ("Pitch range too small."); } double fmidr = fminr + ranger / 2; double factor = ranger / range; autoPitchTier thee = Data_copy (me); for (long i = 1; i <= my points -> size; i ++) { RealPoint point = (RealPoint) thy points -> item [i]; double f = HertzToSpecial (point -> value, pitchUnit); f = factor * (f - fmidr); f = SpecialToHertz (f, pitchUnit); point -> value = f; } return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": no PitchTier created."); } }
PitchTier PitchTier_normalizePitchRange (PitchTier me, double pitchMin_ref_Hz, double pitchMax_ref_Hz, double pitchMin_Hz, double pitchMax_Hz, int pitchUnit) { PitchTier thee; long i; double fmidr, factor, ranger, range; double fminr = HertzToSpecial (pitchMin_ref_Hz, pitchUnit); double fmaxr = HertzToSpecial (pitchMax_ref_Hz, pitchUnit); double fmin = HertzToSpecial (pitchMin_Hz, pitchUnit); double fmax = HertzToSpecial (pitchMax_Hz, pitchUnit); if (fminr == NUMundefined || fmaxr == NUMundefined || fmin == NUMundefined || fmax == NUMundefined) return Melder_errorp1 (L"The conversion of a pitch value is not defined. "); ranger = fmaxr - fminr; range = fmax - fmin; if (ranger < 0.01 || range < 0.01) return Melder_errorp1 (L"Pitch range too small."); fmidr = fminr + ranger / 2; factor = ranger / range; thee = Data_copy (me); if (thee == NULL) return NULL; for (i = 1; i <= my points -> size; i ++) { RealPoint point = thy points -> item [i]; double f = HertzToSpecial (point -> value, pitchUnit); f = factor * (f - fmidr); f = SpecialToHertz (f, pitchUnit); point -> value = f; } return thee; }