Created
October 31, 2016 03:08
-
-
Save thoreaubakker/917e47c459481db07ca680a42380df8b to your computer and use it in GitHub Desktop.
Tam Tam Digital Code Sample 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This Code has been developed by Thoreau Bakker & Samaa Ahmed, with the generous help of Professor Kate Hartman, Professor Nick Puckett and Junjun Zhu | |
//It is for a class on creation & computation at Ocad University in Toronto, Canada, in the fall of 2016 | |
var song, analyzer; | |
var canvas; | |
function preload() { | |
soundFormats('wav'); | |
sample = loadSound('warble.wav'); | |
sample2 = loadSound('warble2.wav'); | |
} | |
function setup() { | |
canvas = createCanvas(window.innerWidth, window.innerHeight); | |
fullscreen(false); | |
// create a new Amplitude analyzer | |
analyzer = new p5.Amplitude(); | |
// Patch the input to an volume analyzer | |
analyzer.setInput(song); | |
} | |
function mousePressed() { | |
if (sample.isPlaying()) { | |
sample.playMode('restart'); | |
} else { | |
sample2.play(); | |
return false; | |
} | |
} | |
function draw() { | |
background(255); | |
// Get the average (root mean square) amplitude | |
var rms = analyzer.getLevel(); | |
//rectMode(CENTER); // Set rectMode to CENTER | |
fill(0,150,220); | |
ellipse(width/2, height/2, 100+rms*2500, 100+rms*2500); | |
fill(255); | |
ellipse(width/2, height/2, 50+rms*1200, 50+rms*1200); | |
} | |
window.onresize = function() { | |
var w = window.innerWidth; | |
var h = window.innerHeight; | |
canvas.size(w,h+500); | |
width = w; | |
height = h; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment