Paul Greenway – Project 10 – Sonic Sketch

pgreenwa_sonic_sketch

// Paul Greenway
// pgreenwa
// pgreenwa@andrew.cmu.edu
// Project-10-Sonic Sketch


let osc;

function preload() {

  
    //load sound files
  
    mySnd1 = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/boop.wav");
    mySnd1.setVolume(0.2);
  
    mySnd2 = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/alert.wav");
    mySnd2.setVolume(0.5);
  
    mySnd3 = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/alertHigh.wav");
    mySnd3.setVolume(0.5);
  
    mySnd4 = loadSound("https://courses.ideate.cmu.edu/15-104/f2019/wp-content/uploads/2019/11/bump.wav");
    mySnd4.setVolume(0.5);
    
}


function setup() {
  
    createCanvas(640, 480);
  
    //set frequency and amplitude
  
    osc = new p5.TriOsc(); 
    osc.amp(0.5);

 
    osc.start();
  
}

function soundSetup() {
    
    myOsc = new p5.Tri0sc();
    
    myOsc.freq(800.0);
  
    myOsc.start();
    myOsc.freq(400); 
}

function draw() {
  
    background(170, 190, mouseY);
    noStroke();
    
    let maxX = constrain(mouseX, 0, width-mouseX);
  
    // left circles 

    fill(170, 190, mouseY);
    //rotate(radians(angle));
    square(maxX, 0, mouseX/2, mouseY/5);
  
    fill(mouseY, 190, 200);
    //rotate(radians(angle));
    square(maxX, 50, mouseX/2, mouseY/5);
  
    fill(170, 190, mouseY);
    //rotate(radians(angle));
    square(maxX, 100, mouseX/2, mouseY/5);
  
    fill(mouseY, 190, 200);
    //rotate(radians(angle));
    square(maxX, 150, mouseX/2, mouseY/5);
  
    fill(170, 190, mouseY);
    //rotate(radians(angle));
    square(maxX, 200, mouseX/2, mouseY/5);
  
    fill(mouseY, 190, 200);
    //rotate(radians(angle));
    square(maxX, 250, mouseX/2, mouseY/5);
  
    fill(170, 190, mouseY);
    //rotate(radians(angle));
    square(maxX, 300, mouseX/2, mouseY/5);
  
    fill(mouseY, 190, 200);
    //rotate(radians(angle));
    square(maxX, 350, mouseX/2, mouseY/5);
  
    fill(170, 190, mouseY);
    //rotate(radians(angle));
    square(maxX, 400, mouseX/2, mouseY/5);
  
    fill(mouseY, 190, 200);
    //rotate(radians(angle));
    square(maxX, 450, mouseX/2, mouseY/5);
  
  
  
    // play sound effects at canvas borders
      
    if (mouseY > 470) {
    
        mySnd2.play();
    }
  
    if (mouseY < 10) {
    
        mySnd3.play();
    }
  
    if (mouseX < 10) {
    
        mySnd4.play();
    }
  
    if (mouseX > 630) {
    
        mySnd4.play();
    }
  
    //modulate sound while mouse is moving
  
    let freq = map(mouseX, 0, width, 40, 880);
    osc.freq(freq);

    let amp = map(mouseY, 0, height, 1, 0.01);
    osc.amp(amp);
  
}


For this project, I used my project 3 dynamic drawing as a starting point. I then decided to use sound effects based on the mouse position on the canvas. The user is able to control the frequency of the base sound with the mouse and can also trigger different sound effects at each border of the canvas.

Leave a Reply