@Test public void testLatency(){ List<SoundEvent> commands = new ArrayList<SoundEvent>(); double latency; int semitonDistance = 1; Assert.assertEquals(2, evaluator.distance(SoundEvent.pitch(freq("D3")), freq("C3")), PRECISION); commands.clear(); commands.add(SoundEvent.pitch(0.0f, freq("D3"))); commands.add(SoundEvent.pitch(0.5f, freq("C#3"))); commands.add(SoundEvent.pitch(1.0f, freq("C3"))); latency = evaluator.latency(commands, freq("C3"), semitonDistance); Assert.assertEquals(0.5, latency, PRECISION); semitonDistance = 2; commands.clear(); commands.add(SoundEvent.pitch(0.0f, freq("D5"))); commands.add(SoundEvent.pitch(0.1f, freq("D6"))); commands.add(SoundEvent.pitch(0.2f, freq("D5"))); commands.add(SoundEvent.pitch(0.3f, freq("B2"))); commands.add(SoundEvent.pitch(0.4f, freq("D3"))); commands.add(SoundEvent.pitch(0.5f, freq("B2"))); commands.add(SoundEvent.pitch(0.6f, freq("C3"))); commands.add(SoundEvent.pitch(0.7f, freq("B2"))); latency = evaluator.latency(commands, freq("B2"), semitonDistance); Assert.assertEquals(0.3, latency, PRECISION); semitonDistance = 2; commands.clear(); commands.add(SoundEvent.pitch(0.0f, freq("D5"))); commands.add(SoundEvent.pitch(0.1f, freq("D6"))); latency = evaluator.latency(commands, freq("B2"), semitonDistance); Assert.assertEquals(PitchPrecisionLatency.NO_CONVERGE, latency, PRECISION); semitonDistance = 1; commands.clear(); commands.add(SoundEvent.pitch(0.0f, freq("B2")+0.002f)); commands.add(SoundEvent.pitch(0.1f, freq("B2")+0.001f)); latency = evaluator.latency(commands, freq("B2"), semitonDistance); Assert.assertEquals(0, latency, PRECISION); }
@Override public double latency(List<SoundEvent> commands, float expectedFrequency, float distance) { for(SoundEvent e: commands){ if(distance(e, expectedFrequency)<=distance){ return e.timeInSec; } } return NO_CONVERGE; }
PitchPrecisionLatencyInSemitone implements PitchPrecisionLatency { @Override public double latency(List<SoundEvent> commands, float expectedFrequency, float distance) { for(SoundEvent e: commands){ if(distance(e, expectedFrequency)<=distance){ return e.timeInSec; } } return NO_CONVERGE; } }
PitchPrecisionLatencyInSemitone implements PitchPrecisionLatency { @Override public double latency(List<SoundEvent> commands, float expectedFrequency, float distance) { for(SoundEvent e: commands){ if(distance(e, expectedFrequency)<=distance){ return e.timeInSec; } } return NO_CONVERGE; } PitchPrecisionLatencyInSemitone(); }
PitchPrecisionLatencyInSemitone implements PitchPrecisionLatency { @Override public double latency(List<SoundEvent> commands, float expectedFrequency, float distance) { for(SoundEvent e: commands){ if(distance(e, expectedFrequency)<=distance){ return e.timeInSec; } } return NO_CONVERGE; } PitchPrecisionLatencyInSemitone(); @Override double latency(List<SoundEvent> commands, float expectedFrequency, float distance); @Override double distance(SoundEvent command, float expectedFrequency); }
PitchPrecisionLatencyInSemitone implements PitchPrecisionLatency { @Override public double latency(List<SoundEvent> commands, float expectedFrequency, float distance) { for(SoundEvent e: commands){ if(distance(e, expectedFrequency)<=distance){ return e.timeInSec; } } return NO_CONVERGE; } PitchPrecisionLatencyInSemitone(); @Override double latency(List<SoundEvent> commands, float expectedFrequency, float distance); @Override double distance(SoundEvent command, float expectedFrequency);  }