This repository has been archived on 2019-12-11. You can view files and clone it, but cannot push or open issues/pull-requests.
jlaudio/lib/util/notefreq.go

19 lines
435 B
Go

package util
import "math"
// Return the frequency of a given MIDI note number.
func NoteFreq(n float64) float64 {
return (math.Pow(2, (n-69)/12)) * 440
}
// Return the midi note number for the given frequency.
func FreqNote(f float64) float64 {
return 12*math.Log2(f/440) + 69
}
// Return the one-cent change in frequency at the given frequency.
func CentDeltaFreq(f float64) float64 {
return f * (math.Pow(2, 1/1200.0) - 1)
}