Exemplo n.º 1
0
 /**
  * Converts a Hertz value to relative cents. E.g. 440Hz is converted to 900 if the reference is a
  * C.
  *
  * @param hertzValue A value in hertz.
  * @return A value in relative cents.
  */
 public static double hertzToRelativeCent(final double hertzValue) {
   double absoluteCentValue = PitchUnit.hertzToAbsoluteCent(hertzValue);
   // make absoluteCentValue positive. E.g. -2410 => 1210
   if (absoluteCentValue < 0) {
     absoluteCentValue = Math.abs(1200 + absoluteCentValue);
   }
   // so it can be folded to one octave. E.g. 1210 => 10
   return absoluteCentValue % 1200.0;
 }
Exemplo n.º 2
0
 /**
  * Converts a Hertz value to pitch in this unit.
  *
  * @param hertzValue The value in Hertz.
  * @return The pitch in this unit.
  */
 private double convertHertz(final double hertzValue) {
   final double convertedPitch;
   switch (this) {
     case ABSOLUTE_CENTS:
       convertedPitch = PitchUnit.hertzToAbsoluteCent(hertzValue);
       break;
     case HERTZ:
       convertedPitch = hertzValue;
       break;
     case MIDI_CENT:
       convertedPitch = PitchUnit.hertzToMidiCent(hertzValue);
       break;
     case MIDI_KEY:
       convertedPitch = PitchUnit.hertzToMidiKey(hertzValue);
       break;
     case RELATIVE_CENTS:
       convertedPitch = PitchUnit.hertzToRelativeCent(hertzValue);
       break;
     default:
       throw new AssertionError("Unknown pitch unit: " + getHumanName());
   }
   return convertedPitch;
 }