Valeria Graziani – Audio

Ho tentato la versione Audio [B] con il theremin 😛

let wave;
let img;
let playing = false;
function preload() {
img = loadImage(‘assets/foto.png’);
}
function setup() {
createCanvas(400, 400);
let toggleButton = createButton(‘start/ stop’);
toggleButton.position(10, 10);
toggleButton.mousePressed(toggleWave);
wave = new p5.Oscillator(‘sine’);
wave.amp(0);
}
function draw() {
background(220);
if (img) {
image(img, 0, 0, width, height);
}
if (playing) {
//frequenza mapping con dimensioni canvas
let f = map(mouseY, height, 0, 100, 1200);
f = constrain(f, 100, 1200);
wave.freq(f, 0.1);
//ampiezza let a = map(mouseX, 0, width, 0, 1); a = constrain(a, 0, 1); wave.amp(a, 0.1); //frequenza fill(255, 0, 0); noStroke(); ellipse(mouseX, mouseY, 20, 20); fill(0); text("FREQ: " + floor(f) + "Hz", mouseX + 15, mouseY);
}
}
//bottone start e stop
function toggleWave() {
userStartAudio();
if (!playing) {
wave.start();
wave.amp(0.5, 0.1);
playing = true;
} else {
wave.amp(0, 0.1);
wave.stop();
playing = false;
}
}

Commenti

Lascia un commento