package panako import "math" type Hertz float64 // Cent Twelve-tone equal temperament divides the Octave into 12 semitones of 100 Cent each. type Cent int64 // Octave The interval between one musical pitch and another with double its frequency type Octave int const CentsPerOctave = 1200 func (h Hertz) DifferenceInCent(b Hertz) Cent { return Cent(CentsPerOctave * math.Log2(float64(b/h))) } func (h Hertz) DifferenceInHertz(b Hertz) Hertz { return b - h } func (h Hertz) Octaves(octaves Octave) Hertz { return h * Hertz(math.Pow(2, float64(octaves))) } func (h Hertz) Cents(cents Cent) Hertz { return h * Hertz(math.Pow(2, float64(cents)/CentsPerOctave)) }