xxxxxxxxxx
var osc, envelope, fft;
var scaleArray = [68, 76, 82, 54, 48, 77, 67,58];
var note = 0;
function setup() {
createCanvas(710, 200);
osc = new p5.SinOsc();
// Instantiate the envelope
envelope = new p5.Env();
// set attackTime, decayTime, sustainRatio, releaseTime
envelope.setADSR(0.001, 0.5, 0.1, 0.5);
// set attackLevel, releaseLevel
envelope.setRange(10, 0);
osc.start();
fft = new p5.FFT();
noStroke();
}
function draw() {
background(20);
if (frameCount % 8 == 0 || frameCount == 1) {
var midiValue = scaleArray[note];
var freqValue = midiToFreq(midiValue);
osc.freq(freqValue);
envelope.play(osc, 0, 0.1);
note = (note + 1) % scaleArray.length;
}
// plot FFT.analyze() frequency analysis on the canvas
var spectrum = fft.analyze();
for (var i = 0; i < spectrum.length/20; i++) {
fill(spectrum[i], spectrum[i]/100, 200);
var x = map(i, 0, spectrum.length/100, 0, width);
var h = map(spectrum[i], 0, 200,0, height);
ellipse(x, height, spectrum.length/20, -h);
}
}x
mySketch, line 45:Uncaught ReferenceError: x is not defined