This repository has been archived on 2019-12-11. You can view files and clone it, but cannot push or open issues/pull-requests.
2019-12-02 19:47:40 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import "math"
|
|
|
|
|
|
|
|
// Return the frequency of a given MIDI note number.
|
2019-12-03 20:34:29 +00:00
|
|
|
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)
|
2019-12-02 19:47:40 +00:00
|
|
|
}
|