Last active
May 2, 2017 19:24
-
-
Save jeremywen/4af098418b941d6062e8b49f07f873e7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<html> | |
<head> | |
<script src="p5.js"></script> | |
<script src="addons/p5.sound.js"></script> | |
</head> | |
<body> | |
<script> | |
var playing = false, recording = false; | |
var mySound, recorder, recordedSound; | |
function preload() { | |
mySound = loadSound('test.wav'); | |
} | |
function setup(){ | |
createCanvas(1000, 1000); | |
background(0); | |
recorder = new p5.SoundRecorder(); | |
recordedSound = new p5.SoundFile(); | |
mySound.setVolume(0.1); | |
mySound.addCue(1, function(){ | |
console.log("cue at 1 second"); | |
recorder.record(recordedSound); | |
recording = true; | |
}); | |
mySound.addCue(2, function(){ | |
console.log("cue at 2 seconds"); | |
recorder.stop(); | |
save(recordedSound, 'recording-from-1-to-2-seconds.wav'); | |
recording = false; | |
}); | |
} | |
function draw(){ | |
if(recording){ | |
background(100,0,0); | |
} else if(playing){ | |
background(0,100,0); | |
} else { | |
background(0); | |
} | |
} | |
function mouseClicked(){ | |
playing ? mySound.stop() : mySound.play(); | |
playing = !playing; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment