PraatPitchTier implements PraatTier { public double getFrequency(double time) { PitchTarget prev = null; PitchTarget current = null; for (int j = 0; j < targets.length; j++) { if (time <= targets[j].time) { current = targets[j]; if (j > 0) { prev = targets[j - 1]; } break; } } if (current == null) return Double.NaN; if (Math.abs(time - current.time) < 1.e-7) return current.frequency; if (prev == null) return Double.NaN; assert prev != null; double deltaT = current.time - prev.time; double deltaF = current.frequency - prev.frequency; return prev.frequency + (time - prev.time) / deltaT * deltaF; } PraatPitchTier(Reader input);  PraatPitchTier(double xmin, double[] frames, double step);  PraatPitchTier(Document acoustparams);  PraatPitchTier(PitchTarget[] targets); @Override String getName(); @Override double getXmax(); void setXmax(double value); @Override double getXmin(); void setXmin(double value); int getNumTargets(); PitchTarget[] getPitchTargets(); void writeTo(Writer out); double[] toFrames(double step); double getFrequency(double time); @Override boolean equals(Object otherObj); @Override int hashCode();  }
@Test public void canComputeFrequency() throws Exception { String simpleFile = PraatPitchTier.FIRSTLINE + "\n" + PraatPitchTier.SECONDLINE + "\n\n"; simpleFile += "0\n3\n" + "3\n" + "1\n100\n" + "2\n200\n" + "2.5\n300\n"; PraatPitchTier simple = new PraatPitchTier(new StringReader(simpleFile)); assertTrue(Double.isNaN(simple.getFrequency(0))); assertTrue(Double.isNaN(simple.getFrequency(0.99))); assertEquals(100, simple.getFrequency(1), 1.e-7); assertEquals(150, simple.getFrequency(1.5), 1.e-7); assertEquals(175, simple.getFrequency(1.75), 1.e-7); assertEquals(200, simple.getFrequency(2), 1.e-7); assertEquals(250, simple.getFrequency(2.25), 1.e-7); assertEquals(300, simple.getFrequency(2.5), 1.e-7); assertTrue(Double.isNaN(simple.getFrequency(2.51))); assertTrue(Double.isNaN(simple.getFrequency(3))); }