This module provides some conversion utilities between different units used when dealing with audio
Example
import { noteToFreq } from 'synth-kit'
noteToFreq('A4') // => 440
Methods
(static) dBToGain(db) → {Number}
Convert decibels into gain.
Parameters:
Name | Type | Description |
---|---|---|
db |
Number |
Returns:
the gain (from 0 to 1)
- Type
- Number
Example
dBToGain(-3) // => 0.7071067811865475
(static) gainToDb(gain) → {Decibels}
Convert gain to decibels.
Parameters:
Name | Type | Description |
---|---|---|
gain |
Number | (0-1) |
Returns:
- Type
- Decibels
Example
s.gainToDb(0.3) // => -10.457574905606752
(static) levelToGain(level) → {Number}
Convert from level (an equal power scale from 0 to 100) into gain.
Parameters:
Name | Type | Description |
---|---|---|
level |
Number | from 0 to 100 |
Returns:
gain (from 0 to 1)
- Type
- Number
Example
levelToGain(80) // => 0.9510565162951535
(static) midiToFreq(midi, tuning) → {Number}
Convert from note midi number to frequency
Parameters:
Name | Type | Description |
---|---|---|
midi |
Number | the midi note number (can have decimals) |
tuning |
Number | (Optional) the frequency of a reference A4 note (440 by default) |
Returns:
the note frequency
- Type
- Number
Example
midiToFreq(69) // => 440
midiToFreq(69.5) // => 452.8929841231365
midiToFreq(70) // => 466.1637615180899
(static) noteToFreq(note, tuning) → {Number}
Convert from note name to frequency
Parameters:
Name | Type | Description |
---|---|---|
note |
String | the note name |
tuning |
Number | (Optional) the tuning of A4 (440 by default) |
Returns:
the note frequency
- Type
- Number
Example
noteToFreq('C3') // => 130.8127826502993
(static) tempoToFreq(bpm, sub) → {Float}
Convert from beats per minute to hertzs
Parameters:
Name | Type | Description |
---|---|---|
bpm |
Integer | the tempo |
sub |
Integer | (Optional) subdivision (default 1) |
Returns:
the tempo expressed in hertzs
- Type
- Float
Example
tempoToFreq(120) // => 2
tempoToFreq(120, 4) // => 8