xxxxxxxxxx
55
let sample;
let playButton;
let stopButton;
let rate;
let volume;
let panning;
let randomStart = 0;
let loopLength = 0.007;
function preload() {
sample = loadSound("dragons.mp3");
playButton = createButton("Play");
playButton.mousePressed(function() {
sample.loop();
});
stopButton = createButton("Stop");
stopButton.mousePressed(function() {
sample.stop();
});
}
function setup() {
createCanvas(400, 400);
// sample.rate(0.5);
}
function mousePressed() {
sample.stop();
let duration = sample.duration();
randomStart = random(0, duration - loopLength);
// let randomDuration = 0.2;
// sample.rate(random(0.1, 3));
// sample.play();
}
function draw() {
background(220);
if (!sample.isPlaying()) {
sample.jump(randomStart, loopLength);
}
// rate = map(mouseX, 0, width, -5, 5);
// volume = map(mouseY, 0, height, 0, 1);
// panning = map(mouseX, 0, width, -1, 1);
// // sample.rate(rate);
// sample.pan(panning);
// sample.setVolume(volume);
}