xxxxxxxxxx
80
// Array of sounds
let guitars = [];
let pianos = [];
let drums = [];
let reverb, delay;
let beatSpeed = 1;
let beat = 60;
let ratios = [1, 1.125, 1.25, 1.34, 1.5, 1.67, 1.875, 2]; // western major scale
// Load all the sounds
function preload() {
//load guitars
for (let g = 0; g < 6; g++) {
guitars.push(loadSound("guitar" + g + ".mp3"));
}
//load pianos
for (let p = 0; p < 7; p++) {
pianos.push(loadSound("piano" + p + ".mp3"));
}
//load drums
for (let d = 0; d < 4; d++) {
drums.push(loadSound("drum" + d + ".mp3"));
}
}
function setup() {
// reverb = new p5.Reverb();
// delay = new p5.Delay();
// for (let g = 0; g < guitars.length; g++) {
// reverb.process(guitars[g], 3, 2); // Reverb decay time: 3 seconds, damping: 2
// delay.process(guitars[g], 0.5, 0.5, 2300); // Delay time: 0.5s, feedback: 0.5
// }
randomSeed(0);
}
function draw() {
beat += beatSpeed;
if (beat < 30 || beat > 90) {
beatSpeed *= -1;
}
// Play Guitar based on the ratio
for (let g = 0; g < guitars.length; g++) {
if (frameCount % (beat * (g + 1)) == 2) {
// Pick a random harmonic ratio for melody
let r = random(ratios);
guitars[g].rate(r);
guitars[g].play();
// Apply occasional panning effect
if (random() < 0.2) {
guitars[g].pan(random(-1, 1));
}
// Play drums on even beats
if (frameCount > 300 && g % 2 == 0) {
drums[g % drums.length].play();
}
// if (random() < 0.2) {
// pianos[g].play();
// }
}
}
/*
// Play Guitar based on the ratio
for (let g = 0; g < drums.length; g++) {
if (frameCount % (beat * (g + 1)) == 2) {
// Pick a random harmonic ratio for melody
let r = random(ratios);
drums[g].rate(r);
drums[g].play();
}
}
*/
}