Skip to content

Instantly share code, notes, and snippets.

@thoreaubakker
Created October 31, 2016 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoreaubakker/917e47c459481db07ca680a42380df8b to your computer and use it in GitHub Desktop.
Save thoreaubakker/917e47c459481db07ca680a42380df8b to your computer and use it in GitHub Desktop.
Tam Tam Digital Code Sample 2
//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