xxxxxxxxxx
110
let song1, song2, song3, reverb;
let songs = [song1, song2, song3]
let currentSong;
let n
function preload(){
song1 = loadSound('song1.mp3')
song2 = loadSound('song2.mp3')
song3 = loadSound('rickRoll.mp3')
}
function setup() {
createCanvas(400, 400);
fft = new p5.FFT();
button = createButton('Song 1 ');
button.position(105, 68);
button.mousePressed(playSong1);
button = createButton('Song 2 ');
button.position(170, 68);
button.mousePressed(playSong2);
button = createButton('Song 3 ');
button.position(170+65, 68);
button.mousePressed(playSong3);
button = createButton('Reverb ')
button.position(300, 68)
button.mousePressed(addReverb)
button = createButton('Delay ')
button.position(105, 100)
button.mousePressed(addDelay)
}
function draw() {
background(220);
let waveform = fft.waveform();
noFill();
beginShape();
stroke(random(100,255),random(100,255),random(100,255))
for (let i = 0; i < waveform.length; i++){
let x = map(i, 0, waveform.length, 0, 100);
let y = map( waveform[i], -1, 1, 0, height);
vertex(x,y);
}
endShape();
}
function playSong1(){
song1.play(1);
n = 0
}
function playSong2(){
song2.play()
n = 1
}
function playSong3(){
song3.play()
n = 2
}
function addReverb(){
reverb = new p5.Reverb();
if (n==0) {
song1.disconnect();
reverb.process(song1, 3, 2);
}
if (n==1) {
song2.disconnect();
reverb.process(song2, 10, 10);
}
if (n==2) {
song3.disconnect();
reverb.process(song3, 10, 60);
}
}
function addDelay(){
delay = new p5.Delay();
/////// DELAY TIME WILL BE BASED ON POTENTIOMETER///////////
if (n==0) {
delay.process(song1, 1, 0.7, 2300);
}
if (n==1) {
delay.process(song2, 0.9, 0.7, 2300);
}
if (n==2) {
delay.process(song3, 0.12, 0.7, 2300);
}
}