xxxxxxxxxx
222
let fft, mic, waveform;
let fft2;
let wAngle = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
mic = new p5.AudioIn();
mic.start();
fft = new p5.FFT();
fft2 = new p5.FFT();
//sound.amp(0.2);
//fft.setInput(mic);
angleMode(DEGREES);
synth = new p5.PolySynth();
fft.setInput(synth);
fft2.setInput(synth);
}
function draw() {
background(0);
let spectrum = fft2.analyze();
let spectrum2 = fft.analyze();
stroke(255, 255, 0);
let angle1 = 360 / spectrum.length;
let rot1 = 180;
noFill(); // spectrum is green
for (let i = 0; i < spectrum.length; i++) {
push();
translate(width / 2, height / 2);
//translate(mouseX, mouseY);
let x = 0;
//let x = map(i, 0, spectrum.length, 0, width);
let h = map(spectrum[i], 0, 255, 0, height);
rot1 = rot1 + angle1 * 3;
rotate(rot1);
//line(x, 0,x, h)
point(x, h);
pop();
}
for (let i = 0; i < spectrum.length; i++) {
let x = map(i, 0, spectrum.length, 0, width);
let h = map(spectrum[i], 0, 255, height / 3, 0);
//line(x, 0,x, h)
point(x, h);
}
stroke(0, 255, 0);
fill(0, 255, 0);
for (let i = 0; i < spectrum2.length; i++) {
let x = map(i, 0, spectrum2.length, 0, width);
let h = map(spectrum2[i], 0, 255, height / 2, height / 2.5);
line(x, height / 2, x, h)
point(x, h);
}
noFill();
let itr = 25;
noFill(); // spectrum is green
push();
translate(mouseX,mouseY);
rotate(wAngle);
for (let i = 0; i < spectrum.length; i++) {
push();
//translate(width / 2, height / 2);
//translate(mouseX,mouseY);
translate(0,0);
let x = 0;
//let x = map(i, 0, spectrum.length, 0, width);
let h = map(spectrum[i], 0, 255, 0, height / 7);
rot1 = rot1 + angle1 * 3;
rotate(rot1);
line(x, 0, x, h)
//point(x, h);
pop();
}
wAngle = wAngle + itr;
pop();
waveform = fft.waveform();
noFill();
//beginShape();
//stroke(255, 255, 0); // YEllow
strokeWeight(1);
let angle = 360 / waveform.length;
let rot = 0;
let b = 255 / waveform.length;
let bl = 0;
//console.log(angle * waveform.length);
for (var i = 0; i < waveform.length; i++) {
push();
stroke(255, bl, bl); // YEllow
bl = bl + b;
translate(width / 2, height / 2);
///Circle///
// let x = 0;
// //let x = map(i, 0, spectrum.length, 0, width);
// let y = map(waveform[i], -1, 1, 0, height/4);
// //let y =0;
// rot = rot +angle;
// rotate(rot);
// point(x, y);
// Lines ////
let x = 0;
//let x = map(i, 0, spectrum.length, 0, width);
let y = map(waveform[i], -1, 1, 0, height / 4);
//let y =0;
rot = rot + angle;
rotate(rot);
//line(x, height / 2, x, y);
point(x, y);
pop();
//console.log(rot);
}
// endShape();
bl = 0;
for (let i = 0; i < waveform.length; i++) {
stroke(255, bl, bl); // YEllow
fill(255, bl, bl); // YEllow
bl = bl + b;
// let x = 0;
// //let x = map(i, 0, spectrum.length, 0, width);
// let y = map(waveform[i], -1, 1, 0, height/4);
// //let y =0;
// rot = rot +angle;
// rotate(rot);
// point(x, y);
// Lines ////
let x = map(i, 0, waveform.length, 0, width);
let y = map(waveform[i], -1, 1, height / 4, 3 * height / 4);
//let y =0;
//line(x, height / 2, x, y);
point(x, y);
//console.log(rot);
}
noStroke();
noFill();
}
//all code highly based off of Dan Shiffman's processing tutorials https://www.youtube.com/watch?v=IKB1hWWedMk
let notes = [
["A5", "C#5", "E5"],
["A5", "C5", "E5"],
["D5", "F#5", "A5"],
["G4", "B5", "D5"],
["E4", "G4", "B4"],
["C3", "E3", "G3"],
["F3", "A3", "C4"]
];
let keynotes = [
["C2", "E2", "G2"],
["F2", "A2", "C2"],
["A2", "C2", "E2"],
["B2", "D2", "F#2"],
["C3", "E3", "G3"],
["F3", "A3", "C3"],
["A3", "C3", "E3"],
["B3", "D3", "F#3"]
];
let lines = 60;
let duration;
let durationk;
let trigger;
let synth;
let synthkey;
let px = 0;
let notecounter = 0;
function mousePressed() {
chooseNote();
}
function mouseReleased() {
synth.noteRelease();
}
function chooseNote() {
// synth.noteRelease();
let chordPicker = floor(random(notes.length));
// console.log(chordPicker);
duration = random(0.2, 1.0);
// play(note, [velocity], [secondsFromNow], [sustainTime])
//synth.play(notes[floor(random(notes.length))], 0.5, .15, .1);
//synth.triggerAttack(notes[floor(random(notes.length))], 0.3, 0, duration);
for (let i = 0; i < 3; i++) {
synth.noteAttack(notes[chordPicker][i], i * 0.2, 0, duration);
}
}