A utility library for calculating musical information e.g. a note from a frequency
$ npm install --save music-math
var Frequency = require('music-math').Frequency;
var freqDetails = Frequency(440)
console.log(JSON.stringify(freqDetails))
//=> {"frequency":440,"noteNumber":57,"note":"A","octave":4,"offset":0}
- Required
- Type:
number
The frequency to perform calculations on (in Hz).
Returns an object with the following properties (lazily calculated first time you request them):
- Type:
number
The frequency of the note (in Hz)
- Type:
number
The number of the [closest matching] note in the scale
- Type:
string
The [closest matching] note in the scale
- Type:
number
The octave the frequency resides in
- Type:
number
The measure of how off pitch the frequency is from the closest matching note (in cents)
This utility was pulled out of a little fun side project I was working on - I am by no means versed in musical theory. I would be immensely grateful of any help especially in the form of:
- corrections to my terminology
- corrections to the math
- additional test cases (especially failing ones that reveal flaws in my math!)
All pull requests / issues / feedback welcome :) Thanks!
npm run build
npm test
To watch for changes, build them and run the tests:
npm run watch
MIT © James Bunt