noteFreq()#
functionoav-p5noteFreq(v)
Returns the frequency in Hz of a note: noteFreq('A4') is 440.
For a sketch that makes its own sound (p5.sound, Web Audio): osc.freq(noteFreq(note)). If you just want the sound, startSound() plays every key for you.
Parameters
| Name | Type | Description |
|---|---|---|
v | Number | String | A note name or a MIDI number. A number may be fractional (69.5 is a quarter tone above A4) and is not held to 0..127. |
Returns
Number Hz, equal temperament with A4 = 69 = 440 Hz.
Examples
function setup() {
createCanvas(400, 300);
textAlign(CENTER, CENTER);
textSize(36);
}
function draw() {
background(20);
fill(255);
text('A4 = ' + noteFreq('A4') + ' Hz\nC4 = ' + noteFreq('C4').toFixed(2) + ' Hz', width / 2, height / 2);
}Related
noteNumber()Turns a note name like'C4'into its MIDI number, 0 to 127.noteName()Turns a MIDI number into a note name:noteName(61)is'C#4'.startSound()Makes the keys you play heard through an instrument you name, and returns a promise that says whether sound is on.