freq
tonal-freq
is a collection of functions to perform calculations related to frequencies.
This is part of tonal music theory library.
Usage
var freq = freq // => 440freq // => 'A4'freq // => ['C4', 200]
Install
API Documentation
- freq
.eqTempFreq(ref, maxDecimals, note)
⇒Number
.toFreq(note)
⇒Float
.eqTempFreqToMidi(tuning, freq)
⇒Number
.toMidi(freq)
⇒Number
.note(freq, useSharps)
⇒String
.cents(base, freq)
⇒Integer
freq.eqTempFreq(ref, maxDecimals, note)
⇒ Number
Return the equal tempered frequency of a note.
This function can be partially applied if note parameter is not present.
Kind: static method of freq
Returns: Number
- the frequency
Param | Type | Description |
---|---|---|
ref | Float |
the tuning reference |
maxDecimals | Integer |
(Optional) the maximum number of decimals (all by default) |
note | String | Pitch |
the note to get the frequency from |
Example
const toFreq = // => 222
freq.toFreq(note)
⇒ Float
Get the frequency of note with 2 decimals precission using A4 440Hz tuning
This is an alias for: eqTempFreq(440, 2, <note>)
Kind: static method of freq
Returns: Float
- the frequency in herzs
Param | Type | Description |
---|---|---|
note | Number | String |
the note name or midi number |
Example
freq // => 440freq // => 261.63
freq.eqTempFreqToMidi(tuning, freq)
⇒ Number
Get the midi note from a frequency in equal temperament scale. You can specify the number of decimals of the midi number.
Kind: static method of freq
Returns: Number
- the midi number
Param | Type | Description |
---|---|---|
tuning | Float |
(Optional) the reference A4 tuning (440Hz by default) |
freq | Number |
the frequency |
freq.toMidi(freq)
⇒ Number
Get midi number from frequency with two decimals of precission.
This is an alisas for: eqTempFreqToMidi(440, 2, <freq>)
Kind: static method of freq
Returns: Number
- midi number
Param | Type |
---|---|
freq | Float |
Example
freq // => 59.96
freq.note(freq, useSharps)
⇒ String
Get note name from frequency using an equal temperament scale with 440Hz as reference
Kind: static method of freq
Returns: String
- note name
Param | Type | Description |
---|---|---|
freq | Float |
|
useSharps | Boolean |
(Optional) set to true to use sharps instead of flats |
Example
freq // => 'A4'
freq.cents(base, freq)
⇒ Integer
Get difference in cents between two frequencies. The frequencies can be expressed with hertzs or midi numbers or note names
Kind: static method of freq
Returns: Integer
- The difference in cents
Param | Type |
---|---|
base | Float | Integer | String |
freq | Float | Integer | String |
Example
// => -4