Skip to content

danigb/midi-freq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

midi-freq npm version

A tiny (188 bytes) function to get the frequency of a midi note number:

var freq = require('midi-freq')(440)
freq(69) // => 440

It uses an equal tempered scale. Basically it's just: Math.pow(2, (midi - 69) / 12) * tuning with a couple of goodies.

API

freq(tuning, midi)

Get the frequency of a midi note with the custom tuning. If not specified, is 440Hz by default.

Basic usage

Get the frequency:

// 69 is note A4
var freq = require('midi-freq')
freq(440, 69) // => 440
freq(null, 69) // => 440
freq(444, 69) /// => 444
// 57 is note A3
freq(null, 57) // => 220
freq(444, 57) // => 222

Set default tuning

Normally you use the same tuning for all your app. You can partially applied the function:

var freq = require('midi-freq')(444)
// the freq function uses 444 as custom tuning
freq(57) // => 222

License

MIT License

About

Get frequency of a midi note

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published