xxxxxxxxxx
var sound, amp, fft;
var s = 200;
function preload() {
sound = loadSound('MyDilemma.mp3');
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
sound.playMode('restart');
// sound.play();
amp = new p5.Amplitude();
amp.setInput(sound);
fft = new p5.FFT(0.5,256);
fft.setInput(sound);
angleMode(DEGREES);
}
function draw() {
background(0,10);
translate(width/2, height/2);
//get Amplitude
var level = amp.getLevel();
s = level * 200;
//decrease the circle size till 0
s = s - 1;
if (s <= 0) {
s = 0;
}
//get WaveForm
var waveform = fft.waveform();
beginShape();
noFill();
stroke(255);
strokeWeight(2);
for (var i=0; i<waveform.length; i++) {
var angle = i*360/waveform.length;
var r = map(waveform[i], -1 , 1, 0, 300);
var x = r * cos(angle);
var y = r * sin(angle);
//draw inner circle points
vertex(x,y);
//draw a circle on each inner circle point
// ellipse(x,y,10,10);
//draw outer circle points
var rr = 300;
var xx = rr * cos(angle);
var yy = rr * sin(angle);
//draw a circle on each outer circle points
// ellipse(xx,yy,10,10);
//draw lines from outer circle points to inner circle points
line (xx,yy,x,y);
}
endShape();
}
function mousePressed() {
if (sound.isPlaying()) {
sound.pause();
} else {
sound.play();
}
}