open-audiovisual
Search GitHub

oav-p5 reference · Note names and pitch

noteFreq()#

functionoav-p5
noteFreq(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

NameTypeDescription
vNumber | StringA 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

jsOpenProcessing ↗
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);
}
Prints 440 Hz and 261.63 Hz.

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.

p5/oav-p5.js, line 244

↑ Back to top · All names