Move the mouse to manipulate the song. Click the mouse to reverse audio. Spacebar to pause. Type a,s,d,f for a surprise. *Reload in case of script error on line -1.
A fork of Code of Music: Sampler Example by Camilla Padgitt-Coles
xxxxxxxxxx
var song;
var gif;
var img;
let player = new Tone.Player("wintergarden.mp3");
player.loop = true;
player.retrigger = true;
player.toMaster();
let sampler = new Tone.Sampler({
"A1": "FrogVoice.wav"
});
sampler.envelope = {
attack: 0.2,
decay: 0,
sustain: 1,
release: 0.1
}
sampler.toMaster();
function keyPressed() {
let pitch;
if(keyCode === 66){
pitch = "A1";
}
else if(keyCode === 67){
pitch = "A1";
}
else if(keyCode === 68){
pitch = "A1";
}
else if(keyCode === 69){
pitch = "A1";
}
else if(keyCode === 70){
pitch = "A1";
}
else if (keyCode === 32) {
if (player.state == "stopped") {
player.pause();
} else {
player.start();
}
}
if(pitch && sampler.loaded){
// Sampler will repitch the closest sample
sampler.triggerAttack(pitch);
}
}
function keyReleased() {
sampler.triggerRelease();
}
function preload() {
song = loadSound('wintergarden.mp3');
gif = createImg('garden.gif');
img = loadImage("snowfrog.jpg");
}
function setup() {
createCanvas(windowWidth,windowHeight);
console.log("Play spacebar to start/stop. Mouse left and right to change speed. Click to reverse");
gif.size(windowWidth,windowHeight);
player.start();
}
function draw() {
player.playbackRate = map(mouseX, 0, width, 0.2, 0.6);
}
function mousePressed() {
// Displays the image at point (0, height/2) at half size
image(img, random(0,1000), random(0,1000), img.width/10, img.height/10);
}
function mouseReleased() {
player.reverse = !(player.reverse);
}