[−][src]Static p5_sys::global::midiToFreq
pub static midiToFreq: MidiToFreqInternalType
Returns the frequency value of a MIDI note value. General MIDI treats notes as integers where middle C is 60, C# is 61, D is 62 etc. Useful for generating musical frequencies with oscillators.
Examples
let midiNotes = [60, 64, 67, 72];
let noteIndex = 0;
let midiVal, freq;
function setup() {
let cnv = createCanvas(100, 100);
cnv.mousePressed(startSound);
osc = new p5.TriOsc();
env = new p5.Envelope();
}
function draw() {
background(220);
text('tap to play', 10, 20);
if (midiVal) {
text('MIDI: ' + midiVal, 10, 40);
text('Freq: ' + freq, 10, 60);
}
}
function startSound() {
// see also: userStartAudio();
osc.start();
midiVal = midiNotes[noteIndex % midiNotes.length];
freq = midiToFreq(midiVal);
osc.freq(freq);
env.ramp(osc, 0, 1.0, 0);
noteIndex++;
}
Parameters
midiNote
The number of a MIDI note