Calibra Music
Music theory utilities for pitch and note conversions.
What is CalibraMusic?
CalibraMusic provides conversion functions between different musical pitch representations:
Hz (Hertz): Physical frequency (e.g., 440.0 Hz)
MIDI note numbers: Integer scale (60 = middle C, 69 = A4)
Note labels: Human-readable (e.g., "C4", "A#5", "Bb3")
Cents: Fine pitch deviation (100 cents = 1 semitone)
Use it when you need to:
Display detected pitch as a note name
Calculate pitch deviation from a target note
Convert between different pitch units for analysis
When to Use
| Scenario | Use This? | Why |
|---|---|---|
| Convert Hz to note name | Yes | hzToNoteLabel(440f) → "A4" |
| Show pitch deviation | Yes | centsDeviation(442f) → +7.8 cents |
| Create note frequencies | Yes | noteLabelToHz("C4") → 261.63 Hz |
| Detect pitch from audio | No | Use CalibraPitch |
Quick Start
Kotlin
// Convert frequency to note name
val noteLabel = CalibraMusic.hzToNoteLabel(440f) // "A4"
// Convert note name to frequency
val frequency = CalibraMusic.noteLabelToHz("C4") // 261.63 Hz
// Get cents deviation from nearest note
val deviation = CalibraMusic.centsDeviation(442f) // +7.8 cents (sharp)
// Convert between MIDI and Hz
val midi = CalibraMusic.hzToMidi(440f) // 69.0
val hz = CalibraMusic.midiToHz(60f) // 261.63 Hz (middle C)Swift
// Convert frequency to note name
let noteLabel = CalibraMusic.hzToNoteLabel(440) // "A4"
// Convert note name to frequency
let frequency = CalibraMusic.noteLabelToHz("C4") // 261.63 Hz
// Get cents deviation from nearest note
let deviation = CalibraMusic.centsDeviation(442) // +7.8 cents
// Convert between MIDI and Hz
let midi = CalibraMusic.hzToMidi(440) // 69.0
let hz = CalibraMusic.midiToHz(60) // 261.63 HzPitch Reference
| Note | MIDI | Hz |
|---|---|---|
| C4 (middle C) | 60 | 261.63 |
| A4 (concert pitch) | 69 | 440.00 |
| C5 | 72 | 523.25 |
Common Pitfalls
Invalid frequencies: Functions return
Float.NaNor "-" for invalid inputFlat notation: Use lowercase 'b' for flats (e.g., "Bb4", not "BB4")
Octave numbering: Middle C is C4 (scientific pitch notation)
Cents interpretation: Positive = sharp, negative = flat
See also
For detecting pitch from audio
For scoring pitch accuracy
Properties
Functions
Get cents deviation from nearest note (-50 to +50).
Convert cents to MIDI note number.
Convert cents to note label (relative to tonic).
Convert frequency in Hz to note label.
Convert MIDI note number to cents.
Convert MIDI note number to note label (e.g., "A4", "C#5").
Convert note label to cents (relative to tonic).
Convert note label to frequency in Hz.
Convert note label to MIDI note number. Supports sharps (#), flats (b).