Unlikely pairings
To play or stop a sound, simply click inside the corresponding circle.
//Ghalya Alsanea
//galsanea@andrew.cmu.edu
//Section B
//Project 10
var amplitude; //global amp variable
var defaultSize = 50; //size of circles if nothing is playing
//compile titles into array for easy access
var titles =
["alien", "bass", "chirp", "snare",
"marimba", "piano", "synth", "hop"];
//have a callerID for the dif sounds for easy access
var callIDs = [];
//X location of all the circles
var xLoc = [];
//set starting booleans for dif sounds
let alienBool = false;
let bassBool = false;
let chirpBool = false;
let kickSnareBool = false;
let marimbaBool = false;
let pianoBool = false;
let synthBool = false;
let hopBool = false;
//store all booleans in an array for easy access
var bools = [alienBool, bassBool, chirpBool, kickSnareBool,
marimbaBool, pianoBool, synthBool, hopBool]
function preload() {
//load all sound files
alienBass = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/alien-bass-loop.wav");
bassLoop = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/bass-loop.wav");
chirp = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/electricbirdchirp.wav");
kickSnare = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/kick-snare-loop.wav");
marimba = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/marimba-loop.wav");
piano = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/piano-loop.mp3");
synth = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/synth-142.wav");
hop = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/trip-hop.wav");
}
function setup() {
createCanvas(600, 150);
useSound();
amplitude = new p5.Amplitude();
//assign IDs to each sound
callIDs = [alienBass, bassLoop, chirp, kickSnare, marimba, piano, synth, hop];
for (var i = 0; i < callIDs.length; i++) {
callIDs[i].stop(); //start with no sound
callIDs[i].setLoop(true); //make sure it plays a continous loop
xLoc.push(i * 75 + 37.5); //assign x location based on ID index
}
}
function draw() {
//function call for rendering the circles
renderCircs();
}
function renderCircs () {
background(0);
for (var i = 0; i < callIDs.length; i++) {
//if the sound is playing, draw as red
//otherwise render as white
if (bools[i] === true) {
fill('red');
} else {
fill(255);
}
//render circle and text
circle(xLoc[i], height / 2, figureSize(bools[i]));
textSize(15);
textFont("Arial");
textAlign(CENTER);
text(titles[i], xLoc[i], height - 30);
}
}
//configure diameter of circle based on volume
function figureSize(a) {
//if the sound is playing, assign a size respectively
if (a === true) {
let level = amplitude.getLevel();
let size = floor(map(level, 0, 1, 50, 70));
return size;
}
//if no sound is playing then have the default size
else {
return defaultSize;
}
}
//configure whether to play the sound or stop based on boolean
function soundState(ind) {
if (bools[ind] === true) {
callIDs[ind].play();
} else if (bools[ind] === false) {
callIDs[ind].stop();
}
}
//state change when mouse is clicked
function mousePressed() {
for (var i = 0; i < xLoc.length; i++) {
//check where the mouse was clicked
var d = dist(mouseX, mouseY, xLoc[i], height / 2);
//if it's within one of the circles, then toggle sound state
if (d < figureSize(bools[i]) / 2) {
bools[i] = !bools[i];
soundState(i);
}
}
}
function soundSetup() {
//nothing here
}
For this project, I wanted to create something similar to a looping machine where you have different sounds and you can play them together and start and stop certain loops based on creative desire. I wanted the user to be in control of what’s being played and express themselves through sound. The 8 sounds I chose have the ability to be looped continuously and smoothly. The sounds sometimes work together and sometimes don’t, and the idea behind that is to see what music you can come up with using an unlikely pairing of sounds. Have fun and see what you come up with!