Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/content/examples/en/17_Sound/00_Echo_Synth/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
let osc, delay, env;

function setup() {
let cnv = createCanvas(400, 400);
background(220);
textAlign(CENTER);
textSize(13);
text('click and drag mouse', width/2, 150);

osc = new p5.Oscillator('sawtooth');
osc.amp(0.74);
env = new p5.Envelope(0.01);
delay = new p5.Delay(0.12, 0.7);

osc.disconnect();
osc.connect(env);
env.disconnect();
env.connect(delay);

cnv.mousePressed(oscStart);
cnv.mouseReleased(oscStop);
cnv.mouseOut(oscStop);
describe('Click and release or hold, to play a square wave with delay effect.');
}

function oscStart() {
background(0, 255, 255);
text('release to hear delay', width/2, 150);
osc.start();
env.triggerAttack();
}

function oscStop() {
background(220);
text('click and drag mouse', width/2, 150);
env.triggerRelease();
}

function draw() {
osc.freq(map(mouseY, height, 0, 440, 880))
let dtime = map(mouseX, 0, width, 0.1, 0.5);
delay.delayTime(dtime);
}
10 changes: 10 additions & 0 deletions src/content/examples/en/17_Sound/00_Echo_Synth/description.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
featuredImage: "../../../images/featured/16_Async_Await_PromiseAll-thumbnail.png"
featuredImageAlt: Three random images loaded and displayed on a canvas after using async/await and Promise.all.
title: Echo Synth
oneLineDescription: Trigger a short sound with a variable echo effect.
---

This example demonstrates how to use the p5.sound.js add-on library.

The sketch includes an oscillator (which produces a tone) and the Envelope and Delay processors. The echo effect is created through the combination of echo and delay.