@Test public void shouldReturnFSharpNote(){ String pitchOne = frequencyToPitchConversion.getPitchName(23f); String pitchTwo = frequencyToPitchConversion.getPitchName(186.1f); String pitchThree = frequencyToPitchConversion.getPitchName(5920f); assertThat(pitchOne).isEqualTo("fs"); assertThat(pitchTwo).isEqualTo("fs"); assertThat(pitchThree).isEqualTo("fs"); }
public String getPitchName(float freq){ float closestDistance = 9999999f; PitchFreq bestMatch = null; for(PitchFreq pitchFreq:pitchFreqs) { int numOfOctaves = 8; for (int i = 0; i < numOfOctaves+1; i++) { double freqOctave = pitchFreq.getFreq() * Math.pow((double)2f,(double)i); if(Math.abs(freq-freqOctave) < closestDistance){ bestMatch = pitchFreq; bestMatch.setOctave(i); closestDistance = (float)Math.abs(freq-freqOctave); } } } return bestMatch.getNote(); }
FrequencyToPitchConversion { public String getPitchName(float freq){ float closestDistance = 9999999f; PitchFreq bestMatch = null; for(PitchFreq pitchFreq:pitchFreqs) { int numOfOctaves = 8; for (int i = 0; i < numOfOctaves+1; i++) { double freqOctave = pitchFreq.getFreq() * Math.pow((double)2f,(double)i); if(Math.abs(freq-freqOctave) < closestDistance){ bestMatch = pitchFreq; bestMatch.setOctave(i); closestDistance = (float)Math.abs(freq-freqOctave); } } } return bestMatch.getNote(); } }
FrequencyToPitchConversion { public String getPitchName(float freq){ float closestDistance = 9999999f; PitchFreq bestMatch = null; for(PitchFreq pitchFreq:pitchFreqs) { int numOfOctaves = 8; for (int i = 0; i < numOfOctaves+1; i++) { double freqOctave = pitchFreq.getFreq() * Math.pow((double)2f,(double)i); if(Math.abs(freq-freqOctave) < closestDistance){ bestMatch = pitchFreq; bestMatch.setOctave(i); closestDistance = (float)Math.abs(freq-freqOctave); } } } return bestMatch.getNote(); } FrequencyToPitchConversion(); }
FrequencyToPitchConversion { public String getPitchName(float freq){ float closestDistance = 9999999f; PitchFreq bestMatch = null; for(PitchFreq pitchFreq:pitchFreqs) { int numOfOctaves = 8; for (int i = 0; i < numOfOctaves+1; i++) { double freqOctave = pitchFreq.getFreq() * Math.pow((double)2f,(double)i); if(Math.abs(freq-freqOctave) < closestDistance){ bestMatch = pitchFreq; bestMatch.setOctave(i); closestDistance = (float)Math.abs(freq-freqOctave); } } } return bestMatch.getNote(); } FrequencyToPitchConversion(); String getPitchName(float freq); }
FrequencyToPitchConversion { public String getPitchName(float freq){ float closestDistance = 9999999f; PitchFreq bestMatch = null; for(PitchFreq pitchFreq:pitchFreqs) { int numOfOctaves = 8; for (int i = 0; i < numOfOctaves+1; i++) { double freqOctave = pitchFreq.getFreq() * Math.pow((double)2f,(double)i); if(Math.abs(freq-freqOctave) < closestDistance){ bestMatch = pitchFreq; bestMatch.setOctave(i); closestDistance = (float)Math.abs(freq-freqOctave); } } } return bestMatch.getNote(); } FrequencyToPitchConversion(); String getPitchName(float freq);  }