コード例 #1
0
ファイル: PitchUnit.java プロジェクト: JorenSix/Tarsos
 /**
  * Calculates the frequency (Hz) for a MIDI key.
  *
  * @param midiKey The MIDI key. A MIDI key is an integer between 0 and 127, inclusive.
  * @return A frequency in Hz corresponding to the MIDI key.
  * @exception IllegalArgumentException If midiKey is not in the valid range between 0 and 127,
  *     inclusive.
  */
 public static double midiKeyToHertz(final int midiKey) {
   if (midiKey < 0 || midiKey > 127) {
     LOG.warning(
         "MIDI keys are defined between 0 and 127 or from "
             + midiKeyToHertz(0)
             + "Hz to "
             + midiKeyToHertz(127)
             + "Hz, MIDI KEY "
             + midiKey
             + " is out of this range.");
   }
   return PitchUnit.midiCentToHertz(midiKey);
 }
コード例 #2
0
ファイル: PitchUnit.java プロジェクト: JorenSix/Tarsos
 private double convertToHertz(final double value, final PitchUnit valueUnit) {
   final double hertzValue;
   switch (valueUnit) {
     case ABSOLUTE_CENTS:
       hertzValue = PitchUnit.absoluteCentToHertz(value);
       break;
     case HERTZ:
       hertzValue = value;
       break;
     case MIDI_CENT:
       hertzValue = PitchUnit.midiCentToHertz(value);
       break;
     case MIDI_KEY:
       hertzValue = PitchUnit.midiKeyToHertz((int) value);
       break;
     case RELATIVE_CENTS:
       hertzValue = PitchUnit.relativeCentToHertz(value);
       break;
     default:
       throw new AssertionError("Unknown pitch unit: " + getHumanName());
   }
   return hertzValue;
 }